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 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_RS_DISTORTION_SHADER_FILTER_H
16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_DISTORTION_SHADER_FILTER_H
17 
18 #include "effect/runtime_effect.h"
19 #include "effect/runtime_shader_builder.h"
20 #include "render/rs_skia_filter.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 class RSB_EXPORT RSDistortionFilter : public RSDrawingFilterOriginal {
25 public:
26     RSDistortionFilter(float distortionK);
27     RSDistortionFilter(const RSDistortionFilter&) = delete;
28     RSDistortionFilter operator=(const RSDistortionFilter&) = delete;
29     ~RSDistortionFilter() override;
30 
31     bool IsValid() const override;
32     std::string GetDescription() override;
33     void DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
34         const Drawing::Rect& src, const Drawing::Rect& dst) const override;
PreProcess(std::shared_ptr<Drawing::Image> image)35     void PreProcess(std::shared_ptr<Drawing::Image> image) override {};
PostProcess(Drawing::Canvas & canvas)36     void PostProcess(Drawing::Canvas& canvas) override {};
Compose(const std::shared_ptr<RSDrawingFilterOriginal> & other)37     std::shared_ptr<RSDrawingFilterOriginal> Compose(
38         const std::shared_ptr<RSDrawingFilterOriginal>& other) const override
39     {
40         return nullptr;
41     }
42 
43 private:
44     float distortionK_ = 0.0f;
45     float scaleCoord_ = 1.0f;
46     float offsetX_ = 0.0f;
47     float offsetY_ = 0.0f;
48 
49     static std::shared_ptr<Drawing::RuntimeShaderBuilder> MakeDistortionShader();
50     void DrawDistortion(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
51         const Drawing::Rect& src, const Drawing::Rect& dst) const;
52 
53     friend class RSMarshallingHelper;
54 };
55 } // namespace Rosen
56 } // namespace OHOS
57 
58 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_DISTORTION_SHADER_FILTER_H