Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsdirect2dbackingstore.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
12
14
15#include <QtGui/qpainter.h>
16#include <QtGui/qwindow.h>
17#include <QtCore/qdebug.h>
18
20
21/*!
22 \class QWindowsDirect2DBackingStore
23 \brief Backing store for windows.
24 \internal
25*/
26
28{
29 return static_cast<QWindowsDirect2DPlatformPixmap *>(p->handle());
30}
31
32static inline QWindowsDirect2DBitmap *bitmap(QPixmap *p)
33{
34 return platformPixmap(p)->bitmap();
35}
36
37static inline QWindowsDirect2DWindow *nativeWindow(QWindow *window)
38{
39 return static_cast<QWindowsDirect2DWindow *>(window->handle());
40}
41
42QWindowsDirect2DBackingStore::QWindowsDirect2DBackingStore(QWindow *window)
43 : QPlatformBackingStore(window)
44{
45}
46
50
51void QWindowsDirect2DBackingStore::beginPaint(const QRegion &region)
52{
53 QPixmap *pixmap = nativeWindow(window())->pixmap();
54 bitmap(pixmap)->deviceContext()->begin();
55
56 QPainter painter(pixmap);
57 QColor clear(Qt::transparent);
58
59 painter.setCompositionMode(QPainter::CompositionMode_Source);
60
61 for (const QRect &r : region)
62 painter.fillRect(r, clear);
63}
64
66{
67 bitmap(nativeWindow(window())->pixmap())->deviceContext()->end();
68}
69
71{
72 return nativeWindow(window())->pixmap();
73}
74
75void QWindowsDirect2DBackingStore::flush(QWindow *targetWindow, const QRegion &region, const QPoint &offset)
76{
77 if (targetWindow != window()) {
78 QSharedPointer<QWindowsDirect2DBitmap> copy(nativeWindow(window())->copyBackBuffer());
79 nativeWindow(targetWindow)->flush(copy.data(), region, offset);
80 }
81
82 nativeWindow(targetWindow)->present(region);
83}
84
85void QWindowsDirect2DBackingStore::resize(const QSize &size, const QRegion &region)
86{
87 QPixmap old = nativeWindow(window())->pixmap()->copy();
88
89 nativeWindow(window())->resizeSwapChain(size);
90 QPixmap *newPixmap = nativeWindow(window())->pixmap();
91
92 if (!old.isNull()) {
93 for (const QRect &rect : region)
94 platformPixmap(newPixmap)->copy(old.handle(), rect);
95 }
96}
97
99{
100 return nativeWindow(window())->pixmap()->toImage();
101}
102
103QT_END_NAMESPACE
\inmodule QtCore\reentrant
Definition qpoint.h:29
void beginPaint(const QRegion &) override
This function is called before painting onto the surface begins, with the region in which the paintin...
void endPaint() override
This function is called after painting onto the surface has ended.
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
QImage toImage() const override
Implemented in subclasses to return the content of the backingstore as a QImage.
static QWindowsDirect2DPlatformPixmap * platformPixmap(QPixmap *p)
static QWindowsDirect2DWindow * nativeWindow(QWindow *window)
static QWindowsDirect2DBitmap * bitmap(QPixmap *p)