-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new exportable interface that outputs EGL images
This new interface is intended to make the backend easy to use by EGL-based applications. A single callback 'export_egl_image' will provide applications with an already constructed, ready to render EGL image. A side benefit of this is that the actual protocol used by the backend's nested compositor (wl_surface, linux-dmabuf, etc) becomes transparent to the application. This new interface is built conditionally by setting the -DEXPORTABLE_EGL cmake option. It is ON by default.
- Loading branch information
Showing
4 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2018 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_EGL_H_INSIDE__) && !defined(WPE_FDO_COMPILATION) | ||
#error "Only <wpe/fdo-egl.h> can be included directly." | ||
#endif | ||
|
||
#ifndef __view_backend_exportable_egl_h__ | ||
#define __view_backend_exportable_egl_h__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <wpe/wpe.h> | ||
|
||
typedef void* EGLImageKHR; | ||
|
||
struct wpe_view_backend_exportable_fdo; | ||
|
||
struct wpe_view_backend_exportable_fdo_egl_client { | ||
void (*export_egl_image)(void* data, EGLImageKHR image); | ||
void (*_wpe_reserved0)(void); | ||
void (*_wpe_reserved1)(void); | ||
void (*_wpe_reserved2)(void); | ||
void (*_wpe_reserved3)(void); | ||
}; | ||
|
||
struct wpe_view_backend_exportable_fdo* | ||
wpe_view_backend_exportable_fdo_egl_create(struct wpe_view_backend_exportable_fdo_egl_client*, void*, uint32_t width, uint32_t height); | ||
|
||
void | ||
wpe_view_backend_exportable_fdo_egl_dispatch_release_image(struct wpe_view_backend_exportable_fdo* exportable, EGLImageKHR image); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __view_backend_exportable_egl_h___ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright (C) 2018 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. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include "ws.h" | ||
#include "view-backend-exportable-fdo.h" | ||
#include "wpe-fdo/view-backend-exportable-egl.h" | ||
#include <EGL/egl.h> | ||
#include <EGL/eglext.h> | ||
#include <list> | ||
|
||
namespace { | ||
|
||
struct buffer_data { | ||
struct wl_resource *buffer_resource; | ||
EGLImageKHR egl_image; | ||
}; | ||
|
||
class ClientBundleEGL : public ClientBundleBase { | ||
public: | ||
ClientBundleEGL(struct wpe_view_backend_exportable_fdo_egl_client* _client, void* data, | ||
ViewBackend* viewBackend, uint32_t initialWidth, uint32_t initialHeight) | ||
: ClientBundleBase(data, viewBackend, initialWidth, initialHeight) | ||
, client(_client) | ||
{ | ||
m_eglDisplay = WS::Instance::singleton().getEGLDisplay(); | ||
assert (m_eglDisplay); | ||
|
||
eglCreateImage = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress ("eglCreateImageKHR"); | ||
assert (eglCreateImage); | ||
|
||
eglDestroyImage = (PFNEGLDESTROYIMAGEKHRPROC) | ||
eglGetProcAddress ("eglDestroyImageKHR"); | ||
assert (eglDestroyImage); | ||
} | ||
|
||
~ClientBundleEGL() | ||
{ | ||
for (auto* buf_data : m_buffers) { | ||
assert(buf_data->egl_image); | ||
eglDestroyImage(m_eglDisplay, buf_data->egl_image); | ||
|
||
delete buf_data; | ||
} | ||
m_buffers.clear(); | ||
} | ||
|
||
void exportBuffer(struct wl_resource *bufferResource) override | ||
{ | ||
static const EGLint image_attrs[] = { | ||
EGL_WAYLAND_PLANE_WL, 0, | ||
EGL_NONE | ||
}; | ||
EGLImageKHR image = eglCreateImage (m_eglDisplay, | ||
EGL_NO_CONTEXT, | ||
EGL_WAYLAND_BUFFER_WL, | ||
bufferResource, | ||
image_attrs); | ||
if (!image) | ||
return; | ||
|
||
auto* buf_data = new struct buffer_data; | ||
buf_data->buffer_resource = bufferResource; | ||
buf_data->egl_image = image; | ||
m_buffers.push_back(buf_data); | ||
|
||
client->export_egl_image(data, image); | ||
} | ||
|
||
struct buffer_data* releaseImage(EGLImageKHR image) | ||
{ | ||
for (auto* buf_data : m_buffers) | ||
if (buf_data->egl_image == image) { | ||
m_buffers.remove(buf_data); | ||
eglDestroyImage(m_eglDisplay, buf_data->egl_image); | ||
|
||
return buf_data; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
struct wpe_view_backend_exportable_fdo_egl_client* client; | ||
|
||
private: | ||
EGLDisplay m_eglDisplay; | ||
PFNEGLCREATEIMAGEKHRPROC eglCreateImage; | ||
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImage; | ||
|
||
std::list<struct buffer_data*> m_buffers; | ||
}; | ||
|
||
} // namespace | ||
|
||
extern "C" { | ||
|
||
__attribute__((visibility("default"))) | ||
struct wpe_view_backend_exportable_fdo* | ||
wpe_view_backend_exportable_fdo_egl_create(struct wpe_view_backend_exportable_fdo_egl_client* client, void* data, uint32_t width, uint32_t height) | ||
{ | ||
auto* clientBundle = new ClientBundleEGL(client, data, nullptr, width, height); | ||
|
||
return wpe_view_backend_exportable_fdo_new(clientBundle); | ||
} | ||
|
||
__attribute__((visibility("default"))) | ||
void | ||
wpe_view_backend_exportable_fdo_egl_dispatch_release_image(struct wpe_view_backend_exportable_fdo* exportable, EGLImageKHR image) | ||
{ | ||
auto* clientBundle = reinterpret_cast<ClientBundleEGL*> | ||
(wpe_view_backend_exportable_fdo_get_client_bundle(exportable)); | ||
|
||
auto* buffer_data = clientBundle->releaseImage(image); | ||
if (!buffer_data) | ||
return; | ||
|
||
/* the EGL image has already been destroyed by ClientBundleEGL */ | ||
|
||
if (buffer_data->buffer_resource) { | ||
wpe_view_backend_exportable_fdo_dispatch_release_buffer(exportable, | ||
buffer_data->buffer_resource); | ||
} | ||
|
||
delete buffer_data; | ||
} | ||
|
||
} |