Chromium Code Reviews| 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 |