1 #include "evas_gl_private.h"
4 evas_gl_common_image_all_unload(Evas_GL_Context *gc)
9 EINA_LIST_FOREACH(gc->shared->images, l, im)
11 if (im->im) evas_cache_image_unload_data(&im->im->cache_entry);
14 if (!im->tex->pt->dyn.img)
16 evas_gl_common_texture_free(im->tex);
24 evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error)
30 im_im = evas_common_load_image_from_file(file, key, lo, error);
31 if (!im_im) return NULL;
33 EINA_LIST_FOREACH(gc->shared->images, l, im)
37 evas_cache_image_drop(&im_im->cache_entry);
38 gc->shared->images = eina_list_remove_list(gc->shared->images, l);
39 gc->shared->images = eina_list_prepend(gc->shared->images, im);
41 *error = EVAS_LOAD_ERROR_NONE;
46 im = calloc(1, sizeof(Evas_GL_Image));
49 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
57 im->cs.space = EVAS_COLORSPACE_ARGB8888;
58 im->alpha = im->im->cache_entry.flags.alpha;
59 im->w = im->im->cache_entry.w;
60 im->h = im->im->cache_entry.h;
61 if (lo) im->load_opts = *lo;
62 gc->shared->images = eina_list_prepend(gc->shared->images, im);
67 evas_gl_common_image_new_from_data(Evas_GL_Context *gc, unsigned int w, unsigned int h, DATA32 *data, int alpha, int cspace)
74 EINA_LIST_FOREACH(gc->shared->images, l, im)
76 if (((void *)(im->im->image.data) == (void *)data) &&
77 (im->im->cache_entry.w == w) &&
78 (im->im->cache_entry.h == h))
80 gc->shared->images = eina_list_remove_list(gc->shared->images, l);
81 gc->shared->images = eina_list_prepend(gc->shared->images, im);
87 im = calloc(1, sizeof(Evas_GL_Image));
90 im->im = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
91 w, h, data, alpha, cspace);
98 im->cs.space = cspace;
99 im->alpha = im->im->cache_entry.flags.alpha;
100 im->w = im->im->cache_entry.w;
101 im->h = im->im->cache_entry.h;
104 case EVAS_COLORSPACE_ARGB8888:
106 case EVAS_COLORSPACE_YCBCR422P601_PL:
107 case EVAS_COLORSPACE_YCBCR422P709_PL:
108 if (im->tex) evas_gl_common_texture_free(im->tex);
121 evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, unsigned int w, unsigned int h, DATA32 *data, int alpha, int cspace)
125 im = calloc(1, sizeof(Evas_GL_Image));
126 if (!im) return NULL;
128 im->im = (RGBA_Image *) evas_cache_image_copied_data(evas_common_image_cache_get(),
129 w, h, data, alpha, cspace);
136 im->cs.space = cspace;
137 im->alpha = im->im->cache_entry.flags.alpha;
138 im->w = im->im->cache_entry.w;
139 im->h = im->im->cache_entry.h;
142 case EVAS_COLORSPACE_ARGB8888:
144 case EVAS_COLORSPACE_YCBCR422P601_PL:
145 case EVAS_COLORSPACE_YCBCR422P709_PL:
146 if (im->tex) evas_gl_common_texture_free(im->tex);
149 if (im->im->cache_entry.h > 0)
150 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
151 if ((data) && (im->cs.data))
152 memcpy(im->cs.data, data, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
162 evas_gl_common_image_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha, int cspace)
166 im = calloc(1, sizeof(Evas_GL_Image));
167 if (!im) return NULL;
169 im->im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
176 im->im->cache_entry.flags.alpha = alpha ? 1 : 0;
177 im->cs.space = cspace;
178 im->alpha = im->im->cache_entry.flags.alpha;
179 im->im->cache_entry.w = w;
180 im->im->cache_entry.h = h;
181 im->w = im->im->cache_entry.w;
182 im->h = im->im->cache_entry.h;
183 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
184 im->im = (RGBA_Image *)evas_cache_image_size_set(&im->im->cache_entry, w, h);
187 case EVAS_COLORSPACE_ARGB8888:
189 case EVAS_COLORSPACE_YCBCR422P601_PL:
190 case EVAS_COLORSPACE_YCBCR422P709_PL:
191 // if (im->tex) evas_gl_common_texture_free(im->tex);
194 if (im->im->cache_entry.h > 0)
195 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
205 evas_gl_common_image_alpha_set(Evas_GL_Image *im, int alpha)
207 if (!im) return NULL;
208 if (im->alpha == alpha) return im;
210 if (!im->im) return im;
211 im->im->cache_entry.flags.alpha = alpha ? 1 : 0;
214 evas_gl_common_texture_free(im->tex);
218 im->tex = evas_gl_common_texture_new(im->gc, im->im);
223 evas_gl_common_image_native_enable(Evas_GL_Image *im)
227 if (!im->cs.no_free) free(im->cs.data);
233 im->gc->shared->images = eina_list_remove(im->gc->shared->images, im);
238 evas_cache_image_drop(&im->im->cache_entry);
243 evas_gl_common_texture_free(im->tex);
247 im->cs.space = EVAS_COLORSPACE_ARGB8888;
248 im->tex = evas_gl_common_texture_native_new(im->gc, im->w, im->h, im->alpha, im);
253 evas_gl_common_image_native_disable(Evas_GL_Image *im)
257 evas_cache_image_drop(&im->im->cache_entry);
262 evas_gl_common_texture_free(im->tex);
267 im->im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
268 im->im->cache_entry.flags.alpha = im->alpha;
269 im->cs.space = EVAS_COLORSPACE_ARGB8888;
270 evas_cache_image_colorspace(&im->im->cache_entry, im->cs.space);
271 im->im = (RGBA_Image *)evas_cache_image_size_set(&im->im->cache_entry, im->w, im->h);
273 im->tex = evas_gl_common_texture_new(im->gc, im->im);
277 evas_gl_common_image_scale_hint_set(Evas_GL_Image *im, int hint)
279 im->scale_hint = hint;
280 // FIXME: take advantage of this even in gl (eg if image is
281 // 1600x1200 but we always use it at 800x600 or even less - drop
282 // the texture res down for "non dynamic" stuff to save memory)
286 evas_gl_common_image_content_hint_set(Evas_GL_Image *im, int hint)
288 if (im->content_hint == hint) return;
289 im->content_hint = hint;
291 if (!im->gc->shared->info.sec_image_map) return;
292 if (!im->gc->shared->info.bgra) return;
293 // does not handle yuv yet.
294 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return;
295 if (im->content_hint == EVAS_IMAGE_CONTENT_HINT_DYNAMIC)
299 if (!im->cs.no_free) free(im->cs.data);
305 im->gc->shared->images = eina_list_remove(im->gc->shared->images, im);
310 evas_cache_image_drop(&im->im->cache_entry);
315 evas_gl_common_texture_free(im->tex);
318 im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
325 evas_cache_image_drop(&im->im->cache_entry);
330 evas_gl_common_texture_free(im->tex);
335 im->im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
336 im->im->cache_entry.flags.alpha = im->alpha;
337 im->cs.space = EVAS_COLORSPACE_ARGB8888;
338 evas_cache_image_colorspace(&im->im->cache_entry, im->cs.space);
339 im->im = (RGBA_Image *)evas_cache_image_size_set(&im->im->cache_entry, im->w, im->h);
341 im->tex = evas_gl_common_texture_new(im->gc, im->im);
346 evas_gl_common_image_free(Evas_GL_Image *im)
349 if (im->references > 0) return;
351 if (im->native.func.free)
352 im->native.func.free(im->native.func.data, im);
356 if (!im->cs.no_free) free(im->cs.data);
358 if (im->cached) im->gc->shared->images = eina_list_remove(im->gc->shared->images, im);
359 if (im->im) evas_cache_image_drop(&im->im->cache_entry);
360 if (im->tex) evas_gl_common_texture_free(im->tex);
365 evas_gl_common_image_surface_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha)
369 im = calloc(1, sizeof(Evas_GL_Image));
370 if (!im) return NULL;
373 im->cs.space = EVAS_COLORSPACE_ARGB8888;
377 im->tex = evas_gl_common_texture_render_new(gc, w, h, alpha);
383 evas_gl_common_image_dirty(Evas_GL_Image *im, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
385 if ((w == 0) && (h == 0) && (x == 0) && (y == 0))
392 im->im = (RGBA_Image *)evas_cache_image_dirty(&im->im->cache_entry, x, y, w, h);
398 _evas_gl_common_image_update(Evas_GL_Context *gc, Evas_GL_Image *im)
402 if ((im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
403 (im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL))
405 // SOFTWARE convert. do multi texture later
406 if ((im->cs.data) && (*((unsigned char **)im->cs.data)))
408 if (im->dirty || !im->im->image.data)
410 free(im->im->image.data);
411 im->im->image.data = malloc(im->im->cache_entry.w * im->im->cache_entry.h * sizeof(DATA32));
412 if (im->im->image.data)
413 evas_common_convert_yuv_420p_601_rgba(im->cs.data,
414 (void *)im->im->image.data,
415 im->im->cache_entry.w, im->im->cache_entry.h);
418 space = EVAS_COLORSPACE_ARGB8888;
422 switch (im->cs.space)
424 case EVAS_COLORSPACE_ARGB8888:
425 if ((im->tex) && (im->dirty))
427 evas_cache_image_load_data(&im->im->cache_entry);
428 evas_gl_common_texture_update(im->tex, im->im);
429 evas_cache_image_unload_data(&im->im->cache_entry);
433 evas_cache_image_load_data(&im->im->cache_entry);
434 im->tex = evas_gl_common_texture_new(gc, im->im);
435 evas_cache_image_unload_data(&im->im->cache_entry);
438 if (!im->tex) return;
440 case EVAS_COLORSPACE_YCBCR422P601_PL:
441 case EVAS_COLORSPACE_YCBCR422P709_PL:
442 if ((im->tex) && (im->dirty))
444 evas_gl_common_texture_yuv_update(im->tex, im->cs.data,
445 im->im->cache_entry.w,
446 im->im->cache_entry.h);
449 if ((!im->tex) && (im->cs.data) && (*((unsigned char **)im->cs.data)))
451 im->tex = evas_gl_common_texture_yuv_new(gc, im->cs.data,
452 im->im->cache_entry.w,
453 im->im->cache_entry.h);
456 if (!im->tex) return;
459 ERR("unhandled img format colorspace=%d", im->cs.space);
465 evas_gl_common_image_map4_draw(Evas_GL_Context *gc, Evas_GL_Image *im,
466 RGBA_Map_Point *p, int smooth, int level __UNUSED__)
468 RGBA_Draw_Context *dc;
470 int c, cx, cy, cw, ch;
476 a = (dc->mul.col >> 24) & 0xff;
477 r = (dc->mul.col >> 16) & 0xff;
478 g = (dc->mul.col >> 8 ) & 0xff;
479 b = (dc->mul.col ) & 0xff;
486 _evas_gl_common_image_update(gc, im);
488 c = gc->dc->clip.use;
489 cx = gc->dc->clip.x; cy = gc->dc->clip.y;
490 cw = gc->dc->clip.w; ch = gc->dc->clip.h;
492 if ((im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
493 (im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL))
495 evas_gl_common_context_image_map4_push(gc, im->tex, p,
497 r, g, b, a, smooth, im->tex_only,
502 evas_gl_common_image_draw(Evas_GL_Context *gc, Evas_GL_Image *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth)
504 RGBA_Draw_Context *dc;
507 double ssx, ssy, ssw, ssh;
508 double mssx, mssy, mssw, mssh;
511 int c, cx, cy, cw, ch;
521 a = (dc->mul.col >> 24) & 0xff;
522 r = (dc->mul.col >> 16) & 0xff;
523 g = (dc->mul.col >> 8 ) & 0xff;
524 b = (dc->mul.col ) & 0xff;
531 _evas_gl_common_image_update(gc, im);
534 evas_gl_common_rect_draw(gc, dx, dy, dw, dh);
539 _evas_gl_common_image_update(gc, imm);
540 if (!imm->tex) imm = NULL; /* Turn of mask on error */
543 if ((im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
544 (im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL))
548 if (imm) imm->tex->im = imm;
549 if ((!gc->dc->cutout.rects) ||
550 ((gc->shared->info.tune.cutout.max > 0) &&
551 (gc->dc->cutout.active > gc->shared->info.tune.cutout.max)))
553 if (gc->dc->clip.use)
556 double scalex,scaley;
558 nx = dx; ny = dy; nw = dw; nh = dh;
559 RECTS_CLIP_TO_RECT(nx, ny, nw, nh,
560 gc->dc->clip.x, gc->dc->clip.y,
561 gc->dc->clip.w, gc->dc->clip.h);
562 if ((nw < 1) || (nh < 1)) return;
563 if ((!imm) && (nx == dx) && (ny == dy) && (nw == dw) && (nh == dh))
566 evas_gl_common_context_yuv_push(gc,
573 evas_gl_common_context_image_push(gc,
578 smooth, im->tex_only);
582 ssx = (double)sx + ((double)(sw * (nx - dx)) / (double)(dw));
583 ssy = (double)sy + ((double)(sh * (ny - dy)) / (double)(dh));
584 ssw = ((double)sw * (double)(nw)) / (double)(dw);
585 ssh = ((double)sh * (double)(nh)) / (double)(dh);
588 /* Correct ones here */
589 scalex = imm->w / (double)dc->mask.w;
590 scaley = imm->h / (double)dc->mask.h;
591 mssx = scalex * (nx - dc->mask.x);
592 mssy = scaley * (ny - dc->mask.y);
596 /* No yuv + imm I'm afraid */
597 evas_gl_common_context_image_mask_push(gc,
601 mssx, mssy, mssw, mssh,
602 //dc->mask.x, dc->mask.y, dc->mask.w, dc->mask.h,
608 evas_gl_common_context_yuv_push(gc,
615 evas_gl_common_context_image_push(gc,
620 smooth, im->tex_only);
625 evas_gl_common_context_yuv_push(gc,
632 evas_gl_common_context_image_push(gc,
637 smooth, im->tex_only);
642 /* save out clip info */
643 c = gc->dc->clip.use; cx = gc->dc->clip.x; cy = gc->dc->clip.y; cw = gc->dc->clip.w; ch = gc->dc->clip.h;
644 evas_common_draw_context_clip_clip(gc->dc, 0, 0, gc->w, gc->h);
645 evas_common_draw_context_clip_clip(gc->dc, dx, dy, dw, dh);
646 /* our clip is 0 size.. abort */
647 if ((gc->dc->clip.w <= 0) || (gc->dc->clip.h <= 0))
649 gc->dc->clip.use = c; gc->dc->clip.x = cx; gc->dc->clip.y = cy; gc->dc->clip.w = cw; gc->dc->clip.h = ch;
652 rects = evas_common_draw_context_apply_cutouts(dc);
653 for (i = 0; i < rects->active; ++i)
657 rct = rects->rects + i;
658 nx = dx; ny = dy; nw = dw; nh = dh;
659 RECTS_CLIP_TO_RECT(nx, ny, nw, nh, rct->x, rct->y, rct->w, rct->h);
660 if ((nw < 1) || (nh < 1)) continue;
661 if ((nx == dx) && (ny == dy) && (nw == dw) && (nh == dh))
664 evas_gl_common_context_yuv_push(gc,
671 evas_gl_common_context_image_push(gc,
676 smooth, im->tex_only);
679 ssx = (double)sx + ((double)(sw * (nx - dx)) / (double)(dw));
680 ssy = (double)sy + ((double)(sh * (ny - dy)) / (double)(dh));
681 ssw = ((double)sw * (double)(nw)) / (double)(dw);
682 ssh = ((double)sh * (double)(nh)) / (double)(dh);
684 evas_gl_common_context_yuv_push(gc,
691 evas_gl_common_context_image_push(gc,
696 smooth, im->tex_only);
698 evas_common_draw_context_apply_clear_cutouts(rects);
699 /* restore clip info */
700 gc->dc->clip.use = c; gc->dc->clip.x = cx; gc->dc->clip.y = cy; gc->dc->clip.w = cw; gc->dc->clip.h = ch;
705 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/