gpu: Make color op obey ccs
This makes use of the GskGpuColorStates by setting the ccs as output colorstate and the color's colorstate as alternative color state. The shader adaption is very straightforward because of that.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "gskgpucoloropprivate.h"
|
||||
|
||||
#include "gskgpucolorstatesprivate.h"
|
||||
#include "gskgpuframeprivate.h"
|
||||
#include "gskgpuprintprivate.h"
|
||||
#include "gskgpushaderopprivate.h"
|
||||
@@ -51,20 +52,21 @@ static const GskGpuShaderOpClass GSK_GPU_COLOR_OP_CLASS = {
|
||||
void
|
||||
gsk_gpu_color_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
GskGpuColorStates color_states,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *offset,
|
||||
const GdkRGBA *color)
|
||||
const float color[4])
|
||||
{
|
||||
GskGpuColorInstance *instance;
|
||||
|
||||
gsk_gpu_shader_op_alloc (frame,
|
||||
&GSK_GPU_COLOR_OP_CLASS,
|
||||
DEFAULT_COLOR_STATES,
|
||||
color_states,
|
||||
0,
|
||||
clip,
|
||||
NULL,
|
||||
&instance);
|
||||
|
||||
gsk_gpu_rect_to_float (rect, offset, instance->rect);
|
||||
gsk_gpu_rgba_to_float (color, instance->color);
|
||||
gsk_gpu_color_to_float (color, instance->color);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@ G_BEGIN_DECLS
|
||||
|
||||
void gsk_gpu_color_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
GskGpuColorStates color_states,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *offset,
|
||||
const GdkRGBA *color);
|
||||
const float color[4]);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -266,6 +266,16 @@ gsk_gpu_node_processor_color_states_self (GskGpuNodeProcessor *self)
|
||||
self->ccs,
|
||||
TRUE);
|
||||
}
|
||||
|
||||
static inline GskGpuColorStates
|
||||
gsk_gpu_node_processor_color_states_for_rgba (GskGpuNodeProcessor *self)
|
||||
{
|
||||
return gsk_gpu_color_states_create (self->ccs,
|
||||
TRUE,
|
||||
GDK_COLOR_STATE_SRGB,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
static guint32
|
||||
gsk_gpu_node_processor_add_image (GskGpuNodeProcessor *self,
|
||||
GskGpuImage *image,
|
||||
@@ -1523,9 +1533,10 @@ gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self,
|
||||
/* Yuck, rounded clip and modelview. I give up. */
|
||||
gsk_gpu_color_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&node->bounds,
|
||||
&self->offset,
|
||||
gsk_color_node_get_color (node));
|
||||
GSK_RGBA_TO_VEC4 (color));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1545,9 +1556,10 @@ gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self,
|
||||
{
|
||||
gsk_gpu_color_op (self->frame,
|
||||
shader_clip,
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&clipped,
|
||||
graphene_point_zero (),
|
||||
color);
|
||||
GSK_RGBA_TO_VEC4 (color));
|
||||
return;
|
||||
}
|
||||
cover = GRAPHENE_RECT_INIT (int_clipped.x / scale_x, int_clipped.y / scale_y,
|
||||
@@ -1555,33 +1567,37 @@ gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self,
|
||||
if (clipped.origin.x != cover.origin.x)
|
||||
gsk_gpu_color_op (self->frame,
|
||||
shader_clip,
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&GRAPHENE_RECT_INIT (clipped.origin.x, clipped.origin.y, cover.origin.x - clipped.origin.x, clipped.size.height),
|
||||
graphene_point_zero (),
|
||||
color);
|
||||
GSK_RGBA_TO_VEC4 (color));
|
||||
if (clipped.origin.y != cover.origin.y)
|
||||
gsk_gpu_color_op (self->frame,
|
||||
shader_clip,
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&GRAPHENE_RECT_INIT (clipped.origin.x, clipped.origin.y, clipped.size.width, cover.origin.y - clipped.origin.y),
|
||||
graphene_point_zero (),
|
||||
color);
|
||||
GSK_RGBA_TO_VEC4 (color));
|
||||
if (clipped.origin.x + clipped.size.width != cover.origin.x + cover.size.width)
|
||||
gsk_gpu_color_op (self->frame,
|
||||
shader_clip,
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&GRAPHENE_RECT_INIT (cover.origin.x + cover.size.width,
|
||||
clipped.origin.y,
|
||||
clipped.origin.x + clipped.size.width - cover.origin.x - cover.size.width,
|
||||
clipped.size.height),
|
||||
graphene_point_zero (),
|
||||
color);
|
||||
GSK_RGBA_TO_VEC4 (color));
|
||||
if (clipped.origin.y + clipped.size.height != cover.origin.y + cover.size.height)
|
||||
gsk_gpu_color_op (self->frame,
|
||||
shader_clip,
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&GRAPHENE_RECT_INIT (clipped.origin.x,
|
||||
cover.origin.y + cover.size.height,
|
||||
clipped.size.width,
|
||||
clipped.origin.y + clipped.size.height - cover.origin.y - cover.size.height),
|
||||
graphene_point_zero (),
|
||||
color);
|
||||
GSK_RGBA_TO_VEC4 (color));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1594,9 +1610,10 @@ gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self,
|
||||
|
||||
gsk_gpu_color_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&node->bounds,
|
||||
&self->offset,
|
||||
&GDK_RGBA_INIT_ALPHA (color, self->opacity));
|
||||
GSK_RGBA_TO_VEC4_ALPHA (color, self->opacity));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -2308,9 +2325,10 @@ gsk_gpu_node_processor_add_gl_shader_node (GskGpuNodeProcessor *self,
|
||||
|
||||
gsk_gpu_color_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
|
||||
gsk_gpu_node_processor_color_states_for_rgba (self),
|
||||
&node->bounds,
|
||||
&self->offset,
|
||||
&GDK_RGBA_INIT_ALPHA (&pink, self->opacity));
|
||||
GSK_RGBA_TO_VEC4_ALPHA (&pink, self->opacity));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -3108,9 +3126,10 @@ gsk_gpu_node_processor_add_subsurface_node (GskGpuNodeProcessor *self,
|
||||
|
||||
gsk_gpu_color_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
|
||||
gsk_gpu_node_processor_color_states_self (self),
|
||||
&node->bounds,
|
||||
&self->offset,
|
||||
&GDK_RGBA_WHITE);
|
||||
(float[4]) { 1, 1, 1, 1 });
|
||||
|
||||
self->blend = GSK_GPU_BLEND_OVER;
|
||||
self->pending_globals |= GSK_GPU_GLOBAL_BLEND;
|
||||
|
||||
@@ -76,6 +76,18 @@ gsk_gpu_rgba_to_float (const GdkRGBA *rgba,
|
||||
values[3] = rgba->alpha;
|
||||
}
|
||||
|
||||
#define GSK_RGBA_TO_VEC4(_color) (float[4]) { (_color)->red, (_color)->green, (_color)->blue, (_color)->alpha }
|
||||
#define GSK_RGBA_TO_VEC4_ALPHA(_color, _alpha) (float[4]) { (_color)->red, (_color)->green, (_color)->blue, (_color)->alpha * (_alpha) }
|
||||
|
||||
static inline void
|
||||
gsk_gpu_color_to_float (const float color[4],
|
||||
float values[4])
|
||||
{
|
||||
values[0] = color[0];
|
||||
values[1] = color[1];
|
||||
values[2] = color[2];
|
||||
values[3] = color[3];
|
||||
}
|
||||
#include <graphene.h>
|
||||
|
||||
static inline void
|
||||
|
||||
@@ -20,7 +20,7 @@ run (out vec2 pos)
|
||||
|
||||
_pos = pos;
|
||||
_rect = r;
|
||||
_color = color_premultiply (in_color);
|
||||
_color = output_color_from_alt (in_color);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -33,7 +33,7 @@ void
|
||||
run (out vec4 color,
|
||||
out vec2 position)
|
||||
{
|
||||
color = _color * rect_coverage (_rect, _pos);
|
||||
color = output_color_alpha (_color, rect_coverage (_rect, _pos));
|
||||
position = _pos;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user