ferroui_base/platform/
i_platform_render_interface.rs1use super::surfaces::IPlatformRenderSurface;
2use super::{
3 AlphaFormat, IBitmapImpl, IDrawingContextLayerImpl, IGeometryImpl, IOptionalFeatureProvider,
4 IPlatformGraphicsContext, IPlatformRenderInterfaceRegion, IRenderTarget, IRenderTargetBitmapImpl,
5 IStreamGeometryBuilder, IWriteableBitmapImpl, PixelFormat,
6};
7use crate::media::imaging::BitmapInterpolationMode;
8use crate::media::{FillRule, GeometryCombineMode};
9use crate::{PixelSize, Point, Rect, Vector};
10use std::io::Read;
11use std::rc::Rc;
12use std::sync::Arc;
13
14pub trait IPlatformRenderInterface: 'static {
20 fn create_ellipse_geometry(&self, rect: Rect) -> Arc<dyn IGeometryImpl>;
22
23 fn create_line_geometry(&self, p1: Point, p2: Point) -> Arc<dyn IGeometryImpl>;
25
26 fn create_rectangle_geometry(&self, rect: Rect) -> Arc<dyn IGeometryImpl>;
28
29 fn create_stream_geometry_builder(&self, source: Option<&dyn IGeometryImpl>) -> Box<dyn IStreamGeometryBuilder>;
35
36 fn create_geometry_group(&self, fill_rule: FillRule, children: &[Arc<dyn IGeometryImpl>]) -> Arc<dyn IGeometryImpl>;
38
39 fn create_combined_geometry(
41 &self,
42 combine_mode: GeometryCombineMode,
43 g1: Arc<dyn IGeometryImpl>,
44 g2: Arc<dyn IGeometryImpl>,
45 ) -> Arc<dyn IGeometryImpl>;
46
47 fn build_glyph_run_geometry(&self, glyph_run: &crate::media::GlyphRun) -> Arc<dyn IGeometryImpl>;
49
50 fn create_glyph_run(
57 &self,
58 glyph_typeface: &Rc<crate::media::GlyphTypeface>,
59 font_rendering_em_size: f64,
60 glyph_infos: &[crate::media::text_formatting::GlyphInfo],
61 baseline_origin: Point,
62 ) -> std::sync::Arc<dyn super::IGlyphRunImpl>;
63
64 fn create_render_target_bitmap(&self, size: PixelSize, dpi: Vector) -> std::sync::Arc<dyn IRenderTargetBitmapImpl>;
68
69 fn create_writeable_bitmap(
71 &self,
72 size: PixelSize,
73 dpi: Vector,
74 format: PixelFormat,
75 alpha_format: AlphaFormat,
76 ) -> std::sync::Arc<dyn IWriteableBitmapImpl>;
77
78 fn load_bitmap_from_file(&self, file_name: &str) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
80
81 fn load_bitmap(&self, stream: &mut dyn Read) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
83
84 fn load_writeable_bitmap_to_width(
86 &self,
87 stream: &mut dyn Read,
88 width: i32,
89 interpolation_mode: BitmapInterpolationMode,
90 ) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
91
92 fn load_writeable_bitmap_to_height(
94 &self,
95 stream: &mut dyn Read,
96 height: i32,
97 interpolation_mode: BitmapInterpolationMode,
98 ) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
99
100 fn load_writeable_bitmap_from_file(&self, file_name: &str) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
102
103 fn load_writeable_bitmap(&self, stream: &mut dyn Read) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
105
106 fn load_bitmap_to_width(
108 &self,
109 stream: &mut dyn Read,
110 width: i32,
111 interpolation_mode: BitmapInterpolationMode,
112 ) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
113
114 fn load_bitmap_to_height(
116 &self,
117 stream: &mut dyn Read,
118 height: i32,
119 interpolation_mode: BitmapInterpolationMode,
120 ) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
121
122 fn resize_bitmap(
124 &self,
125 bitmap_impl: &dyn IBitmapImpl,
126 destination_size: PixelSize,
127 interpolation_mode: BitmapInterpolationMode,
128 ) -> std::sync::Arc<crate::platform::SharedBitmapImpl>;
129
130 fn load_bitmap_from_pixels(
134 &self,
135 format: PixelFormat,
136 alpha_format: AlphaFormat,
137 data: &[u8],
138 size: PixelSize,
139 dpi: Vector,
140 stride: i32,
141 ) -> std::sync::Arc<crate::platform::SharedBitmapImpl>;
142
143 fn create_backend_context(
146 &self,
147 graphics_api_context: Option<Rc<dyn IPlatformGraphicsContext>>,
148 ) -> Rc<dyn IPlatformRenderInterfaceContext>;
149
150 fn supports_individual_round_rects(&self) -> bool;
153
154 fn default_alpha_format(&self) -> AlphaFormat;
156
157 fn default_pixel_format(&self) -> PixelFormat;
159
160 fn is_supported_bitmap_pixel_format(&self, format: PixelFormat) -> bool;
162
163 fn supports_regions(&self) -> bool;
165
166 fn create_region(&self) -> Rc<dyn IPlatformRenderInterfaceRegion>;
168}
169
170pub trait IPlatformRenderInterfaceContext: IOptionalFeatureProvider {
172 fn create_render_target(&self, surfaces: &[std::sync::Arc<dyn IPlatformRenderSurface>]) -> Rc<dyn IRenderTarget>;
174
175 fn create_offscreen_render_target(
177 &self,
178 pixel_size: PixelSize,
179 scaling: Vector,
180 enable_text_antialiasing: bool,
181 ) -> Rc<dyn IDrawingContextLayerImpl>;
182
183 fn is_lost(&self) -> bool;
185
186 fn max_offscreen_render_target_pixel_size(&self) -> Option<PixelSize>;
189
190 fn public_features(&self) -> std::collections::HashMap<std::any::TypeId, Rc<dyn std::any::Any>> {
192 std::collections::HashMap::new()
193 }
194
195 fn is_ready_to_create_render_target(&self, _surfaces: &[std::sync::Arc<dyn IPlatformRenderSurface>]) -> bool {
197 true
198 }
199
200 fn dispose(&self);
202}