pixelcache: allow specifying content type and extra size.
Allow forcing the cairo_content_t of the surface as well as the amount of extra size to render. https://bugzilla.gnome.org/show_bug.cgi?id=706728
This commit is contained in:
committed by
Alexander Larsson
parent
576ae1e3c9
commit
b1745d68cd
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
/* The extra size of the offscreen surface we allocate
|
/* The extra size of the offscreen surface we allocate
|
||||||
to make scrolling more efficient */
|
to make scrolling more efficient */
|
||||||
#define EXTRA_SIZE 64
|
#define DEFAULT_EXTRA_SIZE 64
|
||||||
|
|
||||||
/* When resizing viewport to smaller we allow this extra
|
/* When resizing viewport to smaller we allow this extra
|
||||||
size to avoid constantly reallocating when resizing */
|
size to avoid constantly reallocating when resizing */
|
||||||
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
struct _GtkPixelCache {
|
struct _GtkPixelCache {
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
|
cairo_content_t content;
|
||||||
|
|
||||||
/* Valid if surface != NULL */
|
/* Valid if surface != NULL */
|
||||||
int surface_x;
|
int surface_x;
|
||||||
@ -44,6 +45,9 @@ struct _GtkPixelCache {
|
|||||||
cairo_region_t *surface_dirty;
|
cairo_region_t *surface_dirty;
|
||||||
|
|
||||||
guint timeout_tag;
|
guint timeout_tag;
|
||||||
|
|
||||||
|
guint extra_width;
|
||||||
|
guint extra_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkPixelCache *
|
GtkPixelCache *
|
||||||
@ -52,6 +56,8 @@ _gtk_pixel_cache_new ()
|
|||||||
GtkPixelCache *cache;
|
GtkPixelCache *cache;
|
||||||
|
|
||||||
cache = g_new0 (GtkPixelCache, 1);
|
cache = g_new0 (GtkPixelCache, 1);
|
||||||
|
cache->extra_width = DEFAULT_EXTRA_SIZE;
|
||||||
|
cache->extra_height = DEFAULT_EXTRA_SIZE;
|
||||||
|
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
@ -74,6 +80,23 @@ _gtk_pixel_cache_free (GtkPixelCache *cache)
|
|||||||
g_free (cache);
|
g_free (cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_gtk_pixel_cache_set_extra_size (GtkPixelCache *cache,
|
||||||
|
guint extra_width,
|
||||||
|
guint extra_height)
|
||||||
|
{
|
||||||
|
cache->extra_width = extra_width ? extra_width : DEFAULT_EXTRA_SIZE;
|
||||||
|
cache->extra_height = extra_height ? extra_height : DEFAULT_EXTRA_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_gtk_pixel_cache_set_content (GtkPixelCache *cache,
|
||||||
|
cairo_content_t content)
|
||||||
|
{
|
||||||
|
cache->content = content;
|
||||||
|
_gtk_pixel_cache_invalidate (cache, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Region is in canvas coordinates */
|
/* Region is in canvas coordinates */
|
||||||
void
|
void
|
||||||
_gtk_pixel_cache_invalidate (GtkPixelCache *cache,
|
_gtk_pixel_cache_invalidate (GtkPixelCache *cache,
|
||||||
@ -138,21 +161,25 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache *cache,
|
|||||||
cairo_pattern_t *bg;
|
cairo_pattern_t *bg;
|
||||||
double red, green, blue, alpha;
|
double red, green, blue, alpha;
|
||||||
|
|
||||||
content = CAIRO_CONTENT_COLOR_ALPHA;
|
content = cache->content;
|
||||||
bg = gdk_window_get_background_pattern (window);
|
if (!content)
|
||||||
if (bg != NULL &&
|
{
|
||||||
cairo_pattern_get_type (bg) == CAIRO_PATTERN_TYPE_SOLID &&
|
content = CAIRO_CONTENT_COLOR_ALPHA;
|
||||||
cairo_pattern_get_rgba (bg, &red, &green, &blue, &alpha) == CAIRO_STATUS_SUCCESS &&
|
bg = gdk_window_get_background_pattern (window);
|
||||||
alpha == 1.0)
|
if (bg != NULL &&
|
||||||
content = CAIRO_CONTENT_COLOR;
|
cairo_pattern_get_type (bg) == CAIRO_PATTERN_TYPE_SOLID &&
|
||||||
|
cairo_pattern_get_rgba (bg, &red, &green, &blue, &alpha) == CAIRO_STATUS_SUCCESS &&
|
||||||
|
alpha == 1.0)
|
||||||
|
content = CAIRO_CONTENT_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
surface_w = view_rect->width;
|
surface_w = view_rect->width;
|
||||||
if (canvas_rect->width > surface_w)
|
if (canvas_rect->width > surface_w)
|
||||||
surface_w = MIN (surface_w + EXTRA_SIZE, canvas_rect->width);
|
surface_w = MIN (surface_w + cache->extra_width, canvas_rect->width);
|
||||||
|
|
||||||
surface_h = view_rect->height;
|
surface_h = view_rect->height;
|
||||||
if (canvas_rect->height > surface_h)
|
if (canvas_rect->height > surface_h)
|
||||||
surface_h = MIN (surface_h + EXTRA_SIZE, canvas_rect->height);
|
surface_h = MIN (surface_h + cache->extra_height, canvas_rect->height);
|
||||||
|
|
||||||
/* If current surface can't fit view_rect or is too large, kill it */
|
/* If current surface can't fit view_rect or is too large, kill it */
|
||||||
if (cache->surface != NULL &&
|
if (cache->surface != NULL &&
|
||||||
|
|||||||
@ -30,17 +30,22 @@ typedef struct _GtkPixelCache GtkPixelCache;
|
|||||||
typedef void (*GtkPixelCacheDrawFunc) (cairo_t *cr,
|
typedef void (*GtkPixelCacheDrawFunc) (cairo_t *cr,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
GtkPixelCache *_gtk_pixel_cache_new (void);
|
GtkPixelCache *_gtk_pixel_cache_new (void);
|
||||||
void _gtk_pixel_cache_free (GtkPixelCache *cache);
|
void _gtk_pixel_cache_free (GtkPixelCache *cache);
|
||||||
void _gtk_pixel_cache_invalidate (GtkPixelCache *cache,
|
void _gtk_pixel_cache_invalidate (GtkPixelCache *cache,
|
||||||
cairo_region_t *region);
|
cairo_region_t *region);
|
||||||
void _gtk_pixel_cache_draw (GtkPixelCache *cache,
|
void _gtk_pixel_cache_draw (GtkPixelCache *cache,
|
||||||
cairo_t *cr,
|
cairo_t *cr,
|
||||||
GdkWindow *window,
|
GdkWindow *window,
|
||||||
cairo_rectangle_int_t *view_rect,
|
cairo_rectangle_int_t *view_rect,
|
||||||
cairo_rectangle_int_t *canvas_rect,
|
cairo_rectangle_int_t *canvas_rect,
|
||||||
GtkPixelCacheDrawFunc draw,
|
GtkPixelCacheDrawFunc draw,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
void _gtk_pixel_cache_set_extra_size (GtkPixelCache *cache,
|
||||||
|
guint extra_width,
|
||||||
|
guint extra_height);
|
||||||
|
void _gtk_pixel_cache_set_content (GtkPixelCache *cache,
|
||||||
|
cairo_content_t content);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
Reference in New Issue
Block a user