Skip to content

Commit

Permalink
Add unstable dmabuf-pool API
Browse files Browse the repository at this point in the history
Introduce wpe_view_backend_dmabuf_pool_fdo, a wpe_view_backend extension that
demands manual dmabuf managemenet from the user.

This approach to buffer management allows for most flexibility in terms of what
kind of dmabuf objects should be used for rendering. It allows for user to
specify in detail the format, multi-planarity and modifier data of the dmabuf
object.

In order to work with such dmabuf objects, the renderer_backend_egl interfaces
have to leverage a new WS::EGLClient implementation that uses custom Wayland
protocols to properly handle dmabuf content across process boundaries. To
correctly render into these objects, we have to leverage the surfaceless EGL
platform, along with importing the dmabuf objects into EGLImages that we then
use as backing resources for renderbuffers used to render a given frame.

For each wpe_view_backend_dmabuf_pool_fdo, the related client (managed by the
user) has to provide callback implementations that handle dmabuf pool entry
management as well as the notification of which dmabuf pool entry has been
committed for display as the content of the related view.

Upon the create_entry callback dispatch on the client, the callback (as provided
by the user) has to return a wpe_dmabuf_pool_entry object that was initialized
with the relevant dmabuf data. Upon the destroy_entry callback dispatch, the
specified object has to be destroyed.

The commit_entry callback dispatch on the client specifies which dmabuf object
should be presented on the screen, containing the most-recent composition of the
corresponding view's content.

The dmabuf pool entry allocations and deallocations are relayed from the
renderer_backend_target_egl implementation. Whenever a new buffer is required
for rendering, the renderer_backend_target_egl will request for a pool entry to
be created, getting back the relevant dmabuf information and spawning necessary
GL resources that are needed to render into that dmabuf. When finished, the
pool entry will be committed, leaving it up to the user to handle the pool entry
as required.
  • Loading branch information
zdobersek committed Mar 10, 2021
1 parent 1b3e33d commit 3b106e0
Show file tree
Hide file tree
Showing 32 changed files with 1,394 additions and 1 deletion.
66 changes: 66 additions & 0 deletions include/wpe/unstable/dmabuf-pool-entry.h
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2020 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#if !defined(__WPE_FDO_DMABUF_H_INSIDE__) && !defined(WPE_FDO_COMPILATION)
#error "Only <wpe/unstable/fdo-dmabuf.h> can be included directly."
#endif

#pragma once

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

struct wpe_dmabuf_pool_entry;

struct wpe_dmabuf_pool_entry_init {
uint32_t width;
uint32_t height;
uint32_t format;

unsigned num_planes;
int fds[4];
uint32_t strides[4];
uint32_t offsets[4];
uint64_t modifiers[4];
};

struct wpe_dmabuf_pool_entry*
wpe_dmabuf_pool_entry_create(const struct wpe_dmabuf_pool_entry_init*);

void
wpe_dmabuf_pool_entry_destroy(struct wpe_dmabuf_pool_entry*);

void
wpe_dmabuf_pool_entry_set_user_data(struct wpe_dmabuf_pool_entry*, void*);

void*
wpe_dmabuf_pool_entry_get_user_data(struct wpe_dmabuf_pool_entry*);

#ifdef __cplusplus
}
#endif
38 changes: 38 additions & 0 deletions include/wpe/unstable/fdo-dmabuf.h
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2020 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef __WEBKIT_WEB_EXTENSION_H__
#error "Headers <wpe/unstable/fdo-dmabuf.h> and <wpe/webkit-web-extension.h> cannot be included together."
#endif

#pragma once

#define __WPE_FDO_DMABUF_H_INSIDE__

#include "dmabuf-pool-entry.h"
#include "initialize-dmabuf.h"
#include "view-backend-dmabuf-pool-fdo.h"

#undef __WPE_FDO_DMABUF_H_INSIDE__
43 changes: 43 additions & 0 deletions include/wpe/unstable/initialize-dmabuf.h
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2020 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#if !defined(__WPE_FDO_DMABUF_H_INSIDE__) && !defined(WPE_FDO_COMPILATION)
#error "Only <wpe/unstable/fdo-dmabuf.h> can be included directly."
#endif

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

bool
wpe_fdo_initialize_dmabuf(void);

#ifdef __cplusplus
}
#endif
68 changes: 68 additions & 0 deletions include/wpe/unstable/view-backend-dmabuf-pool-fdo.h
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2020 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#if !defined(__WPE_FDO_DMABUF_H_INSIDE__) && !defined(WPE_FDO_COMPILATION)
#error "Only <wpe/unstable/fdo-dmabuf.h> can be included directly."
#endif

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <wpe/wpe.h>

struct wpe_dmabuf_pool_entry;

struct wpe_view_backend_dmabuf_pool_fdo_client {
struct wpe_dmabuf_pool_entry* (*create_entry)(void*);
void (*destroy_entry)(void*, struct wpe_dmabuf_pool_entry*);
void (*commit_entry)(void*, struct wpe_dmabuf_pool_entry*);

void (*_wpe_reserved0)(void);
void (*_wpe_reserved1)(void);
void (*_wpe_reserved2)(void);
void (*_wpe_reserved3)(void);
};

struct wpe_view_backend_dmabuf_pool_fdo*
wpe_view_backend_dmabuf_pool_fdo_create(const struct wpe_view_backend_dmabuf_pool_fdo_client*, void*, uint32_t width, uint32_t height);

void
wpe_view_backend_dmabuf_pool_fdo_destroy(struct wpe_view_backend_dmabuf_pool_fdo*);

struct wpe_view_backend*
wpe_view_backend_dmabuf_pool_fdo_get_view_backend(struct wpe_view_backend_dmabuf_pool_fdo*);

void
wpe_view_backend_dmabuf_pool_fdo_dispatch_frame_complete(struct wpe_view_backend_dmabuf_pool_fdo*);

void
wpe_view_backend_dmabuf_pool_fdo_dispatch_release_entry(struct wpe_view_backend_dmabuf_pool_fdo*, struct wpe_dmabuf_pool_entry*);

#ifdef __cplusplus
}
#endif
32 changes: 32 additions & 0 deletions meson.build
Expand Up @@ -39,23 +39,28 @@ soversion_micro = soversion[1] # Revision
soversion = '@0@.@1@.@2@'.format(soversion_major, soversion_minor, soversion_micro)

sources = [
'src/dmabuf-pool-entry.cpp',
'src/egl-client-dmabuf-pool.cpp',
'src/egl-client-wayland.cpp',
'src/exported-buffer-shm.cpp',
'src/exported-image-egl.cpp',
'src/fdo.cpp',
'src/initialize-dmabuf.cpp',
'src/initialize-egl.cpp',
'src/initialize-eglstream.cpp',
'src/initialize-shm.cpp',
'src/ipc.cpp',
'src/renderer-backend-egl.cpp',
'src/renderer-host.cpp',
'src/version.c',
'src/view-backend-dmabuf-pool-fdo.cpp',
'src/view-backend-exportable-fdo.cpp',
'src/view-backend-exportable-fdo-egl.cpp',
'src/view-backend-exportable-fdo-eglstream.cpp',
'src/view-backend-private.cpp',
'src/ws.cpp',
'src/ws-client.cpp',
'src/ws-dmabuf-pool.cpp',
'src/ws-egl.cpp',
'src/ws-eglstream.cpp',
'src/ws-shm.cpp',
Expand Down Expand Up @@ -90,10 +95,14 @@ extensions_api_headers = [
]

unstable_api_headers = [
'include/wpe/unstable/dmabuf-pool-entry.h',
'include/wpe/unstable/fdo-dmabuf.h',
'include/wpe/unstable/fdo-eglstream.h',
'include/wpe/unstable/fdo-shm.h',
'include/wpe/unstable/initialize-dmabuf.h',
'include/wpe/unstable/initialize-shm.h',
'include/wpe/unstable/initialize-eglstream.h',
'include/wpe/unstable/view-backend-dmabuf-pool-fdo.h',
'include/wpe/unstable/view-backend-exportable-eglstream.h',
]

Expand Down Expand Up @@ -210,6 +219,26 @@ wayland_eglstream_controller_proto_source = custom_target(
command: [wayland_scanner, wayland_scanner_code, '@INPUT@', '@OUTPUT@'],
)

# Wayland extension: dmabuf pool
wpe_dmabuf_pool_client_proto_header = custom_target(
'dmabuf-pool-client-proto-header',
input: 'src/dmabuf-pool/wpe-dmabuf-pool.xml',
output: '@BASENAME@-client-protocol.h',
command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
)
wpe_dmabuf_pool_server_proto_header = custom_target(
'dmabuf-pool-server-proto-header',
input: 'src/dmabuf-pool/wpe-dmabuf-pool.xml',
output: '@BASENAME@-server-protocol.h',
command: [wayland_scanner, 'server-header', '@INPUT@', '@OUTPUT@'],
)
wpe_dmabuf_pool_proto_source = custom_target(
'dmabuf-pool-proto-source',
input: 'src/dmabuf-pool/wpe-dmabuf-pool.xml',
output: '@BASENAME@-protocol.c',
command: [wayland_scanner, wayland_scanner_code, '@INPUT@', '@OUTPUT@'],
)

cxx = meson.get_compiler('cpp')

# Switch to the 'cpp_eh=none' default option when updating to Meson 0.51 or newer, see
Expand Down Expand Up @@ -299,6 +328,9 @@ generated_sources = [
wpe_video_plane_display_dmabuf_server_proto_header,
wayland_eglstream_controller_proto_source,
wayland_eglstream_controller_server_proto_header,
wpe_dmabuf_pool_client_proto_header,
wpe_dmabuf_pool_server_proto_header,
wpe_dmabuf_pool_proto_source,
]

lib = shared_library('WPEBackend-fdo-' + api_version,
Expand Down
1 change: 1 addition & 0 deletions src/bridge/wpe-bridge.xml
Expand Up @@ -29,6 +29,7 @@
<interface name="wpe_bridge" version="1">
<enum name="client_implementation_type">
<entry name="wayland" value="0"/>
<entry name="dmabuf_pool" value="1"/>
</enum>

<request name="initialize">
Expand Down
48 changes: 48 additions & 0 deletions src/dmabuf-pool-entry-private.h
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2020 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "wpe/unstable/dmabuf-pool-entry.h"

#include <array>

struct wl_resource;

struct wpe_dmabuf_pool_entry {
struct wl_resource* bufferResource { nullptr };

void* data { nullptr };

uint32_t width { 0 };
uint32_t height { 0 };
uint32_t format { 0 };

unsigned num_planes { 0 };
std::array<int, 4> fds { -1, -1, -1, -1 };
std::array<uint32_t, 4> strides { };
std::array<uint32_t, 4> offsets { };
std::array<uint64_t, 4> modifiers { };
};

0 comments on commit 3b106e0

Please sign in to comment.