Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1066)

Side by Side Diff: cc/base/switches.cc

Issue 69123002: Generic version of caching cc switches to avoid searching of switches on each function call (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworked on old patch to avoid regression caused due to global pod variable. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/base/switches.h" 5 #include "cc/base/switches.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h"
8 9
9 namespace cc { 10 namespace cc {
10 namespace switches { 11 namespace switches {
11 12
12 // On platforms where checkerboards are used, prefer background colors instead 13 // On platforms where checkerboards are used, prefer background colors instead
13 // of checkerboards. 14 // of checkerboards.
14 const char kBackgroundColorInsteadOfCheckerboard[] = 15 const char kBackgroundColorInsteadOfCheckerboard[] =
15 "background-color-instead-of-checkerboard"; 16 "background-color-instead-of-checkerboard";
16 17
17 // Disables LCD text. 18 // Disables LCD text.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // Makes pixel tests write their output instead of read it. 145 // Makes pixel tests write their output instead of read it.
145 const char kCCRebaselinePixeltests[] = "cc-rebaseline-pixeltests"; 146 const char kCCRebaselinePixeltests[] = "cc-rebaseline-pixeltests";
146 147
147 // Disable textures using RGBA_4444 layout. 148 // Disable textures using RGBA_4444 layout.
148 const char kDisable4444Textures[] = "disable-4444-textures"; 149 const char kDisable4444Textures[] = "disable-4444-textures";
149 150
150 // Disable touch hit testing in the compositor. 151 // Disable touch hit testing in the compositor.
151 const char kDisableCompositorTouchHitTesting[] = 152 const char kDisableCompositorTouchHitTesting[] =
152 "disable-compositor-touch-hit-testing"; 153 "disable-compositor-touch-hit-testing";
153 154
154 bool IsLCDTextEnabled() {
155 const CommandLine* command_line = CommandLine::ForCurrentProcess();
156 if (command_line->HasSwitch(cc::switches::kDisableLCDText))
157 return false;
158 else if (command_line->HasSwitch(cc::switches::kEnableLCDText))
159 return true;
160 155
156 struct Switches {
157 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
158 IMPL_SIDE_PAINTING = 0,
159 MAP_IMAGE,
160 LCD_TEXT,
161 } Type;
162
163 Switches()
164 : has_initialized_switches_(false)
165 , impl_side_painting_enabled_(false)
166 , map_image_enabled_(false)
167 , lcd_text_enabled_(false) {
168 }
169
170 bool has_initialized_switches_ : 1;
171 bool impl_side_painting_enabled_ : 1;
172 bool map_image_enabled_ : 1;
173 bool lcd_text_enabled_ : 1;
174 };
175
176
177 bool GetSwitchValue(Switches::Type switch_type) {
178 static Switches switch_container;
179 if (!switch_container.has_initialized_switches_) {
180 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
181 // Impl-side painting.
182 if (command_line.HasSwitch(cc::switches::kDisableImplSidePainting)) {
183 switch_container.impl_side_painting_enabled_ = false;
184 } else if (command_line.HasSwitch(cc::switches::kEnableImplSidePainting)) {
185 switch_container.impl_side_painting_enabled_ = true;
186 } else {
161 #if defined(OS_ANDROID) 187 #if defined(OS_ANDROID)
162 return false; 188 switch_container.impl_side_painting_enabled_ = true;
163 #else 189 #else
164 return true; 190 switch_container.impl_side_painting_enabled_ = false;
165 #endif 191 #endif
192 }
193
194 // Map-Image.
195 if (command_line.HasSwitch(cc::switches::kDisableMapImage))
196 switch_container.map_image_enabled_ = false;
197 else if (command_line.HasSwitch(cc::switches::kEnableMapImage))
198 switch_container.map_image_enabled_ = true;
199 else
200 switch_container.map_image_enabled_ = false;
201
202 // LCD-Text.
203 if (command_line.HasSwitch(cc::switches::kDisableLCDText)) {
204 switch_container.lcd_text_enabled_ = false;
205 } else if (command_line.HasSwitch(cc::switches::kEnableLCDText)) {
206 switch_container.lcd_text_enabled_ = true;
207 } else {
208 #if defined(OS_ANDROID)
209 switch_container.lcd_text_enabled_ = false;
210 #else
211 switch_container.lcd_text_enabled_ = true;
212 #endif
213 }
214 switch_container.has_initialized_switches_ = true;
215 }
216
217 switch(switch_type) {
218 case Switches::IMPL_SIDE_PAINTING:
219 return switch_container.impl_side_painting_enabled_;
220 case Switches::MAP_IMAGE:
221 return switch_container.map_image_enabled_;
222 case Switches::LCD_TEXT:
223 return switch_container.lcd_text_enabled_;
224 default:
225 NOTREACHED();
226 return false;
227 }
166 } 228 }
167 229
168 namespace {
169 bool CheckImplSidePaintingStatus() {
170 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
171
172 if (command_line.HasSwitch(cc::switches::kDisableImplSidePainting))
173 return false;
174 else if (command_line.HasSwitch(cc::switches::kEnableImplSidePainting))
175 return true;
176
177 #if defined(OS_ANDROID)
178 return true;
179 #else
180 return false;
181 #endif
182 }
183 } // namespace
184
185 bool IsImplSidePaintingEnabled() { 230 bool IsImplSidePaintingEnabled() {
186 static bool enabled = CheckImplSidePaintingStatus(); 231 return GetSwitchValue(Switches::IMPL_SIDE_PAINTING);
187 return enabled;
188 } 232 }
189 233
190 bool IsMapImageEnabled() { 234 bool IsMapImageEnabled() {
191 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 235 return GetSwitchValue(Switches::MAP_IMAGE);
236 }
192 237
193 if (command_line.HasSwitch(cc::switches::kDisableMapImage)) 238 bool IsLCDTextEnabled() {
194 return false; 239 return GetSwitchValue(Switches::LCD_TEXT);
195 else if (command_line.HasSwitch(cc::switches::kEnableMapImage))
196 return true;
197
198 return false;
199 } 240 }
200 241
201 } // namespace switches 242 } // namespace switches
202 } // namespace cc 243 } // namespace cc
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698