From 9d8db91ada0ab340ae781862f567c9b104e83c63 Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Tue, 6 Dec 2016 22:36:30 +0100 Subject: Android: Enable Adoption of ANativeWindow handle as a QOffscreenSurface This is done by adding an API to QOffscreenSurface to enable setting a native handle which can represent a native offscreen surface. When using the TexureView it is necessary to render to SurfaceTexture objects which are exposed as offscreen window surfaces. After wraping a SurfaceTexture in a android.view.Surface object and passing it to C++ via the JNI, it is possible to get the needed ANativeWindow* handle required to pass to eglCreateWindowSurface. So by setting this native handle Qt can then render to this "native" offscreen surface. Change-Id: If7fc5ac7ac588fe6c3a6fb883ea7e439d095470f Reviewed-by: Laszlo Agocs Reviewed-by: J-P Nurmi Reviewed-by: BogDan Vatra --- src/gui/kernel/qoffscreensurface.cpp | 37 ++++++++++++++++++++++++++++++++++++ src/gui/kernel/qoffscreensurface.h | 3 +++ 2 files changed, 40 insertions(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qoffscreensurface.cpp b/src/gui/kernel/qoffscreensurface.cpp index a9535a6ad7..e8a86590b5 100644 --- a/src/gui/kernel/qoffscreensurface.cpp +++ b/src/gui/kernel/qoffscreensurface.cpp @@ -102,6 +102,7 @@ public: , requestedFormat(QSurfaceFormat::defaultFormat()) , screen(0) , size(1, 1) + , nativeHandle(nullptr) { } @@ -115,6 +116,7 @@ public: QSurfaceFormat requestedFormat; QScreen *screen; QSize size; + void *nativeHandle; }; @@ -217,6 +219,8 @@ void QOffscreenSurface::destroy() delete d->offscreenWindow; d->offscreenWindow = 0; } + + d->nativeHandle = nullptr; } /*! @@ -330,6 +334,26 @@ void QOffscreenSurface::setScreen(QScreen *newScreen) } } +/*! + Sets the native handle to which the offscreen surface is connected. + + The native handle will be resolved in the create() function. Calling + this function after create() will not re-create a native surface. + + \note The interpretation of the native handle is platform specific. Only + some platforms will support adopting native handles of offscreen surfaces + and platforms that do not implement this support will ignore the handle. + + \since 5.9 + \sa nativeHandle() +*/ + +void QOffscreenSurface::setNativeHandle(void *handle) +{ + Q_D(QOffscreenSurface); + d->nativeHandle = handle; +} + /*! Called when the offscreen surface's screen is destroyed. @@ -361,6 +385,19 @@ QPlatformOffscreenSurface *QOffscreenSurface::handle() const return d->platformOffscreenSurface; } +/*! + Returns an optional native handle to which the offscreen surface is connected. + + \since 5.9 + \sa setNativeHandle() +*/ + +void *QOffscreenSurface::nativeHandle() const +{ + Q_D(const QOffscreenSurface); + return d->nativeHandle; +} + /*! Returns the platform surface corresponding to the offscreen surface. diff --git a/src/gui/kernel/qoffscreensurface.h b/src/gui/kernel/qoffscreensurface.h index bacc9c851a..35c498c89a 100644 --- a/src/gui/kernel/qoffscreensurface.h +++ b/src/gui/kernel/qoffscreensurface.h @@ -79,6 +79,9 @@ public: QPlatformOffscreenSurface *handle() const; + void *nativeHandle() const; + void setNativeHandle(void *handle); + Q_SIGNALS: void screenChanged(QScreen *screen); -- cgit v1.2.3