1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef MOZILLA_GFX_PATHD2D_H_
7 #define MOZILLA_GFX_PATHD2D_H_
8 
9 #include <d2d1.h>
10 
11 #include "2D.h"
12 
13 namespace mozilla {
14 namespace gfx {
15 
16 class PathD2D;
17 
18 class PathBuilderD2D : public PathBuilder
19 {
20 public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderD2D)21   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderD2D)
22   PathBuilderD2D(ID2D1GeometrySink *aSink, ID2D1PathGeometry *aGeom, FillRule aFillRule, BackendType aBackendType)
23     : mSink(aSink)
24     , mGeometry(aGeom)
25     , mFigureActive(false)
26     , mFillRule(aFillRule)
27     , mBackendType(aBackendType)
28   {
29   }
30   virtual ~PathBuilderD2D();
31 
32   virtual void MoveTo(const Point &aPoint);
33   virtual void LineTo(const Point &aPoint);
34   virtual void BezierTo(const Point &aCP1,
35                         const Point &aCP2,
36                         const Point &aCP3);
37   virtual void QuadraticBezierTo(const Point &aCP1,
38                                  const Point &aCP2);
39   virtual void Close();
40   virtual void Arc(const Point &aOrigin, Float aRadius, Float aStartAngle,
41                    Float aEndAngle, bool aAntiClockwise = false);
42   virtual Point CurrentPoint() const;
43 
44   virtual already_AddRefed<Path> Finish();
45 
GetBackendType()46   virtual BackendType GetBackendType() const { return mBackendType; }
47 
GetSink()48   ID2D1GeometrySink *GetSink() { return mSink; }
49 
IsFigureActive()50   bool IsFigureActive() const { return mFigureActive; }
51 
52 private:
53   friend class PathD2D;
54 
55   void EnsureActive(const Point &aPoint);
56 
57   RefPtr<ID2D1GeometrySink> mSink;
58   RefPtr<ID2D1PathGeometry> mGeometry;
59 
60   bool mFigureActive;
61   Point mCurrentPoint;
62   Point mBeginPoint;
63   FillRule mFillRule;
64   BackendType mBackendType;
65 };
66 
67 class PathD2D : public Path
68 {
69 public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathD2D)70   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathD2D)
71   PathD2D(ID2D1PathGeometry *aGeometry, bool aEndedActive,
72           const Point &aEndPoint, FillRule aFillRule, BackendType aBackendType)
73     : mGeometry(aGeometry)
74     , mEndedActive(aEndedActive)
75     , mEndPoint(aEndPoint)
76     , mFillRule(aFillRule)
77     , mBackendType(aBackendType)
78   {}
79 
GetBackendType()80   virtual BackendType GetBackendType() const { return mBackendType; }
81 
82   virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const;
83   virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
84                                                              FillRule aFillRule) const;
85 
86   virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
87 
88   virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
89                                    const Point &aPoint,
90                                    const Matrix &aTransform) const;
91 
92   virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
93 
94   virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
95                                 const Matrix &aTransform = Matrix()) const;
96 
97   virtual void StreamToSink(PathSink *aSink) const;
98 
GetFillRule()99   virtual FillRule GetFillRule() const { return mFillRule; }
100 
GetGeometry()101   ID2D1Geometry *GetGeometry() { return mGeometry; }
102 
103 private:
104   friend class DrawTargetD2D;
105   friend class DrawTargetD2D1;
106 
107   mutable RefPtr<ID2D1PathGeometry> mGeometry;
108   bool mEndedActive;
109   Point mEndPoint;
110   FillRule mFillRule;
111   BackendType mBackendType;
112 };
113 
114 }
115 }
116 
117 #endif /* MOZILLA_GFX_PATHD2D_H_ */
118