1 #include "evas_common.h"
2 #include "evas_engine.h"
5 evas_buffer_outbuf_buf_init(void)
10 evas_buffer_outbuf_buf_free(Outbuf *buf)
12 if (buf->priv.back_buf)
14 evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
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 void * (*switch_buffer) (void *data, void *dest_buffer),
29 buf = calloc(1, sizeof(Outbuf));
30 if (!buf) return NULL;
37 buf->dest_row_bytes = dest_row_bytes;
39 buf->alpha_level = alpha_level;
40 buf->color_key = color_key;
41 buf->use_color_key = use_color_key;
44 buf->func.new_update_region = new_update_region;
45 buf->func.free_update_region = free_update_region;
46 buf->func.switch_buffer = switch_buffer;
47 buf->switch_data = switch_data;
49 if ((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888) &&
50 (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
52 memset(buf->dest, 0, h * buf->dest_row_bytes);
53 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
56 1, EVAS_COLORSPACE_ARGB8888);
58 else if ((buf->depth == OUTBUF_DEPTH_RGB_32BPP_888_8888) &&
59 (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
61 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
64 0, EVAS_COLORSPACE_ARGB8888);
71 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)
75 if (buf->priv.back_buf)
77 *cx = x; *cy = y; *cw = w; *ch = h;
78 return buf->priv.back_buf;
82 *cx = 0; *cy = 0; *cw = w; *ch = h;
83 im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
86 if (((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888)) ||
87 ((buf->depth == OUTBUF_DEPTH_BGRA_32BPP_8888_8888)))
89 im->cache_entry.flags.alpha = 1;
90 im = (RGBA_Image *) evas_cache_image_size_set(&im->cache_entry, w, h);
98 evas_buffer_outbuf_buf_free_region_for_update(Outbuf *buf, RGBA_Image *update)
100 if (update != buf->priv.back_buf) evas_cache_image_drop(&update->cache_entry);
104 evas_buffer_outbuf_buf_switch_buffer(Outbuf *buf)
106 if (buf->func.switch_buffer)
108 buf->dest = buf->func.switch_buffer(buf->switch_data, buf->dest);
109 if (buf->priv.back_buf)
111 evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
112 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
115 buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888 ? 1 : 0,
116 EVAS_COLORSPACE_ARGB8888);
122 evas_buffer_outbuf_buf_push_updated_region(Outbuf *buf, RGBA_Image *update, int x, int y, int w, int h)
124 /* copy update image to out buf & convert */
127 case OUTBUF_DEPTH_RGB_24BPP_888_888:
128 /* copy & pack into 24bpp - if colorkey is enabled... etc. */
138 colorkey = buf->color_key;
139 thresh = buf->alpha_level;
140 row_bytes = buf->dest_row_bytes;
141 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
142 if (buf->func.new_update_region)
144 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
147 if (buf->use_color_key)
149 for (yy = 0; yy < h; yy++)
151 dst = dest + (yy * row_bytes);
152 src = update->image.data + (yy * update->cache_entry.w);
153 for (xx = 0; xx < w; xx++)
155 if (A_VAL(src) > thresh)
163 *dst++ = R_VAL(&colorkey);
164 *dst++ = G_VAL(&colorkey);
165 *dst++ = B_VAL(&colorkey);
173 for (yy = 0; yy < h; yy++)
175 dst = dest + (yy * row_bytes);
176 src = update->image.data + (yy * update->cache_entry.w);
177 for (xx = 0; xx < w; xx++)
186 if (buf->func.free_update_region)
188 buf->func.free_update_region(x, y, w, h, dest);
192 case OUTBUF_DEPTH_BGR_24BPP_888_888:
193 /* copy & pack into 24bpp - if colorkey is enabled... etc. */
203 colorkey = buf->color_key;
204 thresh = buf->alpha_level;
205 row_bytes = buf->dest_row_bytes;
206 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
207 if (buf->func.new_update_region)
209 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
212 if (buf->use_color_key)
214 for (yy = 0; yy < h; yy++)
216 dst = dest + (yy * row_bytes);
217 src = update->image.data + (yy * update->cache_entry.w);
218 for (xx = 0; xx < w; xx++)
220 if (A_VAL(src) > thresh)
228 *dst++ = B_VAL(&colorkey);
229 *dst++ = G_VAL(&colorkey);
230 *dst++ = R_VAL(&colorkey);
238 for (yy = 0; yy < h; yy++)
240 dst = dest + (yy * row_bytes);
241 src = update->image.data + (yy * update->cache_entry.w);
242 for (xx = 0; xx < w; xx++)
251 if (buf->func.free_update_region)
253 buf->func.free_update_region(x, y, w, h, dest);
257 case OUTBUF_DEPTH_RGB_32BPP_888_8888:
258 case OUTBUF_DEPTH_ARGB_32BPP_8888_8888:
260 DATA32 *dest, *src, *dst;
263 row_bytes = buf->dest_row_bytes;
264 dest = (DATA32 *)((DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4));
265 if (buf->func.new_update_region)
267 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
269 /* no need src == dest */
270 if (!buf->priv.back_buf)
274 func = evas_common_draw_func_copy_get(w, 0);
277 for (yy = 0; yy < h; yy++)
279 src = update->image.data + (yy * update->cache_entry.w);
280 dst = (DATA32 *)((DATA8 *)(buf->dest) + ((y + yy) * row_bytes));
286 if (buf->func.free_update_region)
288 buf->func.free_update_region(x, y, w, h, dest);
292 case OUTBUF_DEPTH_BGR_32BPP_888_8888:
296 int xx, yy, row_bytes;
298 row_bytes = buf->dest_row_bytes;
299 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
300 if (buf->func.new_update_region)
302 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
304 for (yy = 0; yy < h; yy++)
306 dst = (DATA32 *)(dest + (yy * row_bytes));
307 src = update->image.data + (yy * update->cache_entry.w);
308 for (xx = 0; xx < w; xx++)
310 A_VAL(dst) = B_VAL(src);
311 R_VAL(dst) = G_VAL(src);
312 G_VAL(dst) = R_VAL(src);
317 if (buf->func.free_update_region)
319 buf->func.free_update_region(x, y, w, h, dest);
323 case OUTBUF_DEPTH_BGRA_32BPP_8888_8888:
327 int xx, yy, row_bytes;
329 row_bytes = buf->dest_row_bytes;
330 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
331 if (buf->func.new_update_region)
333 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
335 for (yy = 0; yy < h; yy++)
337 dst = (DATA32 *)(dest + (yy * row_bytes));
338 src = update->image.data + (yy * update->cache_entry.w);
339 for (xx = 0; xx < w; xx++)
341 A_VAL(dst) = B_VAL(src);
342 R_VAL(dst) = G_VAL(src);
343 G_VAL(dst) = R_VAL(src);
348 if (buf->func.free_update_region)
350 buf->func.free_update_region(x, y, w, h, dest);