1use abi_stable::StableAbi;
9use abi_stable::std_types::{ROption, RResult, RString, RVec};
10
11#[repr(C)]
12#[derive(StableAbi, Clone, Debug)]
13pub struct ActiveSidebarFFI {
14 pub plugin_id: RString,
15 pub button_id: ROption<RString>,
16 pub width_px: u32,
17 pub ui_path: RString,
18 pub component: RString,
19}
20
21#[repr(C)]
23#[derive(StableAbi, Clone, Debug)]
24pub struct ToolbarButtonFFI {
25 pub button_id: RString,
26 pub tooltip: RString,
27 pub icon_svg: RString,
28 pub action_id: RString,
29 pub tool_mode: ROption<HostToolModeFFI>,
30 pub hotkey: ROption<RString>,
31}
32
33#[repr(C)]
35#[derive(StableAbi, Clone, Debug)]
36pub struct HudToolbarButtonFFI {
37 pub button_id: RString,
38 pub tooltip: RString,
39 pub icon_svg: RString,
40 pub toggled_icon_svg: ROption<RString>,
41 pub action_id: RString,
42}
43
44#[repr(C)]
45#[derive(StableAbi, Clone, Debug)]
46pub struct UiPropertyFFI {
47 pub name: RString,
48 pub json_value: RString,
49}
50
51#[repr(C)]
52#[derive(StableAbi, Clone, Debug)]
53pub struct ViewportContextMenuItemFFI {
54 pub item_id: RString,
55 pub label: RString,
56 pub icon: RString,
57 pub enabled: bool,
58}
59
60#[repr(C)]
61#[derive(StableAbi, Clone, Debug)]
62pub struct ViewportOverlayPointFFI {
63 pub annotation_id: RString,
64 pub x_level0: f64,
65 pub y_level0: f64,
66 pub diameter_px: f32,
67 pub ring_red: u8,
68 pub ring_green: u8,
69 pub ring_blue: u8,
70}
71
72#[repr(C)]
73#[derive(StableAbi, Clone, Debug)]
74pub struct ViewportOverlayVertexFFI {
75 pub x_level0: f64,
76 pub y_level0: f64,
77}
78
79#[repr(C)]
80#[derive(StableAbi, Clone, Debug)]
81pub struct ViewportOverlayPolygonFFI {
82 pub annotation_id: RString,
83 pub vertices: RVec<ViewportOverlayVertexFFI>,
84 pub fill_red: u8,
85 pub fill_green: u8,
86 pub fill_blue: u8,
87}
88
89#[repr(C)]
90#[derive(StableAbi, Clone, Debug)]
91pub struct ConfirmationDialogRequestFFI {
92 pub title: RString,
93 pub message: RString,
94 pub confirm_label: RString,
95 pub cancel_label: RString,
96 pub confirm_callback: ROption<RString>,
97 pub confirm_args_json: ROption<RString>,
98 pub cancel_callback: ROption<RString>,
99 pub cancel_args_json: ROption<RString>,
100}
101
102#[repr(C)]
103#[derive(StableAbi, Clone, Debug)]
104pub struct ModalDialogRequestFFI {
105 pub ui_path: RString,
106 pub component: RString,
107 pub width_px: u32,
108 pub height_px: u32,
109}
110
111#[repr(C)]
112#[derive(StableAbi, Clone, Debug)]
113pub struct ViewportOverlayComponentRequestFFI {
114 pub ui_path: RString,
115 pub component: RString,
116 pub z_index: i32,
117}
118
119#[repr(C)]
120#[derive(StableAbi, Clone, Debug, Default)]
121pub struct PluginUndoRedoStateFFI {
122 pub enabled: bool,
123 pub undo_available: bool,
124 pub redo_available: bool,
125}
126
127#[repr(C)]
129#[derive(StableAbi, Clone, Debug)]
130pub struct ActionResponseFFI {
131 pub open_window: bool,
133}
134
135#[repr(u32)]
136#[derive(StableAbi, Clone, Copy, Debug, PartialEq, Eq)]
137pub enum HostLogLevelFFI {
138 Trace = 0,
139 Debug = 1,
140 Info = 2,
141 Warn = 3,
142 Error = 4,
143}
144
145#[repr(u32)]
146#[derive(StableAbi, Clone, Copy, Debug, PartialEq, Eq)]
147pub enum HostToolModeFFI {
148 Navigate = 0,
149 RegionOfInterest = 1,
150 MeasureDistance = 2,
151 PointAnnotation = 3,
152 PolygonAnnotation = 4,
153}
154
155#[repr(C)]
156#[derive(StableAbi, Clone, Debug)]
157pub struct OpenFileInfoFFI {
158 pub file_id: i32,
159 pub path: RString,
160 pub filename: RString,
161 pub width: u64,
162 pub height: u64,
163 pub level_count: u32,
164 pub vendor: ROption<RString>,
165 pub mpp_x: ROption<f64>,
166 pub mpp_y: ROption<f64>,
167 pub objective_power: ROption<f64>,
168 pub scan_date: ROption<RString>,
169}
170
171#[repr(C)]
177#[derive(StableAbi, Clone, Copy, Debug)]
178pub struct LevelInfoFFI {
179 pub level: u32,
180 pub width: u64,
181 pub height: u64,
182 pub downsample: f64,
183}
184
185#[repr(C)]
186#[derive(StableAbi, Clone, Debug)]
187pub struct ViewportSnapshotFFI {
188 pub pane_index: u32,
189 pub file_id: i32,
190 pub file_path: RString,
191 pub filename: RString,
192 pub center_x: f64,
193 pub center_y: f64,
194 pub zoom: f64,
195 pub width: f64,
196 pub height: f64,
197 pub image_width: f64,
198 pub image_height: f64,
199 pub bounds_left: f64,
200 pub bounds_top: f64,
201 pub bounds_right: f64,
202 pub bounds_bottom: f64,
203}
204
205#[repr(C)]
206#[derive(StableAbi, Clone, Debug)]
207pub struct HostSnapshotFFI {
208 pub app_name: RString,
209 pub app_version: RString,
210 pub render_backend: RString,
211 pub filtering_mode: RString,
212 pub split_enabled: bool,
213 pub focused_pane: u32,
214 pub open_files: RVec<OpenFileInfoFFI>,
215 pub active_file: ROption<OpenFileInfoFFI>,
216 pub active_viewport: ROption<ViewportSnapshotFFI>,
217 pub recent_files: RVec<RString>,
218 pub active_sidebar: ROption<ActiveSidebarFFI>,
219}
220
221#[repr(C)]
222#[derive(StableAbi, Copy, Clone)]
223pub struct HostApiVTable {
224 pub context: u64,
225 pub get_snapshot: extern "C" fn(context: u64) -> HostSnapshotFFI,
226 pub read_region: extern "C" fn(
227 context: u64,
228 file_id: i32,
229 level: u32,
230 x: i64,
231 y: i64,
232 width: u32,
233 height: u32,
234 ) -> RResult<RVec<u8>, RString>,
235 pub open_file: extern "C" fn(context: u64, path: RString) -> RResult<(), RString>,
236 pub set_active_viewport: extern "C" fn(
237 context: u64,
238 center_x: f64,
239 center_y: f64,
240 zoom: f64,
241 ) -> RResult<(), RString>,
242 pub fit_active_viewport: extern "C" fn(context: u64) -> RResult<(), RString>,
243 pub frame_active_rect: extern "C" fn(
244 context: u64,
245 x: f64,
246 y: f64,
247 width: f64,
248 height: f64,
249 ) -> RResult<(), RString>,
250 pub cycle_focused_pane: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
251 pub cycle_active_tab: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
252 pub toggle_series_bar: extern "C" fn(context: u64) -> RResult<(), RString>,
253 pub cycle_series_selection: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
254 pub activate_selected_series_entry: extern "C" fn(context: u64) -> RResult<(), RString>,
255 pub set_active_tool: extern "C" fn(context: u64, tool: HostToolModeFFI) -> RResult<(), RString>,
256 pub request_render: extern "C" fn(context: u64) -> RResult<(), RString>,
257 pub set_toolbar_button_active:
258 extern "C" fn(context: u64, button_id: RString, active: bool) -> RResult<(), RString>,
259 pub set_hud_toolbar_button_active:
260 extern "C" fn(context: u64, button_id: RString, active: bool) -> RResult<(), RString>,
261 pub show_sidebar: extern "C" fn(
262 context: u64,
263 button_id: RString,
264 width_px: u32,
265 ui_path: RString,
266 component: RString,
267 ) -> RResult<(), RString>,
268 pub refresh_sidebar: extern "C" fn(context: u64) -> RResult<(), RString>,
269 pub hide_sidebar: extern "C" fn(context: u64) -> RResult<(), RString>,
270 pub show_confirmation_dialog:
271 extern "C" fn(context: u64, request: ConfirmationDialogRequestFFI) -> RResult<(), RString>,
272 pub show_modal_dialog:
273 extern "C" fn(context: u64, request: ModalDialogRequestFFI) -> RResult<(), RString>,
274 pub hide_modal_dialog: extern "C" fn(context: u64) -> RResult<(), RString>,
275 pub set_undo_redo_state:
276 extern "C" fn(context: u64, state: PluginUndoRedoStateFFI) -> RResult<(), RString>,
277 pub open_file_dialog: extern "C" fn(
278 context: u64,
279 filter_name: RString,
280 extension: RString,
281 ) -> RResult<RString, RString>,
282 pub save_file_dialog: extern "C" fn(
283 context: u64,
284 default_file_name: RString,
285 filter_name: RString,
286 extension: RString,
287 ) -> RResult<RString, RString>,
288 pub log_message: extern "C" fn(context: u64, level: HostLogLevelFFI, message: RString),
289 pub get_level_info:
293 extern "C" fn(context: u64, file_id: i32) -> RResult<RVec<LevelInfoFFI>, RString>,
294}
295
296#[repr(C)]
304#[derive(StableAbi, Copy, Clone)]
305pub struct PluginVTable {
306 pub set_host_api: extern "C" fn(host_api: HostApiVTable),
309
310 pub get_toolbar_buttons: extern "C" fn() -> RVec<ToolbarButtonFFI>,
312
313 pub get_hud_toolbar_buttons: extern "C" fn() -> RVec<HudToolbarButtonFFI>,
315
316 pub on_action: extern "C" fn(action_id: RString) -> ActionResponseFFI,
318
319 pub on_hud_action:
321 extern "C" fn(action_id: RString, viewport: ViewportSnapshotFFI) -> ActionResponseFFI,
322
323 pub on_ui_callback: extern "C" fn(callback_name: RString, args_json: RString),
327
328 pub get_sidebar_properties: extern "C" fn() -> RVec<UiPropertyFFI>,
331
332 pub get_viewport_context_menu_items:
334 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportContextMenuItemFFI>,
335
336 pub on_viewport_context_menu_action:
338 extern "C" fn(item_id: RString, viewport: ViewportSnapshotFFI) -> ActionResponseFFI,
339
340 pub get_viewport_overlay_points:
342 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportOverlayPointFFI>,
343
344 pub get_viewport_overlay_polygons:
346 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportOverlayPolygonFFI>,
347
348 pub get_viewport_overlay_component:
350 extern "C" fn() -> ROption<ViewportOverlayComponentRequestFFI>,
351
352 pub get_viewport_overlay_properties:
354 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<UiPropertyFFI>,
355
356 pub on_point_annotation_placed:
358 extern "C" fn(viewport: ViewportSnapshotFFI, x_level0: f64, y_level0: f64),
359
360 pub on_polygon_annotation_placed:
362 extern "C" fn(viewport: ViewportSnapshotFFI, vertices: RVec<ViewportOverlayVertexFFI>),
363
364 pub on_undo: extern "C" fn() -> ActionResponseFFI,
366
367 pub on_redo: extern "C" fn() -> ActionResponseFFI,
369
370 pub on_point_annotation_moved: extern "C" fn(
372 viewport: ViewportSnapshotFFI,
373 annotation_id: RString,
374 x_level0: f64,
375 y_level0: f64,
376 ),
377
378 pub on_polygon_annotation_moved: extern "C" fn(
380 viewport: ViewportSnapshotFFI,
381 annotation_id: RString,
382 vertices: RVec<ViewportOverlayVertexFFI>,
383 ),
384
385 pub on_viewport_annotation_selected:
388 extern "C" fn(viewport: ViewportSnapshotFFI, annotation_id: RString),
389
390 pub get_viewport_filters: extern "C" fn() -> RVec<ViewportFilterFFI>,
393
394 pub apply_filter_cpu: extern "C" fn(
399 filter_id: RString,
400 rgba_data: *mut u8,
401 len: u32,
402 width: u32,
403 height: u32,
404 viewport: *const ViewportSnapshotFFI,
405 ) -> bool,
406
407 pub apply_filter_gpu:
413 extern "C" fn(filter_id: RString, ctx: *const GpuFilterContextFFI) -> bool,
414
415 pub set_filter_enabled: extern "C" fn(filter_id: RString, enabled: bool),
417}
418
419#[repr(C)]
426#[derive(StableAbi, Clone, Debug)]
427pub struct GpuFilterContextFFI {
428 pub vk_device: u64,
430 pub vk_physical_device: u64,
432 pub vk_queue: u64,
434 pub queue_family_index: u32,
436 pub vk_image: u64,
438 pub width: u32,
440 pub height: u32,
442 pub vk_format: u32,
444 pub vk_done_fence: u64,
447}
448
449#[repr(C)]
451#[derive(StableAbi, Clone, Debug)]
452pub struct ViewportFilterFFI {
453 pub filter_id: RString,
454 pub name: RString,
455 pub supports_cpu: bool,
456 pub supports_gpu: bool,
457 pub enabled: bool,
458}
459
460pub type GetPluginVTableFn = unsafe extern "C" fn() -> PluginVTable;
462
463pub const PLUGIN_VTABLE_SYMBOL: &[u8] = b"eov_get_plugin_vtable\0";
465
466pub fn plugin_library_filename(id: &str) -> String {
469 if cfg!(target_os = "macos") {
470 format!("lib{id}.dylib")
471 } else if cfg!(target_os = "windows") {
472 format!("{id}.dll")
473 } else {
474 format!("lib{id}.so")
475 }
476}