summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2011-10-13 23:22:06 -0700
committerBenjamin Otte <otte@redhat.com>2011-10-15 00:06:22 -0700
commit8ad98d256e72b91ddfaa581454390572067c30c4 (patch)
treebca6b0078505f47b6851ef7ed96843124c2cc10a
parent90501e6c5b0e4aa911fad1c02adb3efc90b8582a (diff)
graphic: Remove support for caching
Cairo is fast, yadayada...
-rw-r--r--games/pacman/pacman-graphic.c10
-rw-r--r--libgame/game-animation.c23
-rw-r--r--libgame/game-board.c1
-rw-r--r--libgame/game-graphic.c99
-rw-r--r--libgame/game-graphic.h4
-rw-r--r--libgame/game-viewport.c1
6 files changed, 1 insertions, 137 deletions
diff --git a/games/pacman/pacman-graphic.c b/games/pacman/pacman-graphic.c
index a4a5151..ab440d8 100644
--- a/games/pacman/pacman-graphic.c
+++ b/games/pacman/pacman-graphic.c
@@ -75,15 +75,6 @@ pacman_graphic_draw (GameGraphic *graphic, cairo_t *cr, const GameRectangle *are
cairo_fill (cr);
}
-static cairo_pattern_t *
-pacman_graphic_create_cache (GameGraphic *graphic, cairo_t *cr)
-{
- if (PACMAN_GRAPHIC (graphic)->animate)
- return NULL;
-
- return GAME_GRAPHIC_CLASS (parent_class)->create_cache (graphic, cr);
-}
-
static void
pacman_graphic_get_property (GObject *object, guint param_id,
GValue *value, GParamSpec *pspec)
@@ -172,7 +163,6 @@ pacman_graphic_class_init (gpointer g_class, gpointer class_data)
gameobject_class->tick_func = pacman_graphic_tick;
graphic_class->draw = pacman_graphic_draw;
- graphic_class->create_cache = pacman_graphic_create_cache;
}
static void
diff --git a/libgame/game-animation.c b/libgame/game-animation.c
index bc67d67..97908cc 100644
--- a/libgame/game-animation.c
+++ b/libgame/game-animation.c
@@ -168,32 +168,11 @@ game_animation_tick (GameObject *object)
game_animation_update_image (anim, frame->surface);
}
-static cairo_pattern_t *
-game_animation_create_cache (GameGraphic *graphic, cairo_t *cr)
-{
- GameAnimationFrame *frame;
- GameAnimation *anim = GAME_ANIMATION (graphic);
-
- frame = &g_array_index(anim->frames, GameAnimationFrame, anim->current);
-
- if (frame->cache) {
- if (game_cairo_pattern_matches (cr, frame->cache)) {
- cairo_pattern_reference (frame->cache);
- return frame->cache;
- }
- cairo_pattern_destroy (frame->cache);
- //frame->cache = NULL;
- }
- frame->cache = GAME_GRAPHIC_CLASS (parent_class)->create_cache (graphic, cr);
- return frame->cache;
-}
-
static void
game_animation_class_init (gpointer g_class, gpointer class_data)
{
GObjectClass *object_class = G_OBJECT_CLASS (g_class);
GameObjectClass *gameobject_class = GAME_OBJECT_CLASS (g_class);
- GameGraphicClass *graphic_class = GAME_GRAPHIC_CLASS (g_class);
parent_class = g_type_class_peek_parent (g_class);
@@ -208,8 +187,6 @@ game_animation_class_init (gpointer g_class, gpointer class_data)
gameobject_class->copy = game_animation_copy;
gameobject_class->tick_func = game_animation_tick;
-
- graphic_class->create_cache = game_animation_create_cache;
}
static void
diff --git a/libgame/game-board.c b/libgame/game-board.c
index b24b23b..775d8ae 100644
--- a/libgame/game-board.c
+++ b/libgame/game-board.c
@@ -255,7 +255,6 @@ game_board_class_init (gpointer g_class, gpointer class_data)
gameobject_class->game_set = game_board_game_set;
graphic_class->draw = game_board_draw;
- graphic_class->create_cache = NULL;
}
static void
diff --git a/libgame/game-graphic.c b/libgame/game-graphic.c
index c73b55b..eb2e056 100644
--- a/libgame/game-graphic.c
+++ b/libgame/game-graphic.c
@@ -122,69 +122,11 @@ game_graphic_copy (GameObject *odest, GameObject *osrc)
return GAME_OBJECT_CLASS (parent_class)->copy (odest, osrc);
}
-static cairo_pattern_t *
-game_graphic_do_create_cache (GameGraphic *graphic, cairo_t *cr)
-{
- cairo_matrix_t matrix;
- cairo_t *crc;
- cairo_surface_t *cache;
- cairo_pattern_t *pattern;
- double width, height;
-
- g_return_val_if_fail (GAME_IS_GRAPHIC (graphic), NULL);
- g_return_val_if_fail (cr != NULL, NULL);
-
- cairo_get_matrix (cr, &matrix);
- if (!GAME_DOUBLE_EQUAL (matrix.xy, 0.0) ||
- !GAME_DOUBLE_EQUAL (matrix.xy, 0.0))
- return NULL;
-
- width = graphic->rect.x2 - graphic->rect.x1;
- height = graphic->rect.y2 - graphic->rect.y1;
-#if 1
- cache = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA, ceil (matrix.xx * width),
- ceil (matrix.yy * height));
-#else
- cache = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- ceil (matrix.xx * width), ceil (matrix.yy * height));
-#endif
- if (cairo_surface_status (cache) != CAIRO_STATUS_SUCCESS) {
- cairo_surface_destroy (cache);
- return NULL;
- }
- crc = cairo_create (cache);
- /* clear surface */
- cairo_save (crc);
- cairo_set_operator (crc, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_rgba (crc, 0.0, 0.0, 0.0, 0.0);
- cairo_paint (crc);
- cairo_restore (crc);
-
- cairo_scale (crc, matrix.xx, matrix.yy);
- cairo_translate (crc, - graphic->rect.x1, - graphic->rect.y1);
- if (!game_graphic_draw_area_no_cache (graphic, crc, &graphic->rect)) {
- cairo_surface_destroy (cache);
- cairo_destroy (crc);
- return NULL;
- }
-
- pattern = cairo_pattern_create_for_surface (cache);
- cairo_get_matrix (crc, &matrix);
- cairo_pattern_set_matrix (pattern, &matrix);
-
- cairo_surface_destroy (cache);
- cairo_destroy (crc);
-
- return pattern;
-}
-
static void
game_graphic_class_init (gpointer g_class, gpointer class_data)
{
GObjectClass *object_class = G_OBJECT_CLASS (g_class);
GameObjectClass *gameobject_class = GAME_OBJECT_CLASS (g_class);
- GameGraphicClass *graphic_class = GAME_GRAPHIC_CLASS (g_class);
parent_class = g_type_class_peek_parent (g_class);
@@ -216,8 +158,6 @@ game_graphic_class_init (gpointer g_class, gpointer class_data)
gameobject_class->copy = game_graphic_copy;
gameobject_class->to_string = game_graphic_to_string;
-
- graphic_class->create_cache = game_graphic_do_create_cache;
}
static void
@@ -318,7 +258,6 @@ game_graphic_draw_area (GameGraphic *graphic, cairo_t *cr, const
GameRectangle *rect)
{
GameRectangle inval;
- cairo_pattern_t *cache;
g_return_val_if_fail (GAME_IS_GRAPHIC (graphic), FALSE);
g_return_val_if_fail (cr != NULL, FALSE);
@@ -327,43 +266,7 @@ game_graphic_draw_area (GameGraphic *graphic, cairo_t *cr, const
if (!game_rectangle_intersect (&inval, &graphic->rect, rect))
return TRUE;
- cache = game_graphic_get_cache (graphic, cr);
- if (graphic->cache != cache) {
- game_graphic_invalidate_cache (graphic);
- graphic->cache = cache;
- if (cache)
- cairo_pattern_reference (cache);
- }
- if (graphic->cache == NULL)
- return game_graphic_draw_area_no_cache (graphic, cr, rect);
- cairo_save (cr);
- cairo_set_source (cr, graphic->cache);
- cairo_paint (cr);
- cairo_restore (cr);
- return TRUE;
-}
-
-cairo_pattern_t *
-game_graphic_get_cache (GameGraphic *graphic, cairo_t *cr)
-{
- GameGraphicClass *klass;
- cairo_pattern_t *cache;
-
- g_return_val_if_fail (GAME_IS_GRAPHIC (graphic), NULL);
- g_return_val_if_fail (cr != NULL, NULL);
-
- if (graphic->cache != NULL &&
- game_cairo_pattern_matches (cr, graphic->cache)) {
- cairo_pattern_reference (graphic->cache);
- return graphic->cache;
- }
- klass = GAME_GRAPHIC_GET_CLASS (graphic);
- if (klass->create_cache)
- cache = klass->create_cache (graphic, cr);
- else
- cache = NULL;
-
- return cache;
+ return game_graphic_draw_area_no_cache (graphic, cr, rect);
}
gboolean
diff --git a/libgame/game-graphic.h b/libgame/game-graphic.h
index 5de098a..72babc6 100644
--- a/libgame/game-graphic.h
+++ b/libgame/game-graphic.h
@@ -56,8 +56,6 @@ struct _GameGraphicClass {
void (* draw) (GameGraphic * graphic,
cairo_t * cr,
const GameRectangle * rect);
- cairo_pattern_t * (* create_cache) (GameGraphic * graphic,
- cairo_t * cr);
/* signals */
void (* invalidate) (GameGraphic * graphic,
const GameRectangle * rect);
@@ -79,8 +77,6 @@ gboolean game_graphic_draw_area_no_cache (GameGraphic * graphic,
cairo_t * cr,
const GameRectangle * rect);
-cairo_pattern_t *game_graphic_get_cache (GameGraphic * graphic,
- cairo_t * cr);
/* FIXME: find a header/file for this */
gboolean game_cairo_pattern_matches (cairo_t * cr,
cairo_pattern_t * pattern);
diff --git a/libgame/game-viewport.c b/libgame/game-viewport.c
index b0fec67..c5cd24a 100644
--- a/libgame/game-viewport.c
+++ b/libgame/game-viewport.c
@@ -171,7 +171,6 @@ game_viewport_class_init (gpointer g_class, gpointer class_data)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
graphic_class->draw = game_viewport_draw;
- graphic_class->create_cache = NULL;
}
static void