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