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 GRAPHICS_EFFECT_GE_MAGNIFIER_SHADER_FILTER_H 16 #define GRAPHICS_EFFECT_GE_MAGNIFIER_SHADER_FILTER_H 17 18 #include <cstdint> 19 20 #include "ge_shader_filter.h" 21 #include "ge_visual_effect.h" 22 23 #include "draw/canvas.h" 24 #include "effect/runtime_effect.h" 25 #include "effect/runtime_shader_builder.h" 26 #include "image/image.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 31 class GEMagnifierParams { 32 public: GEMagnifierParams()33 explicit GEMagnifierParams() {} 34 ~GEMagnifierParams() = default; 35 36 float factor_ = 0.f; 37 float width_ = 0.f; 38 float height_ = 0.f; 39 float cornerRadius_ = 0.f; 40 float borderWidth_ = 0.f; 41 42 float shadowOffsetX_ = 0.f; 43 float shadowOffsetY_ = 0.f; 44 float shadowSize_ = 0.f; 45 float shadowStrength_ = 0.f; 46 47 // rgba 48 uint32_t gradientMaskColor1_ = 0x00000000; 49 uint32_t gradientMaskColor2_ = 0x00000000; 50 uint32_t outerContourColor1_ = 0x00000000; 51 uint32_t outerContourColor2_ = 0x00000000; 52 53 int32_t rotateDegree_ = 0; 54 }; 55 56 class GEMagnifierShaderFilter : public GEShaderFilter { 57 public: 58 GEMagnifierShaderFilter(const Drawing::GEMagnifierShaderFilterParams& params); 59 GEMagnifierShaderFilter(const GEMagnifierShaderFilter&) = delete; 60 GEMagnifierShaderFilter operator=(const GEMagnifierShaderFilter&) = delete; 61 ~GEMagnifierShaderFilter() override = default; 62 63 std::shared_ptr<Drawing::Image> ProcessImage(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image> image, 64 const Drawing::Rect& src, const Drawing::Rect& dst) override; 65 66 const std::string GetDescription() const; 67 68 private: 69 std::shared_ptr<Drawing::RuntimeShaderBuilder> MakeMagnifierShader( 70 std::shared_ptr<Drawing::ShaderEffect> imageShader, float imageWidth, float imageHeight); 71 bool InitMagnifierEffect(); 72 void ConvertToRgba(uint32_t rgba, float* color, int tupleSize); 73 74 std::shared_ptr<GEMagnifierParams> magnifierPara_ = nullptr; 75 static std::shared_ptr<Drawing::RuntimeEffect> g_magnifierShaderEffect; 76 }; 77 78 } // namespace Rosen 79 } // namespace OHOS 80 81 #endif // GRAPHICS_EFFECT_GE_MAGNIFIER_SHADER_FILTER_H 82