diff options
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qopenglwidget.cpp | 84 | ||||
-rw-r--r-- | src/widgets/kernel/qopenglwidget.h | 3 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 1 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 8 | ||||
-rw-r--r-- | src/widgets/kernel/qwidgetbackingstore.cpp | 4 | ||||
-rw-r--r-- | src/widgets/kernel/qwindowcontainer.cpp | 13 |
6 files changed, 105 insertions, 8 deletions
diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 147e0774e7..4d45782170 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -566,7 +566,8 @@ public: paintDevice(0), updateBehavior(QOpenGLWidget::NoPartialUpdate), requestedSamples(0), - inPaintGL(false) + inPaintGL(false), + textureFormat(0) { requestedFormat = QSurfaceFormat::defaultFormat(); } @@ -580,6 +581,7 @@ public: void recreateFbo(); GLuint textureId() const Q_DECL_OVERRIDE; + QPlatformTextureList::Flags textureListFlags() Q_DECL_OVERRIDE; void initialize(); void invokeUserPaint(); @@ -610,6 +612,7 @@ public: QOpenGLWidget::UpdateBehavior updateBehavior; int requestedSamples; bool inPaintGL; + GLenum textureFormat; }; void QOpenGLWidgetPaintDevicePrivate::beginPaint() @@ -654,6 +657,35 @@ GLuint QOpenGLWidgetPrivate::textureId() const return resolvedFbo ? resolvedFbo->texture() : (fbo ? fbo->texture() : 0); } +#ifndef GL_SRGB +#define GL_SRGB 0x8C40 +#endif +#ifndef GL_SRGB8 +#define GL_SRGB8 0x8C41 +#endif +#ifndef GL_SRGB_ALPHA +#define GL_SRGB_ALPHA 0x8C42 +#endif +#ifndef GL_SRGB8_ALPHA8 +#define GL_SRGB8_ALPHA8 0x8C43 +#endif + +QPlatformTextureList::Flags QOpenGLWidgetPrivate::textureListFlags() +{ + QPlatformTextureList::Flags flags = QWidgetPrivate::textureListFlags(); + switch (textureFormat) { + case GL_SRGB: + case GL_SRGB8: + case GL_SRGB_ALPHA: + case GL_SRGB8_ALPHA8: + flags |= QPlatformTextureList::TextureIsSrgb; + break; + default: + break; + } + return flags; +} + void QOpenGLWidgetPrivate::reset() { Q_Q(QOpenGLWidget); @@ -703,12 +735,16 @@ void QOpenGLWidgetPrivate::recreateFbo() QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setSamples(samples); + if (textureFormat) + format.setInternalTextureFormat(textureFormat); const QSize deviceSize = q->size() * q->devicePixelRatioF(); fbo = new QOpenGLFramebufferObject(deviceSize, format); if (samples > 0) resolvedFbo = new QOpenGLFramebufferObject(deviceSize); + textureFormat = fbo->format().internalTextureFormat(); + fbo->bind(); context->functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -767,7 +803,9 @@ void QOpenGLWidgetPrivate::initialize() return; } - // Propagate settings that make sense only for the tlw. + // Propagate settings that make sense only for the tlw. Note that this only + // makes sense for properties that get picked up even after the native + // window is created. QSurfaceFormat tlwFormat = tlw->windowHandle()->format(); if (requestedFormat.swapInterval() != tlwFormat.swapInterval()) { // Most platforms will pick up the changed swap interval on the next @@ -990,7 +1028,6 @@ QOpenGLWidget::UpdateBehavior QOpenGLWidget::updateBehavior() const */ void QOpenGLWidget::setFormat(const QSurfaceFormat &format) { - Q_UNUSED(format); Q_D(QOpenGLWidget); if (Q_UNLIKELY(d->initialized)) { qWarning("QOpenGLWidget: Already initialized, setting the format has no effect"); @@ -1023,6 +1060,47 @@ QSurfaceFormat QOpenGLWidget::format() const } /*! + Sets a custom internal texture format. + + When working with sRGB framebuffers, it will be necessary to specify a + format like \c{GL_SRGB8_ALPHA8}. This can be achieved by calling this + function. + + \note This function has no effect if called after the widget has already + been shown and thus it performed initialization. + + \note This function will typically have to be used in combination with a + QSurfaceFormat::setDefaultFormat() call that sets the color space to + QSurfaceFormat::sRGBColorSpace. + + \since 5.10 + */ +void QOpenGLWidget::setTextureFormat(GLenum texFormat) +{ + Q_D(QOpenGLWidget); + if (Q_UNLIKELY(d->initialized)) { + qWarning("QOpenGLWidget: Already initialized, setting the internal texture format has no effect"); + return; + } + + d->textureFormat = texFormat; +} + +/*! + \return the active internal texture format if the widget has already + initialized, the requested format if one was set but the widget has not yet + been made visible, or 0 if setTextureFormat() was not called and the widget + has not yet been made visible. + + \since 5.10 + */ +GLenum QOpenGLWidget::textureFormat() const +{ + Q_D(const QOpenGLWidget); + return d->textureFormat; +} + +/*! \return \e true if the widget and OpenGL resources, like the context, have been successfully initialized. Note that the return value is always false until the widget is shown. diff --git a/src/widgets/kernel/qopenglwidget.h b/src/widgets/kernel/qopenglwidget.h index b60d79bedb..c0a6e41522 100644 --- a/src/widgets/kernel/qopenglwidget.h +++ b/src/widgets/kernel/qopenglwidget.h @@ -72,6 +72,9 @@ public: void setFormat(const QSurfaceFormat &format); QSurfaceFormat format() const; + GLenum textureFormat() const; + void setTextureFormat(GLenum texFormat); + bool isValid() const; void makeCurrent(); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 70bc407587..8a642940cd 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -67,7 +67,6 @@ # include <private/qmainwindowlayout_p.h> #endif #include <qpa/qplatformwindow.h> -#include <qpa/qplatformbackingstore.h> #include "private/qwidgetwindow_p.h" #include "qpainter.h" #include "qtooltip.h" diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 68e063c25a..858328e618 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -69,6 +69,7 @@ #include "QtWidgets/qgraphicsscene.h" #include "QtWidgets/qgraphicsview.h" #include <private/qgesture_p.h> +#include <qpa/qplatformbackingstore.h> QT_BEGIN_NAMESPACE @@ -81,7 +82,6 @@ class QWidgetBackingStore; class QGraphicsProxyWidget; class QWidgetItemV2; class QOpenGLContext; -class QPlatformTextureList; class QStyle; @@ -630,6 +630,12 @@ public: #ifndef QT_NO_OPENGL virtual GLuint textureId() const { return 0; } + virtual QPlatformTextureList::Flags textureListFlags() { + Q_Q(QWidget); + return q->testAttribute(Qt::WA_AlwaysStackOnTop) + ? QPlatformTextureList::StacksOnTop + : QPlatformTextureList::Flags(0); + } virtual QImage grabFramebuffer() { return QImage(); } virtual void beginBackingStorePainting() { } virtual void endBackingStorePainting() { } diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index 781ad9600d..4421218d1d 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -945,9 +945,7 @@ static void findTextureWidgetsRecursively(QWidget *tlw, QWidget *widget, QPlatfo { QWidgetPrivate *wd = QWidgetPrivate::get(widget); if (wd->renderToTexture) { - QPlatformTextureList::Flags flags = 0; - if (widget->testAttribute(Qt::WA_AlwaysStackOnTop)) - flags |= QPlatformTextureList::StacksOnTop; + QPlatformTextureList::Flags flags = wd->textureListFlags(); const QRect rect(widget->mapTo(tlw, QPoint()), widget->size()); widgetTextures->appendTexture(widget, wd->textureId(), rect, wd->clipRect(), flags); } diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp index 7ae63e54b3..a17c69c5ce 100644 --- a/src/widgets/kernel/qwindowcontainer.cpp +++ b/src/widgets/kernel/qwindowcontainer.cpp @@ -337,6 +337,19 @@ bool QWindowContainer::event(QEvent *e) e->accept(); return true; #endif + + case QEvent::Paint: + { + static bool needsPunch = !QGuiApplicationPrivate::platformIntegration()->hasCapability( + QPlatformIntegration::TopStackedNativeChildWindows); + if (needsPunch) { + QPainter p(this); + p.setCompositionMode(QPainter::CompositionMode_Source); + p.fillRect(rect(), Qt::transparent); + } + break; + } + default: break; } |