Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: ui/ozone/public/ozone_platform.cc

Issue 1043233003: ozone: Add post message loop initialization hook (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: return without failing Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/public/ozone_platform.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "ui/events/devices/device_data_manager.h" 8 #include "ui/events/devices/device_data_manager.h"
9 #include "ui/ozone/platform_object.h" 9 #include "ui/ozone/platform_object.h"
10 #include "ui/ozone/platform_selection.h" 10 #include "ui/ozone/platform_selection.h"
11 #include "ui/ozone/public/ozone_platform.h" 11 #include "ui/ozone/public/ozone_platform.h"
12 #include "ui/ozone/public/ozone_switches.h" 12 #include "ui/ozone/public/ozone_switches.h"
13 13
14 namespace ui { 14 namespace ui {
15 15
16 namespace { 16 namespace {
17 17
18 bool g_platform_initialized_ui = false; 18 bool g_platform_initialized_ui = false;
19 bool g_platform_initialized_gpu = false; 19 bool g_platform_initialized_gpu = false;
20 20 bool g_platform_initialized_gpu_post_main_loop = false;
21 } 21 }
22 22
23 OzonePlatform::OzonePlatform() { 23 OzonePlatform::OzonePlatform() {
24 DCHECK(!instance_) << "There should only be a single OzonePlatform."; 24 DCHECK(!instance_) << "There should only be a single OzonePlatform.";
25 instance_ = this; 25 instance_ = this;
26 g_platform_initialized_ui = false; 26 g_platform_initialized_ui = false;
27 g_platform_initialized_gpu = false; 27 g_platform_initialized_gpu = false;
28 g_platform_initialized_gpu_post_main_loop = false;
28 } 29 }
29 30
30 OzonePlatform::~OzonePlatform() { 31 OzonePlatform::~OzonePlatform() {
31 DCHECK_EQ(instance_, this); 32 DCHECK_EQ(instance_, this);
32 instance_ = NULL; 33 instance_ = NULL;
33 } 34 }
34 35
35 // static 36 // static
36 void OzonePlatform::InitializeForUI() { 37 void OzonePlatform::InitializeForUI() {
37 CreateInstance(); 38 CreateInstance();
38 if (g_platform_initialized_ui) 39 if (g_platform_initialized_ui)
39 return; 40 return;
40 g_platform_initialized_ui = true; 41 g_platform_initialized_ui = true;
41 instance_->InitializeUI(); 42 instance_->InitializeUI();
42 // This is deliberately created after initializing so that the platform can 43 // This is deliberately created after initializing so that the platform can
43 // create its own version of DDM. 44 // create its own version of DDM.
44 DeviceDataManager::CreateInstance(); 45 DeviceDataManager::CreateInstance();
45 } 46 }
46 47
47 // static 48 // static
48 void OzonePlatform::InitializeForGPU() { 49 void OzonePlatform::InitializeForGPU() {
49 CreateInstance(); 50 CreateInstance();
50 if (g_platform_initialized_gpu) 51 if (g_platform_initialized_gpu)
51 return; 52 return;
52 g_platform_initialized_gpu = true; 53 g_platform_initialized_gpu = true;
53 instance_->InitializeGPU(); 54 instance_->InitializeGPU();
54 } 55 }
55 56
56 // static 57 // static
58 void OzonePlatform::InitializeForGpuPostMainLoop() {
59 DCHECK(g_platform_initialized_gpu) << "InitializeForGPU needs to be called "
60 "before InitializeForGpuPostMainLoop";
61 if (!base::MessageLoop::current() ||
62 g_platform_initialized_gpu_post_main_loop)
63 return;
64 g_platform_initialized_gpu_post_main_loop = true;
65
66 instance_->InitializeGpuPostMainLoop();
67 }
68
69 // static
57 OzonePlatform* OzonePlatform::GetInstance() { 70 OzonePlatform* OzonePlatform::GetInstance() {
58 DCHECK(instance_) << "OzonePlatform is not initialized"; 71 DCHECK(instance_) << "OzonePlatform is not initialized";
59 return instance_; 72 return instance_;
60 } 73 }
61 74
62 // static 75 // static
63 void OzonePlatform::CreateInstance() { 76 void OzonePlatform::CreateInstance() {
64 if (!instance_) { 77 if (!instance_) {
65 TRACE_EVENT1("ozone", 78 TRACE_EVENT1("ozone",
66 "OzonePlatform::Initialize", 79 "OzonePlatform::Initialize",
67 "platform", 80 "platform",
68 GetOzonePlatformName()); 81 GetOzonePlatformName());
69 scoped_ptr<OzonePlatform> platform = 82 scoped_ptr<OzonePlatform> platform =
70 PlatformObject<OzonePlatform>::Create(); 83 PlatformObject<OzonePlatform>::Create();
71 84
72 // TODO(spang): Currently need to leak this object. 85 // TODO(spang): Currently need to leak this object.
73 OzonePlatform* pl = platform.release(); 86 OzonePlatform* pl = platform.release();
74 DCHECK_EQ(instance_, pl); 87 DCHECK_EQ(instance_, pl);
75 } 88 }
76 } 89 }
77 90
78 // static 91 // static
79 OzonePlatform* OzonePlatform::instance_; 92 OzonePlatform* OzonePlatform::instance_;
80 93
81 } // namespace ui 94 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/public/ozone_platform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698