Bug 806428 - Fix crash in omtc-linux caused by nsBaseWidget::SetLayersAcceleration, and rename xxxAcceleratedRendering into xxxLayersAcceleration for concistency. r=BenWa
authorNicolas Silva <nical.bugzilla@gmail.com>
Thu, 15 Nov 2012 19:55:15 +0100
changeset 121569 940e9616ec59e34ab334440d753517aa2c1b6e22
parent 121568 131a7ee2362c4ae530cab9effc6143c9cfca4b00
child 121570 571ae303c8dc7bb364dfc481b319752a22cd6a5f
push idunknown
push userunknown
push dateunknown
reviewersBenWa
bugs806428
milestone19.0a1
Bug 806428 - Fix crash in omtc-linux caused by nsBaseWidget::SetLayersAcceleration, and rename xxxAcceleratedRendering into xxxLayersAcceleration for concistency. r=BenWa
widget/android/nsWindow.cpp
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/gonk/nsWindow.cpp
widget/nsIWidget.h
widget/qt/nsWindow.cpp
widget/windows/nsWindow.cpp
widget/xpwidgets/nsBaseWidget.cpp
widget/xpwidgets/nsBaseWidget.h
xpfe/appshell/src/nsXULWindow.cpp
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -683,32 +683,32 @@ nsWindow::GetLayerManager(PLayersChild*,
     nsWindow *topWindow = TopWindow();
 
     if (!topWindow) {
         printf_stderr(" -- no topwindow\n");
         mLayerManager = CreateBasicLayerManager();
         return mLayerManager;
     }
 
-    mUseAcceleratedRendering = GetShouldAccelerate();
+    mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
 
     bool useCompositor = UseOffMainThreadCompositing();
 
     if (useCompositor) {
         CreateCompositor();
         if (mLayerManager) {
             SetCompositor(mCompositorParent, mCompositorChild);
             return mLayerManager;
         }
 
         // If we get here, then off main thread compositing failed to initialize.
         sFailedToCreateGLContext = true;
     }
 
-    if (!mUseAcceleratedRendering ||
+    if (!mUseLayersAcceleration ||
         sFailedToCreateGLContext)
     {
         printf_stderr(" -- creating basic, not accelerated\n");
         mLayerManager = CreateBasicLayerManager();
         return mLayerManager;
     }
 
     if (!mLayerManager) {
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -408,17 +408,17 @@ public:
   virtual nsresult        ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
   virtual nsIntPoint      WidgetToScreenOffset();
   virtual bool            ShowsResizeIndicator(nsIntRect* aResizerRect);
 
   static  bool            ConvertStatus(nsEventStatus aStatus)
                           { return aStatus == nsEventStatus_eConsumeNoDefault; }
   NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
 
-  virtual bool            GetShouldAccelerate();
+  virtual bool            ComputeShouldAccelerate(bool aDefault);
   virtual bool            UseOffMainThreadCompositing();
 
   NS_IMETHOD        SetCursor(nsCursor aCursor);
   NS_IMETHOD        SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY);
 
   NS_IMETHOD        CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture);
   NS_IMETHOD        SetTitle(const nsAString& title);
 
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1307,32 +1307,33 @@ NS_IMETHODIMP nsChildView::Invalidate(co
   }
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 bool
-nsChildView::GetShouldAccelerate()
+nsChildView::ComputeShouldAccelerate(bool aDefault)
 {
   // Don't use OpenGL for transparent windows or for popup windows.
   if (!mView || ![[mView window] isOpaque] ||
       [[mView window] isKindOfClass:[PopupWindow class]])
     return false;
 
-  return nsBaseWidget::GetShouldAccelerate();
+  return nsBaseWidget::ComputeShouldAccelerate(aDefault);
 }
 
 bool
 nsChildView::UseOffMainThreadCompositing()
 {
   // OMTC doesn't work with Basic Layers on OS X right now. Once it works, we'll
   // still want to disable it for certain kinds of windows (e.g. popups).
-  return nsBaseWidget::UseOffMainThreadCompositing() && GetShouldAccelerate();
+  return nsBaseWidget::UseOffMainThreadCompositing() &&
+         ComputeShouldAccelerate(mUseLayersAcceleration);
 }
 
 inline uint16_t COLOR8TOCOLOR16(uint8_t color8)
 {
   // return (color8 == 0xFF ? 0xFFFF : (color8 << 8));
   return (color8 << 8) | color8;  /* (color8 * 257) == (color8 * 0x0101) */
 }
 
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -571,33 +571,33 @@ nsWindow::GetLayerManager(PLayersChild* 
             BasicLayerManager* manager =
                 static_cast<BasicLayerManager*>(mLayerManager.get());
             manager->SetDefaultTargetConfiguration(mozilla::layers::BUFFER_NONE, 
                                                    ScreenRotation(EffectiveScreenRotation()));
         }
         return mLayerManager;
     }
 
-    // Set mUseAcceleratedRendering here to make it consistent with
+    // Set mUseLayersAcceleration here to make it consistent with
     // nsBaseWidget::GetLayerManager
-    mUseAcceleratedRendering = GetShouldAccelerate();
+    mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
     nsWindow *topWindow = sTopWindows[0];
 
     if (!topWindow) {
         LOGW(" -- no topwindow\n");
         return nullptr;
     }
 
     if (sUsingOMTC) {
         CreateCompositor();
         if (mLayerManager)
             return mLayerManager;
     }
 
-    if (mUseAcceleratedRendering) {
+    if (mUseLayersAcceleration) {
         DebugOnly<nsIntRect> fbBounds = gScreenBounds;
         if (!sGLContext) {
             sGLContext = GLContextProvider::CreateForWindow(this);
         }
 
         MOZ_ASSERT(fbBounds.value == gScreenBounds);
         if (sGLContext) {
             nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
@@ -618,17 +618,17 @@ nsWindow::GetLayerManager(PLayersChild* 
     if (sFramebufferOpen) {
         LOG("Falling back to framebuffer software rendering");
     } else {
         LOGE("Failed to mmap fb(?!?), aborting ...");
         NS_RUNTIMEABORT("Can't open GL context and can't fall back on /dev/graphics/fb0 ...");
     }
 
     mLayerManager = new BasicShadowLayerManager(this);
-    mUseAcceleratedRendering = false;
+    mUseLayersAcceleration = false;
 
     return mLayerManager;
 }
 
 gfxASurface *
 nsWindow::GetThebesSurface()
 {
     /* This is really a dummy surface; this is only used when doing reflow, because
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1492,19 +1492,19 @@ class nsIWidget : public nsISupports {
                                       const InputContextAction& aAction) = 0;
 
     /*
      * Get current input context.
      */
     NS_IMETHOD_(InputContext) GetInputContext() = 0;
 
     /**
-     * Set accelerated rendering to 'True' or 'False'
+     * Set layers acceleration to 'True' or 'False'
      */
-    NS_IMETHOD SetAcceleratedRendering(bool aEnabled) = 0;
+    NS_IMETHOD SetLayersAcceleration(bool aEnabled) = 0;
 
     /*
      * Get toggled key states.
      * aKeyCode should be NS_VK_CAPS_LOCK or  NS_VK_NUM_LOCK or
      * NS_VK_SCROLL_LOCK.
      * aLEDState is the result for current LED state of the key.
      * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
      * If the platform doesn't support the LED state (or we cannot get the
--- a/widget/qt/nsWindow.cpp
+++ b/widget/qt/nsWindow.cpp
@@ -2662,17 +2662,17 @@ nsWindow::createQWidget(MozQWidget *pare
         QGraphicsView* newView =
             nsFastStartup::GetStartupGraphicsView(parentWidget, widget);
 
         if (mWindowType == eWindowType_dialog) {
             newView->setWindowModality(Qt::WindowModal);
         }
 
 #if defined(MOZ_PLATFORM_MAEMO) || defined(MOZ_GL_PROVIDER)
-        if (GetShouldAccelerate()) {
+        if (ComputeShouldAccelerate(mUseLayersAcceleration)) {
             // Only create new OGL widget if it is not yet installed
             if (!HasGLContext()) {
                 MozQGraphicsView *qview = qobject_cast<MozQGraphicsView*>(newView);
                 if (qview) {
                     qview->setGLWidgetEnabled(true);
                 }
             }
         }
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3254,21 +3254,21 @@ nsWindow::GetLayerManager(PLayersChild* 
 
     /* We don't currently support using an accelerated layer manager with
      * transparent windows so don't even try. I'm also not sure if we even
      * want to support this case. See bug #593471 */
     if (eTransparencyTransparent == mTransparencyMode ||
         prefs.mDisableAcceleration ||
         windowRect.right - windowRect.left > MAX_ACCELERATED_DIMENSION ||
         windowRect.bottom - windowRect.top > MAX_ACCELERATED_DIMENSION)
-      mUseAcceleratedRendering = false;
+      mUseLayersAcceleration = false;
     else if (prefs.mAccelerateByDefault)
-      mUseAcceleratedRendering = true;
-
-    if (mUseAcceleratedRendering) {
+      mUseLayersAcceleration = true;
+
+    if (mUseLayersAcceleration) {
       if (aPersistence == LAYER_MANAGER_PERSISTENT && !sAllowD3D9) {
         MOZ_ASSERT(!mLayerManager || !mLayerManager->IsInTransaction());
 
         // This will clear out our existing layer manager if we have one since
         // if we hit this with a LayerManager we're always using BasicLayers.
         nsToolkit::StartAllowingD3D9();
       }
 
--- a/widget/xpwidgets/nsBaseWidget.cpp
+++ b/widget/xpwidgets/nsBaseWidget.cpp
@@ -88,17 +88,17 @@ nsAutoRollup::~nsAutoRollup()
 
 nsBaseWidget::nsBaseWidget()
 : mWidgetListener(nullptr)
 , mAttachedWidgetListener(nullptr)
 , mContext(nullptr)
 , mCursor(eCursor_standard)
 , mWindowType(eWindowType_child)
 , mBorderStyle(eBorderStyle_none)
-, mUseAcceleratedRendering(false)
+, mUseLayersAcceleration(false)
 , mForceLayersAcceleration(false)
 , mTemporarilyUseBasicLayerManager(false)
 , mUseAttachedEvents(false)
 , mContextInitialized(false)
 , mBounds(0,0,0,0)
 , mOriginalBounds(nullptr)
 , mClipRectCount(0)
 , mZIndex(0)
@@ -765,17 +765,17 @@ nsBaseWidget::AutoUseBasicLayerManager::
 }
 
 nsBaseWidget::AutoUseBasicLayerManager::~AutoUseBasicLayerManager()
 {
   mWidget->mTemporarilyUseBasicLayerManager = false;
 }
 
 bool
-nsBaseWidget::GetShouldAccelerate()
+nsBaseWidget::ComputeShouldAccelerate(bool aDefault)
 {
 #if defined(XP_WIN) || defined(ANDROID) || (MOZ_PLATFORM_MAEMO > 5) || \
     defined(MOZ_GL_PROVIDER) || defined(XP_MACOSX)
   bool accelerateByDefault = true;
 #else
   bool accelerateByDefault = false;
 #endif
 
@@ -830,17 +830,17 @@ nsBaseWidget::GetShouldAccelerate()
 #endif
     return false;
   }
 
   if (accelerateByDefault)
     return true;
 
   /* use the window acceleration flag */
-  return mUseAcceleratedRendering;
+  return aDefault;
 }
 
 void nsBaseWidget::CreateCompositor()
 {
   bool renderToEGLSurface = false;
 #ifdef MOZ_ANDROID_OMTC
   renderToEGLSurface = true;
 #endif
@@ -852,17 +852,17 @@ void nsBaseWidget::CreateCompositor()
   MessageLoop *childMessageLoop = CompositorParent::CompositorLoop();
   mCompositorChild = new CompositorChild(lm);
   AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
   AsyncChannel::Side childSide = mozilla::ipc::AsyncChannel::Child;
   mCompositorChild->Open(parentChannel, childMessageLoop, childSide);
   int32_t maxTextureSize;
   PLayersChild* shadowManager;
   mozilla::layers::LayersBackend backendHint =
-    mUseAcceleratedRendering ? mozilla::layers::LAYERS_OPENGL : mozilla::layers::LAYERS_BASIC;
+    mUseLayersAcceleration ? mozilla::layers::LAYERS_OPENGL : mozilla::layers::LAYERS_BASIC;
   mozilla::layers::LayersBackend parentBackend;
   shadowManager = mCompositorChild->SendPLayersConstructor(
     backendHint, 0, &parentBackend, &maxTextureSize);
 
   if (shadowManager) {
     ShadowLayerForwarder* lf = lm->AsShadowForwarder();
     if (!lf) {
       delete lm;
@@ -891,27 +891,27 @@ bool nsBaseWidget::UseOffMainThreadCompo
 
 LayerManager* nsBaseWidget::GetLayerManager(PLayersChild* aShadowManager,
                                             LayersBackend aBackendHint,
                                             LayerManagerPersistence aPersistence,
                                             bool* aAllowRetaining)
 {
   if (!mLayerManager) {
 
-    mUseAcceleratedRendering = GetShouldAccelerate();
+    mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
 
     // Try to use an async compositor first, if possible
     if (UseOffMainThreadCompositing()) {
       // e10s uses the parameter to pass in the shadow manager from the TabChild
       // so we don't expect to see it there since this doesn't support e10s.
       NS_ASSERTION(aShadowManager == nullptr, "Async Compositor not supported with e10s");
       CreateCompositor();
     }
 
-    if (mUseAcceleratedRendering) {
+    if (mUseLayersAcceleration) {
       if (!mLayerManager) {
         nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
         /**
          * XXX - On several OSes initialization is expected to fail for now.
          * If we'd get a non-basic layer manager they'd crash. This is ok though
          * since on those platforms it will fail. Anyone implementing new
          * platforms on LayerManagerOGL should ensure their widget is able to
          * deal with it though!
@@ -1141,35 +1141,38 @@ nsBaseWidget::SetWindowTitlebarColor(nsc
 
 bool
 nsBaseWidget::ShowsResizeIndicator(nsIntRect* aResizerRect)
 {
   return false;
 }
 
 NS_IMETHODIMP
-nsBaseWidget::SetAcceleratedRendering(bool aEnabled)
+nsBaseWidget::SetLayersAcceleration(bool aEnabled)
 {
-  if (mUseAcceleratedRendering == aEnabled) {
+  if (mUseLayersAcceleration == aEnabled) {
     return NS_OK;
   }
-  mUseAcceleratedRendering = aEnabled;
+
+  bool usedAcceleration = mUseLayersAcceleration;
+
+  mUseLayersAcceleration = ComputeShouldAccelerate(aEnabled);
+  // ComputeShouldAccelerate may have set mUseLayersAcceleration to a value
+  // different from aEnabled.
+  if (usedAcceleration == mUseLayersAcceleration) {
+    return NS_OK;
+  }
+
   if (mLayerManager) {
     mLayerManager->Destroy();
   }
   mLayerManager = NULL;
   return NS_OK;
 }
 
-bool
-nsBaseWidget::GetAcceleratedRendering()
-{
-  return mUseAcceleratedRendering;
-}
-
 NS_METHOD nsBaseWidget::RegisterTouchWindow()
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_METHOD nsBaseWidget::UnregisterTouchWindow()
 {
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/widget/xpwidgets/nsBaseWidget.h
+++ b/widget/xpwidgets/nsBaseWidget.h
@@ -134,19 +134,19 @@ public:
   virtual bool            ShowsResizeIndicator(nsIntRect* aResizerRect);
   virtual void            FreeNativeData(void * data, uint32_t aDataType) {}
   NS_IMETHOD              BeginResizeDrag(nsGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical);
   NS_IMETHOD              BeginMoveDrag(nsMouseEvent* aEvent);
   virtual nsresult        ActivateNativeMenuItemAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
   virtual nsresult        ForceUpdateNativeMenuAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              ResetInputState() { return NS_OK; }
   NS_IMETHOD              CancelIMEComposition() { return NS_OK; }
-  NS_IMETHOD              SetAcceleratedRendering(bool aEnabled);
-  virtual bool            GetAcceleratedRendering();
-  virtual bool            GetShouldAccelerate();
+  NS_IMETHOD              SetLayersAcceleration(bool aEnabled);
+  virtual bool            GetLayersAcceleration() { return mUseLayersAcceleration; }
+  virtual bool            ComputeShouldAccelerate(bool aDefault);
   NS_IMETHOD              GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              OnIMEFocusChange(bool aFocus) { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              OnIMETextChange(uint32_t aStart, uint32_t aOldEnd, uint32_t aNewEnd) { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              OnIMESelectionChange(void) { return NS_ERROR_NOT_IMPLEMENTED; }
   virtual nsIMEUpdatePreference GetIMEUpdatePreference() { return nsIMEUpdatePreference(false, false); }
   NS_IMETHOD              OnDefaultButtonLoaded(const nsIntRect &aButtonRect) { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta, bool aIsHorizontal, int32_t &aOverriddenDelta);
   virtual already_AddRefed<nsIWidget>
@@ -333,17 +333,17 @@ protected:
   nsRefPtr<LayerManager> mBasicLayerManager;
   nsRefPtr<CompositorChild> mCompositorChild;
   nsRefPtr<CompositorParent> mCompositorParent;
   nscolor           mBackground;
   nscolor           mForeground;
   nsCursor          mCursor;
   nsWindowType      mWindowType;
   nsBorderStyle     mBorderStyle;
-  bool              mUseAcceleratedRendering;
+  bool              mUseLayersAcceleration;
   bool              mForceLayersAcceleration;
   bool              mTemporarilyUseBasicLayerManager;
   bool              mUseAttachedEvents;
   bool              mContextInitialized;
   nsIntRect         mBounds;
   nsIntRect*        mOriginalBounds;
   // When this pointer is null, the widget is not clipped
   nsAutoArrayPtr<nsIntRect> mClipRects;
--- a/xpfe/appshell/src/nsXULWindow.cpp
+++ b/xpfe/appshell/src/nsXULWindow.cpp
@@ -1390,17 +1390,17 @@ void nsXULWindow::SyncAttributesToWidget
   if (NS_SUCCEEDED(rv) && nsContentUtils::ParseIntMarginValue(attr, margins)) {
     mWindow->SetNonClientMargins(margins);
   }
 
   // "accelerated" attribute
   bool isAccelerated;
   rv = windowElement->HasAttribute(NS_LITERAL_STRING("accelerated"), &isAccelerated);
   if (NS_SUCCEEDED(rv)) {
-    mWindow->SetAcceleratedRendering(isAccelerated);
+    mWindow->SetLayersAcceleration(isAccelerated);
   }
 
   // "windowtype" attribute
   rv = windowElement->GetAttribute(WINDOWTYPE_ATTRIBUTE, attr);
   if (NS_SUCCEEDED(rv) && !attr.IsEmpty()) {
     mWindow->SetWindowClass(attr);
   }