From d9a04350b5a618761126b2dcd4170c963f07a037 Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Wed, 7 Nov 2012 11:39:38 +1300 Subject: [PATCH] Bug 797120 - GLContext::CanUploadNonPowerOfTwo() should not call AddBoolVarCache() when off the main thread. r=bjacob --- gfx/gl/GLContext.cpp | 31 ++++++++++++++++++++++--------- gfx/gl/GLContext.h | 10 ++++++++++ gfx/thebes/gfxPlatform.cpp | 2 ++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index d9f3e27accbc..afb9f895af1b 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -625,21 +625,34 @@ GLContext::CanUploadSubTextures() return true; } +bool GLContext::sPowerOfTwoForced = false; +bool GLContext::sPowerOfTwoPrefCached = false; + +void +GLContext::PlatformStartup() +{ + CacheCanUploadNPOT(); +} + +void +GLContext::CacheCanUploadNPOT() +{ + MOZ_ASSERT(NS_IsMainThread(), "Can't cache prefs off the main thread."); + MOZ_ASSERT(!sPowerOfTwoPrefCached, "Must only call this function once!"); + + sPowerOfTwoPrefCached = true; + mozilla::Preferences::AddBoolVarCache(&sPowerOfTwoForced, + "gfx.textures.poweroftwo.force-enabled"); +} + bool GLContext::CanUploadNonPowerOfTwo() { + MOZ_ASSERT(sPowerOfTwoPrefCached); + if (!mWorkAroundDriverBugs) return true; - static bool sPowerOfTwoForced; - static bool sPowerOfTwoPrefCached = false; - - if (!sPowerOfTwoPrefCached) { - sPowerOfTwoPrefCached = true; - mozilla::Preferences::AddBoolVarCache(&sPowerOfTwoForced, - "gfx.textures.poweroftwo.force-enabled"); - } - // Some GPUs driver crash when uploading non power of two 565 textures. return sPowerOfTwoForced ? false : (Renderer() != RendererAdreno200 && Renderer() != RendererAdreno205); diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index d322d6e644c9..6d14d6d1a5c3 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -744,7 +744,17 @@ public: } bool CanUploadSubTextures(); + + static void PlatformStartup(); + +protected: + static bool sPowerOfTwoForced; + static bool sPowerOfTwoPrefCached; + static void CacheCanUploadNPOT(); + +public: bool CanUploadNonPowerOfTwo(); + bool WantsSmallTiles(); virtual bool HasLockSurface() { return false; } diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 6ced9c9471fc..abe6eae0275c 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -340,6 +340,8 @@ gfxPlatform::Init() gPlatform->mWorkAroundDriverBugs = Preferences::GetBool("gfx.work-around-driver-bugs", true); + mozilla::gl::GLContext::PlatformStartup(); + #ifdef MOZ_WIDGET_ANDROID // Texture pool init mozilla::gl::TexturePoolOGL::Init();