2023-07-03 23:55:17 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanmaskopprivate.h"
|
|
|
|
|
|
|
|
#include "gskvulkanprivate.h"
|
|
|
|
|
|
|
|
#include "vulkan/resources/mask.vert.h"
|
|
|
|
|
|
|
|
typedef struct _GskVulkanMaskOp GskVulkanMaskOp;
|
|
|
|
|
|
|
|
struct _GskVulkanMaskOp
|
|
|
|
{
|
|
|
|
GskVulkanOp op;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GskVulkanImage *image;
|
|
|
|
graphene_rect_t rect;
|
|
|
|
graphene_rect_t tex_rect;
|
|
|
|
guint32 image_descriptor;
|
|
|
|
} source, mask;
|
|
|
|
GskMaskMode mask_mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_mask_op_finish (GskVulkanOp *op)
|
|
|
|
{
|
|
|
|
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
|
|
|
|
|
|
|
|
g_object_unref (self->source.image);
|
|
|
|
g_object_unref (self->mask.image);
|
|
|
|
}
|
|
|
|
|
2023-07-05 04:32:52 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_mask_op_print (GskVulkanOp *op,
|
|
|
|
GString *string,
|
|
|
|
guint indent)
|
|
|
|
{
|
|
|
|
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
|
|
|
|
|
|
|
|
print_indent (string, indent);
|
|
|
|
print_rect (string, &self->source.rect);
|
|
|
|
g_string_append (string, "mask ");
|
|
|
|
print_rect (string, &self->mask.rect);
|
|
|
|
switch (self->mask_mode)
|
|
|
|
{
|
|
|
|
case GSK_MASK_MODE_ALPHA:
|
|
|
|
g_string_append (string, "alpha ");
|
|
|
|
break;
|
|
|
|
case GSK_MASK_MODE_INVERTED_ALPHA:
|
|
|
|
g_string_append (string, "inverted-alpha ");
|
|
|
|
break;
|
|
|
|
case GSK_MASK_MODE_LUMINANCE:
|
|
|
|
g_string_append (string, "luminance ");
|
|
|
|
break;
|
|
|
|
case GSK_MASK_MODE_INVERTED_LUMINANCE:
|
|
|
|
g_string_append (string, "inverted-luminance ");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
print_newline (string);
|
|
|
|
}
|
|
|
|
|
2023-07-03 23:55:17 +00:00
|
|
|
static void
|
2023-07-08 19:28:56 +00:00
|
|
|
gsk_vulkan_mask_op_collect_vertex_data (GskVulkanOp *op,
|
|
|
|
guchar *data)
|
2023-07-03 23:55:17 +00:00
|
|
|
{
|
|
|
|
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
|
2023-07-09 14:27:02 +00:00
|
|
|
GskVulkanMaskInstance *instance = (GskVulkanMaskInstance *) (data + op->vertex_offset);
|
2023-07-03 23:55:17 +00:00
|
|
|
|
|
|
|
gsk_vulkan_rect_to_float (&self->source.rect, instance->source_rect);
|
|
|
|
gsk_vulkan_rect_to_float (&self->source.tex_rect, instance->source_tex_rect);
|
|
|
|
instance->source_id = self->source.image_descriptor;
|
|
|
|
gsk_vulkan_rect_to_float (&self->mask.rect, instance->mask_rect);
|
|
|
|
gsk_vulkan_rect_to_float (&self->mask.tex_rect, instance->mask_tex_rect);
|
|
|
|
instance->mask_id = self->mask.image_descriptor;
|
|
|
|
instance->mask_mode = self->mask_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_mask_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render)
|
|
|
|
{
|
|
|
|
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
|
|
|
|
|
|
|
|
self->source.image_descriptor = gsk_vulkan_render_get_image_descriptor (render, self->source.image, GSK_VULKAN_SAMPLER_DEFAULT);
|
|
|
|
self->mask.image_descriptor = gsk_vulkan_render_get_image_descriptor (render, self->mask.image, GSK_VULKAN_SAMPLER_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GskVulkanOpClass GSK_VULKAN_COLOR_MASK_OP_CLASS = {
|
|
|
|
GSK_VULKAN_OP_SIZE (GskVulkanMaskOp),
|
2023-07-09 13:40:48 +00:00
|
|
|
GSK_VULKAN_STAGE_COMMAND,
|
2023-07-03 23:55:17 +00:00
|
|
|
"mask",
|
|
|
|
&gsk_vulkan_mask_info,
|
|
|
|
gsk_vulkan_mask_op_finish,
|
2023-07-05 04:32:52 +00:00
|
|
|
gsk_vulkan_mask_op_print,
|
2023-07-09 14:27:02 +00:00
|
|
|
gsk_vulkan_op_draw_count_vertex_data,
|
2023-07-03 23:55:17 +00:00
|
|
|
gsk_vulkan_mask_op_collect_vertex_data,
|
|
|
|
gsk_vulkan_mask_op_reserve_descriptor_sets,
|
2023-07-09 14:27:02 +00:00
|
|
|
gsk_vulkan_op_draw_command
|
2023-07-03 23:55:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2023-07-09 18:28:12 +00:00
|
|
|
gsk_vulkan_mask_op (GskVulkanRender *render,
|
2023-07-03 23:55:17 +00:00
|
|
|
const char *clip_type,
|
|
|
|
const graphene_point_t *offset,
|
|
|
|
GskVulkanImage *source,
|
|
|
|
const graphene_rect_t *source_rect,
|
|
|
|
const graphene_rect_t *source_tex_rect,
|
|
|
|
GskVulkanImage *mask,
|
|
|
|
const graphene_rect_t *mask_rect,
|
|
|
|
const graphene_rect_t *mask_tex_rect,
|
|
|
|
GskMaskMode mask_mode)
|
|
|
|
{
|
|
|
|
GskVulkanMaskOp *self;
|
|
|
|
|
2023-07-09 18:28:12 +00:00
|
|
|
self = (GskVulkanMaskOp *) gsk_vulkan_op_alloc (render, &GSK_VULKAN_COLOR_MASK_OP_CLASS);
|
2023-07-03 23:55:17 +00:00
|
|
|
|
|
|
|
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
|
|
|
|
self->source.image = g_object_ref (source);
|
|
|
|
graphene_rect_offset_r (source_rect, offset->x, offset->y, &self->source.rect);
|
|
|
|
gsk_vulkan_normalize_tex_coords (&self->source.tex_rect, source_rect, source_tex_rect);
|
|
|
|
self->mask.image = g_object_ref (mask);
|
|
|
|
graphene_rect_offset_r (mask_rect, offset->x, offset->y, &self->mask.rect);
|
|
|
|
gsk_vulkan_normalize_tex_coords (&self->mask.tex_rect, mask_rect, mask_tex_rect);
|
|
|
|
self->mask_mode = mask_mode;
|
|
|
|
}
|