|
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 #ifndef QPAINTENGINE_RASTER_P_H |
|
43 #define QPAINTENGINE_RASTER_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists for the convenience |
|
50 // of other Qt classes. This header file may change from version to |
|
51 // version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include "private/qpaintengineex_p.h" |
|
57 #include "QtGui/qpainterpath.h" |
|
58 #include "private/qdatabuffer_p.h" |
|
59 #include "private/qdrawhelper_p.h" |
|
60 #include "private/qpaintengine_p.h" |
|
61 #include "private/qrasterizer_p.h" |
|
62 #include "private/qstroker_p.h" |
|
63 #include "private/qpainter_p.h" |
|
64 #include "private/qtextureglyphcache_p.h" |
|
65 #include "private/qoutlinemapper_p.h" |
|
66 |
|
67 #include <stdlib.h> |
|
68 |
|
69 QT_BEGIN_NAMESPACE |
|
70 |
|
71 class QOutlineMapper; |
|
72 class QRasterPaintEnginePrivate; |
|
73 class QRasterBuffer; |
|
74 class QClipData; |
|
75 class QCustomRasterPaintDevice; |
|
76 |
|
77 class QRasterPaintEngineState : public QPainterState |
|
78 { |
|
79 public: |
|
80 QRasterPaintEngineState(QRasterPaintEngineState &other); |
|
81 QRasterPaintEngineState(); |
|
82 ~QRasterPaintEngineState(); |
|
83 |
|
84 |
|
85 QPen lastPen; |
|
86 QSpanData penData; |
|
87 QStrokerOps *stroker; |
|
88 uint strokeFlags; |
|
89 |
|
90 QBrush lastBrush; |
|
91 QSpanData brushData; |
|
92 uint fillFlags; |
|
93 |
|
94 uint pixmapFlags; |
|
95 int intOpacity; |
|
96 |
|
97 qreal txscale; |
|
98 |
|
99 QClipData *clip; |
|
100 // QRect clipRect; |
|
101 // QRegion clipRegion; |
|
102 |
|
103 // QPainter::RenderHints hints; |
|
104 // QPainter::CompositionMode compositionMode; |
|
105 |
|
106 uint dirty; |
|
107 |
|
108 struct Flags { |
|
109 uint has_clip_ownership : 1; // should delete the clip member.. |
|
110 uint fast_pen : 1; // cosmetic 1-width pens, using midpoint drawlines |
|
111 uint non_complex_pen : 1; // can use rasterizer, rather than stroker |
|
112 uint antialiased : 1; |
|
113 uint bilinear : 1; |
|
114 uint fast_text : 1; |
|
115 uint int_xform : 1; |
|
116 uint tx_noshear : 1; |
|
117 uint fast_images : 1; |
|
118 }; |
|
119 |
|
120 union { |
|
121 Flags flags; |
|
122 uint flag_bits; |
|
123 }; |
|
124 }; |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 /******************************************************************************* |
|
130 * QRasterPaintEngine |
|
131 */ |
|
132 class |
|
133 #ifdef Q_WS_QWS |
|
134 Q_GUI_EXPORT |
|
135 #endif |
|
136 QRasterPaintEngine : public QPaintEngineEx |
|
137 { |
|
138 Q_DECLARE_PRIVATE(QRasterPaintEngine) |
|
139 public: |
|
140 |
|
141 QRasterPaintEngine(QPaintDevice *device); |
|
142 ~QRasterPaintEngine(); |
|
143 bool begin(QPaintDevice *device); |
|
144 bool end(); |
|
145 |
|
146 void penChanged(); |
|
147 void brushChanged(); |
|
148 void brushOriginChanged(); |
|
149 void opacityChanged(); |
|
150 void compositionModeChanged(); |
|
151 void renderHintsChanged(); |
|
152 void transformChanged(); |
|
153 void clipEnabledChanged(); |
|
154 |
|
155 void setState(QPainterState *s); |
|
156 QPainterState *createState(QPainterState *orig) const; |
|
157 inline QRasterPaintEngineState *state() { |
|
158 return static_cast<QRasterPaintEngineState *>(QPaintEngineEx::state()); |
|
159 } |
|
160 inline const QRasterPaintEngineState *state() const { |
|
161 return static_cast<const QRasterPaintEngineState *>(QPaintEngineEx::state()); |
|
162 } |
|
163 |
|
164 void updateBrush(const QBrush &brush); |
|
165 void updatePen(const QPen &pen); |
|
166 |
|
167 void updateMatrix(const QTransform &matrix); |
|
168 |
|
169 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode); |
|
170 void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode); |
|
171 void fillPath(const QPainterPath &path, QSpanData *fillData); |
|
172 void fillPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode); |
|
173 |
|
174 void drawEllipse(const QRectF &rect); |
|
175 |
|
176 void fillRect(const QRectF &rect, const QBrush &brush); |
|
177 void fillRect(const QRectF &rect, const QColor &color); |
|
178 |
|
179 void drawRects(const QRect *rects, int rectCount); |
|
180 void drawRects(const QRectF *rects, int rectCount); |
|
181 |
|
182 void drawPixmap(const QPointF &p, const QPixmap &pm); |
|
183 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); |
|
184 void drawImage(const QPointF &p, const QImage &img); |
|
185 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, |
|
186 Qt::ImageConversionFlags falgs = Qt::AutoColor); |
|
187 void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &sr); |
|
188 void drawTextItem(const QPointF &p, const QTextItem &textItem); |
|
189 |
|
190 void drawLines(const QLine *line, int lineCount); |
|
191 void drawLines(const QLineF *line, int lineCount); |
|
192 |
|
193 void drawPoints(const QPointF *points, int pointCount); |
|
194 void drawPoints(const QPoint *points, int pointCount); |
|
195 |
|
196 void stroke(const QVectorPath &path, const QPen &pen); |
|
197 void fill(const QVectorPath &path, const QBrush &brush); |
|
198 |
|
199 void strokePolygonCosmetic(const QPoint *pts, int pointCount, PolygonDrawMode mode); |
|
200 void strokePolygonCosmetic(const QPointF *pt, int pointCount, PolygonDrawMode mode); |
|
201 |
|
202 void clip(const QVectorPath &path, Qt::ClipOperation op); |
|
203 void clip(const QRect &rect, Qt::ClipOperation op); |
|
204 void clip(const QRegion ®ion, Qt::ClipOperation op); |
|
205 |
|
206 enum ClipType { |
|
207 RectClip, |
|
208 ComplexClip |
|
209 }; |
|
210 ClipType clipType() const; |
|
211 QRect clipBoundingRect() const; |
|
212 |
|
213 #ifdef Q_NO_USING_KEYWORD |
|
214 inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); } |
|
215 #else |
|
216 using QPaintEngineEx::drawPolygon; |
|
217 using QPaintEngineEx::drawEllipse; |
|
218 #endif |
|
219 |
|
220 void releaseBuffer(); |
|
221 |
|
222 QSize size() const; |
|
223 |
|
224 #ifndef QT_NO_DEBUG |
|
225 void saveBuffer(const QString &s) const; |
|
226 #endif |
|
227 |
|
228 #ifdef Q_WS_MAC |
|
229 void setCGContext(CGContextRef ref); |
|
230 CGContextRef getCGContext() const; |
|
231 #endif |
|
232 |
|
233 #ifdef Q_WS_WIN |
|
234 void setDC(HDC hdc); |
|
235 HDC getDC() const; |
|
236 void releaseDC(HDC hdc) const; |
|
237 #endif |
|
238 |
|
239 void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h); |
|
240 |
|
241 Type type() const { return Raster; } |
|
242 |
|
243 QPoint coordinateOffset() const; |
|
244 |
|
245 #if defined(Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
246 virtual void drawColorSpans(const QSpan *spans, int count, uint color); |
|
247 virtual void drawBufferSpan(const uint *buffer, int bufsize, |
|
248 int x, int y, int length, uint const_alpha); |
|
249 #endif |
|
250 |
|
251 protected: |
|
252 QRasterPaintEngine(QRasterPaintEnginePrivate &d, QPaintDevice *); |
|
253 private: |
|
254 friend struct QSpanData; |
|
255 void init(); |
|
256 |
|
257 void fillRect(const QRectF &rect, QSpanData *data); |
|
258 void drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fill); |
|
259 |
|
260 void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti); |
|
261 |
|
262 #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) |
|
263 void drawGlyphsS60(const QPointF &p, const QTextItemInt &ti); |
|
264 #endif // Q_OS_SYMBIAN && QT_NO_FREETYPE |
|
265 |
|
266 inline void ensureBrush(const QBrush &brush) { |
|
267 if (!qbrush_fast_equals(state()->lastBrush, brush) || state()->fillFlags) |
|
268 updateBrush(brush); |
|
269 } |
|
270 inline void ensureBrush() { ensureBrush(state()->brush); } |
|
271 |
|
272 inline void ensurePen(const QPen &pen) { |
|
273 if (!qpen_fast_equals(state()->lastPen, pen) || state()->strokeFlags) |
|
274 updatePen(pen); |
|
275 } |
|
276 inline void ensurePen() { ensurePen(state()->pen); } |
|
277 |
|
278 void updateOutlineMapper(); |
|
279 inline void ensureOutlineMapper(); |
|
280 |
|
281 void updateState(); |
|
282 inline void ensureState() { |
|
283 if (state()->dirty) |
|
284 updateState(); |
|
285 } |
|
286 }; |
|
287 |
|
288 |
|
289 /******************************************************************************* |
|
290 * QRasterPaintEnginePrivate |
|
291 */ |
|
292 class |
|
293 #ifdef Q_WS_QWS |
|
294 Q_GUI_EXPORT |
|
295 #endif |
|
296 QRasterPaintEnginePrivate : public QPaintEngineExPrivate |
|
297 { |
|
298 Q_DECLARE_PUBLIC(QRasterPaintEngine) |
|
299 public: |
|
300 |
|
301 void rasterizeLine_dashed(QLineF line, qreal width, |
|
302 int *dashIndex, qreal *dashOffset, bool *inDash); |
|
303 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, QSpanData *spanData, QRasterBuffer *rasterBuffer); |
|
304 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, void *userData, QRasterBuffer *rasterBuffer); |
|
305 void updateMatrixData(QSpanData *spanData, const QBrush &brush, const QTransform &brushMatrix); |
|
306 |
|
307 void systemStateChanged(); |
|
308 |
|
309 void drawImage(const QPointF &pt, const QImage &img, SrcOverBlendFunc func, |
|
310 const QRect &clip, int alpha, const QRect &sr = QRect()); |
|
311 |
|
312 QTransform brushMatrix() const { |
|
313 Q_Q(const QRasterPaintEngine); |
|
314 const QRasterPaintEngineState *s = q->state(); |
|
315 QTransform m(s->matrix); |
|
316 m.translate(s->brushOrigin.x(), s->brushOrigin.y()); |
|
317 return m; |
|
318 } |
|
319 |
|
320 bool isUnclipped_normalized(const QRect &rect) const; |
|
321 bool isUnclipped(const QRect &rect, int penWidth) const; |
|
322 bool isUnclipped(const QRectF &rect, int penWidth) const; |
|
323 ProcessSpans getPenFunc(const QRect &rect, const QSpanData *data) const; |
|
324 ProcessSpans getPenFunc(const QRectF &rect, const QSpanData *data) const; |
|
325 ProcessSpans getBrushFunc(const QRect &rect, const QSpanData *data) const; |
|
326 ProcessSpans getBrushFunc(const QRectF &rect, const QSpanData *data) const; |
|
327 |
|
328 #ifdef Q_WS_QWS |
|
329 void prepare(QCustomRasterPaintDevice *); |
|
330 #endif |
|
331 |
|
332 inline const QClipData *clip() const; |
|
333 |
|
334 void initializeRasterizer(QSpanData *data); |
|
335 |
|
336 void recalculateFastImages(); |
|
337 |
|
338 QPaintDevice *device; |
|
339 QScopedPointer<QOutlineMapper> outlineMapper; |
|
340 QScopedPointer<QRasterBuffer> rasterBuffer; |
|
341 |
|
342 #if defined (Q_WS_WIN) |
|
343 HDC hdc; |
|
344 #elif defined(Q_WS_MAC) |
|
345 CGContextRef cgContext; |
|
346 #endif |
|
347 |
|
348 QRect deviceRect; |
|
349 |
|
350 QStroker basicStroker; |
|
351 QScopedPointer<QDashStroker> dashStroker; |
|
352 |
|
353 QScopedPointer<QT_FT_Raster> grayRaster; |
|
354 unsigned long rasterPoolSize; |
|
355 unsigned char *rasterPoolBase; |
|
356 |
|
357 QDataBuffer<QLineF> cachedLines; |
|
358 QSpanData image_filler; |
|
359 QSpanData image_filler_xform; |
|
360 QSpanData solid_color_filler; |
|
361 |
|
362 |
|
363 QFontEngineGlyphCache::Type glyphCacheType; |
|
364 |
|
365 QScopedPointer<QClipData> baseClip; |
|
366 |
|
367 int deviceDepth; |
|
368 |
|
369 uint mono_surface : 1; |
|
370 uint outlinemapper_xform_dirty : 1; |
|
371 |
|
372 #ifdef Q_WS_WIN |
|
373 uint isPlain45DegreeRotation : 1; |
|
374 #endif |
|
375 |
|
376 QScopedPointer<QRasterizer> rasterizer; |
|
377 }; |
|
378 |
|
379 |
|
380 class |
|
381 #ifdef Q_WS_QWS |
|
382 Q_GUI_EXPORT |
|
383 #endif |
|
384 QClipData { |
|
385 public: |
|
386 QClipData(int height); |
|
387 ~QClipData(); |
|
388 |
|
389 int clipSpanHeight; |
|
390 struct ClipLine { |
|
391 int count; |
|
392 QSpan *spans; |
|
393 } *m_clipLines; |
|
394 |
|
395 void initialize(); |
|
396 |
|
397 inline ClipLine *clipLines() { |
|
398 if (!m_clipLines) |
|
399 initialize(); |
|
400 return m_clipLines; |
|
401 } |
|
402 |
|
403 inline QSpan *spans() { |
|
404 if (!m_spans) |
|
405 initialize(); |
|
406 return m_spans; |
|
407 } |
|
408 |
|
409 int allocated; |
|
410 int count; |
|
411 QSpan *m_spans; |
|
412 int xmin, xmax, ymin, ymax; |
|
413 |
|
414 QRect clipRect; |
|
415 QRegion clipRegion; |
|
416 |
|
417 uint enabled : 1; |
|
418 uint hasRectClip : 1; |
|
419 uint hasRegionClip : 1; |
|
420 |
|
421 void appendSpan(int x, int length, int y, int coverage); |
|
422 void appendSpans(const QSpan *s, int num); |
|
423 |
|
424 // ### Should optimize and actually kill the QSpans if the rect is |
|
425 // ### a subset of The current region. Thus the "fast" clipspan |
|
426 // ### callback can be used |
|
427 void setClipRect(const QRect &rect); |
|
428 void setClipRegion(const QRegion ®ion); |
|
429 void fixup(); |
|
430 }; |
|
431 |
|
432 inline void QClipData::appendSpan(int x, int length, int y, int coverage) |
|
433 { |
|
434 Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans.. |
|
435 |
|
436 if (count == allocated) { |
|
437 allocated *= 2; |
|
438 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan)); |
|
439 } |
|
440 m_spans[count].x = x; |
|
441 m_spans[count].len = length; |
|
442 m_spans[count].y = y; |
|
443 m_spans[count].coverage = coverage; |
|
444 ++count; |
|
445 } |
|
446 |
|
447 inline void QClipData::appendSpans(const QSpan *s, int num) |
|
448 { |
|
449 Q_ASSERT(m_spans); |
|
450 |
|
451 if (count + num > allocated) { |
|
452 do { |
|
453 allocated *= 2; |
|
454 } while (count + num > allocated); |
|
455 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan)); |
|
456 } |
|
457 memcpy(m_spans+count, s, num*sizeof(QSpan)); |
|
458 count += num; |
|
459 } |
|
460 |
|
461 #ifdef Q_WS_QWS |
|
462 class Q_GUI_EXPORT QCustomRasterPaintDevice : public QPaintDevice |
|
463 { |
|
464 public: |
|
465 QCustomRasterPaintDevice(QWidget *w) : widget(w) {} |
|
466 |
|
467 int devType() const { return QInternal::CustomRaster; } |
|
468 |
|
469 virtual int metric(PaintDeviceMetric m) const; |
|
470 |
|
471 virtual void* memory() const { return 0; } |
|
472 |
|
473 virtual QImage::Format format() const { |
|
474 return QImage::Format_ARGB32_Premultiplied; |
|
475 } |
|
476 |
|
477 virtual int bytesPerLine() const; |
|
478 |
|
479 virtual QSize size() const { |
|
480 return static_cast<QRasterPaintEngine*>(paintEngine())->size(); |
|
481 } |
|
482 |
|
483 private: |
|
484 QWidget *widget; |
|
485 }; |
|
486 #endif // Q_WS_QWS |
|
487 |
|
488 /******************************************************************************* |
|
489 * QRasterBuffer |
|
490 */ |
|
491 class |
|
492 #ifdef Q_WS_QWS |
|
493 Q_GUI_EXPORT |
|
494 #endif |
|
495 QRasterBuffer |
|
496 { |
|
497 public: |
|
498 QRasterBuffer() : m_width(0), m_height(0), m_buffer(0) { init(); } |
|
499 |
|
500 ~QRasterBuffer(); |
|
501 |
|
502 void init(); |
|
503 |
|
504 QImage::Format prepare(QImage *image); |
|
505 QImage::Format prepare(QPixmap *pix); |
|
506 #ifdef Q_WS_QWS |
|
507 void prepare(QCustomRasterPaintDevice *device); |
|
508 #endif |
|
509 void prepare(int w, int h); |
|
510 void prepareBuffer(int w, int h); |
|
511 |
|
512 void resetBuffer(int val=0); |
|
513 |
|
514 uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; } |
|
515 |
|
516 #ifndef QT_NO_DEBUG |
|
517 QImage bufferImage() const; |
|
518 #endif |
|
519 |
|
520 void flushToARGBImage(QImage *image) const; |
|
521 |
|
522 int width() const { return m_width; } |
|
523 int height() const { return m_height; } |
|
524 int bytesPerLine() const { return bytes_per_line; } |
|
525 int bytesPerPixel() const { return bytes_per_pixel; } |
|
526 |
|
527 uchar *buffer() const { return m_buffer; } |
|
528 |
|
529 bool monoDestinationWithClut; |
|
530 QRgb destColor0; |
|
531 QRgb destColor1; |
|
532 |
|
533 QPainter::CompositionMode compositionMode; |
|
534 QImage::Format format; |
|
535 DrawHelper *drawHelper; |
|
536 QImage colorizeBitmap(const QImage &image, const QColor &color); |
|
537 |
|
538 private: |
|
539 int m_width; |
|
540 int m_height; |
|
541 int bytes_per_line; |
|
542 int bytes_per_pixel; |
|
543 uchar *m_buffer; |
|
544 }; |
|
545 |
|
546 inline void QRasterPaintEngine::ensureOutlineMapper() { |
|
547 if (d_func()->outlinemapper_xform_dirty) |
|
548 updateOutlineMapper(); |
|
549 } |
|
550 |
|
551 inline const QClipData *QRasterPaintEnginePrivate::clip() const { |
|
552 Q_Q(const QRasterPaintEngine); |
|
553 if (q->state() && q->state()->clip && q->state()->clip->enabled) |
|
554 return q->state()->clip; |
|
555 return baseClip.data(); |
|
556 } |
|
557 |
|
558 |
|
559 QT_END_NAMESPACE |
|
560 #endif // QPAINTENGINE_RASTER_P_H |