diff options
author | Artem Dyomin <[email protected]> | 2023-12-26 13:25:47 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2024-01-13 14:46:31 +0000 |
commit | 04c71d97d88b7241c75c7812216d194fc369f2e0 (patch) | |
tree | 6afdc8519aea99d12a4539bad0e8a14115e8dfd7 | |
parent | e18e3a1f04fefcae0aedf90b56c8af6466369a31 (diff) |
Add an opportunity to grab via QOpenGLCompositor to FBO
The feature is needed for screen capturing Qt multimedia in order
to have better performance of getting frames
(avoid recreating fbo). In QtMM, we're going to create FBO
and use it as a hw frame (or just render it to image on the first stage)
Change-Id: Id08a86b76447faa0f341c6967c2dad8f34c84959
Reviewed-by: Laszlo Agocs <[email protected]>
(cherry picked from commit b96160191fc79514173b202bf6325553a798926d)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 12fb9c4dbba1f393feb8d7f99713a76ed6eda63b)
(cherry picked from commit bdaada60629d03f1c6013257311b82abc449dd1b)
-rw-r--r-- | src/opengl/qopenglcompositor.cpp | 17 | ||||
-rw-r--r-- | src/opengl/qopenglcompositor_p.h | 3 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/opengl/qopenglcompositor.cpp b/src/opengl/qopenglcompositor.cpp index 4878d722890..74d8ae7e1ff 100644 --- a/src/opengl/qopenglcompositor.cpp +++ b/src/opengl/qopenglcompositor.cpp @@ -85,10 +85,21 @@ void QOpenGLCompositor::update() QImage QOpenGLCompositor::grab() { Q_ASSERT(m_context && m_targetWindow); + QOpenGLFramebufferObject fbo(m_nativeTargetGeometry.size()); + grabToFrameBufferObject(&fbo); + return fbo.toImage(); +} + +bool QOpenGLCompositor::grabToFrameBufferObject(QOpenGLFramebufferObject *fbo) +{ + Q_ASSERT(fbo); + if (fbo->size() != m_nativeTargetGeometry.size() + || fbo->format().textureTarget() != GL_TEXTURE_2D) + return false; + m_context->makeCurrent(m_targetWindow); - QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(m_nativeTargetGeometry.size())); - renderAll(fbo.data()); - return fbo->toImage(); + renderAll(fbo); + return true; } void QOpenGLCompositor::handleRenderAllRequest() diff --git a/src/opengl/qopenglcompositor_p.h b/src/opengl/qopenglcompositor_p.h index 72cb4fd350a..9e04cb2b259 100644 --- a/src/opengl/qopenglcompositor_p.h +++ b/src/opengl/qopenglcompositor_p.h @@ -55,10 +55,13 @@ public: void setRotation(int degrees); QOpenGLContext *context() const { return m_context; } QWindow *targetWindow() const { return m_targetWindow; } + QRect nativeTargetGeometry() const { return m_nativeTargetGeometry; } void update(); QImage grab(); + bool grabToFrameBufferObject(QOpenGLFramebufferObject *fbo); + QList<QOpenGLCompositorWindow *> windows() const { return m_windows; } void addWindow(QOpenGLCompositorWindow *window); void removeWindow(QOpenGLCompositorWindow *window); |