gfx/2d/PathRecording.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/PathRecording.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "PathRecording.h"
    1.10 +#include "DrawEventRecorder.h"
    1.11 +
    1.12 +namespace mozilla {
    1.13 +namespace gfx {
    1.14 +
    1.15 +using namespace std;
    1.16 +
    1.17 +void
    1.18 +PathBuilderRecording::MoveTo(const Point &aPoint)
    1.19 +{
    1.20 +  PathOp op;
    1.21 +  op.mType = PathOp::OP_MOVETO;
    1.22 +  op.mP1 = aPoint;
    1.23 +  mPathOps.push_back(op);
    1.24 +  mPathBuilder->MoveTo(aPoint);
    1.25 +}
    1.26 +
    1.27 +void
    1.28 +PathBuilderRecording::LineTo(const Point &aPoint)
    1.29 +{
    1.30 +  PathOp op;
    1.31 +  op.mType = PathOp::OP_LINETO;
    1.32 +  op.mP1 = aPoint;
    1.33 +  mPathOps.push_back(op);
    1.34 +  mPathBuilder->LineTo(aPoint);
    1.35 +}
    1.36 +
    1.37 +void
    1.38 +PathBuilderRecording::BezierTo(const Point &aCP1, const Point &aCP2, const Point &aCP3)
    1.39 +{
    1.40 +  PathOp op;
    1.41 +  op.mType = PathOp::OP_BEZIERTO;
    1.42 +  op.mP1 = aCP1;
    1.43 +  op.mP2 = aCP2;
    1.44 +  op.mP3 = aCP3;
    1.45 +  mPathOps.push_back(op);
    1.46 +  mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
    1.47 +}
    1.48 +
    1.49 +void
    1.50 +PathBuilderRecording::QuadraticBezierTo(const Point &aCP1, const Point &aCP2)
    1.51 +{
    1.52 +  PathOp op;
    1.53 +  op.mType = PathOp::OP_QUADRATICBEZIERTO;
    1.54 +  op.mP1 = aCP1;
    1.55 +  op.mP2 = aCP2;
    1.56 +  mPathOps.push_back(op);
    1.57 +  mPathBuilder->QuadraticBezierTo(aCP1, aCP2);
    1.58 +}
    1.59 +
    1.60 +void
    1.61 +PathBuilderRecording::Close()
    1.62 +{
    1.63 +  PathOp op;
    1.64 +  op.mType = PathOp::OP_CLOSE;
    1.65 +  mPathOps.push_back(op);
    1.66 +  mPathBuilder->Close();
    1.67 +}
    1.68 +
    1.69 +Point
    1.70 +PathBuilderRecording::CurrentPoint() const
    1.71 +{
    1.72 +  return mPathBuilder->CurrentPoint();
    1.73 +}
    1.74 +
    1.75 +TemporaryRef<Path>
    1.76 +PathBuilderRecording::Finish()
    1.77 +{
    1.78 +  RefPtr<Path> path = mPathBuilder->Finish();
    1.79 +  return new PathRecording(path, mPathOps, mFillRule);
    1.80 +}
    1.81 +
    1.82 +PathRecording::~PathRecording()
    1.83 +{
    1.84 +  for (size_t i = 0; i < mStoredRecorders.size(); i++) {
    1.85 +    mStoredRecorders[i]->RemoveStoredPath(this);
    1.86 +    mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this));
    1.87 +  }
    1.88 +}
    1.89 +
    1.90 +TemporaryRef<PathBuilder>
    1.91 +PathRecording::CopyToBuilder(FillRule aFillRule) const
    1.92 +{
    1.93 +  RefPtr<PathBuilder> pathBuilder = mPath->CopyToBuilder(aFillRule);
    1.94 +  RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule);
    1.95 +  recording->mPathOps = mPathOps;
    1.96 +  return recording;
    1.97 +}
    1.98 +
    1.99 +TemporaryRef<PathBuilder>
   1.100 +PathRecording::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
   1.101 +{
   1.102 +  RefPtr<PathBuilder> pathBuilder = mPath->TransformedCopyToBuilder(aTransform, aFillRule);
   1.103 +  RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule);
   1.104 +  typedef std::vector<PathOp> pathOpVec;
   1.105 +  for (pathOpVec::const_iterator iter = mPathOps.begin(); iter != mPathOps.end(); iter++) {
   1.106 +    PathOp newPathOp;
   1.107 +    newPathOp.mType = iter->mType;
   1.108 +    if (sPointCount[newPathOp.mType] >= 1) {
   1.109 +      newPathOp.mP1 = aTransform * iter->mP1;
   1.110 +    }
   1.111 +    if (sPointCount[newPathOp.mType] >= 2) {
   1.112 +      newPathOp.mP2 = aTransform * iter->mP2;
   1.113 +    }
   1.114 +    if (sPointCount[newPathOp.mType] >= 3) {
   1.115 +      newPathOp.mP3 = aTransform * iter->mP3;
   1.116 +    }
   1.117 +    recording->mPathOps.push_back(newPathOp);
   1.118 +  }
   1.119 +  return recording;
   1.120 +}
   1.121 +
   1.122 +}
   1.123 +}

mercurial