Bug 617860: Don't throw out basic layer managers if we're just going to recreate them anyway. r=Bas a=b

This commit is contained in:
Chris Jones 2011-01-12 14:13:41 -06:00
parent c326a0a9fc
commit 976e710402

View File

@ -3271,6 +3271,45 @@ nsWindow::HasPendingInputEvent()
*
**************************************************************/
struct LayerManagerPrefs {
LayerManagerPrefs()
: mAccelerateByDefault(PR_TRUE)
, mDisableAcceleration(PR_FALSE)
, mPreferOpenGL(PR_FALSE)
, mPreferD3D9(PR_FALSE)
{}
PRBool mAccelerateByDefault;
PRBool mDisableAcceleration;
PRBool mPreferOpenGL;
PRBool mPreferD3D9;
};
static void
GetLayerManagerPrefs(LayerManagerPrefs* aManagerPrefs)
{
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->GetBoolPref("layers.acceleration.disabled",
&aManagerPrefs->mDisableAcceleration);
prefs->GetBoolPref("layers.prefer-opengl",
&aManagerPrefs->mPreferOpenGL);
prefs->GetBoolPref("layers.prefer-d3d9",
&aManagerPrefs->mPreferD3D9);
}
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
aManagerPrefs->mAccelerateByDefault =
aManagerPrefs->mAccelerateByDefault ||
(acceleratedEnv && (*acceleratedEnv != '0'));
PRBool safeMode = PR_FALSE;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr)
xr->GetInSafeMode(&safeMode);
aManagerPrefs->mDisableAcceleration =
aManagerPrefs->mDisableAcceleration || safeMode;
}
mozilla::layers::LayerManager*
nsWindow::GetLayerManager(LayerManagerPersistence aPersistence, bool* aAllowRetaining)
{
@ -3302,39 +3341,16 @@ nsWindow::GetLayerManager(LayerManagerPersistence aPersistence, bool* aAllowReta
mozilla::layers::LayerManager::LAYERS_BASIC)) {
// If D3D9 is not currently allowed but the permanent manager is required,
// -and- we're currently using basic layers, run through this check.
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
PRBool accelerateByDefault = PR_TRUE;
PRBool disableAcceleration = PR_FALSE;
PRBool preferOpenGL = PR_FALSE;
PRBool preferD3D9 = PR_FALSE;
if (prefs) {
prefs->GetBoolPref("layers.acceleration.disabled",
&disableAcceleration);
prefs->GetBoolPref("layers.prefer-opengl",
&preferOpenGL);
prefs->GetBoolPref("layers.prefer-d3d9",
&preferD3D9);
}
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
accelerateByDefault = accelerateByDefault ||
(acceleratedEnv && (*acceleratedEnv != '0'));
LayerManagerPrefs prefs;
GetLayerManagerPrefs(&prefs);
/* 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 */
disableAcceleration = disableAcceleration ||
eTransparencyTransparent == mTransparencyMode;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
PRBool safeMode = PR_FALSE;
if (xr)
xr->GetInSafeMode(&safeMode);
if (disableAcceleration || safeMode)
if (eTransparencyTransparent == mTransparencyMode ||
prefs.mDisableAcceleration)
mUseAcceleratedRendering = PR_FALSE;
else if (accelerateByDefault)
else if (prefs.mAccelerateByDefault)
mUseAcceleratedRendering = PR_TRUE;
if (mUseAcceleratedRendering) {
@ -3345,7 +3361,7 @@ nsWindow::GetLayerManager(LayerManagerPersistence aPersistence, bool* aAllowReta
}
#ifdef MOZ_ENABLE_D3D10_LAYER
if (!preferD3D9) {
if (!prefs.mPreferD3D9) {
nsRefPtr<mozilla::layers::LayerManagerD3D10> layerManager =
new mozilla::layers::LayerManagerD3D10(this);
if (layerManager->Initialize()) {
@ -3354,7 +3370,7 @@ nsWindow::GetLayerManager(LayerManagerPersistence aPersistence, bool* aAllowReta
}
#endif
#ifdef MOZ_ENABLE_D3D9_LAYER
if (!preferOpenGL && !mLayerManager && sAllowD3D9) {
if (!prefs.mPreferOpenGL && !mLayerManager && sAllowD3D9) {
nsRefPtr<mozilla::layers::LayerManagerD3D9> layerManager =
new mozilla::layers::LayerManagerD3D9(this);
if (layerManager->Initialize()) {
@ -3362,7 +3378,7 @@ nsWindow::GetLayerManager(LayerManagerPersistence aPersistence, bool* aAllowReta
}
}
#endif
if (!mLayerManager && preferOpenGL) {
if (!mLayerManager && prefs.mPreferOpenGL) {
nsRefPtr<mozilla::layers::LayerManagerOGL> layerManager =
new mozilla::layers::LayerManagerOGL(this);
if (layerManager->Initialize()) {
@ -7682,6 +7698,23 @@ nsWindow::StartAllowingD3D9(bool aReinitialize)
{
sAllowD3D9 = true;
LayerManagerPrefs prefs;
GetLayerManagerPrefs(&prefs);
if (prefs.mDisableAcceleration) {
// The guarantee here is, if there's *any* chance that after we
// throw out our layer managers we'd create at least one new,
// accelerated one, we *will* throw out all the current layer
// managers. We early-return here because currently, if
// |disableAcceleration|, we will always use basic managers and
// it's a waste to recreate them.
//
// NB: the above implies that it's eminently possible for us to
// skip this early return but still recreate basic managers.
// That's OK. It's *not* OK to take this early return when we
// *might* have created an accelerated manager.
return;
}
if (aReinitialize) {
EnumAllWindows(AllowD3D9WithReinitializeCallback);
} else {