0827acb7b89dd029a4842338b61fc41f55256977
[platform/framework/web/crosswalk.git] / src / content / browser / compositor / image_transport_factory.cc
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.
4
5 #include "content/browser/compositor/image_transport_factory.h"
6
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 "ui/compositor/compositor.h"
11 #include "ui/compositor/compositor_switches.h"
12 #include "ui/gl/gl_implementation.h"
13
14 namespace content {
15
16 namespace {
17 ImageTransportFactory* g_factory = NULL;
18 bool g_initialized_for_unit_tests = false;
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
26 }
27
28 // static
29 void ImageTransportFactory::Initialize() {
30   DCHECK(!g_factory || g_initialized_for_unit_tests);
31   if (g_initialized_for_unit_tests)
32     return;
33   SetFactory(new GpuProcessTransportFactory);
34 }
35
36 void ImageTransportFactory::InitializeForUnitTests(
37     scoped_ptr<ui::ContextFactory> test_factory) {
38   DCHECK(!g_factory);
39   DCHECK(!g_initialized_for_unit_tests);
40   g_initialized_for_unit_tests = true;
41
42   CommandLine* command_line = CommandLine::ForCurrentProcess();
43   if (command_line->HasSwitch(switches::kEnablePixelOutputInTests))
44     g_disable_null_draw = new gfx::DisableNullDrawGLBindings;
45
46   SetFactory(new NoTransportImageTransportFactory(test_factory.Pass()));
47 }
48
49 // static
50 void ImageTransportFactory::Terminate() {
51   ui::ContextFactory::SetInstance(NULL);
52   delete g_factory;
53   g_factory = NULL;
54   delete g_disable_null_draw;
55   g_disable_null_draw = NULL;
56   g_initialized_for_unit_tests = false;
57 }
58
59 // static
60 ImageTransportFactory* ImageTransportFactory::GetInstance() {
61   return g_factory;
62 }
63
64 }  // namespace content