Bug 885580 - Make sure that Compositor::GetBackend is only used [Cfrom the compositor thread. r=nical
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 27 Jun 2013 11:30:52 +1200
changeset 139205 dabdd7ceb43eb52cae4aef7a030d65e7b48959e5
parent 139204 3e969b1777a7db826491fdb887693909c77e3898
child 139206 40f9e902464aedf57948308b9aa286b33cbf5af7
push idunknown
push userunknown
push dateunknown
reviewersnical
bugs885580
milestone25.0a1
Bug 885580 - Make sure that Compositor::GetBackend is only used [Cfrom the compositor thread. r=nical
gfx/layers/Compositor.cpp
gfx/layers/Compositor.h
gfx/layers/client/ClientLayerManager.cpp
widget/cocoa/nsChildView.mm
widget/gtk2/nsWindow.cpp
--- a/gfx/layers/Compositor.cpp
+++ b/gfx/layers/Compositor.cpp
@@ -1,23 +1,27 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/Compositor.h"
 #include "mozilla/layers/Effects.h"
+#include "mozilla/layers/CompositorParent.h"
 
 namespace mozilla {
 namespace layers {
 
 /* static */ LayersBackend Compositor::sBackend = LAYERS_NONE;
 /* static */ LayersBackend
 Compositor::GetBackend()
 {
+  MOZ_ASSERT(CompositorParent::CompositorLoop() ==
+             MessageLoop::current(),
+             "Can only call this from the compositor thread!");
   return sBackend;
 }
 
 void
 Compositor::DrawDiagnostics(const gfx::Color& aColor,
                             const gfx::Rect& rect,
                             const gfx::Rect& aClipRect,
                             const gfx::Matrix4x4& aTransform,
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -386,16 +386,18 @@ public:
   virtual nsIWidget* GetWidget() const { return nullptr; }
   virtual const nsIntSize& GetWidgetSize() = 0;
 
   /**
    * We enforce that there can only be one Compositor backend type off the main
    * thread at the same time. The backend type in use can be checked with this
    * static method. We need this for creating texture clients/hosts etc. when we
    * don't have a reference to a Compositor.
+   *
+   * This can only be used from the compositor thread!
    */
   static LayersBackend GetBackend();
 
 protected:
   uint32_t mCompositorID;
   static LayersBackend sBackend;
   bool mDrawColoredBorders;
 };
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -388,17 +388,17 @@ ClientLayerManager::ClearLayer(Layer* aL
        child = child->GetNextSibling()) {
     ClearLayer(child);
   }
 }
 
 void
 ClientLayerManager::GetBackendName(nsAString& aName)
 {
-  switch (Compositor::GetBackend()) {
+  switch (GetCompositorBackendType()) {
     case LAYERS_BASIC: aName.AssignLiteral("Basic"); return;
     case LAYERS_OPENGL: aName.AssignLiteral("OpenGL"); return;
     case LAYERS_D3D9: aName.AssignLiteral("Direct3D 9"); return;
     case LAYERS_D3D10: aName.AssignLiteral("Direct3D 10"); return;
     case LAYERS_D3D11: aName.AssignLiteral("Direct3D 11"); return;
     default: NS_RUNTIMEABORT("Invalid backend");
   }
 }
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1945,18 +1945,18 @@ void
 nsChildView::CreateCompositor()
 {
   nsBaseWidget::CreateCompositor();
   if (mCompositorChild) {
     LayerManagerComposite *manager =
       compositor::GetLayerManager(mCompositorParent);
     Compositor *compositor = manager->GetCompositor();
 
-    LayersBackend backend = compositor->GetBackend();
-    if (backend == LAYERS_OPENGL) {
+    ClientLayerManager *clientManager = static_cast<ClientLayerManager*>(GetLayerManager());
+    if (clientManager->GetCompositorBackendType() == LAYERS_OPENGL) {
       CompositorOGL *compositorOGL = static_cast<CompositorOGL*>(compositor);
 
       NSOpenGLContext *glContext = (NSOpenGLContext *)compositorOGL->gl()->GetNativeData(GLContext::NativeGLContext);
 
       [(ChildView *)mView setGLContext:glContext];
     }
     [(ChildView *)mView setUsingOMTCompositor:true];
   }
--- a/widget/gtk2/nsWindow.cpp
+++ b/widget/gtk2/nsWindow.cpp
@@ -2119,23 +2119,22 @@ nsWindow::OnExposeEvent(cairo_t *cr)
 #if defined(MOZ_WIDGET_GTK2)
         g_free(rects);
 #else
         cairo_rectangle_list_destroy(rects);
 #endif
         return TRUE;
     }
     // If this widget uses OMTC...
-    if (GetLayerManager()->AsShadowForwarder() && GetLayerManager()->AsShadowForwarder()->HasShadowManager() &&
-        Compositor::GetBackend() != LAYERS_BASIC) {
+    if (GetLayerManager()->GetBackendType() == LAYERS_CLIENT) {
+        listener->PaintWindow(this, region);
         listener->DidPaintWindow();
 
         g_free(rects);
         return TRUE;
-
     } else if (GetLayerManager()->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
         LayerManagerOGL *manager = static_cast<LayerManagerOGL*>(GetLayerManager());
         manager->SetClippingRegion(region);
 
         listener->PaintWindow(this, region);
         listener->DidPaintWindow();
 
         g_free(rects);
@@ -2195,20 +2194,16 @@ nsWindow::OnExposeEvent(cairo_t *cr)
 
 #endif // MOZ_X11
 
     bool painted = false;
     {
       if (GetLayerManager()->GetBackendType() == LAYERS_BASIC) {
         AutoLayerManagerSetup setupLayerManager(this, ctx, layerBuffering);
         painted = listener->PaintWindow(this, region);
-      } else if (GetLayerManager()->GetBackendType() == LAYERS_CLIENT) {
-        ClientLayerManager *manager = static_cast<ClientLayerManager*>(GetLayerManager());
-        manager->SetShadowTarget(ctx);
-        painted = listener->PaintWindow(this, region);
       }
     }
 
 #ifdef MOZ_X11
     // PaintWindow can Destroy us (bug 378273), avoid doing any paint
     // operations below if that happened - it will lead to XError and exit().
     if (shaped) {
         if (MOZ_LIKELY(!mIsDestroyed)) {