OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/exo/wayland/server.h" | 5 #include "components/exo/wayland/server.h" |
6 | 6 |
7 #include <wayland-server-core.h> | 7 #include <wayland-server-core.h> |
8 #include <wayland-server-protocol-core.h> | 8 #include <wayland-server-protocol-core.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/exo/buffer.h" | 15 #include "components/exo/buffer.h" |
16 #include "components/exo/display.h" | 16 #include "components/exo/display.h" |
17 #include "components/exo/shared_memory.h" | 17 #include "components/exo/shared_memory.h" |
18 #include "components/exo/shell_surface.h" | 18 #include "components/exo/shell_surface.h" |
| 19 #include "components/exo/sub_surface.h" |
19 #include "components/exo/surface.h" | 20 #include "components/exo/surface.h" |
20 #include "third_party/skia/include/core/SkRegion.h" | 21 #include "third_party/skia/include/core/SkRegion.h" |
21 | 22 |
22 namespace exo { | 23 namespace exo { |
23 namespace wayland { | 24 namespace wayland { |
24 namespace { | 25 namespace { |
25 | 26 |
26 template <class T> | 27 template <class T> |
27 T* GetUserDataAs(wl_resource* resource) { | 28 T* GetUserDataAs(wl_resource* resource) { |
28 return static_cast<T*>(wl_resource_get_user_data(resource)); | 29 return static_cast<T*>(wl_resource_get_user_data(resource)); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return; | 358 return; |
358 } | 359 } |
359 | 360 |
360 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr); | 361 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr); |
361 | 362 |
362 for (const auto& supported_format : shm_supported_formats) | 363 for (const auto& supported_format : shm_supported_formats) |
363 wl_shm_send_format(resource, supported_format.shm_format); | 364 wl_shm_send_format(resource, supported_format.shm_format); |
364 } | 365 } |
365 | 366 |
366 //////////////////////////////////////////////////////////////////////////////// | 367 //////////////////////////////////////////////////////////////////////////////// |
| 368 // wl_subsurface_interface: |
| 369 |
| 370 void subsurface_destroy(wl_client* client, wl_resource* resource) { |
| 371 wl_resource_destroy(resource); |
| 372 } |
| 373 |
| 374 void subsurface_set_position(wl_client* client, |
| 375 wl_resource* resource, |
| 376 int32_t x, |
| 377 int32_t y) { |
| 378 GetUserDataAs<SubSurface>(resource)->SetPosition(gfx::Point(x, y)); |
| 379 } |
| 380 |
| 381 void subsurface_place_above(wl_client* client, |
| 382 wl_resource* resource, |
| 383 wl_resource* reference_resource) { |
| 384 GetUserDataAs<SubSurface>(resource) |
| 385 ->PlaceAbove(GetUserDataAs<Surface>(reference_resource)); |
| 386 } |
| 387 |
| 388 void subsurface_place_below(wl_client* client, |
| 389 wl_resource* resource, |
| 390 wl_resource* sibling_resource) { |
| 391 GetUserDataAs<SubSurface>(resource) |
| 392 ->PlaceBelow(GetUserDataAs<Surface>(sibling_resource)); |
| 393 } |
| 394 |
| 395 void subsurface_set_sync(wl_client* client, wl_resource* resource) { |
| 396 GetUserDataAs<SubSurface>(resource)->SetCommitBehavior(true); |
| 397 } |
| 398 |
| 399 void subsurface_set_desync(wl_client* client, wl_resource* resource) { |
| 400 GetUserDataAs<SubSurface>(resource)->SetCommitBehavior(false); |
| 401 } |
| 402 |
| 403 const struct wl_subsurface_interface subsurface_implementation = { |
| 404 subsurface_destroy, subsurface_set_position, subsurface_place_above, |
| 405 subsurface_place_below, subsurface_set_sync, subsurface_set_desync}; |
| 406 |
| 407 //////////////////////////////////////////////////////////////////////////////// |
| 408 // wl_subcompositor_interface: |
| 409 |
| 410 void subcompositor_destroy(wl_client* client, wl_resource* resource) { |
| 411 wl_resource_destroy(resource); |
| 412 } |
| 413 |
| 414 void subcompositor_get_subsurface(wl_client* client, |
| 415 wl_resource* resource, |
| 416 uint32_t id, |
| 417 wl_resource* surface, |
| 418 wl_resource* parent) { |
| 419 scoped_ptr<SubSurface> subsurface = |
| 420 GetUserDataAs<Display>(resource)->CreateSubSurface( |
| 421 GetUserDataAs<Surface>(surface), GetUserDataAs<Surface>(parent)); |
| 422 if (!subsurface) { |
| 423 wl_resource_post_no_memory(resource); |
| 424 return; |
| 425 } |
| 426 |
| 427 wl_resource* subsurface_resource = |
| 428 wl_resource_create(client, &wl_subsurface_interface, 1, id); |
| 429 if (!subsurface_resource) { |
| 430 wl_resource_post_no_memory(resource); |
| 431 return; |
| 432 } |
| 433 |
| 434 SetImplementation(subsurface_resource, &subsurface_implementation, |
| 435 subsurface.Pass()); |
| 436 } |
| 437 |
| 438 const struct wl_subcompositor_interface subcompositor_implementation = { |
| 439 subcompositor_destroy, subcompositor_get_subsurface}; |
| 440 |
| 441 void bind_subcompositor(wl_client* client, |
| 442 void* data, |
| 443 uint32_t version, |
| 444 uint32_t id) { |
| 445 wl_resource* resource = |
| 446 wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
| 447 if (!resource) { |
| 448 wl_client_post_no_memory(client); |
| 449 return; |
| 450 } |
| 451 wl_resource_set_implementation(resource, &subcompositor_implementation, data, |
| 452 nullptr); |
| 453 } |
| 454 |
| 455 //////////////////////////////////////////////////////////////////////////////// |
367 // wl_shell_surface_interface: | 456 // wl_shell_surface_interface: |
368 | 457 |
369 void shell_surface_pong(wl_client* client, | 458 void shell_surface_pong(wl_client* client, |
370 wl_resource* resource, | 459 wl_resource* resource, |
371 uint32_t serial) { | 460 uint32_t serial) { |
372 NOTIMPLEMENTED(); | 461 NOTIMPLEMENTED(); |
373 } | 462 } |
374 | 463 |
375 void shell_surface_move(wl_client* client, | 464 void shell_surface_move(wl_client* client, |
376 wl_resource* resource, | 465 wl_resource* resource, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } // namespace | 577 } // namespace |
489 | 578 |
490 //////////////////////////////////////////////////////////////////////////////// | 579 //////////////////////////////////////////////////////////////////////////////// |
491 // Server, public: | 580 // Server, public: |
492 | 581 |
493 Server::Server(Display* display) | 582 Server::Server(Display* display) |
494 : display_(display), wl_display_(wl_display_create()) { | 583 : display_(display), wl_display_(wl_display_create()) { |
495 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 584 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
496 compositor_version, display_, bind_compositor); | 585 compositor_version, display_, bind_compositor); |
497 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 586 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
| 587 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, |
| 588 bind_subcompositor); |
498 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, | 589 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, |
499 bind_shell); | 590 bind_shell); |
500 } | 591 } |
501 | 592 |
502 Server::~Server() {} | 593 Server::~Server() {} |
503 | 594 |
504 // static | 595 // static |
505 scoped_ptr<Server> Server::Create(Display* display) { | 596 scoped_ptr<Server> Server::Create(Display* display) { |
506 scoped_ptr<Server> server(new Server(display)); | 597 scoped_ptr<Server> server(new Server(display)); |
507 int rv = wl_display_add_socket(server->wl_display_.get(), nullptr); | 598 int rv = wl_display_add_socket(server->wl_display_.get(), nullptr); |
(...skipping 17 matching lines...) Expand all Loading... |
525 DCHECK(event_loop); | 616 DCHECK(event_loop); |
526 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 617 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
527 } | 618 } |
528 | 619 |
529 void Server::Flush() { | 620 void Server::Flush() { |
530 wl_display_flush_clients(wl_display_.get()); | 621 wl_display_flush_clients(wl_display_.get()); |
531 } | 622 } |
532 | 623 |
533 } // namespace wayland | 624 } // namespace wayland |
534 } // namespace exo | 625 } // namespace exo |
OLD | NEW |