2018-12-05 13:10:11 +00:00
|
|
|
/* Copyright (C) <2018> Philippe Normand <philn@igalia.com>
|
|
|
|
* Copyright (C) <2018> Žan Doberšek <zdobersek@igalia.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gst/gl/gstglfuncs.h>
|
2020-08-14 16:02:44 +00:00
|
|
|
#include <gst/gl/egl/gstgldisplay_egl.h>
|
2018-12-05 13:10:11 +00:00
|
|
|
#include <wpe/fdo.h>
|
|
|
|
#include <wpe/fdo-egl.h>
|
|
|
|
#include <wpe/webkit.h>
|
2021-03-10 20:27:52 +00:00
|
|
|
#include "gstwpevideosrc.h"
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2019-06-05 11:47:16 +00:00
|
|
|
typedef struct _GstGLContext GstGLContext;
|
|
|
|
typedef struct _GstGLDisplay GstGLDisplay;
|
|
|
|
typedef struct _GstEGLImage GstEGLImage;
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
class WPEView {
|
2018-12-05 13:10:11 +00:00
|
|
|
public:
|
2021-03-10 20:27:52 +00:00
|
|
|
WPEView(WebKitWebContext*, GstWpeVideoSrc*, GstGLContext*, GstGLDisplay*, int width, int height);
|
2020-08-05 17:41:45 +00:00
|
|
|
~WPEView();
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
bool operator!() const { return m_isValid; }
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2021-03-10 20:27:52 +00:00
|
|
|
/* Used by wpevideosrc */
|
2018-12-05 13:10:11 +00:00
|
|
|
void resize(int width, int height);
|
|
|
|
void loadUri(const gchar*);
|
2019-09-24 23:57:54 +00:00
|
|
|
void loadData(GBytes*);
|
2023-01-19 14:24:05 +00:00
|
|
|
void runJavascript(const gchar*);
|
2018-12-05 13:10:11 +00:00
|
|
|
void setDrawBackground(gboolean);
|
2019-12-08 11:49:20 +00:00
|
|
|
|
2018-12-05 13:10:11 +00:00
|
|
|
GstEGLImage* image();
|
2020-02-08 12:05:03 +00:00
|
|
|
GstBuffer* buffer();
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
void dispatchKeyboardEvent(struct wpe_input_keyboard_event&);
|
|
|
|
void dispatchPointerEvent(struct wpe_input_pointer_event&);
|
|
|
|
void dispatchAxisEvent(struct wpe_input_axis_event&);
|
2022-02-10 09:21:01 +00:00
|
|
|
void dispatchTouchEvent(struct wpe_input_touch_event&);
|
2020-08-05 17:41:45 +00:00
|
|
|
|
|
|
|
/* Used by WPEContextThread */
|
|
|
|
bool hasUri() const { return webkit.uri; }
|
|
|
|
void disconnectLoadFailedSignal();
|
2020-09-10 13:39:58 +00:00
|
|
|
void waitLoadCompletion();
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2019-06-12 10:12:37 +00:00
|
|
|
protected:
|
|
|
|
void handleExportedImage(gpointer);
|
2020-02-08 12:05:03 +00:00
|
|
|
void handleExportedBuffer(struct wpe_fdo_shm_exported_buffer*);
|
2019-06-12 10:12:37 +00:00
|
|
|
|
2018-12-05 13:10:11 +00:00
|
|
|
private:
|
2020-08-05 17:41:45 +00:00
|
|
|
struct wpe_view_backend* backend() const;
|
2018-12-05 13:10:11 +00:00
|
|
|
void frameComplete();
|
|
|
|
void loadUriUnlocked(const gchar*);
|
2020-09-10 13:39:58 +00:00
|
|
|
void notifyLoadFinished();
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2019-06-12 10:12:37 +00:00
|
|
|
void releaseImage(gpointer);
|
2020-02-08 12:05:03 +00:00
|
|
|
void releaseSHMBuffer(gpointer);
|
|
|
|
static void s_releaseSHMBuffer(gpointer);
|
2019-06-12 10:12:37 +00:00
|
|
|
|
2018-12-05 13:10:11 +00:00
|
|
|
struct {
|
|
|
|
GstGLContext* context;
|
|
|
|
GstGLDisplay* display;
|
2020-08-14 16:02:44 +00:00
|
|
|
GstGLDisplayEGL* display_egl;
|
|
|
|
} gst { nullptr, nullptr, nullptr };
|
2018-12-05 13:10:11 +00:00
|
|
|
|
2020-04-03 14:45:02 +00:00
|
|
|
static struct wpe_view_backend_exportable_fdo_egl_client s_exportableEGLClient;
|
|
|
|
static struct wpe_view_backend_exportable_fdo_client s_exportableClient;
|
|
|
|
|
2018-12-05 13:10:11 +00:00
|
|
|
static void s_releaseImage(GstEGLImage*, gpointer);
|
|
|
|
struct {
|
|
|
|
struct wpe_view_backend_exportable_fdo* exportable;
|
|
|
|
int width;
|
|
|
|
int height;
|
2019-12-08 11:49:20 +00:00
|
|
|
} wpe { nullptr, 0, 0, };
|
2018-12-05 13:10:11 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
gchar* uri;
|
|
|
|
WebKitWebView* view;
|
|
|
|
} webkit = { nullptr, nullptr };
|
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
bool m_isValid { false };
|
|
|
|
|
2020-09-10 13:39:58 +00:00
|
|
|
struct {
|
|
|
|
GMutex ready_mutex;
|
|
|
|
GCond ready_cond;
|
|
|
|
gboolean ready;
|
|
|
|
} threading;
|
|
|
|
|
2020-02-08 12:05:03 +00:00
|
|
|
// This mutex guards access to either egl or shm resources declared below,
|
|
|
|
// depending on the runtime behavior.
|
|
|
|
GMutex images_mutex;
|
|
|
|
|
2018-12-05 13:10:11 +00:00
|
|
|
struct {
|
2020-02-08 12:05:03 +00:00
|
|
|
GstEGLImage* pending;
|
|
|
|
GstEGLImage* committed;
|
|
|
|
} egl { nullptr, nullptr };
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GstBuffer* pending;
|
|
|
|
GstBuffer* committed;
|
|
|
|
} shm { nullptr, nullptr };
|
2020-08-05 17:41:45 +00:00
|
|
|
|
2021-04-20 00:46:46 +00:00
|
|
|
struct {
|
|
|
|
gulong init_ext_sigid;
|
|
|
|
gulong extension_msg_sigid;
|
|
|
|
} audio {0, 0};
|
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WPEContextThread {
|
|
|
|
public:
|
|
|
|
static WPEContextThread& singleton();
|
|
|
|
|
|
|
|
WPEContextThread();
|
|
|
|
~WPEContextThread();
|
|
|
|
|
2021-03-10 20:27:52 +00:00
|
|
|
WPEView* createWPEView(GstWpeVideoSrc*, GstGLContext*, GstGLDisplay*, int width, int height);
|
2020-08-05 17:41:45 +00:00
|
|
|
|
|
|
|
template<typename Function>
|
|
|
|
void dispatch(Function);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static gpointer s_viewThread(gpointer);
|
|
|
|
struct {
|
|
|
|
GMutex mutex;
|
|
|
|
GCond cond;
|
2021-09-18 11:01:39 +00:00
|
|
|
gboolean ready;
|
2020-08-05 17:41:45 +00:00
|
|
|
GThread* thread { nullptr };
|
|
|
|
} threading;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GMainContext* context;
|
|
|
|
GMainLoop* loop;
|
|
|
|
WebKitWebContext* web_context;
|
|
|
|
} glib { nullptr, nullptr, nullptr };
|
2018-12-05 13:10:11 +00:00
|
|
|
};
|