1 /*
2  * Copyright (c) 2024 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 #ifndef BLUR_DRAW_LOOPER_H
17 #define BLUR_DRAW_LOOPER_H
18 
19 #include <memory>
20 
21 #include "common/rs_macros.h"
22 #include "draw/color.h"
23 #include "effect/mask_filter.h"
24 #include "utils/drawing_macros.h"
25 #include "utils/scalar.h"
26 #include "utils/data.h"
27 #include "utils/point.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 
33 class DRAWING_API BlurDrawLooper {
34 public:
35     /**
36      * @brief Create a blur drawLooper, it will generate two draw operations, which may affect performance.
37      * @param radius blur radius.
38      * @param dx x offset.
39      * @param dy y offset.
40      * @param color offset drawlooper's color.
41      * @return A shared pointer to BlurDrawLooper
42      */
43     static std::shared_ptr<BlurDrawLooper> CreateBlurDrawLooper(float blurRadius,
44         scalar dx, scalar dy, const Color& color);
45 
46     BlurDrawLooper(float blurRadius, scalar dx, scalar dy, const Color& color) noexcept;
47 
GetRadius()48     float GetRadius() const { return blurDrawLooperPriv_.blurRadius; }
GetXOffset()49     scalar GetXOffset() const { return blurDrawLooperPriv_.dx; }
GetYOffset()50     scalar GetYOffset() const { return blurDrawLooperPriv_.dy; }
GetColor()51     const Color& GetColor() const { return blurDrawLooperPriv_.color; }
GetMaskFilter()52     const std::shared_ptr<MaskFilter>& GetMaskFilter() const { return blurMaskFilter_; }
53 
54     ~BlurDrawLooper() = default;
55 
56     friend bool operator==(const BlurDrawLooper& lhs, const BlurDrawLooper& rhs);
57     friend bool operator!=(const BlurDrawLooper& lhs, const BlurDrawLooper& rhs);
58 
59     std::shared_ptr<Data> Serialize() const;
60     static std::shared_ptr<BlurDrawLooper> Deserialize(std::shared_ptr<Data> data);
61 
62 private:
63     struct BlurDrawLooperPriv {
64         scalar blurRadius = 0.f;
65         scalar dx = 0.f;
66         scalar dy = 0.f;
67         Color color = Color::COLOR_BLACK;
68     };
69     BlurDrawLooperPriv blurDrawLooperPriv_;
70     std::shared_ptr<MaskFilter> blurMaskFilter_ = nullptr;
71 };
72 } // namespace Drawing
73 } // namespace Rosen
74 } // namespace OHOS
75 #endif