pub struct RenderReplay { /* private fields */ }v4_22 only.Expand description
A facility to replay a RenderNode and its children, potentially
modifying them.
This is a utility tool to walk a rendernode tree. The most powerful way
is to provide a function via set_node_filter()
to filter each individual node and then run
filter_node() on the nodes you want to filter.
If you want to just walk the node tree and extract information
without any modifications, you can also use RenderNode::children().
Here is a little example application that redacts text in a node file:
#include <gtk/gtk.h>
static GskRenderNode *
redact_nodes (GskRenderReplay *replay,
GskRenderNode *node,
gpointer user_data)
{
GskRenderNode *result;
if (gsk_render_node_get_node_type (node) == GSK_TEXT_NODE)
{
graphene_rect_t bounds;
const GdkRGBA *color;
gsk_render_node_get_bounds (node, &bounds);
color = gsk_text_node_get_color (node);
result = gsk_color_node_new (color, &bounds);
}
else
{
result = gsk_render_replay_default (replay, node);
}
return result;
}
int
main (int argc, char *argv[])
{
GFile *file;
GBytes *bytes;
GskRenderNode *result, *node;
GskRenderReplay *replay;
gtk_init ();
if (argc != 3)
{
g_print ("usage: %s INFILE OUTFILE\n", argv[0]);
return 0;
}
file = g_file_new_for_commandline_arg (argv[1]);
bytes = g_file_load_bytes (file, NULL, NULL, NULL);
g_object_unref (file);
if (bytes == NULL)
return 1;
node = gsk_render_node_deserialize (bytes, NULL, NULL);
g_bytes_unref (bytes);
if (node == NULL)
return 1;
replay = gsk_render_replay_new ();
gsk_render_replay_set_node_filter (replay, redact_nodes, NULL, NULL);
result = gsk_render_replay_filter_node (replay, node);
gsk_render_replay_free (replay);
if (!gsk_render_node_write_to_file (result, argv[2], NULL))
return 1;
gsk_render_node_unref (result);
gsk_render_node_unref (node);
return 0;
}GLib type: Boxed type with copy-on-clone semantics.
Implementations§
Source§impl RenderReplay
impl RenderReplay
Sourcepub fn as_ptr(&self) -> *mut GskRenderReplay
pub fn as_ptr(&self) -> *mut GskRenderReplay
Return the inner pointer to the underlying C value.
Sourcepub unsafe fn from_glib_ptr_borrow(ptr: &*mut GskRenderReplay) -> &Self
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GskRenderReplay) -> &Self
Borrows the underlying C value.
Sourcepub unsafe fn from_glib_ptr_borrow_mut(
ptr: &mut *mut GskRenderReplay,
) -> &mut Self
pub unsafe fn from_glib_ptr_borrow_mut( ptr: &mut *mut GskRenderReplay, ) -> &mut Self
Borrows the underlying C value mutably.
Source§impl RenderReplay
impl RenderReplay
Sourcepub fn new() -> RenderReplay
pub fn new() -> RenderReplay
Sourcepub fn default(&mut self, node: impl AsRef<RenderNode>) -> Option<RenderNode>
pub fn default(&mut self, node: impl AsRef<RenderNode>) -> Option<RenderNode>
Replays the node using the default method.
The default method calls filter_node()
on all its child nodes and the filter functions for all its
properties. If none of them are changed, it returns the passed
in node. Otherwise it constructs a new node with the changed
children and properties.
It may not be possible to construct a new node when any of the callbacks return NULL. In that case, this function will return NULL, too.
§node
the node to replay
§Returns
The replayed node
Sourcepub fn filter_font(&mut self, font: &impl IsA<Font>) -> Font
pub fn filter_font(&mut self, font: &impl IsA<Font>) -> Font
Sourcepub fn filter_node(
&mut self,
node: impl AsRef<RenderNode>,
) -> Option<RenderNode>
pub fn filter_node( &mut self, node: impl AsRef<RenderNode>, ) -> Option<RenderNode>
Sourcepub fn filter_texture(&mut self, texture: &impl IsA<Texture>) -> Texture
pub fn filter_texture(&mut self, texture: &impl IsA<Texture>) -> Texture
Sourcepub fn set_font_filter(
&mut self,
filter: Option<Box_<dyn Fn(&RenderReplay, &Font) -> Font + 'static>>,
)
pub fn set_font_filter( &mut self, filter: Option<Box_<dyn Fn(&RenderReplay, &Font) -> Font + 'static>>, )
Sourcepub fn set_node_filter(
&mut self,
filter: Option<Box_<dyn Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static>>,
)
pub fn set_node_filter( &mut self, filter: Option<Box_<dyn Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static>>, )
Sets the function to use as a node filter.
This is the most complex function to use for replaying nodes. It can either:
-
keep the node and just return it unchanged
-
create a replacement node and return that
-
discard the node by returning
NULL -
call
default()to have the default handler run for this node, which calls your function on its children
§filter
the function to call to replay nodes
Sourcepub fn set_texture_filter(
&mut self,
filter: Option<Box_<dyn Fn(&RenderReplay, &Texture) -> Texture + 'static>>,
)
pub fn set_texture_filter( &mut self, filter: Option<Box_<dyn Fn(&RenderReplay, &Texture) -> Texture + 'static>>, )
Trait Implementations§
Source§impl Clone for RenderReplay
impl Clone for RenderReplay
Source§impl Debug for RenderReplay
impl Debug for RenderReplay
Source§impl Default for RenderReplay
impl Default for RenderReplay
impl Eq for RenderReplay
Source§impl From<RenderReplay> for Value
impl From<RenderReplay> for Value
Source§fn from(o: RenderReplay) -> Self
fn from(o: RenderReplay) -> Self
Source§impl HasParamSpec for RenderReplay
impl HasParamSpec for RenderReplay
type ParamSpec = ParamSpecBoxed
Source§type SetValue = RenderReplay
type SetValue = RenderReplay
type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<'_, RenderReplay>
fn param_spec_builder() -> Self::BuilderFn
Source§impl Hash for RenderReplay
impl Hash for RenderReplay
Source§impl Ord for RenderReplay
impl Ord for RenderReplay
Source§fn cmp(&self, other: &RenderReplay) -> Ordering
fn cmp(&self, other: &RenderReplay) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for RenderReplay
impl PartialEq for RenderReplay
Source§fn eq(&self, other: &RenderReplay) -> bool
fn eq(&self, other: &RenderReplay) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for RenderReplay
impl PartialOrd for RenderReplay
Source§impl StaticType for RenderReplay
impl StaticType for RenderReplay
Source§fn static_type() -> Type
fn static_type() -> Type
Self.