RenderReplay

Struct RenderReplay 

Source
pub struct RenderReplay { /* private fields */ }
Available on crate feature 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.

An easier method exists to just walk the node tree and extract information without any modifications. If you want to do that, the functions set_node_foreach() exists. You can also call foreach_node() to run that function. Note that the previously mentioned complex functionality will still be invoked if you have set up a function for it, but its result will not be returned.

Here is an example that combines both approaches to print the whole tree:

⚠️ The following code is in c ⚠️

#include <gtk/gtk.h>

static GskRenderNode *
print_nodes (GskRenderReplay *replay,
             GskRenderNode   *node,
             gpointer         user_data)
{
  int *depth = user_data;
  GskRenderNode *result;

  g_print ("%*s%s\n", 2 * *depth, "", g_type_name_from_instance ((GTypeInstance *) node));

  *depth += 1;
  result = gsk_render_replay_default (replay, node);
  *depth -= 1;

  return result;
}

int
main (int argc, char *argv[])
{
  GFile *file;
  GBytes *bytes;
  GskRenderNode *node;
  GskRenderReplay *replay;
  int depth = 0;

  gtk_init ();

  if (argc < 2)
    {
      g_print ("usage: %s NODEFILE\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, print_nodes, &depth, NULL);
  gsk_render_node_foreach_node (replay, node);
  gsk_render_node_unref (node);

  return 0;
}

GLib type: Boxed type with copy-on-clone semantics.

Implementations§

Source§

impl RenderReplay

Source

pub fn as_ptr(&self) -> *mut GskRenderReplay

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GskRenderReplay) -> &Self

Borrows the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow_mut( ptr: &mut *mut GskRenderReplay, ) -> &mut Self

Borrows the underlying C value mutably.

Source§

impl RenderReplay

Source

pub fn new() -> RenderReplay

Creates a new replay object to replay nodes.

§Returns

A new replay object to replay nodes

Source

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

Source

pub fn filter_font(&mut self, font: &impl IsA<Font>) -> Font

Filters a font using the current filter function.

§font

The font to filter

§Returns

the filtered font

Source

pub fn filter_node( &mut self, node: impl AsRef<RenderNode>, ) -> Option<RenderNode>

Replays a node using the replay’s filter function.

After the replay the node may be unchanged, or it may be removed, which will result in None being returned.

This function calls the registered callback in the following order:

  1. If a foreach function is set, it is called first. If it returns false, this function immediately exits and returns the passed in node.

  2. If a node filter is set, it is called and its result is returned.

  3. default() is called and its result is returned.

§node

the node to replay

§Returns

The replayed node

Source

pub fn filter_texture(&mut self, texture: &impl IsA<Texture>) -> Texture

Filters a texture using the current filter function.

§texture

The texture to filter

§Returns

the filtered texture

Source

pub fn foreach_node(&mut self, node: impl AsRef<RenderNode>)

Calls the filter and foreach functions for each node.

This function calls filter_node() internally, but discards the result assuming no changes were made.

§node

the node to replay

Source

pub fn set_font_filter( &mut self, filter: Option<Box_<dyn Fn(&RenderReplay, &Font) -> Font + 'static>>, )

Sets a filter function to be called by default() for nodes that contain fonts.

You can call GskRenderReplay::filter_font() to filter a font yourself.

§filter

the font filter function

Source

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

Source

pub fn set_node_foreach( &mut self, foreach: Option<Box_<dyn Fn(&RenderReplay, &RenderNode) -> bool + 'static>>, )

Sets the function to call for every node.

This function is called before the node filter, so if it returns false, the node filter will never be called.

§foreach

the function to call for all nodes

Source

pub fn set_texture_filter( &mut self, filter: Option<Box_<dyn Fn(&RenderReplay, &Texture) -> Texture + 'static>>, )

Sets a filter function to be called by default() for nodes that contain textures.

You can call GskRenderReplay::filter_texture() to filter a texture yourself.

§filter

the texture filter function

Trait Implementations§

Source§

impl Clone for RenderReplay

Source§

fn clone(&self) -> Self

Copies the boxed type with the type-specific copy function.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RenderReplay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RenderReplay

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<RenderReplay> for Value

Source§

fn from(o: RenderReplay) -> Self

Converts to this type from the input type.
Source§

impl HasParamSpec for RenderReplay

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = RenderReplay

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<'_, RenderReplay>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for RenderReplay

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for RenderReplay

Source§

fn cmp(&self, other: &RenderReplay) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for RenderReplay

Source§

fn eq(&self, other: &RenderReplay) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RenderReplay

Source§

fn partial_cmp(&self, other: &RenderReplay) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for RenderReplay

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for RenderReplay

Source§

impl StructuralPartialEq for RenderReplay

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GPtrArray, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,