Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qpixmap_blitter.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 "qpixmap_blitter_p.h" | - | ||||||||||||
35 | - | |||||||||||||
36 | #include <qpainter.h> | - | ||||||||||||
37 | #include <qimage.h> | - | ||||||||||||
38 | #include <qscreen.h> | - | ||||||||||||
39 | - | |||||||||||||
40 | #include <private/qguiapplication_p.h> | - | ||||||||||||
41 | #include <private/qblittable_p.h> | - | ||||||||||||
42 | - | |||||||||||||
43 | #include <private/qdrawhelper_p.h> | - | ||||||||||||
44 | #include <private/qfont_p.h> | - | ||||||||||||
45 | - | |||||||||||||
46 | #ifndef QT_NO_BLITTABLE | - | ||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
48 | - | |||||||||||||
49 | static int global_ser_no = 0; | - | ||||||||||||
50 | - | |||||||||||||
51 | QBlittablePlatformPixmap::QBlittablePlatformPixmap() | - | ||||||||||||
52 | : QPlatformPixmap(QPlatformPixmap::PixmapType,BlitterClass) | - | ||||||||||||
53 | , m_alpha(false) | - | ||||||||||||
54 | , m_devicePixelRatio(1.0) | - | ||||||||||||
55 | #ifdef QT_BLITTER_RASTEROVERLAY | - | ||||||||||||
56 | ,m_rasterOverlay(0), m_unmergedCopy(0) | - | ||||||||||||
57 | #endif //QT_BLITTER_RASTEROVERLAY | - | ||||||||||||
58 | { | - | ||||||||||||
59 | setSerialNumber(++global_ser_no); | - | ||||||||||||
60 | } never executed: end of block | 0 | ||||||||||||
61 | - | |||||||||||||
62 | QBlittablePlatformPixmap::~QBlittablePlatformPixmap() | - | ||||||||||||
63 | { | - | ||||||||||||
64 | #ifdef QT_BLITTER_RASTEROVERLAY | - | ||||||||||||
65 | delete m_rasterOverlay; | - | ||||||||||||
66 | delete m_unmergedCopy; | - | ||||||||||||
67 | #endif //QT_BLITTER_RASTEROVERLAY | - | ||||||||||||
68 | } | - | ||||||||||||
69 | - | |||||||||||||
70 | QBlittable *QBlittablePlatformPixmap::blittable() const | - | ||||||||||||
71 | { | - | ||||||||||||
72 | if (!m_blittable) {
| 0 | ||||||||||||
73 | QBlittablePlatformPixmap *that = const_cast<QBlittablePlatformPixmap *>(this); | - | ||||||||||||
74 | that->m_blittable.reset(this->createBlittable(QSize(w, h), m_alpha)); | - | ||||||||||||
75 | } never executed: end of block | 0 | ||||||||||||
76 | - | |||||||||||||
77 | return m_blittable.data(); never executed: return m_blittable.data(); | 0 | ||||||||||||
78 | } | - | ||||||||||||
79 | - | |||||||||||||
80 | void QBlittablePlatformPixmap::setBlittable(QBlittable *blittable) | - | ||||||||||||
81 | { | - | ||||||||||||
82 | resize(blittable->size().width(),blittable->size().height()); | - | ||||||||||||
83 | m_blittable.reset(blittable); | - | ||||||||||||
84 | } never executed: end of block | 0 | ||||||||||||
85 | - | |||||||||||||
86 | void QBlittablePlatformPixmap::resize(int width, int height) | - | ||||||||||||
87 | { | - | ||||||||||||
88 | m_blittable.reset(0); | - | ||||||||||||
89 | m_engine.reset(0); | - | ||||||||||||
90 | d = QGuiApplication::primaryScreen()->depth(); | - | ||||||||||||
91 | w = width; | - | ||||||||||||
92 | h = height; | - | ||||||||||||
93 | is_null = (w <= 0 || h <= 0);
| 0 | ||||||||||||
94 | setSerialNumber(++global_ser_no); | - | ||||||||||||
95 | } never executed: end of block | 0 | ||||||||||||
96 | - | |||||||||||||
97 | int QBlittablePlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric) const | - | ||||||||||||
98 | { | - | ||||||||||||
99 | switch (metric) { | - | ||||||||||||
100 | case QPaintDevice::PdmWidth: never executed: case QPaintDevice::PdmWidth: | 0 | ||||||||||||
101 | return w; never executed: return w; | 0 | ||||||||||||
102 | case QPaintDevice::PdmHeight: never executed: case QPaintDevice::PdmHeight: | 0 | ||||||||||||
103 | return h; never executed: return h; | 0 | ||||||||||||
104 | case QPaintDevice::PdmWidthMM: never executed: case QPaintDevice::PdmWidthMM: | 0 | ||||||||||||
105 | return qRound(w * 25.4 / qt_defaultDpiX()); never executed: return qRound(w * 25.4 / qt_defaultDpiX()); | 0 | ||||||||||||
106 | case QPaintDevice::PdmHeightMM: never executed: case QPaintDevice::PdmHeightMM: | 0 | ||||||||||||
107 | return qRound(h * 25.4 / qt_defaultDpiY()); never executed: return qRound(h * 25.4 / qt_defaultDpiY()); | 0 | ||||||||||||
108 | case QPaintDevice::PdmDepth: never executed: case QPaintDevice::PdmDepth: | 0 | ||||||||||||
109 | return 32; never executed: return 32; | 0 | ||||||||||||
110 | case QPaintDevice::PdmDpiX: // fall-through never executed: case QPaintDevice::PdmDpiX: | 0 | ||||||||||||
111 | case QPaintDevice::PdmPhysicalDpiX: never executed: case QPaintDevice::PdmPhysicalDpiX: | 0 | ||||||||||||
112 | return qt_defaultDpiX(); never executed: return qt_defaultDpiX(); | 0 | ||||||||||||
113 | case QPaintDevice::PdmDpiY: // fall-through never executed: case QPaintDevice::PdmDpiY: | 0 | ||||||||||||
114 | case QPaintDevice::PdmPhysicalDpiY: never executed: case QPaintDevice::PdmPhysicalDpiY: | 0 | ||||||||||||
115 | return qt_defaultDpiY(); never executed: return qt_defaultDpiY(); | 0 | ||||||||||||
116 | case QPaintDevice::PdmDevicePixelRatio: never executed: case QPaintDevice::PdmDevicePixelRatio: | 0 | ||||||||||||
117 | return devicePixelRatio(); never executed: return devicePixelRatio(); | 0 | ||||||||||||
118 | case QPaintDevice::PdmDevicePixelRatioScaled: never executed: case QPaintDevice::PdmDevicePixelRatioScaled: | 0 | ||||||||||||
119 | return devicePixelRatio() * QPaintDevice::devicePixelRatioFScale(); never executed: return devicePixelRatio() * QPaintDevice::devicePixelRatioFScale(); | 0 | ||||||||||||
120 | default: never executed: default: | 0 | ||||||||||||
121 | qWarning("QRasterPlatformPixmap::metric(): Unhandled metric type %d", metric); | - | ||||||||||||
122 | break; never executed: break; | 0 | ||||||||||||
123 | } | - | ||||||||||||
124 | - | |||||||||||||
125 | return 0; never executed: return 0; | 0 | ||||||||||||
126 | } | - | ||||||||||||
127 | - | |||||||||||||
128 | void QBlittablePlatformPixmap::fill(const QColor &color) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | if (blittable()->capabilities() & QBlittable::AlphaFillRectCapability) {
| 0 | ||||||||||||
131 | blittable()->unlock(); | - | ||||||||||||
132 | blittable()->alphaFillRect(QRectF(0,0,w,h),color,QPainter::CompositionMode_Source); | - | ||||||||||||
133 | } else if (color.alpha() == 255 && blittable()->capabilities() & QBlittable::SolidRectCapability) { never executed: end of block
| 0 | ||||||||||||
134 | blittable()->unlock(); | - | ||||||||||||
135 | blittable()->fillRect(QRectF(0,0,w,h),color); | - | ||||||||||||
136 | } else { never executed: end of block | 0 | ||||||||||||
137 | // Need to be backed with an alpha channel now. It would be nice | - | ||||||||||||
138 | // if we could just change the format, e.g. when going from | - | ||||||||||||
139 | // RGB32 -> ARGB8888. | - | ||||||||||||
140 | if (color.alpha() != 255 && !hasAlphaChannel()) {
| 0 | ||||||||||||
141 | m_blittable.reset(0); | - | ||||||||||||
142 | m_engine.reset(0); | - | ||||||||||||
143 | m_alpha = true; | - | ||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||
145 | - | |||||||||||||
146 | uint pixel = qPremultiply(color.rgba()); | - | ||||||||||||
147 | const QPixelLayout *layout = &qPixelLayouts[blittable()->lock()->format()]; | - | ||||||||||||
148 | Q_ASSERT(layout->convertFromARGB32PM); | - | ||||||||||||
149 | layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0); | - | ||||||||||||
150 | - | |||||||||||||
151 | //so premultiplied formats are supported and ARGB32 and RGB32 | - | ||||||||||||
152 | blittable()->lock()->fill(pixel); | - | ||||||||||||
153 | } never executed: end of block | 0 | ||||||||||||
154 | - | |||||||||||||
155 | } | - | ||||||||||||
156 | - | |||||||||||||
157 | QImage *QBlittablePlatformPixmap::buffer() | - | ||||||||||||
158 | { | - | ||||||||||||
159 | return blittable()->lock(); never executed: return blittable()->lock(); | 0 | ||||||||||||
160 | } | - | ||||||||||||
161 | - | |||||||||||||
162 | QImage QBlittablePlatformPixmap::toImage() const | - | ||||||||||||
163 | { | - | ||||||||||||
164 | return blittable()->lock()->copy(); never executed: return blittable()->lock()->copy(); | 0 | ||||||||||||
165 | } | - | ||||||||||||
166 | - | |||||||||||||
167 | bool QBlittablePlatformPixmap::hasAlphaChannel() const | - | ||||||||||||
168 | { | - | ||||||||||||
169 | return blittable()->lock()->hasAlphaChannel(); never executed: return blittable()->lock()->hasAlphaChannel(); | 0 | ||||||||||||
170 | } | - | ||||||||||||
171 | - | |||||||||||||
172 | void QBlittablePlatformPixmap::fromImage(const QImage &image, | - | ||||||||||||
173 | Qt::ImageConversionFlags flags) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | m_alpha = image.hasAlphaChannel(); | - | ||||||||||||
176 | m_devicePixelRatio = image.devicePixelRatio(); | - | ||||||||||||
177 | resize(image.width(),image.height()); | - | ||||||||||||
178 | markRasterOverlay(QRect(0,0,w,h)); | - | ||||||||||||
179 | QImage *thisImg = buffer(); | - | ||||||||||||
180 | - | |||||||||||||
181 | QImage correctFormatPic = image; | - | ||||||||||||
182 | if (correctFormatPic.format() != thisImg->format())
| 0 | ||||||||||||
183 | correctFormatPic = correctFormatPic.convertToFormat(thisImg->format(), flags); never executed: correctFormatPic = correctFormatPic.convertToFormat(thisImg->format(), flags); | 0 | ||||||||||||
184 | - | |||||||||||||
185 | uchar *mem = thisImg->bits(); | - | ||||||||||||
186 | const uchar *bits = correctFormatPic.constBits(); | - | ||||||||||||
187 | int bytesCopied = 0; | - | ||||||||||||
188 | while (bytesCopied < correctFormatPic.byteCount()) {
| 0 | ||||||||||||
189 | memcpy(mem,bits,correctFormatPic.bytesPerLine()); | - | ||||||||||||
190 | mem += thisImg->bytesPerLine(); | - | ||||||||||||
191 | bits += correctFormatPic.bytesPerLine(); | - | ||||||||||||
192 | bytesCopied+=correctFormatPic.bytesPerLine(); | - | ||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||
194 | } never executed: end of block | 0 | ||||||||||||
195 | - | |||||||||||||
196 | qreal QBlittablePlatformPixmap::devicePixelRatio() const | - | ||||||||||||
197 | { | - | ||||||||||||
198 | return m_devicePixelRatio; never executed: return m_devicePixelRatio; | 0 | ||||||||||||
199 | } | - | ||||||||||||
200 | - | |||||||||||||
201 | void QBlittablePlatformPixmap::setDevicePixelRatio(qreal scaleFactor) | - | ||||||||||||
202 | { | - | ||||||||||||
203 | m_devicePixelRatio = scaleFactor; | - | ||||||||||||
204 | } never executed: end of block | 0 | ||||||||||||
205 | - | |||||||||||||
206 | QPaintEngine *QBlittablePlatformPixmap::paintEngine() const | - | ||||||||||||
207 | { | - | ||||||||||||
208 | if (!m_engine) {
| 0 | ||||||||||||
209 | QBlittablePlatformPixmap *that = const_cast<QBlittablePlatformPixmap *>(this); | - | ||||||||||||
210 | that->m_engine.reset(new QBlitterPaintEngine(that)); | - | ||||||||||||
211 | } never executed: end of block | 0 | ||||||||||||
212 | return m_engine.data(); never executed: return m_engine.data(); | 0 | ||||||||||||
213 | } | - | ||||||||||||
214 | - | |||||||||||||
215 | #ifdef QT_BLITTER_RASTEROVERLAY | - | ||||||||||||
216 | - | |||||||||||||
217 | static bool showRasterOverlay = !qEnvironmentVariableIsEmpty("QT_BLITTER_RASTEROVERLAY"); | - | ||||||||||||
218 | - | |||||||||||||
219 | void QBlittablePlatformPixmap::mergeOverlay() | - | ||||||||||||
220 | { | - | ||||||||||||
221 | if (m_unmergedCopy || !showRasterOverlay) | - | ||||||||||||
222 | return; | - | ||||||||||||
223 | m_unmergedCopy = new QImage(buffer()->copy()); | - | ||||||||||||
224 | QPainter p(buffer()); | - | ||||||||||||
225 | p.setCompositionMode(QPainter::CompositionMode_SourceOver); | - | ||||||||||||
226 | p.drawImage(0,0,*overlay()); | - | ||||||||||||
227 | p.end(); | - | ||||||||||||
228 | } | - | ||||||||||||
229 | - | |||||||||||||
230 | void QBlittablePlatformPixmap::unmergeOverlay() | - | ||||||||||||
231 | { | - | ||||||||||||
232 | if (!m_unmergedCopy || !showRasterOverlay) | - | ||||||||||||
233 | return; | - | ||||||||||||
234 | QPainter p(buffer()); | - | ||||||||||||
235 | p.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||
236 | p.drawImage(0,0,*m_unmergedCopy); | - | ||||||||||||
237 | p.end(); | - | ||||||||||||
238 | - | |||||||||||||
239 | delete m_unmergedCopy; | - | ||||||||||||
240 | m_unmergedCopy = 0; | - | ||||||||||||
241 | } | - | ||||||||||||
242 | - | |||||||||||||
243 | QImage *QBlittablePlatformPixmap::overlay() | - | ||||||||||||
244 | { | - | ||||||||||||
245 | if (!m_rasterOverlay|| | - | ||||||||||||
246 | m_rasterOverlay->size() != QSize(w,h)){ | - | ||||||||||||
247 | m_rasterOverlay = new QImage(w,h,QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||
248 | m_rasterOverlay->fill(0x00000000); | - | ||||||||||||
249 | uint color = (qrand() % 11)+7; | - | ||||||||||||
250 | m_overlayColor = QColor(Qt::GlobalColor(color)); | - | ||||||||||||
251 | m_overlayColor.setAlpha(0x88); | - | ||||||||||||
252 | - | |||||||||||||
253 | } | - | ||||||||||||
254 | return m_rasterOverlay; | - | ||||||||||||
255 | } | - | ||||||||||||
256 | - | |||||||||||||
257 | void QBlittablePlatformPixmap::markRasterOverlayImpl(const QRectF &rect) | - | ||||||||||||
258 | { | - | ||||||||||||
259 | if (!showRasterOverlay) | - | ||||||||||||
260 | return; | - | ||||||||||||
261 | QRectF transformationRect = clipAndTransformRect(rect); | - | ||||||||||||
262 | if(!transformationRect.isEmpty()) { | - | ||||||||||||
263 | QPainter p(overlay()); | - | ||||||||||||
264 | p.setBrush(m_overlayColor); | - | ||||||||||||
265 | p.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||
266 | p.fillRect(transformationRect,QBrush(m_overlayColor)); | - | ||||||||||||
267 | } | - | ||||||||||||
268 | } | - | ||||||||||||
269 | - | |||||||||||||
270 | void QBlittablePlatformPixmap::unmarkRasterOverlayImpl(const QRectF &rect) | - | ||||||||||||
271 | { | - | ||||||||||||
272 | if (!showRasterOverlay) | - | ||||||||||||
273 | return; | - | ||||||||||||
274 | QRectF transformationRect = clipAndTransformRect(rect); | - | ||||||||||||
275 | if (!transformationRect.isEmpty()) { | - | ||||||||||||
276 | QPainter p(overlay()); | - | ||||||||||||
277 | QColor color(0x00,0x00,0x00,0x00); | - | ||||||||||||
278 | p.setBrush(color); | - | ||||||||||||
279 | p.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||
280 | p.fillRect(transformationRect,QBrush(color)); | - | ||||||||||||
281 | } | - | ||||||||||||
282 | } | - | ||||||||||||
283 | - | |||||||||||||
284 | QRectF QBlittablePlatformPixmap::clipAndTransformRect(const QRectF &rect) const | - | ||||||||||||
285 | { | - | ||||||||||||
286 | QRectF transformationRect = rect; | - | ||||||||||||
287 | paintEngine(); | - | ||||||||||||
288 | if (m_engine->state()) { | - | ||||||||||||
289 | transformationRect = m_engine->state()->matrix.mapRect(rect); | - | ||||||||||||
290 | const QClipData *clipData = m_engine->clip(); | - | ||||||||||||
291 | if (clipData) { | - | ||||||||||||
292 | if (clipData->hasRectClip) { | - | ||||||||||||
293 | transformationRect &= clipData->clipRect; | - | ||||||||||||
294 | } else if (clipData->hasRegionClip) { | - | ||||||||||||
295 | const QVector<QRect> rects = clipData->clipRegion.rects(); | - | ||||||||||||
296 | for (int i = 0; i < rects.size(); i++) { | - | ||||||||||||
297 | transformationRect &= rects.at(i); | - | ||||||||||||
298 | } | - | ||||||||||||
299 | } | - | ||||||||||||
300 | } | - | ||||||||||||
301 | } | - | ||||||||||||
302 | return transformationRect; | - | ||||||||||||
303 | } | - | ||||||||||||
304 | - | |||||||||||||
305 | #endif //QT_BLITTER_RASTEROVERLAY | - | ||||||||||||
306 | - | |||||||||||||
307 | QT_END_NAMESPACE | - | ||||||||||||
308 | - | |||||||||||||
309 | #endif //QT_NO_BLITTABLE | - | ||||||||||||
Source code | Switch to Preprocessed file |