author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 7 | 3f74d0d4af4c |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtCore/qglobal.h> |
|
43 |
||
44 |
#define QT_FT_BEGIN_HEADER |
|
45 |
#define QT_FT_END_HEADER |
|
46 |
||
47 |
#include <private/qrasterdefs_p.h> |
|
48 |
#include <private/qgrayraster_p.h> |
|
49 |
||
50 |
#include <qpainterpath.h> |
|
51 |
#include <qdebug.h> |
|
52 |
#include <qhash.h> |
|
53 |
#include <qlabel.h> |
|
54 |
#include <qbitmap.h> |
|
55 |
#include <qmath.h> |
|
56 |
||
57 |
#if defined (Q_WS_X11) |
|
58 |
# include <private/qfontengine_ft_p.h> |
|
59 |
#endif |
|
60 |
||
61 |
// #include <private/qdatabuffer_p.h> |
|
62 |
// #include <private/qpainter_p.h> |
|
63 |
#include <private/qmath_p.h> |
|
64 |
#include <private/qtextengine_p.h> |
|
65 |
#include <private/qfontengine_p.h> |
|
66 |
#include <private/qpixmap_raster_p.h> |
|
67 |
// #include <private/qpolygonclipper_p.h> |
|
68 |
// #include <private/qrasterizer_p.h> |
|
69 |
#include <private/qimage_p.h> |
|
70 |
||
71 |
#include "qpaintengine_raster_p.h" |
|
72 |
// #include "qbezier_p.h" |
|
73 |
#include "qoutlinemapper_p.h" |
|
74 |
||
75 |
#if defined(Q_WS_WIN) |
|
76 |
# include <qt_windows.h> |
|
77 |
# include <qvarlengtharray.h> |
|
78 |
# include <private/qfontengine_p.h> |
|
79 |
# if defined(Q_OS_WINCE) |
|
80 |
# include "qguifunctions_wince.h" |
|
81 |
# endif |
|
82 |
#elif defined(Q_WS_MAC) |
|
83 |
# include <private/qt_mac_p.h> |
|
84 |
# include <private/qpixmap_mac_p.h> |
|
85 |
# include <private/qpaintengine_mac_p.h> |
|
86 |
#elif defined(Q_WS_QWS) |
|
87 |
# if !defined(QT_NO_FREETYPE) |
|
88 |
# include <private/qfontengine_ft_p.h> |
|
89 |
# endif |
|
90 |
# if !defined(QT_NO_QWS_QPF2) |
|
91 |
# include <private/qfontengine_qpf_p.h> |
|
92 |
# endif |
|
93 |
# include <private/qabstractfontengine_p.h> |
|
94 |
#elif defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) |
|
95 |
# include <private/qfontengine_s60_p.h> |
|
96 |
#endif |
|
97 |
||
98 |
#if defined(Q_WS_WIN64) |
|
99 |
# include <malloc.h> |
|
100 |
#endif |
|
101 |
#include <limits.h> |
|
102 |
||
103 |
QT_BEGIN_NAMESPACE |
|
104 |
||
105 |
extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp |
|
106 |
||
107 |
#define qreal_to_fixed_26_6(f) (int(f * 64)) |
|
108 |
#define qt_swap_int(x, y) { int tmp = (x); (x) = (y); (y) = tmp; } |
|
109 |
#define qt_swap_qreal(x, y) { qreal tmp = (x); (x) = (y); (y) = tmp; } |
|
110 |
||
111 |
// #define QT_DEBUG_DRAW |
|
112 |
#ifdef QT_DEBUG_DRAW |
|
113 |
void dumpClip(int width, int height, const QClipData *clip); |
|
114 |
#endif |
|
115 |
||
116 |
#define QT_FAST_SPANS |
|
117 |
||
118 |
||
119 |
// A little helper macro to get a better approximation of dimensions. |
|
120 |
// If we have a rect that starting at 0.5 of width 3.5 it should span |
|
121 |
// 4 pixels. |
|
122 |
#define int_dim(pos, dim) (int(pos+dim) - int(pos)) |
|
123 |
||
124 |
// use the same rounding as in qrasterizer.cpp (6 bit fixed point) |
|
125 |
static const qreal aliasedCoordinateDelta = 0.5 - 0.015625; |
|
126 |
||
127 |
#ifdef Q_WS_WIN |
|
128 |
extern bool qt_cleartype_enabled; |
|
129 |
#endif |
|
130 |
||
131 |
#ifdef Q_WS_MAC |
|
132 |
extern bool qt_applefontsmoothing_enabled; |
|
133 |
#endif |
|
134 |
||
135 |
||
136 |
/******************************************************************************** |
|
137 |
* Span functions |
|
138 |
*/ |
|
139 |
static void qt_span_fill_clipRect(int count, const QSpan *spans, void *userData); |
|
140 |
static void qt_span_fill_clipped(int count, const QSpan *spans, void *userData); |
|
141 |
static void qt_span_clip(int count, const QSpan *spans, void *userData); |
|
142 |
static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *result); |
|
143 |
||
144 |
struct ClipData |
|
145 |
{ |
|
146 |
QClipData *oldClip; |
|
147 |
QClipData *newClip; |
|
148 |
Qt::ClipOperation operation; |
|
149 |
}; |
|
150 |
||
151 |
enum LineDrawMode { |
|
152 |
LineDrawClipped, |
|
153 |
LineDrawNormal, |
|
154 |
LineDrawIncludeLastPixel |
|
155 |
}; |
|
156 |
||
157 |
static void drawLine_midpoint_i(int x1, int y1, int x2, int y2, ProcessSpans span_func, QSpanData *data, |
|
158 |
LineDrawMode style, const QIntRect &rect); |
|
159 |
static void drawLine_midpoint_dashed_i(int x1, int y1, int x2, int y2, |
|
160 |
QPen *pen, ProcessSpans span_func, QSpanData *data, |
|
161 |
LineDrawMode style, const QIntRect &devRect, |
|
162 |
int *patternOffset); |
|
163 |
// static void drawLine_midpoint_f(qreal x1, qreal y1, qreal x2, qreal y2, |
|
164 |
// ProcessSpans span_func, QSpanData *data, |
|
165 |
// LineDrawMode style, const QRect &devRect); |
|
166 |
||
167 |
static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip, |
|
168 |
ProcessSpans pen_func, ProcessSpans brush_func, |
|
169 |
QSpanData *pen_data, QSpanData *brush_data); |
|
170 |
||
171 |
struct QRasterFloatPoint { |
|
172 |
qreal x; |
|
173 |
qreal y; |
|
174 |
}; |
|
175 |
||
176 |
#ifdef QT_DEBUG_DRAW |
|
177 |
static const QRectF boundingRect(const QPointF *points, int pointCount) |
|
178 |
{ |
|
179 |
const QPointF *e = points; |
|
180 |
const QPointF *last = points + pointCount; |
|
181 |
qreal minx, maxx, miny, maxy; |
|
182 |
minx = maxx = e->x(); |
|
183 |
miny = maxy = e->y(); |
|
184 |
while (++e < last) { |
|
185 |
if (e->x() < minx) |
|
186 |
minx = e->x(); |
|
187 |
else if (e->x() > maxx) |
|
188 |
maxx = e->x(); |
|
189 |
if (e->y() < miny) |
|
190 |
miny = e->y(); |
|
191 |
else if (e->y() > maxy) |
|
192 |
maxy = e->y(); |
|
193 |
} |
|
194 |
return QRectF(QPointF(minx, miny), QPointF(maxx, maxy)); |
|
195 |
} |
|
196 |
#endif |
|
197 |
||
198 |
template <typename T> static inline bool isRect(const T *pts, int elementCount) { |
|
199 |
return (elementCount == 5 // 5-point polygon, check for closed rect |
|
200 |
&& pts[0] == pts[8] && pts[1] == pts[9] // last point == first point |
|
201 |
&& pts[0] == pts[6] && pts[2] == pts[4] // x values equal |
|
202 |
&& pts[1] == pts[3] && pts[5] == pts[7] // y values equal... |
|
203 |
&& pts[0] < pts[4] && pts[1] < pts[5] |
|
204 |
) || |
|
205 |
(elementCount == 4 // 4-point polygon, check for unclosed rect |
|
206 |
&& pts[0] == pts[6] && pts[2] == pts[4] // x values equal |
|
207 |
&& pts[1] == pts[3] && pts[5] == pts[7] // y values equal... |
|
208 |
&& pts[0] < pts[4] && pts[1] < pts[5] |
|
209 |
); |
|
210 |
} |
|
211 |
||
212 |
||
213 |
static void qt_ft_outline_move_to(qfixed x, qfixed y, void *data) |
|
214 |
{ |
|
215 |
((QOutlineMapper *) data)->moveTo(QPointF(qt_fixed_to_real(x), qt_fixed_to_real(y))); |
|
216 |
} |
|
217 |
||
218 |
static void qt_ft_outline_line_to(qfixed x, qfixed y, void *data) |
|
219 |
{ |
|
220 |
((QOutlineMapper *) data)->lineTo(QPointF(qt_fixed_to_real(x), qt_fixed_to_real(y))); |
|
221 |
} |
|
222 |
||
223 |
static void qt_ft_outline_cubic_to(qfixed c1x, qfixed c1y, |
|
224 |
qfixed c2x, qfixed c2y, |
|
225 |
qfixed ex, qfixed ey, |
|
226 |
void *data) |
|
227 |
{ |
|
228 |
((QOutlineMapper *) data)->curveTo(QPointF(qt_fixed_to_real(c1x), qt_fixed_to_real(c1y)), |
|
229 |
QPointF(qt_fixed_to_real(c2x), qt_fixed_to_real(c2y)), |
|
230 |
QPointF(qt_fixed_to_real(ex), qt_fixed_to_real(ey))); |
|
231 |
} |
|
232 |
||
233 |
||
234 |
#if !defined(QT_NO_DEBUG) && 0 |
|
235 |
static void qt_debug_path(const QPainterPath &path) |
|
236 |
{ |
|
237 |
const char *names[] = { |
|
238 |
"MoveTo ", |
|
239 |
"LineTo ", |
|
240 |
"CurveTo ", |
|
241 |
"CurveToData" |
|
242 |
}; |
|
243 |
||
244 |
fprintf(stderr,"\nQPainterPath: elementCount=%d\n", path.elementCount()); |
|
245 |
for (int i=0; i<path.elementCount(); ++i) { |
|
246 |
const QPainterPath::Element &e = path.elementAt(i); |
|
247 |
Q_ASSERT(e.type >= 0 && e.type <= QPainterPath::CurveToDataElement); |
|
248 |
fprintf(stderr," - %3d:: %s, (%.2f, %.2f)\n", i, names[e.type], e.x, e.y); |
|
249 |
} |
|
250 |
} |
|
251 |
#endif |
|
252 |
||
253 |
||
254 |
||
255 |
/*! |
|
256 |
\class QRasterPaintEngine |
|
257 |
\preliminary |
|
258 |
\ingroup qws |
|
259 |
\since 4.2 |
|
260 |
||
261 |
\brief The QRasterPaintEngine class enables hardware acceleration |
|
262 |
of painting operations in Qt for Embedded Linux. |
|
263 |
||
264 |
Note that this functionality is only available in |
|
265 |
\l{Qt for Embedded Linux}. |
|
266 |
||
267 |
In \l{Qt for Embedded Linux}, painting is a pure software |
|
268 |
implementation. But starting with Qt 4.2, it is |
|
269 |
possible to add an accelerated graphics driver to take advantage |
|
270 |
of available hardware resources. |
|
271 |
||
272 |
Hardware acceleration is accomplished by creating a custom screen |
|
273 |
driver, accelerating the copying from memory to the screen, and |
|
274 |
implementing a custom paint engine accelerating the various |
|
275 |
painting operations. Then a custom paint device (derived from the |
|
276 |
QCustomRasterPaintDevice class) and a custom window surface |
|
277 |
(derived from QWSWindowSurface) must be implemented to make |
|
278 |
\l{Qt for Embedded Linux} aware of the accelerated driver. |
|
279 |
||
280 |
\note The QRasterPaintEngine class does not support 8-bit images. |
|
281 |
Instead, they need to be converted to a supported format, such as |
|
282 |
QImage::Format_ARGB32_Premultiplied. |
|
283 |
||
284 |
See the \l {Adding an Accelerated Graphics Driver to Qt for Embedded Linux} |
|
285 |
documentation for details. |
|
286 |
||
287 |
\sa QCustomRasterPaintDevice, QPaintEngine |
|
288 |
*/ |
|
289 |
||
290 |
/*! |
|
291 |
\fn Type QRasterPaintEngine::type() const |
|
292 |
\reimp |
|
293 |
*/ |
|
294 |
||
295 |
/*! |
|
296 |
\typedef QSpan |
|
297 |
\relates QRasterPaintEngine |
|
298 |
||
299 |
A struct equivalent to QT_FT_Span, containing a position (x, |
|
300 |
y), the span's length in pixels and its color/coverage (a value |
|
301 |
ranging from 0 to 255). |
|
302 |
*/ |
|
303 |
||
304 |
/*! |
|
305 |
\since 4.5 |
|
306 |
||
307 |
Creates a raster based paint engine for operating on the given |
|
308 |
\a device, with the complete set of \l |
|
309 |
{QPaintEngine::PaintEngineFeature}{paint engine features and |
|
310 |
capabilities}. |
|
311 |
*/ |
|
312 |
QRasterPaintEngine::QRasterPaintEngine(QPaintDevice *device) |
|
313 |
: QPaintEngineEx(*(new QRasterPaintEnginePrivate)) |
|
314 |
{ |
|
315 |
d_func()->device = device; |
|
316 |
init(); |
|
317 |
} |
|
318 |
||
319 |
/*! |
|
320 |
\internal |
|
321 |
*/ |
|
322 |
QRasterPaintEngine::QRasterPaintEngine(QRasterPaintEnginePrivate &dd, QPaintDevice *device) |
|
323 |
: QPaintEngineEx(dd) |
|
324 |
{ |
|
325 |
d_func()->device = device; |
|
326 |
init(); |
|
327 |
} |
|
328 |
||
329 |
void QRasterPaintEngine::init() |
|
330 |
{ |
|
331 |
Q_D(QRasterPaintEngine); |
|
332 |
||
333 |
||
334 |
#ifdef Q_WS_WIN |
|
335 |
d->hdc = 0; |
|
336 |
#endif |
|
337 |
||
338 |
d->rasterPoolSize = 8192; |
|
339 |
d->rasterPoolBase = |
|
340 |
#if defined(Q_WS_WIN64) |
|
341 |
// We make use of setjmp and longjmp in qgrayraster.c which requires |
|
342 |
// 16-byte alignment, hence we hardcode this requirement here.. |
|
343 |
(unsigned char *) _aligned_malloc(d->rasterPoolSize, sizeof(void*) * 2); |
|
344 |
#else |
|
345 |
(unsigned char *) malloc(d->rasterPoolSize); |
|
346 |
#endif |
|
347 |
Q_CHECK_PTR(d->rasterPoolBase); |
|
348 |
||
349 |
// The antialiasing raster. |
|
350 |
d->grayRaster.reset(new QT_FT_Raster); |
|
351 |
Q_CHECK_PTR(d->grayRaster.data()); |
|
352 |
if (qt_ft_grays_raster.raster_new(0, d->grayRaster.data())) |
|
353 |
QT_THROW(std::bad_alloc()); // an error creating the raster is caused by a bad malloc |
|
354 |
||
355 |
||
356 |
qt_ft_grays_raster.raster_reset(*d->grayRaster.data(), d->rasterPoolBase, d->rasterPoolSize); |
|
357 |
||
358 |
d->rasterizer.reset(new QRasterizer); |
|
359 |
d->rasterBuffer.reset(new QRasterBuffer()); |
|
360 |
d->outlineMapper.reset(new QOutlineMapper); |
|
361 |
d->outlinemapper_xform_dirty = true; |
|
362 |
||
363 |
d->basicStroker.setMoveToHook(qt_ft_outline_move_to); |
|
364 |
d->basicStroker.setLineToHook(qt_ft_outline_line_to); |
|
365 |
d->basicStroker.setCubicToHook(qt_ft_outline_cubic_to); |
|
366 |
||
367 |
d->baseClip.reset(new QClipData(d->device->height())); |
|
368 |
d->baseClip->setClipRect(QRect(0, 0, d->device->width(), d->device->height())); |
|
369 |
||
370 |
d->image_filler.init(d->rasterBuffer.data(), this); |
|
371 |
d->image_filler.type = QSpanData::Texture; |
|
372 |
||
373 |
d->image_filler_xform.init(d->rasterBuffer.data(), this); |
|
374 |
d->image_filler_xform.type = QSpanData::Texture; |
|
375 |
||
376 |
d->solid_color_filler.init(d->rasterBuffer.data(), this); |
|
377 |
d->solid_color_filler.type = QSpanData::Solid; |
|
378 |
||
379 |
d->deviceDepth = d->device->depth(); |
|
380 |
||
381 |
d->mono_surface = false; |
|
382 |
gccaps &= ~PorterDuff; |
|
383 |
||
384 |
QImage::Format format = QImage::Format_Invalid; |
|
385 |
||
386 |
switch (d->device->devType()) { |
|
387 |
case QInternal::Pixmap: |
|
388 |
qWarning("QRasterPaintEngine: unsupported for pixmaps..."); |
|
389 |
break; |
|
390 |
case QInternal::Image: |
|
391 |
format = d->rasterBuffer->prepare(static_cast<QImage *>(d->device)); |
|
392 |
break; |
|
393 |
#ifdef Q_WS_QWS |
|
394 |
case QInternal::CustomRaster: |
|
395 |
d->rasterBuffer->prepare(static_cast<QCustomRasterPaintDevice*>(d->device)); |
|
396 |
break; |
|
397 |
#endif |
|
398 |
default: |
|
399 |
qWarning("QRasterPaintEngine: unsupported target device %d\n", d->device->devType()); |
|
400 |
d->device = 0; |
|
401 |
return; |
|
402 |
} |
|
403 |
||
404 |
switch (format) { |
|
405 |
case QImage::Format_MonoLSB: |
|
406 |
case QImage::Format_Mono: |
|
407 |
d->mono_surface = true; |
|
408 |
break; |
|
409 |
case QImage::Format_ARGB8565_Premultiplied: |
|
410 |
case QImage::Format_ARGB8555_Premultiplied: |
|
411 |
case QImage::Format_ARGB6666_Premultiplied: |
|
412 |
case QImage::Format_ARGB4444_Premultiplied: |
|
413 |
case QImage::Format_ARGB32_Premultiplied: |
|
414 |
case QImage::Format_ARGB32: |
|
415 |
gccaps |= PorterDuff; |
|
416 |
break; |
|
417 |
case QImage::Format_RGB32: |
|
418 |
case QImage::Format_RGB444: |
|
419 |
case QImage::Format_RGB555: |
|
420 |
case QImage::Format_RGB666: |
|
421 |
case QImage::Format_RGB888: |
|
422 |
case QImage::Format_RGB16: |
|
423 |
break; |
|
424 |
default: |
|
425 |
break; |
|
426 |
} |
|
427 |
} |
|
428 |
||
429 |
||
430 |
||
431 |
||
432 |
/*! |
|
433 |
Destroys this paint engine. |
|
434 |
*/ |
|
435 |
QRasterPaintEngine::~QRasterPaintEngine() |
|
436 |
{ |
|
437 |
Q_D(QRasterPaintEngine); |
|
438 |
||
439 |
#if defined(Q_WS_WIN64) |
|
440 |
_aligned_free(d->rasterPoolBase); |
|
441 |
#else |
|
442 |
free(d->rasterPoolBase); |
|
443 |
#endif |
|
444 |
||
445 |
qt_ft_grays_raster.raster_done(*d->grayRaster.data()); |
|
446 |
} |
|
447 |
||
448 |
/*! |
|
449 |
\reimp |
|
450 |
*/ |
|
451 |
bool QRasterPaintEngine::begin(QPaintDevice *device) |
|
452 |
{ |
|
453 |
Q_D(QRasterPaintEngine); |
|
454 |
||
455 |
if (device->devType() == QInternal::Pixmap) { |
|
456 |
QPixmap *pixmap = static_cast<QPixmap *>(device); |
|
457 |
if (pixmap->data->classId() == QPixmapData::RasterClass) |
|
458 |
d->device = pixmap->data->buffer(); |
|
459 |
} else { |
|
460 |
d->device = device; |
|
461 |
} |
|
462 |
||
463 |
// Make sure QPaintEngine::paintDevice() returns the proper device. |
|
464 |
d->pdev = d->device; |
|
465 |
||
466 |
Q_ASSERT(d->device->devType() == QInternal::Image |
|
467 |
|| d->device->devType() == QInternal::CustomRaster); |
|
468 |
||
469 |
d->systemStateChanged(); |
|
470 |
||
471 |
QRasterPaintEngineState *s = state(); |
|
472 |
ensureOutlineMapper(); |
|
473 |
d->outlineMapper->m_clip_rect = d->deviceRect.adjusted(-10, -10, 10, 10); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
474 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
475 |
// This is the upp |
0 | 476 |
QRect bounds(-QT_RASTER_COORD_LIMIT, -QT_RASTER_COORD_LIMIT, |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
477 |
QT_RASTER_COORD_LIMIT*2 - 1, QT_RASTER_COORD_LIMIT * 2 - 1); |
0 | 478 |
d->outlineMapper->m_clip_rect = bounds.intersected(d->outlineMapper->m_clip_rect); |
479 |
||
480 |
||
481 |
d->rasterizer->setClipRect(d->deviceRect); |
|
482 |
||
483 |
s->penData.init(d->rasterBuffer.data(), this); |
|
484 |
s->penData.setup(s->pen.brush(), s->intOpacity, s->composition_mode); |
|
485 |
s->stroker = &d->basicStroker; |
|
486 |
d->basicStroker.setClipRect(d->deviceRect); |
|
487 |
||
488 |
s->brushData.init(d->rasterBuffer.data(), this); |
|
489 |
s->brushData.setup(s->brush, s->intOpacity, s->composition_mode); |
|
490 |
||
491 |
d->rasterBuffer->compositionMode = QPainter::CompositionMode_SourceOver; |
|
492 |
||
493 |
setDirty(DirtyBrushOrigin); |
|
494 |
||
495 |
#ifdef QT_DEBUG_DRAW |
|
496 |
qDebug() << "QRasterPaintEngine::begin(" << (void *) device |
|
497 |
<< ") devType:" << device->devType() |
|
498 |
<< "devRect:" << d->deviceRect; |
|
499 |
if (d->baseClip) { |
|
500 |
dumpClip(d->rasterBuffer->width(), d->rasterBuffer->height(), &*d->baseClip); |
|
501 |
} |
|
502 |
#endif |
|
503 |
||
504 |
#if defined(Q_WS_WIN) |
|
505 |
d->isPlain45DegreeRotation = true; |
|
506 |
#endif |
|
507 |
||
508 |
if (d->mono_surface) |
|
509 |
d->glyphCacheType = QFontEngineGlyphCache::Raster_Mono; |
|
510 |
#if defined(Q_WS_WIN) |
|
511 |
else if (qt_cleartype_enabled) |
|
512 |
#elif defined (Q_WS_MAC) |
|
513 |
else if (qt_applefontsmoothing_enabled) |
|
514 |
#else |
|
515 |
else if (false) |
|
516 |
#endif |
|
517 |
{ |
|
518 |
QImage::Format format = static_cast<QImage *>(d->device)->format(); |
|
519 |
if (format == QImage::Format_ARGB32_Premultiplied || format == QImage::Format_RGB32) |
|
520 |
d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask; |
|
521 |
else |
|
522 |
d->glyphCacheType = QFontEngineGlyphCache::Raster_A8; |
|
523 |
} else |
|
524 |
d->glyphCacheType = QFontEngineGlyphCache::Raster_A8; |
|
525 |
||
526 |
setActive(true); |
|
527 |
return true; |
|
528 |
} |
|
529 |
||
530 |
/*! |
|
531 |
\reimp |
|
532 |
*/ |
|
533 |
bool QRasterPaintEngine::end() |
|
534 |
{ |
|
535 |
#ifdef QT_DEBUG_DRAW |
|
536 |
Q_D(QRasterPaintEngine); |
|
537 |
qDebug() << "QRasterPaintEngine::end devRect:" << d->deviceRect; |
|
538 |
if (d->baseClip) { |
|
539 |
dumpClip(d->rasterBuffer->width(), d->rasterBuffer->height(), &*d->baseClip); |
|
540 |
} |
|
541 |
#endif |
|
542 |
||
543 |
return true; |
|
544 |
} |
|
545 |
||
546 |
/*! |
|
547 |
\internal |
|
548 |
*/ |
|
549 |
void QRasterPaintEngine::releaseBuffer() |
|
550 |
{ |
|
551 |
Q_D(QRasterPaintEngine); |
|
552 |
d->rasterBuffer.reset(new QRasterBuffer); |
|
553 |
} |
|
554 |
||
555 |
/*! |
|
556 |
\internal |
|
557 |
*/ |
|
558 |
QSize QRasterPaintEngine::size() const |
|
559 |
{ |
|
560 |
Q_D(const QRasterPaintEngine); |
|
561 |
return QSize(d->rasterBuffer->width(), d->rasterBuffer->height()); |
|
562 |
} |
|
563 |
||
564 |
/*! |
|
565 |
\internal |
|
566 |
*/ |
|
567 |
#ifndef QT_NO_DEBUG |
|
568 |
void QRasterPaintEngine::saveBuffer(const QString &s) const |
|
569 |
{ |
|
570 |
Q_D(const QRasterPaintEngine); |
|
571 |
d->rasterBuffer->bufferImage().save(s, "PNG"); |
|
572 |
} |
|
573 |
#endif |
|
574 |
||
575 |
/*! |
|
576 |
\internal |
|
577 |
*/ |
|
578 |
void QRasterPaintEngine::updateMatrix(const QTransform &matrix) |
|
579 |
{ |
|
580 |
QRasterPaintEngineState *s = state(); |
|
581 |
// FALCON: get rid of this line, see drawImage call below. |
|
582 |
s->matrix = matrix; |
|
583 |
QTransform::TransformationType txop = s->matrix.type(); |
|
584 |
||
585 |
switch (txop) { |
|
586 |
||
587 |
case QTransform::TxNone: |
|
588 |
s->flags.int_xform = true; |
|
589 |
break; |
|
590 |
||
591 |
case QTransform::TxTranslate: |
|
592 |
s->flags.int_xform = qreal(int(s->matrix.dx())) == s->matrix.dx() |
|
593 |
&& qreal(int(s->matrix.dy())) == s->matrix.dy(); |
|
594 |
break; |
|
595 |
||
596 |
case QTransform::TxScale: |
|
597 |
s->flags.int_xform = qreal(int(s->matrix.dx())) == s->matrix.dx() |
|
598 |
&& qreal(int(s->matrix.dy())) == s->matrix.dy() |
|
599 |
&& qreal(int(s->matrix.m11())) == s->matrix.m11() |
|
600 |
&& qreal(int(s->matrix.m22())) == s->matrix.m22(); |
|
601 |
break; |
|
602 |
||
603 |
default: // shear / perspective... |
|
604 |
s->flags.int_xform = false; |
|
605 |
break; |
|
606 |
} |
|
607 |
||
608 |
s->flags.tx_noshear = qt_scaleForTransform(s->matrix, &s->txscale); |
|
609 |
||
610 |
ensureOutlineMapper(); |
|
611 |
||
612 |
#ifdef Q_WS_WIN |
|
613 |
Q_D(QRasterPaintEngine); |
|
614 |
d->isPlain45DegreeRotation = false; |
|
615 |
if (txop >= QTransform::TxRotate) { |
|
616 |
d->isPlain45DegreeRotation = |
|
617 |
(qFuzzyIsNull(matrix.m11()) |
|
618 |
&& qFuzzyIsNull(matrix.m12() - qreal(1)) |
|
619 |
&& qFuzzyIsNull(matrix.m21() + qreal(1)) |
|
620 |
&& qFuzzyIsNull(matrix.m22()) |
|
621 |
) |
|
622 |
|| |
|
623 |
(qFuzzyIsNull(matrix.m11() + qreal(1)) |
|
624 |
&& qFuzzyIsNull(matrix.m12()) |
|
625 |
&& qFuzzyIsNull(matrix.m21()) |
|
626 |
&& qFuzzyIsNull(matrix.m22() + qreal(1)) |
|
627 |
) |
|
628 |
|| |
|
629 |
(qFuzzyIsNull(matrix.m11()) |
|
630 |
&& qFuzzyIsNull(matrix.m12() + qreal(1)) |
|
631 |
&& qFuzzyIsNull(matrix.m21() - qreal(1)) |
|
632 |
&& qFuzzyIsNull(matrix.m22()) |
|
633 |
) |
|
634 |
; |
|
635 |
} |
|
636 |
#endif |
|
637 |
||
638 |
} |
|
639 |
||
640 |
||
641 |
||
642 |
QRasterPaintEngineState::~QRasterPaintEngineState() |
|
643 |
{ |
|
644 |
if (flags.has_clip_ownership) |
|
645 |
delete clip; |
|
646 |
} |
|
647 |
||
648 |
||
649 |
QRasterPaintEngineState::QRasterPaintEngineState() |
|
650 |
{ |
|
651 |
stroker = 0; |
|
652 |
||
653 |
fillFlags = 0; |
|
654 |
strokeFlags = 0; |
|
655 |
pixmapFlags = 0; |
|
656 |
||
657 |
intOpacity = 256; |
|
658 |
||
659 |
txscale = 1.; |
|
660 |
||
661 |
flags.fast_pen = true; |
|
662 |
flags.antialiased = false; |
|
663 |
flags.bilinear = false; |
|
664 |
flags.fast_text = true; |
|
665 |
flags.int_xform = true; |
|
666 |
flags.tx_noshear = true; |
|
667 |
flags.fast_images = true; |
|
668 |
||
669 |
clip = 0; |
|
670 |
flags.has_clip_ownership = false; |
|
671 |
||
672 |
dirty = 0; |
|
673 |
} |
|
674 |
||
675 |
QRasterPaintEngineState::QRasterPaintEngineState(QRasterPaintEngineState &s) |
|
676 |
: QPainterState(s) |
|
677 |
{ |
|
678 |
stroker = s.stroker; |
|
679 |
||
680 |
lastBrush = s.lastBrush; |
|
681 |
brushData = s.brushData; |
|
682 |
brushData.tempImage = 0; |
|
683 |
||
684 |
lastPen = s.lastPen; |
|
685 |
penData = s.penData; |
|
686 |
penData.tempImage = 0; |
|
687 |
||
688 |
fillFlags = s.fillFlags; |
|
689 |
strokeFlags = s.strokeFlags; |
|
690 |
pixmapFlags = s.pixmapFlags; |
|
691 |
||
692 |
intOpacity = s.intOpacity; |
|
693 |
||
694 |
txscale = s.txscale; |
|
695 |
||
696 |
flag_bits = s.flag_bits; |
|
697 |
||
698 |
clip = s.clip; |
|
699 |
flags.has_clip_ownership = false; |
|
700 |
||
701 |
dirty = s.dirty; |
|
702 |
} |
|
703 |
||
704 |
/*! |
|
705 |
\internal |
|
706 |
*/ |
|
707 |
QPainterState *QRasterPaintEngine::createState(QPainterState *orig) const |
|
708 |
{ |
|
709 |
QRasterPaintEngineState *s; |
|
710 |
if (!orig) |
|
711 |
s = new QRasterPaintEngineState(); |
|
712 |
else |
|
713 |
s = new QRasterPaintEngineState(*static_cast<QRasterPaintEngineState *>(orig)); |
|
714 |
||
715 |
return s; |
|
716 |
} |
|
717 |
||
718 |
/*! |
|
719 |
\internal |
|
720 |
*/ |
|
721 |
void QRasterPaintEngine::setState(QPainterState *s) |
|
722 |
{ |
|
723 |
Q_D(QRasterPaintEngine); |
|
724 |
QPaintEngineEx::setState(s); |
|
725 |
d->rasterBuffer->compositionMode = s->composition_mode; |
|
726 |
} |
|
727 |
||
728 |
/*! |
|
729 |
\fn QRasterPaintEngineState *QRasterPaintEngine::state() |
|
730 |
\internal |
|
731 |
*/ |
|
732 |
||
733 |
/*! |
|
734 |
\fn const QRasterPaintEngineState *QRasterPaintEngine::state() const |
|
735 |
\internal |
|
736 |
*/ |
|
737 |
||
738 |
/*! |
|
739 |
\internal |
|
740 |
*/ |
|
741 |
void QRasterPaintEngine::penChanged() |
|
742 |
{ |
|
743 |
#ifdef QT_DEBUG_DRAW |
|
744 |
qDebug() << "QRasterPaintEngine::penChanged():" << state()->pen; |
|
745 |
#endif |
|
746 |
QRasterPaintEngineState *s = state(); |
|
747 |
s->strokeFlags |= DirtyPen; |
|
748 |
s->dirty |= DirtyPen; |
|
749 |
} |
|
750 |
||
751 |
/*! |
|
752 |
\internal |
|
753 |
*/ |
|
754 |
void QRasterPaintEngine::updatePen(const QPen &pen) |
|
755 |
{ |
|
756 |
Q_D(QRasterPaintEngine); |
|
757 |
QRasterPaintEngineState *s = state(); |
|
758 |
#ifdef QT_DEBUG_DRAW |
|
759 |
qDebug() << "QRasterPaintEngine::updatePen():" << s->pen; |
|
760 |
#endif |
|
761 |
||
762 |
Qt::PenStyle pen_style = qpen_style(pen); |
|
763 |
||
764 |
s->lastPen = pen; |
|
765 |
s->strokeFlags = 0; |
|
766 |
||
767 |
s->penData.clip = d->clip(); |
|
768 |
s->penData.setup(pen_style == Qt::NoPen ? QBrush() : pen.brush(), s->intOpacity, s->composition_mode); |
|
769 |
||
770 |
if (s->strokeFlags & QRasterPaintEngine::DirtyTransform |
|
771 |
|| pen.brush().transform().type() >= QTransform::TxNone) { |
|
772 |
d->updateMatrixData(&s->penData, pen.brush(), s->matrix); |
|
773 |
} |
|
774 |
||
775 |
// Slightly ugly handling of an uncommon case... We need to change |
|
776 |
// the pen because it is reused in draw_midpoint to decide dashed |
|
777 |
// or non-dashed. |
|
778 |
if (pen_style == Qt::CustomDashLine && pen.dashPattern().size() == 0) { |
|
779 |
pen_style = Qt::SolidLine; |
|
780 |
s->lastPen.setStyle(Qt::SolidLine); |
|
781 |
} |
|
782 |
||
783 |
d->basicStroker.setJoinStyle(qpen_joinStyle(pen)); |
|
784 |
d->basicStroker.setCapStyle(qpen_capStyle(pen)); |
|
785 |
d->basicStroker.setMiterLimit(pen.miterLimit()); |
|
786 |
||
787 |
qreal penWidth = qpen_widthf(pen); |
|
788 |
if (penWidth == 0) |
|
789 |
d->basicStroker.setStrokeWidth(1); |
|
790 |
else |
|
791 |
d->basicStroker.setStrokeWidth(penWidth); |
|
792 |
||
793 |
if(pen_style == Qt::SolidLine) { |
|
794 |
s->stroker = &d->basicStroker; |
|
795 |
} else if (pen_style != Qt::NoPen) { |
|
796 |
if (!d->dashStroker) |
|
797 |
d->dashStroker.reset(new QDashStroker(&d->basicStroker)); |
|
798 |
if (pen.isCosmetic()) { |
|
799 |
d->dashStroker->setClipRect(d->deviceRect); |
|
800 |
} else { |
|
801 |
// ### I've seen this inverted devrect multiple places now... |
|
802 |
QRectF clipRect = s->matrix.inverted().mapRect(QRectF(d->deviceRect)); |
|
803 |
d->dashStroker->setClipRect(clipRect); |
|
804 |
} |
|
805 |
d->dashStroker->setDashPattern(pen.dashPattern()); |
|
806 |
d->dashStroker->setDashOffset(pen.dashOffset()); |
|
807 |
s->stroker = d->dashStroker.data(); |
|
808 |
} else { |
|
809 |
s->stroker = 0; |
|
810 |
} |
|
811 |
||
812 |
s->flags.fast_pen = pen_style > Qt::NoPen |
|
813 |
&& s->penData.blend |
|
814 |
&& !s->flags.antialiased |
|
815 |
&& (penWidth == 0 || (penWidth <= 1 |
|
816 |
&& (s->matrix.type() <= QTransform::TxTranslate |
|
817 |
|| pen.isCosmetic()))); |
|
818 |
||
819 |
ensureState(); // needed because of tx_noshear... |
|
820 |
s->flags.non_complex_pen = qpen_capStyle(s->lastPen) <= Qt::SquareCap && s->flags.tx_noshear; |
|
821 |
||
822 |
s->strokeFlags = 0; |
|
823 |
} |
|
824 |
||
825 |
||
826 |
||
827 |
/*! |
|
828 |
\internal |
|
829 |
*/ |
|
830 |
void QRasterPaintEngine::brushOriginChanged() |
|
831 |
{ |
|
832 |
QRasterPaintEngineState *s = state(); |
|
833 |
#ifdef QT_DEBUG_DRAW |
|
834 |
qDebug() << "QRasterPaintEngine::brushOriginChanged()" << s->brushOrigin; |
|
835 |
#endif |
|
836 |
||
837 |
s->fillFlags |= DirtyBrushOrigin; |
|
838 |
} |
|
839 |
||
840 |
||
841 |
/*! |
|
842 |
\internal |
|
843 |
*/ |
|
844 |
void QRasterPaintEngine::brushChanged() |
|
845 |
{ |
|
846 |
QRasterPaintEngineState *s = state(); |
|
847 |
#ifdef QT_DEBUG_DRAW |
|
848 |
qDebug() << "QRasterPaintEngine::brushChanged():" << s->brush; |
|
849 |
#endif |
|
850 |
s->fillFlags |= DirtyBrush; |
|
851 |
} |
|
852 |
||
853 |
||
854 |
||
855 |
||
856 |
/*! |
|
857 |
\internal |
|
858 |
*/ |
|
859 |
void QRasterPaintEngine::updateBrush(const QBrush &brush) |
|
860 |
{ |
|
861 |
#ifdef QT_DEBUG_DRAW |
|
862 |
qDebug() << "QRasterPaintEngine::updateBrush()" << brush; |
|
863 |
#endif |
|
864 |
Q_D(QRasterPaintEngine); |
|
865 |
QRasterPaintEngineState *s = state(); |
|
866 |
// must set clip prior to setup, as setup uses it... |
|
867 |
s->brushData.clip = d->clip(); |
|
868 |
s->brushData.setup(brush, s->intOpacity, s->composition_mode); |
|
869 |
if (s->fillFlags & DirtyTransform |
|
870 |
|| brush.transform().type() >= QTransform::TxNone) |
|
871 |
d_func()->updateMatrixData(&s->brushData, brush, d->brushMatrix()); |
|
872 |
s->lastBrush = brush; |
|
873 |
s->fillFlags = 0; |
|
874 |
} |
|
875 |
||
876 |
void QRasterPaintEngine::updateOutlineMapper() |
|
877 |
{ |
|
878 |
Q_D(QRasterPaintEngine); |
|
879 |
d->outlineMapper->setMatrix(state()->matrix); |
|
880 |
} |
|
881 |
||
882 |
void QRasterPaintEngine::updateState() |
|
883 |
{ |
|
884 |
QRasterPaintEngineState *s = state(); |
|
885 |
||
886 |
if (s->dirty & DirtyTransform) |
|
887 |
updateMatrix(s->matrix); |
|
888 |
||
889 |
if (s->dirty & (DirtyPen|DirtyCompositionMode)) { |
|
890 |
const QPainter::CompositionMode mode = s->composition_mode; |
|
891 |
s->flags.fast_text = (s->penData.type == QSpanData::Solid) |
|
892 |
&& (mode == QPainter::CompositionMode_Source |
|
893 |
|| (mode == QPainter::CompositionMode_SourceOver |
|
894 |
&& qAlpha(s->penData.solid.color) == 255)); |
|
895 |
} |
|
896 |
||
897 |
s->dirty = 0; |
|
898 |
} |
|
899 |
||
900 |
||
901 |
/*! |
|
902 |
\internal |
|
903 |
*/ |
|
904 |
void QRasterPaintEngine::opacityChanged() |
|
905 |
{ |
|
906 |
QRasterPaintEngineState *s = state(); |
|
907 |
||
908 |
#ifdef QT_DEBUG_DRAW |
|
909 |
qDebug() << "QRasterPaintEngine::opacityChanged()" << s->opacity; |
|
910 |
#endif |
|
911 |
||
912 |
s->fillFlags |= DirtyOpacity; |
|
913 |
s->strokeFlags |= DirtyOpacity; |
|
914 |
s->pixmapFlags |= DirtyOpacity; |
|
915 |
s->intOpacity = (int) (s->opacity * 256); |
|
916 |
} |
|
917 |
||
918 |
/*! |
|
919 |
\internal |
|
920 |
*/ |
|
921 |
void QRasterPaintEngine::compositionModeChanged() |
|
922 |
{ |
|
923 |
Q_D(QRasterPaintEngine); |
|
924 |
QRasterPaintEngineState *s = state(); |
|
925 |
||
926 |
#ifdef QT_DEBUG_DRAW |
|
927 |
qDebug() << "QRasterPaintEngine::compositionModeChanged()" << s->composition_mode; |
|
928 |
#endif |
|
929 |
||
930 |
s->fillFlags |= DirtyCompositionMode; |
|
931 |
s->dirty |= DirtyCompositionMode; |
|
932 |
||
933 |
s->strokeFlags |= DirtyCompositionMode; |
|
934 |
d->rasterBuffer->compositionMode = s->composition_mode; |
|
935 |
||
936 |
d->recalculateFastImages(); |
|
937 |
} |
|
938 |
||
939 |
/*! |
|
940 |
\internal |
|
941 |
*/ |
|
942 |
void QRasterPaintEngine::renderHintsChanged() |
|
943 |
{ |
|
944 |
QRasterPaintEngineState *s = state(); |
|
945 |
||
946 |
#ifdef QT_DEBUG_DRAW |
|
947 |
qDebug() << "QRasterPaintEngine::renderHintsChanged()" << hex << s->renderHints; |
|
948 |
#endif |
|
949 |
||
950 |
bool was_aa = s->flags.antialiased; |
|
951 |
bool was_bilinear = s->flags.bilinear; |
|
952 |
||
953 |
s->flags.antialiased = bool(s->renderHints & QPainter::Antialiasing); |
|
954 |
s->flags.bilinear = bool(s->renderHints & QPainter::SmoothPixmapTransform); |
|
955 |
||
956 |
if (was_aa != s->flags.antialiased) |
|
957 |
s->strokeFlags |= DirtyHints; |
|
958 |
||
959 |
if (was_bilinear != s->flags.bilinear) { |
|
960 |
s->strokeFlags |= DirtyPen; |
|
961 |
s->fillFlags |= DirtyBrush; |
|
962 |
} |
|
963 |
||
964 |
Q_D(QRasterPaintEngine); |
|
965 |
d->recalculateFastImages(); |
|
966 |
} |
|
967 |
||
968 |
/*! |
|
969 |
\internal |
|
970 |
*/ |
|
971 |
void QRasterPaintEngine::transformChanged() |
|
972 |
{ |
|
973 |
QRasterPaintEngineState *s = state(); |
|
974 |
||
975 |
#ifdef QT_DEBUG_DRAW |
|
976 |
qDebug() << "QRasterPaintEngine::transformChanged()" << s->matrix; |
|
977 |
#endif |
|
978 |
||
979 |
s->fillFlags |= DirtyTransform; |
|
980 |
s->strokeFlags |= DirtyTransform; |
|
981 |
||
982 |
s->dirty |= DirtyTransform; |
|
983 |
||
984 |
Q_D(QRasterPaintEngine); |
|
985 |
d->recalculateFastImages(); |
|
986 |
} |
|
987 |
||
988 |
/*! |
|
989 |
\internal |
|
990 |
*/ |
|
991 |
void QRasterPaintEngine::clipEnabledChanged() |
|
992 |
{ |
|
993 |
QRasterPaintEngineState *s = state(); |
|
994 |
||
995 |
#ifdef QT_DEBUG_DRAW |
|
996 |
qDebug() << "QRasterPaintEngine::clipEnabledChanged()" << s->clipEnabled; |
|
997 |
#endif |
|
998 |
||
999 |
if (s->clip) { |
|
1000 |
s->clip->enabled = s->clipEnabled; |
|
1001 |
s->fillFlags |= DirtyClipEnabled; |
|
1002 |
s->strokeFlags |= DirtyClipEnabled; |
|
1003 |
s->pixmapFlags |= DirtyClipEnabled; |
|
1004 |
} |
|
1005 |
} |
|
1006 |
||
1007 |
#ifdef Q_WS_QWS |
|
1008 |
void QRasterPaintEnginePrivate::prepare(QCustomRasterPaintDevice *device) |
|
1009 |
{ |
|
1010 |
rasterBuffer->prepare(device); |
|
1011 |
} |
|
1012 |
#endif |
|
1013 |
||
1014 |
void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, |
|
1015 |
const QImage &img, |
|
1016 |
SrcOverBlendFunc func, |
|
1017 |
const QRect &clip, |
|
1018 |
int alpha, |
|
1019 |
const QRect &sr) |
|
1020 |
{ |
|
1021 |
if (alpha == 0 || !clip.isValid()) |
|
1022 |
return; |
|
1023 |
||
1024 |
Q_ASSERT(img.depth() >= 8); |
|
1025 |
||
1026 |
int srcBPL = img.bytesPerLine(); |
|
1027 |
const uchar *srcBits = img.bits(); |
|
1028 |
int srcSize = img.depth() >> 3; // This is the part that is incompatible with lower than 8-bit.. |
|
1029 |
int iw = img.width(); |
|
1030 |
int ih = img.height(); |
|
1031 |
||
1032 |
if (!sr.isEmpty()) { |
|
1033 |
iw = sr.width(); |
|
1034 |
ih = sr.height(); |
|
1035 |
// Adjust the image according to the source offset... |
|
1036 |
srcBits += ((sr.y() * srcBPL) + sr.x() * srcSize); |
|
1037 |
} |
|
1038 |
||
1039 |
// adapt the x parameters |
|
1040 |
int x = qRound(pt.x()); |
|
1041 |
int cx1 = clip.x(); |
|
1042 |
int cx2 = clip.x() + clip.width(); |
|
1043 |
if (x < cx1) { |
|
1044 |
int d = cx1 - x; |
|
1045 |
srcBits += srcSize * d; |
|
1046 |
iw -= d; |
|
1047 |
x = cx1; |
|
1048 |
} |
|
1049 |
if (x + iw > cx2) { |
|
1050 |
int d = x + iw - cx2; |
|
1051 |
iw -= d; |
|
1052 |
} |
|
1053 |
if (iw <= 0) |
|
1054 |
return; |
|
1055 |
||
1056 |
// adapt the y paremeters... |
|
1057 |
int cy1 = clip.y(); |
|
1058 |
int cy2 = clip.y() + clip.height(); |
|
1059 |
int y = qRound(pt.y()); |
|
1060 |
if (y < cy1) { |
|
1061 |
int d = cy1 - y; |
|
1062 |
srcBits += srcBPL * d; |
|
1063 |
ih -= d; |
|
1064 |
y = cy1; |
|
1065 |
} |
|
1066 |
if (y + ih > cy2) { |
|
1067 |
int d = y + ih - cy2; |
|
1068 |
ih -= d; |
|
1069 |
} |
|
1070 |
if (ih <= 0) |
|
1071 |
return; |
|
1072 |
||
1073 |
// call the blend function... |
|
1074 |
int dstSize = rasterBuffer->bytesPerPixel(); |
|
1075 |
int dstBPL = rasterBuffer->bytesPerLine(); |
|
1076 |
func(rasterBuffer->buffer() + x * dstSize + y * dstBPL, dstBPL, |
|
1077 |
srcBits, srcBPL, |
|
1078 |
iw, ih, |
|
1079 |
alpha); |
|
1080 |
} |
|
1081 |
||
1082 |
||
1083 |
void QRasterPaintEnginePrivate::systemStateChanged() |
|
1084 |
{ |
|
1085 |
QRect clipRect(0, 0, |
|
1086 |
qMin(QT_RASTER_COORD_LIMIT, device->width()), |
|
1087 |
qMin(QT_RASTER_COORD_LIMIT, device->height())); |
|
1088 |
||
1089 |
if (!systemClip.isEmpty()) { |
|
1090 |
QRegion clippedDeviceRgn = systemClip & clipRect; |
|
1091 |
deviceRect = clippedDeviceRgn.boundingRect(); |
|
1092 |
baseClip->setClipRegion(clippedDeviceRgn); |
|
1093 |
} else { |
|
1094 |
deviceRect = clipRect; |
|
1095 |
baseClip->setClipRect(deviceRect); |
|
1096 |
} |
|
1097 |
#ifdef QT_DEBUG_DRAW |
|
1098 |
qDebug() << "systemStateChanged" << this << "deviceRect" << deviceRect << clipRect << systemClip; |
|
1099 |
#endif |
|
1100 |
||
1101 |
exDeviceRect = deviceRect; |
|
1102 |
||
1103 |
Q_Q(QRasterPaintEngine); |
|
1104 |
q->state()->strokeFlags |= QPaintEngine::DirtyClipRegion; |
|
1105 |
q->state()->fillFlags |= QPaintEngine::DirtyClipRegion; |
|
1106 |
q->state()->pixmapFlags |= QPaintEngine::DirtyClipRegion; |
|
1107 |
} |
|
1108 |
||
1109 |
void QRasterPaintEnginePrivate::updateMatrixData(QSpanData *spanData, const QBrush &b, const QTransform &m) |
|
1110 |
{ |
|
1111 |
if (b.d->style == Qt::NoBrush || b.d->style == Qt::SolidPattern) |
|
1112 |
return; |
|
1113 |
||
1114 |
Q_Q(QRasterPaintEngine); |
|
1115 |
bool bilinear = q->state()->flags.bilinear; |
|
1116 |
||
1117 |
if (b.d->transform.type() > QTransform::TxNone) { // FALCON: optimise |
|
1118 |
spanData->setupMatrix(b.transform() * m, bilinear); |
|
1119 |
} else { |
|
1120 |
if (m.type() <= QTransform::TxTranslate) { |
|
1121 |
// specialize setupMatrix for translation matrices |
|
1122 |
// to avoid needless matrix inversion |
|
1123 |
spanData->m11 = 1; |
|
1124 |
spanData->m12 = 0; |
|
1125 |
spanData->m13 = 0; |
|
1126 |
spanData->m21 = 0; |
|
1127 |
spanData->m22 = 1; |
|
1128 |
spanData->m23 = 0; |
|
1129 |
spanData->m33 = 1; |
|
1130 |
spanData->dx = -m.dx(); |
|
1131 |
spanData->dy = -m.dy(); |
|
1132 |
spanData->txop = m.type(); |
|
1133 |
spanData->bilinear = bilinear; |
|
1134 |
spanData->fast_matrix = qAbs(m.dx()) < 1e4 && qAbs(m.dy()) < 1e4; |
|
1135 |
spanData->adjustSpanMethods(); |
|
1136 |
} else { |
|
1137 |
spanData->setupMatrix(m, bilinear); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
} |
|
1141 |
||
1142 |
// #define QT_CLIPPING_RATIOS |
|
1143 |
||
1144 |
#ifdef QT_CLIPPING_RATIOS |
|
1145 |
int rectClips; |
|
1146 |
int regionClips; |
|
1147 |
int totalClips; |
|
1148 |
||
1149 |
static void checkClipRatios(QRasterPaintEnginePrivate *d) |
|
1150 |
{ |
|
1151 |
if (d->clip()->hasRectClip) |
|
1152 |
rectClips++; |
|
1153 |
if (d->clip()->hasRegionClip) |
|
1154 |
regionClips++; |
|
1155 |
totalClips++; |
|
1156 |
||
1157 |
if ((totalClips % 5000) == 0) { |
|
1158 |
printf("Clipping ratio: rectangular=%f%%, region=%f%%, complex=%f%%\n", |
|
1159 |
rectClips * 100.0 / (qreal) totalClips, |
|
1160 |
regionClips * 100.0 / (qreal) totalClips, |
|
1161 |
(totalClips - rectClips - regionClips) * 100.0 / (qreal) totalClips); |
|
1162 |
totalClips = 0; |
|
1163 |
rectClips = 0; |
|
1164 |
regionClips = 0; |
|
1165 |
} |
|
1166 |
||
1167 |
} |
|
1168 |
#endif |
|
1169 |
||
1170 |
static void qrasterpaintengine_state_setNoClip(QRasterPaintEngineState *s) |
|
1171 |
{ |
|
1172 |
if (s->flags.has_clip_ownership) |
|
1173 |
delete s->clip; |
|
1174 |
s->clip = 0; |
|
1175 |
s->flags.has_clip_ownership = false; |
|
1176 |
} |
|
1177 |
||
1178 |
static void qrasterpaintengine_dirty_clip(QRasterPaintEnginePrivate *d, QRasterPaintEngineState *s) |
|
1179 |
{ |
|
1180 |
s->fillFlags |= QPaintEngine::DirtyClipPath; |
|
1181 |
s->strokeFlags |= QPaintEngine::DirtyClipPath; |
|
1182 |
s->pixmapFlags |= QPaintEngine::DirtyClipPath; |
|
1183 |
||
1184 |
d->solid_color_filler.clip = d->clip(); |
|
1185 |
d->solid_color_filler.adjustSpanMethods(); |
|
1186 |
||
1187 |
#ifdef QT_DEBUG_DRAW |
|
1188 |
dumpClip(d->rasterBuffer->width(), d->rasterBuffer->height(), &*d->clip()); |
|
1189 |
#endif |
|
1190 |
||
1191 |
} |
|
1192 |
||
1193 |
||
1194 |
/*! |
|
1195 |
\internal |
|
1196 |
*/ |
|
1197 |
void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) |
|
1198 |
{ |
|
1199 |
#ifdef QT_DEBUG_DRAW |
|
1200 |
qDebug() << "QRasterPaintEngine::clip(): " << path << op; |
|
1201 |
||
1202 |
if (path.elements()) { |
|
1203 |
for (int i=0; i<path.elementCount(); ++i) { |
|
1204 |
qDebug() << " - " << path.elements()[i] |
|
1205 |
<< '(' << path.points()[i*2] << ", " << path.points()[i*2+1] << ')'; |
|
1206 |
} |
|
1207 |
} else { |
|
1208 |
for (int i=0; i<path.elementCount(); ++i) { |
|
1209 |
qDebug() << " ---- " |
|
1210 |
<< '(' << path.points()[i*2] << ", " << path.points()[i*2+1] << ')'; |
|
1211 |
} |
|
1212 |
} |
|
1213 |
#endif |
|
1214 |
||
1215 |
Q_D(QRasterPaintEngine); |
|
1216 |
QRasterPaintEngineState *s = state(); |
|
1217 |
||
1218 |
const qreal *points = path.points(); |
|
1219 |
const QPainterPath::ElementType *types = path.elements(); |
|
1220 |
||
1221 |
// There are some cases that are not supported by clip(QRect) |
|
1222 |
if (op != Qt::UniteClip && (op != Qt::IntersectClip || !s->clip |
|
1223 |
|| s->clip->hasRectClip || s->clip->hasRegionClip)) { |
|
1224 |
if (s->matrix.type() <= QTransform::TxTranslate |
|
1225 |
&& ((path.shape() == QVectorPath::RectangleHint) |
|
1226 |
|| (isRect(points, path.elementCount()) |
|
1227 |
&& (!types || (types[0] == QPainterPath::MoveToElement |
|
1228 |
&& types[1] == QPainterPath::LineToElement |
|
1229 |
&& types[2] == QPainterPath::LineToElement |
|
1230 |
&& types[3] == QPainterPath::LineToElement))))) { |
|
1231 |
#ifdef QT_DEBUG_DRAW |
|
1232 |
qDebug() << " --- optimizing vector clip to rect clip..."; |
|
1233 |
#endif |
|
1234 |
||
1235 |
QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]); |
|
1236 |
clip(r.toRect(), op); |
|
1237 |
return; |
|
1238 |
} |
|
1239 |
} |
|
1240 |
||
1241 |
if (op == Qt::NoClip) { |
|
1242 |
qrasterpaintengine_state_setNoClip(s); |
|
1243 |
||
1244 |
} else { |
|
1245 |
QClipData *base = d->baseClip.data(); |
|
1246 |
||
1247 |
// Intersect with current clip when available... |
|
1248 |
if (op == Qt::IntersectClip && s->clip) |
|
1249 |
base = s->clip; |
|
1250 |
||
1251 |
// We always intersect, except when there is nothing to |
|
1252 |
// intersect with, in which case we simplify the operation to |
|
1253 |
// a replace... |
|
1254 |
Qt::ClipOperation isectOp = Qt::IntersectClip; |
|
1255 |
if (base == 0) |
|
1256 |
isectOp = Qt::ReplaceClip; |
|
1257 |
||
1258 |
QClipData *newClip = new QClipData(d->rasterBuffer->height()); |
|
1259 |
newClip->initialize(); |
|
1260 |
ClipData clipData = { base, newClip, isectOp }; |
|
1261 |
ensureOutlineMapper(); |
|
1262 |
d->rasterize(d->outlineMapper->convertPath(path), qt_span_clip, &clipData, 0); |
|
1263 |
||
1264 |
newClip->fixup(); |
|
1265 |
||
1266 |
if (op == Qt::UniteClip) { |
|
1267 |
// merge clips |
|
1268 |
QClipData *result = new QClipData(d->rasterBuffer->height()); |
|
1269 |
QClipData *current = s->clip ? s->clip : new QClipData(d->rasterBuffer->height()); |
|
1270 |
qt_merge_clip(current, newClip, result); |
|
1271 |
result->fixup(); |
|
1272 |
delete newClip; |
|
1273 |
if (!s->clip) |
|
1274 |
delete current; |
|
1275 |
newClip = result; |
|
1276 |
} |
|
1277 |
||
1278 |
if (s->flags.has_clip_ownership) |
|
1279 |
delete s->clip; |
|
1280 |
||
1281 |
s->clip = newClip; |
|
1282 |
s->flags.has_clip_ownership = true; |
|
1283 |
} |
|
1284 |
qrasterpaintengine_dirty_clip(d, s); |
|
1285 |
} |
|
1286 |
||
1287 |
||
1288 |
||
1289 |
/*! |
|
1290 |
\internal |
|
1291 |
*/ |
|
1292 |
void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) |
|
1293 |
{ |
|
1294 |
#ifdef QT_DEBUG_DRAW |
|
1295 |
qDebug() << "QRasterPaintEngine::clip(): " << rect << op; |
|
1296 |
#endif |
|
1297 |
||
1298 |
Q_D(QRasterPaintEngine); |
|
1299 |
QRasterPaintEngineState *s = state(); |
|
1300 |
||
1301 |
if (op == Qt::NoClip) { |
|
1302 |
qrasterpaintengine_state_setNoClip(s); |
|
1303 |
||
1304 |
} else if (op == Qt::UniteClip || s->matrix.type() > QTransform::TxScale) { |
|
1305 |
QPaintEngineEx::clip(rect, op); |
|
1306 |
return; |
|
1307 |
||
1308 |
} else if (op == Qt::ReplaceClip || s->clip == 0) { |
|
1309 |
||
1310 |
// No current clip, hence we intersect with sysclip and be |
|
1311 |
// done with it... |
|
1312 |
QRect clipRect = s->matrix.mapRect(rect) & d->deviceRect; |
|
1313 |
QRegion clipRegion = systemClip(); |
|
1314 |
QClipData *clip = new QClipData(d->rasterBuffer->height()); |
|
1315 |
||
1316 |
if (clipRegion.isEmpty()) |
|
1317 |
clip->setClipRect(clipRect); |
|
1318 |
else |
|
1319 |
clip->setClipRegion(clipRegion & clipRect); |
|
1320 |
||
1321 |
if (s->flags.has_clip_ownership) |
|
1322 |
delete s->clip; |
|
1323 |
||
1324 |
s->clip = clip; |
|
1325 |
s->clip->enabled = true; |
|
1326 |
s->flags.has_clip_ownership = true; |
|
1327 |
||
1328 |
} else { // intersect clip with current clip |
|
1329 |
QClipData *base = s->clip; |
|
1330 |
||
1331 |
Q_ASSERT(base); |
|
1332 |
if (base->hasRectClip || base->hasRegionClip) { |
|
1333 |
QRect clipRect = s->matrix.mapRect(rect) & d->deviceRect; |
|
1334 |
if (!s->flags.has_clip_ownership) { |
|
1335 |
s->clip = new QClipData(d->rasterBuffer->height()); |
|
1336 |
s->flags.has_clip_ownership = true; |
|
1337 |
} |
|
1338 |
if (base->hasRectClip) |
|
1339 |
s->clip->setClipRect(base->clipRect & clipRect); |
|
1340 |
else |
|
1341 |
s->clip->setClipRegion(base->clipRegion & clipRect); |
|
1342 |
s->clip->enabled = true; |
|
1343 |
} else { |
|
1344 |
QPaintEngineEx::clip(rect, op); |
|
1345 |
return; |
|
1346 |
} |
|
1347 |
} |
|
1348 |
qrasterpaintengine_dirty_clip(d, s); |
|
1349 |
} |
|
1350 |
||
1351 |
||
1352 |
/*! |
|
1353 |
\internal |
|
1354 |
*/ |
|
1355 |
void QRasterPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) |
|
1356 |
{ |
|
1357 |
#ifdef QT_DEBUG_DRAW |
|
1358 |
qDebug() << "QRasterPaintEngine::clip(): " << region << op; |
|
1359 |
#endif |
|
1360 |
||
1361 |
Q_D(QRasterPaintEngine); |
|
1362 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1363 |
if (region.rectCount() == 1) { |
0 | 1364 |
clip(region.boundingRect(), op); |
1365 |
return; |
|
1366 |
} |
|
1367 |
||
1368 |
QRasterPaintEngineState *s = state(); |
|
1369 |
const QClipData *clip = d->clip(); |
|
1370 |
const QClipData *baseClip = d->baseClip.data(); |
|
1371 |
||
1372 |
if (op == Qt::NoClip) { |
|
1373 |
qrasterpaintengine_state_setNoClip(s); |
|
1374 |
} else if (s->matrix.type() > QTransform::TxScale |
|
1375 |
|| op == Qt::UniteClip |
|
1376 |
|| (op == Qt::IntersectClip && !clip->hasRectClip && !clip->hasRegionClip) |
|
1377 |
|| (op == Qt::ReplaceClip && !baseClip->hasRectClip && !baseClip->hasRegionClip)) { |
|
1378 |
QPaintEngineEx::clip(region, op); |
|
1379 |
} else { |
|
1380 |
const QClipData *curClip; |
|
1381 |
QClipData *newClip; |
|
1382 |
||
1383 |
if (op == Qt::IntersectClip) |
|
1384 |
curClip = clip; |
|
1385 |
else |
|
1386 |
curClip = baseClip; |
|
1387 |
||
1388 |
if (s->flags.has_clip_ownership) { |
|
1389 |
newClip = s->clip; |
|
1390 |
Q_ASSERT(newClip); |
|
1391 |
} else { |
|
1392 |
newClip = new QClipData(d->rasterBuffer->height()); |
|
1393 |
s->clip = newClip; |
|
1394 |
s->flags.has_clip_ownership = true; |
|
1395 |
} |
|
1396 |
||
1397 |
QRegion r = s->matrix.map(region); |
|
1398 |
if (curClip->hasRectClip) |
|
1399 |
newClip->setClipRegion(r & curClip->clipRect); |
|
1400 |
else if (curClip->hasRegionClip) |
|
1401 |
newClip->setClipRegion(r & curClip->clipRegion); |
|
1402 |
||
1403 |
qrasterpaintengine_dirty_clip(d, s); |
|
1404 |
} |
|
1405 |
} |
|
1406 |
||
1407 |
/*! |
|
1408 |
\internal |
|
1409 |
*/ |
|
1410 |
void QRasterPaintEngine::fillPath(const QPainterPath &path, QSpanData *fillData) |
|
1411 |
{ |
|
1412 |
#ifdef QT_DEBUG_DRAW |
|
1413 |
qDebug() << " --- fillPath, bounds=" << path.boundingRect(); |
|
1414 |
#endif |
|
1415 |
||
1416 |
if (!fillData->blend) |
|
1417 |
return; |
|
1418 |
||
1419 |
Q_D(QRasterPaintEngine); |
|
1420 |
||
1421 |
const QRectF controlPointRect = path.controlPointRect(); |
|
1422 |
||
1423 |
QRasterPaintEngineState *s = state(); |
|
1424 |
const QRect deviceRect = s->matrix.mapRect(controlPointRect).toRect(); |
|
1425 |
ProcessSpans blend = d->getBrushFunc(deviceRect, fillData); |
|
1426 |
const bool do_clip = (deviceRect.left() < -QT_RASTER_COORD_LIMIT |
|
1427 |
|| deviceRect.right() > QT_RASTER_COORD_LIMIT |
|
1428 |
|| deviceRect.top() < -QT_RASTER_COORD_LIMIT |
|
1429 |
|| deviceRect.bottom() > QT_RASTER_COORD_LIMIT); |
|
1430 |
||
1431 |
if (!s->flags.antialiased && !do_clip) { |
|
1432 |
d->initializeRasterizer(fillData); |
|
1433 |
d->rasterizer->rasterize(path * s->matrix, path.fillRule()); |
|
1434 |
return; |
|
1435 |
} |
|
1436 |
||
1437 |
ensureOutlineMapper(); |
|
1438 |
d->rasterize(d->outlineMapper->convertPath(path), blend, fillData, d->rasterBuffer.data()); |
|
1439 |
} |
|
1440 |
||
1441 |
static void fillRect_normalized(const QRect &r, QSpanData *data, |
|
1442 |
QRasterPaintEnginePrivate *pe) |
|
1443 |
{ |
|
1444 |
int x1, x2, y1, y2; |
|
1445 |
||
1446 |
bool rectClipped = true; |
|
1447 |
||
1448 |
if (data->clip) { |
|
1449 |
x1 = qMax(r.x(), data->clip->xmin); |
|
1450 |
x2 = qMin(r.x() + r.width(), data->clip->xmax); |
|
1451 |
y1 = qMax(r.y(), data->clip->ymin); |
|
1452 |
y2 = qMin(r.y() + r.height(), data->clip->ymax); |
|
1453 |
rectClipped = data->clip->hasRectClip; |
|
1454 |
||
1455 |
} else if (pe) { |
|
1456 |
x1 = qMax(r.x(), pe->deviceRect.x()); |
|
1457 |
x2 = qMin(r.x() + r.width(), pe->deviceRect.x() + pe->deviceRect.width()); |
|
1458 |
y1 = qMax(r.y(), pe->deviceRect.y()); |
|
1459 |
y2 = qMin(r.y() + r.height(), pe->deviceRect.y() + pe->deviceRect.height()); |
|
1460 |
} else { |
|
1461 |
x1 = qMax(r.x(), 0); |
|
1462 |
x2 = qMin(r.x() + r.width(), data->rasterBuffer->width()); |
|
1463 |
y1 = qMax(r.y(), 0); |
|
1464 |
y2 = qMin(r.y() + r.height(), data->rasterBuffer->height()); |
|
1465 |
} |
|
1466 |
||
1467 |
if (x2 <= x1 || y2 <= y1) |
|
1468 |
return; |
|
1469 |
||
1470 |
const int width = x2 - x1; |
|
1471 |
const int height = y2 - y1; |
|
1472 |
||
1473 |
bool isUnclipped = rectClipped |
|
1474 |
|| (pe && pe->isUnclipped_normalized(QRect(x1, y1, width, height))); |
|
1475 |
||
1476 |
if (pe && isUnclipped) { |
|
1477 |
const QPainter::CompositionMode mode = pe->rasterBuffer->compositionMode; |
|
1478 |
||
1479 |
if (data->fillRect && (mode == QPainter::CompositionMode_Source |
|
1480 |
|| (mode == QPainter::CompositionMode_SourceOver |
|
1481 |
&& qAlpha(data->solid.color) == 255))) |
|
1482 |
{ |
|
1483 |
data->fillRect(data->rasterBuffer, x1, y1, width, height, |
|
1484 |
data->solid.color); |
|
1485 |
return; |
|
1486 |
} |
|
1487 |
} |
|
1488 |
||
1489 |
ProcessSpans blend = isUnclipped ? data->unclipped_blend : data->blend; |
|
1490 |
||
1491 |
const int nspans = 256; |
|
1492 |
QT_FT_Span spans[nspans]; |
|
1493 |
||
1494 |
Q_ASSERT(data->blend); |
|
1495 |
int y = y1; |
|
1496 |
while (y < y2) { |
|
1497 |
int n = qMin(nspans, y2 - y); |
|
1498 |
int i = 0; |
|
1499 |
while (i < n) { |
|
1500 |
spans[i].x = x1; |
|
1501 |
spans[i].len = width; |
|
1502 |
spans[i].y = y + i; |
|
1503 |
spans[i].coverage = 255; |
|
1504 |
++i; |
|
1505 |
} |
|
1506 |
||
1507 |
blend(n, spans, data); |
|
1508 |
y += n; |
|
1509 |
} |
|
1510 |
} |
|
1511 |
||
1512 |
/*! |
|
1513 |
\reimp |
|
1514 |
*/ |
|
1515 |
void QRasterPaintEngine::drawRects(const QRect *rects, int rectCount) |
|
1516 |
{ |
|
1517 |
#ifdef QT_DEBUG_DRAW |
|
1518 |
qDebug(" - QRasterPaintEngine::drawRect(), rectCount=%d", rectCount); |
|
1519 |
#endif |
|
1520 |
Q_D(QRasterPaintEngine); |
|
1521 |
QRasterPaintEngineState *s = state(); |
|
1522 |
||
1523 |
// Fill |
|
1524 |
ensureBrush(); |
|
1525 |
if (s->brushData.blend) { |
|
1526 |
if (!s->flags.antialiased && s->matrix.type() <= QTransform::TxTranslate) { |
|
1527 |
const QRect *r = rects; |
|
1528 |
const QRect *lastRect = rects + rectCount; |
|
1529 |
||
1530 |
int offset_x = int(s->matrix.dx()); |
|
1531 |
int offset_y = int(s->matrix.dy()); |
|
1532 |
while (r < lastRect) { |
|
1533 |
QRect rect = r->normalized(); |
|
1534 |
QRect rr = rect.translated(offset_x, offset_y); |
|
1535 |
fillRect_normalized(rr, &s->brushData, d); |
|
1536 |
++r; |
|
1537 |
} |
|
1538 |
} else { |
|
1539 |
QRectVectorPath path; |
|
1540 |
for (int i=0; i<rectCount; ++i) { |
|
1541 |
path.set(rects[i]); |
|
1542 |
fill(path, s->brush); |
|
1543 |
} |
|
1544 |
} |
|
1545 |
} |
|
1546 |
||
1547 |
ensurePen(); |
|
1548 |
if (s->penData.blend) { |
|
1549 |
if (s->flags.fast_pen && s->lastPen.brush().isOpaque()) { |
|
1550 |
const QRect *r = rects; |
|
1551 |
const QRect *lastRect = rects + rectCount; |
|
1552 |
while (r < lastRect) { |
|
1553 |
int left = r->x(); |
|
1554 |
int right = r->x() + r->width(); |
|
1555 |
int top = r->y(); |
|
1556 |
int bottom = r->y() + r->height(); |
|
1557 |
||
1558 |
#ifdef Q_WS_MAC |
|
1559 |
int pts[] = { top, left, |
|
1560 |
top, right, |
|
1561 |
bottom, right, |
|
1562 |
bottom, left }; |
|
1563 |
#else |
|
1564 |
int pts[] = { left, top, |
|
1565 |
right, top, |
|
1566 |
right, bottom, |
|
1567 |
left, bottom }; |
|
1568 |
#endif |
|
1569 |
||
1570 |
strokePolygonCosmetic((QPoint *) pts, 4, WindingMode); |
|
1571 |
++r; |
|
1572 |
} |
|
1573 |
} else { |
|
1574 |
QRectVectorPath path; |
|
1575 |
for (int i = 0; i < rectCount; ++i) { |
|
1576 |
path.set(rects[i]); |
|
1577 |
stroke(path, s->pen); |
|
1578 |
} |
|
1579 |
} |
|
1580 |
} |
|
1581 |
} |
|
1582 |
||
1583 |
/*! |
|
1584 |
\reimp |
|
1585 |
*/ |
|
1586 |
void QRasterPaintEngine::drawRects(const QRectF *rects, int rectCount) |
|
1587 |
{ |
|
1588 |
#ifdef QT_DEBUG_DRAW |
|
1589 |
qDebug(" - QRasterPaintEngine::drawRect(), rectCount=%d", rectCount); |
|
1590 |
#endif |
|
1591 |
#ifdef QT_FAST_SPANS |
|
1592 |
Q_D(QRasterPaintEngine); |
|
1593 |
QRasterPaintEngineState *s = state(); |
|
1594 |
||
1595 |
ensureState(); |
|
1596 |
||
1597 |
if (s->flags.tx_noshear) { |
|
1598 |
ensureBrush(); |
|
1599 |
if (s->brushData.blend) { |
|
1600 |
d->initializeRasterizer(&s->brushData); |
|
1601 |
for (int i = 0; i < rectCount; ++i) { |
|
1602 |
const QRectF &rect = rects[i].normalized(); |
|
1603 |
if (rect.isEmpty()) |
|
1604 |
continue; |
|
1605 |
const QPointF a = s->matrix.map((rect.topLeft() + rect.bottomLeft()) * 0.5f); |
|
1606 |
const QPointF b = s->matrix.map((rect.topRight() + rect.bottomRight()) * 0.5f); |
|
1607 |
d->rasterizer->rasterizeLine(a, b, rect.height() / rect.width()); |
|
1608 |
} |
|
1609 |
} |
|
1610 |
||
1611 |
ensurePen(); |
|
1612 |
if (s->penData.blend) { |
|
1613 |
qreal width = s->pen.isCosmetic() |
|
1614 |
? (s->lastPen.widthF() == 0 ? 1 : s->lastPen.widthF()) |
|
1615 |
: s->lastPen.widthF() * s->txscale; |
|
1616 |
||
1617 |
if (s->flags.fast_pen && s->lastPen.brush().isOpaque()) { |
|
1618 |
for (int i = 0; i < rectCount; ++i) { |
|
1619 |
const QRectF &r = rects[i]; |
|
1620 |
qreal left = r.x(); |
|
1621 |
qreal right = r.x() + r.width(); |
|
1622 |
qreal top = r.y(); |
|
1623 |
qreal bottom = r.y() + r.height(); |
|
1624 |
qreal pts[] = { left, top, |
|
1625 |
right, top, |
|
1626 |
right, bottom, |
|
1627 |
left, bottom }; |
|
1628 |
strokePolygonCosmetic((QPointF *) pts, 4, WindingMode); |
|
1629 |
} |
|
1630 |
} else if (width <= 1 && qpen_style(s->lastPen) == Qt::SolidLine) { |
|
1631 |
d->initializeRasterizer(&s->penData); |
|
1632 |
||
1633 |
for (int i = 0; i < rectCount; ++i) { |
|
1634 |
const QRectF &rect = rects[i].normalized(); |
|
1635 |
if (rect.isEmpty()) { |
|
1636 |
qreal pts[] = { rect.left(), rect.top(), rect.right(), rect.bottom() }; |
|
1637 |
QVectorPath vp(pts, 2, 0, QVectorPath::LinesHint); |
|
1638 |
QPaintEngineEx::stroke(vp, s->lastPen); |
|
1639 |
} else { |
|
1640 |
const QPointF tl = s->matrix.map(rect.topLeft()); |
|
1641 |
const QPointF tr = s->matrix.map(rect.topRight()); |
|
1642 |
const QPointF bl = s->matrix.map(rect.bottomLeft()); |
|
1643 |
const QPointF br = s->matrix.map(rect.bottomRight()); |
|
1644 |
const qreal w = width / (rect.width() * s->txscale); |
|
1645 |
const qreal h = width / (rect.height() * s->txscale); |
|
1646 |
d->rasterizer->rasterizeLine(tl, tr, w); // top |
|
1647 |
d->rasterizer->rasterizeLine(bl, br, w); // bottom |
|
1648 |
d->rasterizer->rasterizeLine(bl, tl, h); // left |
|
1649 |
d->rasterizer->rasterizeLine(br, tr, h); // right |
|
1650 |
} |
|
1651 |
} |
|
1652 |
} else { |
|
1653 |
for (int i = 0; i < rectCount; ++i) { |
|
1654 |
const QRectF &r = rects[i]; |
|
1655 |
qreal left = r.x(); |
|
1656 |
qreal right = r.x() + r.width(); |
|
1657 |
qreal top = r.y(); |
|
1658 |
qreal bottom = r.y() + r.height(); |
|
1659 |
qreal pts[] = { left, top, |
|
1660 |
right, top, |
|
1661 |
right, bottom, |
|
1662 |
left, bottom, |
|
1663 |
left, top }; |
|
1664 |
QVectorPath vp(pts, 5, 0, QVectorPath::RectangleHint); |
|
1665 |
QPaintEngineEx::stroke(vp, s->lastPen); |
|
1666 |
} |
|
1667 |
} |
|
1668 |
} |
|
1669 |
||
1670 |
return; |
|
1671 |
} |
|
1672 |
#endif // QT_FAST_SPANS |
|
1673 |
QPaintEngineEx::drawRects(rects, rectCount); |
|
1674 |
} |
|
1675 |
||
1676 |
||
1677 |
/*! |
|
1678 |
\internal |
|
1679 |
*/ |
|
1680 |
void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen) |
|
1681 |
{ |
|
1682 |
QRasterPaintEngineState *s = state(); |
|
1683 |
ensurePen(pen); |
|
1684 |
if (!s->penData.blend) |
|
1685 |
return; |
|
1686 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1687 |
if (s->flags.fast_pen && !path.isCurved() |
0 | 1688 |
&& s->lastPen.brush().isOpaque()) { |
1689 |
int count = path.elementCount(); |
|
1690 |
QPointF *points = (QPointF *) path.points(); |
|
1691 |
const QPainterPath::ElementType *types = path.elements(); |
|
1692 |
if (types) { |
|
1693 |
int first = 0; |
|
1694 |
int last; |
|
1695 |
while (first < count) { |
|
1696 |
while (first < count && types[first] != QPainterPath::MoveToElement) ++first; |
|
1697 |
last = first + 1; |
|
1698 |
while (last < count && types[last] == QPainterPath::LineToElement) ++last; |
|
1699 |
strokePolygonCosmetic(points + first, last - first, |
|
1700 |
path.hasImplicitClose() && last == count // only close last one.. |
|
1701 |
? WindingMode |
|
1702 |
: PolylineMode); |
|
1703 |
first = last; |
|
1704 |
} |
|
1705 |
} else { |
|
1706 |
strokePolygonCosmetic(points, count, |
|
1707 |
path.hasImplicitClose() |
|
1708 |
? WindingMode |
|
1709 |
: PolylineMode); |
|
1710 |
} |
|
1711 |
||
1712 |
} else if (s->flags.non_complex_pen && path.shape() == QVectorPath::LinesHint) { |
|
1713 |
qreal width = s->lastPen.isCosmetic() |
|
1714 |
? (qpen_widthf(s->lastPen) == 0 ? 1 : qpen_widthf(s->lastPen)) |
|
1715 |
: qpen_widthf(s->lastPen) * s->txscale; |
|
1716 |
int dashIndex = 0; |
|
1717 |
qreal dashOffset = s->lastPen.dashOffset(); |
|
1718 |
bool inDash = true; |
|
1719 |
qreal patternLength = 0; |
|
1720 |
const QVector<qreal> pattern = s->lastPen.dashPattern(); |
|
1721 |
for (int i = 0; i < pattern.size(); ++i) |
|
1722 |
patternLength += pattern.at(i); |
|
1723 |
||
1724 |
if (patternLength > 0) { |
|
1725 |
int n = qFloor(dashOffset / patternLength); |
|
1726 |
dashOffset -= n * patternLength; |
|
1727 |
while (dashOffset > pattern.at(dashIndex)) { |
|
1728 |
dashOffset -= pattern.at(dashIndex); |
|
1729 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
1730 |
inDash = !inDash; |
|
1731 |
} |
|
1732 |
} |
|
1733 |
||
1734 |
Q_D(QRasterPaintEngine); |
|
1735 |
d->initializeRasterizer(&s->penData); |
|
1736 |
int lineCount = path.elementCount() / 2; |
|
1737 |
const QLineF *lines = reinterpret_cast<const QLineF *>(path.points()); |
|
1738 |
||
1739 |
for (int i = 0; i < lineCount; ++i) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1740 |
dashOffset = s->lastPen.dashOffset(); |
0 | 1741 |
if (lines[i].p1() == lines[i].p2()) { |
1742 |
if (s->lastPen.capStyle() != Qt::FlatCap) { |
|
1743 |
QPointF p = lines[i].p1(); |
|
1744 |
QLineF line = s->matrix.map(QLineF(QPointF(p.x() - width*0.5, p.y()), |
|
1745 |
QPointF(p.x() + width*0.5, p.y()))); |
|
1746 |
d->rasterizer->rasterizeLine(line.p1(), line.p2(), 1); |
|
1747 |
} |
|
1748 |
continue; |
|
1749 |
} |
|
1750 |
||
1751 |
const QLineF line = s->matrix.map(lines[i]); |
|
1752 |
if (qpen_style(s->lastPen) == Qt::SolidLine) { |
|
1753 |
d->rasterizer->rasterizeLine(line.p1(), line.p2(), |
|
1754 |
width / line.length(), |
|
1755 |
s->lastPen.capStyle() == Qt::SquareCap); |
|
1756 |
} else { |
|
1757 |
d->rasterizeLine_dashed(line, width, |
|
1758 |
&dashIndex, &dashOffset, &inDash); |
|
1759 |
} |
|
1760 |
} |
|
1761 |
} |
|
1762 |
else |
|
1763 |
QPaintEngineEx::stroke(path, pen); |
|
1764 |
} |
|
1765 |
||
1766 |
static inline QRect toNormalizedFillRect(const QRectF &rect) |
|
1767 |
{ |
|
1768 |
int x1 = qRound(rect.x() + aliasedCoordinateDelta); |
|
1769 |
int y1 = qRound(rect.y() + aliasedCoordinateDelta); |
|
1770 |
int x2 = qRound(rect.right() + aliasedCoordinateDelta); |
|
1771 |
int y2 = qRound(rect.bottom() + aliasedCoordinateDelta); |
|
1772 |
||
1773 |
if (x2 < x1) |
|
1774 |
qSwap(x1, x2); |
|
1775 |
if (y2 < y1) |
|
1776 |
qSwap(y1, y2); |
|
1777 |
||
1778 |
return QRect(x1, y1, x2 - x1, y2 - y1); |
|
1779 |
} |
|
1780 |
||
1781 |
/*! |
|
1782 |
\internal |
|
1783 |
*/ |
|
1784 |
void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) |
|
1785 |
{ |
|
1786 |
if (path.isEmpty()) |
|
1787 |
return; |
|
1788 |
#ifdef QT_DEBUG_DRAW |
|
1789 |
QRectF rf = path.controlPointRect(); |
|
1790 |
qDebug() << "QRasterPaintEngine::fill(): " |
|
1791 |
<< "size=" << path.elementCount() |
|
1792 |
<< ", hints=" << hex << path.hints() |
|
1793 |
<< rf << brush; |
|
1794 |
#endif |
|
1795 |
||
1796 |
Q_D(QRasterPaintEngine); |
|
1797 |
QRasterPaintEngineState *s = state(); |
|
1798 |
||
1799 |
ensureBrush(brush); |
|
1800 |
if (!s->brushData.blend) |
|
1801 |
return; |
|
1802 |
||
1803 |
if (path.shape() == QVectorPath::RectangleHint) { |
|
1804 |
if (!s->flags.antialiased && s->matrix.type() <= QTransform::TxScale) { |
|
1805 |
const qreal *p = path.points(); |
|
1806 |
QPointF tl = QPointF(p[0], p[1]) * s->matrix; |
|
1807 |
QPointF br = QPointF(p[4], p[5]) * s->matrix; |
|
1808 |
fillRect_normalized(toNormalizedFillRect(QRectF(tl, br)), &s->brushData, d); |
|
1809 |
return; |
|
1810 |
} |
|
1811 |
ensureState(); |
|
1812 |
if (s->flags.tx_noshear) { |
|
1813 |
d->initializeRasterizer(&s->brushData); |
|
1814 |
// ### Is normalizing really nessesary here? |
|
1815 |
const qreal *p = path.points(); |
|
1816 |
QRectF r = QRectF(p[0], p[1], p[2] - p[0], p[7] - p[1]).normalized(); |
|
1817 |
if (!r.isEmpty()) { |
|
1818 |
const QPointF a = s->matrix.map((r.topLeft() + r.bottomLeft()) * 0.5f); |
|
1819 |
const QPointF b = s->matrix.map((r.topRight() + r.bottomRight()) * 0.5f); |
|
1820 |
d->rasterizer->rasterizeLine(a, b, r.height() / r.width()); |
|
1821 |
} |
|
1822 |
return; |
|
1823 |
} |
|
1824 |
} |
|
1825 |
||
1826 |
if (path.shape() == QVectorPath::EllipseHint) { |
|
1827 |
if (!s->flags.antialiased && s->matrix.type() <= QTransform::TxScale) { |
|
1828 |
const qreal *p = path.points(); |
|
1829 |
QPointF tl = QPointF(p[0], p[1]) * s->matrix; |
|
1830 |
QPointF br = QPointF(p[4], p[5]) * s->matrix; |
|
1831 |
QRectF r = s->matrix.mapRect(QRectF(tl, br)); |
|
1832 |
||
1833 |
ProcessSpans penBlend = d->getPenFunc(r, &s->penData); |
|
1834 |
ProcessSpans brushBlend = d->getBrushFunc(r, &s->brushData); |
|
1835 |
const QRect brect = QRect(int(r.x()), int(r.y()), |
|
1836 |
int_dim(r.x(), r.width()), |
|
1837 |
int_dim(r.y(), r.height())); |
|
1838 |
if (brect == r) { |
|
1839 |
drawEllipse_midpoint_i(brect, d->deviceRect, penBlend, brushBlend, |
|
1840 |
&s->penData, &s->brushData); |
|
1841 |
return; |
|
1842 |
} |
|
1843 |
} |
|
1844 |
} |
|
1845 |
||
1846 |
// ### Optimize for non transformed ellipses and rectangles... |
|
1847 |
QRectF cpRect = path.controlPointRect(); |
|
1848 |
const QRect deviceRect = s->matrix.mapRect(cpRect).toRect(); |
|
1849 |
ProcessSpans blend = d->getBrushFunc(deviceRect, &s->brushData); |
|
1850 |
||
1851 |
// ### Falcon |
|
1852 |
// const bool do_clip = (deviceRect.left() < -QT_RASTER_COORD_LIMIT |
|
1853 |
// || deviceRect.right() > QT_RASTER_COORD_LIMIT |
|
1854 |
// || deviceRect.top() < -QT_RASTER_COORD_LIMIT |
|
1855 |
// || deviceRect.bottom() > QT_RASTER_COORD_LIMIT); |
|
1856 |
||
1857 |
// ### Falonc: implement.... |
|
1858 |
// if (!s->flags.antialiased && !do_clip) { |
|
1859 |
// d->initializeRasterizer(&s->brushData); |
|
1860 |
// d->rasterizer->rasterize(path * d->matrix, path.fillRule()); |
|
1861 |
// return; |
|
1862 |
// } |
|
1863 |
||
1864 |
ensureOutlineMapper(); |
|
1865 |
d->rasterize(d->outlineMapper->convertPath(path), blend, &s->brushData, d->rasterBuffer.data()); |
|
1866 |
} |
|
1867 |
||
1868 |
void QRasterPaintEngine::fillRect(const QRectF &r, QSpanData *data) |
|
1869 |
{ |
|
1870 |
Q_D(QRasterPaintEngine); |
|
1871 |
QRasterPaintEngineState *s = state(); |
|
1872 |
||
1873 |
if (!s->flags.antialiased) { |
|
1874 |
uint txop = s->matrix.type(); |
|
1875 |
if (txop == QTransform::TxNone) { |
|
1876 |
fillRect_normalized(toNormalizedFillRect(r), data, d); |
|
1877 |
return; |
|
1878 |
} else if (txop == QTransform::TxTranslate) { |
|
1879 |
const QRect rr = toNormalizedFillRect(r.translated(s->matrix.dx(), s->matrix.dy())); |
|
1880 |
fillRect_normalized(rr, data, d); |
|
1881 |
return; |
|
1882 |
} else if (txop == QTransform::TxScale) { |
|
1883 |
const QRect rr = toNormalizedFillRect(s->matrix.mapRect(r)); |
|
1884 |
fillRect_normalized(rr, data, d); |
|
1885 |
return; |
|
1886 |
} |
|
1887 |
} |
|
1888 |
ensureState(); |
|
1889 |
if (s->flags.tx_noshear) { |
|
1890 |
d->initializeRasterizer(data); |
|
1891 |
QRectF nr = r.normalized(); |
|
1892 |
if (!nr.isEmpty()) { |
|
1893 |
const QPointF a = s->matrix.map((nr.topLeft() + nr.bottomLeft()) * 0.5f); |
|
1894 |
const QPointF b = s->matrix.map((nr.topRight() + nr.bottomRight()) * 0.5f); |
|
1895 |
d->rasterizer->rasterizeLine(a, b, nr.height() / nr.width()); |
|
1896 |
} |
|
1897 |
return; |
|
1898 |
} |
|
1899 |
||
1900 |
QPainterPath path; |
|
1901 |
path.addRect(r); |
|
1902 |
ensureOutlineMapper(); |
|
1903 |
fillPath(path, data); |
|
1904 |
} |
|
1905 |
||
1906 |
/*! |
|
1907 |
\reimp |
|
1908 |
*/ |
|
1909 |
void QRasterPaintEngine::fillRect(const QRectF &r, const QBrush &brush) |
|
1910 |
{ |
|
1911 |
#ifdef QT_DEBUG_DRAW |
|
1912 |
qDebug() << "QRasterPaintEngine::fillRecct(): " << r << brush; |
|
1913 |
#endif |
|
1914 |
QRasterPaintEngineState *s = state(); |
|
1915 |
||
1916 |
ensureBrush(brush); |
|
1917 |
if (!s->brushData.blend) |
|
1918 |
return; |
|
1919 |
||
1920 |
fillRect(r, &s->brushData); |
|
1921 |
} |
|
1922 |
||
1923 |
/*! |
|
1924 |
\reimp |
|
1925 |
*/ |
|
1926 |
void QRasterPaintEngine::fillRect(const QRectF &r, const QColor &color) |
|
1927 |
{ |
|
1928 |
#ifdef QT_DEBUG_DRAW |
|
1929 |
qDebug() << "QRasterPaintEngine::fillRect(): " << r << color; |
|
1930 |
#endif |
|
1931 |
Q_D(QRasterPaintEngine); |
|
1932 |
QRasterPaintEngineState *s = state(); |
|
1933 |
||
1934 |
d->solid_color_filler.solid.color = PREMUL(ARGB_COMBINE_ALPHA(color.rgba(), s->intOpacity)); |
|
1935 |
if ((d->solid_color_filler.solid.color & 0xff000000) == 0 |
|
1936 |
&& s->composition_mode == QPainter::CompositionMode_SourceOver) { |
|
1937 |
return; |
|
1938 |
} |
|
1939 |
d->solid_color_filler.clip = d->clip(); |
|
1940 |
d->solid_color_filler.adjustSpanMethods(); |
|
1941 |
fillRect(r, &d->solid_color_filler); |
|
1942 |
} |
|
1943 |
||
1944 |
static inline bool isAbove(const QPointF *a, const QPointF *b) |
|
1945 |
{ |
|
1946 |
return a->y() < b->y(); |
|
1947 |
} |
|
1948 |
||
1949 |
static bool splitPolygon(const QPointF *points, int pointCount, QVector<QPointF> *upper, QVector<QPointF> *lower) |
|
1950 |
{ |
|
1951 |
Q_ASSERT(upper); |
|
1952 |
Q_ASSERT(lower); |
|
1953 |
||
1954 |
Q_ASSERT(pointCount >= 2); |
|
1955 |
||
1956 |
QVector<const QPointF *> sorted; |
|
1957 |
sorted.reserve(pointCount); |
|
1958 |
||
1959 |
upper->reserve(pointCount * 3 / 4); |
|
1960 |
lower->reserve(pointCount * 3 / 4); |
|
1961 |
||
1962 |
for (int i = 0; i < pointCount; ++i) |
|
1963 |
sorted << points + i; |
|
1964 |
||
1965 |
qSort(sorted.begin(), sorted.end(), isAbove); |
|
1966 |
||
1967 |
qreal splitY = sorted.at(sorted.size() / 2)->y(); |
|
1968 |
||
1969 |
const QPointF *end = points + pointCount; |
|
1970 |
const QPointF *last = end - 1; |
|
1971 |
||
1972 |
QVector<QPointF> *bin[2] = { upper, lower }; |
|
1973 |
||
1974 |
for (const QPointF *p = points; p < end; ++p) { |
|
1975 |
int side = p->y() < splitY; |
|
1976 |
int lastSide = last->y() < splitY; |
|
1977 |
||
1978 |
if (side != lastSide) { |
|
1979 |
if (qFuzzyCompare(p->y(), splitY)) { |
|
1980 |
bin[!side]->append(*p); |
|
1981 |
} else if (qFuzzyCompare(last->y(), splitY)) { |
|
1982 |
bin[side]->append(*last); |
|
1983 |
} else { |
|
1984 |
QPointF delta = *p - *last; |
|
1985 |
QPointF intersection(p->x() + delta.x() * (splitY - p->y()) / delta.y(), splitY); |
|
1986 |
||
1987 |
bin[0]->append(intersection); |
|
1988 |
bin[1]->append(intersection); |
|
1989 |
} |
|
1990 |
} |
|
1991 |
||
1992 |
bin[side]->append(*p); |
|
1993 |
||
1994 |
last = p; |
|
1995 |
} |
|
1996 |
||
1997 |
// give up if we couldn't reduce the point count |
|
1998 |
return upper->size() < pointCount && lower->size() < pointCount; |
|
1999 |
} |
|
2000 |
||
2001 |
/*! |
|
2002 |
\internal |
|
2003 |
*/ |
|
2004 |
void QRasterPaintEngine::fillPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) |
|
2005 |
{ |
|
2006 |
Q_D(QRasterPaintEngine); |
|
2007 |
QRasterPaintEngineState *s = state(); |
|
2008 |
||
2009 |
const int maxPoints = 0xffff; |
|
2010 |
||
2011 |
// max amount of points that raster engine can reliably handle |
|
2012 |
if (pointCount > maxPoints) { |
|
2013 |
QVector<QPointF> upper, lower; |
|
2014 |
||
2015 |
if (splitPolygon(points, pointCount, &upper, &lower)) { |
|
2016 |
fillPolygon(upper.constData(), upper.size(), mode); |
|
2017 |
fillPolygon(lower.constData(), lower.size(), mode); |
|
2018 |
} else |
|
2019 |
qWarning("Polygon too complex for filling."); |
|
2020 |
||
2021 |
return; |
|
2022 |
} |
|
2023 |
||
2024 |
// Compose polygon fill.., |
|
2025 |
QVectorPath vp((qreal *) points, pointCount, 0, QVectorPath::polygonFlags(mode)); |
|
2026 |
ensureOutlineMapper(); |
|
2027 |
QT_FT_Outline *outline = d->outlineMapper->convertPath(vp); |
|
2028 |
||
2029 |
// scanconvert. |
|
2030 |
ProcessSpans brushBlend = d->getBrushFunc(d->outlineMapper->controlPointRect, |
|
2031 |
&s->brushData); |
|
2032 |
d->rasterize(outline, brushBlend, &s->brushData, d->rasterBuffer.data()); |
|
2033 |
} |
|
2034 |
||
2035 |
/*! |
|
2036 |
\reimp |
|
2037 |
*/ |
|
2038 |
void QRasterPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) |
|
2039 |
{ |
|
2040 |
Q_D(QRasterPaintEngine); |
|
2041 |
QRasterPaintEngineState *s = state(); |
|
2042 |
||
2043 |
#ifdef QT_DEBUG_DRAW |
|
2044 |
qDebug(" - QRasterPaintEngine::drawPolygon(F), pointCount=%d", pointCount); |
|
2045 |
for (int i=0; i<pointCount; ++i) |
|
2046 |
qDebug() << " - " << points[i]; |
|
2047 |
#endif |
|
2048 |
Q_ASSERT(pointCount >= 2); |
|
2049 |
||
2050 |
if (mode != PolylineMode && isRect((qreal *) points, pointCount)) { |
|
2051 |
QRectF r(points[0], points[2]); |
|
2052 |
drawRects(&r, 1); |
|
2053 |
return; |
|
2054 |
} |
|
2055 |
||
2056 |
ensurePen(); |
|
2057 |
ensureBrush(); |
|
2058 |
if (mode != PolylineMode) { |
|
2059 |
// Do the fill... |
|
2060 |
if (s->brushData.blend) { |
|
2061 |
d->outlineMapper->setCoordinateRounding(s->penData.blend && s->flags.fast_pen && s->lastPen.brush().isOpaque()); |
|
2062 |
fillPolygon(points, pointCount, mode); |
|
2063 |
d->outlineMapper->setCoordinateRounding(false); |
|
2064 |
} |
|
2065 |
} |
|
2066 |
||
2067 |
// Do the outline... |
|
2068 |
if (s->penData.blend) { |
|
2069 |
if (s->flags.fast_pen && s->lastPen.brush().isOpaque()) |
|
2070 |
strokePolygonCosmetic(points, pointCount, mode); |
|
2071 |
else { |
|
2072 |
QVectorPath vp((qreal *) points, pointCount, 0, QVectorPath::polygonFlags(mode)); |
|
2073 |
QPaintEngineEx::stroke(vp, s->lastPen); |
|
2074 |
} |
|
2075 |
} |
|
2076 |
} |
|
2077 |
||
2078 |
/*! |
|
2079 |
\reimp |
|
2080 |
*/ |
|
2081 |
void QRasterPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) |
|
2082 |
{ |
|
2083 |
Q_D(QRasterPaintEngine); |
|
2084 |
QRasterPaintEngineState *s = state(); |
|
2085 |
||
2086 |
#ifdef QT_DEBUG_DRAW |
|
2087 |
qDebug(" - QRasterPaintEngine::drawPolygon(I), pointCount=%d", pointCount); |
|
2088 |
for (int i=0; i<pointCount; ++i) |
|
2089 |
qDebug() << " - " << points[i]; |
|
2090 |
#endif |
|
2091 |
Q_ASSERT(pointCount >= 2); |
|
2092 |
if (mode != PolylineMode && isRect((int *) points, pointCount)) { |
|
2093 |
QRect r(points[0].x(), |
|
2094 |
points[0].y(), |
|
2095 |
points[2].x() - points[0].x(), |
|
2096 |
points[2].y() - points[0].y()); |
|
2097 |
drawRects(&r, 1); |
|
2098 |
return; |
|
2099 |
} |
|
2100 |
||
2101 |
ensureState(); |
|
2102 |
ensurePen(); |
|
2103 |
if (!(s->flags.int_xform && s->flags.fast_pen && (!s->penData.blend || s->pen.brush().isOpaque()))) { |
|
2104 |
// this calls the float version |
|
2105 |
QPaintEngineEx::drawPolygon(points, pointCount, mode); |
|
2106 |
return; |
|
2107 |
} |
|
2108 |
||
2109 |
// Do the fill |
|
2110 |
if (mode != PolylineMode) { |
|
2111 |
ensureBrush(); |
|
2112 |
if (s->brushData.blend) { |
|
2113 |
// Compose polygon fill.., |
|
2114 |
ensureOutlineMapper(); |
|
2115 |
d->outlineMapper->setCoordinateRounding(s->penData.blend != 0); |
|
2116 |
d->outlineMapper->beginOutline(mode == WindingMode ? Qt::WindingFill : Qt::OddEvenFill); |
|
2117 |
d->outlineMapper->moveTo(*points); |
|
2118 |
const QPoint *p = points; |
|
2119 |
const QPoint *ep = points + pointCount - 1; |
|
2120 |
do { |
|
2121 |
d->outlineMapper->lineTo(*(++p)); |
|
2122 |
} while (p < ep); |
|
2123 |
d->outlineMapper->endOutline(); |
|
2124 |
||
2125 |
// scanconvert. |
|
2126 |
ProcessSpans brushBlend = d->getBrushFunc(d->outlineMapper->controlPointRect, |
|
2127 |
&s->brushData); |
|
2128 |
d->rasterize(d->outlineMapper->outline(), brushBlend, &s->brushData, d->rasterBuffer.data()); |
|
2129 |
d->outlineMapper->setCoordinateRounding(false); |
|
2130 |
} |
|
2131 |
} |
|
2132 |
||
2133 |
// Do the outline... |
|
2134 |
if (s->penData.blend) { |
|
2135 |
if (s->flags.fast_pen && s->lastPen.brush().isOpaque()) |
|
2136 |
strokePolygonCosmetic(points, pointCount, mode); |
|
2137 |
else { |
|
2138 |
int count = pointCount * 2; |
|
2139 |
QVarLengthArray<qreal> fpoints(count); |
|
2140 |
#ifdef Q_WS_MAC |
|
2141 |
for (int i=0; i<count; i+=2) { |
|
2142 |
fpoints[i] = ((int *) points)[i+1]; |
|
2143 |
fpoints[i+1] = ((int *) points)[i]; |
|
2144 |
} |
|
2145 |
#else |
|
2146 |
for (int i=0; i<count; ++i) |
|
2147 |
fpoints[i] = ((int *) points)[i]; |
|
2148 |
#endif |
|
2149 |
QVectorPath vp((qreal *) fpoints.data(), pointCount, 0, QVectorPath::polygonFlags(mode)); |
|
2150 |
QPaintEngineEx::stroke(vp, s->lastPen); |
|
2151 |
} |
|
2152 |
} |
|
2153 |
} |
|
2154 |
||
2155 |
/*! |
|
2156 |
\internal |
|
2157 |
*/ |
|
2158 |
void QRasterPaintEngine::strokePolygonCosmetic(const QPointF *points, int pointCount, PolygonDrawMode mode) |
|
2159 |
{ |
|
2160 |
Q_D(QRasterPaintEngine); |
|
2161 |
QRasterPaintEngineState *s = state(); |
|
2162 |
||
2163 |
Q_ASSERT(s->penData.blend); |
|
2164 |
Q_ASSERT(s->flags.fast_pen); |
|
2165 |
||
2166 |
bool needs_closing = mode != PolylineMode && points[0] != points[pointCount-1]; |
|
2167 |
||
2168 |
// Use fast path for 0 width / trivial pens. |
|
2169 |
QIntRect devRect; |
|
2170 |
devRect.set(d->deviceRect); |
|
2171 |
||
2172 |
LineDrawMode mode_for_last = (s->lastPen.capStyle() != Qt::FlatCap |
|
2173 |
? LineDrawIncludeLastPixel |
|
2174 |
: LineDrawNormal); |
|
2175 |
int dashOffset = int(s->lastPen.dashOffset()); |
|
2176 |
||
2177 |
const QPointF offs(aliasedCoordinateDelta, aliasedCoordinateDelta); |
|
2178 |
||
2179 |
// Draw all the line segments. |
|
2180 |
for (int i=1; i<pointCount; ++i) { |
|
2181 |
||
2182 |
QPointF lp1 = points[i-1] * s->matrix + offs; |
|
2183 |
QPointF lp2 = points[i] * s->matrix + offs; |
|
2184 |
||
2185 |
const QRectF brect(lp1, lp2); |
|
2186 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
2187 |
if (qpen_style(s->lastPen) == Qt::SolidLine) { |
|
2188 |
drawLine_midpoint_i(qFloor(lp1.x()), qFloor(lp1.y()), |
|
2189 |
qFloor(lp2.x()), qFloor(lp2.y()), |
|
2190 |
penBlend, &s->penData, |
|
2191 |
i == pointCount - 1 ? mode_for_last : LineDrawIncludeLastPixel, |
|
2192 |
devRect); |
|
2193 |
} else { |
|
2194 |
drawLine_midpoint_dashed_i(qFloor(lp1.x()), qFloor(lp1.y()), |
|
2195 |
qFloor(lp2.x()), qFloor(lp2.y()), |
|
2196 |
&s->lastPen, |
|
2197 |
penBlend, &s->penData, |
|
2198 |
i == pointCount - 1 ? mode_for_last : LineDrawIncludeLastPixel, |
|
2199 |
devRect, &dashOffset); |
|
2200 |
} |
|
2201 |
} |
|
2202 |
||
2203 |
// Polygons are implicitly closed. |
|
2204 |
if (needs_closing) { |
|
2205 |
QPointF lp1 = points[pointCount-1] * s->matrix + offs; |
|
2206 |
QPointF lp2 = points[0] * s->matrix + offs; |
|
2207 |
||
2208 |
const QRectF brect(lp1, lp2); |
|
2209 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
2210 |
if (qpen_style(s->lastPen) == Qt::SolidLine) { |
|
2211 |
drawLine_midpoint_i(qFloor(lp1.x()), qFloor(lp1.y()), |
|
2212 |
qFloor(lp2.x()), qFloor(lp2.y()), |
|
2213 |
penBlend, &s->penData, |
|
2214 |
LineDrawIncludeLastPixel, |
|
2215 |
devRect); |
|
2216 |
} else { |
|
2217 |
drawLine_midpoint_dashed_i(qFloor(lp1.x()), qFloor(lp1.y()), |
|
2218 |
qFloor(lp2.x()), qFloor(lp2.y()), |
|
2219 |
&s->lastPen, |
|
2220 |
penBlend, &s->penData, |
|
2221 |
LineDrawIncludeLastPixel, |
|
2222 |
devRect, &dashOffset); |
|
2223 |
} |
|
2224 |
} |
|
2225 |
||
2226 |
} |
|
2227 |
||
2228 |
/*! |
|
2229 |
\internal |
|
2230 |
*/ |
|
2231 |
void QRasterPaintEngine::strokePolygonCosmetic(const QPoint *points, int pointCount, PolygonDrawMode mode) |
|
2232 |
{ |
|
2233 |
Q_D(QRasterPaintEngine); |
|
2234 |
QRasterPaintEngineState *s = state(); |
|
2235 |
||
2236 |
// We assert here because this function is called from drawRects |
|
2237 |
// and drawPolygon and they already do ensurePen(), so we skip that |
|
2238 |
// here to avoid duplicate checks.. |
|
2239 |
Q_ASSERT(s->penData.blend); |
|
2240 |
||
2241 |
bool needs_closing = mode != PolylineMode && points[0] != points[pointCount-1]; |
|
2242 |
||
2243 |
QIntRect devRect; |
|
2244 |
devRect.set(d->deviceRect); |
|
2245 |
||
2246 |
LineDrawMode mode_for_last = (s->lastPen.capStyle() != Qt::FlatCap |
|
2247 |
? LineDrawIncludeLastPixel |
|
2248 |
: LineDrawNormal); |
|
2249 |
||
2250 |
int m11 = int(s->matrix.m11()); |
|
2251 |
int m22 = int(s->matrix.m22()); |
|
2252 |
int dx = int(s->matrix.dx()); |
|
2253 |
int dy = int(s->matrix.dy()); |
|
2254 |
int m13 = int(s->matrix.m13()); |
|
2255 |
int m23 = int(s->matrix.m23()); |
|
2256 |
bool affine = !m13 && !m23; |
|
2257 |
||
2258 |
int dashOffset = int(s->lastPen.dashOffset()); |
|
2259 |
||
2260 |
if (affine) { |
|
2261 |
// Draw all the line segments. |
|
2262 |
for (int i=1; i<pointCount; ++i) { |
|
2263 |
const QPoint lp1 = points[i-1] * s->matrix; |
|
2264 |
const QPoint lp2 = points[i] * s->matrix; |
|
2265 |
const QRect brect(lp1, lp2); |
|
2266 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
2267 |
||
2268 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
2269 |
drawLine_midpoint_i(lp1.x(), lp1.y(), |
|
2270 |
lp2.x(), lp2.y(), |
|
2271 |
penBlend, &s->penData, |
|
2272 |
i == pointCount - 1 ? mode_for_last : LineDrawIncludeLastPixel, |
|
2273 |
devRect); |
|
2274 |
else |
|
2275 |
drawLine_midpoint_dashed_i(lp1.x(), lp1.y(), |
|
2276 |
lp2.x(), lp2.y(), |
|
2277 |
&s->lastPen, |
|
2278 |
penBlend, &s->penData, |
|
2279 |
i == pointCount - 1 ? mode_for_last : LineDrawIncludeLastPixel, |
|
2280 |
devRect, &dashOffset); |
|
2281 |
||
2282 |
} |
|
2283 |
||
2284 |
// Polygons are implicitly closed. |
|
2285 |
if (needs_closing) { |
|
2286 |
const QPoint lp1 = points[pointCount - 1] * s->matrix; |
|
2287 |
const QPoint lp2 = points[0] * s->matrix; |
|
2288 |
const QRect brect(lp1, lp2); |
|
2289 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
2290 |
||
2291 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
2292 |
drawLine_midpoint_i(lp1.x(), lp1.y(), |
|
2293 |
lp2.x(), lp2.y(), |
|
2294 |
penBlend, &s->penData, LineDrawIncludeLastPixel, |
|
2295 |
devRect); |
|
2296 |
else |
|
2297 |
drawLine_midpoint_dashed_i(lp1.x(), lp1.y(), |
|
2298 |
lp2.x(), lp2.y(), |
|
2299 |
&s->lastPen, |
|
2300 |
penBlend, &s->penData, LineDrawIncludeLastPixel, |
|
2301 |
devRect, &dashOffset); |
|
2302 |
} |
|
2303 |
} else { |
|
2304 |
// Draw all the line segments. |
|
2305 |
for (int i=1; i<pointCount; ++i) { |
|
2306 |
int x1 = points[i-1].x() * m11 + dx; |
|
2307 |
int y1 = points[i-1].y() * m22 + dy; |
|
2308 |
qreal w = m13*points[i-1].x() + m23*points[i-1].y() + 1.; |
|
2309 |
w = 1/w; |
|
2310 |
x1 = int(x1*w); |
|
2311 |
y1 = int(y1*w); |
|
2312 |
int x2 = points[i].x() * m11 + dx; |
|
2313 |
int y2 = points[i].y() * m22 + dy; |
|
2314 |
w = m13*points[i].x() + m23*points[i].y() + 1.; |
|
2315 |
w = 1/w; |
|
2316 |
x2 = int(x2*w); |
|
2317 |
y2 = int(y2*w); |
|
2318 |
||
2319 |
const QRect brect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
|
2320 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
2321 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
2322 |
drawLine_midpoint_i(x1, y1, x2, y2, |
|
2323 |
penBlend, &s->penData, |
|
2324 |
i == pointCount - 1 ? mode_for_last : LineDrawIncludeLastPixel, |
|
2325 |
devRect); |
|
2326 |
else |
|
2327 |
drawLine_midpoint_dashed_i(x1, y1, x2, y2, |
|
2328 |
&s->lastPen, |
|
2329 |
penBlend, &s->penData, |
|
2330 |
i == pointCount - 1 ? mode_for_last : LineDrawIncludeLastPixel, |
|
2331 |
devRect, &dashOffset); |
|
2332 |
||
2333 |
} |
|
2334 |
||
2335 |
int x1 = points[pointCount-1].x() * m11 + dx; |
|
2336 |
int y1 = points[pointCount-1].y() * m22 + dy; |
|
2337 |
qreal w = m13*points[pointCount-1].x() + m23*points[pointCount-1].y() + 1.; |
|
2338 |
w = 1/w; |
|
2339 |
x1 = int(x1*w); |
|
2340 |
y1 = int(y1*w); |
|
2341 |
int x2 = points[0].x() * m11 + dx; |
|
2342 |
int y2 = points[0].y() * m22 + dy; |
|
2343 |
w = m13*points[0].x() + m23*points[0].y() + 1.; |
|
2344 |
w = 1/w; |
|
2345 |
x2 = int(x2 * w); |
|
2346 |
y2 = int(y2 * w); |
|
2347 |
// Polygons are implicitly closed. |
|
2348 |
||
2349 |
if (needs_closing) { |
|
2350 |
const QRect brect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
|
2351 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
2352 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
2353 |
drawLine_midpoint_i(x1, y1, x2, y2, |
|
2354 |
penBlend, &s->penData, LineDrawIncludeLastPixel, |
|
2355 |
devRect); |
|
2356 |
else |
|
2357 |
drawLine_midpoint_dashed_i(x1, y1, x2, y2, |
|
2358 |
&s->lastPen, |
|
2359 |
penBlend, &s->penData, LineDrawIncludeLastPixel, |
|
2360 |
devRect, &dashOffset); |
|
2361 |
} |
|
2362 |
} |
|
2363 |
} |
|
2364 |
||
2365 |
/*! |
|
2366 |
\internal |
|
2367 |
*/ |
|
2368 |
void QRasterPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pixmap) |
|
2369 |
{ |
|
2370 |
#ifdef QT_DEBUG_DRAW |
|
2371 |
qDebug() << " - QRasterPaintEngine::drawPixmap(), pos=" << pos << " pixmap=" << pixmap.size() << "depth=" << pixmap.depth(); |
|
2372 |
#endif |
|
2373 |
||
2374 |
if (pixmap.data->classId() == QPixmapData::RasterClass) { |
|
2375 |
const QImage &image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image; |
|
2376 |
if (image.depth() == 1) { |
|
2377 |
Q_D(QRasterPaintEngine); |
|
2378 |
QRasterPaintEngineState *s = state(); |
|
2379 |
if (s->matrix.type() <= QTransform::TxTranslate) { |
|
2380 |
ensurePen(); |
|
2381 |
drawBitmap(pos + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); |
|
2382 |
} else { |
|
2383 |
drawImage(pos, d->rasterBuffer->colorizeBitmap(image, s->pen.color())); |
|
2384 |
} |
|
2385 |
} else { |
|
2386 |
QRasterPaintEngine::drawImage(pos, image); |
|
2387 |
} |
|
2388 |
} else { |
|
2389 |
const QImage image = pixmap.toImage(); |
|
2390 |
if (pixmap.depth() == 1) { |
|
2391 |
Q_D(QRasterPaintEngine); |
|
2392 |
QRasterPaintEngineState *s = state(); |
|
2393 |
if (s->matrix.type() <= QTransform::TxTranslate) { |
|
2394 |
ensurePen(); |
|
2395 |
drawBitmap(pos + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); |
|
2396 |
} else { |
|
2397 |
drawImage(pos, d->rasterBuffer->colorizeBitmap(image, s->pen.color())); |
|
2398 |
} |
|
2399 |
} else { |
|
2400 |
QRasterPaintEngine::drawImage(pos, image); |
|
2401 |
} |
|
2402 |
} |
|
2403 |
} |
|
2404 |
||
2405 |
/*! |
|
2406 |
\reimp |
|
2407 |
*/ |
|
2408 |
void QRasterPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap, const QRectF &sr) |
|
2409 |
{ |
|
2410 |
#ifdef QT_DEBUG_DRAW |
|
2411 |
qDebug() << " - QRasterPaintEngine::drawPixmap(), r=" << r << " sr=" << sr << " pixmap=" << pixmap.size() << "depth=" << pixmap.depth(); |
|
2412 |
#endif |
|
2413 |
||
2414 |
if (pixmap.data->classId() == QPixmapData::RasterClass) { |
|
2415 |
const QImage &image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image; |
|
2416 |
if (image.depth() == 1) { |
|
2417 |
Q_D(QRasterPaintEngine); |
|
2418 |
QRasterPaintEngineState *s = state(); |
|
2419 |
if (s->matrix.type() <= QTransform::TxTranslate |
|
2420 |
&& r.size() == sr.size() |
|
2421 |
&& r.size() == pixmap.size()) { |
|
2422 |
ensurePen(); |
|
2423 |
drawBitmap(r.topLeft() + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); |
|
2424 |
return; |
|
2425 |
} else { |
|
2426 |
drawImage(r, d->rasterBuffer->colorizeBitmap(image, s->pen.color()), sr); |
|
2427 |
} |
|
2428 |
} else { |
|
2429 |
drawImage(r, image, sr); |
|
2430 |
} |
|
2431 |
} else { |
|
2432 |
const QImage image = pixmap.toImage(); |
|
2433 |
if (image.depth() == 1) { |
|
2434 |
Q_D(QRasterPaintEngine); |
|
2435 |
QRasterPaintEngineState *s = state(); |
|
2436 |
if (s->matrix.type() <= QTransform::TxTranslate |
|
2437 |
&& r.size() == sr.size() |
|
2438 |
&& r.size() == pixmap.size()) { |
|
2439 |
ensurePen(); |
|
2440 |
drawBitmap(r.topLeft() + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); |
|
2441 |
return; |
|
2442 |
} else { |
|
2443 |
drawImage(r, d->rasterBuffer->colorizeBitmap(image, s->pen.color()), sr); |
|
2444 |
} |
|
2445 |
} else { |
|
2446 |
drawImage(r, image, sr); |
|
2447 |
} |
|
2448 |
} |
|
2449 |
} |
|
2450 |
||
2451 |
// assumes that rect has positive width and height |
|
2452 |
static inline const QRect toRect_normalized(const QRectF &rect) |
|
2453 |
{ |
|
2454 |
const int x = qRound(rect.x()); |
|
2455 |
const int y = qRound(rect.y()); |
|
2456 |
const int w = int(rect.width() + qreal(0.5)); |
|
2457 |
const int h = int(rect.height() + qreal(0.5)); |
|
2458 |
||
2459 |
return QRect(x, y, w, h); |
|
2460 |
} |
|
2461 |
||
2462 |
static inline int fast_ceil_positive(const qreal &v) |
|
2463 |
{ |
|
2464 |
const int iv = int(v); |
|
2465 |
if (v - iv == 0) |
|
2466 |
return iv; |
|
2467 |
else |
|
2468 |
return iv + 1; |
|
2469 |
} |
|
2470 |
||
2471 |
static inline const QRect toAlignedRect_positive(const QRectF &rect) |
|
2472 |
{ |
|
2473 |
const int xmin = int(rect.x()); |
|
2474 |
const int xmax = int(fast_ceil_positive(rect.right())); |
|
2475 |
const int ymin = int(rect.y()); |
|
2476 |
const int ymax = int(fast_ceil_positive(rect.bottom())); |
|
2477 |
return QRect(xmin, ymin, xmax - xmin, ymax - ymin); |
|
2478 |
} |
|
2479 |
||
2480 |
/*! |
|
2481 |
\internal |
|
2482 |
*/ |
|
2483 |
void QRasterPaintEngine::drawImage(const QPointF &p, const QImage &img) |
|
2484 |
{ |
|
2485 |
#ifdef QT_DEBUG_DRAW |
|
2486 |
qDebug() << " - QRasterPaintEngine::drawImage(), p=" << p << " image=" << img.size() << "depth=" << img.depth(); |
|
2487 |
#endif |
|
2488 |
||
2489 |
Q_D(QRasterPaintEngine); |
|
2490 |
QRasterPaintEngineState *s = state(); |
|
2491 |
||
2492 |
if (s->matrix.type() > QTransform::TxTranslate) { |
|
2493 |
drawImage(QRectF(p.x(), p.y(), img.width(), img.height()), |
|
2494 |
img, |
|
2495 |
QRectF(0, 0, img.width(), img.height())); |
|
2496 |
} else { |
|
2497 |
||
2498 |
const QClipData *clip = d->clip(); |
|
2499 |
QPointF pt(p.x() + s->matrix.dx(), p.y() + s->matrix.dy()); |
|
2500 |
||
2501 |
if (s->flags.fast_images) { |
|
2502 |
SrcOverBlendFunc func = qBlendFunctions[d->rasterBuffer->format][img.format()]; |
|
2503 |
if (func) { |
|
2504 |
if (!clip) { |
|
2505 |
d->drawImage(pt, img, func, d->deviceRect, s->intOpacity); |
|
2506 |
return; |
|
2507 |
} else if (clip->hasRectClip) { |
|
2508 |
d->drawImage(pt, img, func, clip->clipRect, s->intOpacity); |
|
2509 |
return; |
|
2510 |
} |
|
2511 |
} |
|
2512 |
} |
|
2513 |
||
2514 |
||
2515 |
||
2516 |
d->image_filler.clip = clip; |
|
2517 |
d->image_filler.initTexture(&img, s->intOpacity, QTextureData::Plain, img.rect()); |
|
2518 |
if (!d->image_filler.blend) |
|
2519 |
return; |
|
2520 |
d->image_filler.dx = -pt.x(); |
|
2521 |
d->image_filler.dy = -pt.y(); |
|
2522 |
QRect rr = img.rect().translated(qRound(pt.x()), qRound(pt.y())); |
|
2523 |
||
2524 |
fillRect_normalized(rr, &d->image_filler, d); |
|
2525 |
} |
|
2526 |
||
2527 |
} |
|
2528 |
||
2529 |
QRectF qt_mapRect_non_normalizing(const QRectF &r, const QTransform &t) |
|
2530 |
{ |
|
2531 |
return QRectF(r.topLeft() * t, r.bottomRight() * t); |
|
2532 |
} |
|
2533 |
||
2534 |
/*! |
|
2535 |
\reimp |
|
2536 |
*/ |
|
2537 |
void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRectF &sr, |
|
2538 |
Qt::ImageConversionFlags) |
|
2539 |
{ |
|
2540 |
#ifdef QT_DEBUG_DRAW |
|
2541 |
qDebug() << " - QRasterPaintEngine::drawImage(), r=" << r << " sr=" << sr << " image=" << img.size() << "depth=" << img.depth(); |
|
2542 |
#endif |
|
2543 |
||
2544 |
if (r.isEmpty()) |
|
2545 |
return; |
|
2546 |
||
2547 |
Q_D(QRasterPaintEngine); |
|
2548 |
QRasterPaintEngineState *s = state(); |
|
2549 |
int sr_l = qFloor(sr.left()); |
|
2550 |
int sr_r = qCeil(sr.right()) - 1; |
|
2551 |
int sr_t = qFloor(sr.top()); |
|
2552 |
int sr_b = qCeil(sr.bottom()) - 1; |
|
2553 |
||
2554 |
if (!s->flags.antialiased && sr_l == sr_r && sr_t == sr_b) { |
|
2555 |
// as fillRect will apply the aliased coordinate delta we need to |
|
2556 |
// subtract it here as we don't use it for image drawing |
|
2557 |
QTransform old = s->matrix; |
|
2558 |
s->matrix = s->matrix * QTransform::fromTranslate(-aliasedCoordinateDelta, -aliasedCoordinateDelta); |
|
2559 |
||
2560 |
// Do whatever fillRect() does, but without premultiplying the color if it's already premultiplied. |
|
2561 |
QRgb color = img.pixel(sr_l, sr_t); |
|
2562 |
switch (img.format()) { |
|
2563 |
case QImage::Format_ARGB32_Premultiplied: |
|
2564 |
case QImage::Format_ARGB8565_Premultiplied: |
|
2565 |
case QImage::Format_ARGB6666_Premultiplied: |
|
2566 |
case QImage::Format_ARGB8555_Premultiplied: |
|
2567 |
case QImage::Format_ARGB4444_Premultiplied: |
|
2568 |
// Combine premultiplied color with the opacity set on the painter. |
|
2569 |
d->solid_color_filler.solid.color = |
|
2570 |
((((color & 0x00ff00ff) * s->intOpacity) >> 8) & 0x00ff00ff) |
|
2571 |
| ((((color & 0xff00ff00) >> 8) * s->intOpacity) & 0xff00ff00); |
|
2572 |
break; |
|
2573 |
default: |
|
2574 |
d->solid_color_filler.solid.color = PREMUL(ARGB_COMBINE_ALPHA(color, s->intOpacity)); |
|
2575 |
break; |
|
2576 |
} |
|
2577 |
||
2578 |
if ((d->solid_color_filler.solid.color & 0xff000000) == 0 |
|
2579 |
&& s->composition_mode == QPainter::CompositionMode_SourceOver) { |
|
2580 |
return; |
|
2581 |
} |
|
2582 |
||
2583 |
d->solid_color_filler.clip = d->clip(); |
|
2584 |
d->solid_color_filler.adjustSpanMethods(); |
|
2585 |
fillRect(r, &d->solid_color_filler); |
|
2586 |
||
2587 |
s->matrix = old; |
|
2588 |
return; |
|
2589 |
} |
|
2590 |
||
2591 |
bool stretch_sr = r.width() != sr.width() || r.height() != sr.height(); |
|
2592 |
||
2593 |
const QClipData *clip = d->clip(); |
|
2594 |
||
2595 |
if (s->matrix.type() > QTransform::TxTranslate || stretch_sr) { |
|
2596 |
||
2597 |
if (s->flags.fast_images) { |
|
2598 |
if (s->matrix.type() > QTransform::TxScale) { |
|
2599 |
SrcOverTransformFunc func = qTransformFunctions[d->rasterBuffer->format][img.format()]; |
|
2600 |
if (func && (!clip || clip->hasRectClip)) { |
|
2601 |
func(d->rasterBuffer->buffer(), d->rasterBuffer->bytesPerLine(), img.bits(), |
|
2602 |
img.bytesPerLine(), r, sr, !clip ? d->deviceRect : clip->clipRect, |
|
2603 |
s->matrix, s->intOpacity); |
|
2604 |
return; |
|
2605 |
} |
|
2606 |
} else { |
|
2607 |
SrcOverScaleFunc func = qScaleFunctions[d->rasterBuffer->format][img.format()]; |
|
2608 |
if (func && (!clip || clip->hasRectClip)) { |
|
2609 |
func(d->rasterBuffer->buffer(), d->rasterBuffer->bytesPerLine(), |
|
2610 |
img.bits(), img.bytesPerLine(), |
|
2611 |
qt_mapRect_non_normalizing(r, s->matrix), sr, |
|
2612 |
!clip ? d->deviceRect : clip->clipRect, |
|
2613 |
s->intOpacity); |
|
2614 |
return; |
|
2615 |
} |
|
2616 |
} |
|
2617 |
} |
|
2618 |
||
2619 |
QTransform copy = s->matrix; |
|
2620 |
copy.translate(r.x(), r.y()); |
|
2621 |
if (stretch_sr) |
|
2622 |
copy.scale(r.width() / sr.width(), r.height() / sr.height()); |
|
2623 |
copy.translate(-sr.x(), -sr.y()); |
|
2624 |
||
2625 |
d->image_filler_xform.clip = clip; |
|
2626 |
d->image_filler_xform.initTexture(&img, s->intOpacity, QTextureData::Plain, toAlignedRect_positive(sr)); |
|
2627 |
if (!d->image_filler_xform.blend) |
|
2628 |
return; |
|
2629 |
d->image_filler_xform.setupMatrix(copy, s->flags.bilinear); |
|
2630 |
||
2631 |
if (!s->flags.antialiased && s->matrix.type() == QTransform::TxScale) { |
|
2632 |
QRectF rr = s->matrix.mapRect(r); |
|
2633 |
||
2634 |
const int x1 = qRound(rr.x()); |
|
2635 |
const int y1 = qRound(rr.y()); |
|
2636 |
const int x2 = qRound(rr.right()); |
|
2637 |
const int y2 = qRound(rr.bottom()); |
|
2638 |
||
2639 |
fillRect_normalized(QRect(x1, y1, x2-x1, y2-y1), &d->image_filler_xform, d); |
|
2640 |
return; |
|
2641 |
} |
|
2642 |
||
2643 |
#ifdef QT_FAST_SPANS |
|
2644 |
ensureState(); |
|
2645 |
if (s->flags.tx_noshear || s->matrix.type() == QTransform::TxScale) { |
|
2646 |
d->initializeRasterizer(&d->image_filler_xform); |
|
2647 |
d->rasterizer->setAntialiased(s->flags.antialiased); |
|
2648 |
||
2649 |
const QPointF offs = s->flags.antialiased ? QPointF() : QPointF(aliasedCoordinateDelta, aliasedCoordinateDelta); |
|
2650 |
||
2651 |
const QRectF &rect = r.normalized(); |
|
2652 |
const QPointF a = s->matrix.map((rect.topLeft() + rect.bottomLeft()) * 0.5f) - offs; |
|
2653 |
const QPointF b = s->matrix.map((rect.topRight() + rect.bottomRight()) * 0.5f) - offs; |
|
2654 |
||
2655 |
if (s->flags.tx_noshear) |
|
2656 |
d->rasterizer->rasterizeLine(a, b, rect.height() / rect.width()); |
|
2657 |
else |
|
2658 |
d->rasterizer->rasterizeLine(a, b, qAbs((s->matrix.m22() * rect.height()) / (s->matrix.m11() * rect.width()))); |
|
2659 |
return; |
|
2660 |
} |
|
2661 |
#endif |
|
2662 |
const qreal offs = s->flags.antialiased ? qreal(0) : aliasedCoordinateDelta; |
|
2663 |
QPainterPath path; |
|
2664 |
path.addRect(r); |
|
2665 |
QTransform m = s->matrix; |
|
2666 |
s->matrix = QTransform(m.m11(), m.m12(), m.m13(), |
|
2667 |
m.m21(), m.m22(), m.m23(), |
|
2668 |
m.m31() - offs, m.m32() - offs, m.m33()); |
|
2669 |
fillPath(path, &d->image_filler_xform); |
|
2670 |
s->matrix = m; |
|
2671 |
} else { |
|
2672 |
||
2673 |
if (s->flags.fast_images) { |
|
2674 |
SrcOverBlendFunc func = qBlendFunctions[d->rasterBuffer->format][img.format()]; |
|
2675 |
if (func) { |
|
2676 |
QPointF pt(r.x() + s->matrix.dx(), r.y() + s->matrix.dy()); |
|
2677 |
if (!clip) { |
|
2678 |
d->drawImage(pt, img, func, d->deviceRect, s->intOpacity, sr.toRect()); |
|
2679 |
return; |
|
2680 |
} else if (clip->hasRectClip) { |
|
2681 |
d->drawImage(pt, img, func, clip->clipRect, s->intOpacity, sr.toRect()); |
|
2682 |
return; |
|
2683 |
} |
|
2684 |
} |
|
2685 |
} |
|
2686 |
||
2687 |
d->image_filler.clip = clip; |
|
2688 |
d->image_filler.initTexture(&img, s->intOpacity, QTextureData::Plain, toAlignedRect_positive(sr)); |
|
2689 |
if (!d->image_filler.blend) |
|
2690 |
return; |
|
2691 |
d->image_filler.dx = -(r.x() + s->matrix.dx()) + sr.x(); |
|
2692 |
d->image_filler.dy = -(r.y() + s->matrix.dy()) + sr.y(); |
|
2693 |
||
2694 |
QRectF rr = r; |
|
2695 |
rr.translate(s->matrix.dx(), s->matrix.dy()); |
|
2696 |
||
2697 |
const int x1 = qRound(rr.x()); |
|
2698 |
const int y1 = qRound(rr.y()); |
|
2699 |
const int x2 = qRound(rr.right()); |
|
2700 |
const int y2 = qRound(rr.bottom()); |
|
2701 |
||
2702 |
fillRect_normalized(QRect(x1, y1, x2-x1, y2-y1), &d->image_filler, d); |
|
2703 |
} |
|
2704 |
} |
|
2705 |
||
2706 |
/*! |
|
2707 |
\reimp |
|
2708 |
*/ |
|
2709 |
void QRasterPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &sr) |
|
2710 |
{ |
|
2711 |
#ifdef QT_DEBUG_DRAW |
|
2712 |
qDebug() << " - QRasterPaintEngine::drawTiledPixmap(), r=" << r << "pixmap=" << pixmap.size(); |
|
2713 |
#endif |
|
2714 |
Q_D(QRasterPaintEngine); |
|
2715 |
QRasterPaintEngineState *s = state(); |
|
2716 |
||
2717 |
QImage image; |
|
2718 |
||
2719 |
if (pixmap.data->classId() == QPixmapData::RasterClass) { |
|
2720 |
image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image; |
|
2721 |
} else { |
|
2722 |
image = pixmap.toImage(); |
|
2723 |
} |
|
2724 |
||
2725 |
if (image.depth() == 1) |
|
2726 |
image = d->rasterBuffer->colorizeBitmap(image, s->pen.color()); |
|
2727 |
||
2728 |
if (s->matrix.type() > QTransform::TxTranslate) { |
|
2729 |
QTransform copy = s->matrix; |
|
2730 |
copy.translate(r.x(), r.y()); |
|
2731 |
copy.translate(-sr.x(), -sr.y()); |
|
2732 |
d->image_filler_xform.clip = d->clip(); |
|
2733 |
d->image_filler_xform.initTexture(&image, s->intOpacity, QTextureData::Tiled); |
|
2734 |
if (!d->image_filler_xform.blend) |
|
2735 |
return; |
|
2736 |
d->image_filler_xform.setupMatrix(copy, s->flags.bilinear); |
|
2737 |
||
2738 |
#ifdef QT_FAST_SPANS |
|
2739 |
ensureState(); |
|
2740 |
if (s->flags.tx_noshear || s->matrix.type() == QTransform::TxScale) { |
|
2741 |
d->initializeRasterizer(&d->image_filler_xform); |
|
2742 |
d->rasterizer->setAntialiased(s->flags.antialiased); |
|
2743 |
||
2744 |
const QRectF &rect = r.normalized(); |
|
2745 |
const QPointF a = s->matrix.map((rect.topLeft() + rect.bottomLeft()) * 0.5f); |
|
2746 |
const QPointF b = s->matrix.map((rect.topRight() + rect.bottomRight()) * 0.5f); |
|
2747 |
if (s->flags.tx_noshear) |
|
2748 |
d->rasterizer->rasterizeLine(a, b, rect.height() / rect.width()); |
|
2749 |
else |
|
2750 |
d->rasterizer->rasterizeLine(a, b, qAbs((s->matrix.m22() * rect.height()) / (s->matrix.m11() * rect.width()))); |
|
2751 |
return; |
|
2752 |
} |
|
2753 |
#endif |
|
2754 |
QPainterPath path; |
|
2755 |
path.addRect(r); |
|
2756 |
fillPath(path, &d->image_filler_xform); |
|
2757 |
} else { |
|
2758 |
d->image_filler.clip = d->clip(); |
|
2759 |
||
2760 |
d->image_filler.initTexture(&image, s->intOpacity, QTextureData::Tiled); |
|
2761 |
if (!d->image_filler.blend) |
|
2762 |
return; |
|
2763 |
d->image_filler.dx = -(r.x() + s->matrix.dx()) + sr.x(); |
|
2764 |
d->image_filler.dy = -(r.y() + s->matrix.dy()) + sr.y(); |
|
2765 |
||
2766 |
QRectF rr = r; |
|
2767 |
rr.translate(s->matrix.dx(), s->matrix.dy()); |
|
2768 |
fillRect_normalized(rr.toRect().normalized(), &d->image_filler, d); |
|
2769 |
} |
|
2770 |
} |
|
2771 |
||
2772 |
||
2773 |
//QWS hack |
|
2774 |
static inline bool monoVal(const uchar* s, int x) |
|
2775 |
{ |
|
2776 |
return (s[x>>3] << (x&7)) & 0x80; |
|
2777 |
} |
|
2778 |
||
2779 |
/*! |
|
2780 |
\internal |
|
2781 |
*/ |
|
2782 |
void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h) |
|
2783 |
{ |
|
2784 |
Q_D(QRasterPaintEngine); |
|
2785 |
QRasterPaintEngineState *s = state(); |
|
2786 |
||
2787 |
if (!s->penData.blend) |
|
2788 |
return; |
|
2789 |
||
2790 |
QRasterBuffer *rb = d->rasterBuffer.data(); |
|
2791 |
||
2792 |
const QRect rect(rx, ry, w, h); |
|
2793 |
const QClipData *clip = d->clip(); |
|
2794 |
bool unclipped = false; |
|
2795 |
if (clip) { |
|
2796 |
// inlined QRect::intersects |
|
2797 |
const bool intersects = qMax(clip->xmin, rect.left()) <= qMin(clip->xmax - 1, rect.right()) |
|
2798 |
&& qMax(clip->ymin, rect.top()) <= qMin(clip->ymax - 1, rect.bottom()); |
|
2799 |
||
2800 |
if (clip->hasRectClip) { |
|
2801 |
unclipped = rx > clip->xmin |
|
2802 |
&& rx + w < clip->xmax |
|
2803 |
&& ry > clip->ymin |
|
2804 |
&& ry + h < clip->ymax; |
|
2805 |
} |
|
2806 |
||
2807 |
if (!intersects) |
|
2808 |
return; |
|
2809 |
} else { |
|
2810 |
// inlined QRect::intersects |
|
2811 |
const bool intersects = qMax(0, rect.left()) <= qMin(rb->width() - 1, rect.right()) |
|
2812 |
&& qMax(0, rect.top()) <= qMin(rb->height() - 1, rect.bottom()); |
|
2813 |
if (!intersects) |
|
2814 |
return; |
|
2815 |
||
2816 |
// inlined QRect::contains |
|
2817 |
const bool contains = rect.left() >= 0 && rect.right() < rb->width() |
|
2818 |
&& rect.top() >= 0 && rect.bottom() < rb->height(); |
|
2819 |
||
2820 |
unclipped = contains && d->isUnclipped_normalized(rect); |
|
2821 |
} |
|
2822 |
||
2823 |
ProcessSpans blend = unclipped ? s->penData.unclipped_blend : s->penData.blend; |
|
2824 |
const uchar * scanline = static_cast<const uchar *>(src); |
|
2825 |
||
2826 |
if (s->flags.fast_text) { |
|
2827 |
if (unclipped) { |
|
2828 |
if (depth == 1) { |
|
2829 |
if (s->penData.bitmapBlit) { |
|
2830 |
s->penData.bitmapBlit(rb, rx, ry, s->penData.solid.color, |
|
2831 |
scanline, w, h, bpl); |
|
2832 |
return; |
|
2833 |
} |
|
2834 |
} else if (depth == 8) { |
|
2835 |
if (s->penData.alphamapBlit) { |
|
2836 |
s->penData.alphamapBlit(rb, rx, ry, s->penData.solid.color, |
|
2837 |
scanline, w, h, bpl, 0); |
|
2838 |
return; |
|
2839 |
} |
|
2840 |
} else if (depth == 32) { |
|
2841 |
// (A)RGB Alpha mask where the alpha component is not used. |
|
2842 |
if (s->penData.alphaRGBBlit) { |
|
2843 |
s->penData.alphaRGBBlit(rb, rx, ry, s->penData.solid.color, |
|
2844 |
(const uint *) scanline, w, h, bpl / 4, 0); |
|
2845 |
return; |
|
2846 |
} |
|
2847 |
} |
|
2848 |
} else if (d->deviceDepth == 32 && (depth == 8 || depth == 32)) { |
|
2849 |
// (A)RGB Alpha mask where the alpha component is not used. |
|
2850 |
if (!clip) { |
|
2851 |
int nx = qMax(0, rx); |
|
2852 |
int ny = qMax(0, ry); |
|
2853 |
||
2854 |
// Move scanline pointer to compensate for moved x and y |
|
2855 |
int xdiff = nx - rx; |
|
2856 |
int ydiff = ny - ry; |
|
2857 |
scanline += ydiff * bpl; |
|
2858 |
scanline += xdiff * (depth == 32 ? 4 : 1); |
|
2859 |
||
2860 |
w -= xdiff; |
|
2861 |
h -= ydiff; |
|
2862 |
||
2863 |
if (nx + w > d->rasterBuffer->width()) |
|
2864 |
w = d->rasterBuffer->width() - nx; |
|
2865 |
if (ny + h > d->rasterBuffer->height()) |
|
2866 |
h = d->rasterBuffer->height() - ny; |
|
2867 |
||
2868 |
rx = nx; |
|
2869 |
ry = ny; |
|
2870 |
} |
|
2871 |
if (depth == 8 && s->penData.alphamapBlit) { |
|
2872 |
s->penData.alphamapBlit(rb, rx, ry, s->penData.solid.color, |
|
2873 |
scanline, w, h, bpl, clip); |
|
2874 |
} else if (depth == 32 && s->penData.alphaRGBBlit) { |
|
2875 |
s->penData.alphaRGBBlit(rb, rx, ry, s->penData.solid.color, |
|
2876 |
(const uint *) scanline, w, h, bpl / 4, clip); |
|
2877 |
} |
|
2878 |
return; |
|
2879 |
} |
|
2880 |
} |
|
2881 |
||
2882 |
int x0 = 0; |
|
2883 |
if (rx < 0) { |
|
2884 |
x0 = -rx; |
|
2885 |
w -= x0; |
|
2886 |
} |
|
2887 |
||
2888 |
int y0 = 0; |
|
2889 |
if (ry < 0) { |
|
2890 |
y0 = -ry; |
|
2891 |
scanline += bpl * y0; |
|
2892 |
h -= y0; |
|
2893 |
} |
|
2894 |
||
2895 |
w = qMin(w, rb->width() - qMax(0, rx)); |
|
2896 |
h = qMin(h, rb->height() - qMax(0, ry)); |
|
2897 |
||
2898 |
if (w <= 0 || h <= 0) |
|
2899 |
return; |
|
2900 |
||
2901 |
const int NSPANS = 256; |
|
2902 |
QSpan spans[NSPANS]; |
|
2903 |
int current = 0; |
|
2904 |
||
2905 |
const int x1 = x0 + w; |
|
2906 |
const int y1 = y0 + h; |
|
2907 |
||
2908 |
if (depth == 1) { |
|
2909 |
for (int y = y0; y < y1; ++y) { |
|
2910 |
for (int x = x0; x < x1; ) { |
|
2911 |
if (!monoVal(scanline, x)) { |
|
2912 |
++x; |
|
2913 |
continue; |
|
2914 |
} |
|
2915 |
||
2916 |
if (current == NSPANS) { |
|
2917 |
blend(current, spans, &s->penData); |
|
2918 |
current = 0; |
|
2919 |
} |
|
2920 |
spans[current].x = x + rx; |
|
2921 |
spans[current].y = y + ry; |
|
2922 |
spans[current].coverage = 255; |
|
2923 |
int len = 1; |
|
2924 |
++x; |
|
2925 |
// extend span until we find a different one. |
|
2926 |
while (x < x1 && monoVal(scanline, x)) { |
|
2927 |
++x; |
|
2928 |
++len; |
|
2929 |
} |
|
2930 |
spans[current].len = len; |
|
2931 |
++current; |
|
2932 |
} |
|
2933 |
scanline += bpl; |
|
2934 |
} |
|
2935 |
} else if (depth == 8) { |
|
2936 |
for (int y = y0; y < y1; ++y) { |
|
2937 |
for (int x = x0; x < x1; ) { |
|
2938 |
// Skip those with 0 coverage |
|
2939 |
if (scanline[x] == 0) { |
|
2940 |
++x; |
|
2941 |
continue; |
|
2942 |
} |
|
2943 |
||
2944 |
if (current == NSPANS) { |
|
2945 |
blend(current, spans, &s->penData); |
|
2946 |
current = 0; |
|
2947 |
} |
|
2948 |
int coverage = scanline[x]; |
|
2949 |
spans[current].x = x + rx; |
|
2950 |
spans[current].y = y + ry; |
|
2951 |
spans[current].coverage = coverage; |
|
2952 |
int len = 1; |
|
2953 |
++x; |
|
2954 |
||
2955 |
// extend span until we find a different one. |
|
2956 |
while (x < x1 && scanline[x] == coverage) { |
|
2957 |
++x; |
|
2958 |
++len; |
|
2959 |
} |
|
2960 |
spans[current].len = len; |
|
2961 |
++current; |
|
2962 |
} |
|
2963 |
scanline += bpl; |
|
2964 |
} |
|
2965 |
} else { // 32-bit alpha... |
|
2966 |
uint *sl = (uint *) src; |
|
2967 |
for (int y = y0; y < y1; ++y) { |
|
2968 |
for (int x = x0; x < x1; ) { |
|
2969 |
// Skip those with 0 coverage |
|
2970 |
if ((sl[x] & 0x00ffffff) == 0) { |
|
2971 |
++x; |
|
2972 |
continue; |
|
2973 |
} |
|
2974 |
||
2975 |
if (current == NSPANS) { |
|
2976 |
blend(current, spans, &s->penData); |
|
2977 |
current = 0; |
|
2978 |
} |
|
2979 |
uint rgbCoverage = sl[x]; |
|
2980 |
int coverage = qGreen(rgbCoverage); |
|
2981 |
spans[current].x = x + rx; |
|
2982 |
spans[current].y = y + ry; |
|
2983 |
spans[current].coverage = coverage; |
|
2984 |
int len = 1; |
|
2985 |
++x; |
|
2986 |
||
2987 |
// extend span until we find a different one. |
|
2988 |
while (x < x1 && sl[x] == rgbCoverage) { |
|
2989 |
++x; |
|
2990 |
++len; |
|
2991 |
} |
|
2992 |
spans[current].len = len; |
|
2993 |
++current; |
|
2994 |
} |
|
2995 |
sl += bpl / sizeof(uint); |
|
2996 |
} |
|
2997 |
} |
|
2998 |
// qDebug() << "alphaPenBlt: num spans=" << current |
|
2999 |
// << "span:" << spans->x << spans->y << spans->len << spans->coverage; |
|
3000 |
// Call span func for current set of spans. |
|
3001 |
if (current != 0) |
|
3002 |
blend(current, spans, &s->penData); |
|
3003 |
} |
|
3004 |
||
3005 |
void QRasterPaintEngine::drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti) |
|
3006 |
{ |
|
3007 |
Q_D(QRasterPaintEngine); |
|
3008 |
QRasterPaintEngineState *s = state(); |
|
3009 |
||
3010 |
QVarLengthArray<QFixedPoint> positions; |
|
3011 |
QVarLengthArray<glyph_t> glyphs; |
|
3012 |
QTransform matrix = s->matrix; |
|
3013 |
matrix.translate(p.x(), p.y()); |
|
3014 |
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
|
3015 |
||
3016 |
QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) : d->glyphCacheType; |
|
3017 |
||
3018 |
QImageTextureGlyphCache *cache = |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3019 |
(QImageTextureGlyphCache *) ti.fontEngine->glyphCache(0, glyphType, s->matrix); |
0 | 3020 |
if (!cache) { |
3021 |
cache = new QImageTextureGlyphCache(glyphType, s->matrix); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3022 |
ti.fontEngine->setGlyphCache(0, cache); |
0 | 3023 |
} |
3024 |
||
3025 |
cache->populate(ti, glyphs, positions); |
|
3026 |
||
3027 |
const QImage &image = cache->image(); |
|
3028 |
int bpl = image.bytesPerLine(); |
|
3029 |
||
3030 |
int depth = image.depth(); |
|
3031 |
int rightShift = 0; |
|
3032 |
int leftShift = 0; |
|
3033 |
if (depth == 32) |
|
3034 |
leftShift = 2; // multiply by 4 |
|
3035 |
else if (depth == 1) |
|
3036 |
rightShift = 3; // divide by 8 |
|
3037 |
||
3038 |
int margin = cache->glyphMargin(); |
|
3039 |
||
3040 |
const QFixed offs = QFixed::fromReal(aliasedCoordinateDelta); |
|
3041 |
||
3042 |
const uchar *bits = image.bits(); |
|
3043 |
for (int i=0; i<glyphs.size(); ++i) { |
|
3044 |
const QTextureGlyphCache::Coord &c = cache->coords.value(glyphs[i]); |
|
3045 |
int x = qFloor(positions[i].x + offs) + c.baseLineX - margin; |
|
3046 |
int y = qFloor(positions[i].y + offs) - c.baseLineY - margin; |
|
3047 |
||
3048 |
// printf("drawing [%d %d %d %d] baseline [%d %d], glyph: %d, to: %d %d, pos: %d %d\n", |
|
3049 |
// c.x, c.y, |
|
3050 |
// c.w, c.h, |
|
3051 |
// c.baseLineX, c.baseLineY, |
|
3052 |
// glyphs[i], |
|
3053 |
// x, y, |
|
3054 |
// positions[i].x.toInt(), positions[i].y.toInt()); |
|
3055 |
||
3056 |
alphaPenBlt(bits + ((c.x << leftShift) >> rightShift) + c.y * bpl, bpl, depth, x, y, c.w, c.h); |
|
3057 |
} |
|
3058 |
||
3059 |
return; |
|
3060 |
} |
|
3061 |
||
3062 |
#if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) |
|
3063 |
void QRasterPaintEngine::drawGlyphsS60(const QPointF &p, const QTextItemInt &ti) |
|
3064 |
{ |
|
3065 |
Q_D(QRasterPaintEngine); |
|
3066 |
QRasterPaintEngineState *s = state(); |
|
3067 |
||
3068 |
QFontEngine *fontEngine = ti.fontEngine; |
|
3069 |
if (fontEngine->type() != QFontEngine::S60FontEngine) { |
|
3070 |
QPaintEngineEx::drawTextItem(p, ti); |
|
3071 |
return; |
|
3072 |
} |
|
3073 |
||
3074 |
QFontEngineS60 *fe = static_cast<QFontEngineS60 *>(fontEngine); |
|
3075 |
||
3076 |
QVarLengthArray<QFixedPoint> positions; |
|
3077 |
QVarLengthArray<glyph_t> glyphs; |
|
3078 |
QTransform matrix = s->matrix; |
|
3079 |
matrix.translate(p.x(), p.y()); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3080 |
if (matrix.type() == QTransform::TxScale) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3081 |
fe->setFontScale(matrix.m11()); |
0 | 3082 |
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
3083 |
||
3084 |
const QFixed aliasDelta = QFixed::fromReal(aliasedCoordinateDelta); |
|
3085 |
||
3086 |
for (int i=0; i<glyphs.size(); ++i) { |
|
3087 |
TOpenFontCharMetrics tmetrics; |
|
3088 |
const TUint8 *glyphBitmapBytes; |
|
3089 |
TSize glyphBitmapSize; |
|
3090 |
fe->getCharacterData(glyphs[i], tmetrics, glyphBitmapBytes, glyphBitmapSize); |
|
3091 |
const glyph_metrics_t metrics = ti.fontEngine->boundingBox(glyphs[i]); |
|
3092 |
const int x = qFloor(positions[i].x + metrics.x + aliasDelta); |
|
3093 |
const int y = qFloor(positions[i].y + metrics.y + aliasDelta); |
|
3094 |
||
3095 |
alphaPenBlt(glyphBitmapBytes, glyphBitmapSize.iWidth, 8, x, y, glyphBitmapSize.iWidth, glyphBitmapSize.iHeight); |
|
3096 |
} |
|
3097 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3098 |
if (matrix.type() == QTransform::TxScale) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3099 |
fe->setFontScale(1.0); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3100 |
|
0 | 3101 |
return; |
3102 |
} |
|
3103 |
#endif // Q_OS_SYMBIAN && QT_NO_FREETYPE |
|
3104 |
||
3105 |
/*! |
|
3106 |
* Returns true if the rectangle is completly within the current clip |
|
3107 |
* state of the paint engine. |
|
3108 |
*/ |
|
3109 |
bool QRasterPaintEnginePrivate::isUnclipped_normalized(const QRect &r) const |
|
3110 |
{ |
|
3111 |
const QClipData *cl = clip(); |
|
3112 |
if (!cl) { |
|
3113 |
// inline contains() for performance (we know the rects are normalized) |
|
3114 |
const QRect &r1 = deviceRect; |
|
3115 |
return (r.left() >= r1.left() && r.right() <= r1.right() |
|
3116 |
&& r.top() >= r1.top() && r.bottom() <= r1.bottom()); |
|
3117 |
} |
|
3118 |
||
3119 |
||
3120 |
if (cl->hasRectClip) { |
|
3121 |
// currently all painting functions clips to deviceRect internally |
|
3122 |
if (cl->clipRect == deviceRect) |
|
3123 |
return true; |
|
3124 |
||
3125 |
// inline contains() for performance (we know the rects are normalized) |
|
3126 |
const QRect &r1 = cl->clipRect; |
|
3127 |
return (r.left() >= r1.left() && r.right() <= r1.right() |
|
3128 |
&& r.top() >= r1.top() && r.bottom() <= r1.bottom()); |
|
3129 |
} else { |
|
3130 |
return qt_region_strictContains(cl->clipRegion, r); |
|
3131 |
} |
|
3132 |
} |
|
3133 |
||
3134 |
bool QRasterPaintEnginePrivate::isUnclipped(const QRect &rect, |
|
3135 |
int penWidth) const |
|
3136 |
{ |
|
3137 |
Q_Q(const QRasterPaintEngine); |
|
3138 |
const QRasterPaintEngineState *s = q->state(); |
|
3139 |
const QClipData *cl = clip(); |
|
3140 |
if (!cl) { |
|
3141 |
QRect r = rect.normalized(); |
|
3142 |
// inline contains() for performance (we know the rects are normalized) |
|
3143 |
const QRect &r1 = deviceRect; |
|
3144 |
return (r.left() >= r1.left() && r.right() <= r1.right() |
|
3145 |
&& r.top() >= r1.top() && r.bottom() <= r1.bottom()); |
|
3146 |
} |
|
3147 |
||
3148 |
||
3149 |
// currently all painting functions that call this function clip to deviceRect internally |
|
3150 |
if (cl->hasRectClip && cl->clipRect == deviceRect) |
|
3151 |
return true; |
|
3152 |
||
3153 |
if (s->flags.antialiased) |
|
3154 |
++penWidth; |
|
3155 |
||
3156 |
QRect r = rect.normalized(); |
|
3157 |
if (penWidth > 0) { |
|
3158 |
r.setX(r.x() - penWidth); |
|
3159 |
r.setY(r.y() - penWidth); |
|
3160 |
r.setWidth(r.width() + 2 * penWidth); |
|
3161 |
r.setHeight(r.height() + 2 * penWidth); |
|
3162 |
} |
|
3163 |
||
3164 |
if (cl->hasRectClip) { |
|
3165 |
// inline contains() for performance (we know the rects are normalized) |
|
3166 |
const QRect &r1 = cl->clipRect; |
|
3167 |
return (r.left() >= r1.left() && r.right() <= r1.right() |
|
3168 |
&& r.top() >= r1.top() && r.bottom() <= r1.bottom()); |
|
3169 |
} else { |
|
3170 |
return qt_region_strictContains(cl->clipRegion, r); |
|
3171 |
} |
|
3172 |
} |
|
3173 |
||
3174 |
inline bool QRasterPaintEnginePrivate::isUnclipped(const QRectF &rect, |
|
3175 |
int penWidth) const |
|
3176 |
{ |
|
3177 |
return isUnclipped(rect.normalized().toAlignedRect(), penWidth); |
|
3178 |
} |
|
3179 |
||
3180 |
inline ProcessSpans |
|
3181 |
QRasterPaintEnginePrivate::getBrushFunc(const QRect &rect, |
|
3182 |
const QSpanData *data) const |
|
3183 |
{ |
|
3184 |
return isUnclipped(rect, 0) ? data->unclipped_blend : data->blend; |
|
3185 |
} |
|
3186 |
||
3187 |
inline ProcessSpans |
|
3188 |
QRasterPaintEnginePrivate::getBrushFunc(const QRectF &rect, |
|
3189 |
const QSpanData *data) const |
|
3190 |
{ |
|
3191 |
return isUnclipped(rect, 0) ? data->unclipped_blend : data->blend; |
|
3192 |
} |
|
3193 |
||
3194 |
inline ProcessSpans |
|
3195 |
QRasterPaintEnginePrivate::getPenFunc(const QRect &rect, |
|
3196 |
const QSpanData *data) const |
|
3197 |
{ |
|
3198 |
Q_Q(const QRasterPaintEngine); |
|
3199 |
const QRasterPaintEngineState *s = q->state(); |
|
3200 |
||
3201 |
if (!s->flags.fast_pen && s->matrix.type() > QTransform::TxTranslate) |
|
3202 |
return data->blend; |
|
3203 |
const int penWidth = s->flags.fast_pen ? 1 : qCeil(s->pen.widthF()); |
|
3204 |
return isUnclipped(rect, penWidth) ? data->unclipped_blend : data->blend; |
|
3205 |
} |
|
3206 |
||
3207 |
inline ProcessSpans |
|
3208 |
QRasterPaintEnginePrivate::getPenFunc(const QRectF &rect, |
|
3209 |
const QSpanData *data) const |
|
3210 |
{ |
|
3211 |
Q_Q(const QRasterPaintEngine); |
|
3212 |
const QRasterPaintEngineState *s = q->state(); |
|
3213 |
||
3214 |
if (!s->flags.fast_pen && s->matrix.type() > QTransform::TxTranslate) |
|
3215 |
return data->blend; |
|
3216 |
const int penWidth = s->flags.fast_pen ? 1 : qCeil(s->lastPen.widthF()); |
|
3217 |
return isUnclipped(rect, penWidth) ? data->unclipped_blend : data->blend; |
|
3218 |
} |
|
3219 |
||
3220 |
/*! |
|
3221 |
\reimp |
|
3222 |
*/ |
|
3223 |
void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) |
|
3224 |
{ |
|
3225 |
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); |
|
3226 |
QRasterPaintEngineState *s = state(); |
|
3227 |
||
3228 |
#ifdef QT_DEBUG_DRAW |
|
3229 |
Q_D(QRasterPaintEngine); |
|
3230 |
fprintf(stderr," - QRasterPaintEngine::drawTextItem(), (%.2f,%.2f), string=%s ct=%d\n", |
|
3231 |
p.x(), p.y(), QString::fromRawData(ti.chars, ti.num_chars).toLatin1().data(), |
|
3232 |
d->glyphCacheType); |
|
3233 |
#endif |
|
3234 |
||
3235 |
ensurePen(); |
|
3236 |
ensureState(); |
|
3237 |
||
3238 |
#if defined (Q_WS_WIN) || defined(Q_WS_MAC) |
|
3239 |
||
3240 |
bool drawCached = true; |
|
3241 |
||
3242 |
if (s->matrix.type() >= QTransform::TxProject) |
|
3243 |
drawCached = false; |
|
3244 |
||
3245 |
// don't try to cache huge fonts |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3246 |
const qreal pixelSize = ti.fontEngine->fontDef.pixelSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3247 |
if (pixelSize * pixelSize * qAbs(s->matrix.determinant()) >= 64 * 64) |
0 | 3248 |
drawCached = false; |
3249 |
||
3250 |
// ### Remove the TestFontEngine and Box engine crap, in these |
|
3251 |
// ### cases we should delegate painting to the font engine |
|
3252 |
// ### directly... |
|
3253 |
||
3254 |
#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE) |
|
3255 |
QFontEngine::Type fontEngineType = ti.fontEngine->type(); |
|
3256 |
// qDebug() << "type" << fontEngineType << s->matrix.type(); |
|
3257 |
if ((fontEngineType == QFontEngine::Win && !((QFontEngineWin *) ti.fontEngine)->ttf && s->matrix.type() > QTransform::TxTranslate) |
|
3258 |
|| (s->matrix.type() <= QTransform::TxTranslate |
|
3259 |
&& (fontEngineType == QFontEngine::TestFontEngine |
|
3260 |
|| fontEngineType == QFontEngine::Box))) { |
|
3261 |
drawCached = false; |
|
3262 |
} |
|
3263 |
#else |
|
3264 |
if (s->matrix.type() > QTransform::TxTranslate) |
|
3265 |
drawCached = false; |
|
3266 |
#endif |
|
3267 |
if (drawCached) { |
|
3268 |
drawCachedGlyphs(p, ti); |
|
3269 |
return; |
|
3270 |
} |
|
3271 |
||
3272 |
#elif defined (Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) // Q_WS_WIN || Q_WS_MAC |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3273 |
if (s->matrix.type() <= QTransform::TxTranslate |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3274 |
|| (s->matrix.type() == QTransform::TxScale |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3275 |
&& (qFuzzyCompare(s->matrix.m11(), s->matrix.m22())))) { |
0 | 3276 |
drawGlyphsS60(p, ti); |
3277 |
return; |
|
3278 |
} |
|
3279 |
#else // Q_WS_WIN || Q_WS_MAC |
|
3280 |
||
3281 |
QFontEngine *fontEngine = ti.fontEngine; |
|
3282 |
||
3283 |
#if defined(Q_WS_QWS) |
|
3284 |
if (fontEngine->type() == QFontEngine::Box) { |
|
3285 |
fontEngine->draw(this, qFloor(p.x() + aliasedCoordinateDelta), qFloor(p.y() + aliasedCoordinateDelta), ti); |
|
3286 |
return; |
|
3287 |
} |
|
3288 |
||
3289 |
if (s->matrix.type() < QTransform::TxScale |
|
3290 |
&& (fontEngine->type() == QFontEngine::QPF1 || fontEngine->type() == QFontEngine::QPF2 |
|
3291 |
|| (fontEngine->type() == QFontEngine::Proxy |
|
3292 |
&& !(static_cast<QProxyFontEngine *>(fontEngine)->drawAsOutline())) |
|
3293 |
)) { |
|
3294 |
fontEngine->draw(this, qFloor(p.x() + aliasedCoordinateDelta), qFloor(p.y() + aliasedCoordinateDelta), ti); |
|
3295 |
return; |
|
3296 |
} |
|
3297 |
#endif // Q_WS_QWS |
|
3298 |
||
3299 |
#if (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) && !defined(QT_NO_FREETYPE) |
|
3300 |
||
3301 |
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2) |
|
3302 |
if (fontEngine->type() == QFontEngine::QPF2) { |
|
3303 |
QFontEngine *renderingEngine = static_cast<QFontEngineQPF *>(fontEngine)->renderingEngine(); |
|
3304 |
if (renderingEngine) |
|
3305 |
fontEngine = renderingEngine; |
|
3306 |
} |
|
3307 |
#endif |
|
3308 |
||
3309 |
if (fontEngine->type() != QFontEngine::Freetype) { |
|
3310 |
QPaintEngineEx::drawTextItem(p, ti); |
|
3311 |
return; |
|
3312 |
} |
|
3313 |
||
3314 |
QFontEngineFT *fe = static_cast<QFontEngineFT *>(fontEngine); |
|
3315 |
||
3316 |
QTransform matrix = s->matrix; |
|
3317 |
matrix.translate(p.x(), p.y()); |
|
3318 |
||
3319 |
QVarLengthArray<QFixedPoint> positions; |
|
3320 |
QVarLengthArray<glyph_t> glyphs; |
|
3321 |
fe->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
|
3322 |
if (glyphs.size() == 0) |
|
3323 |
return; |
|
3324 |
||
3325 |
// only use subpixel antialiasing when drawing to widgets |
|
3326 |
QFontEngineFT::GlyphFormat neededFormat = |
|
3327 |
painter()->device()->devType() == QInternal::Widget |
|
3328 |
? fe->defaultGlyphFormat() |
|
3329 |
: QFontEngineFT::Format_A8; |
|
3330 |
||
3331 |
if (d_func()->mono_surface |
|
3332 |
|| fe->isBitmapFont() // alphaPenBlt can handle mono, too |
|
3333 |
) |
|
3334 |
neededFormat = QFontEngineFT::Format_Mono; |
|
3335 |
||
3336 |
if (neededFormat == QFontEngineFT::Format_None) |
|
3337 |
neededFormat = QFontEngineFT::Format_A8; |
|
3338 |
||
3339 |
QFontEngineFT::QGlyphSet *gset = fe->defaultGlyphs(); |
|
3340 |
if (s->matrix.type() >= QTransform::TxScale) { |
|
3341 |
if (s->matrix.isAffine()) |
|
3342 |
gset = fe->loadTransformedGlyphSet(s->matrix); |
|
3343 |
else |
|
3344 |
gset = 0; |
|
3345 |
||
3346 |
} |
|
3347 |
||
3348 |
if (!gset || gset->outline_drawing |
|
3349 |
|| !fe->loadGlyphs(gset, glyphs.data(), glyphs.size(), neededFormat)) |
|
3350 |
{ |
|
3351 |
QPaintEngine::drawTextItem(p, ti); |
|
3352 |
return; |
|
3353 |
} |
|
3354 |
||
3355 |
QFixed offs = QFixed::fromReal(aliasedCoordinateDelta); |
|
3356 |
FT_Face lockedFace = 0; |
|
3357 |
||
3358 |
int depth; |
|
3359 |
switch (neededFormat) { |
|
3360 |
case QFontEngineFT::Format_Mono: |
|
3361 |
depth = 1; |
|
3362 |
break; |
|
3363 |
case QFontEngineFT::Format_A8: |
|
3364 |
depth = 8; |
|
3365 |
break; |
|
3366 |
case QFontEngineFT::Format_A32: |
|
3367 |
depth = 32; |
|
3368 |
break; |
|
3369 |
default: |
|
3370 |
Q_ASSERT(false); |
|
3371 |
depth = 0; |
|
3372 |
}; |
|
3373 |
||
3374 |
for(int i = 0; i < glyphs.size(); i++) { |
|
3375 |
QFontEngineFT::Glyph *glyph = gset->glyph_data.value(glyphs[i]); |
|
3376 |
||
3377 |
if (!glyph || glyph->format != neededFormat) { |
|
3378 |
if (!lockedFace) |
|
3379 |
lockedFace = fe->lockFace(); |
|
3380 |
glyph = fe->loadGlyph(gset, glyphs[i], neededFormat); |
|
3381 |
} |
|
3382 |
||
3383 |
if (!glyph || !glyph->data) |
|
3384 |
continue; |
|
3385 |
||
3386 |
int pitch; |
|
3387 |
switch (neededFormat) { |
|
3388 |
case QFontEngineFT::Format_Mono: |
|
3389 |
pitch = ((glyph->width + 31) & ~31) >> 3; |
|
3390 |
break; |
|
3391 |
case QFontEngineFT::Format_A8: |
|
3392 |
pitch = (glyph->width + 3) & ~3; |
|
3393 |
break; |
|
3394 |
case QFontEngineFT::Format_A32: |
|
3395 |
pitch = glyph->width * 4; |
|
3396 |
break; |
|
3397 |
default: |
|
3398 |
Q_ASSERT(false); |
|
3399 |
pitch = 0; |
|
3400 |
}; |
|
3401 |
||
3402 |
alphaPenBlt(glyph->data, pitch, depth, |
|
3403 |
qFloor(positions[i].x + offs) + glyph->x, |
|
3404 |
qFloor(positions[i].y + offs) - glyph->y, |
|
3405 |
glyph->width, glyph->height); |
|
3406 |
} |
|
3407 |
if (lockedFace) |
|
3408 |
fe->unlockFace(); |
|
3409 |
return; |
|
3410 |
||
3411 |
#endif |
|
3412 |
#endif |
|
3413 |
||
3414 |
QPaintEngineEx::drawTextItem(p, ti); |
|
3415 |
} |
|
3416 |
||
3417 |
/*! |
|
3418 |
\reimp |
|
3419 |
*/ |
|
3420 |
void QRasterPaintEngine::drawPoints(const QPointF *points, int pointCount) |
|
3421 |
{ |
|
3422 |
Q_D(QRasterPaintEngine); |
|
3423 |
QRasterPaintEngineState *s = state(); |
|
3424 |
||
3425 |
ensurePen(); |
|
3426 |
qreal pw = s->lastPen.widthF(); |
|
3427 |
if (!s->flags.fast_pen && (s->matrix.type() > QTransform::TxTranslate || pw > 1)) { |
|
3428 |
QPaintEngineEx::drawPoints(points, pointCount); |
|
3429 |
||
3430 |
} else { |
|
3431 |
if (!s->penData.blend) |
|
3432 |
return; |
|
3433 |
||
3434 |
QVarLengthArray<QT_FT_Span, 4096> array(pointCount); |
|
3435 |
QT_FT_Span span = { 0, 1, 0, 255 }; |
|
3436 |
const QPointF *end = points + pointCount; |
|
3437 |
qreal trans_x, trans_y; |
|
3438 |
int x, y; |
|
3439 |
int left = d->deviceRect.x(); |
|
3440 |
int right = left + d->deviceRect.width(); |
|
3441 |
int top = d->deviceRect.y(); |
|
3442 |
int bottom = top + d->deviceRect.height(); |
|
3443 |
int count = 0; |
|
3444 |
while (points < end) { |
|
3445 |
s->matrix.map(points->x(), points->y(), &trans_x, &trans_y); |
|
3446 |
x = qFloor(trans_x); |
|
3447 |
y = qFloor(trans_y); |
|
3448 |
if (x >= left && x < right && y >= top && y < bottom) { |
|
3449 |
if (count > 0) { |
|
3450 |
const QT_FT_Span &last = array[count - 1]; |
|
3451 |
// spans must be sorted on y (primary) and x (secondary) |
|
3452 |
if (y < last.y || (y == last.y && x < last.x)) { |
|
3453 |
s->penData.blend(count, array.constData(), &s->penData); |
|
3454 |
count = 0; |
|
3455 |
} |
|
3456 |
} |
|
3457 |
||
3458 |
span.x = x; |
|
3459 |
span.y = y; |
|
3460 |
array[count++] = span; |
|
3461 |
} |
|
3462 |
++points; |
|
3463 |
} |
|
3464 |
||
3465 |
if (count > 0) |
|
3466 |
s->penData.blend(count, array.constData(), &s->penData); |
|
3467 |
} |
|
3468 |
} |
|
3469 |
||
3470 |
||
3471 |
void QRasterPaintEngine::drawPoints(const QPoint *points, int pointCount) |
|
3472 |
{ |
|
3473 |
Q_D(QRasterPaintEngine); |
|
3474 |
QRasterPaintEngineState *s = state(); |
|
3475 |
||
3476 |
ensurePen(); |
|
3477 |
double pw = s->lastPen.widthF(); |
|
3478 |
if (!s->flags.fast_pen && (s->matrix.type() > QTransform::TxTranslate || pw > 1)) { |
|
3479 |
QPaintEngineEx::drawPoints(points, pointCount); |
|
3480 |
||
3481 |
} else { |
|
3482 |
if (!s->penData.blend) |
|
3483 |
return; |
|
3484 |
||
3485 |
QVarLengthArray<QT_FT_Span, 4096> array(pointCount); |
|
3486 |
QT_FT_Span span = { 0, 1, 0, 255 }; |
|
3487 |
const QPoint *end = points + pointCount; |
|
3488 |
qreal trans_x, trans_y; |
|
3489 |
int x, y; |
|
3490 |
int left = d->deviceRect.x(); |
|
3491 |
int right = left + d->deviceRect.width(); |
|
3492 |
int top = d->deviceRect.y(); |
|
3493 |
int bottom = top + d->deviceRect.height(); |
|
3494 |
int count = 0; |
|
3495 |
while (points < end) { |
|
3496 |
s->matrix.map(points->x(), points->y(), &trans_x, &trans_y); |
|
3497 |
x = qFloor(trans_x); |
|
3498 |
y = qFloor(trans_y); |
|
3499 |
if (x >= left && x < right && y >= top && y < bottom) { |
|
3500 |
if (count > 0) { |
|
3501 |
const QT_FT_Span &last = array[count - 1]; |
|
3502 |
// spans must be sorted on y (primary) and x (secondary) |
|
3503 |
if (y < last.y || (y == last.y && x < last.x)) { |
|
3504 |
s->penData.blend(count, array.constData(), &s->penData); |
|
3505 |
count = 0; |
|
3506 |
} |
|
3507 |
} |
|
3508 |
||
3509 |
span.x = x; |
|
3510 |
span.y = y; |
|
3511 |
array[count++] = span; |
|
3512 |
} |
|
3513 |
++points; |
|
3514 |
} |
|
3515 |
||
3516 |
if (count > 0) |
|
3517 |
s->penData.blend(count, array.constData(), &s->penData); |
|
3518 |
} |
|
3519 |
} |
|
3520 |
||
3521 |
/*! |
|
3522 |
\reimp |
|
3523 |
*/ |
|
3524 |
void QRasterPaintEngine::drawLines(const QLine *lines, int lineCount) |
|
3525 |
{ |
|
3526 |
#ifdef QT_DEBUG_DRAW |
|
3527 |
qDebug() << " - QRasterPaintEngine::drawLine()"; |
|
3528 |
#endif |
|
3529 |
Q_D(QRasterPaintEngine); |
|
3530 |
QRasterPaintEngineState *s = state(); |
|
3531 |
||
3532 |
ensurePen(); |
|
3533 |
if (s->flags.fast_pen) { |
|
3534 |
QIntRect bounds; bounds.set(d->deviceRect); |
|
3535 |
LineDrawMode mode = s->lastPen.capStyle() == Qt::FlatCap |
|
3536 |
? LineDrawNormal |
|
3537 |
: LineDrawIncludeLastPixel; |
|
3538 |
||
3539 |
int m11 = int(s->matrix.m11()); |
|
3540 |
int m22 = int(s->matrix.m22()); |
|
3541 |
int dx = qFloor(s->matrix.dx() + aliasedCoordinateDelta); |
|
3542 |
int dy = qFloor(s->matrix.dy() + aliasedCoordinateDelta); |
|
3543 |
for (int i=0; i<lineCount; ++i) { |
|
3544 |
int dashOffset = int(s->lastPen.dashOffset()); |
|
3545 |
if (s->flags.int_xform) { |
|
3546 |
const QLine &l = lines[i]; |
|
3547 |
int x1 = l.x1() * m11 + dx; |
|
3548 |
int y1 = l.y1() * m22 + dy; |
|
3549 |
int x2 = l.x2() * m11 + dx; |
|
3550 |
int y2 = l.y2() * m22 + dy; |
|
3551 |
||
3552 |
const QRect brect(QPoint(x1, y1), QPoint(x2, y2)); |
|
3553 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
3554 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
3555 |
drawLine_midpoint_i(x1, y1, x2, y2, |
|
3556 |
penBlend, &s->penData, mode, bounds); |
|
3557 |
else |
|
3558 |
drawLine_midpoint_dashed_i(x1, y1, x2, y2, |
|
3559 |
&s->lastPen, penBlend, |
|
3560 |
&s->penData, mode, bounds, |
|
3561 |
&dashOffset); |
|
3562 |
} else { |
|
3563 |
QLineF line = lines[i] * s->matrix; |
|
3564 |
const QRectF brect(QPointF(line.x1(), line.y1()), |
|
3565 |
QPointF(line.x2(), line.y2())); |
|
3566 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
3567 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
3568 |
drawLine_midpoint_i(int(line.x1()), int(line.y1()), |
|
3569 |
int(line.x2()), int(line.y2()), |
|
3570 |
penBlend, &s->penData, mode, bounds); |
|
3571 |
else |
|
3572 |
drawLine_midpoint_dashed_i(int(line.x1()), int(line.y1()), |
|
3573 |
int(line.x2()), int(line.y2()), |
|
3574 |
&s->lastPen, penBlend, |
|
3575 |
&s->penData, mode, bounds, |
|
3576 |
&dashOffset); |
|
3577 |
} |
|
3578 |
} |
|
3579 |
} else if (s->penData.blend) { |
|
3580 |
QPaintEngineEx::drawLines(lines, lineCount); |
|
3581 |
} |
|
3582 |
} |
|
3583 |
||
3584 |
void QRasterPaintEnginePrivate::rasterizeLine_dashed(QLineF line, |
|
3585 |
qreal width, |
|
3586 |
int *dashIndex, |
|
3587 |
qreal *dashOffset, |
|
3588 |
bool *inDash) |
|
3589 |
{ |
|
3590 |
Q_Q(QRasterPaintEngine); |
|
3591 |
QRasterPaintEngineState *s = q->state(); |
|
3592 |
||
3593 |
const QPen &pen = s->lastPen; |
|
3594 |
const bool squareCap = (pen.capStyle() == Qt::SquareCap); |
|
3595 |
const QVector<qreal> pattern = pen.dashPattern(); |
|
3596 |
||
3597 |
qreal length = line.length(); |
|
3598 |
Q_ASSERT(length > 0); |
|
3599 |
while (length > 0) { |
|
3600 |
const bool rasterize = *inDash; |
|
3601 |
qreal dash = (pattern.at(*dashIndex) - *dashOffset) * width; |
|
3602 |
QLineF l = line; |
|
3603 |
||
3604 |
if (dash >= length) { |
|
3605 |
dash = length; |
|
3606 |
*dashOffset += dash / width; |
|
3607 |
length = 0; |
|
3608 |
} else { |
|
3609 |
*dashOffset = 0; |
|
3610 |
*inDash = !(*inDash); |
|
3611 |
*dashIndex = (*dashIndex + 1) % pattern.size(); |
|
3612 |
length -= dash; |
|
3613 |
l.setLength(dash); |
|
3614 |
line.setP1(l.p2()); |
|
3615 |
} |
|
3616 |
||
3617 |
if (rasterize && dash != 0) |
|
3618 |
rasterizer->rasterizeLine(l.p1(), l.p2(), width / dash, squareCap); |
|
3619 |
} |
|
3620 |
} |
|
3621 |
||
3622 |
/*! |
|
3623 |
\reimp |
|
3624 |
*/ |
|
3625 |
void QRasterPaintEngine::drawLines(const QLineF *lines, int lineCount) |
|
3626 |
{ |
|
3627 |
#ifdef QT_DEBUG_DRAW |
|
3628 |
qDebug() << " - QRasterPaintEngine::drawLine()"; |
|
3629 |
#endif |
|
3630 |
Q_D(QRasterPaintEngine); |
|
3631 |
QRasterPaintEngineState *s = state(); |
|
3632 |
||
3633 |
ensurePen(); |
|
3634 |
if (!s->penData.blend) |
|
3635 |
return; |
|
3636 |
if (s->flags.fast_pen) { |
|
3637 |
QIntRect bounds; |
|
3638 |
bounds.set(d->deviceRect); |
|
3639 |
LineDrawMode mode = s->lastPen.capStyle() == Qt::FlatCap |
|
3640 |
? LineDrawNormal |
|
3641 |
: LineDrawIncludeLastPixel; |
|
3642 |
||
3643 |
for (int i=0; i<lineCount; ++i) { |
|
3644 |
int dashOffset = int(s->lastPen.dashOffset()); |
|
3645 |
QLineF line = (lines[i] * s->matrix).translated(aliasedCoordinateDelta, aliasedCoordinateDelta); |
|
3646 |
const QRectF brect(QPointF(line.x1(), line.y1()), |
|
3647 |
QPointF(line.x2(), line.y2())); |
|
3648 |
ProcessSpans penBlend = d->getPenFunc(brect, &s->penData); |
|
3649 |
if (qpen_style(s->lastPen) == Qt::SolidLine) |
|
3650 |
drawLine_midpoint_i(int(line.x1()), int(line.y1()), |
|
3651 |
int(line.x2()), int(line.y2()), |
|
3652 |
penBlend, &s->penData, mode, bounds); |
|
3653 |
else |
|
3654 |
drawLine_midpoint_dashed_i(int(line.x1()), int(line.y1()), |
|
3655 |
int(line.x2()), int(line.y2()), |
|
3656 |
&s->lastPen, |
|
3657 |
penBlend, &s->penData, mode, |
|
3658 |
bounds, &dashOffset); |
|
3659 |
} |
|
3660 |
} else { |
|
3661 |
QPaintEngineEx::drawLines(lines, lineCount); |
|
3662 |
} |
|
3663 |
} |
|
3664 |
||
3665 |
||
3666 |
/*! |
|
3667 |
\reimp |
|
3668 |
*/ |
|
3669 |
void QRasterPaintEngine::drawEllipse(const QRectF &rect) |
|
3670 |
{ |
|
3671 |
Q_D(QRasterPaintEngine); |
|
3672 |
QRasterPaintEngineState *s = state(); |
|
3673 |
||
3674 |
ensurePen(); |
|
3675 |
if (((qpen_style(s->lastPen) == Qt::SolidLine && s->flags.fast_pen) |
|
3676 |
|| (qpen_style(s->lastPen) == Qt::NoPen && !s->flags.antialiased)) |
|
3677 |
&& qMax(rect.width(), rect.height()) < QT_RASTER_COORD_LIMIT |
|
3678 |
&& s->matrix.type() <= QTransform::TxScale) // no shear |
|
3679 |
{ |
|
3680 |
ensureBrush(); |
|
3681 |
const QRectF r = s->matrix.mapRect(rect); |
|
3682 |
ProcessSpans penBlend = d->getPenFunc(r, &s->penData); |
|
3683 |
ProcessSpans brushBlend = d->getBrushFunc(r, &s->brushData); |
|
3684 |
const QRect brect = QRect(int(r.x()), int(r.y()), |
|
3685 |
int_dim(r.x(), r.width()), |
|
3686 |
int_dim(r.y(), r.height())); |
|
3687 |
if (brect == r) { |
|
3688 |
drawEllipse_midpoint_i(brect, d->deviceRect, penBlend, brushBlend, |
|
3689 |
&s->penData, &s->brushData); |
|
3690 |
return; |
|
3691 |
} |
|
3692 |
} |
|
3693 |
QPaintEngineEx::drawEllipse(rect); |
|
3694 |
} |
|
3695 |
||
3696 |
/*! |
|
3697 |
\internal |
|
3698 |
*/ |
|
3699 |
#ifdef Q_WS_MAC |
|
3700 |
void QRasterPaintEngine::setCGContext(CGContextRef ctx) |
|
3701 |
{ |
|
3702 |
Q_D(QRasterPaintEngine); |
|
3703 |
d->cgContext = ctx; |
|
3704 |
} |
|
3705 |
||
3706 |
/*! |
|
3707 |
\internal |
|
3708 |
*/ |
|
3709 |
CGContextRef QRasterPaintEngine::getCGContext() const |
|
3710 |
{ |
|
3711 |
Q_D(const QRasterPaintEngine); |
|
3712 |
return d->cgContext; |
|
3713 |
} |
|
3714 |
#endif |
|
3715 |
||
3716 |
#ifdef Q_WS_WIN |
|
3717 |
/*! |
|
3718 |
\internal |
|
3719 |
*/ |
|
3720 |
void QRasterPaintEngine::setDC(HDC hdc) { |
|
3721 |
Q_D(QRasterPaintEngine); |
|
3722 |
d->hdc = hdc; |
|
3723 |
} |
|
3724 |
||
3725 |
/*! |
|
3726 |
\internal |
|
3727 |
*/ |
|
3728 |
HDC QRasterPaintEngine::getDC() const |
|
3729 |
{ |
|
3730 |
Q_D(const QRasterPaintEngine); |
|
3731 |
return d->hdc; |
|
3732 |
} |
|
3733 |
||
3734 |
/*! |
|
3735 |
\internal |
|
3736 |
*/ |
|
3737 |
void QRasterPaintEngine::releaseDC(HDC) const |
|
3738 |
{ |
|
3739 |
} |
|
3740 |
||
3741 |
#endif |
|
3742 |
||
3743 |
/*! |
|
3744 |
\internal |
|
3745 |
*/ |
|
3746 |
QPoint QRasterPaintEngine::coordinateOffset() const |
|
3747 |
{ |
|
3748 |
return QPoint(0, 0); |
|
3749 |
} |
|
3750 |
||
3751 |
/*! |
|
3752 |
Draws the given color \a spans with the specified \a color. The \a |
|
3753 |
count parameter specifies the number of spans. |
|
3754 |
||
3755 |
The default implementation does nothing; reimplement this function |
|
3756 |
to draw the given color \a spans with the specified \a color. Note |
|
3757 |
that this function \e must be reimplemented if the framebuffer is |
|
3758 |
not memory-mapped. |
|
3759 |
||
3760 |
\sa drawBufferSpan() |
|
3761 |
*/ |
|
3762 |
#if defined(Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
3763 |
void QRasterPaintEngine::drawColorSpans(const QSpan *spans, int count, uint color) |
|
3764 |
{ |
|
3765 |
Q_UNUSED(spans); |
|
3766 |
Q_UNUSED(count); |
|
3767 |
Q_UNUSED(color); |
|
3768 |
qFatal("QRasterPaintEngine::drawColorSpans must be reimplemented on " |
|
3769 |
"a non memory-mapped device"); |
|
3770 |
} |
|
3771 |
||
3772 |
/*! |
|
3773 |
\fn void QRasterPaintEngine::drawBufferSpan(const uint *buffer, int size, int x, int y, int length, uint alpha) |
|
3774 |
||
3775 |
Draws the given \a buffer. |
|
3776 |
||
3777 |
The default implementation does nothing; reimplement this function |
|
3778 |
to draw a buffer that contains more than one color. Note that this |
|
3779 |
function \e must be reimplemented if the framebuffer is not |
|
3780 |
memory-mapped. |
|
3781 |
||
3782 |
The \a size parameter specifies the total size of the given \a |
|
3783 |
buffer, while the \a length parameter specifies the number of |
|
3784 |
pixels to draw. The buffer's position is given by (\a x, \a |
|
3785 |
y). The provided \a alpha value is added to each pixel in the |
|
3786 |
buffer when drawing. |
|
3787 |
||
3788 |
\sa drawColorSpans() |
|
3789 |
*/ |
|
3790 |
void QRasterPaintEngine::drawBufferSpan(const uint *buffer, int bufsize, |
|
3791 |
int x, int y, int length, uint const_alpha) |
|
3792 |
{ |
|
3793 |
Q_UNUSED(buffer); |
|
3794 |
Q_UNUSED(bufsize); |
|
3795 |
Q_UNUSED(x); |
|
3796 |
Q_UNUSED(y); |
|
3797 |
Q_UNUSED(length); |
|
3798 |
Q_UNUSED(const_alpha); |
|
3799 |
qFatal("QRasterPaintEngine::drawBufferSpan must be reimplemented on " |
|
3800 |
"a non memory-mapped device"); |
|
3801 |
} |
|
3802 |
#endif // Q_WS_QWS |
|
3803 |
||
3804 |
void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fg) |
|
3805 |
{ |
|
3806 |
Q_ASSERT(fg); |
|
3807 |
if (!fg->blend) |
|
3808 |
return; |
|
3809 |
Q_D(QRasterPaintEngine); |
|
3810 |
||
3811 |
Q_ASSERT(image.depth() == 1); |
|
3812 |
||
3813 |
const int spanCount = 256; |
|
3814 |
QT_FT_Span spans[spanCount]; |
|
3815 |
int n = 0; |
|
3816 |
||
3817 |
// Boundaries |
|
3818 |
int w = image.width(); |
|
3819 |
int h = image.height(); |
|
3820 |
int ymax = qMin(qRound(pos.y() + h), d->rasterBuffer->height()); |
|
3821 |
int ymin = qMax(qRound(pos.y()), 0); |
|
3822 |
int xmax = qMin(qRound(pos.x() + w), d->rasterBuffer->width()); |
|
3823 |
int xmin = qMax(qRound(pos.x()), 0); |
|
3824 |
||
3825 |
int x_offset = xmin - qRound(pos.x()); |
|
3826 |
||
3827 |
QImage::Format format = image.format(); |
|
3828 |
for (int y = ymin; y < ymax; ++y) { |
|
3829 |
const uchar *src = image.scanLine(y - qRound(pos.y())); |
|
3830 |
if (format == QImage::Format_MonoLSB) { |
|
3831 |
for (int x = 0; x < xmax - xmin; ++x) { |
|
3832 |
int src_x = x + x_offset; |
|
3833 |
uchar pixel = src[src_x >> 3]; |
|
3834 |
if (!pixel) { |
|
3835 |
x += 7 - (src_x%8); |
|
3836 |
continue; |
|
3837 |
} |
|
3838 |
if (pixel & (0x1 << (src_x & 7))) { |
|
3839 |
spans[n].x = xmin + x; |
|
3840 |
spans[n].y = y; |
|
3841 |
spans[n].coverage = 255; |
|
3842 |
int len = 1; |
|
3843 |
while (src_x < w-1 && src[(src_x+1) >> 3] & (0x1 << ((src_x+1) & 7))) { |
|
3844 |
++src_x; |
|
3845 |
++len; |
|
3846 |
} |
|
3847 |
spans[n].len = ((len + spans[n].x) > xmax) ? (xmax - spans[n].x) : len; |
|
3848 |
x += len; |
|
3849 |
++n; |
|
3850 |
if (n == spanCount) { |
|
3851 |
fg->blend(n, spans, fg); |
|
3852 |
n = 0; |
|
3853 |
} |
|
3854 |
} |
|
3855 |
} |
|
3856 |
} else { |
|
3857 |
for (int x = 0; x < xmax - xmin; ++x) { |
|
3858 |
int src_x = x + x_offset; |
|
3859 |
uchar pixel = src[src_x >> 3]; |
|
3860 |
if (!pixel) { |
|
3861 |
x += 7 - (src_x%8); |
|
3862 |
continue; |
|
3863 |
} |
|
3864 |
if (pixel & (0x80 >> (x & 7))) { |
|
3865 |
spans[n].x = xmin + x; |
|
3866 |
spans[n].y = y; |
|
3867 |
spans[n].coverage = 255; |
|
3868 |
int len = 1; |
|
3869 |
while (src_x < w-1 && src[(src_x+1) >> 3] & (0x80 >> ((src_x+1) & 7))) { |
|
3870 |
++src_x; |
|
3871 |
++len; |
|
3872 |
} |
|
3873 |
spans[n].len = ((len + spans[n].x) > xmax) ? (xmax - spans[n].x) : len; |
|
3874 |
x += len; |
|
3875 |
++n; |
|
3876 |
if (n == spanCount) { |
|
3877 |
fg->blend(n, spans, fg); |
|
3878 |
n = 0; |
|
3879 |
} |
|
3880 |
} |
|
3881 |
} |
|
3882 |
} |
|
3883 |
} |
|
3884 |
if (n) { |
|
3885 |
fg->blend(n, spans, fg); |
|
3886 |
n = 0; |
|
3887 |
} |
|
3888 |
} |
|
3889 |
||
3890 |
/*! |
|
3891 |
\enum QRasterPaintEngine::ClipType |
|
3892 |
\internal |
|
3893 |
||
3894 |
\value RectClip Indicates that the currently set clip is a single rectangle. |
|
3895 |
\value ComplexClip Indicates that the currently set clip is a combination of several shapes. |
|
3896 |
*/ |
|
3897 |
||
3898 |
/*! |
|
3899 |
\internal |
|
3900 |
Returns the type of the clip currently set. |
|
3901 |
*/ |
|
3902 |
QRasterPaintEngine::ClipType QRasterPaintEngine::clipType() const |
|
3903 |
{ |
|
3904 |
Q_D(const QRasterPaintEngine); |
|
3905 |
||
3906 |
const QClipData *clip = d->clip(); |
|
3907 |
if (!clip || clip->hasRectClip) |
|
3908 |
return RectClip; |
|
3909 |
else |
|
3910 |
return ComplexClip; |
|
3911 |
} |
|
3912 |
||
3913 |
/*! |
|
3914 |
\internal |
|
3915 |
Returns the bounding rect of the currently set clip. |
|
3916 |
*/ |
|
3917 |
QRect QRasterPaintEngine::clipBoundingRect() const |
|
3918 |
{ |
|
3919 |
Q_D(const QRasterPaintEngine); |
|
3920 |
||
3921 |
const QClipData *clip = d->clip(); |
|
3922 |
||
3923 |
if (!clip) |
|
3924 |
return d->deviceRect; |
|
3925 |
||
3926 |
if (clip->hasRectClip) |
|
3927 |
return clip->clipRect; |
|
3928 |
||
3929 |
return QRect(clip->xmin, clip->ymin, clip->xmax - clip->xmin, clip->ymax - clip->ymin); |
|
3930 |
} |
|
3931 |
||
3932 |
static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *result) |
|
3933 |
{ |
|
3934 |
Q_ASSERT(c1->clipSpanHeight == c2->clipSpanHeight && c1->clipSpanHeight == result->clipSpanHeight); |
|
3935 |
||
3936 |
QVarLengthArray<short, 4096> buffer; |
|
3937 |
||
3938 |
QClipData::ClipLine *c1ClipLines = const_cast<QClipData *>(c1)->clipLines(); |
|
3939 |
QClipData::ClipLine *c2ClipLines = const_cast<QClipData *>(c2)->clipLines(); |
|
3940 |
result->initialize(); |
|
3941 |
||
3942 |
for (int y = 0; y < c1->clipSpanHeight; ++y) { |
|
3943 |
const QSpan *c1_spans = c1ClipLines[y].spans; |
|
3944 |
int c1_count = c1ClipLines[y].count; |
|
3945 |
const QSpan *c2_spans = c2ClipLines[y].spans; |
|
3946 |
int c2_count = c2ClipLines[y].count; |
|
3947 |
||
3948 |
if (c1_count == 0 && c2_count == 0) |
|
3949 |
continue; |
|
3950 |
if (c1_count == 0) { |
|
3951 |
result->appendSpans(c2_spans, c2_count); |
|
3952 |
continue; |
|
3953 |
} else if (c2_count == 0) { |
|
3954 |
result->appendSpans(c1_spans, c1_count); |
|
3955 |
continue; |
|
3956 |
} |
|
3957 |
||
3958 |
// we need to merge the two |
|
3959 |
||
3960 |
// find required length |
|
3961 |
int max = qMax(c1_spans[c1_count - 1].x + c1_spans[c1_count - 1].len, |
|
3962 |
c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len); |
|
3963 |
buffer.resize(max); |
|
3964 |
memset(buffer.data(), 0, buffer.size() * sizeof(short)); |
|
3965 |
||
3966 |
// Fill with old spans. |
|
3967 |
for (int i = 0; i < c1_count; ++i) { |
|
3968 |
const QSpan *cs = c1_spans + i; |
|
3969 |
for (int j=cs->x; j<cs->x + cs->len; ++j) |
|
3970 |
buffer[j] = cs->coverage; |
|
3971 |
} |
|
3972 |
||
3973 |
// Fill with new spans |
|
3974 |
for (int i = 0; i < c2_count; ++i) { |
|
3975 |
const QSpan *cs = c2_spans + i; |
|
3976 |
for (int j = cs->x; j < cs->x + cs->len; ++j) { |
|
3977 |
buffer[j] += cs->coverage; |
|
3978 |
if (buffer[j] > 255) |
|
3979 |
buffer[j] = 255; |
|
3980 |
} |
|
3981 |
} |
|
3982 |
||
3983 |
int x = 0; |
|
3984 |
while (x<max) { |
|
3985 |
||
3986 |
// Skip to next span |
|
3987 |
while (x < max && buffer[x] == 0) ++x; |
|
3988 |
if (x >= max) break; |
|
3989 |
||
3990 |
int sx = x; |
|
3991 |
int coverage = buffer[x]; |
|
3992 |
||
3993 |
// Find length of span |
|
3994 |
while (x < max && buffer[x] == coverage) |
|
3995 |
++x; |
|
3996 |
||
3997 |
result->appendSpan(sx, x - sx, y, coverage); |
|
3998 |
} |
|
3999 |
} |
|
4000 |
} |
|
4001 |
||
4002 |
void QRasterPaintEnginePrivate::initializeRasterizer(QSpanData *data) |
|
4003 |
{ |
|
4004 |
Q_Q(QRasterPaintEngine); |
|
4005 |
QRasterPaintEngineState *s = q->state(); |
|
4006 |
||
4007 |
rasterizer->setAntialiased(s->flags.antialiased); |
|
4008 |
||
4009 |
QRect clipRect(deviceRect); |
|
4010 |
ProcessSpans blend; |
|
4011 |
// ### get from optimized rectbased QClipData |
|
4012 |
||
4013 |
const QClipData *c = clip(); |
|
4014 |
if (c) { |
|
4015 |
const QRect r(QPoint(c->xmin, c->ymin), |
|
4016 |
QSize(c->xmax - c->xmin, c->ymax - c->ymin)); |
|
4017 |
clipRect = clipRect.intersected(r); |
|
4018 |
blend = data->blend; |
|
4019 |
} else { |
|
4020 |
blend = data->unclipped_blend; |
|
4021 |
} |
|
4022 |
||
4023 |
rasterizer->setClipRect(clipRect); |
|
4024 |
rasterizer->initialize(blend, data); |
|
4025 |
} |
|
4026 |
||
4027 |
void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, |
|
4028 |
ProcessSpans callback, |
|
4029 |
QSpanData *spanData, QRasterBuffer *rasterBuffer) |
|
4030 |
{ |
|
4031 |
if (!callback || !outline) |
|
4032 |
return; |
|
4033 |
||
4034 |
Q_Q(QRasterPaintEngine); |
|
4035 |
QRasterPaintEngineState *s = q->state(); |
|
4036 |
||
4037 |
if (!s->flags.antialiased) { |
|
4038 |
initializeRasterizer(spanData); |
|
4039 |
||
4040 |
const Qt::FillRule fillRule = outline->flags == QT_FT_OUTLINE_NONE |
|
4041 |
? Qt::WindingFill |
|
4042 |
: Qt::OddEvenFill; |
|
4043 |
||
4044 |
rasterizer->rasterize(outline, fillRule); |
|
4045 |
return; |
|
4046 |
} |
|
4047 |
||
4048 |
rasterize(outline, callback, (void *)spanData, rasterBuffer); |
|
4049 |
} |
|
4050 |
||
4051 |
void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, |
|
4052 |
ProcessSpans callback, |
|
4053 |
void *userData, QRasterBuffer *) |
|
4054 |
{ |
|
4055 |
if (!callback || !outline) |
|
4056 |
return; |
|
4057 |
||
4058 |
Q_Q(QRasterPaintEngine); |
|
4059 |
QRasterPaintEngineState *s = q->state(); |
|
4060 |
||
4061 |
if (!s->flags.antialiased) { |
|
4062 |
rasterizer->setAntialiased(s->flags.antialiased); |
|
4063 |
rasterizer->setClipRect(deviceRect); |
|
4064 |
rasterizer->initialize(callback, userData); |
|
4065 |
||
4066 |
const Qt::FillRule fillRule = outline->flags == QT_FT_OUTLINE_NONE |
|
4067 |
? Qt::WindingFill |
|
4068 |
: Qt::OddEvenFill; |
|
4069 |
||
4070 |
rasterizer->rasterize(outline, fillRule); |
|
4071 |
return; |
|
4072 |
} |
|
4073 |
||
4074 |
void *data = userData; |
|
4075 |
||
4076 |
QT_FT_BBox clip_box = { deviceRect.x(), |
|
4077 |
deviceRect.y(), |
|
4078 |
deviceRect.x() + deviceRect.width(), |
|
4079 |
deviceRect.y() + deviceRect.height() }; |
|
4080 |
||
4081 |
QT_FT_Raster_Params rasterParams; |
|
4082 |
rasterParams.target = 0; |
|
4083 |
rasterParams.source = outline; |
|
4084 |
rasterParams.flags = QT_FT_RASTER_FLAG_CLIP; |
|
4085 |
rasterParams.gray_spans = 0; |
|
4086 |
rasterParams.black_spans = 0; |
|
4087 |
rasterParams.bit_test = 0; |
|
4088 |
rasterParams.bit_set = 0; |
|
4089 |
rasterParams.user = data; |
|
4090 |
rasterParams.clip_box = clip_box; |
|
4091 |
||
4092 |
bool done = false; |
|
4093 |
int error; |
|
4094 |
||
4095 |
while (!done) { |
|
4096 |
||
4097 |
rasterParams.flags |= (QT_FT_RASTER_FLAG_AA | QT_FT_RASTER_FLAG_DIRECT); |
|
4098 |
rasterParams.gray_spans = callback; |
|
4099 |
error = qt_ft_grays_raster.raster_render(*grayRaster.data(), &rasterParams); |
|
4100 |
||
4101 |
// Out of memory, reallocate some more and try again... |
|
4102 |
if (error == -6) { // -6 is Result_err_OutOfMemory |
|
4103 |
int new_size = rasterPoolSize * 2; |
|
4104 |
if (new_size > 1024 * 1024) { |
|
4105 |
qWarning("QPainter: Rasterization of primitive failed"); |
|
4106 |
return; |
|
4107 |
} |
|
4108 |
||
4109 |
#if defined(Q_WS_WIN64) |
|
4110 |
_aligned_free(rasterPoolBase); |
|
4111 |
#else |
|
4112 |
free(rasterPoolBase); |
|
4113 |
#endif |
|
4114 |
||
4115 |
rasterPoolSize = new_size; |
|
4116 |
rasterPoolBase = |
|
4117 |
#if defined(Q_WS_WIN64) |
|
4118 |
// We make use of setjmp and longjmp in qgrayraster.c which requires |
|
4119 |
// 16-byte alignment, hence we hardcode this requirement here.. |
|
4120 |
(unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2); |
|
4121 |
#else |
|
4122 |
(unsigned char *) malloc(rasterPoolSize); |
|
4123 |
#endif |
|
4124 |
Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal. |
|
4125 |
||
4126 |
qt_ft_grays_raster.raster_done(*grayRaster.data()); |
|
4127 |
qt_ft_grays_raster.raster_new(0, grayRaster.data()); |
|
4128 |
qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize); |
|
4129 |
} else { |
|
4130 |
done = true; |
|
4131 |
} |
|
4132 |
} |
|
4133 |
} |
|
4134 |
||
4135 |
void QRasterPaintEnginePrivate::recalculateFastImages() |
|
4136 |
{ |
|
4137 |
Q_Q(QRasterPaintEngine); |
|
4138 |
QRasterPaintEngineState *s = q->state(); |
|
4139 |
||
4140 |
s->flags.fast_images = !(s->renderHints & QPainter::SmoothPixmapTransform) |
|
4141 |
&& rasterBuffer->compositionMode == QPainter::CompositionMode_SourceOver |
|
4142 |
&& s->matrix.type() <= QTransform::TxShear; |
|
4143 |
} |
|
4144 |
||
4145 |
||
4146 |
||
4147 |
QImage QRasterBuffer::colorizeBitmap(const QImage &image, const QColor &color) |
|
4148 |
{ |
|
4149 |
Q_ASSERT(image.depth() == 1); |
|
4150 |
||
4151 |
QImage sourceImage = image.convertToFormat(QImage::Format_MonoLSB); |
|
4152 |
QImage dest = QImage(sourceImage.size(), QImage::Format_ARGB32_Premultiplied); |
|
4153 |
||
4154 |
QRgb fg = PREMUL(color.rgba()); |
|
4155 |
QRgb bg = 0; |
|
4156 |
||
4157 |
int height = sourceImage.height(); |
|
4158 |
int width = sourceImage.width(); |
|
4159 |
for (int y=0; y<height; ++y) { |
|
4160 |
uchar *source = sourceImage.scanLine(y); |
|
4161 |
QRgb *target = reinterpret_cast<QRgb *>(dest.scanLine(y)); |
|
4162 |
if (!source || !target) |
|
4163 |
QT_THROW(std::bad_alloc()); // we must have run out of memory |
|
4164 |
for (int x=0; x < width; ++x) |
|
4165 |
target[x] = (source[x>>3] >> (x&7)) & 1 ? fg : bg; |
|
4166 |
} |
|
4167 |
return dest; |
|
4168 |
} |
|
4169 |
||
4170 |
QRasterBuffer::~QRasterBuffer() |
|
4171 |
{ |
|
4172 |
} |
|
4173 |
||
4174 |
void QRasterBuffer::init() |
|
4175 |
{ |
|
4176 |
compositionMode = QPainter::CompositionMode_SourceOver; |
|
4177 |
monoDestinationWithClut = false; |
|
4178 |
destColor0 = 0; |
|
4179 |
destColor1 = 0; |
|
4180 |
} |
|
4181 |
||
4182 |
QImage::Format QRasterBuffer::prepare(QImage *image) |
|
4183 |
{ |
|
4184 |
m_buffer = (uchar *)image->bits(); |
|
4185 |
m_width = qMin(QT_RASTER_COORD_LIMIT, image->width()); |
|
4186 |
m_height = qMin(QT_RASTER_COORD_LIMIT, image->height()); |
|
4187 |
bytes_per_pixel = image->depth()/8; |
|
4188 |
bytes_per_line = image->bytesPerLine(); |
|
4189 |
||
4190 |
format = image->format(); |
|
4191 |
drawHelper = qDrawHelper + format; |
|
4192 |
if (image->depth() == 1 && image->colorTable().size() == 2) { |
|
4193 |
monoDestinationWithClut = true; |
|
4194 |
destColor0 = PREMUL(image->colorTable()[0]); |
|
4195 |
destColor1 = PREMUL(image->colorTable()[1]); |
|
4196 |
} |
|
4197 |
||
4198 |
return format; |
|
4199 |
} |
|
4200 |
||
4201 |
void QRasterBuffer::resetBuffer(int val) |
|
4202 |
{ |
|
4203 |
memset(m_buffer, val, m_height*bytes_per_line); |
|
4204 |
} |
|
4205 |
||
4206 |
||
4207 |
#if defined(Q_WS_QWS) |
|
4208 |
void QRasterBuffer::prepare(QCustomRasterPaintDevice *device) |
|
4209 |
{ |
|
4210 |
m_buffer = reinterpret_cast<uchar*>(device->memory()); |
|
4211 |
m_width = qMin(QT_RASTER_COORD_LIMIT, device->width()); |
|
4212 |
m_height = qMin(QT_RASTER_COORD_LIMIT, device->height()); |
|
4213 |
bytes_per_pixel = device->depth() / 8; |
|
4214 |
bytes_per_line = device->bytesPerLine(); |
|
4215 |
format = device->format(); |
|
4216 |
#ifndef QT_NO_RASTERCALLBACKS |
|
4217 |
if (!m_buffer) |
|
4218 |
drawHelper = qDrawHelperCallback + format; |
|
4219 |
else |
|
4220 |
#endif |
|
4221 |
drawHelper = qDrawHelper + format; |
|
4222 |
} |
|
4223 |
||
4224 |
int QCustomRasterPaintDevice::metric(PaintDeviceMetric m) const |
|
4225 |
{ |
|
4226 |
switch (m) { |
|
4227 |
case PdmWidth: |
|
4228 |
return widget->frameGeometry().width(); |
|
4229 |
case PdmHeight: |
|
4230 |
return widget->frameGeometry().height(); |
|
4231 |
default: |
|
4232 |
break; |
|
4233 |
} |
|
4234 |
||
4235 |
return qt_paint_device_metric(widget, m); |
|
4236 |
} |
|
4237 |
||
4238 |
int QCustomRasterPaintDevice::bytesPerLine() const |
|
4239 |
{ |
|
4240 |
return (width() * depth() + 7) / 8; |
|
4241 |
} |
|
4242 |
||
4243 |
#elif defined(Q_OS_SYMBIAN) |
|
4244 |
||
4245 |
void QRasterBuffer::prepareBuffer(int /* width */, int /* height */) |
|
4246 |
{ |
|
4247 |
} |
|
4248 |
||
4249 |
#endif // Q_OS_SYMBIAN |
|
4250 |
||
4251 |
/*! |
|
4252 |
\class QCustomRasterPaintDevice |
|
4253 |
\preliminary |
|
4254 |
\ingroup qws |
|
4255 |
\since 4.2 |
|
4256 |
||
4257 |
\brief The QCustomRasterPaintDevice class is provided to activate |
|
4258 |
hardware accelerated paint engines in Qt for Embedded Linux. |
|
4259 |
||
4260 |
Note that this class is only available in \l{Qt for Embedded Linux}. |
|
4261 |
||
4262 |
In \l{Qt for Embedded Linux}, painting is a pure software |
|
4263 |
implementation. But starting with Qt 4.2, it is |
|
4264 |
possible to add an accelerated graphics driver to take advantage |
|
4265 |
of available hardware resources. |
|
4266 |
||
4267 |
Hardware acceleration is accomplished by creating a custom screen |
|
4268 |
driver, accelerating the copying from memory to the screen, and |
|
4269 |
implementing a custom paint engine accelerating the various |
|
4270 |
painting operations. Then a custom paint device (derived from the |
|
4271 |
QCustomRasterPaintDevice class) and a custom window surface |
|
4272 |
(derived from QWSWindowSurface) must be implemented to make |
|
4273 |
\l{Qt for Embedded Linux} aware of the accelerated driver. |
|
4274 |
||
4275 |
See the \l {Adding an Accelerated Graphics Driver to Qt for Embedded Linux} |
|
4276 |
documentation for details. |
|
4277 |
||
4278 |
\sa QRasterPaintEngine, QPaintDevice |
|
4279 |
*/ |
|
4280 |
||
4281 |
/*! |
|
4282 |
\fn QCustomRasterPaintDevice::QCustomRasterPaintDevice(QWidget *widget) |
|
4283 |
||
4284 |
Constructs a custom raster based paint device for the given |
|
4285 |
top-level \a widget. |
|
4286 |
*/ |
|
4287 |
||
4288 |
/*! |
|
4289 |
\fn int QCustomRasterPaintDevice::bytesPerLine() const |
|
4290 |
||
4291 |
Returns the number of bytes per line in the framebuffer. Note that |
|
4292 |
this number might be larger than the framebuffer width. |
|
4293 |
*/ |
|
4294 |
||
4295 |
/*! |
|
4296 |
\fn int QCustomRasterPaintDevice::devType() const |
|
4297 |
\internal |
|
4298 |
*/ |
|
4299 |
||
4300 |
/*! |
|
4301 |
\fn QImage::Format QCustomRasterPaintDevice::format() const |
|
4302 |
||
4303 |
Returns the format of the device's memory buffet. |
|
4304 |
||
4305 |
The default format is QImage::Format_ARGB32_Premultiplied. The |
|
4306 |
only other valid format is QImage::Format_RGB16. |
|
4307 |
*/ |
|
4308 |
||
4309 |
/*! |
|
4310 |
\fn void * QCustomRasterPaintDevice::memory () const |
|
4311 |
||
4312 |
Returns a pointer to the paint device's memory buffer, or 0 if no |
|
4313 |
such buffer exists. |
|
4314 |
*/ |
|
4315 |
||
4316 |
/*! |
|
4317 |
\fn int QCustomRasterPaintDevice::metric ( PaintDeviceMetric m ) const |
|
4318 |
\reimp |
|
4319 |
*/ |
|
4320 |
||
4321 |
/*! |
|
4322 |
\fn QSize QCustomRasterPaintDevice::size () const |
|
4323 |
\internal |
|
4324 |
*/ |
|
4325 |
||
4326 |
||
4327 |
QClipData::QClipData(int height) |
|
4328 |
{ |
|
4329 |
clipSpanHeight = height; |
|
4330 |
m_clipLines = 0; |
|
4331 |
||
4332 |
allocated = 0; |
|
4333 |
m_spans = 0; |
|
4334 |
xmin = xmax = ymin = ymax = 0; |
|
4335 |
count = 0; |
|
4336 |
||
4337 |
enabled = true; |
|
4338 |
hasRectClip = hasRegionClip = false; |
|
4339 |
} |
|
4340 |
||
4341 |
QClipData::~QClipData() |
|
4342 |
{ |
|
4343 |
if (m_clipLines) |
|
4344 |
free(m_clipLines); |
|
4345 |
if (m_spans) |
|
4346 |
free(m_spans); |
|
4347 |
} |
|
4348 |
||
4349 |
void QClipData::initialize() |
|
4350 |
{ |
|
4351 |
if (m_spans) |
|
4352 |
return; |
|
4353 |
||
4354 |
if (!m_clipLines) |
|
4355 |
m_clipLines = (ClipLine *)calloc(sizeof(ClipLine), clipSpanHeight); |
|
4356 |
||
4357 |
Q_CHECK_PTR(m_clipLines); |
|
4358 |
QT_TRY { |
|
4359 |
m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan)); |
|
4360 |
allocated = clipSpanHeight; |
|
4361 |
Q_CHECK_PTR(m_spans); |
|
4362 |
||
4363 |
QT_TRY { |
|
4364 |
if (hasRectClip) { |
|
4365 |
int y = 0; |
|
4366 |
while (y < ymin) { |
|
4367 |
m_clipLines[y].spans = 0; |
|
4368 |
m_clipLines[y].count = 0; |
|
4369 |
++y; |
|
4370 |
} |
|
4371 |
||
4372 |
const int len = clipRect.width(); |
|
4373 |
count = 0; |
|
4374 |
while (y < ymax) { |
|
4375 |
QSpan *span = m_spans + count; |
|
4376 |
span->x = xmin; |
|
4377 |
span->len = len; |
|
4378 |
span->y = y; |
|
4379 |
span->coverage = 255; |
|
4380 |
++count; |
|
4381 |
||
4382 |
m_clipLines[y].spans = span; |
|
4383 |
m_clipLines[y].count = 1; |
|
4384 |
++y; |
|
4385 |
} |
|
4386 |
||
4387 |
while (y < clipSpanHeight) { |
|
4388 |
m_clipLines[y].spans = 0; |
|
4389 |
m_clipLines[y].count = 0; |
|
4390 |
++y; |
|
4391 |
} |
|
4392 |
} else if (hasRegionClip) { |
|
4393 |
||
4394 |
const QVector<QRect> rects = clipRegion.rects(); |
|
4395 |
const int numRects = rects.size(); |
|
4396 |
||
4397 |
{ // resize |
|
4398 |
const int maxSpans = (ymax - ymin) * numRects; |
|
4399 |
if (maxSpans > allocated) { |
|
4400 |
m_spans = q_check_ptr((QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan))); |
|
4401 |
allocated = maxSpans; |
|
4402 |
} |
|
4403 |
} |
|
4404 |
||
4405 |
int y = 0; |
|
4406 |
int firstInBand = 0; |
|
4407 |
count = 0; |
|
4408 |
while (firstInBand < numRects) { |
|
4409 |
const int currMinY = rects.at(firstInBand).y(); |
|
4410 |
const int currMaxY = currMinY + rects.at(firstInBand).height(); |
|
4411 |
||
4412 |
while (y < currMinY) { |
|
4413 |
m_clipLines[y].spans = 0; |
|
4414 |
m_clipLines[y].count = 0; |
|
4415 |
++y; |
|
4416 |
} |
|
4417 |
||
4418 |
int lastInBand = firstInBand; |
|
4419 |
while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y) |
|
4420 |
++lastInBand; |
|
4421 |
||
4422 |
while (y < currMaxY) { |
|
4423 |
||
4424 |
m_clipLines[y].spans = m_spans + count; |
|
4425 |
m_clipLines[y].count = lastInBand - firstInBand + 1; |
|
4426 |
||
4427 |
for (int r = firstInBand; r <= lastInBand; ++r) { |
|
4428 |
const QRect &currRect = rects.at(r); |
|
4429 |
QSpan *span = m_spans + count; |
|
4430 |
span->x = currRect.x(); |
|
4431 |
span->len = currRect.width(); |
|
4432 |
span->y = y; |
|
4433 |
span->coverage = 255; |
|
4434 |
++count; |
|
4435 |
} |
|
4436 |
++y; |
|
4437 |
} |
|
4438 |
||
4439 |
firstInBand = lastInBand + 1; |
|
4440 |
} |
|
4441 |
||
4442 |
Q_ASSERT(count <= allocated); |
|
4443 |
||
4444 |
while (y < clipSpanHeight) { |
|
4445 |
m_clipLines[y].spans = 0; |
|
4446 |
m_clipLines[y].count = 0; |
|
4447 |
++y; |
|
4448 |
} |
|
4449 |
||
4450 |
} |
|
4451 |
} QT_CATCH(...) { |
|
4452 |
free(m_spans); // have to free m_spans again or someone might think that we were successfully initialized. |
|
4453 |
m_spans = 0; |
|
4454 |
QT_RETHROW; |
|
4455 |
} |
|
4456 |
} QT_CATCH(...) { |
|
4457 |
free(m_clipLines); // same for clipLines |
|
4458 |
m_clipLines = 0; |
|
4459 |
QT_RETHROW; |
|
4460 |
} |
|
4461 |
} |
|
4462 |
||
4463 |
void QClipData::fixup() |
|
4464 |
{ |
|
4465 |
Q_ASSERT(m_spans); |
|
4466 |
||
4467 |
if (count == 0) { |
|
4468 |
ymin = ymax = xmin = xmax = 0; |
|
4469 |
return; |
|
4470 |
} |
|
4471 |
||
4472 |
// qDebug("QClipData::fixup: count=%d",count); |
|
4473 |
int y = -1; |
|
4474 |
ymin = m_spans[0].y; |
|
4475 |
ymax = m_spans[count-1].y + 1; |
|
4476 |
xmin = INT_MAX; |
|
4477 |
xmax = 0; |
|
4478 |
||
4479 |
bool isRect = true; |
|
4480 |
int left = m_spans[0].x; |
|
4481 |
int right = m_spans[0].x + m_spans[0].len; |
|
4482 |
||
4483 |
for (int i = 0; i < count; ++i) { |
|
4484 |
if (m_spans[i].y != y) { |
|
4485 |
if (m_spans[i].y != y + 1 && y != -1) { |
|
4486 |
isRect = false; |
|
4487 |
} |
|
4488 |
y = m_spans[i].y; |
|
4489 |
m_clipLines[y].spans = m_spans+i; |
|
4490 |
m_clipLines[y].count = 0; |
|
4491 |
// qDebug() << " new line: y=" << y; |
|
4492 |
} |
|
4493 |
++m_clipLines[y].count; |
|
4494 |
int sl = (int) m_spans[i].x; |
|
4495 |
int sr = sl + m_spans[i].len; |
|
4496 |
||
4497 |
xmin = qMin(xmin, (int)m_spans[i].x); |
|
4498 |
xmax = qMax(xmax, (int)m_spans[i].x + m_spans[i].len); |
|
4499 |
||
4500 |
if (sl != left || sr != right) |
|
4501 |
isRect = false; |
|
4502 |
} |
|
4503 |
// qDebug("xmin=%d,xmax=%d,ymin=%d,ymax=%d %s", xmin, xmax, ymin, ymax, isRect ? "rectangular" : ""); |
|
4504 |
||
4505 |
if (isRect) { |
|
4506 |
hasRectClip = true; |
|
4507 |
clipRect.setRect(xmin, ymin, xmax - xmin, ymax - ymin); |
|
4508 |
} |
|
4509 |
} |
|
4510 |
||
4511 |
/* |
|
4512 |
Convert \a rect to clip spans. |
|
4513 |
*/ |
|
4514 |
void QClipData::setClipRect(const QRect &rect) |
|
4515 |
{ |
|
4516 |
if (hasRectClip && rect == clipRect) |
|
4517 |
return; |
|
4518 |
||
4519 |
// qDebug() << "setClipRect" << clipSpanHeight << count << allocated << rect; |
|
4520 |
hasRectClip = true; |
|
4521 |
hasRegionClip = false; |
|
4522 |
clipRect = rect; |
|
4523 |
||
4524 |
xmin = rect.x(); |
|
4525 |
xmax = rect.x() + rect.width(); |
|
4526 |
ymin = qMin(rect.y(), clipSpanHeight); |
|
4527 |
ymax = qMin(rect.y() + rect.height(), clipSpanHeight); |
|
4528 |
||
4529 |
if (m_spans) { |
|
4530 |
free(m_spans); |
|
4531 |
m_spans = 0; |
|
4532 |
} |
|
4533 |
||
4534 |
// qDebug() << xmin << xmax << ymin << ymax; |
|
4535 |
} |
|
4536 |
||
4537 |
/* |
|
4538 |
Convert \a region to clip spans. |
|
4539 |
*/ |
|
4540 |
void QClipData::setClipRegion(const QRegion ®ion) |
|
4541 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4542 |
if (region.rectCount() == 1) { |
0 | 4543 |
setClipRect(region.rects().at(0)); |
4544 |
return; |
|
4545 |
} |
|
4546 |
||
4547 |
hasRegionClip = true; |
|
4548 |
hasRectClip = false; |
|
4549 |
clipRegion = region; |
|
4550 |
||
4551 |
{ // set bounding rect |
|
4552 |
const QRect rect = region.boundingRect(); |
|
4553 |
xmin = rect.x(); |
|
4554 |
xmax = rect.x() + rect.width(); |
|
4555 |
ymin = rect.y(); |
|
4556 |
ymax = rect.y() + rect.height(); |
|
4557 |
} |
|
4558 |
||
4559 |
if (m_spans) { |
|
4560 |
free(m_spans); |
|
4561 |
m_spans = 0; |
|
4562 |
} |
|
4563 |
||
4564 |
} |
|
4565 |
||
4566 |
/*! |
|
4567 |
\internal |
|
4568 |
spans must be sorted on y |
|
4569 |
*/ |
|
4570 |
static const QSpan *qt_intersect_spans(const QClipData *clip, int *currentClip, |
|
4571 |
const QSpan *spans, const QSpan *end, |
|
4572 |
QSpan **outSpans, int available) |
|
4573 |
{ |
|
4574 |
const_cast<QClipData *>(clip)->initialize(); |
|
4575 |
||
4576 |
QSpan *out = *outSpans; |
|
4577 |
||
4578 |
const QSpan *clipSpans = clip->m_spans + *currentClip; |
|
4579 |
const QSpan *clipEnd = clip->m_spans + clip->count; |
|
4580 |
||
4581 |
while (available && spans < end ) { |
|
4582 |
if (clipSpans >= clipEnd) { |
|
4583 |
spans = end; |
|
4584 |
break; |
|
4585 |
} |
|
4586 |
if (clipSpans->y > spans->y) { |
|
4587 |
++spans; |
|
4588 |
continue; |
|
4589 |
} |
|
4590 |
if (spans->y != clipSpans->y) { |
|
4591 |
if (spans->y < clip->count && clip->m_clipLines[spans->y].spans) |
|
4592 |
clipSpans = clip->m_clipLines[spans->y].spans; |
|
4593 |
else |
|
4594 |
++clipSpans; |
|
4595 |
continue; |
|
4596 |
} |
|
4597 |
Q_ASSERT(spans->y == clipSpans->y); |
|
4598 |
||
4599 |
int sx1 = spans->x; |
|
4600 |
int sx2 = sx1 + spans->len; |
|
4601 |
int cx1 = clipSpans->x; |
|
4602 |
int cx2 = cx1 + clipSpans->len; |
|
4603 |
||
4604 |
if (cx1 < sx1 && cx2 < sx1) { |
|
4605 |
++clipSpans; |
|
4606 |
continue; |
|
4607 |
} else if (sx1 < cx1 && sx2 < cx1) { |
|
4608 |
++spans; |
|
4609 |
continue; |
|
4610 |
} |
|
4611 |
int x = qMax(sx1, cx1); |
|
4612 |
int len = qMin(sx2, cx2) - x; |
|
4613 |
if (len) { |
|
4614 |
out->x = qMax(sx1, cx1); |
|
4615 |
out->len = qMin(sx2, cx2) - out->x; |
|
4616 |
out->y = spans->y; |
|
4617 |
out->coverage = qt_div_255(spans->coverage * clipSpans->coverage); |
|
4618 |
++out; |
|
4619 |
--available; |
|
4620 |
} |
|
4621 |
if (sx2 < cx2) { |
|
4622 |
++spans; |
|
4623 |
} else { |
|
4624 |
++clipSpans; |
|
4625 |
} |
|
4626 |
} |
|
4627 |
||
4628 |
*outSpans = out; |
|
4629 |
*currentClip = clipSpans - clip->m_spans; |
|
4630 |
return spans; |
|
4631 |
} |
|
4632 |
||
4633 |
static void qt_span_fill_clipped(int spanCount, const QSpan *spans, void *userData) |
|
4634 |
{ |
|
4635 |
// qDebug() << "qt_span_fill_clipped" << spanCount; |
|
4636 |
QSpanData *fillData = reinterpret_cast<QSpanData *>(userData); |
|
4637 |
||
4638 |
Q_ASSERT(fillData->blend && fillData->unclipped_blend); |
|
4639 |
||
4640 |
const int NSPANS = 256; |
|
4641 |
QSpan cspans[NSPANS]; |
|
4642 |
int currentClip = 0; |
|
4643 |
const QSpan *end = spans + spanCount; |
|
4644 |
while (spans < end) { |
|
4645 |
QSpan *clipped = cspans; |
|
4646 |
spans = qt_intersect_spans(fillData->clip, ¤tClip, spans, end, &clipped, NSPANS); |
|
4647 |
// qDebug() << "processed " << processed << "clipped" << clipped-cspans |
|
4648 |
// << "span:" << cspans->x << cspans->y << cspans->len << spans->coverage; |
|
4649 |
||
4650 |
if (clipped - cspans) |
|
4651 |
fillData->unclipped_blend(clipped - cspans, cspans, fillData); |
|
4652 |
} |
|
4653 |
} |
|
4654 |
||
4655 |
/* |
|
4656 |
\internal |
|
4657 |
Clip spans to \a{clip}-rectangle. |
|
4658 |
Returns number of unclipped spans |
|
4659 |
*/ |
|
4660 |
static int qt_intersect_spans(QT_FT_Span *spans, int numSpans, |
|
4661 |
const QRect &clip) |
|
4662 |
{ |
|
4663 |
const short minx = clip.left(); |
|
4664 |
const short miny = clip.top(); |
|
4665 |
const short maxx = clip.right(); |
|
4666 |
const short maxy = clip.bottom(); |
|
4667 |
||
4668 |
int n = 0; |
|
4669 |
for (int i = 0; i < numSpans; ++i) { |
|
4670 |
if (spans[i].y > maxy) |
|
4671 |
break; |
|
4672 |
if (spans[i].y < miny |
|
4673 |
|| spans[i].x > maxx |
|
4674 |
|| spans[i].x + spans[i].len <= minx) { |
|
4675 |
continue; |
|
4676 |
} |
|
4677 |
if (spans[i].x < minx) { |
|
4678 |
spans[n].len = qMin(spans[i].len - (minx - spans[i].x), maxx - minx + 1); |
|
4679 |
spans[n].x = minx; |
|
4680 |
} else { |
|
4681 |
spans[n].x = spans[i].x; |
|
4682 |
spans[n].len = qMin(spans[i].len, ushort(maxx - spans[n].x + 1)); |
|
4683 |
} |
|
4684 |
if (spans[n].len == 0) |
|
4685 |
continue; |
|
4686 |
spans[n].y = spans[i].y; |
|
4687 |
spans[n].coverage = spans[i].coverage; |
|
4688 |
++n; |
|
4689 |
} |
|
4690 |
return n; |
|
4691 |
} |
|
4692 |
||
4693 |
||
4694 |
static void qt_span_fill_clipRect(int count, const QSpan *spans, |
|
4695 |
void *userData) |
|
4696 |
{ |
|
4697 |
QSpanData *fillData = reinterpret_cast<QSpanData *>(userData); |
|
4698 |
Q_ASSERT(fillData->blend && fillData->unclipped_blend); |
|
4699 |
||
4700 |
Q_ASSERT(fillData->clip); |
|
4701 |
Q_ASSERT(!fillData->clip->clipRect.isEmpty()); |
|
4702 |
||
4703 |
// hw: check if this const_cast<> is safe!!! |
|
4704 |
count = qt_intersect_spans(const_cast<QSpan*>(spans), count, |
|
4705 |
fillData->clip->clipRect); |
|
4706 |
if (count > 0) |
|
4707 |
fillData->unclipped_blend(count, spans, fillData); |
|
4708 |
} |
|
4709 |
||
4710 |
static void qt_span_clip(int count, const QSpan *spans, void *userData) |
|
4711 |
{ |
|
4712 |
ClipData *clipData = reinterpret_cast<ClipData *>(userData); |
|
4713 |
||
4714 |
// qDebug() << " qt_span_clip: " << count << clipData->operation; |
|
4715 |
// for (int i = 0; i < qMin(count, 10); ++i) { |
|
4716 |
// qDebug() << " " << spans[i].x << spans[i].y << spans[i].len << spans[i].coverage; |
|
4717 |
// } |
|
4718 |
||
4719 |
switch (clipData->operation) { |
|
4720 |
||
4721 |
case Qt::IntersectClip: |
|
4722 |
{ |
|
4723 |
QClipData *newClip = clipData->newClip; |
|
4724 |
newClip->initialize(); |
|
4725 |
||
4726 |
int currentClip = 0; |
|
4727 |
const QSpan *end = spans + count; |
|
4728 |
while (spans < end) { |
|
4729 |
QSpan *newspans = newClip->m_spans + newClip->count; |
|
4730 |
spans = qt_intersect_spans(clipData->oldClip, ¤tClip, spans, end, |
|
4731 |
&newspans, newClip->allocated - newClip->count); |
|
4732 |
newClip->count = newspans - newClip->m_spans; |
|
4733 |
if (spans < end) { |
|
4734 |
newClip->m_spans = q_check_ptr((QSpan *)realloc(newClip->m_spans, newClip->allocated*2*sizeof(QSpan))); |
|
4735 |
newClip->allocated *= 2; |
|
4736 |
} |
|
4737 |
} |
|
4738 |
} |
|
4739 |
break; |
|
4740 |
||
4741 |
case Qt::UniteClip: |
|
4742 |
case Qt::ReplaceClip: |
|
4743 |
clipData->newClip->appendSpans(spans, count); |
|
4744 |
break; |
|
4745 |
case Qt::NoClip: |
|
4746 |
break; |
|
4747 |
} |
|
4748 |
} |
|
4749 |
||
4750 |
#ifndef QT_NO_DEBUG |
|
4751 |
QImage QRasterBuffer::bufferImage() const |
|
4752 |
{ |
|
4753 |
QImage image(m_width, m_height, QImage::Format_ARGB32_Premultiplied); |
|
4754 |
||
4755 |
for (int y = 0; y < m_height; ++y) { |
|
4756 |
uint *span = (uint *)const_cast<QRasterBuffer *>(this)->scanLine(y); |
|
4757 |
||
4758 |
for (int x=0; x<m_width; ++x) { |
|
4759 |
uint argb = span[x]; |
|
4760 |
image.setPixel(x, y, argb); |
|
4761 |
} |
|
4762 |
} |
|
4763 |
return image; |
|
4764 |
} |
|
4765 |
#endif |
|
4766 |
||
4767 |
||
4768 |
void QRasterBuffer::flushToARGBImage(QImage *target) const |
|
4769 |
{ |
|
4770 |
int w = qMin(m_width, target->width()); |
|
4771 |
int h = qMin(m_height, target->height()); |
|
4772 |
||
4773 |
for (int y=0; y<h; ++y) { |
|
4774 |
uint *sourceLine = (uint *)const_cast<QRasterBuffer *>(this)->scanLine(y); |
|
4775 |
QRgb *dest = (QRgb *) target->scanLine(y); |
|
4776 |
for (int x=0; x<w; ++x) { |
|
4777 |
QRgb pixel = sourceLine[x]; |
|
4778 |
int alpha = qAlpha(pixel); |
|
4779 |
if (!alpha) { |
|
4780 |
dest[x] = 0; |
|
4781 |
} else { |
|
4782 |
dest[x] = (alpha << 24) |
|
4783 |
| ((255*qRed(pixel)/alpha) << 16) |
|
4784 |
| ((255*qGreen(pixel)/alpha) << 8) |
|
4785 |
| ((255*qBlue(pixel)/alpha) << 0); |
|
4786 |
} |
|
4787 |
} |
|
4788 |
} |
|
4789 |
} |
|
4790 |
||
4791 |
||
4792 |
class QGradientCache |
|
4793 |
{ |
|
4794 |
struct CacheInfo |
|
4795 |
{ |
|
4796 |
inline CacheInfo(QGradientStops s, int op, QGradient::InterpolationMode mode) : |
|
4797 |
stops(s), opacity(op), interpolationMode(mode) {} |
|
4798 |
uint buffer[GRADIENT_STOPTABLE_SIZE]; |
|
4799 |
QGradientStops stops; |
|
4800 |
int opacity; |
|
4801 |
QGradient::InterpolationMode interpolationMode; |
|
4802 |
}; |
|
4803 |
||
4804 |
typedef QMultiHash<quint64, CacheInfo> QGradientColorTableHash; |
|
4805 |
||
4806 |
public: |
|
4807 |
inline const uint *getBuffer(const QGradient &gradient, int opacity) { |
|
4808 |
quint64 hash_val = 0; |
|
4809 |
||
4810 |
QGradientStops stops = gradient.stops(); |
|
4811 |
for (int i = 0; i < stops.size() && i <= 2; i++) |
|
4812 |
hash_val += stops[i].second.rgba(); |
|
4813 |
||
4814 |
QGradientColorTableHash::const_iterator it = cache.constFind(hash_val); |
|
4815 |
||
4816 |
if (it == cache.constEnd()) |
|
4817 |
return addCacheElement(hash_val, gradient, opacity); |
|
4818 |
else { |
|
4819 |
do { |
|
4820 |
const CacheInfo &cache_info = it.value(); |
|
4821 |
if (cache_info.stops == stops && cache_info.opacity == opacity && cache_info.interpolationMode == gradient.interpolationMode()) |
|
4822 |
return cache_info.buffer; |
|
4823 |
++it; |
|
4824 |
} while (it != cache.constEnd() && it.key() == hash_val); |
|
4825 |
// an exact match for these stops and opacity was not found, create new cache |
|
4826 |
return addCacheElement(hash_val, gradient, opacity); |
|
4827 |
} |
|
4828 |
} |
|
4829 |
||
4830 |
inline int paletteSize() const { return GRADIENT_STOPTABLE_SIZE; } |
|
4831 |
protected: |
|
4832 |
inline int maxCacheSize() const { return 60; } |
|
4833 |
inline void generateGradientColorTable(const QGradient& g, |
|
4834 |
uint *colorTable, |
|
4835 |
int size, int opacity) const; |
|
4836 |
uint *addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) { |
|
4837 |
if (cache.size() == maxCacheSize()) { |
|
4838 |
int elem_to_remove = qrand() % maxCacheSize(); |
|
4839 |
cache.remove(cache.keys()[elem_to_remove]); // may remove more than 1, but OK |
|
4840 |
} |
|
4841 |
CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode()); |
|
4842 |
generateGradientColorTable(gradient, cache_entry.buffer, paletteSize(), opacity); |
|
4843 |
return cache.insert(hash_val, cache_entry).value().buffer; |
|
4844 |
} |
|
4845 |
||
4846 |
QGradientColorTableHash cache; |
|
4847 |
}; |
|
4848 |
||
4849 |
void QGradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, int opacity) const |
|
4850 |
{ |
|
4851 |
QGradientStops stops = gradient.stops(); |
|
4852 |
int stopCount = stops.count(); |
|
4853 |
Q_ASSERT(stopCount > 0); |
|
4854 |
||
4855 |
bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation); |
|
4856 |
||
4857 |
uint current_color = ARGB_COMBINE_ALPHA(stops[0].second.rgba(), opacity); |
|
4858 |
if (stopCount == 1) { |
|
4859 |
current_color = PREMUL(current_color); |
|
4860 |
for (int i = 0; i < size; ++i) |
|
4861 |
colorTable[i] = current_color; |
|
4862 |
return; |
|
4863 |
} |
|
4864 |
||
4865 |
// The position where the gradient begins and ends |
|
4866 |
qreal begin_pos = stops[0].first; |
|
4867 |
qreal end_pos = stops[stopCount-1].first; |
|
4868 |
||
4869 |
int pos = 0; // The position in the color table. |
|
4870 |
uint next_color; |
|
4871 |
||
4872 |
qreal incr = 1 / qreal(size); // the double increment. |
|
4873 |
qreal dpos = 1.5 * incr; // current position in gradient stop list (0 to 1) |
|
4874 |
||
4875 |
// Up to first point |
|
4876 |
colorTable[pos++] = PREMUL(current_color); |
|
4877 |
while (dpos <= begin_pos) { |
|
4878 |
colorTable[pos] = colorTable[pos - 1]; |
|
4879 |
++pos; |
|
4880 |
dpos += incr; |
|
4881 |
} |
|
4882 |
||
4883 |
int current_stop = 0; // We always interpolate between current and current + 1. |
|
4884 |
||
4885 |
qreal t; // position between current left and right stops |
|
4886 |
qreal t_delta; // the t increment per entry in the color table |
|
4887 |
||
4888 |
if (dpos < end_pos) { |
|
4889 |
// Gradient area |
|
4890 |
while (dpos > stops[current_stop+1].first) |
|
4891 |
++current_stop; |
|
4892 |
||
4893 |
if (current_stop != 0) |
|
4894 |
current_color = ARGB_COMBINE_ALPHA(stops[current_stop].second.rgba(), opacity); |
|
4895 |
next_color = ARGB_COMBINE_ALPHA(stops[current_stop+1].second.rgba(), opacity); |
|
4896 |
||
4897 |
if (colorInterpolation) { |
|
4898 |
current_color = PREMUL(current_color); |
|
4899 |
next_color = PREMUL(next_color); |
|
4900 |
} |
|
4901 |
||
4902 |
qreal diff = stops[current_stop+1].first - stops[current_stop].first; |
|
4903 |
qreal c = (diff == 0) ? qreal(0) : 256 / diff; |
|
4904 |
t = (dpos - stops[current_stop].first) * c; |
|
4905 |
t_delta = incr * c; |
|
4906 |
||
4907 |
while (true) { |
|
4908 |
Q_ASSERT(current_stop < stopCount); |
|
4909 |
||
4910 |
int dist = qRound(t); |
|
4911 |
int idist = 256 - dist; |
|
4912 |
||
4913 |
if (colorInterpolation) |
|
4914 |
colorTable[pos] = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist); |
|
4915 |
else |
|
4916 |
colorTable[pos] = PREMUL(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)); |
|
4917 |
||
4918 |
++pos; |
|
4919 |
dpos += incr; |
|
4920 |
||
4921 |
if (dpos >= end_pos) |
|
4922 |
break; |
|
4923 |
||
4924 |
t += t_delta; |
|
4925 |
||
4926 |
int skip = 0; |
|
4927 |
while (dpos > stops[current_stop+skip+1].first) |
|
4928 |
++skip; |
|
4929 |
||
4930 |
if (skip != 0) { |
|
4931 |
current_stop += skip; |
|
4932 |
if (skip == 1) |
|
4933 |
current_color = next_color; |
|
4934 |
else |
|
4935 |
current_color = ARGB_COMBINE_ALPHA(stops[current_stop].second.rgba(), opacity); |
|
4936 |
next_color = ARGB_COMBINE_ALPHA(stops[current_stop+1].second.rgba(), opacity); |
|
4937 |
||
4938 |
if (colorInterpolation) { |
|
4939 |
if (skip != 1) |
|
4940 |
current_color = PREMUL(current_color); |
|
4941 |
next_color = PREMUL(next_color); |
|
4942 |
} |
|
4943 |
||
4944 |
qreal diff = stops[current_stop+1].first - stops[current_stop].first; |
|
4945 |
qreal c = (diff == 0) ? qreal(0) : 256 / diff; |
|
4946 |
t = (dpos - stops[current_stop].first) * c; |
|
4947 |
t_delta = incr * c; |
|
4948 |
} |
|
4949 |
} |
|
4950 |
} |
|
4951 |
||
4952 |
// After last point |
|
4953 |
current_color = PREMUL(ARGB_COMBINE_ALPHA(stops[stopCount - 1].second.rgba(), opacity)); |
|
4954 |
while (pos < size - 1) { |
|
4955 |
colorTable[pos] = current_color; |
|
4956 |
++pos; |
|
4957 |
} |
|
4958 |
||
4959 |
// Make sure the last color stop is represented at the end of the table |
|
4960 |
colorTable[size - 1] = current_color; |
|
4961 |
} |
|
4962 |
||
4963 |
Q_GLOBAL_STATIC(QGradientCache, qt_gradient_cache) |
|
4964 |
||
4965 |
||
4966 |
void QSpanData::init(QRasterBuffer *rb, const QRasterPaintEngine *pe) |
|
4967 |
{ |
|
4968 |
rasterBuffer = rb; |
|
4969 |
#ifdef Q_WS_QWS |
|
4970 |
rasterEngine = const_cast<QRasterPaintEngine *>(pe); |
|
4971 |
#endif |
|
4972 |
type = None; |
|
4973 |
txop = 0; |
|
4974 |
bilinear = false; |
|
4975 |
m11 = m22 = m33 = 1.; |
|
4976 |
m12 = m13 = m21 = m23 = dx = dy = 0.0; |
|
4977 |
clip = pe ? pe->d_func()->clip() : 0; |
|
4978 |
} |
|
4979 |
||
4980 |
extern QImage qt_imageForBrush(int brushStyle, bool invert); |
|
4981 |
||
4982 |
void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode) |
|
4983 |
{ |
|
4984 |
Qt::BrushStyle brushStyle = qbrush_style(brush); |
|
4985 |
switch (brushStyle) { |
|
4986 |
case Qt::SolidPattern: { |
|
4987 |
type = Solid; |
|
4988 |
QColor c = qbrush_color(brush); |
|
4989 |
solid.color = PREMUL(ARGB_COMBINE_ALPHA(c.rgba(), alpha)); |
|
4990 |
if ((solid.color & 0xff000000) == 0 |
|
4991 |
&& compositionMode == QPainter::CompositionMode_SourceOver) { |
|
4992 |
type = None; |
|
4993 |
} |
|
4994 |
break; |
|
4995 |
} |
|
4996 |
||
4997 |
case Qt::LinearGradientPattern: |
|
4998 |
{ |
|
4999 |
type = LinearGradient; |
|
5000 |
const QLinearGradient *g = static_cast<const QLinearGradient *>(brush.gradient()); |
|
5001 |
gradient.alphaColor = !brush.isOpaque() || alpha != 256; |
|
5002 |
gradient.colorTable = const_cast<uint*>(qt_gradient_cache()->getBuffer(*g, alpha)); |
|
5003 |
gradient.spread = g->spread(); |
|
5004 |
||
5005 |
QLinearGradientData &linearData = gradient.linear; |
|
5006 |
||
5007 |
linearData.origin.x = g->start().x(); |
|
5008 |
linearData.origin.y = g->start().y(); |
|
5009 |
linearData.end.x = g->finalStop().x(); |
|
5010 |
linearData.end.y = g->finalStop().y(); |
|
5011 |
break; |
|
5012 |
} |
|
5013 |
||
5014 |
case Qt::RadialGradientPattern: |
|
5015 |
{ |
|
5016 |
type = RadialGradient; |
|
5017 |
const QRadialGradient *g = static_cast<const QRadialGradient *>(brush.gradient()); |
|
5018 |
gradient.alphaColor = !brush.isOpaque() || alpha != 256; |
|
5019 |
gradient.colorTable = const_cast<uint*>(qt_gradient_cache()->getBuffer(*g, alpha)); |
|
5020 |
gradient.spread = g->spread(); |
|
5021 |
||
5022 |
QRadialGradientData &radialData = gradient.radial; |
|
5023 |
||
5024 |
QPointF center = g->center(); |
|
5025 |
radialData.center.x = center.x(); |
|
5026 |
radialData.center.y = center.y(); |
|
5027 |
QPointF focal = g->focalPoint(); |
|
5028 |
radialData.focal.x = focal.x(); |
|
5029 |
radialData.focal.y = focal.y(); |
|
5030 |
radialData.radius = g->radius(); |
|
5031 |
} |
|
5032 |
break; |
|
5033 |
||
5034 |
case Qt::ConicalGradientPattern: |
|
5035 |
{ |
|
5036 |
type = ConicalGradient; |
|
5037 |
const QConicalGradient *g = static_cast<const QConicalGradient *>(brush.gradient()); |
|
5038 |
gradient.alphaColor = !brush.isOpaque() || alpha != 256; |
|
5039 |
gradient.colorTable = const_cast<uint*>(qt_gradient_cache()->getBuffer(*g, alpha)); |
|
5040 |
gradient.spread = QGradient::RepeatSpread; |
|
5041 |
||
5042 |
QConicalGradientData &conicalData = gradient.conical; |
|
5043 |
||
5044 |
QPointF center = g->center(); |
|
5045 |
conicalData.center.x = center.x(); |
|
5046 |
conicalData.center.y = center.y(); |
|
5047 |
conicalData.angle = g->angle() * 2 * Q_PI / 360.0; |
|
5048 |
} |
|
5049 |
break; |
|
5050 |
||
5051 |
case Qt::Dense1Pattern: |
|
5052 |
case Qt::Dense2Pattern: |
|
5053 |
case Qt::Dense3Pattern: |
|
5054 |
case Qt::Dense4Pattern: |
|
5055 |
case Qt::Dense5Pattern: |
|
5056 |
case Qt::Dense6Pattern: |
|
5057 |
case Qt::Dense7Pattern: |
|
5058 |
case Qt::HorPattern: |
|
5059 |
case Qt::VerPattern: |
|
5060 |
case Qt::CrossPattern: |
|
5061 |
case Qt::BDiagPattern: |
|
5062 |
case Qt::FDiagPattern: |
|
5063 |
case Qt::DiagCrossPattern: |
|
5064 |
type = Texture; |
|
5065 |
if (!tempImage) |
|
5066 |
tempImage = new QImage(); |
|
5067 |
*tempImage = rasterBuffer->colorizeBitmap(qt_imageForBrush(brushStyle, true), brush.color()); |
|
5068 |
initTexture(tempImage, alpha, QTextureData::Tiled); |
|
5069 |
break; |
|
5070 |
case Qt::TexturePattern: |
|
5071 |
type = Texture; |
|
5072 |
if (!tempImage) |
|
5073 |
tempImage = new QImage(); |
|
5074 |
||
5075 |
if (qHasPixmapTexture(brush) && brush.texture().isQBitmap()) |
|
5076 |
*tempImage = rasterBuffer->colorizeBitmap(brush.textureImage(), brush.color()); |
|
5077 |
else |
|
5078 |
*tempImage = brush.textureImage(); |
|
5079 |
initTexture(tempImage, alpha, QTextureData::Tiled, tempImage->rect()); |
|
5080 |
break; |
|
5081 |
||
5082 |
case Qt::NoBrush: |
|
5083 |
default: |
|
5084 |
type = None; |
|
5085 |
break; |
|
5086 |
} |
|
5087 |
adjustSpanMethods(); |
|
5088 |
} |
|
5089 |
||
5090 |
void QSpanData::adjustSpanMethods() |
|
5091 |
{ |
|
5092 |
bitmapBlit = 0; |
|
5093 |
alphamapBlit = 0; |
|
5094 |
alphaRGBBlit = 0; |
|
5095 |
||
5096 |
fillRect = 0; |
|
5097 |
||
5098 |
switch(type) { |
|
5099 |
case None: |
|
5100 |
unclipped_blend = 0; |
|
5101 |
break; |
|
5102 |
case Solid: |
|
5103 |
unclipped_blend = rasterBuffer->drawHelper->blendColor; |
|
5104 |
bitmapBlit = rasterBuffer->drawHelper->bitmapBlit; |
|
5105 |
alphamapBlit = rasterBuffer->drawHelper->alphamapBlit; |
|
5106 |
alphaRGBBlit = rasterBuffer->drawHelper->alphaRGBBlit; |
|
5107 |
fillRect = rasterBuffer->drawHelper->fillRect; |
|
5108 |
break; |
|
5109 |
case LinearGradient: |
|
5110 |
case RadialGradient: |
|
5111 |
case ConicalGradient: |
|
5112 |
unclipped_blend = rasterBuffer->drawHelper->blendGradient; |
|
5113 |
break; |
|
5114 |
case Texture: |
|
5115 |
#ifdef Q_WS_QWS |
|
5116 |
#ifndef QT_NO_RASTERCALLBACKS |
|
5117 |
if (!rasterBuffer->buffer()) |
|
5118 |
unclipped_blend = qBlendTextureCallback; |
|
5119 |
else |
|
5120 |
#endif |
|
5121 |
unclipped_blend = qBlendTexture; |
|
5122 |
#else |
|
5123 |
unclipped_blend = qBlendTexture; |
|
5124 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5125 |
if (!texture.imageData) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5126 |
unclipped_blend = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5127 |
|
0 | 5128 |
break; |
5129 |
} |
|
5130 |
// setup clipping |
|
5131 |
if (!unclipped_blend) { |
|
5132 |
blend = 0; |
|
5133 |
} else if (!clip) { |
|
5134 |
blend = unclipped_blend; |
|
5135 |
} else if (clip->hasRectClip) { |
|
5136 |
blend = clip->clipRect.isEmpty() ? 0 : qt_span_fill_clipRect; |
|
5137 |
} else { |
|
5138 |
blend = qt_span_fill_clipped; |
|
5139 |
} |
|
5140 |
} |
|
5141 |
||
5142 |
void QSpanData::setupMatrix(const QTransform &matrix, int bilin) |
|
5143 |
{ |
|
5144 |
QTransform delta; |
|
5145 |
// make sure we round off correctly in qdrawhelper.cpp |
|
5146 |
delta.translate(1.0 / 65536, 1.0 / 65536); |
|
5147 |
||
5148 |
QTransform inv = (delta * matrix).inverted(); |
|
5149 |
m11 = inv.m11(); |
|
5150 |
m12 = inv.m12(); |
|
5151 |
m13 = inv.m13(); |
|
5152 |
m21 = inv.m21(); |
|
5153 |
m22 = inv.m22(); |
|
5154 |
m23 = inv.m23(); |
|
5155 |
m33 = inv.m33(); |
|
5156 |
dx = inv.dx(); |
|
5157 |
dy = inv.dy(); |
|
5158 |
txop = inv.type(); |
|
5159 |
bilinear = bilin; |
|
5160 |
||
5161 |
const bool affine = !m13 && !m23; |
|
5162 |
fast_matrix = affine |
|
5163 |
&& m11 * m11 + m21 * m21 < 1e4 |
|
5164 |
&& m12 * m12 + m22 * m22 < 1e4 |
|
5165 |
&& qAbs(dx) < 1e4 |
|
5166 |
&& qAbs(dy) < 1e4; |
|
5167 |
||
5168 |
adjustSpanMethods(); |
|
5169 |
} |
|
5170 |
||
5171 |
extern const QVector<QRgb> *qt_image_colortable(const QImage &image); |
|
5172 |
||
5173 |
void QSpanData::initTexture(const QImage *image, int alpha, QTextureData::Type _type, const QRect &sourceRect) |
|
5174 |
{ |
|
5175 |
const QImageData *d = const_cast<QImage *>(image)->data_ptr(); |
|
5176 |
if (!d || d->height == 0) { |
|
5177 |
texture.imageData = 0; |
|
5178 |
texture.width = 0; |
|
5179 |
texture.height = 0; |
|
5180 |
texture.x1 = 0; |
|
5181 |
texture.y1 = 0; |
|
5182 |
texture.x2 = 0; |
|
5183 |
texture.y2 = 0; |
|
5184 |
texture.bytesPerLine = 0; |
|
5185 |
texture.format = QImage::Format_Invalid; |
|
5186 |
texture.colorTable = 0; |
|
5187 |
texture.hasAlpha = alpha != 256; |
|
5188 |
} else { |
|
5189 |
texture.imageData = d->data; |
|
5190 |
texture.width = d->width; |
|
5191 |
texture.height = d->height; |
|
5192 |
||
5193 |
if (sourceRect.isNull()) { |
|
5194 |
texture.x1 = 0; |
|
5195 |
texture.y1 = 0; |
|
5196 |
texture.x2 = texture.width; |
|
5197 |
texture.y2 = texture.height; |
|
5198 |
} else { |
|
5199 |
texture.x1 = sourceRect.x(); |
|
5200 |
texture.y1 = sourceRect.y(); |
|
5201 |
texture.x2 = qMin(texture.x1 + sourceRect.width(), d->width); |
|
5202 |
texture.y2 = qMin(texture.y1 + sourceRect.height(), d->height); |
|
5203 |
} |
|
5204 |
||
5205 |
texture.bytesPerLine = d->bytes_per_line; |
|
5206 |
||
5207 |
texture.format = d->format; |
|
5208 |
texture.colorTable = (d->format <= QImage::Format_Indexed8 && !d->colortable.isEmpty()) ? &d->colortable : 0; |
|
5209 |
texture.hasAlpha = image->hasAlphaChannel() || alpha != 256; |
|
5210 |
} |
|
5211 |
texture.const_alpha = alpha; |
|
5212 |
texture.type = _type; |
|
5213 |
||
5214 |
adjustSpanMethods(); |
|
5215 |
} |
|
5216 |
||
5217 |
#ifdef Q_WS_WIN |
|
5218 |
||
5219 |
||
5220 |
#endif |
|
5221 |
||
5222 |
||
5223 |
/*! |
|
5224 |
\internal |
|
5225 |
||
5226 |
Draws a line using the floating point midpoint algorithm. The line |
|
5227 |
\a line is already in device coords at this point. |
|
5228 |
*/ |
|
5229 |
||
5230 |
static void drawLine_midpoint_i(int x1, int y1, int x2, int y2, ProcessSpans span_func, QSpanData *data, |
|
5231 |
LineDrawMode style, const QIntRect &devRect) |
|
5232 |
{ |
|
5233 |
#ifdef QT_DEBUG_DRAW |
|
5234 |
qDebug() << " - drawLine_midpoint_i" << QLine(QPoint(x1, y1), QPoint(x2, y2)); |
|
5235 |
#endif |
|
5236 |
||
5237 |
int x, y; |
|
5238 |
int dx, dy, d, incrE, incrNE; |
|
5239 |
||
5240 |
dx = x2 - x1; |
|
5241 |
dy = y2 - y1; |
|
5242 |
||
5243 |
const int NSPANS = 256; |
|
5244 |
QT_FT_Span spans[NSPANS]; |
|
5245 |
int current = 0; |
|
5246 |
bool ordered = true; |
|
5247 |
||
5248 |
if (dy == 0) { |
|
5249 |
// specialcase horizontal lines |
|
5250 |
if (y1 >= devRect.y1 && y1 < devRect.y2) { |
|
5251 |
int start = qMax(devRect.x1, qMin(x1, x2)); |
|
5252 |
int stop = qMax(x1, x2) + 1; |
|
5253 |
int stop_clipped = qMin(devRect.x2, stop); |
|
5254 |
int len = stop_clipped - start; |
|
5255 |
if (style == LineDrawNormal && stop == stop_clipped) |
|
5256 |
len--; |
|
5257 |
if (len > 0) { |
|
5258 |
spans[0].x = ushort(start); |
|
5259 |
spans[0].len = ushort(len); |
|
5260 |
spans[0].y = y1; |
|
5261 |
spans[0].coverage = 255; |
|
5262 |
span_func(1, spans, data); |
|
5263 |
} |
|
5264 |
} |
|
5265 |
return; |
|
5266 |
} else if (dx == 0) { |
|
5267 |
// specialcase vertical lines |
|
5268 |
if (x1 >= devRect.x1 && x1 < devRect.x2) { |
|
5269 |
int start = qMax(devRect.y1, qMin(y1, y2)); |
|
5270 |
int stop = qMax(y1, y2) + 1; |
|
5271 |
int stop_clipped = qMin(devRect.y2, stop); |
|
5272 |
int len = stop_clipped - start; |
|
5273 |
if (style == LineDrawNormal && stop == stop_clipped) |
|
5274 |
len--; |
|
5275 |
// hw: create spans directly instead to possibly avoid clipping |
|
5276 |
if (len > 0) |
|
5277 |
fillRect_normalized(QRect(x1, start, 1, len).normalized(), data, 0); |
|
5278 |
} |
|
5279 |
return; |
|
5280 |
} |
|
5281 |
||
5282 |
||
5283 |
if (qAbs(dx) >= qAbs(dy)) { /* if x is the major axis: */ |
|
5284 |
||
5285 |
if (x2 < x1) { /* if coordinates are out of order */ |
|
5286 |
qt_swap_int(x1, x2); |
|
5287 |
dx = -dx; |
|
5288 |
||
5289 |
qt_swap_int(y1, y2); |
|
5290 |
dy = -dy; |
|
5291 |
} |
|
5292 |
||
5293 |
int x_lower_limit = - 128; |
|
5294 |
if (x1 < x_lower_limit) { |
|
5295 |
int cy = dy * (x_lower_limit - x1) / dx + y1; |
|
5296 |
drawLine_midpoint_i(x_lower_limit, cy, x2, y2, span_func, data, style, devRect); |
|
5297 |
return; |
|
5298 |
} |
|
5299 |
||
5300 |
if (style == LineDrawNormal) |
|
5301 |
--x2; |
|
5302 |
||
5303 |
// In the loops below we increment before call the span function so |
|
5304 |
// we need to stop one pixel before |
|
5305 |
x2 = qMin(x2, devRect.x2 - 1); |
|
5306 |
||
5307 |
// completely clipped, so abort |
|
5308 |
if (x2 <= x1) { |
|
5309 |
return; |
|
5310 |
} |
|
5311 |
||
5312 |
int x = x1; |
|
5313 |
int y = y1; |
|
5314 |
||
5315 |
if (y2 <= y1) |
|
5316 |
ordered = false; |
|
5317 |
||
5318 |
{ |
|
5319 |
const int index = (ordered ? current : NSPANS - 1 - current); |
|
5320 |
spans[index].coverage = 255; |
|
5321 |
spans[index].x = x; |
|
5322 |
spans[index].y = y; |
|
5323 |
||
5324 |
if (x >= devRect.x1 && y >= devRect.y1 && y < devRect.y2) |
|
5325 |
spans[index].len = 1; |
|
5326 |
else |
|
5327 |
spans[index].len = 0; |
|
5328 |
} |
|
5329 |
||
5330 |
if (y2 > y1) { // 315 -> 360 and 135 -> 180 (unit circle degrees) |
|
5331 |
y2 = qMin(y2, devRect.y2 - 1); |
|
5332 |
||
5333 |
incrE = dy * 2; |
|
5334 |
d = incrE - dx; |
|
5335 |
incrNE = (dy - dx) * 2; |
|
5336 |
||
5337 |
if (y > y2) |
|
5338 |
goto flush_and_return; |
|
5339 |
||
5340 |
while (x < x2) { |
|
5341 |
++x; |
|
5342 |
if (d > 0) { |
|
5343 |
if (spans[current].len > 0) |
|
5344 |
++current; |
|
5345 |
if (current == NSPANS) { |
|
5346 |
span_func(NSPANS, spans, data); |
|
5347 |
current = 0; |
|
5348 |
} |
|
5349 |
||
5350 |
++y; |
|
5351 |
d += incrNE; |
|
5352 |
if (y > y2) |
|
5353 |
goto flush_and_return; |
|
5354 |
||
5355 |
spans[current].len = 0; |
|
5356 |
spans[current].coverage = 255; |
|
5357 |
spans[current].x = x; |
|
5358 |
spans[current].y = y; |
|
5359 |
} else { |
|
5360 |
d += incrE; |
|
5361 |
if (x == devRect.x1) |
|
5362 |
spans[current].x = devRect.x1; |
|
5363 |
} |
|
5364 |
||
5365 |
if (x < devRect.x1 || y < devRect.y1) |
|
5366 |
continue; |
|
5367 |
||
5368 |
Q_ASSERT(x<devRect.x2); |
|
5369 |
Q_ASSERT(y<devRect.y2); |
|
5370 |
Q_ASSERT(spans[current].y == y); |
|
5371 |
spans[current].len++; |
|
5372 |
} |
|
5373 |
if (spans[current].len > 0) { |
|
5374 |
++current; |
|
5375 |
} |
|
5376 |
} else { // 0-45 and 180->225 (unit circle degrees) |
|
5377 |
||
5378 |
y1 = qMin(y1, devRect.y2 - 1); |
|
5379 |
||
5380 |
incrE = dy * 2; |
|
5381 |
d = incrE + dx; |
|
5382 |
incrNE = (dy + dx) * 2; |
|
5383 |
||
5384 |
if (y < devRect.y1) |
|
5385 |
goto flush_and_return; |
|
5386 |
||
5387 |
while (x < x2) { |
|
5388 |
++x; |
|
5389 |
if (d < 0) { |
|
5390 |
if (spans[NSPANS - 1 - current].len > 0) |
|
5391 |
++current; |
|
5392 |
if (current == NSPANS) { |
|
5393 |
span_func(NSPANS, spans, data); |
|
5394 |
current = 0; |
|
5395 |
} |
|
5396 |
||
5397 |
--y; |
|
5398 |
d += incrNE; |
|
5399 |
if (y < devRect.y1) |
|
5400 |
goto flush_and_return; |
|
5401 |
||
5402 |
const int index = NSPANS - 1 - current; |
|
5403 |
spans[index].len = 0; |
|
5404 |
spans[index].coverage = 255; |
|
5405 |
spans[index].x = x; |
|
5406 |
spans[index].y = y; |
|
5407 |
} else { |
|
5408 |
d += incrE; |
|
5409 |
if (x == devRect.x1) |
|
5410 |
spans[NSPANS - 1 - current].x = devRect.x1; |
|
5411 |
} |
|
5412 |
||
5413 |
if (x < devRect.x1 || y > y1) |
|
5414 |
continue; |
|
5415 |
||
5416 |
Q_ASSERT(x<devRect.x2 && y<devRect.y2); |
|
5417 |
Q_ASSERT(spans[NSPANS - 1 - current].y == y); |
|
5418 |
spans[NSPANS - 1 - current].len++; |
|
5419 |
} |
|
5420 |
if (spans[NSPANS - 1 - current].len > 0) { |
|
5421 |
++current; |
|
5422 |
} |
|
5423 |
} |
|
5424 |
||
5425 |
} else { |
|
5426 |
||
5427 |
// if y is the major axis: |
|
5428 |
||
5429 |
if (y2 < y1) { /* if coordinates are out of order */ |
|
5430 |
qt_swap_int(y1, y2); |
|
5431 |
dy = -dy; |
|
5432 |
||
5433 |
qt_swap_int(x1, x2); |
|
5434 |
dx = -dx; |
|
5435 |
} |
|
5436 |
||
5437 |
int y_lower_limit = - 128; |
|
5438 |
if (y1 < y_lower_limit) { |
|
5439 |
int cx = dx * (y_lower_limit - y1) / dy + x1; |
|
5440 |
drawLine_midpoint_i(cx, y_lower_limit, x2, y2, span_func, data, style, devRect); |
|
5441 |
return; |
|
5442 |
} |
|
5443 |
||
5444 |
if (style == LineDrawNormal) |
|
5445 |
--y2; |
|
5446 |
||
5447 |
// In the loops below we increment before call the span function so |
|
5448 |
// we need to stop one pixel before |
|
5449 |
y2 = qMin(y2, devRect.y2 - 1); |
|
5450 |
||
5451 |
// completely clipped, so abort |
|
5452 |
if (y2 <= y1) { |
|
5453 |
return; |
|
5454 |
} |
|
5455 |
||
5456 |
x = x1; |
|
5457 |
y = y1; |
|
5458 |
||
5459 |
if (x>=devRect.x1 && y>=devRect.y1 && x < devRect.x2) { |
|
5460 |
Q_ASSERT(x >= devRect.x1 && y >= devRect.y1 && x < devRect.x2 && y < devRect.y2); |
|
5461 |
if (current == NSPANS) { |
|
5462 |
span_func(NSPANS, spans, data); |
|
5463 |
current = 0; |
|
5464 |
} |
|
5465 |
spans[current].len = 1; |
|
5466 |
spans[current].coverage = 255; |
|
5467 |
spans[current].x = x; |
|
5468 |
spans[current].y = y; |
|
5469 |
++current; |
|
5470 |
} |
|
5471 |
||
5472 |
if (x2 > x1) { // 90 -> 135 and 270 -> 315 (unit circle degrees) |
|
5473 |
x2 = qMin(x2, devRect.x2 - 1); |
|
5474 |
incrE = dx * 2; |
|
5475 |
d = incrE - dy; |
|
5476 |
incrNE = (dx - dy) * 2; |
|
5477 |
||
5478 |
if (x > x2) |
|
5479 |
goto flush_and_return; |
|
5480 |
||
5481 |
while (y < y2) { |
|
5482 |
if (d > 0) { |
|
5483 |
++x; |
|
5484 |
d += incrNE; |
|
5485 |
if (x > x2) |
|
5486 |
goto flush_and_return; |
|
5487 |
} else { |
|
5488 |
d += incrE; |
|
5489 |
} |
|
5490 |
++y; |
|
5491 |
if (x < devRect.x1 || y < devRect.y1) |
|
5492 |
continue; |
|
5493 |
Q_ASSERT(x<devRect.x2 && y<devRect.y2); |
|
5494 |
if (current == NSPANS) { |
|
5495 |
span_func(NSPANS, spans, data); |
|
5496 |
current = 0; |
|
5497 |
} |
|
5498 |
spans[current].len = 1; |
|
5499 |
spans[current].coverage = 255; |
|
5500 |
spans[current].x = x; |
|
5501 |
spans[current].y = y; |
|
5502 |
++current; |
|
5503 |
} |
|
5504 |
} else { // 45 -> 90 and 225 -> 270 (unit circle degrees) |
|
5505 |
x1 = qMin(x1, devRect.x2 - 1); |
|
5506 |
incrE = dx * 2; |
|
5507 |
d = incrE + dy; |
|
5508 |
incrNE = (dx + dy) * 2; |
|
5509 |
||
5510 |
if (x < devRect.x1) |
|
5511 |
goto flush_and_return; |
|
5512 |
||
5513 |
while (y < y2) { |
|
5514 |
if (d < 0) { |
|
5515 |
--x; |
|
5516 |
d += incrNE; |
|
5517 |
if (x < devRect.x1) |
|
5518 |
goto flush_and_return; |
|
5519 |
} else { |
|
5520 |
d += incrE; |
|
5521 |
} |
|
5522 |
++y; |
|
5523 |
if (y < devRect.y1 || x > x1) |
|
5524 |
continue; |
|
5525 |
Q_ASSERT(x>=devRect.x1 && x<devRect.x2 && y>=devRect.y1 && y<devRect.y2); |
|
5526 |
if (current == NSPANS) { |
|
5527 |
span_func(NSPANS, spans, data); |
|
5528 |
current = 0; |
|
5529 |
} |
|
5530 |
spans[current].len = 1; |
|
5531 |
spans[current].coverage = 255; |
|
5532 |
spans[current].x = x; |
|
5533 |
spans[current].y = y; |
|
5534 |
++current; |
|
5535 |
} |
|
5536 |
} |
|
5537 |
} |
|
5538 |
flush_and_return: |
|
5539 |
if (current > 0) |
|
5540 |
span_func(current, ordered ? spans : spans + (NSPANS - current), data); |
|
5541 |
} |
|
5542 |
||
5543 |
static void offset_pattern(int offset, bool *inDash, int *dashIndex, int *currentOffset, const QVarLengthArray<qreal> &pattern) |
|
5544 |
{ |
|
5545 |
while (offset--) { |
|
5546 |
if (--*currentOffset == 0) { |
|
5547 |
*inDash = !*inDash; |
|
5548 |
*dashIndex = ((*dashIndex + 1) % pattern.size()); |
|
5549 |
*currentOffset = int(pattern[*dashIndex]); |
|
5550 |
} |
|
5551 |
} |
|
5552 |
} |
|
5553 |
||
5554 |
static void drawLine_midpoint_dashed_i(int x1, int y1, int x2, int y2, |
|
5555 |
QPen *pen, |
|
5556 |
ProcessSpans span_func, QSpanData *data, |
|
5557 |
LineDrawMode style, const QIntRect &devRect, |
|
5558 |
int *patternOffset) |
|
5559 |
{ |
|
5560 |
#ifdef QT_DEBUG_DRAW |
|
5561 |
qDebug() << " - drawLine_midpoint_dashed_i" << x1 << y1 << x2 << y2 << *patternOffset; |
|
5562 |
#endif |
|
5563 |
||
5564 |
int x, y; |
|
5565 |
int dx, dy, d, incrE, incrNE; |
|
5566 |
||
5567 |
dx = x2 - x1; |
|
5568 |
dy = y2 - y1; |
|
5569 |
||
5570 |
Q_ASSERT(*patternOffset >= 0); |
|
5571 |
||
5572 |
const QVector<qreal> penPattern = pen->dashPattern(); |
|
5573 |
QVarLengthArray<qreal> pattern(penPattern.size()); |
|
5574 |
||
5575 |
int patternLength = 0; |
|
5576 |
for (int i = 0; i < penPattern.size(); ++i) |
|
5577 |
patternLength += qMax<qreal>(1.0, (penPattern.at(i))); |
|
5578 |
||
5579 |
// pattern must be reversed if coordinates are out of order |
|
5580 |
int reverseLength = -1; |
|
5581 |
if (dy == 0 && x1 > x2) |
|
5582 |
reverseLength = x1 - x2; |
|
5583 |
else if (dx == 0 && y1 > y2) |
|
5584 |
reverseLength = y1 - y2; |
|
5585 |
else if (qAbs(dx) >= qAbs(dy) && x2 < x1) // x major axis |
|
5586 |
reverseLength = qAbs(dx); |
|
5587 |
else if (qAbs(dy) >= qAbs(dx) && y2 < y1) // y major axis |
|
5588 |
reverseLength = qAbs(dy); |
|
5589 |
||
5590 |
const bool reversed = (reverseLength > -1); |
|
5591 |
if (reversed) { // reverse pattern |
|
5592 |
for (int i = 0; i < penPattern.size(); ++i) |
|
5593 |
pattern[penPattern.size() - 1 - i] = qMax<qreal>(1.0, penPattern.at(i)); |
|
5594 |
||
5595 |
*patternOffset = (patternLength - 1 - *patternOffset); |
|
5596 |
*patternOffset += patternLength - (reverseLength % patternLength); |
|
5597 |
*patternOffset = *patternOffset % patternLength; |
|
5598 |
} else { |
|
5599 |
for (int i = 0; i < penPattern.size(); ++i) |
|
5600 |
pattern[i] = qMax<qreal>(1.0, penPattern.at(i)); |
|
5601 |
} |
|
5602 |
||
5603 |
int dashIndex = 0; |
|
5604 |
bool inDash = !reversed; |
|
5605 |
int currPattern = int(pattern[dashIndex]); |
|
5606 |
||
5607 |
// adjust pattern for offset |
|
5608 |
offset_pattern(*patternOffset, &inDash, &dashIndex, &currPattern, pattern); |
|
5609 |
||
5610 |
const int NSPANS = 256; |
|
5611 |
QT_FT_Span spans[NSPANS]; |
|
5612 |
int current = 0; |
|
5613 |
bool ordered = true; |
|
5614 |
||
5615 |
if (dy == 0) { |
|
5616 |
// specialcase horizontal lines |
|
5617 |
if (y1 >= devRect.y1 && y1 < devRect.y2) { |
|
5618 |
int start_unclipped = qMin(x1, x2); |
|
5619 |
int start = qMax(devRect.x1, start_unclipped); |
|
5620 |
int stop = qMax(x1, x2) + 1; |
|
5621 |
int stop_clipped = qMin(devRect.x2, stop); |
|
5622 |
int len = stop_clipped - start; |
|
5623 |
if (style == LineDrawNormal && stop == stop_clipped) |
|
5624 |
len--; |
|
5625 |
||
5626 |
// adjust pattern for starting offset |
|
5627 |
offset_pattern(start - start_unclipped, &inDash, &dashIndex, &currPattern, pattern); |
|
5628 |
||
5629 |
if (len > 0) { |
|
5630 |
int x = start; |
|
5631 |
while (x < stop_clipped) { |
|
5632 |
if (current == NSPANS) { |
|
5633 |
span_func(NSPANS, spans, data); |
|
5634 |
current = 0; |
|
5635 |
} |
|
5636 |
const int dash = qMin(currPattern, stop_clipped - x); |
|
5637 |
if (inDash) { |
|
5638 |
spans[current].x = ushort(x); |
|
5639 |
spans[current].len = ushort(dash); |
|
5640 |
spans[current].y = y1; |
|
5641 |
spans[current].coverage = 255; |
|
5642 |
++current; |
|
5643 |
} |
|
5644 |
if (dash < currPattern) { |
|
5645 |
currPattern -= dash; |
|
5646 |
} else { |
|
5647 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5648 |
currPattern = int(pattern[dashIndex]); |
|
5649 |
inDash = !inDash; |
|
5650 |
} |
|
5651 |
x += dash; |
|
5652 |
} |
|
5653 |
} |
|
5654 |
} |
|
5655 |
goto flush_and_return; |
|
5656 |
} else if (dx == 0) { |
|
5657 |
if (x1 >= devRect.x1 && x1 < devRect.x2) { |
|
5658 |
int start_unclipped = qMin(y1, y2); |
|
5659 |
int start = qMax(devRect.y1, start_unclipped); |
|
5660 |
int stop = qMax(y1, y2) + 1; |
|
5661 |
int stop_clipped = qMin(devRect.y2, stop); |
|
5662 |
if (style == LineDrawNormal && stop == stop_clipped) |
|
5663 |
--stop; |
|
5664 |
else |
|
5665 |
stop = stop_clipped; |
|
5666 |
||
5667 |
// adjust pattern for starting offset |
|
5668 |
offset_pattern(start - start_unclipped, &inDash, &dashIndex, &currPattern, pattern); |
|
5669 |
||
5670 |
// loop over dashes |
|
5671 |
int y = start; |
|
5672 |
while (y < stop) { |
|
5673 |
const int dash = qMin(currPattern, stop - y); |
|
5674 |
if (inDash) { |
|
5675 |
for (int i = 0; i < dash; ++i) { |
|
5676 |
if (current == NSPANS) { |
|
5677 |
span_func(NSPANS, spans, data); |
|
5678 |
current = 0; |
|
5679 |
} |
|
5680 |
spans[current].x = x1; |
|
5681 |
spans[current].len = 1; |
|
5682 |
spans[current].coverage = 255; |
|
5683 |
spans[current].y = ushort(y + i); |
|
5684 |
++current; |
|
5685 |
} |
|
5686 |
} |
|
5687 |
if (dash < currPattern) { |
|
5688 |
currPattern -= dash; |
|
5689 |
} else { |
|
5690 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5691 |
currPattern = int(pattern[dashIndex]); |
|
5692 |
inDash = !inDash; |
|
5693 |
} |
|
5694 |
y += dash; |
|
5695 |
} |
|
5696 |
} |
|
5697 |
goto flush_and_return; |
|
5698 |
} |
|
5699 |
||
5700 |
if (qAbs(dx) >= qAbs(dy)) { /* if x is the major axis: */ |
|
5701 |
||
5702 |
if (x2 < x1) { /* if coordinates are out of order */ |
|
5703 |
qt_swap_int(x1, x2); |
|
5704 |
dx = -dx; |
|
5705 |
||
5706 |
qt_swap_int(y1, y2); |
|
5707 |
dy = -dy; |
|
5708 |
} |
|
5709 |
||
5710 |
if (style == LineDrawNormal) |
|
5711 |
--x2; |
|
5712 |
||
5713 |
// In the loops below we increment before call the span function so |
|
5714 |
// we need to stop one pixel before |
|
5715 |
x2 = qMin(x2, devRect.x2 - 1); |
|
5716 |
||
5717 |
// completely clipped, so abort |
|
5718 |
if (x2 <= x1) |
|
5719 |
goto flush_and_return; |
|
5720 |
||
5721 |
int x = x1; |
|
5722 |
int y = y1; |
|
5723 |
||
5724 |
if (x >= devRect.x1 && y >= devRect.y1 && y < devRect.y2) { |
|
5725 |
Q_ASSERT(x < devRect.x2); |
|
5726 |
if (inDash) { |
|
5727 |
if (current == NSPANS) { |
|
5728 |
span_func(NSPANS, spans, data); |
|
5729 |
current = 0; |
|
5730 |
} |
|
5731 |
spans[current].len = 1; |
|
5732 |
spans[current].coverage = 255; |
|
5733 |
spans[current].x = x; |
|
5734 |
spans[current].y = y; |
|
5735 |
++current; |
|
5736 |
} |
|
5737 |
if (--currPattern <= 0) { |
|
5738 |
inDash = !inDash; |
|
5739 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5740 |
currPattern = int(pattern[dashIndex]); |
|
5741 |
} |
|
5742 |
} |
|
5743 |
||
5744 |
if (y2 > y1) { // 315 -> 360 and 135 -> 180 (unit circle degrees) |
|
5745 |
y2 = qMin(y2, devRect.y2 - 1); |
|
5746 |
||
5747 |
incrE = dy * 2; |
|
5748 |
d = incrE - dx; |
|
5749 |
incrNE = (dy - dx) * 2; |
|
5750 |
||
5751 |
if (y > y2) |
|
5752 |
goto flush_and_return; |
|
5753 |
||
5754 |
while (x < x2) { |
|
5755 |
if (d > 0) { |
|
5756 |
++y; |
|
5757 |
d += incrNE; |
|
5758 |
if (y > y2) |
|
5759 |
goto flush_and_return; |
|
5760 |
} else { |
|
5761 |
d += incrE; |
|
5762 |
} |
|
5763 |
++x; |
|
5764 |
||
5765 |
const bool skip = x < devRect.x1 || y < devRect.y1; |
|
5766 |
Q_ASSERT(skip || (x < devRect.x2 && y < devRect.y2)); |
|
5767 |
if (inDash && !skip) { |
|
5768 |
if (current == NSPANS) { |
|
5769 |
span_func(NSPANS, spans, data); |
|
5770 |
current = 0; |
|
5771 |
} |
|
5772 |
spans[current].len = 1; |
|
5773 |
spans[current].coverage = 255; |
|
5774 |
spans[current].x = x; |
|
5775 |
spans[current].y = y; |
|
5776 |
++current; |
|
5777 |
} |
|
5778 |
if (--currPattern <= 0) { |
|
5779 |
inDash = !inDash; |
|
5780 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5781 |
currPattern = int(pattern[dashIndex]); |
|
5782 |
} |
|
5783 |
} |
|
5784 |
} else { // 0-45 and 180->225 (unit circle degrees) |
|
5785 |
y1 = qMin(y1, devRect.y2 - 1); |
|
5786 |
||
5787 |
incrE = dy * 2; |
|
5788 |
d = incrE + dx; |
|
5789 |
incrNE = (dy + dx) * 2; |
|
5790 |
||
5791 |
if (y < devRect.y1) |
|
5792 |
goto flush_and_return; |
|
5793 |
||
5794 |
while (x < x2) { |
|
5795 |
if (d < 0) { |
|
5796 |
if (current > 0) { |
|
5797 |
span_func(current, spans, data); |
|
5798 |
current = 0; |
|
5799 |
} |
|
5800 |
||
5801 |
--y; |
|
5802 |
d += incrNE; |
|
5803 |
if (y < devRect.y1) |
|
5804 |
goto flush_and_return; |
|
5805 |
} else { |
|
5806 |
d += incrE; |
|
5807 |
} |
|
5808 |
++x; |
|
5809 |
||
5810 |
const bool skip = x < devRect.x1 || y > y1; |
|
5811 |
Q_ASSERT(skip || (x < devRect.x2 && y < devRect.y2)); |
|
5812 |
if (inDash && !skip) { |
|
5813 |
if (current == NSPANS) { |
|
5814 |
span_func(NSPANS, spans, data); |
|
5815 |
current = 0; |
|
5816 |
} |
|
5817 |
spans[current].len = 1; |
|
5818 |
spans[current].coverage = 255; |
|
5819 |
spans[current].x = x; |
|
5820 |
spans[current].y = y; |
|
5821 |
++current; |
|
5822 |
} |
|
5823 |
if (--currPattern <= 0) { |
|
5824 |
inDash = !inDash; |
|
5825 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5826 |
currPattern = int(pattern[dashIndex]); |
|
5827 |
} |
|
5828 |
} |
|
5829 |
} |
|
5830 |
} else { |
|
5831 |
||
5832 |
// if y is the major axis: |
|
5833 |
||
5834 |
if (y2 < y1) { /* if coordinates are out of order */ |
|
5835 |
qt_swap_int(y1, y2); |
|
5836 |
dy = -dy; |
|
5837 |
||
5838 |
qt_swap_int(x1, x2); |
|
5839 |
dx = -dx; |
|
5840 |
} |
|
5841 |
||
5842 |
if (style == LineDrawNormal) |
|
5843 |
--y2; |
|
5844 |
||
5845 |
// In the loops below we increment before call the span function so |
|
5846 |
// we need to stop one pixel before |
|
5847 |
y2 = qMin(y2, devRect.y2 - 1); |
|
5848 |
||
5849 |
// completely clipped, so abort |
|
5850 |
if (y2 <= y1) |
|
5851 |
goto flush_and_return; |
|
5852 |
||
5853 |
x = x1; |
|
5854 |
y = y1; |
|
5855 |
||
5856 |
if (x>=devRect.x1 && y>=devRect.y1 && x < devRect.x2) { |
|
5857 |
Q_ASSERT(x < devRect.x2); |
|
5858 |
if (inDash) { |
|
5859 |
if (current == NSPANS) { |
|
5860 |
span_func(NSPANS, spans, data); |
|
5861 |
current = 0; |
|
5862 |
} |
|
5863 |
spans[current].len = 1; |
|
5864 |
spans[current].coverage = 255; |
|
5865 |
spans[current].x = x; |
|
5866 |
spans[current].y = y; |
|
5867 |
++current; |
|
5868 |
} |
|
5869 |
if (--currPattern <= 0) { |
|
5870 |
inDash = !inDash; |
|
5871 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5872 |
currPattern = int(pattern[dashIndex]); |
|
5873 |
} |
|
5874 |
} |
|
5875 |
||
5876 |
if (x2 > x1) { // 90 -> 135 and 270 -> 315 (unit circle degrees) |
|
5877 |
x2 = qMin(x2, devRect.x2 - 1); |
|
5878 |
incrE = dx * 2; |
|
5879 |
d = incrE - dy; |
|
5880 |
incrNE = (dx - dy) * 2; |
|
5881 |
||
5882 |
if (x > x2) |
|
5883 |
goto flush_and_return; |
|
5884 |
||
5885 |
while (y < y2) { |
|
5886 |
if (d > 0) { |
|
5887 |
++x; |
|
5888 |
d += incrNE; |
|
5889 |
if (x > x2) |
|
5890 |
goto flush_and_return; |
|
5891 |
} else { |
|
5892 |
d += incrE; |
|
5893 |
} |
|
5894 |
++y; |
|
5895 |
const bool skip = x < devRect.x1 || y < devRect.y1; |
|
5896 |
Q_ASSERT(skip || (x < devRect.x2 && y < devRect.y2)); |
|
5897 |
if (inDash && !skip) { |
|
5898 |
if (current == NSPANS) { |
|
5899 |
span_func(NSPANS, spans, data); |
|
5900 |
current = 0; |
|
5901 |
} |
|
5902 |
spans[current].len = 1; |
|
5903 |
spans[current].coverage = 255; |
|
5904 |
spans[current].x = x; |
|
5905 |
spans[current].y = y; |
|
5906 |
++current; |
|
5907 |
} |
|
5908 |
if (--currPattern <= 0) { |
|
5909 |
inDash = !inDash; |
|
5910 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5911 |
currPattern = int(pattern[dashIndex]); |
|
5912 |
} |
|
5913 |
} |
|
5914 |
} else { // 45 -> 90 and 225 -> 270 (unit circle degrees) |
|
5915 |
x1 = qMin(x1, devRect.x2 - 1); |
|
5916 |
incrE = dx * 2; |
|
5917 |
d = incrE + dy; |
|
5918 |
incrNE = (dx + dy) * 2; |
|
5919 |
||
5920 |
if (x < devRect.x1) |
|
5921 |
goto flush_and_return; |
|
5922 |
||
5923 |
while (y < y2) { |
|
5924 |
if (d < 0) { |
|
5925 |
--x; |
|
5926 |
d += incrNE; |
|
5927 |
if (x < devRect.x1) |
|
5928 |
goto flush_and_return; |
|
5929 |
} else { |
|
5930 |
d += incrE; |
|
5931 |
} |
|
5932 |
++y; |
|
5933 |
const bool skip = y < devRect.y1 || x > x1; |
|
5934 |
Q_ASSERT(skip || (x >= devRect.x1 && x < devRect.x2 && y < devRect.y2)); |
|
5935 |
if (inDash && !skip) { |
|
5936 |
if (current == NSPANS) { |
|
5937 |
span_func(NSPANS, spans, data); |
|
5938 |
current = 0; |
|
5939 |
} |
|
5940 |
spans[current].len = 1; |
|
5941 |
spans[current].coverage = 255; |
|
5942 |
spans[current].x = x; |
|
5943 |
spans[current].y = y; |
|
5944 |
++current; |
|
5945 |
} |
|
5946 |
if (--currPattern <= 0) { |
|
5947 |
inDash = !inDash; |
|
5948 |
dashIndex = (dashIndex + 1) % pattern.size(); |
|
5949 |
currPattern = int(pattern[dashIndex]); |
|
5950 |
} |
|
5951 |
} |
|
5952 |
} |
|
5953 |
} |
|
5954 |
flush_and_return: |
|
5955 |
if (current > 0) |
|
5956 |
span_func(current, ordered ? spans : spans + (NSPANS - current), data); |
|
5957 |
||
5958 |
// adjust offset |
|
5959 |
if (reversed) { |
|
5960 |
*patternOffset = (patternLength - 1 - *patternOffset); |
|
5961 |
} else { |
|
5962 |
*patternOffset = 0; |
|
5963 |
for (int i = 0; i <= dashIndex; ++i) |
|
5964 |
*patternOffset += int(pattern[i]); |
|
5965 |
*patternOffset += patternLength - currPattern - 1; |
|
5966 |
*patternOffset = (*patternOffset % patternLength); |
|
5967 |
} |
|
5968 |
} |
|
5969 |
||
5970 |
/*! |
|
5971 |
\internal |
|
5972 |
\a x and \a y is relative to the midpoint of \a rect. |
|
5973 |
*/ |
|
5974 |
static inline void drawEllipsePoints(int x, int y, int length, |
|
5975 |
const QRect &rect, |
|
5976 |
const QRect &clip, |
|
5977 |
ProcessSpans pen_func, ProcessSpans brush_func, |
|
5978 |
QSpanData *pen_data, QSpanData *brush_data) |
|
5979 |
{ |
|
5980 |
if (length == 0) |
|
5981 |
return; |
|
5982 |
||
5983 |
QT_FT_Span outline[4]; |
|
5984 |
const int midx = rect.x() + (rect.width() + 1) / 2; |
|
5985 |
const int midy = rect.y() + (rect.height() + 1) / 2; |
|
5986 |
||
5987 |
x = x + midx; |
|
5988 |
y = midy - y; |
|
5989 |
||
5990 |
// topleft |
|
5991 |
outline[0].x = midx + (midx - x) - (length - 1) - (rect.width() & 0x1); |
|
5992 |
outline[0].len = qMin(length, x - outline[0].x); |
|
5993 |
outline[0].y = y; |
|
5994 |
outline[0].coverage = 255; |
|
5995 |
||
5996 |
// topright |
|
5997 |
outline[1].x = x; |
|
5998 |
outline[1].len = length; |
|
5999 |
outline[1].y = y; |
|
6000 |
outline[1].coverage = 255; |
|
6001 |
||
6002 |
// bottomleft |
|
6003 |
outline[2].x = outline[0].x; |
|
6004 |
outline[2].len = outline[0].len; |
|
6005 |
outline[2].y = midy + (midy - y) - (rect.height() & 0x1); |
|
6006 |
outline[2].coverage = 255; |
|
6007 |
||
6008 |
// bottomright |
|
6009 |
outline[3].x = x; |
|
6010 |
outline[3].len = length; |
|
6011 |
outline[3].y = outline[2].y; |
|
6012 |
outline[3].coverage = 255; |
|
6013 |
||
6014 |
if (brush_func && outline[0].x + outline[0].len < outline[1].x) { |
|
6015 |
QT_FT_Span fill[2]; |
|
6016 |
||
6017 |
// top fill |
|
6018 |
fill[0].x = outline[0].x + outline[0].len - 1; |
|
6019 |
fill[0].len = qMax(0, outline[1].x - fill[0].x); |
|
6020 |
fill[0].y = outline[1].y; |
|
6021 |
fill[0].coverage = 255; |
|
6022 |
||
6023 |
// bottom fill |
|
6024 |
fill[1].x = outline[2].x + outline[2].len - 1; |
|
6025 |
fill[1].len = qMax(0, outline[3].x - fill[1].x); |
|
6026 |
fill[1].y = outline[3].y; |
|
6027 |
fill[1].coverage = 255; |
|
6028 |
||
6029 |
int n = (fill[0].y >= fill[1].y ? 1 : 2); |
|
6030 |
n = qt_intersect_spans(fill, n, clip); |
|
6031 |
if (n > 0) |
|
6032 |
brush_func(n, fill, brush_data); |
|
6033 |
} |
|
6034 |
if (pen_func) { |
|
6035 |
int n = (outline[1].y >= outline[2].y ? 2 : 4); |
|
6036 |
n = qt_intersect_spans(outline, n, clip); |
|
6037 |
if (n > 0) |
|
6038 |
pen_func(n, outline, pen_data); |
|
6039 |
} |
|
6040 |
} |
|
6041 |
||
6042 |
/*! |
|
6043 |
\internal |
|
6044 |
Draws an ellipse using the integer point midpoint algorithm. |
|
6045 |
*/ |
|
6046 |
static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip, |
|
6047 |
ProcessSpans pen_func, ProcessSpans brush_func, |
|
6048 |
QSpanData *pen_data, QSpanData *brush_data) |
|
6049 |
{ |
|
6050 |
const qreal a = qreal(rect.width()) / 2; |
|
6051 |
const qreal b = qreal(rect.height()) / 2; |
|
6052 |
qreal d = b*b - (a*a*b) + 0.25*a*a; |
|
6053 |
||
6054 |
int x = 0; |
|
6055 |
int y = (rect.height() + 1) / 2; |
|
6056 |
int startx = x; |
|
6057 |
||
6058 |
// region 1 |
|
6059 |
while (a*a*(2*y - 1) > 2*b*b*(x + 1)) { |
|
6060 |
if (d < 0) { // select E |
|
6061 |
d += b*b*(2*x + 3); |
|
6062 |
++x; |
|
6063 |
} else { // select SE |
|
6064 |
d += b*b*(2*x + 3) + a*a*(-2*y + 2); |
|
6065 |
drawEllipsePoints(startx, y, x - startx + 1, rect, clip, |
|
6066 |
pen_func, brush_func, pen_data, brush_data); |
|
6067 |
startx = ++x; |
|
6068 |
--y; |
|
6069 |
} |
|
6070 |
} |
|
6071 |
drawEllipsePoints(startx, y, x - startx + 1, rect, clip, |
|
6072 |
pen_func, brush_func, pen_data, brush_data); |
|
6073 |
||
6074 |
// region 2 |
|
6075 |
d = b*b*(x + 0.5)*(x + 0.5) + a*a*((y - 1)*(y - 1) - b*b); |
|
6076 |
const int miny = rect.height() & 0x1; |
|
6077 |
while (y > miny) { |
|
6078 |
if (d < 0) { // select SE |
|
6079 |
d += b*b*(2*x + 2) + a*a*(-2*y + 3); |
|
6080 |
++x; |
|
6081 |
} else { // select S |
|
6082 |
d += a*a*(-2*y + 3); |
|
6083 |
} |
|
6084 |
--y; |
|
6085 |
drawEllipsePoints(x, y, 1, rect, clip, |
|
6086 |
pen_func, brush_func, pen_data, brush_data); |
|
6087 |
} |
|
6088 |
} |
|
6089 |
||
6090 |
/*! |
|
6091 |
\fn void QRasterPaintEngine::drawPoints(const QPoint *points, int pointCount) |
|
6092 |
\overload |
|
6093 |
||
6094 |
Draws the first \a pointCount points in the buffer \a points |
|
6095 |
||
6096 |
The default implementation converts the first \a pointCount QPoints in \a points |
|
6097 |
to QPointFs and calls the floating point version of drawPoints. |
|
6098 |
*/ |
|
6099 |
||
6100 |
/*! |
|
6101 |
\fn void QRasterPaintEngine::drawEllipse(const QRect &rect) |
|
6102 |
\overload |
|
6103 |
||
6104 |
Reimplement this function to draw the largest ellipse that can be |
|
6105 |
contained within rectangle \a rect. |
|
6106 |
*/ |
|
6107 |
||
6108 |
#ifdef QT_DEBUG_DRAW |
|
6109 |
void dumpClip(int width, int height, const QClipData *clip) |
|
6110 |
{ |
|
6111 |
QImage clipImg(width, height, QImage::Format_ARGB32_Premultiplied); |
|
6112 |
clipImg.fill(0xffff0000); |
|
6113 |
||
6114 |
int x0 = width; |
|
6115 |
int x1 = 0; |
|
6116 |
int y0 = height; |
|
6117 |
int y1 = 0; |
|
6118 |
||
6119 |
((QClipData *) clip)->spans(); // Force allocation of the spans structure... |
|
6120 |
||
6121 |
for (int i = 0; i < clip->count; ++i) { |
|
6122 |
const QSpan *span = ((QClipData *) clip)->spans() + i; |
|
6123 |
for (int j = 0; j < span->len; ++j) |
|
6124 |
clipImg.setPixel(span->x + j, span->y, 0xffffff00); |
|
6125 |
x0 = qMin(x0, int(span->x)); |
|
6126 |
x1 = qMax(x1, int(span->x + span->len - 1)); |
|
6127 |
||
6128 |
y0 = qMin(y0, int(span->y)); |
|
6129 |
y1 = qMax(y1, int(span->y)); |
|
6130 |
} |
|
6131 |
||
6132 |
static int counter = 0; |
|
6133 |
||
6134 |
Q_ASSERT(y0 >= 0); |
|
6135 |
Q_ASSERT(x0 >= 0); |
|
6136 |
Q_ASSERT(y1 >= 0); |
|
6137 |
Q_ASSERT(x1 >= 0); |
|
6138 |
||
6139 |
fprintf(stderr,"clip %d: %d %d - %d %d\n", counter, x0, y0, x1, y1); |
|
6140 |
clipImg.save(QString::fromLatin1("clip-%0.png").arg(counter++)); |
|
6141 |
} |
|
6142 |
#endif |
|
6143 |
||
6144 |
||
6145 |
QT_END_NAMESPACE |