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

Side by Side Diff: components/exo/wayland/server.cc

Issue 1745943003: exo: Add support for linux_dmabuf interface to wayland bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wayland-protocols-linux-dmabuf
Patch Set: Prime -> LinuxDMABuf Created 4 years, 9 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
« no previous file with comments | « components/exo/wayland/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <scaler-server-protocol.h> 9 #include <scaler-server-protocol.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 #include <wayland-server-core.h> 12 #include <wayland-server-core.h>
13 #include <wayland-server-protocol-core.h> 13 #include <wayland-server-protocol-core.h>
14 #include <xdg-shell-unstable-v5-server-protocol.h> 14 #include <xdg-shell-unstable-v5-server-protocol.h>
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <iterator>
17 #include <string> 18 #include <string>
18 #include <utility> 19 #include <utility>
19 20
20 #include "ash/display/display_info.h" 21 #include "ash/display/display_info.h"
21 #include "ash/display/display_manager.h" 22 #include "ash/display/display_manager.h"
22 #include "ash/shell.h" 23 #include "ash/shell.h"
23 #include "base/bind.h" 24 #include "base/bind.h"
24 #include "base/cancelable_callback.h" 25 #include "base/cancelable_callback.h"
25 #include "base/files/file_path.h" 26 #include "base/files/file_path.h"
26 #include "base/macros.h" 27 #include "base/macros.h"
(...skipping 10 matching lines...) Expand all
37 #include "components/exo/sub_surface.h" 38 #include "components/exo/sub_surface.h"
38 #include "components/exo/surface.h" 39 #include "components/exo/surface.h"
39 #include "components/exo/touch.h" 40 #include "components/exo/touch.h"
40 #include "components/exo/touch_delegate.h" 41 #include "components/exo/touch_delegate.h"
41 #include "ipc/unix_domain_socket_util.h" 42 #include "ipc/unix_domain_socket_util.h"
42 #include "third_party/skia/include/core/SkRegion.h" 43 #include "third_party/skia/include/core/SkRegion.h"
43 #include "ui/aura/window_property.h" 44 #include "ui/aura/window_property.h"
44 #include "ui/events/keycodes/dom/keycode_converter.h" 45 #include "ui/events/keycodes/dom/keycode_converter.h"
45 46
46 #if defined(USE_OZONE) 47 #if defined(USE_OZONE)
48 #include <drm_fourcc.h>
49 #include <linux-dmabuf-unstable-v1-server-protocol.h>
47 #include <wayland-drm-server-protocol.h> 50 #include <wayland-drm-server-protocol.h>
48 #endif 51 #endif
49 52
50 #if defined(USE_XKBCOMMON) 53 #if defined(USE_XKBCOMMON)
51 #include <xkbcommon/xkbcommon.h> 54 #include <xkbcommon/xkbcommon.h>
52 #include "ui/events/keycodes/scoped_xkb.h" 55 #include "ui/events/keycodes/scoped_xkb.h"
53 #endif 56 #endif
54 57
55 DECLARE_WINDOW_PROPERTY_TYPE(wl_resource*); 58 DECLARE_WINDOW_PROPERTY_TYPE(wl_resource*);
56 59
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 return supported_format.drm_format == format; 469 return supported_format.drm_format == format;
467 }); 470 });
468 if (supported_format == 471 if (supported_format ==
469 (drm_supported_formats + arraysize(drm_supported_formats))) { 472 (drm_supported_formats + arraysize(drm_supported_formats))) {
470 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, 473 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT,
471 "invalid format 0x%x", format); 474 "invalid format 0x%x", format);
472 return; 475 return;
473 } 476 }
474 477
475 scoped_ptr<Buffer> buffer = 478 scoped_ptr<Buffer> buffer =
476 GetUserDataAs<Display>(resource) 479 GetUserDataAs<Display>(resource)->CreateLinuxDMABufBuffer(
477 ->CreatePrimeBuffer(base::ScopedFD(name), gfx::Size(width, height), 480 base::ScopedFD(name), gfx::Size(width, height),
478 supported_format->buffer_format, stride0); 481 supported_format->buffer_format, stride0);
479 if (!buffer) { 482 if (!buffer) {
480 wl_resource_post_no_memory(resource); 483 wl_resource_post_no_memory(resource);
481 return; 484 return;
482 } 485 }
483 486
484 wl_resource* buffer_resource = 487 wl_resource* buffer_resource =
485 wl_resource_create(client, &wl_buffer_interface, 1, id); 488 wl_resource_create(client, &wl_buffer_interface, 1, id);
486 489
487 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, 490 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback,
488 base::Unretained(buffer_resource))); 491 base::Unretained(buffer_resource)));
(...skipping 12 matching lines...) Expand all
501 client, &wl_drm_interface, std::min(version, drm_version), id); 504 client, &wl_drm_interface, std::min(version, drm_version), id);
502 505
503 wl_resource_set_implementation(resource, &drm_implementation, data, nullptr); 506 wl_resource_set_implementation(resource, &drm_implementation, data, nullptr);
504 507
505 if (version >= 2) 508 if (version >= 2)
506 wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME); 509 wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME);
507 510
508 for (const auto& supported_format : drm_supported_formats) 511 for (const auto& supported_format : drm_supported_formats)
509 wl_drm_send_format(resource, supported_format.drm_format); 512 wl_drm_send_format(resource, supported_format.drm_format);
510 } 513 }
514
515 ////////////////////////////////////////////////////////////////////////////////
516 // linux_buffer_params_interface:
517
518 const struct dmabuf_supported_format {
519 uint32_t dmabuf_format;
520 gfx::BufferFormat buffer_format;
521 } dmabuf_supported_formats[] = {
522 {DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888},
523 {DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888},
524 {DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888},
525 {DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}};
526
527 struct LinuxBufferParams {
528 explicit LinuxBufferParams(Display* display)
529 : display(display), stride(0), offset(0) {}
530
531 Display* const display;
532 base::ScopedFD fd;
533 uint32_t stride;
534 uint32_t offset;
535 };
536
537 void linux_buffer_params_destroy(wl_client* client, wl_resource* resource) {
538 wl_resource_destroy(resource);
539 }
540
541 void linux_buffer_params_add(wl_client* client,
542 wl_resource* resource,
543 int32_t fd,
544 uint32_t plane_idx,
545 uint32_t offset,
546 uint32_t stride,
547 uint32_t modifier_hi,
548 uint32_t modifier_lo) {
549 if (plane_idx) {
550 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX,
551 "plane_idx too large");
552 return;
553 }
554
555 LinuxBufferParams* linux_buffer_params =
556 GetUserDataAs<LinuxBufferParams>(resource);
557 if (linux_buffer_params->fd.is_valid()) {
558 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET,
559 "plane already set");
560 return;
561 }
562
563 linux_buffer_params->fd.reset(fd);
564 linux_buffer_params->stride = stride;
565 linux_buffer_params->offset = offset;
566 }
567
568 void linux_buffer_params_create(wl_client* client,
569 wl_resource* resource,
570 int32_t width,
571 int32_t height,
572 uint32_t format,
573 uint32_t flags) {
574 if (width <= 0 || height <= 0) {
575 wl_resource_post_error(resource,
576 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS,
577 "invalid width or height");
578 return;
579 }
580
581 const auto* supported_format = std::find_if(
582 std::begin(dmabuf_supported_formats), std::end(dmabuf_supported_formats),
583 [format](const dmabuf_supported_format& supported_format) {
584 return supported_format.dmabuf_format == format;
585 });
586 if (supported_format == std::end(dmabuf_supported_formats)) {
587 wl_resource_post_error(resource,
588 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT,
589 "format not supported");
590 return;
591 }
592
593 if (flags & (ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT |
594 ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED)) {
595 wl_resource_post_error(resource,
596 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
597 "flags not supported");
598 return;
599 }
600
601 LinuxBufferParams* linux_buffer_params =
602 GetUserDataAs<LinuxBufferParams>(resource);
603 if (linux_buffer_params->offset) {
604 wl_resource_post_error(resource,
605 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
606 "offset not supported");
607 return;
608 }
609
610 scoped_ptr<Buffer> buffer =
611 linux_buffer_params->display->CreateLinuxDMABufBuffer(
612 std::move(linux_buffer_params->fd), gfx::Size(width, height),
613 supported_format->buffer_format, linux_buffer_params->stride);
614 if (!buffer) {
615 zwp_linux_buffer_params_v1_send_failed(resource);
616 return;
617 }
618
619 wl_resource* buffer_resource =
620 wl_resource_create(client, &wl_buffer_interface, 1, 0);
621
622 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback,
623 base::Unretained(buffer_resource)));
624
625 zwp_linux_buffer_params_v1_send_created(resource, buffer_resource);
626 }
627
628 const struct zwp_linux_buffer_params_v1_interface
629 linux_buffer_params_implementation = {linux_buffer_params_destroy,
630 linux_buffer_params_add,
631 linux_buffer_params_create};
632
633 ////////////////////////////////////////////////////////////////////////////////
634 // linux_dmabuf_interface:
635
636 void linux_dmabuf_destroy(wl_client* client, wl_resource* resource) {
637 wl_resource_destroy(resource);
638 }
639
640 void linux_dmabuf_create_params(wl_client* client,
641 wl_resource* resource,
642 uint32_t id) {
643 scoped_ptr<LinuxBufferParams> linux_buffer_params =
644 make_scoped_ptr(new LinuxBufferParams(GetUserDataAs<Display>(resource)));
645
646 wl_resource* linux_buffer_params_resource =
647 wl_resource_create(client, &zwp_linux_buffer_params_v1_interface, 1, id);
648
649 SetImplementation(linux_buffer_params_resource,
650 &linux_buffer_params_implementation,
651 std::move(linux_buffer_params));
652 }
653
654 const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation = {
655 linux_dmabuf_destroy, linux_dmabuf_create_params};
656
657 void bind_linux_dmabuf(wl_client* client,
658 void* data,
659 uint32_t version,
660 uint32_t id) {
661 wl_resource* resource =
662 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id);
663
664 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data,
665 nullptr);
666
667 for (const auto& supported_format : dmabuf_supported_formats)
668 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format);
669 }
670
511 #endif 671 #endif
512 672
513 //////////////////////////////////////////////////////////////////////////////// 673 ////////////////////////////////////////////////////////////////////////////////
514 // wl_subsurface_interface: 674 // wl_subsurface_interface:
515 675
516 void subsurface_destroy(wl_client* client, wl_resource* resource) { 676 void subsurface_destroy(wl_client* client, wl_resource* resource) {
517 wl_resource_destroy(resource); 677 wl_resource_destroy(resource);
518 } 678 }
519 679
520 void subsurface_set_position(wl_client* client, 680 void subsurface_set_position(wl_client* client,
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 // Server, public: 1747 // Server, public:
1588 1748
1589 Server::Server(Display* display) 1749 Server::Server(Display* display)
1590 : display_(display), wl_display_(wl_display_create()) { 1750 : display_(display), wl_display_(wl_display_create()) {
1591 wl_global_create(wl_display_.get(), &wl_compositor_interface, 1751 wl_global_create(wl_display_.get(), &wl_compositor_interface,
1592 compositor_version, display_, bind_compositor); 1752 compositor_version, display_, bind_compositor);
1593 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); 1753 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm);
1594 #if defined(USE_OZONE) 1754 #if defined(USE_OZONE)
1595 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, 1755 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_,
1596 bind_drm); 1756 bind_drm);
1757 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1,
1758 display_, bind_linux_dmabuf);
1597 #endif 1759 #endif
1598 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, 1760 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_,
1599 bind_subcompositor); 1761 bind_subcompositor);
1600 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, 1762 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_,
1601 bind_shell); 1763 bind_shell);
1602 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, 1764 wl_global_create(wl_display_.get(), &wl_output_interface, output_version,
1603 display_, bind_output); 1765 display_, bind_output);
1604 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, 1766 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_,
1605 bind_xdg_shell); 1767 bind_xdg_shell);
1606 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, 1768 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 DCHECK(event_loop); 1835 DCHECK(event_loop);
1674 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 1836 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
1675 } 1837 }
1676 1838
1677 void Server::Flush() { 1839 void Server::Flush() {
1678 wl_display_flush_clients(wl_display_.get()); 1840 wl_display_flush_clients(wl_display_.get());
1679 } 1841 }
1680 1842
1681 } // namespace wayland 1843 } // namespace wayland
1682 } // namespace exo 1844 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/wayland/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698