summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qplatformbackingstore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting/qplatformbackingstore.cpp')
-rw-r--r--src/gui/painting/qplatformbackingstore.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp
index dd02e24676..5f873bfe7e 100644
--- a/src/gui/painting/qplatformbackingstore.cpp
+++ b/src/gui/painting/qplatformbackingstore.cpp
@@ -224,16 +224,16 @@ static inline QRect deviceRect(const QRect &rect, QWindow *window)
return deviceRect;
}
-static QRegion deviceRegion(const QRegion &region, QWindow *window)
+static QRegion deviceRegion(const QRegion &region, QWindow *window, const QPoint &offset)
{
- if (!(window->devicePixelRatio() > 1))
+ if (offset.isNull() && window->devicePixelRatio() <= 1)
return region;
QVector<QRect> rects;
const QVector<QRect> regionRects = region.rects();
rects.reserve(regionRects.count());
foreach (const QRect &rect, regionRects)
- rects.append(deviceRect(rect, window));
+ rects.append(deviceRect(rect.translated(offset), window));
QRegion deviceRegion;
deviceRegion.setRects(rects.constData(), rects.count());
@@ -246,10 +246,12 @@ static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)
topLeftRect.width(), topLeftRect.height());
}
-static void blit(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect,
- QOpenGLTextureBlitter *blitter)
+static void blitTextureForWidget(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect,
+ QOpenGLTextureBlitter *blitter, const QPoint &offset)
{
- const QRect rectInWindow = textures->geometry(idx);
+ QRect rectInWindow = textures->geometry(idx);
+ // relative to the TLW, not necessarily our window (if the flush is for a native child widget), have to adjust
+ rectInWindow.translate(-offset);
QRect clipRect = textures->clipRect(idx);
if (clipRect.isEmpty())
clipRect = QRect(QPoint(0, 0), rectInWindow.size());
@@ -274,7 +276,9 @@ static void blit(const QPlatformTextureList *textures, int idx, QWindow *window,
and composes using OpenGL. May be reimplemented in subclasses if there
is a more efficient native way to do it.
- Note that the \a offset parameter is currently unused.
+ \note \a region is relative to the window which may not be top-level in case
+ \a window corresponds to a native child widget. \a offset is the position of
+ the native child relative to the top-level window.
*/
void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &region,
@@ -282,7 +286,8 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
QPlatformTextureList *textures, QOpenGLContext *context,
bool translucentBackground)
{
- Q_UNUSED(offset);
+ if (!qt_window_private(window)->receivedExpose)
+ return;
if (!context->makeCurrent(window)) {
qWarning("composeAndFlush: makeCurrent() failed");
@@ -306,7 +311,7 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
// Textures for renderToTexture widgets.
for (int i = 0; i < textures->count(); ++i) {
if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop))
- blit(textures, i, window, deviceWindowRect, d_ptr->blitter);
+ blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset);
}
funcs->glEnable(GL_BLEND);
@@ -348,17 +353,26 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
textureId = d_ptr->textureId;
} else {
TextureFlags flags = 0;
- textureId = toTexture(deviceRegion(region, window), &d_ptr->textureSize, &flags);
+ textureId = toTexture(deviceRegion(region, window, offset), &d_ptr->textureSize, &flags);
d_ptr->needsSwizzle = (flags & TextureSwizzle) != 0;
if (flags & TextureFlip)
origin = QOpenGLTextureBlitter::OriginBottomLeft;
}
if (textureId) {
- QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(QRect(QPoint(), d_ptr->textureSize), deviceWindowRect);
if (d_ptr->needsSwizzle)
d_ptr->blitter->setSwizzleRB(true);
- d_ptr->blitter->blit(textureId, target, origin);
+ // offset is usually (0, 0) unless we have native child widgets.
+ if (offset.isNull()) {
+ d_ptr->blitter->blit(textureId, QMatrix4x4(), origin);
+ } else {
+ // The backingstore is for the entire tlw. offset tells the position of the native child in the tlw.
+ const QRect srcRect = toBottomLeftRect(deviceWindowRect.translated(offset), d_ptr->textureSize.height());
+ const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(deviceRect(srcRect, window),
+ d_ptr->textureSize,
+ origin);
+ d_ptr->blitter->blit(textureId, QMatrix4x4(), source);
+ }
if (d_ptr->needsSwizzle)
d_ptr->blitter->setSwizzleRB(false);
}
@@ -366,7 +380,7 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
// Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set.
for (int i = 0; i < textures->count(); ++i) {
if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop))
- blit(textures, i, window, deviceWindowRect, d_ptr->blitter);
+ blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset);
}
funcs->glDisable(GL_BLEND);
@@ -413,6 +427,8 @@ QImage QPlatformBackingStore::toImage() const
If the image has to be flipped (e.g. because the texture is attached to an FBO), \a
flags will be set to include \c TextureFlip.
+
+ \note \a dirtyRegion is relative to the backingstore so no adjustment is needed.
*/
GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion, QSize *textureSize, TextureFlags *flags) const
{