6 #include "evas_cs2_private.h"
9 #include "evas_common.h"
10 #include "evas_engine.h"
13 evas_buffer_outbuf_buf_init(void)
18 evas_buffer_outbuf_buf_free(Outbuf *buf)
20 if (buf->priv.back_buf)
23 if (evas_cserve2_use_get())
24 evas_cache2_image_close(&buf->priv.back_buf->cache_entry);
27 evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
33 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,
34 void * (*new_update_region) (int x, int y, int w, int h, int *row_bytes),
35 void (*free_update_region) (int x, int y, int w, int h, void *data),
36 void * (*switch_buffer) (void *data, void *dest_buffer),
42 buf = calloc(1, sizeof(Outbuf));
43 if (!buf) return NULL;
50 buf->dest_row_bytes = dest_row_bytes;
52 buf->alpha_level = alpha_level;
53 buf->color_key = color_key;
54 buf->use_color_key = use_color_key;
57 buf->func.new_update_region = new_update_region;
58 buf->func.free_update_region = free_update_region;
59 buf->func.switch_buffer = switch_buffer;
60 buf->switch_data = switch_data;
62 if ((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888) &&
63 (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
65 memset(buf->dest, 0, h * buf->dest_row_bytes);
67 if (evas_cserve2_use_get())
68 buf->priv.back_buf = (RGBA_Image *) evas_cache2_image_data(evas_common_image_cache2_get(),
71 1, EVAS_COLORSPACE_ARGB8888);
74 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
77 1, EVAS_COLORSPACE_ARGB8888);
79 else if ((buf->depth == OUTBUF_DEPTH_RGB_32BPP_888_8888) &&
80 (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
83 if (evas_cserve2_use_get())
84 buf->priv.back_buf = (RGBA_Image *) evas_cache2_image_data(evas_common_image_cache2_get(),
87 0, EVAS_COLORSPACE_ARGB8888);
90 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
93 0, EVAS_COLORSPACE_ARGB8888);
100 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)
104 if (buf->priv.back_buf)
106 *cx = x; *cy = y; *cw = w; *ch = h;
107 return buf->priv.back_buf;
111 *cx = 0; *cy = 0; *cw = w; *ch = h;
113 if (evas_cserve2_use_get())
114 im = (RGBA_Image *)evas_cache2_image_empty(evas_common_image_cache2_get());
117 im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
120 if (((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888)) ||
121 ((buf->depth == OUTBUF_DEPTH_BGRA_32BPP_8888_8888)))
123 im->cache_entry.flags.alpha = 1;
125 if (evas_cserve2_use_get())
126 evas_cache2_image_size_set(&im->cache_entry, w, h);
129 im = (RGBA_Image *) evas_cache_image_size_set(&im->cache_entry, w, h);
137 evas_buffer_outbuf_buf_free_region_for_update(Outbuf *buf, RGBA_Image *update)
139 if (update != buf->priv.back_buf)
142 if (evas_cserve2_use_get())
143 evas_cache2_image_close(&update->cache_entry);
146 evas_cache_image_drop(&update->cache_entry);
151 evas_buffer_outbuf_buf_switch_buffer(Outbuf *buf)
153 if (buf->func.switch_buffer)
155 buf->dest = buf->func.switch_buffer(buf->switch_data, buf->dest);
156 if (buf->priv.back_buf)
159 if (evas_cserve2_use_get())
161 evas_cache2_image_close(&buf->priv.back_buf->cache_entry);
162 buf->priv.back_buf = (RGBA_Image *) evas_cache2_image_data(evas_common_image_cache2_get(),
165 buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888 ? 1 : 0,
166 EVAS_COLORSPACE_ARGB8888);
171 evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
172 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
175 buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888 ? 1 : 0,
176 EVAS_COLORSPACE_ARGB8888);
183 evas_buffer_outbuf_buf_push_updated_region(Outbuf *buf, RGBA_Image *update, int x, int y, int w, int h)
185 /* copy update image to out buf & convert */
188 case OUTBUF_DEPTH_RGB_24BPP_888_888:
189 /* copy & pack into 24bpp - if colorkey is enabled... etc. */
199 colorkey = buf->color_key;
200 thresh = buf->alpha_level;
201 row_bytes = buf->dest_row_bytes;
202 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
203 if (buf->func.new_update_region)
205 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
208 if (buf->use_color_key)
210 for (yy = 0; yy < h; yy++)
212 dst = dest + (yy * row_bytes);
213 src = update->image.data + (yy * update->cache_entry.w);
214 for (xx = 0; xx < w; xx++)
216 if (A_VAL(src) > thresh)
224 *dst++ = R_VAL(&colorkey);
225 *dst++ = G_VAL(&colorkey);
226 *dst++ = B_VAL(&colorkey);
234 for (yy = 0; yy < h; yy++)
236 dst = dest + (yy * row_bytes);
237 src = update->image.data + (yy * update->cache_entry.w);
238 for (xx = 0; xx < w; xx++)
247 if (buf->func.free_update_region)
249 buf->func.free_update_region(x, y, w, h, dest);
253 case OUTBUF_DEPTH_BGR_24BPP_888_888:
254 /* copy & pack into 24bpp - if colorkey is enabled... etc. */
264 colorkey = buf->color_key;
265 thresh = buf->alpha_level;
266 row_bytes = buf->dest_row_bytes;
267 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
268 if (buf->func.new_update_region)
270 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
273 if (buf->use_color_key)
275 for (yy = 0; yy < h; yy++)
277 dst = dest + (yy * row_bytes);
278 src = update->image.data + (yy * update->cache_entry.w);
279 for (xx = 0; xx < w; xx++)
281 if (A_VAL(src) > thresh)
289 *dst++ = B_VAL(&colorkey);
290 *dst++ = G_VAL(&colorkey);
291 *dst++ = R_VAL(&colorkey);
299 for (yy = 0; yy < h; yy++)
301 dst = dest + (yy * row_bytes);
302 src = update->image.data + (yy * update->cache_entry.w);
303 for (xx = 0; xx < w; xx++)
312 if (buf->func.free_update_region)
314 buf->func.free_update_region(x, y, w, h, dest);
318 case OUTBUF_DEPTH_RGB_32BPP_888_8888:
319 case OUTBUF_DEPTH_ARGB_32BPP_8888_8888:
321 DATA32 *dest, *src, *dst;
324 row_bytes = buf->dest_row_bytes;
325 dest = (DATA32 *)((DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4));
326 if (buf->func.new_update_region)
328 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
330 /* no need src == dest */
331 if (!buf->priv.back_buf)
335 func = evas_common_draw_func_copy_get(w, 0);
338 for (yy = 0; yy < h; yy++)
340 src = update->image.data + (yy * update->cache_entry.w);
341 dst = (DATA32 *)((DATA8 *)(buf->dest) + ((y + yy) * row_bytes));
347 if (buf->func.free_update_region)
349 buf->func.free_update_region(x, y, w, h, dest);
353 case OUTBUF_DEPTH_BGR_32BPP_888_8888:
357 int xx, yy, row_bytes;
359 row_bytes = buf->dest_row_bytes;
360 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
361 if (buf->func.new_update_region)
363 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
365 for (yy = 0; yy < h; yy++)
367 dst = (DATA32 *)(dest + (yy * row_bytes));
368 src = update->image.data + (yy * update->cache_entry.w);
369 for (xx = 0; xx < w; xx++)
371 A_VAL(dst) = B_VAL(src);
372 R_VAL(dst) = G_VAL(src);
373 G_VAL(dst) = R_VAL(src);
378 if (buf->func.free_update_region)
380 buf->func.free_update_region(x, y, w, h, dest);
384 case OUTBUF_DEPTH_BGRA_32BPP_8888_8888:
388 int xx, yy, row_bytes;
390 row_bytes = buf->dest_row_bytes;
391 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
392 if (buf->func.new_update_region)
394 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
396 for (yy = 0; yy < h; yy++)
398 dst = (DATA32 *)(dest + (yy * row_bytes));
399 src = update->image.data + (yy * update->cache_entry.w);
400 for (xx = 0; xx < w; xx++)
402 A_VAL(dst) = B_VAL(src);
403 R_VAL(dst) = G_VAL(src);
404 G_VAL(dst) = R_VAL(src);
409 if (buf->func.free_update_region)
411 buf->func.free_update_region(x, y, w, h, dest);