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

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

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 15.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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
66#include <stdlib.h>
67
68QT_BEGIN_NAMESPACE
69
70class QOutlineMapper;
71class QRasterPaintEnginePrivate;
72class QRasterBuffer;
73class QClipData;
74class QCustomRasterPaintDevice;
75
76class QRasterPaintEngineState : public QPainterState
77{
78public:
79 QRasterPaintEngineState(QRasterPaintEngineState &other);
80 QRasterPaintEngineState();
81 ~QRasterPaintEngineState();
82
83
84 QPen lastPen;
85 QSpanData penData;
86 QStrokerOps *stroker;
87 uint strokeFlags;
88
89 QBrush lastBrush;
90 QSpanData brushData;
91 uint fillFlags;
92
93 uint pixmapFlags;
94 int intOpacity;
95
96 qreal txscale;
97
98 QClipData *clip;
99// QRect clipRect;
100// QRegion clipRegion;
101
102// QPainter::RenderHints hints;
103// QPainter::CompositionMode compositionMode;
104
105 uint dirty;
106
107 struct Flags {
108 uint has_clip_ownership : 1; // should delete the clip member..
109 uint fast_pen : 1; // cosmetic 1-width pens, using midpoint drawlines
110 uint non_complex_pen : 1; // can use rasterizer, rather than stroker
111 uint antialiased : 1;
112 uint bilinear : 1;
113 uint fast_text : 1;
114 uint int_xform : 1;
115 uint tx_noshear : 1;
116 uint fast_images : 1;
117 };
118
119 union {
120 Flags flags;
121 uint flag_bits;
122 };
123};
124
125
126
127
128/*******************************************************************************
129 * QRasterPaintEngine
130 */
131class
132#ifdef Q_WS_QWS
133Q_GUI_EXPORT
134#endif
135QRasterPaintEngine : public QPaintEngineEx
136{
137 Q_DECLARE_PRIVATE(QRasterPaintEngine)
138public:
139
140 QRasterPaintEngine(QPaintDevice *device);
141 ~QRasterPaintEngine();
142 bool begin(QPaintDevice *device);
143 bool end();
144
145 void penChanged();
146 void brushChanged();
147 void brushOriginChanged();
148 void opacityChanged();
149 void compositionModeChanged();
150 void renderHintsChanged();
151 void transformChanged();
152 void clipEnabledChanged();
153
154 void setState(QPainterState *s);
155 QPainterState *createState(QPainterState *orig) const;
156 inline QRasterPaintEngineState *state() {
157 return static_cast<QRasterPaintEngineState *>(QPaintEngineEx::state());
158 }
159 inline const QRasterPaintEngineState *state() const {
160 return static_cast<const QRasterPaintEngineState *>(QPaintEngineEx::state());
161 }
162
163 void updateBrush(const QBrush &brush);
164 void updatePen(const QPen &pen);
165
166 void updateMatrix(const QTransform &matrix);
167
168 void drawPath(const QPainterPath &path);
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 void clip(const QPainterPath &path, Qt::ClipOperation op);
206
207 enum ClipType {
208 RectClip,
209 ComplexClip
210 };
211 ClipType clipType() const;
212 QRect clipBoundingRect() const;
213
214#ifdef Q_NO_USING_KEYWORD
215 inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); }
216#else
217 using QPaintEngineEx::drawPolygon;
218 using QPaintEngineEx::drawEllipse;
219#endif
220
221 void releaseBuffer();
222
223 QSize size() const;
224
225#ifndef QT_NO_DEBUG
226 void saveBuffer(const QString &s) const;
227#endif
228
229#ifdef Q_WS_MAC
230 void setCGContext(CGContextRef ref);
231 CGContextRef getCGContext() const;
232#endif
233
234#ifdef Q_WS_WIN
235 void setDC(HDC hdc);
236 HDC getDC() const;
237 void releaseDC(HDC hdc) const;
238#endif
239
240 void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h);
241
242 Type type() const { return Raster; }
243
244 QPoint coordinateOffset() const;
245
246#if defined(Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS)
247 virtual void drawColorSpans(const QSpan *spans, int count, uint color);
248 virtual void drawBufferSpan(const uint *buffer, int bufsize,
249 int x, int y, int length, uint const_alpha);
250#endif
251
252protected:
253 QRasterPaintEngine(QRasterPaintEnginePrivate &d, QPaintDevice *);
254private:
255 friend struct QSpanData;
256 void init();
257
258 void fillRect(const QRectF &rect, QSpanData *data);
259 void drawBitmap(const QPointF &pos, const QPixmap &image, QSpanData *fill);
260
261 void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti);
262
263 inline void ensureBrush(const QBrush &brush) {
264 if (!qbrush_fast_equals(state()->lastBrush, brush) || state()->fillFlags)
265 updateBrush(brush);
266 }
267 inline void ensureBrush() { ensureBrush(state()->brush); }
268
269 inline void ensurePen(const QPen &pen) {
270 if (!qpen_fast_equals(state()->lastPen, pen) || state()->strokeFlags)
271 updatePen(pen);
272 }
273 inline void ensurePen() { ensurePen(state()->pen); }
274
275 void updateOutlineMapper();
276 inline void ensureOutlineMapper();
277
278 void updateState();
279 inline void ensureState() {
280 if (state()->dirty)
281 updateState();
282 }
283};
284
285
286/*******************************************************************************
287 * QRasterPaintEnginePrivate
288 */
289class
290#ifdef Q_WS_QWS
291Q_GUI_EXPORT
292#endif
293QRasterPaintEnginePrivate : public QPaintEngineExPrivate
294{
295 Q_DECLARE_PUBLIC(QRasterPaintEngine)
296public:
297
298 void rasterizeLine_dashed(QLineF line, qreal width,
299 int *dashIndex, qreal *dashOffset, bool *inDash);
300 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, QSpanData *spanData, QRasterBuffer *rasterBuffer);
301 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, void *userData, QRasterBuffer *rasterBuffer);
302 void updateMatrixData(QSpanData *spanData, const QBrush &brush, const QTransform &brushMatrix);
303
304 void systemStateChanged();
305
306 void drawImage(const QPointF &pt, const QImage &img, SrcOverBlendFunc func,
307 const QRect &clip, int alpha, const QRect &sr = QRect());
308
309 QTransform brushMatrix() const {
310 Q_Q(const QRasterPaintEngine);
311 const QRasterPaintEngineState *s = q->state();
312 QTransform m(s->matrix);
313 m.translate(s->brushOrigin.x(), s->brushOrigin.y());
314 return m;
315 }
316
317 bool isUnclipped_normalized(const QRect &rect) const;
318 bool isUnclipped(const QRect &rect, int penWidth) const;
319 bool isUnclipped(const QRectF &rect, int penWidth) const;
320 ProcessSpans getPenFunc(const QRect &rect, const QSpanData *data) const;
321 ProcessSpans getPenFunc(const QRectF &rect, const QSpanData *data) const;
322 ProcessSpans getBrushFunc(const QRect &rect, const QSpanData *data) const;
323 ProcessSpans getBrushFunc(const QRectF &rect, const QSpanData *data) const;
324
325#ifdef Q_WS_QWS
326 void prepare(QCustomRasterPaintDevice *);
327#endif
328
329 inline const QClipData *clip() const;
330
331 void strokeProjective(const QPainterPath &path);
332 void initializeRasterizer(QSpanData *data);
333
334 void recalculateFastImages();
335
336 QPaintDevice *device;
337 QOutlineMapper *outlineMapper;
338 QRasterBuffer *rasterBuffer;
339
340#if defined (Q_WS_WIN)
341 HDC hdc;
342#elif defined(Q_WS_MAC)
343 CGContextRef cgContext;
344#endif
345
346 QRect deviceRect;
347
348 QStroker basicStroker;
349 QDashStroker *dashStroker;
350
351 QT_FT_Raster *grayRaster;
352 unsigned long rasterPoolSize;
353 unsigned char *rasterPoolBase;
354
355 QDataBuffer<QLineF> cachedLines;
356 QSpanData image_filler;
357 QSpanData image_filler_xform;
358 QSpanData solid_color_filler;
359
360
361 QFontEngineGlyphCache::Type glyphCacheType;
362
363 QClipData *baseClip;
364
365 int deviceDepth;
366
367 uint mono_surface : 1;
368 uint outlinemapper_xform_dirty : 1;
369
370#ifdef Q_WS_WIN
371 uint isPlain45DegreeRotation : 1;
372#endif
373
374 QRasterizer *rasterizer;
375};
376
377
378class QClipData {
379public:
380 QClipData(int height);
381 ~QClipData();
382
383 int clipSpanHeight;
384 struct ClipLine {
385 int count;
386 QSpan *spans;
387 } *m_clipLines;
388
389 void initialize();
390
391 inline ClipLine *clipLines() {
392 if (!m_clipLines)
393 initialize();
394 return m_clipLines;
395 }
396
397 inline QSpan *spans() {
398 if (!m_spans)
399 initialize();
400 return m_spans;
401 }
402
403 int allocated;
404 int count;
405 QSpan *m_spans;
406 int xmin, xmax, ymin, ymax;
407
408 QRect clipRect;
409 QRegion clipRegion;
410
411 uint enabled : 1;
412 uint hasRectClip : 1;
413 uint hasRegionClip : 1;
414
415 void appendSpan(int x, int length, int y, int coverage);
416 void appendSpans(const QSpan *s, int num);
417
418 // ### Should optimize and actually kill the QSpans if the rect is
419 // ### a subset of The current region. Thus the "fast" clipspan
420 // ### callback can be used
421 void setClipRect(const QRect &rect);
422 void setClipRegion(const QRegion &region);
423 void fixup();
424};
425
426inline void QClipData::appendSpan(int x, int length, int y, int coverage)
427{
428 Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans..
429
430 if (count == allocated) {
431 allocated *= 2;
432 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
433 }
434 m_spans[count].x = x;
435 m_spans[count].len = length;
436 m_spans[count].y = y;
437 m_spans[count].coverage = coverage;
438 ++count;
439}
440
441inline void QClipData::appendSpans(const QSpan *s, int num)
442{
443 Q_ASSERT(m_spans);
444
445 if (count + num > allocated) {
446 do {
447 allocated *= 2;
448 } while (count + num > allocated);
449 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
450 }
451 memcpy(m_spans+count, s, num*sizeof(QSpan));
452 count += num;
453}
454
455#ifdef Q_WS_QWS
456class Q_GUI_EXPORT QCustomRasterPaintDevice : public QPaintDevice
457{
458public:
459 QCustomRasterPaintDevice(QWidget *w) : widget(w) {}
460
461 int devType() const { return QInternal::CustomRaster; }
462
463 virtual int metric(PaintDeviceMetric m) const;
464
465 virtual void* memory() const { return 0; }
466
467 virtual QImage::Format format() const {
468 return QImage::Format_ARGB32_Premultiplied;
469 }
470
471 virtual int bytesPerLine() const;
472
473 virtual QSize size() const {
474 return static_cast<QRasterPaintEngine*>(paintEngine())->size();
475 }
476
477private:
478 QWidget *widget;
479};
480#endif // Q_WS_QWS
481
482/*******************************************************************************
483 * QRasterBuffer
484 */
485class QRasterBuffer
486{
487public:
488 QRasterBuffer() : m_width(0), m_height(0), m_buffer(0) { init(); }
489
490 ~QRasterBuffer();
491
492 void init();
493
494 QImage::Format prepare(QImage *image);
495 QImage::Format prepare(QPixmap *pix);
496#ifdef Q_WS_QWS
497 void prepare(QCustomRasterPaintDevice *device);
498#endif
499 void prepare(int w, int h);
500 void prepareBuffer(int w, int h);
501
502 void resetBuffer(int val=0);
503
504 uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; }
505
506#ifndef QT_NO_DEBUG
507 QImage bufferImage() const;
508#endif
509
510 void flushToARGBImage(QImage *image) const;
511
512 int width() const { return m_width; }
513 int height() const { return m_height; }
514 int bytesPerLine() const { return bytes_per_line; }
515 int bytesPerPixel() const { return bytes_per_pixel; }
516
517 uchar *buffer() const { return m_buffer; }
518
519 bool monoDestinationWithClut;
520 QRgb destColor0;
521 QRgb destColor1;
522
523 QPainter::CompositionMode compositionMode;
524 QImage::Format format;
525 DrawHelper *drawHelper;
526 QImage colorizeBitmap(const QImage &image, const QColor &color);
527
528private:
529 int m_width;
530 int m_height;
531 int bytes_per_line;
532 int bytes_per_pixel;
533 uchar *m_buffer;
534};
535
536inline void QRasterPaintEngine::ensureOutlineMapper() {
537 if (d_func()->outlinemapper_xform_dirty)
538 updateOutlineMapper();
539}
540
541inline const QClipData *QRasterPaintEnginePrivate::clip() const {
542 Q_Q(const QRasterPaintEngine);
543 if (q->state() && q->state()->clip && q->state()->clip->enabled)
544 return q->state()->clip;
545 return baseClip;
546}
547
548
549QT_END_NAMESPACE
550#endif // QPAINTENGINE_RASTER_P_H
Note: See TracBrowser for help on using the repository browser.