From 51dd83878aa9d3aabd49ddd7c4eb8688028c616b Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 15 Nov 2012 19:55:15 +0100 Subject: [PATCH] Bug 806428 - Fix crash in omtc-linux caused by nsBaseWidget::SetLayersAcceleration, and rename xxxAcceleratedRendering into xxxLayersAcceleration for concistency. r=BenWa --- widget/android/nsWindow.cpp | 4 ++-- widget/cocoa/nsChildView.h | 2 +- widget/cocoa/nsChildView.mm | 7 ++++--- widget/gonk/nsWindow.cpp | 8 ++++---- widget/nsIWidget.h | 4 ++-- widget/qt/nsWindow.cpp | 2 +- widget/windows/nsWindow.cpp | 6 +++--- widget/xpwidgets/nsBaseWidget.cpp | 33 +++++++++++++++++-------------- widget/xpwidgets/nsBaseWidget.h | 8 ++++---- xpfe/appshell/src/nsXULWindow.cpp | 2 +- 10 files changed, 40 insertions(+), 36 deletions(-) diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 27f5b128b0f8..5c06a9ed9254 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -688,7 +688,7 @@ nsWindow::GetLayerManager(PLayersChild*, LayersBackend, LayerManagerPersistence, return mLayerManager; } - mUseAcceleratedRendering = GetShouldAccelerate(); + mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration); bool useCompositor = UseOffMainThreadCompositing(); @@ -703,7 +703,7 @@ nsWindow::GetLayerManager(PLayersChild*, LayersBackend, LayerManagerPersistence, sFailedToCreateGLContext = true; } - if (!mUseAcceleratedRendering || + if (!mUseLayersAcceleration || sFailedToCreateGLContext) { printf_stderr(" -- creating basic, not accelerated\n"); diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index b969ff86e8d0..13b7a43d73fa 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -413,7 +413,7 @@ public: { 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); diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index e71802bb39fe..a37815baf199 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1312,14 +1312,14 @@ NS_IMETHODIMP nsChildView::Invalidate(const nsIntRect &aRect) } 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 @@ -1327,7 +1327,8 @@ 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) diff --git a/widget/gonk/nsWindow.cpp b/widget/gonk/nsWindow.cpp index 09bae7eeaf55..26887c444766 100644 --- a/widget/gonk/nsWindow.cpp +++ b/widget/gonk/nsWindow.cpp @@ -576,9 +576,9 @@ nsWindow::GetLayerManager(PLayersChild* aShadowManager, 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) { @@ -592,7 +592,7 @@ nsWindow::GetLayerManager(PLayersChild* aShadowManager, return mLayerManager; } - if (mUseAcceleratedRendering) { + if (mUseLayersAcceleration) { DebugOnly fbBounds = gScreenBounds; if (!sGLContext) { sGLContext = GLContextProvider::CreateForWindow(this); @@ -623,7 +623,7 @@ nsWindow::GetLayerManager(PLayersChild* aShadowManager, } mLayerManager = new BasicShadowLayerManager(this); - mUseAcceleratedRendering = false; + mUseLayersAcceleration = false; return mLayerManager; } diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index dd5f0188536c..7e649aa7bc6a 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -1497,9 +1497,9 @@ class nsIWidget : public nsISupports { 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. diff --git a/widget/qt/nsWindow.cpp b/widget/qt/nsWindow.cpp index ff7e3d188d34..882dd3252977 100644 --- a/widget/qt/nsWindow.cpp +++ b/widget/qt/nsWindow.cpp @@ -2667,7 +2667,7 @@ nsWindow::createQWidget(MozQWidget *parent, } #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(newView); diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 0fbec64b4db1..a05923f6f3a0 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -3259,11 +3259,11 @@ nsWindow::GetLayerManager(PLayersChild* aShadowManager, 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; + mUseLayersAcceleration = true; - if (mUseAcceleratedRendering) { + if (mUseLayersAcceleration) { if (aPersistence == LAYER_MANAGER_PERSISTENT && !sAllowD3D9) { MOZ_ASSERT(!mLayerManager || !mLayerManager->IsInTransaction()); diff --git a/widget/xpwidgets/nsBaseWidget.cpp b/widget/xpwidgets/nsBaseWidget.cpp index 3f5ade880336..653a8a1a5929 100644 --- a/widget/xpwidgets/nsBaseWidget.cpp +++ b/widget/xpwidgets/nsBaseWidget.cpp @@ -93,7 +93,7 @@ nsBaseWidget::nsBaseWidget() , mCursor(eCursor_standard) , mWindowType(eWindowType_child) , mBorderStyle(eBorderStyle_none) -, mUseAcceleratedRendering(false) +, mUseLayersAcceleration(false) , mForceLayersAcceleration(false) , mTemporarilyUseBasicLayerManager(false) , mUseAttachedEvents(false) @@ -770,7 +770,7 @@ nsBaseWidget::AutoUseBasicLayerManager::~AutoUseBasicLayerManager() } bool -nsBaseWidget::GetShouldAccelerate() +nsBaseWidget::ComputeShouldAccelerate(bool aDefault) { #if defined(XP_WIN) || defined(ANDROID) || (MOZ_PLATFORM_MAEMO > 5) || \ defined(MOZ_GL_PROVIDER) || defined(XP_MACOSX) @@ -835,7 +835,7 @@ nsBaseWidget::GetShouldAccelerate() return true; /* use the window acceleration flag */ - return mUseAcceleratedRendering; + return aDefault; } void nsBaseWidget::CreateCompositor() @@ -857,7 +857,7 @@ void nsBaseWidget::CreateCompositor() 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); @@ -896,7 +896,7 @@ LayerManager* nsBaseWidget::GetLayerManager(PLayersChild* aShadowManager, { if (!mLayerManager) { - mUseAcceleratedRendering = GetShouldAccelerate(); + mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration); // Try to use an async compositor first, if possible if (UseOffMainThreadCompositing()) { @@ -906,7 +906,7 @@ LayerManager* nsBaseWidget::GetLayerManager(PLayersChild* aShadowManager, CreateCompositor(); } - if (mUseAcceleratedRendering) { + if (mUseLayersAcceleration) { if (!mLayerManager) { nsRefPtr layerManager = new LayerManagerOGL(this); /** @@ -1146,12 +1146,21 @@ nsBaseWidget::ShowsResizeIndicator(nsIntRect* aResizerRect) } 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(); } @@ -1159,12 +1168,6 @@ nsBaseWidget::SetAcceleratedRendering(bool aEnabled) return NS_OK; } -bool -nsBaseWidget::GetAcceleratedRendering() -{ - return mUseAcceleratedRendering; -} - NS_METHOD nsBaseWidget::RegisterTouchWindow() { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/widget/xpwidgets/nsBaseWidget.h b/widget/xpwidgets/nsBaseWidget.h index 7df953230d56..d41a7ab92101 100644 --- a/widget/xpwidgets/nsBaseWidget.h +++ b/widget/xpwidgets/nsBaseWidget.h @@ -139,9 +139,9 @@ public: 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; } @@ -338,7 +338,7 @@ protected: nsCursor mCursor; nsWindowType mWindowType; nsBorderStyle mBorderStyle; - bool mUseAcceleratedRendering; + bool mUseLayersAcceleration; bool mForceLayersAcceleration; bool mTemporarilyUseBasicLayerManager; bool mUseAttachedEvents; diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index ac79f48a3a61..276d02dbdb6c 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -1395,7 +1395,7 @@ void nsXULWindow::SyncAttributesToWidget() bool isAccelerated; rv = windowElement->HasAttribute(NS_LITERAL_STRING("accelerated"), &isAccelerated); if (NS_SUCCEEDED(rv)) { - mWindow->SetAcceleratedRendering(isAccelerated); + mWindow->SetLayersAcceleration(isAccelerated); } // "windowtype" attribute