• 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 <condition_variable>
25 #include "render_context/render_context.h"
26 #include "event_handler.h"
27 #include "pipeline/rs_paint_filter_canvas.h"
28 #include "screen_manager/screen_types.h"
29 #include "pipeline/round_corner_display/rs_round_corner_config.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 enum class ScreenRotation : uint32_t;
34 
35 // On the devices that LCD/AMOLED contain notch, at settings-->display-->notch
36 // we can set default or hide notch.
37 enum WindowNotchStatus {
38     // Notch default setting show the notch on the screen, and the
39     // single/time/battery status show at the same horizontal.
40     WINDOW_NOTCH_DEFAULT = 0,
41 
42     // Notch hidden setting fill the status bar with black, so
43     // single/time/battery status show on the backgound of black.
44     WINDOW_NOTCH_HIDDEN
45 };
46 
47 enum ShowTopResourceType {
48     // choose type and then choose resource for harden or RS
49     TOP_PORTRAIT = 0,
50     TOP_LADS_ORIT,
51     TOP_HIDDEN
52 };
53 
54 enum RoundCornerSurfaceType {
55     // choose type and then choose resource for harden or RS
56     TOP_SURFACE = 0,
57     BOTTOM_SURFACE
58 };
59 
60 class RoundCornerDisplay {
61 public:
62     RoundCornerDisplay();
63     virtual ~RoundCornerDisplay();
64 
65     // update displayWidth_ and displayHeight_
66     void UpdateDisplayParameter(uint32_t width, uint32_t height);
67 
68     // update notchStatus_
69     void UpdateNotchStatus(int status);
70 
71     // update curOrientation_ and lastOrientation_
72     void UpdateOrientationStatus(ScreenRotation orientation);
73 
74     void DrawRoundCorner(RSPaintFilterCanvas* canvas);
75 
76     void DrawTopRoundCorner(RSPaintFilterCanvas* canvas);
77 
78     void DrawBottomRoundCorner(RSPaintFilterCanvas* canvas);
79 
IsSupportHardware()80     bool IsSupportHardware() const
81     {
82         return supportHardware_;
83     }
84 
RunHardwareTask(const std::function<void ()> & task)85     void RunHardwareTask(const std::function<void()>& task)
86     {
87         std::lock_guard<std::mutex> lock(resourceMut_);
88         if (!supportHardware_) {
89             return;
90         }
91         UpdateParameter(updateFlag_);
92         task(); // do task
93     }
94 
GetHardwareInfo()95     rs_rcd::RoundCornerHardware GetHardwareInfo() const
96     {
97         return hardInfo_;
98     }
99 
GetRcdEnable()100     bool GetRcdEnable() const
101     {
102         return isRcdEnable_;
103     }
104 
105 private:
106     // load config
107     rs_rcd::LCDModel* lcdModel_ = nullptr;
108     rs_rcd::ROGSetting* rog_ = nullptr;
109 
110     std::map<std::string, bool> updateFlag_ = {
111         // true of change
112         {"display", false},
113         {"notch", false},
114         {"orientation", false}
115     };
116 
117 #ifndef USE_ROSEN_DRAWING
118     // notch resources
119     sk_sp<SkImage> imgTopPortrait_ = nullptr;
120     sk_sp<SkImage> imgTopLadsOrit_ = nullptr;
121     sk_sp<SkImage> imgTopHidden_ = nullptr;
122     sk_sp<SkImage> imgBottomPortrait_ = nullptr;
123 
124     // notch resources for harden
125     SkBitmap bitmapTopPortrait_;
126     SkBitmap bitmapTopLadsOrit_;
127     SkBitmap bitmapTopHidden_;
128     SkBitmap bitmapBottomPortrait_;
129 #else
130     // notch resources
131     std::shared_ptr<Drawing::Image> imgTopPortrait_ = nullptr;
132     std::shared_ptr<Drawing::Image> imgTopLadsOrit_ = nullptr;
133     std::shared_ptr<Drawing::Image> imgTopHidden_ = nullptr;
134     std::shared_ptr<Drawing::Image> imgBottomPortrait_ = nullptr;
135 
136     // notch resources for harden
137     Drawing::Bitmap bitmapTopPortrait_;
138     Drawing::Bitmap bitmapTopLadsOrit_;
139     Drawing::Bitmap bitmapTopHidden_;
140     Drawing::Bitmap bitmapBottomPortrait_;
141 #endif
142     // display resolution
143     uint32_t displayWidth_ = 0;
144     uint32_t displayHeight_ = 0;
145 
146     // status of the notch
147     int notchStatus_ = WINDOW_NOTCH_DEFAULT;
148 
149     int showResourceType_ = (notchStatus_ == WINDOW_NOTCH_DEFAULT) ? TOP_PORTRAIT : TOP_HIDDEN;
150 
151     // status of the rotation
152     ScreenRotation curOrientation_ = ScreenRotation::ROTATION_0;
153     ScreenRotation lastOrientation_ = ScreenRotation::ROTATION_0;
154 
155     bool supportTopSurface_ = false;
156     bool supportBottomSurface_ = false;
157     bool supportHardware_ = false;
158     bool resourceChanged = false;
159 
160     bool isRcdEnable_ = false;
161 
162 #ifndef USE_ROSEN_DRAWING
163     // the resource to be drawn
164     sk_sp<SkImage> curTop_ = nullptr;
165     sk_sp<SkImage> curBottom_ = nullptr;
166 #else
167     // the resource to be drawn
168     std::shared_ptr<Drawing::Image> curTop_ = nullptr;
169     std::shared_ptr<Drawing::Image> curBottom_ = nullptr;
170 #endif
171 
172     std::mutex resourceMut_;
173 
174     rs_rcd::RoundCornerHardware hardInfo_;
175 
176     bool Init();
177 
178     static bool LoadConfigFile();
179 
180     // choose LCD mode
181     bool SeletedLcdModel(const char* lcdModelName);
182 
183 #ifndef USE_ROSEN_DRAWING
184     // load single image as skimage
185     static bool LoadImg(const char* path, sk_sp<SkImage>& img);
186 
187     static bool DecodeBitmap(sk_sp<SkImage> image, SkBitmap &bitmap);
188 #else
189     // load single image as Drawingimage
190     static bool LoadImg(const char* path, std::shared_ptr<Drawing::Image>& img);
191 
192     static bool DecodeBitmap(std::shared_ptr<Drawing::Image> drImage, Drawing::Bitmap &bitmap);
193 #endif
194     bool SetHardwareLayerSize();
195 
196     // load all images according to the resolution
197     bool LoadImgsbyResolution(uint32_t width, uint32_t height);
198 
199     bool GetTopSurfaceSource();
200 
201     bool GetBottomSurfaceSource();
202 
203     void DrawOneRoundCorner(RSPaintFilterCanvas* canvas, int surfaceType);
204 
205     // update resource
206     void UpdateParameter(std::map<std::string, bool> &updateFlag);
207 
208     // choose top rcd resource type
209     void RcdChooseTopResourceType();
210 
211     void RcdChooseRSResource();
212 
213     void RcdChooseHardwareResource();
214 };
215 } // namespace Rosen
216 } // namespace OHOS
217 #endif