X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=Source%2FWebKit%2Fefl%2Fewk%2Fewk_tiled_matrix.cpp;h=c3a596d418c836a89d718e97b69b1266d64278f8;hp=ff4c41c7191347f01a619b3d1cbee9bcb54a62ce;hb=123afd332c70a9d3150bc9b3fe0d361c2c41f0cb;hpb=2115e383d0853d97995c37b9c177bfe50188b6f7 diff --git a/Source/WebKit/efl/ewk/ewk_tiled_matrix.cpp b/Source/WebKit/efl/ewk/ewk_tiled_matrix.cpp index ff4c41c71913..c3a596d418c8 100644 --- a/Source/WebKit/efl/ewk/ewk_tiled_matrix.cpp +++ b/Source/WebKit/efl/ewk/ewk_tiled_matrix.cpp @@ -18,6 +18,7 @@ Boston, MA 02110-1301, USA. */ +#define __STDC_FORMAT_MACROS #include "config.h" #include "ewk_tiled_matrix.h" @@ -31,18 +32,28 @@ #include #include +struct _Ewk_Tile_Matrix_Entry { + EINA_INLIST; + float zoom; + unsigned long count; + Eina_Matrixsparse* matrix; +}; + +typedef struct _Ewk_Tile_Matrix_Entry Ewk_Tile_Matrix_Entry; + struct _Ewk_Tile_Matrix { - Eina_Matrixsparse *matrix; - Ewk_Tile_Unused_Cache *tuc; + Eina_Matrixsparse* matrix; + Eina_Inlist* matrices; + Ewk_Tile_Unused_Cache* tilieUnusedCache; Evas_Colorspace cspace; struct { - void (*cb)(void *data, Ewk_Tile *t, const Eina_Rectangle *update); - void *data; + void (*callback)(void* data, Ewk_Tile* tile, const Eina_Rectangle* update); + void* data; } render; unsigned int frozen; - Eina_List *updates; + Eina_List* updates; struct { - Evas_Coord w, h; + Evas_Coord width, height; } tile; #ifdef DEBUG_MEM_LEAKS struct { @@ -53,78 +64,116 @@ struct _Ewk_Tile_Matrix { #endif }; +// Default 40 MB size of newly created cache +static const size_t DEFAULT_CACHE_SIZE = 40 * 1024 * 1024; + #ifdef DEBUG_MEM_LEAKS static uint64_t tiles_leaked = 0; static uint64_t bytes_leaked = 0; #endif +static Ewk_Tile_Matrix_Entry* ewk_tile_matrix_entry_get(Ewk_Tile_Matrix* tileMatrix, float zoom) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, 0); + Ewk_Tile_Matrix_Entry* iterator; + + EINA_INLIST_FOREACH(tileMatrix->matrices, iterator) { + if (iterator->zoom == zoom) + return iterator; + } + + return 0; +} + /* called when matrixsparse is resized or freed */ -static void _ewk_tile_matrix_cell_free(void *user_data, void *cell_data) +static void _ewk_tile_matrix_cell_free(void* userData, void* cellData) { - Ewk_Tile_Matrix* tm = static_cast(user_data); - Ewk_Tile* t = static_cast(cell_data); + Ewk_Tile_Matrix* tileMatrix = static_cast(userData); + Ewk_Tile* tile = static_cast(cellData); - if (!t) + if (!tile) return; - ewk_tile_unused_cache_freeze(tm->tuc); + ewk_tile_unused_cache_freeze(tileMatrix->tilieUnusedCache); - if (t->updates || t->stats.full_update) - tm->updates = eina_list_remove(tm->updates, t); + if (tile->updates || tile->stats.full_update) + tileMatrix->updates = eina_list_remove(tileMatrix->updates, tile); - if (t->visible) - ERR("freeing cell that is visible, leaking tile %p", t); + if (tile->visible) + ERR("freeing cell that is visible, leaking tile %p", tile); else { - if (!ewk_tile_unused_cache_tile_get(tm->tuc, t)) - ERR("tile %p was not in cache %p? leaking...", t, tm->tuc); + if (!ewk_tile_unused_cache_tile_get(tileMatrix->tilieUnusedCache, tile)) + ERR("tile %p was not in cache %p? leaking...", tile, tileMatrix->tilieUnusedCache); else { - DBG("tile cell does not exist anymore, free it %p", t); + Ewk_Tile_Matrix_Entry* entry; + DBG("tile cell does not exist anymore, free it %p", tile); #ifdef DEBUG_MEM_LEAKS - tm->stats.bytes.freed += t->bytes; - tm->stats.tiles.freed++; + tileMatrix->stats.bytes.freed += tile->bytes; + tileMatrix->stats.tiles.freed++; #endif - ewk_tile_free(t); + entry = ewk_tile_matrix_entry_get(tileMatrix, tile->zoom); + if (!entry) + ERR("can't find matrix for zoom %0.3f", tile->zoom); + else + entry->count--; + + ewk_tile_free(tile); } } - ewk_tile_unused_cache_thaw(tm->tuc); + ewk_tile_unused_cache_thaw(tileMatrix->tilieUnusedCache); } /* called when cache of unused tile is flushed */ -static void _ewk_tile_matrix_tile_free(void *data, Ewk_Tile *t) +static void _ewk_tile_matrix_tile_free(void* data, Ewk_Tile* tile) { - Ewk_Tile_Matrix* tm = static_cast(data); - Eina_Matrixsparse_Cell *cell; - - if (!eina_matrixsparse_cell_idx_get(tm->matrix, t->row, t->col, &cell)) { - ERR("removing tile %p that was not in the matrix? Leaking...", t); + Ewk_Tile_Matrix* tileMatrix = static_cast(data); + Ewk_Tile_Matrix_Entry* entry; + Eina_Matrixsparse_Cell* cell; + + entry = ewk_tile_matrix_entry_get(tileMatrix, tile->zoom); + if (!entry) { + ERR("removing tile %p that was not in any matrix? Leaking...", tile); + return; + } + + if (!eina_matrixsparse_cell_idx_get(entry->matrix, tile->row, tile->col, &cell)) { + + ERR("removing tile %p that was not in the matrix? Leaking...", tile); return; } if (!cell) { - ERR("removing tile %p that was not in the matrix? Leaking...", t); + ERR("removing tile %p that was not in the matrix? Leaking...", tile); return; } - if (t->updates || t->stats.full_update) - tm->updates = eina_list_remove(tm->updates, t); + if (tile->updates || tile->stats.full_update) + tileMatrix->updates = eina_list_remove(tileMatrix->updates, tile); /* set to null to avoid double free */ eina_matrixsparse_cell_data_replace(cell, 0, 0); eina_matrixsparse_cell_clear(cell); - if (EINA_UNLIKELY(!!t->visible)) { + if (EINA_UNLIKELY(!!tile->visible)) { ERR("cache of unused tiles requesting deletion of used tile %p? " - "Leaking...", t); + "Leaking...", tile); return; } #ifdef DEBUG_MEM_LEAKS - tm->stats.bytes.freed += t->bytes; - tm->stats.tiles.freed++; + tileMatrix->stats.bytes.freed += tile->bytes; + tileMatrix->stats.tiles.freed++; #endif - ewk_tile_free(t); + entry->count--; + if (!entry->count && entry->matrix != tileMatrix->matrix) { + eina_matrixsparse_free(entry->matrix); + tileMatrix->matrices = eina_inlist_remove(tileMatrix->matrices, EINA_INLIST_GET(entry)); + free(entry); + } + + ewk_tile_free(tile); } /** @@ -137,46 +186,102 @@ static void _ewk_tile_matrix_tile_free(void *data, Ewk_Tile *t) * * @param tuc cache of unused tiles or @c 0 to create one * automatically. - * @param cols number of columns in the matrix. + * @param columns number of columns in the matrix. * @param rows number of rows in the matrix. + * @param zoomLevel zoom level for the matrix. * @param cspace the color space used to create tiles in this matrix. * @param render_cb function used to render given tile update. * @param render_data context to give back to @a render_cb. * * @return newly allocated instance on success, @c 0 on failure. */ -Ewk_Tile_Matrix *ewk_tile_matrix_new(Ewk_Tile_Unused_Cache *tuc, unsigned long cols, unsigned long rows, Evas_Colorspace cspace, void (*render_cb)(void *data, Ewk_Tile *t, const Eina_Rectangle *update), const void *render_data) +Ewk_Tile_Matrix* ewk_tile_matrix_new(Ewk_Tile_Unused_Cache* tileUnusedCache, unsigned long columns, unsigned long rows, float zoomLevel, Evas_Colorspace colorSpace, void (*renderCallback)(void* data, Ewk_Tile* tile, const Eina_Rectangle* update), const void* renderData) { - Ewk_Tile_Matrix* tm = static_cast(calloc(1, sizeof(Ewk_Tile_Matrix))); - if (!tm) + Ewk_Tile_Matrix* tileMatrix = static_cast(calloc(1, sizeof(Ewk_Tile_Matrix))); + if (!tileMatrix) return 0; - tm->matrix = eina_matrixsparse_new(rows, cols, _ewk_tile_matrix_cell_free, tm); - if (!tm->matrix) { + tileMatrix->matrix = eina_matrixsparse_new(rows, columns, _ewk_tile_matrix_cell_free, tileMatrix); + if (!tileMatrix->matrix) { ERR("could not create sparse matrix."); - free(tm); + free(tileMatrix); return 0; } - if (tuc) - tm->tuc = ewk_tile_unused_cache_ref(tuc); + ewk_tile_matrix_zoom_level_set(tileMatrix, zoomLevel); + + if (tileUnusedCache) + tileMatrix->tilieUnusedCache = ewk_tile_unused_cache_ref(tileUnusedCache); else { - tm->tuc = ewk_tile_unused_cache_new(40960000); - if (!tm->tuc) { + tileMatrix->tilieUnusedCache = ewk_tile_unused_cache_new(DEFAULT_CACHE_SIZE); + if (!tileMatrix->tilieUnusedCache) { ERR("no cache of unused tile!"); - eina_matrixsparse_free(tm->matrix); - free(tm); + eina_matrixsparse_free(tileMatrix->matrix); + free(tileMatrix); return 0; } } - tm->cspace = cspace; - tm->render.cb = render_cb; - tm->render.data = (void *)render_data; - tm->tile.w = DEFAULT_TILE_W; - tm->tile.h = DEFAULT_TILE_H; + tileMatrix->cspace = colorSpace; + tileMatrix->render.callback = renderCallback; + tileMatrix->render.data = (void*)renderData; + tileMatrix->tile.width = DEFAULT_TILE_W; + tileMatrix->tile.height = DEFAULT_TILE_H; - return tm; + return tileMatrix; +} + +void ewk_tile_matrix_zoom_level_set(Ewk_Tile_Matrix* tileMatrix, float zoom) +{ + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + Ewk_Tile_Matrix_Entry* iterator = 0; + Ewk_Tile_Matrix_Entry* entry = 0; + unsigned long rows = 0, columns = 0; + + eina_matrixsparse_size_get(tileMatrix->matrix, &rows, &columns); + + EINA_INLIST_FOREACH(tileMatrix->matrices, iterator) { + if (iterator->zoom != zoom) + continue; + entry = iterator; + tileMatrix->matrices = eina_inlist_promote(tileMatrix->matrices, EINA_INLIST_GET(entry)); + eina_matrixsparse_size_set(entry->matrix, rows, columns); + } + + if (!entry) { + entry = static_cast(calloc(1, sizeof(Ewk_Tile_Matrix_Entry))); + entry->zoom = zoom; + entry->matrix = eina_matrixsparse_new(rows, columns, _ewk_tile_matrix_cell_free, tileMatrix); + if (!entry->matrix) { + ERR("could not create sparse matrix."); + free(entry); + return; + } + tileMatrix->matrices = eina_inlist_prepend(tileMatrix->matrices, EINA_INLIST_GET(entry)); + } + + tileMatrix->matrix = entry->matrix; +} + +void ewk_tile_matrix_invalidate(Ewk_Tile_Matrix* tileMatrix) +{ + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + Ewk_Tile_Matrix_Entry* iterator; + Eina_Inlist* matrixList; + + matrixList = tileMatrix->matrices; + while (matrixList) { + iterator = EINA_INLIST_CONTAINER_GET(matrixList, Ewk_Tile_Matrix_Entry); + Eina_Inlist *next = (matrixList->next) ? matrixList->next : 0; + + if (iterator->matrix != tileMatrix->matrix) { + eina_matrixsparse_free(iterator->matrix); + tileMatrix->matrices = eina_inlist_remove(tileMatrix->matrices, matrixList); + free(iterator); + } + + matrixList = next; + } } /** @@ -184,56 +289,62 @@ Ewk_Tile_Matrix *ewk_tile_matrix_new(Ewk_Tile_Unused_Cache *tuc, unsigned long c * * The cache instance is unreferenced, possibly freeing it. */ -void ewk_tile_matrix_free(Ewk_Tile_Matrix *tm) +void ewk_tile_matrix_free(Ewk_Tile_Matrix* tileMatrix) { + Ewk_Tile_Matrix_Entry* entry; #ifdef DEBUG_MEM_LEAKS uint64_t tiles, bytes; #endif - EINA_SAFETY_ON_NULL_RETURN(tm); - ewk_tile_unused_cache_freeze(tm->tuc); + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + ewk_tile_unused_cache_freeze(tileMatrix->tilieUnusedCache); - eina_matrixsparse_free(tm->matrix); + ewk_tile_unused_cache_freeze(tileMatrix->tilieUnusedCache); + ewk_tile_matrix_invalidate(tileMatrix); + entry = EINA_INLIST_CONTAINER_GET(tileMatrix->matrices, Ewk_Tile_Matrix_Entry); + eina_matrixsparse_free(entry->matrix); + free(entry); + tileMatrix->matrices = 0; - ewk_tile_unused_cache_thaw(tm->tuc); - ewk_tile_unused_cache_unref(tm->tuc); + ewk_tile_unused_cache_thaw(tileMatrix->tilieUnusedCache); + ewk_tile_unused_cache_unref(tileMatrix->tilieUnusedCache); #ifdef DEBUG_MEM_LEAKS - tiles = tm->stats.tiles.allocated - tm->stats.tiles.freed; - bytes = tm->stats.bytes.allocated - tm->stats.bytes.freed; + tiles = tileMatrix->stats.tiles.allocated - tileMatrix->stats.tiles.freed; + bytes = tileMatrix->stats.bytes.allocated - tileMatrix->stats.bytes.freed; tiles_leaked += tiles; bytes_leaked += bytes; if (tiles || bytes) - ERR("tiled matrix leaked: tiles[+%"PRIu64",-%"PRIu64":%"PRIu64"] " - "bytes[+%"PRIu64",-%"PRIu64":%"PRIu64"]", - tm->stats.tiles.allocated, tm->stats.tiles.freed, tiles, - tm->stats.bytes.allocated, tm->stats.bytes.freed, bytes); + ERR("tiled matrix leaked: tiles[+%" PRIu64 ",-%" PRIu64 ":%" PRIu64 "] " + "bytes[+%" PRIu64 ",-%" PRIu64 ":%" PRIu64 "]", + tileMatrix->stats.tiles.allocated, tileMatrix->stats.tiles.freed, tiles, + tileMatrix->stats.bytes.allocated, tileMatrix->stats.bytes.freed, bytes); else if (tiles_leaked || bytes_leaked) - WRN("tiled matrix had no leaks: tiles[+%"PRIu64",-%"PRIu64"] " - "bytes[+%"PRIu64",-%"PRIu64"], but some other leaked " - "%"PRIu64" tiles (%"PRIu64" bytes)", - tm->stats.tiles.allocated, tm->stats.tiles.freed, - tm->stats.bytes.allocated, tm->stats.bytes.freed, + WRN("tiled matrix had no leaks: tiles[+%" PRIu64 ",-%" PRIu64 "] " + "bytes[+%" PRIu64 ",-%" PRIu64 "], but some other leaked " + "%" PRIu64 " tiles (%" PRIu64 " bytes)", + tileMatrix->stats.tiles.allocated, tileMatrix->stats.tiles.freed, + tileMatrix->stats.bytes.allocated, tileMatrix->stats.bytes.freed, tiles_leaked, bytes_leaked); else - INF("tiled matrix had no leaks: tiles[+%"PRIu64",-%"PRIu64"] " - "bytes[+%"PRIu64",-%"PRIu64"]", - tm->stats.tiles.allocated, tm->stats.tiles.freed, - tm->stats.bytes.allocated, tm->stats.bytes.freed); + INF("tiled matrix had no leaks: tiles[+%" PRIu64 ",-%" PRIu64 "] " + "bytes[+%" PRIu64 ",-%" PRIu64 "]", + tileMatrix->stats.tiles.allocated, tileMatrix->stats.tiles.freed, + tileMatrix->stats.bytes.allocated, tileMatrix->stats.bytes.freed); #endif - free(tm); + free(tileMatrix); } /** * Resize matrix to given number of rows and columns. */ -void ewk_tile_matrix_resize(Ewk_Tile_Matrix *tm, unsigned long cols, unsigned long rows) +void ewk_tile_matrix_resize(Ewk_Tile_Matrix* tileMatrix, unsigned long cols, unsigned long rows) { - EINA_SAFETY_ON_NULL_RETURN(tm); - eina_matrixsparse_size_set(tm->matrix, rows, cols); + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + eina_matrixsparse_size_set(tileMatrix->matrix, rows, cols); } /** @@ -241,23 +352,23 @@ void ewk_tile_matrix_resize(Ewk_Tile_Matrix *tm, unsigned long cols, unsigned lo * * No reference is taken to the cache. */ -Ewk_Tile_Unused_Cache *ewk_tile_matrix_unused_cache_get(const Ewk_Tile_Matrix *tm) +Ewk_Tile_Unused_Cache* ewk_tile_matrix_unused_cache_get(const Ewk_Tile_Matrix* tileMatrix) { - EINA_SAFETY_ON_NULL_RETURN_VAL(tm, 0); - return tm->tuc; + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, 0); + return tileMatrix->tilieUnusedCache; } /** * Get the exact tile for the given position and zoom. * - * If the tile was unused then it's removed from the cache. + * If the tile.widthas unused then it's removed from the cache. * * After usage, please give it back using * ewk_tile_matrix_tile_put(). If you just want to check if it exists, * then use ewk_tile_matrix_tile_exact_exists(). * - * @param tm the tile matrix to get tile from. - * @param col the column number. + * @param tileMatrix the tile matrix to get tile from. + * @param column the column number. * @param row the row number. * @param zoom the exact zoom to use. * @@ -268,42 +379,42 @@ Ewk_Tile_Unused_Cache *ewk_tile_matrix_unused_cache_get(const Ewk_Tile_Matrix *t * * @see ewk_tile_matrix_tile_exact_get() */ -Ewk_Tile *ewk_tile_matrix_tile_exact_get(Ewk_Tile_Matrix *tm, unsigned long col, unsigned long row, float zoom) +Ewk_Tile* ewk_tile_matrix_tile_exact_get(Ewk_Tile_Matrix* tileMatrix, unsigned long column, unsigned long row, float zoom) { - Ewk_Tile* t = static_cast(eina_matrixsparse_data_idx_get(tm->matrix, row, col)); - if (!t) + Ewk_Tile* tile = static_cast(eina_matrixsparse_data_idx_get(tileMatrix->matrix, row, column)); + if (!tile) return 0; - if (t->zoom == zoom) + if (tile->zoom == zoom) goto end; - end: - if (!t->visible) { - if (!ewk_tile_unused_cache_tile_get(tm->tuc, t)) +end: + if (!tile->visible) { + if (!ewk_tile_unused_cache_tile_get(tileMatrix->tilieUnusedCache, tile)) WRN("Ewk_Tile was unused but not in cache? bug!"); } - return t; + return tile; } /** * Checks if tile of given zoom exists in matrix. * - * @param tm the tile matrix to check tile existence. - * @param col the column number. + * @param tileMatrix the tile matrix to check tile existence. + * @param column the column number. * @param row the row number. * @param zoom the exact zoom to query. * - * @return @c EINA_TRUE if found, @c EINA_FALSE otherwise. + * @return @c true if found, @c false otherwise. * * @see ewk_tile_matrix_tile_exact_get() */ -Eina_Bool ewk_tile_matrix_tile_exact_exists(Ewk_Tile_Matrix *tm, unsigned long col, unsigned long row, float zoom) +Eina_Bool ewk_tile_matrix_tile_exact_exists(Ewk_Tile_Matrix* tileMatrix, unsigned long column, unsigned long row, float zoom) { - if (!eina_matrixsparse_data_idx_get(tm->matrix, row, col)) - return EINA_FALSE; + if (!eina_matrixsparse_data_idx_get(tileMatrix->matrix, row, column)) + return false; - return EINA_TRUE; + return true; } /** @@ -313,50 +424,57 @@ Eina_Bool ewk_tile_matrix_tile_exact_exists(Ewk_Tile_Matrix *tm, unsigned long c * of unused tiles. After it is used one should call * ewk_tile_matrix_tile_put() to give it back to matrix. * - * @param tm the tile matrix to create tile on. - * @param col the column number. + * @param tileMatrix the tile matrix to create tile on. + * @param column the column number. * @param row the row number. * @param zoom the level to create tile, used to determine tile size. */ -Ewk_Tile *ewk_tile_matrix_tile_new(Ewk_Tile_Matrix *tm, Evas *evas, unsigned long col, unsigned long row, float zoom) +Ewk_Tile* ewk_tile_matrix_tile_new(Ewk_Tile_Matrix* tileMatrix, Evas* canvas, unsigned long column, unsigned long row, float zoom) { - Evas_Coord tw, th; - Ewk_Tile *t; + Evas_Coord tileWidth, tileHeight; + Ewk_Tile* tile; + Ewk_Tile_Matrix_Entry* entry; - EINA_SAFETY_ON_NULL_RETURN_VAL(tm, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, 0); EINA_SAFETY_ON_FALSE_RETURN_VAL(zoom > 0.0, 0); + entry = ewk_tile_matrix_entry_get(tileMatrix, zoom); + if (!entry) { + ERR("could not get matrix at zoom %f for tile", zoom); + return 0; + } + entry->count++; - tw = tm->tile.w; - th = tm->tile.h; + tileWidth = tileMatrix->tile.width; + tileHeight = tileMatrix->tile.height; - t = ewk_tile_new(evas, tw, th, zoom, tm->cspace); - if (!t) { - ERR("could not create tile %dx%d at %f, cspace=%d", tw, th, (double)zoom, tm->cspace); + tile = ewk_tile_new(canvas, tileWidth, tileHeight, zoom, tileMatrix->cspace); + if (!tile) { + ERR("could not create tile %dx%d at %f, cspace=%d", tileWidth, tileHeight, (double)zoom, tileMatrix->cspace); return 0; } - if (!eina_matrixsparse_data_idx_set(tm->matrix, row, col, t)) { + if (!eina_matrixsparse_data_idx_set(tileMatrix->matrix, row, column, tile)) { ERR("could not set matrix cell, row/col outside matrix dimensions!"); - ewk_tile_free(t); + ewk_tile_free(tile); return 0; } - t->col = col; - t->row = row; - t->x = col * tw; - t->y = row * th; + tile->col = column; + tile->row = row; + tile->x = column * tileWidth; + tile->y = row * tileHeight; - cairo_translate(t->cairo, -t->x, -t->y); + cairo_translate(tile->cairo, -tile->x, -tile->y); - t->stats.full_update = EINA_TRUE; - tm->updates = eina_list_append(tm->updates, t); + tile->stats.full_update = true; + tileMatrix->updates = eina_list_append(tileMatrix->updates, tile); #ifdef DEBUG_MEM_LEAKS - tm->stats.bytes.allocated += t->bytes; - tm->stats.tiles.allocated++; + tileMatrix->stats.bytes.allocated += tile->bytes; + tileMatrix->stats.tiles.allocated++; #endif - return t; + return tile; } /** @@ -366,146 +484,146 @@ Ewk_Tile *ewk_tile_matrix_tile_new(Ewk_Tile_Matrix *tm, Evas *evas, unsigned lon * it with ewk_tile_matrix_tile_exact_get(). * * Any previous reference to tile should be released - * (ewk_tile_hide()) before calling this function, so it will + * (ewk_tile.heightide()) before calling this function, so it will * be known if it is not visibile anymore and thus can be put into the * unused cache. * - * @param tm the tile matrix to return tile to. + * @param tileMatrix the tile matrix to return tile to. * @param t the tile instance to return, must @b not be @c 0. - * @param last_used time in which tile was last used. + * @param last_used time in which tile.widthas last used. * - * @return #EINA_TRUE on success or #EINA_FALSE on failure. + * @return #true on success or #false on failure. */ -Eina_Bool ewk_tile_matrix_tile_put(Ewk_Tile_Matrix *tm, Ewk_Tile *t, double last_used) +Eina_Bool ewk_tile_matrix_tile_put(Ewk_Tile_Matrix* tileMatrix, Ewk_Tile* tile, double lastUsed) { - EINA_SAFETY_ON_NULL_RETURN_VAL(tm, EINA_FALSE); - EINA_SAFETY_ON_NULL_RETURN_VAL(t, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, false); + EINA_SAFETY_ON_NULL_RETURN_VAL(tile, false); - if (t->visible) - return EINA_TRUE; + if (tile->visible) + return true; - t->stats.last_used = last_used; - return ewk_tile_unused_cache_tile_put(tm->tuc, t, _ewk_tile_matrix_tile_free, tm); + tile->stats.last_used = lastUsed; + return ewk_tile_unused_cache_tile_put(tileMatrix->tilieUnusedCache, tile, _ewk_tile_matrix_tile_free, tileMatrix); } -Eina_Bool ewk_tile_matrix_tile_update(Ewk_Tile_Matrix *tm, unsigned long col, unsigned long row, const Eina_Rectangle *update) +Eina_Bool ewk_tile_matrix_tile_update(Ewk_Tile_Matrix* tileMatrix, unsigned long col, unsigned long row, const Eina_Rectangle* update) { - Eina_Rectangle new_update; - EINA_SAFETY_ON_NULL_RETURN_VAL(tm, EINA_FALSE); - EINA_SAFETY_ON_NULL_RETURN_VAL(update, EINA_FALSE); + Eina_Rectangle newUpdate; + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, false); + EINA_SAFETY_ON_NULL_RETURN_VAL(update, false); - memcpy(&new_update, update, sizeof(new_update)); - // check update is valid, otherwise return EINA_FALSE + memcpy(&newUpdate, update, sizeof(newUpdate)); + // check update is valid, otherwise return false if (update->x < 0 || update->y < 0 || update->w <= 0 || update->h <= 0) { ERR("invalid update region."); - return EINA_FALSE; + return false; } - if (update->x + update->w - 1 >= tm->tile.w) - new_update.w = tm->tile.w - update->x; - if (update->y + update->h - 1 >= tm->tile.h) - new_update.h = tm->tile.h - update->y; + if (update->x + update->w - 1 >= tileMatrix->tile.width) + newUpdate.w = tileMatrix->tile.width - update->x; + if (update->y + update->h - 1 >= tileMatrix->tile.height) + newUpdate.h = tileMatrix->tile.height - update->y; - Ewk_Tile* t = static_cast(eina_matrixsparse_data_idx_get(tm->matrix, row, col)); - if (!t) - return EINA_TRUE; + Ewk_Tile* tile = static_cast(eina_matrixsparse_data_idx_get(tileMatrix->matrix, row, col)); + if (!tile) + return true; - if (!t->updates && !t->stats.full_update) - tm->updates = eina_list_append(tm->updates, t); - ewk_tile_update_area(t, &new_update); + if (!tile->updates && !tile->stats.full_update) + tileMatrix->updates = eina_list_append(tileMatrix->updates, tile); + ewk_tile_update_area(tile, &newUpdate); - return EINA_TRUE; + return true; } -Eina_Bool ewk_tile_matrix_tile_update_full(Ewk_Tile_Matrix *tm, unsigned long col, unsigned long row) +Eina_Bool ewk_tile_matrix_tile_update_full(Ewk_Tile_Matrix* tileMatrix, unsigned long column, unsigned long row) { - Eina_Matrixsparse_Cell *cell; - EINA_SAFETY_ON_NULL_RETURN_VAL(tm, EINA_FALSE); + Eina_Matrixsparse_Cell* cell; + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, false); - if (!eina_matrixsparse_cell_idx_get(tm->matrix, row, col, &cell)) - return EINA_FALSE; + if (!eina_matrixsparse_cell_idx_get(tileMatrix->matrix, row, column, &cell)) + return false; if (!cell) - return EINA_TRUE; + return true; - Ewk_Tile* t = static_cast(eina_matrixsparse_cell_data_get(cell)); - if (!t) { + Ewk_Tile* tile = static_cast(eina_matrixsparse_cell_data_get(cell)); + if (!tile) { CRITICAL("matrix cell with no tile!"); - return EINA_TRUE; + return true; } - if (!t->updates && !t->stats.full_update) - tm->updates = eina_list_append(tm->updates, t); - ewk_tile_update_full(t); + if (!tile->updates && !tile->stats.full_update) + tileMatrix->updates = eina_list_append(tileMatrix->updates, tile); + ewk_tile_update_full(tile); - return EINA_TRUE; + return true; } -void ewk_tile_matrix_tile_updates_clear(Ewk_Tile_Matrix *tm, Ewk_Tile *t) +void ewk_tile_matrix_tile_updates_clear(Ewk_Tile_Matrix* tileMatrix, Ewk_Tile* tile) { - EINA_SAFETY_ON_NULL_RETURN(tm); - if (!t->updates && !t->stats.full_update) + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + if (!tile->updates && !tile->stats.full_update) return; - ewk_tile_updates_clear(t); - tm->updates = eina_list_remove(tm->updates, t); + ewk_tile_updates_clear(tile); + tileMatrix->updates = eina_list_remove(tileMatrix->updates, tile); } -static Eina_Bool _ewk_tile_matrix_slicer_setup(Ewk_Tile_Matrix *tm, const Eina_Rectangle *area, float zoom, Eina_Tile_Grid_Slicer *slicer) +static Eina_Bool _ewk_tile_matrix_slicer_setup(Ewk_Tile_Matrix* tileMatrix, const Eina_Rectangle* area, float zoom, Eina_Tile_Grid_Slicer* slicer) { unsigned long rows, cols; - Evas_Coord x, y, w, h, tw, th; + Evas_Coord x, y, width, height, tileWidth, tileHeight; if (area->w <= 0 || area->h <= 0) { WRN("invalid area region: %d,%d+%dx%d.", area->x, area->y, area->w, area->h); - return EINA_FALSE; + return false; } x = area->x; y = area->y; - w = area->w; - h = area->h; + width = area->w; + height = area->h; - tw = tm->tile.w; - th = tm->tile.h; + tileWidth = tileMatrix->tile.width; + tileHeight = tileMatrix->tile.height; // cropping area region to fit matrix - eina_matrixsparse_size_get(tm->matrix, &rows, &cols); + eina_matrixsparse_size_get(tileMatrix->matrix, &rows, &cols); if (x < 0) { - w += x; + width += x; x = 0; } if (y < 0) { - h += y; + height += y; y = 0; } - if (y + h - 1 > (long)(rows * th)) - h = rows * th - y; - if (x + w - 1 > (long)(cols * tw)) - w = cols * tw - x; + if (y + height - 1 > (long)(rows * tileHeight)) + height = rows * tileHeight - y; + if (x + width - 1 > (long)(cols * tileWidth)) + width = cols * tileWidth - x; - return eina_tile_grid_slicer_setup(slicer, x, y, w, h, tw, th); + return eina_tile_grid_slicer_setup(slicer, x, y, width, height, tileWidth, tileHeight); } -Eina_Bool ewk_tile_matrix_update(Ewk_Tile_Matrix *tm, const Eina_Rectangle *update, float zoom) +Eina_Bool ewk_tile_matrix_update(Ewk_Tile_Matrix* tileMatrix, const Eina_Rectangle* update, float zoom) { - const Eina_Tile_Grid_Info *info; + const Eina_Tile_Grid_Info* info; Eina_Tile_Grid_Slicer slicer; - EINA_SAFETY_ON_NULL_RETURN_VAL(tm, EINA_FALSE); - EINA_SAFETY_ON_NULL_RETURN_VAL(update, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(tileMatrix, false); + EINA_SAFETY_ON_NULL_RETURN_VAL(update, false); if (update->w < 1 || update->h < 1) { DBG("Why we get updates with empty areas? %d,%d+%dx%d at zoom %f", update->x, update->y, update->w, update->h, zoom); - return EINA_TRUE; + return true; } - if (!_ewk_tile_matrix_slicer_setup(tm, update, zoom, &slicer)) { + if (!_ewk_tile_matrix_slicer_setup(tileMatrix, update, zoom, &slicer)) { ERR("Could not setup slicer for update %d,%d+%dx%d at zoom %f", update->x, update->y, update->w, update->h, zoom); - return EINA_FALSE; + return false; } while (eina_tile_grid_slicer_next(&slicer, &info)) { @@ -513,93 +631,93 @@ Eina_Bool ewk_tile_matrix_update(Ewk_Tile_Matrix *tm, const Eina_Rectangle *upda col = info->col; row = info->row; - Ewk_Tile* t = static_cast(eina_matrixsparse_data_idx_get(tm->matrix, row, col)); - if (!t) + Ewk_Tile* tile = static_cast(eina_matrixsparse_data_idx_get(tileMatrix->matrix, row, col)); + if (!tile) continue; - if (!t->updates && !t->stats.full_update) - tm->updates = eina_list_append(tm->updates, t); + if (!tile->updates && !tile->stats.full_update) + tileMatrix->updates = eina_list_append(tileMatrix->updates, tile); if (info->full) - ewk_tile_update_full(t); + ewk_tile_update_full(tile); else - ewk_tile_update_area(t, &info->rect); + ewk_tile_update_area(tile, &info->rect); } - return EINA_TRUE; + return true; } -void ewk_tile_matrix_updates_process(Ewk_Tile_Matrix *tm) +void ewk_tile_matrix_updates_process(Ewk_Tile_Matrix* tileMatrix) { - Eina_List *l, *l_next; + Eina_List* list, *listNext; void* item; - EINA_SAFETY_ON_NULL_RETURN(tm); + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); // process updates, unflag tiles - EINA_LIST_FOREACH_SAFE(tm->updates, l, l_next, item) { + EINA_LIST_FOREACH_SAFE(tileMatrix->updates, list, listNext, item) { Ewk_Tile* tile = static_cast(item); - ewk_tile_updates_process(tile, tm->render.cb, tm->render.data); + ewk_tile_updates_process(tile, tileMatrix->render.callback, tileMatrix->render.data); if (tile->visible) { ewk_tile_updates_clear(tile); - tm->updates = eina_list_remove_list(tm->updates, l); + tileMatrix->updates = eina_list_remove_list(tileMatrix->updates, list); } } } -void ewk_tile_matrix_updates_clear(Ewk_Tile_Matrix *tm) +void ewk_tile_matrix_updates_clear(Ewk_Tile_Matrix* tileMatrix) { void* item; - EINA_SAFETY_ON_NULL_RETURN(tm); + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); - EINA_LIST_FREE(tm->updates, item) + EINA_LIST_FREE(tileMatrix->updates, item) ewk_tile_updates_clear(static_cast(item)); - tm->updates = 0; + tileMatrix->updates = 0; } // remove me later! -void ewk_tile_matrix_dbg(const Ewk_Tile_Matrix *tm) +void ewk_tile_matrix_dbg(const Ewk_Tile_Matrix* tileMatrix) { - Eina_Iterator *it = eina_matrixsparse_iterator_complete_new(tm->matrix); - Eina_Matrixsparse_Cell *cell; - Eina_Bool last_empty = EINA_FALSE; + Eina_Iterator* iterator = eina_matrixsparse_iterator_complete_new(tileMatrix->matrix); + Eina_Matrixsparse_Cell* cell; + Eina_Bool last_empty = false; #ifdef DEBUG_MEM_LEAKS - printf("Ewk_Tile Matrix: tiles[+%"PRIu64",-%"PRIu64":%"PRIu64"] " - "bytes[+%"PRIu64",-%"PRIu64":%"PRIu64"]\n", - tm->stats.tiles.allocated, tm->stats.tiles.freed, - tm->stats.tiles.allocated - tm->stats.tiles.freed, - tm->stats.bytes.allocated, tm->stats.bytes.freed, - tm->stats.bytes.allocated - tm->stats.bytes.freed); + printf("Ewk_Tile Matrix: tiles[+%" PRIu64 ",-%" PRIu64 ":%" PRIu64 "] " + "bytes[+%" PRIu64 ",-%" PRIu64 ":%" PRIu64 "]\n", + tileMatrix->stats.tiles.allocated, tileMatrix->stats.tiles.freed, + tileMatrix->stats.tiles.allocated - tileMatrix->stats.tiles.freed, + tileMatrix->stats.bytes.allocated, tileMatrix->stats.bytes.freed, + tileMatrix->stats.bytes.allocated - tileMatrix->stats.bytes.freed); #else printf("Ewk_Tile Matrix:\n"); #endif - EINA_ITERATOR_FOREACH(it, cell) { - unsigned long row, col; - eina_matrixsparse_cell_position_get(cell, &row, &col); + EINA_ITERATOR_FOREACH(iterator, cell) { + unsigned long row, column; + eina_matrixsparse_cell_position_get(cell, &row, &column); - Ewk_Tile* t = static_cast(eina_matrixsparse_cell_data_get(cell)); - if (!t) { + Ewk_Tile* tile = static_cast(eina_matrixsparse_cell_data_get(cell)); + if (!tile) { if (!last_empty) { - last_empty = EINA_TRUE; + last_empty = true; printf("Empty:"); } - printf(" [%lu,%lu]", col, row); + printf(" [%lu,%lu]", column, row); } else { if (last_empty) { - last_empty = EINA_FALSE; + last_empty = false; printf("\n"); } - printf("%3lu,%3lu %10p:", col, row, t); - printf(" [%3lu,%3lu + %dx%d @ %0.3f]%c", t->col, t->row, t->w, t->h, t->zoom, t->visible ? '*': ' '); + printf("%3lu,%3lu %10p:", column, row, tile); + printf(" [%3lu,%3lu + %dx%d @ %0.3f]%c", tile->col, tile->row, tile->width, tile->height, tile->zoom, tile->visible ? '*' : ' '); printf("\n"); } } if (last_empty) printf("\n"); - eina_iterator_free(it); + eina_iterator_free(iterator); - ewk_tile_unused_cache_dbg(tm->tuc); + ewk_tile_unused_cache_dbg(tileMatrix->tilieUnusedCache); } /** @@ -611,12 +729,12 @@ void ewk_tile_matrix_dbg(const Ewk_Tile_Matrix *tm) * * @see ewk_tile_matrix_thaw() */ -void ewk_tile_matrix_freeze(Ewk_Tile_Matrix *tm) +void ewk_tile_matrix_freeze(Ewk_Tile_Matrix* tileMatrix) { - EINA_SAFETY_ON_NULL_RETURN(tm); - if (!tm->frozen) - ewk_tile_unused_cache_freeze(tm->tuc); - tm->frozen++; + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + if (!tileMatrix->frozen) + ewk_tile_unused_cache_freeze(tileMatrix->tilieUnusedCache); + tileMatrix->frozen++; } /** @@ -625,15 +743,15 @@ void ewk_tile_matrix_freeze(Ewk_Tile_Matrix *tm) * If this is the last counterpart of freeze, then maintenance tasks * will run immediately. */ -void ewk_tile_matrix_thaw(Ewk_Tile_Matrix *tm) +void ewk_tile_matrix_thaw(Ewk_Tile_Matrix* tileMatrix) { - EINA_SAFETY_ON_NULL_RETURN(tm); - if (!tm->frozen) { + EINA_SAFETY_ON_NULL_RETURN(tileMatrix); + if (!tileMatrix->frozen) { ERR("thawing more than freezing!"); return; } - tm->frozen--; - if (!tm->frozen) - ewk_tile_unused_cache_thaw(tm->tuc); + tileMatrix->frozen--; + if (!tileMatrix->frozen) + ewk_tile_unused_cache_thaw(tileMatrix->tilieUnusedCache); }