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