| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 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_MAC_P_H
|
|---|
| 43 | #define QPAINTENGINE_MAC_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 purely as an
|
|---|
| 50 | // implementation detail. 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 "QtGui/qpaintengine.h"
|
|---|
| 57 | #include "private/qt_mac_p.h"
|
|---|
| 58 | #include "private/qpaintengine_p.h"
|
|---|
| 59 | #include "private/qpolygonclipper_p.h"
|
|---|
| 60 | #include "QtCore/qhash.h"
|
|---|
| 61 |
|
|---|
| 62 | typedef struct CGColorSpace *CGColorSpaceRef;
|
|---|
| 63 | QT_BEGIN_NAMESPACE
|
|---|
| 64 |
|
|---|
| 65 | extern int qt_defaultDpi();
|
|---|
| 66 | extern int qt_defaultDpiX();
|
|---|
| 67 | extern int qt_defaultDpiY();
|
|---|
| 68 |
|
|---|
| 69 | class QCoreGraphicsPaintEnginePrivate;
|
|---|
| 70 | class QCoreGraphicsPaintEngine : public QPaintEngine
|
|---|
| 71 | {
|
|---|
| 72 | Q_DECLARE_PRIVATE(QCoreGraphicsPaintEngine)
|
|---|
| 73 |
|
|---|
| 74 | public:
|
|---|
| 75 | QCoreGraphicsPaintEngine();
|
|---|
| 76 | ~QCoreGraphicsPaintEngine();
|
|---|
| 77 |
|
|---|
| 78 | bool begin(QPaintDevice *pdev);
|
|---|
| 79 | bool end();
|
|---|
| 80 | static CGColorSpaceRef macGenericColorSpace();
|
|---|
| 81 | static CGColorSpaceRef macDisplayColorSpace(const QWidget *widget = 0);
|
|---|
| 82 |
|
|---|
| 83 | void updateState(const QPaintEngineState &state);
|
|---|
| 84 |
|
|---|
| 85 | void updatePen(const QPen &pen);
|
|---|
| 86 | void updateBrush(const QBrush &brush, const QPointF &pt);
|
|---|
| 87 | void updateFont(const QFont &font);
|
|---|
| 88 | void updateOpacity(qreal opacity);
|
|---|
| 89 | void updateMatrix(const QTransform &matrix);
|
|---|
| 90 | void updateTransform(const QTransform &matrix);
|
|---|
| 91 | void updateClipRegion(const QRegion ®ion, Qt::ClipOperation op);
|
|---|
| 92 | void updateClipPath(const QPainterPath &path, Qt::ClipOperation op);
|
|---|
| 93 | void updateCompositionMode(QPainter::CompositionMode mode);
|
|---|
| 94 | void updateRenderHints(QPainter::RenderHints hints);
|
|---|
| 95 |
|
|---|
| 96 | void drawLines(const QLineF *lines, int lineCount);
|
|---|
| 97 | void drawRects(const QRectF *rects, int rectCount);
|
|---|
| 98 | void drawPoints(const QPointF *p, int pointCount);
|
|---|
| 99 | void drawEllipse(const QRectF &r);
|
|---|
| 100 | void drawPath(const QPainterPath &path);
|
|---|
| 101 |
|
|---|
| 102 | void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
|
|---|
| 103 | void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
|
|---|
| 104 | void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
|
|---|
| 105 |
|
|---|
| 106 | void drawTextItem(const QPointF &pos, const QTextItem &item);
|
|---|
| 107 | void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
|
|---|
| 108 | Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 109 |
|
|---|
| 110 | Type type() const { return QPaintEngine::CoreGraphics; }
|
|---|
| 111 |
|
|---|
| 112 | CGContextRef handle() const;
|
|---|
| 113 |
|
|---|
| 114 | static void initialize();
|
|---|
| 115 | static void cleanup();
|
|---|
| 116 |
|
|---|
| 117 | QPainter::RenderHints supportedRenderHints() const;
|
|---|
| 118 |
|
|---|
| 119 | //avoid partial shadowed overload warnings...
|
|---|
| 120 | void drawLines(const QLine *lines, int lineCount) { QPaintEngine::drawLines(lines, lineCount); }
|
|---|
| 121 | void drawRects(const QRect *rects, int rectCount) { QPaintEngine::drawRects(rects, rectCount); }
|
|---|
| 122 | void drawPoints(const QPoint *p, int pointCount) { QPaintEngine::drawPoints(p, pointCount); }
|
|---|
| 123 | void drawEllipse(const QRect &r) { QPaintEngine::drawEllipse(r); }
|
|---|
| 124 | void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
|
|---|
| 125 | { QPaintEngine::drawPolygon(points, pointCount, mode); }
|
|---|
| 126 |
|
|---|
| 127 | protected:
|
|---|
| 128 | friend class QMacPrintEngine;
|
|---|
| 129 | friend class QMacPrintEnginePrivate;
|
|---|
| 130 | friend void qt_mac_display_change_callbk(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void *);
|
|---|
| 131 | friend void qt_color_profile_changed(CFNotificationCenterRef center, void *,
|
|---|
| 132 | CFStringRef , const void *, CFDictionaryRef);
|
|---|
| 133 | QCoreGraphicsPaintEngine(QPaintEnginePrivate &dptr);
|
|---|
| 134 |
|
|---|
| 135 | private:
|
|---|
| 136 | static bool m_postRoutineRegistered;
|
|---|
| 137 | static CGColorSpaceRef m_genericColorSpace;
|
|---|
| 138 | static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
|
|---|
| 139 | static void cleanUpMacColorSpaces();
|
|---|
| 140 | Q_DISABLE_COPY(QCoreGraphicsPaintEngine)
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 | /*****************************************************************************
|
|---|
| 144 | Private data
|
|---|
| 145 | *****************************************************************************/
|
|---|
| 146 | class QCoreGraphicsPaintEnginePrivate : public QPaintEnginePrivate
|
|---|
| 147 | {
|
|---|
| 148 | Q_DECLARE_PUBLIC(QCoreGraphicsPaintEngine)
|
|---|
| 149 | public:
|
|---|
| 150 | QCoreGraphicsPaintEnginePrivate()
|
|---|
| 151 | : hd(0), shading(0), stackCount(0), complexXForm(false), disabledSmoothFonts(false)
|
|---|
| 152 | {
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | struct {
|
|---|
| 156 | QPen pen;
|
|---|
| 157 | QBrush brush;
|
|---|
| 158 | uint clipEnabled : 1;
|
|---|
| 159 | QRegion clip;
|
|---|
| 160 | QTransform transform;
|
|---|
| 161 | } current;
|
|---|
| 162 |
|
|---|
| 163 | //state info (shared with QD)
|
|---|
| 164 | CGAffineTransform orig_xform;
|
|---|
| 165 |
|
|---|
| 166 | //cg structures
|
|---|
| 167 | CGContextRef hd;
|
|---|
| 168 | CGShadingRef shading;
|
|---|
| 169 | int stackCount;
|
|---|
| 170 | bool complexXForm;
|
|---|
| 171 | bool disabledSmoothFonts;
|
|---|
| 172 | enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen;
|
|---|
| 173 |
|
|---|
| 174 | // pixel and cosmetic pen size in user coordinates.
|
|---|
| 175 | QPointF pixelSize;
|
|---|
| 176 | float cosmeticPenSize;
|
|---|
| 177 |
|
|---|
| 178 | //internal functions
|
|---|
| 179 | enum { CGStroke=0x01, CGEOFill=0x02, CGFill=0x04 };
|
|---|
| 180 | void drawPath(uchar ops, CGMutablePathRef path = 0);
|
|---|
| 181 | void setClip(const QRegion *rgn=0);
|
|---|
| 182 | void resetClip();
|
|---|
| 183 | void setFillBrush(const QPointF &origin=QPoint());
|
|---|
| 184 | void setStrokePen(const QPen &pen);
|
|---|
| 185 | inline void saveGraphicsState();
|
|---|
| 186 | inline void restoreGraphicsState();
|
|---|
| 187 | float penOffset();
|
|---|
| 188 | QPointF devicePixelSize(CGContextRef context);
|
|---|
| 189 | float adjustPenWidth(float penWidth);
|
|---|
| 190 | inline void setTransform(const QTransform *matrix=0)
|
|---|
| 191 | {
|
|---|
| 192 | CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
|
|---|
| 193 | CGAffineTransform xform = orig_xform;
|
|---|
| 194 | if(matrix) {
|
|---|
| 195 | extern CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &);
|
|---|
| 196 | xform = CGAffineTransformConcat(qt_mac_convert_transform_to_cg(*matrix), xform);
|
|---|
| 197 | }
|
|---|
| 198 | CGContextConcatCTM(hd, xform);
|
|---|
| 199 | CGContextSetTextMatrix(hd, xform);
|
|---|
| 200 | }
|
|---|
| 201 | };
|
|---|
| 202 |
|
|---|
| 203 | inline void QCoreGraphicsPaintEnginePrivate::saveGraphicsState()
|
|---|
| 204 | {
|
|---|
| 205 | ++stackCount;
|
|---|
| 206 | CGContextSaveGState(hd);
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | inline void QCoreGraphicsPaintEnginePrivate::restoreGraphicsState()
|
|---|
| 210 | {
|
|---|
| 211 | --stackCount;
|
|---|
| 212 | Q_ASSERT(stackCount >= 0);
|
|---|
| 213 | CGContextRestoreGState(hd);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | class QMacQuartzPaintDevice : public QPaintDevice
|
|---|
| 217 | {
|
|---|
| 218 | public:
|
|---|
| 219 | QMacQuartzPaintDevice(CGContextRef cg, int width, int height, int bytesPerLine)
|
|---|
| 220 | : mCG(cg), mWidth(width), mHeight(height), mBytesPerLine(bytesPerLine)
|
|---|
| 221 | { }
|
|---|
| 222 | int devType() const { return QInternal::MacQuartz; }
|
|---|
| 223 | CGContextRef cgContext() const { return mCG; }
|
|---|
| 224 | int metric(PaintDeviceMetric metric) const {
|
|---|
| 225 | switch (metric) {
|
|---|
| 226 | case PdmWidth:
|
|---|
| 227 | return mWidth;
|
|---|
| 228 | case PdmHeight:
|
|---|
| 229 | return mHeight;
|
|---|
| 230 | case PdmWidthMM:
|
|---|
| 231 | return (qt_defaultDpiX() * mWidth) / 2.54;
|
|---|
| 232 | case PdmHeightMM:
|
|---|
| 233 | return (qt_defaultDpiY() * mHeight) / 2.54;
|
|---|
| 234 | case PdmNumColors:
|
|---|
| 235 | return 0;
|
|---|
| 236 | case PdmDepth:
|
|---|
| 237 | return 32;
|
|---|
| 238 | case PdmDpiX:
|
|---|
| 239 | case PdmPhysicalDpiX:
|
|---|
| 240 | return qt_defaultDpiX();
|
|---|
| 241 | case PdmDpiY:
|
|---|
| 242 | case PdmPhysicalDpiY:
|
|---|
| 243 | return qt_defaultDpiY();
|
|---|
| 244 | }
|
|---|
| 245 | return 0;
|
|---|
| 246 | }
|
|---|
| 247 | QPaintEngine *paintEngine() const { qWarning("This function should never be called."); return 0; }
|
|---|
| 248 | private:
|
|---|
| 249 | CGContextRef mCG;
|
|---|
| 250 | int mWidth;
|
|---|
| 251 | int mHeight;
|
|---|
| 252 | int mBytesPerLine;
|
|---|
| 253 | };
|
|---|
| 254 |
|
|---|
| 255 | QT_END_NAMESPACE
|
|---|
| 256 |
|
|---|
| 257 | #endif // QPAINTENGINE_MAC_P_H
|
|---|