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