summaryrefslogtreecommitdiff
path: root/src/lib/ector/software/ector_software_buffer.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-12-01 15:22:20 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-12-03 18:42:50 +0900
commitbad7911cd0f9d7eaa51c0c7b67ff3ed8d7da5599 (patch)
treec1f3f9552f9101c90d904e85f6d8bf5cc43cda57 /src/lib/ector/software/ector_software_buffer.c
parent0cf5719e526b17bb6ad03f05643a760edf389e98 (diff)
Ector: Use Ector Buffer inside SW and Cairo renderers
Ector Surface now inherits from Ector Buffer, and the current two renderers (SW and Cairo SW) use Ector.Software.Buffer implementations for pixel surfaces. Basic pixel handling is merged and will allow easy extension (color conversion, etc...). Buffer classes are Mixins to be fully implemented by the final class, such as: Ector.Software.Buffer, Ector.Software.Surface or Ector.Cairo.Surface. This is a large ugly commit. Sorry. The code is quite a mess right now.
Diffstat (limited to 'src/lib/ector/software/ector_software_buffer.c')
-rw-r--r--src/lib/ector/software/ector_software_buffer.c111
1 files changed, 66 insertions, 45 deletions
diff --git a/src/lib/ector/software/ector_software_buffer.c b/src/lib/ector/software/ector_software_buffer.c
index 4fdbcde947..541417f558 100644
--- a/src/lib/ector/software/ector_software_buffer.c
+++ b/src/lib/ector/software/ector_software_buffer.c
@@ -9,6 +9,9 @@
9#include "ector_private.h" 9#include "ector_private.h"
10#include "ector_software_private.h" 10#include "ector_software_private.h"
11#include "ector_generic_buffer.eo.h" 11#include "ector_generic_buffer.eo.h"
12#include "ector_software_buffer_base.eo.h"
13
14#define MY_CLASS ECTOR_SOFTWARE_BUFFER_CLASS
12 15
13#define fail(fmt, ...) do { ERR(fmt, ##__VA_ARGS__); goto on_fail; } while (0) 16#define fail(fmt, ...) do { ERR(fmt, ##__VA_ARGS__); goto on_fail; } while (0)
14 17
@@ -47,7 +50,7 @@ _pixels_gry8_to_argb_convert(uint32_t *dst, const uint8_t *src, int len)
47} 50}
48 51
49EOLIAN static void 52EOLIAN static void
50_ector_software_buffer_pixels_clear(Eo *obj, Ector_Software_Buffer_Data *pd) 53_ector_software_buffer_base_pixels_clear(Eo *obj, Ector_Software_Buffer_Base_Data *pd)
51{ 54{
52 if (!pd->pixels.u8) 55 if (!pd->pixels.u8)
53 return; 56 return;
@@ -62,11 +65,11 @@ _ector_software_buffer_pixels_clear(Eo *obj, Ector_Software_Buffer_Data *pd)
62} 65}
63 66
64EOLIAN static Eina_Bool 67EOLIAN static Eina_Bool
65_ector_software_buffer_ector_generic_buffer_pixels_set(Eo *obj, Ector_Software_Buffer_Data *pd, 68_ector_software_buffer_base_ector_generic_buffer_pixels_set(Eo *obj, Ector_Software_Buffer_Base_Data *pd,
66 void *pixels, int width, int height, int stride, 69 void *pixels, int width, int height, int stride,
67 Efl_Gfx_Colorspace cspace, Eina_Bool writable, 70 Efl_Gfx_Colorspace cspace, Eina_Bool writable,
68 unsigned char l, unsigned char r, 71 unsigned char l, unsigned char r,
69 unsigned char t, unsigned char b) 72 unsigned char t, unsigned char b)
70{ 73{
71 // safety check 74 // safety check
72 unsigned px = _min_stride_calc(1, cspace); 75 unsigned px = _min_stride_calc(1, cspace);
@@ -86,12 +89,15 @@ _ector_software_buffer_ector_generic_buffer_pixels_set(Eo *obj, Ector_Software_B
86 { 89 {
87 ERR("Invalid stride %u for width %u (+%u+%u) cspace %u. pixels_set failed.", 90 ERR("Invalid stride %u for width %u (+%u+%u) cspace %u. pixels_set failed.",
88 stride, width, l, r, cspace); 91 stride, width, l, r, cspace);
89 _ector_software_buffer_pixels_clear(obj, pd); 92 _ector_software_buffer_base_pixels_clear(obj, pd);
90 return EINA_FALSE; 93 return EINA_FALSE;
91 } 94 }
92 95
96 if ((px > 1) && (stride & (px - 1)))
97 ERR("Stride (%d) is not aligned to the pixel size (%d)", stride, px);
98
93 if (pd->pixels.u8 && (pd->pixels.u8 != pixels)) 99 if (pd->pixels.u8 && (pd->pixels.u8 != pixels))
94 _ector_software_buffer_pixels_clear(obj, pd); 100 _ector_software_buffer_base_pixels_clear(obj, pd);
95 101
96 if (pixels) 102 if (pixels)
97 { 103 {
@@ -105,38 +111,39 @@ _ector_software_buffer_ector_generic_buffer_pixels_set(Eo *obj, Ector_Software_B
105 pd->nofree = EINA_FALSE; 111 pd->nofree = EINA_FALSE;
106 pd->writable = EINA_TRUE; 112 pd->writable = EINA_TRUE;
107 } 113 }
108 pd->generic.w = width; 114 pd->generic->w = width;
109 pd->generic.h = height; 115 pd->generic->h = height;
110 pd->generic.l = l; 116 pd->generic->l = l;
111 pd->generic.r = r; 117 pd->generic->r = r;
112 pd->generic.t = t; 118 pd->generic->t = t;
113 pd->generic.b = b; 119 pd->generic->b = b;
114 pd->generic.cspace = cspace; 120 pd->generic->cspace = cspace;
115 pd->stride = stride; 121 pd->stride = stride;
122 pd->pixel_size = px;
116 return EINA_TRUE; 123 return EINA_TRUE;
117} 124}
118 125
119EOLIAN static uint8_t * 126EOLIAN static uint8_t *
120_ector_software_buffer_ector_generic_buffer_map(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Data *pd, 127_ector_software_buffer_base_ector_generic_buffer_map(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd,
121 int *offset, unsigned int *length, 128 int *offset, unsigned int *length,
122 Ector_Buffer_Access_Flag mode EINA_UNUSED, 129 Ector_Buffer_Access_Flag mode EINA_UNUSED,
123 unsigned int x, unsigned int y, unsigned int w, unsigned int h, 130 unsigned int x, unsigned int y, unsigned int w, unsigned int h,
124 Efl_Gfx_Colorspace cspace EINA_UNUSED, unsigned int *stride) 131 Efl_Gfx_Colorspace cspace EINA_UNUSED, unsigned int *stride)
125{ 132{
126 int off; 133 int off;
127 134
128 if (!pd->pixels.u8 || !pd->stride) 135 if (!pd->pixels.u8 || !pd->stride)
129 fail("Buffer has no pixel data yet"); 136 fail("Buffer has no pixel data yet");
130 if (cspace != pd->generic.cspace) 137 if (cspace != pd->generic->cspace)
131 fail("Invalid colorspace"); 138 fail("Invalid colorspace");
132 if (!w || !h || ((x + w) > pd->generic.w) || (y + h > pd->generic.h)) 139 if (!w || !h || ((x + w) > pd->generic->w) || (y + h > pd->generic->h))
133 fail("Invalid region requested: wanted %u,%u %ux%u but image is %ux%u", 140 fail("Invalid region requested: wanted %u,%u %ux%u but image is %ux%u",
134 x, y, w, h, pd->generic.w, pd->generic.h); 141 x, y, w, h, pd->generic->w, pd->generic->h);
135 142
136 pd->map_count++; 143 pd->map_count++;
137 off = _min_stride_calc(x + pd->generic.l, pd->generic.cspace) + (pd->stride * (y + pd->generic.t)); 144 off = _min_stride_calc(x + pd->generic->l, pd->generic->cspace) + (pd->stride * (y + pd->generic->t));
138 if (offset) *offset = off; 145 if (offset) *offset = off;
139 if (length) *length = (pd->stride * pd->generic.h) - off; 146 if (length) *length = (pd->stride * pd->generic->h) - off;
140 if (stride) *stride = pd->stride; 147 if (stride) *stride = pd->stride;
141 return pd->pixels.u8; 148 return pd->pixels.u8;
142 149
@@ -148,7 +155,7 @@ on_fail:
148} 155}
149 156
150EOLIAN static void 157EOLIAN static void
151_ector_software_buffer_ector_generic_buffer_unmap(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Data *pd, void *data, int offset EINA_UNUSED, unsigned int length EINA_UNUSED) 158_ector_software_buffer_base_ector_generic_buffer_unmap(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd, void *data, int offset EINA_UNUSED, unsigned int length EINA_UNUSED)
152{ 159{
153 if (!data) return; 160 if (!data) return;
154 if (data != pd->pixels.u8) 161 if (data != pd->pixels.u8)
@@ -164,35 +171,35 @@ _ector_software_buffer_ector_generic_buffer_unmap(Eo *obj EINA_UNUSED, Ector_Sof
164 pd->map_count--; 171 pd->map_count--;
165} 172}
166 173
167EOLIAN uint8_t * 174EOLIAN static uint8_t *
168_ector_software_buffer_ector_generic_buffer_span_get(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Data *pd, 175_ector_software_buffer_base_ector_generic_buffer_span_get(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd,
169 int x, int y, unsigned int w, Efl_Gfx_Colorspace cspace, 176 int x, int y, unsigned int w, Efl_Gfx_Colorspace cspace,
170 unsigned int *length) 177 unsigned int *length)
171{ 178{
172 uint8_t *src; 179 uint8_t *src;
173 int len, px; 180 int len, px;
174 181
175 if (!pd->pixels.u8) 182 if (!pd->pixels.u8)
176 fail("No pixel data"); 183 fail("No pixel data");
177 if ((x < -pd->generic.l) || (y < -pd->generic.t) || 184 if ((x < -pd->generic->l) || (y < -pd->generic->t) ||
178 ((unsigned) x > pd->generic.w) || ((unsigned) y > pd->generic.h)) 185 ((unsigned) x > pd->generic->w) || ((unsigned) y > pd->generic->h))
179 fail("Out of bounds"); 186 fail("Out of bounds");
180 if (((unsigned) x + w) > (pd->generic.w + pd->generic.l + pd->generic.r)) 187 if (((unsigned) x + w) > (pd->generic->w + pd->generic->l + pd->generic->r))
181 fail("Requested span too large"); 188 fail("Requested span too large");
182 189
183 px = _min_stride_calc(1, pd->generic.cspace); 190 px = _min_stride_calc(1, pd->generic->cspace);
184 len = _min_stride_calc(w, cspace); 191 len = _min_stride_calc(w, cspace);
185 if (length) *length = len; 192 if (length) *length = len;
186 193
187 src = pd->pixels.u8 + ((pd->generic.t + y) * pd->stride) + (px * (pd->generic.l + x)); 194 src = pd->pixels.u8 + ((pd->generic->t + y) * pd->stride) + (px * (pd->generic->l + x));
188 195
189 if (cspace == pd->generic.cspace) 196 if (cspace == pd->generic->cspace)
190 { 197 {
191 pd->span_free = EINA_FALSE; 198 pd->span_free = EINA_FALSE;
192 return src; 199 return src;
193 } 200 }
194 else if ((cspace == EFL_GFX_COLORSPACE_ARGB8888) && 201 else if ((cspace == EFL_GFX_COLORSPACE_ARGB8888) &&
195 (pd->generic.cspace == EFL_GFX_COLORSPACE_GRY8)) 202 (pd->generic->cspace == EFL_GFX_COLORSPACE_GRY8))
196 { 203 {
197 uint32_t *buf = malloc(len); 204 uint32_t *buf = malloc(len);
198 _pixels_gry8_to_argb_convert(buf, src, w); 205 _pixels_gry8_to_argb_convert(buf, src, w);
@@ -200,7 +207,7 @@ _ector_software_buffer_ector_generic_buffer_span_get(Eo *obj EINA_UNUSED, Ector_
200 return (uint8_t *) buf; 207 return (uint8_t *) buf;
201 } 208 }
202 else if ((cspace == EFL_GFX_COLORSPACE_GRY8) && 209 else if ((cspace == EFL_GFX_COLORSPACE_GRY8) &&
203 (pd->generic.cspace == EFL_GFX_COLORSPACE_ARGB8888)) 210 (pd->generic->cspace == EFL_GFX_COLORSPACE_ARGB8888))
204 { 211 {
205 uint8_t *buf = malloc(len); 212 uint8_t *buf = malloc(len);
206 _pixels_argb_to_gry8_convert(buf, (uint32_t *) src, w); 213 _pixels_argb_to_gry8_convert(buf, (uint32_t *) src, w);
@@ -215,16 +222,16 @@ on_fail:
215 return NULL; 222 return NULL;
216} 223}
217 224
218EOLIAN void 225EOLIAN static void
219_ector_software_buffer_ector_generic_buffer_span_free(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Data *pd, 226_ector_software_buffer_base_ector_generic_buffer_span_free(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd,
220 uint8_t *data) 227 uint8_t *data)
221{ 228{
222 if (pd->span_free) free(data); 229 if (pd->span_free) free(data);
223 pd->span_free = EINA_FALSE; 230 pd->span_free = EINA_FALSE;
224} 231}
225 232
226EOLIAN static Ector_Buffer_Flag 233EOLIAN static Ector_Buffer_Flag
227_ector_software_buffer_ector_generic_buffer_flags_get(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Data *pd) 234_ector_software_buffer_base_ector_generic_buffer_flags_get(Eo *obj EINA_UNUSED, Ector_Software_Buffer_Base_Data *pd)
228{ 235{
229 return ECTOR_BUFFER_FLAG_CPU_READABLE | 236 return ECTOR_BUFFER_FLAG_CPU_READABLE |
230 ECTOR_BUFFER_FLAG_CPU_READABLE_FAST | 237 ECTOR_BUFFER_FLAG_CPU_READABLE_FAST |
@@ -234,11 +241,24 @@ _ector_software_buffer_ector_generic_buffer_flags_get(Eo *obj EINA_UNUSED, Ector
234 : 0); 241 : 0);
235} 242}
236 243
244EOLIAN static Eo_Base *
245_ector_software_buffer_eo_base_constructor(Eo *obj, void *data EINA_UNUSED)
246{
247 Ector_Software_Buffer_Base_Data *pd;
248 eo_do_super(obj, MY_CLASS, obj = eo_constructor());
249 pd = eo_data_scope_get(obj, ECTOR_SOFTWARE_BUFFER_BASE_MIXIN);
250 pd->generic = eo_data_ref(obj, ECTOR_GENERIC_BUFFER_MIXIN);
251 pd->generic->eo = obj;
252 return obj;
253}
254
237EOLIAN static void 255EOLIAN static void
238_ector_software_buffer_eo_base_destructor(Eo *obj, Ector_Software_Buffer_Data *pd) 256_ector_software_buffer_eo_base_destructor(Eo *obj, void *data EINA_UNUSED)
239{ 257{
240 _ector_software_buffer_pixels_clear(obj, pd); 258 Ector_Software_Buffer_Base_Data *pd = eo_data_scope_get(obj, ECTOR_SOFTWARE_BUFFER_BASE_MIXIN);
241 eo_do_super(obj, ECTOR_SOFTWARE_BUFFER_CLASS, eo_destructor()); 259 _ector_software_buffer_base_pixels_clear(obj, pd);
260 eo_data_unref(obj, pd->generic);
261 eo_do_super(obj, MY_CLASS, eo_destructor());
242 if (pd->map_count) 262 if (pd->map_count)
243 { 263 {
244 ERR("Pixel data is still mapped during destroy! Check your code!"); 264 ERR("Pixel data is still mapped during destroy! Check your code!");
@@ -246,3 +266,4 @@ _ector_software_buffer_eo_base_destructor(Eo *obj, Ector_Software_Buffer_Data *p
246} 266}
247 267
248#include "ector_software_buffer.eo.c" 268#include "ector_software_buffer.eo.c"
269#include "ector_software_buffer_base.eo.c"