Chromium Code Reviews| 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 | |
| 520 int planes = | |
| 521 gfx::NumberOfPlanesForBufferFormat(supported_format->buffer_format); | |
| 522 strides.resize(planes); | |
| 523 offsets.resize(planes); | |
| 524 std::vector<base::ScopedFD> fds{name}; | |
| 514 std::unique_ptr<Buffer> buffer = | 525 std::unique_ptr<Buffer> buffer = |
| 515 GetUserDataAs<Display>(resource)->CreateLinuxDMABufBuffer( | 526 GetUserDataAs<Display>(resource)->CreateLinuxDMABufBuffer( |
| 516 base::ScopedFD(name), gfx::Size(width, height), | 527 gfx::Size(width, height), supported_format->buffer_format, strides, |
| 517 supported_format->buffer_format, stride0); | 528 offsets, std::move(fds)); |
| 518 if (!buffer) { | 529 if (!buffer) { |
| 519 wl_resource_post_no_memory(resource); | 530 wl_resource_post_no_memory(resource); |
| 520 return; | 531 return; |
| 521 } | 532 } |
| 522 | 533 |
| 523 wl_resource* buffer_resource = | 534 wl_resource* buffer_resource = |
| 524 wl_resource_create(client, &wl_buffer_interface, 1, id); | 535 wl_resource_create(client, &wl_buffer_interface, 1, id); |
| 525 | 536 |
| 526 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, | 537 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, |
| 527 base::Unretained(buffer_resource))); | 538 base::Unretained(buffer_resource))); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 552 // linux_buffer_params_interface: | 563 // linux_buffer_params_interface: |
| 553 | 564 |
| 554 const struct dmabuf_supported_format { | 565 const struct dmabuf_supported_format { |
| 555 uint32_t dmabuf_format; | 566 uint32_t dmabuf_format; |
| 556 gfx::BufferFormat buffer_format; | 567 gfx::BufferFormat buffer_format; |
| 557 } dmabuf_supported_formats[] = { | 568 } dmabuf_supported_formats[] = { |
| 558 {DRM_FORMAT_RGB565, gfx::BufferFormat::BGR_565}, | 569 {DRM_FORMAT_RGB565, gfx::BufferFormat::BGR_565}, |
| 559 {DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, | 570 {DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, |
| 560 {DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, | 571 {DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, |
| 561 {DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, | 572 {DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, |
| 562 {DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}}; | 573 {DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}, |
| 574 {DRM_FORMAT_YVU420, gfx::BufferFormat::YVU_420}}; | |
| 563 | 575 |
| 564 struct LinuxBufferParams { | 576 struct LinuxBufferParams { |
| 565 explicit LinuxBufferParams(Display* display) | 577 explicit LinuxBufferParams(Display* display) : display(display) {} |
| 566 : display(display), stride(0), offset(0) {} | |
| 567 | 578 |
| 568 Display* const display; | 579 Display* const display; |
| 569 base::ScopedFD fd; | 580 struct Plane { |
|
reveman
2016/06/10 01:57:32
nit: class/struct before ctor please
Daniele Castagna
2016/06/10 02:08:24
Done.
| |
| 570 uint32_t stride; | 581 base::ScopedFD fd; |
| 571 uint32_t offset; | 582 uint32_t stride; |
| 583 uint32_t offset; | |
| 584 }; | |
| 585 std::map<uint32_t, Plane> planes; | |
| 572 }; | 586 }; |
| 573 | 587 |
| 574 void linux_buffer_params_destroy(wl_client* client, wl_resource* resource) { | 588 void linux_buffer_params_destroy(wl_client* client, wl_resource* resource) { |
| 575 wl_resource_destroy(resource); | 589 wl_resource_destroy(resource); |
| 576 } | 590 } |
| 577 | 591 |
| 578 void linux_buffer_params_add(wl_client* client, | 592 void linux_buffer_params_add(wl_client* client, |
| 579 wl_resource* resource, | 593 wl_resource* resource, |
| 580 int32_t fd, | 594 int32_t fd, |
| 581 uint32_t plane_idx, | 595 uint32_t plane_idx, |
| 582 uint32_t offset, | 596 uint32_t offset, |
| 583 uint32_t stride, | 597 uint32_t stride, |
| 584 uint32_t modifier_hi, | 598 uint32_t modifier_hi, |
| 585 uint32_t modifier_lo) { | 599 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 = | 600 LinuxBufferParams* linux_buffer_params = |
| 593 GetUserDataAs<LinuxBufferParams>(resource); | 601 GetUserDataAs<LinuxBufferParams>(resource); |
| 594 if (linux_buffer_params->fd.is_valid()) { | 602 |
| 603 LinuxBufferParams::Plane plane{base::ScopedFD(fd), stride, offset}; | |
| 604 const auto& emplaced = | |
| 605 linux_buffer_params->planes.emplace(plane_idx, std::move(plane)); | |
| 606 if (!emplaced.second) { // The plane was already there. | |
| 595 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET, | 607 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET, |
| 596 "plane already set"); | 608 "plane already set"); |
| 597 return; | 609 return; |
| 598 } | 610 } |
| 599 | |
| 600 linux_buffer_params->fd.reset(fd); | |
| 601 linux_buffer_params->stride = stride; | |
| 602 linux_buffer_params->offset = offset; | |
| 603 } | 611 } |
| 604 | 612 |
| 605 void linux_buffer_params_create(wl_client* client, | 613 void linux_buffer_params_create(wl_client* client, |
| 606 wl_resource* resource, | 614 wl_resource* resource, |
| 607 int32_t width, | 615 int32_t width, |
| 608 int32_t height, | 616 int32_t height, |
| 609 uint32_t format, | 617 uint32_t format, |
| 610 uint32_t flags) { | 618 uint32_t flags) { |
| 611 if (width <= 0 || height <= 0) { | 619 if (width <= 0 || height <= 0) { |
| 612 wl_resource_post_error(resource, | 620 wl_resource_post_error(resource, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 630 if (flags & (ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT | | 638 if (flags & (ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT | |
| 631 ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED)) { | 639 ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED)) { |
| 632 wl_resource_post_error(resource, | 640 wl_resource_post_error(resource, |
| 633 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, | 641 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, |
| 634 "flags not supported"); | 642 "flags not supported"); |
| 635 return; | 643 return; |
| 636 } | 644 } |
| 637 | 645 |
| 638 LinuxBufferParams* linux_buffer_params = | 646 LinuxBufferParams* linux_buffer_params = |
| 639 GetUserDataAs<LinuxBufferParams>(resource); | 647 GetUserDataAs<LinuxBufferParams>(resource); |
| 640 if (linux_buffer_params->offset) { | 648 |
| 641 wl_resource_post_error(resource, | 649 std::vector<base::ScopedFD> fds; |
| 642 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS, | 650 std::vector<int> strides; |
| 643 "offset not supported"); | 651 std::vector<int> offsets; |
| 652 | |
| 653 uint32_t plane_idx = 0; | |
| 654 for (auto& plane_entry : linux_buffer_params->planes) { | |
| 655 if (plane_entry.first != plane_idx) { | |
| 656 wl_resource_post_error(resource, | |
| 657 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, | |
| 658 "missing a plane"); | |
|
reveman
2016/06/10 01:57:32
should we continue looping after this?
Daniele Castagna
2016/06/10 02:08:24
No, return added.
| |
| 659 } | |
| 660 LinuxBufferParams::Plane& plane = plane_entry.second; | |
| 661 fds.push_back(std::move(plane.fd)); | |
|
reveman
2016/06/10 01:57:32
what if plane.fd is not valid?
Daniele Castagna
2016/06/10 02:08:24
We shouldn't add it then. Done.
| |
| 662 strides.push_back(plane.stride); | |
| 663 offsets.push_back(plane.offset); | |
| 664 ++plane_idx; | |
| 665 } | |
| 666 | |
| 667 if (!plane_idx || | |
| 668 plane_idx > 3) { // We don't support any format with more than 3 planes. | |
|
reveman
2016/06/10 01:57:32
We know the format here. Could we return an error
Daniele Castagna
2016/06/10 02:08:24
Yes, added the check before looping on the planes.
| |
| 669 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX, | |
| 670 "plane idx out of bounds"); | |
| 644 return; | 671 return; |
| 645 } | 672 } |
| 646 | 673 |
| 647 std::unique_ptr<Buffer> buffer = | 674 std::unique_ptr<Buffer> buffer = |
| 648 linux_buffer_params->display->CreateLinuxDMABufBuffer( | 675 linux_buffer_params->display->CreateLinuxDMABufBuffer( |
| 649 std::move(linux_buffer_params->fd), gfx::Size(width, height), | 676 gfx::Size(width, height), supported_format->buffer_format, strides, |
| 650 supported_format->buffer_format, linux_buffer_params->stride); | 677 offsets, std::move(fds)); |
| 651 if (!buffer) { | 678 if (!buffer) { |
| 652 zwp_linux_buffer_params_v1_send_failed(resource); | 679 zwp_linux_buffer_params_v1_send_failed(resource); |
| 653 return; | 680 return; |
| 654 } | 681 } |
| 655 | 682 |
| 656 wl_resource* buffer_resource = | 683 wl_resource* buffer_resource = |
| 657 wl_resource_create(client, &wl_buffer_interface, 1, 0); | 684 wl_resource_create(client, &wl_buffer_interface, 1, 0); |
| 658 | 685 |
| 659 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, | 686 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, |
| 660 base::Unretained(buffer_resource))); | 687 base::Unretained(buffer_resource))); |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2577 DCHECK(event_loop); | 2604 DCHECK(event_loop); |
| 2578 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2605 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2579 } | 2606 } |
| 2580 | 2607 |
| 2581 void Server::Flush() { | 2608 void Server::Flush() { |
| 2582 wl_display_flush_clients(wl_display_.get()); | 2609 wl_display_flush_clients(wl_display_.get()); |
| 2583 } | 2610 } |
| 2584 | 2611 |
| 2585 } // namespace wayland | 2612 } // namespace wayland |
| 2586 } // namespace exo | 2613 } // namespace exo |
| OLD | NEW |