1 /* Copyright (C) <2018, 2019, 2020> Philippe Normand <philn@igalia.com>
2 * Copyright (C) <2018> Žan Doberšek <zdobersek@igalia.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #include "WPEThreadedView.h"
26 #include "gstwpesrcbin.h"
28 #include <gst/gl/gl.h>
29 #include <gst/gl/egl/gsteglimage.h>
30 #include <gst/gl/egl/gstgldisplay_egl.h>
31 #include <wayland-server.h>
36 #include <wpe/unstable/fdo-shm.h>
38 GST_DEBUG_CATEGORY_EXTERN (wpe_view_debug);
39 #define GST_CAT_DEFAULT wpe_view_debug
43 GMutexHolder(GMutex& mutex)
57 static WPEContextThread *s_view = NULL;
59 WPEContextThread& WPEContextThread::singleton()
61 static gsize initialized = 0;
63 if (g_once_init_enter (&initialized)) {
64 s_view = new WPEContextThread;
66 g_once_init_leave (&initialized, 1);
72 WPEContextThread::WPEContextThread()
74 g_mutex_init(&threading.mutex);
75 g_cond_init(&threading.cond);
78 GMutexHolder lock(threading.mutex);
79 threading.thread = g_thread_new("WPEContextThread", s_viewThread, this);
80 while (!threading.ready) {
81 g_cond_wait(&threading.cond, &threading.mutex);
83 GST_DEBUG("thread spawned");
87 WPEContextThread::~WPEContextThread()
89 if (threading.thread) {
90 g_thread_unref(threading.thread);
91 threading.thread = nullptr;
94 g_mutex_clear(&threading.mutex);
95 g_cond_clear(&threading.cond);
98 template<typename Function>
99 void WPEContextThread::dispatch(Function func)
104 struct Payload payload { func };
106 GSource* source = g_idle_source_new();
107 g_source_set_callback(source, [](gpointer data) -> gboolean {
108 auto& view = WPEContextThread::singleton();
109 GMutexHolder lock(view.threading.mutex);
111 auto* payload = static_cast<struct Payload*>(data);
114 g_cond_signal(&view.threading.cond);
115 return G_SOURCE_REMOVE;
116 }, &payload, nullptr);
117 g_source_set_priority(source, G_PRIORITY_DEFAULT);
120 GMutexHolder lock(threading.mutex);
121 g_source_attach(source, glib.context);
122 g_cond_wait(&threading.cond, &threading.mutex);
125 g_source_unref(source);
128 gpointer WPEContextThread::s_viewThread(gpointer data)
130 auto& view = *static_cast<WPEContextThread*>(data);
132 view.glib.context = g_main_context_new();
133 view.glib.loop = g_main_loop_new(view.glib.context, FALSE);
135 g_main_context_push_thread_default(view.glib.context);
138 GSource* source = g_idle_source_new();
139 g_source_set_callback(source,
140 [](gpointer data) -> gboolean {
141 auto& view = *static_cast<WPEContextThread*>(data);
142 GMutexHolder lock(view.threading.mutex);
143 view.threading.ready = TRUE;
144 g_cond_signal(&view.threading.cond);
145 return G_SOURCE_REMOVE;
148 g_source_attach(source, view.glib.context);
149 g_source_unref(source);
152 g_main_loop_run(view.glib.loop);
154 g_main_loop_unref(view.glib.loop);
155 view.glib.loop = nullptr;
157 g_main_context_pop_thread_default(view.glib.context);
158 g_main_context_unref(view.glib.context);
159 view.glib.context = nullptr;
165 initialize_web_extensions (WebKitWebContext *context)
167 webkit_web_context_set_web_extensions_directory (context, gst_wpe_get_extension_path ());
171 webkit_extension_gerror_msg_received (GstWpeSrc *src, GVariant *params)
173 GstStructure *structure;
174 GstMessage *forwarded;
175 const gchar *src_path, *src_type, *src_name, *error_domain, *msg, *debug_str, *details_str;
179 g_variant_get (params, "(issssusss)",
191 GError *error = g_error_new(g_quark_from_string(error_domain), error_code, "%s", msg);
192 GstStructure *details = (details_str[0] != '\0') ? gst_structure_new_from_string(details_str) : NULL;
193 gchar * our_message = g_strdup_printf(
194 "`%s` posted from %s running inside the web page",
199 if (message_type == GST_MESSAGE_ERROR) {
201 gst_message_new_error_with_details(GST_OBJECT(src), error,
202 our_message, details);
203 } else if (message_type == GST_MESSAGE_WARNING) {
205 gst_message_new_warning_with_details(GST_OBJECT(src), error,
206 our_message, details);
209 gst_message_new_info_with_details(GST_OBJECT(src), error, our_message, details);
212 structure = gst_structure_new ("WpeForwarded",
213 "message", GST_TYPE_MESSAGE, forwarded,
214 "wpe-original-src-name", G_TYPE_STRING, src_name,
215 "wpe-original-src-type", G_TYPE_STRING, src_type,
216 "wpe-original-src-path", G_TYPE_STRING, src_path,
220 g_free (our_message);
221 gst_element_post_message(GST_ELEMENT(src), gst_message_new_custom(GST_MESSAGE_ELEMENT,
222 GST_OBJECT(src), structure));
224 gst_message_unref (forwarded);
228 webkit_extension_bus_message_received (GstWpeSrc *src, GVariant *params)
230 GstStructure *original_structure, *structure;
231 const gchar *src_name, *src_type, *src_path, *struct_str;
232 GstMessageType message_type;
233 GstMessage *forwarded;
235 g_variant_get (params, "(issss)",
243 original_structure = (struct_str[0] != '\0') ? gst_structure_new_from_string(struct_str) : NULL;
244 if (!original_structure)
246 if (struct_str[0] != '\0')
247 GST_ERROR_OBJECT(src, "Could not deserialize: %s", struct_str);
248 original_structure = gst_structure_new_empty("wpesrc");
252 forwarded = gst_message_new_custom(message_type,
253 GST_OBJECT (src), original_structure);
254 structure = gst_structure_new ("WpeForwarded",
255 "message", GST_TYPE_MESSAGE, forwarded,
256 "wpe-original-src-name", G_TYPE_STRING, src_name,
257 "wpe-original-src-type", G_TYPE_STRING, src_type,
258 "wpe-original-src-path", G_TYPE_STRING, src_path,
262 gst_element_post_message(GST_ELEMENT(src), gst_message_new_custom(GST_MESSAGE_ELEMENT,
263 GST_OBJECT(src), structure));
265 gst_message_unref (forwarded);
269 webkit_extension_msg_received (WebKitWebContext *context,
270 WebKitUserMessage *message,
273 const gchar *name = webkit_user_message_get_name (message);
274 GVariant *params = webkit_user_message_get_parameters (message);
277 if (!g_strcmp0(name, "gstwpe.new_stream")) {
278 guint32 id = g_variant_get_uint32 (g_variant_get_child_value (params, 0));
279 const gchar *capsstr = g_variant_get_string (g_variant_get_child_value (params, 1), NULL);
280 GstCaps *caps = gst_caps_from_string (capsstr);
281 const gchar *stream_id = g_variant_get_string (g_variant_get_child_value (params, 2), NULL);
282 gst_wpe_src_new_audio_stream(src, id, caps, stream_id);
283 gst_caps_unref (caps);
284 } else if (!g_strcmp0(name, "gstwpe.set_shm")) {
285 auto fdlist = webkit_user_message_get_fd_list (message);
286 gint id = g_variant_get_uint32 (g_variant_get_child_value (params, 0));
287 gst_wpe_src_set_audio_shm (src, fdlist, id);
288 } else if (!g_strcmp0(name, "gstwpe.new_buffer")) {
289 guint32 id = g_variant_get_uint32 (g_variant_get_child_value (params, 0));
290 guint64 size = g_variant_get_uint64 (g_variant_get_child_value (params, 1));
291 gst_wpe_src_push_audio_buffer (src, id, size);
293 webkit_user_message_send_reply(message, webkit_user_message_new ("gstwpe.buffer_processed", NULL));
294 } else if (!g_strcmp0(name, "gstwpe.pause")) {
295 guint32 id = g_variant_get_uint32 (params);
297 gst_wpe_src_pause_audio_stream (src, id);
298 } else if (!g_strcmp0(name, "gstwpe.stop")) {
299 guint32 id = g_variant_get_uint32 (params);
301 gst_wpe_src_stop_audio_stream (src, id);
302 } else if (!g_strcmp0(name, "gstwpe.bus_gerror_message")) {
303 webkit_extension_gerror_msg_received (src, params);
304 } else if (!g_strcmp0(name, "gstwpe.bus_message")) {
305 webkit_extension_bus_message_received (src, params);
308 g_error("Unknown event: %s", name);
315 WPEView* WPEContextThread::createWPEView(GstWpeVideoSrc* src, GstGLContext* context, GstGLDisplay* display, int width, int height)
317 GST_DEBUG("context %p display %p, size (%d,%d)", context, display, width, height);
319 static std::once_flag s_loaderFlag;
320 std::call_once(s_loaderFlag,
322 wpe_loader_init("libWPEBackend-fdo-1.0.so");
325 WPEView* view = nullptr;
326 dispatch([&]() mutable {
327 auto* manager = webkit_website_data_manager_new_ephemeral();
328 auto web_context = webkit_web_context_new_with_website_data_manager(manager);
329 g_object_unref(manager);
331 view = new WPEView(web_context, src, context, display, width, height);
334 if (view && view->hasUri()) {
335 GST_DEBUG("waiting load to finish");
336 view->waitLoadCompletion();
343 static gboolean s_loadFailed(WebKitWebView*, WebKitLoadEvent, gchar* failing_uri, GError* error, gpointer data)
345 GstWpeVideoSrc* src = GST_WPE_VIDEO_SRC(data);
347 if (g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) {
348 GST_INFO_OBJECT (src, "Loading cancelled.");
353 GST_ELEMENT_ERROR (GST_ELEMENT_CAST(src), RESOURCE, FAILED, (NULL), ("Failed to load %s (%s)", failing_uri, error->message));
357 static gboolean s_loadFailedWithTLSErrors(WebKitWebView*, gchar* failing_uri, GTlsCertificate*, GTlsCertificateFlags, gpointer data)
359 // Defer to load-failed.
363 static void s_loadProgressChaned(GObject* object, GParamSpec*, gpointer data)
365 GstElement* src = GST_ELEMENT_CAST (data);
366 // The src element is locked already so we can't call
367 // gst_element_post_message(). Instead retrieve the bus manually and use it
369 GstBus* bus = GST_ELEMENT_BUS (src);
370 double estimatedProgress;
371 g_object_get(object, "estimated-load-progress", &estimatedProgress, nullptr);
372 gst_object_ref (bus);
373 gst_bus_post (bus, gst_message_new_element(GST_OBJECT_CAST(src), gst_structure_new("wpe-stats", "estimated-load-progress", G_TYPE_DOUBLE, estimatedProgress * 100, nullptr)));
374 gst_object_unref (bus);
377 WPEView::WPEView(WebKitWebContext* web_context, GstWpeVideoSrc* src, GstGLContext* context, GstGLDisplay* display, int width, int height)
381 GstObject *parent = gst_object_get_parent (GST_OBJECT (src));
383 if (parent && GST_IS_WPE_SRC (parent)) {
384 audio.init_ext_sigid = g_signal_connect (web_context,
385 "initialize-web-extensions",
386 G_CALLBACK (initialize_web_extensions),
388 audio.extension_msg_sigid = g_signal_connect (web_context,
389 "user-message-received",
390 G_CALLBACK (webkit_extension_msg_received),
392 GST_INFO_OBJECT (parent, "Enabled audio");
395 gst_clear_object (&parent);
399 g_mutex_init(&threading.ready_mutex);
400 g_cond_init(&threading.ready_cond);
401 threading.ready = FALSE;
403 g_mutex_init(&images_mutex);
405 gst.context = GST_GL_CONTEXT(gst_object_ref(context));
407 gst.display = GST_GL_DISPLAY(gst_object_ref(display));
413 if (context && display) {
414 if (gst_gl_context_get_gl_platform(context) == GST_GL_PLATFORM_EGL) {
415 gst.display_egl = gst_gl_display_egl_from_gl_display (gst.display);
417 GST_DEBUG ("Available GStreamer GL Context is not EGL - not creating an EGL display from it");
421 if (gst.display_egl) {
422 EGLDisplay eglDisplay = (EGLDisplay)gst_gl_display_get_handle (GST_GL_DISPLAY(gst.display_egl));
423 GST_DEBUG("eglDisplay %p", eglDisplay);
425 m_isValid = wpe_fdo_initialize_for_egl_display(eglDisplay);
426 GST_DEBUG("FDO EGL display initialisation result: %d", m_isValid);
428 m_isValid = wpe_fdo_initialize_shm();
429 GST_DEBUG("FDO SHM initialisation result: %d", m_isValid);
434 if (gst.display_egl) {
435 wpe.exportable = wpe_view_backend_exportable_fdo_egl_create(&s_exportableEGLClient, this, wpe.width, wpe.height);
437 wpe.exportable = wpe_view_backend_exportable_fdo_create(&s_exportableClient, this, wpe.width, wpe.height);
440 auto* wpeViewBackend = wpe_view_backend_exportable_fdo_get_view_backend(wpe.exportable);
441 auto* viewBackend = webkit_web_view_backend_new(wpeViewBackend, (GDestroyNotify) wpe_view_backend_exportable_fdo_destroy, wpe.exportable);
442 wpe_view_backend_add_activity_state(wpeViewBackend, wpe_view_activity_state_visible | wpe_view_activity_state_focused | wpe_view_activity_state_in_window);
444 webkit.view = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
445 "web-context", web_context,
446 "backend", viewBackend,
449 g_signal_connect(webkit.view, "load-failed", G_CALLBACK(s_loadFailed), src);
450 g_signal_connect(webkit.view, "load-failed-with-tls-errors", G_CALLBACK(s_loadFailedWithTLSErrors), src);
451 g_signal_connect(webkit.view, "notify::estimated-load-progress", G_CALLBACK(s_loadProgressChaned), src);
453 auto* settings = webkit_web_view_get_settings(webkit.view);
454 webkit_settings_set_enable_webaudio(settings, TRUE);
456 gst_wpe_video_src_configure_web_view(src, webkit.view);
459 gboolean drawBackground = TRUE;
460 g_object_get(src, "location", &location, "draw-background", &drawBackground, nullptr);
461 setDrawBackground(drawBackground);
463 loadUriUnlocked(location);
470 GstEGLImage *egl_pending = NULL;
471 GstEGLImage *egl_committed = NULL;
472 GstBuffer *shm_pending = NULL;
473 GstBuffer *shm_committed = NULL;
474 GST_TRACE ("%p destroying", this);
476 g_mutex_clear(&threading.ready_mutex);
477 g_cond_clear(&threading.ready_cond);
480 GMutexHolder lock(images_mutex);
483 egl_pending = egl.pending;
484 egl.pending = nullptr;
487 egl_committed = egl.committed;
488 egl.committed = nullptr;
491 GST_TRACE ("%p freeing shm pending %" GST_PTR_FORMAT, this, shm.pending);
492 shm_pending = shm.pending;
493 shm.pending = nullptr;
496 GST_TRACE ("%p freeing shm commited %" GST_PTR_FORMAT, this, shm.committed);
497 shm_committed = shm.committed;
498 shm.committed = nullptr;
503 gst_egl_image_unref (egl_pending);
505 gst_egl_image_unref (egl_committed);
507 gst_buffer_unref (shm_pending);
509 gst_buffer_unref (shm_committed);
511 if (audio.init_ext_sigid) {
512 WebKitWebContext* web_context = webkit_web_view_get_context (webkit.view);
514 g_signal_handler_disconnect(web_context, audio.init_ext_sigid);
515 g_signal_handler_disconnect(web_context, audio.extension_msg_sigid);
516 audio.init_ext_sigid = 0;
517 audio.extension_msg_sigid = 0;
520 WPEContextThread::singleton().dispatch([&]() {
522 g_object_unref(webkit.view);
523 webkit.view = nullptr;
527 if (gst.display_egl) {
528 gst_object_unref(gst.display_egl);
529 gst.display_egl = nullptr;
533 gst_object_unref(gst.display);
534 gst.display = nullptr;
538 gst_object_unref(gst.context);
539 gst.context = nullptr;
543 webkit.uri = nullptr;
546 g_mutex_clear(&images_mutex);
547 GST_TRACE ("%p destroyed", this);
550 void WPEView::notifyLoadFinished()
552 GMutexHolder lock(threading.ready_mutex);
553 if (!threading.ready) {
554 threading.ready = TRUE;
555 g_cond_signal(&threading.ready_cond);
559 void WPEView::waitLoadCompletion()
561 GMutexHolder lock(threading.ready_mutex);
562 while (!threading.ready)
563 g_cond_wait(&threading.ready_cond, &threading.ready_mutex);
566 GstEGLImage* WPEView::image()
568 GstEGLImage* ret = nullptr;
569 bool dispatchFrameComplete = false;
570 GstEGLImage *prev_image = NULL;
573 GMutexHolder lock(images_mutex);
575 GST_TRACE("pending %" GST_PTR_FORMAT " (%d) committed %" GST_PTR_FORMAT " (%d)", egl.pending,
576 GST_IS_EGL_IMAGE(egl.pending) ? GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST(egl.pending)) : 0,
578 GST_IS_EGL_IMAGE(egl.committed) ? GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST(egl.committed)) : 0);
581 prev_image = egl.committed;
582 egl.committed = egl.pending;
583 egl.pending = nullptr;
585 dispatchFrameComplete = true;
593 gst_egl_image_unref(prev_image);
595 if (dispatchFrameComplete)
601 GstBuffer* WPEView::buffer()
603 GstBuffer* ret = nullptr;
604 bool dispatchFrameComplete = false;
605 GstBuffer *prev_image = NULL;
608 GMutexHolder lock(images_mutex);
610 GST_TRACE("pending %" GST_PTR_FORMAT " (%d) committed %" GST_PTR_FORMAT " (%d)", shm.pending,
611 GST_IS_BUFFER(shm.pending) ? GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST(shm.pending)) : 0,
613 GST_IS_BUFFER(shm.committed) ? GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST(shm.committed)) : 0);
616 prev_image = shm.committed;
617 shm.committed = shm.pending;
618 shm.pending = nullptr;
620 dispatchFrameComplete = true;
628 gst_buffer_unref(prev_image);
630 if (dispatchFrameComplete)
636 void WPEView::resize(int width, int height)
638 GST_DEBUG("resize to %dx%d", width, height);
642 s_view->dispatch([&]() {
643 if (wpe.exportable && wpe_view_backend_exportable_fdo_get_view_backend(wpe.exportable))
644 wpe_view_backend_dispatch_set_size(wpe_view_backend_exportable_fdo_get_view_backend(wpe.exportable), wpe.width, wpe.height);
648 void WPEView::frameComplete()
650 GST_TRACE("frame complete");
651 s_view->dispatch([&]() {
652 GST_TRACE("dispatching");
653 wpe_view_backend_exportable_fdo_dispatch_frame_complete(wpe.exportable);
657 void WPEView::loadUriUnlocked(const gchar* uri)
662 GST_DEBUG("loading %s", uri);
663 webkit.uri = g_strdup(uri);
664 webkit_web_view_load_uri(webkit.view, webkit.uri);
667 void WPEView::loadUri(const gchar* uri)
669 s_view->dispatch([&]() {
670 loadUriUnlocked(uri);
674 void WPEView::loadData(GBytes* bytes)
676 s_view->dispatch([this, bytes = g_bytes_ref(bytes)]() {
677 webkit_web_view_load_bytes(webkit.view, bytes, nullptr, nullptr, nullptr);
678 g_bytes_unref(bytes);
682 void WPEView::setDrawBackground(gboolean drawsBackground)
684 GST_DEBUG("%s background rendering", drawsBackground ? "Enabling" : "Disabling");
686 webkit_color_parse(&color, drawsBackground ? "white" : "transparent");
687 webkit_web_view_set_background_color(webkit.view, &color);
690 void WPEView::releaseImage(gpointer imagePointer)
692 s_view->dispatch([&]() {
693 GST_TRACE("Dispatch release exported image %p", imagePointer);
694 wpe_view_backend_exportable_fdo_egl_dispatch_release_exported_image(wpe.exportable,
695 static_cast<struct wpe_fdo_egl_exported_image*>(imagePointer));
699 struct ImageContext {
704 void WPEView::handleExportedImage(gpointer image)
706 ImageContext* imageContext = g_slice_new(ImageContext);
707 imageContext->view = this;
708 imageContext->image = static_cast<gpointer>(image);
709 EGLImageKHR eglImage = wpe_fdo_egl_exported_image_get_egl_image(static_cast<struct wpe_fdo_egl_exported_image*>(image));
711 auto* gstImage = gst_egl_image_new_wrapped(gst.context, eglImage, GST_GL_RGBA, imageContext, s_releaseImage);
713 GMutexHolder lock(images_mutex);
715 GST_TRACE("EGLImage %p wrapped in GstEGLImage %" GST_PTR_FORMAT, eglImage, gstImage);
716 gst_clear_mini_object ((GstMiniObject **) &egl.pending);
717 egl.pending = gstImage;
719 notifyLoadFinished();
723 struct SHMBufferContext {
725 struct wpe_fdo_shm_exported_buffer* buffer;
728 void WPEView::releaseSHMBuffer(gpointer data)
730 SHMBufferContext* context = static_cast<SHMBufferContext*>(data);
731 s_view->dispatch([&]() {
732 auto* buffer = static_cast<struct wpe_fdo_shm_exported_buffer*>(context->buffer);
733 GST_TRACE("Dispatch release exported buffer %p", buffer);
734 wpe_view_backend_exportable_fdo_dispatch_release_shm_exported_buffer(wpe.exportable, buffer);
738 void WPEView::s_releaseSHMBuffer(gpointer data)
740 SHMBufferContext* context = static_cast<SHMBufferContext*>(data);
741 context->view->releaseSHMBuffer(data);
742 g_slice_free(SHMBufferContext, context);
745 void WPEView::handleExportedBuffer(struct wpe_fdo_shm_exported_buffer* buffer)
747 struct wl_shm_buffer* shmBuffer = wpe_fdo_shm_exported_buffer_get_shm_buffer(buffer);
748 auto format = wl_shm_buffer_get_format(shmBuffer);
749 if (format != WL_SHM_FORMAT_ARGB8888 && format != WL_SHM_FORMAT_XRGB8888) {
750 GST_ERROR("Unsupported pixel format: %d", format);
754 int32_t width = wl_shm_buffer_get_width(shmBuffer);
755 int32_t height = wl_shm_buffer_get_height(shmBuffer);
756 gint stride = wl_shm_buffer_get_stride(shmBuffer);
757 gsize size = width * height * 4;
758 auto* data = static_cast<uint8_t*>(wl_shm_buffer_get_data(shmBuffer));
760 SHMBufferContext* bufferContext = g_slice_new(SHMBufferContext);
761 bufferContext->view = this;
762 bufferContext->buffer = buffer;
764 auto* gstBuffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, data, size, 0, size, bufferContext, s_releaseSHMBuffer);
769 gst_buffer_add_video_meta_full(gstBuffer, GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_FORMAT_BGRA, width, height, 1, offsets, strides);
772 GMutexHolder lock(images_mutex);
773 GST_TRACE("SHM buffer %p wrapped in buffer %" GST_PTR_FORMAT, buffer, gstBuffer);
774 gst_clear_buffer (&shm.pending);
775 shm.pending = gstBuffer;
776 notifyLoadFinished();
780 struct wpe_view_backend_exportable_fdo_egl_client WPEView::s_exportableEGLClient = {
783 [](void* data, struct wpe_fdo_egl_exported_image* image) {
784 auto& view = *static_cast<WPEView*>(data);
785 view.handleExportedImage(static_cast<gpointer>(image));
792 struct wpe_view_backend_exportable_fdo_client WPEView::s_exportableClient = {
796 [](void* data, struct wpe_fdo_shm_exported_buffer* buffer) {
797 auto& view = *static_cast<WPEView*>(data);
798 view.handleExportedBuffer(buffer);
804 void WPEView::s_releaseImage(GstEGLImage* image, gpointer data)
806 ImageContext* context = static_cast<ImageContext*>(data);
807 context->view->releaseImage(context->image);
808 g_slice_free(ImageContext, context);
811 struct wpe_view_backend* WPEView::backend() const
813 return wpe.exportable ? wpe_view_backend_exportable_fdo_get_view_backend(wpe.exportable) : nullptr;
816 void WPEView::dispatchKeyboardEvent(struct wpe_input_keyboard_event& wpe_event)
818 s_view->dispatch([&]() {
819 wpe_view_backend_dispatch_keyboard_event(backend(), &wpe_event);
823 void WPEView::dispatchPointerEvent(struct wpe_input_pointer_event& wpe_event)
825 s_view->dispatch([&]() {
826 wpe_view_backend_dispatch_pointer_event(backend(), &wpe_event);
830 void WPEView::dispatchAxisEvent(struct wpe_input_axis_event& wpe_event)
832 s_view->dispatch([&]() {
833 wpe_view_backend_dispatch_axis_event(backend(), &wpe_event);