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