Chromium Code Reviews| Index: ui/gfx/display.cc |
| diff --git a/ui/gfx/display.cc b/ui/gfx/display.cc |
| index c79dcea9ed1dcfedc7a2959cb67710a89a20841e..6bae399b4bfe4691dd947a808b326870d4fa410b 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_has_forced_device_scale_factor = -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_forced_device_scale_factor = -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 = |
|
sky
2015/03/11 00:03:41
UGH! Can we always look at the command line switch
ananta
2015/03/11 00:06:52
That would be great. Would this heavy traffic code
|
| - GetForcedDeviceScaleFactorImpl(); |
| - return kForcedDeviceScaleFactor; |
| + if (g_forced_device_scale_factor < 0) |
| + g_forced_device_scale_factor = GetForcedDeviceScaleFactorImpl(); |
| + return GetForcedDeviceScaleFactorImpl();; |
| } |
| //static |
| bool Display::HasForceDeviceScaleFactor() { |
| - static const bool kHasForceDeviceScaleFactor = |
| - HasForceDeviceScaleFactorImpl(); |
| - return kHasForceDeviceScaleFactor; |
| + if (g_has_forced_device_scale_factor == -1) |
| + g_has_forced_device_scale_factor = HasForceDeviceScaleFactorImpl(); |
| + return !!g_has_forced_device_scale_factor; |
| +} |
| + |
| +// static |
| +void Display::ResetForceDeviceScaleFactorForTesting() { |
| + g_has_forced_device_scale_factor = -1; |
| + g_forced_device_scale_factor = -1.0; |
| } |
| Display::Display() |