2012-09-24 19:02:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_PATHRECORDING_H_
|
|
|
|
#define MOZILLA_GFX_PATHRECORDING_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include <vector>
|
2012-11-08 23:22:16 +04:00
|
|
|
#include <ostream>
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2016-08-08 19:11:38 +03:00
|
|
|
#include "PathHelpers.h"
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
struct PathOp
|
|
|
|
{
|
|
|
|
enum OpType {
|
|
|
|
OP_MOVETO = 0,
|
|
|
|
OP_LINETO,
|
|
|
|
OP_BEZIERTO,
|
|
|
|
OP_QUADRATICBEZIERTO,
|
|
|
|
OP_CLOSE
|
|
|
|
};
|
|
|
|
|
|
|
|
OpType mType;
|
|
|
|
Point mP1;
|
|
|
|
Point mP2;
|
|
|
|
Point mP3;
|
|
|
|
};
|
|
|
|
|
|
|
|
const int32_t sPointCount[] = { 1, 1, 3, 2, 0, 0 };
|
|
|
|
|
|
|
|
class PathRecording;
|
|
|
|
class DrawEventRecorderPrivate;
|
|
|
|
|
|
|
|
class PathBuilderRecording : public PathBuilder
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderRecording)
|
2012-09-24 19:02:50 +04:00
|
|
|
PathBuilderRecording(PathBuilder *aBuilder, FillRule aFillRule)
|
|
|
|
: mPathBuilder(aBuilder), mFillRule(aFillRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move the current point in the path, any figure currently being drawn will
|
|
|
|
* be considered closed during fill operations, however when stroking the
|
|
|
|
* closing line segment will not be drawn.
|
|
|
|
*/
|
|
|
|
virtual void MoveTo(const Point &aPoint);
|
|
|
|
/* Add a linesegment to the current figure */
|
|
|
|
virtual void LineTo(const Point &aPoint);
|
|
|
|
/* Add a cubic bezier curve to the current figure */
|
|
|
|
virtual void BezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2,
|
|
|
|
const Point &aCP3);
|
|
|
|
/* Add a quadratic bezier curve to the current figure */
|
|
|
|
virtual void QuadraticBezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2);
|
|
|
|
/* Close the current figure, this will essentially generate a line segment
|
|
|
|
* from the current point to the starting point for the current figure
|
|
|
|
*/
|
|
|
|
virtual void Close();
|
|
|
|
|
|
|
|
/* Add an arc to the current figure */
|
2016-08-08 19:11:38 +03:00
|
|
|
virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
|
|
|
|
float aEndAngle, bool aAntiClockwise) {
|
|
|
|
ArcToBezier(this, aOrigin, Size(aRadius, aRadius), aStartAngle, aEndAngle,
|
|
|
|
aAntiClockwise);
|
|
|
|
}
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/* Point the current subpath is at - or where the next subpath will start
|
|
|
|
* if there is no active subpath.
|
|
|
|
*/
|
|
|
|
virtual Point CurrentPoint() const;
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<Path> Finish();
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2014-10-04 15:13:29 +04:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::RECORDING; }
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
private:
|
|
|
|
friend class PathRecording;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PathBuilder> mPathBuilder;
|
2012-09-24 19:02:50 +04:00
|
|
|
FillRule mFillRule;
|
|
|
|
std::vector<PathOp> mPathOps;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PathRecording : public Path
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathRecording)
|
2012-09-24 19:02:50 +04:00
|
|
|
PathRecording(Path *aPath, const std::vector<PathOp> aOps, FillRule aFillRule)
|
|
|
|
: mPath(aPath), mPathOps(aOps), mFillRule(aFillRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~PathRecording();
|
|
|
|
|
2014-01-10 23:06:16 +04:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::RECORDING; }
|
2016-02-08 05:15:54 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
|
2016-02-08 05:15:54 +03:00
|
|
|
FillRule aFillRule) const;
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
|
|
|
|
{ return mPath->ContainsPoint(aPoint, aTransform); }
|
2012-10-29 19:54:53 +04:00
|
|
|
virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Point &aPoint,
|
|
|
|
const Matrix &aTransform) const
|
|
|
|
{ return mPath->StrokeContainsPoint(aStrokeOptions, aPoint, aTransform); }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const
|
|
|
|
{ return mPath->GetBounds(aTransform); }
|
|
|
|
|
|
|
|
virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Matrix &aTransform = Matrix()) const
|
|
|
|
{ return mPath->GetStrokedBounds(aStrokeOptions, aTransform); }
|
2013-11-07 13:10:12 +04:00
|
|
|
|
|
|
|
virtual void StreamToSink(PathSink *aSink) const { mPath->StreamToSink(aSink); }
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual FillRule GetFillRule() const { return mFillRule; }
|
|
|
|
|
|
|
|
void StorePath(std::ostream &aStream) const;
|
|
|
|
static void ReadPathToBuilder(std::istream &aStream, PathBuilder *aBuilder);
|
|
|
|
|
|
|
|
private:
|
2017-06-12 23:52:29 +03:00
|
|
|
friend class DrawTargetWrapAndRecord;
|
2012-09-24 19:02:50 +04:00
|
|
|
friend class DrawTargetRecording;
|
|
|
|
friend class RecordedPathCreation;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Path> mPath;
|
2012-09-24 19:02:50 +04:00
|
|
|
std::vector<PathOp> mPathOps;
|
|
|
|
FillRule mFillRule;
|
|
|
|
|
|
|
|
// Event recorders that have this path in their event stream.
|
2016-12-09 05:25:50 +03:00
|
|
|
std::vector<RefPtr<DrawEventRecorderPrivate>> mStoredRecorders;
|
2012-09-24 19:02:50 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_PATHRECORDING_H_ */
|