2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-09-24 19:02:50 +04:00
|
|
|
* 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:
|
2017-11-06 06:37:28 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderRecording, override)
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void MoveTo(const Point &aPoint) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
/* Add a linesegment to the current figure */
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void LineTo(const Point &aPoint) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
/* Add a cubic bezier curve to the current figure */
|
|
|
|
virtual void BezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2,
|
2017-11-06 06:37:28 +03:00
|
|
|
const Point &aCP3) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
/* Add a quadratic bezier curve to the current figure */
|
|
|
|
virtual void QuadraticBezierTo(const Point &aCP1,
|
2017-11-06 06:37:28 +03:00
|
|
|
const Point &aCP2) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
/* Close the current figure, this will essentially generate a line segment
|
|
|
|
* from the current point to the starting point for the current figure
|
|
|
|
*/
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void Close() override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/* 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,
|
2017-11-06 06:37:28 +03:00
|
|
|
float aEndAngle, bool aAntiClockwise) override {
|
2016-08-08 19:11:38 +03:00
|
|
|
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.
|
|
|
|
*/
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual Point CurrentPoint() const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual already_AddRefed<Path> Finish() override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual BackendType GetBackendType() const override { return BackendType::RECORDING; }
|
2014-10-04 15:13:29 +04:00
|
|
|
|
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:
|
2017-11-06 06:37:28 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathRecording, override)
|
|
|
|
|
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();
|
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual BackendType GetBackendType() const override { return BackendType::RECORDING; }
|
|
|
|
virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
|
2017-11-06 06:37:28 +03:00
|
|
|
FillRule aFillRule) const override;
|
|
|
|
virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const override
|
2012-09-24 19:02:50 +04:00
|
|
|
{ return mPath->ContainsPoint(aPoint, aTransform); }
|
2012-10-29 19:54:53 +04:00
|
|
|
virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Point &aPoint,
|
2017-11-06 06:37:28 +03:00
|
|
|
const Matrix &aTransform) const override
|
2012-10-29 19:54:53 +04:00
|
|
|
{ return mPath->StrokeContainsPoint(aStrokeOptions, aPoint, aTransform); }
|
2017-11-06 06:37:28 +03:00
|
|
|
|
|
|
|
virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const override
|
2012-09-24 19:02:50 +04:00
|
|
|
{ return mPath->GetBounds(aTransform); }
|
2017-11-06 06:37:28 +03:00
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
|
2017-11-06 06:37:28 +03:00
|
|
|
const Matrix &aTransform = Matrix()) const override
|
2012-09-24 19:02:50 +04:00
|
|
|
{ return mPath->GetStrokedBounds(aStrokeOptions, aTransform); }
|
2013-11-07 13:10:12 +04:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void StreamToSink(PathSink *aSink) const override { mPath->StreamToSink(aSink); }
|
2013-11-07 13:10:12 +04:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual FillRule GetFillRule() const override { return mFillRule; }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
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_ */
|