drawing_api/common/
context.rs1use std::borrow::Cow;
2
3use crate::{Capabilities, ColorSource, GraphicsApi, ImageFilter, TextureDescriptor};
4
5pub trait Context: Clone + 'static {
9 type ColorSourceFragment: crate::ColorSourceFragment;
10 type DisplayList: crate::DisplayList;
11 type DisplayListBuilder: crate::DisplayListBuilder<
12 DisplayList = Self::DisplayList,
13 ImageFilterFragment = Self::ImageFilterFragment,
14 Paint = Self::Paint,
15 ParagraphBuilder = Self::ParagraphBuilder,
16 PathBuilder = Self::PathBuilder,
17 Texture = Self::Texture,
18 >;
19 type Fonts: crate::Fonts;
20 type FragmentProgram: crate::FragmentProgram;
21 type ImageFilterFragment: crate::ImageFilterFragment;
22 type Paint: crate::Paint<
23 ColorSourceFragment = Self::ColorSourceFragment,
24 ImageFilterFragment = Self::ImageFilterFragment,
25 Texture = Self::Texture,
26 >;
27 type ParagraphBuilder: crate::ParagraphBuilder<
28 Texture = Self::Texture,
29 Paint = Self::Paint,
30 Fonts = Self::Fonts,
31 >;
32 type PathBuilder: crate::PathBuilder;
33 type Surface: crate::Surface<DisplayList = Self::DisplayList>;
34 type Texture: crate::Texture;
35
36 fn get_api_capabilities(api: GraphicsApi) -> Option<Capabilities>;
38
39 fn get_capabilities(&self) -> Capabilities;
41
42 unsafe fn create_texture(
44 &self,
45 contents: Cow<'static, [u8]>,
46 descriptor: TextureDescriptor,
47 ) -> Result<Self::Texture, &'static str>;
48
49 unsafe fn new_color_source_from_fragment_program(
51 &self,
52 frag_program: &Self::FragmentProgram,
53 samplers: &[Self::Texture],
54 uniform_data: &[u8],
55 ) -> ColorSource<Self::Texture, Self::ColorSourceFragment>;
56
57 unsafe fn new_image_filter_from_fragment_program(
59 &self,
60 frag_program: &Self::FragmentProgram,
61 samplers: &[Self::Texture],
62 uniform_data: &[u8],
63 ) -> ImageFilter<Self::ImageFilterFragment>;
64}