Bug 1114398 - Part 1: Make Direct2D paths specifically typed to a backend type. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Thu, 08 Jan 2015 00:10:48 +0000
changeset 235570 8309d6ce7a3892c91600d7327359c538ecaa1ce1
parent 235569 633a1d06b192de3fd7584867389db2bc9a459b5e
child 235571 d5ead6673b9557737a3368d7a1be3763b6d49ae7
push id366
push usercmanchester@mozilla.com
push dateThu, 08 Jan 2015 16:40:24 +0000
reviewersjrmuizel
bugs1114398
milestone37.0a1
Bug 1114398 - Part 1: Make Direct2D paths specifically typed to a backend type. r=jrmuizel
gfx/2d/DrawTargetD2D.cpp
gfx/2d/DrawTargetD2D1.cpp
gfx/2d/PathD2D.cpp
gfx/2d/PathD2D.h
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -1269,17 +1269,17 @@ DrawTargetD2D::CreatePathBuilder(FillRul
     gfxWarning() << "Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   if (aFillRule == FillRule::FILL_WINDING) {
     sink->SetFillMode(D2D1_FILL_MODE_WINDING);
   }
 
-  return new PathBuilderD2D(sink, path, aFillRule);
+  return new PathBuilderD2D(sink, path, aFillRule, BackendType::DIRECT2D);
 }
 
 TemporaryRef<GradientStops>
 DrawTargetD2D::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const
 {
   D2D1_GRADIENT_STOP *stops = new D2D1_GRADIENT_STOP[aNumStops];
 
   for (uint32_t i = 0; i < aNumStops; i++) {
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -406,17 +406,17 @@ DrawTargetD2D1::StrokeLine(const Point &
 }
 
 void
 DrawTargetD2D1::Stroke(const Path *aPath,
                        const Pattern &aPattern,
                        const StrokeOptions &aStrokeOptions,
                        const DrawOptions &aOptions)
 {
-  if (aPath->GetBackendType() != BackendType::DIRECT2D) {
+  if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
     gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
     return;
   }
   const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
 
   PrepareForDrawing(aOptions.mCompositionOp, aPattern);
 
   mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
@@ -429,17 +429,17 @@ DrawTargetD2D1::Stroke(const Path *aPath
   FinalizeDrawing(aOptions.mCompositionOp, aPattern);
 }
 
 void
 DrawTargetD2D1::Fill(const Path *aPath,
                      const Pattern &aPattern,
                      const DrawOptions &aOptions)
 {
-  if (aPath->GetBackendType() != BackendType::DIRECT2D) {
+  if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
     gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
     return;
   }
   const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
 
   PrepareForDrawing(aOptions.mCompositionOp, aPattern);
 
   mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
@@ -555,17 +555,17 @@ DrawTargetD2D1::Mask(const Pattern &aSou
   mDC->PopLayer();
 
   FinalizeDrawing(aOptions.mCompositionOp, aSource);
 }
 
 void
 DrawTargetD2D1::PushClip(const Path *aPath)
 {
-  if (aPath->GetBackendType() != BackendType::DIRECT2D) {
+  if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
     gfxDebug() << *this << ": Ignoring clipping call for incompatible path.";
     return;
   }
 
   mCurrentClippedGeometry = nullptr;
 
   RefPtr<PathD2D> pathD2D = static_cast<PathD2D*>(const_cast<Path*>(aPath));
 
@@ -689,17 +689,17 @@ DrawTargetD2D1::CreatePathBuilder(FillRu
     gfxWarning() << *this << ": Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   if (aFillRule == FillRule::FILL_WINDING) {
     sink->SetFillMode(D2D1_FILL_MODE_WINDING);
   }
 
-  return new PathBuilderD2D(sink, path, aFillRule);
+  return new PathBuilderD2D(sink, path, aFillRule, BackendType::DIRECT2D1_1);
 }
 
 TemporaryRef<GradientStops>
 DrawTargetD2D1::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const
 {
   if (aNumStops == 0) {
     gfxWarning() << *this << ": Failed to create GradientStopCollection with no stops.";
     return nullptr;
--- a/gfx/2d/PathD2D.cpp
+++ b/gfx/2d/PathD2D.cpp
@@ -298,17 +298,17 @@ PathBuilderD2D::Finish()
   }
 
   HRESULT hr = mSink->Close();
   if (FAILED(hr)) {
     gfxDebug() << "Failed to close PathSink. Code: " << hexa(hr);
     return nullptr;
   }
 
-  return new PathD2D(mGeometry, mFigureActive, mCurrentPoint, mFillRule);
+  return new PathD2D(mGeometry, mFigureActive, mCurrentPoint, mFillRule, mBackendType);
 }
 
 TemporaryRef<PathBuilder>
 PathD2D::CopyToBuilder(FillRule aFillRule) const
 {
   return TransformedCopyToBuilder(Matrix(), aFillRule);
 }
 
@@ -340,17 +340,17 @@ PathD2D::TransformedCopyToBuilder(const 
                         D2DMatrix(aTransform),
                         &wrapSink);
   } else {
     mGeometry->Simplify(D2D1_GEOMETRY_SIMPLIFICATION_OPTION_CUBICS_AND_LINES,
                         D2DMatrix(aTransform),
                         sink);
   }
 
-  RefPtr<PathBuilderD2D> pathBuilder = new PathBuilderD2D(sink, path, aFillRule);
+  RefPtr<PathBuilderD2D> pathBuilder = new PathBuilderD2D(sink, path, aFillRule, mBackendType);
   
   pathBuilder->mCurrentPoint = aTransform * mEndPoint;
   
   if (mEndedActive) {
     pathBuilder->mFigureActive = true;
   }
 
   return pathBuilder.forget();
--- a/gfx/2d/PathD2D.h
+++ b/gfx/2d/PathD2D.h
@@ -14,21 +14,22 @@ namespace mozilla {
 namespace gfx {
 
 class PathD2D;
 
 class PathBuilderD2D : public PathBuilder
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderD2D)
-  PathBuilderD2D(ID2D1GeometrySink *aSink, ID2D1PathGeometry *aGeom, FillRule aFillRule)
+  PathBuilderD2D(ID2D1GeometrySink *aSink, ID2D1PathGeometry *aGeom, FillRule aFillRule, BackendType aBackendType)
     : mSink(aSink)
     , mGeometry(aGeom)
     , mFigureActive(false)
     , mFillRule(aFillRule)
+    , mBackendType(aBackendType)
   {
   }
   virtual ~PathBuilderD2D();
 
   virtual void MoveTo(const Point &aPoint);
   virtual void LineTo(const Point &aPoint);
   virtual void BezierTo(const Point &aCP1,
                         const Point &aCP2,
@@ -37,47 +38,49 @@ public:
                                  const Point &aCP2);
   virtual void Close();
   virtual void Arc(const Point &aOrigin, Float aRadius, Float aStartAngle,
                    Float aEndAngle, bool aAntiClockwise = false);
   virtual Point CurrentPoint() const;
 
   virtual TemporaryRef<Path> Finish();
 
-  virtual BackendType GetBackendType() const { return BackendType::DIRECT2D; }
+  virtual BackendType GetBackendType() const { return mBackendType; }
 
   ID2D1GeometrySink *GetSink() { return mSink; }
 
 private:
   friend class PathD2D;
 
   void EnsureActive(const Point &aPoint);
 
   RefPtr<ID2D1GeometrySink> mSink;
   RefPtr<ID2D1PathGeometry> mGeometry;
 
   bool mFigureActive;
   Point mCurrentPoint;
   Point mBeginPoint;
   FillRule mFillRule;
+  BackendType mBackendType;
 };
 
 class PathD2D : public Path
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathD2D)
   PathD2D(ID2D1PathGeometry *aGeometry, bool aEndedActive,
-          const Point &aEndPoint, FillRule aFillRule)
+          const Point &aEndPoint, FillRule aFillRule, BackendType aBackendType)
     : mGeometry(aGeometry)
     , mEndedActive(aEndedActive)
     , mEndPoint(aEndPoint)
     , mFillRule(aFillRule)
+    , mBackendType(aBackendType)
   {}
   
-  virtual BackendType GetBackendType() const { return BackendType::DIRECT2D; }
+  virtual BackendType GetBackendType() const { return mBackendType; }
 
   virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
   virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
                                                              FillRule aFillRule = FillRule::FILL_WINDING) const;
 
   virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
 
   virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
@@ -98,14 +101,15 @@ public:
 private:
   friend class DrawTargetD2D;
   friend class DrawTargetD2D1;
 
   mutable RefPtr<ID2D1PathGeometry> mGeometry;
   bool mEndedActive;
   Point mEndPoint;
   FillRule mFillRule;
+  BackendType mBackendType;
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_PATHD2D_H_ */