- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / wayland / display.h
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.
5
6 #ifndef OZONE_WAYLAND_DISPLAY_H_
7 #define OZONE_WAYLAND_DISPLAY_H_
8
9 #if !defined(__STDC_FORMAT_MACROS)
10 #define __STDC_FORMAT_MACROS
11 #endif
12
13 #include <wayland-client.h>
14 #include <list>
15 #include <map>
16
17 #include "base/basictypes.h"
18
19 namespace ozonewayland {
20
21 class WaylandInputDevice;
22 class WaylandScreen;
23 class WaylandWindow;
24 class OzoneDisplay;
25
26 typedef std::map<unsigned, WaylandWindow*> WindowMap;
27
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 {
32  public:
33   static WaylandDisplay* GetInstance() { return instance_; }
34   // Returns a pointer to wl_display.
35   wl_display* display() const { return display_; }
36
37   wl_registry* registry() const { return registry_; }
38
39   // Returns a list of the registered screens.
40   std::list<WaylandScreen*> GetScreenList() const { return screen_list_; }
41   WaylandScreen* PrimaryScreen() const { return primary_screen_ ; }
42
43   wl_shell* shell() const { return shell_; }
44
45   wl_shm* shm() const { return shm_; }
46   wl_compositor* GetCompositor() const { return compositor_; }
47   int GetDisplayFd() const { return wl_display_get_fd(display_); }
48
49   const WindowMap& GetWindowList() const { return widget_map_; }
50
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);
57
58   // Destroys WaylandWindow whose handle is w.
59   void DestroyWindow(unsigned w);
60
61  private:
62   enum RegistrationType {
63     RegisterAsNeeded,  // Handles all the required registrations.
64     RegisterOutputOnly  // Only screen registration.
65   };
66
67   explicit WaylandDisplay(RegistrationType type);
68   virtual ~WaylandDisplay();
69   void terminate();
70   void SyncDisplay();
71   // This handler resolves all server events used in initialization. It also
72   // handles input device registration, screen registration.
73   static void DisplayHandleGlobal(
74       void *data,
75       struct wl_registry *registry,
76       uint32_t name,
77       const char *interface,
78       uint32_t version);
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(
82       void *data,
83       struct wl_registry *registry,
84       uint32_t name,
85       const char *interface,
86       uint32_t version);
87
88   // WaylandDisplay manages the memory of all these pointers.
89   wl_display* display_;
90   wl_registry* registry_;
91   wl_compositor* compositor_;
92   wl_shell* shell_;
93   wl_shm* shm_;
94   WaylandScreen* primary_screen_;
95
96   std::list<WaylandScreen*> screen_list_;
97   std::list<WaylandInputDevice*> input_list_;
98   WindowMap widget_map_;
99   static WaylandDisplay* instance_;
100
101   friend class OzoneDisplay;
102   DISALLOW_COPY_AND_ASSIGN(WaylandDisplay);
103 };
104
105 }  // namespace ozonewayland
106
107 #endif  // OZONE_WAYLAND_DISPLAY_H_