Commit f457f7a31c03f218cdcb31108fefb343d6be14a8

  • avatar
  • Chia-I Wu <olvaffe @gm…l.com>
  • Tue Oct 27 10:45:13 CET 2009
egl_android: Decide image config by matching the native pixmap.
  
6464 _EGLSurface *surf,
6565 NativeWindowType win);
6666 struct droid_surface *(*create_image_surface)(struct droid_backend *backend,
67 NativePixmapType pix,
68 int *depth);
67 NativePixmapType pix);
6968 void (*destroy_surface)(struct droid_backend *backend, struct droid_surface *surf);
7069 void (*swap_native_buffers)(struct droid_backend *backend,
7170 struct droid_surface *surf);
71
72 int (*match_pixmap)(struct droid_backend *backend, _EGLConfig *conf,
73 NativePixmapType pix);
7274};
7375
7476struct droid_screen {
8282
8383 const __DRIconfig **dri_configs;
8484 int num_dri_configs;
85
86#define DROID_MAX_IMAGE_DEPTH 32
87 const __DRIconfig *image_configs[DROID_MAX_IMAGE_DEPTH + 1];
8885};
8986
9087struct droid_backend *
  
472472
473473static struct droid_surface *
474474intel_create_image_surface(struct droid_backend *backend,
475 NativePixmapType pix, int *depth)
475 NativePixmapType pix)
476476{
477477 struct droid_surface_intel *isurf;
478478 int cpp;
490490 return NULL;
491491 }
492492
493 cpp = ui_bytes_per_pixel(pix->format);
494 if (cpp * 8 > DROID_MAX_IMAGE_DEPTH) {
495 LOGE("pixmap of depth %d is not supported", cpp * 8);
496 _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCreateImage");
497 return NULL;
498 }
499
500493 isurf = calloc(1, sizeof(*isurf));
501494 if (!isurf) {
502495 _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
501501
502502 update_native_buffer((struct droid_surface *) isurf);
503503
504 if (depth)
505 *depth = cpp * 8;
506
507504 return (struct droid_surface *) isurf;
508505}
509506
532532}
533533
534534static int
535intel_match_pixmap(struct droid_backend *backend, _EGLConfig *conf,
536 NativePixmapType pix)
537{
538 int val;
539 val = GET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE);
540 /* match the visual type */
541 return (pix->format == val);
542}
543
544static int
535545intel_initialize(struct droid_backend *backend, int *fd, int *screen_number)
536546{
537547 struct droid_backend_intel *intel = lookup_backend(backend);
637637 intel->base.create_image_surface = intel_create_image_surface;
638638 intel->base.destroy_surface = intel_destroy_surface;
639639 intel->base.swap_native_buffers = intel_swap_native_buffers;
640
641 intel->base.match_pixmap = intel_match_pixmap;
640642
641643 return &intel->base;
642644}
  
209209 backend->destroy(backend);
210210}
211211
212static void
213screen_find_image_configs(struct droid_screen *screen)
214{
215 struct droid_loader *loader = screen->loader;
216 int depth, i;
217
218 for (depth = 0; depth < DROID_MAX_IMAGE_DEPTH + 1; depth++) {
219 for (i = 0; i < screen->num_dri_configs; i++) {
220 const __DRIconfig *conf = screen->dri_configs[i];
221 _EGLConfig egl_conf;
222 EGLint rgba, val;
223
224 droid_screen_convert_config(screen, conf, &egl_conf);
225
226 val = GET_CONFIG_ATTRIB(&egl_conf, EGL_CONFIG_CAVEAT);
227 if (val == EGL_SLOW_CONFIG)
228 continue;
229
230 rgba = GET_CONFIG_ATTRIB(&egl_conf, EGL_RED_SIZE);
231 rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_GREEN_SIZE);
232 rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_BLUE_SIZE);
233 rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_ALPHA_SIZE);
234 if (depth != rgba)
235 continue;
236
237 if (depth == 32) {
238 val = GET_CONFIG_ATTRIB(&egl_conf, EGL_BIND_TO_TEXTURE_RGBA);
239 if (val) {
240 screen->image_configs[depth] = conf;
241 break;
242 }
243 }
244
245 val = GET_CONFIG_ATTRIB(&egl_conf, EGL_BIND_TO_TEXTURE_RGB);
246 if (val) {
247 screen->image_configs[depth] = conf;
248 break;
249 }
250 }
251 }
252}
253
254212struct droid_screen *
255213droid_screen_create(struct droid_backend *backend)
256214{
271271 ;
272272 screen->num_dri_configs = i;
273273
274 screen_find_image_configs(screen);
275
276274 return screen;
277275
278276fail:
436436 img->magic = __DRI_EGL_IMAGE_MAGIC;
437437 img->drawable = drawable->dri_drawable;
438438 img->level = 0;
439 if (drawable->dri_config == screen->image_configs[32] &&
440 loader->core->getConfigAttrib(drawable->dri_config,
441 __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA,
442 &val))
443 img->texture_format_rgba = val;
439 if (loader->core->getConfigAttrib(drawable->dri_config,
440 __DRI_ATTRIB_ALPHA_SIZE, &val))
441 img->texture_format_rgba = (val > 0);
444442
445443 drawable->dri_image = img;
446444 }
  
412412{
413413 struct droid_egl_display *droid_dpy = lookup_display(dpy);
414414 struct droid_egl_image *droid_img;
415 const __DRIconfig *dri_conf;
416 int depth;
415 struct droid_egl_config *droid_conf;
416 _EGLConfig *conf;
417 EGLint val, i;
417418
419 /* only EGL_KHR_image_pixmap is supported */
418420 if (target != EGL_NATIVE_PIXMAP_KHR || ctx) {
419421 _eglError(EGL_BAD_PARAMETER, "eglCreateImageKHR");
420422 return NULL;
421423 }
422424
425 for (i = 0; i < dpy->NumConfigs; i++) {
426 conf = dpy->Configs[i];
427 if (droid_dpy->backend->match_pixmap(droid_dpy->backend, conf,
428 (NativePixmapType) buffer)) {
429 EGLint val;
430 val = GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB);
431 val |= GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA);
432 if (val)
433 break;
434 }
435 }
436 if (i >= dpy->NumConfigs)
437 return NULL;
438
423439 droid_img = calloc(1, sizeof(*droid_img));
424440 if (!droid_img) {
425441 _eglError(EGL_BAD_ALLOC, "eglCreateImageKHR");
449449
450450 droid_img->surface =
451451 droid_dpy->backend->create_image_surface(droid_dpy->backend,
452 (NativePixmapType) buffer,
453 &depth);
452 (NativePixmapType) buffer);
454453 if (!droid_img->surface) {
455454 free(droid_img);
456455 return NULL;
457456 }
458457
459 dri_conf = droid_dpy->screen->image_configs[depth];
460 if (!dri_conf) {
461 droid_dpy->backend->destroy_surface(droid_dpy->backend,
462 droid_img->surface);
463 free(droid_img);
464 return NULL;
465 }
466
458 droid_conf = lookup_config(conf);
467459 droid_img->drawable =
468 droid_screen_create_drawable(droid_dpy->screen, dri_conf,
460 droid_screen_create_drawable(droid_dpy->screen, droid_conf->config,
469461 droid_img->surface);
470462
471463 if (!droid_img->drawable) {