Bug 926258 - Remove gfxFlattenedPath as it doesn't match the abstraction we want for Moz2D. r=roc

This commit is contained in:
Matt Woodrow 2013-10-15 16:23:21 +13:00
parent c8d82e8dcd
commit 806a534a20
21 changed files with 88 additions and 102 deletions

View File

@ -227,7 +227,7 @@ SVGMotionSMILAnimationFunction::
bool ok =
path.GetDistancesFromOriginToEndsOfVisibleSegments(&mPathVertices);
if (ok && mPathVertices.Length()) {
mPath = pathElem->GetFlattenedPath(gfxMatrix());
mPath = pathElem->GetPath(gfxMatrix());
}
}
}
@ -239,7 +239,7 @@ SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromPathAttr()
const nsAString& pathSpec = GetAttr(nsGkAtoms::path)->GetStringValue();
mPathSourceType = ePathSourceType_PathAttr;
// Generate gfxFlattenedPath from |path| attr
// Generate gfxPath from |path| attr
SVGPathData path;
nsSVGPathDataParserToInternal pathParser(&path);
@ -252,7 +252,7 @@ SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromPathAttr()
return;
}
mPath = path.ToFlattenedPath(gfxMatrix());
mPath = path.ToPath(gfxMatrix());
bool ok = path.GetDistancesFromOriginToEndsOfVisibleSegments(&mPathVertices);
if (!ok || !mPathVertices.Length()) {
mPath = nullptr;
@ -292,7 +292,7 @@ SVGMotionSMILAnimationFunction::
bool
SVGMotionSMILAnimationFunction::
GenerateValuesForPathAndPoints(gfxFlattenedPath* aPath,
GenerateValuesForPathAndPoints(gfxPath* aPath,
bool aIsKeyPoints,
nsTArray<double>& aPointDistances,
nsTArray<nsSMILValue>& aResult)

View File

@ -6,7 +6,7 @@
#ifndef MOZILLA_SVGMOTIONSMILANIMATIONFUNCTION_H_
#define MOZILLA_SVGMOTIONSMILANIMATIONFUNCTION_H_
#include "gfxPath.h" // for gfxFlattenedPath
#include "gfxPath.h" // for gfxPath
#include "nsAutoPtr.h"
#include "nsSMILAnimationFunction.h"
#include "nsTArray.h"
@ -78,7 +78,7 @@ protected:
void RebuildPathAndVerticesFromMpathElem(dom::SVGMPathElement* aMpathElem);
void RebuildPathAndVerticesFromPathAttr();
void RebuildPathAndVerticesFromBasicAttrs(const nsIContent* aContextElem);
bool GenerateValuesForPathAndPoints(gfxFlattenedPath* aPath,
bool GenerateValuesForPathAndPoints(gfxPath* aPath,
bool aIsKeyPoints,
nsTArray<double>& aPointDistances,
nsTArray<nsSMILValue>& aResult);
@ -90,8 +90,8 @@ protected:
RotateType mRotateType; // auto, auto-reverse, or explicit.
float mRotateAngle; // the angle value, if explicit.
PathSourceType mPathSourceType; // source of our gfxFlattenedPath.
nsRefPtr<gfxFlattenedPath> mPath; // representation of motion path.
PathSourceType mPathSourceType; // source of our gfxPath.
nsRefPtr<gfxPath> mPath; // representation of motion path.
nsTArray<double> mPathVertices; // distances of vertices along path.
bool mIsPathStale;

View File

@ -76,10 +76,10 @@ SVGMotionSMILPathUtils::PathGenerator::
return true;
}
already_AddRefed<gfxFlattenedPath>
already_AddRefed<gfxPath>
SVGMotionSMILPathUtils::PathGenerator::GetResultingPath()
{
return mGfxContext.GetFlattenedPath();
return mGfxContext.CopyPath();
}
//----------------------------------------------------------------------

View File

@ -17,7 +17,7 @@
#include "nsSMILParserUtils.h"
#include "nsTArray.h"
class gfxFlattenedPath;
class gfxPath;
class nsAString;
class nsSVGElement;
@ -25,7 +25,7 @@ namespace mozilla {
class SVGMotionSMILPathUtils {
public:
// Class to assist in generating a gfxFlattenedPath, based on
// Class to assist in generating a gfxPath, based on
// coordinates in the <animateMotion> from/by/to/values attributes.
class PathGenerator {
public:
@ -50,7 +50,7 @@ public:
// Accessor to let clients check if we've received any commands yet.
inline bool HaveReceivedCommands() { return mHaveReceivedCommands; }
// Accessor to get the finalized path
already_AddRefed<gfxFlattenedPath> GetResultingPath();
already_AddRefed<gfxPath> GetResultingPath();
protected:
// Helper methods
@ -64,7 +64,7 @@ public:
};
// Class to assist in passing each subcomponent of a |values| attribute to
// a PathGenerator, for generating a corresponding gfxFlattenedPath.
// a PathGenerator, for generating a corresponding gfxPath.
class MotionValueParser : public nsSMILParserUtils::GenericValueParser
{
public:

View File

@ -32,7 +32,7 @@ struct TranslationParams { // Simple translation
float mY;
};
struct PathPointParams { // Point along a path
gfxFlattenedPath* mPath; // NOTE: Refcounted; need to AddRef/Release.
gfxPath* mPath; // NOTE: Refcounted; need to AddRef/Release.
float mDistToPoint; // Distance from path start to the point on the path that
// we're interested in.
};
@ -70,7 +70,7 @@ struct MotionSegment
}
// Constructor for a point on a path (NOTE: AddRef's)
MotionSegment(gfxFlattenedPath* aPath, float aDistToPoint,
MotionSegment(gfxPath* aPath, float aDistToPoint,
RotateType aRotateType, float aRotateAngle)
: mRotateType(aRotateType), mRotateAngle(aRotateAngle),
mSegmentType(eSegmentType_PathPoint)
@ -228,7 +228,7 @@ SVGMotionSMILType::IsEqual(const nsSMILValue& aLeft,
// Helper method for Add & CreateMatrix
inline static void
GetAngleAndPointAtDistance(gfxFlattenedPath* aPath, float aDistance,
GetAngleAndPointAtDistance(gfxPath* aPath, float aDistance,
RotateType aRotateType,
gfxFloat& aRotateAngle, // in & out-param.
gfxPoint& aPoint) // out-param.
@ -287,7 +287,7 @@ SVGMotionSMILType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
"unexpected angle mismatch");
NS_ABORT_IF_FALSE(srcParams.mPath == dstParams.mPath,
"unexpected path mismatch");
gfxFlattenedPath* path = srcParams.mPath;
gfxPath* path = srcParams.mPath;
// Use destination to get our rotate angle.
gfxFloat rotateAngle = dstSeg.mRotateAngle;
@ -411,7 +411,7 @@ SVGMotionSMILType::Interpolate(const nsSMILValue& aStartVal,
// NOTE: path & angle should match between start & end (since presumably
// start & end came from the same <animateMotion> element), unless start is
// empty. (as it would be for pure 'to' animation)
gfxFlattenedPath* path = endParams.mPath;
gfxPath* path = endParams.mPath;
RotateType rotateType = endSeg.mRotateType;
float rotateAngle = endSeg.mRotateAngle;
@ -471,7 +471,7 @@ SVGMotionSMILType::CreateMatrix(const nsSMILValue& aSMILVal)
}
/* static */ nsSMILValue
SVGMotionSMILType::ConstructSMILValue(gfxFlattenedPath* aPath,
SVGMotionSMILType::ConstructSMILValue(gfxPath* aPath,
float aDist,
RotateType aRotateType,
float aRotateAngle)

View File

@ -12,7 +12,7 @@
#include "gfxMatrix.h"
#include "nsISMILType.h"
class gfxFlattenedPath;
class gfxPath;
class nsSMILValue;
namespace mozilla {
@ -65,7 +65,7 @@ public:
// Used to generate a nsSMILValue for the point at the given distance along
// the given path.
static nsSMILValue ConstructSMILValue(gfxFlattenedPath* aPath,
static nsSMILValue ConstructSMILValue(gfxPath* aPath,
float aDist,
RotateType aRotateType,
float aRotateAngle);

View File

@ -492,8 +492,8 @@ SVGPathData::ConstructPath(gfxContext *aCtx) const
MAYBE_APPROXIMATE_ZERO_LENGTH_SUBPATH_SQUARE_CAPS;
}
already_AddRefed<gfxFlattenedPath>
SVGPathData::ToFlattenedPath(const gfxMatrix& aMatrix) const
already_AddRefed<gfxPath>
SVGPathData::ToPath(const gfxMatrix& aMatrix) const
{
nsRefPtr<gfxContext> tmpCtx =
new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
@ -502,7 +502,7 @@ SVGPathData::ToFlattenedPath(const gfxMatrix& aMatrix) const
ConstructPath(tmpCtx);
tmpCtx->IdentityMatrix();
return tmpCtx->GetFlattenedPath();
return tmpCtx->CopyPath();
}
static double

View File

@ -17,7 +17,7 @@
#include <string.h>
class gfxContext;
class gfxFlattenedPath;
class gfxPath;
class nsSVGPathDataParserToInternal; // IWYU pragma: keep
struct gfxMatrix;
@ -150,8 +150,8 @@ public:
*/
bool GetDistancesFromOriginToEndsOfVisibleSegments(nsTArray<double> *aArray) const;
already_AddRefed<gfxFlattenedPath>
ToFlattenedPath(const gfxMatrix& aMatrix) const;
already_AddRefed<gfxPath>
ToPath(const gfxMatrix& aMatrix) const;
void ConstructPath(gfxContext *aCtx) const;

View File

@ -53,7 +53,7 @@ SVGPathElement::PathLength()
float
SVGPathElement::GetTotalLength(ErrorResult& rv)
{
nsRefPtr<gfxFlattenedPath> flat = GetFlattenedPath(gfxMatrix());
nsRefPtr<gfxPath> flat = GetPath(gfxMatrix());
if (!flat) {
rv.Throw(NS_ERROR_FAILURE);
@ -66,7 +66,7 @@ SVGPathElement::GetTotalLength(ErrorResult& rv)
already_AddRefed<nsISVGPoint>
SVGPathElement::GetPointAtLength(float distance, ErrorResult& rv)
{
nsRefPtr<gfxFlattenedPath> flat = GetFlattenedPath(gfxMatrix());
nsRefPtr<gfxPath> flat = GetPath(gfxMatrix());
if (!flat) {
rv.Throw(NS_ERROR_FAILURE);
return nullptr;
@ -292,10 +292,10 @@ SVGPathElement::IsAttributeMapped(const nsIAtom* name) const
SVGPathElementBase::IsAttributeMapped(name);
}
already_AddRefed<gfxFlattenedPath>
SVGPathElement::GetFlattenedPath(const gfxMatrix &aMatrix)
already_AddRefed<gfxPath>
SVGPathElement::GetPath(const gfxMatrix &aMatrix)
{
return mD.GetAnimValue().ToFlattenedPath(aMatrix);
return mD.GetAnimValue().ToPath(aMatrix);
}
//----------------------------------------------------------------------
@ -341,7 +341,7 @@ SVGPathElement::GetPathLengthScale(PathLengthScaleForType aFor)
// we need to take that into account.
matrix = PrependLocalTransformsTo(matrix);
}
nsRefPtr<gfxFlattenedPath> path = GetFlattenedPath(matrix);
nsRefPtr<gfxPath> path = GetPath(matrix);
if (path) {
return path->GetLength() / authorsPathLengthEstimate;
}

View File

@ -48,7 +48,7 @@ public:
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual void ConstructPath(gfxContext *aCtx) MOZ_OVERRIDE;
virtual already_AddRefed<gfxFlattenedPath> GetFlattenedPath(const gfxMatrix &aMatrix) MOZ_OVERRIDE;
virtual already_AddRefed<gfxPath> GetPath(const gfxMatrix &aMatrix) MOZ_OVERRIDE;
// nsIContent interface
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -52,8 +52,8 @@ nsSVGPathGeometryElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
{
}
already_AddRefed<gfxFlattenedPath>
nsSVGPathGeometryElement::GetFlattenedPath(const gfxMatrix &aMatrix)
already_AddRefed<gfxPath>
nsSVGPathGeometryElement::GetPath(const gfxMatrix &aMatrix)
{
return nullptr;
}

View File

@ -8,7 +8,7 @@
#include "SVGGraphicsElement.h"
class gfxFlattenedPath;
class gfxPath;
struct gfxMatrix;
template <class E> class nsTArray;
@ -52,7 +52,7 @@ public:
virtual bool IsMarkable();
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
virtual void ConstructPath(gfxContext *aCtx) = 0;
virtual already_AddRefed<gfxFlattenedPath> GetFlattenedPath(const gfxMatrix &aMatrix);
virtual already_AddRefed<gfxPath> GetPath(const gfxMatrix &aMatrix);
};
#endif

View File

@ -1751,19 +1751,6 @@ gfxContext::GetUserStrokeExtent()
}
}
already_AddRefed<gfxFlattenedPath>
gfxContext::GetFlattenedPath()
{
if (mCairo) {
nsRefPtr<gfxFlattenedPath> path =
new gfxFlattenedPath(cairo_copy_path_flat(mCairo));
return path.forget();
} else {
// XXX - Used by SVG, needs fixing.
return nullptr;
}
}
bool
gfxContext::HasError()
{

View File

@ -645,11 +645,6 @@ public:
gfxRect GetUserFillExtent();
gfxRect GetUserStrokeExtent();
/**
** Obtaining a "flattened" path - path converted to all line segments
**/
already_AddRefed<gfxFlattenedPath> GetFlattenedPath();
/**
** Flags
**/

View File

@ -5,24 +5,35 @@
#include "gfxPath.h"
#include "gfxPoint.h"
#include "gfxPlatform.h"
#include "gfxASurface.h"
#include "cairo.h"
gfxPath::gfxPath(cairo_path_t* aPath) : mPath(aPath)
gfxPath::gfxPath(cairo_path_t* aPath)
: mPath(aPath)
, mFlattenedPath(nullptr)
{
}
gfxPath::~gfxPath()
{
cairo_path_destroy(mPath);
cairo_path_destroy(mFlattenedPath);
}
gfxFlattenedPath::gfxFlattenedPath(cairo_path_t* aPath) : gfxPath(aPath)
void
gfxPath::EnsureFlattenedPath()
{
}
if (mFlattenedPath) {
return;
}
gfxFlattenedPath::~gfxFlattenedPath()
{
gfxASurface* surf = gfxPlatform::GetPlatform()->ScreenReferenceSurface();
cairo_t* cr = cairo_create(surf->CairoSurface());
cairo_append_path(cr, mPath);
mFlattenedPath = cairo_copy_path_flat(cr);
cairo_destroy(cr);
}
static gfxFloat
@ -62,33 +73,37 @@ CalcSubLengthAndAdvance(cairo_path_data_t *aData,
}
gfxFloat
gfxFlattenedPath::GetLength()
gfxPath::GetLength()
{
EnsureFlattenedPath();
gfxPoint start(0, 0); // start of current subpath
gfxPoint current(0, 0); // current point
gfxFloat length = 0; // current summed length
for (int32_t i = 0;
i < mPath->num_data;
i += mPath->data[i].header.length) {
length += CalcSubLengthAndAdvance(&mPath->data[i], start, current);
i < mFlattenedPath->num_data;
i += mFlattenedPath->data[i].header.length) {
length += CalcSubLengthAndAdvance(&mFlattenedPath->data[i], start, current);
}
return length;
}
gfxPoint
gfxFlattenedPath::FindPoint(gfxPoint aOffset, gfxFloat *aAngle)
gfxPath::FindPoint(gfxPoint aOffset, gfxFloat *aAngle)
{
EnsureFlattenedPath();
gfxPoint start(0, 0); // start of current subpath
gfxPoint current(0, 0); // current point
gfxFloat length = 0; // current summed length
for (int32_t i = 0;
i < mPath->num_data;
i += mPath->data[i].header.length) {
i < mFlattenedPath->num_data;
i += mFlattenedPath->data[i].header.length) {
gfxPoint prev = current;
gfxFloat sublength = CalcSubLengthAndAdvance(&mPath->data[i],
gfxFloat sublength = CalcSubLengthAndAdvance(&mFlattenedPath->data[i],
start, current);
gfxPoint diff = current - prev;

View File

@ -25,26 +25,11 @@ class gfxPath {
protected:
gfxPath(cairo_path_t* aPath);
void EnsureFlattenedPath();
public:
virtual ~gfxPath();
protected:
cairo_path_t* mPath;
};
/**
* Specialization of a path that only contains linear pieces. Can be created
* from the existing path of a gfxContext.
*/
class gfxFlattenedPath : public gfxPath {
friend class gfxContext;
protected:
gfxFlattenedPath(cairo_path_t* aPath);
public:
virtual ~gfxFlattenedPath();
/**
* Returns calculated total length of path
*/
@ -59,6 +44,10 @@ public:
*/
gfxPoint FindPoint(gfxPoint aOffset,
gfxFloat* aAngle = nullptr);
protected:
cairo_path_t* mPath;
cairo_path_t* mFlattenedPath;
};
#endif

View File

@ -738,7 +738,7 @@ nsSVGGlyphFrame::GetCharacterPositions(nsTArray<CharacterPosition>* aCharacterPo
nsSVGTextPathFrame *textPath = FindTextPathParent();
if (textPath) {
nsRefPtr<gfxFlattenedPath> data = textPath->GetFlattenedPath();
nsRefPtr<gfxPath> data = textPath->GetPath();
// textPath frame, but invalid target
if (!data)

View File

@ -4637,8 +4637,8 @@ nsSVGTextFrame2::GetTextPathPathFrame(nsIFrame* aTextPathFrame)
return property->GetReferencedFrame(nsGkAtoms::svgPathGeometryFrame, nullptr);
}
already_AddRefed<gfxFlattenedPath>
nsSVGTextFrame2::GetFlattenedTextPath(nsIFrame* aTextPathFrame)
already_AddRefed<gfxPath>
nsSVGTextFrame2::GetTextPath(nsIFrame* aTextPathFrame)
{
nsIFrame *path = GetTextPathPathFrame(aTextPathFrame);
@ -4646,7 +4646,7 @@ nsSVGTextFrame2::GetFlattenedTextPath(nsIFrame* aTextPathFrame)
nsSVGPathGeometryElement *element =
static_cast<nsSVGPathGeometryElement*>(path->GetContent());
return element->GetFlattenedPath(element->PrependLocalTransformsTo(gfxMatrix()));
return element->GetPath(element->PrependLocalTransformsTo(gfxMatrix()));
}
return nullptr;
}
@ -4671,7 +4671,7 @@ nsSVGTextFrame2::GetStartOffset(nsIFrame* aTextPathFrame)
&tp->mLengthAttributes[dom::SVGTextPathElement::STARTOFFSET];
if (length->IsPercentage()) {
nsRefPtr<gfxFlattenedPath> data = GetFlattenedTextPath(aTextPathFrame);
nsRefPtr<gfxPath> data = GetTextPath(aTextPathFrame);
return data ?
length->GetAnimValInSpecifiedUnits() * data->GetLength() / 100.0 :
0.0;
@ -4694,7 +4694,7 @@ nsSVGTextFrame2::DoTextPathLayout()
}
// Get the path itself.
nsRefPtr<gfxFlattenedPath> data = GetFlattenedTextPath(textPathFrame);
nsRefPtr<gfxPath> data = GetTextPath(textPathFrame);
if (!data) {
it.AdvancePastCurrentTextPathFrame();
continue;

View File

@ -18,7 +18,7 @@ class nsDisplaySVGText;
class nsRenderingContext;
class nsSVGTextFrame2;
class nsTextFrame;
class gfxFlattenedPath;
class gfxPath;
typedef nsSVGDisplayContainerFrame nsSVGTextFrame2Base;
@ -517,7 +517,7 @@ private:
// Methods to get information for a <textPath> frame.
nsIFrame* GetTextPathPathFrame(nsIFrame* aTextPathFrame);
already_AddRefed<gfxFlattenedPath> GetFlattenedTextPath(nsIFrame* aTextPathFrame);
already_AddRefed<gfxPath> GetTextPath(nsIFrame* aTextPathFrame);
gfxFloat GetOffsetScale(nsIFrame* aTextPathFrame);
gfxFloat GetStartOffset(nsIFrame* aTextPathFrame);

View File

@ -111,8 +111,8 @@ nsSVGTextPathFrame::GetPathFrame()
return frame && frame->GetContent()->Tag() == nsGkAtoms::path ? frame : nullptr;
}
already_AddRefed<gfxFlattenedPath>
nsSVGTextPathFrame::GetFlattenedPath()
already_AddRefed<gfxPath>
nsSVGTextPathFrame::GetPath()
{
nsIFrame *path = GetPathFrame();
@ -120,7 +120,7 @@ nsSVGTextPathFrame::GetFlattenedPath()
nsSVGPathGeometryElement *element =
static_cast<nsSVGPathGeometryElement*>(path->GetContent());
return element->GetFlattenedPath(element->PrependLocalTransformsTo(gfxMatrix()));
return element->GetPath(element->PrependLocalTransformsTo(gfxMatrix()));
}
return nullptr;
}
@ -132,7 +132,7 @@ nsSVGTextPathFrame::GetStartOffset()
nsSVGLength2 *length = &tp->mLengthAttributes[SVGTextPathElement::STARTOFFSET];
if (length->IsPercentage()) {
nsRefPtr<gfxFlattenedPath> data = GetFlattenedPath();
nsRefPtr<gfxPath> data = GetPath();
return data ? (length->GetAnimValInSpecifiedUnits() * data->GetLength() / 100.0) : 0.0;
}
return length->GetAnimValue(tp) * GetOffsetScale();

View File

@ -15,7 +15,7 @@
#include "nsQueryFrame.h"
#include "nsSVGTSpanFrame.h"
class gfxFlattenedPath;
class gfxPath;
class nsIAtom;
class nsIContent;
class nsIFrame;
@ -65,7 +65,7 @@ public:
#endif
// nsSVGTextPathFrame methods:
already_AddRefed<gfxFlattenedPath> GetFlattenedPath();
already_AddRefed<gfxPath> GetPath();
nsIFrame *GetPathFrame();
/**