Commit 9b1f6acc authored by Alexander Larsson's avatar Alexander Larsson
Browse files

broadway: Add shadow node

parent cbbbf490
......@@ -17,6 +17,7 @@ typedef enum { /* Sync changes with broadway.js */
BROADWAY_NODE_INSET_SHADOW = 5,
BROADWAY_NODE_ROUNDED_CLIP = 6,
BROADWAY_NODE_LINEAR_GRADIENT = 7,
BROADWAY_NODE_SHADOW = 8,
} BroadwayNodeType;
typedef enum {
......
......@@ -592,6 +592,29 @@ SwapNodes.prototype.handle_node = function(parent, offset_x, offset_y)
}
break;
case 8: // SHADOW
{
var len = this.decode_uint32();
var filters = "";
for (var i = 0; i < len; i++) {
var color = this.decode_color();
var dx = this.decode_float();
var dy = this.decode_float();
var blur = this.decode_float();
filters = filters + "drop-shadow(" + args (px(dx), px(dy), px(blur), color) + ")";
}
var div = document.createElement('div');
div.style["position"] = "absolute";
div.style["left"] = px(0);
div.style["top"] = px(0);
div.style["filter"] = filters;
parent.appendChild(div);
this.handle_node(div, offset_x, offset_y);
}
break;
default:
alert("Unexpected node type " + type);
}
......
......@@ -222,13 +222,14 @@ get_client_serial (BroadwayClient *client, guint32 daemon_serial)
#define NODE_SIZE_RECT (NODE_SIZE_POINT + NODE_SIZE_SIZE)
#define NODE_SIZE_RRECT (NODE_SIZE_RECT + 4 * NODE_SIZE_SIZE)
#define NODE_SIZE_COLOR_STOP (NODE_SIZE_FLOAT + NODE_SIZE_COLOR)
#define NODE_SIZE_SHADOW (NODE_SIZE_COLOR + 3 * NODE_SIZE_FLOAT)
static int
rewrite_node_textures (BroadwayClient *client,
int len, guint32 data[], int pos)
{
guint32 type;
guint32 i, n_children, n_stops;
guint32 i, n_children, n_stops, n_shadows;
g_assert (pos < len);
......@@ -242,7 +243,7 @@ rewrite_node_textures (BroadwayClient *client,
break;
case BROADWAY_NODE_INSET_SHADOW:
case BROADWAY_NODE_OUTSET_SHADOW:
pos += NODE_SIZE_RRECT + NODE_SIZE_COLOR + 4 * NODE_SIZE_COLOR;
pos += NODE_SIZE_RRECT + NODE_SIZE_COLOR + 4 * NODE_SIZE_FLOAT;
break;
case BROADWAY_NODE_TEXTURE:
data[pos+4] = GPOINTER_TO_INT (g_hash_table_lookup (client->textures,
......@@ -263,6 +264,11 @@ rewrite_node_textures (BroadwayClient *client,
n_stops = data[pos++];
pos += n_stops * NODE_SIZE_COLOR_STOP;
break;
case BROADWAY_NODE_SHADOW:
n_shadows = data[pos++];
pos += n_shadows * NODE_SIZE_SHADOW;
pos = rewrite_node_textures (client, len, data, pos);
break;
default:
g_assert_not_reached ();
}
......
......@@ -437,32 +437,58 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
}
return;
case GSK_TEXT_NODE:
default:
case GSK_SHADOW_NODE:
{
GdkTexture *texture;
guint32 texture_id;
float off_x = 0, off_y = 0;
texture = node_cache_lookup (node, &off_x, &off_y);
if (!texture)
gsize i, n_shadows = gsk_shadow_node_get_n_shadows (node);
add_uint32 (nodes, BROADWAY_NODE_SHADOW);
add_uint32 (nodes, n_shadows);
for (i = 0; i < n_shadows; i++)
{
texture = node_texture_fallback (node, &off_x, &off_y);
node_cache_store (node, texture, off_x, off_y);
const GskShadow *shadow = gsk_shadow_node_peek_shadow (node, i);
add_rgba (nodes, &shadow->color);
add_float (nodes, shadow->dx);
add_float (nodes, shadow->dy);
add_float (nodes, shadow->radius);
}
g_ptr_array_add (node_textures, texture); /* Transfers ownership to node_textures */
texture_id = gdk_broadway_display_ensure_texture (display, texture);
add_uint32 (nodes, BROADWAY_NODE_TEXTURE);
add_float (nodes, node->bounds.origin.x + off_x);
add_float (nodes, node->bounds.origin.y + off_y);
add_float (nodes, gdk_texture_get_width (texture));
add_float (nodes, gdk_texture_get_height (texture));
add_uint32 (nodes, texture_id);
gsk_broadway_renderer_add_node (self, nodes, node_textures,
gsk_shadow_node_get_child (node));
}
return;
case GSK_TEXT_NODE:
default:
break; /* Fallback */
}
{
GdkTexture *texture;
guint32 texture_id;
float off_x = 0, off_y = 0;
texture = node_cache_lookup (node, &off_x, &off_y);
if (!texture)
{
texture = node_texture_fallback (node, &off_x, &off_y);
g_print ("Fallback %p for %s\n", texture, node->node_class->type_name);
node_cache_store (node, texture, off_x, off_y);
}
else
{
g_print ("Cache hit %p for %s\n", texture,
node->node_class->type_name);
}
g_ptr_array_add (node_textures, texture); /* Transfers ownership to node_textures */
texture_id = gdk_broadway_display_ensure_texture (display, texture);
add_uint32 (nodes, BROADWAY_NODE_TEXTURE);
add_float (nodes, node->bounds.origin.x + off_x);
add_float (nodes, node->bounds.origin.y + off_y);
add_float (nodes, gdk_texture_get_width (texture));
add_float (nodes, gdk_texture_get_height (texture));
add_uint32 (nodes, texture_id);
}
}
static void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment