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

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

Issue 2846203002: exo: no-roundtrip dmabuf import (Closed)
Patch Set: Created 3 years, 7 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
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 <alpha-compositing-unstable-v1-server-protocol.h> 7 #include <alpha-compositing-unstable-v1-server-protocol.h>
8 #include <gaming-input-unstable-v1-server-protocol.h> 8 #include <gaming-input-unstable-v1-server-protocol.h>
9 #include <gaming-input-unstable-v2-server-protocol.h> 9 #include <gaming-input-unstable-v2-server-protocol.h>
10 #include <grp.h> 10 #include <grp.h>
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 const auto& inserted = linux_buffer_params->planes.insert( 639 const auto& inserted = linux_buffer_params->planes.insert(
640 std::pair<uint32_t, LinuxBufferParams::Plane>(plane_idx, 640 std::pair<uint32_t, LinuxBufferParams::Plane>(plane_idx,
641 std::move(plane))); 641 std::move(plane)));
642 if (!inserted.second) { // The plane was already there. 642 if (!inserted.second) { // The plane was already there.
643 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET, 643 wl_resource_post_error(resource, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET,
644 "plane already set"); 644 "plane already set");
645 return; 645 return;
646 } 646 }
647 } 647 }
648 648
649 void linux_buffer_params_create(wl_client* client, 649 void linux_buffer_params_create_impl(wl_client* client,
reveman 2017/04/28 17:21:24 I think the code will be easier to read if you did
650 wl_resource* resource, 650 wl_resource* resource,
651 int32_t width, 651 uint32_t buffer_id,
652 int32_t height, 652 int32_t width,
653 uint32_t format, 653 int32_t height,
654 uint32_t flags) { 654 uint32_t format,
655 uint32_t flags) {
655 if (width <= 0 || height <= 0) { 656 if (width <= 0 || height <= 0) {
656 wl_resource_post_error(resource, 657 wl_resource_post_error(resource,
657 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, 658 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS,
658 "invalid width or height"); 659 "invalid width or height");
659 return; 660 return;
660 } 661 }
661 662
662 const auto* supported_format = std::find_if( 663 const auto* supported_format = std::find_if(
663 std::begin(dmabuf_supported_formats), std::end(dmabuf_supported_formats), 664 std::begin(dmabuf_supported_formats), std::end(dmabuf_supported_formats),
664 [format](const dmabuf_supported_format& supported_format) { 665 [format](const dmabuf_supported_format& supported_format) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 LinuxBufferParams::Plane& plane = plane_it->second; 706 LinuxBufferParams::Plane& plane = plane_it->second;
706 planes.emplace_back(plane.stride, plane.offset, 0, 0); 707 planes.emplace_back(plane.stride, plane.offset, 0, 0);
707 fds.push_back(std::move(plane.fd)); 708 fds.push_back(std::move(plane.fd));
708 } 709 }
709 710
710 std::unique_ptr<Buffer> buffer = 711 std::unique_ptr<Buffer> buffer =
711 linux_buffer_params->display->CreateLinuxDMABufBuffer( 712 linux_buffer_params->display->CreateLinuxDMABufBuffer(
712 gfx::Size(width, height), supported_format->buffer_format, planes, 713 gfx::Size(width, height), supported_format->buffer_format, planes,
713 std::move(fds)); 714 std::move(fds));
714 if (!buffer) { 715 if (!buffer) {
715 zwp_linux_buffer_params_v1_send_failed(resource); 716 // buffer_id != 0 indicates a create_immed request. on import failure
716 return; 717 // in that case, the protocol allows us to raise a fatal error from
718 // zwp_linux_dmabuf_v1 version 2+.
719 if (buffer_id == 0)
720 zwp_linux_buffer_params_v1_send_failed(resource);
721 else {
722 wl_resource_post_error(resource,
723 ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_WL_BUFFER,
724 "dmabuf import failed");
725 return;
726 }
717 } 727 }
718 728
719 wl_resource* buffer_resource = 729 wl_resource* buffer_resource =
720 wl_resource_create(client, &wl_buffer_interface, 1, 0); 730 wl_resource_create(client, &wl_buffer_interface, 1, buffer_id);
721 731
722 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, 732 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback,
723 base::Unretained(buffer_resource))); 733 base::Unretained(buffer_resource)));
724 734
725 SetImplementation(buffer_resource, &buffer_implementation, std::move(buffer)); 735 SetImplementation(buffer_resource, &buffer_implementation, std::move(buffer));
726 736
727 zwp_linux_buffer_params_v1_send_created(resource, buffer_resource); 737 // for a create_immed request, no event is triggered.
738 if (buffer_id == 0)
739 zwp_linux_buffer_params_v1_send_created(resource, buffer_resource);
740 }
741
742 void linux_buffer_params_create(wl_client* client,
743 wl_resource* resource,
744 int32_t width,
745 int32_t height,
746 uint32_t format,
747 uint32_t flags) {
748 linux_buffer_params_create_impl(client, resource, 0, width, height, format,
749 flags);
750 }
751
752 void linux_buffer_params_create_immed(wl_client* client,
753 wl_resource* resource,
754 uint32_t buffer_id,
755 int32_t width,
756 int32_t height,
757 uint32_t format,
758 uint32_t flags) {
759 linux_buffer_params_create_impl(client, resource, buffer_id, width, height,
760 format, flags);
728 } 761 }
729 762
730 const struct zwp_linux_buffer_params_v1_interface 763 const struct zwp_linux_buffer_params_v1_interface
731 linux_buffer_params_implementation = {linux_buffer_params_destroy, 764 linux_buffer_params_implementation = {
732 linux_buffer_params_add, 765 linux_buffer_params_destroy, linux_buffer_params_add,
733 linux_buffer_params_create}; 766 linux_buffer_params_create, linux_buffer_params_create_immed};
734 767
735 //////////////////////////////////////////////////////////////////////////////// 768 ////////////////////////////////////////////////////////////////////////////////
736 // linux_dmabuf_interface: 769 // linux_dmabuf_interface:
737 770
738 void linux_dmabuf_destroy(wl_client* client, wl_resource* resource) { 771 void linux_dmabuf_destroy(wl_client* client, wl_resource* resource) {
739 wl_resource_destroy(resource); 772 wl_resource_destroy(resource);
740 } 773 }
741 774
742 void linux_dmabuf_create_params(wl_client* client, 775 void linux_dmabuf_create_params(wl_client* client,
743 wl_resource* resource, 776 wl_resource* resource,
744 uint32_t id) { 777 uint32_t id) {
745 std::unique_ptr<LinuxBufferParams> linux_buffer_params = 778 std::unique_ptr<LinuxBufferParams> linux_buffer_params =
746 base::MakeUnique<LinuxBufferParams>(GetUserDataAs<Display>(resource)); 779 base::MakeUnique<LinuxBufferParams>(GetUserDataAs<Display>(resource));
747 780
748 wl_resource* linux_buffer_params_resource = 781 wl_resource* linux_buffer_params_resource =
749 wl_resource_create(client, &zwp_linux_buffer_params_v1_interface, 1, id); 782 wl_resource_create(client, &zwp_linux_buffer_params_v1_interface, 2, id);
750 783
751 SetImplementation(linux_buffer_params_resource, 784 SetImplementation(linux_buffer_params_resource,
752 &linux_buffer_params_implementation, 785 &linux_buffer_params_implementation,
753 std::move(linux_buffer_params)); 786 std::move(linux_buffer_params));
754 } 787 }
755 788
756 const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation = { 789 const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation = {
757 linux_dmabuf_destroy, linux_dmabuf_create_params}; 790 linux_dmabuf_destroy, linux_dmabuf_create_params};
758 791
759 void bind_linux_dmabuf(wl_client* client, 792 void bind_linux_dmabuf(wl_client* client,
760 void* data, 793 void* data,
761 uint32_t version, 794 uint32_t version,
762 uint32_t id) { 795 uint32_t id) {
763 wl_resource* resource = 796 wl_resource* resource =
764 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id); 797 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, version, id);
765 798
766 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data, 799 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data,
767 nullptr); 800 nullptr);
768 801
769 for (const auto& supported_format : dmabuf_supported_formats) 802 for (const auto& supported_format : dmabuf_supported_formats)
770 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format); 803 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format);
771 } 804 }
772 805
773 #endif 806 #endif
774 807
(...skipping 3071 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 // Server, public: 3879 // Server, public:
3847 3880
3848 Server::Server(Display* display) 3881 Server::Server(Display* display)
3849 : display_(display), wl_display_(wl_display_create()) { 3882 : display_(display), wl_display_(wl_display_create()) {
3850 wl_global_create(wl_display_.get(), &wl_compositor_interface, 3883 wl_global_create(wl_display_.get(), &wl_compositor_interface,
3851 compositor_version, display_, bind_compositor); 3884 compositor_version, display_, bind_compositor);
3852 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); 3885 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm);
3853 #if defined(USE_OZONE) 3886 #if defined(USE_OZONE)
3854 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, 3887 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_,
3855 bind_drm); 3888 bind_drm);
3856 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1, 3889 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 2,
3857 display_, bind_linux_dmabuf); 3890 display_, bind_linux_dmabuf);
3858 #endif 3891 #endif
3859 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, 3892 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_,
3860 bind_subcompositor); 3893 bind_subcompositor);
3861 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, 3894 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_,
3862 bind_shell); 3895 bind_shell);
3863 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, 3896 wl_global_create(wl_display_.get(), &wl_output_interface, output_version,
3864 display_, bind_output); 3897 display_, bind_output);
3865 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, 3898 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_,
3866 bind_xdg_shell_v5); 3899 bind_xdg_shell_v5);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 DCHECK(event_loop); 3989 DCHECK(event_loop);
3957 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3990 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3958 } 3991 }
3959 3992
3960 void Server::Flush() { 3993 void Server::Flush() {
3961 wl_display_flush_clients(wl_display_.get()); 3994 wl_display_flush_clients(wl_display_.get());
3962 } 3995 }
3963 3996
3964 } // namespace wayland 3997 } // namespace wayland
3965 } // namespace exo 3998 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698