vulkan: Factor out call to opacity op
I want to reuse it for crossfades (see next commit).
This commit is contained in:
@@ -144,3 +144,35 @@ gsk_vulkan_color_matrix_op (GskVulkanRenderPass *render_pass,
|
||||
self->color_matrix = *color_matrix;
|
||||
self->color_offset = *color_offset;
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_color_matrix_op_opacity (GskVulkanRenderPass *render_pass,
|
||||
const char *clip_type,
|
||||
GskVulkanImage *image,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *offset,
|
||||
const graphene_rect_t *tex_rect,
|
||||
float opacity)
|
||||
{
|
||||
graphene_matrix_t color_matrix;
|
||||
graphene_vec4_t color_offset;
|
||||
|
||||
graphene_matrix_init_from_float (&color_matrix,
|
||||
(float[16]) {
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, opacity
|
||||
});
|
||||
graphene_vec4_init (&color_offset, 0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
gsk_vulkan_color_matrix_op (render_pass,
|
||||
clip_type,
|
||||
image,
|
||||
rect,
|
||||
offset,
|
||||
tex_rect,
|
||||
&color_matrix,
|
||||
&color_offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,14 @@ void gsk_vulkan_color_matrix_op (GskVulk
|
||||
const graphene_matrix_t *color_matrix,
|
||||
const graphene_vec4_t *color_offset);
|
||||
|
||||
void gsk_vulkan_color_matrix_op_opacity (GskVulkanRenderPass *render_pass,
|
||||
const char *clip_type,
|
||||
GskVulkanImage *image,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *offset,
|
||||
const graphene_rect_t *tex_rect,
|
||||
float opacity);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
159
gsk/vulkan/gskvulkancrossfadeop.c
Normal file
159
gsk/vulkan/gskvulkancrossfadeop.c
Normal file
@@ -0,0 +1,159 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkancrossfadeopprivate.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_upload (GskVulkanOp *op,
|
||||
GskVulkanRenderPass *pass,
|
||||
GskVulkanRender *render,
|
||||
GskVulkanUploader *uploader,
|
||||
const graphene_rect_t *clip,
|
||||
const graphene_vec2_t *scale)
|
||||
{
|
||||
}
|
||||
|
||||
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 VkPipeline
|
||||
gsk_vulkan_cross_fade_op_get_pipeline (GskVulkanOp *op)
|
||||
{
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
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_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_get_pipeline,
|
||||
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);
|
||||
}
|
||||
21
gsk/vulkan/gskvulkancrossfadeopprivate.h
Normal file
21
gsk/vulkan/gskvulkancrossfadeopprivate.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "gskvulkanopprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
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);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkancrossfadepipelineprivate.h"
|
||||
|
||||
#include "vulkan/resources/cross-fade.vert.h"
|
||||
|
||||
struct _GskVulkanCrossFadePipeline
|
||||
{
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GskVulkanCrossFadePipeline, gsk_vulkan_cross_fade_pipeline, GSK_TYPE_VULKAN_PIPELINE)
|
||||
|
||||
static const VkPipelineVertexInputStateCreateInfo *
|
||||
gsk_vulkan_cross_fade_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
|
||||
{
|
||||
return &gsk_vulkan_cross_fade_info;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_cross_fade_pipeline_finalize (GObject *gobject)
|
||||
{
|
||||
//GskVulkanCrossFadePipeline *self = GSK_VULKAN_BLUR_PIPELINE (gobject);
|
||||
|
||||
G_OBJECT_CLASS (gsk_vulkan_cross_fade_pipeline_parent_class)->finalize (gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_cross_fade_pipeline_class_init (GskVulkanCrossFadePipelineClass *klass)
|
||||
{
|
||||
GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
|
||||
|
||||
G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_cross_fade_pipeline_finalize;
|
||||
|
||||
pipeline_class->get_input_state_create_info = gsk_vulkan_cross_fade_pipeline_get_input_state_create_info;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_cross_fade_pipeline_init (GskVulkanCrossFadePipeline *self)
|
||||
{
|
||||
}
|
||||
|
||||
GskVulkanPipeline *
|
||||
gsk_vulkan_cross_fade_pipeline_new (GdkVulkanContext *context,
|
||||
VkPipelineLayout layout,
|
||||
const char *shader_name,
|
||||
VkRenderPass render_pass)
|
||||
{
|
||||
return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_CROSS_FADE_PIPELINE, context, layout, shader_name, render_pass);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_cross_fade_pipeline_collect_vertex_data (GskVulkanCrossFadePipeline *pipeline,
|
||||
guchar *data,
|
||||
guint32 start_tex_id,
|
||||
guint32 end_tex_id,
|
||||
const graphene_point_t *offset,
|
||||
const graphene_rect_t *bounds,
|
||||
const graphene_rect_t *start_bounds,
|
||||
const graphene_rect_t *end_bounds,
|
||||
const graphene_rect_t *start_tex_rect,
|
||||
const graphene_rect_t *end_tex_rect,
|
||||
double progress)
|
||||
{
|
||||
GskVulkanCrossFadeInstance *instance = (GskVulkanCrossFadeInstance *) data;
|
||||
|
||||
instance->rect[0] = bounds->origin.x + offset->x;
|
||||
instance->rect[1] = bounds->origin.y + offset->y;
|
||||
instance->rect[2] = bounds->size.width;
|
||||
instance->rect[3] = bounds->size.height;
|
||||
|
||||
instance->start_rect[0] = start_bounds->origin.x + offset->x;
|
||||
instance->start_rect[1] = start_bounds->origin.y + offset->y;
|
||||
instance->start_rect[2] = start_bounds->size.width;
|
||||
instance->start_rect[3] = start_bounds->size.height;
|
||||
|
||||
instance->end_rect[0] = end_bounds->origin.x + offset->x;
|
||||
instance->end_rect[1] = end_bounds->origin.y + offset->y;
|
||||
instance->end_rect[2] = end_bounds->size.width;
|
||||
instance->end_rect[3] = end_bounds->size.height;
|
||||
|
||||
instance->start_tex_rect[0] = start_tex_rect->origin.x;
|
||||
instance->start_tex_rect[1] = start_tex_rect->origin.y;
|
||||
instance->start_tex_rect[2] = start_tex_rect->size.width;
|
||||
instance->start_tex_rect[3] = start_tex_rect->size.height;
|
||||
|
||||
instance->end_tex_rect[0] = end_tex_rect->origin.x;
|
||||
instance->end_tex_rect[1] = end_tex_rect->origin.y;
|
||||
instance->end_tex_rect[2] = end_tex_rect->size.width;
|
||||
instance->end_tex_rect[3] = end_tex_rect->size.height;
|
||||
|
||||
instance->start_tex_id = start_tex_id;
|
||||
instance->end_tex_id = end_tex_id;
|
||||
instance->progress = progress;
|
||||
}
|
||||
|
||||
gsize
|
||||
gsk_vulkan_cross_fade_pipeline_draw (GskVulkanCrossFadePipeline *pipeline,
|
||||
VkCommandBuffer command_buffer,
|
||||
gsize offset,
|
||||
gsize n_commands)
|
||||
{
|
||||
vkCmdDraw (command_buffer,
|
||||
6, n_commands,
|
||||
0, offset);
|
||||
|
||||
return n_commands;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <graphene.h>
|
||||
|
||||
#include "gskvulkanpipelineprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanCrossFadePipelineLayout GskVulkanCrossFadePipelineLayout;
|
||||
|
||||
#define GSK_TYPE_VULKAN_CROSS_FADE_PIPELINE (gsk_vulkan_cross_fade_pipeline_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GskVulkanCrossFadePipeline, gsk_vulkan_cross_fade_pipeline, GSK, VULKAN_CROSS_FADE_PIPELINE, GskVulkanPipeline)
|
||||
|
||||
GskVulkanPipeline * gsk_vulkan_cross_fade_pipeline_new (GdkVulkanContext *context,
|
||||
VkPipelineLayout layout,
|
||||
const char *shader_name,
|
||||
VkRenderPass render_pass);
|
||||
|
||||
void gsk_vulkan_cross_fade_pipeline_collect_vertex_data (GskVulkanCrossFadePipeline *pipeline,
|
||||
guchar *data,
|
||||
guint32 start_tex_id,
|
||||
guint32 end_tex_id,
|
||||
const graphene_point_t *offset,
|
||||
const graphene_rect_t *bounds,
|
||||
const graphene_rect_t *start_bounds,
|
||||
const graphene_rect_t *end_bounds,
|
||||
const graphene_rect_t *start_tex_rect,
|
||||
const graphene_rect_t *end_tex_rect,
|
||||
double progress);
|
||||
gsize gsk_vulkan_cross_fade_pipeline_draw (GskVulkanCrossFadePipeline *pipeline,
|
||||
VkCommandBuffer command_buffer,
|
||||
gsize offset,
|
||||
gsize n_commands);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -886,23 +886,13 @@ gsk_vulkan_render_pass_add_opacity_node (GskVulkanRenderPass *self,
|
||||
if (image == NULL)
|
||||
return TRUE;
|
||||
|
||||
graphene_matrix_init_from_float (&color_matrix,
|
||||
(float[16]) {
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, gsk_opacity_node_get_opacity (node)
|
||||
});
|
||||
graphene_vec4_init (&color_offset, 0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
gsk_vulkan_color_matrix_op (self,
|
||||
gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &node->bounds),
|
||||
image,
|
||||
&node->bounds,
|
||||
&state->offset,
|
||||
&tex_rect,
|
||||
&color_matrix,
|
||||
&color_offset);
|
||||
gsk_vulkan_color_matrix_op_opacity (self,
|
||||
gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &node->bounds),
|
||||
image,
|
||||
&node->bounds,
|
||||
&state->offset,
|
||||
&tex_rect,
|
||||
gsk_opacity_node_get_opacity (node));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user