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