blob: 2da5232bba9f405790cc8dc8f2a92a15239fa09f [file] [log] [blame] [view]
fwang8491a612016-10-31 20:59:451# Ozone Overview
2
3Ozone is a platform abstraction layer beneath the Aura window system that is
4used for low level input and graphics. Once complete, the abstraction will
5support underlying systems ranging from embedded SoC targets to new
6X11-alternative window systems on Linux such as Wayland or Mir to bring up Aura
7Chromium by providing an implementation of the platform interface.
8
9## Guiding Principles
10
11Our goal is to enable chromium to be used in a wide variety of projects by
12making porting to new platforms easy. To support this goal, ozone follows the
13following principles:
14
151. **Interfaces, not ifdefs**. Differences between platforms are handled by
16 calling a platform-supplied object through an interface instead of using
17 conditional compilation. Platform internals remain encapsulated, and the
18 public interface acts as a firewall between the platform-neutral upper
19 layers (aura, blink, content, etc) and the platform-specific lower layers.
20 The platform layer is relatively centralized to minimize the number of
21 places ports need to add code.
222. **Flexible interfaces**. The platform interfaces should encapsulate just what
23 chrome needs from the platform, with minimal constraints on the platform's
24 implementation as well as minimal constraints on usage from upper layers. An
25 overly prescriptive interface is less useful for porting because fewer ports
26 will be able to use it unmodified. Another way of stating is that the
27 platform layer should provide mechanism, not policy.
283. **Runtime binding of platforms**. Avoiding conditional compilation in the
29 upper layers allows us to build multiple platforms into one binary and bind
30 them at runtime. We allow this and provide a command-line flag to select a
31 platform (`--ozone-platform`) if multiple are enabled. Each platform has a
32 unique build define (e.g. `ozone_platform_foo`) that can be turned on or off
33 independently.
344. **Easy out-of-tree platforms**. Most ports begin as forks. Some of them
35 later merge their code upstream, others will have an extended life out of
36 tree. This is OK, and we should make this process easy to encourage ports,
37 and to encourage frequent gardening of chromium changes into the downstream
38 project. If gardening an out-of-tree port is hard, then those projects will
39 simply ship outdated and potentially insecure chromium-derived code to users.
40 One way we support these projects is by providing a way to inject additional
41 platforms into the build by only patching one `ozone_extra.gni` file.
42
43## Ozone Platform Interface
44
45Ozone moves platform-specific code behind the following interfaces:
46
47* `PlatformWindow` represents a window in the windowing system underlying
48 chrome. Interaction with the windowing system (resize, maximize, close, etc)
49 as well as dispatch of input events happens via this interface. Under aura, a
50 `PlatformWindow` corresponds to a `WindowTreeHost`. Under mojo, it corresponds
51 to a `NativeViewport`. On bare hardware, the underlying windowing system is
52 very simple and a platform window corresponds to a physical display.
53* `SurfaceFactoryOzone` is used to create surfaces for the Chrome compositor to
54 paint on using EGL/GLES2 or Skia.
55* `GpuPlatformSupportHost` provides the platform code
56 access to IPC between the browser & GPU processes. Some platforms need this
57 to provide additional services in the GPU process such as display
58 configuration.
59* `CursorFactoryOzone` is used to load & set platform cursors.
60* `OverlayManagerOzone` is used to manage overlays.
61* `InputController` allows to control input devices such as keyboard, mouse or
62 touchpad.
63* `SystemInputInjector` converts input into events and injects them to the
64 Ozone platform.
65* `NativeDisplayDelegate` is used to support display configuration & hotplug.
66
67## Ozone in Chromium
68
69Our implementation of Ozone required changes concentrated in these areas:
70
71* Cleaning up extensive assumptions about use of X11 throughout the tree,
72 protecting this code behind the `USE_X11` ifdef, and adding a new `USE_OZONE`
73 path that works in a relatively platform-neutral way by delegating to the
74 interfaces described above.
75* a `WindowTreeHostOzone` to send events into Aura and participate in display
76 management on the host system, and
77* an Ozone-specific flavor of `GLSurfaceEGL` which delegates allocation of
78 accelerated surfaces and refresh syncing to the provided implementation of
79 `SurfaceFactoryOzone`.
80
81## Porting with Ozone
82
83Users of the Ozone abstraction need to do the following, at minimum:
84
85* Write a subclass of `PlatformWindow`. This class (I'll call it
86 `PlatformWindowImpl`) is responsible for window system integration. It can
87 use `MessagePumpLibevent` to poll for events from file descriptors and then
88 invoke `PlatformWindowDelegate::DispatchEvent` to dispatch each event.
89* Write a subclass of `SurfaceFactoryOzone` that handles allocating accelerated
90 surfaces. I'll call this `SurfaceFactoryOzoneImpl`.
91* Write a subclass of `CursorFactoryOzone` to manage cursors, or use the
92 `BitmapCursorFactoryOzone` implementation if only bitmap cursors need to be
93 supported.
94* Write a subclass of `OverlayManagerOzone` or just use `StubOverlayManager` if
95 your platform does not support overlays.
96* Write a subclass of `NativeDisplayDelegate` if necessary or just use
97 `FakeDisplayDelegate`.
98* Write a subclass of `GpuPlatformSupportHost` or just use
99 `StubGpuPlatformSupportHost`.
100* Write a subclass of `InputController` or just use `StubInputController`.
101* Write a subclass of `SystemInputInjector` if necessary.
102* Write a subclass of `OzonePlatform` that owns instances of
103 the above subclasses and provide a static constructor function for these
104 objects. This constructor will be called when
105 your platform is selected and the returned objects will be used to provide
106 implementations of all the ozone platform interfaces.
107 If your platform does not need some of the interfaces then you can just
108 return a `Stub*` instance or a `nullptr`.
109
110## Adding an Ozone Platform to the build (instructions for out-of-tree ports)
111
112The recommended way to add your platform to the build is as follows. This walks
113through creating a new ozone platform called `foo`.
114
1151. Fork `chromium/src.git`.
1162. Add your implementation in `ui/ozone/platform/` alongside internal platforms.
1173. Patch `ui/ozone/ozone_extra.gni` to add your `foo` platform.
118
119## Building with Ozone
120
derat817105082017-02-22 17:57:55121### Chrome OS - ([waterfall](https://build.chromium.org/p/chromium.chromiumos/waterfall?builder=Linux+ChromiumOS+Ozone+Builder&builder=Linux+ChromiumOS+Ozone+Tests+%281%29&builder=Linux+ChromiumOS+Ozone+Tests+%282%29&reload=none))
fwang8491a612016-10-31 20:59:45122
123To build `chrome`, do this from the `src` directory:
124
125``` shell
126gn args out/OzoneChromeOS --args="use_ozone=true target_os=\"chromeos\""
127ninja -C out/OzoneChromeOS chrome
128```
129
130Then to run for example the X11 platform:
131
132``` shell
fwang399b51c2016-11-10 09:48:27133./out/OzoneChromeOS/chrome --ozone-platform=x11
fwang8491a612016-10-31 20:59:45134```
135
136### Embedded
137
fwang7af9db62017-01-09 14:52:22138**Warning: Only some targets such as `content_shell` or unit tests are
139currently working for embedded builds.**
fwang8491a612016-10-31 20:59:45140
141To build `content_shell`, do this from the `src` directory:
142
143``` shell
144gn args out/OzoneEmbedded --args="use_ozone=true toolkit_views=false"
145ninja -C out/OzoneEmbedded content_shell
146```
147
148Then to run for example the headless platform:
149
150``` shell
fwang399b51c2016-11-10 09:48:27151./out/OzoneEmbedded/content_shell --ozone-platform=headless \
fwang8491a612016-10-31 20:59:45152 --ozone-dump-file=/tmp/
153```
154
fwang15744c72016-11-08 13:58:33155### Linux Desktop - ([waterfall](https://build.chromium.org/p/chromium.fyi/builders/Ozone%20Linux/))
fwang8491a612016-10-31 20:59:45156
fwangbc6983a72017-04-05 18:06:14157**Warning: Experimental support for Linux Desktop is available since m57 but
158 upstream support has always been a bit fragile. For now, development
159 continues on the
160 [ozone-wayland-dev](https://github.com/Igalia/chromium/tree/ozone-wayland-dev)
161 branch.**
fwang15744c72016-11-08 13:58:33162
163To build `chrome`, do this from the `src` directory:
164
165``` shell
Scott Violet52134e2e2018-05-01 00:33:16166gn args out/OzoneLinuxDesktop --args="use_ozone=true"
fwang15744c72016-11-08 13:58:33167ninja -C out/OzoneLinuxDesktop chrome
168```
169Then to run for example the X11 platform:
170
171``` shell
Scott Violet52134e2e2018-05-01 00:33:16172./out/OzoneLinuxDesktop/chrome --ozone-platform=x11
fwang15744c72016-11-08 13:58:33173```
174
fwang8491a612016-10-31 20:59:45175### GN Configuration notes
176
177You can turn properly implemented ozone platforms on and off by setting the
178corresponding flags in your GN configuration. For example
179`ozone_platform_headless=false ozone_platform_gbm=false` will turn off the
180headless and DRM/GBM platforms.
181This will result in a smaller binary and faster builds. To turn ALL platforms
182off by default, set `ozone_auto_platforms=false`.
183
184You can also specify a default platform to run by setting the `ozone_platform`
185build parameter. For example `ozone_platform="x11"` will make X11 the
186default platform when `--ozone-platform` is not passed to the program.
187If `ozone_auto_platforms` is true then `ozone_platform` is set to `headless`
188by default.
189
190## Running with Ozone
191
192Specify the platform you want to use at runtime using the `--ozone-platform`
fwang399b51c2016-11-10 09:48:27193flag. For example, to run `content_shell` with the GBM platform:
fwang8491a612016-10-31 20:59:45194
195``` shell
fwang399b51c2016-11-10 09:48:27196content_shell --ozone-platform=gbm
fwang8491a612016-10-31 20:59:45197```
198
199Caveats:
200
201* `content_shell` always runs at 800x600 resolution.
202* For the GBM platform, you may need to terminate your X server (or any other
203 display server) prior to testing.
fwang399b51c2016-11-10 09:48:27204* During development, you may need to configure
205 [sandboxing](linux_sandboxing.md) or to disable it.
fwang8491a612016-10-31 20:59:45206
207## Ozone Platforms
208
209### Headless
210
211This platform
212draws graphical output to a PNG image (no GPU support; software rendering only)
213and will not output to the screen. You can set
214the path of the directory where to output the images
215by specifying `--ozone-dump-file=/path/to/output-directory` on the
216command line:
217
218``` shell
fwang399b51c2016-11-10 09:48:27219content_shell --ozone-platform=headless \
fwang8491a612016-10-31 20:59:45220 --ozone-dump-file=/tmp/
221```
222
223### DRM/GBM
224
225This is Linux direct rending with acceleration via mesa GBM & linux DRM/KMS
226(EGL/GLES2 accelerated rendering & modesetting in GPU process) and is in
derat817105082017-02-22 17:57:55227production use on [Chrome OS](https://www.chromium.org/chromium-os).
fwang8491a612016-10-31 20:59:45228
derat817105082017-02-22 17:57:55229Note that all Chrome OS builds of Chrome will compile and attempt to use this.
fwang8491a612016-10-31 20:59:45230See [Building Chromium for Chromium OS](https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/building-chromium-browser) for build instructions.
231
232### Cast
233
234This platform is used for
235[Chromecast](https://www.google.com/intl/en_us/chromecast/).
236
237### X11
238
239This platform provides support for the [X window system](https://www.x.org/).
240
241### Wayland
242
243This platform provides support for the
244[Wayland](http://wayland.freedesktop.org/) display protocol. It was
245initially developed by Intel as
246[a fork of chromium](https://github.com/01org/ozone-wayland)
247and then partially upstreamed.
fwangbc6983a72017-04-05 18:06:14248It is still actively being developed on the
249[ozone-wayland-dev](https://github.com/Igalia/chromium/tree/ozone-wayland-dev)
250branch, feel free to discuss
fwang8491a612016-10-31 20:59:45251with us on freenode.net, `#ozone-wayland` channel or on `ozone-dev`.
252
fwang15744c72016-11-08 13:58:33253Below are some quick build & run instructions. It is assumed that you are
fwang7af9db62017-01-09 14:52:22254launching `chrome` from a Wayland environment such as `weston`. Execute the
fwang15744c72016-11-08 13:58:33255following commands:
fwang8491a612016-10-31 20:59:45256
257``` shell
Scott Violet2eb92292017-11-06 22:53:10258gn args out/OzoneWayland --args="use_ozone=true enable_mus=true"
fwang8491a612016-10-31 20:59:45259ninja -C out/OzoneWayland chrome
Scott Violet8ff9c302018-02-22 22:28:35260./out/OzoneWayland/chrome --ozone-platform=wayland --enable-features=Mus
fwang8491a612016-10-31 20:59:45261```
262
263### Caca
264
265This platform
266draws graphical output to text using
267[libcaca](http://caca.zoy.org/wiki/libcaca)
268(no GPU support; software
269rendering only). In case you ever wanted to test embedded content shell on
270tty.
271It has been
272[removed from the tree](https://codereview.chromium.org/2445323002/) and is no
fwang7fa6daf72016-11-03 16:07:04273longer maintained but you can
274[build it as an out-of-tree port](https://github.com/fred-wang/ozone-caca).
275
276Alternatively, you can try the latest revision known to work. First, install
277libcaca shared library and development files. Next, move to the git revision
278`0e64be9cf335ee3bea7c989702c5a9a0934af037`
279(you will probably need to synchronize the build dependencies with
280`gclient sync --with_branch_heads`). Finally, build and run the caca platform
281with the following commands:
fwang8491a612016-10-31 20:59:45282
283``` shell
fwang8491a612016-10-31 20:59:45284gn args out/OzoneCaca \
285 --args="use_ozone=true ozone_platform_caca=true use_sysroot=false ozone_auto_platforms=false toolkit_views=false"
286ninja -C out/OzoneCaca content_shell
fwang399b51c2016-11-10 09:48:27287./out/OzoneCaca/content_shell
fwang8491a612016-10-31 20:59:45288```
289
290 Note: traditional TTYs are not the ideal browsing experience.<br/>
fwang639002722016-11-08 12:33:04291 ![Picture of a workstation using Ozone/caca to display the Google home page in a text terminal](./images/ozone_caca.jpg)
fwang8491a612016-10-31 20:59:45292
293## Communication
294
295There is a public mailing list:
296[ozone-dev@chromium.org](https://groups.google.com/a/chromium.org/forum/#!forum/ozone-dev)