gpu: Add a color shader
We don't want to use the pattern shader for simple colors, slow GPUs do not like this at all.
This commit is contained in:
77
gsk/gpu/gskgpucolorop.c
Normal file
77
gsk/gpu/gskgpucolorop.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskgpucoloropprivate.h"
|
||||
|
||||
#include "gskgpuframeprivate.h"
|
||||
#include "gskgpuprintprivate.h"
|
||||
#include "gskgpushaderopprivate.h"
|
||||
#include "gskrectprivate.h"
|
||||
|
||||
#include "gpu/shaders/gskgpucolorinstance.h"
|
||||
|
||||
typedef struct _GskGpuColorOp GskGpuColorOp;
|
||||
|
||||
struct _GskGpuColorOp
|
||||
{
|
||||
GskGpuShaderOp op;
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_gpu_color_op_finish (GskGpuOp *op)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_gpu_color_op_print (GskGpuOp *op,
|
||||
GskGpuFrame *frame,
|
||||
GString *string,
|
||||
guint indent)
|
||||
{
|
||||
GskGpuShaderOp *shader = (GskGpuShaderOp *) op;
|
||||
GskGpuColorInstance *instance;
|
||||
|
||||
instance = (GskGpuColorInstance *) gsk_gpu_frame_get_vertex_data (frame, shader->vertex_offset);
|
||||
|
||||
gsk_gpu_print_op (string, indent, "color");
|
||||
gsk_gpu_print_rect (string, instance->rect);
|
||||
gsk_gpu_print_rgba (string, instance->color);
|
||||
gsk_gpu_print_newline (string);
|
||||
}
|
||||
|
||||
static const GskGpuShaderOpClass GSK_GPU_COLOR_OP_CLASS = {
|
||||
{
|
||||
GSK_GPU_OP_SIZE (GskGpuColorOp),
|
||||
GSK_GPU_STAGE_SHADER,
|
||||
gsk_gpu_color_op_finish,
|
||||
gsk_gpu_color_op_print,
|
||||
#ifdef GDK_RENDERING_VULKAN
|
||||
gsk_gpu_shader_op_vk_command,
|
||||
#endif
|
||||
gsk_gpu_shader_op_gl_command
|
||||
},
|
||||
"gskgpucolor",
|
||||
sizeof (GskGpuColorInstance),
|
||||
#ifdef GDK_RENDERING_VULKAN
|
||||
&gsk_gpu_color_info,
|
||||
#endif
|
||||
gsk_gpu_shader_op_no_images,
|
||||
gsk_gpu_color_setup_vao
|
||||
};
|
||||
|
||||
void
|
||||
gsk_gpu_color_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *offset,
|
||||
const GdkRGBA *color)
|
||||
{
|
||||
GskGpuColorInstance *instance;
|
||||
|
||||
gsk_gpu_shader_op_alloc (frame,
|
||||
&GSK_GPU_COLOR_OP_CLASS,
|
||||
clip,
|
||||
&instance);
|
||||
|
||||
gsk_gpu_rect_to_float (rect, offset, instance->rect);
|
||||
gsk_gpu_rgba_to_float (color, instance->color);
|
||||
}
|
||||
17
gsk/gpu/gskgpucoloropprivate.h
Normal file
17
gsk/gpu/gskgpucoloropprivate.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "gskgputypesprivate.h"
|
||||
|
||||
#include <graphene.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void gsk_gpu_color_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *offset,
|
||||
const GdkRGBA *color);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "gskgpubluropprivate.h"
|
||||
#include "gskgpuclipprivate.h"
|
||||
#include "gskgpucolorizeopprivate.h"
|
||||
#include "gskgpucoloropprivate.h"
|
||||
#include "gskgpudeviceprivate.h"
|
||||
#include "gskgpuframeprivate.h"
|
||||
#include "gskgpuglobalsopprivate.h"
|
||||
@@ -940,6 +941,17 @@ gsk_gpu_node_processor_add_transform_node (GskGpuNodeProcessor *self,
|
||||
self->pending_globals |= GSK_GPU_GLOBAL_MATRIX | GSK_GPU_GLOBAL_SCALE | GSK_GPU_GLOBAL_CLIP;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self,
|
||||
GskRenderNode *node)
|
||||
{
|
||||
gsk_gpu_color_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
|
||||
&node->bounds,
|
||||
&self->offset,
|
||||
gsk_color_node_get_color (node));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_gpu_node_processor_create_color_pattern (GskGpuPatternWriter *self,
|
||||
GskRenderNode *node)
|
||||
@@ -1571,7 +1583,7 @@ static const struct
|
||||
},
|
||||
[GSK_COLOR_NODE] = {
|
||||
0,
|
||||
gsk_gpu_node_processor_add_node_as_pattern,
|
||||
gsk_gpu_node_processor_add_color_node,
|
||||
gsk_gpu_node_processor_create_color_pattern,
|
||||
},
|
||||
[GSK_LINEAR_GRADIENT_NODE] = {
|
||||
|
||||
40
gsk/gpu/shaders/gskgpucolor.glsl
Normal file
40
gsk/gpu/shaders/gskgpucolor.glsl
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
PASS_FLAT(1) Rect _rect;
|
||||
PASS_FLAT(2) vec4 _color;
|
||||
|
||||
|
||||
|
||||
#ifdef GSK_VERTEX_SHADER
|
||||
|
||||
IN(0) vec4 in_rect;
|
||||
IN(1) vec4 in_color;
|
||||
|
||||
void
|
||||
run (out vec2 pos)
|
||||
{
|
||||
Rect r = rect_from_gsk (in_rect);
|
||||
|
||||
pos = rect_get_position (r);
|
||||
|
||||
_pos = pos;
|
||||
_rect = r;
|
||||
_color = color_premultiply (in_color);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef GSK_FRAGMENT_SHADER
|
||||
|
||||
void
|
||||
run (out vec4 color,
|
||||
out vec2 position)
|
||||
{
|
||||
color = _color * rect_coverage (_rect, _pos);
|
||||
position = _pos;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,6 +14,7 @@ gsk_private_gpu_include_shaders = files([
|
||||
gsk_private_gpu_shaders = files([
|
||||
'gskgpublur.glsl',
|
||||
'gskgpuborder.glsl',
|
||||
'gskgpucolor.glsl',
|
||||
'gskgpucolorize.glsl',
|
||||
'gskgputexture.glsl',
|
||||
'gskgpuuber.glsl',
|
||||
|
||||
@@ -78,6 +78,7 @@ gsk_private_sources = files([
|
||||
'gpu/gskgpubufferwriter.c',
|
||||
'gpu/gskgpuclip.c',
|
||||
'gpu/gskgpucolorizeop.c',
|
||||
'gpu/gskgpucolorop.c',
|
||||
'gpu/gskgpudownloadop.c',
|
||||
'gpu/gskgpudevice.c',
|
||||
'gpu/gskgpuframe.c',
|
||||
|
||||
Reference in New Issue
Block a user