diff options
Diffstat (limited to 'ui/ozone/ozone_platform.cc')
-rw-r--r-- | ui/ozone/ozone_platform.cc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/ui/ozone/ozone_platform.cc b/ui/ozone/ozone_platform.cc index 9715e13..a084005 100644 --- a/ui/ozone/ozone_platform.cc +++ b/ui/ozone/ozone_platform.cc @@ -5,9 +5,38 @@ #include "base/command_line.h" #include "base/logging.h" #include "ui/ozone/ozone_platform.h" +#include "ui/ozone/ozone_platform_list.h" +#include "ui/ozone/ozone_switches.h" namespace ui { +namespace { + +// Helper to construct an OzonePlatform by name using the platform list. +OzonePlatform* CreatePlatform(const std::string& platform_name) { + // The first platform is the defualt. + if (platform_name == "default" && kOzonePlatformCount > 0) + return kOzonePlatforms[0].constructor(); + + // Otherwise, 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(); + + LOG(FATAL) << "Invalid ozone platform: " << platform_name; + return NULL; // not reached +} + +// Returns the name of the platform to use (value of --ozone-platform flag). +std::string GetRequestedPlatform() { + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform)) + return "default"; + return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kOzonePlatform); +} + +} // namespace + OzonePlatform::OzonePlatform() {} OzonePlatform::~OzonePlatform() { @@ -20,7 +49,7 @@ void OzonePlatform::Initialize() { if (instance_) return; - instance_ = CreateDefaultOzonePlatform(); + instance_ = CreatePlatform(GetRequestedPlatform()); // Inject ozone interfaces. gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone()); |