OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_WAYLAND_WAYLAND_DISPLAY_H_ |
| 6 #define UI_WAYLAND_WAYLAND_DISPLAY_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <list> |
| 11 |
| 12 #if !defined(__STDC_FORMAT_MACROS) |
| 13 #define __STDC_FORMAT_MACROS |
| 14 #endif |
| 15 |
| 16 #include "ui/gfx/point.h" |
| 17 #include "ui/gfx/rect.h" |
| 18 #include <wayland-client.h> |
| 19 #include "ui/wayland/wayland_task.h" |
| 20 |
| 21 #ifndef GLAPIENTRY |
| 22 #define GLAPIENTRY |
| 23 #endif |
| 24 |
| 25 #ifndef APIENTRY |
| 26 #define APIENTRY GLAPIENTRY |
| 27 #endif |
| 28 |
| 29 /* "P" suffix to be used for a pointer to a function */ |
| 30 #ifndef APIENTRYP |
| 31 #define APIENTRYP APIENTRY * |
| 32 #endif |
| 33 |
| 34 typedef unsigned int GLenum; |
| 35 typedef void* GLeglImageOES; |
| 36 typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLe
glImageOES image); |
| 37 |
| 38 struct wl_compositor; |
| 39 struct wl_display; |
| 40 struct wl_surface; |
| 41 struct wl_shell; |
| 42 struct wl_shm; |
| 43 struct wl_data_device_manager; |
| 44 struct wl_list; |
| 45 struct wl_buffer; |
| 46 struct wl_cursor_theme; |
| 47 struct wl_cursor; |
| 48 |
| 49 struct _cairo_surface; |
| 50 typedef struct _cairo_surface cairo_surface_t; |
| 51 struct _cairo_device; |
| 52 typedef struct _cairo_device cairo_device_t; |
| 53 struct _cairo_rectangle_int; |
| 54 typedef struct _cairo_rectangle_int cairo_rectangle_int_t; |
| 55 |
| 56 #include <EGL/eglplatform.h> |
| 57 typedef unsigned int EGLBoolean; |
| 58 typedef unsigned int EGLenum; |
| 59 typedef void *EGLConfig; |
| 60 typedef void *EGLContext; |
| 61 typedef void *EGLDisplay; |
| 62 typedef void *EGLSurface; |
| 63 typedef void *EGLClientBuffer; |
| 64 |
| 65 typedef void *EGLImageKHR; |
| 66 typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGL
Context ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); |
| 67 typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGL
ImageKHR image); |
| 68 |
| 69 struct wl_compositor; |
| 70 struct wl_display; |
| 71 struct wl_shell; |
| 72 struct wl_shm; |
| 73 struct wl_surface; |
| 74 struct wl_shell_surface; |
| 75 |
| 76 namespace ui { |
| 77 |
| 78 class WaylandBuffer; |
| 79 class WaylandInputDevice; |
| 80 class WaylandScreen; |
| 81 class WaylandWindow; |
| 82 class WaylandInputMethodEventFilter; |
| 83 class InputMethod; |
| 84 |
| 85 enum pointer_type { |
| 86 POINTER_BOTTOM_LEFT, |
| 87 POINTER_BOTTOM_RIGHT, |
| 88 POINTER_BOTTOM, |
| 89 POINTER_DRAGGING, |
| 90 POINTER_LEFT_PTR, |
| 91 POINTER_LEFT, |
| 92 POINTER_RIGHT, |
| 93 POINTER_TOP_LEFT, |
| 94 POINTER_TOP_RIGHT, |
| 95 POINTER_TOP, |
| 96 POINTER_IBEAM, |
| 97 POINTER_HAND1, |
| 98 }; |
| 99 |
| 100 enum { |
| 101 POINTER_DEFAULT = 100, |
| 102 POINTER_UNSET |
| 103 }; |
| 104 |
| 105 // WaylandDisplay is a wrapper around wl_display. Once we get a valid |
| 106 // wl_display, the Wayland server will send different events to register |
| 107 // the Wayland compositor, shell, screens, input devices, ... |
| 108 class WaylandDisplay { |
| 109 public: |
| 110 // Attempt to create a connection to the display. If it fails this returns |
| 111 // NULL |
| 112 static WaylandDisplay* Connect(char* name); |
| 113 |
| 114 // Get the WaylandDisplay associated with the native Wayland display |
| 115 static WaylandDisplay* GetDisplay(wl_display* display); |
| 116 |
| 117 static WaylandDisplay* GetDisplay(); |
| 118 static void DestroyDisplay(); |
| 119 |
| 120 virtual ~WaylandDisplay(); |
| 121 |
| 122 // Creates a wayland surface. This is used to create a window surface. |
| 123 // The returned pointer should be deleted by the caller. |
| 124 wl_surface* CreateSurface(); |
| 125 |
| 126 // Returns a pointer to the wl_display. |
| 127 wl_display* display() const { return display_; } |
| 128 |
| 129 wl_registry* registry() const { return registry_; } |
| 130 |
| 131 // Returns a list of the registered screens. |
| 132 std::list<WaylandScreen*> GetScreenList() const; |
| 133 |
| 134 wl_shell* shell() const { return shell_; } |
| 135 |
| 136 wl_shm* shm() const { return shm_; } |
| 137 |
| 138 void DestroyEGLImage(EGLImageKHR image); |
| 139 |
| 140 void AddWindow(WaylandWindow* window); |
| 141 void RemoveWindow(WaylandWindow* window); |
| 142 bool IsWindow(WaylandWindow* window); |
| 143 |
| 144 void AddTask(WaylandTask* task); |
| 145 void ProcessTasks(); |
| 146 |
| 147 cairo_surface_t* CreateSurfaceFromFile(const char *filename, gfx::Rect *rect); |
| 148 cairo_surface_t* CreateSurface(wl_surface *surface, gfx::Rect *rect, uint32_t
flags); |
| 149 |
| 150 void AddWindowCallback(const wl_callback_listener *listener, WaylandWindow *wi
ndow); |
| 151 |
| 152 void SetPointerImage(WaylandInputDevice* device, uint32_t time, int pointer); |
| 153 |
| 154 InputMethod* GetInputMethod() const; |
| 155 |
| 156 void SetSerial(uint32_t serial) { serial_ = serial; } |
| 157 uint32_t GetSerial() const { return serial_; } |
| 158 |
| 159 private: |
| 160 WaylandDisplay(char* name); |
| 161 void CreateCursors(); |
| 162 void DestroyCursors(); |
| 163 |
| 164 // This handler resolves all server events used in initialization. It also |
| 165 // handles input device registration, screen registration. |
| 166 static void DisplayHandleGlobal(void *data, struct wl_registry *registry, |
| 167 uint32_t name, const char *interface, |
| 168 uint32_t version); |
| 169 |
| 170 // WaylandDisplay manages the memory of all these pointers. |
| 171 wl_display* display_; |
| 172 wl_registry *registry_; |
| 173 wl_compositor* compositor_; |
| 174 wl_shell* shell_; |
| 175 wl_shm* shm_; |
| 176 |
| 177 std::list<WaylandScreen*> screen_list_; |
| 178 std::list<WaylandInputDevice*> input_list_; |
| 179 std::list<WaylandTask*> task_list_; |
| 180 std::list<WaylandWindow*> window_list_; |
| 181 WaylandInputMethodEventFilter *input_method_filter_; |
| 182 |
| 183 EGLDisplay dpy_; |
| 184 EGLConfig argb_config_; |
| 185 EGLContext argb_ctx_; |
| 186 cairo_device_t *argb_device_; |
| 187 uint32_t serial_; |
| 188 |
| 189 wl_cursor_theme *cursor_theme_; |
| 190 wl_cursor **cursors_; |
| 191 |
| 192 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d_; |
| 193 PFNEGLCREATEIMAGEKHRPROC create_image_; |
| 194 PFNEGLDESTROYIMAGEKHRPROC destroy_image_; |
| 195 |
| 196 friend class WaylandEGLImageSurfaceData; |
| 197 friend class WaylandEGLWindowSurfaceData; |
| 198 |
| 199 DISALLOW_COPY_AND_ASSIGN(WaylandDisplay); |
| 200 }; |
| 201 |
| 202 } // namespace ui |
| 203 |
| 204 #endif // UI_WAYLAND_WAYLAND_DISPLAY_H_ |
OLD | NEW |