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 try_build_glyph_run_geometry(&self, _glyph_run: &crate::media::GlyphRun) -> Option<Arc<dyn IGeometryImpl>> {
58 None
59 }
60
61 fn create_glyph_run(
68 &self,
69 glyph_typeface: &Rc<crate::media::GlyphTypeface>,
70 font_rendering_em_size: f64,
71 glyph_infos: &[crate::media::text_formatting::GlyphInfo],
72 baseline_origin: Point,
73 ) -> std::sync::Arc<dyn super::IGlyphRunImpl>;
74
75 fn create_render_target_bitmap(&self, size: PixelSize, dpi: Vector) -> std::sync::Arc<dyn IRenderTargetBitmapImpl>;
79
80 fn create_writeable_bitmap(
82 &self,
83 size: PixelSize,
84 dpi: Vector,
85 format: PixelFormat,
86 alpha_format: AlphaFormat,
87 ) -> std::sync::Arc<dyn IWriteableBitmapImpl>;
88
89 fn load_bitmap_from_file(&self, file_name: &str) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
91
92 fn load_bitmap(&self, stream: &mut dyn Read) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
94
95 fn load_writeable_bitmap_to_width(
97 &self,
98 stream: &mut dyn Read,
99 width: i32,
100 interpolation_mode: BitmapInterpolationMode,
101 ) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
102
103 fn load_writeable_bitmap_to_height(
105 &self,
106 stream: &mut dyn Read,
107 height: i32,
108 interpolation_mode: BitmapInterpolationMode,
109 ) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
110
111 fn load_writeable_bitmap_from_file(&self, file_name: &str) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
113
114 fn load_writeable_bitmap(&self, stream: &mut dyn Read) -> std::io::Result<std::sync::Arc<dyn IWriteableBitmapImpl>>;
116
117 fn load_bitmap_to_width(
119 &self,
120 stream: &mut dyn Read,
121 width: i32,
122 interpolation_mode: BitmapInterpolationMode,
123 ) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
124
125 fn load_bitmap_to_height(
127 &self,
128 stream: &mut dyn Read,
129 height: i32,
130 interpolation_mode: BitmapInterpolationMode,
131 ) -> std::io::Result<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
132
133 fn resize_bitmap(
135 &self,
136 bitmap_impl: &dyn IBitmapImpl,
137 destination_size: PixelSize,
138 interpolation_mode: BitmapInterpolationMode,
139 ) -> std::sync::Arc<crate::platform::SharedBitmapImpl>;
140
141 fn load_bitmap_from_pixels(
145 &self,
146 format: PixelFormat,
147 alpha_format: AlphaFormat,
148 data: &[u8],
149 size: PixelSize,
150 dpi: Vector,
151 stride: i32,
152 ) -> std::sync::Arc<crate::platform::SharedBitmapImpl>;
153
154 fn create_backend_context(
157 &self,
158 graphics_api_context: Option<Rc<dyn IPlatformGraphicsContext>>,
159 ) -> Rc<dyn IPlatformRenderInterfaceContext>;
160
161 fn supports_individual_round_rects(&self) -> bool;
164
165 fn supports_compositing_layers(&self) -> bool {
169 false
170 }
171
172 fn default_alpha_format(&self) -> AlphaFormat;
174
175 fn default_pixel_format(&self) -> PixelFormat;
177
178 fn is_supported_bitmap_pixel_format(&self, format: PixelFormat) -> bool;
180
181 fn supports_regions(&self) -> bool;
183
184 fn create_region(&self) -> Rc<dyn IPlatformRenderInterfaceRegion>;
186}
187
188pub trait IPlatformRenderInterfaceContext: IOptionalFeatureProvider {
190 fn create_render_target(&self, surfaces: &[std::sync::Arc<dyn IPlatformRenderSurface>]) -> Rc<dyn IRenderTarget>;
192
193 fn create_offscreen_render_target(
195 &self,
196 pixel_size: PixelSize,
197 scaling: Vector,
198 enable_text_antialiasing: bool,
199 ) -> Rc<dyn IDrawingContextLayerImpl>;
200
201 fn is_lost(&self) -> bool;
203
204 fn max_offscreen_render_target_pixel_size(&self) -> Option<PixelSize>;
207
208 fn public_features(&self) -> std::collections::HashMap<std::any::TypeId, Rc<dyn std::any::Any>> {
210 std::collections::HashMap::new()
211 }
212
213 fn is_ready_to_create_render_target(&self, _surfaces: &[std::sync::Arc<dyn IPlatformRenderSurface>]) -> bool {
215 true
216 }
217
218 fn dispose(&self);
220}