On this page

C

QAndroidSurfaceRenderEngine Class

Renders a Qt Quick scene into one or more Android native surfaces. More...

Header: #include <QAndroidSurfaceRenderEngine>
CMake: find_package(Qt6 REQUIRED COMPONENTS androidautomotiveservice)
target_link_libraries(mytarget PRIVATE Qt6::androidautomotiveservice)
Since: QtAndroidAutomotive 6.10
Inherits: QQmlApplicationEngine

Public Functions

QAndroidSurfaceRenderEngine(QObject *parent = nullptr)
virtual ~QAndroidSurfaceRenderEngine()
void setNativeWindowForItem(ANativeWindow *nativeWindow, const QString &itemId)
void setSurfaceForItem(const QJniObject &surface, const QString &itemId)

Detailed Description

QAndroidSurfaceRenderEngine is a convenience engine that drives a Qt Quick scene and presents selected items into Android native windows (ANativeWindow) provided by the Android system.

The engine owns an internal, headless QQuickWindow that renders the scene into an OpenGL framebuffer object. The resulting texture is then forwarded to internal windows instances, each of which presents the content into a separate Android surface that is associated with a Quick item.

QAndroidSurfaceRenderEngine is typically used together with QAndroidRaaSApplication, which forwards surface create and destroy events from the Android side and requests the engine to bind those surfaces to Quick items.

Example usage:

int main(int argc, char *argv[])
{
    QAndroidRaaSApplication app(argc, argv);

    QAndroidSurfaceRenderEngine renderEngine;
    renderEngine.load(QLatin1String(":/qt/qml/path/to/qmlmodule/Main.qml"));

    return app.exec();
}

See also QAndroidRaaSApplication and QQuickRenderControl.

Member Function Documentation

[explicit] QAndroidSurfaceRenderEngine::QAndroidSurfaceRenderEngine(QObject *parent = nullptr)

Creates a new surface render engine with the given parent.

The engine behaves like a QQmlApplicationEngine that loads the root QML component and then renders the scene into an offscreen QQuickWindow.

QAndroidSurfaceRenderEngine expects that a QAndroidRaaSApplication instance has been created earlier. The QAndroidRaaSApplication instance is used to receive surface requests from the Android side.

[virtual noexcept] QAndroidSurfaceRenderEngine::~QAndroidSurfaceRenderEngine()

Destroys the surface render engine.

The internal render thread is stopped, any live offscreen window instances are scheduled for deletion, and the OpenGL context and offscreen surface used for rendering are released.

void QAndroidSurfaceRenderEngine::setNativeWindowForItem(ANativeWindow *nativeWindow, const QString &itemId)

Associates the given nativeWindow with the Qt Quick item identified by itemId.

When a valid nativeWindow is provided, the engine creates or updates an internal window that presents the rendered Qt Quick item into the supplied Android window on each frame.

Passing nullptr as nativeWindow removes any existing mapping for itemId.

Note: When an Android surface is about to be destroyed, this function should be called with a nullptr nativeWindow and the same itemId that was associated previously.

Note: This function must be called from the Qt main thread. If the nativeWindow is associated with an Android surface that is being destroyed on another thread, that thread should be blocked until this function returns.

See also setSurfaceForItem().

void QAndroidSurfaceRenderEngine::setSurfaceForItem(const QJniObject &surface, const QString &itemId)

Associates the Android surface with the Qt Quick item identified by itemId.

The surface argument is expected to wrap an Android Surface object. The surface is converted to an ANativeWindow and passed to setNativeWindowForItem().

Passing an invalid surface is equivalent to passing nullptr to setNativeWindowForItem() and removes any existing association for itemId.

This function is normally invoked by QAndroidRaaSApplication when a new surface becomes available on the Android side.

Note: When an Android surface is about to be destroyed, this function should be called with a null surface and the same itemId that was associated previously.

Note: This function must be called from the Qt main thread. If the Android surface is being destroyed on another thread, that thread should be blocked until this function returns.

See also setNativeWindowForItem().

Available under certain Qt licenses.
Find out more.