summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorspang@chromium.org <spang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 05:37:26 +0000
committerspang@chromium.org <spang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 05:37:26 +0000
commit4814ed220f72cdf35d40e22b0afa66d8cf1ee044 (patch)
tree1e0b11916a5075275f2951e84b94b9288c11c90f /ui
parent16511ed533ddaae976e9a9ce81b40342626bc5f3 (diff)
downloadchromium_src-4814ed220f72cdf35d40e22b0afa66d8cf1ee044.zip
chromium_src-4814ed220f72cdf35d40e22b0afa66d8cf1ee044.tar.gz
chromium_src-4814ed220f72cdf35d40e22b0afa66d8cf1ee044.tar.bz2
Implement --ozone-platform flag to select OzonePlatform implementation at runtime
This provides a way to select an ozone implementation to use at runtime. Each ozone implementation adds its name to the ozone_platforms GYP variable, and we take care of parsing the flag value and configuring chromium to use that implementation during initialization. To support external ports, we generate the list of enabled platforms at build time. The list is a static array that maps values of the --ozone_platform flag to a constructor function for an OzonePlatform subclass. At runtime, we call the constructor for platform specified on the command-line and use it to provide implementations of the various ozone interfaces (SurfaceFactoryOzone, EventFactoryOzone). Review URL: https://codereview.chromium.org/44053005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rwxr-xr-xui/ozone/generate_ozone_platform_list.py101
-rw-r--r--ui/ozone/ozone.gyp45
-rw-r--r--ui/ozone/ozone_platform.cc31
-rw-r--r--ui/ozone/ozone_platform.h3
-rw-r--r--ui/ozone/ozone_platform_list.h25
-rw-r--r--ui/ozone/ozone_switches.cc3
-rw-r--r--ui/ozone/ozone_switches.h2
-rw-r--r--ui/ozone/platform/dri/ozone_platform_dri.cc2
-rw-r--r--ui/ozone/platform/dri/ozone_platform_dri.h3
-rw-r--r--ui/ozone/platform/test/ozone_platform_test.cc2
-rw-r--r--ui/ozone/platform/test/ozone_platform_test.h3
11 files changed, 212 insertions, 8 deletions
diff --git a/ui/ozone/generate_ozone_platform_list.py b/ui/ozone/generate_ozone_platform_list.py
new file mode 100755
index 0000000..df85a1e
--- /dev/null
+++ b/ui/ozone/generate_ozone_platform_list.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Code generator for Ozone platform list.
+
+This script takes as arguments a list of platform names and generates a C++
+source file containing a list of those platforms. Each list entry contains the
+name and a function pointer to the initializer for that platform.
+
+Example Output: ./generate_ozone_platform_list.py --default wayland dri wayland
+
+ #include "ui/ozone/ozone_platform_list.h"
+
+ namespace ui {
+
+ OzonePlatform* CreateOzonePlatformDri();
+ OzonePlatform* CreateOzonePlatformWayland();
+
+ const OzonePlatformListEntry kOzonePlatforms[] = {
+ { "wayland", &CreateOzonePlatformWayland },
+ { "dri", &CreateOzonePlatformDri },
+ };
+
+ const int kOzonePlatformCount = 2;
+
+ } // namespace ui
+"""
+
+import optparse
+import os
+import collections
+import re
+import sys
+import string
+
+
+def GetConstructorName(name):
+ """Determine name of static constructor function from platform name.
+
+ We just capitalize the platform name and prepend "CreateOzonePlatform".
+ """
+
+ return 'CreateOzonePlatform' + string.capitalize(name)
+
+
+def GeneratePlatformList(out, platforms):
+ """Generate static array containing a list of ozone platforms."""
+
+ out.write('#include "ui/ozone/ozone_platform_list.h"\n')
+ out.write('\n')
+
+ out.write('namespace ui {\n')
+ out.write('\n')
+
+ # Prototypes for platform initializers.
+ for platform in platforms:
+ out.write('OzonePlatform* %s();\n' % GetConstructorName(platform))
+ out.write('\n')
+
+ # List of platform names and initializers.
+ out.write('const OzonePlatformListEntry kOzonePlatforms[] = {\n')
+ for platform in platforms:
+ out.write(' { "%s", &%s },\n' % (platform, GetConstructorName(platform)))
+ out.write('};\n')
+ out.write('\n')
+
+ out.write('const int kOzonePlatformCount = %d;\n' % len(platforms))
+ out.write('\n')
+
+ out.write('} // namespace ui\n')
+
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--output_file')
+ parser.add_option('--default')
+ options, platforms = parser.parse_args(argv)
+
+ # Write to standard output or file specified by --output_file.
+ out = sys.stdout
+ if options.output_file:
+ out = open(options.output_file, 'wb')
+
+ # Reorder the platforms when --default is specified.
+ # The default platform must appear first in the platform list.
+ if options.default and options.default in platforms:
+ platforms.remove(options.default)
+ platforms.insert(0, options.default)
+
+ GeneratePlatformList(out, platforms)
+
+ if options.output_file:
+ out.close()
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
diff --git a/ui/ozone/ozone.gyp b/ui/ozone/ozone.gyp
index 32008b7..ee5db69 100644
--- a/ui/ozone/ozone.gyp
+++ b/ui/ozone/ozone.gyp
@@ -5,6 +5,7 @@
{
'variables': {
'chromium_code': 1,
+ 'external_ozone_platforms': [],
'external_ozone_platform_files': [],
'external_ozone_platform_deps': [],
},
@@ -22,7 +23,14 @@
'defines': [
'OZONE_IMPLEMENTATION',
],
+ 'variables': {
+ 'platform_list_file': '<(SHARED_INTERMEDIATE_DIR)/ui/ozone/ozone_platform_list.cc',
+ 'ozone_platforms': [
+ '<@(external_ozone_platforms)',
+ ],
+ },
'sources': [
+ '<(platform_list_file)',
'ozone_platform.cc',
'ozone_platform.h',
'ozone_switches.cc',
@@ -33,13 +41,46 @@
'platform/test/ozone_platform_test.h',
'<@(external_ozone_platform_files)',
],
+ 'actions': [
+ {
+ 'action_name': 'generate_ozone_platform_list',
+ 'variables': {
+ 'generator_path': 'generate_ozone_platform_list.py',
+ },
+ 'inputs': [
+ '<(generator_path)',
+ ],
+ 'outputs': [
+ '<(platform_list_file)',
+ ],
+ 'action': [
+ 'python',
+ '<(generator_path)',
+ '--output_file=<(platform_list_file)',
+ '--default=<(ozone_platform)',
+ '<@(ozone_platforms)',
+ ],
+ },
+ ],
'conditions': [
- ['ozone_platform != "dri"', {
+ ['<(ozone_platform_dri)==1', {
+ 'variables': {
+ 'ozone_platforms': [
+ 'dri'
+ ]
+ }
+ }, { # ozone_platform_dri==0
'sources/': [
['exclude', '^platform/dri/'],
]
}],
- ['ozone_platform != "test"', {
+ ['<(ozone_platform_test)==1', {
+ 'variables': {
+ 'ozone_platforms': [
+ 'test'
+ ],
+ }
+ }, { # ozone_platform_test==0
'sources/': [
['exclude', '^platform/test/'],
]
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());
diff --git a/ui/ozone/ozone_platform.h b/ui/ozone/ozone_platform.h
index 2426b23..519d8b2 100644
--- a/ui/ozone/ozone_platform.h
+++ b/ui/ozone/ozone_platform.h
@@ -47,9 +47,6 @@ class OZONE_EXPORT OzonePlatform {
DISALLOW_COPY_AND_ASSIGN(OzonePlatform);
};
-// Hook to be provided by the built-in default implementation.
-OzonePlatform* CreateDefaultOzonePlatform();
-
} // namespace ui
#endif // UI_OZONE_OZONE_PLATFORM_H_
diff --git a/ui/ozone/ozone_platform_list.h b/ui/ozone/ozone_platform_list.h
new file mode 100644
index 0000000..2689c25
--- /dev/null
+++ b/ui/ozone/ozone_platform_list.h
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_OZONE_OZONE_PLATFORM_LIST_H_
+#define UI_OZONE_OZONE_PLATFORM_LIST_H_
+
+namespace ui {
+
+class OzonePlatform;
+
+typedef OzonePlatform* (*OzonePlatformConstructor)();
+
+struct OzonePlatformListEntry {
+ const char* name;
+ OzonePlatformConstructor constructor;
+};
+
+extern const OzonePlatformListEntry kOzonePlatforms[];
+
+extern const int kOzonePlatformCount;
+
+} // namespace ui
+
+#endif // UI_OZONE_OZONE_PLATFORM_LIST_H_
diff --git a/ui/ozone/ozone_switches.cc b/ui/ozone/ozone_switches.cc
index bd30dee..3c117d0 100644
--- a/ui/ozone/ozone_switches.cc
+++ b/ui/ozone/ozone_switches.cc
@@ -6,6 +6,9 @@
namespace switches {
+// Specify ozone platform implementation to use.
+const char kOzonePlatform[] = "ozone-platform";
+
// Specify location for image dumps.
const char kOzoneDumpFile[] = "ozone-dump-file";
diff --git a/ui/ozone/ozone_switches.h b/ui/ozone/ozone_switches.h
index 7aa18af..3204fa7 100644
--- a/ui/ozone/ozone_switches.h
+++ b/ui/ozone/ozone_switches.h
@@ -10,6 +10,8 @@
namespace switches {
+OZONE_EXPORT extern const char kOzonePlatform[];
+
OZONE_EXPORT extern const char kOzoneDumpFile[];
} // namespace switches
diff --git a/ui/ozone/platform/dri/ozone_platform_dri.cc b/ui/ozone/platform/dri/ozone_platform_dri.cc
index 3d248b6..9feb9a2 100644
--- a/ui/ozone/platform/dri/ozone_platform_dri.cc
+++ b/ui/ozone/platform/dri/ozone_platform_dri.cc
@@ -20,6 +20,6 @@ ui::EventFactoryOzone* OzonePlatformDri::GetEventFactoryOzone() {
return &event_factory_ozone_;
}
-OzonePlatform* CreateDefaultOzonePlatform() { return new OzonePlatformDri; }
+OzonePlatform* CreateOzonePlatformDri() { return new OzonePlatformDri; }
} // namespace ui
diff --git a/ui/ozone/platform/dri/ozone_platform_dri.h b/ui/ozone/platform/dri/ozone_platform_dri.h
index 9c040e9..95bae8c 100644
--- a/ui/ozone/platform/dri/ozone_platform_dri.h
+++ b/ui/ozone/platform/dri/ozone_platform_dri.h
@@ -30,6 +30,9 @@ class OzonePlatformDri : public OzonePlatform {
DISALLOW_COPY_AND_ASSIGN(OzonePlatformDri);
};
+// Constructor hook for use in ozone_platform_list.cc
+OzonePlatform* CreateOzonePlatformDri();
+
} // namespace ui
#endif // UI_OZONE_PLATFORM_DRI_OZONE_PLATFORM_DRI_H_
diff --git a/ui/ozone/platform/test/ozone_platform_test.cc b/ui/ozone/platform/test/ozone_platform_test.cc
index 6fc9beb..860837e 100644
--- a/ui/ozone/platform/test/ozone_platform_test.cc
+++ b/ui/ozone/platform/test/ozone_platform_test.cc
@@ -24,7 +24,7 @@ ui::EventFactoryOzone* OzonePlatformTest::GetEventFactoryOzone() {
return &event_factory_ozone_;
}
-OzonePlatform* CreateDefaultOzonePlatform() {
+OzonePlatform* CreateOzonePlatformTest() {
CommandLine* cmd = CommandLine::ForCurrentProcess();
base::FilePath location = base::FilePath("/dev/null");
if (cmd->HasSwitch(switches::kOzoneDumpFile))
diff --git a/ui/ozone/platform/test/ozone_platform_test.h b/ui/ozone/platform/test/ozone_platform_test.h
index 9218312..c86aec3 100644
--- a/ui/ozone/platform/test/ozone_platform_test.h
+++ b/ui/ozone/platform/test/ozone_platform_test.h
@@ -30,6 +30,9 @@ class OzonePlatformTest : public OzonePlatform {
DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest);
};
+// Constructor hook for use in ozone_platform_list.cc
+OzonePlatform* CreateOzonePlatformTest();
+
} // namespace ui
#endif // UI_OZONE_PLATFORM_TEST_OZONE_PLATFORM_TEST_H_