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 RS_SLR_SCALE_H 17 #define RS_SLR_SCALE_H 18 19 #include "params/rs_display_render_params.h" 20 #include "pipeline/rs_paint_filter_canvas.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 const float SLR_SCALE_THR_HIGH = 0.79f; 25 class RSSLRScaleFunction { 26 public: 27 RSSLRScaleFunction(float dstWidth, float dstHeight, float srcWidth, float srcHeight); 28 ~RSSLRScaleFunction() = default; 29 void CheckOrRefreshScreen( 30 float dstWidth, float dstHeight, float srcWidth, float srcHeight); 31 void CanvasScale(RSPaintFilterCanvas& canvas); 32 void ProcessCacheImage(RSPaintFilterCanvas& canvas, Drawing::Image& cacheImageProcessed); 33 void ProcessOffscreenImage(RSPaintFilterCanvas& canvas, Drawing::Image& offscreenImage); 34 GetIsSLRCopy()35 bool GetIsSLRCopy() const 36 { 37 return isSLRCopy_; 38 } 39 GetScaleNum()40 float GetScaleNum() const 41 { 42 return scaleNum_; 43 } 44 GetSaveCount()45 uint32_t GetSaveCount() const 46 { 47 return saveCount_; 48 } 49 GetScaleMatrix()50 Drawing::Matrix GetScaleMatrix() const 51 { 52 return scaleMatrix_; 53 } 54 GetKernelSize()55 int GetKernelSize() const 56 { 57 return kernelSize_; 58 } 59 private: 60 void RefreshScreenData(); 61 std::shared_ptr<Rosen::Drawing::Image> ProcessSLRImage(RSPaintFilterCanvas& canvas, 62 Drawing::Image& cacheImageProcessed); 63 std::shared_ptr<Drawing::RuntimeShaderBuilder> SLRImageShaderBuilder( 64 const Drawing::Image& image); 65 std::shared_ptr<Drawing::RuntimeShaderBuilder> LaplaceShaderBuilder(const Drawing::Image& image); 66 static std::shared_ptr<Drawing::RuntimeEffect> MakeSLRShaderEffect(); 67 static std::shared_ptr<Drawing::RuntimeEffect> MakeLaplaceShaderEffect(); 68 bool isSLRCopy_ = true; 69 float mirrorWidth_; 70 float mirrorHeight_; 71 float srcWidth_; 72 float srcHeight_; 73 float dstWidth_ = 1.0f; 74 float dstHeight_ = 1.0f; 75 float scaleNum_ = 1.0f; 76 float alpha_ = 0.15f; 77 uint32_t saveCount_ = 0; 78 int kernelSize_ = 2; 79 Drawing::Matrix scaleMatrix_; 80 81 std::shared_ptr<Drawing::ShaderEffect> widthEffect_; 82 std::shared_ptr<Drawing::ShaderEffect> heightEffect_; 83 84 static std::shared_ptr<Drawing::RuntimeEffect> slrFilterShader_; 85 static std::shared_ptr<Drawing::RuntimeEffect> laplaceFilterShader_; 86 static std::shared_ptr<Drawing::RuntimeShaderBuilder> slrShaderBuilder_; 87 static std::shared_ptr<Drawing::RuntimeShaderBuilder> laplaceShaderBuilder_; 88 }; 89 } 90 } 91 #endif // RS_SLR_SCALE_H