This source file includes following definitions.
- CreatePlatform
- GetPlatformName
- Initialize
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "ui/base/cursor/ozone/cursor_factory_ozone.h"
#include "ui/ozone/ozone_platform.h"
#include "ui/ozone/ozone_platform_list.h"
#include "ui/ozone/ozone_switches.h"
namespace ui {
namespace {
OzonePlatform* CreatePlatform(const std::string& platform_name) {
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;
}
std::string GetPlatformName() {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) &&
kOzonePlatformCount > 0)
return kOzonePlatforms[0].name;
return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kOzonePlatform);
}
}
OzonePlatform::OzonePlatform() {}
OzonePlatform::~OzonePlatform() {
gfx::SurfaceFactoryOzone::SetInstance(NULL);
ui::EventFactoryOzone::SetInstance(NULL);
ui::CursorFactoryOzone::SetInstance(NULL);
}
void OzonePlatform::Initialize() {
if (instance_)
return;
std::string platform = GetPlatformName();
TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform);
instance_ = CreatePlatform(platform);
gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone());
ui::EventFactoryOzone::SetInstance(instance_->GetEventFactoryOzone());
ui::InputMethodContextFactoryOzone::SetInstance(
instance_->GetInputMethodContextFactoryOzone());
ui::CursorFactoryOzone::SetInstance(instance_->GetCursorFactoryOzone());
}
OzonePlatform* OzonePlatform::instance_;
}