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>
bb10
Artem Dyomin 2023-12-26 13:25:47 +01:00
parent c4bd6ac4e5
commit b96160191f
2 changed files with 17 additions and 3 deletions

View File

@ -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()

View File

@ -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);