1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{RenderNode, Renderer};
use glib::object::IsA;
use glib::translate::*;
pub trait RendererExtManual: 'static {
/// Renders the scene graph, described by a tree of [`RenderNode`][crate::RenderNode] instances,
/// ensuring that the given `region` gets redrawn.
///
/// Renderers must ensure that changes of the contents given by the `root`
/// node as well as the area given by `region` are redrawn. They are however
/// free to not redraw any pixel outside of `region` if they can guarantee that
/// it didn't change.
///
/// The `self` will acquire a reference on the [`RenderNode`][crate::RenderNode] tree while
/// the rendering is in progress.
/// ## `root`
/// a [`RenderNode`][crate::RenderNode]
/// ## `region`
/// the `cairo_region_t` that must be redrawn or [`None`]
/// for the whole window
#[doc(alias = "gsk_renderer_render")]
fn render<P: AsRef<RenderNode>>(&self, root: &P, region: Option<&cairo::Region>);
/// Renders the scene graph, described by a tree of [`RenderNode`][crate::RenderNode] instances,
/// to a [`gdk::Texture`][crate::gdk::Texture].
///
/// The `self` will acquire a reference on the [`RenderNode`][crate::RenderNode] tree while
/// the rendering is in progress.
///
/// If you want to apply any transformations to `root`, you should put it into a
/// transform node and pass that node instead.
/// ## `root`
/// a [`RenderNode`][crate::RenderNode]
/// ## `viewport`
/// the section to draw or [`None`] to use `root`'s bounds
///
/// # Returns
///
/// a [`gdk::Texture`][crate::gdk::Texture] with the rendered contents of `root`.
#[doc(alias = "gsk_renderer_render_texture")]
fn render_texture<P: AsRef<RenderNode>>(
&self,
root: &P,
viewport: Option<&graphene::Rect>,
) -> Option<gdk::Texture>;
}
impl<O: IsA<Renderer>> RendererExtManual for O {
fn render<P: AsRef<RenderNode>>(&self, root: &P, region: Option<&cairo::Region>) {
unsafe {
ffi::gsk_renderer_render(
self.as_ref().to_glib_none().0,
root.as_ref().to_glib_none().0,
region.to_glib_none().0,
);
}
}
fn render_texture<P: AsRef<RenderNode>>(
&self,
root: &P,
viewport: Option<&graphene::Rect>,
) -> Option<gdk::Texture> {
unsafe {
from_glib_full(ffi::gsk_renderer_render_texture(
self.as_ref().to_glib_none().0,
root.as_ref().to_glib_none().0,
viewport.to_glib_none().0,
))
}
}
}