pub trait RenderingContext {
// Required methods
fn read_to_image(
&self,
source_rectangle: DeviceIntRect,
) -> Option<RgbaImage>;
fn size(&self) -> PhysicalSize<u32>;
fn resize(&self, size: PhysicalSize<u32>);
fn present(&self);
fn make_current(&self) -> Result<(), Error>;
fn gleam_gl_api(&self) -> Rc<dyn Gl>;
fn glow_gl_api(&self) -> Arc<Context>;
// Provided methods
fn prepare_for_rendering(&self) { ... }
fn size2d(&self) -> Size2D<u32, DevicePixel> { ... }
fn create_texture(
&self,
_surface: Surface,
) -> Option<(SurfaceTexture, u32, UntypedSize2D<i32>)> { ... }
fn destroy_texture(
&self,
_surface_texture: SurfaceTexture,
) -> Option<Surface> { ... }
fn connection(&self) -> Option<Connection> { ... }
}
Expand description
The RenderingContext
trait defines a set of methods for managing
an OpenGL or GLES rendering context.
Implementors of this trait are responsible for handling the creation,
management, and destruction of the rendering context and its associated
resources.
Required Methods§
Sourcefn read_to_image(&self, source_rectangle: DeviceIntRect) -> Option<RgbaImage>
fn read_to_image(&self, source_rectangle: DeviceIntRect) -> Option<RgbaImage>
Read the contents of this [Renderingcontext
] into an in-memory image. If the
image cannot be read (for instance, if no rendering has taken place yet), then
None
is returned.
In a double-buffered RenderingContext
this is expected to read from the back
buffer. That means that once Servo renders to the context, this should return those
results, even before RenderingContext::present
is called.
Sourcefn size(&self) -> PhysicalSize<u32>
fn size(&self) -> PhysicalSize<u32>
Get the current size of this RenderingContext
.
Sourcefn resize(&self, size: PhysicalSize<u32>)
fn resize(&self, size: PhysicalSize<u32>)
Resizes the rendering surface to the given size.
Sourcefn present(&self)
fn present(&self)
Presents the rendered frame to the screen. In a double-buffered context, this would swap buffers.
Sourcefn make_current(&self) -> Result<(), Error>
fn make_current(&self) -> Result<(), Error>
Makes the context the current OpenGL context for this thread. After calling this function, it is valid to use OpenGL rendering commands.
Sourcefn gleam_gl_api(&self) -> Rc<dyn Gl>
fn gleam_gl_api(&self) -> Rc<dyn Gl>
Returns the gleam
version of the OpenGL or GLES API.
Sourcefn glow_gl_api(&self) -> Arc<Context>
fn glow_gl_api(&self) -> Arc<Context>
Returns the OpenGL or GLES API.
Provided Methods§
Sourcefn prepare_for_rendering(&self)
fn prepare_for_rendering(&self)
Prepare this RenderingContext
to be rendered upon by Servo. For instance,
by binding a framebuffer to the current OpenGL context.
Sourcefn size2d(&self) -> Size2D<u32, DevicePixel>
fn size2d(&self) -> Size2D<u32, DevicePixel>
Get the current size of this RenderingContext
as Size2D
.
Sourcefn create_texture(
&self,
_surface: Surface,
) -> Option<(SurfaceTexture, u32, UntypedSize2D<i32>)>
fn create_texture( &self, _surface: Surface, ) -> Option<(SurfaceTexture, u32, UntypedSize2D<i32>)>
Creates a texture from a given surface and returns the surface texture,
the OpenGL texture object, and the size of the surface. Default to None
.
Sourcefn destroy_texture(&self, _surface_texture: SurfaceTexture) -> Option<Surface>
fn destroy_texture(&self, _surface_texture: SurfaceTexture) -> Option<Surface>
Destroys the texture and returns the surface. Default to None
.
Sourcefn connection(&self) -> Option<Connection>
fn connection(&self) -> Option<Connection>
The connection to the display server for WebGL. Default to None
.