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

Unified Diff: ui/ozone/ozone_platform.cc

Issue 291473002: ozone: Initialize a subsystem only if necessary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/ozone_platform.h ('k') | ui/ozone/ozone_platform_list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/ozone_platform.cc
diff --git a/ui/ozone/ozone_platform.cc b/ui/ozone/ozone_platform.cc
index e8199b2ce93f86846235f73b8459b9f650859d5f..281a7516fc1b45d065b7acac48bf86644e6fbaaa 100644
--- a/ui/ozone/ozone_platform.cc
+++ b/ui/ozone/ozone_platform.cc
@@ -18,11 +18,14 @@ namespace ui {
namespace {
// Helper to construct an OzonePlatform by name using the platform list.
-OzonePlatform* CreatePlatform(const std::string& platform_name) {
+OzonePlatform* CreatePlatform(const std::string& platform_name,
+ bool for_gpu) {
// Search for a matching platform in the list.
for (int i = 0; i < kOzonePlatformCount; ++i)
- if (platform_name == kOzonePlatforms[i].name)
- return kOzonePlatforms[i].constructor();
+ if (platform_name == kOzonePlatforms[i].name) {
+ return for_gpu ? kOzonePlatforms[i].ConstructorForGPU()
+ : kOzonePlatforms[i].ConstructorForUI();
+ }
LOG(FATAL) << "Invalid ozone platform: " << platform_name;
return NULL; // not reached
@@ -40,31 +43,37 @@ std::string GetPlatformName() {
} // namespace
-OzonePlatform::OzonePlatform() {}
+OzonePlatform::OzonePlatform() {
+ CHECK(!instance_) << "There should only be a single OzonePlatform.";
+ instance_ = this;
+}
OzonePlatform::~OzonePlatform() {
- gfx::SurfaceFactoryOzone::SetInstance(NULL);
- ui::EventFactoryOzone::SetInstance(NULL);
- ui::CursorFactoryOzone::SetInstance(NULL);
+ CHECK_EQ(instance_, this);
+ instance_ = NULL;
}
// static
-void OzonePlatform::Initialize() {
+void OzonePlatform::InitializeForUI() {
if (instance_)
return;
std::string platform = GetPlatformName();
-
- TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform);
-
- instance_ = CreatePlatform(platform);
-
- // Inject ozone interfaces.
- gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone());
- ui::EventFactoryOzone::SetInstance(instance_->GetEventFactoryOzone());
+ TRACE_EVENT1("ozone", "OzonePlatform::InitializeForUI", "platform", platform);
+ CreatePlatform(platform, false);
ui::InputMethodContextFactoryOzone::SetInstance(
kalyank 2014/05/15 19:21:45 shouldn't we do the same with this. It should be s
sadrul 2014/05/15 19:27:24 I wanted to, but the SetInstance() here is for the
instance_->GetInputMethodContextFactoryOzone());
- ui::CursorFactoryOzone::SetInstance(instance_->GetCursorFactoryOzone());
+}
+
+// static
+void OzonePlatform::InitializeForGPU() {
+ if (instance_)
+ return;
+
+ std::string platform = GetPlatformName();
+ TRACE_EVENT1("ozone", "OzonePlatform::InitializeForGPU",
+ "platform", platform);
+ CreatePlatform(platform, true);
}
// static
« no previous file with comments | « ui/ozone/ozone_platform.h ('k') | ui/ozone/ozone_platform_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698