gpu: Handle alpha in image_op() wrapper

There are various places where the alpha is implicitly assumed to be
handled, so just handle it.

As a bonus, this simplifies a bunch of code and makes the texture node
rendering work with alpha.
This commit is contained in:
Benjamin Otte
2023-12-29 22:41:38 +01:00
parent 493b83ff24
commit 9947760d87
4 changed files with 20 additions and 3 deletions

View File

@@ -679,12 +679,24 @@ gsk_gpu_node_processor_image_op (GskGpuNodeProcessor *self,
{
gsk_gpu_straight_alpha_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, rect),
self->opacity,
self->desc,
descriptor,
rect,
&self->offset,
tex_rect);
}
else if (self->opacity < 1.0)
{
gsk_gpu_color_matrix_op_opacity (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, rect),
self->desc,
descriptor,
rect,
&self->offset,
tex_rect,
self->opacity);
}
else
{
gsk_gpu_texture_op (self->frame,
@@ -3561,7 +3573,7 @@ static const struct
},
[GSK_TEXTURE_NODE] = {
0,
0,
GSK_GPU_HANDLE_OPACITY,
gsk_gpu_node_processor_add_texture_node,
gsk_gpu_node_processor_create_texture_pattern,
},

View File

@@ -54,6 +54,7 @@ static const GskGpuShaderOpClass GSK_GPU_STRAIGHT_ALPHA_OP_CLASS = {
void
gsk_gpu_straight_alpha_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
float opacity,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,
@@ -71,4 +72,5 @@ gsk_gpu_straight_alpha_op (GskGpuFrame *frame,
gsk_gpu_rect_to_float (rect, offset, instance->rect);
gsk_gpu_rect_to_float (tex_rect, offset, instance->tex_rect);
instance->tex_id = descriptor;
instance->opacity = opacity;
}

View File

@@ -8,6 +8,7 @@ G_BEGIN_DECLS
void gsk_gpu_straight_alpha_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
float opacity,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,

View File

@@ -4,7 +4,7 @@ PASS(0) vec2 _pos;
PASS_FLAT(1) Rect _rect;
PASS(2) vec2 _tex_coord;
PASS_FLAT(3) uint _tex_id;
PASS_FLAT(4) float _opacity;
#ifdef GSK_VERTEX_SHADER
@@ -12,6 +12,7 @@ PASS_FLAT(3) uint _tex_id;
IN(0) vec4 in_rect;
IN(1) vec4 in_tex_rect;
IN(2) uint in_tex_id;
IN(3) float in_opacity;
void
run (out vec2 pos)
@@ -24,6 +25,7 @@ run (out vec2 pos)
_rect = r;
_tex_coord = rect_get_coord (rect_from_gsk (in_tex_rect), pos);
_tex_id = in_tex_id;
_opacity = in_opacity;
}
#endif
@@ -37,7 +39,7 @@ run (out vec4 color,
out vec2 position)
{
color = gsk_texture_straight_alpha (_tex_id, _tex_coord) *
rect_coverage (_rect, _pos);
rect_coverage (_rect, _pos) * _opacity;
position = _pos;
}