OLD | NEW |
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 "content/browser/aura/image_transport_factory.h" | 5 #include "content/browser/aura/image_transport_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | |
8 #include "base/sys_info.h" | |
9 #include "content/browser/aura/gpu_process_transport_factory.h" | 7 #include "content/browser/aura/gpu_process_transport_factory.h" |
10 #include "content/browser/aura/no_transport_image_transport_factory.h" | 8 #include "content/browser/aura/no_transport_image_transport_factory.h" |
11 #include "content/public/common/content_switches.h" | |
12 #include "ui/compositor/compositor.h" | 9 #include "ui/compositor/compositor.h" |
13 #include "ui/compositor/compositor_switches.h" | |
14 | 10 |
15 namespace content { | 11 namespace content { |
16 | 12 |
17 namespace { | 13 namespace { |
18 ImageTransportFactory* g_factory; | 14 ImageTransportFactory* g_factory = NULL; |
19 } | 15 bool g_initialized_for_unit_tests = false; |
20 | |
21 | |
22 static bool UseTestContextAndTransportFactory() { | |
23 #if defined(OS_CHROMEOS) | |
24 // If the test is running on the chromeos envrionment (such as | |
25 // device or vm bots), always use real contexts. | |
26 if (base::SysInfo::IsRunningOnChromeOS()) | |
27 return false; | |
28 #endif | |
29 | |
30 // Only used if the enable command line flag is used. | |
31 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
32 if (!command_line->HasSwitch(switches::kTestCompositor)) | |
33 return false; | |
34 | |
35 // The disable command line flag preempts the enable flag. | |
36 if (!command_line->HasSwitch(switches::kDisableTestCompositor)) | |
37 return true; | |
38 | |
39 return false; | |
40 } | 16 } |
41 | 17 |
42 // static | 18 // static |
43 void ImageTransportFactory::Initialize() { | 19 void ImageTransportFactory::Initialize() { |
44 DCHECK(!g_factory); | 20 DCHECK(!g_factory || g_initialized_for_unit_tests); |
45 if (UseTestContextAndTransportFactory()) { | 21 if (g_initialized_for_unit_tests) |
46 g_factory = | 22 return; |
47 new NoTransportImageTransportFactory(new ui::TestContextFactory); | 23 g_factory = new GpuProcessTransportFactory; |
48 } else { | |
49 g_factory = new GpuProcessTransportFactory; | |
50 } | |
51 ui::ContextFactory::SetInstance(g_factory->AsContextFactory()); | 24 ui::ContextFactory::SetInstance(g_factory->AsContextFactory()); |
52 } | 25 } |
53 | 26 |
54 void ImageTransportFactory::InitializeForUnitTests() { | 27 void ImageTransportFactory::InitializeForUnitTests( |
| 28 scoped_ptr<ui::ContextFactory> test_factory) { |
55 DCHECK(!g_factory); | 29 DCHECK(!g_factory); |
56 g_factory = new NoTransportImageTransportFactory(new ui::TestContextFactory); | 30 DCHECK(!g_initialized_for_unit_tests); |
| 31 g_initialized_for_unit_tests = true; |
| 32 g_factory = new NoTransportImageTransportFactory(test_factory.Pass()); |
57 ui::ContextFactory::SetInstance(g_factory->AsContextFactory()); | 33 ui::ContextFactory::SetInstance(g_factory->AsContextFactory()); |
58 } | 34 } |
59 | 35 |
60 // static | 36 // static |
61 void ImageTransportFactory::Terminate() { | 37 void ImageTransportFactory::Terminate() { |
62 ui::ContextFactory::SetInstance(NULL); | 38 ui::ContextFactory::SetInstance(NULL); |
63 delete g_factory; | 39 delete g_factory; |
64 g_factory = NULL; | 40 g_factory = NULL; |
| 41 g_initialized_for_unit_tests = false; |
65 } | 42 } |
66 | 43 |
67 // static | 44 // static |
68 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 45 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
69 return g_factory; | 46 return g_factory; |
70 } | 47 } |
71 | 48 |
72 } // namespace content | 49 } // namespace content |
OLD | NEW |