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 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_RS_GRADIENT_BLUR_PARA_H 16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_GRADIENT_BLUR_PARA_H 17 18 #include <array> 19 #include "common/rs_macros.h" 20 #include "platform/common/rs_system_properties.h" 21 #include "render/rs_filter.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 26 enum class GradientDirection { 27 LEFT = 0, 28 TOP, 29 RIGHT, 30 BOTTOM, 31 LEFT_TOP, 32 LEFT_BOTTOM, 33 RIGHT_TOP, 34 RIGHT_BOTTOM, 35 NONE, 36 START_TO_END, 37 END_TO_START, 38 }; 39 40 class RSB_EXPORT RSLinearGradientBlurPara { 41 public: 42 float blurRadius_; 43 // Each pair in fractionStops_ represents <blur degree, position scale> 44 std::vector<std::pair<float, float>> fractionStops_; 45 GradientDirection direction_; 46 std::shared_ptr<RSFilter> LinearGradientBlurFilter_; 47 bool useMaskAlgorithm_ = true; 48 float originalBase_ = 1000.0f; // 1000.0f represents original radius_base RSLinearGradientBlurPara(const float blurRadius,const std::vector<std::pair<float,float>> fractionStops,const GradientDirection direction)49 explicit RSLinearGradientBlurPara(const float blurRadius, 50 const std::vector<std::pair<float, float>>fractionStops, const GradientDirection direction) 51 { 52 if (blurRadius > originalBase_) { 53 useMaskAlgorithm_ = false; 54 } else { 55 useMaskAlgorithm_ = true; 56 } 57 blurRadius_ = blurRadius; 58 fractionStops_ = fractionStops; 59 direction_ = direction; 60 if (RSSystemProperties::GetMaskLinearBlurEnabled() && useMaskAlgorithm_) { 61 LinearGradientBlurFilter_ = RSFilter::CreateBlurFilter(blurRadius_ / 2, blurRadius_ / 2); 62 } 63 } 64 ~RSLinearGradientBlurPara() = default; 65 Dump(std::string & out)66 void Dump(std::string& out) const 67 { 68 out += "[blurRadius:" + std::to_string(blurRadius_); 69 out += " direction:" + std::to_string(static_cast<int>(direction_)) + " fractionStops["; 70 for (auto& val : fractionStops_) { 71 out += "[blurDegree:" + std::to_string(val.first) + " positionScale:" + std::to_string(val.second) + "] "; 72 } 73 if (fractionStops_.size() > 0) { 74 out.pop_back(); 75 } 76 out += "]]"; 77 } 78 }; 79 } // namespace Rosen 80 } // namespace OHOS 81 82 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_GRADIENT_BLUR_PARA_H