Home | History | Annotate | Download | only in ewk
      1 /*
      2     Copyright (C) 2009-2010 Samsung Electronics
      3     Copyright (C) 2009-2010 ProFUSION embedded systems
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Library General Public
      7     License as published by the Free Software Foundation; either
      8     version 2 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Library General Public License for more details.
     14 
     15     You should have received a copy of the GNU Library General Public License
     16     along with this library; see the file COPYING.LIB.  If not, write to
     17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18     Boston, MA 02110-1301, USA.
     19 */
     20 
     21 #ifndef ewk_tiled_backing_store_h
     22 #define ewk_tiled_backing_store_h
     23 
     24 #include "EWebKit.h"
     25 
     26 /* Enable accounting of render time in tile statistics */
     27 // #define TILE_STATS_ACCOUNT_RENDER_TIME
     28 
     29 
     30 /* If define ewk will do more accounting to check for memory leaks
     31  * try "kill -USR1 $PID" to get instantaneous debug
     32  * try "kill -USR2 $PID" to get instantaneous debug and force flush of cache
     33  */
     34 #define DEBUG_MEM_LEAKS 1
     35 
     36 #define TILE_W (256)
     37 #define TILE_H (256)
     38 
     39 #define ZOOM_STEP_MIN (0.01)
     40 
     41 #define TILE_SIZE_AT_ZOOM(SIZE, ZOOM) ((int)roundf((SIZE) * (ZOOM)))
     42 #define TILE_W_ZOOM_AT_SIZE(SIZE) ((float)SIZE / (float)TILE_W)
     43 #define TILE_H_ZOOM_AT_SIZE(SIZE) ((float)SIZE / (float)TILE_H)
     44 
     45 #ifdef __cplusplus
     46 extern "C" {
     47 #endif
     48 
     49 #include <Evas.h>
     50 #include <cairo.h>
     51 
     52 typedef struct _Ewk_Tile                     Ewk_Tile;
     53 typedef struct _Ewk_Tile_Stats               Ewk_Tile_Stats;
     54 typedef struct _Ewk_Tile_Matrix              Ewk_Tile_Matrix;
     55 
     56 struct _Ewk_Tile_Stats {
     57     double last_used;        /**< time of last use */
     58 #ifdef TILE_STATS_ACCOUNT_RENDER_TIME
     59     double render_time;      /**< amount of time this tile took to render */
     60 #endif
     61     unsigned int area;       /**< cache for (w * h) */
     62     unsigned int misses;     /**< number of times it became dirty but not
     63                               * repainted at all since it was not visible.
     64                               */
     65     Eina_Bool full_update:1; /**< tile requires full size update */
     66 };
     67 
     68 struct _Ewk_Tile {
     69     EINA_INLIST;            /**< sibling tiles at same (i, j) but other zoom */
     70     Eina_Tiler *updates;    /**< updated/dirty areas */
     71     Ewk_Tile_Stats stats;       /**< tile usage statistics */
     72     unsigned long col, row; /**< tile tile position */
     73     Evas_Coord x, y;        /**< tile coordinate position */
     74 
     75     /* TODO: does it worth to keep those or create on demand? */
     76     cairo_surface_t *surface;
     77     cairo_t *cairo;
     78 
     79     /** Never ever change those after tile is created (respect const!) */
     80     const Evas_Coord w, h;        /**< tile size (see TILE_SIZE_AT_ZOOM()) */
     81     const Evas_Colorspace cspace; /**< colorspace */
     82     const float zoom;             /**< zoom level contents were rendered at */
     83     const size_t bytes;           /**< bytes used in pixels. keep
     84                                    * before pixels to guarantee
     85                                    * alignement!
     86                                    */
     87     int visible;                  /**< visibility counter of this tile */
     88     Evas_Object *image;           /**< Evas Image, the tile to be rendered */
     89     uint8_t *pixels;
     90 };
     91 
     92 #include "ewk_tiled_matrix.h"
     93 #include "ewk_tiled_model.h"
     94 
     95 /* view */
     96 EAPI Evas_Object *ewk_tiled_backing_store_add(Evas *e);
     97 
     98 EAPI void ewk_tiled_backing_store_render_cb_set(Evas_Object *o, Eina_Bool (*cb)(void *data, Ewk_Tile *t, const Eina_Rectangle *area), const void *data);
     99 
    100 EAPI Eina_Bool    ewk_tiled_backing_store_scroll_full_offset_set(Evas_Object *o, Evas_Coord x, Evas_Coord y);
    101 EAPI Eina_Bool    ewk_tiled_backing_store_scroll_full_offset_add(Evas_Object *o, Evas_Coord dx, Evas_Coord dy);
    102 EAPI Eina_Bool    ewk_tiled_backing_store_scroll_inner_offset_add(Evas_Object *o, Evas_Coord dx, Evas_Coord dy, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
    103 
    104 EAPI Eina_Bool    ewk_tiled_backing_store_zoom_set(Evas_Object *o, float *zoom, Evas_Coord cx, Evas_Coord cy, Evas_Coord *offx, Evas_Coord *offy);
    105 EAPI Eina_Bool    ewk_tiled_backing_store_zoom_weak_set(Evas_Object *o, float zoom, Evas_Coord cx, Evas_Coord cy);
    106 EAPI void ewk_tiled_backing_store_fix_offsets(Evas_Object *o, Evas_Coord w, Evas_Coord h);
    107 EAPI void ewk_tiled_backing_store_zoom_weak_smooth_scale_set(Evas_Object *o, Eina_Bool smooth_scale);
    108 EAPI Eina_Bool    ewk_tiled_backing_store_update(Evas_Object *o, const Eina_Rectangle *update);
    109 EAPI void ewk_tiled_backing_store_updates_process_pre_set(Evas_Object *o, void *(*cb)(void *data, Evas_Object *o), const void *data);
    110 EAPI void ewk_tiled_backing_store_updates_process_post_set(Evas_Object *o, void *(*cb)(void *data, void *pre_data, Evas_Object *o), const void *data);
    111 EAPI void ewk_tiled_backing_store_process_entire_queue_set(Evas_Object *o, Eina_Bool value);
    112 EAPI void ewk_tiled_backing_store_updates_process(Evas_Object *o);
    113 EAPI void ewk_tiled_backing_store_updates_clear(Evas_Object *o);
    114 EAPI void ewk_tiled_backing_store_contents_resize(Evas_Object *o, Evas_Coord width, Evas_Coord height);
    115 EAPI void ewk_tiled_backing_store_disabled_update_set(Evas_Object *o, Eina_Bool value);
    116 EAPI void ewk_tiled_backing_store_flush(Evas_Object *o);
    117 EAPI void ewk_tiled_backing_store_enable_scale_set(Evas_Object *o, Eina_Bool value);
    118 
    119 EAPI Ewk_Tile_Unused_Cache *ewk_tiled_backing_store_tile_unused_cache_get(const Evas_Object *o);
    120 EAPI void                   ewk_tiled_backing_store_tile_unused_cache_set(Evas_Object *o, Ewk_Tile_Unused_Cache *tuc);
    121 
    122 EAPI Eina_Bool ewk_tiled_backing_store_pre_render_region(Evas_Object *o, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, float zoom);
    123 EAPI Eina_Bool ewk_tiled_backing_store_pre_render_relative_radius(Evas_Object *o, unsigned int n, float zoom);
    124 EAPI void ewk_tiled_backing_store_pre_render_cancel(Evas_Object *o);
    125 
    126 EAPI Eina_Bool ewk_tiled_backing_store_disable_render(Evas_Object *o);
    127 EAPI Eina_Bool ewk_tiled_backing_store_enable_render(Evas_Object *o);
    128 #ifdef __cplusplus
    129 }
    130 #endif
    131 #endif // ewk_tiled_backing_store_h
    132