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>
|
|
|
|
#include <wpe/fdo.h>
|
|
|
|
#include <wpe/fdo-egl.h>
|
|
|
|
#include <wpe/webkit.h>
|
|
|
|
#include "gstwpesrc.h"
|
|
|
|
|
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-04-03 14:45:02 +00:00
|
|
|
#if defined(WPE_FDO_CHECK_VERSION) && WPE_FDO_CHECK_VERSION(1, 7, 0)
|
2020-02-08 12:05:03 +00:00
|
|
|
#define ENABLE_SHM_BUFFER_SUPPORT 1
|
|
|
|
#else
|
|
|
|
#define ENABLE_SHM_BUFFER_SUPPORT 0
|
|
|
|
#endif
|
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
class WPEView {
|
2018-12-05 13:10:11 +00:00
|
|
|
public:
|
2020-08-05 17:41:45 +00:00
|
|
|
WPEView(WebKitWebContext*, GstWpeSrc*, GstGLContext*, GstGLDisplay*, int width, int height);
|
|
|
|
~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
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
/* Used by wpesrc */
|
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*);
|
2018-12-05 13:10:11 +00:00
|
|
|
void setDrawBackground(gboolean);
|
|
|
|
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&);
|
|
|
|
|
|
|
|
/* Used by WPEContextThread */
|
|
|
|
bool hasUri() const { return webkit.uri; }
|
|
|
|
void disconnectLoadFailedSignal();
|
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
|
|
|
#if ENABLE_SHM_BUFFER_SUPPORT
|
|
|
|
void handleExportedBuffer(struct wpe_fdo_shm_exported_buffer*);
|
|
|
|
#endif
|
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*);
|
|
|
|
|
2019-06-12 10:12:37 +00:00
|
|
|
void releaseImage(gpointer);
|
2020-02-08 12:05:03 +00:00
|
|
|
#if ENABLE_SHM_BUFFER_SUPPORT
|
|
|
|
void releaseSHMBuffer(gpointer);
|
|
|
|
static void s_releaseSHMBuffer(gpointer);
|
|
|
|
#endif
|
2019-06-12 10:12:37 +00:00
|
|
|
|
2018-12-05 13:10:11 +00:00
|
|
|
struct {
|
|
|
|
GstGLContext* context;
|
|
|
|
GstGLDisplay* display;
|
|
|
|
} gst { nullptr, nullptr };
|
|
|
|
|
2020-04-03 14:45:02 +00:00
|
|
|
static struct wpe_view_backend_exportable_fdo_egl_client s_exportableEGLClient;
|
|
|
|
#if ENABLE_SHM_BUFFER_SUPPORT
|
|
|
|
static struct wpe_view_backend_exportable_fdo_client s_exportableClient;
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
} wpe { nullptr, 0, 0 };
|
|
|
|
|
|
|
|
struct {
|
|
|
|
gchar* uri;
|
|
|
|
WebKitWebView* view;
|
|
|
|
} webkit = { nullptr, nullptr };
|
|
|
|
|
2020-08-05 17:41:45 +00:00
|
|
|
bool m_isValid { false };
|
|
|
|
|
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
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class WPEContextThread {
|
|
|
|
public:
|
|
|
|
static WPEContextThread& singleton();
|
|
|
|
|
|
|
|
WPEContextThread();
|
|
|
|
~WPEContextThread();
|
|
|
|
|
|
|
|
WPEView* createWPEView(GstWpeSrc*, GstGLContext*, GstGLDisplay*, int width, int height);
|
|
|
|
|
|
|
|
template<typename Function>
|
|
|
|
void dispatch(Function);
|
|
|
|
|
|
|
|
void notifyLoadFinished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static gpointer s_viewThread(gpointer);
|
|
|
|
struct {
|
|
|
|
GMutex mutex;
|
|
|
|
GCond cond;
|
|
|
|
GMutex ready_mutex;
|
|
|
|
GCond ready_cond;
|
|
|
|
gboolean ready;
|
|
|
|
GThread* thread { nullptr };
|
|
|
|
} threading;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GMainContext* context;
|
|
|
|
GMainLoop* loop;
|
|
|
|
WebKitWebContext* web_context;
|
|
|
|
} glib { nullptr, nullptr, nullptr };
|
2018-12-05 13:10:11 +00:00
|
|
|
};
|