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