Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 bool g_platform_initialized_gpu_post_main_loop = false; | |
| 20 | 21 |
| 21 } | 22 } |
| 22 | 23 |
| 23 OzonePlatform::OzonePlatform() { | 24 OzonePlatform::OzonePlatform() { |
| 24 DCHECK(!instance_) << "There should only be a single OzonePlatform."; | 25 DCHECK(!instance_) << "There should only be a single OzonePlatform."; |
| 25 instance_ = this; | 26 instance_ = this; |
| 26 g_platform_initialized_ui = false; | 27 g_platform_initialized_ui = false; |
| 27 g_platform_initialized_gpu = false; | 28 g_platform_initialized_gpu = false; |
| 29 g_platform_initialized_gpu_post_main_loop = false; | |
| 28 } | 30 } |
| 29 | 31 |
| 30 OzonePlatform::~OzonePlatform() { | 32 OzonePlatform::~OzonePlatform() { |
| 31 DCHECK_EQ(instance_, this); | 33 DCHECK_EQ(instance_, this); |
| 32 instance_ = NULL; | 34 instance_ = NULL; |
| 33 } | 35 } |
| 34 | 36 |
| 35 // static | 37 // static |
| 36 void OzonePlatform::InitializeForUI() { | 38 void OzonePlatform::InitializeForUI() { |
| 37 CreateInstance(); | 39 CreateInstance(); |
| 38 if (g_platform_initialized_ui) | 40 if (g_platform_initialized_ui) |
| 39 return; | 41 return; |
| 40 g_platform_initialized_ui = true; | 42 g_platform_initialized_ui = true; |
| 41 instance_->InitializeUI(); | 43 instance_->InitializeUI(); |
| 42 // This is deliberately created after initializing so that the platform can | 44 // This is deliberately created after initializing so that the platform can |
| 43 // create its own version of DDM. | 45 // create its own version of DDM. |
| 44 DeviceDataManager::CreateInstance(); | 46 DeviceDataManager::CreateInstance(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 // static | 49 // static |
| 48 void OzonePlatform::InitializeForGPU() { | 50 void OzonePlatform::InitializeForGPU() { |
| 49 CreateInstance(); | 51 CreateInstance(); |
| 50 if (g_platform_initialized_gpu) | 52 if (g_platform_initialized_gpu) |
| 51 return; | 53 return; |
| 52 g_platform_initialized_gpu = true; | 54 g_platform_initialized_gpu = true; |
| 53 instance_->InitializeGPU(); | 55 instance_->InitializeGPU(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 // static | 58 // static |
| 59 void OzonePlatform::InitializeForGPUPostMainLoop() { | |
| 60 CHECK(instance_ && g_platform_initialized_gpu) | |
| 61 << "OzonePlatform is not initialized"; | |
|
spang
2015/03/31 20:58:49
DCHECK per the style guide (it says never use CHEC
vignatti (out of this project)
2015/04/01 16:26:11
Done.
| |
| 62 | |
| 63 if (g_platform_initialized_gpu_post_main_loop) | |
| 64 return; | |
| 65 g_platform_initialized_gpu_post_main_loop = true; | |
| 66 | |
| 67 instance_->InitializeGPUPostMainLoop(); | |
| 68 } | |
| 69 | |
| 70 // static | |
| 57 OzonePlatform* OzonePlatform::GetInstance() { | 71 OzonePlatform* OzonePlatform::GetInstance() { |
| 58 DCHECK(instance_) << "OzonePlatform is not initialized"; | 72 DCHECK(instance_) << "OzonePlatform is not initialized"; |
| 59 return instance_; | 73 return instance_; |
| 60 } | 74 } |
| 61 | 75 |
| 62 // static | 76 // static |
| 63 void OzonePlatform::CreateInstance() { | 77 void OzonePlatform::CreateInstance() { |
| 64 if (!instance_) { | 78 if (!instance_) { |
| 65 TRACE_EVENT1("ozone", | 79 TRACE_EVENT1("ozone", |
| 66 "OzonePlatform::Initialize", | 80 "OzonePlatform::Initialize", |
| 67 "platform", | 81 "platform", |
| 68 GetOzonePlatformName()); | 82 GetOzonePlatformName()); |
| 69 scoped_ptr<OzonePlatform> platform = | 83 scoped_ptr<OzonePlatform> platform = |
| 70 PlatformObject<OzonePlatform>::Create(); | 84 PlatformObject<OzonePlatform>::Create(); |
| 71 | 85 |
| 72 // TODO(spang): Currently need to leak this object. | 86 // TODO(spang): Currently need to leak this object. |
| 73 OzonePlatform* pl = platform.release(); | 87 OzonePlatform* pl = platform.release(); |
| 74 DCHECK_EQ(instance_, pl); | 88 DCHECK_EQ(instance_, pl); |
| 75 } | 89 } |
| 76 } | 90 } |
| 77 | 91 |
| 78 // static | 92 // static |
| 79 OzonePlatform* OzonePlatform::instance_; | 93 OzonePlatform* OzonePlatform::instance_; |
| 80 | 94 |
| 81 } // namespace ui | 95 } // namespace ui |
| OLD | NEW |