• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 IMAGE_FILTER_LAZY_H
17 #define IMAGE_FILTER_LAZY_H
18 
19 #include "effect/image_filter.h"
20 #include "effect/image_filter_obj.h"
21 #include "utils/drawing_macros.h"
22 #include "utils/object.h"
23 #include "utils/rect.h"
24 #include "utils/scalar.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 
30 // Only supports the Drawing NDK interface.
31 class DRAWING_API ImageFilterLazy : public ImageFilter {
32 public:
33     static std::shared_ptr<ImageFilterLazy> CreateBlur(scalar sigmaX, scalar sigmaY,
34         TileMode tileMode, const std::shared_ptr<ImageFilter>& input = nullptr,
35         ImageBlurType blurType = ImageBlurType::GAUSS, const Rect& cropRect = noCropRect);
36     static std::shared_ptr<ImageFilterLazy> CreateColorFilter(const std::shared_ptr<ColorFilter>& colorFilter,
37         const std::shared_ptr<ImageFilter>& input = nullptr, const Rect& cropRect = noCropRect);
38     static std::shared_ptr<ImageFilterLazy> CreateOffset(scalar dx, scalar dy,
39         const std::shared_ptr<ImageFilter>& input = nullptr, const Rect& cropRect = noCropRect);
40     static std::shared_ptr<ImageFilterLazy> CreateShader(const std::shared_ptr<ShaderEffect>& shader,
41         const Rect& cropRect = noCropRect);
42     static std::shared_ptr<ImageFilterLazy> CreateFromImageFilterObj(std::shared_ptr<ImageFilterObj> object);
43 
44     ~ImageFilterLazy() override = default;
45 
IsLazy()46     bool IsLazy() const override { return true; }
47 
GetImageFilterObj()48     std::shared_ptr<ImageFilterObj> GetImageFilterObj() const { return imageFilterObj_; }
49     std::shared_ptr<ImageFilter> Materialize();
50 
51     // WARNING: Do not call Serialize()/Deserialize() on Lazy objects!
52     // Use Object Marshalling()/Unmarshalling() instead.
53     // These methods will return nullptr/false and log errors.
54     std::shared_ptr<Data> Serialize() const override;
55     bool Deserialize(std::shared_ptr<Data> data) override;
56 
57 #ifdef ROSEN_OHOS
58     bool Marshalling(Parcel& parcel) override;
59     static std::shared_ptr<ImageFilterLazy> Unmarshalling(Parcel& parcel, bool& isValid, int32_t depth = 0);
60 #endif
61 
62 private:
ImageFilterLazy()63     ImageFilterLazy() noexcept : ImageFilter(FilterType::LAZY_IMAGE_FILTER) {}
64     ImageFilterLazy(std::shared_ptr<ImageFilterObj> imageFilterObj) noexcept;
65 
66     std::shared_ptr<ImageFilterObj> imageFilterObj_ = nullptr;
67     std::shared_ptr<ImageFilter> imageFilterCache_ = nullptr; // not lazy
68 };
69 
70 } // namespace Drawing
71 } // namespace Rosen
72 } // namespace OHOS
73 
74 #endif // IMAGE_FILTER_LAZY_H