[gtk+/wip/alexl/broadway4: 78/96] broadway: Add color nodes
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/alexl/broadway4: 78/96] broadway: Add color nodes
- Date: Thu, 23 Nov 2017 09:52:49 +0000 (UTC)
commit 0b38ab339ed35a86cf1c6b563e59d4531b8251cb
Author: Alexander Larsson <alexl redhat com>
Date: Tue Nov 21 21:56:06 2017 +0100
broadway: Add color nodes
gdk/broadway/broadway-protocol.h | 1 +
gdk/broadway/broadway.js | 25 +++++++++++++++++++++++++
gdk/broadway/broadwayd.c | 3 +++
gsk/gskbroadwayrenderer.c | 38 ++++++++++++++++++++++++++++++++++----
4 files changed, 63 insertions(+), 4 deletions(-)
---
diff --git a/gdk/broadway/broadway-protocol.h b/gdk/broadway/broadway-protocol.h
index 3266330..57b3110 100644
--- a/gdk/broadway/broadway-protocol.h
+++ b/gdk/broadway/broadway-protocol.h
@@ -11,6 +11,7 @@ typedef struct {
typedef enum { /* Sync changes with broadway.js */
BROADWAY_NODE_TEXTURE,
BROADWAY_NODE_CONTAINER,
+ BROADWAY_NODE_COLOR,
} BroadwayNodeType;
typedef enum {
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 32406b0..eeb4bc7 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -347,6 +347,31 @@ SwapNodes.prototype.handle_node = function(parent, node_data, data_pos)
data_pos = this.handle_node(parent, node_data, data_pos);
}
break;
+
+ case 2: // COLOR
+ var x = node_data[data_pos++];
+ var y = node_data[data_pos++];
+ var width = node_data[data_pos++];
+ var height = node_data[data_pos++];
+ var rgba = node_data[data_pos++];
+ var div = document.createElement('div');
+ div.style["position"] = "absolute";
+ div.style["left"] = x + "px";
+ div.style["top"] = y + "px";
+ div.style["width"] = width + "px";
+ div.style["height"] = height + "px";
+ a = (rgba >> 24) & 0xff;
+ r = (rgba >> 16) & 0xff;
+ g = (rgba >> 8) & 0xff;
+ b = (rgba >> 0) & 0xff;
+ if (a == 0)
+ c = "rgb(" + r + "," + g + "," + b + ")";
+ else
+ c = "rgba(" + r + "," + g + "," + b + "," + (a / 255.0) + ")";
+ div.style["background-color"] = c;
+ parent.appendChild(div);
+ break;
+
default:
alert("Unexpected node type " + type);
}
diff --git a/gdk/broadway/broadwayd.c b/gdk/broadway/broadwayd.c
index ebb0055..55a23b3 100644
--- a/gdk/broadway/broadwayd.c
+++ b/gdk/broadway/broadwayd.c
@@ -226,6 +226,9 @@ rewrite_node_textures (BroadwayClient *client,
type = data[pos++];
switch (type) {
+ case BROADWAY_NODE_COLOR:
+ pos += 5;
+ break;
case BROADWAY_NODE_TEXTURE:
data[pos+4] = GPOINTER_TO_INT (g_hash_table_lookup (client->textures,
GINT_TO_POINTER (data[pos+4])));
diff --git a/gsk/gskbroadwayrenderer.c b/gsk/gskbroadwayrenderer.c
index fcc8583..f22f404 100644
--- a/gsk/gskbroadwayrenderer.c
+++ b/gsk/gskbroadwayrenderer.c
@@ -89,6 +89,24 @@ add_uint32 (GArray *nodes, guint32 v)
g_array_append_val (nodes, v);
}
+static guint32
+rgba_to_uint32 (const GdkRGBA *rgba)
+{
+ return
+ ((guint32)(0.5 + CLAMP (rgba->alpha, 0., 1.) * 255.) << 24) |
+ ((guint32)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.) << 16) |
+ ((guint32)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.) << 8) |
+ ((guint32)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.) << 0);
+}
+
+
+static void
+add_rgba (GArray *nodes, const GdkRGBA *rgba)
+{
+ guint32 c = rgba_to_uint32 (rgba);
+ g_array_append_val (nodes, c);
+}
+
static void
gsk_broadway_renderer_add_node (GskRenderer *self,
GArray *nodes,
@@ -96,6 +114,10 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
GskRenderNode *node)
{
GdkDisplay *display = gsk_renderer_get_display (self);
+ int x = floorf (node->bounds.origin.x);
+ int y = floorf (node->bounds.origin.y);
+ int width = ceil (node->bounds.origin.x + node->bounds.size.width) - x;
+ int height = ceil (node->bounds.origin.y + node->bounds.size.height) - y;
switch (gsk_render_node_get_node_type (node))
{
@@ -115,12 +137,20 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
}
return;
+ case GSK_COLOR_NODE:
+ {
+
+ add_uint32 (nodes, BROADWAY_NODE_COLOR);
+ add_uint32 (nodes, x);
+ add_uint32 (nodes, y);
+ add_uint32 (nodes, width);
+ add_uint32 (nodes, height);
+ add_rgba (nodes, gsk_color_node_peek_color (node));
+ }
+ return;
+
default:
{
- int x = floorf (node->bounds.origin.x);
- int y = floorf (node->bounds.origin.y);
- int width = ceil (node->bounds.origin.x + node->bounds.size.width) - x;
- int height = ceil (node->bounds.origin.y + node->bounds.size.height) - y;
cairo_surface_t *surface;
GdkTexture *texture;
guint32 texture_id;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]