mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
gdk: Remove all code that only existed because of use_gl
Now that we don't use GL anymore, this code is unnecessary.
This commit is contained in:
parent
77d336de17
commit
bddfd7bb41
359
gdk/gdkgl.c
359
gdk/gdkgl.c
@ -340,18 +340,11 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
|
||||
GdkGLContext *paint_context;
|
||||
cairo_surface_t *image;
|
||||
cairo_matrix_t matrix;
|
||||
int dx, dy, window_scale;
|
||||
gboolean trivial_transform;
|
||||
cairo_surface_t *group_target;
|
||||
GdkWindow *direct_window, *impl_window;
|
||||
guint framebuffer;
|
||||
int alpha_size = 0;
|
||||
cairo_region_t *clip_region;
|
||||
GdkGLContextPaintData *paint_data;
|
||||
|
||||
impl_window = window->impl_window;
|
||||
|
||||
window_scale = gdk_window_get_scale_factor (impl_window);
|
||||
int major, minor, version;
|
||||
|
||||
paint_context = gdk_window_get_paint_gl_context (window, NULL);
|
||||
if (paint_context == NULL)
|
||||
@ -388,324 +381,71 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
|
||||
return;
|
||||
}
|
||||
|
||||
group_target = cairo_get_group_target (cr);
|
||||
direct_window = cairo_surface_get_user_data (group_target, &direct_key);
|
||||
|
||||
cairo_get_matrix (cr, &matrix);
|
||||
|
||||
dx = matrix.x0;
|
||||
dy = matrix.y0;
|
||||
gdk_gl_context_get_version (paint_context, &major, &minor);
|
||||
version = major * 100 + minor;
|
||||
|
||||
/* Trivial == integer-only translation */
|
||||
trivial_transform =
|
||||
(double)dx == matrix.x0 && (double)dy == matrix.y0 &&
|
||||
matrix.xx == 1.0 && matrix.xy == 0.0 &&
|
||||
matrix.yx == 0.0 && matrix.yy == 1.0;
|
||||
/* TODO: Use glTexSubImage2D() and do a row-by-row copy to replace
|
||||
* the GL_UNPACK_ROW_LENGTH support
|
||||
*/
|
||||
if (gdk_gl_context_get_use_es (paint_context) &&
|
||||
!(version >= 300 || gdk_gl_context_has_unpack_subimage (paint_context)))
|
||||
goto out;
|
||||
|
||||
/* For direct paint of non-alpha renderbuffer, we can
|
||||
just do a bitblit */
|
||||
if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_GL) == 0 &&
|
||||
source_type == GL_RENDERBUFFER &&
|
||||
alpha_size == 0 &&
|
||||
direct_window != NULL &&
|
||||
direct_window->current_paint.use_gl &&
|
||||
trivial_transform &&
|
||||
clip_region != NULL)
|
||||
/* TODO: avoid reading back non-required data due to dest clip */
|
||||
image = cairo_surface_create_similar_image (cairo_get_target (cr),
|
||||
(alpha_size == 0) ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32,
|
||||
width, height);
|
||||
|
||||
cairo_surface_set_device_scale (image, buffer_scale, buffer_scale);
|
||||
|
||||
framebuffer = paint_data->tmp_framebuffer;
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
|
||||
if (source_type == GL_RENDERBUFFER)
|
||||
{
|
||||
int unscaled_window_height;
|
||||
int i;
|
||||
|
||||
/* Create a framebuffer with the source renderbuffer and
|
||||
make it the current target for reads */
|
||||
framebuffer = paint_data->tmp_framebuffer;
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_RENDERBUFFER_EXT, source);
|
||||
glBindFramebufferEXT (GL_DRAW_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
/* Translate to impl coords */
|
||||
cairo_region_translate (clip_region, dx, dy);
|
||||
|
||||
glEnable (GL_SCISSOR_TEST);
|
||||
|
||||
gdk_window_get_unscaled_size (impl_window, NULL, &unscaled_window_height);
|
||||
|
||||
/* We can use glDrawBuffer on OpenGL only; on GLES 2.0 we are already
|
||||
* double buffered so we don't need it...
|
||||
*/
|
||||
if (!gdk_gl_context_get_use_es (paint_context))
|
||||
glDrawBuffer (GL_BACK);
|
||||
else
|
||||
{
|
||||
int maj, min;
|
||||
|
||||
gdk_gl_context_get_version (paint_context, &maj, &min);
|
||||
|
||||
/* ... but on GLES 3.0 we can use the vectorized glDrawBuffers
|
||||
* call.
|
||||
*/
|
||||
if ((maj * 100 + min) >= 300)
|
||||
{
|
||||
static const GLenum buffers[] = { GL_BACK };
|
||||
|
||||
glDrawBuffers (G_N_ELEMENTS (buffers), buffers);
|
||||
}
|
||||
}
|
||||
|
||||
#define FLIP_Y(_y) (unscaled_window_height - (_y))
|
||||
|
||||
for (i = 0; i < cairo_region_num_rectangles (clip_region); i++)
|
||||
{
|
||||
cairo_rectangle_int_t clip_rect, dest;
|
||||
|
||||
cairo_region_get_rectangle (clip_region, i, &clip_rect);
|
||||
clip_rect.x *= window_scale;
|
||||
clip_rect.y *= window_scale;
|
||||
clip_rect.width *= window_scale;
|
||||
clip_rect.height *= window_scale;
|
||||
|
||||
glScissor (clip_rect.x, FLIP_Y (clip_rect.y + clip_rect.height),
|
||||
clip_rect.width, clip_rect.height);
|
||||
|
||||
dest.x = dx * window_scale;
|
||||
dest.y = dy * window_scale;
|
||||
dest.width = width * window_scale / buffer_scale;
|
||||
dest.height = height * window_scale / buffer_scale;
|
||||
|
||||
if (gdk_rectangle_intersect (&clip_rect, &dest, &dest))
|
||||
{
|
||||
int clipped_src_x = x + (dest.x - dx * window_scale);
|
||||
int clipped_src_y = y + (height - dest.height - (dest.y - dy * window_scale));
|
||||
glBlitFramebufferEXT(clipped_src_x, clipped_src_y,
|
||||
(clipped_src_x + dest.width), (clipped_src_y + dest.height),
|
||||
dest.x, FLIP_Y(dest.y + dest.height),
|
||||
dest.x + dest.width, FLIP_Y(dest.y),
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
if (impl_window->current_paint.flushed_region)
|
||||
{
|
||||
cairo_rectangle_int_t flushed_rect;
|
||||
|
||||
flushed_rect.x = dest.x / window_scale;
|
||||
flushed_rect.y = dest.y / window_scale;
|
||||
flushed_rect.width = (dest.x + dest.width + window_scale - 1) / window_scale - flushed_rect.x;
|
||||
flushed_rect.height = (dest.y + dest.height + window_scale - 1) / window_scale - flushed_rect.y;
|
||||
|
||||
cairo_region_union_rectangle (impl_window->current_paint.flushed_region,
|
||||
&flushed_rect);
|
||||
cairo_region_subtract_rectangle (impl_window->current_paint.need_blend_region,
|
||||
&flushed_rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glDisable (GL_SCISSOR_TEST);
|
||||
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
#undef FLIP_Y
|
||||
|
||||
}
|
||||
/* For direct paint of alpha or non-alpha textures we can use texturing */
|
||||
else if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_GL) == 0 &&
|
||||
source_type == GL_TEXTURE &&
|
||||
direct_window != NULL &&
|
||||
direct_window->current_paint.use_gl &&
|
||||
trivial_transform &&
|
||||
clip_region != NULL)
|
||||
{
|
||||
int unscaled_window_height;
|
||||
GLint texture_width;
|
||||
GLint texture_height;
|
||||
int i, n_rects, n_quads;
|
||||
GdkTexturedQuad *quads;
|
||||
cairo_rectangle_int_t clip_rect;
|
||||
|
||||
/* Translate to impl coords */
|
||||
cairo_region_translate (clip_region, dx, dy);
|
||||
|
||||
if (alpha_size != 0)
|
||||
{
|
||||
cairo_region_t *opaque_region, *blend_region;
|
||||
|
||||
opaque_region = cairo_region_copy (clip_region);
|
||||
cairo_region_subtract (opaque_region, impl_window->current_paint.flushed_region);
|
||||
cairo_region_subtract (opaque_region, impl_window->current_paint.need_blend_region);
|
||||
|
||||
if (!cairo_region_is_empty (opaque_region))
|
||||
gdk_gl_texture_from_surface (impl_window->current_paint.surface,
|
||||
opaque_region);
|
||||
|
||||
blend_region = cairo_region_copy (clip_region);
|
||||
cairo_region_intersect (blend_region, impl_window->current_paint.need_blend_region);
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
if (!cairo_region_is_empty (blend_region))
|
||||
gdk_gl_texture_from_surface (impl_window->current_paint.surface,
|
||||
blend_region);
|
||||
|
||||
cairo_region_destroy (opaque_region);
|
||||
cairo_region_destroy (blend_region);
|
||||
}
|
||||
|
||||
glBindTexture (GL_TEXTURE_2D, source);
|
||||
|
||||
if (gdk_gl_context_get_use_es (paint_context))
|
||||
{
|
||||
texture_width = width;
|
||||
texture_height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texture_width);
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texture_height);
|
||||
}
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glEnable (GL_SCISSOR_TEST);
|
||||
|
||||
gdk_window_get_unscaled_size (impl_window, NULL, &unscaled_window_height);
|
||||
|
||||
#define FLIP_Y(_y) (unscaled_window_height - (_y))
|
||||
|
||||
cairo_region_get_extents (clip_region, &clip_rect);
|
||||
|
||||
glScissor (clip_rect.x * window_scale, FLIP_Y ((clip_rect.y + clip_rect.height) * window_scale),
|
||||
clip_rect.width * window_scale, clip_rect.height * window_scale);
|
||||
|
||||
n_quads = 0;
|
||||
n_rects = cairo_region_num_rectangles (clip_region);
|
||||
quads = g_new (GdkTexturedQuad, n_rects);
|
||||
for (i = 0; i < n_rects; i++)
|
||||
{
|
||||
cairo_rectangle_int_t dest;
|
||||
|
||||
cairo_region_get_rectangle (clip_region, i, &clip_rect);
|
||||
|
||||
clip_rect.x *= window_scale;
|
||||
clip_rect.y *= window_scale;
|
||||
clip_rect.width *= window_scale;
|
||||
clip_rect.height *= window_scale;
|
||||
|
||||
dest.x = dx * window_scale;
|
||||
dest.y = dy * window_scale;
|
||||
dest.width = width * window_scale / buffer_scale;
|
||||
dest.height = height * window_scale / buffer_scale;
|
||||
|
||||
if (gdk_rectangle_intersect (&clip_rect, &dest, &dest))
|
||||
{
|
||||
int clipped_src_x = x + (dest.x - dx * window_scale);
|
||||
int clipped_src_y = y + (height - dest.height - (dest.y - dy * window_scale));
|
||||
GdkTexturedQuad quad = {
|
||||
dest.x, FLIP_Y(dest.y),
|
||||
dest.x + dest.width, FLIP_Y(dest.y + dest.height),
|
||||
clipped_src_x / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height,
|
||||
(clipped_src_x + dest.width) / (float)texture_width, clipped_src_y / (float)texture_height,
|
||||
};
|
||||
|
||||
quads[n_quads++] = quad;
|
||||
|
||||
if (impl_window->current_paint.flushed_region)
|
||||
{
|
||||
cairo_rectangle_int_t flushed_rect;
|
||||
|
||||
flushed_rect.x = dest.x / window_scale;
|
||||
flushed_rect.y = dest.y / window_scale;
|
||||
flushed_rect.width = (dest.x + dest.width + window_scale - 1) / window_scale - flushed_rect.x;
|
||||
flushed_rect.height = (dest.y + dest.height + window_scale - 1) / window_scale - flushed_rect.y;
|
||||
|
||||
cairo_region_union_rectangle (impl_window->current_paint.flushed_region,
|
||||
&flushed_rect);
|
||||
cairo_region_subtract_rectangle (impl_window->current_paint.need_blend_region,
|
||||
&flushed_rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n_quads > 0)
|
||||
gdk_gl_texture_quads (paint_context, GL_TEXTURE_2D, n_quads, quads, FALSE);
|
||||
|
||||
g_free (quads);
|
||||
|
||||
if (alpha_size != 0)
|
||||
glDisable (GL_BLEND);
|
||||
|
||||
#undef FLIP_Y
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Software fallback */
|
||||
int major, minor, version;
|
||||
|
||||
gdk_gl_context_get_version (paint_context, &major, &minor);
|
||||
version = major * 100 + minor;
|
||||
|
||||
/* TODO: Use glTexSubImage2D() and do a row-by-row copy to replace
|
||||
* the GL_UNPACK_ROW_LENGTH support
|
||||
*/
|
||||
if (gdk_gl_context_get_use_es (paint_context) &&
|
||||
!(version >= 300 || gdk_gl_context_has_unpack_subimage (paint_context)))
|
||||
goto out;
|
||||
|
||||
/* TODO: avoid reading back non-required data due to dest clip */
|
||||
image = cairo_surface_create_similar_image (cairo_get_target (cr),
|
||||
(alpha_size == 0) ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32,
|
||||
width, height);
|
||||
|
||||
cairo_surface_set_device_scale (image, buffer_scale, buffer_scale);
|
||||
|
||||
framebuffer = paint_data->tmp_framebuffer;
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer);
|
||||
|
||||
if (source_type == GL_RENDERBUFFER)
|
||||
{
|
||||
/* Create a framebuffer with the source renderbuffer and
|
||||
make it the current target for reads */
|
||||
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_RENDERBUFFER_EXT, source);
|
||||
}
|
||||
else
|
||||
{
|
||||
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, source, 0);
|
||||
}
|
||||
|
||||
glPixelStorei (GL_PACK_ALIGNMENT, 4);
|
||||
glPixelStorei (GL_PACK_ROW_LENGTH, cairo_image_surface_get_stride (image) / 4);
|
||||
|
||||
/* The implicit format conversion is going to make this path slower */
|
||||
if (!gdk_gl_context_get_use_es (paint_context))
|
||||
glReadPixels (x, y, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
|
||||
cairo_image_surface_get_data (image));
|
||||
else
|
||||
glReadPixels (x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
cairo_image_surface_get_data (image));
|
||||
|
||||
glPixelStorei (GL_PACK_ROW_LENGTH, 0);
|
||||
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
cairo_surface_mark_dirty (image);
|
||||
|
||||
/* Invert due to opengl having different origin */
|
||||
cairo_scale (cr, 1, -1);
|
||||
cairo_translate (cr, 0, -height / buffer_scale);
|
||||
|
||||
cairo_set_source_surface (cr, image, 0, 0);
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_surface_destroy (image);
|
||||
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, source, 0);
|
||||
}
|
||||
|
||||
glPixelStorei (GL_PACK_ALIGNMENT, 4);
|
||||
glPixelStorei (GL_PACK_ROW_LENGTH, cairo_image_surface_get_stride (image) / 4);
|
||||
|
||||
/* The implicit format conversion is going to make this path slower */
|
||||
if (!gdk_gl_context_get_use_es (paint_context))
|
||||
glReadPixels (x, y, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
|
||||
cairo_image_surface_get_data (image));
|
||||
else
|
||||
glReadPixels (x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
cairo_image_surface_get_data (image));
|
||||
|
||||
glPixelStorei (GL_PACK_ROW_LENGTH, 0);
|
||||
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
cairo_surface_mark_dirty (image);
|
||||
|
||||
/* Invert due to opengl having different origin */
|
||||
cairo_scale (cr, 1, -1);
|
||||
cairo_translate (cr, 0, -height / buffer_scale);
|
||||
|
||||
cairo_set_source_surface (cr, image, 0, 0);
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_surface_destroy (image);
|
||||
|
||||
out:
|
||||
if (clip_region)
|
||||
cairo_region_destroy (clip_region);
|
||||
|
||||
}
|
||||
|
||||
/* This is always called with the paint context current */
|
||||
@ -726,6 +466,7 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface,
|
||||
float umax, vmax;
|
||||
gboolean use_texture_rectangle;
|
||||
guint target;
|
||||
|
||||
paint_context = gdk_gl_context_get_current ();
|
||||
if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_SURFACE) == 0 &&
|
||||
paint_context &&
|
||||
|
@ -187,74 +187,6 @@ struct _GdkWindow
|
||||
GList children_list_node;
|
||||
GList *native_children;
|
||||
|
||||
/* The paint logic here is a bit complex because of our intermingling of
|
||||
* cairo and GL. Let's first go over the cairo-alone case:
|
||||
*
|
||||
* 1) gdk_window_begin_paint_region() is called with an update region. If
|
||||
* the backend wants it, we redirect drawing to a temporary surface
|
||||
* sized the same as the update region and set `surface_needs_composite`
|
||||
* to TRUE. Otherwise, we paint directly onto the real server-side window.
|
||||
*
|
||||
* 2) Things paint with cairo using GdkDrawingContext
|
||||
*
|
||||
* 3) When everything is painted, the user calls gdk_window_end_paint().
|
||||
* If there was a temporary surface, this is composited back onto the
|
||||
* real backing surface in the appropriate places.
|
||||
*
|
||||
* This is similar to double buffering, except we only have partial surfaces
|
||||
* of undefined contents, and instead of swapping between two buffers, we
|
||||
* create a new temporary buffer every time.
|
||||
*
|
||||
* When we add GL to the mix, we have this instead:
|
||||
*
|
||||
* 1) gdk_window_begin_paint_region() is called with an update region like
|
||||
* before. We always redirect cairo drawing to a temporary surface when
|
||||
* GL is enabled.
|
||||
*
|
||||
* 2) Things paint with cairo using GdkDrawingContext. Whenever
|
||||
* something paints, it calls gdk_window_mark_paint_from_clip() to mark
|
||||
* which regions it has painted in software. We'll learn what this does
|
||||
* soon.
|
||||
*
|
||||
* 3) Something paints with GL and uses gdk_cairo_draw_from_gl() to
|
||||
* composite back into the scene. We paint this onto the backing
|
||||
* store for the window *immediately* by using GL, rather than
|
||||
* painting to the temporary surface, and keep track of the area that
|
||||
* we've painted in `flushed_region`.
|
||||
*
|
||||
* 4) Something paints using software again. It calls
|
||||
* gdk_window_mark_paint_from_clip(), which subtracts the region it
|
||||
* has painted from `flushed_region` and adds the region to
|
||||
* `needs_blended_region`.
|
||||
*
|
||||
* 5) Something paints using GL again, using gdk_cairo_draw_from_gl().
|
||||
* It paints directly to the backing store, removes the region it
|
||||
* painted from `needs_blended_region`, and adds to `flushed_region`.
|
||||
*
|
||||
* 6) gdk_window_end_paint() is called. It composites the temporary surface
|
||||
* back to the window, using GL, except it doesn't bother copying
|
||||
* `flushed_region`, and when it paints `needs_blended_region`, it also
|
||||
* turns on GL blending.
|
||||
*
|
||||
* That means that at any point in time, we have three regions:
|
||||
*
|
||||
* * `region` - This is the original invalidated region and is never
|
||||
* touched.
|
||||
*
|
||||
* * `flushed_region` - This is the portion of `region` that has GL
|
||||
* contents that have been painted directly to the window, and
|
||||
* doesn't have any cairo drawing painted over it.
|
||||
*
|
||||
* * `needs_blended_region` - This is the portion of `region` that
|
||||
* GL contents that have part cairo drawing painted over it.
|
||||
* gdk_window_end_paint() will draw this region using blending.
|
||||
*
|
||||
* `flushed_region` and `needs_blended_region` never intersect, and the
|
||||
* rest of `region` that isn't covered by either is the "opaque region",
|
||||
* which is any area of cairo drawing that didn't ever intersect with GL.
|
||||
* We can paint these from GL without turning on blending.
|
||||
**/
|
||||
|
||||
struct {
|
||||
/* The temporary surface that we're painting to. This will be composited
|
||||
* back into the window when we call end_paint. This is our poor-man's
|
||||
@ -262,11 +194,8 @@ struct _GdkWindow
|
||||
cairo_surface_t *surface;
|
||||
|
||||
cairo_region_t *region;
|
||||
cairo_region_t *flushed_region;
|
||||
cairo_region_t *need_blend_region;
|
||||
|
||||
gboolean surface_needs_composite;
|
||||
gboolean use_gl;
|
||||
} current_paint;
|
||||
GdkGLContext *gl_paint_context;
|
||||
|
||||
|
110
gdk/gdkwindow.c
110
gdk/gdkwindow.c
@ -1874,12 +1874,6 @@ gdk_window_free_current_paint (GdkWindow *window)
|
||||
cairo_region_destroy (window->current_paint.region);
|
||||
window->current_paint.region = NULL;
|
||||
|
||||
cairo_region_destroy (window->current_paint.flushed_region);
|
||||
window->current_paint.flushed_region = NULL;
|
||||
|
||||
cairo_region_destroy (window->current_paint.need_blend_region);
|
||||
window->current_paint.need_blend_region = NULL;
|
||||
|
||||
window->current_paint.surface_needs_composite = FALSE;
|
||||
}
|
||||
|
||||
@ -2719,13 +2713,9 @@ gdk_window_begin_paint_internal (GdkWindow *window,
|
||||
cairo_region_intersect (window->current_paint.region, window->clip_region);
|
||||
cairo_region_get_extents (window->current_paint.region, &clip_box);
|
||||
|
||||
window->current_paint.flushed_region = cairo_region_create ();
|
||||
window->current_paint.need_blend_region = cairo_region_create ();
|
||||
|
||||
surface_content = gdk_window_get_content (window);
|
||||
|
||||
window->current_paint.use_gl = FALSE;
|
||||
|
||||
#if 0
|
||||
if (window->current_paint.use_gl)
|
||||
{
|
||||
GdkGLContext *context;
|
||||
@ -2757,6 +2747,7 @@ gdk_window_begin_paint_internal (GdkWindow *window,
|
||||
glViewport (0, 0, ww, wh);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (needs_surface)
|
||||
{
|
||||
@ -2806,11 +2797,10 @@ gdk_window_end_paint_internal (GdkWindow *window)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
|
||||
#if 0
|
||||
if (window->current_paint.use_gl)
|
||||
{
|
||||
cairo_region_t *opaque_region = cairo_region_copy (window->current_paint.region);
|
||||
cairo_region_subtract (opaque_region, window->current_paint.flushed_region);
|
||||
cairo_region_subtract (opaque_region, window->current_paint.need_blend_region);
|
||||
|
||||
gdk_gl_context_make_current (window->gl_paint_context);
|
||||
|
||||
@ -2831,23 +2821,21 @@ gdk_window_end_paint_internal (GdkWindow *window)
|
||||
window->current_paint.region,
|
||||
window->active_update_area);
|
||||
}
|
||||
else
|
||||
{
|
||||
surface = gdk_window_ref_impl_surface (window);
|
||||
cr = cairo_create (surface);
|
||||
#endif
|
||||
surface = gdk_window_ref_impl_surface (window);
|
||||
cr = cairo_create (surface);
|
||||
|
||||
cairo_set_source_surface (cr, window->current_paint.surface, 0, 0);
|
||||
gdk_cairo_region (cr, window->current_paint.region);
|
||||
cairo_clip (cr);
|
||||
cairo_set_source_surface (cr, window->current_paint.surface, 0, 0);
|
||||
gdk_cairo_region (cr, window->current_paint.region);
|
||||
cairo_clip (cr);
|
||||
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint (cr);
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_destroy (cr);
|
||||
|
||||
cairo_surface_flush (surface);
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
cairo_surface_flush (surface);
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
|
||||
gdk_window_free_current_paint (window);
|
||||
@ -3007,76 +2995,6 @@ gdk_window_get_drawing_context (GdkWindow *window)
|
||||
return window->drawing_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_window_mark_paint_from_clip:
|
||||
* @window: a #GdkWindow
|
||||
* @cr: a #cairo_t
|
||||
*
|
||||
* If you call this during a paint (e.g. between gdk_window_begin_paint_region()
|
||||
* and gdk_window_end_paint() then GDK will mark the current clip region of the
|
||||
* window as being drawn. This is required when mixing GL rendering via
|
||||
* gdk_cairo_draw_from_gl() and cairo rendering, as otherwise GDK has no way
|
||||
* of knowing when something paints over the GL-drawn regions.
|
||||
*
|
||||
* This is typically called automatically by GTK+ and you don't need
|
||||
* to care about this.
|
||||
*
|
||||
* Since: 3.16
|
||||
**/
|
||||
void
|
||||
gdk_window_mark_paint_from_clip (GdkWindow *window,
|
||||
cairo_t *cr)
|
||||
{
|
||||
cairo_region_t *clip_region;
|
||||
GdkWindow *impl_window = window->impl_window;
|
||||
|
||||
if (impl_window->current_paint.surface == NULL ||
|
||||
cairo_get_target (cr) != impl_window->current_paint.surface)
|
||||
return;
|
||||
|
||||
if (cairo_region_is_empty (impl_window->current_paint.flushed_region))
|
||||
return;
|
||||
|
||||
/* This here seems a bit weird, but basically, we're taking the current
|
||||
clip and applying also the flushed region, and the result is that the
|
||||
new clip is the intersection of these. This is the area where the newly
|
||||
drawn region overlaps a previosly flushed area, which is an area of the
|
||||
double buffer surface that need to be blended OVER the back buffer rather
|
||||
than SRCed. */
|
||||
cairo_save (cr);
|
||||
/* We set the identity matrix here so we get and apply regions in native
|
||||
window coordinates. */
|
||||
cairo_identity_matrix (cr);
|
||||
gdk_cairo_region (cr, impl_window->current_paint.flushed_region);
|
||||
cairo_clip (cr);
|
||||
|
||||
clip_region = gdk_cairo_region_from_clip (cr);
|
||||
if (clip_region == NULL)
|
||||
{
|
||||
/* Failed to represent clip as region, mark all as requiring
|
||||
blend */
|
||||
cairo_region_union (impl_window->current_paint.need_blend_region,
|
||||
impl_window->current_paint.flushed_region);
|
||||
cairo_region_destroy (impl_window->current_paint.flushed_region);
|
||||
impl_window->current_paint.flushed_region = cairo_region_create ();
|
||||
}
|
||||
else
|
||||
{
|
||||
cairo_region_subtract (impl_window->current_paint.flushed_region, clip_region);
|
||||
cairo_region_union (impl_window->current_paint.need_blend_region, clip_region);
|
||||
}
|
||||
cairo_region_destroy (clip_region);
|
||||
|
||||
/* Clear the area on the double buffer surface to transparent so we
|
||||
can start drawing from scratch the area "above" the flushed
|
||||
region */
|
||||
cairo_set_source_rgba (cr, 0, 0, 0, 0);
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_restore (cr);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_window_get_clip_region:
|
||||
* @window: a #GdkWindow
|
||||
|
@ -882,6 +882,7 @@ gdk_window_impl_wayland_begin_paint (GdkWindow *window)
|
||||
static void
|
||||
gdk_window_impl_wayland_end_paint (GdkWindow *window)
|
||||
{
|
||||
#if 0
|
||||
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
|
||||
cairo_rectangle_int_t rect;
|
||||
int i, n;
|
||||
@ -920,6 +921,7 @@ gdk_window_impl_wayland_end_paint (GdkWindow *window)
|
||||
|
||||
impl->pending_commit = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
gdk_wayland_window_sync_margin (window);
|
||||
gdk_wayland_window_sync_opaque_region (window);
|
||||
|
@ -6252,24 +6252,6 @@ gtk_widget_real_mnemonic_activate (GtkWidget *widget,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const cairo_user_data_key_t mark_for_draw_key;
|
||||
|
||||
static gboolean
|
||||
gtk_cairo_is_marked_for_draw (cairo_t *cr)
|
||||
{
|
||||
return cairo_get_user_data (cr, &mark_for_draw_key) != NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cairo_set_marked_for_draw (cairo_t *cr,
|
||||
gboolean marked)
|
||||
{
|
||||
if (marked)
|
||||
cairo_set_user_data (cr, &mark_for_draw_key, GINT_TO_POINTER (1), NULL);
|
||||
else
|
||||
cairo_set_user_data (cr, &mark_for_draw_key, NULL, NULL);
|
||||
}
|
||||
|
||||
static GskRenderer *
|
||||
gtk_widget_get_renderer (GtkWidget *widget)
|
||||
{
|
||||
@ -6333,23 +6315,6 @@ gtk_widget_draw_internal (GtkWidget *widget,
|
||||
gboolean push_group;
|
||||
RenderMode mode;
|
||||
|
||||
/* If this was a cairo_t passed via gtk_widget_draw() then we don't
|
||||
* require a window; otherwise we check for the window associated
|
||||
* to the drawing context and mark it using the clip region of the
|
||||
* Cairo context.
|
||||
*/
|
||||
if (!gtk_cairo_is_marked_for_draw (cr))
|
||||
{
|
||||
GdkDrawingContext *context = gdk_cairo_get_drawing_context (cr);
|
||||
|
||||
if (context != NULL)
|
||||
{
|
||||
event_window = gdk_drawing_context_get_window (context);
|
||||
if (event_window != NULL)
|
||||
gdk_window_mark_paint_from_clip (event_window, cr);
|
||||
}
|
||||
}
|
||||
|
||||
push_group =
|
||||
widget->priv->alpha != 255 && !_gtk_widget_is_toplevel (widget);
|
||||
|
||||
@ -6500,8 +6465,6 @@ void
|
||||
gtk_widget_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
gboolean was_marked;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (!widget->priv->alloc_needed);
|
||||
g_return_if_fail (!widget->priv->alloc_needed_on_child);
|
||||
@ -6509,17 +6472,8 @@ gtk_widget_draw (GtkWidget *widget,
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
was_marked = gtk_cairo_is_marked_for_draw (cr);
|
||||
|
||||
/* We mark the window so that gtk_cairo_should_draw_window()
|
||||
* will always return TRUE, and all GdkWindows get drawn
|
||||
*/
|
||||
gtk_cairo_set_marked_for_draw (cr, TRUE);
|
||||
|
||||
gtk_widget_draw_internal (widget, cr, TRUE);
|
||||
|
||||
gtk_cairo_set_marked_for_draw (cr, was_marked);
|
||||
|
||||
cairo_restore (cr);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user