• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef RENDER_SERVICE_CORE_PIPELINE_RCD_RENDER_RS_RCD_DISPLAY_H
17 #define RENDER_SERVICE_CORE_PIPELINE_RCD_RENDER_RS_RCD_DISPLAY_H
18 
19 #pragma once
20 #include <string>
21 #include <map>
22 #include <thread>
23 #include <mutex>
24 #include <shared_mutex>
25 #include <condition_variable>
26 #include "render_context/render_context.h"
27 #include "event_handler.h"
28 #include "pipeline/rs_paint_filter_canvas.h"
29 #include "screen_manager/screen_types.h"
30 #include "feature/round_corner_display/rs_round_corner_config.h"
31 
32 namespace OHOS {
33 namespace Rosen {
34 enum class ScreenRotation : uint32_t;
35 
36 // On the devices that LCD/AMOLED contain notch, at settings-->display-->notch
37 // we can set default or hide notch.
38 enum WindowNotchStatus {
39     // Notch default setting show the notch on the screen, and the
40     // single/time/battery status show at the same horizontal.
41     WINDOW_NOTCH_DEFAULT = 0,
42 
43     // Notch hidden setting fill the status bar with black, so
44     // single/time/battery status show on the backgound of black.
45     WINDOW_NOTCH_HIDDEN
46 };
47 
48 enum ShowTopResourceType {
49     // choose type and then choose resource for harden or RS
50     TOP_PORTRAIT = 0,
51     TOP_LADS_ORIT,
52     TOP_HIDDEN
53 };
54 
55 enum RoundCornerSurfaceType {
56     // choose type and then choose resource for harden or RS
57     TOP_SURFACE = 0,
58     BOTTOM_SURFACE
59 };
60 
61 enum class RoundCornerDirtyType : uint8_t {
62     // Use bit operation to judge dirty type
63     RCD_DIRTY_NONE = 0x00,
64     RCD_DIRTY_TOP = 0x01,
65     RCD_DIRTY_BOTTOM = 0x02,
66     RCD_DIRTY_ALL = 0x03
67 };
68 
69 using RectU = RectT<uint32_t>;
70 
71 class RoundCornerDisplay {
72 public:
RoundCornerDisplay()73     RoundCornerDisplay() {};
74     explicit RoundCornerDisplay(NodeId id);
75     virtual ~RoundCornerDisplay();
76 
77     // update Render Rect
78     void UpdateDisplayParameter(uint32_t left, uint32_t top, uint32_t width, uint32_t height);
79 
80     // update notchStatus_
81     void UpdateNotchStatus(int status);
82 
83     // update curOrientation_ and lastOrientation_
84     void UpdateOrientationStatus(ScreenRotation orientation);
85 
86     // update rcd status and create resource
87     void RefreshFlagAndUpdateResource();
88 
89     // update hardInfo_.resourceChanged after hw resource applied
90     void UpdateHardwareResourcePrepared(bool prepared);
91 
92     void DrawTopRoundCorner(RSPaintFilterCanvas* canvas);
93 
94     void DrawBottomRoundCorner(RSPaintFilterCanvas* canvas);
95 
96     bool HandleTopRcdDirty(RectI& dirtyRect);
97 
98     bool HandleBottomRcdDirty(RectI& dirtyRect);
99 
IsSupportHardware()100     bool IsSupportHardware() const
101     {
102         return supportHardware_;
103     }
104 
RunHardwareTask(const std::function<void ()> & task)105     void RunHardwareTask(const std::function<void()>& task)
106     {
107         if (!supportHardware_) {
108             return;
109         }
110         UpdateParameter(updateFlag_);
111         task(); // do task
112     }
113 
GetHardwareInfo()114     rs_rcd::RoundCornerHardware GetHardwareInfo()
115     {
116         std::shared_lock<std::shared_mutex> lock(resourceMut_);
117         return hardInfo_;
118     }
119 
PrepareHardwareInfo()120     rs_rcd::RoundCornerHardware PrepareHardwareInfo()
121     {
122         std::unique_lock<std::shared_mutex> lock(resourceMut_);
123         if (hardInfo_.resourceChanged) {
124             hardInfo_.resourcePreparing = true;
125         }
126         return hardInfo_;
127     }
128 
IsNotchNeedUpdate(bool notchStatus)129     bool IsNotchNeedUpdate(bool notchStatus)
130     {
131         std::shared_lock<std::shared_mutex> lock(resourceMut_);
132         bool result = notchStatus != lastNotchStatus_;
133         lastNotchStatus_ = notchStatus;
134         return result;
135     }
136 
137     void InitOnce();
138 
139 private:
140     NodeId renderTargetId_ = 0;
141     bool isInit = false;
142     // load config
143     rs_rcd::LCDModel* lcdModel_ = nullptr;
144     rs_rcd::ROGSetting* rog_ = nullptr;
145 
146     std::map<std::string, bool> updateFlag_ = {
147         // true of change
148         {"display", false},
149         {"notch", false},
150         {"orientation", false}
151     };
152 
153     // notch resources
154     std::shared_ptr<Drawing::Image> imgTopPortrait_ = nullptr;
155     std::shared_ptr<Drawing::Image> imgTopLadsOrit_ = nullptr;
156     std::shared_ptr<Drawing::Image> imgTopHidden_ = nullptr;
157     std::shared_ptr<Drawing::Image> imgBottomPortrait_ = nullptr;
158 
159     // notch resources for harden
160     std::shared_ptr<Drawing::Bitmap> bitmapTopPortrait_ = nullptr;
161     std::shared_ptr<Drawing::Bitmap> bitmapTopLadsOrit_ = nullptr;
162     std::shared_ptr<Drawing::Bitmap> bitmapTopHidden_ = nullptr;
163     std::shared_ptr<Drawing::Bitmap> bitmapBottomPortrait_ = nullptr;
164 
165     // current display resolution
166     RectU displayRect_;
167 
168     // last time rcv display resolution and notchState
169     RectU lastRcvDisplayRect_;
170 
171     // status of the notch
172     int notchStatus_ = WINDOW_NOTCH_DEFAULT;
173 
174     // type of rcd dirty region
175     RoundCornerDirtyType rcdDirtyType_ = RoundCornerDirtyType::RCD_DIRTY_NONE;
176 
177     int showResourceType_ = (notchStatus_ == WINDOW_NOTCH_DEFAULT) ? TOP_PORTRAIT : TOP_HIDDEN;
178     bool lastNotchStatus_ = false;
179 
180     // status of the rotation
181     ScreenRotation curOrientation_ = ScreenRotation::ROTATION_0;
182     ScreenRotation lastOrientation_ = ScreenRotation::ROTATION_0;
183 
184     bool supportTopSurface_ = false;
185     bool supportBottomSurface_ = false;
186     bool supportHardware_ = false;
187     bool resourceChanged = false;
188 
189     // the resource to be drawn
190     std::shared_ptr<Drawing::Image> curTop_ = nullptr;
191     std::shared_ptr<Drawing::Image> curBottom_ = nullptr;
192 
193     std::shared_mutex resourceMut_;
194 
195     rs_rcd::RoundCornerHardware hardInfo_;
196 
197     bool Init();
198 
199     static bool LoadConfigFile();
200 
201     // choose LCD mode
202     bool SeletedLcdModel(const char* lcdModelName);
203 
204     // load single image as Drawingimage
205     static bool LoadImg(const char* path, std::shared_ptr<Drawing::Image>& img);
206 
207     static bool DecodeBitmap(std::shared_ptr<Drawing::Image> image, std::shared_ptr<Drawing::Bitmap>& bitmap);
208     bool SetHardwareLayerSize();
209 
210     // load all images according to the resolution
211     bool LoadImgsbyResolution(uint32_t width, uint32_t height);
212 
213     bool GetTopSurfaceSource();
214 
215     bool GetBottomSurfaceSource();
216 
217     void DrawOneRoundCorner(RSPaintFilterCanvas* canvas, int surfaceType);
218 
219     // update resource
220     void UpdateParameter(std::map<std::string, bool> &updateFlag);
221 
222     // choose top rcd resource type
223     void RcdChooseTopResourceType();
224 
225     void RcdChooseRSResource();
226 
227     void RcdChooseHardwareResource();
228 
229     void PrintRCDInfo();
230 
231     // Check if the input resolution changes
232     bool CheckResolutionChanged(uint32_t width, uint32_t height);
233 };
234 } // namespace Rosen
235 } // namespace OHOS
236 #endif