Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: ui/wayland/wayland_display.cc

Issue 7457023: Adding a Wayland basic toolkit (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More comments and Chrome style formatting Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include "wayland_display.h"
6
7 #include <string.h>
8 #include <wayland-client.h>
9
10 #include "wayland_buffer.h"
11 #include "wayland_input_device.h"
12 #include "wayland_screen.h"
13 #include "wayland_window.h"
14
15 // static
16 WaylandDisplay* WaylandDisplay::Connect(char* name) {
17 static WaylandDisplay *display = NULL;
18 if (display) {
19 return display;
20 }
21
22 display = new WaylandDisplay(name);
23 if (!display->display_) {
24 delete display;
25 display = NULL;
26 return NULL;
27 }
28
29 /* Register the display initialization handler and iterate over the initial
30 connection events sent by the server. This is required since the display will
31 send registration events needed to initialize everything else. This will
32 create the compositor, visuals, etc.., which are required in creating a
33 drawing context.
34 */
35 wl_display_add_global_listener(display->display_,
36 WaylandDisplay::DisplayHandleGlobal,
37 display);
38 wl_display_iterate(display->display_, WL_DISPLAY_READABLE);
39
40 return display;
41 }
42
43 WaylandDisplay::WaylandDisplay(char* name) : display_(NULL),
44 compositor_(NULL),
45 shell_(NULL),
46 shm_(NULL),
47 visual_(NULL) {
48 display_ = wl_display_connect(name);
49 }
50
51 WaylandDisplay::~WaylandDisplay() {
52 if (display_) {
53 wl_display_destroy(display_);
54 }
Evan Martin 2011/07/22 18:21:22 Chrome style is for single-line "if" statements to
55 if (compositor_) {
56 wl_compositor_destroy(compositor_);
57 }
58 if (visual_) {
59 wl_visual_destroy(visual_);
60 }
61 if (shell_) {
62 wl_shell_destroy(shell_);
63 }
64 if (shm_) {
65 wl_shm_destroy(shm_);
66 }
67 for (std::list<WaylandInputDevice*>::iterator it = input_list_.begin();
68 it != input_list_.end(); it++) {
69 delete *it;
70 }
71 for (std::list<WaylandScreen*>::iterator it = screen_list_.begin();
72 it != screen_list_.end(); it++) {
73 delete *it;
74 }
75 }
76
77 wl_surface* WaylandDisplay::CreateSurface() {
78 return wl_compositor_create_surface(compositor_);
79 }
80
81 void WaylandDisplay::SetCursor(WaylandBuffer* buffer,
82 int32_t x, int32_t y) {
83 /* Currently there is no way of knowing which input device should have the
84 buffer attached, so we just attach to every input device.
85 */
86 for (std::list<WaylandInputDevice*>::iterator it = input_list_.begin();
87 it != input_list_.end(); it++) {
88 (*it)->Attach(buffer->GetBuffer(), x, y);
89 }
90 }
91
92 wl_display* WaylandDisplay::GetNativeDisplay() const {
93 return display_;
94 }
95
96 std::list<WaylandScreen*> WaylandDisplay::GetScreenList() const {
97 return screen_list_;
98 }
99
100 wl_shell* WaylandDisplay::GetShell() const {
101 return shell_;
102 }
103
104 wl_shm* WaylandDisplay::GetShm() const {
105 return shm_;
106 }
107
108 wl_visual* WaylandDisplay::GetVisual() const {
109 return visual_;
110 }
111
112 // static
113 void WaylandDisplay::DisplayHandleGlobal(wl_display* display,
114 uint32_t id,
115 const char* interface,
116 uint32_t version,
117 void* data) {
118 WaylandDisplay* disp = static_cast<WaylandDisplay*>(data);
119
120 static const wl_compositor_listener compositor_listener = {
121 WaylandDisplay::CompositorHandleVisual,
122 };
123 static const wl_shell_listener shell_listener = {
124 WaylandDisplay::ShellHandleConfigure,
125 };
126
127 if (strcmp(interface, "wl_compositor") == 0) {
128 disp->compositor_ = wl_compositor_create(display, id, 1);
129 wl_compositor_add_listener(disp->compositor_,
130 &compositor_listener,
131 disp);
132 } else if (strcmp(interface, "wl_output") == 0) {
133 WaylandScreen* screen = new WaylandScreen(disp, id);
134 disp->screen_list_.push_back(screen);
135 } else if (strcmp(interface, "wl_input_device") == 0) {
136 WaylandInputDevice *input_device = new WaylandInputDevice(display, id);
137 disp->input_list_.push_back(input_device);
138 } else if (strcmp(interface, "wl_shell") == 0) {
139 disp->shell_ = wl_shell_create(display, id, 1);
140 wl_shell_add_listener(disp->shell_, &shell_listener, disp);
141 } else if (strcmp(interface, "wl_shm") == 0) {
142 disp->shm_ = wl_shm_create(display, id, 1);
143 }
144 }
145
146 // static
147 void WaylandDisplay::CompositorHandleVisual(void* data,
148 wl_compositor* compositor,
149 uint32_t id,
150 uint32_t token) {
151 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
152
153 /* The compositor may support multiple types of visuals but we really only
154 need one.
155 */
156 switch (token) {
157 case WL_COMPOSITOR_VISUAL_ARGB32:
158 break;
159 case WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32:
160 display->visual_ = wl_visual_create(display->display_, id, 1);
161 break;
162 case WL_COMPOSITOR_VISUAL_XRGB32:
163 break;
164 }
165 }
166
167 // static
168 void WaylandDisplay::ShellHandleConfigure(void* data,
169 wl_shell* shell,
170 uint32_t time,
171 uint32_t edges,
172 wl_surface* surface,
173 int32_t width,
174 int32_t height) {
175 WaylandWindow* window = static_cast<WaylandWindow*>(
176 wl_surface_get_user_data(surface));
177 window->Configure(time, edges, 0, 0, width, height);
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698