| 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 <grp.h> | 7 #include <grp.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "components/exo/surface.h" | 49 #include "components/exo/surface.h" |
| 50 #include "components/exo/touch.h" | 50 #include "components/exo/touch.h" |
| 51 #include "components/exo/touch_delegate.h" | 51 #include "components/exo/touch_delegate.h" |
| 52 #include "ipc/unix_domain_socket_util.h" | 52 #include "ipc/unix_domain_socket_util.h" |
| 53 #include "third_party/skia/include/core/SkRegion.h" | 53 #include "third_party/skia/include/core/SkRegion.h" |
| 54 #include "ui/aura/window_property.h" | 54 #include "ui/aura/window_property.h" |
| 55 #include "ui/base/hit_test.h" | 55 #include "ui/base/hit_test.h" |
| 56 #include "ui/display/display_observer.h" | 56 #include "ui/display/display_observer.h" |
| 57 #include "ui/display/screen.h" | 57 #include "ui/display/screen.h" |
| 58 #include "ui/events/keycodes/dom/keycode_converter.h" | 58 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 59 #include "ui/gfx/buffer_format_util.h" |
| 60 #include "ui/gfx/buffer_types.h" |
| 59 #include "ui/views/widget/widget.h" | 61 #include "ui/views/widget/widget.h" |
| 60 #include "ui/views/widget/widget_observer.h" | 62 #include "ui/views/widget/widget_observer.h" |
| 61 #include "ui/wm/public/activation_change_observer.h" | 63 #include "ui/wm/public/activation_change_observer.h" |
| 62 #include "ui/wm/public/activation_client.h" | 64 #include "ui/wm/public/activation_client.h" |
| 63 | 65 |
| 64 #if defined(USE_OZONE) | 66 #if defined(USE_OZONE) |
| 65 #include <drm_fourcc.h> | 67 #include <drm_fourcc.h> |
| 66 #include <linux-dmabuf-unstable-v1-server-protocol.h> | 68 #include <linux-dmabuf-unstable-v1-server-protocol.h> |
| 67 #include <wayland-drm-server-protocol.h> | 69 #include <wayland-drm-server-protocol.h> |
| 68 #endif | 70 #endif |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 // wl_drm_interface: | 445 // wl_drm_interface: |
| 444 | 446 |
| 445 const struct drm_supported_format { | 447 const struct drm_supported_format { |
| 446 uint32_t drm_format; | 448 uint32_t drm_format; |
| 447 gfx::BufferFormat buffer_format; | 449 gfx::BufferFormat buffer_format; |
| 448 } drm_supported_formats[] = { | 450 } drm_supported_formats[] = { |
| 449 {WL_DRM_FORMAT_RGB565, gfx::BufferFormat::BGR_565}, | 451 {WL_DRM_FORMAT_RGB565, gfx::BufferFormat::BGR_565}, |
| 450 {WL_DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, | 452 {WL_DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, |
| 451 {WL_DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, | 453 {WL_DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, |
| 452 {WL_DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, | 454 {WL_DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, |
| 453 {WL_DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}}; | 455 {WL_DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}, |
| 456 {WL_DRM_FORMAT_YVU420, gfx::BufferFormat::YVU_420}}; |
| 454 | 457 |
| 455 void drm_authenticate(wl_client* client, wl_resource* resource, uint32_t id) { | 458 void drm_authenticate(wl_client* client, wl_resource* resource, uint32_t id) { |
| 456 wl_drm_send_authenticated(resource); | 459 wl_drm_send_authenticated(resource); |
| 457 } | 460 } |
| 458 | 461 |
| 459 void drm_create_buffer(wl_client* client, | 462 void drm_create_buffer(wl_client* client, |
| 460 wl_resource* resource, | 463 wl_resource* resource, |
| 461 uint32_t id, | 464 uint32_t id, |
| 462 uint32_t name, | 465 uint32_t name, |
| 463 int32_t width, | 466 int32_t width, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 [format](const drm_supported_format& supported_format) { | 507 [format](const drm_supported_format& supported_format) { |
| 505 return supported_format.drm_format == format; | 508 return supported_format.drm_format == format; |
| 506 }); | 509 }); |
| 507 if (supported_format == | 510 if (supported_format == |
| 508 (drm_supported_formats + arraysize(drm_supported_formats))) { | 511 (drm_supported_formats + arraysize(drm_supported_formats))) { |
| 509 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, | 512 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, |
| 510 "invalid format 0x%x", format); | 513 "invalid format 0x%x", format); |
| 511 return; | 514 return; |
| 512 } | 515 } |
| 513 | 516 |
| 517 std::vector<int> strides{stride0, stride1, stride2}; |
| 518 std::vector<int> offsets{offset0, offset1, offset2}; |
| 519 std::vector<base::ScopedFD> fds; |
| 520 |
| 521 int planes = |
| 522 gfx::NumberOfPlanesForBufferFormat(supported_format->buffer_format); |
| 523 strides.resize(planes); |
| 524 offsets.resize(planes); |
| 525 fds.push_back(base::ScopedFD(name)); |
| 526 |
| 514 std::unique_ptr<Buffer> buffer = | 527 std::unique_ptr<Buffer> buffer = |
| 515 GetUserDataAs<Display>(resource)->CreateLinuxDMABufBuffer( | 528 GetUserDataAs<Display>(resource)->CreateLinuxDMABufBuffer( |
| 516 base::ScopedFD(name), gfx::Size(width, height), | 529 gfx::Size(width, height), supported_format->buffer_format, strides, |
| 517 supported_format->buffer_format, stride0); | 530 offsets, std::move(fds)); |
| 518 if (!buffer) { | 531 if (!buffer) { |
| 519 wl_resource_post_no_memory(resource); | 532 wl_resource_post_no_memory(resource); |
| 520 return; | 533 return; |
| 521 } | 534 } |
| 522 | 535 |
| 523 wl_resource* buffer_resource = | 536 wl_resource* buffer_resource = |
| 524 wl_resource_create(client, &wl_buffer_interface, 1, id); | 537 wl_resource_create(client, &wl_buffer_interface, 1, id); |
| 525 | 538 |
| 526 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, | 539 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, |
| 527 base::Unretained(buffer_resource))); | 540 base::Unretained(buffer_resource))); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 552 // linux_buffer_params_interface: | 565 // linux_buffer_params_interface: |
| 553 | 566 |
| 554 const struct dmabuf_supported_format { | 567 const struct dmabuf_supported_format { |
| 555 uint32_t dmabuf_format; | 568 uint32_t dmabuf_format; |
| 556 gfx::BufferFormat buffer_format; | 569 gfx::BufferFormat buffer_format; |
| 557 } dmabuf_supported_formats[] = { | 570 } dmabuf_supported_formats[] = { |
| 558 {DRM_FORMAT_RGB565, gfx::BufferFormat::BGR_565}, | 571 {DRM_FORMAT_RGB565, gfx::BufferFormat::BGR_565}, |
| 559 {DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, | 572 {DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, |
| 560 {DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, | 573 {DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, |
| 561 {DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, | 574 {DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, |
| 562 {DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}}; | 575 {DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}, |
| 576 {DRM_FORMAT_YVU420, gfx::BufferFormat::YVU_420}}; |
| 563 | 577 |
| 564 struct LinuxBufferParams { | 578 struct LinuxBufferParams { |
| 565 explicit LinuxBufferParams(Display* display) | 579 struct Plane { |
| 566 : display(display), stride(0), offset(0) {} | 580 base::ScopedFD fd; |
| 581 uint32_t stride; |
| 582 uint32_t offset; |
| 583 }; |
| 584 |
| 585 explicit LinuxBufferParams(Display* display) : display(display) {} |
| 567 | 586 |
| 568 Display* const display; | 587 Display* const display; |
| 569 base::ScopedFD fd; | 588 std::map<uint32_t, Plane> planes; |
| 570 uint32_t stride; | |
| 571 uint32_t offset; | |
| 572 }; | 589 }; |
| 573 | 590 |
| 574 void linux_buffer_params_destroy(wl_client* client, wl_resource* resource) { | 591 void linux_buffer_params_destroy(wl_client* client, wl_resource* resource) { |
| 575 wl_resource_destroy(resource); | 592 wl_resource_destroy(resource); |
| 576 } | 593 } |
| 577 | 594 |
| 578 void linux_buffer_params_add(wl_client* client, | 595 void linux_buffer_params_add(wl_client* client, |
| 579 wl_resource* resource, | 596 wl_resource* resource, |
| 580 int32_t fd, | 597 int32_t fd, |
| 581 uint32_t plane_idx, | 598 uint32_t plane_idx, |
| 582 uint32_t offset, | 599 uint32_t offset, |
| 583 uint32_t stride, | 600 uint32_t stride, |
| 584 uint32_t modifier_hi, | 601 uint32_t modifier_hi, |
| 585 uint32_t modifier_lo) { | 602 uint32_t modifier_lo) { |
| 586 if (plane_idx) { | |
| 587 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX, | |
| 588 "plane_idx too large"); | |
| 589 return; | |
| 590 } | |
| 591 | |
| 592 LinuxBufferParams* linux_buffer_params = | 603 LinuxBufferParams* linux_buffer_params = |
| 593 GetUserDataAs<LinuxBufferParams>(resource); | 604 GetUserDataAs<LinuxBufferParams>(resource); |
| 594 if (linux_buffer_params->fd.is_valid()) { | 605 |
| 606 LinuxBufferParams::Plane plane{base::ScopedFD(fd), stride, offset}; |
| 607 |
| 608 const auto& inserted = linux_buffer_params->planes.insert( |
| 609 std::pair<uint32_t, LinuxBufferParams::Plane>(plane_idx, |
| 610 std::move(plane))); |
| 611 if (!inserted.second) { // The plane was already there. |
| 595 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET, | 612 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET, |
| 596 "plane already set"); | 613 "plane already set"); |
| 597 return; | 614 return; |
| 598 } | 615 } |
| 599 | |
| 600 linux_buffer_params->fd.reset(fd); | |
| 601 linux_buffer_params->stride = stride; | |
| 602 linux_buffer_params->offset = offset; | |
| 603 } | 616 } |
| 604 | 617 |
| 605 void linux_buffer_params_create(wl_client* client, | 618 void linux_buffer_params_create(wl_client* client, |
| 606 wl_resource* resource, | 619 wl_resource* resource, |
| 607 int32_t width, | 620 int32_t width, |
| 608 int32_t height, | 621 int32_t height, |
| 609 uint32_t format, | 622 uint32_t format, |
| 610 uint32_t flags) { | 623 uint32_t flags) { |
| 611 if (width <= 0 || height <= 0) { | 624 if (width <= 0 || height <= 0) { |
| 612 wl_resource_post_error(resource, | 625 wl_resource_post_error(resource, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 630 if (flags & (ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT | | 643 if (flags & (ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT | |
| 631 ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED)) { | 644 ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED)) { |
| 632 wl_resource_post_error(resource, | 645 wl_resource_post_error(resource, |
| 633 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, | 646 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, |
| 634 "flags not supported"); | 647 "flags not supported"); |
| 635 return; | 648 return; |
| 636 } | 649 } |
| 637 | 650 |
| 638 LinuxBufferParams* linux_buffer_params = | 651 LinuxBufferParams* linux_buffer_params = |
| 639 GetUserDataAs<LinuxBufferParams>(resource); | 652 GetUserDataAs<LinuxBufferParams>(resource); |
| 640 if (linux_buffer_params->offset) { | 653 |
| 641 wl_resource_post_error(resource, | 654 size_t num_planes = |
| 642 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS, | 655 gfx::NumberOfPlanesForBufferFormat(supported_format->buffer_format); |
| 643 "offset not supported"); | 656 |
| 657 if (linux_buffer_params->planes.size() != num_planes) { |
| 658 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX, |
| 659 "plane idx out of bounds"); |
| 644 return; | 660 return; |
| 645 } | 661 } |
| 646 | 662 |
| 663 std::vector<int> strides; |
| 664 std::vector<int> offsets; |
| 665 std::vector<base::ScopedFD> fds; |
| 666 |
| 667 for (uint32_t i = 0; i < num_planes; ++i) { |
| 668 auto plane_it = linux_buffer_params->planes.find(i); |
| 669 if (plane_it == linux_buffer_params->planes.end()) { |
| 670 wl_resource_post_error(resource, |
| 671 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, |
| 672 "missing a plane"); |
| 673 return; |
| 674 } |
| 675 LinuxBufferParams::Plane& plane = plane_it->second; |
| 676 strides.push_back(plane.stride); |
| 677 offsets.push_back(plane.offset); |
| 678 if (plane.fd.is_valid()) |
| 679 fds.push_back(std::move(plane.fd)); |
| 680 } |
| 681 |
| 647 std::unique_ptr<Buffer> buffer = | 682 std::unique_ptr<Buffer> buffer = |
| 648 linux_buffer_params->display->CreateLinuxDMABufBuffer( | 683 linux_buffer_params->display->CreateLinuxDMABufBuffer( |
| 649 std::move(linux_buffer_params->fd), gfx::Size(width, height), | 684 gfx::Size(width, height), supported_format->buffer_format, strides, |
| 650 supported_format->buffer_format, linux_buffer_params->stride); | 685 offsets, std::move(fds)); |
| 651 if (!buffer) { | 686 if (!buffer) { |
| 652 zwp_linux_buffer_params_v1_send_failed(resource); | 687 zwp_linux_buffer_params_v1_send_failed(resource); |
| 653 return; | 688 return; |
| 654 } | 689 } |
| 655 | 690 |
| 656 wl_resource* buffer_resource = | 691 wl_resource* buffer_resource = |
| 657 wl_resource_create(client, &wl_buffer_interface, 1, 0); | 692 wl_resource_create(client, &wl_buffer_interface, 1, 0); |
| 658 | 693 |
| 659 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, | 694 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, |
| 660 base::Unretained(buffer_resource))); | 695 base::Unretained(buffer_resource))); |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2577 DCHECK(event_loop); | 2612 DCHECK(event_loop); |
| 2578 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2613 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2579 } | 2614 } |
| 2580 | 2615 |
| 2581 void Server::Flush() { | 2616 void Server::Flush() { |
| 2582 wl_display_flush_clients(wl_display_.get()); | 2617 wl_display_flush_clients(wl_display_.get()); |
| 2583 } | 2618 } |
| 2584 | 2619 |
| 2585 } // namespace wayland | 2620 } // namespace wayland |
| 2586 } // namespace exo | 2621 } // namespace exo |
| OLD | NEW |