| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/debug/trace_event.h" |
| 6 #include "base/logging.h" | 7 #include "base/logging.h" |
| 7 #include "ui/ozone/ozone_platform.h" | 8 #include "ui/ozone/ozone_platform.h" |
| 8 #include "ui/ozone/ozone_platform_list.h" | 9 #include "ui/ozone/ozone_platform_list.h" |
| 9 #include "ui/ozone/ozone_switches.h" | 10 #include "ui/ozone/ozone_switches.h" |
| 10 | 11 |
| 11 namespace ui { | 12 namespace ui { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Helper to construct an OzonePlatform by name using the platform list. | 16 // Helper to construct an OzonePlatform by name using the platform list. |
| 16 OzonePlatform* CreatePlatform(const std::string& platform_name) { | 17 OzonePlatform* CreatePlatform(const std::string& platform_name) { |
| 17 // The first platform is the defualt. | 18 // Search for a matching platform in the list. |
| 18 if (platform_name == "default" && kOzonePlatformCount > 0) | |
| 19 return kOzonePlatforms[0].constructor(); | |
| 20 | |
| 21 // Otherwise, search for a matching platform in the list. | |
| 22 for (int i = 0; i < kOzonePlatformCount; ++i) | 19 for (int i = 0; i < kOzonePlatformCount; ++i) |
| 23 if (platform_name == kOzonePlatforms[i].name) | 20 if (platform_name == kOzonePlatforms[i].name) |
| 24 return kOzonePlatforms[i].constructor(); | 21 return kOzonePlatforms[i].constructor(); |
| 25 | 22 |
| 26 LOG(FATAL) << "Invalid ozone platform: " << platform_name; | 23 LOG(FATAL) << "Invalid ozone platform: " << platform_name; |
| 27 return NULL; // not reached | 24 return NULL; // not reached |
| 28 } | 25 } |
| 29 | 26 |
| 30 // Returns the name of the platform to use (value of --ozone-platform flag). | 27 // Returns the name of the platform to use (value of --ozone-platform flag). |
| 31 std::string GetRequestedPlatform() { | 28 std::string GetPlatformName() { |
| 32 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform)) | 29 // The first platform is the default. |
| 33 return "default"; | 30 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) && |
| 31 kOzonePlatformCount > 0) |
| 32 return kOzonePlatforms[0].name; |
| 34 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 33 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 35 switches::kOzonePlatform); | 34 switches::kOzonePlatform); |
| 36 } | 35 } |
| 37 | 36 |
| 38 } // namespace | 37 } // namespace |
| 39 | 38 |
| 40 OzonePlatform::OzonePlatform() {} | 39 OzonePlatform::OzonePlatform() {} |
| 41 | 40 |
| 42 OzonePlatform::~OzonePlatform() { | 41 OzonePlatform::~OzonePlatform() { |
| 43 gfx::SurfaceFactoryOzone::SetInstance(NULL); | 42 gfx::SurfaceFactoryOzone::SetInstance(NULL); |
| 44 ui::EventFactoryOzone::SetInstance(NULL); | 43 ui::EventFactoryOzone::SetInstance(NULL); |
| 45 } | 44 } |
| 46 | 45 |
| 47 // static | 46 // static |
| 48 void OzonePlatform::Initialize() { | 47 void OzonePlatform::Initialize() { |
| 49 if (instance_) | 48 if (instance_) |
| 50 return; | 49 return; |
| 51 | 50 |
| 52 instance_ = CreatePlatform(GetRequestedPlatform()); | 51 std::string platform = GetPlatformName(); |
| 52 |
| 53 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform); |
| 54 |
| 55 instance_ = CreatePlatform(platform); |
| 53 | 56 |
| 54 // Inject ozone interfaces. | 57 // Inject ozone interfaces. |
| 55 gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone()); | 58 gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone()); |
| 56 ui::EventFactoryOzone::SetInstance(instance_->GetEventFactoryOzone()); | 59 ui::EventFactoryOzone::SetInstance(instance_->GetEventFactoryOzone()); |
| 57 ui::InputMethodContextFactoryOzone::SetInstance( | 60 ui::InputMethodContextFactoryOzone::SetInstance( |
| 58 instance_->GetInputMethodContextFactoryOzone()); | 61 instance_->GetInputMethodContextFactoryOzone()); |
| 59 } | 62 } |
| 60 | 63 |
| 61 // static | 64 // static |
| 62 OzonePlatform* OzonePlatform::instance_; | 65 OzonePlatform* OzonePlatform::instance_; |
| 63 | 66 |
| 64 } // namespace ui | 67 } // namespace ui |
| OLD | NEW |