1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Copyright 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #ifndef OZONE_WAYLAND_DISPLAY_H_
7 #define OZONE_WAYLAND_DISPLAY_H_
9 #if !defined(__STDC_FORMAT_MACROS)
10 #define __STDC_FORMAT_MACROS
13 #include <wayland-client.h>
17 #include "base/basictypes.h"
19 namespace ozonewayland {
21 class WaylandInputDevice;
26 typedef std::map<unsigned, WaylandWindow*> WindowMap;
28 // WaylandDisplay is a wrapper around wl_display. Once we get a valid
29 // wl_display, the Wayland server will send different events to register
30 // the Wayland compositor, shell, screens, input devices, ...
31 class WaylandDisplay {
33 static WaylandDisplay* GetInstance() { return instance_; }
34 // Returns a pointer to wl_display.
35 wl_display* display() const { return display_; }
37 wl_registry* registry() const { return registry_; }
39 // Returns a list of the registered screens.
40 std::list<WaylandScreen*> GetScreenList() const { return screen_list_; }
41 WaylandScreen* PrimaryScreen() const { return primary_screen_ ; }
43 wl_shell* shell() const { return shell_; }
45 wl_shm* shm() const { return shm_; }
46 wl_compositor* GetCompositor() const { return compositor_; }
47 int GetDisplayFd() const { return wl_display_get_fd(display_); }
49 const WindowMap& GetWindowList() const { return widget_map_; }
51 // Creates a WaylandWindow backed by EGL Window and maps it to w. This can be
52 // useful for callers to track a particular surface. By default the type of
53 // surface(i.e. toplevel, menu) is none. One needs to explicitly call
54 // WaylandWindow::SetShellAttributes to set this. The ownership of
55 // WaylandWindow is not passed to the caller.
56 WaylandWindow* CreateAcceleratedSurface(unsigned w);
58 // Destroys WaylandWindow whose handle is w.
59 void DestroyWindow(unsigned w);
62 enum RegistrationType {
63 RegisterAsNeeded, // Handles all the required registrations.
64 RegisterOutputOnly // Only screen registration.
67 explicit WaylandDisplay(RegistrationType type);
68 virtual ~WaylandDisplay();
71 // This handler resolves all server events used in initialization. It also
72 // handles input device registration, screen registration.
73 static void DisplayHandleGlobal(
75 struct wl_registry *registry,
77 const char *interface,
79 // This handler resolves only screen registration. In general you don't want
80 // to use this but the one below.
81 static void DisplayHandleOutputOnly(
83 struct wl_registry *registry,
85 const char *interface,
88 // WaylandDisplay manages the memory of all these pointers.
90 wl_registry* registry_;
91 wl_compositor* compositor_;
94 WaylandScreen* primary_screen_;
96 std::list<WaylandScreen*> screen_list_;
97 std::list<WaylandInputDevice*> input_list_;
98 WindowMap widget_map_;
99 static WaylandDisplay* instance_;
101 friend class OzoneDisplay;
102 DISALLOW_COPY_AND_ASSIGN(WaylandDisplay);
105 } // namespace ozonewayland
107 #endif // OZONE_WAYLAND_DISPLAY_H_