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 #include "src/core/SkMaskFilterBase.h"
16 #include "skia_mask_filter.h"
17 #include "skia_helper.h"
18 #include "effect/mask_filter.h"
19 #include "utils/data.h"
20 #include "utils/log.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
SkiaMaskFilter()25 SkiaMaskFilter::SkiaMaskFilter() noexcept : filter_(nullptr) {}
26 
InitWithBlur(BlurType t,scalar sigma,bool respectCTM)27 void SkiaMaskFilter::InitWithBlur(BlurType t, scalar sigma, bool respectCTM)
28 {
29     filter_ = SkMaskFilter::MakeBlur(static_cast<SkBlurStyle>(t), sigma, respectCTM);
30 }
31 
GetMaskFilter() const32 sk_sp<SkMaskFilter> SkiaMaskFilter::GetMaskFilter() const
33 {
34     return filter_;
35 }
36 
SetSkMaskFilter(const sk_sp<SkMaskFilter> & filter)37 void SkiaMaskFilter::SetSkMaskFilter(const sk_sp<SkMaskFilter>& filter)
38 {
39     filter_ = filter;
40 }
41 
Serialize() const42 std::shared_ptr<Data> SkiaMaskFilter::Serialize() const
43 {
44     if (filter_ == nullptr) {
45         return nullptr;
46     }
47 
48     return SkiaHelper::FlattenableSerialize(filter_.get());
49 }
50 
Deserialize(std::shared_ptr<Data> data)51 bool SkiaMaskFilter::Deserialize(std::shared_ptr<Data> data)
52 {
53     if (data == nullptr) {
54         LOGD("SkiaMaskFilter::Deserialize, data is invalid!");
55         return false;
56     }
57 
58     filter_ = SkiaHelper::FlattenableDeserialize<SkMaskFilterBase>(data);
59     return true;
60 }
61 
62 } // namespace Drawing
63 } // namespace Rosen
64 } // namespace OHOS