1 /* Copyright (C) <2018> Philippe Normand <philn@igalia.com> 2 * Copyright (C) <2018> Žan Doberšek <zdobersek@igalia.com> 3 * 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. 8 * 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. 13 * 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. 18 */ 19 20 #pragma once 21 22 #include <EGL/egl.h> 23 #include <glib.h> 24 #include <gst/gl/gl.h> 25 #include <gst/gl/gstglfuncs.h> 26 #include <gst/gl/egl/gsteglimage.h> 27 #include <gst/gl/egl/gstgldisplay_egl.h> 28 #include <wpe/fdo.h> 29 #include <wpe/fdo-egl.h> 30 #include <wpe/webkit.h> 31 #include "gstwpesrc.h" 32 33 GST_DEBUG_CATEGORY_EXTERN(wpe_src_debug); 34 35 class WPEThreadedView { 36 public: 37 WPEThreadedView(); 38 ~WPEThreadedView(); 39 40 void initialize(GstWpeSrc*, GstGLContext*, GstGLDisplay*, int width, int height); 41 42 void resize(int width, int height); 43 void loadUri(const gchar*); 44 void setDrawBackground(gboolean); 45 46 GstEGLImage* image(); 47 48 struct wpe_view_backend* backend() const; 49 50 private: 51 void frameComplete(); 52 void releaseImage(EGLImageKHR); 53 void loadUriUnlocked(const gchar*); 54 55 static void s_loadEvent(WebKitWebView*, WebKitLoadEvent, gpointer); 56 57 static gpointer s_viewThread(gpointer); 58 struct { 59 GMutex mutex; 60 GCond cond; 61 GMutex ready_mutex; 62 GCond ready_cond; 63 GThread* thread { nullptr }; 64 } threading; 65 66 struct { 67 GMainContext* context; 68 GMainLoop* loop; 69 } glib { nullptr, nullptr }; 70 71 struct { 72 GstGLContext* context; 73 GstGLDisplay* display; 74 } gst { nullptr, nullptr }; 75 76 static struct wpe_view_backend_exportable_fdo_egl_client s_exportableClient; 77 static void s_releaseImage(GstEGLImage*, gpointer); 78 struct { 79 struct wpe_view_backend_exportable_fdo* exportable; 80 int width; 81 int height; 82 } wpe { nullptr, 0, 0 }; 83 84 struct { 85 gchar* uri; 86 WebKitWebView* view; 87 } webkit = { nullptr, nullptr }; 88 89 struct { 90 GMutex mutex; 91 GstEGLImage* pending { nullptr }; 92 GstEGLImage* committed { nullptr }; 93 } images; 94 }; 95