gsk: Add private color node api
Add a constructor that takes a color state, a getter for it, and also a getter for the color coordinates that avoids GdkRGBA.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include "gdk/gdktextureprivate.h"
|
||||
#include "gdk/gdktexturedownloaderprivate.h"
|
||||
#include "gdk/gdkrgbaprivate.h"
|
||||
#include "gdk/gdkcolorstateprivate.h"
|
||||
|
||||
#include <cairo.h>
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
@@ -172,10 +173,20 @@ region_union_region_affine (cairo_region_t *region,
|
||||
struct _GskColorNode
|
||||
{
|
||||
GskRenderNode render_node;
|
||||
|
||||
GdkRGBA color;
|
||||
GdkColor color;
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_color_node_finalize (GskRenderNode *node)
|
||||
{
|
||||
GskColorNode *self = (GskColorNode *) node;
|
||||
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_COLOR_NODE));
|
||||
|
||||
gdk_color_finish (&self->color);
|
||||
|
||||
parent_class->finalize (node);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_color_node_draw (GskRenderNode *node,
|
||||
cairo_t *cr,
|
||||
@@ -183,8 +194,7 @@ gsk_color_node_draw (GskRenderNode *node,
|
||||
{
|
||||
GskColorNode *self = (GskColorNode *) node;
|
||||
|
||||
gdk_cairo_set_source_rgba_ccs (cr, ccs, &self->color);
|
||||
|
||||
gdk_cairo_set_source_color (cr, ccs, &self->color);
|
||||
gdk_cairo_rect (cr, &node->bounds);
|
||||
cairo_fill (cr);
|
||||
}
|
||||
@@ -198,7 +208,7 @@ gsk_color_node_diff (GskRenderNode *node1,
|
||||
GskColorNode *self2 = (GskColorNode *) node2;
|
||||
|
||||
if (gsk_rect_equal (&node1->bounds, &node2->bounds) &&
|
||||
gdk_rgba_equal (&self1->color, &self2->color))
|
||||
gdk_color_equal (&self1->color, &self2->color))
|
||||
return;
|
||||
|
||||
gsk_render_node_diff_impossible (node1, node2, data);
|
||||
@@ -212,6 +222,7 @@ gsk_color_node_class_init (gpointer g_class,
|
||||
|
||||
node_class->node_type = GSK_COLOR_NODE;
|
||||
|
||||
node_class->finalize = gsk_color_node_finalize;
|
||||
node_class->draw = gsk_color_node_draw;
|
||||
node_class->diff = gsk_color_node_diff;
|
||||
}
|
||||
@@ -222,6 +233,9 @@ gsk_color_node_class_init (gpointer g_class,
|
||||
*
|
||||
* Retrieves the color of the given @node.
|
||||
*
|
||||
* The value returned by this function will not be correct
|
||||
* if the render node was created for a non-sRGB color.
|
||||
*
|
||||
* Returns: (transfer none): the color of the node
|
||||
*/
|
||||
const GdkRGBA *
|
||||
@@ -231,6 +245,25 @@ gsk_color_node_get_color (const GskRenderNode *node)
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_COLOR_NODE), NULL);
|
||||
|
||||
/* NOTE: This is only correct for nodes with sRGB colors */
|
||||
return (const GdkRGBA *) &self->color.values;
|
||||
}
|
||||
|
||||
/*< private >
|
||||
* gsk_color_node_get_color2:
|
||||
* @node: (type GskColorNode): a `GskRenderNode`
|
||||
*
|
||||
* Retrieves the color of the given @node.
|
||||
*
|
||||
* Returns: (transfer none): the color of the node
|
||||
*/
|
||||
const GdkColor *
|
||||
gsk_color_node_get_color2 (const GskRenderNode *node)
|
||||
{
|
||||
GskColorNode *self = (GskColorNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_COLOR_NODE), NULL);
|
||||
|
||||
return &self->color;
|
||||
}
|
||||
|
||||
@@ -247,20 +280,45 @@ gsk_color_node_get_color (const GskRenderNode *node)
|
||||
GskRenderNode *
|
||||
gsk_color_node_new (const GdkRGBA *rgba,
|
||||
const graphene_rect_t *bounds)
|
||||
{
|
||||
GdkColor color;
|
||||
GskRenderNode *node;
|
||||
|
||||
gdk_color_init_from_rgba (&color, rgba);
|
||||
node = gsk_color_node_new2 (&color, bounds);
|
||||
gdk_color_finish (&color);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/*< private >
|
||||
* gsk_color_node_new2:
|
||||
* @color: a `GdkColor` specifying a color
|
||||
* @bounds: the rectangle to render the color into
|
||||
*
|
||||
* Creates a `GskRenderNode` that will render the color specified by @color
|
||||
* into the area given by @bounds.
|
||||
*
|
||||
* Returns: (transfer full) (type GskColorNode): A new `GskRenderNode`
|
||||
*/
|
||||
GskRenderNode *
|
||||
gsk_color_node_new2 (const GdkColor *color,
|
||||
const graphene_rect_t *bounds)
|
||||
{
|
||||
GskColorNode *self;
|
||||
GskRenderNode *node;
|
||||
|
||||
g_return_val_if_fail (rgba != NULL, NULL);
|
||||
g_return_val_if_fail (color != NULL, NULL);
|
||||
g_return_val_if_fail (bounds != NULL, NULL);
|
||||
|
||||
self = gsk_render_node_alloc (GSK_COLOR_NODE);
|
||||
node = (GskRenderNode *) self;
|
||||
node->offscreen_for_opacity = FALSE;
|
||||
node->fully_opaque = gdk_rgba_is_opaque (rgba);
|
||||
node->preferred_depth = my_color_get_depth (rgba);
|
||||
node->fully_opaque = gdk_color_is_opaque (color);
|
||||
node->preferred_depth = gdk_color_get_depth (color);
|
||||
|
||||
gdk_color_init_copy (&self->color, color);
|
||||
|
||||
self->color = *rgba;
|
||||
gsk_rect_init_from_rect (&node->bounds, bounds);
|
||||
gsk_rect_normalize (&node->bounds);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cairo.h>
|
||||
|
||||
#include "gdk/gdkmemoryformatprivate.h"
|
||||
#include "gdk/gdkcolorprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -120,5 +121,10 @@ _gsk_render_node_ref (GskRenderNode *node)
|
||||
return node;
|
||||
}
|
||||
|
||||
GskRenderNode * gsk_color_node_new2 (const GdkColor *color,
|
||||
const graphene_rect_t *bounds);
|
||||
|
||||
const GdkColor* gsk_color_node_get_color2 (const GskRenderNode *node);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user