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)]
172#[derive(StableAbi, Clone, Debug)]
173pub struct ViewportSnapshotFFI {
174 pub pane_index: u32,
175 pub file_id: i32,
176 pub file_path: RString,
177 pub filename: RString,
178 pub center_x: f64,
179 pub center_y: f64,
180 pub zoom: f64,
181 pub width: f64,
182 pub height: f64,
183 pub image_width: f64,
184 pub image_height: f64,
185 pub bounds_left: f64,
186 pub bounds_top: f64,
187 pub bounds_right: f64,
188 pub bounds_bottom: f64,
189}
190
191#[repr(C)]
192#[derive(StableAbi, Clone, Debug)]
193pub struct HostSnapshotFFI {
194 pub app_name: RString,
195 pub app_version: RString,
196 pub render_backend: RString,
197 pub filtering_mode: RString,
198 pub split_enabled: bool,
199 pub focused_pane: u32,
200 pub open_files: RVec<OpenFileInfoFFI>,
201 pub active_file: ROption<OpenFileInfoFFI>,
202 pub active_viewport: ROption<ViewportSnapshotFFI>,
203 pub recent_files: RVec<RString>,
204 pub active_sidebar: ROption<ActiveSidebarFFI>,
205}
206
207#[repr(C)]
208#[derive(StableAbi, Copy, Clone)]
209pub struct HostApiVTable {
210 pub context: u64,
211 pub get_snapshot: extern "C" fn(context: u64) -> HostSnapshotFFI,
212 pub read_region: extern "C" fn(
213 context: u64,
214 file_id: i32,
215 level: u32,
216 x: i64,
217 y: i64,
218 width: u32,
219 height: u32,
220 ) -> RResult<RVec<u8>, RString>,
221 pub open_file: extern "C" fn(context: u64, path: RString) -> RResult<(), RString>,
222 pub set_active_viewport: extern "C" fn(
223 context: u64,
224 center_x: f64,
225 center_y: f64,
226 zoom: f64,
227 ) -> RResult<(), RString>,
228 pub fit_active_viewport: extern "C" fn(context: u64) -> RResult<(), RString>,
229 pub frame_active_rect: extern "C" fn(
230 context: u64,
231 x: f64,
232 y: f64,
233 width: f64,
234 height: f64,
235 ) -> RResult<(), RString>,
236 pub cycle_focused_pane: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
237 pub cycle_active_tab: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
238 pub toggle_series_bar: extern "C" fn(context: u64) -> RResult<(), RString>,
239 pub cycle_series_selection: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
240 pub activate_selected_series_entry: extern "C" fn(context: u64) -> RResult<(), RString>,
241 pub set_active_tool: extern "C" fn(context: u64, tool: HostToolModeFFI) -> RResult<(), RString>,
242 pub request_render: extern "C" fn(context: u64) -> RResult<(), RString>,
243 pub set_toolbar_button_active:
244 extern "C" fn(context: u64, button_id: RString, active: bool) -> RResult<(), RString>,
245 pub set_hud_toolbar_button_active:
246 extern "C" fn(context: u64, button_id: RString, active: bool) -> RResult<(), RString>,
247 pub show_sidebar: extern "C" fn(
248 context: u64,
249 button_id: RString,
250 width_px: u32,
251 ui_path: RString,
252 component: RString,
253 ) -> RResult<(), RString>,
254 pub refresh_sidebar: extern "C" fn(context: u64) -> RResult<(), RString>,
255 pub hide_sidebar: extern "C" fn(context: u64) -> RResult<(), RString>,
256 pub show_confirmation_dialog:
257 extern "C" fn(context: u64, request: ConfirmationDialogRequestFFI) -> RResult<(), RString>,
258 pub show_modal_dialog:
259 extern "C" fn(context: u64, request: ModalDialogRequestFFI) -> RResult<(), RString>,
260 pub hide_modal_dialog: extern "C" fn(context: u64) -> RResult<(), RString>,
261 pub set_undo_redo_state:
262 extern "C" fn(context: u64, state: PluginUndoRedoStateFFI) -> RResult<(), RString>,
263 pub open_file_dialog: extern "C" fn(
264 context: u64,
265 filter_name: RString,
266 extension: RString,
267 ) -> RResult<RString, RString>,
268 pub save_file_dialog: extern "C" fn(
269 context: u64,
270 default_file_name: RString,
271 filter_name: RString,
272 extension: RString,
273 ) -> RResult<RString, RString>,
274 pub log_message: extern "C" fn(context: u64, level: HostLogLevelFFI, message: RString),
275}
276
277#[repr(C)]
285#[derive(StableAbi, Copy, Clone)]
286pub struct PluginVTable {
287 pub set_host_api: extern "C" fn(host_api: HostApiVTable),
290
291 pub get_toolbar_buttons: extern "C" fn() -> RVec<ToolbarButtonFFI>,
293
294 pub get_hud_toolbar_buttons: extern "C" fn() -> RVec<HudToolbarButtonFFI>,
296
297 pub on_action: extern "C" fn(action_id: RString) -> ActionResponseFFI,
299
300 pub on_hud_action:
302 extern "C" fn(action_id: RString, viewport: ViewportSnapshotFFI) -> ActionResponseFFI,
303
304 pub on_ui_callback: extern "C" fn(callback_name: RString, args_json: RString),
308
309 pub get_sidebar_properties: extern "C" fn() -> RVec<UiPropertyFFI>,
312
313 pub get_viewport_context_menu_items:
315 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportContextMenuItemFFI>,
316
317 pub on_viewport_context_menu_action:
319 extern "C" fn(item_id: RString, viewport: ViewportSnapshotFFI) -> ActionResponseFFI,
320
321 pub get_viewport_overlay_points:
323 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportOverlayPointFFI>,
324
325 pub get_viewport_overlay_polygons:
327 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportOverlayPolygonFFI>,
328
329 pub get_viewport_overlay_component:
331 extern "C" fn() -> ROption<ViewportOverlayComponentRequestFFI>,
332
333 pub get_viewport_overlay_properties:
335 extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<UiPropertyFFI>,
336
337 pub on_point_annotation_placed:
339 extern "C" fn(viewport: ViewportSnapshotFFI, x_level0: f64, y_level0: f64),
340
341 pub on_polygon_annotation_placed:
343 extern "C" fn(viewport: ViewportSnapshotFFI, vertices: RVec<ViewportOverlayVertexFFI>),
344
345 pub on_undo: extern "C" fn() -> ActionResponseFFI,
347
348 pub on_redo: extern "C" fn() -> ActionResponseFFI,
350
351 pub on_point_annotation_moved: extern "C" fn(
353 viewport: ViewportSnapshotFFI,
354 annotation_id: RString,
355 x_level0: f64,
356 y_level0: f64,
357 ),
358
359 pub on_polygon_annotation_moved: extern "C" fn(
361 viewport: ViewportSnapshotFFI,
362 annotation_id: RString,
363 vertices: RVec<ViewportOverlayVertexFFI>,
364 ),
365
366 pub on_viewport_annotation_selected:
369 extern "C" fn(viewport: ViewportSnapshotFFI, annotation_id: RString),
370
371 pub get_viewport_filters: extern "C" fn() -> RVec<ViewportFilterFFI>,
374
375 pub apply_filter_cpu: extern "C" fn(
380 filter_id: RString,
381 rgba_data: *mut u8,
382 len: u32,
383 width: u32,
384 height: u32,
385 viewport: *const ViewportSnapshotFFI,
386 ) -> bool,
387
388 pub apply_filter_gpu:
394 extern "C" fn(filter_id: RString, ctx: *const GpuFilterContextFFI) -> bool,
395
396 pub set_filter_enabled: extern "C" fn(filter_id: RString, enabled: bool),
398}
399
400#[repr(C)]
407#[derive(StableAbi, Clone, Debug)]
408pub struct GpuFilterContextFFI {
409 pub vk_device: u64,
411 pub vk_physical_device: u64,
413 pub vk_queue: u64,
415 pub queue_family_index: u32,
417 pub vk_image: u64,
419 pub width: u32,
421 pub height: u32,
423 pub vk_format: u32,
425 pub vk_done_fence: u64,
428}
429
430#[repr(C)]
432#[derive(StableAbi, Clone, Debug)]
433pub struct ViewportFilterFFI {
434 pub filter_id: RString,
435 pub name: RString,
436 pub supports_cpu: bool,
437 pub supports_gpu: bool,
438 pub enabled: bool,
439}
440
441pub type GetPluginVTableFn = unsafe extern "C" fn() -> PluginVTable;
443
444pub const PLUGIN_VTABLE_SYMBOL: &[u8] = b"eov_get_plugin_vtable\0";
446
447pub fn plugin_library_filename(id: &str) -> String {
450 if cfg!(target_os = "macos") {
451 format!("lib{id}.dylib")
452 } else if cfg!(target_os = "windows") {
453 format!("{id}.dll")
454 } else {
455 format!("lib{id}.so")
456 }
457}