2016-03-17 13:48:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
#include "gskglrendererprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
#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"
|
2019-10-11 14:23:33 +00:00
|
|
|
#include "gskrendernodeprivate.h"
|
2019-03-01 05:35:55 +00:00
|
|
|
#include "gsktransformprivate.h"
|
2019-12-14 21:06:12 +00:00
|
|
|
#include "gskglshaderbuilderprivate.h"
|
2017-11-18 13:30:57 +00:00
|
|
|
#include "gskglglyphcacheprivate.h"
|
2019-05-22 07:33:25 +00:00
|
|
|
#include "gskgliconcacheprivate.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"
|
2019-03-01 05:35:55 +00:00
|
|
|
#include "gsktransform.h"
|
2020-05-20 06:01:48 +00:00
|
|
|
#include "glutilsprivate.h"
|
2020-09-18 16:03:30 +00:00
|
|
|
#include "gskglshaderprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
#include "gskprivate.h"
|
|
|
|
|
2018-03-05 13:38:38 +00:00
|
|
|
#include "gdk/gdkgltextureprivate.h"
|
2019-04-24 11:27:43 +00:00
|
|
|
#include "gdk/gdkglcontextprivate.h"
|
2018-05-19 19:25:17 +00:00
|
|
|
#include "gdk/gdkprofilerprivate.h"
|
2019-10-11 13:06:51 +00:00
|
|
|
#include "gdk/gdkrgbaprivate.h"
|
2018-03-05 13:38:38 +00:00
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
#include <epoxy/gl.h>
|
|
|
|
|
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
|
|
|
|
|
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{\
|
2020-02-11 15:56:24 +00:00
|
|
|
programs->program_name ## _program.program_name.uniform_basename ## _location = \
|
|
|
|
glGetUniformLocation(programs->program_name ## _program.id, "u_" #uniform_basename);\
|
2020-04-17 16:35:37 +00:00
|
|
|
if (programs->program_name ## _program.program_name.uniform_basename ## _location == -1) \
|
|
|
|
{ \
|
2020-12-03 04:33:30 +00:00
|
|
|
g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_LINK_FAILED, \
|
|
|
|
"Failed to find variable \"u_%s\" in shader program \"%s\"", #uniform_basename, #program_name); \
|
2020-04-17 16:35:37 +00:00
|
|
|
g_clear_pointer (&programs, gsk_gl_renderer_programs_unref); \
|
|
|
|
goto out; \
|
|
|
|
} \
|
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
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static Program *gsk_gl_renderer_lookup_custom_program (GskGLRenderer *self,
|
|
|
|
GskGLShader *shader);
|
|
|
|
static Program *gsk_gl_renderer_create_custom_program (GskGLRenderer *self,
|
|
|
|
GskGLShader *shader);
|
|
|
|
|
2019-01-18 12:06:41 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2019-03-31 04:14:41 +00:00
|
|
|
FORCE_OFFSCREEN = 1 << 0,
|
|
|
|
RESET_CLIP = 1 << 1,
|
2019-11-29 05:54:43 +00:00
|
|
|
DUMP_FRAMEBUFFER = 1 << 3,
|
|
|
|
NO_CACHE_PLZ = 1 << 5,
|
2020-09-02 22:01:06 +00:00
|
|
|
LINEAR_FILTER = 1 << 6,
|
2019-01-18 12:06:41 +00:00
|
|
|
} OffscreenFlags;
|
|
|
|
|
2019-06-04 17:28:59 +00:00
|
|
|
static inline void
|
|
|
|
init_full_texture_region (TextureRegion *r,
|
|
|
|
int texture_id)
|
|
|
|
{
|
|
|
|
r->texture_id = texture_id;
|
|
|
|
r->x = 0;
|
|
|
|
r->y = 0;
|
|
|
|
r->x2 = 1;
|
|
|
|
r->y2 = 1;
|
|
|
|
}
|
|
|
|
|
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_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;
|
|
|
|
|
2019-12-20 11:30:39 +00:00
|
|
|
case GSK_COLOR_NODE:
|
2020-11-16 23:59:36 +00:00
|
|
|
g_print ("%*s Color %s\n", level * INDENT, " ", gdk_rgba_to_string (gsk_color_node_get_color (root)));
|
2019-12-20 11:30:39 +00:00
|
|
|
break;
|
|
|
|
|
2018-05-12 04:57:59 +00:00
|
|
|
case GSK_SHADOW_NODE:
|
|
|
|
g_print ("%*s Shadow\n", level * INDENT, " ");
|
|
|
|
print_render_node_tree (gsk_shadow_node_get_child (root), level + 1);
|
|
|
|
break;
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
case GSK_GL_SHADER_NODE:
|
|
|
|
g_print ("%*s GL Shader\n", level * INDENT, " ");
|
|
|
|
for (i = 0; i < gsk_gl_shader_node_get_n_children (root); i++)
|
|
|
|
print_render_node_tree (gsk_gl_shader_node_get_child (root, i), level + 1);
|
|
|
|
break;
|
|
|
|
|
2018-05-12 04:57:59 +00:00
|
|
|
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:
|
2020-04-07 22:33:54 +00:00
|
|
|
g_print ("%*s %s\n", level * INDENT, " ", g_type_name_from_instance ((GTypeInstance *) root));
|
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);
|
|
|
|
}
|
|
|
|
|
2019-02-24 08:09:02 +00:00
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
dump_node (GskRenderNode *node,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
const int surface_width = ceilf (node->bounds.size.width);
|
|
|
|
const int surface_height = ceilf (node->bounds.size.height);
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
surface_width,
|
|
|
|
surface_height);
|
|
|
|
|
|
|
|
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);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
cairo_surface_write_to_png (surface, filename);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
2020-07-31 17:13:46 +00:00
|
|
|
static inline bool G_GNUC_PURE
|
2019-11-23 09:20:15 +00:00
|
|
|
node_is_invisible (const GskRenderNode *node)
|
|
|
|
{
|
|
|
|
return node->bounds.size.width == 0.0f ||
|
|
|
|
node->bounds.size.height == 0.0f ||
|
|
|
|
isnan (node->bounds.size.width) ||
|
|
|
|
isnan (node->bounds.size.height);
|
|
|
|
}
|
|
|
|
|
2020-07-31 17:13:46 +00:00
|
|
|
static inline bool G_GNUC_PURE
|
2020-07-24 15:01:32 +00:00
|
|
|
graphene_rect_intersects (const graphene_rect_t *r1,
|
|
|
|
const graphene_rect_t *r2)
|
|
|
|
{
|
|
|
|
/* Assume both rects are already normalized, as they usually are */
|
|
|
|
if (r1->origin.x > (r2->origin.x + r2->size.width) ||
|
|
|
|
(r1->origin.x + r1->size.width) < r2->origin.x)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (r1->origin.y > (r2->origin.y + r2->size.height) ||
|
|
|
|
(r1->origin.y + r1->size.height) < r2->origin.y)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-31 17:13:46 +00:00
|
|
|
static inline bool G_GNUC_PURE
|
2020-07-24 15:18:18 +00:00
|
|
|
_graphene_rect_contains_rect (const graphene_rect_t *r1,
|
|
|
|
const graphene_rect_t *r2)
|
|
|
|
{
|
|
|
|
if (r2->origin.x >= r1->origin.x &&
|
|
|
|
(r2->origin.x + r2->size.width) <= (r1->origin.x + r1->size.width) &&
|
|
|
|
r2->origin.y >= r1->origin.y &&
|
|
|
|
(r2->origin.y + r2->size.height) <= (r1->origin.y + r1->size.height))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-05 12:13:15 +00:00
|
|
|
static inline bool G_GNUC_PURE
|
|
|
|
equal_texture_nodes (GskRenderNode *node1,
|
|
|
|
GskRenderNode *node2)
|
|
|
|
{
|
|
|
|
if (gsk_render_node_get_node_type (node1) != GSK_TEXTURE_NODE ||
|
|
|
|
gsk_render_node_get_node_type (node2) != GSK_TEXTURE_NODE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (gsk_texture_node_get_texture (node1) !=
|
|
|
|
gsk_texture_node_get_texture (node2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return graphene_rect_equal (&node1->bounds, &node2->bounds);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 06:39:19 +00:00
|
|
|
static inline void
|
|
|
|
init_projection_matrix (graphene_matrix_t *out_proj,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
|
|
|
graphene_matrix_init_ortho (out_proj,
|
|
|
|
viewport->origin.x,
|
|
|
|
viewport->origin.x + viewport->size.width,
|
|
|
|
viewport->origin.y,
|
|
|
|
viewport->origin.y + viewport->size.height,
|
|
|
|
ORTHO_NEAR_PLANE,
|
|
|
|
ORTHO_FAR_PLANE);
|
|
|
|
graphene_matrix_scale (out_proj, 1, -1, 1);
|
|
|
|
}
|
|
|
|
|
2020-01-24 12:17:09 +00:00
|
|
|
static inline gboolean G_GNUC_PURE
|
2017-12-06 15:07:18 +00:00
|
|
|
color_matrix_modifies_alpha (GskRenderNode *node)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const graphene_matrix_t *matrix = gsk_color_matrix_node_get_color_matrix (node);
|
|
|
|
const graphene_vec4_t *offset = gsk_color_matrix_node_get_color_offset (node);
|
2017-12-06 15:07:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-11-03 08:18:37 +00:00
|
|
|
self->bounds.size.width = MAX (self->corner[0].width + self->corner[1].width,
|
|
|
|
self->corner[3].width + self->corner[2].width);
|
|
|
|
self->bounds.size.height = MAX (self->corner[0].height + self->corner[3].height,
|
|
|
|
self->corner[1].height + self->corner[2].height);
|
2017-12-21 17:09:32 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 12:17:09 +00:00
|
|
|
static inline gboolean G_GNUC_PURE
|
2018-11-29 07:09:02 +00:00
|
|
|
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:
|
2019-02-23 06:50:51 +00:00
|
|
|
case GSK_CROSS_FADE_NODE:
|
2019-02-26 06:17:08 +00:00
|
|
|
case GSK_LINEAR_GRADIENT_NODE:
|
|
|
|
case GSK_DEBUG_NODE:
|
|
|
|
case GSK_TEXT_NODE:
|
2018-11-29 07:09:02 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2020-05-22 17:50:29 +00:00
|
|
|
case GSK_TRANSFORM_NODE:
|
|
|
|
return node_supports_transform (gsk_transform_node_get_child (node));
|
|
|
|
|
2018-11-29 07:09:02 +00:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-29 15:54:56 +00:00
|
|
|
static inline void
|
2020-10-31 10:54:33 +00:00
|
|
|
load_vertex_data_with_region (GskQuadVertex vertex_data[GL_N_VERTICES],
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const TextureRegion *r,
|
|
|
|
gboolean flip_y)
|
2019-12-29 15:54:56 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float min_x = builder->dx + bounds->origin.x;
|
|
|
|
const float min_y = builder->dy + bounds->origin.y;
|
|
|
|
const float max_x = min_x + bounds->size.width;
|
|
|
|
const float max_y = min_y + bounds->size.height;
|
2019-12-29 15:54:56 +00:00
|
|
|
const float y1 = flip_y ? r->y2 : r->y;
|
|
|
|
const float y2 = flip_y ? r->y : r->y2;
|
|
|
|
|
|
|
|
vertex_data[0].position[0] = min_x;
|
|
|
|
vertex_data[0].position[1] = min_y;
|
|
|
|
vertex_data[0].uv[0] = r->x;
|
|
|
|
vertex_data[0].uv[1] = y1;
|
|
|
|
|
|
|
|
vertex_data[1].position[0] = min_x;
|
|
|
|
vertex_data[1].position[1] = max_y;
|
|
|
|
vertex_data[1].uv[0] = r->x;
|
|
|
|
vertex_data[1].uv[1] = y2;
|
|
|
|
|
|
|
|
vertex_data[2].position[0] = max_x;
|
|
|
|
vertex_data[2].position[1] = min_y;
|
|
|
|
vertex_data[2].uv[0] = r->x2;
|
|
|
|
vertex_data[2].uv[1] = y1;
|
|
|
|
|
|
|
|
vertex_data[3].position[0] = max_x;
|
|
|
|
vertex_data[3].position[1] = max_y;
|
|
|
|
vertex_data[3].uv[0] = r->x2;
|
|
|
|
vertex_data[3].uv[1] = y2;
|
|
|
|
|
|
|
|
vertex_data[4].position[0] = min_x;
|
|
|
|
vertex_data[4].position[1] = max_y;
|
|
|
|
vertex_data[4].uv[0] = r->x;
|
|
|
|
vertex_data[4].uv[1] = y2;
|
|
|
|
|
|
|
|
vertex_data[5].position[0] = max_x;
|
|
|
|
vertex_data[5].position[1] = min_y;
|
|
|
|
vertex_data[5].uv[0] = r->x2;
|
|
|
|
vertex_data[5].uv[1] = y1;
|
|
|
|
}
|
|
|
|
|
2020-11-01 11:22:06 +00:00
|
|
|
static inline void
|
|
|
|
load_float_vertex_data (GskQuadVertex vertex_data[GL_N_VERTICES],
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height)
|
2019-11-26 07:58:38 +00:00
|
|
|
{
|
2020-11-01 11:22:06 +00:00
|
|
|
const float min_x = builder->dx + x;
|
|
|
|
const float min_y = builder->dy + y;
|
|
|
|
const float max_x = min_x + width;
|
|
|
|
const float max_y = min_y + height;
|
2019-11-26 07:58:38 +00:00
|
|
|
|
|
|
|
vertex_data[0].position[0] = min_x;
|
|
|
|
vertex_data[0].position[1] = min_y;
|
|
|
|
vertex_data[0].uv[0] = 0;
|
|
|
|
vertex_data[0].uv[1] = 0;
|
|
|
|
|
|
|
|
vertex_data[1].position[0] = min_x;
|
|
|
|
vertex_data[1].position[1] = max_y;
|
|
|
|
vertex_data[1].uv[0] = 0;
|
|
|
|
vertex_data[1].uv[1] = 1;
|
|
|
|
|
|
|
|
vertex_data[2].position[0] = max_x;
|
|
|
|
vertex_data[2].position[1] = min_y;
|
|
|
|
vertex_data[2].uv[0] = 1;
|
|
|
|
vertex_data[2].uv[1] = 0;
|
|
|
|
|
|
|
|
vertex_data[3].position[0] = max_x;
|
|
|
|
vertex_data[3].position[1] = max_y;
|
|
|
|
vertex_data[3].uv[0] = 1;
|
|
|
|
vertex_data[3].uv[1] = 1;
|
|
|
|
|
|
|
|
vertex_data[4].position[0] = min_x;
|
|
|
|
vertex_data[4].position[1] = max_y;
|
|
|
|
vertex_data[4].uv[0] = 0;
|
|
|
|
vertex_data[4].uv[1] = 1;
|
|
|
|
|
|
|
|
vertex_data[5].position[0] = max_x;
|
|
|
|
vertex_data[5].position[1] = min_y;
|
|
|
|
vertex_data[5].uv[0] = 1;
|
|
|
|
vertex_data[5].uv[1] = 0;
|
|
|
|
}
|
|
|
|
|
2020-11-01 11:22:06 +00:00
|
|
|
static void
|
|
|
|
load_vertex_data (GskQuadVertex vertex_data[GL_N_VERTICES],
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
load_float_vertex_data (vertex_data, builder,
|
|
|
|
bounds->origin.x, bounds->origin.y,
|
|
|
|
bounds->size.width, bounds->size.height);
|
|
|
|
}
|
|
|
|
|
2019-11-26 07:58:38 +00:00
|
|
|
static void
|
2020-12-19 16:43:43 +00:00
|
|
|
fill_vertex_data (GskQuadVertex vertex_data[GL_N_VERTICES],
|
|
|
|
const float min_x,
|
|
|
|
const float min_y,
|
|
|
|
const float max_x,
|
|
|
|
const float max_y)
|
2019-11-26 07:58:38 +00:00
|
|
|
{
|
|
|
|
vertex_data[0].position[0] = min_x;
|
|
|
|
vertex_data[0].position[1] = min_y;
|
|
|
|
vertex_data[0].uv[0] = 0;
|
|
|
|
vertex_data[0].uv[1] = 1;
|
|
|
|
|
|
|
|
vertex_data[1].position[0] = min_x;
|
|
|
|
vertex_data[1].position[1] = max_y;
|
|
|
|
vertex_data[1].uv[0] = 0;
|
|
|
|
vertex_data[1].uv[1] = 0;
|
|
|
|
|
|
|
|
vertex_data[2].position[0] = max_x;
|
|
|
|
vertex_data[2].position[1] = min_y;
|
|
|
|
vertex_data[2].uv[0] = 1;
|
|
|
|
vertex_data[2].uv[1] = 1;
|
|
|
|
|
|
|
|
vertex_data[3].position[0] = max_x;
|
|
|
|
vertex_data[3].position[1] = max_y;
|
|
|
|
vertex_data[3].uv[0] = 1;
|
|
|
|
vertex_data[3].uv[1] = 0;
|
|
|
|
|
|
|
|
vertex_data[4].position[0] = min_x;
|
|
|
|
vertex_data[4].position[1] = max_y;
|
|
|
|
vertex_data[4].uv[0] = 0;
|
|
|
|
vertex_data[4].uv[1] = 0;
|
|
|
|
|
|
|
|
vertex_data[5].position[0] = max_x;
|
|
|
|
vertex_data[5].position[1] = min_y;
|
|
|
|
vertex_data[5].uv[0] = 1;
|
|
|
|
vertex_data[5].uv[1] = 1;
|
|
|
|
}
|
2018-11-29 07:09:02 +00:00
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
static void
|
|
|
|
load_offscreen_vertex_data (GskQuadVertex vertex_data[GL_N_VERTICES],
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
fill_vertex_data (vertex_data,
|
|
|
|
min_x, min_y,
|
|
|
|
max_x, max_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-24 09:18:51 +00:00
|
|
|
static void gsk_gl_renderer_setup_render_mode (GskGLRenderer *self);
|
2020-12-19 16:43:56 +00:00
|
|
|
static gboolean add_offscreen_ops (GskGLRenderer *self,
|
2018-12-02 08:05:50 +00:00
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GskRenderNode *child_node,
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion *region_out,
|
|
|
|
gboolean *is_offscreen,
|
|
|
|
guint flags) G_GNUC_WARN_UNUSED_RESULT;
|
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
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
GskGLRendererPrograms *programs;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2019-04-24 15:55:14 +00:00
|
|
|
RenderOpBuilder op_builder;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
GskGLTextureAtlases *atlases;
|
|
|
|
GskGLGlyphCache *glyph_cache;
|
|
|
|
GskGLIconCache *icon_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;
|
|
|
|
} 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)
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static void
|
|
|
|
init_shader_builder (GskGLRenderer *self,
|
|
|
|
GskGLShaderBuilder *shader_builder)
|
|
|
|
{
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), SHADERS))
|
|
|
|
shader_builder->debugging = TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (gdk_gl_context_get_use_es (self->gl_context))
|
|
|
|
{
|
|
|
|
gsk_gl_shader_builder_set_glsl_version (shader_builder, SHADER_VERSION_GLES);
|
|
|
|
shader_builder->gles = TRUE;
|
|
|
|
}
|
|
|
|
else if (gdk_gl_context_is_legacy (self->gl_context))
|
|
|
|
{
|
|
|
|
int maj, min;
|
|
|
|
|
|
|
|
gdk_gl_context_get_version (self->gl_context, &maj, &min);
|
|
|
|
|
|
|
|
if (maj == 3)
|
|
|
|
gsk_gl_shader_builder_set_glsl_version (shader_builder, SHADER_VERSION_GL3_LEGACY);
|
|
|
|
else
|
|
|
|
gsk_gl_shader_builder_set_glsl_version (shader_builder, SHADER_VERSION_GL2_LEGACY);
|
|
|
|
|
|
|
|
shader_builder->legacy = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gsk_gl_shader_builder_set_glsl_version (shader_builder, SHADER_VERSION_GL3);
|
|
|
|
shader_builder->gl3 = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 13:49:30 +00:00
|
|
|
static GdkRGBA BLACK = {0, 0, 0, 1};
|
2018-12-02 13:31:57 +00:00
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
add_rect_outline_ops (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *rect)
|
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->color_program);
|
2019-12-10 13:49:30 +00:00
|
|
|
ops_set_color (builder, &BLACK);
|
2018-12-02 13:31:57 +00:00
|
|
|
|
2020-11-01 11:27:59 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x, rect->origin.y, 1, rect->size.height),
|
|
|
|
builder);
|
|
|
|
load_vertex_data (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x, rect->origin.y, rect->size.width, 1),
|
|
|
|
builder);
|
|
|
|
load_vertex_data (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x + rect->size.width - 1,rect->origin.y,
|
|
|
|
1, rect->size.height),
|
|
|
|
builder);
|
|
|
|
load_vertex_data (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (rect->origin.x, rect->origin.y + rect->size.height - 1,
|
|
|
|
rect->size.width, 1),
|
|
|
|
builder);
|
2018-12-02 13:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 12:53:59 +00:00
|
|
|
static inline GskRoundedRect
|
|
|
|
transform_rect (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const GskRoundedRect *rect)
|
2017-12-09 08:41:52 +00:00
|
|
|
{
|
2019-12-14 12:53:59 +00:00
|
|
|
GskRoundedRect r;
|
2017-12-09 08:41:52 +00:00
|
|
|
|
2020-01-19 16:11:57 +00:00
|
|
|
r.bounds.origin.x = builder->dx + rect->bounds.origin.x;
|
|
|
|
r.bounds.origin.y = builder->dy + rect->bounds.origin.y;
|
|
|
|
r.bounds.size = rect->bounds.size;
|
2017-12-09 08:41:52 +00:00
|
|
|
|
2020-01-19 16:11:57 +00:00
|
|
|
r.corner[0] = rect->corner[0];
|
|
|
|
r.corner[1] = rect->corner[1];
|
|
|
|
r.corner[2] = rect->corner[2];
|
|
|
|
r.corner[3] = rect->corner[3];
|
2019-12-14 12:53:59 +00:00
|
|
|
|
|
|
|
return r;
|
2017-12-09 08:41:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 08:58:58 +00:00
|
|
|
static inline void
|
2019-12-18 08:06:16 +00:00
|
|
|
render_fallback_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-01 08:58:58 +00:00
|
|
|
{
|
2020-12-04 20:12:34 +00:00
|
|
|
const float scale_x = builder->scale_x;
|
|
|
|
const float scale_y = builder->scale_y;
|
|
|
|
const int surface_width = ceilf (node->bounds.size.width * scale_x);
|
|
|
|
const int surface_height = ceilf (node->bounds.size.height * scale_y);
|
2020-09-24 14:58:46 +00:00
|
|
|
GdkTexture *texture;
|
2017-12-01 08:58:58 +00:00
|
|
|
cairo_surface_t *surface;
|
2019-05-21 06:38:11 +00:00
|
|
|
cairo_surface_t *rendered_surface;
|
2017-12-01 08:58:58 +00:00
|
|
|
cairo_t *cr;
|
2019-03-05 08:03:11 +00:00
|
|
|
int cached_id;
|
2017-12-01 08:58:58 +00:00
|
|
|
int texture_id;
|
2020-09-09 17:55:09 +00:00
|
|
|
GskTextureKey key;
|
2017-12-01 08:58:58 +00:00
|
|
|
|
2018-06-26 19:40:59 +00:00
|
|
|
if (surface_width <= 0 ||
|
|
|
|
surface_height <= 0)
|
|
|
|
return;
|
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
key.pointer = node;
|
2020-09-30 12:53:13 +00:00
|
|
|
key.pointer_is_child = FALSE;
|
2020-12-04 20:12:34 +00:00
|
|
|
key.scale_x = scale_x;
|
|
|
|
key.scale_y = scale_y;
|
2020-09-09 17:55:09 +00:00
|
|
|
key.filter = GL_NEAREST;
|
|
|
|
|
|
|
|
cached_id = gsk_gl_driver_get_texture_for_key (self->gl_driver, &key);
|
2019-03-05 08:03:11 +00:00
|
|
|
|
|
|
|
if (cached_id != 0)
|
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2019-03-05 08:03:11 +00:00
|
|
|
ops_set_texture (builder, cached_id);
|
2020-12-19 16:43:43 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), node, builder);
|
2019-03-05 08:03:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-21 06:38:11 +00:00
|
|
|
|
|
|
|
/* We first draw the recording surface on an image surface,
|
|
|
|
* just because the scaleY(-1) later otherwise screws up the
|
|
|
|
* rendering... */
|
|
|
|
{
|
|
|
|
rendered_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
surface_width,
|
|
|
|
surface_height);
|
|
|
|
|
2020-12-04 20:12:34 +00:00
|
|
|
cairo_surface_set_device_scale (rendered_surface, scale_x, scale_y);
|
2019-05-21 06:38:11 +00:00
|
|
|
cr = cairo_create (rendered_surface);
|
|
|
|
|
|
|
|
cairo_save (cr);
|
2020-07-22 04:35:48 +00:00
|
|
|
cairo_translate (cr, - floorf (node->bounds.origin.x), - floorf (node->bounds.origin.y));
|
2019-05-21 06:38:11 +00:00
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
cairo_restore (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
}
|
|
|
|
|
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);
|
2020-12-04 20:12:34 +00:00
|
|
|
cairo_surface_set_device_scale (surface, scale_x, scale_y);
|
2017-12-01 08:58:58 +00:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
2019-05-18 11:45:19 +00:00
|
|
|
/* We draw upside down here, so it matches what GL does. */
|
2017-12-01 08:58:58 +00:00
|
|
|
cairo_save (cr);
|
2019-05-18 11:45:19 +00:00
|
|
|
cairo_scale (cr, 1, -1);
|
2020-12-04 20:12:34 +00:00
|
|
|
cairo_translate (cr, 0, - surface_height / scale_y);
|
2019-05-21 06:38:11 +00:00
|
|
|
cairo_set_source_surface (cr, rendered_surface, 0, 0);
|
2020-12-04 20:12:34 +00:00
|
|
|
cairo_rectangle (cr, 0, 0, surface_width / scale_x, surface_height / scale_y);
|
2019-05-21 06:38:11 +00:00
|
|
|
cairo_fill (cr);
|
2017-12-01 08:58:58 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
2020-01-24 12:17:09 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2019-10-31 02:30:34 +00:00
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), FALLBACK))
|
2018-03-30 21:32:19 +00:00
|
|
|
{
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
cairo_rectangle (cr, 0, 0, node->bounds.size.width, node->bounds.size.height);
|
2019-10-31 02:30:34 +00:00
|
|
|
if (gsk_render_node_get_node_type (node) == GSK_CAIRO_NODE)
|
|
|
|
cairo_set_source_rgba (cr, 0.3, 0, 1, 0.25);
|
|
|
|
else
|
|
|
|
cairo_set_source_rgba (cr, 1, 0, 0, 0.25);
|
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
if (gsk_render_node_get_node_type (node) == GSK_CAIRO_NODE)
|
|
|
|
cairo_set_source_rgba (cr, 0.3, 0, 1, 1);
|
|
|
|
else
|
|
|
|
cairo_set_source_rgba (cr, 1, 0, 0, 1);
|
2018-03-30 21:32:19 +00:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2017-12-01 08:58:58 +00:00
|
|
|
#endif
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
2020-09-24 14:58:46 +00:00
|
|
|
|
2017-12-01 08:58:58 +00:00
|
|
|
/* 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);
|
2020-09-24 14:58:46 +00:00
|
|
|
|
|
|
|
texture = gdk_texture_new_for_surface (surface);
|
|
|
|
gsk_gl_driver_init_texture (self->gl_driver,
|
|
|
|
texture_id,
|
|
|
|
texture,
|
|
|
|
GL_NEAREST, GL_NEAREST);
|
2020-07-24 16:54:23 +00:00
|
|
|
|
|
|
|
if (gdk_gl_context_has_debug (self->gl_context))
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, texture_id,
|
|
|
|
"Fallback %s %d",
|
|
|
|
g_type_name_from_instance ((GTypeInstance *) node),
|
|
|
|
texture_id);
|
2019-04-27 07:50:21 +00:00
|
|
|
|
2020-09-24 14:58:46 +00:00
|
|
|
g_object_unref (texture);
|
2017-12-01 08:58:58 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2019-05-21 06:38:11 +00:00
|
|
|
cairo_surface_destroy (rendered_surface);
|
2017-12-01 08:58:58 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
gsk_gl_driver_set_texture_for_key (self->gl_driver, &key, texture_id);
|
2019-03-05 08:03:11 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2017-12-01 08:58:58 +00:00
|
|
|
ops_set_texture (builder, texture_id);
|
2020-12-19 16:43:43 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), node, builder);
|
2017-12-01 08:58:58 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const PangoFont *font = gsk_text_node_get_font (node);
|
|
|
|
const PangoGlyphInfo *glyphs = gsk_text_node_get_glyphs (node, NULL);
|
2020-12-04 20:12:34 +00:00
|
|
|
const float text_scale = MAX (builder->scale_x, builder->scale_y); /* TODO: Fix for uneven scales? */
|
2019-12-16 06:13:37 +00:00
|
|
|
const graphene_point_t *offset = gsk_text_node_get_offset (node);
|
|
|
|
const guint num_glyphs = gsk_text_node_get_num_glyphs (node);
|
2019-12-30 11:59:01 +00:00
|
|
|
const float x = offset->x + builder->dx;
|
|
|
|
const float y = offset->y + builder->dy;
|
2017-12-01 09:47:13 +00:00
|
|
|
int i;
|
|
|
|
int x_position = 0;
|
2019-10-10 01:49:43 +00:00
|
|
|
GlyphCacheKey lookup;
|
2017-12-01 09:47:13 +00:00
|
|
|
|
|
|
|
/* If the font has color glyphs, we don't need to recolor anything */
|
2019-10-10 11:31:08 +00:00
|
|
|
if (!force_color && gsk_text_node_has_color_glyphs (node))
|
2017-12-01 09:47:13 +00:00
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2017-12-01 09:47:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->coloring_program);
|
2017-12-01 09:47:13 +00:00
|
|
|
ops_set_color (builder, color);
|
|
|
|
}
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
memset (&lookup, 0, sizeof (CacheKeyData));
|
|
|
|
lookup.data.font = (PangoFont *)font;
|
|
|
|
lookup.data.scale = (guint) (text_scale * 1024);
|
2019-10-10 01:49:43 +00:00
|
|
|
|
2020-10-31 16:13:31 +00:00
|
|
|
/* We use one quad per character */
|
2017-12-01 09:47:13 +00:00
|
|
|
for (i = 0; i < num_glyphs; i++)
|
|
|
|
{
|
|
|
|
const PangoGlyphInfo *gi = &glyphs[i];
|
2019-10-09 21:27:48 +00:00
|
|
|
const GskGLCachedGlyph *glyph;
|
2019-10-10 03:17:15 +00:00
|
|
|
float glyph_x, glyph_y, glyph_x2, glyph_y2;
|
2017-12-01 09:47:13 +00:00
|
|
|
float tx, ty, tx2, ty2;
|
2019-10-10 19:13:14 +00:00
|
|
|
float cx;
|
|
|
|
float cy;
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2018-01-06 12:02:31 +00:00
|
|
|
if (gi->glyph == PANGO_GLYPH_EMPTY)
|
2017-12-01 09:47:13 +00:00
|
|
|
continue;
|
|
|
|
|
2019-10-10 19:13:14 +00:00
|
|
|
cx = (float)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
|
|
|
|
cy = (float)(gi->geometry.y_offset) / PANGO_SCALE;
|
2019-07-31 02:21:52 +00:00
|
|
|
|
2019-10-22 05:34:56 +00:00
|
|
|
glyph_cache_key_set_glyph_and_shift (&lookup, gi->glyph, x + cx, y + cy);
|
2019-10-10 01:49:43 +00:00
|
|
|
|
2019-10-22 05:34:56 +00:00
|
|
|
gsk_gl_glyph_cache_lookup_or_add (self->glyph_cache,
|
|
|
|
&lookup,
|
|
|
|
self->gl_driver,
|
|
|
|
&glyph);
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2019-10-09 21:27:48 +00:00
|
|
|
if (glyph->texture_id == 0)
|
2019-07-28 09:57:43 +00:00
|
|
|
goto next;
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-10-09 21:27:48 +00:00
|
|
|
ops_set_texture (builder, glyph->texture_id);
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2019-10-09 21:27:48 +00:00
|
|
|
tx = glyph->tx;
|
|
|
|
ty = glyph->ty;
|
|
|
|
tx2 = tx + glyph->tw;
|
|
|
|
ty2 = ty + glyph->th;
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2019-10-09 21:27:48 +00:00
|
|
|
glyph_x = floor (x + cx + 0.125) + glyph->draw_x;
|
|
|
|
glyph_y = floor (y + cy + 0.125) + glyph->draw_y;
|
2019-10-10 03:17:15 +00:00
|
|
|
glyph_x2 = glyph_x + glyph->draw_width;
|
|
|
|
glyph_y2 = glyph_y + 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]) {
|
2019-10-10 03:17:15 +00:00
|
|
|
{ { glyph_x, glyph_y }, { tx, ty }, },
|
|
|
|
{ { glyph_x, glyph_y2 }, { tx, ty2 }, },
|
|
|
|
{ { glyph_x2, glyph_y }, { tx2, ty }, },
|
2017-12-01 09:47:13 +00:00
|
|
|
|
2019-10-10 03:17:15 +00:00
|
|
|
{ { glyph_x2, glyph_y2 }, { tx2, ty2 }, },
|
|
|
|
{ { glyph_x, glyph_y2 }, { tx, ty2 }, },
|
|
|
|
{ { glyph_x2, glyph_y }, { tx2, ty }, },
|
2017-12-30 09:01:12 +00:00
|
|
|
});
|
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)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const GdkRGBA *colors = gsk_border_node_get_colors (node);
|
|
|
|
const GskRoundedRect *rounded_outline = gsk_border_node_get_outline (node);
|
|
|
|
const float *widths = gsk_border_node_get_widths (node);
|
2017-12-09 07:57:13 +00:00
|
|
|
int i;
|
2017-12-01 10:55:10 +00:00
|
|
|
struct {
|
|
|
|
float w;
|
|
|
|
float h;
|
|
|
|
} sizes[4];
|
|
|
|
|
2020-07-24 13:59:45 +00:00
|
|
|
if (gsk_border_node_get_uniform (node))
|
2020-01-14 14:43:53 +00:00
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->inset_shadow_program);
|
2020-07-24 06:49:24 +00:00
|
|
|
ops_set_inset_shadow (builder, transform_rect (self, builder, rounded_outline),
|
|
|
|
widths[0], &colors[0], 0, 0);
|
2020-01-14 14:43:53 +00:00
|
|
|
|
2020-11-01 11:22:06 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
2020-01-14 14:43:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-09 07:57:13 +00:00
|
|
|
|
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-08 16:01:16 +00:00
|
|
|
{
|
2020-01-24 10:29:43 +00:00
|
|
|
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 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 };
|
2020-01-17 15:37:29 +00:00
|
|
|
GskRoundedRect outline;
|
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 */
|
2019-12-20 11:21:04 +00:00
|
|
|
outline = transform_rect (self, builder, rounded_outline);
|
2018-03-15 16:27:19 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->border_program);
|
2018-12-05 09:44:11 +00:00
|
|
|
ops_set_border_width (builder, widths);
|
|
|
|
ops_set_border (builder, &outline);
|
2018-03-15 16:27:19 +00:00
|
|
|
|
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
|
2019-11-26 07:58:38 +00:00
|
|
|
render_color_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->color_program);
|
2020-11-16 23:59:36 +00:00
|
|
|
ops_set_color (builder, gsk_color_node_get_color (node));
|
2020-11-01 11:22:06 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:28:59 +00:00
|
|
|
static inline void
|
|
|
|
upload_texture (GskGLRenderer *self,
|
|
|
|
GdkTexture *texture,
|
|
|
|
TextureRegion *out_region)
|
|
|
|
{
|
|
|
|
if (texture->width <= 128 &&
|
2019-06-29 05:13:10 +00:00
|
|
|
texture->height <= 128 &&
|
|
|
|
!GDK_IS_GL_TEXTURE (texture))
|
2019-06-04 17:28:59 +00:00
|
|
|
{
|
2019-10-15 11:51:05 +00:00
|
|
|
const IconData *icon_data;
|
2019-06-04 17:28:59 +00:00
|
|
|
|
|
|
|
gsk_gl_icon_cache_lookup_or_add (self->icon_cache,
|
|
|
|
texture,
|
2019-10-15 11:51:05 +00:00
|
|
|
&icon_data);
|
|
|
|
|
|
|
|
out_region->texture_id = icon_data->texture_id;
|
|
|
|
out_region->x = icon_data->x;
|
|
|
|
out_region->y = icon_data->y;
|
|
|
|
out_region->x2 = icon_data->x2;
|
|
|
|
out_region->y2 = icon_data->y2;
|
2019-06-04 17:28:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-08 03:45:34 +00:00
|
|
|
|
2019-10-15 11:51:05 +00:00
|
|
|
out_region->texture_id =
|
|
|
|
gsk_gl_driver_get_texture_for_texture (self->gl_driver,
|
|
|
|
texture,
|
|
|
|
GL_LINEAR,
|
|
|
|
GL_LINEAR);
|
|
|
|
|
2019-06-04 17:28:59 +00:00
|
|
|
out_region->x = 0;
|
|
|
|
out_region->y = 0;
|
|
|
|
out_region->x2 = 1;
|
|
|
|
out_region->y2 = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
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);
|
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
|
|
|
{
|
2019-12-29 15:54:56 +00:00
|
|
|
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;
|
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
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2018-03-20 08:17:26 +00:00
|
|
|
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
|
|
|
|
{
|
2019-06-04 17:28:59 +00:00
|
|
|
TextureRegion r;
|
2018-03-19 10:34:01 +00:00
|
|
|
|
2019-06-04 17:28:59 +00:00
|
|
|
upload_texture (self, texture, &r);
|
2018-03-19 10:34:01 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2019-06-04 17:28:59 +00:00
|
|
|
ops_set_texture (builder, r.texture_id);
|
2018-01-18 07:21:11 +00:00
|
|
|
|
2019-12-29 15:54:56 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-10-31 10:54:33 +00:00
|
|
|
&node->bounds, builder,
|
2019-12-29 15:54:56 +00:00
|
|
|
&r,
|
|
|
|
FALSE);
|
2018-03-19 10:34:01 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static Program *
|
|
|
|
compile_glshader (GskGLRenderer *self,
|
|
|
|
GskGLShader *shader,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GskGLShaderBuilder shader_builder;
|
|
|
|
const char *shader_source;
|
|
|
|
gsize shader_source_len;
|
|
|
|
int n_uniforms;
|
|
|
|
const GskGLUniform *uniforms;
|
|
|
|
GBytes *bytes;
|
|
|
|
int n_required_textures = gsk_gl_shader_get_n_textures (shader);
|
|
|
|
int program_id;
|
|
|
|
Program *program;
|
|
|
|
|
|
|
|
bytes = gsk_gl_shader_get_source (shader);
|
|
|
|
shader_source = g_bytes_get_data (bytes, &shader_source_len);
|
|
|
|
uniforms = gsk_gl_shader_get_uniforms (shader, &n_uniforms);
|
|
|
|
|
|
|
|
if (n_uniforms > G_N_ELEMENTS (program->glshader.args_locations))
|
|
|
|
{
|
|
|
|
g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_UNSUPPORTED_FORMAT,
|
|
|
|
"GLShaderNode supports max %d custom uniforms", (int)G_N_ELEMENTS (program->glshader.args_locations));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_required_textures > G_N_ELEMENTS (program->glshader.texture_locations))
|
|
|
|
{
|
|
|
|
g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_UNSUPPORTED_FORMAT,
|
|
|
|
"GLShaderNode supports max %d texture sources", (int)(G_N_ELEMENTS (program->glshader.texture_locations)));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsk_gl_shader_builder_init (&shader_builder,
|
|
|
|
"/org/gtk/libgsk/glsl/preamble.glsl",
|
|
|
|
"/org/gtk/libgsk/glsl/preamble.vs.glsl",
|
|
|
|
"/org/gtk/libgsk/glsl/preamble.fs.glsl");
|
|
|
|
|
|
|
|
init_shader_builder (self, &shader_builder);
|
|
|
|
program_id = gsk_gl_shader_builder_create_program (&shader_builder,
|
|
|
|
"/org/gtk/libgsk/glsl/custom.glsl",
|
|
|
|
shader_source, shader_source_len,
|
|
|
|
error);
|
|
|
|
gsk_gl_shader_builder_finish (&shader_builder);
|
|
|
|
|
|
|
|
if (program_id < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
program = gsk_gl_renderer_create_custom_program (self, shader);
|
|
|
|
|
|
|
|
program->id = program_id;
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (program, alpha);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (program, clip_rect);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (program, viewport);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (program, projection);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (program, modelview);
|
|
|
|
program->glshader.size_location = glGetUniformLocation(program->id, "u_size");
|
|
|
|
program->glshader.texture_locations[0] = glGetUniformLocation(program->id, "u_texture1");
|
|
|
|
program->glshader.texture_locations[1] = glGetUniformLocation(program->id, "u_texture2");
|
|
|
|
program->glshader.texture_locations[2] = glGetUniformLocation(program->id, "u_texture3");
|
|
|
|
program->glshader.texture_locations[3] = glGetUniformLocation(program->id, "u_texture4");
|
|
|
|
|
2020-10-01 17:48:08 +00:00
|
|
|
/* We use u_texture1 for the texture 0 in the glshaders, so alias it here so we can use the regular setters */
|
2020-09-18 16:03:30 +00:00
|
|
|
program->source_location = program->glshader.texture_locations[0];
|
|
|
|
|
|
|
|
for (int i = 0; i < G_N_ELEMENTS (program->glshader.args_locations); i++)
|
|
|
|
{
|
|
|
|
if (i < n_uniforms)
|
|
|
|
{
|
|
|
|
program->glshader.args_locations[i] = glGetUniformLocation(program->id, uniforms[i].name);
|
|
|
|
/* This isn't necessary a hard error, you might declare uniforms that are not actually
|
|
|
|
always used, for instance if you have an "API" in uniforms for multiple shaders. */
|
|
|
|
if (program->glshader.args_locations[i] == -1)
|
|
|
|
g_debug ("Declared uniform `%s` not found in GskGLShader", uniforms[i].name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
program->glshader.args_locations[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2020-10-10 18:20:38 +00:00
|
|
|
gsk_gl_renderer_try_compile_gl_shader (GskGLRenderer *self,
|
|
|
|
GskGLShader *shader,
|
|
|
|
GError **error)
|
2020-09-18 16:03:30 +00:00
|
|
|
{
|
|
|
|
Program *program;
|
|
|
|
|
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
|
|
|
|
|
|
|
/* Maybe we tried to compile it already? */
|
|
|
|
program = gsk_gl_renderer_lookup_custom_program (self, shader);
|
|
|
|
if (program != NULL)
|
|
|
|
{
|
|
|
|
if (program->id > 0)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_propagate_error (error, g_error_copy (program->glshader.compile_error));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
program = compile_glshader (self, shader, error);
|
|
|
|
return program != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_gl_shader_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
GskGLShader *shader = gsk_gl_shader_node_get_shader (node);
|
|
|
|
Program *program = gsk_gl_renderer_lookup_custom_program (self, shader);
|
|
|
|
int n_children = gsk_gl_shader_node_get_n_children (node);
|
|
|
|
|
|
|
|
if (program == NULL)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
program = compile_glshader (self, shader, &error);
|
|
|
|
if (program == NULL)
|
|
|
|
{
|
|
|
|
/* We create the program anyway (in a failed state), so that any compiler warnings or other are only reported once */
|
|
|
|
program = gsk_gl_renderer_create_custom_program (self, shader);
|
|
|
|
program->id = -1;
|
|
|
|
program->glshader.compile_error = error;
|
|
|
|
|
|
|
|
g_warning ("Failed to compile gl shader: %s", error->message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (program->id >= 0 && n_children <= G_N_ELEMENTS (program->glshader.texture_locations))
|
|
|
|
{
|
|
|
|
GBytes *args;
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion regions[4];
|
|
|
|
gboolean is_offscreen[4];
|
2020-09-18 16:03:30 +00:00
|
|
|
for (guint i = 0; i < n_children; i++)
|
|
|
|
{
|
|
|
|
GskRenderNode *child = gsk_gl_shader_node_get_child (node, i);
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
child,
|
|
|
|
®ions[i], &is_offscreen[i],
|
|
|
|
FORCE_OFFSCREEN | RESET_CLIP))
|
2020-09-18 16:03:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
args = gsk_gl_shader_node_get_args (node);
|
|
|
|
ops_set_program (builder, program);
|
|
|
|
|
|
|
|
ops_set_gl_shader_args (builder, shader, node->bounds.size.width, node->bounds.size.height, g_bytes_get_data (args, NULL));
|
|
|
|
for (guint i = 0; i < n_children; i++)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, regions[i].texture_id);
|
2020-09-18 16:03:30 +00:00
|
|
|
else
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_extra_texture (builder, regions[i].texture_id, i);
|
2020-09-18 16:03:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), node, builder);
|
2020-09-18 16:03:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static GdkRGBA pink = { 255 / 255., 105 / 255., 180 / 255., 1.0 };
|
|
|
|
ops_set_program (builder, &self->programs->color_program);
|
|
|
|
ops_set_color (builder, &pink);
|
2020-11-01 11:22:06 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
2020-09-18 16:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 16:15:24 +00:00
|
|
|
/* Returns TRUE if applying @transform to @bounds
|
2020-09-02 22:01:06 +00:00
|
|
|
* yields an axis-aligned rectangle
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
result_is_axis_aligned (GskTransform *transform,
|
|
|
|
const graphene_rect_t *bounds)
|
|
|
|
{
|
|
|
|
graphene_matrix_t m;
|
|
|
|
graphene_quad_t q;
|
|
|
|
graphene_rect_t b;
|
|
|
|
graphene_point_t b1, b2;
|
|
|
|
const graphene_point_t *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gsk_transform_to_matrix (transform, &m);
|
|
|
|
gsk_matrix_transform_rect (&m, bounds, &q);
|
|
|
|
graphene_quad_bounds (&q, &b);
|
|
|
|
graphene_rect_get_top_left (&b, &b1);
|
|
|
|
graphene_rect_get_bottom_right (&b, &b2);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
p = graphene_quad_get_point (&q, i);
|
|
|
|
if (fabs (p->x - b1.x) > FLT_EPSILON && fabs (p->x - b2.x) > FLT_EPSILON)
|
|
|
|
return FALSE;
|
|
|
|
if (fabs (p->y - b1.y) > FLT_EPSILON && fabs (p->y - b2.y) > FLT_EPSILON)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
static inline void
|
|
|
|
render_transform_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2019-03-01 05:35:55 +00:00
|
|
|
GskTransform *node_transform = gsk_transform_node_get_transform (node);
|
2019-03-01 06:51:23 +00:00
|
|
|
const GskTransformCategory category = gsk_transform_get_category (node_transform);
|
2017-12-08 12:12:43 +00:00
|
|
|
GskRenderNode *child = gsk_transform_node_get_child (node);
|
2018-12-03 17:29:36 +00:00
|
|
|
|
2019-02-22 17:10:27 +00:00
|
|
|
switch (category)
|
2018-11-29 07:09:02 +00:00
|
|
|
{
|
2019-03-01 06:51:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_IDENTITY:
|
2018-11-29 07:09:02 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2019-02-22 17:10:27 +00:00
|
|
|
break;
|
|
|
|
|
2019-03-01 06:51:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
|
2019-02-22 17:10:27 +00:00
|
|
|
{
|
2019-03-01 05:35:55 +00:00
|
|
|
float dx, dy;
|
2019-06-02 07:55:11 +00:00
|
|
|
|
2019-03-04 18:33:04 +00:00
|
|
|
gsk_transform_to_translate (node_transform, &dx, &dy);
|
2019-02-22 17:10:27 +00:00
|
|
|
|
|
|
|
ops_offset (builder, dx, dy);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
ops_offset (builder, -dx, -dy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-03-01 06:51:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
|
2019-02-22 17:10:27 +00:00
|
|
|
{
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_push_modelview (builder, node_transform);
|
2019-02-22 17:10:27 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
ops_pop_modelview (builder);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-03-01 06:51:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_2D:
|
2020-09-04 16:35:59 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_3D:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_ANY:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_UNKNOWN:
|
2019-02-22 17:10:27 +00:00
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion region;
|
|
|
|
gboolean is_offscreen;
|
|
|
|
|
2019-02-23 06:50:51 +00:00
|
|
|
if (node_supports_transform (child))
|
|
|
|
{
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_push_modelview (builder, node_transform);
|
2019-02-23 06:50:51 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2019-03-31 04:16:16 +00:00
|
|
|
ops_pop_modelview (builder);
|
2019-02-22 17:10:27 +00:00
|
|
|
}
|
2020-09-04 16:35:59 +00:00
|
|
|
else
|
|
|
|
{
|
2020-09-02 22:01:06 +00:00
|
|
|
int filter_flag = 0;
|
|
|
|
|
|
|
|
if (!result_is_axis_aligned (node_transform, &child->bounds))
|
|
|
|
filter_flag = LINEAR_FILTER;
|
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if (add_offscreen_ops (self, builder,
|
|
|
|
&child->bounds,
|
|
|
|
child,
|
|
|
|
®ion, &is_offscreen,
|
|
|
|
RESET_CLIP | filter_flag))
|
2020-09-02 22:01:06 +00:00
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
ops_push_modelview (builder, node_transform);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2020-09-02 22:01:06 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
|
|
|
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-10-31 10:54:33 +00:00
|
|
|
&child->bounds, builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
®ion,
|
|
|
|
is_offscreen);
|
2020-09-02 22:01:06 +00:00
|
|
|
ops_pop_modelview (builder);
|
|
|
|
}
|
2019-03-31 04:16:16 +00:00
|
|
|
}
|
2019-02-22 17:10:27 +00:00
|
|
|
}
|
2020-09-04 16:35:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2018-11-29 07:09:02 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_opacity_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2019-07-13 15:35:59 +00:00
|
|
|
GskRenderNode *child = gsk_opacity_node_get_child (node);
|
|
|
|
const float opacity = gsk_opacity_node_get_opacity (node);
|
2017-12-08 12:12:43 +00:00
|
|
|
float prev_opacity;
|
|
|
|
|
2019-07-13 15:35:59 +00:00
|
|
|
if (gsk_render_node_get_node_type (child) == GSK_CONTAINER_NODE)
|
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
gboolean is_offscreen;
|
|
|
|
TextureRegion region;
|
2019-07-13 15:35:59 +00:00
|
|
|
|
|
|
|
/* The semantics of an opacity node mandate that when, e.g., two color nodes overlap,
|
|
|
|
* there may not be any blending between them */
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder, &child->bounds,
|
|
|
|
child,
|
|
|
|
®ion, &is_offscreen,
|
|
|
|
FORCE_OFFSCREEN | RESET_CLIP))
|
2019-11-23 09:20:15 +00:00
|
|
|
return;
|
2019-07-13 15:35:59 +00:00
|
|
|
|
|
|
|
prev_opacity = ops_set_opacity (builder,
|
|
|
|
builder->current_opacity * opacity);
|
|
|
|
|
2020-10-01 06:29:10 +00:00
|
|
|
if (builder->current_opacity >= ((float) 0x00ff / (float) 0xffff))
|
|
|
|
{
|
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2019-07-13 15:35:59 +00:00
|
|
|
|
2020-10-01 06:29:10 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-10-31 10:54:33 +00:00
|
|
|
&node->bounds, builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
®ion,
|
|
|
|
is_offscreen);
|
2020-10-01 06:29:10 +00:00
|
|
|
}
|
2019-07-13 15:35:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_opacity = ops_set_opacity (builder,
|
|
|
|
builder->current_opacity * opacity);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-10-01 06:29:10 +00:00
|
|
|
if (builder->current_opacity >= ((float) 0x00ff / (float) 0xffff))
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2019-07-13 15:35:59 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
|
|
|
|
ops_set_opacity (builder, prev_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-11-26 07:58:38 +00:00
|
|
|
render_linear_gradient_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2020-09-21 19:19:19 +00:00
|
|
|
const int n_color_stops = gsk_linear_gradient_node_get_n_color_stops (node);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-09-21 19:19:19 +00:00
|
|
|
if (n_color_stops < GL_MAX_GRADIENT_STOPS)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskColorStop *stops = gsk_linear_gradient_node_get_color_stops (node, NULL);
|
|
|
|
const graphene_point_t *start = gsk_linear_gradient_node_get_start (node);
|
|
|
|
const graphene_point_t *end = gsk_linear_gradient_node_get_end (node);
|
2020-09-21 19:19:19 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->programs->linear_gradient_program);
|
|
|
|
ops_set_linear_gradient (builder,
|
|
|
|
n_color_stops,
|
|
|
|
stops,
|
|
|
|
builder->dx + start->x,
|
|
|
|
builder->dy + start->y,
|
|
|
|
builder->dx + end->x,
|
|
|
|
builder->dy + end->y);
|
|
|
|
|
2020-11-01 11:22:06 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
2020-09-21 19:19:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
render_fallback_node (self, node, builder);
|
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 12:42:36 +00:00
|
|
|
static inline void
|
|
|
|
render_radial_gradient_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2020-09-21 19:19:19 +00:00
|
|
|
const int n_color_stops = gsk_radial_gradient_node_get_n_color_stops (node);
|
2020-09-18 12:42:36 +00:00
|
|
|
|
2020-09-21 19:19:19 +00:00
|
|
|
if (n_color_stops < GL_MAX_GRADIENT_STOPS)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskColorStop *stops = gsk_radial_gradient_node_get_color_stops (node, NULL);
|
|
|
|
const graphene_point_t *center = gsk_radial_gradient_node_get_center (node);
|
2020-09-21 19:19:19 +00:00
|
|
|
const float start = gsk_radial_gradient_node_get_start (node);
|
|
|
|
const float end = gsk_radial_gradient_node_get_end (node);
|
|
|
|
const float hradius = gsk_radial_gradient_node_get_hradius (node);
|
|
|
|
const float vradius = gsk_radial_gradient_node_get_vradius (node);
|
|
|
|
|
|
|
|
ops_set_program (builder, &self->programs->radial_gradient_program);
|
|
|
|
ops_set_radial_gradient (builder,
|
|
|
|
n_color_stops,
|
|
|
|
stops,
|
|
|
|
builder->dx + center->x,
|
|
|
|
builder->dy + center->y,
|
|
|
|
start, end,
|
|
|
|
hradius * builder->scale_x,
|
|
|
|
vradius * builder->scale_y);
|
|
|
|
|
2020-11-01 11:22:06 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
2020-09-21 19:19:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
render_fallback_node (self, node, builder);
|
|
|
|
}
|
2020-09-18 12:42:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 05:02:18 +00:00
|
|
|
static inline void
|
|
|
|
render_conic_gradient_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
const int n_color_stops = gsk_conic_gradient_node_get_n_color_stops (node);
|
|
|
|
|
|
|
|
if (n_color_stops < GL_MAX_GRADIENT_STOPS)
|
|
|
|
{
|
|
|
|
const GskColorStop *stops = gsk_conic_gradient_node_get_color_stops (node, NULL);
|
|
|
|
const graphene_point_t *center = gsk_conic_gradient_node_get_center (node);
|
|
|
|
const float rotation = gsk_conic_gradient_node_get_rotation (node);
|
|
|
|
|
|
|
|
ops_set_program (builder, &self->programs->conic_gradient_program);
|
|
|
|
ops_set_conic_gradient (builder,
|
|
|
|
n_color_stops,
|
|
|
|
stops,
|
|
|
|
builder->dx + center->x,
|
|
|
|
builder->dy + center->y,
|
|
|
|
rotation);
|
|
|
|
|
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
render_fallback_node (self, node, builder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:11:13 +00:00
|
|
|
static inline gboolean
|
|
|
|
rounded_inner_rect_contains_rect (const GskRoundedRect *rounded,
|
|
|
|
const graphene_rect_t *rect)
|
|
|
|
{
|
|
|
|
const graphene_rect_t *rounded_bounds = &rounded->bounds;
|
|
|
|
graphene_rect_t inner;
|
|
|
|
float offset_x, offset_y;
|
|
|
|
|
|
|
|
/* TODO: This is pretty conservative and we could to further, more
|
|
|
|
* fine-grained checks to avoid offscreen drawing. */
|
|
|
|
|
|
|
|
offset_x = MAX (rounded->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
rounded->corner[GSK_CORNER_BOTTOM_LEFT].width);
|
|
|
|
offset_y = MAX (rounded->corner[GSK_CORNER_TOP_LEFT].height,
|
|
|
|
rounded->corner[GSK_CORNER_TOP_RIGHT].height);
|
|
|
|
|
|
|
|
|
|
|
|
inner.origin.x = rounded_bounds->origin.x + offset_x;
|
|
|
|
inner.origin.y = rounded_bounds->origin.y + offset_y;
|
|
|
|
inner.size.width = rounded_bounds->size.width - offset_x -
|
|
|
|
MAX (rounded->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
rounded->corner[GSK_CORNER_BOTTOM_RIGHT].width);
|
|
|
|
inner.size.height = rounded_bounds->size.height - offset_y -
|
|
|
|
MAX (rounded->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
|
|
|
rounded->corner[GSK_CORNER_BOTTOM_RIGHT].height);
|
|
|
|
|
|
|
|
return graphene_rect_contains_rect (&inner, rect);
|
|
|
|
}
|
|
|
|
|
2020-07-08 03:45:34 +00:00
|
|
|
/* Current clip is NOT rounded but new one is definitely! */
|
|
|
|
static inline bool
|
|
|
|
intersect_rounded_rectilinear (const graphene_rect_t *non_rounded,
|
|
|
|
const GskRoundedRect *rounded,
|
|
|
|
GskRoundedRect *result)
|
|
|
|
{
|
|
|
|
bool corners[4];
|
|
|
|
|
|
|
|
/* Intersects with top left corner? */
|
2020-07-24 18:01:14 +00:00
|
|
|
corners[0] = rounded_rect_has_corner (rounded, 0) &&
|
|
|
|
graphene_rect_intersects (non_rounded,
|
|
|
|
&rounded_rect_corner (rounded, 0));
|
2020-07-08 03:45:34 +00:00
|
|
|
/* top right? */
|
2020-07-24 18:01:14 +00:00
|
|
|
corners[1] = rounded_rect_has_corner (rounded, 1) &&
|
|
|
|
graphene_rect_intersects (non_rounded,
|
|
|
|
&rounded_rect_corner (rounded, 1));
|
2020-07-08 03:45:34 +00:00
|
|
|
/* bottom right? */
|
2020-07-24 18:01:14 +00:00
|
|
|
corners[2] = rounded_rect_has_corner (rounded, 2) &&
|
|
|
|
graphene_rect_intersects (non_rounded,
|
|
|
|
&rounded_rect_corner (rounded, 2));
|
2020-07-08 03:45:34 +00:00
|
|
|
/* bottom left */
|
2020-07-24 18:01:14 +00:00
|
|
|
corners[3] = rounded_rect_has_corner (rounded, 3) &&
|
|
|
|
graphene_rect_intersects (non_rounded,
|
|
|
|
&rounded_rect_corner (rounded, 3));
|
2020-07-08 03:45:34 +00:00
|
|
|
|
2020-07-24 15:18:18 +00:00
|
|
|
if (corners[0] && !_graphene_rect_contains_rect (non_rounded, &rounded_rect_corner (rounded, 0)))
|
2020-07-08 03:45:34 +00:00
|
|
|
return false;
|
2020-07-24 15:18:18 +00:00
|
|
|
if (corners[1] && !_graphene_rect_contains_rect (non_rounded, &rounded_rect_corner (rounded, 1)))
|
2020-07-08 03:45:34 +00:00
|
|
|
return false;
|
2020-07-24 15:18:18 +00:00
|
|
|
if (corners[2] && !_graphene_rect_contains_rect (non_rounded, &rounded_rect_corner (rounded, 2)))
|
2020-07-08 03:45:34 +00:00
|
|
|
return false;
|
2020-07-24 15:18:18 +00:00
|
|
|
if (corners[3] && !_graphene_rect_contains_rect (non_rounded, &rounded_rect_corner (rounded, 3)))
|
2020-07-08 03:45:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* We do intersect with at least one of the corners, but in such a way that the
|
|
|
|
* intersection between the two clips can still be represented by a single rounded
|
|
|
|
* rect in a trivial way. do that. */
|
|
|
|
graphene_rect_intersection (non_rounded, &rounded->bounds, &result->bounds);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (corners[i])
|
|
|
|
result->corner[i] = rounded->corner[i];
|
|
|
|
else
|
|
|
|
result->corner[i].width = result->corner[i].height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This code intersects the current (maybe rounded) clip with the new
|
|
|
|
* non-rounded clip */
|
2017-12-08 12:12:43 +00:00
|
|
|
static inline void
|
2019-11-19 09:45:02 +00:00
|
|
|
render_clipped_child (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *clip,
|
|
|
|
GskRenderNode *child)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
|
|
|
graphene_rect_t transformed_clip;
|
2020-07-08 03:45:34 +00:00
|
|
|
GskRoundedRect intersection;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-10-11 19:49:13 +00:00
|
|
|
ops_transform_bounds_modelview (builder, clip, &transformed_clip);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-05-24 06:31:55 +00:00
|
|
|
if (builder->clip_is_rectilinear)
|
|
|
|
{
|
2020-07-08 03:45:34 +00:00
|
|
|
memset (&intersection, 0, sizeof (GskRoundedRect));
|
|
|
|
graphene_rect_intersection (&transformed_clip,
|
|
|
|
&builder->current_clip->bounds,
|
|
|
|
&intersection.bounds);
|
2020-05-12 18:11:13 +00:00
|
|
|
|
2020-07-08 03:45:34 +00:00
|
|
|
ops_push_clip (builder, &intersection);
|
2020-05-24 10:06:07 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2020-05-24 06:31:55 +00:00
|
|
|
ops_pop_clip (builder);
|
2020-05-24 10:06:07 +00:00
|
|
|
}
|
2020-07-08 03:45:34 +00:00
|
|
|
else if (intersect_rounded_rectilinear (&transformed_clip,
|
|
|
|
builder->current_clip,
|
|
|
|
&intersection))
|
|
|
|
{
|
|
|
|
ops_push_clip (builder, &intersection);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
ops_pop_clip (builder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* well fuck */
|
2020-12-19 16:43:56 +00:00
|
|
|
const float scale_x = builder->scale_x;
|
|
|
|
const float scale_y = builder->scale_y;
|
|
|
|
const GskRoundedRect scaled_clip = GSK_ROUNDED_RECT_INIT (clip->origin.x * scale_x,
|
|
|
|
clip->origin.y * scale_y,
|
|
|
|
clip->size.width * scale_x,
|
|
|
|
clip->size.height * scale_y);
|
|
|
|
gboolean is_offscreen;
|
|
|
|
TextureRegion region;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-07-08 03:45:34 +00:00
|
|
|
ops_push_clip (builder, &scaled_clip);
|
|
|
|
if (!add_offscreen_ops (self, builder, &child->bounds,
|
2020-12-19 16:43:56 +00:00
|
|
|
child,
|
|
|
|
®ion, &is_offscreen,
|
|
|
|
FORCE_OFFSCREEN))
|
2020-07-08 03:45:34 +00:00
|
|
|
g_assert_not_reached ();
|
|
|
|
ops_pop_clip (builder);
|
2020-05-24 06:31:55 +00:00
|
|
|
|
2020-07-08 03:45:34 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), child, builder);
|
2020-07-08 03:45:34 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 09:45:02 +00:00
|
|
|
static inline void
|
|
|
|
render_clip_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const graphene_rect_t *clip = gsk_clip_node_get_clip (node);
|
2019-11-19 09:45:02 +00:00
|
|
|
GskRenderNode *child = gsk_clip_node_get_child (node);
|
|
|
|
|
|
|
|
render_clipped_child (self, builder, clip, child);
|
|
|
|
}
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
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
|
|
|
{
|
2020-09-19 16:13:00 +00:00
|
|
|
const float scale_x = builder->scale_x;
|
|
|
|
const float scale_y = builder->scale_y;
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskRoundedRect *clip = gsk_rounded_clip_node_get_clip (node);
|
2017-12-08 12:12:43 +00:00
|
|
|
GskRenderNode *child = gsk_rounded_clip_node_get_child (node);
|
2020-01-22 07:32:11 +00:00
|
|
|
GskRoundedRect transformed_clip;
|
2018-12-30 14:25:01 +00:00
|
|
|
gboolean need_offscreen;
|
2018-03-15 10:01:53 +00:00
|
|
|
int i;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-11-23 09:20:15 +00:00
|
|
|
if (node_is_invisible (child))
|
|
|
|
return;
|
|
|
|
|
2020-01-22 07:32:11 +00:00
|
|
|
ops_transform_bounds_modelview (builder, &clip->bounds, &transformed_clip.bounds);
|
2020-07-08 03:45:34 +00:00
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
2020-09-19 16:13:00 +00:00
|
|
|
transformed_clip.corner[i].width = clip->corner[i].width * scale_x;
|
|
|
|
transformed_clip.corner[i].height = clip->corner[i].height * scale_y;
|
2020-07-08 03:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (builder->clip_is_rectilinear)
|
|
|
|
{
|
|
|
|
GskRoundedRect intersected_clip;
|
|
|
|
|
|
|
|
if (intersect_rounded_rectilinear (&builder->current_clip->bounds,
|
|
|
|
&transformed_clip,
|
|
|
|
&intersected_clip))
|
|
|
|
{
|
|
|
|
ops_push_clip (builder, &intersected_clip);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
ops_pop_clip (builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* After this point we are really working with a new and a current clip
|
|
|
|
* which both have rounded corners. */
|
2018-03-15 10:01:53 +00:00
|
|
|
|
2018-12-30 14:25:01 +00:00
|
|
|
if (!ops_has_clip (builder))
|
2019-10-09 14:41:02 +00:00
|
|
|
need_offscreen = FALSE;
|
2020-05-12 18:11:13 +00:00
|
|
|
else if (rounded_inner_rect_contains_rect (builder->current_clip,
|
|
|
|
&transformed_clip.bounds))
|
2019-10-09 14:41:02 +00:00
|
|
|
need_offscreen = FALSE;
|
2018-12-30 14:25:01 +00:00
|
|
|
else
|
2019-10-09 14:41:02 +00:00
|
|
|
need_offscreen = TRUE;
|
2018-12-30 14:25:01 +00:00
|
|
|
|
|
|
|
if (!need_offscreen)
|
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 */
|
|
|
|
|
2020-07-03 04:41:29 +00:00
|
|
|
/* If the new clip entirely contains the current clip, the intersection is simply
|
|
|
|
* the current clip, so we can ignore the new one */
|
|
|
|
if (rounded_inner_rect_contains_rect (&transformed_clip, &builder->current_clip->bounds))
|
|
|
|
{
|
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Intersect current and new clip */
|
2019-10-09 14:41:02 +00:00
|
|
|
ops_push_clip (builder, &transformed_clip);
|
2018-04-11 15:57:57 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2018-12-30 14:25:01 +00:00
|
|
|
ops_pop_clip (builder);
|
2018-03-15 10:01:53 +00:00
|
|
|
}
|
2018-12-30 14:25:01 +00:00
|
|
|
else
|
2018-04-11 15:57:57 +00:00
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
GskRoundedRect scaled_clip;
|
|
|
|
gboolean is_offscreen;
|
|
|
|
TextureRegion region;
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
scaled_clip.bounds.origin.x = clip->bounds.origin.x * scale_x;
|
|
|
|
scaled_clip.bounds.origin.y = clip->bounds.origin.y * scale_y;
|
|
|
|
scaled_clip.bounds.size.width = clip->bounds.size.width * scale_x;
|
|
|
|
scaled_clip.bounds.size.height = clip->bounds.size.height * scale_y;
|
|
|
|
|
|
|
|
/* Increase corner radius size by scale factor */
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
|
|
|
scaled_clip.corner[i].width = clip->corner[i].width * scale_x;
|
|
|
|
scaled_clip.corner[i].height = clip->corner[i].height * scale_y;
|
|
|
|
}
|
2018-03-15 10:01:53 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_push_clip (builder, &scaled_clip);
|
|
|
|
if (!add_offscreen_ops (self, builder, &node->bounds,
|
|
|
|
child,
|
|
|
|
®ion, &is_offscreen,
|
|
|
|
0))
|
2019-11-27 15:56:47 +00:00
|
|
|
g_assert_not_reached ();
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_pop_clip (builder);
|
2020-12-13 15:29:14 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2018-03-14 11:36:32 +00:00
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), node, builder);
|
2018-04-11 15:57:57 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
render_color_matrix_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
2019-10-15 03:28:15 +00:00
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2019-03-31 05:50:33 +00:00
|
|
|
GskRenderNode *child = gsk_color_matrix_node_get_child (node);
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion region;
|
|
|
|
gboolean is_offscreen;
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-11-23 09:20:15 +00:00
|
|
|
if (node_is_invisible (child))
|
|
|
|
return;
|
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
child,
|
|
|
|
®ion, &is_offscreen,
|
|
|
|
RESET_CLIP))
|
2019-11-27 15:56:47 +00:00
|
|
|
g_assert_not_reached ();
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->color_matrix_program);
|
2017-12-08 12:12:43 +00:00
|
|
|
ops_set_color_matrix (builder,
|
2020-11-16 23:59:36 +00:00
|
|
|
gsk_color_matrix_node_get_color_matrix (node),
|
|
|
|
gsk_color_matrix_node_get_color_offset (node));
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-12-29 15:54:56 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-12-19 16:43:56 +00:00
|
|
|
&node->bounds, builder,
|
|
|
|
®ion,
|
|
|
|
is_offscreen);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
static inline int
|
2019-11-29 05:53:57 +00:00
|
|
|
blur_texture (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const TextureRegion *region,
|
|
|
|
const int texture_to_blur_width,
|
|
|
|
const int texture_to_blur_height,
|
2020-10-10 17:57:29 +00:00
|
|
|
float blur_radius_x,
|
|
|
|
float blur_radius_y)
|
2019-11-26 08:38:53 +00:00
|
|
|
{
|
|
|
|
int pass1_texture_id, pass1_render_target;
|
|
|
|
int pass2_texture_id, pass2_render_target;
|
|
|
|
int prev_render_target;
|
|
|
|
graphene_matrix_t prev_projection;
|
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
graphene_matrix_t item_proj;
|
|
|
|
OpBlur *op;
|
|
|
|
|
2020-10-10 17:57:29 +00:00
|
|
|
g_assert (blur_radius_x > 0);
|
|
|
|
g_assert (blur_radius_y > 0);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
|
|
|
gsk_gl_driver_create_render_target (self->gl_driver,
|
2020-10-10 17:39:33 +00:00
|
|
|
MAX (texture_to_blur_width, 1), MAX (texture_to_blur_height, 1),
|
2020-09-02 22:01:06 +00:00
|
|
|
GL_NEAREST, GL_NEAREST,
|
2019-11-26 08:38:53 +00:00
|
|
|
&pass1_texture_id, &pass1_render_target);
|
|
|
|
|
2020-10-10 17:39:33 +00:00
|
|
|
if (texture_to_blur_width <= 0 || texture_to_blur_height <= 0)
|
|
|
|
{
|
|
|
|
return pass1_texture_id;
|
|
|
|
}
|
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
gsk_gl_driver_create_render_target (self->gl_driver,
|
|
|
|
texture_to_blur_width, texture_to_blur_height,
|
2020-09-02 22:01:06 +00:00
|
|
|
GL_NEAREST, GL_NEAREST,
|
2019-11-26 08:38:53 +00:00
|
|
|
&pass2_texture_id, &pass2_render_target);
|
|
|
|
|
2020-10-01 06:39:19 +00:00
|
|
|
init_projection_matrix (&item_proj,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, texture_to_blur_width, texture_to_blur_height));
|
2019-11-26 08:38:53 +00:00
|
|
|
|
|
|
|
prev_projection = ops_set_projection (builder, &item_proj);
|
|
|
|
ops_set_modelview (builder, NULL);
|
|
|
|
prev_viewport = ops_set_viewport (builder, &GRAPHENE_RECT_INIT (0, 0, texture_to_blur_width, texture_to_blur_height));
|
|
|
|
ops_push_clip (builder, &GSK_ROUNDED_RECT_INIT (0, 0, texture_to_blur_width, texture_to_blur_height));
|
|
|
|
|
|
|
|
prev_render_target = ops_set_render_target (builder, pass1_render_target);
|
|
|
|
ops_begin (builder, OP_CLEAR);
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blur_program);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
|
|
|
op = ops_begin (builder, OP_CHANGE_BLUR);
|
|
|
|
op->size.width = texture_to_blur_width;
|
|
|
|
op->size.height = texture_to_blur_height;
|
2020-10-10 17:57:29 +00:00
|
|
|
op->radius = blur_radius_x;
|
2019-11-26 08:38:53 +00:00
|
|
|
op->dir[0] = 1;
|
|
|
|
op->dir[1] = 0;
|
2019-11-29 05:53:57 +00:00
|
|
|
ops_set_texture (builder, region->texture_id);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
2020-11-01 11:16:44 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, texture_to_blur_width, texture_to_blur_height),
|
|
|
|
builder, region,
|
|
|
|
FALSE);
|
2019-11-29 05:53:57 +00:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
static int k;
|
|
|
|
ops_dump_framebuffer (builder,
|
|
|
|
g_strdup_printf ("pass1_%d.png", k++),
|
|
|
|
texture_to_blur_width,
|
|
|
|
texture_to_blur_height);
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-26 08:38:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_BLUR);
|
|
|
|
op->size.width = texture_to_blur_width;
|
|
|
|
op->size.height = texture_to_blur_height;
|
2020-10-10 17:57:29 +00:00
|
|
|
op->radius = blur_radius_y;
|
2019-11-26 08:38:53 +00:00
|
|
|
op->dir[0] = 0;
|
|
|
|
op->dir[1] = 1;
|
|
|
|
ops_set_texture (builder, pass1_texture_id);
|
|
|
|
ops_set_render_target (builder, pass2_render_target);
|
|
|
|
ops_begin (builder, OP_CLEAR);
|
2020-11-01 11:16:44 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL), /* render pass 2 */
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, texture_to_blur_width, texture_to_blur_height),
|
|
|
|
builder, region,
|
|
|
|
FALSE);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
2019-11-28 08:01:56 +00:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
static int k;
|
|
|
|
ops_dump_framebuffer (builder,
|
|
|
|
g_strdup_printf ("blurred%d.png", k++),
|
|
|
|
texture_to_blur_width,
|
|
|
|
texture_to_blur_height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
ops_set_render_target (builder, prev_render_target);
|
|
|
|
ops_set_viewport (builder, &prev_viewport);
|
|
|
|
ops_set_projection (builder, &prev_projection);
|
|
|
|
ops_pop_modelview (builder);
|
|
|
|
ops_pop_clip (builder);
|
|
|
|
|
|
|
|
return pass2_texture_id;
|
|
|
|
}
|
|
|
|
|
2019-12-07 12:11:07 +00:00
|
|
|
static inline void
|
|
|
|
blur_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
float blur_radius,
|
|
|
|
guint extra_flags,
|
|
|
|
TextureRegion *out_region,
|
2020-12-19 16:43:43 +00:00
|
|
|
float *out_vertex_data[4]) /* min, max, min, max */
|
2019-12-07 12:11:07 +00:00
|
|
|
{
|
2020-10-10 17:57:29 +00:00
|
|
|
const float scale_x = builder->scale_x;
|
|
|
|
const float scale_y = builder->scale_y;
|
2020-08-07 04:43:06 +00:00
|
|
|
const float blur_extra = blur_radius * 2.0; /* 2.0 = shader radius_multiplier */
|
2019-12-07 12:11:07 +00:00
|
|
|
float texture_width, texture_height;
|
2020-12-19 16:43:56 +00:00
|
|
|
gboolean is_offscreen;
|
|
|
|
TextureRegion region;
|
2019-12-07 12:11:07 +00:00
|
|
|
int blurred_texture_id;
|
|
|
|
|
|
|
|
g_assert (blur_radius > 0);
|
|
|
|
|
|
|
|
/* Increase texture size for the given blur radius and scale it */
|
2020-08-07 04:43:06 +00:00
|
|
|
texture_width = ceilf ((node->bounds.size.width + blur_extra));
|
|
|
|
texture_height = ceilf ((node->bounds.size.height + blur_extra));
|
2019-12-07 12:11:07 +00:00
|
|
|
|
2020-10-22 15:45:39 +00:00
|
|
|
/* Only blur this if the out region has no texture id yet */
|
|
|
|
if (out_region->texture_id == 0)
|
|
|
|
{
|
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&GRAPHENE_RECT_INIT (node->bounds.origin.x - (blur_extra / 2.0),
|
|
|
|
node->bounds.origin.y - (blur_extra / 2.0),
|
|
|
|
texture_width, texture_height),
|
|
|
|
node,
|
2020-12-19 16:43:56 +00:00
|
|
|
®ion, &is_offscreen,
|
|
|
|
RESET_CLIP | FORCE_OFFSCREEN | extra_flags))
|
2020-10-22 15:45:39 +00:00
|
|
|
g_assert_not_reached ();
|
2019-12-07 12:11:07 +00:00
|
|
|
|
2020-10-22 15:45:39 +00:00
|
|
|
blurred_texture_id = blur_texture (self, builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
®ion,
|
2020-10-22 15:45:39 +00:00
|
|
|
texture_width * scale_x, texture_height * scale_y,
|
|
|
|
blur_radius * scale_x,
|
|
|
|
blur_radius * scale_y);
|
|
|
|
init_full_texture_region (out_region, blurred_texture_id);
|
|
|
|
}
|
2019-12-07 12:11:07 +00:00
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
if (out_vertex_data)
|
|
|
|
{
|
|
|
|
*out_vertex_data[0] = builder->dx + node->bounds.origin.x - (blur_extra / 2.0);
|
|
|
|
*out_vertex_data[1] = builder->dx + node->bounds.origin.x + node->bounds.size.width + (blur_extra / 2.0);
|
|
|
|
*out_vertex_data[2] = builder->dy + node->bounds.origin.y - (blur_extra / 2.0);
|
|
|
|
*out_vertex_data[3] = builder->dy + node->bounds.origin.y + node->bounds.size.height + (blur_extra / 2.0);
|
|
|
|
}
|
2019-12-07 12:11:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 03:28:15 +00:00
|
|
|
static inline void
|
|
|
|
render_blur_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
2019-11-26 07:58:38 +00:00
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2019-12-07 12:11:07 +00:00
|
|
|
const float blur_radius = gsk_blur_node_get_radius (node);
|
2019-10-11 19:56:12 +00:00
|
|
|
GskRenderNode *child = gsk_blur_node_get_child (node);
|
2019-12-07 12:11:07 +00:00
|
|
|
TextureRegion blurred_region;
|
2020-09-09 17:55:09 +00:00
|
|
|
GskTextureKey key;
|
2020-12-19 16:43:43 +00:00
|
|
|
float min_x, max_x, min_y, max_y;
|
2019-01-05 08:18:27 +00:00
|
|
|
|
2020-01-22 07:38:41 +00:00
|
|
|
if (node_is_invisible (child))
|
|
|
|
return;
|
|
|
|
|
2019-05-07 15:20:11 +00:00
|
|
|
if (blur_radius <= 0)
|
|
|
|
{
|
2019-10-11 19:56:12 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, child, builder);
|
2019-05-07 15:20:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
key.pointer = node;
|
2020-09-30 12:53:13 +00:00
|
|
|
key.pointer_is_child = FALSE;
|
2020-12-04 20:12:34 +00:00
|
|
|
key.scale_x = builder->scale_x;
|
|
|
|
key.scale_y = builder->scale_y;
|
2020-09-09 17:55:09 +00:00
|
|
|
key.filter = GL_NEAREST;
|
|
|
|
blurred_region.texture_id = gsk_gl_driver_get_texture_for_key (self->gl_driver, &key);
|
2020-12-19 16:43:43 +00:00
|
|
|
blur_node (self, child, builder, blur_radius, 0, &blurred_region,
|
|
|
|
(float*[4]){&min_x, &max_x, &min_y, &max_y});
|
2019-01-13 07:21:58 +00:00
|
|
|
|
2019-12-07 12:11:07 +00:00
|
|
|
g_assert (blurred_region.texture_id != 0);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Draw the result */
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2019-12-07 12:11:07 +00:00
|
|
|
ops_set_texture (builder, blurred_region.texture_id);
|
2020-12-19 16:43:43 +00:00
|
|
|
fill_vertex_data (ops_draw (builder, NULL), min_x, min_y, max_x, max_y);
|
|
|
|
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Add to cache for the blur node */
|
2020-09-09 17:55:09 +00:00
|
|
|
gsk_gl_driver_set_texture_for_key (self->gl_driver, &key, blurred_region.texture_id);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-11-30 11:44:30 +00:00
|
|
|
render_unblurred_inset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2019-11-30 11:44:30 +00:00
|
|
|
const float blur_radius = gsk_inset_shadow_node_get_blur_radius (node);
|
|
|
|
const float dx = gsk_inset_shadow_node_get_dx (node);
|
|
|
|
const float dy = gsk_inset_shadow_node_get_dy (node);
|
|
|
|
const float spread = gsk_inset_shadow_node_get_spread (node);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2019-11-30 11:44:30 +00:00
|
|
|
g_assert (blur_radius == 0);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->inset_shadow_program);
|
2020-11-16 23:59:36 +00:00
|
|
|
ops_set_inset_shadow (builder, transform_rect (self, builder, gsk_inset_shadow_node_get_outline (node)),
|
2020-07-24 06:49:24 +00:00
|
|
|
spread,
|
2020-11-16 23:59:36 +00:00
|
|
|
gsk_inset_shadow_node_get_color (node),
|
2020-07-24 06:49:24 +00:00
|
|
|
dx, dy);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-11-01 11:22:06 +00:00
|
|
|
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 11:44:30 +00:00
|
|
|
static inline void
|
|
|
|
render_inset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2020-10-10 17:57:29 +00:00
|
|
|
const float scale_x = builder->scale_x;
|
|
|
|
const float scale_y = builder->scale_y;
|
2019-11-30 11:44:30 +00:00
|
|
|
const float blur_radius = gsk_inset_shadow_node_get_blur_radius (node);
|
2020-08-07 04:43:06 +00:00
|
|
|
const float blur_extra = blur_radius * 2.0; /* 2.0 = shader radius_multiplier */
|
2019-11-30 11:44:30 +00:00
|
|
|
const float dx = gsk_inset_shadow_node_get_dx (node);
|
|
|
|
const float dy = gsk_inset_shadow_node_get_dy (node);
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskRoundedRect *node_outline = gsk_inset_shadow_node_get_outline (node);
|
2019-11-30 11:44:30 +00:00
|
|
|
float texture_width;
|
|
|
|
float texture_height;
|
|
|
|
int blurred_texture_id;
|
2020-09-09 17:55:09 +00:00
|
|
|
GskTextureKey key;
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
g_assert (blur_radius > 0);
|
|
|
|
|
2020-10-10 17:57:29 +00:00
|
|
|
texture_width = ceilf ((node_outline->bounds.size.width + blur_extra) * scale_x);
|
|
|
|
texture_height = ceilf ((node_outline->bounds.size.height + blur_extra) * scale_y);
|
2019-11-30 11:44:30 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
key.pointer = node;
|
2020-09-30 12:53:13 +00:00
|
|
|
key.pointer_is_child = FALSE;
|
2020-12-04 20:12:34 +00:00
|
|
|
key.scale_x = scale_x;
|
|
|
|
key.scale_y = scale_y;
|
2020-09-09 17:55:09 +00:00
|
|
|
key.filter = GL_NEAREST;
|
|
|
|
blurred_texture_id = gsk_gl_driver_get_texture_for_key (self->gl_driver, &key);
|
2019-11-30 11:44:30 +00:00
|
|
|
if (blurred_texture_id == 0)
|
|
|
|
{
|
|
|
|
const float spread = gsk_inset_shadow_node_get_spread (node) + (blur_extra / 2.0);
|
|
|
|
GskRoundedRect outline_to_blur;
|
|
|
|
int render_target, texture_id;
|
|
|
|
int prev_render_target;
|
|
|
|
graphene_matrix_t prev_projection;
|
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
graphene_matrix_t item_proj;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* TODO: In the following code, we have to be careful about where we apply the scale.
|
|
|
|
* We're manually scaling stuff (e.g. the outline) so we can later use texture_width
|
|
|
|
* and texture_height (which are already scaled) as the geometry and keep the modelview
|
|
|
|
* at a scale of 1. That's kinda complicated though... */
|
|
|
|
|
|
|
|
/* Outline of what we actually want to blur later.
|
|
|
|
* Spread grows inside, so we don't need to account for that. But the blur will need
|
|
|
|
* to read outside of the inset shadow, so we need to draw some color in there. */
|
|
|
|
outline_to_blur = *node_outline;
|
|
|
|
gsk_rounded_rect_shrink (&outline_to_blur,
|
|
|
|
- blur_extra / 2.0, - blur_extra / 2.0,
|
|
|
|
- blur_extra / 2.0, - blur_extra / 2.0);
|
|
|
|
|
|
|
|
/* Fit to our texture */
|
|
|
|
outline_to_blur.bounds.origin.x = 0;
|
|
|
|
outline_to_blur.bounds.origin.y = 0;
|
2020-10-10 17:57:29 +00:00
|
|
|
outline_to_blur.bounds.size.width *= scale_x;
|
|
|
|
outline_to_blur.bounds.size.height *= scale_y;
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
{
|
2020-10-10 17:57:29 +00:00
|
|
|
outline_to_blur.corner[i].width *= scale_x;
|
|
|
|
outline_to_blur.corner[i].height *= scale_y;
|
2019-11-30 11:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gsk_gl_driver_create_render_target (self->gl_driver,
|
|
|
|
texture_width, texture_height,
|
2020-09-02 22:01:06 +00:00
|
|
|
GL_NEAREST, GL_NEAREST,
|
2019-11-30 11:44:30 +00:00
|
|
|
&texture_id, &render_target);
|
|
|
|
|
2020-10-01 06:39:19 +00:00
|
|
|
init_projection_matrix (&item_proj,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height));
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
prev_projection = ops_set_projection (builder, &item_proj);
|
|
|
|
ops_set_modelview (builder, NULL);
|
|
|
|
prev_viewport = ops_set_viewport (builder, &GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height));
|
|
|
|
ops_push_clip (builder, &GSK_ROUNDED_RECT_INIT (0, 0, texture_width, texture_height));
|
|
|
|
|
|
|
|
prev_render_target = ops_set_render_target (builder, render_target);
|
|
|
|
ops_begin (builder, OP_CLEAR);
|
|
|
|
|
|
|
|
/* Actual inset shadow outline drawing */
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->inset_shadow_program);
|
2020-07-24 06:49:24 +00:00
|
|
|
ops_set_inset_shadow (builder, transform_rect (self, builder, &outline_to_blur),
|
2020-10-10 17:57:29 +00:00
|
|
|
spread * MAX (scale_x, scale_y),
|
2020-11-16 23:59:36 +00:00
|
|
|
gsk_inset_shadow_node_get_color (node),
|
2020-10-10 17:57:29 +00:00
|
|
|
dx * scale_x, dy * scale_y);
|
2019-11-30 11:44:30 +00:00
|
|
|
|
2020-11-01 11:16:44 +00:00
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
0, 0, texture_width, texture_height);
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
ops_set_render_target (builder, prev_render_target);
|
|
|
|
ops_set_viewport (builder, &prev_viewport);
|
|
|
|
ops_set_projection (builder, &prev_projection);
|
|
|
|
ops_pop_modelview (builder);
|
|
|
|
ops_pop_clip (builder);
|
|
|
|
|
|
|
|
blurred_texture_id = blur_texture (self, builder,
|
|
|
|
&(TextureRegion) { texture_id, 0, 0, 1, 1 },
|
|
|
|
texture_width,
|
|
|
|
texture_height,
|
2020-10-10 17:57:29 +00:00
|
|
|
blur_radius * scale_x,
|
|
|
|
blur_radius * scale_y);
|
2019-11-30 11:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (blurred_texture_id != 0);
|
|
|
|
|
|
|
|
/* Blur the rendered unblurred inset shadow */
|
|
|
|
/* Use a clip to cut away the unwanted parts outside of the original outline */
|
|
|
|
{
|
|
|
|
const gboolean needs_clip = !gsk_rounded_rect_is_rectilinear (node_outline);
|
2020-10-10 17:57:29 +00:00
|
|
|
const float tx1 = blur_extra / 2.0 * scale_x / texture_width;
|
2019-12-22 14:53:46 +00:00
|
|
|
const float tx2 = 1.0 - tx1;
|
2020-10-10 17:57:29 +00:00
|
|
|
const float ty1 = blur_extra / 2.0 * scale_y / texture_height;
|
2019-12-22 14:53:46 +00:00
|
|
|
const float ty2 = 1.0 - ty1;
|
2019-11-30 11:44:30 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
gsk_gl_driver_set_texture_for_key (self->gl_driver, &key, blurred_texture_id);
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
if (needs_clip)
|
|
|
|
{
|
2020-12-05 17:19:16 +00:00
|
|
|
GskRoundedRect node_clip;
|
|
|
|
|
|
|
|
ops_transform_bounds_modelview (builder, &node_outline->bounds, &node_clip.bounds);
|
|
|
|
for (int i = 0; i < 4; i ++)
|
|
|
|
{
|
|
|
|
node_clip.corner[i].width = node_outline->corner[i].width * scale_x;
|
|
|
|
node_clip.corner[i].height = node_outline->corner[i].height * scale_y;
|
|
|
|
}
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
ops_push_clip (builder, &node_clip);
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blit_program);
|
2019-11-30 11:44:30 +00:00
|
|
|
ops_set_texture (builder, blurred_texture_id);
|
|
|
|
|
2019-12-29 15:54:56 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-10-31 10:54:33 +00:00
|
|
|
&node->bounds, builder,
|
2019-12-29 15:54:56 +00:00
|
|
|
&(TextureRegion) { 0, tx1, ty1, tx2, ty2 },
|
|
|
|
TRUE);
|
2019-11-30 11:44:30 +00:00
|
|
|
|
|
|
|
if (needs_clip)
|
|
|
|
ops_pop_clip (builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-31 07:54:27 +00:00
|
|
|
/* Spread *grows* the outline. The offset moves the shadow and leaves the
|
|
|
|
* inner rect where it was */
|
2018-01-15 09:55:40 +00:00
|
|
|
static inline void
|
2019-11-26 07:58:38 +00:00
|
|
|
render_unblurred_outset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2018-01-15 09:55:40 +00:00
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskRoundedRect *outline = gsk_outset_shadow_node_get_outline (node);
|
2020-10-31 07:54:27 +00:00
|
|
|
const float x = node->bounds.origin.x;
|
|
|
|
const float y = node->bounds.origin.y;
|
|
|
|
const float w = node->bounds.size.width;
|
|
|
|
const float h = node->bounds.size.height;
|
2018-01-15 09:55:40 +00:00
|
|
|
const float spread = gsk_outset_shadow_node_get_spread (node);
|
2019-10-11 07:32:24 +00:00
|
|
|
const float dx = gsk_outset_shadow_node_get_dx (node);
|
|
|
|
const float dy = gsk_outset_shadow_node_get_dy (node);
|
2020-10-31 07:54:27 +00:00
|
|
|
const float edge_sizes[] = { // Top, right, bottom, left
|
|
|
|
spread - dy, spread + dx, spread + dy, spread - dx
|
|
|
|
};
|
|
|
|
const float corner_sizes[][2] = { // top left, top right, bottom right, bottom left
|
|
|
|
{ outline->corner[0].width + spread - dx, outline->corner[0].height + spread - dy },
|
|
|
|
{ outline->corner[1].width + spread + dx, outline->corner[1].height + spread - dy },
|
|
|
|
{ outline->corner[2].width + spread + dx, outline->corner[2].height + spread + dy },
|
|
|
|
{ outline->corner[3].width + spread - dx, outline->corner[3].height + spread + dy },
|
|
|
|
};
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->unblurred_outset_shadow_program);
|
2020-07-24 06:49:24 +00:00
|
|
|
ops_set_unblurred_outset_shadow (builder, transform_rect (self, builder, outline),
|
|
|
|
spread,
|
2020-11-16 23:59:36 +00:00
|
|
|
gsk_outset_shadow_node_get_color (node),
|
2020-07-24 06:49:24 +00:00
|
|
|
dx, dy);
|
2018-01-15 09:55:40 +00:00
|
|
|
|
2020-10-31 07:54:27 +00:00
|
|
|
/* Corners... */
|
|
|
|
if (corner_sizes[0][0] > 0 && corner_sizes[0][1] > 0) /* Top left */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x, y,
|
|
|
|
corner_sizes[0][0], corner_sizes[0][1]);
|
|
|
|
if (corner_sizes[1][0] > 0 && corner_sizes[1][1] > 0) /* Top right */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x + w - corner_sizes[1][0], y,
|
|
|
|
corner_sizes[1][0], corner_sizes[1][1]);
|
|
|
|
if (corner_sizes[2][0] > 0 && corner_sizes[2][1] > 0) /* Bottom right */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x + w - corner_sizes[2][0], y + h - corner_sizes[2][1],
|
|
|
|
corner_sizes[2][0], corner_sizes[2][1]);
|
|
|
|
if (corner_sizes[3][0] > 0 && corner_sizes[3][1] > 0) /* Bottom left */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x, y + h - corner_sizes[3][1],
|
|
|
|
corner_sizes[3][0], corner_sizes[3][1]);
|
|
|
|
/* Edges... */;
|
|
|
|
if (edge_sizes[0] > 0) /* Top */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x + corner_sizes[0][0], y,
|
|
|
|
w - corner_sizes[0][0] - corner_sizes[1][0], edge_sizes[0]);
|
|
|
|
if (edge_sizes[1] > 0) /* Right */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x + w - edge_sizes[1], y + corner_sizes[1][1],
|
|
|
|
edge_sizes[1], h - corner_sizes[1][1] - corner_sizes[2][1]);
|
|
|
|
if (edge_sizes[2] > 0) /* Bottom */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x + corner_sizes[3][0], y + h - edge_sizes[2],
|
|
|
|
w - corner_sizes[3][0] - corner_sizes[2][0], edge_sizes[2]);
|
|
|
|
if (edge_sizes[3] > 0) /* Left */
|
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
x, y + corner_sizes[0][1],
|
|
|
|
edge_sizes[3], h - corner_sizes[0][1] - corner_sizes[3][1]);
|
2018-01-15 09:55:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 06:01:48 +00:00
|
|
|
|
2020-01-16 07:02:48 +00:00
|
|
|
static GdkRGBA COLOR_WHITE = { 1, 1, 1, 1 };
|
2017-12-08 12:12:43 +00:00
|
|
|
static inline void
|
2019-11-26 08:38:53 +00:00
|
|
|
render_outset_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
2020-10-10 17:57:29 +00:00
|
|
|
const float scale_x = builder->scale_x;
|
|
|
|
const float scale_y = builder->scale_y;
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskRoundedRect *outline = gsk_outset_shadow_node_get_outline (node);
|
|
|
|
const GdkRGBA *color = gsk_outset_shadow_node_get_color (node);
|
2017-12-21 17:09:32 +00:00
|
|
|
const float blur_radius = gsk_outset_shadow_node_get_blur_radius (node);
|
2020-08-07 04:43:06 +00:00
|
|
|
const float blur_extra = blur_radius * 2.0f; /* 2.0 = shader radius_multiplier */
|
2020-12-04 20:12:34 +00:00
|
|
|
const int extra_blur_pixels = (int) ceilf(blur_extra / 2.0 * MAX (scale_x, scale_y)); /* TODO: No need to MAX() her actually */
|
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);
|
2019-11-26 08:38:53 +00:00
|
|
|
GskRoundedRect scaled_outline;
|
2020-05-20 06:01:48 +00:00
|
|
|
int texture_width, texture_height;
|
2020-07-24 06:49:24 +00:00
|
|
|
OpOutsetShadow *shadow;
|
2018-07-15 15:52:34 +00:00
|
|
|
int blurred_texture_id;
|
2018-07-08 18:08:15 +00:00
|
|
|
int cached_tid;
|
2020-07-12 07:40:00 +00:00
|
|
|
bool do_slicing;
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* scaled_outline is the minimal outline we need to draw the given drop shadow,
|
2017-12-21 17:09:32 +00:00
|
|
|
* enlarged by the spread and offset by the blur radius. */
|
2019-11-26 08:38:53 +00:00
|
|
|
scaled_outline = *outline;
|
2020-07-12 07:40:00 +00:00
|
|
|
|
|
|
|
if (outline->bounds.size.width < blur_extra ||
|
|
|
|
outline->bounds.size.height < blur_extra)
|
|
|
|
{
|
|
|
|
do_slicing = false;
|
|
|
|
gsk_rounded_rect_shrink (&scaled_outline, -spread, -spread, -spread, -spread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Shrink our outline to the minimum size that can still hold all the border radii */
|
|
|
|
gsk_rounded_rect_shrink_to_minimum (&scaled_outline);
|
|
|
|
/* Increase by the spread */
|
|
|
|
gsk_rounded_rect_shrink (&scaled_outline, -spread, -spread, -spread, -spread);
|
|
|
|
/* Grow bounds but don't grow corners */
|
|
|
|
graphene_rect_inset (&scaled_outline.bounds, - blur_extra / 2.0, - blur_extra / 2.0);
|
|
|
|
/* For the center part, we add a few pixels */
|
|
|
|
scaled_outline.bounds.size.width += SHADOW_EXTRA_SIZE;
|
|
|
|
scaled_outline.bounds.size.height += SHADOW_EXTRA_SIZE;
|
|
|
|
|
|
|
|
do_slicing = true;
|
|
|
|
}
|
2019-11-26 08:38:53 +00:00
|
|
|
|
2020-10-10 17:57:29 +00:00
|
|
|
texture_width = (int)ceil ((scaled_outline.bounds.size.width + blur_extra) * scale_x);
|
|
|
|
texture_height = (int)ceil ((scaled_outline.bounds.size.height + blur_extra) * scale_y);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
2020-05-22 17:37:15 +00:00
|
|
|
scaled_outline.bounds.origin.x = extra_blur_pixels;
|
|
|
|
scaled_outline.bounds.origin.y = extra_blur_pixels;
|
|
|
|
scaled_outline.bounds.size.width = texture_width - (extra_blur_pixels * 2);
|
|
|
|
scaled_outline.bounds.size.height = texture_height - (extra_blur_pixels * 2);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i ++)
|
|
|
|
{
|
2020-10-10 17:57:29 +00:00
|
|
|
scaled_outline.corner[i].width *= scale_x;
|
|
|
|
scaled_outline.corner[i].height *= scale_y;
|
2019-11-26 08:38:53 +00:00
|
|
|
}
|
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,
|
2019-11-26 08:38:53 +00:00
|
|
|
&scaled_outline,
|
2018-07-08 18:08:15 +00:00
|
|
|
blur_radius);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
2018-07-08 18:08:15 +00:00
|
|
|
if (cached_tid == 0)
|
|
|
|
{
|
2018-07-15 15:52:34 +00:00
|
|
|
int texture_id, render_target;
|
|
|
|
int prev_render_target;
|
2019-11-26 08:38:53 +00:00
|
|
|
graphene_matrix_t prev_projection;
|
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
graphene_matrix_t item_proj;
|
2018-07-15 15:52:34 +00:00
|
|
|
|
2020-09-02 22:01:06 +00:00
|
|
|
gsk_gl_driver_create_render_target (self->gl_driver,
|
|
|
|
texture_width, texture_height,
|
|
|
|
GL_NEAREST, GL_NEAREST,
|
2019-05-22 05:10:57 +00:00
|
|
|
&texture_id, &render_target);
|
2020-07-24 16:54:23 +00:00
|
|
|
if (gdk_gl_context_has_debug (self->gl_context))
|
|
|
|
{
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, texture_id,
|
|
|
|
"Outset Shadow Temp %d", texture_id);
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_FRAMEBUFFER, render_target,
|
|
|
|
"Outset Shadow FB Temp %d", render_target);
|
|
|
|
}
|
2018-07-08 18:08:15 +00:00
|
|
|
|
2020-05-20 06:01:48 +00:00
|
|
|
ops_set_program (builder, &self->programs->color_program);
|
2020-10-01 06:39:19 +00:00
|
|
|
init_projection_matrix (&item_proj,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height));
|
2018-07-08 18:08:15 +00:00
|
|
|
|
|
|
|
prev_render_target = ops_set_render_target (builder, render_target);
|
2019-10-09 22:41:53 +00:00
|
|
|
ops_begin (builder, OP_CLEAR);
|
2018-07-08 18:08:15 +00:00
|
|
|
prev_projection = ops_set_projection (builder, &item_proj);
|
2019-11-26 08:38:53 +00:00
|
|
|
ops_set_modelview (builder, NULL);
|
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 */
|
2019-11-26 08:38:53 +00:00
|
|
|
ops_push_clip (builder, &scaled_outline);
|
2020-01-16 07:02:48 +00:00
|
|
|
ops_set_color (builder, &COLOR_WHITE);
|
2020-11-01 10:25:00 +00:00
|
|
|
load_float_vertex_data (ops_draw (builder, NULL), builder,
|
|
|
|
0, 0, texture_width, texture_height);
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2018-12-30 14:25:01 +00:00
|
|
|
ops_pop_clip (builder);
|
2018-07-08 18:08:15 +00:00
|
|
|
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);
|
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Now blur the outline */
|
|
|
|
blurred_texture_id = blur_texture (self, builder,
|
2019-11-29 05:53:57 +00:00
|
|
|
&(TextureRegion) { texture_id, 0, 0, 1, 1 },
|
2019-11-26 08:38:53 +00:00
|
|
|
texture_width,
|
|
|
|
texture_height,
|
2020-10-10 17:57:29 +00:00
|
|
|
blur_radius * scale_x,
|
|
|
|
blur_radius * scale_y);
|
2019-11-26 08:38:53 +00:00
|
|
|
|
2019-05-22 05:10:57 +00:00
|
|
|
gsk_gl_driver_mark_texture_permanent (self->gl_driver, blurred_texture_id);
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_gl_shadow_cache_commit (&self->shadow_cache,
|
2019-11-26 08:38:53 +00:00
|
|
|
&scaled_outline,
|
2018-07-08 18:08:15 +00:00
|
|
|
blur_radius,
|
|
|
|
blurred_texture_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
blurred_texture_id = cached_tid;
|
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-07-12 07:40:00 +00:00
|
|
|
|
|
|
|
if (!do_slicing)
|
|
|
|
{
|
2020-11-01 10:25:00 +00:00
|
|
|
const float min_x = floorf (outline->bounds.origin.x - spread - (blur_extra / 2.0) + dx);
|
|
|
|
const float min_y = floorf (outline->bounds.origin.y - spread - (blur_extra / 2.0) + dy);
|
2020-07-12 07:40:00 +00:00
|
|
|
|
|
|
|
ops_set_program (builder, &self->programs->outset_shadow_program);
|
|
|
|
ops_set_color (builder, color);
|
|
|
|
ops_set_texture (builder, blurred_texture_id);
|
|
|
|
|
|
|
|
shadow = ops_begin (builder, OP_CHANGE_OUTSET_SHADOW);
|
2020-07-24 06:49:24 +00:00
|
|
|
shadow->outline.value = transform_rect (self, builder, outline);
|
|
|
|
shadow->outline.send = TRUE;
|
2020-07-12 07:40:00 +00:00
|
|
|
|
2020-11-01 10:25:00 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x, min_y,
|
|
|
|
texture_width / scale_x, texture_height / scale_y
|
|
|
|
), builder,
|
|
|
|
&(TextureRegion) { 0, 0, 0, 1, 1 },
|
|
|
|
FALSE);
|
2020-07-12 07:40:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->outset_shadow_program);
|
2020-01-16 07:02:48 +00:00
|
|
|
ops_set_color (builder, color);
|
2017-12-21 17:09:32 +00:00
|
|
|
ops_set_texture (builder, blurred_texture_id);
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
shadow = ops_begin (builder, OP_CHANGE_OUTSET_SHADOW);
|
2020-07-24 06:49:24 +00:00
|
|
|
shadow->outline.value = transform_rect (self, builder, outline);
|
|
|
|
shadow->outline.send = TRUE;
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float min_x = floorf (outline->bounds.origin.x - spread - (blur_extra / 2.0) + dx);
|
|
|
|
const float min_y = floorf (outline->bounds.origin.y - spread - (blur_extra / 2.0) + dy);
|
|
|
|
const float max_x = ceilf (outline->bounds.origin.x + outline->bounds.size.width +
|
2020-05-22 17:37:15 +00:00
|
|
|
(blur_extra / 2.0) + dx + spread);
|
2020-10-31 10:54:33 +00:00
|
|
|
const float max_y = ceilf (outline->bounds.origin.y + outline->bounds.size.height +
|
2020-05-22 17:37:15 +00:00
|
|
|
(blur_extra / 2.0) + dy + spread);
|
2020-05-20 06:01:48 +00:00
|
|
|
cairo_rectangle_int_t slices[9];
|
|
|
|
TextureRegion tregs[9];
|
|
|
|
|
|
|
|
/* TODO: The slicing never changes and could just go into the cache */
|
|
|
|
nine_slice_rounded_rect (&scaled_outline, slices);
|
2020-05-22 17:37:15 +00:00
|
|
|
nine_slice_grow (slices, extra_blur_pixels);
|
2020-05-20 06:01:48 +00:00
|
|
|
nine_slice_to_texture_coords (slices, texture_width, texture_height, tregs);
|
2017-12-28 15:41:32 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Our texture coordinates MUST be scaled, while the actual vertex coords
|
|
|
|
* MUST NOT be scaled. */
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Top left */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_TOP_LEFT]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x, min_y,
|
|
|
|
slices[NINE_SLICE_TOP_LEFT].width / scale_x,
|
|
|
|
slices[NINE_SLICE_TOP_LEFT].height / scale_y
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_TOP_LEFT], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2020-05-20 06:01:48 +00:00
|
|
|
/* Top center */
|
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_TOP_CENTER]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float width = (max_x - min_x) - (slices[NINE_SLICE_TOP_LEFT].width / scale_x +
|
|
|
|
slices[NINE_SLICE_TOP_RIGHT].width / scale_x);
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x + (slices[NINE_SLICE_TOP_LEFT].width / scale_x),
|
|
|
|
min_y,
|
|
|
|
width,
|
|
|
|
slices[NINE_SLICE_TOP_CENTER].height / scale_y
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_TOP_CENTER], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Top right */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_TOP_RIGHT]))
|
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
max_x - (slices[NINE_SLICE_TOP_RIGHT].width / scale_x),
|
|
|
|
min_y,
|
|
|
|
slices[NINE_SLICE_TOP_RIGHT].width / scale_x,
|
|
|
|
slices[NINE_SLICE_TOP_RIGHT].height / scale_y
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_TOP_RIGHT], TRUE);
|
2019-11-26 08:38:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
/* Bottom right */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_BOTTOM_RIGHT]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
max_x - (slices[NINE_SLICE_BOTTOM_RIGHT].width / scale_x),
|
|
|
|
max_y - (slices[NINE_SLICE_BOTTOM_RIGHT].height / scale_y),
|
|
|
|
slices[NINE_SLICE_BOTTOM_RIGHT].width / scale_x,
|
|
|
|
slices[NINE_SLICE_BOTTOM_RIGHT].height / scale_y
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_BOTTOM_RIGHT], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Bottom left */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_BOTTOM_LEFT]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x,
|
|
|
|
max_y - (slices[NINE_SLICE_BOTTOM_LEFT].height / scale_y),
|
|
|
|
slices[NINE_SLICE_BOTTOM_LEFT].width / scale_x,
|
|
|
|
slices[NINE_SLICE_BOTTOM_LEFT].height / scale_y
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_BOTTOM_LEFT], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Left side */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_LEFT_CENTER]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float height = (max_y - min_y) - (slices[NINE_SLICE_TOP_LEFT].height / scale_y +
|
|
|
|
slices[NINE_SLICE_BOTTOM_LEFT].height / scale_y);
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x,
|
|
|
|
min_y + (slices[NINE_SLICE_TOP_LEFT].height / scale_y),
|
|
|
|
slices[NINE_SLICE_LEFT_CENTER].width / scale_x,
|
|
|
|
height
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_LEFT_CENTER], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
|
|
|
/* Right side */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_RIGHT_CENTER]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float height = (max_y - min_y) - (slices[NINE_SLICE_TOP_RIGHT].height / scale_y +
|
|
|
|
slices[NINE_SLICE_BOTTOM_RIGHT].height / scale_y);
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
max_x - (slices[NINE_SLICE_RIGHT_CENTER].width / scale_x),
|
|
|
|
min_y + (slices[NINE_SLICE_TOP_LEFT].height / scale_y),
|
|
|
|
slices[NINE_SLICE_RIGHT_CENTER].width / scale_x,
|
|
|
|
height
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_RIGHT_CENTER], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Bottom side */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_BOTTOM_CENTER]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float width = (max_x - min_x) - (slices[NINE_SLICE_BOTTOM_LEFT].width / scale_x +
|
|
|
|
slices[NINE_SLICE_BOTTOM_RIGHT].width / scale_x);
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x + (slices[NINE_SLICE_BOTTOM_LEFT].width / scale_x),
|
|
|
|
max_y - (slices[NINE_SLICE_BOTTOM_CENTER].height / scale_y),
|
|
|
|
width,
|
|
|
|
slices[NINE_SLICE_BOTTOM_CENTER].height / scale_y
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_BOTTOM_CENTER], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
/* Middle */
|
2020-05-20 06:01:48 +00:00
|
|
|
if (slice_is_visible (&slices[NINE_SLICE_CENTER]))
|
2017-12-28 17:00:59 +00:00
|
|
|
{
|
2020-10-31 10:54:33 +00:00
|
|
|
const float width = (max_x - min_x) - (slices[NINE_SLICE_LEFT_CENTER].width / scale_x +
|
|
|
|
slices[NINE_SLICE_RIGHT_CENTER].width / scale_x);
|
|
|
|
const float height = (max_y - min_y) - (slices[NINE_SLICE_TOP_CENTER].height / scale_y +
|
|
|
|
slices[NINE_SLICE_BOTTOM_CENTER].height / scale_y);
|
|
|
|
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
min_x + (slices[NINE_SLICE_LEFT_CENTER].width / scale_x),
|
|
|
|
min_y + (slices[NINE_SLICE_TOP_CENTER].height / scale_y),
|
|
|
|
width, height
|
|
|
|
),
|
|
|
|
builder,
|
|
|
|
&tregs[NINE_SLICE_CENTER], TRUE);
|
2017-12-28 17:00:59 +00:00
|
|
|
}
|
2017-12-21 17:09:32 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-11-29 05:54:43 +00:00
|
|
|
render_shadow_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
const gsize n_shadows = gsk_shadow_node_get_n_shadows (node);
|
2017-12-08 12:12:43 +00:00
|
|
|
GskRenderNode *original_child = gsk_shadow_node_get_child (node);
|
|
|
|
GskRenderNode *shadow_child = original_child;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* 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 ++)
|
|
|
|
{
|
2020-11-16 23:59:36 +00:00
|
|
|
const GskShadow *shadow = gsk_shadow_node_get_shadow (node, i);
|
2017-12-09 17:26:29 +00:00
|
|
|
const float dx = shadow->dx;
|
|
|
|
const float dy = shadow->dy;
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion region;
|
|
|
|
gboolean is_offscreen;
|
2020-10-31 16:12:38 +00:00
|
|
|
graphene_rect_t bounds;
|
2017-12-09 13:32:24 +00:00
|
|
|
|
2019-11-29 05:54:43 +00:00
|
|
|
if (shadow->radius == 0 &&
|
|
|
|
gsk_render_node_get_node_type (shadow_child) == GSK_TEXT_NODE)
|
2017-12-08 12:12:43 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-18 07:11:59 +00:00
|
|
|
if (gdk_rgba_is_clear (&shadow->color))
|
|
|
|
continue;
|
|
|
|
|
2019-11-23 09:20:15 +00:00
|
|
|
if (node_is_invisible (shadow_child))
|
|
|
|
continue;
|
|
|
|
|
2019-11-29 05:54:43 +00:00
|
|
|
if (shadow->radius > 0)
|
|
|
|
{
|
2020-12-19 16:43:43 +00:00
|
|
|
float min_x;
|
|
|
|
float min_y;
|
|
|
|
float max_x;
|
|
|
|
float max_y;
|
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
region.texture_id = 0;
|
|
|
|
blur_node (self, shadow_child, builder, shadow->radius, NO_CACHE_PLZ, ®ion,
|
2020-12-19 16:43:43 +00:00
|
|
|
(float*[4]){&min_x, &max_x, &min_y, &max_y});
|
|
|
|
bounds.origin.x = min_x - builder->dx;
|
|
|
|
bounds.origin.y = min_y - builder->dy;
|
|
|
|
bounds.size.width = max_x - min_x;
|
|
|
|
bounds.size.height = max_y - min_y;
|
2020-12-19 16:43:56 +00:00
|
|
|
is_offscreen = TRUE;
|
2019-11-29 05:54:43 +00:00
|
|
|
}
|
|
|
|
else if (dx == 0 && dy == 0)
|
|
|
|
{
|
|
|
|
continue; /* Invisible anyway */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&shadow_child->bounds,
|
|
|
|
shadow_child, ®ion, &is_offscreen,
|
|
|
|
RESET_CLIP | NO_CACHE_PLZ))
|
2019-11-29 05:54:43 +00:00
|
|
|
g_assert_not_reached ();
|
|
|
|
|
2020-10-31 16:12:38 +00:00
|
|
|
bounds = shadow_child->bounds;
|
2019-11-29 05:54:43 +00:00
|
|
|
}
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->coloring_program);
|
2017-12-08 12:12:43 +00:00
|
|
|
ops_set_color (builder, &shadow->color);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2017-12-08 12:12:43 +00:00
|
|
|
|
2020-10-31 16:12:38 +00:00
|
|
|
ops_offset (builder, dx, dy);
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
|
|
|
&bounds, builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
®ion,
|
|
|
|
is_offscreen);
|
2020-10-31 16:12:38 +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
|
2019-10-15 03:28:15 +00:00
|
|
|
render_cross_fade_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
2019-11-26 07:58:38 +00:00
|
|
|
RenderOpBuilder *builder)
|
2017-12-11 07:22:28 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *start_node = gsk_cross_fade_node_get_start_child (node);
|
|
|
|
GskRenderNode *end_node = gsk_cross_fade_node_get_end_child (node);
|
2020-06-21 05:17:54 +00:00
|
|
|
const float progress = gsk_cross_fade_node_get_progress (node);
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion start_region;
|
|
|
|
TextureRegion end_region;
|
|
|
|
gboolean is_offscreen1, is_offscreen2;
|
2019-10-11 14:23:33 +00:00
|
|
|
OpCrossFade *op;
|
2017-12-11 07:22:28 +00:00
|
|
|
|
2020-06-21 05:17:54 +00:00
|
|
|
if (progress <= 0)
|
|
|
|
{
|
|
|
|
gsk_gl_renderer_add_render_ops (self, start_node, builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (progress >= 1)
|
|
|
|
{
|
2020-12-05 12:13:15 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, end_node, builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (equal_texture_nodes (start_node, end_node))
|
|
|
|
{
|
2020-06-21 05:17:54 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, end_node, builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-11 07:22:28 +00:00
|
|
|
/* 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. */
|
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
start_node,
|
|
|
|
&start_region, &is_offscreen1,
|
|
|
|
FORCE_OFFSCREEN | RESET_CLIP))
|
2020-01-22 07:38:55 +00:00
|
|
|
{
|
|
|
|
gsk_gl_renderer_add_render_ops (self, end_node, builder);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-11 07:22:28 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
end_node,
|
|
|
|
&end_region, &is_offscreen2,
|
|
|
|
FORCE_OFFSCREEN | RESET_CLIP))
|
2020-01-22 07:38:55 +00:00
|
|
|
{
|
2020-06-21 05:45:50 +00:00
|
|
|
const float prev_opacity = ops_set_opacity (builder, builder->current_opacity * progress);
|
|
|
|
gsk_gl_renderer_add_render_ops (self, start_node, builder);
|
|
|
|
ops_set_opacity (builder, prev_opacity);
|
|
|
|
|
2020-01-22 07:38:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-11 07:22:28 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->cross_fade_program);
|
2019-10-09 22:41:53 +00:00
|
|
|
|
|
|
|
op = ops_begin (builder, OP_CHANGE_CROSS_FADE);
|
2019-10-11 14:23:33 +00:00
|
|
|
op->progress = progress;
|
2020-12-19 16:43:56 +00:00
|
|
|
op->source2 = end_region.texture_id;
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, start_region.texture_id);
|
2017-12-11 07:22:28 +00:00
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), node, builder);
|
2017-12-11 07:22:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-28 05:46:17 +00:00
|
|
|
static inline void
|
|
|
|
render_blend_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
2019-11-26 07:58:38 +00:00
|
|
|
RenderOpBuilder *builder)
|
2019-04-28 05:46:17 +00:00
|
|
|
{
|
|
|
|
GskRenderNode *top_child = gsk_blend_node_get_top_child (node);
|
|
|
|
GskRenderNode *bottom_child = gsk_blend_node_get_bottom_child (node);
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion top_region;
|
|
|
|
TextureRegion bottom_region;
|
|
|
|
gboolean is_offscreen1, is_offscreen2;
|
2019-10-11 14:23:33 +00:00
|
|
|
OpBlend *op;
|
2019-04-28 05:46:17 +00:00
|
|
|
|
|
|
|
/* TODO: We create 2 textures here as big as the blend node, but both the
|
|
|
|
* start and the end node might be a lot smaller than that. */
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
bottom_child,
|
|
|
|
&bottom_region, &is_offscreen1,
|
|
|
|
FORCE_OFFSCREEN | RESET_CLIP))
|
2020-01-07 16:15:02 +00:00
|
|
|
{
|
|
|
|
gsk_gl_renderer_add_render_ops (self, top_child, builder);
|
|
|
|
return;
|
|
|
|
}
|
2019-11-27 15:56:47 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&node->bounds,
|
|
|
|
top_child,
|
|
|
|
&top_region, &is_offscreen2,
|
|
|
|
FORCE_OFFSCREEN | RESET_CLIP))
|
2020-01-07 16:15:02 +00:00
|
|
|
{
|
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-10-31 10:54:33 +00:00
|
|
|
&node->bounds,
|
2020-01-07 16:15:02 +00:00
|
|
|
builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
&bottom_region,
|
2020-01-07 16:15:02 +00:00
|
|
|
TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-28 05:46:17 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->blend_program);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, bottom_region.texture_id);
|
2019-10-09 22:41:53 +00:00
|
|
|
|
|
|
|
op = ops_begin (builder, OP_CHANGE_BLEND);
|
2020-12-19 16:43:56 +00:00
|
|
|
op->source2 = top_region.texture_id;
|
2019-10-11 14:23:33 +00:00
|
|
|
op->mode = gsk_blend_node_get_blend_mode (node);
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
load_offscreen_vertex_data (ops_draw (builder, NULL), node, builder);
|
2019-04-28 05:46:17 +00:00
|
|
|
}
|
|
|
|
|
2019-08-10 12:45:45 +00:00
|
|
|
static inline void
|
|
|
|
render_repeat_node (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
GskRenderNode *child = gsk_repeat_node_get_child (node);
|
2020-11-16 23:59:36 +00:00
|
|
|
const graphene_rect_t *child_bounds = gsk_repeat_node_get_child_bounds (node);
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion region;
|
|
|
|
gboolean is_offscreen;
|
2019-10-11 14:23:33 +00:00
|
|
|
OpRepeat *op;
|
2019-08-10 12:45:45 +00:00
|
|
|
|
2019-11-23 09:20:15 +00:00
|
|
|
if (node_is_invisible (child))
|
|
|
|
return;
|
|
|
|
|
2020-07-24 18:01:37 +00:00
|
|
|
if (!graphene_rect_equal (child_bounds, &child->bounds))
|
2019-08-10 12:45:45 +00:00
|
|
|
{
|
|
|
|
/* TODO: Implement these repeat nodes. */
|
|
|
|
render_fallback_node (self, node, builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-19 09:45:02 +00:00
|
|
|
/* If the size of the repeat node is smaller than the size of the
|
|
|
|
* child node, we don't repeat at all and can just draw that part
|
|
|
|
* of the child texture... */
|
|
|
|
if (graphene_rect_contains_rect (child_bounds, &node->bounds))
|
|
|
|
{
|
|
|
|
render_clipped_child (self, builder, &node->bounds, child);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 12:45:45 +00:00
|
|
|
/* Draw the entire child on a texture */
|
2020-12-19 16:43:56 +00:00
|
|
|
if (!add_offscreen_ops (self, builder,
|
|
|
|
&child->bounds,
|
|
|
|
child,
|
|
|
|
®ion, &is_offscreen,
|
|
|
|
RESET_CLIP))
|
2019-11-27 15:56:47 +00:00
|
|
|
g_assert_not_reached ();
|
2019-08-10 12:45:45 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
ops_set_program (builder, &self->programs->repeat_program);
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_set_texture (builder, region.texture_id);
|
2019-08-10 12:45:45 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_REPEAT);
|
2019-11-19 09:31:21 +00:00
|
|
|
op->child_bounds[0] = (node->bounds.origin.x - child_bounds->origin.x) / child_bounds->size.width;
|
|
|
|
op->child_bounds[1] = (node->bounds.origin.y - child_bounds->origin.y) / child_bounds->size.height;
|
2019-10-11 14:23:33 +00:00
|
|
|
op->child_bounds[2] = node->bounds.size.width / child_bounds->size.width;
|
|
|
|
op->child_bounds[3] = node->bounds.size.height / child_bounds->size.height;
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
op->texture_rect[0] = region.x;
|
|
|
|
op->texture_rect[2] = region.x2;
|
2019-08-10 12:45:45 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if (is_offscreen)
|
2019-08-10 12:45:45 +00:00
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
op->texture_rect[1] = region.y2;
|
|
|
|
op->texture_rect[3] = region.y;
|
2019-08-10 12:45:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
op->texture_rect[1] = region.y;
|
|
|
|
op->texture_rect[3] = region.y2;
|
2019-08-10 12:45:45 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 15:54:56 +00:00
|
|
|
load_vertex_data_with_region (ops_draw (builder, NULL),
|
2020-10-31 10:54:33 +00:00
|
|
|
&node->bounds, builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
®ion,
|
|
|
|
is_offscreen);
|
2019-08-10 12:45:45 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_viewport_op (const Program *program,
|
|
|
|
const OpViewport *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OP_PRINT (" -> New Viewport: %f, %f, %f, %f",
|
|
|
|
op->viewport.origin.x, op->viewport.origin.y,
|
|
|
|
op->viewport.size.width, op->viewport.size.height);
|
2017-12-16 09:02:03 +00:00
|
|
|
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,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpMatrix *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
float mat[16];
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
graphene_matrix_to_float (&op->matrix, mat);
|
2020-11-19 01:02:27 +00:00
|
|
|
OP_PRINT (" -> Modelview { { %f,%f,%f,%f }, { %f,%f,%f,%f }, { %f,%f,%f,%f }, { %f,%f,%f,%f }",
|
|
|
|
mat[0], mat[1], mat[2], mat[3],
|
|
|
|
mat[4], mat[5], mat[6], mat[7],
|
|
|
|
mat[8], mat[9], mat[10], mat[11],
|
|
|
|
mat[12], mat[13], mat[14], mat[15]);
|
2017-12-16 09:02:03 +00:00
|
|
|
glUniformMatrix4fv (program->modelview_location, 1, GL_FALSE, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_projection_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpMatrix *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
float mat[16];
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
graphene_matrix_to_float (&op->matrix, mat);
|
2020-11-19 01:02:27 +00:00
|
|
|
OP_PRINT (" -> Projection { { %f,%f,%f,%f }, { %f,%f,%f,%f }, { %f,%f,%f,%f }, { %f,%f,%f,%f }",
|
|
|
|
mat[0], mat[1], mat[2], mat[3],
|
|
|
|
mat[4], mat[5], mat[6], mat[7],
|
|
|
|
mat[8], mat[9], mat[10], mat[11],
|
|
|
|
mat[12], mat[13], mat[14], mat[15]);
|
2017-12-16 09:02:03 +00:00
|
|
|
glUniformMatrix4fv (program->projection_location, 1, GL_FALSE, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_program_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpProgram *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> Program: %d", op->program->index);
|
|
|
|
glUseProgram (op->program->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_render_target_op (GskGLRenderer *self,
|
|
|
|
const OpRenderTarget *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
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
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_color_op (const Program *program,
|
|
|
|
const OpColor *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2019-10-11 13:06:51 +00:00
|
|
|
OP_PRINT (" -> Color: (%f, %f, %f, %f)",
|
2019-12-14 13:33:17 +00:00
|
|
|
op->rgba->red, op->rgba->green, op->rgba->blue, op->rgba->alpha);
|
2019-12-10 14:08:47 +00:00
|
|
|
glUniform4fv (program->color.color_location, 1, (float *)op->rgba);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_opacity_op (const Program *program,
|
|
|
|
const OpOpacity *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> Opacity %f", op->opacity);
|
|
|
|
glUniform1f (program->alpha_location, op->opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_source_texture_op (const Program *program,
|
|
|
|
const OpTexture *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static inline void
|
|
|
|
apply_source_extra_texture_op (const Program *program,
|
|
|
|
const OpExtraTexture *op)
|
|
|
|
{
|
|
|
|
g_assert(op->texture_id != 0);
|
|
|
|
OP_PRINT (" -> New extra texture %d: %d", op->idx, op->texture_id);
|
|
|
|
glUniform1i (program->glshader.texture_locations[op->idx], op->idx);
|
|
|
|
glActiveTexture (GL_TEXTURE0 + op->idx);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, op->texture_id);
|
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_color_matrix_op (const Program *program,
|
|
|
|
const OpColorMatrix *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
float mat[16];
|
|
|
|
OP_PRINT (" -> Color Matrix");
|
2019-12-16 05:32:36 +00:00
|
|
|
graphene_matrix_to_float (op->matrix, mat);
|
2017-12-16 09:02:03 +00:00
|
|
|
glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
|
|
|
|
|
2020-07-24 15:29:22 +00:00
|
|
|
if (op->offset.send)
|
|
|
|
{
|
|
|
|
float vec[4];
|
|
|
|
graphene_vec4_to_float (op->offset.value, vec);
|
|
|
|
glUniform4fv (program->color_matrix.color_offset_location, 1, vec);
|
|
|
|
}
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_clip_op (const Program *program,
|
|
|
|
const OpClip *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2019-12-16 05:16:26 +00:00
|
|
|
int count;
|
2019-12-14 14:41:32 +00:00
|
|
|
|
|
|
|
if (op->send_corners)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Clip: %s", gsk_rounded_rect_to_string (&op->clip));
|
2019-12-16 05:16:26 +00:00
|
|
|
count = 3;
|
2019-12-14 14:41:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> clip: %f, %f, %f, %f",
|
|
|
|
op->clip.bounds.origin.x, op->clip.bounds.origin.y,
|
|
|
|
op->clip.bounds.size.width, op->clip.bounds.size.height);
|
2019-12-16 05:16:26 +00:00
|
|
|
count = 1;
|
2019-12-14 14:41:32 +00:00
|
|
|
}
|
2019-12-16 05:16:26 +00:00
|
|
|
|
|
|
|
glUniform4fv (program->clip_rect_location, count, (float *)&op->clip.bounds);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_inset_shadow_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpShadow *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2019-12-14 13:33:17 +00:00
|
|
|
OP_PRINT (" -> inset shadow. Color: %s, Offset: (%f, %f), Spread: %f, Outline: %s",
|
2020-07-24 06:49:24 +00:00
|
|
|
op->color.send ? gdk_rgba_to_string (op->color.value) : "don't send",
|
|
|
|
op->offset.send ? op->offset.value[0] : -1337.0,
|
|
|
|
op->offset.send ? op->offset.value[1] : -1337.0,
|
|
|
|
op->spread.send ? op->spread.value : -1337.0,
|
|
|
|
op->outline.send ? gsk_rounded_rect_to_string (&op->outline.value) : "don't send");
|
|
|
|
if (op->outline.send)
|
|
|
|
{
|
|
|
|
if (op->outline.send_corners)
|
|
|
|
glUniform4fv (program->inset_shadow.outline_rect_location, 3, (float *)&op->outline.value);
|
|
|
|
else
|
|
|
|
glUniform4fv (program->inset_shadow.outline_rect_location, 1, (float *)&op->outline.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op->color.send)
|
|
|
|
glUniform4fv (program->inset_shadow.color_location, 1, (float *)op->color.value);
|
|
|
|
|
|
|
|
if (op->spread.send)
|
|
|
|
glUniform1f (program->inset_shadow.spread_location, op->spread.value);
|
|
|
|
|
|
|
|
if (op->offset.send)
|
|
|
|
glUniform2fv (program->inset_shadow.offset_location, 1, op->offset.value);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
2018-01-15 09:55:40 +00:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
apply_unblurred_outset_shadow_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpShadow *op)
|
2018-01-15 09:55:40 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> unblurred outset shadow");
|
2020-07-24 06:49:24 +00:00
|
|
|
|
|
|
|
if (op->outline.send)
|
|
|
|
{
|
|
|
|
if (op->outline.send_corners)
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.outline_rect_location, 3, (float *)&op->outline.value);
|
|
|
|
else
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.outline_rect_location, 1, (float *)&op->outline.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op->color.send)
|
|
|
|
glUniform4fv (program->unblurred_outset_shadow.color_location, 1, (float *)op->color.value);
|
|
|
|
|
|
|
|
if (op->spread.send)
|
|
|
|
glUniform1f (program->unblurred_outset_shadow.spread_location, op->spread.value);
|
|
|
|
|
|
|
|
if (op->offset.send)
|
|
|
|
glUniform2fv (program->unblurred_outset_shadow.offset_location, 1, op->offset.value);
|
2018-01-15 09:55:40 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
2020-07-24 06:49:24 +00:00
|
|
|
apply_outset_shadow_op (const Program *program,
|
|
|
|
const OpOutsetShadow *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> outset shadow");
|
2020-07-24 06:49:24 +00:00
|
|
|
glUniform4fv (program->outset_shadow.outline_rect_location, 3, (float *)&op->outline.value.bounds);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_linear_gradient_op (const Program *program,
|
|
|
|
const OpLinearGradient *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> Linear gradient");
|
2020-07-24 18:45:22 +00:00
|
|
|
if (op->n_color_stops.send)
|
|
|
|
glUniform1i (program->linear_gradient.num_color_stops_location, op->n_color_stops.value);
|
|
|
|
|
|
|
|
if (op->color_stops.send)
|
|
|
|
glUniform1fv (program->linear_gradient.color_stops_location,
|
|
|
|
op->n_color_stops.value * 5,
|
|
|
|
(float *)op->color_stops.value);
|
|
|
|
|
|
|
|
glUniform2f (program->linear_gradient.start_point_location, op->start_point[0], op->start_point[1]);
|
|
|
|
glUniform2f (program->linear_gradient.end_point_location, op->end_point[0], op->end_point[1]);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 12:42:36 +00:00
|
|
|
static inline void
|
|
|
|
apply_radial_gradient_op (const Program *program,
|
|
|
|
const OpRadialGradient *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Radial gradient");
|
|
|
|
if (op->n_color_stops.send)
|
|
|
|
glUniform1i (program->radial_gradient.num_color_stops_location, op->n_color_stops.value);
|
|
|
|
|
|
|
|
if (op->color_stops.send)
|
|
|
|
glUniform1fv (program->radial_gradient.color_stops_location,
|
|
|
|
op->n_color_stops.value * 5,
|
|
|
|
(float *)op->color_stops.value);
|
|
|
|
|
|
|
|
glUniform1f (program->radial_gradient.start_location, op->start);
|
|
|
|
glUniform1f (program->radial_gradient.end_location, op->end);
|
|
|
|
glUniform2f (program->radial_gradient.radius_location, op->radius[0], op->radius[1]);
|
|
|
|
glUniform2f (program->radial_gradient.center_location, op->center[0], op->center[1]);
|
|
|
|
}
|
|
|
|
|
2020-12-03 05:02:18 +00:00
|
|
|
static inline void
|
|
|
|
apply_conic_gradient_op (const Program *program,
|
|
|
|
const OpConicGradient *op)
|
|
|
|
{
|
|
|
|
OP_PRINT (" -> Conic gradient");
|
|
|
|
if (op->n_color_stops.send)
|
|
|
|
glUniform1i (program->conic_gradient.num_color_stops_location, op->n_color_stops.value);
|
|
|
|
|
|
|
|
if (op->color_stops.send)
|
|
|
|
glUniform1fv (program->conic_gradient.color_stops_location,
|
|
|
|
op->n_color_stops.value * 5,
|
|
|
|
(float *)op->color_stops.value);
|
|
|
|
|
|
|
|
glUniform1f (program->conic_gradient.rotation_location, op->rotation);
|
|
|
|
glUniform2f (program->conic_gradient.center_location, op->center[0], op->center[1]);
|
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
|
|
|
apply_border_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpBorder *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2018-12-05 09:44:11 +00:00
|
|
|
OP_PRINT (" -> Border Outline");
|
2018-03-15 16:27:19 +00:00
|
|
|
|
2019-12-16 05:16:26 +00:00
|
|
|
glUniform4fv (program->border.outline_rect_location, 3, (float *)&op->outline.bounds);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static inline void
|
|
|
|
apply_gl_shader_args_op (const Program *program,
|
|
|
|
const OpGLShader *op)
|
|
|
|
{
|
|
|
|
int n_uniforms, i;
|
|
|
|
const GskGLUniform *uniforms;
|
|
|
|
|
|
|
|
OP_PRINT (" -> GL Shader Args");
|
|
|
|
|
|
|
|
glUniform2fv (program->glshader.size_location, 1, op->size);
|
|
|
|
|
|
|
|
uniforms = gsk_gl_shader_get_uniforms (op->shader, &n_uniforms);
|
|
|
|
for (i = 0; i < n_uniforms; i++)
|
|
|
|
{
|
|
|
|
const GskGLUniform *u = &uniforms[i];
|
|
|
|
const guchar *data = op->uniform_data + u->offset;
|
|
|
|
|
|
|
|
switch (u->type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case GSK_GL_UNIFORM_TYPE_NONE:
|
|
|
|
break;
|
|
|
|
case GSK_GL_UNIFORM_TYPE_FLOAT:
|
|
|
|
glUniform1fv (program->glshader.args_locations[i], 1, (const float *)data);
|
|
|
|
break;
|
|
|
|
case GSK_GL_UNIFORM_TYPE_INT:
|
|
|
|
glUniform1iv (program->glshader.args_locations[i], 1, (const gint32 *)data);
|
|
|
|
break;
|
|
|
|
case GSK_GL_UNIFORM_TYPE_UINT:
|
|
|
|
case GSK_GL_UNIFORM_TYPE_BOOL:
|
|
|
|
glUniform1uiv (program->glshader.args_locations[i], 1, (const guint32 *) data);
|
|
|
|
break;
|
|
|
|
case GSK_GL_UNIFORM_TYPE_VEC2:
|
|
|
|
glUniform2fv (program->glshader.args_locations[i], 1, (const float *)data);
|
|
|
|
break;
|
|
|
|
case GSK_GL_UNIFORM_TYPE_VEC3:
|
|
|
|
glUniform3fv (program->glshader.args_locations[i], 1, (const float *)data);
|
|
|
|
break;
|
|
|
|
case GSK_GL_UNIFORM_TYPE_VEC4:
|
|
|
|
glUniform4fv (program->glshader.args_locations[i], 1, (const float *)data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 09:44:11 +00:00
|
|
|
static inline void
|
|
|
|
apply_border_width_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpBorder *op)
|
2018-12-05 09:44:11 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> Border width (%f, %f, %f, %f)",
|
2019-10-11 14:23:33 +00:00
|
|
|
op->widths[0], op->widths[1], op->widths[2], op->widths[3]);
|
2018-12-05 09:44:11 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
glUniform4fv (program->border.widths_location, 1, op->widths);
|
2018-12-05 09:44:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 09:02:03 +00:00
|
|
|
static inline void
|
|
|
|
apply_border_color_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpBorder *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2019-12-14 13:33:17 +00:00
|
|
|
OP_PRINT (" -> Border color: %s", gdk_rgba_to_string (op->color));
|
2019-12-10 14:08:47 +00:00
|
|
|
glUniform4fv (program->border.color_location, 1, (float *)op->color);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_blur_op (const Program *program,
|
|
|
|
const OpBlur *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
|
|
|
OP_PRINT (" -> Blur");
|
2019-10-11 14:23:33 +00:00
|
|
|
glUniform1f (program->blur.blur_radius_location, op->radius);
|
|
|
|
glUniform2f (program->blur.blur_size_location, op->size.width, op->size.height);
|
2019-11-26 08:38:53 +00:00
|
|
|
glUniform2f (program->blur.blur_dir_location, op->dir[0], op->dir[1]);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_cross_fade_op (const Program *program,
|
|
|
|
const OpCrossFade *op)
|
2017-12-16 09:02:03 +00:00
|
|
|
{
|
2020-07-24 06:49:24 +00:00
|
|
|
OP_PRINT (" -> Cross fade");
|
2017-12-16 09:02:03 +00:00
|
|
|
/* End texture id */
|
|
|
|
glUniform1i (program->cross_fade.source2_location, 1);
|
|
|
|
glActiveTexture (GL_TEXTURE0 + 1);
|
2019-10-11 14:23:33 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, op->source2);
|
2017-12-16 09:02:03 +00:00
|
|
|
/* progress */
|
2019-10-11 14:23:33 +00:00
|
|
|
glUniform1f (program->cross_fade.progress_location, op->progress);
|
2017-12-16 09:02:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-28 05:46:17 +00:00
|
|
|
static inline void
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_blend_op (const Program *program,
|
|
|
|
const OpBlend *op)
|
2019-04-28 05:46:17 +00:00
|
|
|
{
|
|
|
|
/* End texture id */
|
|
|
|
glUniform1i (program->blend.source2_location, 1);
|
|
|
|
glActiveTexture (GL_TEXTURE0 + 1);
|
2019-10-11 14:23:33 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, op->source2);
|
2019-04-28 05:46:17 +00:00
|
|
|
/* progress */
|
2019-10-11 14:23:33 +00:00
|
|
|
glUniform1i (program->blend.mode_location, op->mode);
|
2019-04-28 05:46:17 +00:00
|
|
|
}
|
|
|
|
|
2019-08-10 12:45:45 +00:00
|
|
|
static inline void
|
|
|
|
apply_repeat_op (const Program *program,
|
2019-10-11 14:23:33 +00:00
|
|
|
const OpRepeat *op)
|
2019-08-10 12:45:45 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
glUniform4fv (program->repeat.child_bounds_location, 1, op->child_bounds);
|
|
|
|
glUniform4fv (program->repeat.texture_rect_location, 1, op->texture_rect);
|
2019-08-10 12:45:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_renderer_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
GskGLRenderer *self = GSK_GL_RENDERER (gobject);
|
|
|
|
|
2019-07-06 11:38:55 +00:00
|
|
|
ops_free (&self->op_builder);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gsk_gl_renderer_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static void
|
|
|
|
program_init (Program *program)
|
|
|
|
{
|
|
|
|
program->index = -1;
|
|
|
|
program->state.opacity = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
program_finalize (Program *program)
|
|
|
|
{
|
|
|
|
if (program->id > 0)
|
|
|
|
glDeleteProgram (program->id);
|
|
|
|
if (program->index == -1 &&
|
|
|
|
program->glshader.compile_error != NULL)
|
|
|
|
g_error_free (program->glshader.compile_error);
|
|
|
|
|
|
|
|
gsk_transform_unref (program->state.modelview);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
program_free (Program *program)
|
|
|
|
{
|
|
|
|
program_finalize (program);
|
|
|
|
g_free (program);
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
static GskGLRendererPrograms *
|
|
|
|
gsk_gl_renderer_programs_new (void)
|
|
|
|
{
|
|
|
|
GskGLRendererPrograms *programs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
programs = g_new0 (GskGLRendererPrograms, 1);
|
|
|
|
programs->ref_count = 1;
|
|
|
|
for (i = 0; i < GL_N_PROGRAMS; i ++)
|
2020-09-18 16:03:30 +00:00
|
|
|
program_init (&programs->programs[i]);
|
|
|
|
|
|
|
|
/* We use direct hash for performance, not string hash on the source, because we assume each caller
|
|
|
|
* reuses a single GskGLShader for all uses and different callers will use different source content. */
|
|
|
|
programs->custom_programs = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify)g_object_unref, (GDestroyNotify)program_free);
|
2020-02-11 15:56:24 +00:00
|
|
|
|
|
|
|
return programs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskGLRendererPrograms *
|
|
|
|
gsk_gl_renderer_programs_ref (GskGLRendererPrograms *programs)
|
|
|
|
{
|
|
|
|
programs->ref_count++;
|
|
|
|
return programs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called with the context current */
|
|
|
|
static void
|
|
|
|
gsk_gl_renderer_programs_unref (GskGLRendererPrograms *programs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
programs->ref_count--;
|
|
|
|
if (programs->ref_count == 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < GL_N_PROGRAMS; i ++)
|
2020-09-18 16:03:30 +00:00
|
|
|
program_finalize (&programs->programs[i]);
|
|
|
|
|
|
|
|
g_hash_table_destroy (programs->custom_programs);
|
2020-02-11 15:56:24 +00:00
|
|
|
g_free (programs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
static Program *
|
|
|
|
gsk_gl_renderer_lookup_custom_program (GskGLRenderer *self,
|
|
|
|
GskGLShader *shader)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (self->programs->custom_programs, shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Program *
|
|
|
|
gsk_gl_renderer_create_custom_program (GskGLRenderer *self,
|
|
|
|
GskGLShader *shader)
|
|
|
|
{
|
|
|
|
Program *program = g_new0 (Program, 1);
|
|
|
|
|
|
|
|
program_init (program);
|
|
|
|
|
|
|
|
g_hash_table_insert (self->programs->custom_programs, g_object_ref (shader), program);
|
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
static GskGLRendererPrograms *
|
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
|
|
|
{
|
2019-12-14 21:06:12 +00:00
|
|
|
GskGLShaderBuilder shader_builder;
|
2020-02-11 15:56:24 +00:00
|
|
|
GskGLRendererPrograms *programs = NULL;
|
2017-11-30 17:47:55 +00:00
|
|
|
int i;
|
2018-01-08 20:46:16 +00:00
|
|
|
static const struct {
|
2019-12-14 21:06:12 +00:00
|
|
|
const char *resource_path;
|
2017-11-30 17:47:55 +00:00
|
|
|
const char *name;
|
|
|
|
} program_definitions[] = {
|
2019-12-14 21:06:12 +00:00
|
|
|
{ "/org/gtk/libgsk/glsl/blend.glsl", "blend" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/blit.glsl", "blit" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/blur.glsl", "blur" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/border.glsl", "border" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/color_matrix.glsl", "color matrix" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/color.glsl", "color" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/coloring.glsl", "coloring" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/cross_fade.glsl", "cross fade" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/inset_shadow.glsl", "inset shadow" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/linear_gradient.glsl", "linear gradient" },
|
2020-09-18 12:42:36 +00:00
|
|
|
{ "/org/gtk/libgsk/glsl/radial_gradient.glsl", "radial gradient" },
|
2020-12-03 05:02:18 +00:00
|
|
|
{ "/org/gtk/libgsk/glsl/conic_gradient.glsl", "conic gradient" },
|
2019-12-14 21:06:12 +00:00
|
|
|
{ "/org/gtk/libgsk/glsl/outset_shadow.glsl", "outset shadow" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/repeat.glsl", "repeat" },
|
|
|
|
{ "/org/gtk/libgsk/glsl/unblurred_outset_shadow.glsl", "unblurred_outset shadow" },
|
2017-11-30 17:47:55 +00:00
|
|
|
};
|
2016-07-03 21:54:30 +00:00
|
|
|
|
2019-12-14 21:06:12 +00:00
|
|
|
gsk_gl_shader_builder_init (&shader_builder,
|
2020-01-19 19:08:23 +00:00
|
|
|
"/org/gtk/libgsk/glsl/preamble.glsl",
|
2019-12-14 21:06:12 +00:00
|
|
|
"/org/gtk/libgsk/glsl/preamble.vs.glsl",
|
|
|
|
"/org/gtk/libgsk/glsl/preamble.fs.glsl");
|
2016-07-03 20:12:22 +00:00
|
|
|
|
2019-12-14 21:06:12 +00:00
|
|
|
g_assert (G_N_ELEMENTS (program_definitions) == GL_N_PROGRAMS);
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
init_shader_builder (self, &shader_builder);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
programs = gsk_gl_renderer_programs_new ();
|
|
|
|
|
2017-11-30 17:47:55 +00:00
|
|
|
for (i = 0; i < GL_N_PROGRAMS; i ++)
|
2017-11-25 07:56:50 +00:00
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
Program *prog = &programs->programs[i];
|
2017-11-30 17:47:55 +00:00
|
|
|
|
2020-11-19 01:02:27 +00:00
|
|
|
prog->name = program_definitions[i].name;
|
2017-11-30 17:47:55 +00:00
|
|
|
prog->index = i;
|
2019-12-14 21:06:12 +00:00
|
|
|
prog->id = gsk_gl_shader_builder_create_program (&shader_builder,
|
|
|
|
program_definitions[i].resource_path,
|
2020-09-18 16:03:30 +00:00
|
|
|
NULL, 0, error);
|
2019-12-14 21:06:12 +00:00
|
|
|
if (prog->id < 0)
|
2017-11-30 17:47:55 +00:00
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
g_clear_pointer (&programs, gsk_gl_renderer_programs_unref);
|
2019-12-14 21:06:12 +00:00
|
|
|
goto out;
|
2017-11-30 17:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, alpha);
|
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, source);
|
2019-12-16 05:16:26 +00:00
|
|
|
INIT_COMMON_UNIFORM_LOCATION (prog, clip_rect);
|
2017-11-30 17:47:55 +00:00
|
|
|
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, 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
|
|
|
|
2020-09-18 12:42:36 +00:00
|
|
|
/* radial gradient */
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (radial_gradient, color_stops);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (radial_gradient, num_color_stops);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (radial_gradient, center);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (radial_gradient, start);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (radial_gradient, end);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (radial_gradient, radius);
|
|
|
|
|
2020-12-03 05:02:18 +00:00
|
|
|
/* conic gradient */
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (conic_gradient, color_stops);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (conic_gradient, num_color_stops);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (conic_gradient, center);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (conic_gradient, rotation);
|
|
|
|
|
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);
|
2019-11-26 08:38:53 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (blur, 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);
|
2019-12-16 05:16:26 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow, outline_rect);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2017-12-01 07:30:11 +00:00
|
|
|
/* outset shadow */
|
2020-01-16 07:02:48 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (outset_shadow, color);
|
2019-12-16 05:16:26 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (outset_shadow, outline_rect);
|
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);
|
2019-12-16 05:16:26 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (unblurred_outset_shadow, outline_rect);
|
2018-01-15 09:55:40 +00:00
|
|
|
|
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);
|
2019-12-16 05:16:26 +00:00
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (border, outline_rect);
|
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);
|
|
|
|
|
2019-04-28 05:46:17 +00:00
|
|
|
/* blend */
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (blend, source2);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (blend, mode);
|
|
|
|
|
2019-08-10 12:45:45 +00:00
|
|
|
/* repeat */
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (repeat, child_bounds);
|
|
|
|
INIT_PROGRAM_UNIFORM_LOCATION (repeat, texture_rect);
|
|
|
|
|
2019-12-16 05:29:01 +00:00
|
|
|
|
|
|
|
/* We initialize the alpha uniform here, since the default value is important.
|
2020-08-21 12:41:13 +00:00
|
|
|
* We can't do it in the shader like a reasonable person would because that doesn't
|
2019-12-16 05:29:01 +00:00
|
|
|
* work in gles. */
|
|
|
|
for (i = 0; i < GL_N_PROGRAMS; i++)
|
|
|
|
{
|
2020-02-11 15:56:24 +00:00
|
|
|
glUseProgram(programs->programs[i].id);
|
|
|
|
glUniform1f (programs->programs[i].alpha_location, 1.0);
|
2019-12-16 05:29:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 21:06:12 +00:00
|
|
|
out:
|
|
|
|
gsk_gl_shader_builder_finish (&shader_builder);
|
|
|
|
|
2020-12-03 04:33:30 +00:00
|
|
|
/* Check we indeed emitted an error if there was one */
|
|
|
|
g_assert (programs || !error || *error);
|
2020-09-16 03:57:11 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
return programs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskGLRendererPrograms *
|
|
|
|
get_programs_for_display (GskGLRenderer *self,
|
|
|
|
GdkDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GskGLRendererPrograms *programs;
|
|
|
|
|
|
|
|
if (g_getenv ("GSK_NO_SHARED_PROGRAMS"))
|
|
|
|
return gsk_gl_renderer_create_programs (self, error);
|
|
|
|
|
|
|
|
programs = (GskGLRendererPrograms *)g_object_get_data (G_OBJECT (display), "gsk-gl-programs");
|
|
|
|
if (programs == NULL)
|
|
|
|
{
|
|
|
|
programs = gsk_gl_renderer_create_programs (self, error);
|
|
|
|
if (programs)
|
|
|
|
g_object_set_data_full (G_OBJECT (display), "gsk-gl-programs",
|
|
|
|
programs,
|
|
|
|
(GDestroyNotify) gsk_gl_renderer_programs_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (programs)
|
|
|
|
return gsk_gl_renderer_programs_ref (programs);
|
|
|
|
return NULL;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
static GskGLTextureAtlases *
|
|
|
|
get_texture_atlases_for_display (GdkDisplay *display)
|
|
|
|
{
|
|
|
|
GskGLTextureAtlases *atlases;
|
|
|
|
|
|
|
|
if (g_getenv ("GSK_NO_SHARED_CACHES"))
|
|
|
|
return gsk_gl_texture_atlases_new ();
|
|
|
|
|
|
|
|
atlases = (GskGLTextureAtlases*)g_object_get_data (G_OBJECT (display), "gsk-gl-texture-atlases");
|
|
|
|
if (atlases == NULL)
|
|
|
|
{
|
|
|
|
atlases = gsk_gl_texture_atlases_new ();
|
|
|
|
g_object_set_data_full (G_OBJECT (display), "gsk-gl-texture-atlases",
|
2019-06-05 02:49:07 +00:00
|
|
|
atlases,
|
2019-06-04 21:27:09 +00:00
|
|
|
(GDestroyNotify) gsk_gl_texture_atlases_unref);
|
|
|
|
}
|
|
|
|
|
2019-06-05 02:49:07 +00:00
|
|
|
return gsk_gl_texture_atlases_ref (atlases);
|
2019-06-04 21:27:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GskGLGlyphCache *
|
|
|
|
get_glyph_cache_for_display (GdkDisplay *display,
|
|
|
|
GskGLTextureAtlases *atlases)
|
|
|
|
{
|
|
|
|
GskGLGlyphCache *glyph_cache;
|
|
|
|
|
|
|
|
if (g_getenv ("GSK_NO_SHARED_CACHES"))
|
|
|
|
return gsk_gl_glyph_cache_new (display, atlases);
|
|
|
|
|
|
|
|
glyph_cache = (GskGLGlyphCache*)g_object_get_data (G_OBJECT (display), "gsk-gl-glyph-cache");
|
|
|
|
if (glyph_cache == NULL)
|
|
|
|
{
|
|
|
|
glyph_cache = gsk_gl_glyph_cache_new (display, atlases);
|
|
|
|
g_object_set_data_full (G_OBJECT (display), "gsk-gl-glyph-cache",
|
2019-06-05 02:49:07 +00:00
|
|
|
glyph_cache,
|
2019-06-04 21:27:09 +00:00
|
|
|
(GDestroyNotify) gsk_gl_glyph_cache_unref);
|
|
|
|
}
|
|
|
|
|
2019-06-05 02:49:07 +00:00
|
|
|
return gsk_gl_glyph_cache_ref (glyph_cache);
|
2019-06-04 21:27:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GskGLIconCache *
|
|
|
|
get_icon_cache_for_display (GdkDisplay *display,
|
|
|
|
GskGLTextureAtlases *atlases)
|
|
|
|
{
|
|
|
|
GskGLIconCache *icon_cache;
|
|
|
|
|
|
|
|
if (g_getenv ("GSK_NO_SHARED_CACHES"))
|
|
|
|
return gsk_gl_icon_cache_new (display, atlases);
|
|
|
|
|
|
|
|
icon_cache = (GskGLIconCache*)g_object_get_data (G_OBJECT (display), "gsk-gl-icon-cache");
|
|
|
|
if (icon_cache == NULL)
|
|
|
|
{
|
|
|
|
icon_cache = gsk_gl_icon_cache_new (display, atlases);
|
|
|
|
g_object_set_data_full (G_OBJECT (display), "gsk-gl-icon-cache",
|
2019-06-05 02:49:07 +00:00
|
|
|
icon_cache,
|
2019-06-04 21:27:09 +00:00
|
|
|
(GDestroyNotify) gsk_gl_icon_cache_unref);
|
|
|
|
}
|
|
|
|
|
2019-06-05 02:49:07 +00:00
|
|
|
return gsk_gl_icon_cache_ref (icon_cache);
|
2019-06-04 21:27:09 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2020-08-19 22:49:34 +00:00
|
|
|
gint64 before G_GNUC_UNUSED;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
before = GDK_PROFILER_CURRENT_TIME;
|
2016-03-17 13:48:19 +00:00
|
|
|
/* 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"));
|
2020-02-11 15:56:24 +00:00
|
|
|
self->programs = get_programs_for_display (self, gdk_surface_get_display (surface), error);
|
|
|
|
if (self->programs == NULL)
|
2016-07-03 20:12:22 +00:00
|
|
|
return FALSE;
|
2020-02-11 15:56:24 +00:00
|
|
|
self->op_builder.programs = self->programs;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
self->atlases = get_texture_atlases_for_display (gdk_surface_get_display (surface));
|
|
|
|
self->glyph_cache = get_glyph_cache_for_display (gdk_surface_get_display (surface), self->atlases);
|
|
|
|
self->icon_cache = get_icon_cache_for_display (gdk_surface_get_display (surface), self->atlases);
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_gl_shadow_cache_init (&self->shadow_cache);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
gdk_profiler_end_mark (before, "gl renderer realize", NULL);
|
2020-01-25 06:28:24 +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);
|
|
|
|
|
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
|
|
|
|
*/
|
2019-10-11 14:23:33 +00:00
|
|
|
ops_reset (&self->op_builder);
|
2020-02-11 15:56:24 +00:00
|
|
|
self->op_builder.programs = NULL;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2020-02-11 15:56:24 +00:00
|
|
|
g_clear_pointer (&self->programs, gsk_gl_renderer_programs_unref);
|
2019-06-04 21:27:09 +00:00
|
|
|
g_clear_pointer (&self->glyph_cache, gsk_gl_glyph_cache_unref);
|
|
|
|
g_clear_pointer (&self->icon_cache, gsk_gl_icon_cache_unref);
|
|
|
|
g_clear_pointer (&self->atlases, gsk_gl_texture_atlases_unref);
|
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-22 10:32:23 +00:00
|
|
|
if (self->gl_context == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
ops_reset (&self->op_builder);
|
2020-01-29 13:02:41 +00:00
|
|
|
|
2020-02-13 03:45:24 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2020-02-13 15:42:21 +00:00
|
|
|
int removed_textures = gsk_gl_driver_collect_textures (self->gl_driver);
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_RENDERER_NOTE (GSK_RENDERER (self), OPENGL, g_message ("Collected: %d textures", removed_textures));
|
2020-02-13 15:42:21 +00:00
|
|
|
#else
|
|
|
|
gsk_gl_driver_collect_textures (self->gl_driver);
|
2020-01-29 13:02:41 +00:00
|
|
|
#endif
|
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
|
|
|
|
2019-10-13 23:39:54 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
|
|
|
|
GskRenderNode *node,
|
|
|
|
RenderOpBuilder *builder)
|
|
|
|
{
|
2018-03-25 09:47:04 +00:00
|
|
|
/* This can still happen, even if the render nodes are created using
|
2020-08-21 12:41:13 +00:00
|
|
|
* GtkSnapshot, so let's just be safe. */
|
2019-11-23 09:20:15 +00:00
|
|
|
if (node_is_invisible (node))
|
2018-03-25 09:47:04 +00:00
|
|
|
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
|
|
|
|
2020-07-24 15:01:32 +00:00
|
|
|
if (!graphene_rect_intersects (&builder->current_clip->bounds,
|
|
|
|
&transformed_node_bounds))
|
2018-05-01 10:51:04 +00:00
|
|
|
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:
|
2019-05-21 03:41:06 +00:00
|
|
|
{
|
|
|
|
const char *message = gsk_debug_node_get_message (node);
|
|
|
|
if (message)
|
|
|
|
ops_push_debug_group (builder, message);
|
|
|
|
gsk_gl_renderer_add_render_ops (self,
|
|
|
|
gsk_debug_node_get_child (node),
|
|
|
|
builder);
|
|
|
|
if (message)
|
|
|
|
ops_pop_debug_group (builder);
|
|
|
|
}
|
2018-04-23 22:41:48 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case GSK_COLOR_NODE:
|
2019-11-26 07:58:38 +00:00
|
|
|
render_color_node (self, node, builder);
|
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
|
|
|
|
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:
|
2019-11-26 07:58:38 +00:00
|
|
|
render_linear_gradient_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2020-09-18 12:42:36 +00:00
|
|
|
case GSK_RADIAL_GRADIENT_NODE:
|
|
|
|
render_radial_gradient_node (self, node, builder);
|
|
|
|
break;
|
|
|
|
|
2020-12-03 05:02:18 +00:00
|
|
|
case GSK_CONIC_GRADIENT_NODE:
|
|
|
|
render_conic_gradient_node (self, node, builder);
|
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
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,
|
2020-11-16 23:59:36 +00:00
|
|
|
gsk_text_node_get_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:
|
2019-10-15 03:28:15 +00:00
|
|
|
render_color_matrix_node (self, node, builder);
|
2017-11-24 09:32:08 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-25 07:56:50 +00:00
|
|
|
case GSK_BLUR_NODE:
|
2019-11-26 07:58:38 +00:00
|
|
|
render_blur_node (self, node, builder);
|
2017-11-25 07:56:50 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-30 15:48:03 +00:00
|
|
|
case GSK_INSET_SHADOW_NODE:
|
2019-11-30 11:44:30 +00:00
|
|
|
if (gsk_inset_shadow_node_get_blur_radius (node) > 0)
|
|
|
|
render_inset_shadow_node (self, node, builder);
|
|
|
|
else
|
|
|
|
render_unblurred_inset_shadow_node (self, node, builder);
|
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)
|
2019-11-26 07:58:38 +00:00
|
|
|
render_outset_shadow_node (self, node, builder);
|
2018-01-15 09:55:40 +00:00
|
|
|
else
|
2019-11-26 07:58:38 +00:00
|
|
|
render_unblurred_outset_shadow_node (self, node, builder);
|
2017-12-01 07:30:11 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-01 09:27:31 +00:00
|
|
|
case GSK_SHADOW_NODE:
|
2019-10-15 03:28:15 +00:00
|
|
|
render_shadow_node (self, node, builder);
|
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:
|
2019-11-26 07:58:38 +00:00
|
|
|
render_cross_fade_node (self, node, builder);
|
2017-12-11 07:22:28 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
case GSK_BLEND_NODE:
|
2019-11-26 07:58:38 +00:00
|
|
|
render_blend_node (self, node, builder);
|
2019-04-28 05:46:17 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
case GSK_REPEAT_NODE:
|
2019-08-10 12:45:45 +00:00
|
|
|
render_repeat_node (self, node, builder);
|
|
|
|
break;
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
case GSK_GL_SHADER_NODE:
|
|
|
|
render_gl_shader_node (self, node, builder);
|
|
|
|
break;
|
|
|
|
|
2019-08-10 12:45:45 +00:00
|
|
|
case GSK_REPEATING_LINEAR_GRADIENT_NODE:
|
2020-09-12 02:55:37 +00:00
|
|
|
case GSK_REPEATING_RADIAL_GRADIENT_NODE:
|
2018-03-25 09:46:48 +00:00
|
|
|
case GSK_CAIRO_NODE:
|
2016-12-13 03:20:04 +00:00
|
|
|
default:
|
|
|
|
{
|
2019-05-18 11:45:19 +00:00
|
|
|
render_fallback_node (self, node, builder);
|
2017-11-22 10:32:23 +00:00
|
|
|
}
|
2017-11-03 12:09:02 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
static gboolean
|
2018-12-02 08:05:50 +00:00
|
|
|
add_offscreen_ops (GskGLRenderer *self,
|
|
|
|
RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
GskRenderNode *child_node,
|
2020-12-19 16:43:56 +00:00
|
|
|
TextureRegion *texture_region_out,
|
|
|
|
gboolean *is_offscreen,
|
|
|
|
guint flags)
|
2017-11-24 09:18:51 +00:00
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
float width, height;
|
2018-12-02 07:12:44 +00:00
|
|
|
const float dx = builder->dx;
|
|
|
|
const float dy = builder->dy;
|
2020-12-04 20:12:34 +00:00
|
|
|
float scale_x;
|
|
|
|
float scale_y;
|
2017-11-24 09:18:51 +00:00
|
|
|
int render_target;
|
|
|
|
int prev_render_target;
|
|
|
|
graphene_matrix_t prev_projection;
|
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
graphene_matrix_t item_proj;
|
2020-01-29 13:02:41 +00:00
|
|
|
float prev_opacity = 1.0;
|
2018-11-28 17:40:48 +00:00
|
|
|
int texture_id = 0;
|
2020-09-02 22:01:06 +00:00
|
|
|
int filter;
|
2020-09-09 17:55:09 +00:00
|
|
|
GskTextureKey key;
|
|
|
|
int cached_id;
|
2020-12-19 16:43:56 +00:00
|
|
|
graphene_rect_t viewport;
|
2017-11-24 09:18:51 +00:00
|
|
|
|
2019-11-23 09:20:15 +00:00
|
|
|
if (node_is_invisible (child_node))
|
|
|
|
{
|
|
|
|
/* Just to be safe */
|
2020-12-19 16:43:56 +00:00
|
|
|
*is_offscreen = FALSE;
|
|
|
|
init_full_texture_region (texture_region_out, 0);
|
|
|
|
return FALSE;
|
2019-11-23 09:20:15 +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. */
|
2019-01-18 12:06:41 +00:00
|
|
|
if (gsk_render_node_get_node_type (child_node) == GSK_TEXTURE_NODE &&
|
|
|
|
(flags & FORCE_OFFSCREEN) == 0)
|
2017-11-24 09:43:17 +00:00
|
|
|
{
|
|
|
|
GdkTexture *texture = gsk_texture_node_get_texture (child_node);
|
2020-12-19 16:43:56 +00:00
|
|
|
upload_texture (self, texture, texture_region_out);
|
|
|
|
*is_offscreen = FALSE;
|
|
|
|
return TRUE;
|
2017-11-24 09:43:17 +00:00
|
|
|
}
|
2017-11-24 09:18:51 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
if (flags & LINEAR_FILTER)
|
|
|
|
filter = GL_LINEAR;
|
|
|
|
else
|
|
|
|
filter = GL_NEAREST;
|
|
|
|
|
2018-11-28 17:40:48 +00:00
|
|
|
/* Check if we've already cached the drawn texture. */
|
2020-09-09 17:55:09 +00:00
|
|
|
key.pointer = child_node;
|
2020-09-30 12:53:13 +00:00
|
|
|
key.pointer_is_child = TRUE; /* Don't conflict with the child using the cache too */
|
2020-10-05 13:19:27 +00:00
|
|
|
key.parent_rect = *bounds;
|
2020-12-04 20:12:34 +00:00
|
|
|
key.scale_x = builder->scale_x;
|
|
|
|
key.scale_y = builder->scale_y;
|
2020-09-09 17:55:09 +00:00
|
|
|
key.filter = filter;
|
|
|
|
cached_id = gsk_gl_driver_get_texture_for_key (self->gl_driver, &key);
|
2018-11-28 17:40:48 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
if (cached_id != 0)
|
|
|
|
{
|
2020-12-19 16:43:56 +00:00
|
|
|
init_full_texture_region (texture_region_out, cached_id);
|
2020-09-09 17:55:09 +00:00
|
|
|
/* We didn't render it offscreen, but hand out an offscreen texture id */
|
2020-12-19 16:43:56 +00:00
|
|
|
*is_offscreen = TRUE;
|
|
|
|
return TRUE;
|
2020-09-09 17:55:09 +00:00
|
|
|
}
|
2018-11-28 17:40:48 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
width = bounds->size.width;
|
|
|
|
height = bounds->size.height;
|
2020-12-04 20:12:34 +00:00
|
|
|
scale_x = builder->scale_x;
|
|
|
|
scale_y = builder->scale_y;
|
2020-02-11 12:01:27 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
/* Tweak the scale factor so that the required texture doesn't
|
|
|
|
* exceed the max texture limit. This will render with a lower
|
|
|
|
* resolution, but this is better than clipping.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
const int max_texture_size = gsk_gl_driver_get_max_texture_size (self->gl_driver);
|
2020-12-13 15:29:14 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
width = ceilf (width * scale_x);
|
|
|
|
if (width > max_texture_size)
|
|
|
|
{
|
|
|
|
scale_x *= (float)max_texture_size / width;
|
|
|
|
width = max_texture_size;
|
|
|
|
}
|
2020-12-13 15:29:14 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
height = ceilf (height * scale_y);
|
|
|
|
if (height > max_texture_size)
|
|
|
|
{
|
|
|
|
scale_y *= (float)max_texture_size / height;
|
|
|
|
height = max_texture_size;
|
|
|
|
}
|
|
|
|
}
|
2020-02-11 12:01:27 +00:00
|
|
|
|
2020-09-02 22:01:06 +00:00
|
|
|
gsk_gl_driver_create_render_target (self->gl_driver,
|
|
|
|
width, height,
|
|
|
|
filter, filter,
|
|
|
|
&texture_id, &render_target);
|
2020-07-24 16:54:23 +00:00
|
|
|
if (gdk_gl_context_has_debug (self->gl_context))
|
|
|
|
{
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, texture_id,
|
|
|
|
"Offscreen<%s> %d",
|
|
|
|
g_type_name_from_instance ((GTypeInstance *) child_node),
|
|
|
|
texture_id);
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_FRAMEBUFFER, render_target,
|
|
|
|
"Offscreen<%s> FB %d",
|
|
|
|
g_type_name_from_instance ((GTypeInstance *) child_node),
|
|
|
|
render_target);
|
|
|
|
}
|
2017-11-24 09:18:51 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
viewport = GRAPHENE_RECT_INIT (bounds->origin.x * scale_x,
|
|
|
|
bounds->origin.y * scale_y,
|
|
|
|
width, height);
|
2017-11-24 09:18:51 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
init_projection_matrix (&item_proj, &viewport);
|
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 */
|
2019-10-09 22:41:53 +00:00
|
|
|
ops_begin (builder, OP_CLEAR);
|
2017-11-24 09:18:51 +00:00
|
|
|
prev_projection = ops_set_projection (builder, &item_proj);
|
2020-12-04 20:12:34 +00:00
|
|
|
ops_set_modelview (builder, gsk_transform_scale (NULL, scale_x, scale_y));
|
2020-12-19 16:43:56 +00:00
|
|
|
prev_viewport = ops_set_viewport (builder, &viewport);
|
2019-01-18 12:06:41 +00:00
|
|
|
if (flags & RESET_CLIP)
|
2020-12-19 16:43:56 +00:00
|
|
|
ops_push_clip (builder, &GSK_ROUNDED_RECT_INIT_FROM_RECT (viewport));
|
2018-12-02 08:05:50 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
builder->dx = 0;
|
|
|
|
builder->dy = 0;
|
2019-11-29 05:54:43 +00:00
|
|
|
|
2020-12-06 19:03:35 +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);
|
|
|
|
|
2019-03-31 04:14:41 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
if (G_UNLIKELY (flags & DUMP_FRAMEBUFFER))
|
|
|
|
{
|
|
|
|
static int k;
|
2020-04-07 22:33:54 +00:00
|
|
|
ops_dump_framebuffer (builder,
|
2020-12-19 16:43:56 +00:00
|
|
|
g_strdup_printf ("%s_%p_%d.png",
|
2020-04-07 22:33:54 +00:00
|
|
|
g_type_name_from_instance ((GTypeInstance *) child_node),
|
2020-12-19 16:43:56 +00:00
|
|
|
child_node,
|
|
|
|
k ++),
|
2019-03-31 04:14:41 +00:00
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-06 19:03:35 +00:00
|
|
|
ops_set_opacity (builder, prev_opacity);
|
2019-01-18 12:06:41 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
builder->dx = dx;
|
|
|
|
builder->dy = dy;
|
|
|
|
|
2019-01-18 12:06:41 +00:00
|
|
|
if (flags & RESET_CLIP)
|
2018-12-30 14:25:01 +00:00
|
|
|
ops_pop_clip (builder);
|
2018-03-14 11:36:32 +00:00
|
|
|
|
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);
|
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
*is_offscreen = TRUE;
|
|
|
|
init_full_texture_region (texture_region_out, texture_id);
|
2018-11-28 17:40:48 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
if ((flags & NO_CACHE_PLZ) == 0)
|
2020-09-09 17:55:09 +00:00
|
|
|
gsk_gl_driver_set_texture_for_key (self->gl_driver, &key, texture_id);
|
2019-11-23 09:20:15 +00:00
|
|
|
|
2020-12-19 16:43:56 +00:00
|
|
|
return TRUE;
|
2017-11-24 09:18:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 12:09:02 +00:00
|
|
|
static void
|
2019-10-11 18:10:56 +00:00
|
|
|
gsk_gl_renderer_render_ops (GskGLRenderer *self)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2017-11-22 10:32:23 +00:00
|
|
|
const Program *program = NULL;
|
2019-12-16 06:01:34 +00:00
|
|
|
const gsize vertex_data_size = self->op_builder.vertices->len * sizeof (GskQuadVertex);
|
|
|
|
const float *vertex_data = (float *)self->op_builder.vertices->data;
|
2019-10-11 14:23:33 +00:00
|
|
|
OpBufferIter iter;
|
|
|
|
OpKind kind;
|
|
|
|
gpointer ptr;
|
2019-12-16 06:01:34 +00:00
|
|
|
GLuint buffer_id, vao_id;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2019-12-16 06:34:35 +00:00
|
|
|
#if DEBUG_OPS
|
|
|
|
g_print ("============================================\n");
|
|
|
|
#endif
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
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
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
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
|
|
|
/* 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
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
op_buffer_iter_init (&iter, ops_get_buffer (&self->op_builder));
|
|
|
|
while ((ptr = op_buffer_iter_next (&iter, &kind)))
|
2017-11-22 10:32:23 +00:00
|
|
|
{
|
2019-10-11 17:59:58 +00:00
|
|
|
if (kind == OP_NONE)
|
2017-11-22 10:32:23 +00:00
|
|
|
continue;
|
2017-11-03 12:09:02 +00:00
|
|
|
|
2019-10-09 18:51:32 +00:00
|
|
|
if (program == NULL &&
|
2019-10-11 14:23:33 +00:00
|
|
|
kind != OP_PUSH_DEBUG_GROUP &&
|
|
|
|
kind != OP_POP_DEBUG_GROUP &&
|
|
|
|
kind != OP_CHANGE_PROGRAM &&
|
|
|
|
kind != OP_CHANGE_RENDER_TARGET &&
|
|
|
|
kind != OP_CLEAR)
|
2017-12-08 19:43:47 +00:00
|
|
|
continue;
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
OP_PRINT ("Op %u: %u", iter.pos - 2, kind);
|
2017-03-20 09:52:58 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
switch (kind)
|
2017-11-22 10:32:23 +00:00
|
|
|
{
|
|
|
|
case OP_CHANGE_PROJECTION:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_projection_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_MODELVIEW:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_modelview_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_PROGRAM:
|
2019-10-11 14:23:33 +00:00
|
|
|
{
|
|
|
|
const OpProgram *op = ptr;
|
|
|
|
apply_program_op (program, op);
|
|
|
|
program = op->program;
|
|
|
|
break;
|
|
|
|
}
|
2017-11-22 10:32:23 +00:00
|
|
|
|
|
|
|
case OP_CHANGE_RENDER_TARGET:
|
2020-10-10 16:40:03 +00:00
|
|
|
apply_render_target_op (self, ptr);
|
2017-11-22 20:02:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CLEAR:
|
2020-07-24 06:49:24 +00:00
|
|
|
OP_PRINT ("-> CLEAR");
|
2017-11-22 20:02:50 +00:00
|
|
|
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:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_viewport_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_OPACITY:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_opacity_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-24 09:32:08 +00:00
|
|
|
case OP_CHANGE_COLOR_MATRIX:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_color_matrix_op (program, ptr);
|
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);*/
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_color_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-05 07:38:42 +00:00
|
|
|
case OP_CHANGE_BORDER_COLOR:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_border_color_op (program, ptr);
|
2017-12-05 07:38:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_CHANGE_CLIP:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_clip_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_SOURCE_TEXTURE:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_source_texture_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
case OP_CHANGE_EXTRA_SOURCE_TEXTURE:
|
|
|
|
apply_source_extra_texture_op (program, ptr);
|
|
|
|
break;
|
|
|
|
|
2017-12-11 07:22:28 +00:00
|
|
|
case OP_CHANGE_CROSS_FADE:
|
2020-02-11 15:56:24 +00:00
|
|
|
g_assert (program == &self->programs->cross_fade_program);
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_cross_fade_op (program, ptr);
|
2017-12-11 07:22:28 +00:00
|
|
|
break;
|
|
|
|
|
2019-04-28 05:46:17 +00:00
|
|
|
case OP_CHANGE_BLEND:
|
2020-02-11 15:56:24 +00:00
|
|
|
g_assert (program == &self->programs->blend_program);
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_blend_op (program, ptr);
|
2019-04-28 05:46:17 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_CHANGE_LINEAR_GRADIENT:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_linear_gradient_op (program, ptr);
|
2017-11-22 10:32:23 +00:00
|
|
|
break;
|
|
|
|
|
2020-09-18 12:42:36 +00:00
|
|
|
case OP_CHANGE_RADIAL_GRADIENT:
|
|
|
|
apply_radial_gradient_op (program, ptr);
|
|
|
|
break;
|
|
|
|
|
2020-12-03 05:02:18 +00:00
|
|
|
case OP_CHANGE_CONIC_GRADIENT:
|
|
|
|
apply_conic_gradient_op (program, ptr);
|
|
|
|
break;
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
case OP_CHANGE_BLUR:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_blur_op (program, ptr);
|
2017-11-25 07:56:50 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
case OP_CHANGE_INSET_SHADOW:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_inset_shadow_op (program, ptr);
|
2017-11-30 15:48:03 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-21 17:09:32 +00:00
|
|
|
case OP_CHANGE_OUTSET_SHADOW:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_outset_shadow_op (program, ptr);
|
2017-12-01 07:30:11 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-01 10:55:10 +00:00
|
|
|
case OP_CHANGE_BORDER:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_border_op (program, ptr);
|
2017-12-01 10:55:10 +00:00
|
|
|
break;
|
|
|
|
|
2018-12-05 09:44:11 +00:00
|
|
|
case OP_CHANGE_BORDER_WIDTH:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_border_width_op (program, ptr);
|
2018-12-05 09:44:11 +00:00
|
|
|
break;
|
|
|
|
|
2018-01-15 09:55:40 +00:00
|
|
|
case OP_CHANGE_UNBLURRED_OUTSET_SHADOW:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_unblurred_outset_shadow_op (program, ptr);
|
2019-08-10 12:45:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CHANGE_REPEAT:
|
2019-10-11 14:23:33 +00:00
|
|
|
apply_repeat_op (program, ptr);
|
2018-01-15 09:55:40 +00:00
|
|
|
break;
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
case OP_CHANGE_GL_SHADER_ARGS:
|
|
|
|
apply_gl_shader_args_op (program, ptr);
|
|
|
|
break;
|
|
|
|
|
2017-11-22 10:32:23 +00:00
|
|
|
case OP_DRAW:
|
2019-10-11 14:23:33 +00:00
|
|
|
{
|
|
|
|
const OpDraw *op = ptr;
|
|
|
|
|
2020-11-19 01:02:27 +00:00
|
|
|
OP_PRINT (" -> draw %ld, size %ld and program %d: %s",
|
|
|
|
op->vao_offset, op->vao_size, program->index,
|
|
|
|
program->name ?: "");
|
2019-10-11 14:23:33 +00:00
|
|
|
glDrawArrays (GL_TRIANGLES, op->vao_offset, op->vao_size);
|
|
|
|
break;
|
|
|
|
}
|
2017-11-22 10:32:23 +00:00
|
|
|
|
2018-12-02 07:12:09 +00:00
|
|
|
case OP_DUMP_FRAMEBUFFER:
|
2019-10-11 14:23:33 +00:00
|
|
|
{
|
|
|
|
const OpDumpFrameBuffer *op = ptr;
|
|
|
|
|
|
|
|
dump_framebuffer (op->filename, op->width, op->height);
|
|
|
|
break;
|
|
|
|
}
|
2018-12-02 07:12:09 +00:00
|
|
|
|
2019-04-24 11:28:11 +00:00
|
|
|
case OP_PUSH_DEBUG_GROUP:
|
2019-10-11 14:23:33 +00:00
|
|
|
{
|
|
|
|
const OpDebugGroup *op = ptr;
|
|
|
|
gdk_gl_context_push_debug_group (self->gl_context, op->text);
|
2019-12-19 05:05:01 +00:00
|
|
|
OP_PRINT (" Debug: %s", op->text);
|
2019-10-11 14:23:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-24 11:28:11 +00:00
|
|
|
|
|
|
|
case OP_POP_DEBUG_GROUP:
|
|
|
|
gdk_gl_context_pop_debug_group (self->gl_context);
|
|
|
|
break;
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
case OP_NONE:
|
|
|
|
case OP_LAST:
|
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-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);
|
2019-07-21 10:11:36 +00:00
|
|
|
graphene_matrix_t projection;
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler;
|
2020-08-19 22:49:34 +00:00
|
|
|
gint64 gpu_time, cpu_time;
|
|
|
|
gint64 start_time G_GNUC_UNUSED;
|
2016-08-03 15:51:21 +00:00
|
|
|
#endif
|
2019-10-12 00:42:24 +00:00
|
|
|
GPtrArray *removed;
|
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;
|
|
|
|
}
|
|
|
|
|
2019-04-22 12:20:02 +00:00
|
|
|
g_assert (gsk_gl_driver_in_frame (self->gl_driver));
|
|
|
|
|
2019-10-12 00:42:24 +00:00
|
|
|
removed = g_ptr_array_new ();
|
|
|
|
gsk_gl_texture_atlases_begin_frame (self->atlases, removed);
|
2019-10-12 22:26:09 +00:00
|
|
|
gsk_gl_glyph_cache_begin_frame (self->glyph_cache, self->gl_driver, removed);
|
2019-10-12 00:42:24 +00:00
|
|
|
gsk_gl_icon_cache_begin_frame (self->icon_cache, removed);
|
2018-07-08 18:08:15 +00:00
|
|
|
gsk_gl_shadow_cache_begin_frame (&self->shadow_cache, self->gl_driver);
|
2019-10-12 00:42:24 +00:00
|
|
|
g_ptr_array_unref (removed);
|
2016-08-03 15:51:21 +00:00
|
|
|
|
2020-10-01 06:39:19 +00:00
|
|
|
/* Set up the modelview and projection matrices to fit our viewport */
|
|
|
|
init_projection_matrix (&projection, viewport);
|
2019-04-24 15:55:14 +00:00
|
|
|
ops_set_projection (&self->op_builder, &projection);
|
|
|
|
ops_set_viewport (&self->op_builder, viewport);
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_set_modelview (&self->op_builder, gsk_transform_scale (NULL, scale_factor, scale_factor));
|
2018-12-30 14:25:01 +00:00
|
|
|
|
2018-12-02 05:56:52 +00:00
|
|
|
/* Initial clip is self->render_region! */
|
|
|
|
if (self->render_region != NULL)
|
|
|
|
{
|
2019-02-23 15:59:46 +00:00
|
|
|
graphene_rect_t transformed_render_region;
|
2019-01-06 09:59:21 +00:00
|
|
|
cairo_rectangle_int_t render_extents;
|
2018-12-02 05:56:52 +00:00
|
|
|
|
|
|
|
cairo_region_get_extents (self->render_region, &render_extents);
|
|
|
|
|
2019-04-24 15:55:14 +00:00
|
|
|
ops_transform_bounds_modelview (&self->op_builder,
|
2018-12-30 14:25:01 +00:00
|
|
|
&GRAPHENE_RECT_INIT (render_extents.x,
|
|
|
|
render_extents.y,
|
|
|
|
render_extents.width,
|
|
|
|
render_extents.height),
|
2019-02-23 15:59:46 +00:00
|
|
|
&transformed_render_region);
|
2019-04-24 15:55:14 +00:00
|
|
|
ops_push_clip (&self->op_builder,
|
2019-02-23 15:59:46 +00:00
|
|
|
&GSK_ROUNDED_RECT_INIT (transformed_render_region.origin.x,
|
|
|
|
transformed_render_region.origin.y,
|
|
|
|
transformed_render_region.size.width,
|
|
|
|
transformed_render_region.size.height));
|
2018-12-02 05:56:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-24 15:55:14 +00:00
|
|
|
ops_push_clip (&self->op_builder,
|
2018-12-30 14:25:01 +00:00
|
|
|
&GSK_ROUNDED_RECT_INIT (viewport->origin.x,
|
|
|
|
viewport->origin.y,
|
|
|
|
viewport->size.width,
|
|
|
|
viewport->size.height));
|
2018-12-02 05:56:52 +00:00
|
|
|
}
|
2017-12-27 22:15:07 +00:00
|
|
|
|
2018-04-21 08:13:16 +00:00
|
|
|
if (fbo_id != 0)
|
2019-04-24 15:55:14 +00:00
|
|
|
ops_set_render_target (&self->op_builder, fbo_id);
|
2017-12-27 22:15:07 +00:00
|
|
|
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_push_debug_group (self->gl_context, "Adding render ops");
|
2019-04-24 15:55:14 +00:00
|
|
|
gsk_gl_renderer_add_render_ops (self, root, &self->op_builder);
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_pop_debug_group (self->gl_context);
|
2017-11-22 10:32:23 +00:00
|
|
|
|
2018-04-12 09:02:46 +00:00
|
|
|
/* We correctly reset the state everywhere */
|
2019-04-24 15:55:14 +00:00
|
|
|
g_assert_cmpint (self->op_builder.current_render_target, ==, fbo_id);
|
|
|
|
ops_pop_modelview (&self->op_builder);
|
|
|
|
ops_pop_clip (&self->op_builder);
|
|
|
|
ops_finish (&self->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
|
|
|
|
2019-04-24 12:25:54 +00:00
|
|
|
/* Actually do the rendering */
|
|
|
|
if (fbo_id != 0)
|
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, fbo_id);
|
|
|
|
|
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
|
|
|
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_push_debug_group (self->gl_context, "Rendering ops");
|
2019-10-11 18:10:56 +00:00
|
|
|
gsk_gl_renderer_render_ops (self);
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_pop_debug_group (self->gl_context);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
gsk_profiler_counter_inc (profiler, self->profile_counters.frames);
|
|
|
|
|
2018-05-19 19:25:17 +00:00
|
|
|
start_time = gsk_profiler_timer_get_start (profiler, self->profile_timers.cpu_time);
|
2016-08-03 15:51:21 +00:00
|
|
|
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);
|
2018-05-19 19:25:17 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
gdk_profiler_add_mark (start_time * 1000, cpu_time * 1000, "GL render", "");
|
2016-08-03 15:51:21 +00:00
|
|
|
#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);
|
|
|
|
|
2019-05-08 16:18:11 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_push_debug_group_printf (self->gl_context,
|
2020-04-07 22:33:54 +00:00
|
|
|
"Render %s<%p> to texture",
|
|
|
|
g_type_name_from_instance ((GTypeInstance *) root),
|
|
|
|
root);
|
2019-04-24 11:28:11 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2020-10-10 07:16:30 +00:00
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2020-10-08 16:00:36 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
|
2020-07-24 16:54:23 +00:00
|
|
|
if (gdk_gl_context_has_debug (self->gl_context))
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, texture_id,
|
|
|
|
"Texture %s<%p> %d",
|
|
|
|
g_type_name_from_instance ((GTypeInstance *) root),
|
|
|
|
root,
|
|
|
|
texture_id);
|
2019-04-24 11:27:43 +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);
|
2020-07-24 16:54:23 +00:00
|
|
|
|
|
|
|
if (gdk_gl_context_has_debug (self->gl_context))
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_FRAMEBUFFER, fbo_id,
|
|
|
|
"FB %s<%p> %d",
|
|
|
|
g_type_name_from_instance ((GTypeInstance *) root),
|
|
|
|
root,
|
|
|
|
fbo_id);
|
2020-11-18 04:11:18 +00:00
|
|
|
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0);
|
2017-11-03 12:09:02 +00:00
|
|
|
|
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
|
|
|
|
2020-10-08 16:00:36 +00:00
|
|
|
glDeleteFramebuffers (1, &fbo_id);
|
|
|
|
|
2020-10-10 17:03:02 +00:00
|
|
|
|
2020-10-08 16:00:36 +00:00
|
|
|
/* Render the now drawn framebuffer y-flipped so it's as GdkGLTexture expects it to be */
|
|
|
|
{
|
|
|
|
guint final_texture_id, final_fbo_id;
|
|
|
|
graphene_matrix_t m;
|
|
|
|
|
2020-10-10 17:03:02 +00:00
|
|
|
ops_reset (&self->op_builder);
|
|
|
|
|
2020-10-08 16:00:36 +00:00
|
|
|
glGenFramebuffers (1, &final_fbo_id);
|
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, final_fbo_id);
|
|
|
|
glGenTextures (1, &final_texture_id);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, final_texture_id);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-10-10 07:16:30 +00:00
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2020-10-08 16:00:36 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
|
2020-11-16 17:26:07 +00:00
|
|
|
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, final_texture_id, 0);
|
2020-10-08 16:00:36 +00:00
|
|
|
g_assert_cmphex (glCheckFramebufferStatus (GL_FRAMEBUFFER), ==, GL_FRAMEBUFFER_COMPLETE);
|
|
|
|
|
2020-10-10 17:03:02 +00:00
|
|
|
ops_set_render_target (&self->op_builder, final_fbo_id);
|
|
|
|
ops_push_clip (&self->op_builder, &GSK_ROUNDED_RECT_INIT (0, 0, width, height));
|
|
|
|
ops_set_program (&self->op_builder, &self->programs->blit_program);
|
2020-10-08 16:00:36 +00:00
|
|
|
|
2020-10-10 17:03:02 +00:00
|
|
|
ops_begin (&self->op_builder, OP_CLEAR);
|
|
|
|
ops_set_texture (&self->op_builder, texture_id);
|
|
|
|
ops_set_modelview (&self->op_builder, NULL);
|
|
|
|
ops_set_viewport (&self->op_builder, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
2020-10-08 16:00:36 +00:00
|
|
|
init_projection_matrix (&m, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
|
|
|
graphene_matrix_scale (&m, 1, -1, 1); /* Undo the scale init_projection_matrix() does again */
|
2020-10-10 17:03:02 +00:00
|
|
|
ops_set_projection (&self->op_builder, &m);
|
2020-10-08 16:00:36 +00:00
|
|
|
|
2020-12-19 16:43:43 +00:00
|
|
|
fill_vertex_data (ops_draw (&self->op_builder, NULL),
|
|
|
|
0, 0, width, height);
|
2020-10-10 17:03:02 +00:00
|
|
|
ops_pop_clip (&self->op_builder);
|
|
|
|
gsk_gl_renderer_render_ops (self);
|
2020-10-08 16:00:36 +00:00
|
|
|
|
2020-10-10 17:03:02 +00:00
|
|
|
ops_finish (&self->op_builder);
|
2020-11-16 17:26:07 +00:00
|
|
|
|
|
|
|
glDeleteTextures (1, &texture_id);
|
|
|
|
|
2020-10-08 16:00:36 +00:00
|
|
|
texture_id = final_texture_id;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-04-22 12:20:02 +00:00
|
|
|
gsk_gl_driver_end_frame (self->gl_driver);
|
2019-04-24 11:28:11 +00:00
|
|
|
|
|
|
|
gdk_gl_context_pop_debug_group (self->gl_context);
|
|
|
|
|
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;
|
|
|
|
|
2020-10-01 07:38:39 +00:00
|
|
|
surface = gsk_renderer_get_surface (renderer);
|
|
|
|
self->scale_factor = gdk_surface_get_scale_factor (surface);
|
|
|
|
|
2019-05-08 16:18:11 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_push_debug_group_printf (self->gl_context,
|
|
|
|
"Render root node %p", root);
|
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
2020-10-01 07:38:39 +00:00
|
|
|
viewport.size.width = whole_surface.width;
|
|
|
|
viewport.size.height = whole_surface.height;
|
2016-12-22 19:01:52 +00:00
|
|
|
|
2019-04-22 12:20:02 +00:00
|
|
|
gsk_gl_driver_begin_frame (self->gl_driver);
|
2018-02-03 18:35:25 +00:00
|
|
|
gsk_gl_renderer_do_render (renderer, root, &viewport, 0, self->scale_factor);
|
2019-04-22 12:20:02 +00:00
|
|
|
gsk_gl_driver_end_frame (self->gl_driver);
|
2016-07-12 13:50:48 +00:00
|
|
|
|
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));
|
2019-05-20 06:47:41 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2018-03-28 13:01:34 +00:00
|
|
|
|
2019-04-24 11:28:11 +00:00
|
|
|
gdk_gl_context_pop_debug_group (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 ();
|
|
|
|
|
2019-04-24 15:55:14 +00:00
|
|
|
ops_init (&self->op_builder);
|
|
|
|
self->op_builder.renderer = self;
|
|
|
|
|
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_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
|
|
|
}
|
2019-05-02 00:13:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_gl_renderer_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GskRenderer using OpenGL. This is the default renderer
|
|
|
|
* used by GTK.
|
|
|
|
*
|
|
|
|
* Returns: a new GL renderer
|
|
|
|
**/
|
|
|
|
GskRenderer *
|
|
|
|
gsk_gl_renderer_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GSK_TYPE_GL_RENDERER, NULL);
|
|
|
|
}
|