Compare commits
8 Commits
columnview
...
wip/matthi
Author | SHA1 | Date | |
---|---|---|---|
|
6c94d7f06a | ||
|
168d4415d7 | ||
|
ec46ac920e | ||
|
ce7dd32748 | ||
|
ac6274abac | ||
|
c9eb292362 | ||
|
4b4fbf2ac6 | ||
|
a9eb06392f |
@@ -46,6 +46,7 @@
|
||||
* @GSK_BLEND_NODE: A node that blends two children together
|
||||
* @GSK_CROSS_FADE_NODE: A node that cross-fades between two children
|
||||
* @GSK_TEXT_NODE: A node containing a glyph string
|
||||
* @GSK_BLUR_NODE: A node that applies a blur
|
||||
*
|
||||
* The type of a node determines what the node is rendering.
|
||||
*
|
||||
@@ -71,7 +72,8 @@ typedef enum {
|
||||
GSK_SHADOW_NODE,
|
||||
GSK_BLEND_NODE,
|
||||
GSK_CROSS_FADE_NODE,
|
||||
GSK_TEXT_NODE
|
||||
GSK_TEXT_NODE,
|
||||
GSK_BLUR_NODE
|
||||
} GskRenderNodeType;
|
||||
|
||||
/**
|
||||
|
@@ -183,6 +183,10 @@ GskRenderNode * gsk_text_node_new (PangoFont
|
||||
double base_x,
|
||||
double base_y);
|
||||
|
||||
GDK_AVAILABLE_IN_3_92
|
||||
GskRenderNode * gsk_blur_node_new (GskRenderNode *child,
|
||||
double radius);
|
||||
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
void gsk_render_node_set_scaling_filters (GskRenderNode *node,
|
||||
GskScalingFilter min_filter,
|
||||
|
@@ -4070,6 +4070,288 @@ gsk_text_node_new (PangoFont *font,
|
||||
return &self->render_node;
|
||||
}
|
||||
|
||||
/*** GSK_BLUR_NODE ***/
|
||||
|
||||
typedef struct _GskBlurNode GskBlurNode;
|
||||
|
||||
struct _GskBlurNode
|
||||
{
|
||||
GskRenderNode render_node;
|
||||
|
||||
GskRenderNode *child;
|
||||
double radius;
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_blur_node_finalize (GskRenderNode *node)
|
||||
{
|
||||
GskBlurNode *self = (GskBlurNode *) node;
|
||||
|
||||
gsk_render_node_unref (self->child);
|
||||
}
|
||||
|
||||
static void
|
||||
blur_once (cairo_surface_t *src,
|
||||
cairo_surface_t *dest,
|
||||
int radius,
|
||||
guchar *div_kernel_size)
|
||||
{
|
||||
int width, height, src_rowstride, dest_rowstride, n_channels;
|
||||
guchar *p_src, *p_dest, *c1, *c2;
|
||||
gint x, y, i, i1, i2, width_minus_1, height_minus_1, radius_plus_1;
|
||||
gint r, g, b, a;
|
||||
guchar *p_dest_row, *p_dest_col;
|
||||
|
||||
width = cairo_image_surface_get_width (src);
|
||||
height = cairo_image_surface_get_height (src);
|
||||
n_channels = 4;
|
||||
radius_plus_1 = radius + 1;
|
||||
|
||||
/* horizontal blur */
|
||||
p_src = cairo_image_surface_get_data (src);
|
||||
p_dest = cairo_image_surface_get_data (dest);
|
||||
src_rowstride = cairo_image_surface_get_stride (src);
|
||||
dest_rowstride = cairo_image_surface_get_stride (dest);
|
||||
|
||||
width_minus_1 = width - 1;
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
/* calc the initial sums of the kernel */
|
||||
r = g = b = a = 0;
|
||||
for (i = -radius; i <= radius; i++)
|
||||
{
|
||||
c1 = p_src + (CLAMP (i, 0, width_minus_1) * n_channels);
|
||||
r += c1[0];
|
||||
g += c1[1];
|
||||
b += c1[2];
|
||||
}
|
||||
p_dest_row = p_dest;
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
/* set as the mean of the kernel */
|
||||
p_dest_row[0] = div_kernel_size[r];
|
||||
p_dest_row[1] = div_kernel_size[g];
|
||||
p_dest_row[2] = div_kernel_size[b];
|
||||
p_dest_row += n_channels;
|
||||
|
||||
/* the pixel to add to the kernel */
|
||||
i1 = x + radius_plus_1;
|
||||
if (i1 > width_minus_1)
|
||||
i1 = width_minus_1;
|
||||
c1 = p_src + (i1 * n_channels);
|
||||
|
||||
/* the pixel to remove from the kernel */
|
||||
i2 = x - radius;
|
||||
if (i2 < 0)
|
||||
i2 = 0;
|
||||
c2 = p_src + (i2 * n_channels);
|
||||
|
||||
/* calc the new sums of the kernel */
|
||||
r += c1[0] - c2[0];
|
||||
g += c1[1] - c2[1];
|
||||
b += c1[2] - c2[2];
|
||||
}
|
||||
|
||||
p_src += src_rowstride;
|
||||
p_dest += dest_rowstride;
|
||||
}
|
||||
|
||||
/* vertical blur */
|
||||
p_src = cairo_image_surface_get_data (dest);
|
||||
p_dest = cairo_image_surface_get_data (src);
|
||||
src_rowstride = cairo_image_surface_get_stride (dest);
|
||||
dest_rowstride = cairo_image_surface_get_stride (src);
|
||||
|
||||
height_minus_1 = height - 1;
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
/* calc the initial sums of the kernel */
|
||||
r = g = b = a = 0;
|
||||
for (i = -radius; i <= radius; i++)
|
||||
{
|
||||
c1 = p_src + (CLAMP (i, 0, height_minus_1) * src_rowstride);
|
||||
r += c1[0];
|
||||
g += c1[1];
|
||||
b += c1[2];
|
||||
}
|
||||
|
||||
p_dest_col = p_dest;
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
/* set as the mean of the kernel */
|
||||
|
||||
p_dest_col[0] = div_kernel_size[r];
|
||||
p_dest_col[1] = div_kernel_size[g];
|
||||
p_dest_col[2] = div_kernel_size[b];
|
||||
p_dest_col += dest_rowstride;
|
||||
|
||||
/* the pixel to add to the kernel */
|
||||
i1 = y + radius_plus_1;
|
||||
if (i1 > height_minus_1)
|
||||
i1 = height_minus_1;
|
||||
c1 = p_src + (i1 * src_rowstride);
|
||||
|
||||
/* the pixel to remove from the kernel */
|
||||
i2 = y - radius;
|
||||
if (i2 < 0)
|
||||
i2 = 0;
|
||||
c2 = p_src + (i2 * src_rowstride);
|
||||
/* calc the new sums of the kernel */
|
||||
r += c1[0] - c2[0];
|
||||
g += c1[1] - c2[1];
|
||||
b += c1[2] - c2[2];
|
||||
}
|
||||
|
||||
p_src += n_channels;
|
||||
p_dest += n_channels;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
blur_image_surface (cairo_surface_t *surface, int radius, int iterations)
|
||||
{
|
||||
int kernel_size;
|
||||
int i;
|
||||
guchar *div_kernel_size;
|
||||
cairo_surface_t *tmp;
|
||||
int width, height;
|
||||
|
||||
width = cairo_image_surface_get_width (surface);
|
||||
height = cairo_image_surface_get_height (surface);
|
||||
tmp = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
||||
|
||||
kernel_size = 2 * radius + 1;
|
||||
div_kernel_size = g_new (guchar, 256 * kernel_size);
|
||||
for (i = 0; i < 256 * kernel_size; i++)
|
||||
div_kernel_size[i] = (guchar) (i / kernel_size);
|
||||
|
||||
while (iterations-- > 0)
|
||||
blur_once (surface, tmp, radius, div_kernel_size);
|
||||
|
||||
g_free (div_kernel_size);
|
||||
cairo_surface_destroy (tmp);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_blur_node_draw (GskRenderNode *node,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GskBlurNode *self = (GskBlurNode *) node;
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_surface_t *surface;
|
||||
cairo_surface_t *image_surface;
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
/* clip so the push_group() creates a smaller surface */
|
||||
cairo_rectangle (cr, node->bounds.origin.x, node->bounds.origin.y,
|
||||
node->bounds.size.width, node->bounds.size.height);
|
||||
cairo_clip (cr);
|
||||
|
||||
cairo_push_group (cr);
|
||||
|
||||
gsk_render_node_draw (self->child, cr);
|
||||
|
||||
pattern = cairo_pop_group (cr);
|
||||
cairo_pattern_get_surface (pattern, &surface);
|
||||
image_surface = cairo_surface_map_to_image (surface, NULL);
|
||||
blur_image_surface (image_surface, (int)self->radius, 3);
|
||||
cairo_surface_mark_dirty (surface);
|
||||
cairo_surface_unmap_image (surface, image_surface);
|
||||
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_restore (cr);
|
||||
cairo_pattern_destroy (pattern);
|
||||
}
|
||||
|
||||
#define GSK_BLUR_NODE_VARIANT_TYPE "(duv)"
|
||||
|
||||
static GVariant *
|
||||
gsk_blur_node_serialize (GskRenderNode *node)
|
||||
{
|
||||
GskBlurNode *self = (GskBlurNode *) node;
|
||||
|
||||
return g_variant_new (GSK_BLUR_NODE_VARIANT_TYPE,
|
||||
(double) self->radius,
|
||||
(guint32) gsk_render_node_get_node_type (self->child),
|
||||
gsk_render_node_serialize (self->child));
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gsk_blur_node_deserialize (GVariant *variant,
|
||||
GError **error)
|
||||
{
|
||||
double radius;
|
||||
guint32 child_type;
|
||||
GVariant *child_variant;
|
||||
GskRenderNode *result, *child;
|
||||
|
||||
g_variant_get (variant, GSK_BLUR_NODE_VARIANT_TYPE,
|
||||
&radius, &child_type, &child_variant);
|
||||
|
||||
child = gsk_render_node_deserialize_node (child_type, child_variant, error);
|
||||
g_variant_unref (child_variant);
|
||||
|
||||
if (child == NULL)
|
||||
return NULL;
|
||||
|
||||
result = gsk_blur_node_new (child, radius);
|
||||
|
||||
gsk_render_node_unref (child);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static const GskRenderNodeClass GSK_BLUR_NODE_CLASS = {
|
||||
GSK_BLUR_NODE,
|
||||
sizeof (GskBlurNode),
|
||||
"GskBlurNode",
|
||||
gsk_blur_node_finalize,
|
||||
gsk_blur_node_draw,
|
||||
gsk_blur_node_serialize,
|
||||
gsk_blur_node_deserialize
|
||||
};
|
||||
|
||||
GskRenderNode *
|
||||
gsk_blur_node_new (GskRenderNode *child,
|
||||
double radius)
|
||||
{
|
||||
GskBlurNode *self;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
||||
|
||||
self = (GskBlurNode *) gsk_render_node_new (&GSK_BLUR_NODE_CLASS, 0);
|
||||
|
||||
self->child = gsk_render_node_ref (child);
|
||||
self->radius = radius;
|
||||
|
||||
graphene_rect_init_from_rect (&self->render_node.bounds, &child->bounds);
|
||||
|
||||
return &self->render_node;
|
||||
}
|
||||
|
||||
GskRenderNode *
|
||||
gsk_blur_node_get_child (GskRenderNode *node)
|
||||
{
|
||||
GskBlurNode *self = (GskBlurNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_BLUR_NODE), NULL);
|
||||
|
||||
return self->child;
|
||||
}
|
||||
|
||||
double
|
||||
gsk_blur_node_get_radius (GskRenderNode *node)
|
||||
{
|
||||
GskBlurNode *self = (GskBlurNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_BLUR_NODE), 0.0);
|
||||
|
||||
return self->radius;
|
||||
}
|
||||
|
||||
static const GskRenderNodeClass *klasses[] = {
|
||||
[GSK_CONTAINER_NODE] = &GSK_CONTAINER_NODE_CLASS,
|
||||
[GSK_CAIRO_NODE] = &GSK_CAIRO_NODE_CLASS,
|
||||
@@ -4088,7 +4370,8 @@ static const GskRenderNodeClass *klasses[] = {
|
||||
[GSK_SHADOW_NODE] = &GSK_SHADOW_NODE_CLASS,
|
||||
[GSK_BLEND_NODE] = &GSK_BLEND_NODE_CLASS,
|
||||
[GSK_CROSS_FADE_NODE] = &GSK_CROSS_FADE_NODE_CLASS,
|
||||
[GSK_TEXT_NODE] = &GSK_TEXT_NODE_CLASS
|
||||
[GSK_TEXT_NODE] = &GSK_TEXT_NODE_CLASS,
|
||||
[GSK_BLUR_NODE] = &GSK_BLUR_NODE_CLASS
|
||||
};
|
||||
|
||||
GskRenderNode *
|
||||
|
@@ -101,6 +101,9 @@ GskRenderNode * gsk_cross_fade_node_get_start_child (GskRenderNode *node);
|
||||
GskRenderNode * gsk_cross_fade_node_get_end_child (GskRenderNode *node);
|
||||
double gsk_cross_fade_node_get_progress (GskRenderNode *node);
|
||||
|
||||
GskRenderNode * gsk_blur_node_get_child (GskRenderNode *node);
|
||||
double gsk_blur_node_get_radius (GskRenderNode *node);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSK_RENDER_NODE_PRIVATE_H__ */
|
||||
|
129
gsk/gskvulkanblurpipeline.c
Normal file
129
gsk/gskvulkanblurpipeline.c
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkanblurpipelineprivate.h"
|
||||
|
||||
struct _GskVulkanBlurPipeline
|
||||
{
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
typedef struct _GskVulkanBlurInstance GskVulkanBlurInstance;
|
||||
|
||||
struct _GskVulkanBlurInstance
|
||||
{
|
||||
float rect[4];
|
||||
float tex_rect[4];
|
||||
float blur_radius;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GskVulkanBlurPipeline, gsk_vulkan_blur_pipeline, GSK_TYPE_VULKAN_PIPELINE)
|
||||
|
||||
static const VkPipelineVertexInputStateCreateInfo *
|
||||
gsk_vulkan_blur_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
|
||||
{
|
||||
static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
|
||||
{
|
||||
.binding = 0,
|
||||
.stride = sizeof (GskVulkanBlurInstance),
|
||||
.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
|
||||
}
|
||||
};
|
||||
static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
|
||||
{
|
||||
.location = 0,
|
||||
.binding = 0,
|
||||
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.offset = 0,
|
||||
},
|
||||
{
|
||||
.location = 1,
|
||||
.binding = 0,
|
||||
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.offset = G_STRUCT_OFFSET (GskVulkanBlurInstance, tex_rect),
|
||||
},
|
||||
{
|
||||
.location = 2,
|
||||
.binding = 0,
|
||||
.format = VK_FORMAT_R32_SFLOAT,
|
||||
.offset = G_STRUCT_OFFSET (GskVulkanBlurInstance, blur_radius),
|
||||
}
|
||||
};
|
||||
static const VkPipelineVertexInputStateCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||
.vertexBindingDescriptionCount = G_N_ELEMENTS (vertexBindingDescriptions),
|
||||
.pVertexBindingDescriptions = vertexBindingDescriptions,
|
||||
.vertexAttributeDescriptionCount = G_N_ELEMENTS (vertexInputAttributeDescription),
|
||||
.pVertexAttributeDescriptions = vertexInputAttributeDescription
|
||||
};
|
||||
|
||||
return &info;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_blur_pipeline_finalize (GObject *gobject)
|
||||
{
|
||||
//GskVulkanBlurPipeline *self = GSK_VULKAN_BLUR_PIPELINE (gobject);
|
||||
|
||||
G_OBJECT_CLASS (gsk_vulkan_blur_pipeline_parent_class)->finalize (gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_blur_pipeline_class_init (GskVulkanBlurPipelineClass *klass)
|
||||
{
|
||||
GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
|
||||
|
||||
G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_blur_pipeline_finalize;
|
||||
|
||||
pipeline_class->get_input_state_create_info = gsk_vulkan_blur_pipeline_get_input_state_create_info;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_blur_pipeline_init (GskVulkanBlurPipeline *self)
|
||||
{
|
||||
}
|
||||
|
||||
GskVulkanPipeline *
|
||||
gsk_vulkan_blur_pipeline_new (GskVulkanPipelineLayout *layout,
|
||||
const char *shader_name,
|
||||
VkRenderPass render_pass)
|
||||
{
|
||||
return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_BLUR_PIPELINE, layout, shader_name, render_pass);
|
||||
}
|
||||
|
||||
gsize
|
||||
gsk_vulkan_blur_pipeline_count_vertex_data (GskVulkanBlurPipeline *pipeline)
|
||||
{
|
||||
return sizeof (GskVulkanBlurInstance);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_blur_pipeline_collect_vertex_data (GskVulkanBlurPipeline *pipeline,
|
||||
guchar *data,
|
||||
const graphene_rect_t *rect,
|
||||
double blur_radius)
|
||||
{
|
||||
GskVulkanBlurInstance *instance = (GskVulkanBlurInstance *) data;
|
||||
|
||||
instance->rect[0] = rect->origin.x;
|
||||
instance->rect[1] = rect->origin.y;
|
||||
instance->rect[2] = rect->size.width;
|
||||
instance->rect[3] = rect->size.height;
|
||||
instance->tex_rect[0] = 0.0;
|
||||
instance->tex_rect[1] = 0.0;
|
||||
instance->tex_rect[2] = 1.0;
|
||||
instance->tex_rect[3] = 1.0;
|
||||
instance->blur_radius = blur_radius;
|
||||
}
|
||||
|
||||
gsize
|
||||
gsk_vulkan_blur_pipeline_draw (GskVulkanBlurPipeline *pipeline,
|
||||
VkCommandBuffer command_buffer,
|
||||
gsize offset,
|
||||
gsize n_commands)
|
||||
{
|
||||
vkCmdDraw (command_buffer,
|
||||
6, n_commands,
|
||||
0, offset);
|
||||
|
||||
return n_commands;
|
||||
}
|
32
gsk/gskvulkanblurpipelineprivate.h
Normal file
32
gsk/gskvulkanblurpipelineprivate.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef __GSK_VULKAN_BLUR_PIPELINE_PRIVATE_H__
|
||||
#define __GSK_VULKAN_BLUR_PIPELINE_PRIVATE_H__
|
||||
|
||||
#include <graphene.h>
|
||||
|
||||
#include "gskvulkanpipelineprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanBlurPipelineLayout GskVulkanBlurPipelineLayout;
|
||||
|
||||
#define GSK_TYPE_VULKAN_BLUR_PIPELINE (gsk_vulkan_blur_pipeline_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GskVulkanBlurPipeline, gsk_vulkan_blur_pipeline, GSK, VULKAN_BLUR_PIPELINE, GskVulkanPipeline)
|
||||
|
||||
GskVulkanPipeline * gsk_vulkan_blur_pipeline_new (GskVulkanPipelineLayout *layout,
|
||||
const char *shader_name,
|
||||
VkRenderPass render_pass);
|
||||
|
||||
gsize gsk_vulkan_blur_pipeline_count_vertex_data (GskVulkanBlurPipeline *pipeline);
|
||||
void gsk_vulkan_blur_pipeline_collect_vertex_data (GskVulkanBlurPipeline *pipeline,
|
||||
guchar *data,
|
||||
const graphene_rect_t *rect,
|
||||
double radius);
|
||||
gsize gsk_vulkan_blur_pipeline_draw (GskVulkanBlurPipeline *pipeline,
|
||||
VkCommandBuffer command_buffer,
|
||||
gsize offset,
|
||||
gsize n_commands);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSK_VULKAN_BLUR_PIPELINE_PRIVATE_H__ */
|
@@ -11,6 +11,7 @@
|
||||
#include "gskvulkanrenderpassprivate.h"
|
||||
|
||||
#include "gskvulkanblendpipelineprivate.h"
|
||||
#include "gskvulkanblurpipelineprivate.h"
|
||||
#include "gskvulkanborderpipelineprivate.h"
|
||||
#include "gskvulkanboxshadowpipelineprivate.h"
|
||||
#include "gskvulkancolorpipelineprivate.h"
|
||||
@@ -340,6 +341,9 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender *self,
|
||||
{ "outset-shadow", gsk_vulkan_box_shadow_pipeline_new },
|
||||
{ "outset-shadow-clip", gsk_vulkan_box_shadow_pipeline_new },
|
||||
{ "outset-shadow-clip-rounded", gsk_vulkan_box_shadow_pipeline_new },
|
||||
{ "blur", gsk_vulkan_blur_pipeline_new },
|
||||
{ "blur-clip", gsk_vulkan_blur_pipeline_new },
|
||||
{ "blur-clip-rounded", gsk_vulkan_blur_pipeline_new },
|
||||
};
|
||||
|
||||
g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "gskrenderer.h"
|
||||
#include "gskroundedrectprivate.h"
|
||||
#include "gskvulkanblendpipelineprivate.h"
|
||||
#include "gskvulkanblurpipelineprivate.h"
|
||||
#include "gskvulkanborderpipelineprivate.h"
|
||||
#include "gskvulkanboxshadowpipelineprivate.h"
|
||||
#include "gskvulkanclipprivate.h"
|
||||
@@ -31,6 +32,7 @@ typedef enum {
|
||||
GSK_VULKAN_OP_COLOR,
|
||||
GSK_VULKAN_OP_LINEAR_GRADIENT,
|
||||
GSK_VULKAN_OP_OPACITY,
|
||||
GSK_VULKAN_OP_BLUR,
|
||||
GSK_VULKAN_OP_COLOR_MATRIX,
|
||||
GSK_VULKAN_OP_BORDER,
|
||||
GSK_VULKAN_OP_INSET_SHADOW,
|
||||
@@ -231,6 +233,20 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
|
||||
g_array_append_val (self->render_ops, op);
|
||||
return;
|
||||
|
||||
case GSK_BLUR_NODE:
|
||||
if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_BLUR;
|
||||
else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_BLUR_CLIP;
|
||||
else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_BLUR_CLIP_ROUNDED;
|
||||
else
|
||||
FALLBACK ("Blur nodes can't deal with clip type %u\n", constants->clip.type);
|
||||
op.type = GSK_VULKAN_OP_BLUR;
|
||||
op.render.pipeline = gsk_vulkan_render_get_pipeline (render, pipeline_type);
|
||||
g_array_append_val (self->render_ops, op);
|
||||
return;
|
||||
|
||||
case GSK_COLOR_MATRIX_NODE:
|
||||
if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_COLOR_MATRIX;
|
||||
@@ -543,6 +559,18 @@ gsk_vulkan_render_pass_upload (GskVulkanRenderPass *self,
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BLUR:
|
||||
{
|
||||
GskRenderNode *child = gsk_blur_node_get_child (op->render.node);
|
||||
|
||||
op->render.source = gsk_vulkan_render_pass_get_node_as_texture (self,
|
||||
render,
|
||||
uploader,
|
||||
child,
|
||||
&child->bounds);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_COLOR_MATRIX:
|
||||
{
|
||||
GskRenderNode *child = gsk_color_matrix_node_get_child (op->render.node);
|
||||
@@ -607,6 +635,11 @@ gsk_vulkan_render_pass_count_vertex_data (GskVulkanRenderPass *self)
|
||||
n_bytes += op->render.vertex_count;
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BLUR:
|
||||
op->render.vertex_count = gsk_vulkan_blur_pipeline_count_vertex_data (GSK_VULKAN_BLUR_PIPELINE (op->render.pipeline));
|
||||
n_bytes += op->render.vertex_count;
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
op->render.vertex_count = gsk_vulkan_border_pipeline_count_vertex_data (GSK_VULKAN_BORDER_PIPELINE (op->render.pipeline));
|
||||
n_bytes += op->render.vertex_count;
|
||||
@@ -707,6 +740,17 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BLUR:
|
||||
{
|
||||
op->render.vertex_offset = offset + n_bytes;
|
||||
gsk_vulkan_blur_pipeline_collect_vertex_data (GSK_VULKAN_BLUR_PIPELINE (op->render.pipeline),
|
||||
data + n_bytes + offset,
|
||||
&op->render.node->bounds,
|
||||
gsk_blur_node_get_radius (op->render.node));
|
||||
n_bytes += op->render.vertex_count;
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_COLOR_MATRIX:
|
||||
{
|
||||
op->render.vertex_offset = offset + n_bytes;
|
||||
@@ -792,6 +836,7 @@ gsk_vulkan_render_pass_reserve_descriptor_sets (GskVulkanRenderPass *self,
|
||||
case GSK_VULKAN_OP_SURFACE:
|
||||
case GSK_VULKAN_OP_TEXTURE:
|
||||
case GSK_VULKAN_OP_OPACITY:
|
||||
case GSK_VULKAN_OP_BLUR:
|
||||
case GSK_VULKAN_OP_COLOR_MATRIX:
|
||||
op->render.descriptor_set_index = gsk_vulkan_render_reserve_descriptor_set (render, op->render.source);
|
||||
break;
|
||||
@@ -899,6 +944,39 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
|
||||
current_draw_index, 1);
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BLUR:
|
||||
if (current_pipeline != op->render.pipeline)
|
||||
{
|
||||
current_pipeline = op->render.pipeline;
|
||||
vkCmdBindPipeline (command_buffer,
|
||||
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
gsk_vulkan_pipeline_get_pipeline (current_pipeline));
|
||||
vkCmdBindVertexBuffers (command_buffer,
|
||||
0,
|
||||
1,
|
||||
(VkBuffer[1]) {
|
||||
gsk_vulkan_buffer_get_buffer (vertex_buffer)
|
||||
},
|
||||
(VkDeviceSize[1]) { op->render.vertex_offset });
|
||||
current_draw_index = 0;
|
||||
}
|
||||
|
||||
vkCmdBindDescriptorSets (command_buffer,
|
||||
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
|
||||
0,
|
||||
1,
|
||||
(VkDescriptorSet[1]) {
|
||||
gsk_vulkan_render_get_descriptor_set (render, op->render.descriptor_set_index)
|
||||
},
|
||||
0,
|
||||
NULL);
|
||||
|
||||
current_draw_index += gsk_vulkan_blur_pipeline_draw (GSK_VULKAN_BLUR_PIPELINE (current_pipeline),
|
||||
command_buffer,
|
||||
current_draw_index, 1);
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_COLOR:
|
||||
if (current_pipeline != op->render.pipeline)
|
||||
{
|
||||
|
@@ -31,6 +31,9 @@ typedef enum {
|
||||
GSK_VULKAN_PIPELINE_OUTSET_SHADOW,
|
||||
GSK_VULKAN_PIPELINE_OUTSET_SHADOW_CLIP,
|
||||
GSK_VULKAN_PIPELINE_OUTSET_SHADOW_CLIP_ROUNDED,
|
||||
GSK_VULKAN_PIPELINE_BLUR,
|
||||
GSK_VULKAN_PIPELINE_BLUR_CLIP,
|
||||
GSK_VULKAN_PIPELINE_BLUR_CLIP_ROUNDED,
|
||||
/* add more */
|
||||
GSK_VULKAN_N_PIPELINES
|
||||
} GskVulkanPipelineType;
|
||||
|
@@ -50,6 +50,7 @@ gsk_private_vulkan_compiled_shaders = []
|
||||
if have_vulkan
|
||||
gsk_private_sources += files([
|
||||
'gskvulkanblendpipeline.c',
|
||||
'gskvulkanblurpipeline.c',
|
||||
'gskvulkanborderpipeline.c',
|
||||
'gskvulkanboxshadowpipeline.c',
|
||||
'gskvulkanbuffer.c',
|
||||
|
BIN
gsk/resources/vulkan/blur-clip-rounded.frag.spv
Normal file
BIN
gsk/resources/vulkan/blur-clip-rounded.frag.spv
Normal file
Binary file not shown.
BIN
gsk/resources/vulkan/blur-clip-rounded.vert.spv
Normal file
BIN
gsk/resources/vulkan/blur-clip-rounded.vert.spv
Normal file
Binary file not shown.
BIN
gsk/resources/vulkan/blur-clip.frag.spv
Normal file
BIN
gsk/resources/vulkan/blur-clip.frag.spv
Normal file
Binary file not shown.
BIN
gsk/resources/vulkan/blur-clip.vert.spv
Normal file
BIN
gsk/resources/vulkan/blur-clip.vert.spv
Normal file
Binary file not shown.
52
gsk/resources/vulkan/blur.frag
Normal file
52
gsk/resources/vulkan/blur.frag
Normal file
@@ -0,0 +1,52 @@
|
||||
#version 420 core
|
||||
|
||||
#include "clip.frag.glsl"
|
||||
|
||||
layout(location = 0) in vec2 inPos;
|
||||
layout(location = 1) in vec2 inTexCoord;
|
||||
layout(location = 2) in float inRadius;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D inTexture;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
const int c_samplesX = 15; // must be odd
|
||||
const int c_samplesY = 15; // must be odd
|
||||
const float c_textureSize = 512.0;
|
||||
|
||||
const int c_halfSamplesX = c_samplesX / 2;
|
||||
const int c_halfSamplesY = c_samplesY / 2;
|
||||
const float c_pixelSize = (1.0 / c_textureSize);
|
||||
|
||||
float Gaussian (float sigma, float x)
|
||||
{
|
||||
return exp(-(x*x) / (2.0 * sigma*sigma));
|
||||
}
|
||||
|
||||
vec3 BlurredPixel (in vec2 uv)
|
||||
{
|
||||
float c_sigmaX = inRadius;
|
||||
float c_sigmaY = inRadius;
|
||||
float total = 0.0;
|
||||
vec3 ret = vec3(0);
|
||||
|
||||
for (int iy = 0; iy < c_samplesY; ++iy)
|
||||
{
|
||||
float fy = Gaussian (c_sigmaY, float(iy) - float(c_halfSamplesY));
|
||||
float offsety = float(iy-c_halfSamplesY) * c_pixelSize;
|
||||
for (int ix = 0; ix < c_samplesX; ++ix)
|
||||
{
|
||||
float fx = Gaussian (c_sigmaX, float(ix) - float(c_halfSamplesX));
|
||||
float offsetx = float(ix-c_halfSamplesX) * c_pixelSize;
|
||||
total += fx * fy;
|
||||
ret += texture(inTexture, uv + vec2(offsetx, offsety)).rgb * fx*fy;
|
||||
}
|
||||
}
|
||||
return ret / total;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// color = clip (inPos, vec4(BlurredPixel (inTexCoord), 1.0));
|
||||
color = clip (inPos, vec4(1.0, 0.0, 0.0, 1.0));
|
||||
}
|
13
gsk/resources/vulkan/blur.frag.glsl
Normal file
13
gsk/resources/vulkan/blur.frag.glsl
Normal file
@@ -0,0 +1,13 @@
|
||||
#version 420 core
|
||||
|
||||
#include "clip.frag.glsl"
|
||||
|
||||
layout(location = 0) in vec2 inPos;
|
||||
layout(location = 1) in float inRadius;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = clip (inPos, vec4(1, 0, 0, 0));
|
||||
}
|
BIN
gsk/resources/vulkan/blur.frag.spv
Normal file
BIN
gsk/resources/vulkan/blur.frag.spv
Normal file
Binary file not shown.
30
gsk/resources/vulkan/blur.vert
Normal file
30
gsk/resources/vulkan/blur.vert
Normal file
@@ -0,0 +1,30 @@
|
||||
#version 420 core
|
||||
|
||||
#include "clip.vert.glsl"
|
||||
|
||||
layout(location = 0) in vec4 inRect;
|
||||
layout(location = 1) in float inRadius;
|
||||
|
||||
layout(location = 0) out vec2 outPos;
|
||||
layout(location = 1) out flat float outRadius;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(1.0, 1.0) };
|
||||
|
||||
void main() {
|
||||
vec4 rect = clip (inRect);
|
||||
|
||||
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
|
||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
||||
outPos = pos;
|
||||
outRadius = inRadius;
|
||||
}
|
||||
|
30
gsk/resources/vulkan/blur.vert.glsl
Normal file
30
gsk/resources/vulkan/blur.vert.glsl
Normal file
@@ -0,0 +1,30 @@
|
||||
#version 420 core
|
||||
|
||||
#include "clip.vert.glsl"
|
||||
|
||||
layout(location = 0) in vec4 inRect;
|
||||
layout(location = 1) in float inRadius;
|
||||
|
||||
layout(location = 0) out vec2 outPos;
|
||||
layout(location = 1) out flat float outRadius;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(1.0, 1.0) };
|
||||
|
||||
void main() {
|
||||
vec4 rect = clip (inRect);
|
||||
|
||||
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
|
||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
||||
outPos = pos;
|
||||
outRadius = inRadius;
|
||||
}
|
||||
|
BIN
gsk/resources/vulkan/blur.vert.spv
Normal file
BIN
gsk/resources/vulkan/blur.vert.spv
Normal file
Binary file not shown.
@@ -8,6 +8,7 @@
|
||||
|
||||
gsk_private_vulkan_fragment_shaders = [
|
||||
'blend.frag',
|
||||
'blur.frag',
|
||||
'border.frag',
|
||||
'color.frag',
|
||||
'color-matrix.frag',
|
||||
@@ -18,6 +19,7 @@ gsk_private_vulkan_fragment_shaders = [
|
||||
|
||||
gsk_private_vulkan_vertex_shaders = [
|
||||
'blend.vert',
|
||||
'blur.vert',
|
||||
'border.vert',
|
||||
'color.vert',
|
||||
'color-matrix.vert',
|
||||
|
@@ -46,7 +46,7 @@ union _GtkCssFilter {
|
||||
struct {
|
||||
GtkCssFilterType type;
|
||||
GtkCssValue *value;
|
||||
} brightness, contrast, grayscale, hue_rotate, invert, opacity, saturate, sepia;
|
||||
} brightness, contrast, grayscale, hue_rotate, invert, opacity, saturate, sepia, blur;
|
||||
};
|
||||
|
||||
struct _GtkCssValue {
|
||||
@@ -87,8 +87,10 @@ gtk_css_filter_clear (GtkCssFilter *filter)
|
||||
case GTK_CSS_FILTER_SEPIA:
|
||||
_gtk_css_value_unref (filter->sepia.value);
|
||||
break;
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
_gtk_css_value_unref (filter->blur.value);
|
||||
break;
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
@@ -126,8 +128,10 @@ gtk_css_filter_init_identity (GtkCssFilter *filter,
|
||||
case GTK_CSS_FILTER_SEPIA:
|
||||
filter->sepia.value = _gtk_css_number_value_new (0, GTK_CSS_NUMBER);
|
||||
break;
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
filter->blur.value = _gtk_css_number_value_new (0, GTK_CSS_PX);
|
||||
break;
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
@@ -141,7 +145,7 @@ gtk_css_filter_init_identity (GtkCssFilter *filter,
|
||||
#define G 0.7152
|
||||
#define B 0.0722
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
gtk_css_filter_get_matrix (const GtkCssFilter *filter,
|
||||
graphene_matrix_t *matrix,
|
||||
graphene_vec4_t *offset)
|
||||
@@ -240,30 +244,36 @@ gtk_css_filter_get_matrix (const GtkCssFilter *filter,
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
return FALSE;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#undef R
|
||||
#undef G
|
||||
#undef B
|
||||
|
||||
static void
|
||||
static int
|
||||
gtk_css_filter_value_compute_matrix (const GtkCssValue *value,
|
||||
int first,
|
||||
graphene_matrix_t *matrix,
|
||||
graphene_vec4_t *offset)
|
||||
{
|
||||
graphene_matrix_t m, m2;
|
||||
graphene_vec4_t o, o2;
|
||||
guint i;
|
||||
int i;
|
||||
|
||||
gtk_css_filter_get_matrix (&value->filters[0], matrix, offset);
|
||||
if (!gtk_css_filter_get_matrix (&value->filters[first], matrix, offset))
|
||||
return first;
|
||||
|
||||
for (i = 1; i < value->n_filters; i++)
|
||||
for (i = first + 1; i < value->n_filters; i++)
|
||||
{
|
||||
gtk_css_filter_get_matrix (&value->filters[i], &m, &o);
|
||||
if (!gtk_css_filter_get_matrix (&value->filters[i], &m, &o))
|
||||
return i;
|
||||
|
||||
graphene_matrix_multiply (matrix, &m, &m2);
|
||||
graphene_matrix_transform_vec4 (&m, offset, &o2);
|
||||
@@ -271,6 +281,8 @@ gtk_css_filter_value_compute_matrix (const GtkCssValue *value,
|
||||
graphene_matrix_init_from_matrix (matrix, &m2);
|
||||
graphene_vec4_add (&o, &o2, offset);
|
||||
}
|
||||
|
||||
return value->n_filters;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -331,8 +343,11 @@ gtk_css_filter_compute (GtkCssFilter *dest,
|
||||
dest->sepia.value = _gtk_css_value_compute (src->sepia.value, property_id, provider, style, parent_style);
|
||||
return dest->sepia.value == src->sepia.value;
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
dest->blur.value = _gtk_css_value_compute (src->blur.value, property_id, provider, style, parent_style);
|
||||
return dest->blur.value == src->blur.value;
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
@@ -410,8 +425,10 @@ gtk_css_filter_equal (const GtkCssFilter *filter1,
|
||||
case GTK_CSS_FILTER_SEPIA:
|
||||
return _gtk_css_value_equal (filter1->sepia.value, filter2->sepia.value);
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
return _gtk_css_value_equal (filter1->blur.value, filter2->blur.value);
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
@@ -496,8 +513,11 @@ gtk_css_filter_transition (GtkCssFilter *result,
|
||||
result->sepia.value = _gtk_css_value_transition (start->sepia.value, end->sepia.value, property_id, progress);
|
||||
break;
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
result->blur.value = _gtk_css_value_transition (start->blur.value, end->blur.value, property_id, progress);
|
||||
break;
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
@@ -637,8 +657,13 @@ gtk_css_filter_print (const GtkCssFilter *filter,
|
||||
g_string_append (string, ")");
|
||||
break;
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_BLUR:
|
||||
g_string_append (string, "blur(");
|
||||
_gtk_css_value_print (filter->blur.value, string);
|
||||
g_string_append (string, ")");
|
||||
break;
|
||||
|
||||
case GTK_CSS_FILTER_NONE:
|
||||
case GTK_CSS_FILTER_DROP_SHADOW:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
@@ -770,6 +795,14 @@ gtk_css_filter_parse (GtkCssFilter *filter,
|
||||
if (filter->sepia.value == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
else if (_gtk_css_parser_try (parser, "blur(", TRUE))
|
||||
{
|
||||
filter->type = GTK_CSS_FILTER_BLUR;
|
||||
|
||||
filter->blur.value = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH);
|
||||
if (filter->blur.value == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
_gtk_css_parser_error (parser, "unknown syntax for filter");
|
||||
@@ -821,43 +854,67 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
|
||||
return value;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_css_filter_value_get_color_matrix (const GtkCssValue *filter,
|
||||
graphene_matrix_t *matrix,
|
||||
graphene_vec4_t *offset)
|
||||
{
|
||||
g_return_val_if_fail (filter->class == >K_CSS_VALUE_FILTER, FALSE);
|
||||
g_return_val_if_fail (matrix != NULL, FALSE);
|
||||
|
||||
gtk_css_filter_value_compute_matrix (filter, matrix, offset);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_filter_value_push_snapshot (const GtkCssValue *filter,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
graphene_matrix_t matrix;
|
||||
graphene_vec4_t offset;
|
||||
int i, j;
|
||||
double radius;
|
||||
|
||||
if (gtk_css_filter_value_is_none (filter))
|
||||
return;
|
||||
|
||||
gtk_css_filter_value_get_color_matrix (filter, &matrix, &offset);
|
||||
i = 0;
|
||||
while (i < filter->n_filters)
|
||||
{
|
||||
j = gtk_css_filter_value_compute_matrix (filter, i, &matrix, &offset);
|
||||
if (i < j)
|
||||
gtk_snapshot_push_color_matrix (snapshot,
|
||||
&matrix,
|
||||
&offset,
|
||||
"CssFilter ColorMatrix<%d-%d>", i, j);
|
||||
|
||||
gtk_snapshot_push_color_matrix (snapshot,
|
||||
&matrix,
|
||||
&offset,
|
||||
"CssFilter<%u>", filter->n_filters);
|
||||
if (j < filter->n_filters)
|
||||
{
|
||||
if (filter->filters[j].type == GTK_CSS_FILTER_BLUR)
|
||||
{
|
||||
radius = _gtk_css_number_value_get (filter->filters[j].blur.value, 100.0);
|
||||
gtk_snapshot_push_blur (snapshot, radius, "CssFilter Blur<%d, radius %g>", j, radius);
|
||||
}
|
||||
else
|
||||
g_warning ("Don't know how to handle filter type %d", filter->filters[j].type);
|
||||
}
|
||||
|
||||
i = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_filter_value_pop_snapshot (const GtkCssValue *filter,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if (gtk_css_filter_value_is_none (filter))
|
||||
return;
|
||||
|
||||
gtk_snapshot_pop (snapshot);
|
||||
i = 0;
|
||||
while (i < filter->n_filters)
|
||||
{
|
||||
for (j = i; j < filter->n_filters; j++)
|
||||
{
|
||||
if (filter->filters[j].type == GTK_CSS_FILTER_BLUR)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i < j)
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
if (j < filter->n_filters)
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
i = j + 1;
|
||||
}
|
||||
}
|
||||
|
@@ -28,10 +28,6 @@ G_BEGIN_DECLS
|
||||
GtkCssValue * gtk_css_filter_value_new_none (void);
|
||||
GtkCssValue * gtk_css_filter_value_parse (GtkCssParser *parser);
|
||||
|
||||
gboolean gtk_css_filter_value_get_color_matrix (const GtkCssValue *filter,
|
||||
graphene_matrix_t *matrix,
|
||||
graphene_vec4_t *offset);
|
||||
|
||||
void gtk_css_filter_value_push_snapshot (const GtkCssValue *filter,
|
||||
GtkSnapshot *snapshot);
|
||||
void gtk_css_filter_value_pop_snapshot (const GtkCssValue *filter,
|
||||
|
125
gtk/gtkoverlay.c
125
gtk/gtkoverlay.c
@@ -25,6 +25,7 @@
|
||||
#include "gtkscrolledwindow.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtksnapshotprivate.h"
|
||||
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkintl.h"
|
||||
@@ -65,6 +66,7 @@ struct _GtkOverlayChild
|
||||
{
|
||||
GtkWidget *widget;
|
||||
gboolean pass_through;
|
||||
double blur;
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -76,6 +78,7 @@ enum
|
||||
{
|
||||
CHILD_PROP_0,
|
||||
CHILD_PROP_PASS_THROUGH,
|
||||
CHILD_PROP_BLUR,
|
||||
CHILD_PROP_INDEX
|
||||
};
|
||||
|
||||
@@ -539,6 +542,17 @@ gtk_overlay_set_child_property (GtkContainer *container,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CHILD_PROP_BLUR:
|
||||
if (child_info)
|
||||
{
|
||||
if (g_value_get_double (value) != child_info->blur)
|
||||
{
|
||||
child_info->blur = g_value_get_double (value);
|
||||
gtk_container_child_notify (container, child, "blur");
|
||||
gtk_widget_queue_draw (GTK_WIDGET (overlay));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CHILD_PROP_INDEX:
|
||||
if (child_info != NULL)
|
||||
gtk_overlay_reorder_overlay (GTK_OVERLAY (container),
|
||||
@@ -585,6 +599,12 @@ gtk_overlay_get_child_property (GtkContainer *container,
|
||||
else
|
||||
g_value_set_boolean (value, FALSE);
|
||||
break;
|
||||
case CHILD_PROP_BLUR:
|
||||
if (child_info)
|
||||
g_value_set_double (value, child_info->blur);
|
||||
else
|
||||
g_value_set_double (value, 0);
|
||||
break;
|
||||
case CHILD_PROP_INDEX:
|
||||
g_value_set_int (value, g_slist_index (priv->children, child_info));
|
||||
break;
|
||||
@@ -594,6 +614,99 @@ gtk_overlay_get_child_property (GtkContainer *container,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_overlay_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
GtkWidget *main_widget;
|
||||
GskRenderNode *main_widget_node = NULL;
|
||||
GtkWidget *child;
|
||||
GtkAllocation main_alloc;
|
||||
cairo_region_t *clip = NULL;
|
||||
int i;
|
||||
graphene_matrix_t translate;
|
||||
|
||||
main_widget = gtk_bin_get_child (GTK_BIN (widget));
|
||||
gtk_widget_get_allocation (widget, &main_alloc);
|
||||
|
||||
for (child = _gtk_widget_get_first_child (widget);
|
||||
child != NULL;
|
||||
child = _gtk_widget_get_next_sibling (child))
|
||||
{
|
||||
double blur;
|
||||
gtk_container_child_get (GTK_CONTAINER (widget), child, "blur", &blur, NULL);
|
||||
if (blur > 0)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
graphene_rect_t bounds;
|
||||
|
||||
if (main_widget_node == NULL)
|
||||
{
|
||||
GtkSnapshot child_snapshot;
|
||||
|
||||
gtk_snapshot_init (&child_snapshot,
|
||||
gtk_snapshot_get_renderer (snapshot),
|
||||
snapshot->record_names,
|
||||
NULL,
|
||||
"OverlayCaptureMainChild");
|
||||
gtk_snapshot_offset (&child_snapshot, main_alloc.x, main_alloc.y);
|
||||
gtk_widget_snapshot (main_widget, &child_snapshot);
|
||||
gtk_snapshot_offset (&child_snapshot, -main_alloc.x, -main_alloc.y);
|
||||
main_widget_node = gtk_snapshot_finish (&child_snapshot);
|
||||
graphene_matrix_init_translate (&translate, &GRAPHENE_POINT3D_INIT (main_alloc.x,main_alloc.y, 0));
|
||||
}
|
||||
|
||||
gtk_widget_get_allocation (child, &alloc);
|
||||
graphene_rect_init (&bounds, alloc.x, alloc.y, alloc.width, alloc.height);
|
||||
gtk_snapshot_push_clip (snapshot, &bounds, "Overlay Effect Clip");
|
||||
gtk_snapshot_push_blur (snapshot, blur, "Overlay Effect");
|
||||
gtk_snapshot_append_node (snapshot, main_widget_node);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
if (clip == NULL)
|
||||
{
|
||||
cairo_rectangle_int_t rect;
|
||||
rect.x = rect.y = 0;
|
||||
rect.width = main_alloc.width;
|
||||
rect.height = main_alloc.height;
|
||||
clip = cairo_region_create ();
|
||||
cairo_region_union_rectangle (clip, &rect);
|
||||
}
|
||||
cairo_region_subtract_rectangle (clip, (cairo_rectangle_int_t *)&alloc);
|
||||
}
|
||||
}
|
||||
|
||||
if (clip == NULL)
|
||||
{
|
||||
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->snapshot (widget, snapshot);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < cairo_region_num_rectangles (clip); i++)
|
||||
{
|
||||
cairo_rectangle_int_t rect;
|
||||
graphene_rect_t bounds;
|
||||
|
||||
cairo_region_get_rectangle (clip, i, &rect);
|
||||
graphene_rect_init (&bounds, rect.x, rect.y, rect.width, rect.height);
|
||||
gtk_snapshot_push_clip (snapshot, &bounds, "Overlay Non-Effect Clip");
|
||||
gtk_snapshot_append_node (snapshot, main_widget_node);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
cairo_region_destroy (clip);
|
||||
|
||||
for (child = _gtk_widget_get_first_child (widget);
|
||||
child != NULL;
|
||||
child = _gtk_widget_get_next_sibling (child))
|
||||
{
|
||||
if (child != main_widget)
|
||||
gtk_widget_snapshot_child (widget, child, snapshot);
|
||||
}
|
||||
|
||||
gsk_render_node_unref (main_widget_node);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_overlay_class_init (GtkOverlayClass *klass)
|
||||
@@ -603,6 +716,7 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
|
||||
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
||||
|
||||
widget_class->size_allocate = gtk_overlay_size_allocate;
|
||||
widget_class->snapshot = gtk_overlay_snapshot;
|
||||
|
||||
container_class->add = gtk_overlay_add;
|
||||
container_class->remove = gtk_overlay_remove;
|
||||
@@ -624,6 +738,17 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
|
||||
FALSE,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkOverlay:blur:
|
||||
*
|
||||
* Blur the content behind this child with a Gaussian blur of this radius.
|
||||
*
|
||||
* Since: 3.92
|
||||
*/
|
||||
gtk_container_class_install_child_property (container_class, CHILD_PROP_BLUR,
|
||||
g_param_spec_double ("blur", P_("Blur Radius"), P_("Apply a blur to the content behind this child"),
|
||||
0, 100, 0,
|
||||
GTK_PARAM_READWRITE));
|
||||
/**
|
||||
* GtkOverlay:index:
|
||||
*
|
||||
|
@@ -321,6 +321,57 @@ gtk_snapshot_push_opacity (GtkSnapshot *snapshot,
|
||||
snapshot->state = state;
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_blur (GtkSnapshotState *state,
|
||||
GskRenderNode **nodes,
|
||||
guint n_nodes,
|
||||
const char *name)
|
||||
{
|
||||
GskRenderNode *node, *blur_node;
|
||||
|
||||
node = gtk_snapshot_collect_default (state, nodes, n_nodes, name);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
blur_node = gsk_blur_node_new (node, state->data.blur.radius);
|
||||
if (name)
|
||||
gsk_render_node_set_name (blur_node, name);
|
||||
|
||||
gsk_render_node_unref (node);
|
||||
|
||||
return blur_node;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_snapshot_push_blur (GtkSnapshot *snapshot,
|
||||
double radius,
|
||||
const char *name,
|
||||
...)
|
||||
{
|
||||
GtkSnapshotState *state;
|
||||
char *str;
|
||||
|
||||
if (name && snapshot->record_names)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, name);
|
||||
str = g_strdup_vprintf (name, args);
|
||||
va_end (args);
|
||||
}
|
||||
else
|
||||
str = NULL;
|
||||
|
||||
state = gtk_snapshot_state_new (snapshot->state,
|
||||
str,
|
||||
snapshot->state->clip_region,
|
||||
snapshot->state->translate_x,
|
||||
snapshot->state->translate_y,
|
||||
gtk_snapshot_collect_blur);
|
||||
state->data.blur.radius = radius;
|
||||
snapshot->state = state;
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_color_matrix (GtkSnapshotState *state,
|
||||
GskRenderNode **nodes,
|
||||
|
@@ -51,6 +51,11 @@ void gtk_snapshot_push_opacity (GtkSnapshot
|
||||
double opacity,
|
||||
const char *name,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
GDK_AVAILABLE_IN_3_92
|
||||
void gtk_snapshot_push_blur (GtkSnapshot *snapshot,
|
||||
double radius,
|
||||
const char *name,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
GDK_AVAILABLE_IN_3_90
|
||||
void gtk_snapshot_push_color_matrix (GtkSnapshot *snapshot,
|
||||
const graphene_matrix_t*color_matrix,
|
||||
|
@@ -48,6 +48,9 @@ struct _GtkSnapshotState {
|
||||
struct {
|
||||
double opacity;
|
||||
} opacity;
|
||||
struct {
|
||||
double radius;
|
||||
} blur;
|
||||
struct {
|
||||
graphene_matrix_t matrix;
|
||||
graphene_vec4_t offset;
|
||||
|
@@ -546,6 +546,10 @@ append_node (GtkTreeModelRenderNode *nodemodel,
|
||||
append_node (nodemodel, gsk_color_matrix_node_get_child (node), priv->nodes->len - 1);
|
||||
break;
|
||||
|
||||
case GSK_BLUR_NODE:
|
||||
append_node (nodemodel, gsk_blur_node_get_child (node), priv->nodes->len - 1);
|
||||
break;
|
||||
|
||||
case GSK_REPEAT_NODE:
|
||||
append_node (nodemodel, gsk_repeat_node_get_child (node), priv->nodes->len - 1);
|
||||
break;
|
||||
|
@@ -183,6 +183,8 @@ node_type_name (GskRenderNodeType type)
|
||||
return "CrossFade";
|
||||
case GSK_TEXT_NODE:
|
||||
return "Text";
|
||||
case GSK_BLUR_NODE:
|
||||
return "Blur";
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
tests/portland-rose.jpg
Normal file
BIN
tests/portland-rose.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 459 KiB |
@@ -534,6 +534,68 @@ test_child_order (void)
|
||||
}
|
||||
|
||||
|
||||
static GtkWidget *
|
||||
test_effect (void)
|
||||
{
|
||||
GtkWidget *win;
|
||||
GtkWidget *overlay;
|
||||
GtkWidget *button;
|
||||
GtkWidget *image;
|
||||
GtkWidget *sw;
|
||||
GtkWidget *box;
|
||||
GtkWidget *label;
|
||||
|
||||
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_default_size (GTK_WINDOW (win), 600, 400);
|
||||
gtk_window_set_title (GTK_WINDOW (win), "Fancy Effect");
|
||||
|
||||
overlay = gtk_overlay_new ();
|
||||
gtk_container_add (GTK_CONTAINER (win), overlay);
|
||||
|
||||
button = gtk_button_new_with_label ("Don't click this button!");
|
||||
label = gtk_bin_get_child (GTK_BIN (button));
|
||||
g_object_set (label, "margin", 50, NULL);
|
||||
|
||||
gtk_widget_set_opacity (button, 0.7);
|
||||
gtk_widget_set_halign (button, GTK_ALIGN_FILL);
|
||||
gtk_widget_set_valign (button, GTK_ALIGN_START);
|
||||
|
||||
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), button);
|
||||
gtk_container_child_set (GTK_CONTAINER (overlay), button, "blur", 5.0, NULL);
|
||||
|
||||
button = gtk_button_new_with_label ("Maybe this one?");
|
||||
label = gtk_bin_get_child (GTK_BIN (button));
|
||||
g_object_set (label, "margin", 50, NULL);
|
||||
|
||||
gtk_widget_set_opacity (button, 0.7);
|
||||
gtk_widget_set_halign (button, GTK_ALIGN_FILL);
|
||||
gtk_widget_set_valign (button, GTK_ALIGN_END);
|
||||
|
||||
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), button);
|
||||
gtk_container_child_set (GTK_CONTAINER (overlay), button, "blur", 5.0, NULL);
|
||||
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_container_add (GTK_CONTAINER (overlay), sw);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_container_add (GTK_CONTAINER (sw), box);
|
||||
image = gtk_image_new ();
|
||||
if (g_file_test ("portland-rose.jpg", G_FILE_TEST_EXISTS))
|
||||
gtk_image_set_from_file (GTK_IMAGE (image), "portland-rose.jpg");
|
||||
else if (g_file_test ("tests/portland-rose.jpg", G_FILE_TEST_EXISTS))
|
||||
gtk_image_set_from_file (GTK_IMAGE (image), "tests/portland-rose.jpg");
|
||||
else if (g_file_test ("../tests/portland-rose.jpg", G_FILE_TEST_EXISTS))
|
||||
gtk_image_set_from_file (GTK_IMAGE (image), "../tests/portland-rose.jpg");
|
||||
else
|
||||
g_error ("portland-rose.jpg not found. No rose for you!\n");
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (box), image);
|
||||
|
||||
return win;
|
||||
}
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@@ -546,6 +608,7 @@ main (int argc, char *argv[])
|
||||
GtkWidget *win7;
|
||||
GtkWidget *win8;
|
||||
GtkWidget *win9;
|
||||
GtkWidget *win10;
|
||||
GtkCssProvider *css_provider;
|
||||
|
||||
gtk_init ();
|
||||
@@ -586,6 +649,9 @@ main (int argc, char *argv[])
|
||||
win9 = test_child_order ();
|
||||
gtk_widget_show (win9);
|
||||
|
||||
win10 = test_effect ();
|
||||
gtk_widget_show (win10);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user