source: trunk/src/gui/painting/qpaintengine_raster_p.h@ 714

Last change on this file since 714 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 15.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
69QT_BEGIN_NAMESPACE
70
71class QOutlineMapper;
72class QRasterPaintEnginePrivate;
73class QRasterBuffer;
74class QClipData;
75class QCustomRasterPaintDevice;
76
77class QRasterPaintEngineState : public QPainterState
78{
79public:
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 */
132class
133#ifdef Q_WS_QWS
134Q_GUI_EXPORT
135#endif
136QRasterPaintEngine : public QPaintEngineEx
137{
138 Q_DECLARE_PRIVATE(QRasterPaintEngine)
139public:
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 &region, 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
251protected:
252 QRasterPaintEngine(QRasterPaintEnginePrivate &d, QPaintDevice *);
253private:
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) || (brush.style() != Qt::NoBrush && 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) || (pen.style() != Qt::NoPen && 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 */
292class
293#ifdef Q_WS_QWS
294Q_GUI_EXPORT
295#endif
296QRasterPaintEnginePrivate : public QPaintEngineExPrivate
297{
298 Q_DECLARE_PUBLIC(QRasterPaintEngine)
299public:
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
380class
381#ifdef Q_WS_QWS
382Q_GUI_EXPORT
383#endif
384QClipData {
385public:
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 &region);
429 void fixup();
430};
431
432inline 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
447inline 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
462class Q_GUI_EXPORT QCustomRasterPaintDevice : public QPaintDevice
463{
464public:
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
483private:
484 QWidget *widget;
485};
486#endif // Q_WS_QWS
487
488/*******************************************************************************
489 * QRasterBuffer
490 */
491class
492#ifdef Q_WS_QWS
493Q_GUI_EXPORT
494#endif
495QRasterBuffer
496{
497public:
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
538private:
539 int m_width;
540 int m_height;
541 int bytes_per_line;
542 int bytes_per_pixel;
543 uchar *m_buffer;
544};
545
546inline void QRasterPaintEngine::ensureOutlineMapper() {
547 if (d_func()->outlinemapper_xform_dirty)
548 updateOutlineMapper();
549}
550
551inline 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
559QT_END_NAMESPACE
560#endif // QPAINTENGINE_RASTER_P_H
Note: See TracBrowser for help on using the repository browser.