pub trait GPUBackendImpl {
type Texture: Texture;
Show 24 methods
// Required methods
fn begin_frame(&mut self);
fn limits(&self) -> &DrawPhaseLimits;
fn new_texture(
&mut self,
size: DeviceSize,
format: ColorFormat,
) -> Self::Texture;
fn load_alpha_vertices(&mut self, buffers: &VertexBuffers<()>);
fn draw_alpha_triangles(
&mut self,
indices: &Range<u32>,
texture: &mut Self::Texture,
size_offset: u32,
);
fn draw_alpha_triangles_with_scissor(
&mut self,
indices: &Range<u32>,
texture: &mut Self::Texture,
scissor: DeviceRect,
size_offset: u32,
);
fn load_alpha_size(&mut self, size: DeviceSize) -> u32;
fn load_textures(&mut self, textures: &[&Self::Texture]);
fn load_mask_layers(&mut self, layers: &[MaskLayer]) -> u32;
fn load_color_vertices(&mut self, buffers: &VertexBuffers<ColorAttr>);
fn load_img_data(
&mut self,
primitives: &[ImgPrimitive],
buffers: &VertexBuffers<ImagePrimIndex>,
) -> u32;
fn load_radial_gradient_data(
&mut self,
primitives: &[RadialGradientPrimitive],
stops: &[GradientStopPrimitive],
buffers: &VertexBuffers<RadialGradientPrimIndex>,
) -> (u32, u32);
fn load_linear_gradient_data(
&mut self,
primitives: &[LinearGradientPrimitive],
stops: &[GradientStopPrimitive],
buffers: &VertexBuffers<LinearGradientPrimIndex>,
) -> (u32, u32);
fn load_filter_data(
&mut self,
primitives: &FilterPrimitive,
kernel_matrix: &[f32],
buffers: &VertexBuffers<()>,
) -> u32;
fn draw_color_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
);
fn draw_img_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
);
fn draw_filter_triangles(
&mut self,
texture: &mut Self::Texture,
origin: &Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
);
fn draw_radial_gradient_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
stops_offset: u32,
);
fn draw_linear_gradient_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
stops_offset: u32,
);
fn flush_draw_commands(&mut self);
fn copy_texture_from_texture(
&mut self,
dest_tex: &mut Self::Texture,
copy_to: DevicePoint,
from_tex: &Self::Texture,
from_rect: &DeviceRect,
);
fn load_texture_data(
&mut self,
primitives: &[TexturePrimitive],
buffers: &VertexBuffers<TexturePrimIndex>,
) -> u32;
fn draw_texture_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
from_texture: &Self::Texture,
mask_offset: u32,
prims_offset: u32,
);
fn end_frame(&mut self);
}Expand description
Trait to help implement a gpu backend.
The call graph:
– begin_frame()
+—>–––– Draw Phase –––––––––––––+
| |
| +->- new_texture()––+ |
| +-<—––<——<––+ |
| v
| -> load_alpha_vertices() |
| |
| -> + draw_alpha_triangles_with_scissor()–+ |
| ^ v |
| ^––<———–<———————+ |
| |
| -> + draw_alpha_triangles()—————+ |
| ^ v |
| +––<———–<———————+ |
| |
| -> load_textures() |
| -> load_mask_layers() |
| |
| +–––––––––––––+ |
| | load_color_vertices() | |
| +->| draw_color_triangles() | |
| | +–––––––––––––+ |
| | |
| | +–––––––––––––+ |
| | | load_img_primitives() | |
| +->| load_image_vertices() | |
| | | draw_img_triangles() | |
| | +–––––––––––––+ |
| | |
| -> | +————————————+ |
| | | load_radial_gradient_primitives() | v
| +->| load_radial_gradient_stops() | |
| | | load_radial_gradient_vertices() | |
| | | draw_radial_gradient_triangles() | |
| | +————————————+ |
| | |
| | +————————————+ |
| | | load_linear_gradient_primitives() | |
| +->| load_linear_gradient_stops() | |
| | load_linear_gradient_vertices() | |
| | draw_linear_gradient_triangles() | |
| +————————————+ |
+—<–––––––––––––––––––––––+
-+ ->- end_frame()
The coordinate always start from the left-top to right-bottom. Vertices
use percent as value, and others use pixel value.
Vertices Axis Device axis
0 +––x––+> 1 0 +––x—–+> width
| | | |
y | y |
| | | |
+———+ +–––––+
v v
1 height
Required Associated Types§
Required Methods§
Sourcefn begin_frame(&mut self)
fn begin_frame(&mut self)
A frame start, call once per frame
Sourcefn limits(&self) -> &DrawPhaseLimits
fn limits(&self) -> &DrawPhaseLimits
Returns the limits of the GPU backend.
Sourcefn new_texture(
&mut self,
size: DeviceSize,
format: ColorFormat,
) -> Self::Texture
fn new_texture( &mut self, size: DeviceSize, format: ColorFormat, ) -> Self::Texture
Create a texture.
Sourcefn load_alpha_vertices(&mut self, buffers: &VertexBuffers<()>)
fn load_alpha_vertices(&mut self, buffers: &VertexBuffers<()>)
Load the vertices and indices buffer that draw_alpha_triangles &
draw_alpha_triangles_with_scissor will use.
Sourcefn draw_alpha_triangles(
&mut self,
indices: &Range<u32>,
texture: &mut Self::Texture,
size_offset: u32,
)
fn draw_alpha_triangles( &mut self, indices: &Range<u32>, texture: &mut Self::Texture, size_offset: u32, )
Draw triangles only alpha channel with 1.0. Caller guarantee the texture
format is ColorFormat::Alpha8, caller will try to batch as much as
possible, but also possibly call multi times in a frame.
Sourcefn draw_alpha_triangles_with_scissor(
&mut self,
indices: &Range<u32>,
texture: &mut Self::Texture,
scissor: DeviceRect,
size_offset: u32,
)
fn draw_alpha_triangles_with_scissor( &mut self, indices: &Range<u32>, texture: &mut Self::Texture, scissor: DeviceRect, size_offset: u32, )
Same behavior as draw_alpha_triangles, but the Vertex with a offset and
gives a clip rectangle for the texture, the path should only painting in
the rectangle.
fn load_alpha_size(&mut self, size: DeviceSize) -> u32
Sourcefn load_textures(&mut self, textures: &[&Self::Texture])
fn load_textures(&mut self, textures: &[&Self::Texture])
load textures that will be use in this draw phase
Sourcefn load_mask_layers(&mut self, layers: &[MaskLayer]) -> u32
fn load_mask_layers(&mut self, layers: &[MaskLayer]) -> u32
load the mask layers that the current draw phase will use, called at most once per draw phase.
Sourcefn load_color_vertices(&mut self, buffers: &VertexBuffers<ColorAttr>)
fn load_color_vertices(&mut self, buffers: &VertexBuffers<ColorAttr>)
Load the vertices and indices buffer that draw_color_triangles will
use.
Sourcefn load_img_data(
&mut self,
primitives: &[ImgPrimitive],
buffers: &VertexBuffers<ImagePrimIndex>,
) -> u32
fn load_img_data( &mut self, primitives: &[ImgPrimitive], buffers: &VertexBuffers<ImagePrimIndex>, ) -> u32
Load the vertices and indices buffer that draw_img_triangles will use.
Sourcefn load_radial_gradient_data(
&mut self,
primitives: &[RadialGradientPrimitive],
stops: &[GradientStopPrimitive],
buffers: &VertexBuffers<RadialGradientPrimIndex>,
) -> (u32, u32)
fn load_radial_gradient_data( &mut self, primitives: &[RadialGradientPrimitive], stops: &[GradientStopPrimitive], buffers: &VertexBuffers<RadialGradientPrimIndex>, ) -> (u32, u32)
Load the primitives and gradient color stops that
draw_radial_gradient_triangles will use.
Sourcefn load_linear_gradient_data(
&mut self,
primitives: &[LinearGradientPrimitive],
stops: &[GradientStopPrimitive],
buffers: &VertexBuffers<LinearGradientPrimIndex>,
) -> (u32, u32)
fn load_linear_gradient_data( &mut self, primitives: &[LinearGradientPrimitive], stops: &[GradientStopPrimitive], buffers: &VertexBuffers<LinearGradientPrimIndex>, ) -> (u32, u32)
Load the primitives and gradient color stops that
draw_linear_gradient_triangles will use.
Sourcefn load_filter_data(
&mut self,
primitives: &FilterPrimitive,
kernel_matrix: &[f32],
buffers: &VertexBuffers<()>,
) -> u32
fn load_filter_data( &mut self, primitives: &FilterPrimitive, kernel_matrix: &[f32], buffers: &VertexBuffers<()>, ) -> u32
load the filter
Sourcefn draw_color_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
)
fn draw_color_triangles( &mut self, texture: &mut Self::Texture, indices: Range<u32>, clear: Option<Color>, mask_offset: u32, )
Draw pure color triangles in the texture. And use the clear color clear the texture first if it’s a Some-Value
Sourcefn draw_img_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
)
fn draw_img_triangles( &mut self, texture: &mut Self::Texture, indices: Range<u32>, clear: Option<Color>, mask_offset: u32, prims_offset: u32, )
Draw triangles fill with image. And use the clear color clear the texture first if it’s a Some-Value
fn draw_filter_triangles( &mut self, texture: &mut Self::Texture, origin: &Self::Texture, indices: Range<u32>, clear: Option<Color>, mask_offset: u32, prims_offset: u32, )
Sourcefn draw_radial_gradient_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
stops_offset: u32,
)
fn draw_radial_gradient_triangles( &mut self, texture: &mut Self::Texture, indices: Range<u32>, clear: Option<Color>, mask_offset: u32, prims_offset: u32, stops_offset: u32, )
Draw triangles fill with color radial gradient. And use the clear color clear the texture first if it’s a Some-Value
Sourcefn draw_linear_gradient_triangles(
&mut self,
texture: &mut Self::Texture,
indices: Range<u32>,
clear: Option<Color>,
mask_offset: u32,
prims_offset: u32,
stops_offset: u32,
)
fn draw_linear_gradient_triangles( &mut self, texture: &mut Self::Texture, indices: Range<u32>, clear: Option<Color>, mask_offset: u32, prims_offset: u32, stops_offset: u32, )
Draw triangles fill with color linear gradient. And use the clear color clear the texture first if it’s a Some-Value
Sourcefn flush_draw_commands(&mut self)
fn flush_draw_commands(&mut self)
Flush any pending draw commands to the queue.
fn copy_texture_from_texture( &mut self, dest_tex: &mut Self::Texture, copy_to: DevicePoint, from_tex: &Self::Texture, from_rect: &DeviceRect, )
Sourcefn load_texture_data(
&mut self,
primitives: &[TexturePrimitive],
buffers: &VertexBuffers<TexturePrimIndex>,
) -> u32
fn load_texture_data( &mut self, primitives: &[TexturePrimitive], buffers: &VertexBuffers<TexturePrimIndex>, ) -> u32
Load the primitives and vertices that draw_texture_triangles will use.