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: components/exo/wayland/wayland_bindings.h

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ShellSurface::SetTitle Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2015 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 // TODO(reveman): Most of code in this file could be auto-generated from
6 // the Wayland protocol description.
7
8 #ifndef COMPONENTS_EXO_WAYLAND_WAYLAND_BINDINGS_H_
9 #define COMPONENTS_EXO_WAYLAND_WAYLAND_BINDINGS_H_
10
11 template <class T>
12 T* DataAs(void* data) {
13 return static_cast<T*>(data);
14 }
15
16 template <class T>
17 T* GetUserDataAs(wl_resource* resource) {
18 return DataAs<T>(wl_resource_get_user_data(resource));
19 }
20
21 template <class T>
22 scoped_ptr<T> TakeUserDataAs(wl_resource* resource) {
23 scoped_ptr<T> user_data = make_scoped_ptr(GetUserDataAs<T>(resource));
24 wl_resource_set_user_data(resource, nullptr);
25 return user_data.Pass();
26 }
27
28 template <class T>
29 void DestroyUserData(wl_resource* resource) {
30 TakeUserDataAs<T>(resource);
31 }
32
33 template <class T>
34 void SetImplementation(wl_resource* resource,
35 const void* implementation,
36 scoped_ptr<T> user_data) {
37 wl_resource_set_implementation(resource, implementation, user_data.release(),
38 DestroyUserData<T>);
39 }
40
41 ////////////////////////////////////////////////////////////////////////////////
42 // wl_buffer_interface:
43
44 void buffer_destroy(wl_client* client, wl_resource* resource) {
45 wl_resource_destroy(resource);
46 }
47
48 const struct wl_buffer_interface buffer_implementation = {buffer_destroy};
49
50 ////////////////////////////////////////////////////////////////////////////////
51 // wl_surface_interface:
52
53 void surface_destroy(wl_client* client, wl_resource* resource) {
54 wl_resource_destroy(resource);
55 }
56
57 void surface_attach(wl_client* client,
58 wl_resource* resource,
59 wl_resource* buffer,
60 int32_t x,
61 int32_t y) {
62 GetUserDataAs<Surface>(resource)->Attach(
63 buffer ? GetUserDataAs<Buffer>(buffer) : nullptr, gfx::Point(x, y));
64 }
65
66 void surface_damage(wl_client* client,
67 wl_resource* resource,
68 int32_t x,
69 int32_t y,
70 int32_t width,
71 int32_t height) {
72 GetUserDataAs<Surface>(resource)->Damage(gfx::Rect(x, y, width, height));
73 }
74
75 void handle_surface_frame_callback(wl_resource* resource,
76 base::TimeTicks frame_time) {
77 wl_callback_send_done(resource,
78 (frame_time - base::TimeTicks()).InMilliseconds());
79 // TODO(reveman): Remove this potentially blocking flush and instead watch
80 // the file descriptor to be ready for write without blocking.
81 wl_client_flush(wl_resource_get_client(resource));
82 wl_resource_destroy(resource);
83 }
84
85 void surface_frame(wl_client* client,
86 wl_resource* resource,
87 uint32_t callback) {
88 wl_resource* callback_resource =
89 wl_resource_create(client, &wl_callback_interface, 1, callback);
90 if (!callback_resource) {
91 wl_resource_post_no_memory(resource);
92 return;
93 }
94
95 // base::Unretained is safe as the resource owns the callback.
96 scoped_ptr<base::CancelableCallback<void(base::TimeTicks)>>
97 cancelable_callback(new base::CancelableCallback<void(base::TimeTicks)>(
98 base::Bind(&handle_surface_frame_callback,
99 base::Unretained(callback_resource))));
100
101 GetUserDataAs<Surface>(resource)
102 ->RequestFrameCallback(cancelable_callback->callback());
103
104 SetImplementation(callback_resource, nullptr, cancelable_callback.Pass());
105 }
106
107 void surface_set_opaque_region(wl_client* client,
108 wl_resource* resource,
109 wl_resource* region_resource) {
110 GetUserDataAs<Surface>(resource)->SetOpaqueRegion(
111 region_resource ? *GetUserDataAs<cc::Region>(region_resource)
112 : cc::Region());
113 }
114
115 void surface_set_input_region(wl_client* client,
116 wl_resource* resource,
117 wl_resource* region_resource) {
118 NOTIMPLEMENTED();
119 }
120
121 void surface_commit(wl_client* client, wl_resource* resource) {
122 GetUserDataAs<Surface>(resource)->Commit();
123 }
124
125 void surface_set_buffer_transform(wl_client* client,
126 wl_resource* resource,
127 int transform) {
128 NOTIMPLEMENTED();
129 }
130
131 void surface_set_buffer_scale(wl_client* client,
132 wl_resource* resource,
133 int32_t scale) {
134 NOTIMPLEMENTED();
135 }
136
137 const struct wl_surface_interface surface_implementation = {
138 surface_destroy,
139 surface_attach,
140 surface_damage,
141 surface_frame,
142 surface_set_opaque_region,
143 surface_set_input_region,
144 surface_commit,
145 surface_set_buffer_transform,
146 surface_set_buffer_scale};
147
148 ////////////////////////////////////////////////////////////////////////////////
149 // wl_region_interface:
150
151 void region_destroy(wl_client* client, wl_resource* resource) {
152 wl_resource_destroy(resource);
153 }
154
155 void region_add(wl_client* client,
156 wl_resource* resource,
157 int32_t x,
158 int32_t y,
159 int32_t width,
160 int32_t height) {
161 GetUserDataAs<cc::Region>(resource)->Union(gfx::Rect(x, y, width, height));
162 }
163
164 static void region_subtract(wl_client* client,
165 wl_resource* resource,
166 int32_t x,
167 int32_t y,
168 int32_t width,
169 int32_t height) {
170 GetUserDataAs<cc::Region>(resource)->Subtract(gfx::Rect(x, y, width, height));
171 }
172
173 const struct wl_region_interface region_implementation = {
174 region_destroy, region_add, region_subtract};
175
176 ////////////////////////////////////////////////////////////////////////////////
177 // wl_compositor_interface:
178
179 void compositor_create_surface(wl_client* client,
180 wl_resource* resource,
181 uint32_t id) {
182 scoped_ptr<Surface> surface =
183 GetUserDataAs<Display>(resource)->CreateSurface();
184 DCHECK(surface);
185
186 wl_resource* surface_resource = wl_resource_create(
187 client, &wl_surface_interface, wl_resource_get_version(resource), id);
188 if (!surface_resource) {
189 wl_resource_post_no_memory(resource);
190 return;
191 }
192
193 SetImplementation(surface_resource, &surface_implementation, surface.Pass());
194 }
195
196 void compositor_create_region(wl_client* client,
197 wl_resource* resource,
198 uint32_t id) {
199 scoped_ptr<cc::Region> region(new cc::Region);
200
201 wl_resource* region_resource = wl_resource_create(
202 client, &wl_region_interface, wl_resource_get_version(resource), id);
203 if (!region_resource) {
204 wl_resource_post_no_memory(resource);
205 return;
206 }
207
208 SetImplementation(region_resource, &region_implementation, region.Pass());
209 }
210
211 const struct wl_compositor_interface compositor_implementation = {
212 compositor_create_surface, compositor_create_region};
213
214 const uint32_t compositor_version = 3;
215
216 void bind_compositor(wl_client* client,
217 void* data,
218 uint32_t version,
219 uint32_t id) {
220 wl_resource* resource =
221 wl_resource_create(client, &wl_compositor_interface,
222 std::min(version, compositor_version), id);
223 if (!resource) {
224 wl_client_post_no_memory(client);
225 return;
226 }
227
228 wl_resource_set_implementation(resource, &compositor_implementation, data,
229 nullptr);
230 }
231
232 ////////////////////////////////////////////////////////////////////////////////
233 // wl_shm_pool_interface:
234
235 const struct shm_supported_format {
236 uint32_t shm_format;
237 gfx::BufferFormat buffer_format;
238 } shm_supported_formats[] = {
239 {WL_SHM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888},
240 {WL_SHM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888},
241 {WL_SHM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888},
242 {WL_SHM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}};
243
244 void shm_pool_create_buffer(wl_client* client,
245 wl_resource* resource,
246 uint32_t id,
247 int32_t offset,
248 int32_t width,
249 int32_t height,
250 int32_t stride,
251 uint32_t format) {
252 const auto supported_format =
253 std::find_if(shm_supported_formats,
254 shm_supported_formats + arraysize(shm_supported_formats),
255 [format](const shm_supported_format& supported_format) {
256 return supported_format.shm_format == format;
257 });
258 if (supported_format ==
259 (shm_supported_formats + arraysize(shm_supported_formats))) {
260 wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FORMAT,
261 "invalid format 0x%x", format);
262 return;
263 }
264
265 scoped_ptr<Buffer> buffer =
266 GetUserDataAs<SharedMemory>(resource)
267 ->CreateBuffer(gfx::Size(width, height),
268 supported_format->buffer_format, offset, stride);
269 if (!buffer) {
270 wl_resource_post_no_memory(resource);
271 return;
272 }
273
274 wl_resource* buffer_resource = wl_resource_create(
275 client, &wl_buffer_interface, wl_resource_get_version(resource), id);
276 if (!buffer_resource) {
277 wl_resource_post_no_memory(resource);
278 return;
279 }
280
281 buffer->set_release_callback(
282 base::Bind(&wl_buffer_send_release, base::Unretained(buffer_resource)));
283
284 SetImplementation(buffer_resource, &buffer_implementation, buffer.Pass());
285 }
286
287 void shm_pool_destroy(wl_client* client, wl_resource* resource) {
288 wl_resource_destroy(resource);
289 }
290
291 void shm_pool_resize(wl_client* client, wl_resource* resource, int32_t size) {
292 // Nothing to do here.
293 }
294
295 const struct wl_shm_pool_interface shm_pool_implementation = {
296 shm_pool_create_buffer, shm_pool_destroy, shm_pool_resize};
297
298 const uint32_t shm_pool_version = 1;
299
300 ////////////////////////////////////////////////////////////////////////////////
301 // wl_shm_interface:
302
303 void shm_create_pool(wl_client* client,
304 wl_resource* resource,
305 uint32_t id,
306 int fd,
307 int32_t size) {
308 scoped_ptr<SharedMemory> shared_memory =
309 GetUserDataAs<Display>(resource)
310 ->CreateSharedMemory(base::FileDescriptor(fd, true), size);
311 if (!shared_memory) {
312 wl_resource_post_no_memory(resource);
313 return;
314 }
315
316 wl_resource* shm_pool_resource = wl_resource_create(
317 client, &wl_shm_pool_interface, wl_resource_get_version(resource), id);
318 if (!shm_pool_resource) {
319 wl_resource_post_no_memory(resource);
320 return;
321 }
322
323 SetImplementation(shm_pool_resource, &shm_pool_implementation,
324 shared_memory.Pass());
325 }
326
327 const struct wl_shm_interface shm_implementation = {shm_create_pool};
328
329 const uint32_t shm_version = 1;
330
331 void bind_shm(wl_client* client, void* data, uint32_t version, uint32_t id) {
332 wl_resource* resource = wl_resource_create(
333 client, &wl_shm_interface, std::min(version, shm_version), id);
334 if (!resource) {
335 wl_client_post_no_memory(client);
336 return;
337 }
338
339 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr);
340
341 for (const auto& supported_format : shm_supported_formats)
342 wl_shm_send_format(resource, supported_format.shm_format);
343 }
344
345 ////////////////////////////////////////////////////////////////////////////////
346 // wl_shell_surface_interface:
347
348 void shell_surface_pong(wl_client* client,
349 wl_resource* resource,
350 uint32_t serial) {
351 NOTIMPLEMENTED();
352 }
353
354 void shell_surface_move(wl_client* client,
355 wl_resource* resource,
356 wl_resource* seat_resource,
357 uint32_t serial) {
358 NOTIMPLEMENTED();
359 }
360
361 void shell_surface_resize(wl_client* client,
362 wl_resource* resource,
363 wl_resource* seat_resource,
364 uint32_t serial,
365 uint32_t edges) {
366 NOTIMPLEMENTED();
367 }
368
369 void shell_surface_set_toplevel(wl_client* client, wl_resource* resource) {
370 NOTIMPLEMENTED();
371 }
372
373 void shell_surface_set_transient(wl_client* client,
374 wl_resource* resource,
375 wl_resource* parent_resource,
376 int x,
377 int y,
378 uint32_t flags) {
379 NOTIMPLEMENTED();
380 }
381
382 void shell_surface_set_fullscreen(wl_client* client,
383 wl_resource* resource,
384 uint32_t method,
385 uint32_t framerate,
386 wl_resource* output_resource) {
387 GetUserDataAs<ShellSurface>(resource)->SetFullscreen(true);
388 }
389
390 void shell_surface_set_popup(wl_client* client,
391 wl_resource* resource,
392 wl_resource* seat_resource,
393 uint32_t serial,
394 wl_resource* parent_resource,
395 int32_t x,
396 int32_t y,
397 uint32_t flags) {
398 NOTIMPLEMENTED();
399 }
400
401 void shell_surface_set_maximized(wl_client* client,
402 wl_resource* resource,
403 wl_resource* output_resource) {
404 NOTIMPLEMENTED();
405 }
406
407 void shell_surface_set_title(wl_client* client,
408 wl_resource* resource,
409 const char* title) {
410 GetUserDataAs<ShellSurface>(resource)->SetTitle(title);
411 }
412
413 void shell_surface_set_class(wl_client* client,
414 wl_resource* resource,
415 const char* clazz) {
416 NOTIMPLEMENTED();
417 }
418
419 const struct wl_shell_surface_interface shell_surface_implementation = {
420 shell_surface_pong, shell_surface_move,
421 shell_surface_resize, shell_surface_set_toplevel,
422 shell_surface_set_transient, shell_surface_set_fullscreen,
423 shell_surface_set_popup, shell_surface_set_maximized,
424 shell_surface_set_title, shell_surface_set_class};
425
426 ////////////////////////////////////////////////////////////////////////////////
427 // wl_shell_interface:
428
429 void shell_get_shell_surface(wl_client* client,
430 wl_resource* resource,
431 uint32_t id,
432 wl_resource* surface) {
433 scoped_ptr<ShellSurface> shell_surface =
434 GetUserDataAs<Display>(resource)
435 ->GetShellSurface(GetUserDataAs<Surface>(surface));
436 if (!shell_surface) {
437 wl_resource_post_no_memory(resource);
438 return;
439 }
440
441 wl_resource* shell_surface_resource =
442 wl_resource_create(client, &wl_shell_surface_interface,
443 wl_resource_get_version(resource), id);
444 if (!shell_surface_resource) {
445 wl_resource_post_no_memory(resource);
446 return;
447 }
448
449 SetImplementation(shell_surface_resource, &shell_surface_implementation,
450 shell_surface.Pass());
451 }
452
453 const struct wl_shell_interface shell_implementation = {
454 shell_get_shell_surface};
455
456 const uint32_t shell_version = 1;
457
458 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) {
459 wl_resource* resource = wl_resource_create(
460 client, &wl_shell_interface, std::min(version, shell_version), id);
461 if (!resource) {
462 wl_client_post_no_memory(client);
463 return;
464 }
465 wl_resource_set_implementation(resource, &shell_implementation, data,
466 nullptr);
467 }
468
469 #endif // COMPONENTS_EXO_WAYLAND_WAYLAND_BINDINGS_H_
OLDNEW
« components/exo/surface.cc ('K') | « components/exo/wayland/server_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698