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