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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/debug/trace_event.h"
7 #include "base/logging.h"
8 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
9 #include "ui/ozone/ozone_platform.h"
10 #include "ui/ozone/ozone_platform_list.h"
11 #include "ui/ozone/ozone_switches.h"
17 // Helper to construct an OzonePlatform by name using the platform list.
18 OzonePlatform
* CreatePlatform(const std::string
& platform_name
) {
19 // Search for a matching platform in the list.
20 for (int i
= 0; i
< kOzonePlatformCount
; ++i
)
21 if (platform_name
== kOzonePlatforms
[i
].name
)
22 return kOzonePlatforms
[i
].constructor();
24 LOG(FATAL
) << "Invalid ozone platform: " << platform_name
;
25 return NULL
; // not reached
28 // Returns the name of the platform to use (value of --ozone-platform flag).
29 std::string
GetPlatformName() {
30 // The first platform is the default.
31 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform
) &&
32 kOzonePlatformCount
> 0)
33 return kOzonePlatforms
[0].name
;
34 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
35 switches::kOzonePlatform
);
40 OzonePlatform::OzonePlatform() {}
42 OzonePlatform::~OzonePlatform() {
43 gfx::SurfaceFactoryOzone::SetInstance(NULL
);
44 ui::EventFactoryOzone::SetInstance(NULL
);
45 ui::CursorFactoryOzone::SetInstance(NULL
);
49 void OzonePlatform::Initialize() {
53 std::string platform
= GetPlatformName();
55 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform
);
57 instance_
= CreatePlatform(platform
);
59 // Inject ozone interfaces.
60 gfx::SurfaceFactoryOzone::SetInstance(instance_
->GetSurfaceFactoryOzone());
61 ui::EventFactoryOzone::SetInstance(instance_
->GetEventFactoryOzone());
62 ui::InputMethodContextFactoryOzone::SetInstance(
63 instance_
->GetInputMethodContextFactoryOzone());
64 ui::CursorFactoryOzone::SetInstance(instance_
->GetCursorFactoryOzone());
68 OzonePlatform
* OzonePlatform::instance_
;