OSDN Git Service

egl_android: Decide image config by matching the native pixmap.
authorChia-I Wu <olvaffe@gmail.com>
Tue, 27 Oct 2009 08:15:54 +0000 (16:15 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 27 Oct 2009 09:45:13 +0000 (17:45 +0800)
src/egl/drivers/android/droid.h
src/egl/drivers/android/droid_intel.c
src/egl/drivers/android/droid_loader.c
src/egl/drivers/android/egl_android.c

index 06ca7ab..7a8c725 100644 (file)
@@ -64,11 +64,13 @@ struct droid_backend {
                                                   _EGLSurface *surf,
                                                   NativeWindowType win);
    struct droid_surface *(*create_image_surface)(struct droid_backend *backend,
-                                                 NativePixmapType pix,
-                                                 int *depth);
+                                                 NativePixmapType pix);
    void (*destroy_surface)(struct droid_backend *backend, struct droid_surface *surf);
    void (*swap_native_buffers)(struct droid_backend *backend,
                                struct droid_surface *surf);
+
+   int (*match_pixmap)(struct droid_backend *backend, _EGLConfig *conf,
+                       NativePixmapType pix);
 };
 
 struct droid_screen {
@@ -80,9 +82,6 @@ struct droid_screen {
 
    const __DRIconfig **dri_configs;
    int num_dri_configs;
-
-#define DROID_MAX_IMAGE_DEPTH 32
-   const __DRIconfig *image_configs[DROID_MAX_IMAGE_DEPTH + 1];
 };
 
 struct droid_backend *
index 32570b5..3209ff9 100644 (file)
@@ -472,7 +472,7 @@ intel_create_window_surface(struct droid_backend *backend,
 
 static struct droid_surface *
 intel_create_image_surface(struct droid_backend *backend,
-                           NativePixmapType pix, int *depth)
+                           NativePixmapType pix)
 {
    struct droid_surface_intel *isurf;
    int cpp;
@@ -490,13 +490,6 @@ intel_create_image_surface(struct droid_backend *backend,
       return NULL;
    }
 
-   cpp = ui_bytes_per_pixel(pix->format);
-   if (cpp * 8 > DROID_MAX_IMAGE_DEPTH) {
-      LOGE("pixmap of depth %d is not supported", cpp * 8);
-      _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCreateImage");
-      return NULL;
-   }
-
    isurf = calloc(1, sizeof(*isurf));
    if (!isurf) {
       _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
@@ -508,9 +501,6 @@ intel_create_image_surface(struct droid_backend *backend,
 
    update_native_buffer((struct droid_surface *) isurf);
 
-   if (depth)
-      *depth = cpp * 8;
-
    return (struct droid_surface *) isurf;
 }
 
@@ -542,6 +532,16 @@ intel_swap_native_buffers(struct droid_backend *backend,
 }
 
 static int
+intel_match_pixmap(struct droid_backend *backend, _EGLConfig *conf,
+                   NativePixmapType pix)
+{
+   int val;
+   val = GET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE);
+   /* match the visual type */
+   return (pix->format == val);
+}
+
+static int
 intel_initialize(struct droid_backend *backend, int *fd, int *screen_number)
 {
    struct droid_backend_intel *intel = lookup_backend(backend);
@@ -638,5 +638,7 @@ droid_backend_create_intel(const char *dev)
    intel->base.destroy_surface = intel_destroy_surface;
    intel->base.swap_native_buffers = intel_swap_native_buffers;
 
+   intel->base.match_pixmap = intel_match_pixmap;
+
    return &intel->base;
 }
index 00b08a5..7832885 100644 (file)
@@ -209,48 +209,6 @@ droid_backend_destroy(struct droid_backend *backend)
    backend->destroy(backend);
 }
 
-static void
-screen_find_image_configs(struct droid_screen *screen)
-{
-   struct droid_loader *loader = screen->loader;
-   int depth, i;
-
-   for (depth = 0; depth < DROID_MAX_IMAGE_DEPTH + 1; depth++) {
-      for (i = 0; i < screen->num_dri_configs; i++) {
-         const __DRIconfig *conf = screen->dri_configs[i];
-         _EGLConfig egl_conf;
-         EGLint rgba, val;
-
-         droid_screen_convert_config(screen, conf, &egl_conf);
-
-         val = GET_CONFIG_ATTRIB(&egl_conf, EGL_CONFIG_CAVEAT);
-         if (val == EGL_SLOW_CONFIG)
-            continue;
-
-         rgba  = GET_CONFIG_ATTRIB(&egl_conf, EGL_RED_SIZE);
-         rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_GREEN_SIZE);
-         rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_BLUE_SIZE);
-         rgba += GET_CONFIG_ATTRIB(&egl_conf, EGL_ALPHA_SIZE);
-         if (depth != rgba)
-            continue;
-
-         if (depth == 32) {
-            val = GET_CONFIG_ATTRIB(&egl_conf, EGL_BIND_TO_TEXTURE_RGBA);
-            if (val) {
-               screen->image_configs[depth] = conf;
-               break;
-            }
-         }
-
-         val = GET_CONFIG_ATTRIB(&egl_conf, EGL_BIND_TO_TEXTURE_RGB);
-         if (val) {
-            screen->image_configs[depth] = conf;
-            break;
-         }
-      }
-   }
-}
-
 struct droid_screen *
 droid_screen_create(struct droid_backend *backend)
 {
@@ -313,8 +271,6 @@ droid_screen_create(struct droid_backend *backend)
       ;
    screen->num_dri_configs = i;
 
-   screen_find_image_configs(screen);
-
    return screen;
 
 fail:
@@ -480,11 +436,9 @@ droid_screen_get_drawable_data(struct droid_screen *screen,
       img->magic = __DRI_EGL_IMAGE_MAGIC;
       img->drawable = drawable->dri_drawable;
       img->level = 0;
-      if (drawable->dri_config == screen->image_configs[32] &&
-          loader->core->getConfigAttrib(drawable->dri_config,
-                                        __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA,
-                                        &val))
-         img->texture_format_rgba = val;
+      if (loader->core->getConfigAttrib(drawable->dri_config,
+                                        __DRI_ATTRIB_ALPHA_SIZE, &val))
+         img->texture_format_rgba = (val > 0);
 
       drawable->dri_image = img;
    }
index c1bc1f3..d8eb5fd 100644 (file)
@@ -412,14 +412,30 @@ droid_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
 {
    struct droid_egl_display *droid_dpy = lookup_display(dpy);
    struct droid_egl_image *droid_img;
-   const __DRIconfig *dri_conf;
-   int depth;
+   struct droid_egl_config *droid_conf;
+   _EGLConfig *conf;
+   EGLint val, i;
 
+   /* only EGL_KHR_image_pixmap is supported */
    if (target != EGL_NATIVE_PIXMAP_KHR || ctx) {
       _eglError(EGL_BAD_PARAMETER, "eglCreateImageKHR");
       return NULL;
    }
 
+   for (i = 0; i < dpy->NumConfigs; i++) {
+      conf = dpy->Configs[i];
+      if (droid_dpy->backend->match_pixmap(droid_dpy->backend, conf,
+                                           (NativePixmapType) buffer)) {
+         EGLint val;
+         val = GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB);
+         val |= GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA);
+         if (val)
+            break;
+      }
+   }
+   if (i >= dpy->NumConfigs)
+      return NULL;
+
    droid_img = calloc(1, sizeof(*droid_img));
    if (!droid_img) {
       _eglError(EGL_BAD_ALLOC, "eglCreateImageKHR");
@@ -433,23 +449,15 @@ droid_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
 
    droid_img->surface = 
       droid_dpy->backend->create_image_surface(droid_dpy->backend,
-                                               (NativePixmapType) buffer,
-                                               &depth);
+                                               (NativePixmapType) buffer);
    if (!droid_img->surface) {
       free(droid_img);
       return NULL;
    }
 
-   dri_conf = droid_dpy->screen->image_configs[depth];
-   if (!dri_conf) {
-      droid_dpy->backend->destroy_surface(droid_dpy->backend,
-                                          droid_img->surface);
-      free(droid_img);
-      return NULL;
-   }
-
+   droid_conf = lookup_config(conf);
    droid_img->drawable =
-      droid_screen_create_drawable(droid_dpy->screen, dri_conf,
+      droid_screen_create_drawable(droid_dpy->screen, droid_conf->config,
                                    droid_img->surface);
 
    if (!droid_img->drawable) {