OLD | NEW |
| (Empty) |
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/events/device_data_manager.h" | |
9 #include "ui/ozone/ozone_platform.h" | |
10 #include "ui/ozone/ozone_switches.h" | |
11 #include "ui/ozone/platform_object.h" | |
12 #include "ui/ozone/platform_selection.h" | |
13 | |
14 namespace ui { | |
15 | |
16 namespace { | |
17 | |
18 bool g_platform_initialized_ui = false; | |
19 bool g_platform_initialized_gpu = false; | |
20 | |
21 } | |
22 | |
23 OzonePlatform::OzonePlatform() { | |
24 CHECK(!instance_) << "There should only be a single OzonePlatform."; | |
25 instance_ = this; | |
26 g_platform_initialized_ui = false; | |
27 g_platform_initialized_gpu = false; | |
28 } | |
29 | |
30 OzonePlatform::~OzonePlatform() { | |
31 CHECK_EQ(instance_, this); | |
32 instance_ = NULL; | |
33 } | |
34 | |
35 // static | |
36 void OzonePlatform::InitializeForUI() { | |
37 CreateInstance(); | |
38 if (g_platform_initialized_ui) | |
39 return; | |
40 g_platform_initialized_ui = true; | |
41 instance_->InitializeUI(); | |
42 // This is deliberately created after initializing so that the platform can | |
43 // create its own version of DDM. | |
44 DeviceDataManager::CreateInstance(); | |
45 } | |
46 | |
47 // static | |
48 void OzonePlatform::InitializeForGPU() { | |
49 CreateInstance(); | |
50 if (g_platform_initialized_gpu) | |
51 return; | |
52 g_platform_initialized_gpu = true; | |
53 instance_->InitializeGPU(); | |
54 } | |
55 | |
56 // static | |
57 OzonePlatform* OzonePlatform::GetInstance() { | |
58 CHECK(instance_) << "OzonePlatform is not initialized"; | |
59 return instance_; | |
60 } | |
61 | |
62 // static | |
63 void OzonePlatform::CreateInstance() { | |
64 if (!instance_) { | |
65 TRACE_EVENT1("ozone", | |
66 "OzonePlatform::Initialize", | |
67 "platform", | |
68 GetOzonePlatformName()); | |
69 scoped_ptr<OzonePlatform> platform = | |
70 PlatformObject<OzonePlatform>::Create(); | |
71 | |
72 // TODO(spang): Currently need to leak this object. | |
73 CHECK_EQ(instance_, platform.release()); | |
74 } | |
75 } | |
76 | |
77 // static | |
78 OzonePlatform* OzonePlatform::instance_; | |
79 | |
80 } // namespace ui | |
OLD | NEW |