• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 "base/command_line.h"
6 #include "base/debug/trace_event.h"
7 #include "base/logging.h"
8 #include "ui/ozone/ozone_platform.h"
9 #include "ui/ozone/ozone_switches.h"
10 #include "ui/ozone/platform_object.h"
11 #include "ui/ozone/platform_selection.h"
12 
13 namespace ui {
14 
15 namespace {
16 
17 bool g_platform_initialized_ui = false;
18 bool g_platform_initialized_gpu = false;
19 
20 }
21 
OzonePlatform()22 OzonePlatform::OzonePlatform() {
23   CHECK(!instance_) << "There should only be a single OzonePlatform.";
24   instance_ = this;
25   g_platform_initialized_ui = false;
26   g_platform_initialized_gpu = false;
27 }
28 
~OzonePlatform()29 OzonePlatform::~OzonePlatform() {
30   CHECK_EQ(instance_, this);
31   instance_ = NULL;
32 }
33 
34 // static
InitializeForUI()35 void OzonePlatform::InitializeForUI() {
36   CreateInstance();
37   if (g_platform_initialized_ui)
38     return;
39   g_platform_initialized_ui = true;
40   instance_->InitializeUI();
41 }
42 
43 // static
InitializeForGPU()44 void OzonePlatform::InitializeForGPU() {
45   CreateInstance();
46   if (g_platform_initialized_gpu)
47     return;
48   g_platform_initialized_gpu = true;
49   instance_->InitializeGPU();
50 }
51 
52 // static
GetInstance()53 OzonePlatform* OzonePlatform::GetInstance() {
54   CHECK(instance_) << "OzonePlatform is not initialized";
55   return instance_;
56 }
57 
58 // static
CreateInstance()59 void OzonePlatform::CreateInstance() {
60   if (!instance_) {
61     TRACE_EVENT1("ozone",
62                  "OzonePlatform::Initialize",
63                  "platform",
64                  GetOzonePlatformName());
65     scoped_ptr<OzonePlatform> platform =
66         PlatformObject<OzonePlatform>::Create();
67 
68     // TODO(spang): Currently need to leak this object.
69     CHECK_EQ(instance_, platform.release());
70   }
71 }
72 
73 // static
74 OzonePlatform* OzonePlatform::instance_;
75 
76 }  // namespace ui
77