summaryrefslogtreecommitdiffstats
path: root/content/browser/aura/image_transport_factory.cc
blob: 28b04bf7ea429398f4db5278db3a0da5b6336745 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/aura/image_transport_factory.h"

#include "base/command_line.h"
#include "content/browser/aura/gpu_process_transport_factory.h"
#include "content/browser/aura/no_transport_image_transport_factory.h"
#include "content/public/common/content_switches.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_switches.h"

#if defined(OS_CHROMEOS)
#include "base/chromeos/chromeos_version.h"
#endif

namespace content {

namespace {
ImageTransportFactory* g_factory;
}


static bool UseTestContextAndTransportFactory() {
#if defined(OS_CHROMEOS)
  // If the test is running on the chromeos envrionment (such as
  // device or vm bots), always use real contexts.
  if (base::chromeos::IsRunningOnChromeOS())
    return false;
#endif

  // Only used if the enable command line flag is used.
  CommandLine* command_line = CommandLine::ForCurrentProcess();
  if (!command_line->HasSwitch(switches::kTestCompositor))
    return false;

  // The disable command line flag preempts the enable flag.
  if (!command_line->HasSwitch(switches::kDisableTestCompositor))
    return true;

  return false;
}

// static
void ImageTransportFactory::Initialize() {
  if (UseTestContextAndTransportFactory()) {
    g_factory =
        new NoTransportImageTransportFactory(new ui::TestContextFactory);
  } else {
    g_factory = new GpuProcessTransportFactory;
  }
  ui::ContextFactory::SetInstance(g_factory->AsContextFactory());
}

// static
void ImageTransportFactory::Terminate() {
  ui::ContextFactory::SetInstance(NULL);
  delete g_factory;
  g_factory = NULL;
}

// static
ImageTransportFactory* ImageTransportFactory::GetInstance() {
  return g_factory;
}

}  // namespace content