1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QPAINTENGINE_MAC_P_H
43 #define QPAINTENGINE_MAC_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "QtGui/qpaintengine.h"
57 #include "private/qpaintengine_p.h"
58 #include "private/qpolygonclipper_p.h"
59 #include "private/qfont_p.h"
60 #include "QtCore/qhash.h"
64 typedef struct CGColorSpace *CGColorSpaceRef;
67 class QCoreGraphicsPaintEnginePrivate;
68 class QCoreGraphicsPaintEngine : public QPaintEngine
70 Q_DECLARE_PRIVATE(QCoreGraphicsPaintEngine)
73 QCoreGraphicsPaintEngine();
74 ~QCoreGraphicsPaintEngine();
76 bool begin(QPaintDevice *pdev);
78 static CGColorSpaceRef macGenericColorSpace();
79 static CGColorSpaceRef macDisplayColorSpace(const QWidget *widget = 0);
81 void updateState(const QPaintEngineState &state);
83 void updatePen(const QPen &pen);
84 void updateBrush(const QBrush &brush, const QPointF &pt);
85 void updateFont(const QFont &font);
86 void updateOpacity(qreal opacity);
87 void updateMatrix(const QTransform &matrix);
88 void updateTransform(const QTransform &matrix);
89 void updateClipRegion(const QRegion ®ion, Qt::ClipOperation op);
90 void updateClipPath(const QPainterPath &path, Qt::ClipOperation op);
91 void updateCompositionMode(QPainter::CompositionMode mode);
92 void updateRenderHints(QPainter::RenderHints hints);
94 void drawLines(const QLineF *lines, int lineCount);
95 void drawRects(const QRectF *rects, int rectCount);
96 void drawPoints(const QPointF *p, int pointCount);
97 void drawEllipse(const QRectF &r);
98 void drawPath(const QPainterPath &path);
100 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
101 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
102 void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
104 void drawTextItem(const QPointF &pos, const QTextItem &item);
105 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
106 Qt::ImageConversionFlags flags = Qt::AutoColor);
108 Type type() const { return QPaintEngine::CoreGraphics; }
110 CGContextRef handle() const;
112 static void initialize();
113 static void cleanup();
115 QPainter::RenderHints supportedRenderHints() const;
117 //avoid partial shadowed overload warnings...
118 void drawLines(const QLine *lines, int lineCount) { QPaintEngine::drawLines(lines, lineCount); }
119 void drawRects(const QRect *rects, int rectCount) { QPaintEngine::drawRects(rects, rectCount); }
120 void drawPoints(const QPoint *p, int pointCount) { QPaintEngine::drawPoints(p, pointCount); }
121 void drawEllipse(const QRect &r) { QPaintEngine::drawEllipse(r); }
122 void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
123 { QPaintEngine::drawPolygon(points, pointCount, mode); }
125 bool supportsTransformations(qreal, const QTransform &) const { return true; };
128 friend class QMacPrintEngine;
129 friend class QMacPrintEnginePrivate;
130 QCoreGraphicsPaintEngine(QPaintEnginePrivate &dptr);
133 static bool m_postRoutineRegistered;
134 static CGColorSpaceRef m_genericColorSpace;
135 static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
136 static void cleanUpMacColorSpaces();
137 Q_DISABLE_COPY(QCoreGraphicsPaintEngine)
140 /*****************************************************************************
142 *****************************************************************************/
143 class QCoreGraphicsPaintEnginePrivate : public QPaintEnginePrivate
145 Q_DECLARE_PUBLIC(QCoreGraphicsPaintEngine)
147 QCoreGraphicsPaintEnginePrivate()
148 : hd(0), shading(0), stackCount(0), complexXForm(false), disabledSmoothFonts(false)
155 uint clipEnabled : 1;
157 QTransform transform;
160 //state info (shared with QD)
161 CGAffineTransform orig_xform;
165 CGShadingRef shading;
168 bool disabledSmoothFonts;
169 enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen;
171 // pixel and cosmetic pen size in user coordinates.
173 float cosmeticPenSize;
176 enum { CGStroke=0x01, CGEOFill=0x02, CGFill=0x04 };
177 void drawPath(uchar ops, CGMutablePathRef path = 0);
178 void setClip(const QRegion *rgn=0);
180 void setFillBrush(const QPointF &origin=QPoint());
181 void setStrokePen(const QPen &pen);
182 inline void saveGraphicsState();
183 inline void restoreGraphicsState();
185 QPointF devicePixelSize(CGContextRef context);
186 float adjustPenWidth(float penWidth);
187 inline void setTransform(const QTransform *matrix=0)
189 CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
190 CGAffineTransform xform = orig_xform;
192 extern CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &);
193 xform = CGAffineTransformConcat(qt_mac_convert_transform_to_cg(*matrix), xform);
195 CGContextConcatCTM(hd, xform);
196 CGContextSetTextMatrix(hd, xform);
200 inline void QCoreGraphicsPaintEnginePrivate::saveGraphicsState()
203 CGContextSaveGState(hd);
206 inline void QCoreGraphicsPaintEnginePrivate::restoreGraphicsState()
209 Q_ASSERT(stackCount >= 0);
210 CGContextRestoreGState(hd);
213 class QMacQuartzPaintDevice : public QPaintDevice
216 QMacQuartzPaintDevice(CGContextRef cg, int width, int height, int bytesPerLine)
217 : mCG(cg), mWidth(width), mHeight(height), mBytesPerLine(bytesPerLine)
219 int devType() const { return QInternal::MacQuartz; }
220 CGContextRef cgContext() const { return mCG; }
221 int metric(PaintDeviceMetric metric) const {
228 return (qt_defaultDpiX() * mWidth) / 2.54;
230 return (qt_defaultDpiY() * mHeight) / 2.54;
236 case PdmPhysicalDpiX:
237 return qt_defaultDpiX();
239 case PdmPhysicalDpiY:
240 return qt_defaultDpiY();
244 QPaintEngine *paintEngine() const { qWarning("This function should never be called."); return 0; }
254 #endif // QPAINTENGINE_MAC_P_H