2016-03-17 13:48:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskglrendererprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
|
|
|
#include "gskenums.h"
|
2016-07-08 15:21:13 +00:00
|
|
|
#include "gskgldriverprivate.h"
|
2016-07-12 13:50:48 +00:00
|
|
|
#include "gskglprofilerprivate.h"
|
2016-08-03 15:51:21 +00:00
|
|
|
#include "gskprofilerprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
#include "gskrendernodeprivate.h"
|
2016-07-03 20:12:22 +00:00
|
|
|
#include "gskshaderbuilderprivate.h"
|
2017-11-18 13:30:57 +00:00
|
|
|
#include "gskglglyphcacheprivate.h"
|
2017-11-22 20:02:50 +00:00
|
|
|
#include "gskglrenderopsprivate.h"
|
2017-12-28 15:41:32 +00:00
|
|
|
#include "gskcairoblurprivate.h"
|
2018-07-08 18:08:15 +00:00
|
|
|
#include "gskglshadowcacheprivate.h"
|
2018-12-02 09:20:59 +00:00
|
|
|
#include "gskglnodesampleprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
#include "gskprivate.h"
|
|
|
|
|
2018-03-05 13:38:38 +00:00
|
|
|
#include "gdk/gdkgltextureprivate.h"
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
#include <epoxy/gl.h>
|
2017-11-18 13:30:57 +00:00
|
|
|
#include <cairo-ft.h>
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-01 15:00:31 +00:00
|
|
|
#define SHADER_VERSION_GLES 100
|
|
|
|
#define SHADER_VERSION_GL2_LEGACY 110
|
|
|
|
#define SHADER_VERSION_GL3_LEGACY 130
|
2016-07-03 21:54:30 +00:00
|
|
|
#define SHADER_VERSION_GL3 150
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
#define ORTHO_NEAR_PLANE -10000
|
|
|
|
#define ORTHO_FAR_PLANE 10000
|
|
|
|
|
|
|
|
#define HIGHLIGHT_FALLBACK 0
|
2017-11-22 10:32:23 +00:00
|
|
|
#define DEBUG_OPS 0
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
#define SHADOW_EXTRA_SIZE 4
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
#if DEBUG_OPS
|
|
|
|
#define OP_PRINT(format, ...) g_print(format, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define OP_PRINT(format, ...)
|
|
|
|
#endif
|
|
|
|
|
2017-12-01 12:56:56 +00:00
|
|
|
#define INIT_PROGRAM_UNIFORM_LOCATION(program_name, uniform_basename) \
|
2017-11-22 10:32:23 +00:00
|
|
|
G_STMT_START{\
|
2017-11-30 17:47:55 +00:00
|
|
|
self->program_name ## _program.program_name.uniform_basename ## _location = \
|
|
|
|
glGetUniformLocation(self->program_name ## _program.id, "u_" #uniform_basename);\
|
|
|
|
g_assert_cmpint (self->program_name ## _program.program_name.uniform_basename ## _location, >, -1); \
|
2017-11-22 10:32:23 +00:00
|
|
|
}G_STMT_END
|
|
|
|
|
2017-11-30 17:47:55 +00:00
|
|
|
#define INIT_COMMON_UNIFORM_LOCATION(program_ptr, uniform_basename) \
|
|
|
|
G_STMT_START{\
|
|
|
|
program_ptr->uniform_basename ## _location = \
|
|
|
|
glGetUniformLocation(program_ptr->id, "u_" #uniform_basename);\
|
|
|
|
}G_STMT_END
|
|
|
|
|
2018-05-12 04:57:59 +00:00
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
print_render_node_tree (GskRenderNode *root, int level)
|
|
|
|
{
|
|
|
|
#define INDENT 4
|
|
|
|
const guint type = gsk_render_node_get_node_type (root);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GSK_CONTAINER_NODE:
|
|
|
|
g_print ("%*s Container\n", level * INDENT, " ");
|
|
|
|
for (i = 0; i < gsk_container_node_get_n_children (root); i++)
|
|
|
|
print_render_node_tree (gsk_container_node_get_child (root, i), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_OFFSET_NODE:
|
|
|
|
g_print ("%*s Offset\n", level * INDENT, " ");
|
|
|
|
print_render_node_tree (gsk_offset_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TRANSFORM_NODE:
|
|
|
|
g_print ("%*s Transform\n", level * INDENT, " ");
|
|
|
|
print_render_node_tree (gsk_transform_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_COLOR_MATRIX_NODE:
|
|
|
|
g_print ("%*s Color Matrix\n", level * INDENT, " ");
|
|
|
|
print_render_node_tree (gsk_color_matrix_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_CROSS_FADE_NODE:
|
|
|
|
g_print ("%*s Crossfade(%.2f)\n", level * INDENT, " ",
|
|
|
|
gsk_cross_fade_node_get_progress (root));
|
|
|
|
print_render_node_tree (gsk_cross_fade_node_get_start_child (root), level + 1);
|
|
|
|
print_render_node_tree (gsk_cross_fade_node_get_end_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TEXT_NODE:
|
|
|
|
g_print ("%*s Text\n", level * INDENT, " ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_SHADOW_NODE:
|
|
|
|
g_print ("%*s Shadow\n", level * INDENT, " ");
|
|
|
|
print_render_node_tree (gsk_shadow_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TEXTURE_NODE:
|
|
|
|
g_print ("%*s Texture %p\n", level * INDENT, " ", gsk_texture_node_get_texture (root));
|
|
|
|
break;
|
|
|
|
|
2018-12-02 12:39:55 +00:00
|
|
|
case GSK_DEBUG_NODE:
|
|
|
|
g_print ("%*s Debug: %s\n", level * INDENT, " ", gsk_debug_node_get_message (root));
|
|
|
|
print_render_node_tree (gsk_debug_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_CLIP_NODE:
|
|
|
|
g_print ("%*s Clip (%f, %f, %f, %f):\n", level * INDENT, " ",
|
|
|
|
root->bounds.origin.x, root->bounds.origin.y, root->bounds.size.width, root->bounds.size.height);
|
|
|
|
print_render_node_tree (gsk_clip_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
2018-05-12 04:57:59 +00:00
|
|
|
default:
|
2018-12-02 12:39:55 +00:00
|
|
|
g_print ("%*s %s\n", level * INDENT, " ", root->node_class->type_name);
|
2018-05-12 04:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef INDENT
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
dump_framebuffer (const char *filename, int w, int h)
|
|
|
|
{
|
|
|
|
int stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, w);
|
|
|
|
guchar *data = g_malloc (h * stride);
|
|
|
|
cairo_surface_t *s;
|
|
|
|
|
|
|
|
glReadPixels (0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, data);
|
2017-11-22 20:02:50 +00:00
|
|
|
s = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, w, h, stride);
|
2017-11-03 12:09:02 +00:00
|
|
|
cairo_surface_write_to_png (s, filename);
|
|
|
|
|
|
|
|
cairo_surface_destroy (s);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:56:56 +00:00
|
|
|
static gboolean
|
2017-11-18 13:30:57 +00:00
|
|
|
font_has_color_glyphs (const PangoFont *font)
|
|
|
|
{
|
|
|
|
cairo_scaled_font_t *scaled_font;
|
|
|
|
gboolean has_color = FALSE;
|
|
|
|
|
|
|
|
scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)font);
|
|
|
|
if (cairo_scaled_font_get_type (scaled_font) == CAIRO_FONT_TYPE_FT)
|
|
|
|
{
|
|
|
|
FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
|
|
|
|
has_color = (FT_HAS_COLOR (ft_face) != 0);
|
|
|
|
cairo_ft_scaled_font_unlock_face (scaled_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
return has_color;
|
|
|
|
}
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
static void
|
|
|
|
get_gl_scaling_filters (GskRenderNode *node,
|
|
|
|
int *min_filter_r,
|
|
|
|
int *mag_filter_r)
|
|
|
|
{
|
|
|
|
*min_filter_r = GL_LINEAR;
|
|
|
|
*mag_filter_r = GL_LINEAR;
|
|
|
|
}
|
|
|
|
|
2017-11-30 15:48:03 +00:00
|
|
|
static inline void
|
|
|
|
rgba_to_float (const GdkRGBA *c,
|
|
|
|
float *f)
|
|
|
|
{
|
|
|
|
f[0] = c->red;
|
|
|
|
f[1] = c->green;
|
|
|
|
f[2] = c->blue;
|
|
|
|
f[3] = c->alpha;
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:46:29 +00:00
|
|
|
static inline void
|
|
|
|
sort_border_sides (const GdkRGBA *colors,
|
|
|
|
int *indices)
|
|
|
|
{
|
|
|
|
gboolean done[4] = {0, 0, 0, 0};
|
|
|
|
int i, k;
|
|
|
|
int cur = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i ++)
|
|
|
|
{
|
|
|
|
if (done[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
indices[cur] = i;
|
|
|
|
done[i] = TRUE;
|
|
|
|
cur ++;
|
|
|
|
|
|
|
|
for (k = i + 1; k < 4; k ++)
|
|
|
|
{
|
|
|
|
if (gdk_rgba_equal (&colors[k], &colors[i]))
|
|
|
|
{
|
|
|
|
indices[cur] = k;
|
|
|
|
done[k] = TRUE;
|
|
|
|
cur ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur >= 4)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 15:07:18 +00:00
|
|
|
static inline gboolean
|
|
|
|
color_matrix_modifies_alpha (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
const graphene_matrix_t *matrix = gsk_color_matrix_node_peek_color_matrix (node);
|
|
|
|
const graphene_vec4_t *offset = gsk_color_matrix_node_peek_color_offset (node);
|
|
|
|
graphene_vec4_t row3;
|
|
|
|
|
|
|
|
if (graphene_vec4_get_w (offset) != 0.0f)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
graphene_matrix_get_row (matrix, 3, &row3);
|
|
|
|
|
2018-05-27 16:05:00 +00:00
|
|
|
return !graphene_vec4_equal (graphene_vec4_w_axis (), &row3);
|
2017-12-06 15:07:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
static inline void
|
|
|
|
gsk_rounded_rect_shrink_to_minimum (GskRoundedRect *self)
|
|
|
|
{
|
|
|
|
self->bounds.size.width = ceilf (MAX (MAX (self->corner[0].width, self->corner[1].width),
|
|
|
|
MAX (self->corner[2].width, self->corner[3].width)) * 2);
|
|
|
|
self->bounds.size.height = ceilf (MAX (MAX (self->corner[0].height, self->corner[1].height),
|
|
|
|
MAX (self->corner[2].height, self->corner[3].height)) * 2);
|
|
|
|
}
|
|
|
|
|
2018-11-29 07:09:02 +00:00
|
|
|
static inline gboolean
|
|
|
|
node_supports_transform (GskRenderNode *node)
|
|
|
|
{
|
|
|
|
/* Some nodes can't handle non-trivial transforms without being
|
|
|
|
* rendered to a texture (e.g. rotated clips, etc.). Some however
|
|
|
|
* work just fine, mostly because they already draw their child
|
|
|
|
* to a texture and just render the texture manipulated in some
|
|
|
|
* way, think opacity or color matrix. */
|
|
|
|
const guint node_type = gsk_render_node_get_node_type (node);
|
|
|
|
|
|
|
|
switch (node_type)
|
|
|
|
{
|
|
|
|
case GSK_COLOR_NODE:
|
|
|
|
case GSK_OPACITY_NODE:
|
|
|
|
case GSK_COLOR_MATRIX_NODE:
|
|
|
|
case GSK_TEXTURE_NODE:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-24 09:18:51 +00:00
|
|
|
static void gsk_gl_renderer_setup_render_mode (GskGLRenderer *self);
|
2017-11-24 09:43:17 +00:00
|
|
|
static void add_offscreen_ops (GskGLRenderer *self,
|
2018-12-02 08:05:50 +00:00
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GskRenderNode *child_node,
|
|
|
|
int *texture_id,
|
|
|
|
gboolean *is_offscreen,
|
|
|
|
gboolean force_offscreen,
|
|
|
|
gboolean reset_clip);
|
2017-12-08 12:12:43 +00:00
|
|
|
static void gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder);
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
struct _GskGLRenderer
|
|
|
|
{
|
|
|
|
GskRenderer parent_instance;
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
int scale_factor;
|
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
GdkGLContext *gl_context;
|
2016-07-08 15:21:13 +00:00
|
|
|
GskGLDriver *gl_driver;
|
2016-07-12 13:50:48 +00:00
|
|
|
GskGLProfiler *gl_profiler;
|
2016-07-04 12:46:22 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
union {
|
2017-11-22 20:02:50 +00:00
|
|
|
Program programs[GL_N_PROGRAMS];
|
2017-11-22 10:32:23 +00:00
|
|
|
struct {
|
|
|
|
Program blit_program;
|
|
|
|
Program color_program;
|
|
|
|
Program coloring_program;
|
|
|
|
Program color_matrix_program;
|
|
|
|
Program linear_gradient_program;
|
2017-11-25 07:56:50 +00:00
|
|
|
Program blur_program;
|
2017-11-30 15:48:03 +00:00
|
|
|
Program inset_shadow_program;
|
2017-12-01 07:30:11 +00:00
|
|
|
Program outset_shadow_program;
|
2018-01-15 09:55:40 +00:00
|
|
|
Program unblurred_outset_shadow_program;
|
2017-12-01 10:55:10 +00:00
|
|
|
Program border_program;
|
2017-12-11 07:22:28 +00:00
|
|
|
Program cross_fade_program;
|
2017-11-22 10:32:23 +00:00
|
|
|
};
|
|
|
|
};
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
GArray *render_ops;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-18 13:30:57 +00:00
|
|
|
GskGLGlyphCache glyph_cache;
|
2018-07-08 18:08:15 +00:00
|
|
|
GskGLShadowCache shadow_cache;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-12-03 15:54:34 +00:00
|
|
|
struct {
|
|
|
|
GQuark frames;
|
|
|
|
GQuark draw_calls;
|
|
|
|
} profile_counters;
|
|
|
|
struct {
|
|
|
|
GQuark cpu_time;
|
|
|
|
GQuark gpu_time;
|
|
|
|
} profile_timers;
|
2016-08-03 15:51:21 +00:00
|
|
|
#endif
|
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
cairo_region_t *render_region;
|
2016-03-17 13:48:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GskGLRendererClass
|
|
|
|
{
|
|
|
|
GskRendererClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskGLRenderer, gsk_gl_renderer, GSK_TYPE_RENDERER)
|
|
|
|
|
2018-12-02 13:31:57 +00:00
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
add_rect_ops (RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *r)
|
|
|
|
{
|
|
|
|
const float min_x = r->origin.x;
|
|
|
|
const float min_y = r->origin.y;
|
|
|
|
const float max_x = min_x + r->size.width;
|
|
|
|
const float max_y = min_y + r->size.height;
|
|
|
|
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
add_rect_outline_ops (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *rect)
|
|
|
|
{
|
|
|
|
ops_set_program (builder, &self->color_program);
|
|
|
|
ops_set_color (builder, &(GdkRGBA) { 1, 0, 0, 1 });
|
|
|
|
|
|
|
|
add_rect_ops (builder,
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x, rect->origin.y,
|
|
|
|
1, rect->size.height));
|
|
|
|
add_rect_ops (builder,
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x, rect->origin.y,
|
|
|
|
rect->size.width, 1));
|
|
|
|
add_rect_ops (builder,
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x + rect->size.width - 1, rect->origin.y,
|
|
|
|
1, rect->size.height));
|
|
|
|
|
|
|
|
add_rect_ops (builder,
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x, rect->origin.y + rect->size.height - 1,
|
|
|
|
rect->size.width, 1));
|
|
|
|
}
|
|
|
|
|
2017-12-09 08:41:52 +00:00
|
|
|
static inline void
|
|
|
|
rounded_rect_to_floats (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskRoundedRect *rect,
|
|
|
|
float *outline,
|
|
|
|
float *corner_widths,
|
|
|
|
float *corner_heights)
|
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2017-12-09 08:41:52 +00:00
|
|
|
int i;
|
|
|
|
graphene_rect_t transformed_bounds;
|
|
|
|
|
2018-12-02 10:04:15 +00:00
|
|
|
ops_transform_bounds_modelview (builder, &rect->bounds, &transformed_bounds);
|
2017-12-09 08:41:52 +00:00
|
|
|
|
|
|
|
outline[0] = transformed_bounds.origin.x;
|
|
|
|
outline[1] = transformed_bounds.origin.y;
|
|
|
|
outline[2] = transformed_bounds.size.width;
|
|
|
|
outline[3] = transformed_bounds.size.height;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
corner_widths[i] = rect->corner[i].width * scale;
|
|
|
|
corner_heights[i] = rect->corner[i].height * scale;
|
2017-12-09 08:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 08:58:58 +00:00
|
|
|
static inline void
|
|
|
|
render_fallback_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
2018-04-15 16:20:52 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2018-06-26 19:40:59 +00:00
|
|
|
const int surface_width = ceilf (node->bounds.size.width) * scale;
|
|
|
|
const int surface_height = ceilf (node->bounds.size.height) * scale;
|
2017-12-01 08:58:58 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
int texture_id;
|
|
|
|
|
2018-06-26 19:40:59 +00:00
|
|
|
if (surface_width <= 0 ||
|
|
|
|
surface_height <= 0)
|
|
|
|
return;
|
|
|
|
|
2017-12-01 08:58:58 +00:00
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
2018-06-26 19:40:59 +00:00
|
|
|
surface_width,
|
|
|
|
surface_height);
|
2018-04-15 16:20:52 +00:00
|
|
|
cairo_surface_set_device_scale (surface, scale, scale);
|
2017-12-01 08:58:58 +00:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
cairo_translate (cr, -node->bounds.origin.x, -node->bounds.origin.y);
|
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
#if HIGHLIGHT_FALLBACK
|
2018-03-30 21:32:19 +00:00
|
|
|
if (gsk_render_node_get_node_type (node) != GSK_CAIRO_NODE)
|
|
|
|
{
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
cairo_rectangle (cr, 0, 0, node->bounds.size.width, node->bounds.size.height);
|
|
|
|
cairo_set_source_rgba (cr, 1, 0, 0, 1);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2017-12-01 08:58:58 +00:00
|
|
|
#endif
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
/* Upload the Cairo surface to a GL texture */
|
|
|
|
texture_id = gsk_gl_driver_create_texture (self->gl_driver,
|
2018-06-26 19:40:59 +00:00
|
|
|
surface_width,
|
|
|
|
surface_height);
|
2017-12-01 08:58:58 +00:00
|
|
|
|
|
|
|
gsk_gl_driver_bind_source_texture (self->gl_driver, texture_id);
|
|
|
|
gsk_gl_driver_init_texture_with_surface (self->gl_driver,
|
|
|
|
texture_id,
|
|
|
|
surface,
|
|
|
|
GL_NEAREST, GL_NEAREST);
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
ops_set_program (builder, &self->blit_program);
|
|
|
|
ops_set_texture (builder, texture_id);
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
|
2017-12-01 09:47:13 +00:00
|
|
|
static inline void
|
|
|
|
render_text_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GdkRGBA *color,
|
2017-12-09 17:26:29 +00:00
|
|
|
gboolean force_color)
|
2017-12-01 09:47:13 +00:00
|
|
|
{
|
|
|
|
const PangoFont *font = gsk_text_node_peek_font (node);
|
|
|
|
const PangoGlyphInfo *glyphs = gsk_text_node_peek_glyphs (node);
|
2018-04-11 09:20:50 +00:00
|
|
|
const float text_scale = ops_get_scale (builder);
|
2017-12-01 09:47:13 +00:00
|
|
|
guint num_glyphs = gsk_text_node_get_num_glyphs (node);
|
|
|
|
int i;
|
|
|
|
int x_position = 0;
|
2018-07-08 14:52:33 +00:00
|
|
|
float x = gsk_text_node_get_x (node) + builder->dx;
|
|
|
|
float y = gsk_text_node_get_y (node) + builder->dy;
|
2017-12-01 09:47:13 +00:00
|
|
|
|
|
|
|
/* If the font has color glyphs, we don't need to recolor anything */
|
|
|
|
if (!force_color && font_has_color_glyphs (font))
|
|
|
|
{
|
|
|
|
ops_set_program (builder, &self->blit_program);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ops_set_program (builder, &self->coloring_program);
|
|
|
|
ops_set_color (builder, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We use one quad per character, unlike the other nodes which
|
|
|
|
* use at most one quad altogether */
|
|
|
|
for (i = 0; i < num_glyphs; i++)
|
|
|
|
{
|
|
|
|
const PangoGlyphInfo *gi = &glyphs[i];
|
|
|
|
const GskGLCachedGlyph *glyph;
|
2018-07-08 14:52:33 +00:00
|
|
|
float glyph_x, glyph_y, glyph_w, glyph_h;
|
2017-12-01 09:47:13 +00:00
|
|
|
float tx, ty, tx2, ty2;
|
|
|
|
double cx;
|
|
|
|
double cy;
|
|
|
|
|
2018-01-06 12:02:31 +00:00
|
|
|
if (gi->glyph == PANGO_GLYPH_EMPTY)
|
2017-12-01 09:47:13 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
glyph = gsk_gl_glyph_cache_lookup (&self->glyph_cache,
|
|
|
|
TRUE,
|
|
|
|
(PangoFont *)font,
|
|
|
|
gi->glyph,
|
2018-04-11 09:20:50 +00:00
|
|
|
text_scale);
|
2017-12-01 09:47:13 +00:00
|
|
|
|
|
|
|
/* e.g. whitespace */
|
|
|
|
if (glyph->draw_width <= 0 || glyph->draw_height <= 0)
|
2017-12-30 09:01:12 +00:00
|
|
|
goto next;
|
|
|
|
|
2017-12-01 09:47:13 +00:00
|
|
|
cx = (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
|
|
|
|
cy = (double)(gi->geometry.y_offset) / PANGO_SCALE;
|
|
|
|
|
|
|
|
ops_set_texture (builder, gsk_gl_glyph_cache_get_glyph_image (&self->glyph_cache,
|
2018-04-11 09:20:50 +00:00
|
|
|
glyph)->texture_id);
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2017-12-09 15:21:19 +00:00
|
|
|
tx = glyph->tx;
|
|
|
|
ty = glyph->ty;
|
|
|
|
tx2 = tx + glyph->tw;
|
|
|
|
ty2 = ty + glyph->th;
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2017-12-09 15:21:19 +00:00
|
|
|
glyph_x = x + cx + glyph->draw_x;
|
|
|
|
glyph_y = y + cy + glyph->draw_y;
|
|
|
|
glyph_w = glyph->draw_width;
|
|
|
|
glyph_h = glyph->draw_height;
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2017-12-30 09:01:12 +00:00
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { glyph_x, glyph_y }, { tx, ty }, },
|
|
|
|
{ { glyph_x, glyph_y + glyph_h }, { tx, ty2 }, },
|
|
|
|
{ { glyph_x + glyph_w, glyph_y }, { tx2, ty }, },
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2017-12-30 09:01:12 +00:00
|
|
|
{ { glyph_x + glyph_w, glyph_y + glyph_h }, { tx2, ty2 }, },
|
|
|
|
{ { glyph_x, glyph_y + glyph_h }, { tx, ty2 }, },
|
|
|
|
{ { glyph_x + glyph_w, glyph_y }, { tx2, ty }, },
|
|
|
|
});
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2017-12-30 09:01:12 +00:00
|
|
|
next:
|
2017-12-01 09:47:13 +00:00
|
|
|
x_position += gi->geometry.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 10:55:10 +00:00
|
|
|
static inline void
|
|
|
|
render_border_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2018-12-03 16:53:04 +00:00
|
|
|
const float min_x = builder->dx + node->bounds.origin.x;
|
|
|
|
const float min_y = builder->dy + node->bounds.origin.y;
|
2017-12-08 16:01:16 +00:00
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
2017-12-01 10:55:10 +00:00
|
|
|
const GdkRGBA *colors = gsk_border_node_peek_colors (node);
|
|
|
|
const GskRoundedRect *rounded_outline = gsk_border_node_peek_outline (node);
|
2017-12-09 07:57:13 +00:00
|
|
|
const float *og_widths = gsk_border_node_peek_widths (node);
|
2018-03-15 16:27:19 +00:00
|
|
|
GskRoundedRect outline;
|
2017-12-09 07:57:13 +00:00
|
|
|
float widths[4];
|
|
|
|
int i;
|
2017-12-01 10:55:10 +00:00
|
|
|
struct {
|
|
|
|
float w;
|
|
|
|
float h;
|
|
|
|
} sizes[4];
|
|
|
|
|
2017-12-09 07:57:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
widths[i] = og_widths[i];
|
|
|
|
|
2017-12-01 10:55:10 +00:00
|
|
|
/* Top left */
|
2017-12-08 16:01:16 +00:00
|
|
|
if (widths[3] > 0)
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[0].w = MAX (widths[3], rounded_outline->corner[0].width);
|
2017-12-08 16:01:16 +00:00
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[0].w = 0;
|
2017-12-08 16:01:16 +00:00
|
|
|
|
|
|
|
if (widths[0] > 0)
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[0].h = MAX (widths[0], rounded_outline->corner[0].height);
|
2017-12-08 16:01:16 +00:00
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[0].h = 0;
|
2017-12-01 10:55:10 +00:00
|
|
|
|
|
|
|
/* Top right */
|
2017-12-08 16:01:16 +00:00
|
|
|
if (widths[1] > 0)
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[1].w = MAX (widths[1], rounded_outline->corner[1].width);
|
2017-12-08 16:01:16 +00:00
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[1].w = 0;
|
2017-12-08 16:01:16 +00:00
|
|
|
|
|
|
|
if (widths[0] > 0)
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[1].h = MAX (widths[0], rounded_outline->corner[1].height);
|
2017-12-08 16:01:16 +00:00
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[1].h = 0;
|
2017-12-01 10:55:10 +00:00
|
|
|
|
|
|
|
/* Bottom right */
|
2017-12-08 16:01:16 +00:00
|
|
|
if (widths[1] > 0)
|
|
|
|
sizes[2].w = MAX (widths[1], rounded_outline->corner[2].width);
|
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[2].w = 0;
|
2017-12-08 16:01:16 +00:00
|
|
|
|
|
|
|
if (widths[2] > 0)
|
|
|
|
sizes[2].h = MAX (widths[2], rounded_outline->corner[2].height);
|
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[2].h = 0;
|
2017-12-08 16:01:16 +00:00
|
|
|
|
2017-12-01 10:55:10 +00:00
|
|
|
|
|
|
|
/* Bottom left */
|
2017-12-08 16:01:16 +00:00
|
|
|
if (widths[3] > 0)
|
|
|
|
sizes[3].w = MAX (widths[3], rounded_outline->corner[3].width);
|
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[3].w = 0;
|
2017-12-08 16:01:16 +00:00
|
|
|
|
|
|
|
if (widths[2] > 0)
|
|
|
|
sizes[3].h = MAX (widths[2], rounded_outline->corner[3].height);
|
|
|
|
else
|
2017-12-08 21:19:52 +00:00
|
|
|
sizes[3].h = 0;
|
2017-12-01 10:55:10 +00:00
|
|
|
|
2017-12-09 07:57:13 +00:00
|
|
|
for (i = 0; i < 4; i ++)
|
2018-04-11 09:20:50 +00:00
|
|
|
widths[i] *= scale;
|
2017-12-09 07:57:13 +00:00
|
|
|
|
2017-12-08 16:01:16 +00:00
|
|
|
{
|
|
|
|
const GskQuadVertex side_data[4][6] = {
|
|
|
|
/* Top */
|
|
|
|
{
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, }, /* Upper left */
|
|
|
|
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */
|
|
|
|
|
|
|
|
{ { max_x - sizes[1].w, min_y + sizes[1].h }, { 1, 0 }, }, /* Lower right */
|
|
|
|
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */
|
|
|
|
},
|
|
|
|
/* Right */
|
|
|
|
{
|
|
|
|
{ { max_x - sizes[1].w, min_y + sizes[1].h }, { 0, 1 }, }, /* Upper left */
|
|
|
|
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, }, /* Lower right */
|
|
|
|
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */
|
|
|
|
},
|
|
|
|
/* Bottom */
|
|
|
|
{
|
|
|
|
{ { min_x + sizes[3].w, max_y - sizes[3].h }, { 0, 1 }, }, /* Upper left */
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 1, 1 }, }, /* Upper right */
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, }, /* Lower right */
|
|
|
|
{ { min_x , max_y }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 1, 1 }, }, /* Upper right */
|
|
|
|
},
|
|
|
|
/* Left */
|
|
|
|
{
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, }, /* Upper left */
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 1, 1 }, }, /* Upper right */
|
2017-12-05 12:46:29 +00:00
|
|
|
|
2017-12-08 21:19:52 +00:00
|
|
|
{ { min_x + sizes[3].w, max_y - sizes[3].h }, { 1, 0 }, }, /* Lower right */
|
2017-12-08 16:01:16 +00:00
|
|
|
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */
|
|
|
|
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 1, 1 }, }, /* Upper right */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
int indices[4] = { 0, 1, 2, 3 };
|
|
|
|
int i;
|
2017-12-05 12:46:29 +00:00
|
|
|
|
2017-12-08 16:01:16 +00:00
|
|
|
/* We sort them by color */
|
|
|
|
sort_border_sides (colors, indices);
|
2017-12-05 12:46:29 +00:00
|
|
|
|
2018-03-15 16:27:19 +00:00
|
|
|
/* Prepare outline */
|
|
|
|
outline = *rounded_outline;
|
2018-12-02 10:04:15 +00:00
|
|
|
ops_transform_bounds_modelview (builder, &outline.bounds, &outline.bounds);
|
|
|
|
|
2018-03-15 16:27:19 +00:00
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
outline.corner[i].width *= scale;
|
|
|
|
outline.corner[i].height *= scale;
|
2018-03-15 16:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ops_set_program (builder, &self->border_program);
|
|
|
|
ops_set_border (builder, widths, &outline);
|
|
|
|
|
2017-12-08 16:01:16 +00:00
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
|
|
|
if (widths[indices[i]] > 0)
|
|
|
|
{
|
|
|
|
ops_set_border_color (builder, &colors[indices[i]]);
|
|
|
|
ops_draw (builder, side_data[indices[i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-01 10:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
static inline void
|
|
|
|
render_color_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
|
|
|
ops_set_program (builder, &self->color_program);
|
|
|
|
ops_set_color (builder, gsk_color_node_peek_color (node));
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2018-03-19 07:08:31 +00:00
|
|
|
render_texture_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
|
|
|
GdkTexture *texture = gsk_texture_node_get_texture (node);
|
2018-03-20 08:17:26 +00:00
|
|
|
const int max_texture_size = gsk_gl_driver_get_max_texture_size (self->gl_driver);
|
|
|
|
const float min_x = builder->dx + node->bounds.origin.x;
|
|
|
|
const float min_y = builder->dy + node->bounds.origin.y;
|
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-03-20 08:17:26 +00:00
|
|
|
if (texture->width > max_texture_size || texture->height > max_texture_size)
|
2018-03-19 10:34:01 +00:00
|
|
|
{
|
2018-03-20 08:17:26 +00:00
|
|
|
const float scale_x = (max_x - min_x) / texture->width;
|
|
|
|
const float scale_y = (max_y - min_y) / texture->height;
|
|
|
|
TextureSlice *slices;
|
|
|
|
guint n_slices;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
gsk_gl_driver_slice_texture (self->gl_driver, texture, &slices, &n_slices);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-03-20 08:17:26 +00:00
|
|
|
ops_set_program (builder, &self->blit_program);
|
|
|
|
for (i = 0; i < n_slices; i ++)
|
|
|
|
{
|
|
|
|
const TextureSlice *slice = &slices[i];
|
|
|
|
float x1, x2, y1, y2;
|
|
|
|
|
|
|
|
x1 = min_x + (scale_x * slice->rect.x);
|
|
|
|
x2 = x1 + (slice->rect.width * scale_x);
|
|
|
|
y1 = min_y + (scale_y * slice->rect.y);
|
|
|
|
y2 = y1 + (slice->rect.height * scale_y);
|
|
|
|
|
|
|
|
ops_set_texture (builder, slice->texture_id);
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { 0, 0 }, },
|
|
|
|
{ { x1, y2 }, { 0, 1 }, },
|
|
|
|
{ { x2, y1 }, { 1, 0 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { 1, 1 }, },
|
|
|
|
{ { x1, y2 }, { 0, 1 }, },
|
|
|
|
{ { x2, y1 }, { 1, 0 }, },
|
|
|
|
});
|
|
|
|
}
|
2018-03-19 10:34:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
|
|
|
|
int texture_id;
|
|
|
|
|
|
|
|
get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
|
|
|
|
|
|
|
|
texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver,
|
|
|
|
texture,
|
|
|
|
gl_min_filter,
|
|
|
|
gl_mag_filter);
|
|
|
|
ops_set_program (builder, &self->blit_program);
|
|
|
|
ops_set_texture (builder, texture_id);
|
2018-01-18 07:21:11 +00:00
|
|
|
|
2018-03-04 16:15:39 +00:00
|
|
|
|
2018-03-19 10:34:01 +00:00
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { min_x, min_y }, { 0, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 1 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 0 }, },
|
2018-03-14 11:23:38 +00:00
|
|
|
|
2018-03-19 10:34:01 +00:00
|
|
|
{ { max_x, max_y }, { 1, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 1 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 0 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 01:46:57 +00:00
|
|
|
static inline void
|
|
|
|
render_offset_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
GskRenderNode *child = gsk_offset_node_get_child (node);
|
2018-05-01 06:19:48 +00:00
|
|
|
const guint child_type = gsk_render_node_get_node_type (child);
|
|
|
|
const float dx = gsk_offset_node_get_x_offset (node);
|
|
|
|
const float dy = gsk_offset_node_get_y_offset (node);
|
|
|
|
|
|
|
|
/* TODO: We do this only for selected node type we know handle
|
|
|
|
* builder->dx/dy correctly. That should be "all nodes" eventually.
|
|
|
|
*/
|
|
|
|
switch (child_type)
|
|
|
|
{
|
|
|
|
case GSK_TEXT_NODE:
|
|
|
|
case GSK_TEXTURE_NODE:
|
|
|
|
case GSK_COLOR_NODE:
|
2018-05-27 12:41:56 +00:00
|
|
|
case GSK_COLOR_MATRIX_NODE:
|
2018-12-03 16:49:51 +00:00
|
|
|
case GSK_SHADOW_NODE:
|
2018-12-03 16:53:04 +00:00
|
|
|
case GSK_BORDER_NODE:
|
2018-12-03 16:56:46 +00:00
|
|
|
case GSK_OUTSET_SHADOW_NODE:
|
2018-12-03 17:03:34 +00:00
|
|
|
case GSK_LINEAR_GRADIENT_NODE:
|
2018-05-01 06:19:48 +00:00
|
|
|
{
|
|
|
|
ops_offset (builder, dx, dy);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
ops_offset (builder, - dx, - dy);
|
|
|
|
}
|
|
|
|
break;
|
2018-03-20 01:46:57 +00:00
|
|
|
|
2018-05-01 06:19:48 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
graphene_matrix_t transform, transformed_mv;
|
2018-03-20 01:46:57 +00:00
|
|
|
|
2018-05-01 06:19:48 +00:00
|
|
|
graphene_matrix_init_translate (&transform,
|
|
|
|
&GRAPHENE_POINT3D_INIT(dx, dy, 1.0));
|
2018-11-26 16:52:35 +00:00
|
|
|
graphene_matrix_multiply (&transform, builder->current_modelview, &transformed_mv);
|
2018-03-20 01:46:57 +00:00
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_push_modelview (builder, &transformed_mv);
|
2018-05-01 06:19:48 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_pop_modelview (builder);
|
2018-05-01 06:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-20 01:46:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
static inline void
|
|
|
|
render_transform_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
GskRenderNode *child = gsk_transform_node_get_child (node);
|
|
|
|
graphene_matrix_t transform, transformed_mv;
|
|
|
|
|
|
|
|
graphene_matrix_init_from_matrix (&transform, gsk_transform_node_peek_transform (node));
|
2018-11-26 16:52:35 +00:00
|
|
|
graphene_matrix_multiply (&transform, builder->current_modelview, &transformed_mv);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_push_modelview (builder, &transformed_mv);
|
2018-11-29 07:09:02 +00:00
|
|
|
if (ops_modelview_is_simple (builder) ||
|
|
|
|
node_supports_transform (child))
|
|
|
|
{
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const float min_x = builder->dx + child->bounds.origin.x;
|
|
|
|
const float min_y = builder->dy + child->bounds.origin.y;
|
|
|
|
const float max_x = min_x + child->bounds.size.width;
|
|
|
|
const float max_y = min_y + child->bounds.size.height;
|
|
|
|
const GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
};
|
|
|
|
int texture_id;
|
|
|
|
gboolean is_offscreen;
|
|
|
|
/* For non-trivial transforms, we draw everything on a texture and then
|
|
|
|
* draw the texture transformed. */
|
|
|
|
/* TODO: We should compute a modelview containing only the "non-trivial"
|
|
|
|
* part (e.g. the rotation) and use that. We want to keep the scale
|
|
|
|
* for the texture.
|
|
|
|
*/
|
|
|
|
add_offscreen_ops (self, builder,
|
2018-12-02 08:05:50 +00:00
|
|
|
&node->bounds,
|
2018-11-29 07:09:02 +00:00
|
|
|
child,
|
|
|
|
&texture_id, &is_offscreen,
|
|
|
|
FALSE, TRUE);
|
|
|
|
ops_set_texture (builder, texture_id);
|
|
|
|
ops_set_program (builder, &self->blit_program);
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_pop_modelview (builder);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_opacity_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
float prev_opacity;
|
|
|
|
|
|
|
|
prev_opacity = ops_set_opacity (builder,
|
|
|
|
builder->current_opacity * gsk_opacity_node_get_opacity (node));
|
|
|
|
|
|
|
|
gsk_gl_renderer_add_render_ops (self, gsk_opacity_node_get_child (node), builder);
|
|
|
|
|
|
|
|
ops_set_opacity (builder, prev_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_linear_gradient_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
|
|
|
RenderOp op;
|
|
|
|
int n_color_stops = MIN (8, gsk_linear_gradient_node_get_n_color_stops (node));
|
|
|
|
const GskColorStop *stops = gsk_linear_gradient_node_peek_color_stops (node);
|
|
|
|
const graphene_point_t *start = gsk_linear_gradient_node_peek_start (node);
|
|
|
|
const graphene_point_t *end = gsk_linear_gradient_node_peek_end (node);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_color_stops; i ++)
|
|
|
|
{
|
|
|
|
const GskColorStop *stop = stops + i;
|
|
|
|
|
|
|
|
op.linear_gradient.color_stops[(i * 4) + 0] = stop->color.red;
|
|
|
|
op.linear_gradient.color_stops[(i * 4) + 1] = stop->color.green;
|
|
|
|
op.linear_gradient.color_stops[(i * 4) + 2] = stop->color.blue;
|
|
|
|
op.linear_gradient.color_stops[(i * 4) + 3] = stop->color.alpha;
|
|
|
|
op.linear_gradient.color_offsets[i] = stop->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
ops_set_program (builder, &self->linear_gradient_program);
|
|
|
|
op.op = OP_CHANGE_LINEAR_GRADIENT;
|
|
|
|
op.linear_gradient.n_color_stops = n_color_stops;
|
|
|
|
op.linear_gradient.start_point = *start;
|
2018-12-03 17:03:34 +00:00
|
|
|
op.linear_gradient.start_point.x += builder->dx;
|
|
|
|
op.linear_gradient.start_point.y += builder->dy;
|
2017-12-08 12:12:43 +00:00
|
|
|
op.linear_gradient.end_point = *end;
|
2018-12-03 17:03:34 +00:00
|
|
|
op.linear_gradient.end_point.x += builder->dx;
|
|
|
|
op.linear_gradient.end_point.y += builder->dy;
|
2017-12-08 12:12:43 +00:00
|
|
|
ops_add (builder, &op);
|
|
|
|
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_clip_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
GskRoundedRect prev_clip;
|
|
|
|
GskRenderNode *child = gsk_clip_node_get_child (node);
|
|
|
|
graphene_rect_t transformed_clip;
|
|
|
|
graphene_rect_t intersection;
|
|
|
|
GskRoundedRect child_clip;
|
|
|
|
|
|
|
|
transformed_clip = *gsk_clip_node_peek_clip (node);
|
2018-12-02 10:04:15 +00:00
|
|
|
ops_transform_bounds_modelview (builder, &transformed_clip, &transformed_clip);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
|
|
|
graphene_rect_intersection (&transformed_clip,
|
|
|
|
&builder->current_clip.bounds,
|
|
|
|
&intersection);
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_from_rect (&child_clip, &intersection, 0.0f);
|
|
|
|
|
|
|
|
prev_clip = ops_set_clip (builder, &child_clip);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
ops_set_clip (builder, &prev_clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2018-03-14 11:36:32 +00:00
|
|
|
render_rounded_clip_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2018-03-14 11:36:32 +00:00
|
|
|
const float min_x = node->bounds.origin.x;
|
|
|
|
const float min_y = node->bounds.origin.y;
|
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
2018-03-15 10:01:53 +00:00
|
|
|
GskRoundedRect child_clip = *gsk_rounded_clip_node_peek_clip (node);
|
2018-04-11 15:57:57 +00:00
|
|
|
GskRoundedRect transformed_clip;
|
2017-12-08 12:12:43 +00:00
|
|
|
GskRoundedRect prev_clip;
|
|
|
|
GskRenderNode *child = gsk_rounded_clip_node_get_child (node);
|
2018-03-15 10:01:53 +00:00
|
|
|
int i;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-04-11 15:57:57 +00:00
|
|
|
transformed_clip = child_clip;
|
2018-12-02 10:04:15 +00:00
|
|
|
ops_transform_bounds_modelview (builder, &child_clip.bounds, &transformed_clip.bounds);
|
2018-03-15 10:01:53 +00:00
|
|
|
|
2018-04-11 15:57:57 +00:00
|
|
|
if (graphene_rect_contains_rect (&builder->current_clip.bounds,
|
|
|
|
&transformed_clip.bounds))
|
2018-03-15 10:01:53 +00:00
|
|
|
{
|
2018-04-11 15:57:57 +00:00
|
|
|
/* If they don't intersect at all, we can simply set
|
|
|
|
* the new clip and add the render ops */
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
|
|
|
transformed_clip.corner[i].width *= scale;
|
|
|
|
transformed_clip.corner[i].height *= scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_clip = ops_set_clip (builder, &transformed_clip);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
|
|
|
|
ops_set_clip (builder, &prev_clip);
|
2018-03-15 10:01:53 +00:00
|
|
|
}
|
2018-04-11 15:57:57 +00:00
|
|
|
else if (graphene_rect_intersection (&builder->current_clip.bounds,
|
|
|
|
&transformed_clip.bounds, NULL))
|
|
|
|
{
|
|
|
|
graphene_matrix_t scale_matrix;
|
|
|
|
gboolean is_offscreen;
|
|
|
|
int texture_id;
|
|
|
|
/* NOTE: We are *not* transforming the clip by the current modelview here.
|
|
|
|
* We instead draw the untransformed clip to a texture and then transform
|
|
|
|
* that texture.
|
|
|
|
*
|
|
|
|
* We do, however, apply the scale factor to the child clip of course.
|
|
|
|
*/
|
|
|
|
|
|
|
|
graphene_matrix_init_scale (&scale_matrix, scale, scale, 1.0f);
|
|
|
|
graphene_matrix_transform_bounds (&scale_matrix, &child_clip.bounds, &child_clip.bounds);
|
|
|
|
|
|
|
|
/* Increase corner radius size by scale factor */
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
|
|
|
child_clip.corner[i].width *= scale;
|
|
|
|
child_clip.corner[i].height *= scale;
|
|
|
|
}
|
2018-03-15 10:01:53 +00:00
|
|
|
|
2018-04-11 15:57:57 +00:00
|
|
|
prev_clip = ops_set_clip (builder, &child_clip);
|
2018-12-02 08:05:50 +00:00
|
|
|
add_offscreen_ops (self, builder, &node->bounds,
|
2018-04-11 15:57:57 +00:00
|
|
|
child,
|
|
|
|
&texture_id, &is_offscreen, TRUE, FALSE);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-04-11 15:57:57 +00:00
|
|
|
ops_set_clip (builder, &prev_clip);
|
|
|
|
ops_set_program (builder, &self->blit_program);
|
|
|
|
ops_set_texture (builder, texture_id);
|
2018-03-14 11:36:32 +00:00
|
|
|
|
2018-04-11 15:57:57 +00:00
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
2018-03-14 11:36:32 +00:00
|
|
|
|
2018-04-11 15:57:57 +00:00
|
|
|
{ { max_x, max_y }, { 1, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/* Else this node is entirely out of the current clip node and we don't draw it anyway. */
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_color_matrix_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
2018-05-27 12:41:56 +00:00
|
|
|
const float min_x = builder->dx + node->bounds.origin.x;
|
|
|
|
const float min_y = builder->dy + node->bounds.origin.y;
|
2017-12-08 12:12:43 +00:00
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
|
|
|
int texture_id;
|
|
|
|
gboolean is_offscreen;
|
|
|
|
|
2018-12-02 07:17:34 +00:00
|
|
|
/* Pass min_x/max_x/min_y/max_y without builder->dx/dy! */
|
|
|
|
add_offscreen_ops (self, builder,
|
2018-12-02 08:05:50 +00:00
|
|
|
&node->bounds,
|
2017-12-08 12:12:43 +00:00
|
|
|
gsk_color_matrix_node_get_child (node),
|
2018-03-14 11:36:32 +00:00
|
|
|
&texture_id, &is_offscreen, FALSE, TRUE);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->color_matrix_program);
|
|
|
|
ops_set_color_matrix (builder,
|
|
|
|
gsk_color_matrix_node_peek_color_matrix (node),
|
|
|
|
gsk_color_matrix_node_peek_color_offset (node));
|
|
|
|
|
|
|
|
ops_set_texture (builder, texture_id);
|
|
|
|
|
|
|
|
if (is_offscreen)
|
|
|
|
{
|
|
|
|
GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
};
|
|
|
|
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_blur_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
|
|
|
const float min_x = node->bounds.origin.x;
|
|
|
|
const float min_y = node->bounds.origin.y;
|
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
|
|
|
int texture_id;
|
|
|
|
gboolean is_offscreen;
|
|
|
|
RenderOp op;
|
2018-12-02 08:05:50 +00:00
|
|
|
add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
2017-12-08 12:12:43 +00:00
|
|
|
gsk_blur_node_get_child (node),
|
2018-03-14 11:36:32 +00:00
|
|
|
&texture_id, &is_offscreen, FALSE, TRUE);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->blur_program);
|
|
|
|
op.op = OP_CHANGE_BLUR;
|
|
|
|
graphene_size_init_from_size (&op.blur.size, &node->bounds.size);
|
|
|
|
op.blur.radius = gsk_blur_node_get_radius (node);
|
|
|
|
ops_add (builder, &op);
|
|
|
|
|
|
|
|
ops_set_texture (builder, texture_id);
|
|
|
|
|
|
|
|
if (is_offscreen)
|
|
|
|
{
|
|
|
|
GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
};
|
|
|
|
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_inset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2017-12-08 12:12:43 +00:00
|
|
|
RenderOp op;
|
|
|
|
|
|
|
|
/* TODO: Implement blurred inset shadows as well */
|
|
|
|
if (gsk_inset_shadow_node_get_blur_radius (node) > 0)
|
|
|
|
{
|
|
|
|
render_fallback_node (self, node, builder, vertex_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
op.op = OP_CHANGE_INSET_SHADOW;
|
|
|
|
rgba_to_float (gsk_inset_shadow_node_peek_color (node), op.inset_shadow.color);
|
2017-12-09 08:41:52 +00:00
|
|
|
rounded_rect_to_floats (self, builder,
|
|
|
|
gsk_inset_shadow_node_peek_outline (node),
|
2017-12-08 12:12:43 +00:00
|
|
|
op.inset_shadow.outline,
|
|
|
|
op.inset_shadow.corner_widths,
|
|
|
|
op.inset_shadow.corner_heights);
|
2018-04-11 09:20:50 +00:00
|
|
|
op.inset_shadow.radius = gsk_inset_shadow_node_get_blur_radius (node) * scale;
|
|
|
|
op.inset_shadow.spread = gsk_inset_shadow_node_get_spread (node) * scale;
|
|
|
|
op.inset_shadow.offset[0] = gsk_inset_shadow_node_get_dx (node) * scale;
|
|
|
|
op.inset_shadow.offset[1] = -gsk_inset_shadow_node_get_dy (node) * scale;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->inset_shadow_program);
|
|
|
|
ops_add (builder, &op);
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
|
2018-01-15 09:55:40 +00:00
|
|
|
static inline void
|
|
|
|
render_unblurred_outset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2018-01-15 09:55:40 +00:00
|
|
|
const float spread = gsk_outset_shadow_node_get_spread (node);
|
|
|
|
GskRoundedRect r = *gsk_outset_shadow_node_peek_outline (node);
|
|
|
|
RenderOp op;
|
|
|
|
|
|
|
|
op.op = OP_CHANGE_UNBLURRED_OUTSET_SHADOW;
|
|
|
|
rgba_to_float (gsk_outset_shadow_node_peek_color (node), op.unblurred_outset_shadow.color);
|
|
|
|
|
|
|
|
gsk_rounded_rect_shrink (&r, -spread, -spread, -spread, -spread);
|
|
|
|
|
|
|
|
rounded_rect_to_floats (self, builder,
|
|
|
|
&r,
|
|
|
|
op.unblurred_outset_shadow.outline,
|
|
|
|
op.unblurred_outset_shadow.corner_widths,
|
|
|
|
op.unblurred_outset_shadow.corner_heights);
|
|
|
|
|
2018-04-11 09:20:50 +00:00
|
|
|
op.unblurred_outset_shadow.spread = gsk_outset_shadow_node_get_spread (node) * scale;
|
|
|
|
op.unblurred_outset_shadow.offset[0] = gsk_outset_shadow_node_get_dx (node) * scale;
|
|
|
|
op.unblurred_outset_shadow.offset[1] = -gsk_outset_shadow_node_get_dy (node) * scale;
|
2018-01-15 09:55:40 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->unblurred_outset_shadow_program);
|
|
|
|
ops_add (builder, &op);
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
static inline void
|
|
|
|
render_outset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
2017-12-28 17:57:53 +00:00
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2017-12-21 17:09:32 +00:00
|
|
|
const GskRoundedRect *outline = gsk_outset_shadow_node_peek_outline (node);
|
|
|
|
GskRoundedRect offset_outline;
|
|
|
|
const float blur_radius = gsk_outset_shadow_node_get_blur_radius (node);
|
2017-12-28 15:41:32 +00:00
|
|
|
const float blur_extra = gsk_cairo_blur_compute_pixels (blur_radius);
|
2017-12-21 17:09:32 +00:00
|
|
|
const float spread = gsk_outset_shadow_node_get_spread (node);
|
|
|
|
const float dx = gsk_outset_shadow_node_get_dx (node);
|
|
|
|
const float dy = gsk_outset_shadow_node_get_dy (node);
|
2018-12-03 16:56:46 +00:00
|
|
|
const float min_x = builder->dx + outline->bounds.origin.x - spread - blur_extra / 2.0;
|
|
|
|
const float min_y = builder->dy + outline->bounds.origin.y - spread - blur_extra / 2.0;
|
2017-12-28 15:41:32 +00:00
|
|
|
const float max_x = min_x + outline->bounds.size.width + (spread + blur_extra/2.0) * 2;
|
|
|
|
const float max_y = min_y + outline->bounds.size.height + (spread + blur_extra/2.0) * 2;
|
2017-12-21 17:09:32 +00:00
|
|
|
float texture_width, texture_height;
|
2017-12-08 12:12:43 +00:00
|
|
|
RenderOp op;
|
2017-12-21 17:09:32 +00:00
|
|
|
graphene_matrix_t identity;
|
|
|
|
graphene_matrix_t prev_projection;
|
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
graphene_matrix_t item_proj;
|
2018-07-15 15:52:34 +00:00
|
|
|
int blurred_texture_id;
|
2018-07-08 18:08:15 +00:00
|
|
|
int cached_tid;
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* offset_outline is the minimal outline we need to draw the given drop shadow,
|
|
|
|
* enlarged by the spread and offset by the blur radius. */
|
|
|
|
offset_outline = *outline;
|
2017-12-28 15:41:32 +00:00
|
|
|
/* Shrink our outline to the minimum size that can still hold all the border radii */
|
2017-12-21 17:09:32 +00:00
|
|
|
gsk_rounded_rect_shrink_to_minimum (&offset_outline);
|
2017-12-28 15:41:32 +00:00
|
|
|
/* Increase by the spread */
|
2017-12-21 17:09:32 +00:00
|
|
|
gsk_rounded_rect_shrink (&offset_outline, -spread, -spread, -spread, -spread);
|
2017-12-28 15:41:32 +00:00
|
|
|
/* No we need to incorporate the blur radius; since we blur an edge an equal blur_extra/2.0
|
|
|
|
* on both sides, the minimum side of both width and height needs to be blur_extra */
|
|
|
|
offset_outline.bounds.size.width = MAX (offset_outline.bounds.size.width, blur_extra);
|
|
|
|
offset_outline.bounds.size.height = MAX (offset_outline.bounds.size.height, blur_extra);
|
|
|
|
/* For the center part, we add a few pixels */
|
2017-12-21 17:09:32 +00:00
|
|
|
offset_outline.bounds.size.width += SHADOW_EXTRA_SIZE;
|
|
|
|
offset_outline.bounds.size.height += SHADOW_EXTRA_SIZE;
|
2017-12-28 15:41:32 +00:00
|
|
|
offset_outline.bounds.origin.x = blur_extra / 2.0f;
|
|
|
|
offset_outline.bounds.origin.y = blur_extra / 2.0f;
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2017-12-28 15:41:32 +00:00
|
|
|
texture_width = offset_outline.bounds.size.width + blur_extra;
|
|
|
|
texture_height = offset_outline.bounds.size.height + blur_extra;
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
cached_tid = gsk_gl_shadow_cache_get_texture_id (&self->shadow_cache,
|
|
|
|
self->gl_driver,
|
|
|
|
&offset_outline,
|
|
|
|
blur_radius);
|
|
|
|
if (cached_tid == 0)
|
|
|
|
{
|
2018-07-15 15:52:34 +00:00
|
|
|
int texture_id, render_target;
|
|
|
|
int blurred_render_target;
|
|
|
|
int prev_render_target;
|
|
|
|
GskRoundedRect prev_clip, blit_clip;
|
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
texture_id = gsk_gl_driver_create_texture (self->gl_driver, texture_width, texture_height);
|
|
|
|
gsk_gl_driver_bind_source_texture (self->gl_driver, texture_id);
|
|
|
|
gsk_gl_driver_init_texture_empty (self->gl_driver, texture_id);
|
|
|
|
render_target = gsk_gl_driver_create_render_target (self->gl_driver, texture_id, FALSE, FALSE);
|
|
|
|
|
|
|
|
|
|
|
|
graphene_matrix_init_ortho (&item_proj,
|
|
|
|
0, texture_width, 0, texture_height,
|
|
|
|
ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE);
|
|
|
|
graphene_matrix_scale (&item_proj, 1, -1, 1);
|
|
|
|
graphene_matrix_init_identity (&identity);
|
|
|
|
|
|
|
|
prev_render_target = ops_set_render_target (builder, render_target);
|
|
|
|
op.op = OP_CLEAR;
|
|
|
|
ops_add (builder, &op);
|
|
|
|
prev_projection = ops_set_projection (builder, &item_proj);
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_push_modelview (builder, &identity);
|
2018-07-08 18:08:15 +00:00
|
|
|
prev_viewport = ops_set_viewport (builder, &GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height));
|
|
|
|
|
|
|
|
/* Draw outline */
|
|
|
|
ops_set_program (builder, &self->color_program);
|
|
|
|
prev_clip = ops_set_clip (builder, &offset_outline);
|
|
|
|
ops_set_color (builder, gsk_outset_shadow_node_peek_color (node));
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { 0, }, { 0, 1 }, },
|
|
|
|
{ { 0, texture_height }, { 0, 0 }, },
|
|
|
|
{ { texture_width, }, { 1, 1 }, },
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
{ { texture_width, texture_height }, { 1, 0 }, },
|
|
|
|
{ { 0, texture_height }, { 0, 0 }, },
|
|
|
|
{ { texture_width, }, { 1, 1 }, },
|
|
|
|
});
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
blurred_texture_id = gsk_gl_driver_create_permanent_texture (self->gl_driver, texture_width, texture_height);
|
|
|
|
gsk_gl_driver_bind_source_texture (self->gl_driver, blurred_texture_id);
|
|
|
|
gsk_gl_driver_init_texture_empty (self->gl_driver, blurred_texture_id);
|
|
|
|
blurred_render_target = gsk_gl_driver_create_render_target (self->gl_driver, blurred_texture_id, TRUE, TRUE);
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
ops_set_render_target (builder, blurred_render_target);
|
|
|
|
op.op = OP_CLEAR;
|
|
|
|
ops_add (builder, &op);
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_rounded_rect_init_from_rect (&blit_clip,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height), 0.0f);
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
ops_set_program (builder, &self->blur_program);
|
|
|
|
op.op = OP_CHANGE_BLUR;
|
|
|
|
op.blur.size.width = texture_width;
|
|
|
|
op.blur.size.height = texture_height;
|
|
|
|
op.blur.radius = blur_radius;
|
|
|
|
ops_add (builder, &op);
|
2017-12-31 07:45:40 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
ops_set_clip (builder, &blit_clip);
|
|
|
|
ops_set_texture (builder, texture_id);
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { 0, 0 }, { 0, 1 }, },
|
|
|
|
{ { 0, texture_height }, { 0, 0 }, },
|
|
|
|
{ { texture_width, 0 }, { 1, 1 }, },
|
2017-12-31 07:45:40 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
{ { texture_width, texture_height }, { 1, 0 }, },
|
|
|
|
{ { 0, texture_height }, { 0, 0 }, },
|
|
|
|
{ { texture_width, 0 }, { 1, 1 }, },
|
|
|
|
});
|
2017-12-31 07:45:40 +00:00
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
ops_set_clip (builder, &prev_clip);
|
|
|
|
ops_set_viewport (builder, &prev_viewport);
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_pop_modelview (builder);
|
2018-07-08 18:08:15 +00:00
|
|
|
ops_set_projection (builder, &prev_projection);
|
|
|
|
ops_set_render_target (builder, prev_render_target);
|
|
|
|
|
|
|
|
gsk_gl_shadow_cache_commit (&self->shadow_cache,
|
|
|
|
&offset_outline,
|
|
|
|
blur_radius,
|
|
|
|
blurred_texture_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
blurred_texture_id = cached_tid;
|
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
ops_set_program (builder, &self->outset_shadow_program);
|
|
|
|
ops_set_texture (builder, blurred_texture_id);
|
2017-12-08 12:12:43 +00:00
|
|
|
op.op = OP_CHANGE_OUTSET_SHADOW;
|
2018-01-23 20:44:33 +00:00
|
|
|
rounded_rect_to_floats (self, builder,
|
|
|
|
outline,
|
|
|
|
op.outset_shadow.outline,
|
|
|
|
op.outset_shadow.corner_widths,
|
|
|
|
op.outset_shadow.corner_heights);
|
2017-12-08 12:12:43 +00:00
|
|
|
ops_add (builder, &op);
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* We use the one outset shadow op from above to draw all 8 sides/corners. */
|
|
|
|
{
|
|
|
|
const GskRoundedRect *o = &offset_outline;
|
2017-12-28 15:41:32 +00:00
|
|
|
float top_height = MAX (o->corner[0].height, o->corner[1].height);
|
|
|
|
float bottom_height = MAX (o->corner[2].height, o->corner[3].height);
|
|
|
|
float left_width = MAX (o->corner[0].width, o->corner[3].width);
|
|
|
|
float right_width = MAX (o->corner[1].width, o->corner[2].width);
|
|
|
|
float x1, x2, y1, y2, tx1, tx2, ty1, ty2;
|
|
|
|
|
|
|
|
top_height = MAX (top_height, blur_extra / 2.0f) + (blur_extra / 2.0f);
|
|
|
|
bottom_height = MAX (bottom_height, blur_extra / 2.0f) + (blur_extra / 2.0f);
|
|
|
|
left_width = MAX (left_width, blur_extra / 2.0f) + (blur_extra / 2.0f);
|
|
|
|
right_width = MAX (right_width, blur_extra / 2.0f) + (blur_extra / 2.0f);
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Top left */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (top_height > 0 && left_width > 0)
|
|
|
|
{
|
|
|
|
x1 = min_x + dx;
|
|
|
|
x2 = min_x + dx + left_width;
|
|
|
|
y1 = min_y + dy;
|
|
|
|
y2 = min_y + dy + top_height;
|
|
|
|
tx1 = 0;
|
|
|
|
tx2 = left_width / texture_width;
|
|
|
|
ty1 = 1 - (top_height / texture_height);
|
|
|
|
ty2 = 1;
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Top right */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (top_height > 0 && right_width > 0)
|
|
|
|
{
|
|
|
|
x1 = max_x + dx - right_width;
|
|
|
|
x2 = max_x + dx;
|
|
|
|
y1 = min_y + dy;
|
|
|
|
y2 = min_y + dy + top_height;
|
|
|
|
tx1 = 1 - (right_width / texture_width);
|
|
|
|
tx2 = 1;
|
|
|
|
ty1 = 1 - (top_height / texture_height);
|
|
|
|
ty2 = 1;
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Bottom right */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (bottom_height > 0 && left_width > 0)
|
|
|
|
{
|
|
|
|
x1 = max_x + dx - right_width;
|
|
|
|
x2 = max_x + dx;
|
|
|
|
y1 = max_y + dy - bottom_height;
|
|
|
|
y2 = max_y + dy;
|
|
|
|
tx1 = 1 - (right_width / texture_width);
|
|
|
|
tx2 = 1;
|
|
|
|
ty1 = 0;
|
|
|
|
ty2 = (bottom_height / texture_height);
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Bottom left */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (bottom_height > 0 && left_width > 0)
|
|
|
|
{
|
|
|
|
x1 = min_x + dx;
|
|
|
|
x2 = min_x + dx + left_width;
|
|
|
|
y1 = max_y + dy - bottom_height;
|
|
|
|
y2 = max_y + dy;
|
|
|
|
tx1 = 0;
|
|
|
|
tx2 = left_width / texture_width;
|
|
|
|
ty1 = 0;
|
|
|
|
ty2 = bottom_height / texture_height;
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Left side */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (left_width > 0)
|
|
|
|
{
|
|
|
|
x1 = min_x + dx;
|
|
|
|
x2 = min_x + dx + left_width;
|
|
|
|
y1 = min_y + dy + top_height;
|
|
|
|
y2 = max_y + dy - bottom_height;
|
|
|
|
tx1 = 0;
|
|
|
|
tx2 = left_width / texture_width;
|
|
|
|
ty1 = 0.5f - SHADOW_EXTRA_SIZE / 2.0f / texture_height;
|
|
|
|
ty2 = ty1 + (SHADOW_EXTRA_SIZE / texture_height);
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Right side */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (right_width > 0)
|
|
|
|
{
|
|
|
|
x1 = max_x + dx - right_width;
|
|
|
|
x2 = max_x + dx;
|
|
|
|
y1 = min_y + dy + top_height;
|
|
|
|
y2 = max_y + dy - bottom_height;
|
|
|
|
tx1 = 1 - (right_width / texture_width);
|
|
|
|
tx2 = 1;
|
|
|
|
ty1 = 0.5f - SHADOW_EXTRA_SIZE / 2.0f / texture_height;
|
|
|
|
ty2 = ty1 + (SHADOW_EXTRA_SIZE / texture_height);
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Top side */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (top_height > 0)
|
|
|
|
{
|
|
|
|
x1 = min_x + dx + left_width;
|
|
|
|
x2 = max_x + dx - right_width;
|
|
|
|
y1 = min_y + dy;
|
|
|
|
y2 = min_y + dy + top_height;
|
|
|
|
tx1 = 0.5f - (SHADOW_EXTRA_SIZE / 2.0f / texture_width);
|
|
|
|
tx2 = tx1 + (SHADOW_EXTRA_SIZE / texture_width);
|
|
|
|
ty1 = 1 - (top_height / texture_height);
|
|
|
|
ty2 = 1;
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Bottom side */
|
2017-12-28 17:00:59 +00:00
|
|
|
if (bottom_height > 0)
|
|
|
|
{
|
|
|
|
x1 = min_x + dx + left_width;
|
|
|
|
x2 = max_x + dx - right_width;
|
|
|
|
y1 = max_y + dy - bottom_height;
|
|
|
|
y2 = max_y + dy;
|
|
|
|
tx1 = 0.5f - (SHADOW_EXTRA_SIZE / 2.0f / texture_width);
|
|
|
|
tx2 = tx1 + (SHADOW_EXTRA_SIZE / texture_width);
|
|
|
|
ty1 = 0;
|
|
|
|
ty2 = bottom_height / texture_height;
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-28 15:41:32 +00:00
|
|
|
|
|
|
|
/* Middle */
|
|
|
|
x1 = min_x + dx + left_width;
|
|
|
|
x2 = max_x + dx - right_width;
|
|
|
|
y1 = min_y + dy + top_height;
|
|
|
|
y2 = max_y + dy - bottom_height;
|
2017-12-28 17:00:59 +00:00
|
|
|
if (x2 > x1 && y2 > y1)
|
|
|
|
{
|
|
|
|
tx1 = (texture_width - SHADOW_EXTRA_SIZE) / 2.0f / texture_width;
|
|
|
|
tx2 = (texture_width + SHADOW_EXTRA_SIZE) / 2.0f / texture_width;
|
|
|
|
ty1 = (texture_height - SHADOW_EXTRA_SIZE) / 2.0f / texture_height;
|
|
|
|
ty2 = (texture_height + SHADOW_EXTRA_SIZE) / 2.0f / texture_height;
|
|
|
|
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
|
|
|
|
{ { x1, y1 }, { tx1, ty2 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
|
|
|
|
{ { x2, y2 }, { tx2, ty1 }, },
|
|
|
|
{ { x1, y2 }, { tx1, ty1 }, },
|
|
|
|
{ { x2, y1 }, { tx2, ty2 }, },
|
|
|
|
});
|
|
|
|
}
|
2017-12-28 15:41:32 +00:00
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex *vertex_data)
|
|
|
|
{
|
|
|
|
float min_x = node->bounds.origin.x;
|
|
|
|
float min_y = node->bounds.origin.y;
|
|
|
|
float max_x = min_x + node->bounds.size.width;
|
|
|
|
float max_y = min_y + node->bounds.size.height;
|
|
|
|
GskRenderNode *original_child = gsk_shadow_node_get_child (node);
|
|
|
|
GskRenderNode *shadow_child = original_child;
|
|
|
|
gsize n_shadows = gsk_shadow_node_get_n_shadows (node);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* TODO: Implement blurred shadow nodes */;
|
|
|
|
for (i = 0; i < n_shadows; i ++)
|
|
|
|
{
|
|
|
|
const GskShadow *shadow = gsk_shadow_node_peek_shadow (node, i);
|
|
|
|
|
|
|
|
if (shadow->radius > 0)
|
|
|
|
{
|
|
|
|
render_fallback_node (self, node, builder, vertex_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shadow nodes recolor every pixel of the source texture, but leave the alpha in tact.
|
|
|
|
* If the child is a color matrix node that doesn't touch the alpha, we can throw that away. */
|
|
|
|
if (gsk_render_node_get_node_type (shadow_child) == GSK_COLOR_MATRIX_NODE &&
|
|
|
|
!color_matrix_modifies_alpha (shadow_child))
|
|
|
|
{
|
|
|
|
shadow_child = gsk_color_matrix_node_get_child (shadow_child);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_shadows; i ++)
|
|
|
|
{
|
|
|
|
const GskShadow *shadow = gsk_shadow_node_peek_shadow (node, i);
|
2017-12-09 17:26:29 +00:00
|
|
|
const float dx = shadow->dx;
|
|
|
|
const float dy = shadow->dy;
|
2017-12-08 12:12:43 +00:00
|
|
|
int texture_id;
|
|
|
|
gboolean is_offscreen;
|
2017-12-09 13:32:24 +00:00
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
g_assert (shadow->radius <= 0);
|
|
|
|
|
|
|
|
if (gsk_render_node_get_node_type (shadow_child) == GSK_TEXT_NODE)
|
|
|
|
{
|
2018-01-19 14:00:22 +00:00
|
|
|
ops_offset (builder, dx, dy);
|
2017-12-09 17:26:29 +00:00
|
|
|
render_text_node (self, shadow_child, builder, &shadow->color, TRUE);
|
2018-04-11 16:09:30 +00:00
|
|
|
ops_offset (builder, - dx, - dy);
|
2017-12-08 12:12:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-03 16:49:51 +00:00
|
|
|
min_x = builder->dx + shadow_child->bounds.origin.x;
|
|
|
|
min_y = builder->dy + shadow_child->bounds.origin.y;
|
2018-12-02 08:41:13 +00:00
|
|
|
max_x = min_x + shadow_child->bounds.size.width;
|
|
|
|
max_y = min_y + shadow_child->bounds.size.height;
|
|
|
|
|
2018-01-19 14:00:22 +00:00
|
|
|
/* Draw the child offscreen, without the offset. */
|
2017-12-08 12:12:43 +00:00
|
|
|
add_offscreen_ops (self, builder,
|
2018-12-02 08:05:50 +00:00
|
|
|
&shadow_child->bounds,
|
2018-03-14 11:36:32 +00:00
|
|
|
shadow_child, &texture_id, &is_offscreen, FALSE, TRUE);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2018-01-19 14:00:22 +00:00
|
|
|
ops_offset (builder, dx, dy);
|
2018-03-15 17:07:35 +00:00
|
|
|
ops_set_program (builder, &self->coloring_program);
|
2017-12-08 12:12:43 +00:00
|
|
|
ops_set_color (builder, &shadow->color);
|
|
|
|
ops_set_texture (builder, texture_id);
|
|
|
|
if (is_offscreen)
|
|
|
|
{
|
|
|
|
const GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
|
|
|
{ { dx + min_x, dy + min_y }, { 0, 1 }, },
|
|
|
|
{ { dx + min_x, dy + max_y }, { 0, 0 }, },
|
|
|
|
{ { dx + max_x, dy + min_y }, { 1, 1 }, },
|
|
|
|
|
|
|
|
{ { dx + max_x, dy + max_y }, { 1, 0 }, },
|
|
|
|
{ { dx + min_x, dy + max_y }, { 0, 0 }, },
|
|
|
|
{ { dx + max_x, dy + min_y }, { 1, 1 }, },
|
|
|
|
};
|
|
|
|
|
2017-12-09 17:26:29 +00:00
|
|
|
ops_draw (builder, vertex_data);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
|
|
|
{ { dx + min_x, dy + min_y }, { 0, 0 }, },
|
|
|
|
{ { dx + min_x, dy + max_y }, { 0, 1 }, },
|
|
|
|
{ { dx + max_x, dy + min_y }, { 1, 0 }, },
|
|
|
|
|
|
|
|
{ { dx + max_x, dy + max_y }, { 1, 1 }, },
|
|
|
|
{ { dx + min_x, dy + max_y }, { 0, 1 }, },
|
|
|
|
{ { dx + max_x, dy + min_y }, { 1, 0 }, },
|
|
|
|
};
|
|
|
|
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
2018-01-19 14:00:22 +00:00
|
|
|
|
2018-04-11 16:09:30 +00:00
|
|
|
ops_offset (builder, - dx, - dy);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now draw the child normally */
|
|
|
|
gsk_gl_renderer_add_render_ops (self, original_child, builder);
|
|
|
|
}
|
|
|
|
|
2017-12-11 07:22:28 +00:00
|
|
|
static inline void
|
|
|
|
render_cross_fade_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2018-12-02 08:05:50 +00:00
|
|
|
const float min_x = builder->dx + node->bounds.origin.x;
|
|
|
|
const float min_y = builder->dy + node->bounds.origin.y;
|
2017-12-11 07:22:28 +00:00
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
|
|
|
GskRenderNode *start_node = gsk_cross_fade_node_get_start_child (node);
|
|
|
|
GskRenderNode *end_node = gsk_cross_fade_node_get_end_child (node);
|
|
|
|
float progress = gsk_cross_fade_node_get_progress (node);
|
|
|
|
int start_texture_id;
|
|
|
|
int end_texture_id;
|
2017-12-19 11:45:32 +00:00
|
|
|
gboolean is_offscreen1, is_offscreen2;
|
2017-12-11 07:22:28 +00:00
|
|
|
RenderOp op;
|
|
|
|
const GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
|
|
|
{ { min_x, min_y }, { 0, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 0 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 1 }, },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* TODO: We create 2 textures here as big as the cross-fade node, but both the
|
|
|
|
* start and the end node might be a lot smaller than that. */
|
|
|
|
|
2018-12-02 08:05:50 +00:00
|
|
|
add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
start_node,
|
2018-03-14 11:36:32 +00:00
|
|
|
&start_texture_id, &is_offscreen1, TRUE, TRUE);
|
2017-12-11 07:22:28 +00:00
|
|
|
|
2018-12-02 08:05:50 +00:00
|
|
|
add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
end_node,
|
2018-03-14 11:36:32 +00:00
|
|
|
&end_texture_id, &is_offscreen2, TRUE, TRUE);
|
2017-12-11 07:22:28 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->cross_fade_program);
|
|
|
|
op.op = OP_CHANGE_CROSS_FADE;
|
|
|
|
op.cross_fade.progress = progress;
|
|
|
|
op.cross_fade.source2 = end_texture_id;
|
|
|
|
ops_add (builder, &op);
|
|
|
|
ops_set_texture (builder, start_texture_id);
|
|
|
|
|
|
|
|
ops_draw (builder, vertex_data);
|
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
|
|
|
apply_viewport_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> New Viewport: %f, %f, %f, %f", op->viewport.origin.x, op->viewport.origin.y, op->viewport.size.width, op->viewport.size.height);
|
|
|
|
glUniform4f (program->viewport_location,
|
|
|
|
op->viewport.origin.x, op->viewport.origin.y,
|
|
|
|
op->viewport.size.width, op->viewport.size.height);
|
|
|
|
glViewport (0, 0, op->viewport.size.width, op->viewport.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_modelview_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
float mat[16];
|
|
|
|
|
|
|
|
OP_PRINT (" -> Modelview");
|
|
|
|
graphene_matrix_to_float (&op->modelview, mat);
|
|
|
|
glUniformMatrix4fv (program->modelview_location, 1, GL_FALSE, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_projection_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
float mat[16];
|
|
|
|
|
|
|
|
OP_PRINT (" -> Projection");
|
|
|
|
graphene_matrix_to_float (&op->projection, mat);
|
|
|
|
glUniformMatrix4fv (program->projection_location, 1, GL_FALSE, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_program_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Program: %d", op->program->index);
|
|
|
|
glUseProgram (op->program->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_render_target_op (GskGLRenderer *self,
|
|
|
|
const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Render Target: %d", op->render_target_id);
|
|
|
|
|
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, op->render_target_id);
|
|
|
|
|
|
|
|
if (op->render_target_id != 0)
|
|
|
|
glDisable (GL_SCISSOR_TEST);
|
|
|
|
else
|
|
|
|
gsk_gl_renderer_setup_render_mode (self); /* Reset glScissor etc. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_color_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Color: (%f, %f, %f, %f)", op->color.red, op->color.green, op->color.blue, op->color.alpha);
|
|
|
|
glUniform4f (program->color.color_location,
|
|
|
|
op->color.red, op->color.green, op->color.blue, op->color.alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_opacity_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Opacity %f", op->opacity);
|
|
|
|
glUniform1f (program->alpha_location, op->opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_source_texture_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
g_assert(op->texture_id != 0);
|
|
|
|
OP_PRINT (" -> New texture: %d", op->texture_id);
|
|
|
|
/* Use texture unit 0 for the source */
|
|
|
|
glUniform1i (program->source_location, 0);
|
|
|
|
glActiveTexture (GL_TEXTURE0);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, op->texture_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_color_matrix_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
float mat[16];
|
|
|
|
float vec[4];
|
|
|
|
OP_PRINT (" -> Color Matrix");
|
|
|
|
graphene_matrix_to_float (&op->color_matrix.matrix, mat);
|
|
|
|
glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
|
|
|
|
|
|
|
|
graphene_vec4_to_float (&op->color_matrix.offset, vec);
|
|
|
|
glUniform4fv (program->color_matrix.color_offset_location, 1, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_clip_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Clip (%f, %f, %f, %f) (%f, %f, %f, %f), (%f, %f, %f, %f)",
|
|
|
|
op->clip.bounds.origin.x, op->clip.bounds.origin.y,
|
|
|
|
op->clip.bounds.size.width, op->clip.bounds.size.height,
|
|
|
|
op->clip.corner[0].width,
|
|
|
|
op->clip.corner[1].width,
|
|
|
|
op->clip.corner[2].width,
|
|
|
|
op->clip.corner[3].width,
|
|
|
|
op->clip.corner[0].height,
|
|
|
|
op->clip.corner[1].height,
|
|
|
|
op->clip.corner[2].height,
|
|
|
|
op->clip.corner[3].height);
|
|
|
|
glUniform4f (program->clip_location,
|
|
|
|
op->clip.bounds.origin.x, op->clip.bounds.origin.y,
|
|
|
|
op->clip.bounds.size.width, op->clip.bounds.size.height);
|
|
|
|
|
|
|
|
glUniform4f (program->clip_corner_widths_location,
|
|
|
|
op->clip.corner[0].width,
|
|
|
|
op->clip.corner[1].width,
|
|
|
|
op->clip.corner[2].width,
|
|
|
|
op->clip.corner[3].width);
|
|
|
|
glUniform4f (program->clip_corner_heights_location,
|
|
|
|
op->clip.corner[0].height,
|
|
|
|
op->clip.corner[1].height,
|
|
|
|
op->clip.corner[2].height,
|
|
|
|
op->clip.corner[3].height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_inset_shadow_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> inset shadow. Color: (%f, %f, %f, %f), Offset: (%f, %f), Spread: %f, Outline: (%f, %f, %f, %f) Corner widths: (%f, %f, %f, %f), Corner Heights: (%f, %f, %f, %f)",
|
|
|
|
op->inset_shadow.color[0],
|
|
|
|
op->inset_shadow.color[1],
|
|
|
|
op->inset_shadow.color[2],
|
|
|
|
op->inset_shadow.color[3],
|
|
|
|
op->inset_shadow.offset[0],
|
|
|
|
op->inset_shadow.offset[1],
|
|
|
|
op->inset_shadow.spread,
|
|
|
|
op->inset_shadow.outline[0],
|
|
|
|
op->inset_shadow.outline[1],
|
|
|
|
op->inset_shadow.outline[2],
|
|
|
|
op->inset_shadow.outline[3],
|
|
|
|
op->inset_shadow.corner_widths[0],
|
|
|
|
op->inset_shadow.corner_widths[1],
|
|
|
|
op->inset_shadow.corner_widths[2],
|
|
|
|
op->inset_shadow.corner_widths[3],
|
|
|
|
op->inset_shadow.corner_heights[0],
|
|
|
|
op->inset_shadow.corner_heights[1],
|
|
|
|
op->inset_shadow.corner_heights[2],
|
|
|
|
op->inset_shadow.corner_heights[3]);
|
|
|
|
glUniform4fv (program->inset_shadow.color_location, 1, op->inset_shadow.color);
|
|
|
|
glUniform2fv (program->inset_shadow.offset_location, 1, op->inset_shadow.offset);
|
|
|
|
glUniform1f (program->inset_shadow.spread_location, op->inset_shadow.spread);
|
|
|
|
glUniform4fv (program->inset_shadow.outline_location, 1, op->inset_shadow.outline);
|
|
|
|
glUniform4fv (program->inset_shadow.corner_widths_location, 1, op->inset_shadow.corner_widths);
|
|
|
|
glUniform4fv (program->inset_shadow.corner_heights_location, 1, op->inset_shadow.corner_heights);
|
|
|
|
}
|
2018-01-15 09:55:40 +00:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_unblurred_outset_shadow_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> unblurred outset shadow");
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.color_location, 1, op->unblurred_outset_shadow.color);
|
|
|
|
glUniform2fv (program->unblurred_outset_shadow.offset_location, 1, op->unblurred_outset_shadow.offset);
|
|
|
|
glUniform1f (program->unblurred_outset_shadow.spread_location, op->unblurred_outset_shadow.spread);
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.outline_location, 1, op->unblurred_outset_shadow.outline);
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.corner_widths_location, 1,
|
|
|
|
op->unblurred_outset_shadow.corner_widths);
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.corner_heights_location, 1,
|
|
|
|
op->unblurred_outset_shadow.corner_heights);
|
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
|
|
|
apply_outset_shadow_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> outset shadow");
|
|
|
|
glUniform4fv (program->outset_shadow.outline_location, 1, op->outset_shadow.outline);
|
|
|
|
glUniform4fv (program->outset_shadow.corner_widths_location, 1, op->outset_shadow.corner_widths);
|
|
|
|
glUniform4fv (program->outset_shadow.corner_heights_location, 1, op->outset_shadow.corner_heights);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_linear_gradient_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Linear gradient");
|
|
|
|
glUniform1i (program->linear_gradient.num_color_stops_location,
|
|
|
|
op->linear_gradient.n_color_stops);
|
|
|
|
glUniform4fv (program->linear_gradient.color_stops_location,
|
|
|
|
op->linear_gradient.n_color_stops,
|
|
|
|
op->linear_gradient.color_stops);
|
|
|
|
glUniform1fv (program->linear_gradient.color_offsets_location,
|
|
|
|
op->linear_gradient.n_color_stops,
|
|
|
|
op->linear_gradient.color_offsets);
|
|
|
|
glUniform2f (program->linear_gradient.start_point_location,
|
|
|
|
op->linear_gradient.start_point.x, op->linear_gradient.start_point.y);
|
|
|
|
glUniform2f (program->linear_gradient.end_point_location,
|
|
|
|
op->linear_gradient.end_point.x, op->linear_gradient.end_point.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_border_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
2018-03-15 16:27:19 +00:00
|
|
|
const GskRoundedRect *o = &op->border.outline;
|
|
|
|
float outline[4];
|
|
|
|
float widths[4];
|
|
|
|
float heights[4];
|
|
|
|
int i;
|
2017-12-16 09:02:03 +00:00
|
|
|
OP_PRINT (" -> Border (%f, %f, %f, %f)",
|
|
|
|
op->border.widths[0], op->border.widths[1], op->border.widths[2], op->border.widths[3]);
|
2018-03-15 16:27:19 +00:00
|
|
|
|
|
|
|
outline[0] = o->bounds.origin.x;
|
|
|
|
outline[1] = o->bounds.origin.y;
|
|
|
|
outline[2] = o->bounds.size.width;
|
|
|
|
outline[3] = o->bounds.size.height;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
|
|
|
widths[i] = o->corner[i].width;
|
|
|
|
heights[i] = o->corner[i].height;
|
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
glUniform4fv (program->border.widths_location, 1, op->border.widths);
|
2018-03-15 16:27:19 +00:00
|
|
|
glUniform4fv (program->border.outline_location, 1, outline);
|
|
|
|
glUniform4fv (program->border.corner_widths_location, 1, widths);
|
|
|
|
glUniform4fv (program->border.corner_heights_location, 1, heights);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_border_color_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Border color (%f, %f, %f, %f)",
|
|
|
|
op->border.color[0], op->border.color[1], op->border.color[2], op->border.color[3]);
|
|
|
|
glUniform4fv (program->border.color_location, 1, op->border.color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_blur_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Blur");
|
|
|
|
glUniform1f (program->blur.blur_radius_location, op->blur.radius);
|
|
|
|
glUniform2f (program->blur.blur_size_location, op->blur.size.width, op->blur.size.height);
|
2017-12-28 15:41:32 +00:00
|
|
|
/*glUniform2f (program->blur.dir_location, op->blur.dir[0], op->blur.dir[1]);*/
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_cross_fade_op (const Program *program,
|
|
|
|
const RenderOp *op)
|
|
|
|
{
|
|
|
|
/* End texture id */
|
|
|
|
glUniform1i (program->cross_fade.source2_location, 1);
|
|
|
|
glActiveTexture (GL_TEXTURE0 + 1);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, op->cross_fade.source2);
|
|
|
|
/* progress */
|
|
|
|
glUniform1f (program->cross_fade.progress_location, op->cross_fade.progress);
|
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_renderer_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (gobject);
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
g_clear_pointer (&self->render_ops, g_array_unref);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gsk_gl_renderer_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
2016-07-03 20:12:22 +00:00
|
|
|
static gboolean
|
2016-11-29 03:51:07 +00:00
|
|
|
gsk_gl_renderer_create_programs (GskGLRenderer *self,
|
|
|
|
GError **error)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2016-07-03 20:12:22 +00:00
|
|
|
GskShaderBuilder *builder;
|
2016-11-29 03:51:07 +00:00
|
|
|
GError *shader_error = NULL;
|
2017-11-30 17:47:55 +00:00
|
|
|
int i;
|
2018-01-08 20:46:16 +00:00
|
|
|
static const struct {
|
2017-11-30 17:47:55 +00:00
|
|
|
const char *name;
|
|
|
|
const char *vs;
|
|
|
|
const char *fs;
|
|
|
|
} program_definitions[] = {
|
2017-12-01 10:55:10 +00:00
|
|
|
{ "blit", "blit.vs.glsl", "blit.fs.glsl" },
|
|
|
|
{ "color", "blit.vs.glsl", "color.fs.glsl" },
|
|
|
|
{ "coloring", "blit.vs.glsl", "coloring.fs.glsl" },
|
|
|
|
{ "color matrix", "blit.vs.glsl", "color_matrix.fs.glsl" },
|
|
|
|
{ "linear gradient", "blit.vs.glsl", "linear_gradient.fs.glsl" },
|
|
|
|
{ "blur", "blit.vs.glsl", "blur.fs.glsl" },
|
|
|
|
{ "inset shadow", "blit.vs.glsl", "inset_shadow.fs.glsl" },
|
|
|
|
{ "outset shadow", "blit.vs.glsl", "outset_shadow.fs.glsl" },
|
2018-01-15 09:55:40 +00:00
|
|
|
{ "unblurred outset shadow", "blit.vs.glsl", "unblurred_outset_shadow.fs.glsl" },
|
2017-12-01 10:55:10 +00:00
|
|
|
{ "border", "blit.vs.glsl", "border.fs.glsl" },
|
2017-12-11 07:22:28 +00:00
|
|
|
{ "cross fade", "blit.vs.glsl", "cross_fade.fs.glsl" },
|
2017-11-30 17:47:55 +00:00
|
|
|
};
|
2016-07-03 21:54:30 +00:00
|
|
|
|
2016-07-03 20:12:22 +00:00
|
|
|
builder = gsk_shader_builder_new ();
|
|
|
|
|
|
|
|
gsk_shader_builder_set_resource_base_path (builder, "/org/gtk/libgsk/glsl");
|
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
if (gdk_gl_context_get_use_es (self->gl_context))
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2016-07-03 20:12:22 +00:00
|
|
|
gsk_shader_builder_set_version (builder, SHADER_VERSION_GLES);
|
2016-07-04 12:46:22 +00:00
|
|
|
gsk_shader_builder_set_vertex_preamble (builder, "es2_common.vs.glsl");
|
|
|
|
gsk_shader_builder_set_fragment_preamble (builder, "es2_common.fs.glsl");
|
2016-07-03 20:12:22 +00:00
|
|
|
gsk_shader_builder_add_define (builder, "GSK_GLES", "1");
|
|
|
|
}
|
2016-07-27 10:34:20 +00:00
|
|
|
else if (gdk_gl_context_is_legacy (self->gl_context))
|
2016-07-03 20:12:22 +00:00
|
|
|
{
|
2016-11-01 15:00:31 +00:00
|
|
|
int maj, min;
|
|
|
|
gdk_gl_context_get_version (self->gl_context, &maj, &min);
|
|
|
|
|
|
|
|
if (maj == 3)
|
|
|
|
gsk_shader_builder_set_version (builder, SHADER_VERSION_GL3_LEGACY);
|
|
|
|
else
|
|
|
|
gsk_shader_builder_set_version (builder, SHADER_VERSION_GL2_LEGACY);
|
|
|
|
|
2016-07-04 12:46:22 +00:00
|
|
|
gsk_shader_builder_set_vertex_preamble (builder, "gl_common.vs.glsl");
|
|
|
|
gsk_shader_builder_set_fragment_preamble (builder, "gl_common.fs.glsl");
|
2016-07-03 20:12:22 +00:00
|
|
|
gsk_shader_builder_add_define (builder, "GSK_LEGACY", "1");
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
2016-07-03 20:12:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gsk_shader_builder_set_version (builder, SHADER_VERSION_GL3);
|
2016-07-04 12:46:22 +00:00
|
|
|
gsk_shader_builder_set_vertex_preamble (builder, "gl3_common.vs.glsl");
|
|
|
|
gsk_shader_builder_set_fragment_preamble (builder, "gl3_common.fs.glsl");
|
2016-07-03 20:12:22 +00:00
|
|
|
gsk_shader_builder_add_define (builder, "GSK_GL3", "1");
|
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-03 20:12:22 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-01-14 20:11:33 +00:00
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), SHADERS))
|
2016-07-03 20:12:22 +00:00
|
|
|
gsk_shader_builder_add_define (builder, "GSK_DEBUG", "1");
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-30 17:47:55 +00:00
|
|
|
for (i = 0; i < GL_N_PROGRAMS; i ++)
|
2017-11-25 07:56:50 +00:00
|
|
|
{
|
2017-11-30 17:47:55 +00:00
|
|
|
Program *prog = &self->programs[i];
|
|
|
|
|
|
|
|
prog->index = i;
|
|
|
|
prog->id = gsk_shader_builder_create_program (builder,
|
|
|
|
program_definitions[i].vs,
|
|
|
|
program_definitions[i].fs,
|
|
|
|
&shader_error);
|
|
|
|
|
|
|
|
if (shader_error != NULL)
|
|
|
|
{
|
|
|
|
g_propagate_prefixed_error (error, shader_error,
|
|
|
|
"Unable to create '%s' program (from %s and %s):\n",
|
|
|
|
program_definitions[i].name,
|
|
|
|
program_definitions[i].vs,
|
|
|
|
program_definitions[i].fs);
|
|
|
|
|
|
|
|
g_object_unref (builder);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, alpha);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, source);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, clip);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, clip_corner_widths);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, clip_corner_heights);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, viewport);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, projection);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, modelview);
|
2017-11-30 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 17:47:55 +00:00
|
|
|
/* color */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (color, color);
|
2017-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
/* coloring */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (coloring, color);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-30 17:47:55 +00:00
|
|
|
/* color matrix */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (color_matrix, color_matrix);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (color_matrix, color_offset);
|
2017-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
/* linear gradient */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, color_stops);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, color_offsets);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, num_color_stops);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, start_point);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, end_point);
|
2017-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
/* blur */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (blur, blur_radius);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (blur, blur_size);
|
2017-12-28 15:41:32 +00:00
|
|
|
/*INIT_PROGRAM_UNIFORM_LOCATION (blur, dir);*/
|
2017-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
/* inset shadow */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, color);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, spread);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, offset);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, outline);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, corner_widths);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, corner_heights);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-12-01 07:30:11 +00:00
|
|
|
/* outset shadow */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (outset_shadow, outline);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (outset_shadow, corner_widths);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (outset_shadow, corner_heights);
|
2017-12-01 07:30:11 +00:00
|
|
|
|
2018-01-15 09:55:40 +00:00
|
|
|
/* unblurred outset shadow */
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, color);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, spread);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, offset);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, outline);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, corner_widths);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, corner_heights);
|
|
|
|
|
2017-12-01 10:55:10 +00:00
|
|
|
/* border */
|
2017-12-01 12:56:56 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (border, color);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (border, widths);
|
2018-03-15 16:27:19 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (border, outline);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (border, corner_widths);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (border, corner_heights);
|
2017-12-01 10:55:10 +00:00
|
|
|
|
2017-12-11 07:22:28 +00:00
|
|
|
/* cross fade */
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (cross_fade, progress);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (cross_fade, source2);
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
g_object_unref (builder);
|
2017-11-30 17:47:55 +00:00
|
|
|
return TRUE;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-11-29 03:51:07 +00:00
|
|
|
gsk_gl_renderer_realize (GskRenderer *renderer,
|
2018-03-26 19:13:52 +00:00
|
|
|
GdkSurface *surface,
|
2016-11-29 03:51:07 +00:00
|
|
|
GError **error)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
|
|
|
|
|
|
|
/* If we didn't get a GdkGLContext before realization, try creating
|
|
|
|
* one now, for our exclusive use.
|
|
|
|
*/
|
2016-07-27 10:34:20 +00:00
|
|
|
if (self->gl_context == NULL)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2018-03-26 19:13:52 +00:00
|
|
|
self->gl_context = gdk_surface_create_gl_context (surface, error);
|
2016-11-29 03:51:07 +00:00
|
|
|
if (self->gl_context == NULL)
|
|
|
|
return FALSE;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 03:51:07 +00:00
|
|
|
if (!gdk_gl_context_realize (self->gl_context, error))
|
|
|
|
return FALSE;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
g_assert (self->gl_driver == NULL);
|
2016-07-27 10:34:20 +00:00
|
|
|
self->gl_profiler = gsk_gl_profiler_new (self->gl_context);
|
2017-11-03 12:09:02 +00:00
|
|
|
self->gl_driver = gsk_gl_driver_new (self->gl_context);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_RENDERER_NOTE (renderer, OPENGL, g_message ("Creating buffers and programs"));
|
2016-11-29 03:51:07 +00:00
|
|
|
if (!gsk_gl_renderer_create_programs (self, error))
|
2016-07-03 20:12:22 +00:00
|
|
|
return FALSE;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
gsk_gl_glyph_cache_init (&self->glyph_cache, renderer, self->gl_driver);
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_gl_shadow_cache_init (&self->shadow_cache);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_renderer_unrealize (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
2017-12-29 04:31:49 +00:00
|
|
|
guint i;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
if (self->gl_context == NULL)
|
2016-03-17 13:48:19 +00:00
|
|
|
return;
|
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-20 16:55:35 +00:00
|
|
|
/* We don't need to iterate to destroy the associated GL resources,
|
|
|
|
* as they will be dropped when we finalize the GskGLDriver
|
|
|
|
*/
|
2017-11-22 10:32:23 +00:00
|
|
|
g_array_set_size (self->render_ops, 0);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-12-29 04:31:49 +00:00
|
|
|
for (i = 0; i < GL_N_PROGRAMS; i ++)
|
|
|
|
glDeleteProgram (self->programs[i].id);
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-11-18 13:30:57 +00:00
|
|
|
gsk_gl_glyph_cache_free (&self->glyph_cache);
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_gl_shadow_cache_free (&self->shadow_cache, self->gl_driver);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2016-07-12 13:50:48 +00:00
|
|
|
g_clear_object (&self->gl_profiler);
|
2016-07-08 15:21:13 +00:00
|
|
|
g_clear_object (&self->gl_driver);
|
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
if (self->gl_context == gdk_gl_context_get_current ())
|
2016-03-17 13:48:19 +00:00
|
|
|
gdk_gl_context_clear_current ();
|
2017-11-01 14:33:02 +00:00
|
|
|
|
|
|
|
g_clear_object (&self->gl_context);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_renderer_clear_tree (GskGLRenderer *self)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2017-11-23 09:28:30 +00:00
|
|
|
int removed_textures;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
if (self->gl_context == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
|
|
|
|
|
|
|
g_array_remove_range (self->render_ops, 0, self->render_ops->len);
|
|
|
|
removed_textures = gsk_gl_driver_collect_textures (self->gl_driver);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_RENDERER_NOTE (GSK_RENDERER (self), OPENGL, g_message ("Collected: %d textures", removed_textures));
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
static void
|
2017-11-22 10:32:23 +00:00
|
|
|
gsk_gl_renderer_clear (GskGLRenderer *self)
|
2016-07-25 16:15:05 +00:00
|
|
|
{
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_RENDERER_NOTE (GSK_RENDERER (self), OPENGL, g_message ("Clearing viewport"));
|
2017-11-22 10:32:23 +00:00
|
|
|
glClearColor (0, 0, 0, 0);
|
|
|
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2016-07-25 16:15:05 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
static void
|
2017-11-22 10:32:23 +00:00
|
|
|
gsk_gl_renderer_setup_render_mode (GskGLRenderer *self)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2018-03-28 13:01:34 +00:00
|
|
|
if (self->render_region == NULL)
|
|
|
|
{
|
2017-11-22 10:32:23 +00:00
|
|
|
glDisable (GL_SCISSOR_TEST);
|
2018-03-28 13:01:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GdkSurface *surface = gsk_renderer_get_surface (GSK_RENDERER (self));
|
|
|
|
cairo_rectangle_int_t extents;
|
|
|
|
int surface_height;
|
2017-11-20 13:30:46 +00:00
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
g_assert (cairo_region_num_rectangles (self->render_region) == 1);
|
2017-11-20 13:30:46 +00:00
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
surface_height = gdk_surface_get_height (surface) * self->scale_factor;
|
|
|
|
cairo_region_get_rectangle (self->render_region, 0, &extents);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
glEnable (GL_SCISSOR_TEST);
|
|
|
|
glScissor (extents.x * self->scale_factor,
|
|
|
|
surface_height - (extents.height * self->scale_factor) - (extents.y * self->scale_factor),
|
|
|
|
extents.width * self->scale_factor,
|
|
|
|
extents.height * self->scale_factor);
|
|
|
|
}
|
2017-11-22 10:32:23 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2017-12-09 17:26:29 +00:00
|
|
|
const float min_x = builder->dx + node->bounds.origin.x;
|
|
|
|
const float min_y = builder->dy + node->bounds.origin.y;
|
2017-12-08 12:12:43 +00:00
|
|
|
const float max_x = min_x + node->bounds.size.width;
|
|
|
|
const float max_y = min_y + node->bounds.size.height;
|
2017-11-22 10:32:23 +00:00
|
|
|
/* Default vertex data */
|
2017-12-01 09:27:31 +00:00
|
|
|
const GskQuadVertex vertex_data[GL_N_VERTICES] = {
|
2017-11-22 10:32:23 +00:00
|
|
|
{ { min_x, min_y }, { 0, 0 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 1 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 0 }, },
|
|
|
|
|
|
|
|
{ { max_x, max_y }, { 1, 1 }, },
|
|
|
|
{ { min_x, max_y }, { 0, 1 }, },
|
|
|
|
{ { max_x, min_y }, { 1, 0 }, },
|
|
|
|
};
|
2016-06-30 16:06:31 +00:00
|
|
|
|
2018-03-25 09:47:04 +00:00
|
|
|
/* This can still happen, even if the render nodes are created using
|
|
|
|
* GtkSnapshot, so let's juse be safe. */
|
|
|
|
if (node->bounds.size.width == 0.0f || node->bounds.size.height == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2018-05-01 10:51:04 +00:00
|
|
|
/* Check whether the render node is entirely out of the current
|
|
|
|
* already transformed clip region */
|
|
|
|
{
|
|
|
|
graphene_rect_t transformed_node_bounds;
|
|
|
|
|
2018-10-06 07:23:26 +00:00
|
|
|
ops_transform_bounds_modelview (builder,
|
|
|
|
&node->bounds,
|
|
|
|
&transformed_node_bounds);
|
2018-05-01 10:51:04 +00:00
|
|
|
|
|
|
|
if (!graphene_rect_intersection (&builder->current_clip.bounds,
|
|
|
|
&transformed_node_bounds, NULL))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
switch (gsk_render_node_get_node_type (node))
|
2016-08-09 15:30:13 +00:00
|
|
|
{
|
2017-11-22 10:32:23 +00:00
|
|
|
case GSK_NOT_A_RENDER_NODE:
|
|
|
|
g_assert_not_reached ();
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case GSK_CONTAINER_NODE:
|
|
|
|
{
|
|
|
|
guint i, p;
|
2017-11-16 11:20:35 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
for (i = 0, p = gsk_container_node_get_n_children (node); i < p; i ++)
|
2017-11-16 11:20:35 +00:00
|
|
|
{
|
2017-11-22 10:32:23 +00:00
|
|
|
GskRenderNode *child = gsk_container_node_get_child (node, i);
|
2017-11-16 11:20:35 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2017-11-16 11:20:35 +00:00
|
|
|
}
|
2017-11-03 12:09:02 +00:00
|
|
|
}
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2016-08-09 15:30:13 +00:00
|
|
|
|
2018-04-23 22:41:48 +00:00
|
|
|
case GSK_DEBUG_NODE:
|
|
|
|
gsk_gl_renderer_add_render_ops (self,
|
|
|
|
gsk_debug_node_get_child (node),
|
|
|
|
builder);
|
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case GSK_COLOR_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_color_node (self, node, builder, vertex_data);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2016-08-09 15:30:13 +00:00
|
|
|
|
2017-11-04 15:03:03 +00:00
|
|
|
case GSK_TEXTURE_NODE:
|
2018-01-18 07:21:11 +00:00
|
|
|
render_texture_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2016-11-07 16:59:38 +00:00
|
|
|
|
2018-03-20 01:46:57 +00:00
|
|
|
case GSK_OFFSET_NODE:
|
|
|
|
render_offset_node (self, node, builder);
|
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case GSK_TRANSFORM_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_transform_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2017-01-06 19:53:12 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case GSK_OPACITY_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_opacity_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2016-11-16 03:14:32 +00:00
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
case GSK_LINEAR_GRADIENT_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_linear_gradient_node (self, node, builder, vertex_data);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_CLIP_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_clip_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_ROUNDED_CLIP_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_rounded_clip_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2016-12-12 18:30:41 +00:00
|
|
|
|
2017-11-18 13:30:57 +00:00
|
|
|
case GSK_TEXT_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_text_node (self, node, builder,
|
2017-12-09 17:26:29 +00:00
|
|
|
gsk_text_node_peek_color (node), FALSE);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
2017-12-01 09:27:31 +00:00
|
|
|
|
2017-11-24 09:32:08 +00:00
|
|
|
case GSK_COLOR_MATRIX_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_color_matrix_node (self, node, builder, vertex_data);
|
2017-11-24 09:32:08 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-25 07:56:50 +00:00
|
|
|
case GSK_BLUR_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_blur_node (self, node, builder, vertex_data);
|
2017-11-25 07:56:50 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-30 15:48:03 +00:00
|
|
|
case GSK_INSET_SHADOW_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_inset_shadow_node (self, node, builder, vertex_data);
|
2017-11-30 15:48:03 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-01 07:30:11 +00:00
|
|
|
case GSK_OUTSET_SHADOW_NODE:
|
2018-01-15 09:55:40 +00:00
|
|
|
if (gsk_outset_shadow_node_get_blur_radius (node) > 0)
|
|
|
|
render_outset_shadow_node (self, node, builder);
|
|
|
|
else
|
|
|
|
render_unblurred_outset_shadow_node (self, node, builder, vertex_data);
|
2017-12-01 07:30:11 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-01 09:27:31 +00:00
|
|
|
case GSK_SHADOW_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_shadow_node (self, node, builder, vertex_data);
|
2017-12-01 09:27:31 +00:00
|
|
|
break;
|
2017-11-30 15:48:03 +00:00
|
|
|
|
2017-12-01 07:30:11 +00:00
|
|
|
case GSK_BORDER_NODE:
|
2017-12-08 12:12:43 +00:00
|
|
|
render_border_node (self, node, builder);
|
2017-12-01 10:55:10 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
case GSK_CROSS_FADE_NODE:
|
2017-12-11 07:22:28 +00:00
|
|
|
render_cross_fade_node (self, node, builder);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_REPEATING_LINEAR_GRADIENT_NODE:
|
2017-11-03 12:09:02 +00:00
|
|
|
case GSK_BLEND_NODE:
|
|
|
|
case GSK_REPEAT_NODE:
|
2018-03-25 09:46:48 +00:00
|
|
|
case GSK_CAIRO_NODE:
|
2016-12-13 03:20:04 +00:00
|
|
|
default:
|
|
|
|
{
|
2017-12-01 08:58:58 +00:00
|
|
|
render_fallback_node (self, node, builder, vertex_data);
|
2017-11-22 10:32:23 +00:00
|
|
|
}
|
2017-11-03 12:09:02 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 09:43:17 +00:00
|
|
|
static void
|
2018-12-02 08:05:50 +00:00
|
|
|
add_offscreen_ops (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GskRenderNode *child_node,
|
|
|
|
int *texture_id_out,
|
|
|
|
gboolean *is_offscreen,
|
|
|
|
gboolean force_offscreen,
|
|
|
|
gboolean reset_clip)
|
2017-11-24 09:18:51 +00:00
|
|
|
{
|
2018-04-11 09:20:50 +00:00
|
|
|
const float scale = ops_get_scale (builder);
|
2018-12-02 08:05:50 +00:00
|
|
|
const float width = bounds->size.width * scale;
|
|
|
|
const float height = bounds->size.height * scale;
|
2018-12-02 07:12:44 +00:00
|
|
|
const float dx = builder->dx;
|
|
|
|
const float dy = builder->dy;
|
2017-11-24 09:18:51 +00:00
|
|
|
int render_target;
|
|
|
|
int prev_render_target;
|
|
|
|
RenderOp op;
|
|
|
|
graphene_matrix_t identity;
|
|
|
|
graphene_matrix_t prev_projection;
|
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
graphene_matrix_t item_proj;
|
2018-01-27 11:13:37 +00:00
|
|
|
GskRoundedRect prev_clip;
|
2018-12-02 15:03:08 +00:00
|
|
|
float prev_opacity;
|
2018-11-28 17:40:48 +00:00
|
|
|
int texture_id = 0;
|
2017-11-24 09:18:51 +00:00
|
|
|
|
2017-11-24 09:43:17 +00:00
|
|
|
/* We need the child node as a texture. If it already is one, we don't need to draw
|
|
|
|
* it on a framebuffer of course. */
|
2017-12-19 11:45:32 +00:00
|
|
|
if (gsk_render_node_get_node_type (child_node) == GSK_TEXTURE_NODE && !force_offscreen)
|
2017-11-24 09:43:17 +00:00
|
|
|
{
|
|
|
|
GdkTexture *texture = gsk_texture_node_get_texture (child_node);
|
|
|
|
int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
|
|
|
|
|
|
|
|
get_gl_scaling_filters (child_node, &gl_min_filter, &gl_mag_filter);
|
|
|
|
|
2018-11-28 17:40:48 +00:00
|
|
|
*texture_id_out = gsk_gl_driver_get_texture_for_texture (self->gl_driver,
|
|
|
|
texture,
|
|
|
|
gl_min_filter,
|
|
|
|
gl_mag_filter);
|
2017-11-24 09:43:17 +00:00
|
|
|
*is_offscreen = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2017-11-24 09:18:51 +00:00
|
|
|
|
2018-11-28 17:40:48 +00:00
|
|
|
/* Check if we've already cached the drawn texture. */
|
|
|
|
{
|
|
|
|
const int cached_id = gsk_gl_driver_get_texture_for_pointer (self->gl_driver, child_node);
|
|
|
|
|
|
|
|
if (cached_id != 0)
|
|
|
|
{
|
|
|
|
*texture_id_out = cached_id;
|
|
|
|
/* We didn't render it offscreen, but hand out an offscreen texture id */
|
|
|
|
*is_offscreen = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
texture_id = gsk_gl_driver_create_texture (self->gl_driver, width, height);
|
|
|
|
gsk_gl_driver_bind_source_texture (self->gl_driver, texture_id);
|
|
|
|
gsk_gl_driver_init_texture_empty (self->gl_driver, texture_id);
|
|
|
|
render_target = gsk_gl_driver_create_render_target (self->gl_driver, texture_id, TRUE, TRUE);
|
2017-11-24 09:18:51 +00:00
|
|
|
|
|
|
|
graphene_matrix_init_ortho (&item_proj,
|
2018-12-02 08:05:50 +00:00
|
|
|
bounds->origin.x * scale,
|
|
|
|
(bounds->origin.x + bounds->size.width) * scale,
|
|
|
|
bounds->origin.y * scale,
|
|
|
|
(bounds->origin.y + bounds->size.height) * scale,
|
2017-11-24 09:18:51 +00:00
|
|
|
ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE);
|
|
|
|
graphene_matrix_scale (&item_proj, 1, -1, 1);
|
|
|
|
graphene_matrix_init_identity (&identity);
|
2018-04-11 09:20:50 +00:00
|
|
|
graphene_matrix_scale (&identity, scale, scale, 1);
|
2017-11-24 09:18:51 +00:00
|
|
|
|
|
|
|
prev_render_target = ops_set_render_target (builder, render_target);
|
|
|
|
/* Clear since we use this rendertarget for the first time */
|
|
|
|
op.op = OP_CLEAR;
|
|
|
|
ops_add (builder, &op);
|
|
|
|
prev_projection = ops_set_projection (builder, &item_proj);
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_push_modelview (builder, &identity);
|
2018-12-02 08:05:50 +00:00
|
|
|
prev_viewport = ops_set_viewport (builder,
|
|
|
|
&GRAPHENE_RECT_INIT (bounds->origin.x * scale,
|
|
|
|
bounds->origin.y * scale,
|
|
|
|
width, height));
|
2018-03-14 11:36:32 +00:00
|
|
|
if (reset_clip)
|
|
|
|
prev_clip = ops_set_clip (builder,
|
2018-12-02 08:05:50 +00:00
|
|
|
&GSK_ROUNDED_RECT_INIT (bounds->origin.x * scale,
|
|
|
|
bounds->origin.y * scale,
|
2018-03-15 12:52:07 +00:00
|
|
|
width, height));
|
2018-12-02 08:05:50 +00:00
|
|
|
|
2018-12-02 07:12:44 +00:00
|
|
|
builder->dx = 0;
|
|
|
|
builder->dy = 0;
|
2018-12-02 15:03:08 +00:00
|
|
|
prev_opacity = ops_set_opacity (builder, 1.0);
|
2017-11-24 09:18:51 +00:00
|
|
|
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child_node, builder);
|
|
|
|
|
2018-12-02 15:03:08 +00:00
|
|
|
ops_set_opacity (builder, prev_opacity);
|
2018-12-02 07:12:44 +00:00
|
|
|
builder->dx = dx;
|
|
|
|
builder->dy = dy;
|
|
|
|
|
2018-03-14 11:36:32 +00:00
|
|
|
if (reset_clip)
|
|
|
|
ops_set_clip (builder, &prev_clip);
|
|
|
|
|
2017-11-24 09:18:51 +00:00
|
|
|
ops_set_viewport (builder, &prev_viewport);
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_pop_modelview (builder);
|
2017-11-24 09:18:51 +00:00
|
|
|
ops_set_projection (builder, &prev_projection);
|
|
|
|
ops_set_render_target (builder, prev_render_target);
|
|
|
|
|
2017-11-24 09:43:17 +00:00
|
|
|
*is_offscreen = TRUE;
|
2018-11-28 17:40:48 +00:00
|
|
|
*texture_id_out = texture_id;
|
|
|
|
|
|
|
|
gsk_gl_driver_set_texture_for_pointer (self->gl_driver, child_node, texture_id);
|
2017-11-24 09:18:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
static void
|
2017-11-22 10:32:23 +00:00
|
|
|
gsk_gl_renderer_render_ops (GskGLRenderer *self,
|
|
|
|
gsize vertex_data_size)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2017-11-22 10:32:23 +00:00
|
|
|
guint i;
|
|
|
|
guint n_ops = self->render_ops->len;
|
|
|
|
const Program *program = NULL;
|
|
|
|
gsize buffer_index = 0;
|
|
|
|
float *vertex_data = g_malloc (vertex_data_size);
|
2017-11-16 20:04:18 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
/*g_message ("%s: Buffer size: %ld", __FUNCTION__, vertex_data_size);*/
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
GLuint buffer_id, vao_id;
|
|
|
|
glGenVertexArrays (1, &vao_id);
|
|
|
|
glBindVertexArray (vao_id);
|
2016-04-26 13:23:12 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
glGenBuffers (1, &buffer_id);
|
|
|
|
glBindBuffer (GL_ARRAY_BUFFER, buffer_id);
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2016-08-04 11:37:54 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
// Fill buffer data
|
|
|
|
for (i = 0; i < n_ops; i ++)
|
|
|
|
{
|
|
|
|
const RenderOp *op = &g_array_index (self->render_ops, RenderOp, i);
|
2016-04-26 13:23:12 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
if (op->op == OP_CHANGE_VAO)
|
|
|
|
{
|
2017-11-22 20:02:50 +00:00
|
|
|
memcpy (vertex_data + buffer_index, &op->vertex_data, sizeof (GskQuadVertex) * GL_N_VERTICES);
|
|
|
|
buffer_index += sizeof (GskQuadVertex) * GL_N_VERTICES / sizeof (float);
|
2017-11-22 10:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
// Set buffer data
|
|
|
|
glBufferData (GL_ARRAY_BUFFER, vertex_data_size, vertex_data, GL_STATIC_DRAW);
|
2016-12-04 15:33:13 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
// Describe buffer contents
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
/* 0 = position location */
|
|
|
|
glEnableVertexAttribArray (0);
|
|
|
|
glVertexAttribPointer (0, 2, GL_FLOAT, GL_FALSE,
|
|
|
|
sizeof (GskQuadVertex),
|
|
|
|
(void *) G_STRUCT_OFFSET (GskQuadVertex, position));
|
|
|
|
/* 1 = texture coord location */
|
|
|
|
glEnableVertexAttribArray (1);
|
|
|
|
glVertexAttribPointer (1, 2, GL_FLOAT, GL_FALSE,
|
|
|
|
sizeof (GskQuadVertex),
|
|
|
|
(void *) G_STRUCT_OFFSET (GskQuadVertex, uv));
|
2017-03-20 09:52:58 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
for (i = 0; i < n_ops; i ++)
|
|
|
|
{
|
|
|
|
const RenderOp *op = &g_array_index (self->render_ops, RenderOp, i);
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
if (op->op == OP_NONE ||
|
|
|
|
op->op == OP_CHANGE_VAO)
|
|
|
|
continue;
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-12-08 19:43:47 +00:00
|
|
|
if (op->op != OP_CHANGE_PROGRAM &&
|
2017-12-21 17:09:32 +00:00
|
|
|
op->op != OP_CHANGE_RENDER_TARGET &&
|
|
|
|
op->op != OP_CLEAR &&
|
2017-12-08 19:43:47 +00:00
|
|
|
program == NULL)
|
|
|
|
continue;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
OP_PRINT ("Op %u: %u", i, op->op);
|
2017-03-20 09:52:58 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
switch (op->op)
|
|
|
|
{
|
|
|
|
case OP_CHANGE_PROJECTION:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_projection_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_MODELVIEW:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_modelview_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_PROGRAM:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_program_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
program = op->program;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_RENDER_TARGET:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_render_target_op (self, program, op);
|
2017-11-22 20:02:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CLEAR:
|
|
|
|
glClearColor (0, 0, 0, 0);
|
|
|
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_VIEWPORT:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_viewport_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_OPACITY:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_opacity_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-24 09:32:08 +00:00
|
|
|
case OP_CHANGE_COLOR_MATRIX:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_color_matrix_op (program, op);
|
2017-11-24 09:32:08 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_CHANGE_COLOR:
|
2017-12-28 15:41:32 +00:00
|
|
|
/*g_assert (program == &self->color_program || program == &self->coloring_program ||*/
|
|
|
|
/*program == &self->shadow_program);*/
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_color_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-05 07:38:42 +00:00
|
|
|
case OP_CHANGE_BORDER_COLOR:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_border_color_op (program, op);
|
2017-12-05 07:38:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_CHANGE_CLIP:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_clip_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_SOURCE_TEXTURE:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_source_texture_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-11 07:22:28 +00:00
|
|
|
case OP_CHANGE_CROSS_FADE:
|
|
|
|
g_assert (program == &self->cross_fade_program);
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_cross_fade_op (program, op);
|
2017-12-11 07:22:28 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_CHANGE_LINEAR_GRADIENT:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_linear_gradient_op (program, op);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
case OP_CHANGE_BLUR:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_blur_op (program, op);
|
2017-11-25 07:56:50 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
case OP_CHANGE_INSET_SHADOW:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_inset_shadow_op (program, op);
|
2017-11-30 15:48:03 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
case OP_CHANGE_OUTSET_SHADOW:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_outset_shadow_op (program, op);
|
2017-12-01 07:30:11 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-01 10:55:10 +00:00
|
|
|
case OP_CHANGE_BORDER:
|
2017-12-16 09:02:03 +00:00
|
|
|
apply_border_op (program, op);
|
2017-12-01 10:55:10 +00:00
|
|
|
break;
|
|
|
|
|
2018-01-15 09:55:40 +00:00
|
|
|
case OP_CHANGE_UNBLURRED_OUTSET_SHADOW:
|
|
|
|
apply_unblurred_outset_shadow_op (program, op);
|
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_DRAW:
|
2017-12-01 11:29:27 +00:00
|
|
|
OP_PRINT (" -> draw %ld, size %ld and program %d\n",
|
|
|
|
op->draw.vao_offset, op->draw.vao_size, program->index);
|
2017-11-25 06:51:00 +00:00
|
|
|
glDrawArrays (GL_TRIANGLES, op->draw.vao_offset, op->draw.vao_size);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2018-12-02 07:12:09 +00:00
|
|
|
case OP_DUMP_FRAMEBUFFER:
|
|
|
|
dump_framebuffer (op->dump.filename, op->dump.width, op->dump.height);
|
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
}
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
OP_PRINT ("\n");
|
|
|
|
}
|
2016-12-04 15:33:13 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
/* Done drawing, destroy the buffer again.
|
|
|
|
* TODO: Can we reuse the memory, though? */
|
|
|
|
g_free (vertex_data);
|
2017-12-16 01:37:03 +00:00
|
|
|
glDeleteVertexArrays (1, &vao_id);
|
|
|
|
glDeleteBuffers (1, &buffer_id);
|
2016-12-04 15:33:13 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
static void
|
2016-12-22 19:01:52 +00:00
|
|
|
gsk_gl_renderer_do_render (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport,
|
2018-04-21 08:13:16 +00:00
|
|
|
int fbo_id,
|
2016-12-22 19:01:52 +00:00
|
|
|
int scale_factor)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
2017-11-22 10:32:23 +00:00
|
|
|
RenderOpBuilder render_op_builder;
|
2016-06-22 16:30:36 +00:00
|
|
|
graphene_matrix_t modelview, projection;
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler;
|
|
|
|
gint64 gpu_time, cpu_time;
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-08-24 15:21:50 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2016-08-03 15:51:21 +00:00
|
|
|
profiler = gsk_renderer_get_profiler (renderer);
|
2016-08-24 15:21:50 +00:00
|
|
|
#endif
|
2016-08-03 15:51:21 +00:00
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
if (self->gl_context == NULL)
|
|
|
|
{
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_RENDERER_NOTE (renderer, OPENGL, g_message ("No valid GL context associated to the renderer"));
|
2017-11-03 12:09:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-10 16:50:03 +00:00
|
|
|
/* Set up the modelview and projection matrices to fit our viewport */
|
|
|
|
graphene_matrix_init_scale (&modelview, scale_factor, scale_factor, 1.0);
|
|
|
|
graphene_matrix_init_ortho (&projection,
|
2016-12-22 19:01:52 +00:00
|
|
|
viewport->origin.x,
|
2017-11-03 12:09:02 +00:00
|
|
|
viewport->origin.x + viewport->size.width,
|
2016-12-22 19:01:52 +00:00
|
|
|
viewport->origin.y,
|
2017-11-03 12:09:02 +00:00
|
|
|
viewport->origin.y + viewport->size.height,
|
2016-08-10 16:50:03 +00:00
|
|
|
ORTHO_NEAR_PLANE,
|
|
|
|
ORTHO_FAR_PLANE);
|
2017-12-28 10:03:33 +00:00
|
|
|
graphene_matrix_scale (&projection, 1, -1, 1);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
|
|
|
gsk_gl_driver_begin_frame (self->gl_driver);
|
2017-11-18 13:30:57 +00:00
|
|
|
gsk_gl_glyph_cache_begin_frame (&self->glyph_cache);
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_gl_shadow_cache_begin_frame (&self->shadow_cache, self->gl_driver);
|
2016-08-03 15:51:21 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
memset (&render_op_builder, 0, sizeof (render_op_builder));
|
|
|
|
render_op_builder.renderer = self;
|
|
|
|
render_op_builder.current_projection = projection;
|
|
|
|
render_op_builder.current_viewport = *viewport;
|
|
|
|
render_op_builder.current_opacity = 1.0f;
|
2017-11-22 20:02:50 +00:00
|
|
|
render_op_builder.render_ops = self->render_ops;
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_push_modelview (&render_op_builder, &modelview);
|
2018-12-02 05:56:52 +00:00
|
|
|
/* Initial clip is self->render_region! */
|
|
|
|
if (self->render_region != NULL)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t render_extents;
|
|
|
|
|
|
|
|
cairo_region_get_extents (self->render_region, &render_extents);
|
|
|
|
render_op_builder.current_clip = GSK_ROUNDED_RECT_INIT (render_extents.x,
|
|
|
|
render_extents.y,
|
|
|
|
render_extents.width,
|
|
|
|
render_extents.height);
|
|
|
|
|
|
|
|
ops_transform_bounds_modelview (&render_op_builder,
|
|
|
|
&render_op_builder.current_clip.bounds,
|
|
|
|
&render_op_builder.current_clip.bounds);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gsk_rounded_rect_init_from_rect (&render_op_builder.current_clip, viewport, 0.0f);
|
|
|
|
}
|
|
|
|
|
2017-12-27 22:15:07 +00:00
|
|
|
|
2018-04-21 08:13:16 +00:00
|
|
|
if (fbo_id != 0)
|
|
|
|
ops_set_render_target (&render_op_builder, fbo_id);
|
2017-12-27 22:15:07 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, root, &render_op_builder);
|
|
|
|
|
2018-04-12 09:02:46 +00:00
|
|
|
/* We correctly reset the state everywhere */
|
2018-04-21 08:13:16 +00:00
|
|
|
g_assert_cmpint (render_op_builder.current_render_target, ==, fbo_id);
|
2018-11-26 16:52:35 +00:00
|
|
|
ops_pop_modelview (&render_op_builder);
|
|
|
|
ops_finish (&render_op_builder);
|
2018-04-12 09:02:46 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
/*g_message ("Ops: %u", self->render_ops->len);*/
|
|
|
|
|
|
|
|
/* Now actually draw things... */
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2016-07-20 16:55:35 +00:00
|
|
|
gsk_gl_profiler_begin_gpu_region (self->gl_profiler);
|
2016-08-03 15:51:21 +00:00
|
|
|
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-06-10 12:41:43 +00:00
|
|
|
glViewport (0, 0, ceilf (viewport->size.width), ceilf (viewport->size.height));
|
2016-12-04 15:33:13 +00:00
|
|
|
gsk_gl_renderer_setup_render_mode (self);
|
2016-06-22 16:30:36 +00:00
|
|
|
gsk_gl_renderer_clear (self);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-19 13:42:54 +00:00
|
|
|
glEnable (GL_DEPTH_TEST);
|
|
|
|
glDepthFunc (GL_LEQUAL);
|
2016-07-08 15:40:42 +00:00
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
/* Pre-multiplied alpha! */
|
2017-11-22 10:32:23 +00:00
|
|
|
glEnable (GL_BLEND);
|
2016-08-09 15:27:18 +00:00
|
|
|
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2017-11-03 12:09:02 +00:00
|
|
|
glBlendEquation (GL_FUNC_ADD);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
gsk_gl_renderer_render_ops (self, render_op_builder.buffer_size);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-07-12 13:50:48 +00:00
|
|
|
gsk_gl_driver_end_frame (self->gl_driver);
|
2016-08-03 15:51:21 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
gsk_profiler_counter_inc (profiler, self->profile_counters.frames);
|
|
|
|
|
|
|
|
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
|
|
|
|
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
|
|
|
|
|
2016-07-12 13:50:48 +00:00
|
|
|
gpu_time = gsk_gl_profiler_end_gpu_region (self->gl_profiler);
|
2016-08-03 15:51:21 +00:00
|
|
|
gsk_profiler_timer_set (profiler, self->profile_timers.gpu_time, gpu_time);
|
|
|
|
|
|
|
|
gsk_profiler_push_samples (profiler);
|
|
|
|
#endif
|
2016-12-22 19:01:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
static GdkTexture *
|
2016-12-22 19:01:52 +00:00
|
|
|
gsk_gl_renderer_render_texture (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2017-11-03 12:09:02 +00:00
|
|
|
int width, height;
|
2018-02-03 18:35:25 +00:00
|
|
|
guint texture_id;
|
|
|
|
guint fbo_id;
|
2016-12-22 19:01:52 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (self->gl_context != NULL, NULL);
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
width = ceilf (viewport->size.width);
|
|
|
|
height = ceilf (viewport->size.height);
|
2016-12-22 19:01:52 +00:00
|
|
|
|
2018-03-20 11:05:26 +00:00
|
|
|
self->scale_factor = gdk_surface_get_scale_factor (gsk_renderer_get_surface (renderer));
|
2016-12-22 19:01:52 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
/* Prepare our framebuffer */
|
2016-12-22 19:01:52 +00:00
|
|
|
gsk_gl_driver_begin_frame (self->gl_driver);
|
2018-02-03 18:35:25 +00:00
|
|
|
glGenTextures (1, &texture_id);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, texture_id);
|
2017-12-28 10:03:33 +00:00
|
|
|
|
2018-02-03 18:35:25 +00:00
|
|
|
if (gdk_gl_context_get_use_es (self->gl_context))
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
else
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
2016-12-22 19:01:52 +00:00
|
|
|
|
2018-02-03 18:35:25 +00:00
|
|
|
glGenFramebuffers (1, &fbo_id);
|
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, fbo_id);
|
|
|
|
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0);
|
2018-03-14 11:36:32 +00:00
|
|
|
g_assert_cmphex (glCheckFramebufferStatus (GL_FRAMEBUFFER), ==, GL_FRAMEBUFFER_COMPLETE);
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2018-02-03 18:35:25 +00:00
|
|
|
gsk_gl_renderer_clear (self);
|
2017-11-03 12:09:02 +00:00
|
|
|
gsk_gl_driver_end_frame (self->gl_driver);
|
|
|
|
|
2018-02-03 18:35:25 +00:00
|
|
|
/* Render the actual scene */
|
2018-04-12 09:02:46 +00:00
|
|
|
gsk_gl_renderer_do_render (renderer, root, viewport, fbo_id, 1);
|
2017-12-28 10:03:33 +00:00
|
|
|
|
2018-03-05 13:38:38 +00:00
|
|
|
texture = gdk_gl_texture_new (self->gl_context,
|
|
|
|
texture_id,
|
|
|
|
width, height,
|
|
|
|
NULL, NULL);
|
2016-12-22 19:01:52 +00:00
|
|
|
|
2018-02-03 12:24:55 +00:00
|
|
|
gsk_gl_renderer_clear_tree (self);
|
2016-12-22 19:01:52 +00:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-03-28 13:01:34 +00:00
|
|
|
gsk_gl_renderer_render (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const cairo_region_t *update_area)
|
2016-12-22 19:01:52 +00:00
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
|
|
|
|
graphene_rect_t viewport;
|
2018-04-20 22:58:53 +00:00
|
|
|
const cairo_region_t *damage;
|
2018-03-28 13:01:34 +00:00
|
|
|
GdkRectangle whole_surface;
|
|
|
|
GdkSurface *surface;
|
2016-12-22 19:01:52 +00:00
|
|
|
|
|
|
|
if (self->gl_context == NULL)
|
|
|
|
return;
|
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
surface = gsk_renderer_get_surface (renderer);
|
|
|
|
whole_surface = (GdkRectangle) {
|
|
|
|
0, 0,
|
|
|
|
gdk_surface_get_width (surface) * self->scale_factor,
|
|
|
|
gdk_surface_get_height (surface) * self->scale_factor
|
|
|
|
};
|
2018-04-20 14:07:34 +00:00
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
gdk_draw_context_begin_frame (GDK_DRAW_CONTEXT (self->gl_context),
|
2018-04-20 23:22:19 +00:00
|
|
|
update_area);
|
2018-04-20 14:07:34 +00:00
|
|
|
|
2018-04-20 22:58:53 +00:00
|
|
|
damage = gdk_draw_context_get_frame_region (GDK_DRAW_CONTEXT (self->gl_context));
|
2018-03-28 13:01:34 +00:00
|
|
|
|
|
|
|
if (cairo_region_contains_rectangle (damage, &whole_surface) == CAIRO_REGION_OVERLAP_IN)
|
|
|
|
{
|
|
|
|
self->render_region = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GdkRectangle extents;
|
|
|
|
|
|
|
|
cairo_region_get_extents (damage, &extents);
|
|
|
|
|
|
|
|
if (gdk_rectangle_equal (&extents, &whole_surface))
|
|
|
|
self->render_region = NULL;
|
|
|
|
else
|
2018-04-20 22:58:53 +00:00
|
|
|
self->render_region = cairo_region_create_rectangle (&extents);
|
2018-03-28 13:01:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 19:13:52 +00:00
|
|
|
self->scale_factor = gdk_surface_get_scale_factor (surface);
|
2016-12-22 19:01:52 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
viewport.origin.x = 0;
|
|
|
|
viewport.origin.y = 0;
|
2018-03-26 19:13:52 +00:00
|
|
|
viewport.size.width = gdk_surface_get_width (surface) * self->scale_factor;
|
|
|
|
viewport.size.height = gdk_surface_get_height (surface) * self->scale_factor;
|
2016-12-22 19:01:52 +00:00
|
|
|
|
2018-02-03 18:35:25 +00:00
|
|
|
gsk_gl_renderer_do_render (renderer, root, &viewport, 0, self->scale_factor);
|
2016-07-12 13:50:48 +00:00
|
|
|
|
2016-07-27 10:34:20 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2016-06-22 16:30:36 +00:00
|
|
|
gsk_gl_renderer_clear_tree (self);
|
2018-03-28 13:01:34 +00:00
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
gdk_draw_context_end_frame (GDK_DRAW_CONTEXT (self->gl_context));
|
2018-03-28 13:01:34 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&self->render_region, cairo_region_destroy);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_renderer_class_init (GskGLRendererClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GskRendererClass *renderer_class = GSK_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->dispose = gsk_gl_renderer_dispose;
|
|
|
|
|
|
|
|
renderer_class->realize = gsk_gl_renderer_realize;
|
|
|
|
renderer_class->unrealize = gsk_gl_renderer_unrealize;
|
|
|
|
renderer_class->render = gsk_gl_renderer_render;
|
2016-12-22 19:01:52 +00:00
|
|
|
renderer_class->render_texture = gsk_gl_renderer_render_texture;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_renderer_init (GskGLRenderer *self)
|
|
|
|
{
|
|
|
|
gsk_ensure_resources ();
|
|
|
|
|
2017-12-05 17:05:12 +00:00
|
|
|
self->render_ops = g_array_new (FALSE, FALSE, sizeof (RenderOp));
|
2017-03-29 16:45:51 +00:00
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
{
|
|
|
|
GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
|
|
|
|
|
|
|
|
self->profile_counters.frames = gsk_profiler_add_counter (profiler, "frames", "Frames", FALSE);
|
|
|
|
self->profile_counters.draw_calls = gsk_profiler_add_counter (profiler, "draws", "glDrawArrays", TRUE);
|
|
|
|
|
|
|
|
self->profile_timers.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU time", FALSE, TRUE);
|
|
|
|
self->profile_timers.gpu_time = gsk_profiler_add_timer (profiler, "gpu-time", "GPU time", FALSE, TRUE);
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|