broadway: Add color nodes

This commit is contained in:
Alexander Larsson 2017-11-21 21:56:06 +01:00
parent cfdb3952c6
commit 0b38ab339e
4 changed files with 63 additions and 4 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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])));

View File

@ -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;