| 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 | |
| 4 | #include "qfbbackingstore_p.h" |
| 5 | #include "qfbwindow_p.h" |
| 6 | #include "qfbscreen_p.h" |
| 7 | |
| 8 | #include <qpa/qplatformwindow.h> |
| 9 | #include <QtGui/qscreen.h> |
| 10 | #include <QtGui/qpainter.h> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | QFbBackingStore::QFbBackingStore(QWindow *window) |
| 15 | : QPlatformBackingStore(window) |
| 16 | { |
| 17 | if (window->handle()) |
| 18 | (static_cast<QFbWindow *>(window->handle()))->setBackingStore(this); |
| 19 | else |
| 20 | (static_cast<QFbScreen *>(window->screen()->handle()))->addPendingBackingStore(bs: this); |
| 21 | } |
| 22 | |
| 23 | QFbBackingStore::~QFbBackingStore() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | void QFbBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) |
| 28 | { |
| 29 | Q_UNUSED(window); |
| 30 | Q_UNUSED(offset); |
| 31 | |
| 32 | (static_cast<QFbWindow *>(window->handle()))->repaint(region); |
| 33 | } |
| 34 | |
| 35 | void QFbBackingStore::resize(const QSize &size, const QRegion &staticContents) |
| 36 | { |
| 37 | Q_UNUSED(staticContents); |
| 38 | |
| 39 | if (mImage.size() != size) |
| 40 | mImage = QImage(size, window()->screen()->handle()->format()); |
| 41 | } |
| 42 | |
| 43 | const QImage QFbBackingStore::image() |
| 44 | { |
| 45 | return mImage; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | QImage QFbBackingStore::toImage() const |
| 50 | { |
| 51 | return mImage; |
| 52 | } |
| 53 | |
| 54 | void QFbBackingStore::lock() |
| 55 | { |
| 56 | mImageMutex.lock(); |
| 57 | } |
| 58 | |
| 59 | void QFbBackingStore::unlock() |
| 60 | { |
| 61 | mImageMutex.unlock(); |
| 62 | } |
| 63 | |
| 64 | void QFbBackingStore::beginPaint(const QRegion ®ion) |
| 65 | { |
| 66 | lock(); |
| 67 | |
| 68 | if (mImage.hasAlphaChannel()) { |
| 69 | QPainter p(&mImage); |
| 70 | p.setCompositionMode(QPainter::CompositionMode_Source); |
| 71 | for (const QRect &r : region) |
| 72 | p.fillRect(r, c: Qt::transparent); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void QFbBackingStore::endPaint() |
| 77 | { |
| 78 | unlock(); |
| 79 | } |
| 80 | |
| 81 | QT_END_NAMESPACE |
| 82 |
