Bug 937994 - Make the SMIL animateMotion code use a Moz2D PathBuilder instead of gfxContext. r=dholbert

This commit is contained in:
Jonathan Watt 2013-11-18 01:29:05 +00:00
Родитель ff4b20243d
Коммит dc9a078082
2 изменённых файлов: 29 добавлений и 12 удалений

Просмотреть файл

@ -4,11 +4,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SVGMotionSMILPathUtils.h"
#include "gfxPath.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsContentUtils.h" // for NS_ENSURE_FINITE2
#include "SVGContentUtils.h"
#include "SVGLength.h"
using namespace mozilla::gfx;
namespace mozilla {
//----------------------------------------------------------------------
@ -22,7 +26,7 @@ SVGMotionSMILPathUtils::PathGenerator::
NS_ABORT_IF_FALSE(!mHaveReceivedCommands,
"Not expecting requests for mid-path MoveTo commands");
mHaveReceivedCommands = true;
mGfxContext.MoveTo(gfxPoint(0, 0));
mPathBuilder->MoveTo(Point(0, 0));
}
// For 'from' and the first entry in 'values'.
@ -38,7 +42,7 @@ SVGMotionSMILPathUtils::PathGenerator::
if (!ParseCoordinatePair(aCoordPairStr, xVal, yVal)) {
return false;
}
mGfxContext.MoveTo(gfxPoint(xVal, yVal));
mPathBuilder->MoveTo(Point(xVal, yVal));
return true;
}
@ -53,9 +57,9 @@ SVGMotionSMILPathUtils::PathGenerator::
if (!ParseCoordinatePair(aCoordPairStr, xVal, yVal)) {
return false;
}
gfxPoint initialPoint = mGfxContext.CurrentPoint();
Point initialPoint = mPathBuilder->CurrentPoint();
mGfxContext.LineTo(gfxPoint(xVal, yVal));
mPathBuilder->LineTo(Point(xVal, yVal));
aSegmentDistance = NS_hypot(initialPoint.x - xVal, initialPoint.y -yVal);
return true;
}
@ -71,7 +75,7 @@ SVGMotionSMILPathUtils::PathGenerator::
if (!ParseCoordinatePair(aCoordPairStr, xVal, yVal)) {
return false;
}
mGfxContext.LineTo(mGfxContext.CurrentPoint() + gfxPoint(xVal, yVal));
mPathBuilder->LineTo(mPathBuilder->CurrentPoint() + Point(xVal, yVal));
aSegmentDistance = NS_hypot(xVal, yVal);
return true;
}
@ -79,7 +83,9 @@ SVGMotionSMILPathUtils::PathGenerator::
already_AddRefed<gfxPath>
SVGMotionSMILPathUtils::PathGenerator::GetResultingPath()
{
return mGfxContext.CopyPath();
RefPtr<Path> path = mPathBuilder->Finish();
nsRefPtr<gfxPath> thebesPath = new gfxPath(path);
return thebesPath.forget();
}
//----------------------------------------------------------------------

Просмотреть файл

@ -10,9 +10,9 @@
#define MOZILLA_SVGMOTIONSMILPATHUTILS_H_
#include "mozilla/Attributes.h"
#include "gfxContext.h"
#include "gfxPlatform.h"
#include "nsCOMPtr.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/RefPtr.h"
#include "nsDebug.h"
#include "nsSMILParserUtils.h"
#include "nsTArray.h"
@ -23,7 +23,11 @@ class nsSVGElement;
namespace mozilla {
class SVGMotionSMILPathUtils {
class SVGMotionSMILPathUtils
{
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::PathBuilder PathBuilder;
public:
// Class to assist in generating a gfxPath, based on
// coordinates in the <animateMotion> from/by/to/values attributes.
@ -31,9 +35,16 @@ public:
public:
PathGenerator(const nsSVGElement* aSVGElement)
: mSVGElement(aSVGElement),
mGfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()),
mHaveReceivedCommands(false)
{}
{
RefPtr<DrawTarget> drawTarget =
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
NS_ASSERTION(gfxPlatform::GetPlatform()->
SupportsAzureContentForDrawTarget(drawTarget),
"Should support Moz2D content drawing");
mPathBuilder = drawTarget->CreatePathBuilder();
}
// Methods for adding various path commands to output path.
// Note: aCoordPairStr is expected to be a whitespace and/or
@ -59,7 +70,7 @@ public:
// Member data
const nsSVGElement* mSVGElement; // context for converting to user units
gfxContext mGfxContext;
RefPtr<PathBuilder> mPathBuilder;
bool mHaveReceivedCommands;
};