Index: cc/base/switches.cc |
diff --git a/cc/base/switches.cc b/cc/base/switches.cc |
index be4a2c55adfbcb22214a0a92439f59da8fd112e2..71e87f8f1a75eba932a3b5a59d9958053147678f 100644 |
--- a/cc/base/switches.cc |
+++ b/cc/base/switches.cc |
@@ -5,6 +5,7 @@ |
#include "cc/base/switches.h" |
#include "base/command_line.h" |
+#include "base/logging.h" |
namespace cc { |
namespace switches { |
@@ -151,51 +152,91 @@ const char kDisable4444Textures[] = "disable-4444-textures"; |
const char kDisableCompositorTouchHitTesting[] = |
"disable-compositor-touch-hit-testing"; |
-bool IsLCDTextEnabled() { |
- const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
- if (command_line->HasSwitch(cc::switches::kDisableLCDText)) |
- return false; |
- else if (command_line->HasSwitch(cc::switches::kEnableLCDText)) |
- return true; |
+struct Switches { |
+ typedef enum { |
danakj
2013/11/26 15:55:50
This is a lot of work. Can we just have 4 static b
sivag
2013/11/26 17:28:49
As you know we cannot maintain the static bool glo
danakj
2013/11/26 17:35:17
Why can't we have global static bools? We do this
|
+ IMPL_SIDE_PAINTING = 0, |
+ MAP_IMAGE, |
+ LCD_TEXT, |
+ } Type; |
+ |
+ Switches() |
+ : has_initialized_switches_(false) |
+ , impl_side_painting_enabled_(false) |
+ , map_image_enabled_(false) |
+ , lcd_text_enabled_(false) { |
+ } |
+ |
+ bool has_initialized_switches_ : 1; |
+ bool impl_side_painting_enabled_ : 1; |
+ bool map_image_enabled_ : 1; |
+ bool lcd_text_enabled_ : 1; |
+}; |
+ |
+ |
+bool GetSwitchValue(Switches::Type switch_type) { |
+ static Switches switch_container; |
+ if (!switch_container.has_initialized_switches_) { |
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
+ // Impl-side painting. |
+ if (command_line.HasSwitch(cc::switches::kDisableImplSidePainting)) { |
+ switch_container.impl_side_painting_enabled_ = false; |
+ } else if (command_line.HasSwitch(cc::switches::kEnableImplSidePainting)) { |
+ switch_container.impl_side_painting_enabled_ = true; |
+ } else { |
#if defined(OS_ANDROID) |
- return false; |
+ switch_container.impl_side_painting_enabled_ = true; |
#else |
- return true; |
+ switch_container.impl_side_painting_enabled_ = false; |
#endif |
-} |
- |
-namespace { |
-bool CheckImplSidePaintingStatus() { |
- const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
- |
- if (command_line.HasSwitch(cc::switches::kDisableImplSidePainting)) |
- return false; |
- else if (command_line.HasSwitch(cc::switches::kEnableImplSidePainting)) |
- return true; |
- |
+ } |
+ |
+ // Map-Image. |
+ if (command_line.HasSwitch(cc::switches::kDisableMapImage)) |
+ switch_container.map_image_enabled_ = false; |
+ else if (command_line.HasSwitch(cc::switches::kEnableMapImage)) |
+ switch_container.map_image_enabled_ = true; |
+ else |
+ switch_container.map_image_enabled_ = false; |
+ |
+ // LCD-Text. |
+ if (command_line.HasSwitch(cc::switches::kDisableLCDText)) { |
+ switch_container.lcd_text_enabled_ = false; |
+ } else if (command_line.HasSwitch(cc::switches::kEnableLCDText)) { |
+ switch_container.lcd_text_enabled_ = true; |
+ } else { |
#if defined(OS_ANDROID) |
- return true; |
+ switch_container.lcd_text_enabled_ = false; |
#else |
- return false; |
+ switch_container.lcd_text_enabled_ = true; |
#endif |
+ } |
+ switch_container.has_initialized_switches_ = true; |
+ } |
+ |
+ switch(switch_type) { |
+ case Switches::IMPL_SIDE_PAINTING: |
+ return switch_container.impl_side_painting_enabled_; |
+ case Switches::MAP_IMAGE: |
+ return switch_container.map_image_enabled_; |
+ case Switches::LCD_TEXT: |
+ return switch_container.lcd_text_enabled_; |
+ default: |
+ NOTREACHED(); |
+ return false; |
+ } |
} |
-} // namespace |
bool IsImplSidePaintingEnabled() { |
- static bool enabled = CheckImplSidePaintingStatus(); |
- return enabled; |
+ return GetSwitchValue(Switches::IMPL_SIDE_PAINTING); |
} |
bool IsMapImageEnabled() { |
- const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
- |
- if (command_line.HasSwitch(cc::switches::kDisableMapImage)) |
- return false; |
- else if (command_line.HasSwitch(cc::switches::kEnableMapImage)) |
- return true; |
+ return GetSwitchValue(Switches::MAP_IMAGE); |
+} |
- return false; |
+bool IsLCDTextEnabled() { |
+ return GetSwitchValue(Switches::LCD_TEXT); |
} |
} // namespace switches |