1 #include "evas_gl_private.h"
3 static const GLenum rgba_fmt = GL_RGBA;
4 static const GLenum rgba_ifmt = GL_RGBA;
5 //#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
6 //static const GLenum rgb_fmt = GL_RGBA;
7 //static const GLenum rgb_ifmt = GL_RGBA;
9 static const GLenum rgb_fmt = GL_RGBA;
10 static const GLenum rgb_ifmt = GL_RGB;
13 # if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
14 static const GLenum bgra_fmt = GL_BGRA;
15 static const GLenum bgra_ifmt = GL_BGRA;
16 static const GLenum bgr_fmt = GL_BGRA;
17 static const GLenum bgr_ifmt = GL_BGRA;
19 static const GLenum bgra_fmt = GL_BGRA;
20 static const GLenum bgra_ifmt = GL_RGBA;
21 static const GLenum bgr_fmt = GL_BGRA;
22 static const GLenum bgr_ifmt = GL_RGB;
25 static const GLenum alpha_fmt = GL_ALPHA;
26 static const GLenum alpha_ifmt = GL_ALPHA;
27 static const GLenum lum_fmt = GL_LUMINANCE;
28 static const GLenum lum_ifmt = GL_LUMINANCE;
29 static const GLenum lum_alpha_fmt = GL_LUMINANCE_ALPHA;
30 static const GLenum lum_alpha_ifmt = GL_LUMINANCE_ALPHA;
31 static const GLenum rgba8_ifmt = GL_RGBA;
32 static const GLenum rgba8_fmt = GL_BGRA;
38 } texinfo = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}};
41 _print_tex_count(void)
43 if (getenv("EVAS_GL_MEMINFO"))
46 "T: c:%i/%ik | a:%i/%ik | v:%i/%ik | r:%i/%ik | n:%i/%ik | d:%i/%ik\n",
47 texinfo.c.num, (texinfo.c.pix * 4) / 1024,
48 texinfo.a.num, (texinfo.a.pix ) / 1024,
49 texinfo.v.num, (texinfo.v.pix ) / 1024,
50 texinfo.r.num, (texinfo.r.pix * 4) / 1024,
51 texinfo.n.num, (texinfo.n.pix * 4) / 1024,
52 texinfo.d.num, (texinfo.d.pix * 4) / 1024
58 _nearest_pow2(int num)
60 unsigned int n = num - 1;
70 _tex_adjust(Evas_Engine_GL_Context *gc, int *w, int *h)
72 if (gc->shared->info.tex_npo2) return;
73 /*if (gc->shared->info.tex_rect) return;*/
74 *w = _nearest_pow2(*w);
75 *h = _nearest_pow2(*h);
79 _tex_round_slot(Evas_Engine_GL_Context *gc, int h)
81 if (!gc->shared->info.tex_npo2)
83 return (h + gc->shared->info.tune.atlas.slot_size - 1) /
84 gc->shared->info.tune.atlas.slot_size;
88 _tex_format_index(GLuint format)
101 case GL_LUMINANCE: // never used in atlas
110 _tex_2d(int intfmt, int w, int h, int fmt, int type)
112 glTexImage2D(GL_TEXTURE_2D, 0, intfmt, w, h, 0, fmt, type, NULL);
113 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
117 _tex_sub_2d(int x, int y, int w, int h, int fmt, int type, const void *pix)
119 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, fmt, type, pix);
120 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
123 static Evas_GL_Texture_Pool *
124 _pool_tex_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, GLenum format)
126 Evas_GL_Texture_Pool *pt;
128 pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
129 if (!pt) return NULL;
130 h = _tex_round_slot(gc, h) * gc->shared->info.tune.atlas.slot_size;
131 _tex_adjust(gc, &w, &h);
135 pt->intformat = intformat;
137 pt->dataformat = GL_UNSIGNED_BYTE;
140 if (format == alpha_fmt)
143 texinfo.a.pix += pt->w * pt->h;
145 else if (format == lum_fmt)
148 texinfo.v.pix += pt->w * pt->h;
153 texinfo.c.pix += pt->w * pt->h;
158 glGenTextures(1, &(pt->texture));
159 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
160 glBindTexture(GL_TEXTURE_2D, pt->texture);
161 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
163 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
165 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
167 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
168 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
169 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
170 _tex_2d(pt->intformat, w, h, pt->format, pt->dataformat);
171 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
172 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
177 _pool_tex_alloc(Evas_GL_Texture_Pool *pt, int w, int h __UNUSED__, int *u, int *v, Eina_List **l_after)
180 Evas_GL_Texture *tex, *tex2;
185 tex = pt->allocations->data;
186 // if firest tex is not at left edge...
187 if (tex->x > (0 + 1))
189 if ((tex->x - 1) >= w)
198 EINA_LIST_FOREACH(pt->allocations, l, tex)
200 b = tex->x + tex->w + 2;
203 tex2 = l->next->data;
221 static Evas_GL_Texture_Pool *
222 _pool_tex_find(Evas_Engine_GL_Context *gc, int w, int h,
223 int intformat, int format, int *u, int *v,
224 Eina_List **l_after, int atlas_w)
226 Evas_GL_Texture_Pool *pt = NULL;
230 if (atlas_w > gc->shared->info.max_texture_size)
231 atlas_w = gc->shared->info.max_texture_size;
232 if ((w > gc->shared->info.tune.atlas.max_w) ||
233 (h > gc->shared->info.tune.atlas.max_h))
235 pt = _pool_tex_new(gc, w, h, intformat, format);
236 gc->shared->tex.whole = eina_list_prepend(gc->shared->tex.whole, pt);
246 th = _tex_round_slot(gc, h);
247 th2 = _tex_format_index(intformat);
248 EINA_LIST_FOREACH(gc->shared->tex.atlas[th][th2], l, pt)
250 if (_pool_tex_alloc(pt, w, h, u, v, l_after))
252 gc->shared->tex.atlas[th][th2] =
253 eina_list_remove_list(gc->shared->tex.atlas[th][th2], l);
254 gc->shared->tex.atlas[th][th2] =
255 eina_list_prepend(gc->shared->tex.atlas[th][th2], pt);
259 pt = _pool_tex_new(gc, atlas_w, h, intformat, format);
260 gc->shared->tex.atlas[th][th2] =
261 eina_list_prepend(gc->shared->tex.atlas[th][th2], pt);
271 evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im)
273 Evas_GL_Texture *tex;
274 Eina_List *l_after = NULL;
277 tex = calloc(1, sizeof(Evas_GL_Texture));
278 if (!tex) return NULL;
283 if (im->cache_entry.flags.alpha)
285 if (gc->shared->info.bgra)
286 tex->pt = _pool_tex_find(gc, im->cache_entry.w + 2,
287 im->cache_entry.h + 1, bgra_ifmt, bgra_fmt,
289 gc->shared->info.tune.atlas.max_alloc_size);
291 tex->pt = _pool_tex_find(gc, im->cache_entry.w + 2,
292 im->cache_entry.h + 1, rgba_ifmt, rgba_fmt,
294 gc->shared->info.tune.atlas.max_alloc_size);
299 if (gc->shared->info.bgra)
300 tex->pt = _pool_tex_find(gc, im->cache_entry.w + 3,
301 im->cache_entry.h + 1, bgr_ifmt, bgr_fmt,
303 gc->shared->info.tune.atlas.max_alloc_size);
305 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
306 tex->pt = _pool_tex_find(gc, im->cache_entry.w + 3,
307 im->cache_entry.h + 1, rgba_ifmt, rgba_fmt,
309 gc->shared->info.tune.atlas.max_alloc_size);
311 tex->pt = _pool_tex_find(gc, im->cache_entry.w + 3,
312 im->cache_entry.h + 1, rgb_ifmt, rgb_fmt,
314 gc->shared->info.tune.atlas.max_alloc_size);
324 tex->w = im->cache_entry.w;
325 tex->h = im->cache_entry.h;
327 tex->pt->allocations =
328 eina_list_append_relative_list(tex->pt->allocations, tex, l_after);
330 tex->pt->allocations =
331 eina_list_prepend(tex->pt->allocations, tex);
332 tex->pt->references++;
333 evas_gl_common_texture_update(tex, im);
337 static Evas_GL_Texture_Pool *
338 _pool_tex_render_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, int format)
340 Evas_GL_Texture_Pool *pt;
342 pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
343 if (!pt) return NULL;
344 h = _tex_round_slot(gc, h) * gc->shared->info.tune.atlas.slot_size;
345 _tex_adjust(gc, &w, &h);
349 pt->intformat = intformat;
351 pt->dataformat = GL_UNSIGNED_BYTE;
354 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
355 # ifndef GL_FRAMEBUFFER
356 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
358 # ifndef GL_COLOR_ATTACHMENT0
359 # define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
362 # ifndef GL_FRAMEBUFFER
363 # define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
365 # ifndef GL_COLOR_ATTACHMENT0
366 # define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
370 texinfo.r.pix += pt->w * pt->h;
374 glGenTextures(1, &(pt->texture));
375 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
376 glBindTexture(GL_TEXTURE_2D, pt->texture);
377 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
379 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
381 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
383 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
385 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
386 _tex_2d(pt->intformat, w, h, pt->format, pt->dataformat);
388 glsym_glGenFramebuffers(1, &(pt->fb));
389 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
390 glsym_glBindFramebuffer(GL_FRAMEBUFFER, pt->fb);
391 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
392 glsym_glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pt->texture, 0);
393 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
394 glsym_glBindFramebuffer(GL_FRAMEBUFFER, 0);
395 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
397 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
398 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
402 static Evas_GL_Texture_Pool *
403 _pool_tex_native_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, int format, Evas_GL_Image *im)
405 Evas_GL_Texture_Pool *pt;
407 pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
408 if (!pt) return NULL;
410 #ifdef GL_TEXTURE_RECTANGLE_ARB
411 if (im->native.target == GL_TEXTURE_RECTANGLE_ARB)
413 printf("REEEEEEEEECT\n");
420 // FIXME: handle po2 only textures
424 pt->intformat = intformat;
426 pt->dataformat = GL_UNSIGNED_BYTE;
430 texinfo.n.pix += pt->w * pt->h;
434 glGenTextures(1, &(pt->texture));
435 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
436 glBindTexture(im->native.target, pt->texture);
437 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
439 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
441 if (im->native.loose)
443 if (im->native.func.bind)
444 im->native.func.bind(im->native.func.data, im);
448 glTexParameteri(im->native.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
449 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
450 glTexParameteri(im->native.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
451 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
452 glTexParameteri(im->native.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
453 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
454 glTexParameteri(im->native.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
455 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
456 glBindTexture(im->native.target, 0);
457 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
458 glBindTexture(im->native.target, gc->pipe[0].shader.cur_tex);
459 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
463 static Evas_GL_Texture_Pool *
464 _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, int format)
466 Evas_GL_Texture_Pool *pt = NULL;
468 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
469 int fmt; // EGL_MAP_GL_TEXTURE_RGBA_SEC or EGL_MAP_GL_TEXTURE_RGB_SEC or bust
470 int pixtype; // EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC or bust
474 EGL_MAP_GL_TEXTURE_WIDTH_SEC, 32,
475 EGL_MAP_GL_TEXTURE_HEIGHT_SEC, 32,
476 EGL_MAP_GL_TEXTURE_FORMAT_SEC, EGL_MAP_GL_TEXTURE_RGBA_SEC,
477 EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC, EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC,
482 if (intformat != format) return NULL;
486 #ifdef EGL_MAP_GL_TEXTURE_LUMINANCE_SEC
487 case GL_LUMINANCE: attr[5] = EGL_MAP_GL_TEXTURE_LUMINANCE_SEC; break;
489 #ifdef EGL_MAP_GL_TEXTURE_LUMINANCE_ALPHA_SEC
490 case GL_LUMINANCE_ALPHA: attr[5] = EGL_MAP_GL_TEXTURE_LUMINANCE_ALPHA_SEC; break;
492 case GL_RGBA: attr[5] = EGL_MAP_GL_TEXTURE_RGBA_SEC; break;
493 default: fprintf(stderr, "unknown format\n"); return NULL;
496 pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
497 if (!pt) return NULL;
498 h = _tex_round_slot(gc, h) * gc->shared->info.tune.atlas.slot_size;
499 _tex_adjust(gc, &w, &h);
503 pt->intformat = intformat;
505 pt->dataformat = GL_UNSIGNED_BYTE;
509 texinfo.d.pix += pt->w * pt->h;
513 glGenTextures(1, &(pt->texture));
514 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
515 glBindTexture(GL_TEXTURE_2D, pt->texture);
516 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
517 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
518 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
520 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
522 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
524 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
526 egldisplay = pt->gc->egldisp;
531 // FIXME: seems a bit slower than i'd like - maybe too many flushes?
532 // FIXME: YCbCr no support as yet
533 pt->dyn.img = secsym_eglCreateImage(egldisplay,
535 EGL_MAP_GL_TEXTURE_2D_SEC,
537 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
540 glBindTexture(GL_TEXTURE_2D, 0);
541 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
542 glDeleteTextures(1, &(pt->texture));
543 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
547 if (secsym_eglGetImageAttribSEC(egldisplay,
549 EGL_MAP_GL_TEXTURE_WIDTH_SEC,
550 &(pt->dyn.w)) != EGL_TRUE) goto error;
551 if (secsym_eglGetImageAttribSEC(egldisplay,
553 EGL_MAP_GL_TEXTURE_HEIGHT_SEC,
554 &(pt->dyn.h)) != EGL_TRUE) goto error;
555 if (secsym_eglGetImageAttribSEC(egldisplay,
557 EGL_MAP_GL_TEXTURE_STRIDE_IN_BYTES_SEC,
558 &(pt->dyn.stride)) != EGL_TRUE) goto error;
559 if (secsym_eglGetImageAttribSEC(egldisplay,
561 EGL_MAP_GL_TEXTURE_FORMAT_SEC,
562 &(fmt)) != EGL_TRUE) goto error;
564 if (secsym_eglGetImageAttribSEC(egldisplay,
566 EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC,
567 &(pixtype)) != EGL_TRUE) goto error;
569 if (pixtype != EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC) goto error;
571 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
572 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
583 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
585 secsym_eglDestroyImage(egldisplay, pt->dyn.img);
586 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
588 glBindTexture(GL_TEXTURE_2D, 0);
589 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
590 glDeleteTextures(1, &(pt->texture));
591 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
598 evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt)
602 if (pt->format == alpha_fmt)
605 texinfo.a.pix -= pt->w * pt->h;
607 else if (pt->format == lum_fmt)
610 texinfo.v.pix -= pt->w * pt->h;
612 else if (pt->dyn.img)
615 texinfo.d.pix -= pt->w * pt->h;
620 texinfo.r.pix -= pt->w * pt->h;
625 texinfo.n.pix -= pt->w * pt->h;
630 texinfo.c.pix -= pt->w * pt->h;
635 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
638 secsym_eglDestroyImage(pt->gc->egldisp, pt->dyn.img);
647 glDeleteTextures(1, &(pt->texture));
648 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
651 glsym_glDeleteFramebuffers(1, &(pt->fb));
652 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
655 while (pt->allocations)
657 eina_list_remove_list(pt->allocations, pt->allocations);
665 pt_unref(Evas_GL_Texture_Pool *pt)
670 if (pt->references != 0) return;
672 if (!((pt->render) || (pt->native)))
675 pt->gc->shared->tex.whole =
676 eina_list_remove(pt->gc->shared->tex.whole, pt);
678 pt->gc->shared->tex.atlas [pt->slot][pt->fslot] =
679 eina_list_remove(pt->gc->shared->tex.atlas[pt->slot][pt->fslot], pt);
681 evas_gl_texture_pool_empty(pt);
686 pt_link(Evas_Engine_GL_Context *gc, Evas_GL_Texture *tex, Evas_GL_Texture_Pool *pt)
688 gc->shared->tex.whole = eina_list_prepend(gc->shared->tex.whole, pt);
692 pt->allocations = eina_list_prepend(pt->allocations, tex);
697 evas_gl_common_texture_native_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha, Evas_GL_Image *im)
699 Evas_GL_Texture *tex;
701 tex = calloc(1, sizeof(Evas_GL_Texture));
702 if (!tex) return NULL;
709 if (gc->shared->info.bgra)
710 tex->pt = _pool_tex_native_new(gc, w, h, rgba_ifmt, rgba_fmt, im);
712 tex->pt = _pool_tex_native_new(gc, w, h, rgba_ifmt, rgba_fmt, im);
716 if (gc->shared->info.bgra)
717 tex->pt = _pool_tex_native_new(gc, w, h, rgb_ifmt, rgb_fmt, im);
719 tex->pt = _pool_tex_native_new(gc, w, h, rgb_ifmt, rgb_fmt, im);
730 tex->pt->references++;
735 evas_gl_common_texture_render_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha)
737 Evas_GL_Texture *tex;
739 tex = calloc(1, sizeof(Evas_GL_Texture));
740 if (!tex) return NULL;
747 if (gc->shared->info.bgra)
748 tex->pt = _pool_tex_render_new(gc, w, h, rgba_ifmt, rgba_fmt);
750 tex->pt = _pool_tex_render_new(gc, w, h, rgba_ifmt, rgba_fmt);
754 if (gc->shared->info.bgra)
755 tex->pt = _pool_tex_render_new(gc, w, h, rgb_ifmt, rgb_fmt);
757 tex->pt = _pool_tex_render_new(gc, w, h, rgb_ifmt, rgb_fmt);
768 tex->pt->references++;
773 evas_gl_common_texture_dynamic_new(Evas_Engine_GL_Context *gc, Evas_GL_Image *im)
775 Evas_GL_Texture *tex;
777 tex = calloc(1, sizeof(Evas_GL_Texture));
778 if (!tex) return NULL;
782 tex->alpha = im->alpha;
789 if (gc->shared->info.bgra)
790 tex->pt = _pool_tex_dynamic_new(gc, tex->w, tex->h, bgra_ifmt, bgra_fmt);
792 tex->pt = _pool_tex_dynamic_new(gc, tex->w, tex->h, bgra_ifmt, bgra_fmt);
796 if (gc->shared->info.bgra)
797 tex->pt = _pool_tex_dynamic_new(gc, tex->w, tex->h, bgra_ifmt, bgra_fmt);
799 tex->pt = _pool_tex_dynamic_new(gc, tex->w, tex->h, bgra_ifmt, bgra_fmt);
806 tex->pt->references++;
811 evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im)
815 if (tex->alpha != im->cache_entry.flags.alpha)
817 tex->pt->allocations = eina_list_remove(tex->pt->allocations, tex);
819 tex->alpha = im->cache_entry.flags.alpha;
822 if (tex->gc->shared->info.bgra)
823 tex->pt = _pool_tex_render_new(tex->gc, tex->w, tex->h, bgra_ifmt, bgra_fmt);
825 tex->pt = _pool_tex_render_new(tex->gc, tex->w, tex->h, rgba_ifmt, rgba_fmt);
829 if (tex->gc->shared->info.bgra)
830 tex->pt = _pool_tex_render_new(tex->gc, tex->w, tex->h, bgr_ifmt, bgr_fmt);
832 tex->pt = _pool_tex_render_new(tex->gc, tex->w, tex->h, rgb_ifmt, rgb_fmt);
835 if (!tex->pt) return;
836 if (!im->image.data) return;
838 fmt = tex->pt->format;
839 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
840 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
841 #ifdef GL_UNPACK_ROW_LENGTH
842 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
843 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
845 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
846 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
848 // printf("tex upload %ix%i\n", im->cache_entry.w, im->cache_entry.h);
852 _tex_sub_2d(tex->x, tex->y,
853 im->cache_entry.w, im->cache_entry.h,
854 fmt, tex->pt->dataformat,
859 _tex_sub_2d(tex->x - 1, tex->y,
860 1, im->cache_entry.h,
861 fmt, tex->pt->dataformat,
866 _tex_sub_2d(tex->x + im->cache_entry.w, tex->y,
867 1, im->cache_entry.h,
868 fmt, tex->pt->dataformat,
869 im->image.data + (im->cache_entry.w - 1));
873 _tex_sub_2d(tex->x, tex->y + im->cache_entry.h,
874 im->cache_entry.w, 1,
875 fmt, tex->pt->dataformat,
876 im->image.data + ((im->cache_entry.h - 1) * im->cache_entry.w));
880 _tex_sub_2d(tex->x - 1, tex->y + im->cache_entry.h,
882 fmt, tex->pt->dataformat,
883 im->image.data + ((im->cache_entry.h - 1) * im->cache_entry.w));
887 _tex_sub_2d(tex->x + im->cache_entry.w, tex->y + im->cache_entry.h,
889 fmt, tex->pt->dataformat,
890 im->image.data + ((im->cache_entry.h - 1) * im->cache_entry.w) + (im->cache_entry.w - 1));
891 if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
893 glBindTexture(GL_TEXTURE_2D, tex->gc->pipe[0].shader.cur_tex);
894 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
899 evas_gl_common_texture_free(Evas_GL_Texture *tex)
903 if (tex->references != 0) return;
904 if (tex->double_buffer.pt[0])
906 tex->double_buffer.pt[0]->allocations = eina_list_remove(tex->double_buffer.pt[0]->allocations, tex);
907 tex->double_buffer.pt[1]->allocations = eina_list_remove(tex->double_buffer.pt[1]->allocations, tex);
908 tex->double_buffer.ptuv[0]->allocations = eina_list_remove(tex->double_buffer.ptuv[0]->allocations, tex);
909 tex->double_buffer.ptuv[1]->allocations = eina_list_remove(tex->double_buffer.ptuv[1]->allocations, tex);
915 tex->pt->allocations = eina_list_remove(tex->pt->allocations, tex);
920 tex->ptu->allocations = eina_list_remove(tex->ptu->allocations, tex);
925 tex->ptv->allocations = eina_list_remove(tex->ptv->allocations, tex);
930 tex->ptuv->allocations = eina_list_remove(tex->ptuv->allocations, tex);
938 evas_gl_common_texture_alpha_new(Evas_Engine_GL_Context *gc, DATA8 *pixels,
939 unsigned int w, unsigned int h, int fh)
941 Evas_GL_Texture *tex;
942 Eina_List *l_after = NULL;
945 tex = calloc(1, sizeof(Evas_GL_Texture));
946 if (!tex) return NULL;
950 tex->pt = _pool_tex_find(gc, w + 3, fh, alpha_ifmt, alpha_fmt, &u, &v,
952 gc->shared->info.tune.atlas.max_alloc_alpha_size);
963 tex->pt->allocations =
964 eina_list_append_relative_list(tex->pt->allocations, tex, l_after);
966 tex->pt->allocations = eina_list_prepend(tex->pt->allocations, tex);
967 tex->pt->references++;
968 evas_gl_common_texture_alpha_update(tex, pixels, w, h, fh);
973 evas_gl_common_texture_alpha_update(Evas_GL_Texture *tex, DATA8 *pixels,
974 unsigned int w, unsigned int h, int fh __UNUSED__)
976 if (!tex->pt) return;
977 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
978 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
979 #ifdef GL_UNPACK_ROW_LENGTH
980 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
981 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
983 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
984 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
985 _tex_sub_2d(tex->x, tex->y, w, h, tex->pt->format, tex->pt->dataformat,
987 if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
989 glBindTexture(GL_TEXTURE_2D, tex->gc->pipe[0].shader.cur_tex);
990 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
995 evas_gl_common_texture_yuv_new(Evas_Engine_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h)
997 Evas_GL_Texture *tex;
999 tex = calloc(1, sizeof(Evas_GL_Texture));
1000 if (!tex) return NULL;
1003 tex->references = 1;
1004 tex->pt = _pool_tex_new(gc, w + 1, h + 1, lum_ifmt, lum_fmt);
1010 gc->shared->tex.whole = eina_list_prepend(gc->shared->tex.whole, tex->pt);
1012 tex->pt->fslot = -1;
1014 tex->ptu = _pool_tex_new(gc, (w / 2) + 1, (h / 2) + 1, lum_ifmt, lum_fmt);
1020 gc->shared->tex.whole = eina_list_prepend(gc->shared->tex.whole, tex->ptu);
1021 tex->ptu->slot = -1;
1022 tex->ptu->fslot = -1;
1023 tex->ptu->whole = 1;
1024 tex->ptv = _pool_tex_new(gc, (w / 2) + 1, (h / 2) + 1, lum_ifmt, lum_fmt);
1032 gc->shared->tex.whole = eina_list_prepend(gc->shared->tex.whole, tex->ptv);
1033 tex->ptv->slot = -1;
1034 tex->ptv->fslot = -1;
1035 tex->ptv->whole = 1;
1040 tex->pt->allocations = eina_list_prepend(tex->pt->allocations, tex);
1041 tex->ptu->allocations = eina_list_prepend(tex->ptu->allocations, tex);
1042 tex->ptv->allocations = eina_list_prepend(tex->ptv->allocations, tex);
1043 tex->pt->references++;
1044 tex->ptu->references++;
1045 tex->ptv->references++;
1046 evas_gl_common_texture_yuv_update(tex, rows, w, h);
1051 evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, DATA8 **rows, unsigned int w, unsigned int h)
1053 if (!tex->pt) return;
1054 // FIXME: works on lowest size 4 pixel high buffers. must also be multiple of 2
1055 #ifdef GL_UNPACK_ROW_LENGTH
1056 glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[1] - rows[0]);
1057 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1058 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1059 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1060 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
1061 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1062 _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
1063 _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
1064 glBindTexture(GL_TEXTURE_2D, tex->ptu->texture);
1065 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1066 glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[h + 1] - rows[h]);
1067 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1068 _tex_2d(tex->ptu->intformat, w / 2, h / 2, tex->ptu->format, tex->ptu->dataformat);
1069 _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptu->format, tex->ptu->dataformat, rows[h]);
1070 glBindTexture(GL_TEXTURE_2D, tex->ptv->texture);
1071 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1072 glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[h + (h / 2) + 1] - rows[h + (h / 2)]);
1073 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1074 _tex_2d(tex->ptv->intformat, w / 2, h / 2, tex->ptv->format, tex->ptv->dataformat);
1075 _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptv->format, tex->ptv->dataformat, rows[h + (h / 2)]);
1079 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1080 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1081 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
1082 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1083 _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
1084 if ((rows[1] - rows[0]) == (int)w)
1085 _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
1088 for (y = 0; y < h; y++)
1089 _tex_sub_2d(0, y, w, 1, tex->pt->format, tex->pt->dataformat, rows[y]);
1092 glBindTexture(GL_TEXTURE_2D, tex->ptu->texture);
1093 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1094 _tex_2d(tex->ptu->intformat, w / 2, h / 2, tex->ptu->format, tex->ptu->dataformat);
1095 if ((rows[h + 1] - rows[h]) == (int)(w / 2))
1096 _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptu->format, tex->ptu->dataformat, rows[h]);
1099 for (y = 0; y < (h / 2); y++)
1100 _tex_sub_2d(0, y, w / 2, 1, tex->ptu->format, tex->ptu->dataformat, rows[h + y]);
1103 glBindTexture(GL_TEXTURE_2D, tex->ptv->texture);
1104 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1105 _tex_2d(tex->ptv->intformat, w / 2, h / 2, tex->ptv->format, tex->ptv->dataformat);
1106 if ((rows[h + (h / 2) + 1] - rows[h + (h / 2)]) == (int)(w / 2))
1107 _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptv->format, tex->ptv->dataformat, rows[h + (h / 2)]);
1110 for (y = 0; y < (h / 2); y++)
1111 _tex_sub_2d(0, y, w / 2, 1, tex->ptv->format, tex->ptv->dataformat, rows[h + (h / 2) + y]);
1114 if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
1116 glBindTexture(GL_TEXTURE_2D, tex->gc->pipe[0].shader.cur_tex);
1117 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1121 static Evas_GL_Texture *
1122 _evas_gl_common_texture_y2uv_new(Evas_Engine_GL_Context *gc,
1123 unsigned int yw, unsigned int yh,
1124 unsigned int uvw, unsigned int uvh,
1125 GLenum y_ifmt, GLenum y_fmt,
1126 GLenum uv_ifmt, GLenum uv_fmt,
1129 Evas_GL_Texture_Pool *pt[2] = { NULL, NULL };
1130 Evas_GL_Texture_Pool *ptuv[2] = { NULL, NULL };
1131 Evas_GL_Texture *tex;
1135 pt[0] = _pool_tex_new(gc, yw + 1, yh + 1, y_ifmt, y_fmt);
1136 pt[1] = _pool_tex_new(gc, yw + 1, yh + 1, y_ifmt, y_fmt);
1138 ptuv[0] = _pool_tex_new(gc, uvw + 1, uvh + 1, uv_ifmt, uv_fmt);
1139 ptuv[1] = _pool_tex_new(gc, uvw + 1, uvh + 1, uv_ifmt, uv_fmt);
1143 pt[0] = _pool_tex_dynamic_new(gc, yw + 1, yh + 1, y_ifmt, y_fmt);
1144 pt[1] = _pool_tex_dynamic_new(gc, yw + 1, yh + 1, y_ifmt, y_fmt);
1146 ptuv[0] = _pool_tex_dynamic_new(gc, uvw + 1, uvh + 1, uv_ifmt, uv_fmt);
1147 ptuv[1] = _pool_tex_dynamic_new(gc, uvw + 1, uvh + 1, uv_ifmt, uv_fmt);
1150 if (!pt[0] || !pt[1] || !ptuv[0] || !ptuv[1])
1153 tex = calloc(1, sizeof(Evas_GL_Texture));
1158 tex->references = 1;
1160 tex->ptuv = ptuv[0];
1163 pt_link(gc, tex, pt[0]);
1164 pt_link(gc, tex, pt[1]);
1165 pt_link(gc, tex, ptuv[0]);
1166 pt_link(gc, tex, ptuv[1]);
1172 tex->double_buffer.source = 0;
1173 memcpy(tex->double_buffer.pt, pt, sizeof (Evas_GL_Texture_Pool *) * 2);
1174 memcpy(tex->double_buffer.ptuv, ptuv, sizeof (Evas_GL_Texture_Pool *) * 2);
1187 evas_gl_common_texture_yuy2_new(Evas_Engine_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h)
1189 Evas_GL_Texture *tex;
1191 tex = _evas_gl_common_texture_y2uv_new(gc, w, h, w / 2, h, lum_alpha_ifmt, lum_alpha_fmt, rgba8_ifmt, rgba8_fmt, 0);
1192 evas_gl_common_texture_yuy2_update(tex, rows, w, h);
1197 evas_gl_common_texture_nv12_new(Evas_Engine_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h)
1199 Evas_GL_Texture *tex;
1201 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1202 tex = _evas_gl_common_texture_y2uv_new(gc, w, h, w / 2, h / 2, lum_ifmt, lum_fmt, lum_alpha_ifmt, lum_alpha_fmt, 1);
1205 tex = _evas_gl_common_texture_y2uv_new(gc, w, h, w / 2, h / 2, lum_ifmt, lum_fmt, lum_alpha_ifmt, lum_alpha_fmt, 0);
1207 evas_gl_common_texture_nv12_update(tex, rows, w, h);
1212 evas_gl_common_texture_nv12tiled_new(Evas_Engine_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h)
1214 Evas_GL_Texture *tex = NULL;
1216 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1217 tex = _evas_gl_common_texture_y2uv_new(gc, w, h, w, h, lum_ifmt, lum_fmt, lum_alpha_ifmt, lum_alpha_fmt, 1);
1220 tex = _evas_gl_common_texture_y2uv_new(gc, w, h, w, h, lum_ifmt, lum_fmt, lum_alpha_ifmt, lum_alpha_fmt, 0);
1222 evas_gl_common_texture_nv12tiled_update(tex, rows, w, h);
1227 evas_gl_common_texture_yuy2_update(Evas_GL_Texture *tex, DATA8 **rows, unsigned int w, unsigned int h)
1229 if (!tex->pt) return;
1230 // FIXME: works on lowest size 4 pixel high buffers. must also be multiple of 2
1233 tex->double_buffer.source = 1 - tex->double_buffer.source;
1234 tex->pt = tex->double_buffer.pt[tex->double_buffer.source];
1235 tex->ptuv = tex->double_buffer.ptuv[tex->double_buffer.source];
1237 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1238 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1239 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
1240 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1241 _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
1242 if ((rows[1] - rows[0]) == (int)w * 4)
1243 _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
1246 for (y = 0; y < h; y++)
1247 _tex_sub_2d(0, y, w, 1, tex->pt->format, tex->pt->dataformat, rows[y]);
1250 glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
1251 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1252 _tex_2d(tex->ptuv->intformat, w / 2, h, tex->ptuv->format, tex->ptuv->dataformat);
1253 if ((rows[1] - rows[0]) == (int)(w * 2))
1254 _tex_sub_2d(0, 0, w / 2, h, tex->ptuv->format, tex->ptuv->dataformat, rows[0]);
1257 for (y = 0; y < h; y++)
1258 _tex_sub_2d(0, y, w / 2, 1, tex->ptuv->format, tex->ptuv->dataformat, rows[y]);
1261 if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
1263 glBindTexture(GL_TEXTURE_2D, tex->gc->pipe[0].shader.cur_tex);
1264 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1269 evas_gl_common_texture_nv12_update(Evas_GL_Texture *tex, DATA8 **rows, unsigned int w, unsigned int h)
1271 if (!tex->pt) return;
1273 tex->double_buffer.source = 1 - tex->double_buffer.source;
1274 tex->pt = tex->double_buffer.pt[tex->double_buffer.source];
1275 tex->ptuv = tex->double_buffer.ptuv[tex->double_buffer.source];
1277 // FIXME: works on lowest size 4 pixel high buffers. must also be multiple of 2
1278 #ifdef GL_UNPACK_ROW_LENGTH
1279 glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[1] - rows[0]);
1280 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1281 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1282 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1283 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
1284 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1285 _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
1286 _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
1287 glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
1288 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1289 glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[h + 1] - rows[h]);
1290 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1291 _tex_2d(tex->ptuv->intformat, w / 2, h / 2, tex->ptuv->format, tex->ptuv->dataformat);
1292 _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptuv->format, tex->ptuv->dataformat, rows[h]);
1296 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1297 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1298 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
1299 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1300 _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
1301 if ((rows[1] - rows[0]) == (int)w)
1302 _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
1305 for (y = 0; y < h; y++)
1306 _tex_sub_2d(0, y, w, 1, tex->pt->format, tex->pt->dataformat, rows[y]);
1309 glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
1310 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1311 _tex_2d(tex->ptuv->intformat, w / 2, h / 2, tex->ptuv->format, tex->ptuv->dataformat);
1312 if ((rows[h + 1] - rows[h]) == (int)(w / 2))
1313 _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptuv->format, tex->ptuv->dataformat, rows[h]);
1316 for (y = 0; y < (h / 2); y++)
1317 _tex_sub_2d(0, y, w / 2, 1, tex->ptuv->format, tex->ptuv->dataformat, rows[h + y]);
1320 if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
1322 glBindTexture(GL_TEXTURE_2D, tex->gc->pipe[0].shader.cur_tex);
1323 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1328 evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture *tex, DATA8 **rows, unsigned int w, unsigned int h)
1330 unsigned int mb_x, mb_y, mb_w, mb_h;
1331 unsigned int base_h;
1333 if (!tex->pt) return;
1335 tex->double_buffer.source = 1 - tex->double_buffer.source;
1336 tex->pt = tex->double_buffer.pt[tex->double_buffer.source];
1337 tex->ptuv = tex->double_buffer.ptuv[tex->double_buffer.source];
1339 mb_w = w / 64 + (w % 64 ? 1 : 0);
1340 mb_h = h / 32 + (h % 32 ? 1 : 0);
1342 #if ( defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) )
1348 texture_addr = secsym_eglMapImageSEC(tex->gc->egldisp, tex->pt->dyn.img);
1350 /* Iterate each Y macroblock like we do in evas_convert_yuv.c */
1351 for (mb_y = 0; mb_y < (mb_h >> 1); mb_y++)
1359 ry[0] = mb_y * 2 * 32 * tex->pt->dyn.stride;
1360 ry[1] = ry[0] + 32 * tex->pt->dyn.stride;
1362 for (mb_x = 0; mb_x < mb_w * 2; mb_x++, rmb_x += 64 * 32)
1366 tmp = texture_addr + x + ry[offset];
1368 for (i = 0; i < 32 * 64; i += 64, tmp += tex->pt->dyn.stride)
1369 memcpy(tmp, rows[mb_y] + rmb_x + i, 64);
1372 if ((step & 0x3) == 0)
1374 offset = 1 - offset;
1390 ry = mb_y * 2 * 32 * tex->pt->dyn.stride;
1392 for (mb_x = 0; mb_x < mb_w; mb_x++, x += 64, rmb_x += 64 * 32)
1396 tmp = texture_addr + x + ry;
1398 for (i = 0; i < 32 * 64; i += 64, tmp += tex->pt->dyn.stride)
1399 memcpy(tmp, rows[mb_y] + rmb_x + i, 64);
1403 secsym_eglUnmapImageSEC(tex->gc->egldisp, tex->pt->dyn.img);
1405 texture_addr = secsym_eglMapImageSEC(tex->gc->egldisp, tex->ptuv->dyn.img);
1407 /* Iterate each UV macroblock like we do in evas_convert_yuv.c */
1408 base_h = (mb_h >> 1) + (mb_h & 0x1);
1410 /* h is always a multiple of 32 */
1412 mb_h = (mb_h / 32 + (mb_h % 32 ? 1 : 0));
1415 mb_w = (mb_w / 32 + (mb_w % 32 ? 1 : 0));
1417 for (mb_y = 0; mb_y < (mb_h >> 1); mb_y++)
1425 ry[0] = mb_y * 2 * 32 * tex->ptuv->dyn.stride;
1426 ry[1] = ry[0] + 32 * tex->ptuv->dyn.stride;
1428 for (mb_x = 0; mb_x < mb_w * 4; mb_x++, rmb_x += 64 * 32)
1432 tmp = texture_addr + x + ry[offset];
1434 for (i = 0; i < 32 * 64; i += 64, tmp += tex->ptuv->dyn.stride)
1435 memcpy(tmp, rows[mb_y + base_h] + rmb_x + i, 64);
1438 if ((step & 0x3) == 0)
1440 offset = 1 - offset;
1456 ry = mb_y * 2 * 32 * tex->ptuv->dyn.stride;
1458 for (mb_x = 0; mb_x < mb_w * 2; mb_x++, x += 64, rmb_x += 64 * 32)
1462 tmp = texture_addr + x + ry;
1464 /* It has horizontaly half the pixels, but they are double the size*/
1465 for (i = 0; i < 32 * 64; i += 64, tmp += tex->ptuv->dyn.stride)
1466 memcpy(tmp, rows[mb_y + base_h] + rmb_x + i, 64);
1470 secsym_eglUnmapImageSEC(tex->gc->egldisp, tex->ptuv->dyn.img);
1475 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1476 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1478 glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
1479 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1481 // We are telling the driver to not swizzle back the buffer as we are going to replace all pixel
1482 _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
1484 /* Iterate each Y macroblock like we do in evas_convert_yuv.c */
1485 for (mb_y = 0; mb_y < (mb_h >> 1); mb_y++)
1493 ry[0] = mb_y * 2 * 32;
1496 for (mb_x = 0; mb_x < mb_w * 2; mb_x++, rmb_x += 64 * 32)
1498 _tex_sub_2d(x, ry[offset], 64, 32, tex->pt->format, tex->pt->dataformat, rows[mb_y] + rmb_x);
1501 if ((step & 0x3) == 0)
1503 offset = 1 - offset;
1521 for (mb_x = 0; mb_x < mb_w; mb_x++, x += 64, rmb_x += 64 * 32)
1522 _tex_sub_2d(x, ry, 64, 32, tex->pt->format, tex->pt->dataformat, rows[mb_y] + rmb_x);
1525 glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
1526 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1528 _tex_2d(tex->ptuv->intformat, w, h, tex->ptuv->format, tex->ptuv->dataformat);
1530 /* Iterate each UV macroblock like we do in evas_convert_yuv.c */
1531 base_h = (mb_h >> 1) + (mb_h & 0x1);
1533 /* h is always a multiple of 32 */
1535 mb_h = (mb_h / 32 + (mb_h % 32 ? 1 : 0));
1538 mb_w = (mb_w / 32 + (mb_w % 32 ? 1 : 0));
1540 for (mb_y = 0; mb_y < (mb_h >> 1); mb_y++)
1548 ry[0] = mb_y * 2 * 32;
1551 for (mb_x = 0; mb_x < mb_w * 2; mb_x++, rmb_x += 64 * 32)
1553 _tex_sub_2d(x, ry[offset], 32, 32,
1554 tex->ptuv->format, tex->ptuv->dataformat,
1555 rows[mb_y + base_h] + rmb_x);
1557 if ((step & 0x3) == 0)
1559 offset = 1 - offset;
1577 for (mb_x = 0; mb_x < mb_w; mb_x++, x += 32, rmb_x += 64 * 32)
1578 _tex_sub_2d(x, ry, 64, 32, tex->ptuv->format, tex->ptuv->dataformat, rows[mb_y + base_h] + rmb_x);