michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_gfx_DrawTargetCG_h michael@0: #define mozilla_gfx_DrawTargetCG_h michael@0: michael@0: #include michael@0: michael@0: #include "2D.h" michael@0: #include "Rect.h" michael@0: #include "PathCG.h" michael@0: #include "SourceSurfaceCG.h" michael@0: #include "GLDefs.h" michael@0: #include "Tools.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: static inline CGAffineTransform michael@0: GfxMatrixToCGAffineTransform(Matrix m) michael@0: { michael@0: CGAffineTransform t; michael@0: t.a = m._11; michael@0: t.b = m._12; michael@0: t.c = m._21; michael@0: t.d = m._22; michael@0: t.tx = m._31; michael@0: t.ty = m._32; michael@0: return t; michael@0: } michael@0: michael@0: static inline Rect michael@0: CGRectToRect(CGRect rect) michael@0: { michael@0: return Rect(rect.origin.x, michael@0: rect.origin.y, michael@0: rect.size.width, michael@0: rect.size.height); michael@0: } michael@0: michael@0: static inline Point michael@0: CGPointToPoint(CGPoint point) michael@0: { michael@0: return Point(point.x, point.y); michael@0: } michael@0: michael@0: static inline void michael@0: SetStrokeOptions(CGContextRef cg, const StrokeOptions &aStrokeOptions) michael@0: { michael@0: switch (aStrokeOptions.mLineCap) michael@0: { michael@0: case CapStyle::BUTT: michael@0: CGContextSetLineCap(cg, kCGLineCapButt); michael@0: break; michael@0: case CapStyle::ROUND: michael@0: CGContextSetLineCap(cg, kCGLineCapRound); michael@0: break; michael@0: case CapStyle::SQUARE: michael@0: CGContextSetLineCap(cg, kCGLineCapSquare); michael@0: break; michael@0: } michael@0: michael@0: switch (aStrokeOptions.mLineJoin) michael@0: { michael@0: case JoinStyle::BEVEL: michael@0: CGContextSetLineJoin(cg, kCGLineJoinBevel); michael@0: break; michael@0: case JoinStyle::ROUND: michael@0: CGContextSetLineJoin(cg, kCGLineJoinRound); michael@0: break; michael@0: case JoinStyle::MITER: michael@0: case JoinStyle::MITER_OR_BEVEL: michael@0: CGContextSetLineJoin(cg, kCGLineJoinMiter); michael@0: break; michael@0: } michael@0: michael@0: CGContextSetLineWidth(cg, aStrokeOptions.mLineWidth); michael@0: CGContextSetMiterLimit(cg, aStrokeOptions.mMiterLimit); michael@0: michael@0: // XXX: rename mDashLength to dashLength michael@0: if (aStrokeOptions.mDashLength > 0) { michael@0: // we use a regular array instead of a std::vector here because we don't want to leak the include michael@0: CGFloat *dashes = new CGFloat[aStrokeOptions.mDashLength]; michael@0: for (size_t i=0; i Snapshot(); michael@0: michael@0: virtual void DrawSurface(SourceSurface *aSurface, michael@0: const Rect &aDest, michael@0: const Rect &aSource, michael@0: const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void DrawFilter(FilterNode *aNode, michael@0: const Rect &aSourceRect, michael@0: const Point &aDestPoint, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void MaskSurface(const Pattern &aSource, michael@0: SourceSurface *aMask, michael@0: Point aOffset, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: virtual void FillRect(const Rect &aRect, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: michael@0: //XXX: why do we take a reference to SurfaceFormat? michael@0: bool Init(BackendType aType, const IntSize &aSize, SurfaceFormat&); michael@0: bool Init(BackendType aType, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat); michael@0: bool Init(CGContextRef cgContext, const IntSize &aSize); michael@0: michael@0: // Flush if using IOSurface context michael@0: virtual void Flush(); michael@0: michael@0: virtual void DrawSurfaceWithShadow(SourceSurface *, const Point &, const Color &, const Point &, Float, CompositionOp); michael@0: virtual void ClearRect(const Rect &); michael@0: virtual void CopySurface(SourceSurface *, const IntRect&, const IntPoint&); michael@0: virtual void StrokeRect(const Rect &, const Pattern &, const StrokeOptions&, const DrawOptions&); michael@0: virtual void StrokeLine(const Point &, const Point &, const Pattern &, const StrokeOptions &, const DrawOptions &); michael@0: virtual void Stroke(const Path *, const Pattern &, const StrokeOptions &, const DrawOptions &); michael@0: virtual void Fill(const Path *, const Pattern &, const DrawOptions &); michael@0: virtual void FillGlyphs(ScaledFont *, const GlyphBuffer&, const Pattern &, const DrawOptions &, const GlyphRenderingOptions *); michael@0: virtual void Mask(const Pattern &aSource, michael@0: const Pattern &aMask, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void PushClip(const Path *); michael@0: virtual void PushClipRect(const Rect &aRect); michael@0: virtual void PopClip(); michael@0: virtual TemporaryRef CreateSourceSurfaceFromNativeSurface(const NativeSurface&) const { return nullptr;} michael@0: virtual TemporaryRef CreateSimilarDrawTarget(const IntSize &, SurfaceFormat) const; michael@0: virtual TemporaryRef CreatePathBuilder(FillRule) const; michael@0: virtual TemporaryRef CreateGradientStops(GradientStop *, uint32_t, michael@0: ExtendMode aExtendMode = ExtendMode::CLAMP) const; michael@0: virtual TemporaryRef CreateFilter(FilterType aType); michael@0: michael@0: virtual void *GetNativeSurface(NativeSurfaceType); michael@0: michael@0: virtual IntSize GetSize() { return mSize; } michael@0: michael@0: michael@0: /* This is for creating good compatible surfaces */ michael@0: virtual TemporaryRef CreateSourceSurfaceFromData(unsigned char *aData, michael@0: const IntSize &aSize, michael@0: int32_t aStride, michael@0: SurfaceFormat aFormat) const; michael@0: virtual TemporaryRef OptimizeSourceSurface(SourceSurface *aSurface) const; michael@0: CGContextRef GetCGContext() { michael@0: return mCg; michael@0: } michael@0: private: michael@0: void MarkChanged(); michael@0: michael@0: IntSize mSize; michael@0: CGColorSpaceRef mColorSpace; michael@0: CGContextRef mCg; michael@0: michael@0: /** michael@0: * The image buffer, if the buffer is owned by this class. michael@0: * If the DrawTarget was created for a pre-existing buffer or if the buffer's michael@0: * lifetime is managed by CoreGraphics, mData will be null. michael@0: * Data owned by DrawTargetCG will be deallocated in the destructor. michael@0: */ michael@0: AlignedArray mData; michael@0: michael@0: RefPtr mSnapshot; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: