summaryrefslogtreecommitdiff
path: root/gsk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2016-12-13 05:49:57 +0100
committerBenjamin Otte <otte@redhat.com>2016-12-20 18:01:10 +0100
commit07d39299ead9d936c05242d2aab664b7112c3070 (patch)
tree34e395706c1ebc2c9cb665e99d9a86b4d8f58097 /gsk
parent671d43b873770eb70f98050ab2a918a704199063 (diff)
downloadgtk+-07d39299ead9d936c05242d2aab664b7112c3070.tar.gz
gsk: Replace gsk_render_node_set_opacity()
... with gsk_opacity_node_new(). Also implement support for opacity in gtk_widget_snapshot() using this new node.
Diffstat (limited to 'gsk')
-rw-r--r--gsk/gskenums.h4
-rw-r--r--gsk/gskglrenderer.c7
-rw-r--r--gsk/gskrendernode.c40
-rw-r--r--gsk/gskrendernode.h6
-rw-r--r--gsk/gskrendernodeimpl.c127
-rw-r--r--gsk/gskrendernodeprivate.h2
-rw-r--r--gsk/gskvulkanrenderpass.c8
7 files changed, 136 insertions, 58 deletions
diff --git a/gsk/gskenums.h b/gsk/gskenums.h
index 579e3d9c50..caba77f6ab 100644
--- a/gsk/gskenums.h
+++ b/gsk/gskenums.h
@@ -31,6 +31,7 @@
* @GSK_TEXTURE_NODE: A node drawing a #GskTexture
* @GSK_TRANSFORM_NODE: A node that renders its child after applying a
* matrix transform
+ * @GSK_OPACITY_NODE: A node that changes the opacity of its child
*
* The type of a node determines what the node is rendering.
*
@@ -42,7 +43,8 @@ typedef enum {
GSK_CAIRO_NODE,
GSK_COLOR_NODE,
GSK_TEXTURE_NODE,
- GSK_TRANSFORM_NODE
+ GSK_TRANSFORM_NODE,
+ GSK_OPACITY_NODE
} GskRenderNodeType;
/**
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index bb98e2ff42..7812121131 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -592,11 +592,6 @@ project_item (const graphene_matrix_t *projection,
static gboolean
render_node_needs_render_target (GskRenderNode *node)
{
- double opacity = gsk_render_node_get_opacity (node);
-
- if (opacity < 1.0)
- return TRUE;
-
return FALSE;
}
@@ -647,7 +642,7 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
graphene_matrix_multiply (modelview, &self->mvp, &item.mvp);
item.z = project_item (projection, modelview);
- item.opacity = gsk_render_node_get_opacity (node);
+ item.opacity = 1.0;
item.blend_mode = gsk_render_node_get_blend_mode (node);
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index 1a343ae852..ab41235c4d 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -97,8 +97,6 @@ gsk_render_node_new (const GskRenderNodeClass *node_class)
self->ref_count = 1;
- self->opacity = 1.0;
-
self->min_filter = GSK_SCALING_FILTER_NEAREST;
self->mag_filter = GSK_SCALING_FILTER_NEAREST;
@@ -185,44 +183,6 @@ gsk_render_node_get_bounds (GskRenderNode *node,
node->node_class->get_bounds (node, bounds);
}
-/**
- * gsk_render_node_set_opacity:
- * @node: a #GskRenderNode
- * @opacity: the opacity of the node, between 0 (fully transparent) and
- * 1 (fully opaque)
- *
- * Sets the opacity of the @node.
- *
- * Since: 3.90
- */
-void
-gsk_render_node_set_opacity (GskRenderNode *node,
- double opacity)
-{
- g_return_if_fail (GSK_IS_RENDER_NODE (node));
- g_return_if_fail (node->is_mutable);
-
- node->opacity = CLAMP (opacity, 0.0, 1.0);
-}
-
-/**
- * gsk_render_node_get_opacity:
- * @node: a #GskRenderNode
- *
- * Retrieves the opacity set using gsk_render_node_set_opacity().
- *
- * Returns: the opacity of the #GskRenderNode
- *
- * Since: 3.90
- */
-double
-gsk_render_node_get_opacity (GskRenderNode *node)
-{
- g_return_val_if_fail (GSK_IS_RENDER_NODE (node), 0.0);
-
- return node->opacity;
-}
-
void
gsk_render_node_set_scaling_filters (GskRenderNode *node,
GskScalingFilter min_filter,
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index 2119dfb760..3be25035b1 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -74,8 +74,10 @@ GDK_AVAILABLE_IN_3_90
GskRenderNode * gsk_transform_node_get_child (GskRenderNode *node);
GDK_AVAILABLE_IN_3_90
-void gsk_render_node_set_opacity (GskRenderNode *node,
- double opacity);
+GskRenderNode * gsk_opacity_node_new (GskRenderNode *child,
+ double opacity);
+GDK_AVAILABLE_IN_3_90
+GskRenderNode * gsk_opacity_node_get_child (GskRenderNode *node);
GDK_AVAILABLE_IN_3_90
void gsk_render_node_set_blend_mode (GskRenderNode *node,
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index feb7f0891c..764b702df8 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -692,3 +692,130 @@ gsk_transform_node_get_transform (GskRenderNode *node,
graphene_matrix_init_from_matrix (transform, &self->transform);
}
+/*** GSK_OPACITY_NODE ***/
+
+typedef struct _GskOpacityNode GskOpacityNode;
+
+struct _GskOpacityNode
+{
+ GskRenderNode render_node;
+
+ GskRenderNode *child;
+ double opacity;
+};
+
+static void
+gsk_opacity_node_finalize (GskRenderNode *node)
+{
+ GskOpacityNode *self = (GskOpacityNode *) node;
+
+ gsk_render_node_unref (self->child);
+}
+
+static void
+gsk_opacity_node_make_immutable (GskRenderNode *node)
+{
+ GskOpacityNode *self = (GskOpacityNode *) node;
+
+ gsk_render_node_make_immutable (self->child);
+}
+
+static void
+gsk_opacity_node_draw (GskRenderNode *node,
+ cairo_t *cr)
+{
+ GskOpacityNode *self = (GskOpacityNode *) node;
+ graphene_rect_t bounds;
+
+ cairo_save (cr);
+
+ /* clip so the push_group() creates a smaller surface */
+ gsk_render_node_get_bounds (self->child, &bounds);
+ cairo_rectangle (cr, bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
+ cairo_clip (cr);
+
+ cairo_push_group (cr);
+
+ gsk_render_node_draw (self->child, cr);
+
+ cairo_pop_group_to_source (cr);
+ cairo_paint_with_alpha (cr, self->opacity);
+
+ cairo_restore (cr);
+}
+
+static void
+gsk_opacity_node_get_bounds (GskRenderNode *node,
+ graphene_rect_t *bounds)
+{
+ GskOpacityNode *self = (GskOpacityNode *) node;
+
+ gsk_render_node_get_bounds (self->child, bounds);
+}
+
+static const GskRenderNodeClass GSK_OPACITY_NODE_CLASS = {
+ GSK_OPACITY_NODE,
+ sizeof (GskOpacityNode),
+ "GskOpacityNode",
+ gsk_opacity_node_finalize,
+ gsk_opacity_node_make_immutable,
+ gsk_opacity_node_draw,
+ gsk_opacity_node_get_bounds
+};
+
+/**
+ * gsk_opacity_node_new:
+ * @child: The node to draw
+ * @opacity: The opacity to apply
+ *
+ * Creates a #GskRenderNode that will drawn the @child with reduced
+ * @opacity.
+ *
+ * Returns: A new #GskRenderNode
+ *
+ * Since: 3.90
+ */
+GskRenderNode *
+gsk_opacity_node_new (GskRenderNode *child,
+ double opacity)
+{
+ GskOpacityNode *self;
+
+ g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
+
+ self = (GskOpacityNode *) gsk_render_node_new (&GSK_OPACITY_NODE_CLASS);
+
+ self->child = gsk_render_node_ref (child);
+ self->opacity = CLAMP (opacity, 0.0, 1.0);
+
+ return &self->render_node;
+}
+
+/**
+ * gsk_opacity_node_get_child:
+ * @node: a opacity @GskRenderNode
+ *
+ * Gets the child node that is getting opacityed by the given @node.
+ *
+ * Returns: (transfer none): The child that is getting opacityed
+ **/
+GskRenderNode *
+gsk_opacity_node_get_child (GskRenderNode *node)
+{
+ GskOpacityNode *self = (GskOpacityNode *) node;
+
+ g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_OPACITY_NODE), NULL);
+
+ return self->child;
+}
+
+double
+gsk_opacity_node_get_opacity (GskRenderNode *node)
+{
+ GskOpacityNode *self = (GskOpacityNode *) node;
+
+ g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_OPACITY_NODE), 1.0);
+
+ return self->opacity;
+}
+
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index c4e3c48751..3ad5c43658 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -52,7 +52,7 @@ void gsk_render_node_make_immutable (GskRenderNode *node);
void gsk_render_node_get_bounds (GskRenderNode *node,
graphene_rect_t *frame);
-double gsk_render_node_get_opacity (GskRenderNode *node);
+double gsk_opacity_node_get_opacity (GskRenderNode *node);
cairo_surface_t *gsk_cairo_node_get_surface (GskRenderNode *node);
diff --git a/gsk/gskvulkanrenderpass.c b/gsk/gskvulkanrenderpass.c
index 86ac1a198b..9b28951a23 100644
--- a/gsk/gskvulkanrenderpass.c
+++ b/gsk/gskvulkanrenderpass.c
@@ -66,9 +66,6 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
.node = node
};
- if (gsk_render_node_get_opacity (node) < 1.0)
- goto fallback;
-
switch (gsk_render_node_get_node_type (node))
{
case GSK_NOT_A_RENDER_NODE:
@@ -115,11 +112,6 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
break;
}
-
- return;
-
-fallback:
- g_array_append_val (self->render_ops, op);
}
void