| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qplatformpixmap.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | #include "qplatformpixmap.h" | - | ||||||||||||
| 35 | #include <qpa/qplatformintegration.h> | - | ||||||||||||
| 36 | #include <QtCore/qbuffer.h> | - | ||||||||||||
| 37 | #include <QtGui/qbitmap.h> | - | ||||||||||||
| 38 | #include <QtGui/qimagereader.h> | - | ||||||||||||
| 39 | #include <private/qguiapplication_p.h> | - | ||||||||||||
| 40 | #include <private/qimagepixmapcleanuphooks_p.h> | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | /*! | - | ||||||||||||
| 45 | \class QPlatformPixmap | - | ||||||||||||
| 46 | \since 5.0 | - | ||||||||||||
| 47 | \internal | - | ||||||||||||
| 48 | \preliminary | - | ||||||||||||
| 49 | \ingroup qpa | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | \brief The QPlatformPixmap class provides an abstraction for native pixmaps. | - | ||||||||||||
| 52 | */ | - | ||||||||||||
| 53 | QPlatformPixmap *QPlatformPixmap::create(int w, int h, PixelType type) | - | ||||||||||||
| 54 | { | - | ||||||||||||
| 55 | QPlatformPixmap *data = QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(static_cast<QPlatformPixmap::PixelType>(type)); | - | ||||||||||||
| 56 | data->resize(w, h); | - | ||||||||||||
| 57 | return data; never executed: return data; | 0 | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | - | |||||||||||||
| 61 | QPlatformPixmap::QPlatformPixmap(PixelType pixelType, int objectId) | - | ||||||||||||
| 62 | : w(0), | - | ||||||||||||
| 63 | h(0), | - | ||||||||||||
| 64 | d(0), | - | ||||||||||||
| 65 | is_null(true), | - | ||||||||||||
| 66 | ref(0), | - | ||||||||||||
| 67 | detach_no(0), | - | ||||||||||||
| 68 | type(pixelType), | - | ||||||||||||
| 69 | id(objectId), | - | ||||||||||||
| 70 | ser_no(0), | - | ||||||||||||
| 71 | is_cached(false) | - | ||||||||||||
| 72 | { | - | ||||||||||||
| 73 | } never executed: end of block | 0 | ||||||||||||
| 74 | - | |||||||||||||
| 75 | QPlatformPixmap::~QPlatformPixmap() | - | ||||||||||||
| 76 | { | - | ||||||||||||
| 77 | // Sometimes the pixmap cleanup hooks will be called from derrived classes, which will | - | ||||||||||||
| 78 | // then set is_cached to false. For example, on X11 Qt GUI needs to delete the GLXPixmap | - | ||||||||||||
| 79 | // or EGL Pixmap Surface for a given pixmap _before_ the native X11 pixmap is deleted, | - | ||||||||||||
| 80 | // otherwise some drivers will leak the GL surface. In this case, QX11PlatformPixmap will | - | ||||||||||||
| 81 | // call the cleanup hooks itself before deleting the native pixmap and set is_cached to | - | ||||||||||||
| 82 | // false. | - | ||||||||||||
| 83 | if (is_cached) {
| 0 | ||||||||||||
| 84 | QImagePixmapCleanupHooks::executePlatformPixmapDestructionHooks(this); | - | ||||||||||||
| 85 | is_cached = false; | - | ||||||||||||
| 86 | } never executed: end of block | 0 | ||||||||||||
| 87 | } never executed: end of block | 0 | ||||||||||||
| 88 | - | |||||||||||||
| 89 | QPlatformPixmap *QPlatformPixmap::createCompatiblePlatformPixmap() const | - | ||||||||||||
| 90 | { | - | ||||||||||||
| 91 | QPlatformPixmap *d = QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(pixelType()); | - | ||||||||||||
| 92 | return d; never executed: return d; | 0 | ||||||||||||
| 93 | } | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | static QImage makeBitmapCompliantIfNeeded(QPlatformPixmap *d, const QImage &image, Qt::ImageConversionFlags flags) | - | ||||||||||||
| 96 | { | - | ||||||||||||
| 97 | if (d->pixelType() == QPlatformPixmap::BitmapType) {
| 0 | ||||||||||||
| 98 | QImage img = image.convertToFormat(QImage::Format_MonoLSB, flags); | - | ||||||||||||
| 99 | - | |||||||||||||
| 100 | // make sure image.color(0) == Qt::color0 (white) | - | ||||||||||||
| 101 | // and image.color(1) == Qt::color1 (black) | - | ||||||||||||
| 102 | const QRgb c0 = QColor(Qt::black).rgb(); | - | ||||||||||||
| 103 | const QRgb c1 = QColor(Qt::white).rgb(); | - | ||||||||||||
| 104 | if (img.color(0) == c0 && img.color(1) == c1) {
| 0 | ||||||||||||
| 105 | img.invertPixels(); | - | ||||||||||||
| 106 | img.setColor(0, c1); | - | ||||||||||||
| 107 | img.setColor(1, c0); | - | ||||||||||||
| 108 | } never executed: end of block | 0 | ||||||||||||
| 109 | return img; never executed: return img; | 0 | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | return image; never executed: return image; | 0 | ||||||||||||
| 113 | } | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | void QPlatformPixmap::fromImageReader(QImageReader *imageReader, | - | ||||||||||||
| 116 | Qt::ImageConversionFlags flags) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | const QImage image = imageReader->read(); | - | ||||||||||||
| 119 | fromImage(image, flags); | - | ||||||||||||
| 120 | } never executed: end of block | 0 | ||||||||||||
| 121 | - | |||||||||||||
| 122 | bool QPlatformPixmap::fromFile(const QString &fileName, const char *format, | - | ||||||||||||
| 123 | Qt::ImageConversionFlags flags) | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | QImage image = QImageReader(fileName, format).read(); | - | ||||||||||||
| 126 | if (image.isNull())
| 0 | ||||||||||||
| 127 | return false; never executed: return false; | 0 | ||||||||||||
| 128 | fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags); | - | ||||||||||||
| 129 | return !isNull(); never executed: return !isNull(); | 0 | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | bool QPlatformPixmap::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) | - | ||||||||||||
| 133 | { | - | ||||||||||||
| 134 | QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len); | - | ||||||||||||
| 135 | QBuffer b(&a); | - | ||||||||||||
| 136 | b.open(QIODevice::ReadOnly); | - | ||||||||||||
| 137 | QImage image = QImageReader(&b, format).read(); | - | ||||||||||||
| 138 | if (image.isNull())
| 0 | ||||||||||||
| 139 | return false; never executed: return false; | 0 | ||||||||||||
| 140 | fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags); | - | ||||||||||||
| 141 | return !isNull(); never executed: return !isNull(); | 0 | ||||||||||||
| 142 | } | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | void QPlatformPixmap::copy(const QPlatformPixmap *data, const QRect &rect) | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | fromImage(data->toImage(rect), Qt::NoOpaqueDetection); | - | ||||||||||||
| 147 | } never executed: end of block | 0 | ||||||||||||
| 148 | - | |||||||||||||
| 149 | bool QPlatformPixmap::scroll(int dx, int dy, const QRect &rect) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | Q_UNUSED(dx); | - | ||||||||||||
| 152 | Q_UNUSED(dy); | - | ||||||||||||
| 153 | Q_UNUSED(rect); | - | ||||||||||||
| 154 | return false; never executed: return false; | 0 | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | QPixmap QPlatformPixmap::transformed(const QTransform &matrix, | - | ||||||||||||
| 158 | Qt::TransformationMode mode) const | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 | return QPixmap::fromImage(toImage().transformed(matrix, mode)); never executed: return QPixmap::fromImage(toImage().transformed(matrix, mode)); | 0 | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | void QPlatformPixmap::setSerialNumber(int serNo) | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | ser_no = serNo; | - | ||||||||||||
| 166 | } never executed: end of block | 0 | ||||||||||||
| 167 | - | |||||||||||||
| 168 | void QPlatformPixmap::setDetachNumber(int detNo) | - | ||||||||||||
| 169 | { | - | ||||||||||||
| 170 | detach_no = detNo; | - | ||||||||||||
| 171 | } never executed: end of block | 0 | ||||||||||||
| 172 | - | |||||||||||||
| 173 | QImage QPlatformPixmap::toImage(const QRect &rect) const | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | if (rect.contains(QRect(0, 0, w, h)))
| 0 | ||||||||||||
| 176 | return toImage(); never executed: return toImage(); | 0 | ||||||||||||
| 177 | else | - | ||||||||||||
| 178 | return toImage().copy(rect); never executed: return toImage().copy(rect); | 0 | ||||||||||||
| 179 | } | - | ||||||||||||
| 180 | - | |||||||||||||
| 181 | QImage* QPlatformPixmap::buffer() | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | return 0; never executed: return 0; | 0 | ||||||||||||
| 184 | } | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | - | |||||||||||||
| 187 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |