blob: cb77cef88e6705cb44cb329d99cc0f6bf445f6d9 [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.
Maksim Sisov0a0b7482018-10-18 07:59:4266* `PlatformScreen` is used to fetch screen configuration.
67* `ClipboardDelegate` provides an interface to exchange data with other
68applications on the host system using a system clipboard mechanism.
fwang8491a612016-10-31 20:59:4569
70## Ozone in Chromium
71
72Our implementation of Ozone required changes concentrated in these areas:
73
74* Cleaning up extensive assumptions about use of X11 throughout the tree,
75 protecting this code behind the `USE_X11` ifdef, and adding a new `USE_OZONE`
76 path that works in a relatively platform-neutral way by delegating to the
77 interfaces described above.
78* a `WindowTreeHostOzone` to send events into Aura and participate in display
79 management on the host system, and
80* an Ozone-specific flavor of `GLSurfaceEGL` which delegates allocation of
81 accelerated surfaces and refresh syncing to the provided implementation of
82 `SurfaceFactoryOzone`.
83
84## Porting with Ozone
85
86Users of the Ozone abstraction need to do the following, at minimum:
87
88* Write a subclass of `PlatformWindow`. This class (I'll call it
89 `PlatformWindowImpl`) is responsible for window system integration. It can
90 use `MessagePumpLibevent` to poll for events from file descriptors and then
91 invoke `PlatformWindowDelegate::DispatchEvent` to dispatch each event.
92* Write a subclass of `SurfaceFactoryOzone` that handles allocating accelerated
93 surfaces. I'll call this `SurfaceFactoryOzoneImpl`.
94* Write a subclass of `CursorFactoryOzone` to manage cursors, or use the
95 `BitmapCursorFactoryOzone` implementation if only bitmap cursors need to be
96 supported.
97* Write a subclass of `OverlayManagerOzone` or just use `StubOverlayManager` if
98 your platform does not support overlays.
99* Write a subclass of `NativeDisplayDelegate` if necessary or just use
Maksim Sisov0a0b7482018-10-18 07:59:42100 `FakeDisplayDelegate`, and write a subclass of `PlatformScreen`, which is
101 used by aura::ScreenOzone then.
fwang8491a612016-10-31 20:59:45102* Write a subclass of `GpuPlatformSupportHost` or just use
103 `StubGpuPlatformSupportHost`.
104* Write a subclass of `InputController` or just use `StubInputController`.
105* Write a subclass of `SystemInputInjector` if necessary.
106* Write a subclass of `OzonePlatform` that owns instances of
107 the above subclasses and provide a static constructor function for these
108 objects. This constructor will be called when
109 your platform is selected and the returned objects will be used to provide
110 implementations of all the ozone platform interfaces.
111 If your platform does not need some of the interfaces then you can just
112 return a `Stub*` instance or a `nullptr`.
113
114## Adding an Ozone Platform to the build (instructions for out-of-tree ports)
115
116The recommended way to add your platform to the build is as follows. This walks
117through creating a new ozone platform called `foo`.
118
1191. Fork `chromium/src.git`.
1202. Add your implementation in `ui/ozone/platform/` alongside internal platforms.
1213. Patch `ui/ozone/ozone_extra.gni` to add your `foo` platform.
122
123## Building with Ozone
124
derat817105082017-02-22 17:57:55125### 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:45126
127To build `chrome`, do this from the `src` directory:
128
129``` shell
130gn args out/OzoneChromeOS --args="use_ozone=true target_os=\"chromeos\""
131ninja -C out/OzoneChromeOS chrome
132```
133
134Then to run for example the X11 platform:
135
136``` shell
fwang399b51c2016-11-10 09:48:27137./out/OzoneChromeOS/chrome --ozone-platform=x11
fwang8491a612016-10-31 20:59:45138```
139
140### Embedded
141
fwang7af9db62017-01-09 14:52:22142**Warning: Only some targets such as `content_shell` or unit tests are
143currently working for embedded builds.**
fwang8491a612016-10-31 20:59:45144
145To build `content_shell`, do this from the `src` directory:
146
147``` shell
148gn args out/OzoneEmbedded --args="use_ozone=true toolkit_views=false"
149ninja -C out/OzoneEmbedded content_shell
150```
151
152Then to run for example the headless platform:
153
154``` shell
fwang399b51c2016-11-10 09:48:27155./out/OzoneEmbedded/content_shell --ozone-platform=headless \
fwang8491a612016-10-31 20:59:45156 --ozone-dump-file=/tmp/
157```
158
fwang15744c72016-11-08 13:58:33159### Linux Desktop - ([waterfall](https://build.chromium.org/p/chromium.fyi/builders/Ozone%20Linux/))
fwang8491a612016-10-31 20:59:45160
Maksim Sisov0a0b7482018-10-18 07:59:42161**Warning: Experimental support for Linux Desktop is available since m57 and still under
Maksim Sisovc3642a62019-03-13 08:06:40162 development. The work is purely done in the upstream, but you can still find some Ozone/X11
163 patches in the the old [ozone-wayland-dev](https://github.com/Igalia/chromium/tree/ozone-wayland-dev) branch.**
fwang15744c72016-11-08 13:58:33164
165To build `chrome`, do this from the `src` directory:
166
167``` shell
Maksim Sisovc3642a62019-03-13 08:06:40168gn args out/OzoneLinuxDesktop --args="use_ozone=true use_system_minigbm=true use_system_libdrm=true"
fwang15744c72016-11-08 13:58:33169ninja -C out/OzoneLinuxDesktop chrome
170```
Maksim Sisov0a0b7482018-10-18 07:59:42171
fwang15744c72016-11-08 13:58:33172Then to run for example the X11 platform:
173
174``` shell
Scott Violet52134e2e2018-05-01 00:33:16175./out/OzoneLinuxDesktop/chrome --ozone-platform=x11
fwang15744c72016-11-08 13:58:33176```
177
Maksim Sisov0a0b7482018-10-18 07:59:42178Or run for example the Wayland platform:
179
180``` shell
Maksim Sisovc3642a62019-03-13 08:06:40181./out/OzoneLinuxDesktop/chrome --ozone-platform=wayland
Maksim Sisov0a0b7482018-10-18 07:59:42182```
183
fwang8491a612016-10-31 20:59:45184### GN Configuration notes
185
186You can turn properly implemented ozone platforms on and off by setting the
187corresponding flags in your GN configuration. For example
188`ozone_platform_headless=false ozone_platform_gbm=false` will turn off the
189headless and DRM/GBM platforms.
190This will result in a smaller binary and faster builds. To turn ALL platforms
191off by default, set `ozone_auto_platforms=false`.
192
193You can also specify a default platform to run by setting the `ozone_platform`
194build parameter. For example `ozone_platform="x11"` will make X11 the
195default platform when `--ozone-platform` is not passed to the program.
196If `ozone_auto_platforms` is true then `ozone_platform` is set to `headless`
197by default.
198
199## Running with Ozone
200
201Specify the platform you want to use at runtime using the `--ozone-platform`
fwang399b51c2016-11-10 09:48:27202flag. For example, to run `content_shell` with the GBM platform:
fwang8491a612016-10-31 20:59:45203
204``` shell
fwang399b51c2016-11-10 09:48:27205content_shell --ozone-platform=gbm
fwang8491a612016-10-31 20:59:45206```
207
208Caveats:
209
210* `content_shell` always runs at 800x600 resolution.
211* For the GBM platform, you may need to terminate your X server (or any other
212 display server) prior to testing.
fwang399b51c2016-11-10 09:48:27213* During development, you may need to configure
214 [sandboxing](linux_sandboxing.md) or to disable it.
fwang8491a612016-10-31 20:59:45215
216## Ozone Platforms
217
218### Headless
219
220This platform
221draws graphical output to a PNG image (no GPU support; software rendering only)
222and will not output to the screen. You can set
223the path of the directory where to output the images
224by specifying `--ozone-dump-file=/path/to/output-directory` on the
225command line:
226
227``` shell
fwang399b51c2016-11-10 09:48:27228content_shell --ozone-platform=headless \
fwang8491a612016-10-31 20:59:45229 --ozone-dump-file=/tmp/
230```
231
232### DRM/GBM
233
234This is Linux direct rending with acceleration via mesa GBM & linux DRM/KMS
235(EGL/GLES2 accelerated rendering & modesetting in GPU process) and is in
derat817105082017-02-22 17:57:55236production use on [Chrome OS](https://www.chromium.org/chromium-os).
fwang8491a612016-10-31 20:59:45237
derat817105082017-02-22 17:57:55238Note that all Chrome OS builds of Chrome will compile and attempt to use this.
fwang8491a612016-10-31 20:59:45239See [Building Chromium for Chromium OS](https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/building-chromium-browser) for build instructions.
240
241### Cast
242
243This platform is used for
244[Chromecast](https://www.google.com/intl/en_us/chromecast/).
245
246### X11
247
248This platform provides support for the [X window system](https://www.x.org/).
249
Maksim Sisov0c9db242019-11-22 06:20:35250The support for X11 is being actively developed by Igalia and the chromium
251community and is intended to replace the current legacy X11 path.
252
253You can try to compile and run it with the following configuration:
254
255``` shell
256gn args out/OzoneX11 --args="use_ozone=true"
257ninja -C out/OzoneX11 chrome
258./out/OzoneX11/chrome --ozone-platform=x11
259```
260
fwang8491a612016-10-31 20:59:45261### Wayland
262
263This platform provides support for the
264[Wayland](http://wayland.freedesktop.org/) display protocol. It was
265initially developed by Intel as
266[a fork of chromium](https://github.com/01org/ozone-wayland)
267and then partially upstreamed.
Maksim Sisov0c9db242019-11-22 06:20:35268
269Currently, the Ozone/Wayland is actively being developed by Igalia in
270the Chromium mainline repository with some features missing at the moment. The
271progress can be tracked in the [issue #578890](https://crbug.com/578890).
fwang8491a612016-10-31 20:59:45272
fwang15744c72016-11-08 13:58:33273Below are some quick build & run instructions. It is assumed that you are
fwang7af9db62017-01-09 14:52:22274launching `chrome` from a Wayland environment such as `weston`. Execute the
Maksim Sisov0c9db242019-11-22 06:20:35275following commands (make sure a system version of gbm and drm is used, which
276are required by Ozone/Wayland by design, when running on Linux platforms.):
fwang8491a612016-10-31 20:59:45277
278``` shell
Maksim Sisov0c9db242019-11-22 06:20:35279gn args out/OzoneWayland --args="use_ozone=true use_system_minigbm=true use_system_libdrm=true use_xkbcommon=true"
fwang8491a612016-10-31 20:59:45280ninja -C out/OzoneWayland chrome
Maksim Sisov0a0b7482018-10-18 07:59:42281./out/OzoneWayland/chrome --ozone-platform=wayland
fwang8491a612016-10-31 20:59:45282```
283
Maksim Sisov0c9db242019-11-22 06:20:35284Native file dialogs are currently supported through the GTK toolkit. That
285implies that the browser is compiled with glib and gtk enabled. Please
286append the following gn args to your configuration:
287
288``` shell
289use_ozone=true
290use_system_minigbm=true
291use_system_libdrm=true
292use_xkbcommon=true
293use_glib=true
294use_gtk=true
295```
296
297Feel free to discuss with us on freenode.net, `#ozone-wayland` channel or on
298`ozone-dev`, or on `#ozone-wayland-x11` channel in [chromium slack](https://www.chromium.org/developers/slack).
299
fwang8491a612016-10-31 20:59:45300### Caca
301
302This platform
303draws graphical output to text using
304[libcaca](http://caca.zoy.org/wiki/libcaca)
305(no GPU support; software
306rendering only). In case you ever wanted to test embedded content shell on
307tty.
308It has been
309[removed from the tree](https://codereview.chromium.org/2445323002/) and is no
fwang7fa6daf72016-11-03 16:07:04310longer maintained but you can
311[build it as an out-of-tree port](https://github.com/fred-wang/ozone-caca).
312
313Alternatively, you can try the latest revision known to work. First, install
314libcaca shared library and development files. Next, move to the git revision
315`0e64be9cf335ee3bea7c989702c5a9a0934af037`
316(you will probably need to synchronize the build dependencies with
317`gclient sync --with_branch_heads`). Finally, build and run the caca platform
318with the following commands:
fwang8491a612016-10-31 20:59:45319
320``` shell
fwang8491a612016-10-31 20:59:45321gn args out/OzoneCaca \
322 --args="use_ozone=true ozone_platform_caca=true use_sysroot=false ozone_auto_platforms=false toolkit_views=false"
323ninja -C out/OzoneCaca content_shell
fwang399b51c2016-11-10 09:48:27324./out/OzoneCaca/content_shell
fwang8491a612016-10-31 20:59:45325```
326
327 Note: traditional TTYs are not the ideal browsing experience.<br/>
fwang639002722016-11-08 12:33:04328 ![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:45329
330## Communication
331
332There is a public mailing list:
333[[email protected]](https://groups.google.com/a/chromium.org/forum/#!forum/ozone-dev)