• 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 "pipeline/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 class RoundCornerDisplay {
62 public:
63     RoundCornerDisplay();
64     virtual ~RoundCornerDisplay();
65 
66     // update displayWidth_ and displayHeight_
67     void UpdateDisplayParameter(uint32_t width, uint32_t height);
68 
69     // update notchStatus_
70     void UpdateNotchStatus(int status);
71 
72     // update curOrientation_ and lastOrientation_
73     void UpdateOrientationStatus(ScreenRotation orientation);
74 
75     // update hardInfo_.resourceChanged after hw resource applied
76     void UpdateHardwareResourcePrepared(bool prepared);
77 
78     void DrawRoundCorner(RSPaintFilterCanvas *canvas);
79 
80     void DrawTopRoundCorner(RSPaintFilterCanvas* canvas);
81 
82     void DrawBottomRoundCorner(RSPaintFilterCanvas* canvas);
83 
IsSupportHardware()84     bool IsSupportHardware() const
85     {
86         return supportHardware_;
87     }
88 
RunHardwareTask(const std::function<void ()> & task)89     void RunHardwareTask(const std::function<void()>& task)
90     {
91         if (!supportHardware_) {
92             return;
93         }
94         UpdateParameter(updateFlag_);
95         task(); // do task
96     }
97 
GetHardwareInfo()98     rs_rcd::RoundCornerHardware GetHardwareInfo()
99     {
100         std::shared_lock<std::shared_mutex> lock(resourceMut_);
101         return hardInfo_;
102     }
103 
GetHardwareInfoPreparing()104     rs_rcd::RoundCornerHardware GetHardwareInfoPreparing()
105     {
106         std::unique_lock<std::shared_mutex> lock(resourceMut_);
107         if (hardInfo_.resourceChanged)
108             hardInfo_.resourcePreparing = true;
109         return hardInfo_;
110     }
111 
GetRcdEnable()112     bool GetRcdEnable() const
113     {
114         return isRcdEnable_;
115     }
116 
IsNotchNeedUpdate(bool notchStatus)117     bool IsNotchNeedUpdate(bool notchStatus)
118     {
119         std::shared_lock<std::shared_mutex> lock(resourceMut_);
120         bool result = notchStatus != lastNotchStatus_;
121         lastNotchStatus_ = notchStatus;
122         return result;
123     }
124 
125 private:
126     // load config
127     rs_rcd::LCDModel* lcdModel_ = nullptr;
128     rs_rcd::ROGSetting* rog_ = nullptr;
129 
130     std::map<std::string, bool> updateFlag_ = {
131         // true of change
132         {"display", false},
133         {"notch", false},
134         {"orientation", false}
135     };
136 
137     // notch resources
138     std::shared_ptr<Drawing::Image> imgTopPortrait_ = nullptr;
139     std::shared_ptr<Drawing::Image> imgTopLadsOrit_ = nullptr;
140     std::shared_ptr<Drawing::Image> imgTopHidden_ = nullptr;
141     std::shared_ptr<Drawing::Image> imgBottomPortrait_ = nullptr;
142 
143     // notch resources for harden
144     Drawing::Bitmap bitmapTopPortrait_;
145     Drawing::Bitmap bitmapTopLadsOrit_;
146     Drawing::Bitmap bitmapTopHidden_;
147     Drawing::Bitmap bitmapBottomPortrait_;
148     // display resolution
149     uint32_t displayWidth_ = 0;
150     uint32_t displayHeight_ = 0;
151 
152     // status of the notch
153     int notchStatus_ = WINDOW_NOTCH_DEFAULT;
154 
155     int showResourceType_ = (notchStatus_ == WINDOW_NOTCH_DEFAULT) ? TOP_PORTRAIT : TOP_HIDDEN;
156     bool lastNotchStatus_ = false;
157 
158     // status of the rotation
159     ScreenRotation curOrientation_ = ScreenRotation::ROTATION_0;
160     ScreenRotation lastOrientation_ = ScreenRotation::ROTATION_0;
161 
162     bool supportTopSurface_ = false;
163     bool supportBottomSurface_ = false;
164     bool supportHardware_ = false;
165     bool resourceChanged = false;
166 
167     bool isRcdEnable_ = false;
168 
169     // the resource to be drawn
170     std::shared_ptr<Drawing::Image> curTop_ = nullptr;
171     std::shared_ptr<Drawing::Image> curBottom_ = nullptr;
172 
173     std::shared_mutex resourceMut_;
174 
175     rs_rcd::RoundCornerHardware hardInfo_;
176 
177     bool Init();
178 
179     static bool LoadConfigFile();
180 
181     // choose LCD mode
182     bool SeletedLcdModel(const char* lcdModelName);
183 
184     // load single image as Drawingimage
185     static bool LoadImg(const char* path, std::shared_ptr<Drawing::Image>& img);
186     static bool DecodeBitmap(std::shared_ptr<Drawing::Image> image, Drawing::Bitmap &bitmap);
187     bool SetHardwareLayerSize();
188 
189     // load all images according to the resolution
190     bool LoadImgsbyResolution(uint32_t width, uint32_t height);
191 
192     bool GetTopSurfaceSource();
193 
194     bool GetBottomSurfaceSource();
195 
196     void DrawOneRoundCorner(RSPaintFilterCanvas* canvas, int surfaceType);
197 
198     // update resource
199     void UpdateParameter(std::map<std::string, bool> &updateFlag);
200 
201     // choose top rcd resource type
202     void RcdChooseTopResourceType();
203 
204     void RcdChooseRSResource();
205 
206     void RcdChooseHardwareResource();
207 };
208 } // namespace Rosen
209 } // namespace OHOS
210 #endif