OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/compositor/test/context_factories_for_test.h" | 5 #include "ui/compositor/test/context_factories_for_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
9 #include "ui/compositor/compositor.h" | 9 #include "ui/compositor/compositor.h" |
10 #include "ui/compositor/compositor_switches.h" | 10 #include "ui/compositor/compositor_switches.h" |
11 #include "ui/compositor/test/default_context_factory.h" | 11 #include "ui/compositor/test/in_process_context_factory.h" |
12 #include "ui/compositor/test/test_context_factory.h" | |
13 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 | 15 |
17 static ContextFactory* g_implicit_factory = NULL; | 16 static ContextFactory* g_implicit_factory = NULL; |
| 17 static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL; |
18 | 18 |
19 // static | 19 // static |
20 void InitializeContextFactoryForTests(bool allow_test_contexts) { | 20 void InitializeContextFactoryForTests(bool enable_pixel_output) { |
21 DCHECK(!g_implicit_factory) << | 21 DCHECK(!g_implicit_factory) << |
22 "ContextFactory for tests already initialized."; | 22 "ContextFactory for tests already initialized."; |
23 | 23 |
24 bool use_test_contexts = true; | 24 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 25 if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) |
| 26 enable_pixel_output = true; |
| 27 if (enable_pixel_output) |
| 28 g_disable_null_draw = new gfx::DisableNullDrawGLBindings; |
25 | 29 |
26 // Always use test contexts unless the disable command line flag is used. | 30 g_implicit_factory = new InProcessContextFactory(); |
27 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
28 if (command_line->HasSwitch(switches::kDisableTestCompositor)) | |
29 use_test_contexts = false; | |
30 | |
31 #if defined(OS_CHROMEOS) | |
32 // If the test is running on the chromeos envrionment (such as | |
33 // device or vm bots), always use real contexts. | |
34 if (base::SysInfo::IsRunningOnChromeOS()) | |
35 use_test_contexts = false; | |
36 #endif | |
37 | |
38 if (!allow_test_contexts) | |
39 use_test_contexts = false; | |
40 | |
41 if (use_test_contexts) { | |
42 g_implicit_factory = new ui::TestContextFactory; | |
43 } else { | |
44 DCHECK_NE(gfx::kGLImplementationNone, gfx::GetGLImplementation()); | |
45 DVLOG(1) << "Using DefaultContextFactory"; | |
46 g_implicit_factory = new ui::DefaultContextFactory(); | |
47 } | |
48 ContextFactory::SetInstance(g_implicit_factory); | 31 ContextFactory::SetInstance(g_implicit_factory); |
49 } | 32 } |
50 | 33 |
51 void TerminateContextFactoryForTests() { | 34 void TerminateContextFactoryForTests() { |
52 ContextFactory::SetInstance(NULL); | 35 ContextFactory::SetInstance(NULL); |
53 delete g_implicit_factory; | 36 delete g_implicit_factory; |
54 g_implicit_factory = NULL; | 37 g_implicit_factory = NULL; |
| 38 delete g_disable_null_draw; |
| 39 g_disable_null_draw = NULL; |
55 } | 40 } |
56 | 41 |
57 } // namespace ui | 42 } // namespace ui |
OLD | NEW |