Commit 6a98703c authored by Alexander Larsson's avatar Alexander Larsson
Browse files

gdk: Add gdk_cairo_surface_create_similar

We track the window that each cairo surface is created for, which
allows us to use gdk_window_create_similar_surface() when creating
similar surfaces, even when you don't have access to the GdkWindow.
This will be extra important when we need to create larger surfaces
on HiDPI displays.
parent 59318184
......@@ -459,3 +459,40 @@ gdk_cairo_region_create_from_surface (cairo_surface_t *surface)
return region;
}
static const cairo_user_data_key_t window_key;
static GdkWindow *
_gdk_cairo_surface_get_window (cairo_surface_t *surface)
{
return cairo_surface_get_user_data (surface, &window_key);
}
void
_gdk_cairo_surface_set_window (cairo_surface_t *surface,
GdkWindow *window)
{
cairo_surface_set_user_data (surface, &window_key,
window, NULL);
}
cairo_surface_t *
gdk_cairo_surface_create_similar (cairo_surface_t *surface,
cairo_content_t content,
int width,
int height)
{
GdkWindow *window;
window = _gdk_cairo_surface_get_window (surface);
if (window)
return gdk_window_create_similar_surface (window,
content,
width,
height);
else
return cairo_surface_create_similar (surface,
content,
width,
height);
}
......@@ -66,6 +66,12 @@ GDK_DEPRECATED_IN_3_4_FOR(gdk_cairo_set_source_rgba)
void gdk_cairo_set_source_color (cairo_t *cr,
const GdkColor *color);
GDK_AVAILABLE_IN_3_10
cairo_surface_t * gdk_cairo_surface_create_similar (cairo_surface_t *surface,
cairo_content_t content,
int width,
int height);
G_END_DECLS
#endif /* __GDK_CAIRO_H__ */
......@@ -318,6 +318,8 @@ void gdk_synthesize_window_state (GdkWindow *window,
gboolean _gdk_cairo_surface_extents (cairo_surface_t *surface,
GdkRectangle *extents);
void _gdk_cairo_surface_set_window (cairo_surface_t *surface,
GdkWindow *window);
/*************************************
* Interfaces used by windowing code *
......
......@@ -3094,8 +3094,9 @@ gdk_window_create_cairo_surface (GdkWindow *window,
subsurface = cairo_surface_create_for_rectangle (surface,
window->abs_x,
window->abs_y,
width,
width ,
height);
_gdk_cairo_surface_set_window (subsurface, window);
cairo_surface_destroy (surface);
return subsurface;
}
......@@ -3120,6 +3121,7 @@ _gdk_window_ref_cairo_surface (GdkWindow *window)
window->abs_y,
window->width,
window->height);
_gdk_cairo_surface_set_window (surface, window);
}
else
{
......@@ -3128,6 +3130,7 @@ _gdk_window_ref_cairo_surface (GdkWindow *window)
window->cairo_surface = gdk_window_create_cairo_surface (window,
window->width,
window->height);
_gdk_cairo_surface_set_window (window->cairo_surface, window);
if (window->cairo_surface)
{
......@@ -9225,6 +9228,8 @@ gdk_window_create_similar_surface (GdkWindow * window,
cairo_surface_destroy (window_surface);
_gdk_cairo_surface_set_window (surface, window);
return surface;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment