tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PathSkia.h (3759B)


      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_PATH_SKIA_H_
      8 #define MOZILLA_GFX_PATH_SKIA_H_
      9 
     10 #include "2D.h"
     11 #include "skia/include/core/SkPath.h"
     12 
     13 namespace mozilla {
     14 namespace gfx {
     15 
     16 class PathSkia;
     17 
     18 class PathBuilderSkia : public PathBuilder {
     19 public:
     20  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderSkia, override)
     21 
     22  PathBuilderSkia(SkPath&& aPath, FillRule aFillRule,
     23                  const Point& aCurrentPoint, const Point& aBeginPoint);
     24  explicit PathBuilderSkia(FillRule aFillRule);
     25 
     26  void MoveTo(const Point& aPoint) override;
     27  void LineTo(const Point& aPoint) override;
     28  void BezierTo(const Point& aCP1, const Point& aCP2,
     29                const Point& aCP3) override;
     30  void QuadraticBezierTo(const Point& aCP1, const Point& aCP2) override;
     31  void Close() override;
     32  void Arc(const Point& aOrigin, float aRadius, float aStartAngle,
     33           float aEndAngle, bool aAntiClockwise = false) override;
     34  already_AddRefed<Path> Finish() override;
     35 
     36  void AppendPath(const SkPath& aPath);
     37 
     38  BackendType GetBackendType() const override { return BackendType::SKIA; }
     39 
     40  bool IsActive() const override { return mPath.countPoints() > 0; }
     41 
     42  static already_AddRefed<PathBuilder> Create(FillRule aFillRule);
     43 
     44 private:
     45  friend class PathSkia;
     46 
     47  void SetFillRule(FillRule aFillRule);
     48 
     49  SkPath mPath;
     50  FillRule mFillRule;
     51 };
     52 
     53 class PathSkia : public Path {
     54 public:
     55  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathSkia, override)
     56 
     57  PathSkia(SkPath& aPath, FillRule aFillRule, Point aCurrentPoint = Point(),
     58           Point aBeginPoint = Point())
     59      : mFillRule(aFillRule),
     60        mCurrentPoint(aCurrentPoint),
     61        mBeginPoint(aBeginPoint) {
     62    mPath.swap(aPath);
     63  }
     64 
     65  BackendType GetBackendType() const override { return BackendType::SKIA; }
     66 
     67  already_AddRefed<PathBuilder> CopyToBuilder(
     68      FillRule aFillRule) const override;
     69  already_AddRefed<PathBuilder> TransformedCopyToBuilder(
     70      const Matrix& aTransform, FillRule aFillRule) const override;
     71  already_AddRefed<PathBuilder> MoveToBuilder(FillRule aFillRule) override;
     72  already_AddRefed<PathBuilder> TransformedMoveToBuilder(
     73      const Matrix& aTransform, FillRule aFillRule) override;
     74 
     75  bool ContainsPoint(const Point& aPoint,
     76                     const Matrix& aTransform) const override;
     77 
     78  bool StrokeContainsPoint(const StrokeOptions& aStrokeOptions,
     79                           const Point& aPoint,
     80                           const Matrix& aTransform) const override;
     81 
     82  Rect GetBounds(const Matrix& aTransform = Matrix()) const override;
     83 
     84  Rect GetStrokedBounds(const StrokeOptions& aStrokeOptions,
     85                        const Matrix& aTransform = Matrix()) const override;
     86 
     87  Rect GetFastBounds(
     88      const Matrix& aTransform = Matrix(),
     89      const StrokeOptions* aStrokeOptions = nullptr) const override;
     90 
     91  void StreamToSink(PathSink* aSink) const override;
     92 
     93  FillRule GetFillRule() const override { return mFillRule; }
     94 
     95  const SkPath& GetPath() const { return mPath; }
     96 
     97  Maybe<Rect> AsRect() const override;
     98 
     99  bool GetFillPath(const StrokeOptions& aStrokeOptions,
    100                   const Matrix& aTransform, SkPath& aFillPath,
    101                   const Maybe<Rect>& aClipRect = Nothing()) const;
    102 
    103  bool IsEmpty() const override;
    104 
    105 private:
    106  friend class DrawTargetSkia;
    107 
    108  SkPath mPath;
    109  FillRule mFillRule;
    110  Point mCurrentPoint;
    111  Point mBeginPoint;
    112 };
    113 
    114 }  // namespace gfx
    115 }  // namespace mozilla
    116 
    117 #endif /* MOZILLA_GFX_PATH_SKIA_H_ */