2011-06-24 17:41:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include "Rect.h"
|
2012-01-09 18:54:44 +00:00
|
|
|
#include "PathCG.h"
|
2012-01-31 06:46:54 +00:00
|
|
|
#include "SourceSurfaceCG.h"
|
2012-07-31 15:17:43 +00:00
|
|
|
#include "GLDefs.h"
|
2012-01-09 18:54:44 +00:00
|
|
|
|
2011-05-26 19:41:33 +00:00
|
|
|
namespace mozilla {
|
2011-06-24 17:41:16 +00:00
|
|
|
namespace gfx {
|
|
|
|
|
2012-01-09 18:54:44 +00:00
|
|
|
static inline CGAffineTransform
|
|
|
|
GfxMatrixToCGAffineTransform(Matrix m)
|
|
|
|
{
|
|
|
|
CGAffineTransform t;
|
|
|
|
t.a = m._11;
|
|
|
|
t.b = m._12;
|
|
|
|
t.c = m._21;
|
|
|
|
t.d = m._22;
|
|
|
|
t.tx = m._31;
|
|
|
|
t.ty = m._32;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Rect
|
|
|
|
CGRectToRect(CGRect rect)
|
|
|
|
{
|
|
|
|
return Rect(rect.origin.x,
|
|
|
|
rect.origin.y,
|
|
|
|
rect.size.width,
|
|
|
|
rect.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
SetStrokeOptions(CGContextRef cg, const StrokeOptions &aStrokeOptions)
|
|
|
|
{
|
|
|
|
switch (aStrokeOptions.mLineCap)
|
|
|
|
{
|
|
|
|
case CAP_BUTT:
|
|
|
|
CGContextSetLineCap(cg, kCGLineCapButt);
|
|
|
|
break;
|
|
|
|
case CAP_ROUND:
|
|
|
|
CGContextSetLineCap(cg, kCGLineCapRound);
|
|
|
|
break;
|
|
|
|
case CAP_SQUARE:
|
|
|
|
CGContextSetLineCap(cg, kCGLineCapSquare);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aStrokeOptions.mLineJoin)
|
|
|
|
{
|
|
|
|
case JOIN_BEVEL:
|
|
|
|
CGContextSetLineJoin(cg, kCGLineJoinBevel);
|
|
|
|
break;
|
|
|
|
case JOIN_ROUND:
|
|
|
|
CGContextSetLineJoin(cg, kCGLineJoinRound);
|
|
|
|
break;
|
|
|
|
case JOIN_MITER:
|
|
|
|
case JOIN_MITER_OR_BEVEL:
|
|
|
|
CGContextSetLineJoin(cg, kCGLineJoinMiter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGContextSetLineWidth(cg, aStrokeOptions.mLineWidth);
|
|
|
|
CGContextSetMiterLimit(cg, aStrokeOptions.mMiterLimit);
|
|
|
|
|
|
|
|
// XXX: rename mDashLength to dashLength
|
2012-03-27 02:50:08 +00:00
|
|
|
if (aStrokeOptions.mDashLength > 0) {
|
2012-01-09 18:54:44 +00:00
|
|
|
// we use a regular array instead of a std::vector here because we don't want to leak the <vector> include
|
|
|
|
CGFloat *dashes = new CGFloat[aStrokeOptions.mDashLength];
|
|
|
|
for (size_t i=0; i<aStrokeOptions.mDashLength; i++) {
|
|
|
|
dashes[i] = aStrokeOptions.mDashPattern[i];
|
|
|
|
}
|
|
|
|
CGContextSetLineDash(cg, aStrokeOptions.mDashOffset, dashes, aStrokeOptions.mDashLength);
|
|
|
|
delete[] dashes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
class DrawTargetCG : public DrawTarget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DrawTargetCG();
|
|
|
|
virtual ~DrawTargetCG();
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2012-07-31 15:17:43 +00:00
|
|
|
virtual BackendType GetType() const;
|
2011-06-24 17:41:16 +00:00
|
|
|
virtual TemporaryRef<SourceSurface> Snapshot();
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
virtual void DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
2012-01-09 18:54:44 +00:00
|
|
|
const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
|
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
virtual void FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-05-26 19:41:33 +00:00
|
|
|
|
|
|
|
|
2012-01-09 18:54:44 +00:00
|
|
|
//XXX: why do we take a reference to SurfaceFormat?
|
2012-07-31 15:17:43 +00:00
|
|
|
bool Init(BackendType aType, const IntSize &aSize, SurfaceFormat&);
|
|
|
|
bool Init(BackendType aType, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
|
2011-06-24 17:41:16 +00:00
|
|
|
bool Init(CGContextRef cgContext, const IntSize &aSize);
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2012-07-31 15:17:43 +00:00
|
|
|
// Flush if using IOSurface context
|
|
|
|
virtual void Flush();
|
2012-01-09 18:54:44 +00:00
|
|
|
|
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface *, const Point &, const Color &, const Point &, Float, CompositionOp);
|
|
|
|
virtual void ClearRect(const Rect &);
|
|
|
|
virtual void CopySurface(SourceSurface *, const IntRect&, const IntPoint&);
|
|
|
|
virtual void StrokeRect(const Rect &, const Pattern &, const StrokeOptions&, const DrawOptions&);
|
|
|
|
virtual void StrokeLine(const Point &, const Point &, const Pattern &, const StrokeOptions &, const DrawOptions &);
|
|
|
|
virtual void Stroke(const Path *, const Pattern &, const StrokeOptions &, const DrawOptions &);
|
|
|
|
virtual void Fill(const Path *, const Pattern &, const DrawOptions &);
|
2012-03-19 19:20:17 +00:00
|
|
|
virtual void FillGlyphs(ScaledFont *, const GlyphBuffer&, const Pattern &, const DrawOptions &, const GlyphRenderingOptions *);
|
2012-01-09 18:54:44 +00:00
|
|
|
virtual void Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
|
|
|
virtual void PushClip(const Path *);
|
|
|
|
virtual void PushClipRect(const Rect &aRect);
|
|
|
|
virtual void PopClip();
|
2012-08-14 18:06:12 +00:00
|
|
|
virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromNativeSurface(const NativeSurface&) const { return nullptr;}
|
2012-01-09 18:54:44 +00:00
|
|
|
virtual TemporaryRef<DrawTarget> CreateSimilarDrawTarget(const IntSize &, SurfaceFormat) const;
|
|
|
|
virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule) const;
|
|
|
|
virtual TemporaryRef<GradientStops> CreateGradientStops(GradientStop *, uint32_t,
|
|
|
|
ExtendMode aExtendMode = EXTEND_CLAMP) const;
|
|
|
|
|
|
|
|
virtual void *GetNativeSurface(NativeSurfaceType);
|
|
|
|
|
|
|
|
virtual IntSize GetSize() { return mSize; }
|
|
|
|
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
/* This is for creating good compatible surfaces */
|
|
|
|
virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat) const;
|
|
|
|
virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
|
2012-01-09 18:54:44 +00:00
|
|
|
CGContextRef GetCGContext() {
|
|
|
|
return mCg;
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
private:
|
2012-01-31 06:46:54 +00:00
|
|
|
void MarkChanged();
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
IntSize mSize;
|
2012-01-09 18:54:44 +00:00
|
|
|
CGColorSpaceRef mColorSpace;
|
2011-06-24 17:41:16 +00:00
|
|
|
CGContextRef mCg;
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2012-07-26 18:06:23 +00:00
|
|
|
/**
|
|
|
|
* A pointer to the image buffer if the buffer is owned by this class (set to
|
2012-08-14 18:06:12 +00:00
|
|
|
* nullptr otherwise).
|
2012-07-26 18:06:23 +00:00
|
|
|
* The data is not considered owned by DrawTargetCG if the DrawTarget was
|
|
|
|
* created for a pre-existing buffer or if the buffer's lifetime is managed
|
|
|
|
* by CoreGraphics.
|
|
|
|
* Data owned by DrawTargetCG will be deallocated in the destructor.
|
|
|
|
*/
|
2012-01-09 18:54:44 +00:00
|
|
|
void *mData;
|
|
|
|
|
2012-07-31 15:17:43 +00:00
|
|
|
RefPtr<SourceSurfaceCGContext> mSnapshot;
|
2011-05-26 19:41:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|