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: #include "PathRecording.h" michael@0: #include "DrawEventRecorder.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: using namespace std; michael@0: michael@0: void michael@0: PathBuilderRecording::MoveTo(const Point &aPoint) michael@0: { michael@0: PathOp op; michael@0: op.mType = PathOp::OP_MOVETO; michael@0: op.mP1 = aPoint; michael@0: mPathOps.push_back(op); michael@0: mPathBuilder->MoveTo(aPoint); michael@0: } michael@0: michael@0: void michael@0: PathBuilderRecording::LineTo(const Point &aPoint) michael@0: { michael@0: PathOp op; michael@0: op.mType = PathOp::OP_LINETO; michael@0: op.mP1 = aPoint; michael@0: mPathOps.push_back(op); michael@0: mPathBuilder->LineTo(aPoint); michael@0: } michael@0: michael@0: void michael@0: PathBuilderRecording::BezierTo(const Point &aCP1, const Point &aCP2, const Point &aCP3) michael@0: { michael@0: PathOp op; michael@0: op.mType = PathOp::OP_BEZIERTO; michael@0: op.mP1 = aCP1; michael@0: op.mP2 = aCP2; michael@0: op.mP3 = aCP3; michael@0: mPathOps.push_back(op); michael@0: mPathBuilder->BezierTo(aCP1, aCP2, aCP3); michael@0: } michael@0: michael@0: void michael@0: PathBuilderRecording::QuadraticBezierTo(const Point &aCP1, const Point &aCP2) michael@0: { michael@0: PathOp op; michael@0: op.mType = PathOp::OP_QUADRATICBEZIERTO; michael@0: op.mP1 = aCP1; michael@0: op.mP2 = aCP2; michael@0: mPathOps.push_back(op); michael@0: mPathBuilder->QuadraticBezierTo(aCP1, aCP2); michael@0: } michael@0: michael@0: void michael@0: PathBuilderRecording::Close() michael@0: { michael@0: PathOp op; michael@0: op.mType = PathOp::OP_CLOSE; michael@0: mPathOps.push_back(op); michael@0: mPathBuilder->Close(); michael@0: } michael@0: michael@0: Point michael@0: PathBuilderRecording::CurrentPoint() const michael@0: { michael@0: return mPathBuilder->CurrentPoint(); michael@0: } michael@0: michael@0: TemporaryRef michael@0: PathBuilderRecording::Finish() michael@0: { michael@0: RefPtr path = mPathBuilder->Finish(); michael@0: return new PathRecording(path, mPathOps, mFillRule); michael@0: } michael@0: michael@0: PathRecording::~PathRecording() michael@0: { michael@0: for (size_t i = 0; i < mStoredRecorders.size(); i++) { michael@0: mStoredRecorders[i]->RemoveStoredPath(this); michael@0: mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this)); michael@0: } michael@0: } michael@0: michael@0: TemporaryRef michael@0: PathRecording::CopyToBuilder(FillRule aFillRule) const michael@0: { michael@0: RefPtr pathBuilder = mPath->CopyToBuilder(aFillRule); michael@0: RefPtr recording = new PathBuilderRecording(pathBuilder, aFillRule); michael@0: recording->mPathOps = mPathOps; michael@0: return recording; michael@0: } michael@0: michael@0: TemporaryRef michael@0: PathRecording::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const michael@0: { michael@0: RefPtr pathBuilder = mPath->TransformedCopyToBuilder(aTransform, aFillRule); michael@0: RefPtr recording = new PathBuilderRecording(pathBuilder, aFillRule); michael@0: typedef std::vector pathOpVec; michael@0: for (pathOpVec::const_iterator iter = mPathOps.begin(); iter != mPathOps.end(); iter++) { michael@0: PathOp newPathOp; michael@0: newPathOp.mType = iter->mType; michael@0: if (sPointCount[newPathOp.mType] >= 1) { michael@0: newPathOp.mP1 = aTransform * iter->mP1; michael@0: } michael@0: if (sPointCount[newPathOp.mType] >= 2) { michael@0: newPathOp.mP2 = aTransform * iter->mP2; michael@0: } michael@0: if (sPointCount[newPathOp.mType] >= 3) { michael@0: newPathOp.mP3 = aTransform * iter->mP3; michael@0: } michael@0: recording->mPathOps.push_back(newPathOp); michael@0: } michael@0: return recording; michael@0: } michael@0: michael@0: } michael@0: }