1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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/qt_mac_p.h"
58 #include "private/qpaintengine_p.h"
59 #include "private/qpolygonclipper_p.h"
60 #include "private/qfont_p.h"
61 #include "QtCore/qhash.h"
63 typedef struct CGColorSpace *CGColorSpaceRef;
66 class QCoreGraphicsPaintEnginePrivate;
67 class QCoreGraphicsPaintEngine : public QPaintEngine
69 Q_DECLARE_PRIVATE(QCoreGraphicsPaintEngine)
72 QCoreGraphicsPaintEngine();
73 ~QCoreGraphicsPaintEngine();
75 bool begin(QPaintDevice *pdev);
77 static CGColorSpaceRef macGenericColorSpace();
78 static CGColorSpaceRef macDisplayColorSpace(const QWidget *widget = 0);
80 void updateState(const QPaintEngineState &state);
82 void updatePen(const QPen &pen);
83 void updateBrush(const QBrush &brush, const QPointF &pt);
84 void updateFont(const QFont &font);
85 void updateOpacity(qreal opacity);
86 void updateMatrix(const QTransform &matrix);
87 void updateTransform(const QTransform &matrix);
88 void updateClipRegion(const QRegion ®ion, Qt::ClipOperation op);
89 void updateClipPath(const QPainterPath &path, Qt::ClipOperation op);
90 void updateCompositionMode(QPainter::CompositionMode mode);
91 void updateRenderHints(QPainter::RenderHints hints);
93 void drawLines(const QLineF *lines, int lineCount);
94 void drawRects(const QRectF *rects, int rectCount);
95 void drawPoints(const QPointF *p, int pointCount);
96 void drawEllipse(const QRectF &r);
97 void drawPath(const QPainterPath &path);
99 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
100 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
101 void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
103 void drawTextItem(const QPointF &pos, const QTextItem &item);
104 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
105 Qt::ImageConversionFlags flags = Qt::AutoColor);
107 Type type() const { return QPaintEngine::CoreGraphics; }
109 CGContextRef handle() const;
111 static void initialize();
112 static void cleanup();
114 QPainter::RenderHints supportedRenderHints() const;
116 //avoid partial shadowed overload warnings...
117 void drawLines(const QLine *lines, int lineCount) { QPaintEngine::drawLines(lines, lineCount); }
118 void drawRects(const QRect *rects, int rectCount) { QPaintEngine::drawRects(rects, rectCount); }
119 void drawPoints(const QPoint *p, int pointCount) { QPaintEngine::drawPoints(p, pointCount); }
120 void drawEllipse(const QRect &r) { QPaintEngine::drawEllipse(r); }
121 void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
122 { QPaintEngine::drawPolygon(points, pointCount, mode); }
124 bool supportsTransformations(qreal, const QTransform &) const { return true; };
127 friend class QMacPrintEngine;
128 friend class QMacPrintEnginePrivate;
129 friend void qt_mac_display_change_callbk(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void *);
130 friend void qt_color_profile_changed(CFNotificationCenterRef center, void *,
131 CFStringRef , const void *, CFDictionaryRef);
132 QCoreGraphicsPaintEngine(QPaintEnginePrivate &dptr);
135 static bool m_postRoutineRegistered;
136 static CGColorSpaceRef m_genericColorSpace;
137 static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
138 static void cleanUpMacColorSpaces();
139 Q_DISABLE_COPY(QCoreGraphicsPaintEngine)
142 /*****************************************************************************
144 *****************************************************************************/
145 class QCoreGraphicsPaintEnginePrivate : public QPaintEnginePrivate
147 Q_DECLARE_PUBLIC(QCoreGraphicsPaintEngine)
149 QCoreGraphicsPaintEnginePrivate()
150 : hd(0), shading(0), stackCount(0), complexXForm(false), disabledSmoothFonts(false)
157 uint clipEnabled : 1;
159 QTransform transform;
162 //state info (shared with QD)
163 CGAffineTransform orig_xform;
167 CGShadingRef shading;
170 bool disabledSmoothFonts;
171 enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen;
173 // pixel and cosmetic pen size in user coordinates.
175 float cosmeticPenSize;
178 enum { CGStroke=0x01, CGEOFill=0x02, CGFill=0x04 };
179 void drawPath(uchar ops, CGMutablePathRef path = 0);
180 void setClip(const QRegion *rgn=0);
182 void setFillBrush(const QPointF &origin=QPoint());
183 void setStrokePen(const QPen &pen);
184 inline void saveGraphicsState();
185 inline void restoreGraphicsState();
187 QPointF devicePixelSize(CGContextRef context);
188 float adjustPenWidth(float penWidth);
189 inline void setTransform(const QTransform *matrix=0)
191 CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
192 CGAffineTransform xform = orig_xform;
194 extern CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &);
195 xform = CGAffineTransformConcat(qt_mac_convert_transform_to_cg(*matrix), xform);
197 CGContextConcatCTM(hd, xform);
198 CGContextSetTextMatrix(hd, xform);
202 inline void QCoreGraphicsPaintEnginePrivate::saveGraphicsState()
205 CGContextSaveGState(hd);
208 inline void QCoreGraphicsPaintEnginePrivate::restoreGraphicsState()
211 Q_ASSERT(stackCount >= 0);
212 CGContextRestoreGState(hd);
215 class QMacQuartzPaintDevice : public QPaintDevice
218 QMacQuartzPaintDevice(CGContextRef cg, int width, int height, int bytesPerLine)
219 : mCG(cg), mWidth(width), mHeight(height), mBytesPerLine(bytesPerLine)
221 int devType() const { return QInternal::MacQuartz; }
222 CGContextRef cgContext() const { return mCG; }
223 int metric(PaintDeviceMetric metric) const {
230 return (qt_defaultDpiX() * mWidth) / 2.54;
232 return (qt_defaultDpiY() * mHeight) / 2.54;
238 case PdmPhysicalDpiX:
239 return qt_defaultDpiX();
241 case PdmPhysicalDpiY:
242 return qt_defaultDpiY();
246 QPaintEngine *paintEngine() const { qWarning("This function should never be called."); return 0; }
256 #endif // QPAINTENGINE_MAC_P_H