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/. */
|
|
|
|
|
|
|
|
#include "PathRecording.h"
|
|
|
|
#include "DrawEventRecorder.h"
|
2017-06-22 23:46:08 +03:00
|
|
|
#include "RecordedEventImpl.h"
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2018-12-02 17:20:00 +03:00
|
|
|
#define NEXT_PARAMS(_type) \
|
|
|
|
const _type params = *reinterpret_cast<const _type*>(nextByte); \
|
|
|
|
nextByte += sizeof(_type);
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
using namespace std;
|
|
|
|
|
2018-12-02 17:20:00 +03:00
|
|
|
bool PathOps::StreamToSink(PathSink& aPathSink) const {
|
|
|
|
if (mPathData.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t* nextByte = mPathData.data();
|
|
|
|
const uint8_t* end = nextByte + mPathData.size();
|
|
|
|
while (nextByte < end) {
|
|
|
|
const OpType opType = *reinterpret_cast<const OpType*>(nextByte);
|
|
|
|
nextByte += sizeof(OpType);
|
|
|
|
switch (opType) {
|
|
|
|
case OpType::OP_MOVETO: {
|
|
|
|
NEXT_PARAMS(Point)
|
|
|
|
aPathSink.MoveTo(params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_LINETO: {
|
|
|
|
NEXT_PARAMS(Point)
|
|
|
|
aPathSink.LineTo(params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_BEZIERTO: {
|
|
|
|
NEXT_PARAMS(ThreePoints)
|
|
|
|
aPathSink.BezierTo(params.p1, params.p2, params.p3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_QUADRATICBEZIERTO: {
|
|
|
|
NEXT_PARAMS(TwoPoints)
|
|
|
|
aPathSink.QuadraticBezierTo(params.p1, params.p2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_ARC: {
|
|
|
|
NEXT_PARAMS(ArcParams)
|
|
|
|
aPathSink.Arc(params.origin, params.radius, params.startAngle,
|
|
|
|
params.endAngle, params.antiClockwise);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_CLOSE:
|
|
|
|
aPathSink.Close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PathOps PathOps::TransformedCopy(const Matrix& aTransform) const {
|
|
|
|
PathOps newPathOps;
|
|
|
|
const uint8_t* nextByte = mPathData.data();
|
|
|
|
const uint8_t* end = nextByte + mPathData.size();
|
|
|
|
while (nextByte < end) {
|
|
|
|
const OpType opType = *reinterpret_cast<const OpType*>(nextByte);
|
|
|
|
nextByte += sizeof(OpType);
|
|
|
|
switch (opType) {
|
|
|
|
case OpType::OP_MOVETO: {
|
|
|
|
NEXT_PARAMS(Point)
|
|
|
|
newPathOps.MoveTo(aTransform.TransformPoint(params));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_LINETO: {
|
|
|
|
NEXT_PARAMS(Point)
|
|
|
|
newPathOps.LineTo(aTransform.TransformPoint(params));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_BEZIERTO: {
|
|
|
|
NEXT_PARAMS(ThreePoints)
|
|
|
|
newPathOps.BezierTo(aTransform.TransformPoint(params.p1),
|
|
|
|
aTransform.TransformPoint(params.p2),
|
|
|
|
aTransform.TransformPoint(params.p3));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_QUADRATICBEZIERTO: {
|
|
|
|
NEXT_PARAMS(TwoPoints)
|
|
|
|
newPathOps.QuadraticBezierTo(aTransform.TransformPoint(params.p1),
|
|
|
|
aTransform.TransformPoint(params.p2));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_ARC: {
|
|
|
|
NEXT_PARAMS(ArcParams)
|
|
|
|
ArcToBezier(&newPathOps, params.origin,
|
|
|
|
gfx::Size(params.radius, params.radius), params.startAngle,
|
|
|
|
params.endAngle, params.antiClockwise, 0.0f, aTransform);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpType::OP_CLOSE:
|
|
|
|
newPathOps.Close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("We control mOpTypes, so this should never happen.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newPathOps;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef NEXT_PARAMS
|
|
|
|
|
|
|
|
size_t PathOps::NumberOfOps() const {
|
|
|
|
size_t size = 0;
|
|
|
|
const uint8_t* nextByte = mPathData.data();
|
|
|
|
const uint8_t* end = nextByte + mPathData.size();
|
|
|
|
while (nextByte < end) {
|
|
|
|
size++;
|
|
|
|
const OpType opType = *reinterpret_cast<const OpType*>(nextByte);
|
|
|
|
nextByte += sizeof(OpType);
|
|
|
|
switch (opType) {
|
|
|
|
case OpType::OP_MOVETO:
|
|
|
|
nextByte += sizeof(Point);
|
|
|
|
break;
|
|
|
|
case OpType::OP_LINETO:
|
|
|
|
nextByte += sizeof(Point);
|
|
|
|
break;
|
|
|
|
case OpType::OP_BEZIERTO:
|
|
|
|
nextByte += sizeof(ThreePoints);
|
|
|
|
break;
|
|
|
|
case OpType::OP_QUADRATICBEZIERTO:
|
|
|
|
nextByte += sizeof(TwoPoints);
|
|
|
|
break;
|
|
|
|
case OpType::OP_ARC:
|
|
|
|
nextByte += sizeof(ArcParams);
|
|
|
|
break;
|
|
|
|
case OpType::OP_CLOSE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("We control mOpTypes, so this should never happen.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void PathBuilderRecording::MoveTo(const Point& aPoint) {
|
2018-12-02 17:20:00 +03:00
|
|
|
mPathOps.MoveTo(aPoint);
|
2012-09-24 19:02:50 +04:00
|
|
|
mPathBuilder->MoveTo(aPoint);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void PathBuilderRecording::LineTo(const Point& aPoint) {
|
2018-12-02 17:20:00 +03:00
|
|
|
mPathOps.LineTo(aPoint);
|
2012-09-24 19:02:50 +04:00
|
|
|
mPathBuilder->LineTo(aPoint);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void PathBuilderRecording::BezierTo(const Point& aCP1, const Point& aCP2,
|
|
|
|
const Point& aCP3) {
|
2018-12-02 17:20:00 +03:00
|
|
|
mPathOps.BezierTo(aCP1, aCP2, aCP3);
|
2012-09-24 19:02:50 +04:00
|
|
|
mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void PathBuilderRecording::QuadraticBezierTo(const Point& aCP1,
|
|
|
|
const Point& aCP2) {
|
2018-12-02 17:20:00 +03:00
|
|
|
mPathOps.QuadraticBezierTo(aCP1, aCP2);
|
2012-09-24 19:02:50 +04:00
|
|
|
mPathBuilder->QuadraticBezierTo(aCP1, aCP2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PathBuilderRecording::Close() {
|
2018-12-02 17:20:00 +03:00
|
|
|
mPathOps.Close();
|
2012-09-24 19:02:50 +04:00
|
|
|
mPathBuilder->Close();
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:20:00 +03:00
|
|
|
void PathBuilderRecording::Arc(const Point& aOrigin, float aRadius,
|
|
|
|
float aStartAngle, float aEndAngle,
|
|
|
|
bool aAntiClockwise) {
|
|
|
|
mPathOps.Arc(aOrigin, aRadius, aStartAngle, aEndAngle, aAntiClockwise);
|
|
|
|
mPathBuilder->Arc(aOrigin, aRadius, aStartAngle, aEndAngle, aAntiClockwise);
|
|
|
|
}
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
already_AddRefed<Path> PathBuilderRecording::Finish() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Path> path = mPathBuilder->Finish();
|
2018-12-02 17:20:00 +03:00
|
|
|
return MakeAndAddRef<PathRecording>(path, std::move(mPathOps), mFillRule,
|
|
|
|
mCurrentPoint, mBeginPoint);
|
2012-09-24 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PathRecording::~PathRecording() {
|
|
|
|
for (size_t i = 0; i < mStoredRecorders.size(); i++) {
|
2016-01-05 13:08:56 +03:00
|
|
|
mStoredRecorders[i]->RemoveStoredObject(this);
|
2012-09-24 19:02:50 +04:00
|
|
|
mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<PathBuilder> PathRecording::CopyToBuilder(
|
2012-09-24 19:02:50 +04:00
|
|
|
FillRule aFillRule) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PathBuilder> pathBuilder = mPath->CopyToBuilder(aFillRule);
|
|
|
|
RefPtr<PathBuilderRecording> recording =
|
2018-12-02 17:20:00 +03:00
|
|
|
new PathBuilderRecording(pathBuilder, mPathOps, aFillRule);
|
2019-06-05 10:55:46 +03:00
|
|
|
recording->SetCurrentPoint(mCurrentPoint);
|
|
|
|
recording->SetBeginPoint(mBeginPoint);
|
2014-06-13 20:09:23 +04:00
|
|
|
return recording.forget();
|
2012-09-24 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<PathBuilder> PathRecording::TransformedCopyToBuilder(
|
2019-05-01 11:47:10 +03:00
|
|
|
const Matrix& aTransform, FillRule aFillRule) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PathBuilder> pathBuilder =
|
|
|
|
mPath->TransformedCopyToBuilder(aTransform, aFillRule);
|
2018-12-02 17:20:00 +03:00
|
|
|
RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(
|
|
|
|
pathBuilder, mPathOps.TransformedCopy(aTransform), aFillRule);
|
2019-06-05 10:55:46 +03:00
|
|
|
|
|
|
|
recording->SetCurrentPoint(aTransform.TransformPoint(mCurrentPoint));
|
|
|
|
recording->SetBeginPoint(aTransform.TransformPoint(mBeginPoint));
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return recording.forget();
|
2012-09-24 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|