diff options
author | Louai Al-Khanji <louai.al-khanji@digia.com> | 2014-04-30 10:27:57 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-05 14:13:50 +0200 |
commit | ac448335f177eff59465300a7141db559c9eadad (patch) | |
tree | a70d815ba5cb629e1b2f41a29673b58f98036107 /src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp | |
parent | 89b70f3910dfec7108d6e95cc96f904fce01da29 (diff) |
Direct2D QPA: Draw directly to swap chain
Remove the intermediate pixmap in the backing store and draw directly to
the window swap chain. This is faster and reduces memory pressure on the
graphics card.
In case of native child widgets we need to read back the back buffer,
which incurs an extra copy in this case.
In an artificial benchmark drawing animated full screen
gradients as fast as possible this patch increases performance by 42% on
my current machine from 480fps to around 680fps, i.e. the time for
actually getting the pixels to the screen is now lower.
Change-Id: Ifbeda0e199afec03cecfe76337679a9e9d082bdd
Reviewed-by: Risto Avila <risto.avila@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Diffstat (limited to 'src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp')
-rw-r--r-- | src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp index e4ce81bd24..be013f027b 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dbackingstore.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -66,6 +66,16 @@ static inline QWindowsDirect2DPlatformPixmap *platformPixmap(QPixmap *p) return static_cast<QWindowsDirect2DPlatformPixmap *>(p->handle()); } +static inline QWindowsDirect2DBitmap *bitmap(QPixmap *p) +{ + return platformPixmap(p)->bitmap(); +} + +static inline QWindowsDirect2DWindow *nativeWindow(QWindow *window) +{ + return static_cast<QWindowsDirect2DWindow *>(window->handle()); +} + QWindowsDirect2DBackingStore::QWindowsDirect2DBackingStore(QWindow *window) : QPlatformBackingStore(window) { @@ -77,36 +87,40 @@ QWindowsDirect2DBackingStore::~QWindowsDirect2DBackingStore() void QWindowsDirect2DBackingStore::beginPaint(const QRegion &) { - platformPixmap(m_pixmap.data())->bitmap()->deviceContext()->begin(); + bitmap(nativeWindow(window())->pixmap())->deviceContext()->begin(); } void QWindowsDirect2DBackingStore::endPaint() { - platformPixmap(m_pixmap.data())->bitmap()->deviceContext()->end(); + bitmap(nativeWindow(window())->pixmap())->deviceContext()->end(); } QPaintDevice *QWindowsDirect2DBackingStore::paintDevice() { - return m_pixmap.data(); + return nativeWindow(window())->pixmap(); } -void QWindowsDirect2DBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +void QWindowsDirect2DBackingStore::flush(QWindow *targetWindow, const QRegion ®ion, const QPoint &offset) { - QPlatformWindow *pw = window->handle(); - if (pw && m_pixmap) - static_cast<QWindowsDirect2DWindow *>(pw)->flush(platformPixmap(m_pixmap.data())->bitmap(), region, offset); + if (targetWindow != window()) { + QSharedPointer<QWindowsDirect2DBitmap> copy(nativeWindow(window())->copyBackBuffer()); + nativeWindow(targetWindow)->flush(copy.data(), region, offset); + } + + nativeWindow(targetWindow)->present(); } void QWindowsDirect2DBackingStore::resize(const QSize &size, const QRegion ®ion) { - Q_UNUSED(region); + QPixmap old = nativeWindow(window())->pixmap()->copy(); - QScopedPointer<QPixmap> oldPixmap(m_pixmap.take()); - m_pixmap.reset(new QPixmap(size.width(), size.height())); + nativeWindow(window())->resizeSwapChain(size); + QPixmap *newPixmap = nativeWindow(window())->pixmap(); - if (oldPixmap) { - foreach (const QRect &rect, region.rects()) - platformPixmap(m_pixmap.data())->copy(oldPixmap->handle(), rect); + if (!old.isNull()) { + foreach (const QRect &rect, region.rects()) { + platformPixmap(newPixmap)->copy(old.handle(), rect); + } } } |