Created
December 21, 2015 13:56
-
-
Save romuald/2e3f4ad4f8180caa1cae to your computer and use it in GitHub Desktop.
Pebble bitmap cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static BitmapLayer *s_graph_layer; | |
static GBitmap *s_cache_bitmap; | |
static void init_bitmap(Window *window) { | |
Layer *window_layer = window_get_root_layer(window); | |
GRect bounds = layer_get_bounds(window_layer); | |
s_graph_layer = bitmap_layer_create(bounds); | |
s_cache_bitmap = gbitmap_create_blank(bounds.size, GBitmapFormat8Bit); | |
} | |
static void graphics_copy_frame_buffer_to_bitmap(GContext *ctx, GBitmap *bitmap) { | |
GBitmap *buffer = graphics_capture_frame_buffer(ctx); | |
GBitmapDataRowInfo source, dest; | |
GRect bounds = gbitmap_get_bounds(buffer); | |
for (int i = 0; i < bounds.size.h; i++) { | |
source = gbitmap_get_data_row_info(buffer, i); | |
dest = gbitmap_get_data_row_info(bitmap, i); | |
memcpy(dest.data, source.data, source.max_x + 1); | |
} | |
graphics_release_frame_buffer(ctx, buffer); | |
} | |
static void layer_update(Layer *layer, GContext* ctx) { | |
// Use cache if available and relevant | |
graphics_draw_bitmap_in_rect(ctx, s_cache_bitmap, layer_get_bounds(layer)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment