mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 14:10:30 +00:00
d86d4c5597
... and add a GSK_DEBUG=verbose setting making use of it.
167 lines
5.8 KiB
C
167 lines
5.8 KiB
C
#include "config.h"
|
|
|
|
#include "gskvulkancrossfadeopprivate.h"
|
|
|
|
#include "gskvulkanprivate.h"
|
|
|
|
#include "vulkan/resources/cross-fade.vert.h"
|
|
|
|
typedef struct _GskVulkanCrossFadeOp GskVulkanCrossFadeOp;
|
|
|
|
struct _GskVulkanCrossFadeOp
|
|
{
|
|
GskVulkanOp op;
|
|
|
|
graphene_rect_t bounds;
|
|
float progress;
|
|
|
|
struct {
|
|
GskVulkanImage *image;
|
|
graphene_rect_t rect;
|
|
graphene_rect_t tex_rect;
|
|
guint32 image_descriptor;
|
|
} start, end;
|
|
|
|
gsize vertex_offset;
|
|
};
|
|
|
|
static void
|
|
gsk_vulkan_cross_fade_op_finish (GskVulkanOp *op)
|
|
{
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
g_object_unref (self->start.image);
|
|
g_object_unref (self->end.image);
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_cross_fade_op_print (GskVulkanOp *op,
|
|
GString *string,
|
|
guint indent)
|
|
{
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
print_indent (string, indent);
|
|
print_rect (string, &self->bounds);
|
|
g_string_append_printf (string, "cross-fade %d%% ", (int) (self->progress * 100 + 0.5));
|
|
print_newline (string);
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_cross_fade_op_upload (GskVulkanOp *op,
|
|
GskVulkanRenderPass *pass,
|
|
GskVulkanRender *render,
|
|
GskVulkanUploader *uploader)
|
|
{
|
|
}
|
|
|
|
static inline gsize
|
|
round_up (gsize number, gsize divisor)
|
|
{
|
|
return (number + divisor - 1) / divisor * divisor;
|
|
}
|
|
|
|
static gsize
|
|
gsk_vulkan_cross_fade_op_count_vertex_data (GskVulkanOp *op,
|
|
gsize n_bytes)
|
|
{
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
gsize vertex_stride;
|
|
|
|
vertex_stride = gsk_vulkan_cross_fade_info.pVertexBindingDescriptions[0].stride;
|
|
n_bytes = round_up (n_bytes, vertex_stride);
|
|
self->vertex_offset = n_bytes;
|
|
n_bytes += vertex_stride;
|
|
return n_bytes;
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_cross_fade_op_collect_vertex_data (GskVulkanOp *op,
|
|
GskVulkanRenderPass *pass,
|
|
GskVulkanRender *render,
|
|
guchar *data)
|
|
{
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
GskVulkanCrossFadeInstance *instance = (GskVulkanCrossFadeInstance *) (data + self->vertex_offset);
|
|
|
|
gsk_vulkan_rect_to_float (&self->bounds, instance->rect);
|
|
gsk_vulkan_rect_to_float (&self->start.rect, instance->start_rect);
|
|
gsk_vulkan_rect_to_float (&self->end.rect, instance->end_rect);
|
|
gsk_vulkan_rect_to_float (&self->start.tex_rect, instance->start_tex_rect);
|
|
gsk_vulkan_rect_to_float (&self->end.tex_rect, instance->end_tex_rect);
|
|
|
|
instance->start_tex_id = self->start.image_descriptor;
|
|
instance->end_tex_id = self->end.image_descriptor;
|
|
instance->progress = self->progress;
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_cross_fade_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
GskVulkanRender *render)
|
|
{
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
self->start.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
|
|
self->start.image,
|
|
GSK_VULKAN_SAMPLER_DEFAULT);
|
|
self->end.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
|
|
self->end.image,
|
|
GSK_VULKAN_SAMPLER_DEFAULT);
|
|
}
|
|
|
|
static void
|
|
gsk_vulkan_cross_fade_op_command (GskVulkanOp *op,
|
|
GskVulkanRender *render,
|
|
VkPipelineLayout pipeline_layout,
|
|
VkCommandBuffer command_buffer)
|
|
{
|
|
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
|
|
|
|
vkCmdDraw (command_buffer,
|
|
6, 1,
|
|
0, self->vertex_offset / gsk_vulkan_cross_fade_info.pVertexBindingDescriptions[0].stride);
|
|
}
|
|
|
|
static const GskVulkanOpClass GSK_VULKAN_CROSS_FADE_OP_CLASS = {
|
|
GSK_VULKAN_OP_SIZE (GskVulkanCrossFadeOp),
|
|
"cross-fade",
|
|
&gsk_vulkan_cross_fade_info,
|
|
gsk_vulkan_cross_fade_op_finish,
|
|
gsk_vulkan_cross_fade_op_print,
|
|
gsk_vulkan_cross_fade_op_upload,
|
|
gsk_vulkan_cross_fade_op_count_vertex_data,
|
|
gsk_vulkan_cross_fade_op_collect_vertex_data,
|
|
gsk_vulkan_cross_fade_op_reserve_descriptor_sets,
|
|
gsk_vulkan_cross_fade_op_command
|
|
};
|
|
|
|
void
|
|
gsk_vulkan_cross_fade_op (GskVulkanRenderPass *render_pass,
|
|
const char *clip_type,
|
|
const graphene_rect_t *bounds,
|
|
const graphene_point_t *offset,
|
|
float progress,
|
|
GskVulkanImage *start_image,
|
|
const graphene_rect_t *start_rect,
|
|
const graphene_rect_t *start_tex_rect,
|
|
GskVulkanImage *end_image,
|
|
const graphene_rect_t *end_rect,
|
|
const graphene_rect_t *end_tex_rect)
|
|
{
|
|
GskVulkanCrossFadeOp *self;
|
|
|
|
self = (GskVulkanCrossFadeOp *) gsk_vulkan_op_alloc (render_pass, &GSK_VULKAN_CROSS_FADE_OP_CLASS);
|
|
|
|
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
|
|
graphene_rect_offset_r (bounds, offset->x, offset->y, &self->bounds);
|
|
self->progress = progress;
|
|
|
|
self->start.image = g_object_ref (start_image);
|
|
graphene_rect_offset_r (start_rect, offset->x, offset->y, &self->start.rect);
|
|
gsk_vulkan_normalize_tex_coords (&self->start.tex_rect, bounds, start_tex_rect);
|
|
|
|
self->end.image = g_object_ref (end_image);
|
|
graphene_rect_offset_r (end_rect, offset->x, offset->y, &self->end.rect);
|
|
gsk_vulkan_normalize_tex_coords (&self->end.tex_rect, bounds, end_tex_rect);
|
|
}
|