Index: ui/gfx/display.cc |
diff --git a/ui/gfx/display.cc b/ui/gfx/display.cc |
index c79dcea9ed1dcfedc7a2959cb67710a89a20841e..c596a9aca34201bcd6033526f6fd34546ad04fd1 100644 |
--- a/ui/gfx/display.cc |
+++ b/ui/gfx/display.cc |
@@ -19,6 +19,16 @@ |
namespace gfx { |
namespace { |
+// This variable tracks whether the forced device scale factor switch needs to |
+// be read from the command line, i.e. if it is set to -1 then the command line |
+// is checked. |
+int g_HasForcedDeviceScaleFactor = -1; |
+ |
+// This variable caches the forced device scale factor value which is read off |
+// the command line. If the cache is invalidated by setting this variable to |
+// -1.0, we read the forced device scale factor again. |
+float g_ForcedDeviceScaleFactor = -1.0; |
+ |
bool HasForceDeviceScaleFactorImpl() { |
return base::CommandLine::ForCurrentProcess()->HasSwitch( |
switches::kForceDeviceScaleFactor); |
@@ -44,16 +54,22 @@ const int64 Display::kInvalidDisplayID = -1; |
// static |
float Display::GetForcedDeviceScaleFactor() { |
- static const float kForcedDeviceScaleFactor = |
- GetForcedDeviceScaleFactorImpl(); |
- return kForcedDeviceScaleFactor; |
+ if (g_ForcedDeviceScaleFactor < 0) |
scottmg
2015/03/10 23:02:01
I think it would be less complex to have
bool
ananta
2015/03/10 23:31:57
Sadly that would be tricky. Given that we have two
|
+ g_ForcedDeviceScaleFactor = GetForcedDeviceScaleFactorImpl(); |
+ return g_ForcedDeviceScaleFactor; |
} |
//static |
bool Display::HasForceDeviceScaleFactor() { |
- static const bool kHasForceDeviceScaleFactor = |
- HasForceDeviceScaleFactorImpl(); |
- return kHasForceDeviceScaleFactor; |
+ if (g_HasForcedDeviceScaleFactor == -1) |
+ g_HasForcedDeviceScaleFactor = HasForceDeviceScaleFactorImpl(); |
+ return !!g_HasForcedDeviceScaleFactor; |
+} |
+ |
+// static |
+void Display::ResetForceDeviceScaleFactor() { |
+ g_HasForcedDeviceScaleFactor = -1; |
+ g_ForcedDeviceScaleFactor = -1.0; |
} |
Display::Display() |