From c2804730fc572fd005979d707753d4c5d47298cf Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Mon, 24 May 2010 17:28:54 +0200 Subject: [PATCH] Bug 546515: Part 2: Use D3D9 layers backend as the preferred hardware backend for Windows. r=roc --- modules/libpref/src/init/all.js | 6 +++++ widget/src/windows/nsWindow.cpp | 40 ++++++++++++++++++++++++++++++ widget/src/windows/nsWindowGfx.cpp | 10 ++++++++ 3 files changed, 56 insertions(+) diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 3f37975bc25..287810a1a04 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -2813,6 +2813,12 @@ pref("mozilla.widget.render-mode", -1); // Initialize default accelerated layers pref("mozilla.widget.accelerated-layers", true); +#ifdef XP_WIN +#ifndef WINCE +pref("mozilla.layers.prefer-opengl", false); +#endif +#endif + // Enable/Disable the geolocation API for content pref("geo.enabled", true); diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 9e54fed0b05..a4cad516bb4 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -125,6 +125,7 @@ #include "nsIDOMNSUIEvent.h" #include "nsITheme.h" #include "nsIPrefBranch.h" +#include "nsIPrefBranch2.h" #include "nsIPrefService.h" #include "nsIObserverService.h" #include "nsIScreenManager.h" @@ -167,6 +168,10 @@ #include "nsWindowGfx.h" #include "gfxWindowsPlatform.h" #include "Layers.h" +#ifndef WINCE +#include "LayerManagerD3D9.h" +#include "LayerManagerOGL.h" +#endif #if !defined(WINCE) #include "nsUXThemeConstants.h" @@ -2917,6 +2922,41 @@ nsWindow::GetLayerManager() mLayerManager = NULL; mUseAcceleratedRendering = topWindow->GetAcceleratedRendering(); } + +#ifndef WINCE + if (!mLayerManager) { + if (mUseAcceleratedRendering) { + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + + PRBool allowAcceleration = PR_TRUE; + PRBool preferOpenGL = PR_FALSE; + if (prefs) { + prefs->GetBoolPref("mozilla.widget.accelerated-layers", + &allowAcceleration); + prefs->GetBoolPref("mozilla.layers.prefer-opengl", + &preferOpenGL); + } + + if (allowAcceleration) { + if (preferOpenGL) { + nsRefPtr layerManager = + new mozilla::layers::LayerManagerOGL(this); + if (layerManager->Initialize()) { + mLayerManager = layerManager; + } + } + if (!mLayerManager) { + nsRefPtr layerManager = + new mozilla::layers::LayerManagerD3D9(this); + if (layerManager->Initialize()) { + mLayerManager = layerManager; + } + } + } + } + } +#endif + return nsBaseWidget::GetLayerManager(); } diff --git a/widget/src/windows/nsWindowGfx.cpp b/widget/src/windows/nsWindowGfx.cpp index c86153a9a69..c5130ac618d 100644 --- a/widget/src/windows/nsWindowGfx.cpp +++ b/widget/src/windows/nsWindowGfx.cpp @@ -71,6 +71,9 @@ using mozilla::plugins::PluginInstanceParent; #include "prmem.h" #include "LayerManagerOGL.h" +#ifndef WINCE +#include "LayerManagerD3D9.h" +#endif #ifndef WINCE #include "nsUXThemeData.h" @@ -677,6 +680,13 @@ DDRAW_FAILED: SetClippingRegion(event.region); result = DispatchWindowEvent(&event, eventStatus); break; +#ifndef WINCE + case LayerManager::LAYERS_D3D9: + static_cast(GetLayerManager())-> + SetClippingRegion(event.region); + result = DispatchWindowEvent(&event, eventStatus); + break; +#endif default: NS_ERROR("Unknown layers backend used!"); break;