diff options
author | Paul Olav Tvete <paul.tvete@qt.io> | 2020-06-09 11:31:58 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-06-11 22:23:46 +0200 |
commit | 66056aba7b47c147b4cf9fd70a855dd15b8a9eb6 (patch) | |
tree | 91dc8d5e96d49abdc84d913d4b83725e04e88d26 /src/quick/items/context2d | |
parent | 212c2bffbb041aee0e3c9a7f0551ef151ed2d3ad (diff) |
Remove FBO path from painternode/context2d
Task-number: QTBUG-84623
Change-Id: Icef7ab7460799b989f4e122be3f8d5cab98382e4
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/quick/items/context2d')
-rw-r--r-- | src/quick/items/context2d/qquickcanvasitem.cpp | 4 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2d.cpp | 143 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2d_p.h | 3 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtexture.cpp | 322 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtexture_p.h | 48 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtile.cpp | 56 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtile_p.h | 21 |
7 files changed, 5 insertions, 592 deletions
diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index 84f65d5241..9ee0dbba04 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -827,14 +827,14 @@ QSGTextureProvider *QQuickCanvasItem::textureProvider() const return QQuickItem::textureProvider(); Q_D(const QQuickCanvasItem); -#if QT_CONFIG(opengl) + QQuickWindow *w = window(); if (!w || !w->isSceneGraphInitialized() || QThread::currentThread() != QQuickWindowPrivate::get(w)->context->thread()) { qWarning("QQuickCanvasItem::textureProvider: can only be queried on the rendering thread of an exposed window"); return nullptr; } -#endif + if (!d->textureProvider) d->textureProvider = new QQuickCanvasTextureProvider; d->textureProvider->tex = d->nodeTexture; diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index f3d2d242d2..f7cbf11927 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -77,10 +77,7 @@ #include <private/qguiapplication_p.h> #include <qpa/qplatformintegration.h> -#if QT_CONFIG(opengl) -#include <qopenglframebufferobject.h> #include <private/qsgdefaultrendercontext_p.h> -#endif #include <cmath> #if defined(Q_OS_QNX) || defined(Q_OS_ANDROID) @@ -4209,36 +4206,6 @@ bool QQuickContext2D::isPointInPath(qreal x, qreal y) const return contains; } -class QQuickContext2DThreadCleanup : public QObject -{ -public: - QQuickContext2DThreadCleanup(QOpenGLContext *gl, QQuickContext2DTexture *t, QOffscreenSurface *s) - : context(gl), texture(t), surface(s) - { } - - ~QQuickContext2DThreadCleanup() - { -#if QT_CONFIG(opengl) - context->makeCurrent(surface); - delete texture; - context->doneCurrent(); - delete context; -#endif - surface->deleteLater(); - } - - QOpenGLContext *context; - QQuickContext2DTexture *texture; - QOffscreenSurface *surface; -}; - -class QQuickContext2DTextureCleanup : public QRunnable -{ -public: - QQuickContext2DTexture *texture; - void run() override { delete texture; } -}; - QMutex QQuickContext2D::mutex; QQuickContext2D::QQuickContext2D(QObject *parent) @@ -4246,7 +4213,6 @@ QQuickContext2D::QQuickContext2D(QObject *parent) , m_buffer(new QQuickContext2DCommandBuffer) , m_v4engine(nullptr) , m_surface(nullptr) - , m_glContext(nullptr) , m_thread(nullptr) , m_grabbed(false) { @@ -4257,36 +4223,8 @@ QQuickContext2D::~QQuickContext2D() mutex.lock(); m_texture->setItem(nullptr); delete m_buffer; + m_texture->deleteLater(); - if (m_renderTarget == QQuickCanvasItem::FramebufferObject) { -#if QT_CONFIG(opengl) - if (m_renderStrategy == QQuickCanvasItem::Immediate && m_glContext) { - Q_ASSERT(QThread::currentThread() == m_glContext->thread()); - m_glContext->makeCurrent(m_surface.data()); - delete m_texture; - m_glContext->doneCurrent(); - delete m_glContext; - } else if (m_texture->isOnCustomThread()) { - Q_ASSERT(m_glContext); - QQuickContext2DThreadCleanup *cleaner = new QQuickContext2DThreadCleanup(m_glContext, m_texture, m_surface.take()); - cleaner->moveToThread(m_texture->thread()); - cleaner->deleteLater(); - } else { - if (m_canvas->window()) { - QQuickContext2DTextureCleanup *c = new QQuickContext2DTextureCleanup; - c->texture = m_texture; - m_canvas->window()->scheduleRenderJob(c, QQuickWindow::AfterSynchronizingStage); - } else { - m_texture->deleteLater(); - } - } -#endif - } else { - // Image based does not have GL resources, but must still be deleted - // on its designated thread after it has completed whatever it might - // currently be doing. - m_texture->deleteLater(); - } mutex.unlock(); } @@ -4308,15 +4246,6 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_renderTarget = canvasItem->renderTarget(); m_renderStrategy = canvasItem->renderStrategy(); -#ifdef Q_OS_WIN - if (m_renderTarget == QQuickCanvasItem::FramebufferObject - && (m_renderStrategy != QQuickCanvasItem::Cooperative)) { - // On windows a context needs to be unbound set up sharing, so - // for simplicity we disallow FBO + !coop here. - m_renderTarget = QQuickCanvasItem::Image; - } -#endif - // Disable threaded background rendering if the platform has issues with it if (m_renderTarget == QQuickCanvasItem::FramebufferObject && m_renderStrategy == QQuickCanvasItem::Threaded @@ -4332,19 +4261,8 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_renderTarget = QQuickCanvasItem::Image; } - switch (m_renderTarget) { - case QQuickCanvasItem::Image: - m_texture = new QQuickContext2DImageTexture; - break; - case QQuickCanvasItem::FramebufferObject: -#if QT_CONFIG(opengl) - m_texture = new QQuickContext2DFBOTexture; -#else - // It shouldn't be possible to use a FramebufferObject without OpenGL - m_texture = nullptr; -#endif - break; - } + Q_ASSERT(m_renderTarget == QQuickCanvasItem::Image); + m_texture = new QQuickContext2DImageTexture; m_texture->setItem(canvasItem); m_texture->setCanvasWindow(canvasItem->canvasWindow().toRect()); @@ -4356,39 +4274,10 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_thread = QThread::currentThread(); QThread *renderThread = m_thread; -#if QT_CONFIG(opengl) - QQuickWindow *window = canvasItem->window(); - QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window); - QThread *sceneGraphThread = wd->context->thread(); - - if (m_renderStrategy == QQuickCanvasItem::Threaded) - renderThread = QQuickContext2DRenderThread::instance(qmlEngine(canvasItem)); - else if (m_renderStrategy == QQuickCanvasItem::Cooperative) - renderThread = sceneGraphThread; -#else if (m_renderStrategy == QQuickCanvasItem::Threaded) renderThread = QQuickContext2DRenderThread::instance(qmlEngine(canvasItem)); -#endif - - if (renderThread && renderThread != QThread::currentThread()) m_texture->moveToThread(renderThread); -#if QT_CONFIG(opengl) - if (m_renderTarget == QQuickCanvasItem::FramebufferObject && renderThread != sceneGraphThread) { - //auto openglRenderContext = static_cast<const QSGDefaultRenderContext *>(QQuickWindowPrivate::get(window)->context); - // ### glpurge - QOpenGLContext *cc = nullptr; // openglRenderContext->openglContext(); - m_surface.reset(new QOffscreenSurface); - m_surface->setFormat(window->format()); - m_surface->create(); - m_glContext = new QOpenGLContext; - m_glContext->setFormat(cc->format()); - m_glContext->setShareContext(cc); - if (renderThread != QThread::currentThread()) - m_glContext->moveToThread(renderThread); - m_texture->initializeOpenGL(m_glContext, m_surface.data()); - } -#endif connect(m_texture, SIGNAL(textureChanged()), SIGNAL(textureChanged())); reset(); @@ -4428,34 +4317,8 @@ QQuickContext2DTexture *QQuickContext2D::texture() const QImage QQuickContext2D::toImage(const QRectF& bounds) { if (m_texture->thread() == QThread::currentThread()) { - // if we're either not rendering to an fbo or we have a separate opengl context we can just - // flush. Otherwise we have to make sure the shared opengl context is current before we do - // so. It may or may not be current already, depending on how this method is called. - if (m_renderTarget != QQuickCanvasItem::FramebufferObject || m_glContext) { - flush(); - m_texture->grabImage(bounds); - } else { -#if QT_CONFIG(opengl) - QQuickWindow *window = m_canvas->window(); - QOpenGLContext *ctx = window ? window->openglContext() : nullptr; - if (ctx && ctx->isValid()) { - if (ctx == QOpenGLContext::currentContext()) { - flush(); - } else { - ctx->makeCurrent(window); - flush(); - ctx->doneCurrent(); - } - m_texture->grabImage(bounds); - } else { - qWarning() << "Cannot read pixels from canvas before opengl context is valid"; - return QImage(); - } -#else flush(); m_texture->grabImage(bounds); -#endif - } } else if (m_renderStrategy == QQuickCanvasItem::Cooperative) { qWarning() << "Pixel readback is not supported in Cooperative mode, please try Threaded or Immediate mode"; return QImage(); diff --git a/src/quick/items/context2d/qquickcontext2d_p.h b/src/quick/items/context2d/qquickcontext2d_p.h index b5626dec0c..92ec1e6470 100644 --- a/src/quick/items/context2d/qquickcontext2d_p.h +++ b/src/quick/items/context2d/qquickcontext2d_p.h @@ -83,7 +83,6 @@ class QQuickContext2DTexture; class QQuickPixmap; class QSGTexture; class QSurface; -class QOpenGLContext; class QQuickContext2D : public QQuickCanvasContext { @@ -248,7 +247,6 @@ public: QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text); QQmlRefPointer<QQuickCanvasPixmap> createPixmap(const QUrl& url); - QOpenGLContext *glContext() const { return m_glContext; } QSurface *surface() const { return m_surface.data(); } void setGrabbedImage(const QImage& grab); @@ -262,7 +260,6 @@ public: QV4::PersistentValue m_v4path; QV4::ExecutionEngine *m_v4engine; QScopedPointer<QOffscreenSurface> m_surface; - QOpenGLContext *m_glContext; QV4::PersistentValue m_v4value; QQuickContext2DTexture *m_texture; QQuickCanvasItem::RenderTarget m_renderTarget; diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp index 96af4008df..e111f908d0 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture.cpp +++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp @@ -43,13 +43,6 @@ #include <private/qquickitem_p.h> #include <QtQuick/private/qsgplaintexture_p.h> #include "qquickcontext2dcommandbuffer_p.h" -#if QT_CONFIG(opengl) -#include <QOpenGLPaintDevice> -#include <QOpenGLFramebufferObject> -#include <QOpenGLFramebufferObjectFormat> -#include <QOpenGLFunctions> -#include <private/qopenglextensions_p.h> -#endif #include <QtCore/QThread> #include <QtGui/QGuiApplication> @@ -57,46 +50,8 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcCanvas, "qt.quick.canvas") -#if QT_CONFIG(opengl) -#define QT_MINIMUM_FBO_SIZE 64 - -static inline int qt_next_power_of_two(int v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - ++v; - return v; -} - -struct GLAcquireContext { - GLAcquireContext(QOpenGLContext *c, QSurface *s):ctx(c) { - if (ctx) { - Q_ASSERT(s); - if (!ctx->isValid()) - ctx->create(); - - if (!ctx->isValid()) - qWarning() << "Unable to create GL context"; - else if (!ctx->makeCurrent(s)) - qWarning() << "Can't make current GL context"; - } - } - ~GLAcquireContext() { - if (ctx) - ctx->doneCurrent(); - } - QOpenGLContext *ctx; -}; -#endif QQuickContext2DTexture::QQuickContext2DTexture() : m_context(nullptr) -#if QT_CONFIG(opengl) - , m_gl(nullptr) -#endif , m_surface(nullptr) , m_item(nullptr) , m_canvasDevicePixelRatio(1) @@ -262,9 +217,6 @@ void QQuickContext2DTexture::paint(QQuickContext2DCommandBuffer *ccb) return; } QQuickContext2D::mutex.unlock(); -#if QT_CONFIG(opengl) - GLAcquireContext currentContext(m_gl, m_surface); -#endif if (!m_tiledCanvas) { paintWithoutTiles(ccb); delete ccb; @@ -391,280 +343,6 @@ bool QQuickContext2DTexture::event(QEvent *e) } return QObject::event(e); } -#if QT_CONFIG(opengl) -static inline QSize npotAdjustedSize(const QSize &size) -{ - static bool checked = false; - static bool npotSupported = false; - - if (!checked) { - npotSupported = QOpenGLContext::currentContext()->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); - checked = true; - } - - if (npotSupported) { - return QSize(qMax(QT_MINIMUM_FBO_SIZE, size.width()), - qMax(QT_MINIMUM_FBO_SIZE, size.height())); - } - - return QSize(qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(size.width())), - qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(size.height()))); -} - -QQuickContext2DFBOTexture::QQuickContext2DFBOTexture() - : QQuickContext2DTexture() - , m_fbo(nullptr) - , m_multisampledFbo(nullptr) - , m_paint_device(nullptr) -{ - m_displayTextures[0] = 0; - m_displayTextures[1] = 0; - m_displayTexture = -1; -} - -QQuickContext2DFBOTexture::~QQuickContext2DFBOTexture() -{ - if (m_multisampledFbo) - m_multisampledFbo->release(); - else if (m_fbo) - m_fbo->release(); - - delete m_fbo; - delete m_multisampledFbo; - delete m_paint_device; - - if (QOpenGLContext::currentContext()) - QOpenGLContext::currentContext()->functions()->glDeleteTextures(2, m_displayTextures); -} - -QVector2D QQuickContext2DFBOTexture::scaleFactor() const -{ - if (!m_fbo) - return QVector2D(1, 1); - return QVector2D(m_fbo->width() / m_fboSize.width(), - m_fbo->height() / m_fboSize.height()); -} - -QSGTexture *QQuickContext2DFBOTexture::textureForNextFrame(QSGTexture *lastTexture, QQuickWindow *) -{ - QSGPlainTexture *texture = static_cast<QSGPlainTexture *>(lastTexture); - - if (m_onCustomThread) - m_mutex.lock(); - - if (m_fbo) { - if (!texture) { - texture = new QSGPlainTexture(); - texture->setHasAlphaChannel(true); - texture->setOwnsTexture(false); - m_dirtyTexture = true; - } - - if (m_dirtyTexture) { - if (!m_gl) { - // on a rendering thread, use the fbo directly... - // ### glpurge - //texture->setTextureId(m_fbo->texture()); - } else { - // on GUI or custom thread, use display textures... - m_displayTexture = m_displayTexture == 0 ? 1 : 0; - // ### glpurge - //texture->setTextureId(m_displayTextures[m_displayTexture]); - } - texture->setTextureSize(m_fbo->size()); - m_dirtyTexture = false; - } - - } - - if (m_onCustomThread) { - m_condition.wakeOne(); - m_mutex.unlock(); - } - - return texture; -} - -QSize QQuickContext2DFBOTexture::adjustedTileSize(const QSize &ts) -{ - return npotAdjustedSize(ts); -} - -QRectF QQuickContext2DFBOTexture::normalizedTextureSubRect() const -{ - return QRectF(0 - , 0 - , qreal(m_canvasWindow.width()) / m_fboSize.width() - , qreal(m_canvasWindow.height()) / m_fboSize.height()); -} - -QQuickContext2DTile* QQuickContext2DFBOTexture::createTile() const -{ - return new QQuickContext2DFBOTile(); -} - -bool QQuickContext2DFBOTexture::doMultisampling() const -{ - static bool extensionsChecked = false; - static bool multisamplingSupported = false; - - if (!extensionsChecked) { - QOpenGLExtensions *e = static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions()); - multisamplingSupported = e->hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample) - && e->hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit); - extensionsChecked = true; - } - - return multisamplingSupported && m_antialiasing; -} - -void QQuickContext2DFBOTexture::grabImage(const QRectF& rf) -{ - Q_ASSERT(rf.isValid()); - QQuickContext2D::mutex.lock(); - if (m_context) { - if (!m_fbo) { - m_context->setGrabbedImage(QImage()); - } else { - QImage grabbed; - GLAcquireContext ctx(m_gl, m_surface); - grabbed = m_fbo->toImage().scaled(m_fboSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).mirrored().copy(rf.toRect()); - m_context->setGrabbedImage(grabbed); - } - } - QQuickContext2D::mutex.unlock(); -} - -void QQuickContext2DFBOTexture::compositeTile(QQuickContext2DTile* tile) -{ - QQuickContext2DFBOTile* t = static_cast<QQuickContext2DFBOTile*>(tile); - QRect target = t->rect().intersected(m_canvasWindow); - if (target.isValid()) { - QRect source = target; - - source.moveTo(source.topLeft() - t->rect().topLeft()); - target.moveTo(target.topLeft() - m_canvasWindow.topLeft()); - - QOpenGLFramebufferObject::blitFramebuffer(m_fbo, target, t->fbo(), source); - } -} - -QQuickCanvasItem::RenderTarget QQuickContext2DFBOTexture::renderTarget() const -{ - return QQuickCanvasItem::FramebufferObject; -} - -QPaintDevice* QQuickContext2DFBOTexture::beginPainting() -{ - QQuickContext2DTexture::beginPainting(); - - if (m_canvasWindow.size().isEmpty()) { - delete m_fbo; - delete m_multisampledFbo; - delete m_paint_device; - m_fbo = nullptr; - m_multisampledFbo = nullptr; - m_paint_device = nullptr; - return nullptr; - } else if (!m_fbo || m_canvasWindowChanged) { - delete m_fbo; - delete m_multisampledFbo; - delete m_paint_device; - m_paint_device = nullptr; - - m_fboSize = npotAdjustedSize(m_canvasWindow.size() * m_canvasDevicePixelRatio); - m_canvasWindowChanged = false; - - if (doMultisampling()) { - { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setSamples(8); - m_multisampledFbo = new QOpenGLFramebufferObject(m_fboSize, format); - } - { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::NoAttachment); - m_fbo = new QOpenGLFramebufferObject(m_fboSize, format); - } - } else { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - QSize s = m_fboSize; - if (m_antialiasing) { // do supersampling since multisampling is not available - GLint max; - QOpenGLContext::currentContext()->functions()->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); - if (s.width() * 2 <= max && s.height() * 2 <= max) - s = s * 2; - } - m_fbo = new QOpenGLFramebufferObject(s, format); - } - } - - if (doMultisampling()) - m_multisampledFbo->bind(); - else - m_fbo->bind(); - - if (!m_paint_device) { - QOpenGLPaintDevice *gl_device = new QOpenGLPaintDevice(m_fbo->size()); - gl_device->setPaintFlipped(true); - gl_device->setSize(m_fbo->size()); - gl_device->setDevicePixelRatio(m_canvasDevicePixelRatio); - qCDebug(lcCanvas, "%s size %.1lf x %.1lf painting with size %d x %d DPR %.1lf", - (m_item->objectName().isEmpty() ? "Canvas" : qPrintable(m_item->objectName())), - m_item->width(), m_item->height(), m_fbo->size().width(), m_fbo->size().height(), m_canvasDevicePixelRatio); - m_paint_device = gl_device; - } - - return m_paint_device; -} - -void QQuickContext2DFBOTexture::endPainting() -{ - QQuickContext2DTexture::endPainting(); - - // There may not be an FBO due to zero width or height. - if (!m_fbo) - return; - - if (m_multisampledFbo) - QOpenGLFramebufferObject::blitFramebuffer(m_fbo, m_multisampledFbo); - - if (m_gl) { - /* When rendering happens on the render thread, the fbo's texture is - * used directly for display. If we are on the GUI thread or a - * dedicated Canvas render thread, we need to decouple the FBO from - * the texture we are displaying in the SG rendering thread to avoid - * stalls and read/write issues in the GL pipeline as the FBO's texture - * could then potentially be used in different threads. - * - * We could have gotten away with only one display texture, but this - * would have implied that beginPainting would have to wait for SG - * to release that texture. - */ - - if (m_onCustomThread) - m_mutex.lock(); - - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - if (m_displayTextures[0] == 0) { - m_displayTexture = 1; - funcs->glGenTextures(2, m_displayTextures); - } - - m_fbo->bind(); - GLuint target = m_displayTexture == 0 ? 1 : 0; - funcs->glBindTexture(GL_TEXTURE_2D, m_displayTextures[target]); - funcs->glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, m_fbo->width(), m_fbo->height(), 0); - - if (m_onCustomThread) - m_mutex.unlock(); - } - - m_fbo->bindDefault(); -} -#endif QQuickContext2DImageTexture::QQuickContext2DImageTexture() : QQuickContext2DTexture() diff --git a/src/quick/items/context2d/qquickcontext2dtexture_p.h b/src/quick/items/context2d/qquickcontext2dtexture_p.h index 9c4870f328..4a525f1a9e 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture_p.h +++ b/src/quick/items/context2d/qquickcontext2dtexture_p.h @@ -58,10 +58,6 @@ QT_REQUIRE_CONFIG(quick_canvas); #include <QtQuick/qsgtexture.h> #include "qquickcanvasitem_p.h" #include "qquickcontext2d_p.h" -#if QT_CONFIG(opengl) -# include <QOpenGLContext> -# include <QOpenGLFramebufferObject> -#endif #include <QtCore/QMutex> #include <QtCore/QWaitCondition> #include <QtCore/QThread> @@ -125,12 +121,6 @@ public: // Called during sync() on the scene graph thread while GUI is blocked. virtual QSGTexture *textureForNextFrame(QSGTexture *lastFrame, QQuickWindow *window) = 0; bool event(QEvent *e) override; -#if QT_CONFIG(opengl) - void initializeOpenGL(QOpenGLContext *gl, QOffscreenSurface *s) { - m_gl = gl; - m_surface = s; - } -#endif Q_SIGNALS: void textureChanged(); @@ -157,9 +147,6 @@ protected: QList<QQuickContext2DTile*> m_tiles; QQuickContext2D *m_context; -#if QT_CONFIG(opengl) - QOpenGLContext *m_gl; -#endif QSurface *m_surface; QQuickContext2D::State m_state; @@ -181,42 +168,7 @@ protected: uint m_painting : 1; uint m_onCustomThread : 1; // Not GUI and not SGRender }; -#if QT_CONFIG(opengl) -class QQuickContext2DFBOTexture : public QQuickContext2DTexture -{ - Q_OBJECT - -public: - QQuickContext2DFBOTexture(); - ~QQuickContext2DFBOTexture(); - QQuickContext2DTile* createTile() const override; - QPaintDevice* beginPainting() override; - void endPainting() override; - QRectF normalizedTextureSubRect() const; - QQuickCanvasItem::RenderTarget renderTarget() const override; - void compositeTile(QQuickContext2DTile* tile) override; - QSize adjustedTileSize(const QSize &ts) override; - - QSGTexture *textureForNextFrame(QSGTexture *, QQuickWindow *window) override; -protected: - QVector2D scaleFactor() const override; - -public Q_SLOTS: - void grabImage(const QRectF& region = QRectF()) override; - -private: - bool doMultisampling() const; - QOpenGLFramebufferObject *m_fbo; - QOpenGLFramebufferObject *m_multisampledFbo; - QSize m_fboSize; - QPaintDevice *m_paint_device; - - - GLuint m_displayTextures[2]; - int m_displayTexture; -}; -#endif class QSGPlainTexture; class QQuickContext2DImageTexture : public QQuickContext2DTexture { diff --git a/src/quick/items/context2d/qquickcontext2dtile.cpp b/src/quick/items/context2d/qquickcontext2dtile.cpp index 0ee3de6bcc..61ed1e7d26 100644 --- a/src/quick/items/context2d/qquickcontext2dtile.cpp +++ b/src/quick/items/context2d/qquickcontext2dtile.cpp @@ -38,11 +38,6 @@ ****************************************************************************/ #include "qquickcontext2dtile_p.h" -#if QT_CONFIG(opengl) -# include <QOpenGLFramebufferObject> -# include <QOpenGLFramebufferObjectFormat> -# include <QOpenGLPaintDevice> -#endif QT_BEGIN_NAMESPACE @@ -97,57 +92,6 @@ QPainter* QQuickContext2DTile::createPainter(bool smooth, bool antialiasing) return nullptr; } -#if QT_CONFIG(opengl) -QQuickContext2DFBOTile::QQuickContext2DFBOTile() - : QQuickContext2DTile() - , m_fbo(nullptr) -{ -} - - -QQuickContext2DFBOTile::~QQuickContext2DFBOTile() -{ - if (m_fbo) - m_fbo->release(); - delete m_fbo; -} - -void QQuickContext2DFBOTile::aboutToDraw() -{ - m_fbo->bind(); - if (!m_device) { - QOpenGLPaintDevice *gl_device = new QOpenGLPaintDevice(rect().size()); - m_device = gl_device; - QPainter p(m_device); - p.fillRect(QRectF(0, 0, m_fbo->width(), m_fbo->height()), QColor(qRgba(0, 0, 0, 0))); - p.end(); - } -} - -void QQuickContext2DFBOTile::drawFinished() -{ -} - -void QQuickContext2DFBOTile::setRect(const QRect& r) -{ - if (m_rect == r) - return; - m_rect = r; - m_dirty = true; - if (!m_fbo || m_fbo->size() != r.size()) { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setInternalTextureFormat(GL_RGBA); - format.setMipmap(false); - - if (m_painter.isActive()) - m_painter.end(); - - delete m_fbo; - m_fbo = new QOpenGLFramebufferObject(r.size(), format); - } -} -#endif QQuickContext2DImageTile::QQuickContext2DImageTile() : QQuickContext2DTile() diff --git a/src/quick/items/context2d/qquickcontext2dtile_p.h b/src/quick/items/context2d/qquickcontext2dtile_p.h index c3d4dfef64..f9400ece4e 100644 --- a/src/quick/items/context2d/qquickcontext2dtile_p.h +++ b/src/quick/items/context2d/qquickcontext2dtile_p.h @@ -56,9 +56,6 @@ QT_REQUIRE_CONFIG(quick_canvas); #include "qquickcontext2d_p.h" -#if QT_CONFIG(opengl) -# include <QOpenGLFramebufferObject> -#endif QT_BEGIN_NAMESPACE class QQuickContext2DTexture; @@ -87,24 +84,6 @@ protected: QPainter m_painter; }; -#if QT_CONFIG(opengl) -class QQuickContext2DFBOTile : public QQuickContext2DTile -{ -public: - QQuickContext2DFBOTile(); - ~QQuickContext2DFBOTile(); - void setRect(const QRect& r) override; - QOpenGLFramebufferObject* fbo() const {return m_fbo;} - void drawFinished() override; - -protected: - void aboutToDraw() override; -private: - - - QOpenGLFramebufferObject *m_fbo; -}; -#endif class QQuickContext2DImageTile : public QQuickContext2DTile { public: |