diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/modules/engines/buffer/evas_outbuf.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/modules/engines/buffer/evas_outbuf.c')
-rw-r--r-- | libraries/evas/src/modules/engines/buffer/evas_outbuf.c | 340 |
1 files changed, 340 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/buffer/evas_outbuf.c b/libraries/evas/src/modules/engines/buffer/evas_outbuf.c new file mode 100644 index 0000000..27f7a2c --- /dev/null +++ b/libraries/evas/src/modules/engines/buffer/evas_outbuf.c | |||
@@ -0,0 +1,340 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_engine.h" | ||
3 | |||
4 | void | ||
5 | evas_buffer_outbuf_buf_init(void) | ||
6 | { | ||
7 | } | ||
8 | |||
9 | void | ||
10 | evas_buffer_outbuf_buf_free(Outbuf *buf) | ||
11 | { | ||
12 | if (buf->priv.back_buf) | ||
13 | { | ||
14 | evas_cache_image_drop(&buf->priv.back_buf->cache_entry); | ||
15 | } | ||
16 | free(buf); | ||
17 | } | ||
18 | |||
19 | Outbuf * | ||
20 | evas_buffer_outbuf_buf_setup_fb(int w, int h, Outbuf_Depth depth, void *dest, int dest_row_bytes, int use_color_key, DATA32 color_key, int alpha_level, | ||
21 | void * (*new_update_region) (int x, int y, int w, int h, int *row_bytes), | ||
22 | void (*free_update_region) (int x, int y, int w, int h, void *data) | ||
23 | ) | ||
24 | { | ||
25 | Outbuf *buf; | ||
26 | int bpp; | ||
27 | |||
28 | buf = calloc(1, sizeof(Outbuf)); | ||
29 | if (!buf) return NULL; | ||
30 | |||
31 | buf->w = w; | ||
32 | buf->h = h; | ||
33 | buf->depth = depth; | ||
34 | |||
35 | buf->dest = dest; | ||
36 | buf->dest_row_bytes = dest_row_bytes; | ||
37 | |||
38 | buf->alpha_level = alpha_level; | ||
39 | buf->color_key = color_key; | ||
40 | buf->use_color_key = use_color_key; | ||
41 | |||
42 | buf->func.new_update_region = new_update_region; | ||
43 | buf->func.free_update_region = free_update_region; | ||
44 | |||
45 | bpp = sizeof(DATA32); | ||
46 | if ((buf->depth == OUTBUF_DEPTH_RGB_24BPP_888_888) || | ||
47 | (buf->depth == OUTBUF_DEPTH_BGR_24BPP_888_888)) | ||
48 | bpp = 3; | ||
49 | |||
50 | if ((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888) && | ||
51 | (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32)))) | ||
52 | { | ||
53 | memset(buf->dest, 0, h * buf->dest_row_bytes); | ||
54 | buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(), | ||
55 | w, h, | ||
56 | buf->dest, | ||
57 | 1, EVAS_COLORSPACE_ARGB8888); | ||
58 | } | ||
59 | else if ((buf->depth == OUTBUF_DEPTH_RGB_32BPP_888_8888) && | ||
60 | (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32)))) | ||
61 | { | ||
62 | buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(), | ||
63 | w, h, | ||
64 | buf->dest, | ||
65 | 0, EVAS_COLORSPACE_ARGB8888); | ||
66 | } | ||
67 | |||
68 | return buf; | ||
69 | } | ||
70 | |||
71 | RGBA_Image * | ||
72 | evas_buffer_outbuf_buf_new_region_for_update(Outbuf *buf, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch) | ||
73 | { | ||
74 | RGBA_Image *im; | ||
75 | |||
76 | if (buf->priv.back_buf) | ||
77 | { | ||
78 | *cx = x; *cy = y; *cw = w; *ch = h; | ||
79 | return buf->priv.back_buf; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | *cx = 0; *cy = 0; *cw = w; *ch = h; | ||
84 | im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get()); | ||
85 | if (im) | ||
86 | { | ||
87 | if (((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888)) || | ||
88 | ((buf->depth == OUTBUF_DEPTH_BGRA_32BPP_8888_8888))) | ||
89 | { | ||
90 | im->cache_entry.flags.alpha = 1; | ||
91 | im = (RGBA_Image *) evas_cache_image_size_set(&im->cache_entry, w, h); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | return im; | ||
96 | } | ||
97 | |||
98 | void | ||
99 | evas_buffer_outbuf_buf_free_region_for_update(Outbuf *buf, RGBA_Image *update) | ||
100 | { | ||
101 | if (update != buf->priv.back_buf) evas_cache_image_drop(&update->cache_entry); | ||
102 | } | ||
103 | |||
104 | void | ||
105 | evas_buffer_outbuf_buf_push_updated_region(Outbuf *buf, RGBA_Image *update, int x, int y, int w, int h) | ||
106 | { | ||
107 | /* copy update image to out buf & convert */ | ||
108 | switch (buf->depth) | ||
109 | { | ||
110 | case OUTBUF_DEPTH_RGB_24BPP_888_888: | ||
111 | /* copy & pack into 24bpp - if colorkey is enabled... etc. */ | ||
112 | { | ||
113 | DATA8 thresh; | ||
114 | int xx, yy; | ||
115 | int row_bytes; | ||
116 | DATA8 *dest; | ||
117 | DATA32 colorkey; | ||
118 | DATA32 *src; | ||
119 | DATA8 *dst; | ||
120 | |||
121 | colorkey = buf->color_key; | ||
122 | thresh = buf->alpha_level; | ||
123 | row_bytes = buf->dest_row_bytes; | ||
124 | dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3); | ||
125 | if (buf->func.new_update_region) | ||
126 | { | ||
127 | dest = buf->func.new_update_region(x, y, w, h, &row_bytes); | ||
128 | } | ||
129 | if (!dest) break; | ||
130 | if (buf->use_color_key) | ||
131 | { | ||
132 | for (yy = 0; yy < h; yy++) | ||
133 | { | ||
134 | dst = dest + (yy * row_bytes); | ||
135 | src = update->image.data + (yy * update->cache_entry.w); | ||
136 | for (xx = 0; xx < w; xx++) | ||
137 | { | ||
138 | if (A_VAL(src) > thresh) | ||
139 | { | ||
140 | *dst++ = R_VAL(src); | ||
141 | *dst++ = G_VAL(src); | ||
142 | *dst++ = B_VAL(src); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | *dst++ = R_VAL(&colorkey); | ||
147 | *dst++ = G_VAL(&colorkey); | ||
148 | *dst++ = B_VAL(&colorkey); | ||
149 | } | ||
150 | src++; | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | for (yy = 0; yy < h; yy++) | ||
157 | { | ||
158 | dst = dest + (yy * row_bytes); | ||
159 | src = update->image.data + (yy * update->cache_entry.w); | ||
160 | for (xx = 0; xx < w; xx++) | ||
161 | { | ||
162 | *dst++ = R_VAL(src); | ||
163 | *dst++ = G_VAL(src); | ||
164 | *dst++ = B_VAL(src); | ||
165 | src++; | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | if (buf->func.free_update_region) | ||
170 | { | ||
171 | buf->func.free_update_region(x, y, w, h, dest); | ||
172 | } | ||
173 | } | ||
174 | break; | ||
175 | case OUTBUF_DEPTH_BGR_24BPP_888_888: | ||
176 | /* copy & pack into 24bpp - if colorkey is enabled... etc. */ | ||
177 | { | ||
178 | DATA8 thresh; | ||
179 | int xx, yy; | ||
180 | int row_bytes; | ||
181 | DATA8 *dest; | ||
182 | DATA32 colorkey; | ||
183 | DATA32 *src; | ||
184 | DATA8 *dst; | ||
185 | |||
186 | colorkey = buf->color_key; | ||
187 | thresh = buf->alpha_level; | ||
188 | row_bytes = buf->dest_row_bytes; | ||
189 | dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3); | ||
190 | if (buf->func.new_update_region) | ||
191 | { | ||
192 | dest = buf->func.new_update_region(x, y, w, h, &row_bytes); | ||
193 | } | ||
194 | if (!dest) break; | ||
195 | if (buf->use_color_key) | ||
196 | { | ||
197 | for (yy = 0; yy < h; yy++) | ||
198 | { | ||
199 | dst = dest + (yy * row_bytes); | ||
200 | src = update->image.data + (yy * update->cache_entry.w); | ||
201 | for (xx = 0; xx < w; xx++) | ||
202 | { | ||
203 | if (A_VAL(src) > thresh) | ||
204 | { | ||
205 | *dst++ = B_VAL(src); | ||
206 | *dst++ = G_VAL(src); | ||
207 | *dst++ = R_VAL(src); | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | *dst++ = B_VAL(&colorkey); | ||
212 | *dst++ = G_VAL(&colorkey); | ||
213 | *dst++ = R_VAL(&colorkey); | ||
214 | } | ||
215 | src++; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | else | ||
220 | { | ||
221 | for (yy = 0; yy < h; yy++) | ||
222 | { | ||
223 | dst = dest + (yy * row_bytes); | ||
224 | src = update->image.data + (yy * update->cache_entry.w); | ||
225 | for (xx = 0; xx < w; xx++) | ||
226 | { | ||
227 | *dst++ = B_VAL(src); | ||
228 | *dst++ = G_VAL(src); | ||
229 | *dst++ = R_VAL(src); | ||
230 | src++; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | if (buf->func.free_update_region) | ||
235 | { | ||
236 | buf->func.free_update_region(x, y, w, h, dest); | ||
237 | } | ||
238 | } | ||
239 | break; | ||
240 | case OUTBUF_DEPTH_RGB_32BPP_888_8888: | ||
241 | case OUTBUF_DEPTH_ARGB_32BPP_8888_8888: | ||
242 | { | ||
243 | DATA32 *dest, *src, *dst; | ||
244 | int yy, row_bytes; | ||
245 | |||
246 | row_bytes = buf->dest_row_bytes; | ||
247 | dest = (DATA32 *)((DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4)); | ||
248 | if (buf->func.new_update_region) | ||
249 | { | ||
250 | dest = buf->func.new_update_region(x, y, w, h, &row_bytes); | ||
251 | } | ||
252 | /* no need src == dest */ | ||
253 | if (!buf->priv.back_buf) | ||
254 | { | ||
255 | Gfx_Func_Copy func; | ||
256 | |||
257 | func = evas_common_draw_func_copy_get(w, 0); | ||
258 | if (func) | ||
259 | { | ||
260 | for (yy = 0; yy < h; yy++) | ||
261 | { | ||
262 | src = update->image.data + (yy * update->cache_entry.w); | ||
263 | dst = (DATA32 *)((DATA8 *)(buf->dest) + ((y + yy) * row_bytes)); | ||
264 | func(src, dst, w); | ||
265 | } | ||
266 | |||
267 | } | ||
268 | } | ||
269 | if (buf->func.free_update_region) | ||
270 | { | ||
271 | buf->func.free_update_region(x, y, w, h, dest); | ||
272 | } | ||
273 | } | ||
274 | break; | ||
275 | case OUTBUF_DEPTH_BGR_32BPP_888_8888: | ||
276 | { | ||
277 | DATA32 *src, *dst; | ||
278 | DATA8 *dest; | ||
279 | int xx, yy, row_bytes; | ||
280 | |||
281 | row_bytes = buf->dest_row_bytes; | ||
282 | dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4); | ||
283 | if (buf->func.new_update_region) | ||
284 | { | ||
285 | dest = buf->func.new_update_region(x, y, w, h, &row_bytes); | ||
286 | } | ||
287 | for (yy = 0; yy < h; yy++) | ||
288 | { | ||
289 | dst = (DATA32 *)(dest + (yy * row_bytes)); | ||
290 | src = update->image.data + (yy * update->cache_entry.w); | ||
291 | for (xx = 0; xx < w; xx++) | ||
292 | { | ||
293 | A_VAL(dst) = B_VAL(src); | ||
294 | R_VAL(dst) = G_VAL(src); | ||
295 | G_VAL(dst) = R_VAL(src); | ||
296 | dst++; | ||
297 | src++; | ||
298 | } | ||
299 | } | ||
300 | if (buf->func.free_update_region) | ||
301 | { | ||
302 | buf->func.free_update_region(x, y, w, h, dest); | ||
303 | } | ||
304 | } | ||
305 | break; | ||
306 | case OUTBUF_DEPTH_BGRA_32BPP_8888_8888: | ||
307 | { | ||
308 | DATA32 *src, *dst; | ||
309 | DATA8 *dest; | ||
310 | int xx, yy, row_bytes; | ||
311 | |||
312 | row_bytes = buf->dest_row_bytes; | ||
313 | dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4); | ||
314 | if (buf->func.new_update_region) | ||
315 | { | ||
316 | dest = buf->func.new_update_region(x, y, w, h, &row_bytes); | ||
317 | } | ||
318 | for (yy = 0; yy < h; yy++) | ||
319 | { | ||
320 | dst = (DATA32 *)(dest + (yy * row_bytes)); | ||
321 | src = update->image.data + (yy * update->cache_entry.w); | ||
322 | for (xx = 0; xx < w; xx++) | ||
323 | { | ||
324 | A_VAL(dst) = B_VAL(src); | ||
325 | R_VAL(dst) = G_VAL(src); | ||
326 | G_VAL(dst) = R_VAL(src); | ||
327 | dst++; | ||
328 | src++; | ||
329 | } | ||
330 | } | ||
331 | if (buf->func.free_update_region) | ||
332 | { | ||
333 | buf->func.free_update_region(x, y, w, h, dest); | ||
334 | } | ||
335 | } | ||
336 | break; | ||
337 | default: | ||
338 | break; | ||
339 | } | ||
340 | } | ||