OSDN Git Service

egl_android: Set surface type and native visual type.
authorChia-I Wu <olvaffe@gmail.com>
Tue, 27 Oct 2009 09:19:39 +0000 (17:19 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 27 Oct 2009 09:30:24 +0000 (17:30 +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/droid_ui.cpp
src/egl/drivers/android/droid_ui.h
src/egl/drivers/android/egl_android.c

index 1793f6a..06ca7ab 100644 (file)
@@ -47,6 +47,7 @@ struct droid_backend {
    /* these are usually used by a loader */
    const char *driver_name;
    int (*initialize)(struct droid_backend *backend, int *fd, int *screen_number);
+   int (*process_config)(struct droid_backend *backend, _EGLConfig *conf);
    void (*destroy)(struct droid_backend *backend);
 
    __DRIbuffer *(*get_native_buffer)(struct droid_backend *backend,
@@ -96,7 +97,7 @@ droid_screen_create(struct droid_backend *backend);
 void
 droid_screen_destroy(struct droid_screen *screen);
 
-void
+int
 droid_screen_convert_config(struct droid_screen *screen,
                             const __DRIconfig *conf, _EGLConfig *egl_conf);
 
index 070b270..32570b5 100644 (file)
@@ -565,6 +565,34 @@ intel_initialize(struct droid_backend *backend, int *fd, int *screen_number)
    return 1;
 }
 
+#include <assert.h>
+static int
+intel_process_config(struct droid_backend *backend, _EGLConfig *conf)
+{
+   int r, g, b, a;
+   int surface_type;
+   int format;
+
+   r = GET_CONFIG_ATTRIB(conf, EGL_RED_SIZE);
+   g = GET_CONFIG_ATTRIB(conf, EGL_GREEN_SIZE);
+   b = GET_CONFIG_ATTRIB(conf, EGL_BLUE_SIZE);
+   a = GET_CONFIG_ATTRIB(conf, EGL_ALPHA_SIZE);
+   format = ui_get_rgb_format(r, g, b, a);
+
+   if (format) {
+      SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, format);
+      SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE,
+                        EGL_WINDOW_BIT |
+                        EGL_PIXMAP_BIT |
+                        EGL_PBUFFER_BIT);
+   }
+   else {
+      SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT);
+   }
+
+   return 1;
+}
+
 static void
 intel_destroy(struct droid_backend *backend)
 {
@@ -599,6 +627,7 @@ droid_backend_create_intel(const char *dev)
 
    intel->base.driver_name = "i915";
    intel->base.initialize = intel_initialize;
+   intel->base.process_config = intel_process_config;
    intel->base.destroy = intel_destroy;
 
    intel->base.get_native_buffer = intel_get_native_buffer;
index 7dc846a..00b08a5 100644 (file)
@@ -357,7 +357,7 @@ static const struct {
    { EGL_STENCIL_SIZE,             __DRI_ATTRIB_STENCIL_SIZE },
 };
 
-void
+int
 droid_screen_convert_config(struct droid_screen *screen,
                             const __DRIconfig *conf, _EGLConfig *egl_conf)
 {
@@ -374,7 +374,7 @@ droid_screen_convert_config(struct droid_screen *screen,
 
       if (!loader->core->getConfigAttrib(conf, dri_attrib, &dri_value)) {
          LOGE("failed to get attribute %02d for %p", dri_attrib, conf);
-         continue;
+         return 0;
       }
 
       switch (egl_attrib) {
@@ -392,6 +392,8 @@ droid_screen_convert_config(struct droid_screen *screen,
       }
       SET_CONFIG_ATTRIB(egl_conf, egl_attrib, egl_value);
    }
+
+   return loader->backend->process_config(loader->backend, egl_conf);
 }
 
 struct droid_context *
index 6ceff1b..994480c 100644 (file)
@@ -52,3 +52,30 @@ int ui_bytes_per_pixel(int format)
 {
    return bytesPerPixel(format);
 }
+
+int ui_get_rgb_format(int red, int green, int blue, int alpha)
+{
+   PixelFormatInfo info;
+   PixelFormat fmt;
+
+   /* look in the RGB range */
+   for (fmt = 1; fmt < PIXEL_FORMAT_YCbCr_422_SP; fmt++) {
+      status_t err = getPixelFormatInfo(fmt, &info);
+      if (err)
+         return -1;
+      /* bpp must be equal to depth */
+      if (info.bytesPerPixel * 8 != info.bitsPerPixel)
+         continue;
+
+      if ((info.h_red - info.l_red != red) ||
+          (info.h_green - info.l_green != green) ||
+          (info.h_blue - info.l_blue != blue) ||
+          (info.h_alpha - info.l_alpha != alpha))
+         continue;
+
+      /* mask? */
+      return fmt;
+   }
+
+   return -1;
+}
index 3153ec8..e7bdbf2 100644 (file)
@@ -32,6 +32,7 @@ extern "C" {
 
 int ui_auth_gpu(drm_magic_t magic);
 int ui_bytes_per_pixel(int format);
+int ui_get_rgb_format(int red, int green, int blue, int alpha);
 
 #ifdef __cplusplus
 }
index 601e9fb..c1bc1f3 100644 (file)
@@ -137,8 +137,11 @@ droid_create_configs(_EGLDisplay *dpy, struct droid_egl_display *droid_dpy,
 
       _eglInitConfig(&droid_conf->base, id);
       droid_conf->config = configs[i];
-      droid_screen_convert_config(droid_dpy->screen, droid_conf->config,
-                                  &droid_conf->base);
+      if (!droid_screen_convert_config(droid_dpy->screen, droid_conf->config,
+                                       &droid_conf->base)) {
+         free(droid_conf);
+         continue;
+      }
 
       val = GET_CONFIG_ATTRIB(&droid_conf->base, EGL_CONFIG_CAVEAT);
       /* we do not want slow configs */