Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: ui/ozone/ozone_platform.cc

Issue 275263002: [wip] ozonex: X11 backend for ozone. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ozone/ozone.gyp ('k') | ui/ozone/platform/dri/dri_surface_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/trace_event.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_native_library.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_restrictions.h"
8 #include "ui/ozone/ozone_platform.h" 11 #include "ui/ozone/ozone_platform.h"
9 #include "ui/ozone/ozone_platform_list.h" 12 #include "ui/ozone/ozone_platform_list.h"
10 #include "ui/ozone/ozone_switches.h" 13 #include "ui/ozone/ozone_switches.h"
11 14
12 namespace ui { 15 namespace ui {
13 16
14 namespace { 17 namespace {
15 18
16 bool g_platform_initialized_ui = false; 19 bool g_platform_initialized_ui = false;
17 bool g_platform_initialized_gpu = false; 20 bool g_platform_initialized_gpu = false;
18 21
19 // Helper to construct an OzonePlatform by name using the platform list. 22 // Helper to construct an OzonePlatform by name using the platform list.
20 OzonePlatform* CreatePlatform(const std::string& platform_name) { 23 OzonePlatform* CreatePlatform(const std::string& platform_name) {
21 // Search for a matching platform in the list. 24 // Search for a matching platform in the list.
22 for (int i = 0; i < kOzonePlatformCount; ++i) 25 for (int i = 0; i < kOzonePlatformCount; ++i) {
23 if (platform_name == kOzonePlatforms[i].name) 26 if (platform_name == kOzonePlatforms[i].name)
24 return kOzonePlatforms[i].constructor(); 27 return kOzonePlatforms[i].constructor();
28 }
25 29
26 LOG(FATAL) << "Invalid ozone platform: " << platform_name; 30 // Try to load the module for the paltform.
31 base::ThreadRestrictions::ScopedAllowIO allow_io;
32 base::NativeLibraryLoadError load_error;
33 base::string16 platform_module_path =
34 base::GetNativeLibraryName(base::ASCIIToUTF16(platform_name));
35 const char kPlatformConstructor[] = "CreateOzonePlatform";
36 base::NativeLibrary platform_module = base::LoadNativeLibrary(
37 base::FilePath(base::UTF16ToASCII(platform_module_path)), &load_error);
38 if (!platform_module) {
39 LOG(FATAL) << "Failed to load library (error: " << load_error.ToString()
40 << ")";
41 } else {
42 OzonePlatformConstructor platform_constructor =
43 reinterpret_cast<OzonePlatformConstructor>(
44 base::GetFunctionPointerFromNativeLibrary(platform_module,
45 kPlatformConstructor));
46 if (platform_constructor) {
47 return platform_constructor();
48 } else {
49 LOG(FATAL) << "Module " << platform_module_path
50 << " does not have the constructor function ("
51 << kPlatformConstructor << ") to initialize the platform.";
52 }
53 }
54
55 NOTREACHED();
27 return NULL; // not reached 56 return NULL; // not reached
28 } 57 }
29 58
30 // Returns the name of the platform to use (value of --ozone-platform flag). 59 // Returns the name of the platform to use (value of --ozone-platform flag).
31 std::string GetPlatformName() { 60 std::string GetPlatformName() {
32 // The first platform is the default. 61 // The first platform is the default.
33 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) && 62 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) &&
34 kOzonePlatformCount > 0) 63 kOzonePlatformCount > 0)
35 return kOzonePlatforms[0].name; 64 return kOzonePlatforms[0].name;
36 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 65 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 std::string platform = GetPlatformName(); 110 std::string platform = GetPlatformName();
82 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform); 111 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform);
83 CreatePlatform(platform); 112 CreatePlatform(platform);
84 } 113 }
85 } 114 }
86 115
87 // static 116 // static
88 OzonePlatform* OzonePlatform::instance_; 117 OzonePlatform* OzonePlatform::instance_;
89 118
90 } // namespace ui 119 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/ozone.gyp ('k') | ui/ozone/platform/dri/dri_surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698