summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-12-10 17:15:25 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-01-05 15:43:43 +0900
commit9121e503a3a1394e7b56b0e54b6bba3a0338d1e2 (patch)
treec501230f09c011a49d3468d01a43439ac69f5ccf
parent7a8879ba8bf5d9aec15428f94222222eea6c0e2e (diff)
ector: track maps in software buffer
-rw-r--r--src/lib/ector/ector_buffer.h4
-rw-r--r--src/lib/ector/software/ector_software_buffer.c50
2 files changed, 34 insertions, 20 deletions
diff --git a/src/lib/ector/ector_buffer.h b/src/lib/ector/ector_buffer.h
index afa6f288c5..f4a5f9df8c 100644
--- a/src/lib/ector/ector_buffer.h
+++ b/src/lib/ector/ector_buffer.h
@@ -30,7 +30,9 @@ typedef struct _Ector_Software_Buffer_Base_Data
30 } pixels; 30 } pixels;
31 unsigned int stride; 31 unsigned int stride;
32 unsigned int pixel_size; // in bytes 32 unsigned int pixel_size; // in bytes
33 unsigned int map_count; 33 struct {
34 Eina_Inlist *maps; // Ector_Software_Buffer_Map
35 } internal;
34 Eina_Bool writable : 1; // pixels can be written to 36 Eina_Bool writable : 1; // pixels can be written to
35 Eina_Bool nofree : 1; // pixel data should not be free()'ed 37 Eina_Bool nofree : 1; // pixel data should not be free()'ed
36 Eina_Bool span_free : 1; // FIXME 38 Eina_Bool span_free : 1; // FIXME
diff --git a/src/lib/ector/software/ector_software_buffer.c b/src/lib/ector/software/ector_software_buffer.c
index 26c1329cda..1783258a95 100644
--- a/src/lib/ector/software/ector_software_buffer.c
+++ b/src/lib/ector/software/ector_software_buffer.c
@@ -1,21 +1,25 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2# include "config.h" 2# include "config.h"
3#else
4# define EFL_BETA_API_SUPPORT
5#endif 3#endif
6 4
7#include <Eo.h>
8#include "Ector_Software.h" 5#include "Ector_Software.h"
9#include "ector_private.h" 6#include "ector_private.h"
10#include "ector_software_private.h" 7#include "ector_software_private.h"
11#include "ector_generic_buffer.eo.h" 8#include "ector_buffer.h"
12#include "ector_software_buffer_base.eo.h"
13#include "draw.h" 9#include "draw.h"
14 10
15#define MY_CLASS ECTOR_SOFTWARE_BUFFER_CLASS 11#define MY_CLASS ECTOR_SOFTWARE_BUFFER_CLASS
16 12
17#define fail(fmt, ...) do { ERR(fmt, ##__VA_ARGS__); goto on_fail; } while (0) 13#define fail(fmt, ...) do { ERR(fmt, ##__VA_ARGS__); goto on_fail; } while (0)
18 14
15typedef struct _Ector_Software_Buffer_Map
16{
17 EINA_INLIST;
18 void *ptr;
19 unsigned int len;
20 Eina_Bool allocated;
21} Ector_Software_Buffer_Map;
22
19static inline int 23static inline int
20_min_stride_calc(int width, Efl_Gfx_Colorspace cspace) 24_min_stride_calc(int width, Efl_Gfx_Colorspace cspace)
21{ 25{
@@ -138,6 +142,7 @@ _ector_software_buffer_base_ector_generic_buffer_map(Eo *obj EINA_UNUSED, Ector_
138 unsigned int x, unsigned int y, unsigned int w, unsigned int h, 142 unsigned int x, unsigned int y, unsigned int w, unsigned int h,
139 Efl_Gfx_Colorspace cspace EINA_UNUSED, unsigned int *stride) 143 Efl_Gfx_Colorspace cspace EINA_UNUSED, unsigned int *stride)
140{ 144{
145 Ector_Software_Buffer_Map *map;
141 int off; 146 int off;
142 147
143 if (!pd->pixels.u8 || !pd->stride) 148 if (!pd->pixels.u8 || !pd->stride)
@@ -150,11 +155,16 @@ _ector_software_buffer_base_ector_generic_buffer_map(Eo *obj EINA_UNUSED, Ector_
150 if ((mode & ECTOR_BUFFER_ACCESS_FLAG_WRITE) && !pd->writable) 155 if ((mode & ECTOR_BUFFER_ACCESS_FLAG_WRITE) && !pd->writable)
151 fail("can not map a read-only buffer for writing"); 156 fail("can not map a read-only buffer for writing");
152 157
153 pd->map_count++;
154 off = _min_stride_calc(x + pd->generic->l, pd->generic->cspace) + (pd->stride * (y + pd->generic->t)); 158 off = _min_stride_calc(x + pd->generic->l, pd->generic->cspace) + (pd->stride * (y + pd->generic->t));
155 if (length) *length = (pd->stride * h) - off; 159
160 map = calloc(1, sizeof(*map));
161 map->len = (pd->stride * h) - off;
162 map->ptr = pd->pixels.u8 + off;
163 pd->internal.maps = eina_inlist_append(pd->internal.maps, EINA_INLIST_GET(map));
164
165 if (length) *length = map->len;
156 if (stride) *stride = pd->stride; 166 if (stride) *stride = pd->stride;
157 return pd->pixels.u8 + off; 167 return map->ptr;
158 168
159on_fail: 169on_fail:
160 if (length) *length = 0; 170 if (length) *length = 0;
@@ -164,20 +174,22 @@ on_fail:
164 174
165EOLIAN static void 175EOLIAN static void
166_ector_software_buffer_base_ector_generic_buffer_unmap(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd, 176_ector_software_buffer_base_ector_generic_buffer_unmap(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd,
167 void *data, unsigned int length EINA_UNUSED) 177 void *data, unsigned int length)
168{ 178{
179 Ector_Software_Buffer_Map *map;
169 if (!data) return; 180 if (!data) return;
170 if (data != pd->pixels.u8) 181
171 { 182 EINA_INLIST_FOREACH(pd->internal.maps, map)
172 CRI("Trying to unmap a non-mapped region!");
173 return;
174 }
175 if (pd->map_count == 0)
176 { 183 {
177 CRI("Unmapped too many times! Check your code!"); 184 if ((map->ptr == data) && (map->len == length))
178 return; 185 {
186 pd->internal.maps = eina_inlist_remove(pd->internal.maps, EINA_INLIST_GET(map));
187 free(map);
188 return;
189 }
179 } 190 }
180 pd->map_count--; 191
192 CRI("Tried to unmap a non-mapped region!");
181} 193}
182 194
183EOLIAN static uint8_t * 195EOLIAN static uint8_t *
@@ -268,7 +280,7 @@ _ector_software_buffer_eo_base_destructor(Eo *obj, void *data EINA_UNUSED)
268 _ector_software_buffer_base_pixels_clear(obj, pd); 280 _ector_software_buffer_base_pixels_clear(obj, pd);
269 eo_data_unref(obj, pd->generic); 281 eo_data_unref(obj, pd->generic);
270 eo_do_super(obj, MY_CLASS, eo_destructor()); 282 eo_do_super(obj, MY_CLASS, eo_destructor());
271 if (pd->map_count) 283 if (pd->internal.maps)
272 { 284 {
273 ERR("Pixel data is still mapped during destroy! Check your code!"); 285 ERR("Pixel data is still mapped during destroy! Check your code!");
274 } 286 }