mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
gsk: Tweak cairo node apis
Rename the surface getter to peek, following other render node getters, and make the surface-based constructor private, since it is not something we want to encourage. Update all callers.
This commit is contained in:
parent
eee89587c3
commit
243bd4f0c8
@ -813,7 +813,7 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
|
||||
|
||||
case GSK_CAIRO_NODE:
|
||||
{
|
||||
cairo_surface_t *surface = gsk_cairo_node_get_surface (node);
|
||||
const cairo_surface_t *surface = gsk_cairo_node_peek_surface (node);
|
||||
int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
|
||||
|
||||
if (surface == NULL)
|
||||
@ -828,7 +828,7 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
|
||||
gsk_gl_driver_bind_source_texture (self->gl_driver, item.render_data.texture_id);
|
||||
gsk_gl_driver_init_texture_with_surface (self->gl_driver,
|
||||
item.render_data.texture_id,
|
||||
surface,
|
||||
(cairo_surface_t *)surface,
|
||||
gl_min_filter,
|
||||
gl_mag_filter);
|
||||
item.mode = MODE_TEXTURE;
|
||||
|
@ -183,13 +183,10 @@ float gsk_outset_shadow_node_get_blur_radius (GskRenderNode
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
GskRenderNode * gsk_cairo_node_new (const graphene_rect_t *bounds);
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
GskRenderNode * gsk_cairo_node_new_for_surface (const graphene_rect_t *bounds,
|
||||
cairo_surface_t *surface);
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
cairo_t * gsk_cairo_node_get_draw_context (GskRenderNode *node,
|
||||
GskRenderer *renderer);
|
||||
GDK_AVAILABLE_IN_3_94
|
||||
cairo_surface_t * gsk_cairo_node_get_surface (GskRenderNode *node);
|
||||
const cairo_surface_t * gsk_cairo_node_peek_surface (GskRenderNode *node);
|
||||
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
GskRenderNode * gsk_container_node_new (GskRenderNode **children,
|
||||
|
@ -1829,16 +1829,8 @@ static const GskRenderNodeClass GSK_CAIRO_NODE_CLASS = {
|
||||
gsk_cairo_node_deserialize
|
||||
};
|
||||
|
||||
/*< private >
|
||||
* gsk_cairo_node_get_surface:
|
||||
* @node: a #GskRenderNode
|
||||
*
|
||||
* Retrieves the surface set using gsk_render_node_set_surface().
|
||||
*
|
||||
* Returns: (transfer none) (nullable): a Cairo surface
|
||||
*/
|
||||
cairo_surface_t *
|
||||
gsk_cairo_node_get_surface (GskRenderNode *node)
|
||||
const cairo_surface_t *
|
||||
gsk_cairo_node_peek_surface (GskRenderNode *node)
|
||||
{
|
||||
GskCairoNode *self = (GskCairoNode *) node;
|
||||
|
||||
|
@ -48,6 +48,9 @@ GskRenderNode * gsk_render_node_deserialize_node (GskRenderNodeType typ
|
||||
GVariant *variant,
|
||||
GError **error);
|
||||
|
||||
GskRenderNode * gsk_cairo_node_new_for_surface (const graphene_rect_t *bounds,
|
||||
cairo_surface_t *surface);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSK_RENDER_NODE_PRIVATE_H__ */
|
||||
|
@ -353,7 +353,7 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
|
||||
return;
|
||||
|
||||
case GSK_CAIRO_NODE:
|
||||
if (gsk_cairo_node_get_surface (node) == NULL)
|
||||
if (gsk_cairo_node_peek_surface (node) == NULL)
|
||||
return;
|
||||
if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_TEXTURE;
|
||||
@ -691,7 +691,7 @@ gsk_vulkan_render_pass_get_node_as_texture (GskVulkanRenderPass *self,
|
||||
case GSK_CAIRO_NODE:
|
||||
if (graphene_rect_equal (bounds, &node->bounds))
|
||||
{
|
||||
surface = cairo_surface_reference (gsk_cairo_node_get_surface (node));
|
||||
surface = cairo_surface_reference ((cairo_surface_t *)gsk_cairo_node_peek_surface (node));
|
||||
goto got_surface;
|
||||
}
|
||||
break;
|
||||
@ -910,7 +910,7 @@ gsk_vulkan_render_pass_upload (GskVulkanRenderPass *self,
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
|
||||
surface = gsk_cairo_node_get_surface (op->render.node);
|
||||
surface = gsk_cairo_node_peek_surface (op->render.node);
|
||||
op->render.source = gsk_vulkan_image_new_from_data (uploader,
|
||||
cairo_image_surface_get_data (surface),
|
||||
cairo_image_surface_get_width (surface),
|
||||
|
@ -322,7 +322,7 @@ populate_render_node_properties (GtkListStore *store,
|
||||
else
|
||||
{
|
||||
text = "Surface";
|
||||
surface = gsk_cairo_node_get_surface (node);
|
||||
surface = (cairo_surface_t *)gsk_cairo_node_peek_surface (node);
|
||||
}
|
||||
|
||||
show_inline = cairo_image_surface_get_height (surface) <= 40 &&
|
||||
|
@ -430,10 +430,7 @@ cairo_node (guint n)
|
||||
{
|
||||
GskRenderNode **nodes = g_newa (GskRenderNode *, n);
|
||||
GskRenderNode *container;
|
||||
cairo_surface_t *surface;
|
||||
graphene_rect_t bounds;
|
||||
gint offset = 0, height, width, stride;
|
||||
guchar *buf;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
@ -442,25 +439,7 @@ cairo_node (guint n)
|
||||
bounds.origin.x = g_random_int_range (0, 1000 - bounds.size.width);
|
||||
bounds.size.height = g_random_int_range (20, 100);
|
||||
bounds.origin.y = g_random_int_range (0, 1000 - bounds.size.height);
|
||||
|
||||
height = g_random_int_range (1, 100);
|
||||
width = g_random_int_range (1, 100);
|
||||
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width + offset);
|
||||
|
||||
buf = g_malloc (stride * height);
|
||||
|
||||
if (i % 3 == 0)
|
||||
surface = NULL;
|
||||
else
|
||||
surface = cairo_image_surface_create_for_data (buf, CAIRO_FORMAT_ARGB32, width, height, stride);
|
||||
|
||||
nodes[i] = gsk_cairo_node_new_for_surface (&bounds, surface);
|
||||
|
||||
/* Offset in stride helps to test when image is not 'tightly packed' condition */
|
||||
offset = offset ? 0 : 3;
|
||||
|
||||
cairo_surface_destroy (surface);
|
||||
g_free (buf);
|
||||
nodes [i] = gsk_cairo_node_new (&bounds);
|
||||
}
|
||||
|
||||
container = gsk_container_node_new (nodes, n);
|
||||
|
@ -255,17 +255,18 @@ static GskRenderNode *
|
||||
ducky (void)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_surface_t *surface;
|
||||
GskRenderNode *node;
|
||||
cairo_t *cr;
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_file_at_size ("ducky.png", 100, 100, NULL);
|
||||
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
|
||||
node = gsk_cairo_node_new_for_surface (&GRAPHENE_RECT_INIT (0, 0,
|
||||
cairo_image_surface_get_width (surface),
|
||||
cairo_image_surface_get_height (surface)),
|
||||
surface);
|
||||
node = gsk_cairo_node_new (&GRAPHENE_RECT_INIT (0, 0,
|
||||
gdk_pixbuf_get_width (pixbuf),
|
||||
gdk_pixbuf_get_height (pixbuf)));
|
||||
cr = gsk_cairo_node_get_draw_context (node, NULL);
|
||||
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
|
||||
cairo_paint (cr);
|
||||
cairo_destroy (cr);
|
||||
g_object_unref (pixbuf);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user