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
3 // found in the LICENSE file.
5 #include "content/browser/compositor/image_transport_factory.h"
7 #include "base/command_line.h"
8 #include "content/browser/compositor/gpu_process_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"
12 #include "ui/compositor/compositor_switches.h"
13 #include "ui/gl/gl_implementation.h"
18 ImageTransportFactory
* g_factory
= NULL
;
19 bool g_initialized_for_unit_tests
= false;
20 static gfx::DisableNullDrawGLBindings
* g_disable_null_draw
= NULL
;
24 void ImageTransportFactory::Initialize() {
25 DCHECK(!g_factory
|| g_initialized_for_unit_tests
);
26 if (g_initialized_for_unit_tests
)
28 g_factory
= new GpuProcessTransportFactory
;
29 ui::ContextFactory::SetInstance(g_factory
->AsContextFactory());
30 ui::Compositor::SetSharedBitmapManager(HostSharedBitmapManager::current());
33 void ImageTransportFactory::InitializeForUnitTests(
34 scoped_ptr
<ui::ContextFactory
> test_factory
) {
36 DCHECK(!g_initialized_for_unit_tests
);
37 g_initialized_for_unit_tests
= true;
39 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
40 if (command_line
->HasSwitch(switches::kEnablePixelOutputInTests
))
41 g_disable_null_draw
= new gfx::DisableNullDrawGLBindings
;
43 g_factory
= new NoTransportImageTransportFactory(test_factory
.Pass());
44 ui::ContextFactory::SetInstance(g_factory
->AsContextFactory());
48 void ImageTransportFactory::Terminate() {
49 ui::ContextFactory::SetInstance(NULL
);
52 delete g_disable_null_draw
;
53 g_disable_null_draw
= NULL
;
54 g_initialized_for_unit_tests
= false;
58 ImageTransportFactory
* ImageTransportFactory::GetInstance() {
62 } // namespace content