Bug 1158284 - Utility in gfxPlatform to check for safe mode, lazier computation if we should accelerate and random cleanup of prefs usage. r=botond

This commit is contained in:
Milan Sreckovic 2015-04-24 12:33:35 -07:00
Родитель e7a9b7acc7
Коммит 1266c84e30
6 изменённых файлов: 59 добавлений и 62 удалений

Просмотреть файл

@ -1759,6 +1759,22 @@ gfxPlatform::GetBackendPref(const char* aBackendPrefName, uint32_t &aBackendBitm
return result;
}
bool
gfxPlatform::InSafeMode()
{
static bool sSafeModeInitialized = false;
static bool sInSafeMode = false;
if (!sSafeModeInitialized) {
sSafeModeInitialized = true;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr) {
xr->GetInSafeMode(&sInSafeMode);
}
}
return sInSafeMode;
}
bool
gfxPlatform::OffMainThreadCompositingEnabled()
{

Просмотреть файл

@ -491,6 +491,9 @@ public:
// platform-specific override, by default do nothing
}
// Are we in safe mode?
static bool InSafeMode();
static bool OffMainThreadCompositingEnabled();
static bool CanUseDirect3D9();

Просмотреть файл

@ -494,11 +494,6 @@ gfxWindowsPlatform::UpdateRenderMode()
bool isVistaOrHigher = IsVistaOrLater();
bool safeMode = false;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr)
xr->GetInSafeMode(&safeMode);
mUseDirectWrite = Preferences::GetBool("gfx.font_rendering.directwrite.enabled", false);
#ifdef CAIRO_HAS_D2D_SURFACE
@ -535,7 +530,7 @@ gfxWindowsPlatform::UpdateRenderMode()
}
ID3D11Device *device = GetD3D11Device();
if (isVistaOrHigher && !safeMode && tryD2D &&
if (isVistaOrHigher && !InSafeMode() && tryD2D &&
device &&
device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_10_0 &&
DoesD3D11TextureSharingWork(device)) {
@ -1869,13 +1864,7 @@ gfxWindowsPlatform::InitD3D11Devices()
MOZ_ASSERT(!mD3D11Device);
bool safeMode = false;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr) {
xr->GetInSafeMode(&safeMode);
}
if (safeMode) {
if (InSafeMode()) {
return;
}

Просмотреть файл

@ -129,7 +129,6 @@ nsBaseWidget::nsBaseWidget()
, mUpdateCursor(true)
, mBorderStyle(eBorderStyle_none)
, mUseLayersAcceleration(false)
, mForceLayersAcceleration(false)
, mUseAttachedEvents(false)
, mBounds(0,0,0,0)
, mOriginalBounds(nullptr)
@ -826,35 +825,23 @@ nsBaseWidget::AutoLayerManagerSetup::~AutoLayerManagerSetup()
bool
nsBaseWidget::ComputeShouldAccelerate(bool aDefault)
{
#if defined(XP_WIN) || defined(ANDROID) || \
defined(MOZ_GL_PROVIDER) || defined(XP_MACOSX) || defined(MOZ_WIDGET_QT)
bool accelerateByDefault = true;
#else
bool accelerateByDefault = false;
#endif
// Pref to disable acceleration wins:
if (gfxPrefs::LayersAccelerationDisabled()) {
return false;
}
#ifdef XP_MACOSX
// 10.6.2 and lower have a bug involving textures and pixel buffer objects
// that caused bug 629016, so we don't allow OpenGL-accelerated layers on
// those versions of the OS.
// This will still let full-screen video be accelerated on OpenGL, because
// that XUL widget opts in to acceleration, but that's probably OK.
accelerateByDefault = nsCocoaFeatures::AccelerateByDefault();
#endif
// No acceleration in the safe mode:
if (gfxPlatform::InSafeMode()) {
return false;
}
// we should use AddBoolPrefVarCache
bool disableAcceleration = gfxPrefs::LayersAccelerationDisabled();
mForceLayersAcceleration = gfxPrefs::LayersAccelerationForceEnabled();
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
accelerateByDefault = accelerateByDefault ||
(acceleratedEnv && (*acceleratedEnv != '0'));
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
bool safeMode = false;
if (xr)
xr->GetInSafeMode(&safeMode);
// If the pref forces acceleration, no need to check further:
if (gfxPrefs::LayersAccelerationForceEnabled()) {
return true;
}
// Being whitelisted is not enough to accelerate, but not being whitelisted is
// enough not to:
bool whitelisted = false;
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
@ -873,12 +860,6 @@ nsBaseWidget::ComputeShouldAccelerate(bool aDefault)
}
}
if (disableAcceleration || safeMode)
return false;
if (mForceLayersAcceleration)
return true;
if (!whitelisted) {
static int tell_me_once = 0;
if (!tell_me_once) {
@ -892,8 +873,26 @@ nsBaseWidget::ComputeShouldAccelerate(bool aDefault)
return false;
}
if (accelerateByDefault)
#if defined (XP_MACOSX)
// 10.6.2 and lower have a bug involving textures and pixel buffer objects
// that caused bug 629016, so we don't allow OpenGL-accelerated layers on
// those versions of the OS.
// This will still let full-screen video be accelerated on OpenGL, because
// that XUL widget opts in to acceleration, but that's probably OK.
bool accelerateByDefault = nsCocoaFeatures::AccelerateByDefault();
#elif defined(XP_WIN) || defined(ANDROID) || \
defined(MOZ_GL_PROVIDER) || defined(MOZ_WIDGET_QT)
bool accelerateByDefault = true;
#else
bool accelerateByDefault = false;
#endif
// If the platform is accelerated by default or the environment
// variable is set, we accelerate:
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
if (accelerateByDefault || (acceleratedEnv && (*acceleratedEnv != '0'))) {
return true;
}
/* use the window acceleration flag */
return aDefault;

Просмотреть файл

@ -482,7 +482,6 @@ protected:
bool mUpdateCursor;
nsBorderStyle mBorderStyle;
bool mUseLayersAcceleration;
bool mForceLayersAcceleration;
bool mMultiProcessWindow;
bool mUseAttachedEvents;
nsIntRect mBounds;

Просмотреть файл

@ -3279,26 +3279,17 @@ struct LayerManagerPrefs {
static void
GetLayerManagerPrefs(LayerManagerPrefs* aManagerPrefs)
{
Preferences::GetBool("layers.acceleration.disabled",
&aManagerPrefs->mDisableAcceleration);
Preferences::GetBool("layers.acceleration.force-enabled",
&aManagerPrefs->mForceAcceleration);
Preferences::GetBool("layers.prefer-opengl",
&aManagerPrefs->mPreferOpenGL);
Preferences::GetBool("layers.prefer-d3d9",
&aManagerPrefs->mPreferD3D9);
aManagerPrefs->mDisableAcceleration = gfxPrefs::LayersAccelerationDisabled();
aManagerPrefs->mForceAcceleration = gfxPrefs::LayersAccelerationForceEnabled();
aManagerPrefs->mPreferOpenGL = gfxPrefs::LayersPreferOpenGL();
aManagerPrefs->mPreferD3D9 = gfxPrefs::LayersPreferD3D9();
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
aManagerPrefs->mAccelerateByDefault =
aManagerPrefs->mAccelerateByDefault ||
(acceleratedEnv && (*acceleratedEnv != '0'));
bool safeMode = false;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr)
xr->GetInSafeMode(&safeMode);
aManagerPrefs->mDisableAcceleration =
aManagerPrefs->mDisableAcceleration || safeMode;
aManagerPrefs->mDisableAcceleration || gfxPlatform::InSafeMode();
}
LayerManager*