Bug 935297 - Part 4: Implement new API to allow streaming paths to arbitrary sinks on Skia. r=mattwoodrow
authorBas Schouten <bschouten@mozilla.com>
Thu, 07 Nov 2013 22:11:48 +1300
changeset 156865 552952fcc5604bb8a2d8b33f5c0a4a94a774bf06
parent 156864 ce50e724668429467852f6007d2082e2bfbd51c3
child 156866 72784fe5e8367a603f240a1394a18d72271372c1
push idunknown
push userunknown
push dateunknown
reviewersmattwoodrow
bugs935297
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 935297 - Part 4: Implement new API to allow streaming paths to arbitrary sinks on Skia. r=mattwoodrow
gfx/2d/HelpersSkia.h
gfx/2d/PathSkia.cpp
gfx/2d/PathSkia.h
--- a/gfx/2d/HelpersSkia.h
+++ b/gfx/2d/HelpersSkia.h
@@ -245,16 +245,22 @@ RectToSkIRect(const Rect& aRect)
 }
 
 static inline SkIRect
 IntRectToSkIRect(const IntRect& aRect)
 {
   return SkIRect::MakeXYWH(aRect.x, aRect.y, aRect.width, aRect.height);
 }
 
+static inline Point
+SkPointToPoint(const SkPoint &aPoint)
+{
+  return Point(SkScalarToFloat(aPoint.x()), SkScalarToFloat(aPoint.y()));
+}
+
 static inline SkShader::TileMode
 ExtendModeToTileMode(ExtendMode aMode)
 {
   switch (aMode)
   {
     case EXTEND_CLAMP:
       return SkShader::kClamp_TileMode;
     case EXTEND_REPEAT:
--- a/gfx/2d/PathSkia.cpp
+++ b/gfx/2d/PathSkia.cpp
@@ -204,10 +204,44 @@ PathSkia::GetStrokedBounds(const StrokeO
   
   SkPath result;
   paint.getFillPath(mPath, &result);
 
   Rect bounds = SkRectToRect(result.getBounds());
   return aTransform.TransformBounds(bounds);
 }
 
+void
+PathSkia::StreamToSink(PathSink *aSink) const
+{
+  SkPath::RawIter iter(mPath);
+
+  SkPoint points[4];
+  SkPath::Verb currentVerb;
+  while ((currentVerb = iter.next(points)) != SkPath::kDone_Verb) {
+    switch (currentVerb) {
+    case SkPath::kMove_Verb:
+      aSink->MoveTo(SkPointToPoint(points[0]));
+      break;
+    case SkPath::kLine_Verb:
+      aSink->LineTo(SkPointToPoint(points[1]));
+      break;
+    case SkPath::kCubic_Verb:
+      aSink->BezierTo(SkPointToPoint(points[1]),
+                      SkPointToPoint(points[2]),
+                      SkPointToPoint(points[3]));
+      break;
+    case SkPath::kQuad_Verb:
+      aSink->QuadraticBezierTo(SkPointToPoint(points[1]),
+                               SkPointToPoint(points[2]));
+      break;
+    case SkPath::kClose_Verb:
+      aSink->Close();
+      break;
+    default:
+      MOZ_ASSERT(false);
+      // Unexpected verb found in path!
+    }
+  }
+}
+
 }
 }
--- a/gfx/2d/PathSkia.h
+++ b/gfx/2d/PathSkia.h
@@ -61,17 +61,17 @@ public:
                                    const Point &aPoint,
                                    const Matrix &aTransform) const;
 
   virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
   
   virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
                                 const Matrix &aTransform = Matrix()) const;
 
-  virtual void StreamToSink(PathSink *aSink) const { MOZ_ASSERT(false); }
+  virtual void StreamToSink(PathSink *aSink) const;
 
   virtual FillRule GetFillRule() const { return mFillRule; }
 
   const SkPath& GetPath() const { return mPath; }
 
 private:
   friend class DrawTargetSkia;