Merge branch 'matthiasc/for-master' into 'master'

vulkan: Add visible fallback rendering

See merge request GNOME/gtk!3264
This commit is contained in:
Matthias Clasen 2021-03-06 19:29:50 +00:00
commit 50ccab487f
5 changed files with 84 additions and 11 deletions

View File

@ -3,6 +3,7 @@
#include "gskvulkanclipprivate.h"
#include "gskroundedrectprivate.h"
#include "gsktransform.h"
void
gsk_vulkan_clip_init_empty (GskVulkanClip *clip,
@ -137,10 +138,10 @@ gsk_vulkan_clip_intersect_rounded_rect (GskVulkanClip *dest,
}
gboolean
gsk_vulkan_clip_transform (GskVulkanClip *dest,
const GskVulkanClip *src,
const graphene_matrix_t *transform,
const graphene_rect_t *viewport)
gsk_vulkan_clip_transform (GskVulkanClip *dest,
const GskVulkanClip *src,
GskTransform *transform,
const graphene_rect_t *viewport)
{
switch (src->type)
{
@ -159,8 +160,56 @@ gsk_vulkan_clip_transform (GskVulkanClip *dest,
case GSK_VULKAN_CLIP_RECT:
case GSK_VULKAN_CLIP_ROUNDED_CIRCULAR:
case GSK_VULKAN_CLIP_ROUNDED:
/* FIXME: Handle 2D operations, in particular transform and scale */
return FALSE;
switch (gsk_transform_get_category (transform))
{
case GSK_TRANSFORM_CATEGORY_IDENTITY:
gsk_vulkan_clip_init_copy (dest, src);
return TRUE;
case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
{
float dx, dy;
gsk_transform_to_translate (transform, &dx, &dy);
gsk_vulkan_clip_init_copy (dest, src);
dest->rect.bounds.origin.x -= dx;
dest->rect.bounds.origin.y -= dy;
}
return TRUE;
case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
{
float dx, dy, scale_x, scale_y;
gsk_transform_to_affine (transform, &scale_x, &scale_y, &dx, &dy);
scale_x = 1. / scale_x;
scale_y = 1. / scale_y;
gsk_vulkan_clip_init_copy (dest, src);
dest->rect.bounds.origin.x = (dest->rect.bounds.origin.x - dx) * scale_x;
dest->rect.bounds.origin.y = (dest->rect.bounds.origin.y - dy) * scale_y;
dest->rect.bounds.size.width *= scale_x;
dest->rect.bounds.size.height *= scale_y;
if (src->type != GSK_VULKAN_CLIP_RECT)
{
dest->rect.corner[0].width *= scale_x;
dest->rect.corner[0].height *= scale_y;
dest->rect.corner[1].width *= scale_x;
dest->rect.corner[1].height *= scale_y;
dest->rect.corner[2].width *= scale_x;
dest->rect.corner[2].height *= scale_y;
dest->rect.corner[3].width *= scale_x;
dest->rect.corner[3].height *= scale_y;
}
}
return TRUE;
case GSK_TRANSFORM_CATEGORY_UNKNOWN:
case GSK_TRANSFORM_CATEGORY_ANY:
case GSK_TRANSFORM_CATEGORY_3D:
case GSK_TRANSFORM_CATEGORY_2D:
default:
return FALSE;
}
}
}

View File

@ -46,7 +46,7 @@ gboolean gsk_vulkan_clip_intersect_rounded_rect (GskVulk
const GskRoundedRect *rounded) G_GNUC_WARN_UNUSED_RESULT;
gboolean gsk_vulkan_clip_transform (GskVulkanClip *dest,
const GskVulkanClip *src,
const graphene_matrix_t*transform,
GskTransform *transform,
const graphene_rect_t *viewport) G_GNUC_WARN_UNUSED_RESULT;
gboolean gsk_vulkan_clip_contains_rect (const GskVulkanClip *self,

View File

@ -3,6 +3,7 @@
#include "gskvulkanpushconstantsprivate.h"
#include "gskroundedrectprivate.h"
#include "gsktransform.h"
typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
@ -33,14 +34,18 @@ gsk_vulkan_push_constants_init_copy (GskVulkanPushConstants *self,
gboolean
gsk_vulkan_push_constants_transform (GskVulkanPushConstants *self,
const GskVulkanPushConstants *src,
const graphene_matrix_t *transform,
GskTransform *transform,
const graphene_rect_t *viewport)
{
graphene_matrix_t matrix;
if (!gsk_vulkan_clip_transform (&self->clip, &src->clip, transform, viewport))
return FALSE;
graphene_matrix_multiply (transform, &src->mvp, &self->mvp);
gsk_transform_to_matrix (transform, &matrix);
graphene_matrix_multiply (&matrix, &src->mvp, &self->mvp);
return TRUE;
}

View File

@ -27,7 +27,7 @@ void gsk_vulkan_push_constants_init_copy (GskVulk
gboolean gsk_vulkan_push_constants_transform (GskVulkanPushConstants *self,
const GskVulkanPushConstants *src,
const graphene_matrix_t *transform,
GskTransform *transform,
const graphene_rect_t *viewport);
gboolean gsk_vulkan_push_constants_intersect_rect (GskVulkanPushConstants *self,
const GskVulkanPushConstants *src,

View File

@ -558,7 +558,7 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
gsk_transform_to_matrix (gsk_transform_node_get_transform (node), &transform);
graphene_matrix_init_from_matrix (&mv, &self->mv);
graphene_matrix_multiply (&transform, &mv, &self->mv);
if (!gsk_vulkan_push_constants_transform (&op.constants.constants, constants, &transform, &child->bounds))
if (!gsk_vulkan_push_constants_transform (&op.constants.constants, constants, gsk_transform_node_get_transform (node), &child->bounds))
FALLBACK ("Transform nodes can't deal with clip type %u", constants->clip.type);
op.type = GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS;
g_array_append_val (self->render_ops, op);
@ -859,6 +859,25 @@ gsk_vulkan_render_pass_upload_fallback (GskVulkanRenderPass *self,
gsk_render_node_draw (node, cr);
#ifdef G_ENABLE_DEBUG
if (GSK_RENDERER_DEBUG_CHECK (gsk_vulkan_render_get_renderer (render), FALLBACK))
{
cairo_rectangle (cr,
op->clip.bounds.origin.x, op->clip.bounds.origin.y,
op->clip.bounds.size.width, op->clip.bounds.size.height);
if (gsk_render_node_get_node_type (node) == GSK_CAIRO_NODE)
cairo_set_source_rgba (cr, 0.3, 0, 1, 0.25);
else
cairo_set_source_rgba (cr, 1, 0, 0, 0.25);
cairo_fill_preserve (cr);
if (gsk_render_node_get_node_type (node) == GSK_CAIRO_NODE)
cairo_set_source_rgba (cr, 0.3, 0, 1, 1);
else
cairo_set_source_rgba (cr, 1, 0, 0, 1);
cairo_stroke (cr);
}
#endif
cairo_destroy (cr);
op->source = gsk_vulkan_image_new_from_data (uploader,