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