b=682625 pass VisualID when PictFormat is not available r=cjones
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 10 Jan 2012 23:54:38 +1300
changeset 85455 6571d631dd40922a6ba6b25dcd0ddb8460894ebd
parent 85454 98768291cee95712410e1ca285693f8aaa32c253
child 85456 9a6371bdb362e27f7afb54f23e494e8eaa1c00a6
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs682625
milestone12.0a1
b=682625 pass VisualID when PictFormat is not available r=cjones
gfx/layers/ipc/ShadowLayerUtilsX11.cpp
gfx/layers/ipc/ShadowLayerUtilsX11.h
--- a/gfx/layers/ipc/ShadowLayerUtilsX11.cpp
+++ b/gfx/layers/ipc/ShadowLayerUtilsX11.cpp
@@ -40,16 +40,17 @@
 
 #include "mozilla/layers/PLayers.h"
 #include "mozilla/layers/ShadowLayers.h"
  
 #include "gfxPlatform.h"
 
 #include "gfxXlibSurface.h"
 #include "mozilla/X11Util.h"
+#include "cairo-xlib.h"
 
 namespace mozilla {
 namespace layers {
 
 // Return true if we're likely compositing using X and so should use
 // Xlib surfaces in shadow layers.
 static bool
 UsingXCompositing()
@@ -77,34 +78,51 @@ TakeAndDestroyXlibSurface(SurfaceDescrip
   *aSurface = SurfaceDescriptor();
   // the Pixmap is destroyed when |surf| goes out of scope
   return true;
 }
 
 SurfaceDescriptorX11::SurfaceDescriptorX11(gfxXlibSurface* aSurf)
   : mId(aSurf->XDrawable())
   , mSize(aSurf->GetSize())
-  , mFormat(aSurf->XRenderFormat()->id)
-{ }
+{
+  const XRenderPictFormat *pictFormat = aSurf->XRenderFormat();
+  if (pictFormat) {
+    mFormat = pictFormat->id;
+  } else {
+    mFormat = cairo_xlib_surface_get_visual(aSurf->CairoSurface())->visualid;
+  }
+}
 
-SurfaceDescriptorX11::SurfaceDescriptorX11(const int aXid, const int aXrenderPictID, const gfxIntSize& aSize)
-  : mId(aXid)
+SurfaceDescriptorX11::SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID,
+                                           const gfxIntSize& aSize)
+  : mId(aDrawable)
+  , mFormat(aFormatID)
   , mSize(aSize)
-  , mFormat(aXrenderPictID)
 { }
 
 already_AddRefed<gfxXlibSurface>
 SurfaceDescriptorX11::OpenForeign() const
 {
   Display* display = DefaultXDisplay();
   Screen* screen = DefaultScreenOfDisplay(display);
 
-  XRenderPictFormat* format = GetXRenderPictFormatFromId(display, mFormat);
-  nsRefPtr<gfxXlibSurface> surf =
-    new gfxXlibSurface(screen, mId, format, mSize);
+  nsRefPtr<gfxXlibSurface> surf;
+  XRenderPictFormat* pictFormat = GetXRenderPictFormatFromId(display, mFormat);
+  if (pictFormat) {
+    surf = new gfxXlibSurface(screen, mId, pictFormat, mSize);
+  } else {
+    Visual* visual = NULL;
+    unsigned int depth;
+    XVisualIDToInfo(display, mFormat, &visual, &depth);
+    if (!visual)
+      return nsnull;
+
+    surf = new gfxXlibSurface(display, mId, visual, mSize);
+  }
   return surf->CairoStatus() ? nsnull : surf.forget();
 }
 
 bool
 ShadowLayerForwarder::PlatformAllocDoubleBuffer(const gfxIntSize& aSize,
                                                 gfxASurface::gfxContentType aContent,
                                                 SurfaceDescriptor* aFrontBuffer,
                                                 SurfaceDescriptor* aBackBuffer)
--- a/gfx/layers/ipc/ShadowLayerUtilsX11.h
+++ b/gfx/layers/ipc/ShadowLayerUtilsX11.h
@@ -55,34 +55,35 @@ namespace mozilla {
 namespace layers {
 
 struct SurfaceDescriptorX11 {
   SurfaceDescriptorX11()
   { }
 
   SurfaceDescriptorX11(gfxXlibSurface* aSurf);
 
-  SurfaceDescriptorX11(const int aXid, const int aXrenderPictID, const gfxIntSize& aSize);
+  SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID,
+                       const gfxIntSize& aSize);
 
   // Default copy ctor and operator= are OK
 
   bool operator==(const SurfaceDescriptorX11& aOther) const {
     // Define == as two descriptors having the same XID for now,
     // ignoring size and render format.  If the two indeed refer to
     // the same valid XID, then size/format are "actually" the same
     // anyway, regardless of the values of the fields in
     // SurfaceDescriptorX11.
     return mId == aOther.mId;
   }
 
   already_AddRefed<gfxXlibSurface> OpenForeign() const;
 
   Drawable mId;
+  XID mFormat; // either a PictFormat or VisualID
   gfxIntSize mSize;
-  PictFormat mFormat;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 namespace IPC {
 
 template <>