Chromium Code Reviews| 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 ui { | 15 namespace ui { |
| 16 | 16 |
| 17 static ContextFactory* g_implicit_factory = NULL; | 17 static ContextFactory* g_implicit_factory = NULL; |
| 18 static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL; | |
|
no sievers
2014/02/21 19:51:49
nit: Shouldn't these statics be in an anonymous na
danakj
2014/02/21 19:56:58
Sure!
| |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 void InitializeContextFactoryForTests(bool enable_pixel_output) { | 21 void InitializeContextFactoryForTests(bool enable_pixel_output) { |
| 21 DCHECK(!g_implicit_factory) << | 22 DCHECK(!g_implicit_factory) << |
| 22 "ContextFactory for tests already initialized."; | 23 "ContextFactory for tests already initialized."; |
| 24 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 25 if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) | |
| 26 enable_pixel_output = true; | |
| 23 | 27 |
| 24 bool use_test_contexts = true; | 28 bool use_test_contexts = true; |
| 25 | 29 |
| 30 if (gfx::HasInitializedNullDrawGLBindings()) | |
| 31 use_test_contexts = false; | |
|
no sievers
2014/02/21 19:51:49
Is that ok even if enable_pixel_output == true?
danakj
2014/02/21 19:56:58
Ya, the gfx::DisableNullDrawGLBindings down below
| |
| 32 | |
| 26 // Always use test contexts unless the disable command line flag is used. | 33 // 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)) | 34 if (command_line->HasSwitch(switches::kDisableTestCompositor)) |
| 29 use_test_contexts = false; | 35 use_test_contexts = false; |
| 30 | 36 |
| 31 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
| 32 // If the test is running on the chromeos envrionment (such as | 38 // If the test is running on the chromeos envrionment (such as |
| 33 // device or vm bots), always use real contexts. | 39 // device or vm bots), always use real contexts. |
| 34 if (base::SysInfo::IsRunningOnChromeOS()) | 40 if (base::SysInfo::IsRunningOnChromeOS()) |
| 35 use_test_contexts = false; | 41 use_test_contexts = false; |
| 36 #endif | 42 #endif |
| 37 | 43 |
| 38 if (enable_pixel_output) | 44 if (enable_pixel_output) |
| 39 use_test_contexts = false; | 45 use_test_contexts = false; |
| 40 | 46 |
| 41 if (use_test_contexts) { | 47 if (use_test_contexts) { |
| 42 g_implicit_factory = new ui::TestContextFactory; | 48 g_implicit_factory = new ui::TestContextFactory; |
| 43 } else { | 49 } else { |
| 44 DCHECK_NE(gfx::kGLImplementationNone, gfx::GetGLImplementation()); | 50 DCHECK_NE(gfx::kGLImplementationNone, gfx::GetGLImplementation()); |
| 45 DVLOG(1) << "Using InProcessContextFactory"; | 51 DVLOG(1) << "Using InProcessContextFactory"; |
| 52 if (enable_pixel_output && gfx::HasInitializedNullDrawGLBindings()) | |
| 53 g_disable_null_draw = new gfx::DisableNullDrawGLBindings; | |
| 46 g_implicit_factory = new ui::InProcessContextFactory(); | 54 g_implicit_factory = new ui::InProcessContextFactory(); |
| 47 } | 55 } |
| 48 ContextFactory::SetInstance(g_implicit_factory); | 56 ContextFactory::SetInstance(g_implicit_factory); |
| 49 } | 57 } |
| 50 | 58 |
| 51 void TerminateContextFactoryForTests() { | 59 void TerminateContextFactoryForTests() { |
| 52 ContextFactory::SetInstance(NULL); | 60 ContextFactory::SetInstance(NULL); |
| 53 delete g_implicit_factory; | 61 delete g_implicit_factory; |
| 54 g_implicit_factory = NULL; | 62 g_implicit_factory = NULL; |
| 63 delete g_disable_null_draw; | |
| 64 g_disable_null_draw = NULL; | |
| 55 } | 65 } |
| 56 | 66 |
| 57 } // namespace ui | 67 } // namespace ui |
| OLD | NEW |