summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2023-12-26 13:25:47 +0100
committerArtem Dyomin <artem.dyomin@qt.io>2024-01-07 12:53:34 +0000
commitb96160191fc79514173b202bf6325553a798926d (patch)
tree25d7824f5ffcff3554faa75111c6af4e05ebaf9f
parentc4bd6ac4e5a0782d8771af1485a3b78733180785 (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) Pick-to: 6.7 6.6 6.5 Change-Id: Id08a86b76447faa0f341c6967c2dad8f34c84959 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r--src/opengl/qopenglcompositor.cpp17
-rw-r--r--src/opengl/qopenglcompositor_p.h3
2 files changed, 17 insertions, 3 deletions
diff --git a/src/opengl/qopenglcompositor.cpp b/src/opengl/qopenglcompositor.cpp
index b260445fec..6fda40c27c 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 66dd77c1c2..f2059f90fa 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);