diff options
Diffstat (limited to 'src/gui/image/qpixmap.cpp')
-rw-r--r-- | src/gui/image/qpixmap.cpp | 106 |
1 files changed, 33 insertions, 73 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 3d46dc4a6b..afef16f867 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <qglobal.h> @@ -68,8 +32,15 @@ #include <qtgui_tracepoints_p.h> +#include <memory> + QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + +Q_TRACE_PARAM_REPLACE(Qt::AspectRatioMode, int); +Q_TRACE_PARAM_REPLACE(Qt::TransformationMode, int); + // MSVC 19.28 does show spurious warning "C4723: potential divide by 0" for code that divides // by height() in release builds. Anyhow, all the code paths in this file are only executed // for valid QPixmap's, where height() cannot be 0. Therefore disable the warning. @@ -81,17 +52,11 @@ static bool qt_pixmap_thread_test() qFatal("QPixmap: Must construct a QGuiApplication before a QPixmap"); return false; } - - if (qApp->thread() != QThread::currentThread()) { - bool fail = false; - if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) { - printf("Platform plugin does not support threaded pixmaps!\n"); - fail = true; - } - if (fail) { - qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread"); - return false; - } + if (QGuiApplicationPrivate::instance() + && qApp->thread() != QThread::currentThread() + && !QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) { + qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread on this platform"); + return false; } return true; } @@ -324,7 +289,6 @@ QPixmap QPixmap::copy(const QRect &rect) const /*! \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed) - \since 4.6 This convenience function is equivalent to calling QPixmap::scroll(\a dx, \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed). @@ -333,8 +297,6 @@ QPixmap QPixmap::copy(const QRect &rect) const */ /*! - \since 4.6 - Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed region is left unchanged. You can optionally pass a pointer to an empty QRegion to get the region that is \a exposed by the scroll operation. @@ -406,7 +368,6 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap) /*! \fn void QPixmap::swap(QPixmap &other) - \since 4.8 Swaps pixmap \a other with this pixmap. This operation is very fast and never fails. @@ -658,7 +619,9 @@ void QPixmap::setDevicePixelRatio(qreal scaleFactor) This value should be used when using the pixmap size in user interface size calculations. - The return value is equivalent to pixmap.size() / pixmap.devicePixelRatio(), + The return value is equivalent to pixmap.size() / pixmap.devicePixelRatio(). + + \since 6.2 */ QSizeF QPixmap::deviceIndependentSize() const { @@ -748,9 +711,9 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers if (info.completeSuffix().isEmpty() || info.exists()) { const bool inGuiThread = qApp->thread() == QThread::currentThread(); - QString key = QLatin1String("qt_pixmap") + QString key = "qt_pixmap"_L1 % info.absoluteFilePath() - % HexString<uint>(info.lastModified().toSecsSinceEpoch()) + % HexString<uint>(info.lastModified(QTimeZone::UTC).toSecsSinceEpoch()) % HexString<quint64>(info.size()) % HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType); @@ -905,6 +868,7 @@ void QPixmap::fill(const QColor &color) // it will be filled with new pixel data anyway. QPlatformPixmap *d = data->createCompatiblePlatformPixmap(); d->resize(data->width(), data->height()); + d->setDevicePixelRatio(data->devicePixelRatio()); data = d; } data->fill(color); @@ -1002,12 +966,7 @@ bool QPixmap::isDetached() const Passing 0 for \a flags sets all the default options. Returns \c true if the result is that this pixmap is not null. - Note: this function was part of Qt 3 support in Qt 4.6 and earlier. - It has been promoted to official API status in 4.7 to support updating - the pixmap's image without creating a new QPixmap as fromImage() would. - \sa fromImage() - \since 4.7 */ bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) { @@ -1067,7 +1026,7 @@ bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags fla Transformations} */ -QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const +QPixmap Q_TRACE_INSTRUMENT(qtgui) QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const { if (isNull()) { qWarning("QPixmap::scaled: Pixmap is a null pixmap"); @@ -1105,7 +1064,7 @@ QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::Tran \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap Transformations} */ -QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const +QPixmap Q_TRACE_INSTRUMENT(qtgui) QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const { if (isNull()) { qWarning("QPixmap::scaleWidth: Pixmap is a null pixmap"); @@ -1135,7 +1094,7 @@ QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap Transformations} */ -QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const +QPixmap Q_TRACE_INSTRUMENT(qtgui) QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const { if (isNull()) { qWarning("QPixmap::scaleHeight: Pixmap is a null pixmap"); @@ -1312,8 +1271,9 @@ QPixmap QPixmap::transformed(const QTransform &transform, QPixmap using the fromImage(). If this is too expensive an operation, you can use QBitmap::fromImage() instead. - To convert a QPixmap to and from HICON you can use the QtWinExtras - functions QtWin::toHICON() and QtWin::fromHICON() respectively. + To convert a QPixmap to and from HICON you can use the + QImage::toHICON() and QImage::fromHICON() functions respectively + (after converting the QPixmap to a QImage, as explained above). \section1 Pixmap Transformations @@ -1442,7 +1402,7 @@ void QPixmap::detach() return; // QPixmap.data member may be QRuntimePlatformPixmap so use handle() function to get - // the actual underlaying runtime pixmap data. + // the actual underlying runtime pixmap data. QPlatformPixmap *pd = handle(); QPlatformPixmap::ClassId id = pd->classId(); if (id == QPlatformPixmap::RasterClass) { @@ -1484,9 +1444,9 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) return QPixmap(); } - QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImage(image, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! @@ -1511,9 +1471,9 @@ QPixmap QPixmap::fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags) return QPixmap(); } - QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImageInPlace(image, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! @@ -1535,9 +1495,9 @@ QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionF return QPixmap(); } - QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImageReader(imageReader, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! |