All information is kept in GdkDrawContext these days, so use that one.
GDK_IS_MONITOR
</SECTION>
-<SECTION>
-<FILE>gdkdrawingcontext</FILE>
-GdkDrawingContext
-gdk_drawing_context_get_paint_context
-
-<SUBSECTION Standard>
-gdk_drawing_context_get_type
-GdkDrawingContextClass
-GDK_TYPE_DRAWING_CONTEXT
-GDK_DRAWING_CONTEXT_CLASS
-GDK_DRAWING_CONTEXT_GET_CLASS
-GDK_IS_DRAWING_CONTEXT_CLASS
-GDK_DRAWING_CONTEXT
-GDK_IS_DRAWING_CONTEXT
-</SECTION>
-
<SECTION>
<FILE>gdkcairocontext</FILE>
GdkCairoContext
#include <gdk/gdkdisplaymanager.h>
#include <gdk/gdkdnd.h>
#include <gdk/gdkdrawcontext.h>
-#include <gdk/gdkdrawingcontext.h>
#include <gdk/gdkenumtypes.h>
#include <gdk/gdkevents.h>
#include <gdk/gdkframeclock.h>
#include <gdk/gdkversionmacros.h>
#include <gdk/gdkrgba.h>
-#include <gdk/gdkdrawingcontext.h>
#include <gdk/gdkpixbuf.h>
#include <pango/pangocairo.h>
static cairo_t *
gdk_cairo_context_default_cairo_create (GdkCairoContext *self)
{
+ GdkDrawContext *context;
GdkSurface *surface;
- cairo_region_t *region;
cairo_surface_t *cairo_surface;
cairo_t *cr;
g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL);
- surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self));
- if (surface->drawing_context == NULL ||
- gdk_drawing_context_get_paint_context (surface->drawing_context) != GDK_DRAW_CONTEXT (self))
+ context = GDK_DRAW_CONTEXT (self);
+ if (!gdk_draw_context_is_drawing (context))
return NULL;
+ surface = gdk_draw_context_get_surface (context);
cairo_surface = _gdk_surface_ref_cairo_surface (surface);
cr = cairo_create (cairo_surface);
- region = gdk_surface_get_current_paint_region (surface);
- gdk_cairo_region (cr, region);
+ gdk_cairo_region (cr, gdk_draw_context_get_frame_region (context));
cairo_clip (cr);
- cairo_region_destroy (region);
cairo_surface_destroy (cairo_surface);
return cr;
+++ /dev/null
-/* GDK - The GIMP Drawing Kit
- * Copyright 2016 Endless
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * SECTION:gdkdrawingcontext
- * @Title: GdkDrawingContext
- * @Short_description: Drawing context for GDK surfaces
- *
- * #GdkDrawingContext is an object that represents the current drawing
- * state of a #GdkSurface.
- *
- * It's possible to use a #GdkDrawingContext to draw on a #GdkSurface
- * via rendering API like Cairo or OpenGL.
- *
- * A #GdkDrawingContext can only be created by calling gdk_surface_begin_draw_frame()
- * and will be valid until a call to gdk_surface_end_draw_frame().
- *
- * #GdkDrawingContext is available since GDK 3.22
- */
-
-/**
- * GdkDrawingContext:
- *
- * The GdkDrawingContext struct contains only private fields and should not
- * be accessed directly.
- */
-
-#include "config.h"
-
-#include <cairo-gobject.h>
-
-#include "gdkdrawingcontextprivate.h"
-
-#include "gdkrectangle.h"
-#include "gdkinternals.h"
-#include "gdkintl.h"
-#include "gdksurfaceimpl.h"
-#include "gdk-private.h"
-
-typedef struct _GdkDrawingContextPrivate GdkDrawingContextPrivate;
-
-struct _GdkDrawingContextPrivate {
- GdkSurface *surface;
- GdkDrawContext *paint_context;
-
- cairo_t *cr;
-};
-
-G_DEFINE_TYPE_WITH_PRIVATE (GdkDrawingContext, gdk_drawing_context, G_TYPE_OBJECT)
-
-enum {
- PROP_0,
-
- PROP_SURFACE,
- PROP_PAINT_CONTEXT,
-
- N_PROPS
-};
-
-static GParamSpec *obj_property[N_PROPS];
-
-static void
-gdk_drawing_context_dispose (GObject *gobject)
-{
- GdkDrawingContext *self = GDK_DRAWING_CONTEXT (gobject);
- GdkDrawingContextPrivate *priv = gdk_drawing_context_get_instance_private (self);
-
- g_clear_object (&priv->surface);
- g_clear_object (&priv->paint_context);
- g_clear_pointer (&priv->cr, cairo_destroy);
-
- G_OBJECT_CLASS (gdk_drawing_context_parent_class)->dispose (gobject);
-}
-
-static void
-gdk_drawing_context_set_property (GObject *gobject,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GdkDrawingContext *self = GDK_DRAWING_CONTEXT (gobject);
- GdkDrawingContextPrivate *priv = gdk_drawing_context_get_instance_private (self);
-
- switch (prop_id)
- {
- case PROP_SURFACE:
- priv->surface = g_value_dup_object (value);
- if (priv->surface == NULL)
- {
- g_critical ("The drawing context of type %s does not have a surface "
- "associated to it. Drawing contexts can only be created "
- "using gdk_surface_begin_draw_frame().",
- G_OBJECT_TYPE_NAME (gobject));
- return;
- }
- break;
-
- case PROP_PAINT_CONTEXT:
- priv->paint_context = g_value_dup_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
- }
-}
-
-static void
-gdk_drawing_context_get_property (GObject *gobject,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GdkDrawingContext *self = GDK_DRAWING_CONTEXT (gobject);
- GdkDrawingContextPrivate *priv = gdk_drawing_context_get_instance_private (self);
-
- switch (prop_id)
- {
- case PROP_SURFACE:
- g_value_set_object (value, priv->surface);
- break;
-
- case PROP_PAINT_CONTEXT:
- g_value_set_object (value, priv->paint_context);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
- }
-}
-
-static void
-gdk_drawing_context_class_init (GdkDrawingContextClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->set_property = gdk_drawing_context_set_property;
- gobject_class->get_property = gdk_drawing_context_get_property;
- gobject_class->dispose = gdk_drawing_context_dispose;
-
- /**
- * GdkDrawingContext:surface:
- *
- * The #GdkSurface that created the drawing context.
- */
- obj_property[PROP_SURFACE] =
- g_param_spec_object ("surface", "Surface", "The surface that created the context",
- GDK_TYPE_SURFACE,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS);
- /**
- * GdkDrawingContext:paint-context:
- *
- * The #GdkDrawContext used to draw or %NULL if Cairo is used.
- */
- obj_property[PROP_PAINT_CONTEXT] =
- g_param_spec_object ("paint-context", "Paint context", "The context used to draw",
- GDK_TYPE_DRAW_CONTEXT,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (gobject_class, N_PROPS, obj_property);
-}
-
-static void
-gdk_drawing_context_init (GdkDrawingContext *self)
-{
-}
-
-/**
- * gdk_drawing_context_get_paint_context:
- * @context: a #GdkDrawingContext
- *
- * Retrieves the paint context used to draw with.
- *
- * Returns: (transfer none): a #GdkDrawContext or %NULL
- */
-GdkDrawContext *
-gdk_drawing_context_get_paint_context (GdkDrawingContext *context)
-{
- GdkDrawingContextPrivate *priv = gdk_drawing_context_get_instance_private (context);
-
- g_return_val_if_fail (GDK_IS_DRAWING_CONTEXT (context), NULL);
-
- return priv->paint_context;
-}
-
+++ /dev/null
-/* GDK - The GIMP Drawing Kit
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GDK_DRAWING_CONTEXT_H__
-#define __GDK_DRAWING_CONTEXT_H__
-
-#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
-#error "Only <gdk/gdk.h> can be included directly."
-#endif
-
-#include <gdk/gdkversionmacros.h>
-#include <gdk/gdktypes.h>
-
-G_BEGIN_DECLS
-
-#define GDK_TYPE_DRAWING_CONTEXT (gdk_drawing_context_get_type ())
-
-#define GDK_DRAWING_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_DRAWING_CONTEXT, GdkDrawingContext))
-#define GDK_IS_DRAWING_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_DRAWING_CONTEXT))
-
-typedef struct _GdkDrawingContextClass GdkDrawingContextClass;
-
-GDK_AVAILABLE_IN_ALL
-GType gdk_drawing_context_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GdkDrawContext* gdk_drawing_context_get_paint_context (GdkDrawingContext *context);
-
-G_END_DECLS
-
-#endif /* __GDK_DRAWING_CONTEXT_H__ */
+++ /dev/null
-#ifndef __GDK_DRAWING_CONTEXT_PRIVATE_H__
-#define __GDK_DRAWING_CONTEXT_PRIVATE_H__
-
-#include "gdkdrawingcontext.h"
-
-G_BEGIN_DECLS
-
-#define GDK_DRAWING_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_DRAWING_CONTEXT, GdkDrawingContextClass))
-#define GDK_IS_DRAWING_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_DRAWING_CONTEXT))
-#define GDK_DRAWING_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_DRAWING_CONTEXT, GdkDrawingContextClass))
-
-struct _GdkDrawingContext
-{
- GObject parent_instance;
-};
-
-struct _GdkDrawingContextClass
-{
- GObjectClass parent_instance;
-};
-
-G_END_DECLS
-
-#endif /* __GDK_DRAWING_CONTEXT_PRIVATE_H__ */
GdkFrameClock *frame_clock; /* NULL to use from parent or default */
GSList *draw_contexts;
- GdkDrawingContext *drawing_context;
+ GdkDrawContext *paint_context;
cairo_region_t *opaque_region;
};
cairo_region_t *gdk_cairo_region_from_clip (cairo_t *cr);
-void gdk_cairo_set_drawing_context (cairo_t *cr,
- GdkDrawingContext *context);
-
/*************************************
* Interfaces used by windowing code *
*************************************/
int *unscaled_width,
int *unscaled_height);
-GdkDrawingContext *gdk_surface_get_drawing_context (GdkSurface *surface);
-
cairo_region_t *gdk_surface_get_current_paint_region (GdkSurface *surface);
/*****************************************
#include "gdkmarshalers.h"
#include "gdksurfaceimpl.h"
#include "gdkglcontextprivate.h"
-#include "gdkdrawingcontextprivate.h"
#include "gdk-private.h"
#include <math.h>
* @region: a Cairo region
*
* Indicates that you are beginning the process of redrawing @region
- * on @surface, and provides you with a #GdkDrawingContext.
+ * on @surface.
*
* If @surface is a top level #GdkSurface, backed by a native surface
* implementation, a backing store (offscreen buffer) large enough to
* and already has a backing store. Therefore in most cases, application
* code in GTK does not need to call gdk_surface_begin_draw_frame()
* explicitly.
- *
- * Returns: (transfer none): a #GdkDrawingContext context that should be
- * used to draw the contents of the surface; the returned context is owned
- * by GDK.
*/
-GdkDrawingContext *
+void
gdk_surface_begin_draw_frame (GdkSurface *surface,
GdkDrawContext *draw_context,
const cairo_region_t *region)
{
- GdkDrawingContext *context;
-
- g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
- g_return_val_if_fail (gdk_surface_has_native (surface), NULL);
- g_return_val_if_fail (gdk_surface_is_toplevel (surface), NULL);
- g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (draw_context), NULL);
- g_return_val_if_fail (gdk_draw_context_get_surface (draw_context) == surface, NULL);
- g_return_val_if_fail (region != NULL, NULL);
+ g_return_if_fail (GDK_IS_SURFACE (surface));
+ g_return_if_fail (gdk_surface_has_native (surface));
+ g_return_if_fail (gdk_surface_is_toplevel (surface));
+ g_return_if_fail (GDK_IS_DRAW_CONTEXT (draw_context));
+ g_return_if_fail (gdk_draw_context_get_surface (draw_context) == surface);
+ g_return_if_fail (region != NULL);
if (GDK_SURFACE_DESTROYED (surface))
- return NULL;
+ return;
- if (surface->drawing_context != NULL)
+ if (surface->paint_context != NULL)
{
g_critical ("The surface %p already has a drawing context. You cannot "
"call gdk_surface_begin_draw_frame() without calling "
"gdk_surface_end_draw_frame() first.", surface);
- return NULL;
+ return;
}
draw_context->frame_region = cairo_region_copy (region);
gdk_draw_context_begin_frame (draw_context, draw_context->frame_region);
- context = g_object_new (GDK_TYPE_DRAWING_CONTEXT,
- "surface", surface,
- "paint-context", draw_context,
- NULL);
-
- /* Do not take a reference, to avoid creating cycles */
- surface->drawing_context = context;
-
- return context;
+ surface->paint_context = g_object_ref (draw_context);
}
/**
* gdk_surface_end_draw_frame:
* @surface: a #GdkSurface
- * @context: the #GdkDrawingContext created by gdk_surface_begin_draw_frame()
*
* Indicates that the drawing of the contents of @surface started with
* gdk_surface_begin_frame() has been completed.
*
- * This function will take care of destroying the #GdkDrawingContext.
- *
* It is an error to call this function without a matching
* gdk_surface_begin_frame() first.
*/
void
-gdk_surface_end_draw_frame (GdkSurface *surface,
- GdkDrawingContext *context)
+gdk_surface_end_draw_frame (GdkSurface *surface)
{
GdkDrawContext *paint_context;
g_return_if_fail (GDK_IS_SURFACE (surface));
- g_return_if_fail (GDK_IS_DRAWING_CONTEXT (context));
if (GDK_SURFACE_DESTROYED (surface))
return;
- if (surface->drawing_context == NULL)
+ if (surface->paint_context == NULL)
{
g_critical ("The surface %p has no drawing context. You must call "
"gdk_surface_begin_draw_frame() before calling "
"gdk_surface_end_draw_frame().", surface);
return;
}
- g_return_if_fail (surface->drawing_context == context);
- paint_context = gdk_drawing_context_get_paint_context (context);
+ paint_context = g_steal_pointer (&surface->paint_context);
gdk_draw_context_end_frame (paint_context,
paint_context->frame_region,
surface->active_update_area);
- surface->drawing_context = NULL;
-
g_clear_pointer (&paint_context->frame_region, cairo_region_destroy);
- g_object_unref (context);
+ g_object_unref (paint_context);
}
/*< private >
return region;
}
-/*< private >
- * gdk_surface_get_drawing_context:
- * @surface: a #GdkSurface
- *
- * Retrieves the #GdkDrawingContext associated to @surface by
- * gdk_surface_begin_draw_frame().
- *
- * Returns: (transfer none) (nullable): a #GdkDrawingContext, if any is set
- */
-GdkDrawingContext *
-gdk_surface_get_drawing_context (GdkSurface *surface)
-{
- g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
-
- if (GDK_SURFACE_DESTROYED (surface))
- return NULL;
-
- return surface->drawing_context;
-}
-
/* This is used in places like gdk_cairo_set_source_surface and
* other places to take "screenshots" of surfaces. Thus, we allow
* it to be used outside of a begin_paint / end_paint. */
#include <gdk/gdkversionmacros.h>
#include <gdk/gdktypes.h>
-#include <gdk/gdkdrawingcontext.h>
#include <gdk/gdkevents.h>
#include <gdk/gdkframeclock.h>
#include <gdk/gdkmonitor.h>
GdkSurfaceHints geom_mask);
GDK_AVAILABLE_IN_ALL
-GdkDrawingContext *gdk_surface_begin_draw_frame (GdkSurface *surface,
+void gdk_surface_begin_draw_frame (GdkSurface *surface,
GdkDrawContext *context,
const cairo_region_t *region);
GDK_AVAILABLE_IN_ALL
-void gdk_surface_end_draw_frame (GdkSurface *surface,
- GdkDrawingContext *context);
+void gdk_surface_end_draw_frame (GdkSurface *surface);
GDK_AVAILABLE_IN_ALL
void gdk_surface_set_title (GdkSurface *surface,
'gdkdisplaymanager.c',
'gdkdnd.c',
'gdkdrawcontext.c',
- 'gdkdrawingcontext.c',
'gdkevents.c',
'gdkframeclock.c',
'gdkframeclockidle.c',
'gdkdisplaymanager.h',
'gdkdnd.h',
'gdkdrawcontext.h',
- 'gdkdrawingcontext.h',
'gdkevents.h',
'gdkframeclock.h',
'gdkframetimings.h',
gdk_private_h_sources = files([
'gdkeventsprivate.h',
'gdkdevicetoolprivate.h',
- 'gdkdrawingcontextprivate.h',
'gdkmonitorprivate.h',
'gdkseatdefaultprivate.h',
])
GskGLRenderer *self = GSK_GL_RENDERER (renderer);
graphene_rect_t viewport;
const cairo_region_t *damage;
- GdkDrawingContext *context;
GdkRectangle whole_surface;
GdkSurface *surface;
gdk_surface_get_height (surface) * self->scale_factor
};
- context = gdk_surface_begin_draw_frame (surface,
- GDK_DRAW_CONTEXT (self->gl_context),
- update_area);
+ gdk_surface_begin_draw_frame (surface,
+ GDK_DRAW_CONTEXT (self->gl_context),
+ update_area);
damage = gdk_draw_context_get_frame_region (GDK_DRAW_CONTEXT (self->gl_context));
gdk_gl_context_make_current (self->gl_context);
gsk_gl_renderer_clear_tree (self);
- gdk_surface_end_draw_frame (surface, context);
+ gdk_surface_end_draw_frame (surface);
g_clear_pointer (&self->render_region, cairo_region_destroy);
}
GArray *nodes;
GPtrArray *node_textures;
cairo_region_t *whole;
- GdkDrawingContext *context;
GdkSurface *surface;
surface = gsk_renderer_get_surface (self);
gdk_surface_get_width (surface),
gdk_surface_get_height (surface)
});
- context = gdk_surface_begin_draw_frame (surface, NULL, whole);
+ gdk_surface_begin_draw_frame (surface, NULL, whole);
cairo_region_destroy (whole);
nodes = g_array_new (FALSE, FALSE, sizeof(guint32));
g_array_unref (nodes);
g_ptr_array_unref (node_textures);
- gdk_surface_end_draw_frame (surface, context);
+ gdk_surface_end_draw_frame (surface);
}
static void
{
GskCairoRenderer *self = GSK_CAIRO_RENDERER (renderer);
GdkSurface *surface = gsk_renderer_get_surface (renderer);
- GdkDrawingContext *context;
cairo_t *cr;
- context = gdk_surface_begin_draw_frame (surface,
- GDK_DRAW_CONTEXT (self->cairo_context),
- region);
+ gdk_surface_begin_draw_frame (surface,
+ GDK_DRAW_CONTEXT (self->cairo_context),
+ region);
cr = gdk_cairo_context_cairo_create (self->cairo_context);
g_return_if_fail (cr != NULL);
cairo_destroy (cr);
- gdk_surface_end_draw_frame (surface, context);
+ gdk_surface_end_draw_frame (surface);
}
static void
{
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
GskVulkanRender *render;
- GdkDrawingContext *context;
GdkSurface *surface;
const cairo_region_t *clip;
#ifdef G_ENABLE_DEBUG
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
#endif
- context = gdk_surface_begin_draw_frame (surface,
- GDK_DRAW_CONTEXT (self->vulkan),
- region);
+ gdk_surface_begin_draw_frame (surface,
+ GDK_DRAW_CONTEXT (self->vulkan),
+ region);
render = self->render;
clip = gdk_draw_context_get_frame_region (GDK_DRAW_CONTEXT (self->vulkan));
gsk_profiler_push_samples (profiler);
#endif
- gdk_surface_end_draw_frame (surface, context);
+ gdk_surface_end_draw_frame (surface);
}
static void
/* These can't be freely constructed/destroyed */
if (g_type_is_a (type, GTK_TYPE_APPLICATION) ||
g_type_is_a (type, GDK_TYPE_PIXBUF_LOADER) ||
- g_type_is_a (type, GDK_TYPE_DRAWING_CONTEXT) ||
#ifdef G_OS_UNIX
g_type_is_a (type, GTK_TYPE_PRINT_JOB) ||
#endif
/* These can't be freely constructed/destroyed */
if (g_type_is_a (type, GTK_TYPE_APPLICATION) ||
g_type_is_a (type, GDK_TYPE_PIXBUF_LOADER) ||
- g_type_is_a (type, GDK_TYPE_DRAWING_CONTEXT) ||
#ifdef G_OS_UNIX
g_type_is_a (type, GTK_TYPE_PRINT_JOB) ||
#endif
#endif
/* Not allowed to finalize a GdkPixbufLoader without calling gdk_pixbuf_loader_close() */
all_types[i] != GDK_TYPE_PIXBUF_LOADER &&
- all_types[i] != GDK_TYPE_DRAWING_CONTEXT &&
all_types[i] != gdk_pixbuf_simple_anim_iter_get_type())
{
gchar *test_path = g_strdup_printf ("/FinalizeObject/%s", g_type_name (all_types[i]));