2016-11-28 16:22:35 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
*
|
|
|
|
* gdkdrawcontext.c: base class for rendering system support
|
|
|
|
*
|
|
|
|
* Copyright © 2016 Benjamin Otte
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkdrawcontextprivate.h"
|
|
|
|
|
2022-09-24 03:11:41 +00:00
|
|
|
#include "gdkdebugprivate.h"
|
2022-09-24 03:33:42 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2019-05-18 17:12:32 +00:00
|
|
|
#include "gdkprofilerprivate.h"
|
2021-09-24 19:11:00 +00:00
|
|
|
#include "gdksurfaceprivate.h"
|
2016-11-28 16:22:35 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkDrawContext:
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Base class for objects implementing different rendering methods.
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* `GdkDrawContext` is the base object used by contexts implementing different
|
|
|
|
* rendering methods, such as [class@Gdk.CairoContext] or [class@Gdk.GLContext].
|
|
|
|
* It provides shared functionality between those contexts.
|
2017-12-26 19:39:24 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* You will always interact with one of those subclasses.
|
2017-12-26 19:39:24 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* A `GdkDrawContext` is always associated with a single toplevel surface.
|
2016-11-28 16:22:35 +00:00
|
|
|
*/
|
2017-12-26 19:39:24 +00:00
|
|
|
|
2016-11-28 16:22:35 +00:00
|
|
|
typedef struct _GdkDrawContextPrivate GdkDrawContextPrivate;
|
|
|
|
|
|
|
|
struct _GdkDrawContextPrivate {
|
2021-07-04 00:43:49 +00:00
|
|
|
GdkDisplay *display;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2016-12-01 00:38:20 +00:00
|
|
|
|
2018-04-23 16:17:29 +00:00
|
|
|
cairo_region_t *frame_region;
|
2016-11-28 16:22:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_DISPLAY,
|
2018-03-20 14:14:10 +00:00
|
|
|
PROP_SURFACE,
|
2016-11-28 16:22:35 +00:00
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *pspecs[LAST_PROP] = { NULL, };
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkDrawContext, gdk_draw_context, G_TYPE_OBJECT)
|
|
|
|
|
2018-04-08 22:35:32 +00:00
|
|
|
static void
|
|
|
|
gdk_draw_context_default_surface_resized (GdkDrawContext *context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-09 21:41:10 +00:00
|
|
|
static void
|
|
|
|
gdk_draw_context_default_empty_frame (GdkDrawContext *context)
|
|
|
|
{
|
2024-01-06 13:59:36 +00:00
|
|
|
g_warning ("FIXME: Implement GdkDrawContext.empty_frame in %s", G_OBJECT_TYPE_NAME (context));
|
2023-11-09 21:41:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 16:22:35 +00:00
|
|
|
static void
|
|
|
|
gdk_draw_context_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
GdkDrawContext *context = GDK_DRAW_CONTEXT (gobject);
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
2018-04-08 22:25:03 +00:00
|
|
|
if (priv->surface)
|
|
|
|
{
|
|
|
|
priv->surface->draw_contexts = g_slist_remove (priv->surface->draw_contexts, context);
|
|
|
|
g_clear_object (&priv->surface);
|
|
|
|
}
|
2021-07-04 00:43:49 +00:00
|
|
|
g_clear_object (&priv->display);
|
2016-11-28 16:22:35 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gdk_draw_context_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_draw_context_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkDrawContext *context = GDK_DRAW_CONTEXT (gobject);
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2021-07-04 00:43:49 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
if (priv->display != NULL)
|
|
|
|
{
|
|
|
|
g_assert (g_value_get_object (value) == NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->display = g_value_dup_object (value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
case PROP_SURFACE:
|
|
|
|
priv->surface = g_value_dup_object (value);
|
2021-07-04 00:43:49 +00:00
|
|
|
if (priv->surface)
|
|
|
|
{
|
|
|
|
priv->surface->draw_contexts = g_slist_prepend (priv->surface->draw_contexts, context);
|
|
|
|
if (priv->display)
|
|
|
|
{
|
|
|
|
g_assert (priv->display == gdk_surface_get_display (priv->surface));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->display = g_object_ref (gdk_surface_get_display (priv->surface));
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 16:22:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_draw_context_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkDrawContext *context = GDK_DRAW_CONTEXT (gobject);
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, gdk_draw_context_get_display (context));
|
|
|
|
break;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
case PROP_SURFACE:
|
|
|
|
g_value_set_object (value, priv->surface);
|
2016-11-28 16:22:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_draw_context_class_init (GdkDrawContextClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = gdk_draw_context_set_property;
|
|
|
|
gobject_class->get_property = gdk_draw_context_get_property;
|
|
|
|
gobject_class->dispose = gdk_draw_context_dispose;
|
|
|
|
|
2018-04-08 22:35:32 +00:00
|
|
|
klass->surface_resized = gdk_draw_context_default_surface_resized;
|
2023-11-09 21:41:10 +00:00
|
|
|
klass->empty_frame = gdk_draw_context_default_empty_frame;
|
2018-04-08 22:35:32 +00:00
|
|
|
|
2016-11-28 16:22:35 +00:00
|
|
|
/**
|
2021-02-25 01:03:48 +00:00
|
|
|
* GdkDrawContext:display: (attributes org.gtk.Property.get=gdk_draw_context_get_display)
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The `GdkDisplay` used to create the `GdkDrawContext`.
|
2016-11-28 16:22:35 +00:00
|
|
|
*/
|
|
|
|
pspecs[PROP_DISPLAY] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("display", NULL, NULL,
|
2016-11-28 16:22:35 +00:00
|
|
|
GDK_TYPE_DISPLAY,
|
2021-07-04 00:43:49 +00:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
2016-11-28 16:22:35 +00:00
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
/**
|
2021-02-25 01:03:48 +00:00
|
|
|
* GdkDrawContext:surface: (attributes org.gtk.Property.get=gdk_draw_context_get_surface)
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The `GdkSurface` the context is bound to.
|
2016-11-28 16:22:35 +00:00
|
|
|
*/
|
2018-03-20 14:14:10 +00:00
|
|
|
pspecs[PROP_SURFACE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("surface", NULL, NULL,
|
2018-03-20 10:40:08 +00:00
|
|
|
GDK_TYPE_SURFACE,
|
2016-11-28 16:22:35 +00:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROP, pspecs);
|
|
|
|
}
|
|
|
|
|
2019-05-18 17:12:32 +00:00
|
|
|
static guint pixels_counter;
|
|
|
|
|
2016-11-28 16:22:35 +00:00
|
|
|
static void
|
|
|
|
gdk_draw_context_init (GdkDrawContext *self)
|
|
|
|
{
|
2019-05-18 17:12:32 +00:00
|
|
|
if (pixels_counter == 0)
|
|
|
|
pixels_counter = gdk_profiler_define_int_counter ("frame pixels", "Pixels drawn per frame");
|
2016-11-28 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 16:24:29 +00:00
|
|
|
/**
|
|
|
|
* gdk_draw_context_is_in_frame:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkDrawContext`
|
|
|
|
*
|
|
|
|
* Returns %TRUE if @context is in the process of drawing to its surface.
|
2016-12-01 00:38:20 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* This is the case between calls to [method@Gdk.DrawContext.begin_frame]
|
|
|
|
* and [method@Gdk.DrawContext.end_frame]. In this situation, drawing commands
|
|
|
|
* may be effecting the contents of the @context's surface.
|
2016-12-01 00:38:20 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: %TRUE if the context is between [method@Gdk.DrawContext.begin_frame]
|
2021-05-18 21:05:26 +00:00
|
|
|
* and [method@Gdk.DrawContext.end_frame] calls.
|
2016-12-01 00:38:20 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2018-04-23 16:24:29 +00:00
|
|
|
gdk_draw_context_is_in_frame (GdkDrawContext *context)
|
2016-12-01 00:38:20 +00:00
|
|
|
{
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
2018-04-23 16:24:29 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), FALSE);
|
|
|
|
|
2018-04-23 16:17:29 +00:00
|
|
|
return priv->frame_region != NULL;
|
2016-12-01 00:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-04-08 22:35:32 +00:00
|
|
|
/*< private >
|
|
|
|
* gdk_draw_context_surface_resized:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkDrawContext`
|
2018-04-08 22:35:32 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Called by the surface the @context belongs to when the size of the surface
|
2018-04-08 22:35:32 +00:00
|
|
|
* changes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gdk_draw_context_surface_resized (GdkDrawContext *context)
|
|
|
|
{
|
|
|
|
GDK_DRAW_CONTEXT_GET_CLASS (context)->surface_resized (context);
|
|
|
|
}
|
|
|
|
|
2016-11-28 16:22:35 +00:00
|
|
|
/**
|
2021-02-25 01:03:48 +00:00
|
|
|
* gdk_draw_context_get_display: (attributes org.gtk.Method.get_property=display)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkDrawContext`
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Retrieves the `GdkDisplay` the @context is created for
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (nullable) (transfer none): the `GdkDisplay`
|
2016-11-28 16:22:35 +00:00
|
|
|
*/
|
|
|
|
GdkDisplay *
|
|
|
|
gdk_draw_context_get_display (GdkDrawContext *context)
|
|
|
|
{
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), NULL);
|
|
|
|
|
2021-07-04 00:43:49 +00:00
|
|
|
return priv->display;
|
2016-11-28 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 01:03:48 +00:00
|
|
|
* gdk_draw_context_get_surface: (attributes org.gtk.Method.get_property=surface)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkDrawContext`
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Retrieves the surface that @context is bound to.
|
2016-11-28 16:22:35 +00:00
|
|
|
*
|
2021-05-20 03:39:18 +00:00
|
|
|
* Returns: (nullable) (transfer none): a `GdkSurface`
|
2016-11-28 16:22:35 +00:00
|
|
|
*/
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurface *
|
2018-03-20 11:05:26 +00:00
|
|
|
gdk_draw_context_get_surface (GdkDrawContext *context)
|
2016-11-28 16:22:35 +00:00
|
|
|
{
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), NULL);
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
return priv->surface;
|
2016-11-28 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
/**
|
|
|
|
* gdk_draw_context_begin_frame:
|
2021-10-20 18:07:37 +00:00
|
|
|
* @context: the `GdkDrawContext` used to draw the frame. The context must
|
|
|
|
* have a surface.
|
2018-04-23 15:28:55 +00:00
|
|
|
* @region: minimum region that should be drawn
|
|
|
|
*
|
|
|
|
* Indicates that you are beginning the process of redrawing @region
|
|
|
|
* on the @context's surface.
|
|
|
|
*
|
|
|
|
* Calling this function begins a drawing operation using @context on the
|
|
|
|
* surface that @context was created from. The actual requirements and
|
|
|
|
* guarantees for the drawing operation vary for different implementations
|
2021-02-21 05:13:57 +00:00
|
|
|
* of drawing, so a [class@Gdk.CairoContext] and a [class@Gdk.GLContext]
|
|
|
|
* need to be treated differently.
|
2018-04-23 15:28:55 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* A call to this function is a requirement for drawing and must be
|
|
|
|
* followed by a call to [method@Gdk.DrawContext.end_frame], which will
|
|
|
|
* complete the drawing operation and ensure the contents become visible
|
|
|
|
* on screen.
|
2018-04-23 15:28:55 +00:00
|
|
|
*
|
|
|
|
* Note that the @region passed to this function is the minimum region that
|
|
|
|
* needs to be drawn and depending on implementation, windowing system and
|
|
|
|
* hardware in use, it might be necessary to draw a larger region. Drawing
|
2021-05-27 00:18:23 +00:00
|
|
|
* implementation must use [method@Gdk.DrawContext.get_frame_region] to
|
2021-02-21 05:13:57 +00:00
|
|
|
* query the region that must be drawn.
|
2018-04-23 15:28:55 +00:00
|
|
|
*
|
2021-01-02 21:34:34 +00:00
|
|
|
* When using GTK, the widget system automatically places calls to
|
2018-04-23 15:28:55 +00:00
|
|
|
* gdk_draw_context_begin_frame() and gdk_draw_context_end_frame() via the
|
2024-01-05 19:02:32 +00:00
|
|
|
* use of [GskRenderer](../gsk4/class.Renderer.html)s, so application code
|
|
|
|
* does not need to call these functions explicitly.
|
2018-04-23 15:28:55 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gdk_draw_context_begin_frame (GdkDrawContext *context,
|
|
|
|
const cairo_region_t *region)
|
|
|
|
{
|
2021-10-20 18:07:37 +00:00
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
g_return_if_fail (GDK_IS_DRAW_CONTEXT (context));
|
2021-10-20 18:07:37 +00:00
|
|
|
g_return_if_fail (priv->surface != NULL);
|
2018-04-23 15:28:55 +00:00
|
|
|
g_return_if_fail (region != NULL);
|
|
|
|
|
2023-06-16 06:00:19 +00:00
|
|
|
gdk_draw_context_begin_frame_full (context, GDK_MEMORY_U8, region);
|
2021-10-02 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2023-06-16 06:00:19 +00:00
|
|
|
* @depth: best depth to render in
|
2021-10-02 20:21:23 +00:00
|
|
|
*
|
2023-06-16 06:00:19 +00:00
|
|
|
* If the given depth is not `GDK_MEMORY_U8`, GDK will see about providing a
|
|
|
|
* rendering target that supports a higher bit depth than 8 bits per channel.
|
|
|
|
* Typically this means a target supporting 16bit floating point pixels, but
|
|
|
|
* that is not guaranteed.
|
2021-10-02 20:21:23 +00:00
|
|
|
*
|
|
|
|
* This is only a request and if the GDK backend does not support HDR rendering
|
|
|
|
* or does not consider it worthwhile, it may choose to not honor the request.
|
2024-01-08 01:43:26 +00:00
|
|
|
* It may also choose to provide a different depth even if it was not requested.
|
2021-10-02 20:21:23 +00:00
|
|
|
* Typically the steps undertaken by a backend are:
|
2021-10-06 16:25:30 +00:00
|
|
|
* 1. Check if high depth is supported by this drawing backend.
|
|
|
|
* 2. Check if the compositor supports high depth.
|
|
|
|
* 3. Check if the compositor prefers regular bit depth. This is usually the case
|
|
|
|
* when the attached monitors do not support high depth content or when the
|
|
|
|
* system is resource constrained.
|
2021-10-02 20:21:23 +00:00
|
|
|
* In either of those cases, the context will usually choose to not honor the request.
|
|
|
|
*
|
2021-10-06 16:25:30 +00:00
|
|
|
* The rendering code must be able to deal with content in any bit depth, no matter
|
2023-06-16 06:00:19 +00:00
|
|
|
* the preference. The depth argument is only a hint and GDK is free
|
2021-10-06 16:25:30 +00:00
|
|
|
* to choose.
|
2021-10-02 20:21:23 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gdk_draw_context_begin_frame_full (GdkDrawContext *context,
|
2023-06-16 06:00:19 +00:00
|
|
|
GdkMemoryDepth depth,
|
2021-10-02 20:21:23 +00:00
|
|
|
const cairo_region_t *region)
|
|
|
|
{
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
if (GDK_SURFACE_DESTROYED (priv->surface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->surface->paint_context != NULL)
|
|
|
|
{
|
|
|
|
if (priv->surface->paint_context == context)
|
|
|
|
{
|
|
|
|
g_critical ("The surface %p is already drawing. You must finish the "
|
|
|
|
"previous drawing operation with gdk_draw_context_end_frame() first.",
|
|
|
|
priv->surface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_critical ("The surface %p is already being drawn by %s %p. "
|
2020-08-21 12:41:13 +00:00
|
|
|
"You cannot draw a surface with multiple contexts at the same time.",
|
2018-04-23 15:28:55 +00:00
|
|
|
priv->surface,
|
|
|
|
G_OBJECT_TYPE_NAME (priv->surface->paint_context), priv->surface->paint_context);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:47:26 +00:00
|
|
|
if (gdk_display_get_debug_flags (priv->display) & GDK_DEBUG_HIGH_DEPTH)
|
2023-06-16 06:00:19 +00:00
|
|
|
depth = GDK_MEMORY_FLOAT32;
|
2021-10-02 20:38:05 +00:00
|
|
|
|
2018-04-23 16:17:29 +00:00
|
|
|
priv->frame_region = cairo_region_copy (region);
|
2018-04-23 15:28:55 +00:00
|
|
|
priv->surface->paint_context = g_object_ref (context);
|
|
|
|
|
2023-06-16 06:00:19 +00:00
|
|
|
GDK_DRAW_CONTEXT_GET_CLASS (context)->begin_frame (context, depth, priv->frame_region);
|
2023-05-13 16:35:02 +00:00
|
|
|
|
|
|
|
cairo_region_intersect_rectangle (priv->frame_region,
|
|
|
|
&(cairo_rectangle_int_t) {
|
|
|
|
0, 0,
|
|
|
|
priv->surface->width, priv->surface->height
|
|
|
|
});
|
2018-04-23 15:28:55 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2019-05-18 17:12:32 +00:00
|
|
|
static gint64
|
|
|
|
region_get_pixels (cairo_region_t *region)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gint64 pixels = 0;
|
|
|
|
|
|
|
|
n = cairo_region_num_rectangles (region);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
cairo_region_get_rectangle (region, i, &rect);
|
|
|
|
pixels += rect.width * rect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixels;
|
|
|
|
}
|
2020-01-29 13:02:16 +00:00
|
|
|
#endif
|
2019-05-18 17:12:32 +00:00
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
/**
|
|
|
|
* gdk_draw_context_end_frame:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkDrawContext`
|
|
|
|
*
|
|
|
|
* Ends a drawing operation started with gdk_draw_context_begin_frame().
|
2018-04-23 15:28:55 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* This makes the drawing available on screen.
|
|
|
|
* See [method@Gdk.DrawContext.begin_frame] for more details about drawing.
|
2018-04-23 15:28:55 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* When using a [class@Gdk.GLContext], this function may call `glFlush()`
|
2018-04-23 15:28:55 +00:00
|
|
|
* implicitly before returning; it is not recommended to call `glFlush()`
|
|
|
|
* explicitly before calling this function.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gdk_draw_context_end_frame (GdkDrawContext *context)
|
|
|
|
{
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAW_CONTEXT (context));
|
2021-10-20 18:07:37 +00:00
|
|
|
g_return_if_fail (priv->surface != NULL);
|
2018-04-23 15:28:55 +00:00
|
|
|
|
|
|
|
if (GDK_SURFACE_DESTROYED (priv->surface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->surface->paint_context == NULL)
|
|
|
|
{
|
|
|
|
g_critical ("The surface %p has no drawing context. You must call "
|
|
|
|
"gdk_draw_context_begin_frame() before calling "
|
|
|
|
"gdk_draw_context_end_frame().", priv->surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (priv->surface->paint_context != context)
|
|
|
|
{
|
|
|
|
g_critical ("The surface %p is not drawn by this context but by %s %p.",
|
|
|
|
priv->surface,
|
|
|
|
G_OBJECT_TYPE_NAME (priv->surface->paint_context), priv->surface->paint_context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-23 21:26:14 +00:00
|
|
|
GDK_DRAW_CONTEXT_GET_CLASS (context)->end_frame (context, priv->frame_region);
|
2018-04-23 15:28:55 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
gdk_profiler_set_int_counter (pixels_counter, region_get_pixels (priv->frame_region));
|
2019-05-18 17:12:32 +00:00
|
|
|
|
2018-04-23 16:17:29 +00:00
|
|
|
g_clear_pointer (&priv->frame_region, cairo_region_destroy);
|
2018-04-23 15:28:55 +00:00
|
|
|
g_clear_object (&priv->surface->paint_context);
|
|
|
|
}
|
|
|
|
|
2018-04-20 22:47:35 +00:00
|
|
|
/**
|
|
|
|
* gdk_draw_context_get_frame_region:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @context: a `GdkDrawContext`
|
2018-04-20 22:47:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Retrieves the region that is currently being repainted.
|
2018-04-20 22:47:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* After a call to [method@Gdk.DrawContext.begin_frame] this function will
|
|
|
|
* return a union of the region passed to that function and the area of the
|
|
|
|
* surface that the @context determined needs to be repainted.
|
2018-04-20 22:47:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* If @context is not in between calls to [method@Gdk.DrawContext.begin_frame]
|
|
|
|
* and [method@Gdk.DrawContext.end_frame], %NULL will be returned.
|
2018-04-20 22:47:35 +00:00
|
|
|
*
|
2021-05-18 21:05:26 +00:00
|
|
|
* Returns: (transfer none) (nullable): a Cairo region
|
2018-04-20 22:47:35 +00:00
|
|
|
*/
|
|
|
|
const cairo_region_t *
|
|
|
|
gdk_draw_context_get_frame_region (GdkDrawContext *context)
|
|
|
|
{
|
2018-04-23 16:17:29 +00:00
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
2018-04-20 22:47:35 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), NULL);
|
|
|
|
|
2018-04-23 16:17:29 +00:00
|
|
|
return priv->frame_region;
|
2018-04-20 22:47:35 +00:00
|
|
|
}
|
2023-11-09 21:41:10 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gdk_draw_context_empty_frame (GdkDrawContext *context)
|
|
|
|
{
|
|
|
|
GdkDrawContextPrivate *priv = gdk_draw_context_get_instance_private (context);
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAW_CONTEXT (context));
|
|
|
|
g_return_if_fail (priv->surface != NULL);
|
|
|
|
|
|
|
|
if (GDK_SURFACE_DESTROYED (priv->surface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
GDK_DRAW_CONTEXT_GET_CLASS (context)->empty_frame (context);
|
|
|
|
}
|