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