File: path.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (168 lines) | stat: -rw-r--r-- 6,485 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
 *               2006 Rob Buis <buis@kde.org>
 * Copyright (C) 2007-2008 Torch Mobile, Inc.
 * Copyright (C) 2013 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_PATH_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_PATH_H_

#include "base/memory/raw_span.h"
#include "third_party/blink/renderer/platform/geometry/float_rounded_rect.h"
#include "third_party/blink/renderer/platform/geometry/path_types.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPathMeasure.h"
#include "ui/gfx/geometry/transform.h"

namespace gfx {
class PointF;
class QuadF;
class RectF;
}  // namespace gfx

namespace blink {

class AffineTransform;
class ContouredRect;
class StrokeData;

enum PathElementType {
  kPathElementMoveToPoint,          // The points member will contain 1 value.
  kPathElementAddLineToPoint,       // The points member will contain 1 value.
  kPathElementAddQuadCurveToPoint,  // The points member will contain 2 values.
  kPathElementAddCurveToPoint,      // The points member will contain 3 values.
  kPathElementCloseSubpath          // The points member will contain no values.
};

// The points in the structure are the same as those that would be used with the
// add... method. For example, a line returns the endpoint, while a cubic
// returns two tangent points and the endpoint.
struct PathElement {
  PathElementType type;
  base::raw_span<gfx::PointF> points;
};

// Result structure from Path::PointAndNormalAtLength() (and similar).
struct PointAndTangent {
  gfx::PointF point;
  float tangent_in_degrees = 0;
};

typedef void (*PathApplierFunction)(void* info, const PathElement&);

class PLATFORM_EXPORT Path {
  USING_FAST_MALLOC(Path);

 public:
  Path();
  ~Path();

  Path(const Path&);
  Path(const SkPath&);
  Path& operator=(const Path&);
  Path& operator=(const SkPath&);
  bool operator==(const Path&) const;
  bool operator!=(const Path& other) const { return !(*this == other); }

  bool Contains(const gfx::PointF&) const;
  bool Contains(const gfx::PointF&, WindRule) const;

  bool Intersects(const gfx::QuadF&) const;
  bool Intersects(const gfx::QuadF&, WindRule) const;

  // Determine if the path's stroke contains the point.  The transform is used
  // only to determine the precision factor when analyzing the stroke, so that
  // we return accurate results in high-zoom scenarios.
  bool StrokeContains(const gfx::PointF&,
                      const StrokeData&,
                      const AffineTransform&) const;
  SkPath StrokePath(const StrokeData&, const AffineTransform&) const;

  // Tight Bounding calculation is very expensive, but it guarantees the strict
  // bounding box. It's always included in BoundingRect. For a logical bounding
  // box (used for clipping or damage) BoundingRect is recommended.
  gfx::RectF TightBoundingRect() const;
  gfx::RectF BoundingRect() const;
  gfx::RectF StrokeBoundingRect(const StrokeData&) const;

  float length() const;
  gfx::PointF PointAtLength(float length) const;
  PointAndTangent PointAndNormalAtLength(float length) const;

  // Helper for computing a sequence of positions and normals (normal angles) on
  // a path. The best possible access pattern will be one where the |length|
  // value is strictly increasing. For other access patterns, performance will
  // vary depending on curvature and number of segments, but should never be
  // worse than that of the state-less method on Path.
  class PLATFORM_EXPORT PositionCalculator {
    USING_FAST_MALLOC(PositionCalculator);

   public:
    explicit PositionCalculator(const Path&);
    PositionCalculator(const PositionCalculator&) = delete;
    PositionCalculator& operator=(const PositionCalculator&) = delete;

    PointAndTangent PointAndNormalAtLength(float length);

   private:
    SkPath path_;
    SkPathMeasure path_measure_;
    SkScalar accumulated_length_;
  };

  bool IsEmpty() const;
  bool IsClosed() const;
  bool IsLine() const;

  const SkPath& GetSkPath() const { return path_; }

  void Apply(void* info, PathApplierFunction) const;

  // Utility factories for simple shapes.
  static Path MakeRect(const gfx::RectF&);
  // Use this form if the rect is defined by locations of a pair of opposite
  // corners, where |origin| may not be the top-left corner.
  static Path MakeRect(const gfx::PointF& origin,
                       const gfx::PointF& opposite_point);
  static Path MakeRoundedRect(const FloatRoundedRect&);
  static Path MakeContouredRect(const ContouredRect&);
  static Path MakeEllipse(const gfx::PointF& center,
                          float radius_x,
                          float radius_y);

 private:
  SkPath StrokePath(const StrokeData&, float stroke_precision) const;

  SkPath path_;
};

// Only used for DCHECKs
PLATFORM_EXPORT bool EllipseIsRenderable(float start_angle, float end_angle);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_PATH_H_