1 /* This file is part of GEGL.
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 3 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
15  *
16  * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
17  */
18 
19 #ifndef __GEGL_TILE_STORAGE_H__
20 #define __GEGL_TILE_STORAGE_H__
21 
22 #include "gegl-buffer.h"
23 #include "gegl-tile-handler-chain.h"
24 #include "gegl-tile-handler-cache.h"
25 
26 /***
27  * GeglTileStorage provide the command API to GeglBuffer, and setup a chain of GeglTileHandler to
28  * treat and store tiles.
29  */
30 
31 #define GEGL_TYPE_TILE_STORAGE            (gegl_tile_storage_get_type ())
32 #define GEGL_TILE_STORAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_TILE_STORAGE, GeglTileStorage))
33 #define GEGL_TILE_STORAGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GEGL_TYPE_TILE_STORAGE, GeglTileStorageClass))
34 #define GEGL_IS_TILE_STORAGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_TILE_STORAGE))
35 #define GEGL_IS_TILE_STORAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GEGL_TYPE_TILE_STORAGE))
36 #define GEGL_TILE_STORAGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GEGL_TYPE_TILE_STORAGE, GeglTileStorageClass))
37 
38 typedef struct _GeglTileStorageClass GeglTileStorageClass;
39 
40 struct _GeglTileStorage
41 {
42   GeglTileHandlerChain parent_instance;
43   GeglTileHandlerCache *cache;
44   GRecMutex      mutex;
45   const Babl    *format;
46   gint           tile_width;
47   gint           tile_height;
48   gint           tile_size;
49   gint           px_size;
50   gint           seen_zoom; /* the maximum zoom level we've seen tiles for */
51   gint           n_user_handlers; /* number of handlers added through
52                                    * gegl_tile_storage_add_handler()
53                                    */
54 
55   GeglTile      *hot_tile; /* cached tile for speeding up gegl_buffer_get_pixel
56                               and gegl_buffer_set_pixel (1x1 sized gets/sets)*/
57 };
58 
59 struct _GeglTileStorageClass
60 {
61   GeglTileHandlerChainClass parent_class;
62 };
63 
64 GType gegl_tile_storage_get_type (void) G_GNUC_CONST;
65 
66 GeglTileStorage *
67 gegl_tile_storage_new (GeglTileBackend *backend,
68                        gboolean         initialized);
69 
70 void gegl_tile_storage_add_handler (GeglTileStorage *tile_storage, GeglTileHandler *handler);
71 void gegl_tile_storage_remove_handler (GeglTileStorage *tile_storage, GeglTileHandler *handler);
72 
73 GeglTile * gegl_tile_storage_steal_hot_tile     (GeglTileStorage *tile_storage);
74 GeglTile * gegl_tile_storage_try_steal_hot_tile (GeglTileStorage *tile_storage,
75                                                  GeglTile        *tile);
76 void       gegl_tile_storage_take_hot_tile      (GeglTileStorage *tile_storage,
77                                                  GeglTile        *tile);
78 
79 #endif
80