OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/image_transport_factory.h" | 5 #include "content/browser/compositor/image_transport_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/compositor/gpu_process_transport_factory.h" | 8 #include "content/browser/compositor/gpu_process_transport_factory.h" |
9 #include "content/browser/compositor/no_transport_image_transport_factory.h" | 9 #include "content/browser/compositor/no_transport_image_transport_factory.h" |
10 #include "ui/compositor/compositor.h" | 10 #include "ui/compositor/compositor.h" |
11 #include "ui/compositor/compositor_switches.h" | 11 #include "ui/compositor/compositor_switches.h" |
12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace { | 16 namespace { |
17 ImageTransportFactory* g_factory = NULL; | 17 ImageTransportFactory* g_factory = NULL; |
18 bool g_initialized_for_unit_tests = false; | 18 bool g_initialized_for_unit_tests = false; |
19 static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL; | 19 static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL; |
| 20 |
| 21 void SetFactory(ImageTransportFactory* factory) { |
| 22 g_factory = factory; |
| 23 ui::ContextFactory::SetInstance(factory->GetContextFactory()); |
| 24 } |
| 25 |
20 } | 26 } |
21 | 27 |
22 // static | 28 // static |
23 void ImageTransportFactory::Initialize() { | 29 void ImageTransportFactory::Initialize() { |
24 DCHECK(!g_factory || g_initialized_for_unit_tests); | 30 DCHECK(!g_factory || g_initialized_for_unit_tests); |
25 if (g_initialized_for_unit_tests) | 31 if (g_initialized_for_unit_tests) |
26 return; | 32 return; |
27 GpuProcessTransportFactory* factory = new GpuProcessTransportFactory; | 33 SetFactory(new GpuProcessTransportFactory); |
28 g_factory = factory; | |
29 ui::ContextFactory::SetInstance(factory); | |
30 } | 34 } |
31 | 35 |
32 void ImageTransportFactory::InitializeForUnitTests( | 36 void ImageTransportFactory::InitializeForUnitTests( |
33 scoped_ptr<ui::ContextFactory> test_factory) { | 37 scoped_ptr<ui::ContextFactory> test_factory) { |
34 DCHECK(!g_factory); | 38 DCHECK(!g_factory); |
35 DCHECK(!g_initialized_for_unit_tests); | 39 DCHECK(!g_initialized_for_unit_tests); |
36 g_initialized_for_unit_tests = true; | 40 g_initialized_for_unit_tests = true; |
37 | 41 |
38 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 42 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
39 if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) | 43 if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) |
40 g_disable_null_draw = new gfx::DisableNullDrawGLBindings; | 44 g_disable_null_draw = new gfx::DisableNullDrawGLBindings; |
41 | 45 |
42 NoTransportImageTransportFactory* factory = | 46 SetFactory(new NoTransportImageTransportFactory(test_factory.Pass())); |
43 new NoTransportImageTransportFactory(test_factory.Pass()); | |
44 g_factory = factory; | |
45 ui::ContextFactory::SetInstance(factory->context_factory()); | |
46 } | 47 } |
47 | 48 |
48 // static | 49 // static |
49 void ImageTransportFactory::Terminate() { | 50 void ImageTransportFactory::Terminate() { |
50 ui::ContextFactory::SetInstance(NULL); | 51 ui::ContextFactory::SetInstance(NULL); |
51 delete g_factory; | 52 delete g_factory; |
52 g_factory = NULL; | 53 g_factory = NULL; |
53 delete g_disable_null_draw; | 54 delete g_disable_null_draw; |
54 g_disable_null_draw = NULL; | 55 g_disable_null_draw = NULL; |
55 g_initialized_for_unit_tests = false; | 56 g_initialized_for_unit_tests = false; |
56 } | 57 } |
57 | 58 |
58 // static | 59 // static |
59 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 60 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
60 return g_factory; | 61 return g_factory; |
61 } | 62 } |
62 | 63 |
63 } // namespace content | 64 } // namespace content |
OLD | NEW |