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