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// Qt-Security score:significant reason:default
4
13
15
16#include <QtGui/qpainter.h>
17#include <QtGui/qwindow.h>
18#include <QtCore/qdebug.h>
19
21
22/*!
23 \class QWindowsDirect2DBackingStore
24 \brief Backing store for windows.
25 \internal
26*/
27
29{
30 return static_cast<QWindowsDirect2DPlatformPixmap *>(p->handle());
31}
32
33static inline QWindowsDirect2DBitmap *bitmap(QPixmap *p)
34{
35 return platformPixmap(p)->bitmap();
36}
37
38static inline QWindowsDirect2DWindow *nativeWindow(QWindow *window)
39{
40 return static_cast<QWindowsDirect2DWindow *>(window->handle());
41}
42
43QWindowsDirect2DBackingStore::QWindowsDirect2DBackingStore(QWindow *window)
44 : QPlatformBackingStore(window)
45{
46}
47
51
52void QWindowsDirect2DBackingStore::beginPaint(const QRegion &region)
53{
54 QPixmap *pixmap = nativeWindow(window())->pixmap();
55 bitmap(pixmap)->deviceContext()->begin();
56
57 QPainter painter(pixmap);
58 QColor clear(Qt::transparent);
59
60 painter.setCompositionMode(QPainter::CompositionMode_Source);
61
62 for (const QRect &r : region)
63 painter.fillRect(r, clear);
64}
65
67{
68 bitmap(nativeWindow(window())->pixmap())->deviceContext()->end();
69}
70
72{
73 return nativeWindow(window())->pixmap();
74}
75
76void QWindowsDirect2DBackingStore::flush(QWindow *targetWindow, const QRegion &region, const QPoint &offset)
77{
78 if (targetWindow != window()) {
79 QSharedPointer<QWindowsDirect2DBitmap> copy(nativeWindow(window())->copyBackBuffer());
80 nativeWindow(targetWindow)->flush(copy.data(), region, offset);
81 }
82
83 nativeWindow(targetWindow)->present(region);
84}
85
86void QWindowsDirect2DBackingStore::resize(const QSize &size, const QRegion &region)
87{
88 QPixmap old = nativeWindow(window())->pixmap()->copy();
89
90 nativeWindow(window())->resizeSwapChain(size);
91 QPixmap *newPixmap = nativeWindow(window())->pixmap();
92
93 if (!old.isNull()) {
94 for (const QRect &rect : region)
95 platformPixmap(newPixmap)->copy(old.handle(), rect);
96 }
97}
98
100{
101 return nativeWindow(window())->pixmap()->toImage();
102}
103
104QT_END_NAMESPACE
\inmodule QtCore\reentrant
Definition qpoint.h:30
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.
Combined button and popup list for selecting options.
static QWindowsDirect2DPlatformPixmap * platformPixmap(QPixmap *p)
static QWindowsDirect2DWindow * nativeWindow(QWindow *window)
static QWindowsDirect2DBitmap * bitmap(QPixmap *p)