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