kernel/qpaintengine_alpha.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7QAlphaPaintEngine::QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps) -
8 : QPaintEngine(data, devcaps) -
9{ -
10 -
11}
never executed: }
0
12 -
13QAlphaPaintEngine::~QAlphaPaintEngine() -
14{ -
15 -
16} -
17 -
18bool QAlphaPaintEngine::begin(QPaintDevice *pdev) -
19{ -
20 QAlphaPaintEnginePrivate * const d = d_func(); -
21 -
22 d->m_continueCall = true; -
23 if (d->m_pass != 0) {
never evaluated: d->m_pass != 0
0
24 return true;
never executed: return true;
0
25 } -
26 -
27 d->m_savedcaps = gccaps; -
28 d->m_pdev = pdev; -
29 -
30 d->m_alphaPen = false; -
31 d->m_alphaBrush = false; -
32 d->m_alphaOpacity = false; -
33 d->m_hasalpha = false; -
34 d->m_advancedPen = false; -
35 d->m_advancedBrush = false; -
36 d->m_complexTransform = false; -
37 d->m_emulateProjectiveTransforms = false; -
38 -
39 -
40 d->m_alphargn = QRegion(); -
41 d->m_cliprgn = QRegion(); -
42 d->m_pen = QPen(); -
43 d->m_transform = QTransform(); -
44 -
45 flushAndInit(); -
46 -
47 return true;
never executed: return true;
0
48} -
49 -
50bool QAlphaPaintEngine::end() -
51{ -
52 QAlphaPaintEnginePrivate * const d = d_func(); -
53 -
54 d->m_continueCall = true; -
55 if (d->m_pass != 0) {
never evaluated: d->m_pass != 0
0
56 return true;
never executed: return true;
0
57 } -
58 -
59 flushAndInit(false); -
60 return true;
never executed: return true;
0
61} -
62 -
63void QAlphaPaintEngine::updateState(const QPaintEngineState &state) -
64{ -
65 QAlphaPaintEnginePrivate * const d = d_func(); -
66 -
67 DirtyFlags flags = state.state(); -
68 if (flags & QPaintEngine::DirtyTransform) {
never evaluated: flags & QPaintEngine::DirtyTransform
0
69 d->m_transform = state.transform(); -
70 d->m_complexTransform = (d->m_transform.type() > QTransform::TxScale); -
71 d->m_emulateProjectiveTransforms = !(d->m_savedcaps & QPaintEngine::PerspectiveTransform)
never evaluated: !(d->m_savedcaps & QPaintEngine::PerspectiveTransform)
0
72 && !(d->m_savedcaps & QPaintEngine::AlphaBlend)
never evaluated: !(d->m_savedcaps & QPaintEngine::AlphaBlend)
0
73 && (d->m_transform.type() >= QTransform::TxProject);
never evaluated: (d->m_transform.type() >= QTransform::TxProject)
0
74 }
never executed: }
0
75 if (flags & QPaintEngine::DirtyPen) {
never evaluated: flags & QPaintEngine::DirtyPen
0
76 d->m_pen = state.pen(); -
77 if (d->m_pen.style() == Qt::NoPen) {
never evaluated: d->m_pen.style() == Qt::NoPen
0
78 d->m_advancedPen = false; -
79 d->m_alphaPen = false; -
80 } else {
never executed: }
0
81 d->m_advancedPen = (d->m_pen.brush().style() != Qt::SolidPattern); -
82 d->m_alphaPen = !d->m_pen.brush().isOpaque(); -
83 }
never executed: }
0
84 } -
85 -
86 if (d->m_pass != 0) {
never evaluated: d->m_pass != 0
0
87 d->m_continueCall = true; -
88 return;
never executed: return;
0
89 } -
90 d->m_continueCall = false; -
91 -
92 if (flags & QPaintEngine::DirtyOpacity) {
never evaluated: flags & QPaintEngine::DirtyOpacity
0
93 d->m_alphaOpacity = (state.opacity() != 1.0f); -
94 }
never executed: }
0
95 -
96 if (flags & QPaintEngine::DirtyBrush) {
never evaluated: flags & QPaintEngine::DirtyBrush
0
97 if (state.brush().style() == Qt::NoBrush) {
never evaluated: state.brush().style() == Qt::NoBrush
0
98 d->m_advancedBrush = false; -
99 d->m_alphaBrush = false; -
100 } else {
never executed: }
0
101 d->m_advancedBrush = (state.brush().style() != Qt::SolidPattern); -
102 d->m_alphaBrush = !state.brush().isOpaque(); -
103 }
never executed: }
0
104 } -
105 -
106 -
107 d->m_hasalpha = d->m_alphaOpacity || d->m_alphaBrush || d->m_alphaPen;
never evaluated: d->m_alphaOpacity
never evaluated: d->m_alphaBrush
never evaluated: d->m_alphaPen
0
108 -
109 if (d->m_picengine)
never evaluated: d->m_picengine
0
110 d->m_picengine->updateState(state);
never executed: d->m_picengine->updateState(state);
0
111}
never executed: }
0
112 -
113void QAlphaPaintEngine::drawPath(const QPainterPath &path) -
114{ -
115 QAlphaPaintEnginePrivate * const d = d_func(); -
116 -
117 QRectF tr = d->addPenWidth(path); -
118 -
119 if (d->m_pass == 0) {
never evaluated: d->m_pass == 0
0
120 d->m_continueCall = false; -
121 if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush
never evaluated: d->m_hasalpha
never evaluated: d->m_advancedPen
never evaluated: d->m_advancedBrush
0
122 || d->m_emulateProjectiveTransforms)
never evaluated: d->m_emulateProjectiveTransforms
0
123 { -
124 d->addAlphaRect(tr); -
125 }
never executed: }
0
126 if (d->m_picengine)
never evaluated: d->m_picengine
0
127 d->m_picengine->drawPath(path);
never executed: d->m_picengine->drawPath(path);
0
128 } else {
never executed: }
0
129 d->m_continueCall = !d->fullyContained(tr); -
130 }
never executed: }
0
131} -
132 -
133void QAlphaPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) -
134{ -
135 QAlphaPaintEnginePrivate * const d = d_func(); -
136 -
137 QPolygonF poly; -
138 for (int i=0; i<pointCount; ++i)
never evaluated: i<pointCount
0
139 poly.append(points[i]);
never executed: poly.append(points[i]);
0
140 -
141 QPainterPath path; -
142 path.addPolygon(poly); -
143 QRectF tr = d->addPenWidth(path); -
144 -
145 if (d->m_pass == 0) {
never evaluated: d->m_pass == 0
0
146 d->m_continueCall = false; -
147 if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush
never evaluated: d->m_advancedPen
never evaluated: d->m_advancedBrush
never evaluated: d->m_hasalpha
0
148 || d->m_emulateProjectiveTransforms)
never evaluated: d->m_emulateProjectiveTransforms
0
149 { -
150 d->addAlphaRect(tr); -
151 }
never executed: }
0
152 -
153 if (d->m_picengine)
never evaluated: d->m_picengine
0
154 d->m_picengine->drawPolygon(points, pointCount, mode);
never executed: d->m_picengine->drawPolygon(points, pointCount, mode);
0
155 } else {
never executed: }
0
156 d->m_continueCall = !d->fullyContained(tr); -
157 }
never executed: }
0
158} -
159 -
160void QAlphaPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) -
161{ -
162 QAlphaPaintEnginePrivate * const d = d_func(); -
163 -
164 QRectF tr = d->m_transform.mapRect(r); -
165 if (d->m_pass == 0) {
never evaluated: d->m_pass == 0
0
166 d->m_continueCall = false; -
167 if (pm.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pm.isQBitmap()) {
never evaluated: pm.hasAlpha()
never evaluated: d->m_alphaOpacity
never evaluated: d->m_complexTransform
never evaluated: pm.isQBitmap()
0
168 d->addAlphaRect(tr); -
169 }
never executed: }
0
170 -
171 if (d->m_picengine)
never evaluated: d->m_picengine
0
172 d->m_picengine->drawPixmap(r, pm, sr);
never executed: d->m_picengine->drawPixmap(r, pm, sr);
0
173 -
174 } else {
never executed: }
0
175 d->m_continueCall = !d->fullyContained(tr); -
176 }
never executed: }
0
177} -
178 -
179void QAlphaPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) -
180{ -
181 QAlphaPaintEnginePrivate * const d = d_func(); -
182 -
183 QRectF tr(p.x(), p.y() - textItem.ascent(), textItem.width() + 5, textItem.ascent() + textItem.descent() + 5); -
184 tr = d->m_transform.mapRect(tr); -
185 -
186 if (d->m_pass == 0) {
never evaluated: d->m_pass == 0
0
187 d->m_continueCall = false; -
188 if (d->m_alphaPen || d->m_alphaOpacity || d->m_advancedPen) {
never evaluated: d->m_alphaPen
never evaluated: d->m_alphaOpacity
never evaluated: d->m_advancedPen
0
189 d->addAlphaRect(tr); -
190 }
never executed: }
0
191 if (d->m_picengine) {
never evaluated: d->m_picengine
0
192 d->m_picengine->drawTextItem(p, textItem); -
193 }
never executed: }
0
194 } else {
never executed: }
0
195 d->m_continueCall = !d->fullyContained(tr); -
196 }
never executed: }
0
197} -
198 -
199void QAlphaPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) -
200{ -
201 QAlphaPaintEnginePrivate * const d = d_func(); -
202 -
203 QRectF brect = d->m_transform.mapRect(r); -
204 -
205 if (d->m_pass == 0) {
never evaluated: d->m_pass == 0
0
206 d->m_continueCall = false; -
207 if (pixmap.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pixmap.isQBitmap()) {
never evaluated: pixmap.hasAlpha()
never evaluated: d->m_alphaOpacity
never evaluated: d->m_complexTransform
never evaluated: pixmap.isQBitmap()
0
208 d->addAlphaRect(brect); -
209 }
never executed: }
0
210 if (d->m_picengine)
never evaluated: d->m_picengine
0
211 d->m_picengine->drawTiledPixmap(r, pixmap, s);
never executed: d->m_picengine->drawTiledPixmap(r, pixmap, s);
0
212 } else {
never executed: }
0
213 d->m_continueCall = !d->fullyContained(brect); -
214 }
never executed: }
0
215} -
216 -
217QRegion QAlphaPaintEngine::alphaClipping() const -
218{ -
219 const QAlphaPaintEnginePrivate * const d = d_func(); -
220 return d->m_cliprgn;
never executed: return d->m_cliprgn;
0
221} -
222 -
223bool QAlphaPaintEngine::continueCall() const -
224{ -
225 const QAlphaPaintEnginePrivate * const d = d_func(); -
226 return d->m_continueCall;
never executed: return d->m_continueCall;
0
227} -
228 -
229void QAlphaPaintEngine::flushAndInit(bool init) -
230{ -
231 QAlphaPaintEnginePrivate * const d = d_func(); -
232 qt_noop(); -
233 -
234 if (d->m_pic) {
never evaluated: d->m_pic
0
235 d->m_picpainter->end(); -
236 -
237 -
238 d->m_alphargn = d->m_alphargn.intersected(QRect(0, 0, d->m_pdev->width(), d->m_pdev->height())); -
239 -
240 -
241 QVector<QRect> rects = d->m_alphargn.rects(); -
242 if (rects.size() > 10) {
never evaluated: rects.size() > 10
0
243 QRect br = d->m_alphargn.boundingRect(); -
244 d->m_alphargn = QRegion(br); -
245 rects.clear(); -
246 rects.append(br); -
247 }
never executed: }
0
248 -
249 d->m_cliprgn = d->m_alphargn; -
250 -
251 -
252 ++d->m_pass; -
253 -
254 -
255 gccaps = d->m_savedcaps; -
256 -
257 painter()->save(); -
258 d->resetState(painter()); -
259 -
260 -
261 QTransform mtx; -
262 mtx.scale(1.0f / (qreal(d->m_pdev->logicalDpiX()) / qreal(qt_defaultDpiX())), -
263 1.0f / (qreal(d->m_pdev->logicalDpiY()) / qreal(qt_defaultDpiY()))); -
264 painter()->setTransform(mtx); -
265 painter()->drawPicture(0, 0, *d->m_pic); -
266 -
267 d->m_cliprgn = QRegion(); -
268 d->resetState(painter()); -
269 -
270 -
271 for (int i=0; i<rects.size(); ++i)
never evaluated: i<rects.size()
0
272 d->drawAlphaImage(rects.at(i));
never executed: d->drawAlphaImage(rects.at(i));
0
273 -
274 d->m_alphargn = QRegion(); -
275 -
276 painter()->restore(); -
277 -
278 --d->m_pass; -
279 -
280 cleanUp(); -
281 }
never executed: }
0
282 -
283 if (init) {
never evaluated: init
0
284 gccaps = PaintEngineFeatures(AllFeatures & ~QPaintEngine::ObjectBoundingModeGradients); -
285 -
286 d->m_pic = new QPicture(); -
287 d->m_pic->d_ptr->in_memory_only = true; -
288 d->m_picpainter = new QPainter(d->m_pic); -
289 d->m_picengine = d->m_picpainter->paintEngine(); -
290 -
291 -
292 -
293 -
294 d->m_picpainter->setPen(painter()->pen()); -
295 d->m_picpainter->setBrush(painter()->brush()); -
296 d->m_picpainter->setBrushOrigin(painter()->brushOrigin()); -
297 d->m_picpainter->setFont(painter()->font()); -
298 d->m_picpainter->setOpacity(painter()->opacity()); -
299 d->m_picpainter->setTransform(painter()->combinedTransform()); -
300 d->m_picengine->syncState(); -
301 }
never executed: }
0
302}
never executed: }
0
303 -
304void QAlphaPaintEngine::cleanUp() -
305{ -
306 QAlphaPaintEnginePrivate * const d = d_func(); -
307 -
308 delete d->m_picpainter; -
309 delete d->m_pic; -
310 -
311 d->m_picpainter = 0; -
312 d->m_pic = 0; -
313 d->m_picengine = 0; -
314}
never executed: }
0
315 -
316QAlphaPaintEnginePrivate::QAlphaPaintEnginePrivate() -
317 : m_pass(0), -
318 m_pic(0), -
319 m_picengine(0), -
320 m_picpainter(0), -
321 m_hasalpha(false), -
322 m_alphaPen(false), -
323 m_alphaBrush(false), -
324 m_alphaOpacity(false), -
325 m_advancedPen(false), -
326 m_advancedBrush(false), -
327 m_complexTransform(false) -
328{ -
329 -
330}
never executed: }
0
331 -
332QAlphaPaintEnginePrivate::~QAlphaPaintEnginePrivate() -
333{ -
334 delete m_picpainter; -
335 delete m_pic; -
336}
never executed: }
0
337 -
338QRectF QAlphaPaintEnginePrivate::addPenWidth(const QPainterPath &path) -
339{ -
340 QAlphaPaintEngine * const q = q_func(); -
341 -
342 QPainterPath tmp = path; -
343 -
344 if (m_pen.style() == Qt::NoPen)
never evaluated: m_pen.style() == Qt::NoPen
0
345 return (path.controlPointRect() * m_transform).boundingRect();
never executed: return (path.controlPointRect() * m_transform).boundingRect();
0
346 bool cosmetic = qt_pen_is_cosmetic(m_pen, q->state->renderHints()); -
347 if (cosmetic)
never evaluated: cosmetic
0
348 tmp = path * m_transform;
never executed: tmp = path * m_transform;
0
349 -
350 QPainterPathStroker stroker; -
351 if (m_pen.widthF() == 0.0f)
never evaluated: m_pen.widthF() == 0.0f
0
352 stroker.setWidth(1.0);
never executed: stroker.setWidth(1.0);
0
353 else -
354 stroker.setWidth(m_pen.widthF());
never executed: stroker.setWidth(m_pen.widthF());
0
355 stroker.setJoinStyle(m_pen.joinStyle()); -
356 stroker.setCapStyle(m_pen.capStyle()); -
357 tmp = stroker.createStroke(tmp); -
358 if (cosmetic)
never evaluated: cosmetic
0
359 return tmp.controlPointRect();
never executed: return tmp.controlPointRect();
0
360 -
361 return (tmp.controlPointRect() * m_transform).boundingRect();
never executed: return (tmp.controlPointRect() * m_transform).boundingRect();
0
362} -
363 -
364QRect QAlphaPaintEnginePrivate::toRect(const QRectF &rect) const -
365{ -
366 QRect r; -
367 r.setLeft(int(rect.left())); -
368 r.setTop(int(rect.top())); -
369 r.setRight(int(rect.right() + 1)); -
370 r.setBottom(int(rect.bottom() + 1)); -
371 return r;
never executed: return r;
0
372} -
373 -
374void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect) -
375{ -
376 m_alphargn |= toRect(rect); -
377}
never executed: }
0
378 -
379void QAlphaPaintEnginePrivate::drawAlphaImage(const QRectF &rect) -
380{ -
381 QAlphaPaintEngine * const q = q_func(); -
382 -
383 qreal dpiX = qMax(m_pdev->logicalDpiX(), 300); -
384 qreal dpiY = qMax(m_pdev->logicalDpiY(), 300); -
385 qreal xscale = (dpiX / m_pdev->logicalDpiX()); -
386 qreal yscale = (dpiY / m_pdev->logicalDpiY()); -
387 -
388 QTransform picscale; -
389 picscale.scale(xscale, yscale); -
390 -
391 const int tileSize = 2048; -
392 QSize size((int(rect.width() * xscale)), int(rect.height() * yscale)); -
393 int divw = (size.width() / tileSize); -
394 int divh = (size.height() / tileSize); -
395 divw += 1; -
396 divh += 1; -
397 -
398 int incx = int(rect.width() / divw); -
399 int incy = int(rect.height() / divh); -
400 -
401 for (int y=0; y<divh; ++y) {
never evaluated: y<divh
0
402 int ypos = int((incy * y) + rect.y()); -
403 int height = int((y == (divh - 1)) ? (rect.height() - (incy * y)) : incy) + 1; -
404 -
405 for (int x=0; x<divw; ++x) {
never evaluated: x<divw
0
406 int xpos = int((incx * x) + rect.x()); -
407 int width = int((x == (divw - 1)) ? (rect.width() - (incx * x)) : incx) + 1; -
408 -
409 QSize imgsize((int)(width * xscale), (int)(height * yscale)); -
410 QImage img(imgsize, QImage::Format_RGB32); -
411 img.fill(0xffffffff); -
412 -
413 QPainter imgpainter(&img); -
414 imgpainter.setTransform(picscale); -
415 QPointF picpos(qreal(-xpos), qreal(-ypos)); -
416 imgpainter.drawPicture(picpos, *m_pic); -
417 imgpainter.end(); -
418 -
419 q->painter()->setTransform(QTransform()); -
420 QRect r(xpos, ypos, width, height); -
421 q->painter()->drawImage(r, img); -
422 }
never executed: }
0
423 }
never executed: }
0
424}
never executed: }
0
425 -
426bool QAlphaPaintEnginePrivate::fullyContained(const QRectF &rect) const -
427{ -
428 QRegion r(toRect(rect)); -
429 return (m_cliprgn.intersected(r) == r);
never executed: return (m_cliprgn.intersected(r) == r);
0
430} -
431 -
432void QAlphaPaintEnginePrivate::resetState(QPainter *p) -
433{ -
434 p->setPen(QPen()); -
435 p->setBrush(QBrush()); -
436 p->setBrushOrigin(0,0); -
437 p->setBackground(QBrush()); -
438 p->setFont(QFont()); -
439 p->setTransform(QTransform()); -
440 -
441 -
442 -
443 p->setViewTransformEnabled(false); -
444 p->setClipRegion(QRegion(), Qt::NoClip); -
445 p->setClipPath(QPainterPath(), Qt::NoClip); -
446 p->setClipping(false); -
447 p->setOpacity(1.0f); -
448}
never executed: }
0
449 -
450 -
451 -
452 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial