qpixmap_blitter.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9