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_PATHRECORDING_H_ michael@0: #define MOZILLA_GFX_PATHRECORDING_H_ michael@0: michael@0: #include "2D.h" michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: struct PathOp michael@0: { michael@0: enum OpType { michael@0: OP_MOVETO = 0, michael@0: OP_LINETO, michael@0: OP_BEZIERTO, michael@0: OP_QUADRATICBEZIERTO, michael@0: OP_CLOSE michael@0: }; michael@0: michael@0: OpType mType; michael@0: Point mP1; michael@0: Point mP2; michael@0: Point mP3; michael@0: }; michael@0: michael@0: const int32_t sPointCount[] = { 1, 1, 3, 2, 0, 0 }; michael@0: michael@0: class PathRecording; michael@0: class DrawEventRecorderPrivate; michael@0: michael@0: class PathBuilderRecording : public PathBuilder michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderRecording) michael@0: PathBuilderRecording(PathBuilder *aBuilder, FillRule aFillRule) michael@0: : mPathBuilder(aBuilder), mFillRule(aFillRule) michael@0: { michael@0: } michael@0: michael@0: /* Move the current point in the path, any figure currently being drawn will michael@0: * be considered closed during fill operations, however when stroking the michael@0: * closing line segment will not be drawn. michael@0: */ michael@0: virtual void MoveTo(const Point &aPoint); michael@0: /* Add a linesegment to the current figure */ michael@0: virtual void LineTo(const Point &aPoint); michael@0: /* Add a cubic bezier curve to the current figure */ michael@0: virtual void BezierTo(const Point &aCP1, michael@0: const Point &aCP2, michael@0: const Point &aCP3); michael@0: /* Add a quadratic bezier curve to the current figure */ michael@0: virtual void QuadraticBezierTo(const Point &aCP1, michael@0: const Point &aCP2); michael@0: /* Close the current figure, this will essentially generate a line segment michael@0: * from the current point to the starting point for the current figure michael@0: */ michael@0: virtual void Close(); michael@0: michael@0: /* Add an arc to the current figure */ michael@0: virtual void Arc(const Point &, float, float, float, bool) { } michael@0: michael@0: /* Point the current subpath is at - or where the next subpath will start michael@0: * if there is no active subpath. michael@0: */ michael@0: virtual Point CurrentPoint() const; michael@0: michael@0: virtual TemporaryRef Finish(); michael@0: michael@0: private: michael@0: friend class PathRecording; michael@0: michael@0: RefPtr mPathBuilder; michael@0: FillRule mFillRule; michael@0: std::vector mPathOps; michael@0: }; michael@0: michael@0: class PathRecording : public Path michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathRecording) michael@0: PathRecording(Path *aPath, const std::vector aOps, FillRule aFillRule) michael@0: : mPath(aPath), mPathOps(aOps), mFillRule(aFillRule) michael@0: { michael@0: } michael@0: michael@0: ~PathRecording(); michael@0: michael@0: virtual BackendType GetBackendType() const { return BackendType::RECORDING; } michael@0: virtual TemporaryRef CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; michael@0: virtual TemporaryRef TransformedCopyToBuilder(const Matrix &aTransform, michael@0: FillRule aFillRule = FillRule::FILL_WINDING) const; michael@0: virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const michael@0: { return mPath->ContainsPoint(aPoint, aTransform); } michael@0: virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, michael@0: const Point &aPoint, michael@0: const Matrix &aTransform) const michael@0: { return mPath->StrokeContainsPoint(aStrokeOptions, aPoint, aTransform); } michael@0: michael@0: virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const michael@0: { return mPath->GetBounds(aTransform); } michael@0: michael@0: virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, michael@0: const Matrix &aTransform = Matrix()) const michael@0: { return mPath->GetStrokedBounds(aStrokeOptions, aTransform); } michael@0: michael@0: virtual void StreamToSink(PathSink *aSink) const { mPath->StreamToSink(aSink); } michael@0: michael@0: virtual FillRule GetFillRule() const { return mFillRule; } michael@0: michael@0: void StorePath(std::ostream &aStream) const; michael@0: static void ReadPathToBuilder(std::istream &aStream, PathBuilder *aBuilder); michael@0: michael@0: private: michael@0: friend class DrawTargetRecording; michael@0: friend class RecordedPathCreation; michael@0: michael@0: RefPtr mPath; michael@0: std::vector mPathOps; michael@0: FillRule mFillRule; michael@0: michael@0: // Event recorders that have this path in their event stream. michael@0: std::vector mStoredRecorders; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_PATHRECORDING_H_ */