• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkCornerPathEffect_DEFINED
9 #define SkCornerPathEffect_DEFINED
10 
11 #include "include/core/SkFlattenable.h"
12 #include "include/core/SkPathEffect.h"
13 
14 /** \class SkCornerPathEffect
15 
16     SkCornerPathEffect is a subclass of SkPathEffect that can turn sharp corners
17     into various treatments (e.g. rounded corners)
18 */
19 class SK_API SkCornerPathEffect : public SkPathEffect {
20 public:
21     /** radius must be > 0 to have an effect. It specifies the distance from each corner
22         that should be "rounded".
23     */
Make(SkScalar radius)24     static sk_sp<SkPathEffect> Make(SkScalar radius) {
25         return radius > 0 ? sk_sp<SkPathEffect>(new SkCornerPathEffect(radius)) : nullptr;
26     }
27 
28 protected:
29     ~SkCornerPathEffect() override;
30 
31     explicit SkCornerPathEffect(SkScalar radius);
32     void flatten(SkWriteBuffer&) const override;
33     bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
34 
35 private:
SK_FLATTENABLE_HOOKS(SkCornerPathEffect)36     SK_FLATTENABLE_HOOKS(SkCornerPathEffect)
37 
38     bool computeFastBounds(SkRect*) const override {
39         // Rounding sharp corners within a path produces a new path that is still contained within
40         // the original's bounds, so leave 'bounds' unmodified.
41         return true;
42     }
43 
44     SkScalar    fRadius;
45 
46     using INHERITED = SkPathEffect;
47 };
48 
49 #endif
50