add a function to look for a Visual matching an image format b=576143 r=jrmuizel
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 23 Jul 2010 10:28:56 +1200
changeset 48108 92559a5573bd3ef6159f8dab92931107ff581440
parent 48107 a171b4faa517e9bda444757ee7c153b9438a3daf
child 48109 8fd528e132d7737b5fb2e5b1e610f59e4d390668
push id14574
push userktomlinson@mozilla.com
push dateThu, 22 Jul 2010 23:01:26 +0000
treeherdermozilla-central@02d92df7381d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs576143
milestone2.0b3pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
add a function to look for a Visual matching an image format b=576143 r=jrmuizel
gfx/thebes/gfxXlibSurface.cpp
gfx/thebes/gfxXlibSurface.h
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -417,52 +417,85 @@ gfxXlibSurface::DepthOfVisual(const Scre
             return d_info.depth;
     }
 
     NS_ERROR("Visual not on Screen.");
     return 0;
 }
     
 /* static */
+Visual*
+gfxXlibSurface::FindVisual(Screen *screen, gfxImageFormat format)
+{
+    int depth;
+    unsigned long red_mask, green_mask, blue_mask;
+    switch (format) {
+        case ImageFormatARGB32:
+            depth = 32;
+            red_mask = 0xff0000;
+            green_mask = 0xff00;
+            blue_mask = 0xff;
+            break;
+        case ImageFormatRGB24:
+            depth = 24;
+            red_mask = 0xff0000;
+            green_mask = 0xff00;
+            blue_mask = 0xff;
+            break;
+        case ImageFormatRGB16_565:
+            depth = 16;
+            red_mask = 0xf800;
+            green_mask = 0x7e0;
+            blue_mask = 0x1f;
+            break;
+        case ImageFormatA8:
+        case ImageFormatA1:
+        default:
+            return NULL;
+    }
+
+    for (int d = 0; d < screen->ndepths; d++) {
+        const Depth& d_info = screen->depths[d];
+        if (d_info.depth != depth)
+            continue;
+
+        for (int v = 0; v < d_info.nvisuals; v++) {
+            Visual* visual = &d_info.visuals[v];
+
+            if (visual->c_class == TrueColor &&
+                visual->red_mask == red_mask &&
+                visual->green_mask == green_mask &&
+                visual->blue_mask == blue_mask)
+                return visual;
+        }
+    }
+
+    return NULL;
+}
+
+/* static */
 XRenderPictFormat*
 gfxXlibSurface::FindRenderFormat(Display *dpy, gfxImageFormat format)
 {
     switch (format) {
         case ImageFormatARGB32:
             return XRenderFindStandardFormat (dpy, PictStandardARGB32);
-            break;
         case ImageFormatRGB24:
             return XRenderFindStandardFormat (dpy, PictStandardRGB24);
-            break;
         case ImageFormatRGB16_565: {
             // PictStandardRGB16_565 is not standard Xrender format
             // we should try to find related visual
             // and find xrender format by visual
-            Visual *visual = NULL;
-            Screen *screen = DefaultScreenOfDisplay(dpy);
-            int j;
-            for (j = 0; j < screen->ndepths; j++) {
-                Depth *d = &screen->depths[j];
-                if (d->depth == 16 && d->nvisuals && &d->visuals[0]) {
-                    if (d->visuals[0].red_mask   == 0xf800 &&
-                        d->visuals[0].green_mask == 0x7e0 &&
-                        d->visuals[0].blue_mask  == 0x1f)
-                        visual = &d->visuals[0];
-                    break;
-                }
-            }
+            Visual *visual = FindVisual(DefaultScreenOfDisplay(dpy), format);
             if (!visual)
                 return NULL;
             return XRenderFindVisualFormat(dpy, visual);
-            break;
         }
         case ImageFormatA8:
             return XRenderFindStandardFormat (dpy, PictStandardA8);
-            break;
         case ImageFormatA1:
             return XRenderFindStandardFormat (dpy, PictStandardA1);
+        default:
             break;
-        default:
-            return NULL;
     }
 
     return (XRenderPictFormat*)NULL;
 }
--- a/gfx/thebes/gfxXlibSurface.h
+++ b/gfx/thebes/gfxXlibSurface.h
@@ -78,16 +78,17 @@ public:
     CreateSimilarSurface(gfxContentType aType, const gfxIntSize& aSize);
 
     const gfxIntSize& GetSize() { return mSize; }
 
     Display* XDisplay() { return mDisplay; }
     Drawable XDrawable() { return mDrawable; }
 
     static int DepthOfVisual(const Screen* screen, const Visual* visual);
+    static Visual* FindVisual(Screen* screen, gfxImageFormat format);
     static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format);
 
     // take ownership of a passed-in Pixmap, calling XFreePixmap on it
     // when the gfxXlibSurface is destroyed.
     void TakePixmap() {
         NS_ASSERTION(!mPixmapTaken, "I already own the Pixmap!");
         mPixmapTaken = PR_TRUE;
     }