1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "skia_path_effect.h"
17
18 #include <memory>
19
20 #include "include/core/SkPathEffect.h"
21 #include "include/effects/Sk1DPathEffect.h"
22 #include "include/effects/SkCornerPathEffect.h"
23 #include "include/effects/SkDashPathEffect.h"
24 #include "skia_path.h"
25
26 #include "effect/path_effect.h"
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace Drawing {
SkiaPathEffect()31 SkiaPathEffect::SkiaPathEffect() noexcept : pathEffect_(nullptr) {}
32
InitWithDash(const scalar intervals[],int count,scalar phase)33 void SkiaPathEffect::InitWithDash(const scalar intervals[], int count, scalar phase)
34 {
35 pathEffect_ = SkDashPathEffect::Make(intervals, count, phase);
36 }
37
InitWithPathDash(const Path & path,scalar advance,scalar phase,PathDashStyle style)38 void SkiaPathEffect::InitWithPathDash(const Path& path, scalar advance, scalar phase, PathDashStyle style)
39 {
40 auto p = path.GetImpl<SkiaPath>();
41 if (p != nullptr) {
42 pathEffect_ =
43 SkPath1DPathEffect::Make(p->GetPath(), advance, phase, static_cast<SkPath1DPathEffect::Style>(style));
44 }
45 }
46
InitWithCorner(scalar radius)47 void SkiaPathEffect::InitWithCorner(scalar radius)
48 {
49 pathEffect_ = SkCornerPathEffect::Make(radius);
50 }
51
InitWithSum(const PathEffect & e1,const PathEffect & e2)52 void SkiaPathEffect::InitWithSum(const PathEffect& e1, const PathEffect& e2)
53 {
54 auto first = e1.GetImpl<SkiaPathEffect>();
55 auto second = e2.GetImpl<SkiaPathEffect>();
56 if (first != nullptr && second != nullptr) {
57 pathEffect_ = SkPathEffect::MakeSum(first->GetPathEffect(), second->GetPathEffect());
58 }
59 }
60
InitWithCompose(const PathEffect & e1,const PathEffect & e2)61 void SkiaPathEffect::InitWithCompose(const PathEffect& e1, const PathEffect& e2)
62 {
63 auto outer = e1.GetImpl<SkiaPathEffect>();
64 auto inner = e2.GetImpl<SkiaPathEffect>();
65 if (outer != nullptr && inner != nullptr) {
66 pathEffect_ = SkPathEffect::MakeCompose(outer->GetPathEffect(), inner->GetPathEffect());
67 }
68 }
69
GetPathEffect() const70 sk_sp<SkPathEffect> SkiaPathEffect::GetPathEffect() const
71 {
72 return pathEffect_;
73 }
74
SetSkPathEffect(const sk_sp<SkPathEffect> & pathEffect)75 void SkiaPathEffect::SetSkPathEffect(const sk_sp<SkPathEffect>& pathEffect)
76 {
77 pathEffect_ = pathEffect;
78 }
79 } // namespace Drawing
80 } // namespace Rosen
81 } // namespace OHOS
82