Bug 1125848 - Reduce the likelyhood of a CompositorParent being destroyed without the proper shutdown sequence. r=sotaro a=lmandel
authorNicolas Silva <nsilva@mozilla.com>
Thu, 12 Mar 2015 20:47:19 +0100
changeset 250447 45897d27ef82
parent 250446 d76c709556bb
child 250448 17adc07baf56
push id4590
push usernsilva@mozilla.com
push date2015-03-19 10:58 +0000
treeherdermozilla-beta@45897d27ef82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro, lmandel
bugs1125848
milestone37.0
Bug 1125848 - Reduce the likelyhood of a CompositorParent being destroyed without the proper shutdown sequence. r=sotaro a=lmandel
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
widget/nsIWidget.h
widget/windows/nsWindow.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -991,16 +991,19 @@ nsBaseWidget::GetCompositorVsyncDispatch
 void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
 {
   // This makes sure that gfxPlatforms gets initialized if it hasn't by now.
   gfxPlatform::GetPlatform();
 
   MOZ_ASSERT(gfxPlatform::UsesOffMainThreadCompositing(),
              "This function assumes OMTC");
 
+  MOZ_ASSERT(!mCompositorParent,
+    "Should have properly cleaned up the previous CompositorParent beforehand");
+
   // Recreating this is tricky, as we may still have an old and we need
   // to make sure it's properly destroyed by calling DestroyCompositor!
 
   // If we've already received a shutdown notification, don't try
   // create a new compositor.
   if (!mShutdownObserver) {
     return;
   }
@@ -1303,38 +1306,16 @@ nsBaseWidget::SetWindowTitlebarColor(nsc
 }
 
 bool
 nsBaseWidget::ShowsResizeIndicator(nsIntRect* aResizerRect)
 {
   return false;
 }
 
-NS_IMETHODIMP
-nsBaseWidget::SetLayersAcceleration(bool aEnabled)
-{
-  if (mUseLayersAcceleration == aEnabled) {
-    return NS_OK;
-  }
-
-  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 = nullptr;
-  return NS_OK;
-}
-
 NS_METHOD nsBaseWidget::RegisterTouchWindow()
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_METHOD nsBaseWidget::UnregisterTouchWindow()
 {
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -203,17 +203,16 @@ public:
   NS_IMETHOD              SetPluginFocused(bool& aFocused) MOZ_OVERRIDE
                           { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD_(bool)       ExecuteNativeKeyBinding(
                             NativeKeyBindingsType aType,
                             const mozilla::WidgetKeyboardEvent& aEvent,
                             DoCommandCallback aCallback,
                             void* aCallbackData) MOZ_OVERRIDE { return false; }
-  NS_IMETHOD              SetLayersAcceleration(bool aEnabled) MOZ_OVERRIDE;
   virtual bool            ComputeShouldAccelerate(bool aDefault);
   NS_IMETHOD              GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
   virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE { return nsIMEUpdatePreference(); }
   NS_IMETHOD              OnDefaultButtonLoaded(const nsIntRect &aButtonRect) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
                                                          double aOriginalDeltaY,
                                                          double& aOverriddenDeltaX,
                                                          double& aOverriddenDeltaY) MOZ_OVERRIDE;
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1993,21 +1993,16 @@ public:
       NativeKeyBindingsForRichTextEditor
     };
     NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
                         NativeKeyBindingsType aType,
                         const mozilla::WidgetKeyboardEvent& aEvent,
                         DoCommandCallback aCallback,
                         void* aCallbackData) = 0;
 
-    /**
-     * Set layers acceleration to 'True' or 'False'
-     */
-    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
      * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -687,16 +687,17 @@ NS_METHOD nsWindow::Destroy()
   /**
    * On windows the LayerManagerOGL destructor wants the widget to be around for
    * cleanup. It also would like to have the HWND intact, so we nullptr it here.
    */
   if (mLayerManager) {
     mLayerManager->Destroy();
   }
   mLayerManager = nullptr;
+  DestroyCompositor();
 
   /* We should clear our cached resources now and not wait for the GC to
    * delete the nsWindow. */
   ClearCachedResources();
 
   // The DestroyWindow function destroys the specified window. The function sends WM_DESTROY
   // and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus
   // from it. The function also destroys the window's menu, flushes the thread message queue,
@@ -3353,16 +3354,20 @@ nsWindow::GetLayerManager(PLayerTransact
     gfxWindowsPlatform::GetPlatform()->UpdateRenderMode();
 
     // 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 we don't have a layer manager at this point we shouldn't have a
+  // PCompositor actor pair either.
+  MOZ_ASSERT(mLayerManager || (!mCompositorParent && !mCompositorChild));
+
   if (!mLayerManager ||
       (!sAllowD3D9 && aPersistence == LAYER_MANAGER_PERSISTENT &&
         mLayerManager->GetBackendType() == LayersBackend::LAYERS_BASIC &&
         !ShouldUseOffMainThreadCompositing())) {
     // If D3D9 is not currently allowed but the permanent manager is required,
     // -and- we're currently using basic layers, run through this check.
     LayerManagerPrefs prefs;
     GetLayerManagerPrefs(&prefs);
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1386,20 +1386,16 @@ void nsXULWindow::SyncAttributesToWidget
 
   // "chromemargin" attribute
   nsIntMargin margins;
   windowElement->GetAttribute(NS_LITERAL_STRING("chromemargin"), attr);
   if (nsContentUtils::ParseIntMarginValue(attr, margins)) {
     mWindow->SetNonClientMargins(margins);
   }
 
-  // "accelerated" attribute
-  bool isAccelerated = windowElement->HasAttribute(NS_LITERAL_STRING("accelerated"));
-  mWindow->SetLayersAcceleration(isAccelerated);
-
   // "windowtype" attribute
   windowElement->GetAttribute(WINDOWTYPE_ATTRIBUTE, attr);
   if (!attr.IsEmpty()) {
     mWindow->SetWindowClass(attr);
   }
 
   // "id" attribute for icon
   windowElement->GetAttribute(NS_LITERAL_STRING("id"), attr);