1 /*
2  * Copyright (c) 2021-2022 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 #include "rs_screen.h"
17 
18 #include <algorithm>
19 #include <cinttypes>
20 
21 #include "platform/common/rs_log.h"
22 #include "rs_trace.h"
23 #include "string_utils.h"
24 #include "hisysevent.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 using namespace HiviewDFX;
29 
30 namespace impl {
31 std::map<GraphicColorGamut, GraphicCM_ColorSpaceType> RSScreen::RS_TO_COMMON_COLOR_SPACE_TYPE_MAP {
32     {GRAPHIC_COLOR_GAMUT_STANDARD_BT601, GRAPHIC_CM_BT601_EBU_FULL},
33     {GRAPHIC_COLOR_GAMUT_STANDARD_BT709, GRAPHIC_CM_BT709_FULL},
34     {GRAPHIC_COLOR_GAMUT_SRGB, GRAPHIC_CM_SRGB_FULL},
35     {GRAPHIC_COLOR_GAMUT_ADOBE_RGB, GRAPHIC_CM_ADOBERGB_FULL},
36     {GRAPHIC_COLOR_GAMUT_DISPLAY_P3, GRAPHIC_CM_P3_FULL},
37     {GRAPHIC_COLOR_GAMUT_BT2020, GRAPHIC_CM_DISPLAY_BT2020_SRGB},
38     {GRAPHIC_COLOR_GAMUT_BT2100_PQ, GRAPHIC_CM_BT2020_PQ_FULL},
39     {GRAPHIC_COLOR_GAMUT_BT2100_HLG, GRAPHIC_CM_BT2020_HLG_FULL},
40     {GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020, GRAPHIC_CM_DISPLAY_BT2020_SRGB},
41 };
42 std::map<GraphicCM_ColorSpaceType, GraphicColorGamut> RSScreen::COMMON_COLOR_SPACE_TYPE_TO_RS_MAP {
43     {GRAPHIC_CM_BT601_EBU_FULL, GRAPHIC_COLOR_GAMUT_STANDARD_BT601},
44     {GRAPHIC_CM_BT709_FULL, GRAPHIC_COLOR_GAMUT_STANDARD_BT709},
45     {GRAPHIC_CM_SRGB_FULL, GRAPHIC_COLOR_GAMUT_SRGB},
46     {GRAPHIC_CM_ADOBERGB_FULL, GRAPHIC_COLOR_GAMUT_ADOBE_RGB},
47     {GRAPHIC_CM_P3_FULL, GRAPHIC_COLOR_GAMUT_DISPLAY_P3},
48     {GRAPHIC_CM_DISPLAY_BT2020_SRGB, GRAPHIC_COLOR_GAMUT_BT2020},
49     {GRAPHIC_CM_BT2020_PQ_FULL, GRAPHIC_COLOR_GAMUT_BT2100_PQ},
50     {GRAPHIC_CM_BT2020_HLG_FULL, GRAPHIC_COLOR_GAMUT_BT2100_HLG},
51     {GRAPHIC_CM_DISPLAY_BT2020_SRGB, GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020},
52 };
53 std::map<GraphicHDRFormat, ScreenHDRFormat> RSScreen::HDI_HDR_FORMAT_TO_RS_MAP {
54     {GRAPHIC_NOT_SUPPORT_HDR, NOT_SUPPORT_HDR},
55     {GRAPHIC_DOLBY_VISION, NOT_SUPPORT_HDR},
56     {GRAPHIC_HDR10, VIDEO_HDR10},
57     {GRAPHIC_HLG, VIDEO_HLG},
58     {GRAPHIC_HDR10_PLUS, NOT_SUPPORT_HDR},
59     {GRAPHIC_HDR_VIVID, VIDEO_HDR_VIVID},
60 };
61 std::map<ScreenHDRFormat, GraphicHDRFormat> RSScreen::RS_TO_HDI_HDR_FORMAT_MAP {
62     {NOT_SUPPORT_HDR, GRAPHIC_NOT_SUPPORT_HDR},
63     {VIDEO_HLG, GRAPHIC_HLG},
64     {VIDEO_HDR10, GRAPHIC_HDR10},
65     {VIDEO_HDR_VIVID, GRAPHIC_HDR_VIVID},
66     {IMAGE_HDR_VIVID_DUAL, GRAPHIC_HDR_VIVID},
67     {IMAGE_HDR_VIVID_SINGLE, GRAPHIC_HDR_VIVID},
68     {IMAGE_HDR_ISO_DUAL, GRAPHIC_NOT_SUPPORT_HDR},
69     {IMAGE_HDR_ISO_SINGLE, GRAPHIC_NOT_SUPPORT_HDR},
70 };
71 
72 constexpr int MAX_LUM = 1000;
73 
RSScreen(ScreenId id,bool isVirtual,std::shared_ptr<HdiOutput> output,sptr<Surface> surface)74 RSScreen::RSScreen(ScreenId id,
75     bool isVirtual,
76     std::shared_ptr<HdiOutput> output,
77     sptr<Surface> surface)
78     : id_(id),
79       isVirtual_(isVirtual),
80       hdiOutput_(std::move(output)),
81       producerSurface_(std::move(surface))
82 {
83     if (!IsVirtual()) {
84         hdrCapability_.formatCount = 0;
85         name_ = "Screen_" + std::to_string(id_);
86         PhysicalScreenInit();
87         RS_LOGD_IF(DEBUG_SCREEN, "RSSCreen init physical: {id: %{public}" PRIu64 ", w * h: [%{public}u * %{public}u],"
88             "screenType: %{public}u}", id_, width_, height_, screenType_);
89     }
90     capability_.props.clear();
91 }
92 
RSScreen(const VirtualScreenConfigs & configs)93 RSScreen::RSScreen(const VirtualScreenConfigs &configs)
94     : id_(configs.id),
95       mirrorId_(configs.mirrorId),
96       name_(configs.name),
97       width_(configs.width),
98       height_(configs.height),
99       isVirtual_(true),
100       producerSurface_(configs.surface),
101       pixelFormat_(configs.pixelFormat),
102       screenType_(RSScreenType::VIRTUAL_TYPE_SCREEN),
103       whiteList_(configs.whiteList)
104 {
105     VirtualScreenInit();
106     RS_LOGD_IF(DEBUG_SCREEN, "RSSCreen init virtual: {id: %{public}" PRIu64 ", mirrorId: %{public}" PRIu64 ", "
107         "w * h: [%{public}u * %{public}u], name: %{public}s, screenType: %{public}u}",
108         id_, mirrorId_, width_, height_, name_.c_str(), screenType_);
109 }
110 
~RSScreen()111 RSScreen::~RSScreen() noexcept
112 {
113 }
114 
VirtualScreenInit()115 void RSScreen::VirtualScreenInit() noexcept
116 {
117     hdrCapability_.formatCount = 0;
118     for (auto item : supportedVirtualHDRFormats_) {
119         hdrCapability_.formats.emplace_back(RS_TO_HDI_HDR_FORMAT_MAP[item]);
120         ++hdrCapability_.formatCount;
121     }
122 }
123 
PhysicalScreenInit()124 void RSScreen::PhysicalScreenInit() noexcept
125 {
126     hdiScreen_ = HdiScreen::CreateHdiScreen(ScreenPhysicalId(id_));
127     if (hdiScreen_ == nullptr) {
128         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") failed to CreateHdiScreens.",
129             __func__, id_);
130         return;
131     }
132 
133     hdiScreen_->Init();
134     if (hdiScreen_->GetScreenSupportedModes(supportedModes_) < 0) {
135         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") failed to GetScreenSupportedModes.",
136             __func__, id_);
137     }
138 
139     if (hdiScreen_->GetHDRCapabilityInfos(hdrCapability_) < 0) {
140         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") failed to GetHDRCapabilityInfos.",
141             __func__, id_);
142     }
143     std::transform(hdrCapability_.formats.begin(), hdrCapability_.formats.end(),
144                    back_inserter(supportedPhysicalHDRFormats_),
145                    [](GraphicHDRFormat item) -> ScreenHDRFormat {return HDI_HDR_FORMAT_TO_RS_MAP[item];});
146     auto status = GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON;
147     if (hdiScreen_->SetScreenPowerStatus(status) < 0) {
148         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") failed to SetScreenPowerStatus.",
149             __func__, id_);
150     }
151     auto activeMode = GetActiveMode();
152     if (activeMode) {
153         phyWidth_ = activeMode->width;
154         phyHeight_ = activeMode->height;
155         width_ = phyWidth_;
156         height_ = phyHeight_;
157     }
158     if (hdiScreen_->GetScreenPowerStatus(powerStatus_) < 0) {
159         powerStatus_ = static_cast<GraphicDispPowerStatus>(INVALID_POWER_STATUS);
160     }
161     if (capability_.type == GraphicInterfaceType::GRAPHIC_DISP_INTF_MIPI) {
162         screenType_ = RSScreenType::BUILT_IN_TYPE_SCREEN;
163     } else {
164         screenType_ = RSScreenType::EXTERNAL_TYPE_SCREEN;
165     }
166     ScreenCapabilityInit();
167 
168     std::vector<GraphicColorGamut> supportedColorGamuts;
169     if (hdiScreen_->GetScreenSupportedColorGamuts(supportedColorGamuts) != GRAPHIC_DISPLAY_SUCCESS) {
170         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") failed to GetScreenSupportedColorGamuts.",
171             __func__, id_);
172     } else {
173         int index = 0;
174         for (auto item : supportedColorGamuts) {
175             supportedPhysicalColorGamuts_.push_back(static_cast<ScreenColorGamut>(item));
176             if (item == GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB) {
177                 currentPhysicalColorGamutIdx_ = index;
178             }
179             ++index;
180         }
181     }
182     screenBacklightLevel_ = GetScreenBacklight();
183 }
184 
ScreenCapabilityInit()185 void RSScreen::ScreenCapabilityInit() noexcept
186 {
187     if (!hdiScreen_) {
188         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
189         return;
190     }
191     if (IsVirtual()) {
192         RS_LOGW("RSScreen %{public}s: this is virtual screen, use the default display capability.",  __func__);
193         return;
194     }
195     int32_t ret = hdiScreen_->GetScreenCapability(capability_);
196     if (ret != GRAPHIC_DISPLAY_SUCCESS) {
197         RS_LOGW("RSScreen %{public}s: get display capability failed, ret is %{public}d, use the default"
198             " display capability.", __func__, ret);
199         capability_ = {
200             .name = "test1",
201             .type = GRAPHIC_DISP_INTF_HDMI,
202             .phyWidth = 1921,
203             .phyHeight = 1081,
204             .supportLayers = 0,
205             .virtualDispCount = 0,
206             .supportWriteBack = true,
207             .propertyCount = 0
208         };
209     }
210 }
211 
Id() const212 ScreenId RSScreen::Id() const
213 {
214     return id_;
215 }
216 
MirrorId() const217 ScreenId RSScreen::MirrorId() const
218 {
219     return mirrorId_;
220 }
221 
SetMirror(ScreenId mirrorId)222 void RSScreen::SetMirror(ScreenId mirrorId)
223 {
224     mirrorId_ = mirrorId;
225 }
226 
Name() const227 const std::string& RSScreen::Name() const
228 {
229     return name_;
230 }
231 
Width() const232 uint32_t RSScreen::Width() const
233 {
234     return width_;
235 }
236 
Height() const237 uint32_t RSScreen::Height() const
238 {
239     return height_;
240 }
241 
PhyWidth() const242 uint32_t RSScreen::PhyWidth() const
243 {
244     return phyWidth_;
245 }
246 
PhyHeight() const247 uint32_t RSScreen::PhyHeight() const
248 {
249     return phyHeight_;
250 }
251 
IsEnable() const252 bool RSScreen::IsEnable() const
253 {
254     if (id_ == INVALID_SCREEN_ID) {
255         return false;
256     }
257 
258     if (!hdiOutput_ && !producerSurface_) {
259         return false;
260     }
261 
262     // [PLANNING]: maybe need more information to judge whether this screen is enable.
263     return true;
264 }
265 
IsVirtual() const266 bool RSScreen::IsVirtual() const
267 {
268     return isVirtual_;
269 }
270 
SetActiveMode(uint32_t modeId)271 void RSScreen::SetActiveMode(uint32_t modeId)
272 {
273     if (IsVirtual()) {
274         RS_LOGW("RSScreen %{public}s: virtual screen not support SetActiveMode.", __func__);
275         return;
276     }
277     if (!hdiScreen_) {
278         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
279         return;
280     }
281 
282     if (modeId >= supportedModes_.size()) {
283         RS_LOGE("RSScreen %{public}s: set fails because the index is out of bounds.", __func__);
284         return;
285     }
286     RS_LOGD_IF(DEBUG_SCREEN, "RSScreen set active mode: %{public}u", modeId);
287     int32_t selectModeId = supportedModes_[modeId].id;
288     if (hdiScreen_->SetScreenMode(static_cast<uint32_t>(selectModeId)) < 0) {
289         RS_LOGE("RSScreen %{public}s: Hdi SetScreenMode fails.", __func__);
290         return;
291     }
292     auto activeMode = GetActiveMode();
293     if (activeMode) {
294         phyWidth_ = activeMode->width;
295         phyHeight_ = activeMode->height;
296         static GraphicDisplayModeInfo modeInfo;
297         if ((modeInfo.freshRate != activeMode->freshRate)
298             || modeInfo.width != activeMode->width || modeInfo.height != activeMode->height) {
299             HiSysEventWrite(HiSysEvent::Domain::GRAPHIC, "EPS_LCD_FREQ",
300                 HiSysEvent::EventType::STATISTIC, "SOURCERATE", modeInfo.freshRate,
301                 "TARGETRATE", activeMode->freshRate, "WIDTH", phyWidth_, "HEIGHT", phyHeight_);
302             modeInfo = activeMode.value();
303         }
304     }
305 }
306 
SetRogResolution(uint32_t width,uint32_t height)307 void RSScreen::SetRogResolution(uint32_t width, uint32_t height)
308 {
309     if (!hdiScreen_) {
310         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
311         return;
312     }
313     if ((width == 0 || height == 0) ||
314         (width == width_ && height == height_) ||
315         (width > phyWidth_ || height > phyHeight_)) {
316         RS_LOGD("RSScreen:%{public}s: width: %{public}d, height: %{public}d.", __func__, width, height);
317         return;
318     }
319     if (hdiScreen_->SetScreenOverlayResolution(width, height) < 0) {
320         RS_LOGD("RSScreen:%{public}s: hdi set screen rog resolution failed.", __func__);
321     }
322     width_ = width;
323     height_ = height;
324     RS_LOGI("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 "), width: %{public}d,"
325         " height: %{public}d, phywidth: %{public}d, phyHeight: %{public}d.",
326 	    __func__, id_, width_, height_, phyWidth_, phyHeight_);
327 }
328 
329 
SetResolution(uint32_t width,uint32_t height)330 void RSScreen::SetResolution(uint32_t width, uint32_t height)
331 {
332     if (!IsVirtual()) {
333         RS_LOGW("RSScreen %{public}s: physical screen not support SetResolution.", __func__);
334         return;
335     }
336     RS_LOGD_IF(DEBUG_SCREEN, "RSScreen set resolution, w * h: [%{public}u * %{public}u]", width, height);
337     width_ = width;
338     height_ = height;
339 }
340 
GetActiveModePosByModeId(int32_t modeId) const341 int32_t RSScreen::GetActiveModePosByModeId(int32_t modeId) const
342 {
343     decltype(supportedModes_.size()) modeIndex = 0;
344     for (; modeIndex < supportedModes_.size(); ++modeIndex) {
345         if (supportedModes_[modeIndex].id == modeId) {
346             return static_cast<int32_t>(modeIndex);
347         }
348     }
349     return -1;
350 }
351 
SetPowerStatus(uint32_t powerStatus)352 void RSScreen::SetPowerStatus(uint32_t powerStatus)
353 {
354     if (!hdiScreen_) {
355         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
356         return;
357     }
358     if (IsVirtual()) {
359         RS_LOGW("[UL_POWER]RSScreen %{public}s: virtual screen not support SetPowerStatus.", __func__);
360         return;
361     }
362 
363     RS_LOGI("[UL_POWER]RSScreen_%{public}" PRIu64 " SetPowerStatus, status is %{public}u", id_, powerStatus);
364     RS_TRACE_NAME_FMT("[UL_POWER]Screen_%llu SetPowerStatus %u", id_, powerStatus);
365     if (hdiScreen_->SetScreenPowerStatus(static_cast<GraphicDispPowerStatus>(powerStatus)) < 0) {
366         return;
367     }
368 
369     if (powerStatus == GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON ||
370         powerStatus == GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON_ADVANCED) {
371         RS_LOGD("RSScreen %{public}s Enable hardware vsync", __func__);
372         if (hdiScreen_->SetScreenVsyncEnabled(true) != GRAPHIC_DISPLAY_SUCCESS) {
373             RS_LOGE("RSScreen %{public}s SetScreenVsyncEnabled failed", __func__);
374         }
375     }
376 }
377 
GetActiveMode() const378 std::optional<GraphicDisplayModeInfo> RSScreen::GetActiveMode() const
379 {
380     if (IsVirtual()) {
381         RS_LOGW("RSScreen %{public}s: virtual screen not support GetActiveMode.", __func__);
382         return {};
383     }
384 
385     uint32_t modeId = 0;
386 
387     if (hdiScreen_ == nullptr) {
388         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") hdiScreen is null.",
389             __func__, id_);
390         return {};
391     }
392 
393     if (hdiScreen_->GetScreenMode(modeId) < 0) {
394         RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") GetScreenMode failed.",
395             __func__, id_);
396         return {};
397     }
398 
399     auto iter = std::find_if(supportedModes_.cbegin(), supportedModes_.cend(),
400         [modeId](const auto &mode) { return static_cast<uint32_t>(mode.id) == modeId; });
401     if (iter == supportedModes_.cend()) {
402         return {};
403     }
404 
405     return *iter;
406 }
407 
GetSupportedModes() const408 const std::vector<GraphicDisplayModeInfo>& RSScreen::GetSupportedModes() const
409 {
410     return supportedModes_;
411 }
412 
GetCapability() const413 const GraphicDisplayCapability& RSScreen::GetCapability() const
414 {
415     return capability_;
416 }
417 
GetPowerStatus() const418 uint32_t RSScreen::GetPowerStatus() const
419 {
420     if (IsVirtual()) {
421         RS_LOGW("RSScreen %{public}s: virtual screen not support GetPowerStatus.", __func__);
422         return ScreenPowerStatus::INVALID_POWER_STATUS;
423     }
424 
425     if (!hdiScreen_) {
426         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
427         return INVALID_POWER_STATUS;
428     }
429     GraphicDispPowerStatus status;
430     if (!hdiScreen_) {
431         RS_LOGW("RSScreen %{public}s: hdiScreen_ is nullptr.", __func__);
432         return INVALID_POWER_STATUS;
433     }
434     if (hdiScreen_->GetScreenPowerStatus(status) < 0) {
435         return INVALID_POWER_STATUS;
436     }
437     return static_cast<uint32_t>(status);
438 }
439 
GetOutput() const440 std::shared_ptr<HdiOutput> RSScreen::GetOutput() const
441 {
442     return hdiOutput_;
443 }
444 
GetProducerSurface() const445 sptr<Surface> RSScreen::GetProducerSurface() const
446 {
447     return producerSurface_;
448 }
449 
SetProducerSurface(sptr<Surface> producerSurface)450 void RSScreen::SetProducerSurface(sptr<Surface> producerSurface)
451 {
452     producerSurface_ = producerSurface;
453     isVirtualSurfaceUpdateFlag_ = true;
454 }
455 
GetAndResetVirtualSurfaceUpdateFlag()456 bool RSScreen::GetAndResetVirtualSurfaceUpdateFlag()
457 {
458     if (isVirtualSurfaceUpdateFlag_) {
459         isVirtualSurfaceUpdateFlag_ = false;
460         return true;
461     }
462     return false;
463 }
464 
ModeInfoDump(std::string & dumpString)465 void RSScreen::ModeInfoDump(std::string& dumpString)
466 {
467     decltype(supportedModes_.size()) modeIndex = 0;
468     for (; modeIndex < supportedModes_.size(); ++modeIndex) {
469         AppendFormat(dumpString, "  supportedMode[%d]: %dx%d, refreshrate=%d\n",
470                      modeIndex, supportedModes_[modeIndex].width,
471                      supportedModes_[modeIndex].height, supportedModes_[modeIndex].freshRate);
472     }
473     std::optional<GraphicDisplayModeInfo> activeMode = GetActiveMode();
474     if (activeMode) {
475         AppendFormat(dumpString, "  activeMode: %dx%d, refreshrate=%d\n",
476             activeMode->width, activeMode->height, activeMode->freshRate);
477     }
478 }
479 
CapabilityTypeDump(GraphicInterfaceType capabilityType,std::string & dumpString)480 void RSScreen::CapabilityTypeDump(GraphicInterfaceType capabilityType, std::string& dumpString)
481 {
482     dumpString += "type=";
483     switch (capabilityType) {
484         case GRAPHIC_DISP_INTF_HDMI: {
485             dumpString += "DISP_INTF_HDMI, ";
486             break;
487         }
488         case GRAPHIC_DISP_INTF_LCD: {
489             dumpString += "DISP_INTF_LCD, ";
490             break;
491         }
492         case GRAPHIC_DISP_INTF_BT1120: {
493             dumpString += "DISP_INTF_BT1120, ";
494             break;
495         }
496         case GRAPHIC_DISP_INTF_BT656: {
497             dumpString += "DISP_INTF_BT656, ";
498             break;
499         }
500         default:
501             dumpString += "INVILID_DISP_INTF, ";
502             break;
503     }
504 }
505 
CapabilityDump(std::string & dumpString)506 void RSScreen::CapabilityDump(std::string& dumpString)
507 {
508     AppendFormat(dumpString, "  capability: name=%s, phywidth=%d, phyheight=%d,"
509                  "supportlayers=%d, virtualDispCount=%d, propCount=%d, ",
510                  capability_.name.c_str(), capability_.phyWidth, capability_.phyHeight,
511                  capability_.supportLayers, capability_.virtualDispCount, capability_.propertyCount);
512     CapabilityTypeDump(capability_.type, dumpString);
513     dumpString += "supportWriteBack=";
514     dumpString += (capability_.supportWriteBack) ? "true" : "false";
515     dumpString += "\n";
516     PropDump(dumpString);
517 }
518 
PropDump(std::string & dumpString)519 void RSScreen::PropDump(std::string& dumpString)
520 {
521     decltype(capability_.propertyCount) propIndex = 0;
522     for (; propIndex < capability_.propertyCount; ++propIndex) {
523         AppendFormat(dumpString, "prop[%u]: name=%s, propid=%d, value=%d\n",
524                      propIndex, capability_.props[propIndex].name.c_str(), capability_.props[propIndex].propId,
525                      capability_.props[propIndex].value);
526     }
527 }
528 
PowerStatusDump(std::string & dumpString)529 void RSScreen::PowerStatusDump(std::string& dumpString)
530 {
531     dumpString += "powerstatus=";
532     switch (GetPowerStatus()) {
533         case GRAPHIC_POWER_STATUS_ON: {
534             dumpString += "POWER_STATUS_ON";
535             break;
536         }
537         case GRAPHIC_POWER_STATUS_STANDBY: {
538             dumpString += "POWER_STATUS_STANDBY";
539             break;
540         }
541         case GRAPHIC_POWER_STATUS_SUSPEND: {
542             dumpString += "POWER_STATUS_SUSPEND";
543             break;
544         }
545         case GRAPHIC_POWER_STATUS_OFF: {
546             dumpString += "POWER_STATUS_OFF";
547             break;
548         }
549         case GRAPHIC_POWER_STATUS_OFF_FAKE: {
550             dumpString += "POWER_STATUS_OFF_FAKE";
551             break;
552         }
553         case GRAPHIC_POWER_STATUS_BUTT: {
554             dumpString += "POWER_STATUS_BUTT";
555             break;
556         }
557         case GRAPHIC_POWER_STATUS_ON_ADVANCED: {
558             dumpString += "POWER_STATUS_ON_ADVANCED";
559             break;
560         }
561         case GRAPHIC_POWER_STATUS_OFF_ADVANCED: {
562             dumpString += "POWER_STATUS_OFF_ADVANCED";
563             break;
564         }
565         default: {
566             dumpString += "INVALID_POWER_STATUS";
567             break;
568         }
569     }
570 }
571 
572 
DisplayDump(int32_t screenIndex,std::string & dumpString)573 void RSScreen::DisplayDump(int32_t screenIndex, std::string& dumpString)
574 {
575     dumpString += "-- ScreenInfo\n";
576     if (IsVirtual()) {
577         dumpString += "screen[" + std::to_string(screenIndex) + "]: ";
578         dumpString += "id=";
579         dumpString += (id_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(id_);
580         dumpString += ", ";
581         dumpString += "mirrorId=";
582         dumpString += (mirrorId_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(mirrorId_);
583         dumpString += ", ";
584         AppendFormat(dumpString, ", render size: %dx%d, isvirtual=true, skipFrameInterval_:%d"
585             ", expectedRefreshRate_:%d, skipFrameStrategy_:%d\n",
586             width_, height_, skipFrameInterval_, expectedRefreshRate_, skipFrameStrategy_);
587     } else {
588         dumpString += "screen[" + std::to_string(screenIndex) + "]: ";
589         dumpString += "id=";
590         dumpString += (id_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(id_);
591         dumpString += ", ";
592         PowerStatusDump(dumpString);
593         dumpString += ", ";
594         dumpString += "backlight=" + std::to_string(GetScreenBacklight());
595         dumpString += ", ";
596         ScreenTypeDump(dumpString);
597         AppendFormat(dumpString,
598             ", render size: %dx%d, physical screen resolution: %dx%d, isvirtual=false, skipFrameInterval_:%d"
599             ", expectedRefreshRate_:%d, skipFrameStrategy_:%d\n",
600             width_, height_, phyWidth_, phyHeight_, skipFrameInterval_, expectedRefreshRate_, skipFrameStrategy_);
601         dumpString += "\n";
602         ModeInfoDump(dumpString);
603         CapabilityDump(dumpString);
604     }
605 }
606 
ScreenTypeDump(std::string & dumpString)607 void RSScreen::ScreenTypeDump(std::string& dumpString)
608 {
609     dumpString += "screenType=";
610     switch (screenType_) {
611         case RSScreenType::BUILT_IN_TYPE_SCREEN: {
612             dumpString += "BUILT_IN_TYPE";
613             break;
614         }
615         case RSScreenType::EXTERNAL_TYPE_SCREEN: {
616             dumpString += "EXTERNAL_TYPE";
617             break;
618         }
619         case RSScreenType::VIRTUAL_TYPE_SCREEN: {
620             dumpString += "VIRTUAL_TYPE";
621             break;
622         }
623         default: {
624             dumpString += "UNKNOWN_TYPE";
625             break;
626         }
627     }
628 }
629 
SurfaceDump(int32_t screenIndex,std::string & dumpString)630 void RSScreen::SurfaceDump(int32_t screenIndex, std::string& dumpString)
631 {
632     if (hdiOutput_ == nullptr) {
633         RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
634         return;
635     }
636     hdiOutput_->Dump(dumpString);
637 }
638 
FpsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)639 void RSScreen::FpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
640 {
641     if (hdiOutput_ == nullptr) {
642         RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
643         return;
644     }
645     hdiOutput_->DumpFps(dumpString, arg);
646 }
647 
ClearFpsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)648 void RSScreen::ClearFpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
649 {
650     if (hdiOutput_ == nullptr) {
651         RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
652         return;
653     }
654     hdiOutput_->ClearFpsDump(dumpString, arg);
655 }
656 
HitchsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)657 void RSScreen::HitchsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
658 {
659     if (hdiOutput_ == nullptr) {
660         RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
661         return;
662     }
663     hdiOutput_->DumpHitchs(dumpString, arg);
664 }
665 
ResizeVirtualScreen(uint32_t width,uint32_t height)666 void RSScreen::ResizeVirtualScreen(uint32_t width, uint32_t height)
667 {
668     if (!IsVirtual()) {
669         RS_LOGW("RSScreen %{public}s: physical screen not support ResizeVirtualScreen.", __func__);
670         return;
671     }
672     width_ = width;
673     height_ = height;
674 }
675 
SetScreenBacklight(uint32_t level)676 void RSScreen::SetScreenBacklight(uint32_t level)
677 {
678     if (!hdiScreen_) {
679         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
680         return;
681     }
682     if (IsVirtual()) {
683         RS_LOGW("RSScreen %{public}s: virtual screen not support SetScreenBacklight.", __func__);
684         return;
685     }
686 
687     RS_LOGD("RSScreen_%{public}" PRIu64 " SetScreenBacklight, level is %{public}u", id_, level);
688     if (hdiScreen_->SetScreenBacklight(level) < 0) {
689         return;
690     }
691     screenBacklightLevel_ = static_cast<int32_t>(level);
692 }
693 
GetScreenBacklight() const694 int32_t RSScreen::GetScreenBacklight() const
695 {
696     if (IsVirtual()) {
697         RS_LOGW("RSScreen %{public}s: virtual screen not support GetScreenBacklight.", __func__);
698         return INVALID_BACKLIGHT_VALUE;
699     }
700     uint32_t level = 0;
701     if (screenBacklightLevel_ != INVALID_BACKLIGHT_VALUE) {
702         return screenBacklightLevel_;
703     }
704     if (!hdiScreen_) {
705         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
706         return INVALID_BACKLIGHT_VALUE;
707     }
708     if (hdiScreen_->GetScreenBacklight(level) < 0) {
709         return INVALID_BACKLIGHT_VALUE;
710     }
711     return static_cast<int32_t>(level);
712 }
713 
GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> & mode) const714 int32_t RSScreen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> &mode) const
715 {
716     mode.clear();
717     if (IsVirtual()) {
718         mode = supportedVirtualColorGamuts_;
719     } else {
720         mode = supportedPhysicalColorGamuts_;
721     }
722     if (mode.size() == 0) {
723         return StatusCode::HDI_ERROR;
724     }
725     return StatusCode::SUCCESS;
726 }
727 
GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> & keys) const728 int32_t RSScreen::GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> &keys) const
729 {
730     if (IsVirtual()) {
731         RS_LOGW("RSScreen %{public}s: virtual screen not support GetScreenSupportedMetaDataKeys.", __func__);
732         return INVALID_BACKLIGHT_VALUE;
733     }
734 
735     // ScreenHDRMetadataKey now is mock data.
736     keys.push_back(ScreenHDRMetadataKey::MATAKEY_RED_PRIMARY_X);
737     keys.push_back(ScreenHDRMetadataKey::MATAKEY_RED_PRIMARY_Y);
738     keys.push_back(ScreenHDRMetadataKey::MATAKEY_GREEN_PRIMARY_X);
739     keys.push_back(ScreenHDRMetadataKey::MATAKEY_GREEN_PRIMARY_Y);
740     keys.push_back(ScreenHDRMetadataKey::MATAKEY_BLUE_PRIMARY_X);
741     keys.push_back(ScreenHDRMetadataKey::MATAKEY_BLUE_PRIMARY_Y);
742     keys.push_back(ScreenHDRMetadataKey::MATAKEY_WHITE_PRIMARY_X);
743     keys.push_back(ScreenHDRMetadataKey::MATAKEY_WHITE_PRIMARY_Y);
744     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_LUMINANCE);
745     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MIN_LUMINANCE);
746     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_CONTENT_LIGHT_LEVEL);
747     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL);
748     keys.push_back(ScreenHDRMetadataKey::MATAKEY_HDR10_PLUS);
749     keys.push_back(ScreenHDRMetadataKey::MATAKEY_HDR_VIVID);
750     return StatusCode::SUCCESS;
751 }
752 
GetScreenColorGamut(ScreenColorGamut & mode) const753 int32_t RSScreen::GetScreenColorGamut(ScreenColorGamut &mode) const
754 {
755     if (IsVirtual()) {
756         mode = supportedVirtualColorGamuts_[currentVirtualColorGamutIdx_];
757         return StatusCode::SUCCESS;
758     } else {
759         if (supportedPhysicalColorGamuts_.size() == 0) {
760             return StatusCode::HDI_ERROR;
761         }
762         mode = supportedPhysicalColorGamuts_[currentPhysicalColorGamutIdx_];
763         return StatusCode::SUCCESS;
764     }
765     return StatusCode::HDI_ERROR;
766 }
767 
SetScreenColorGamut(int32_t modeIdx)768 int32_t RSScreen::SetScreenColorGamut(int32_t modeIdx)
769 {
770     if (modeIdx < 0) {
771         return StatusCode::INVALID_ARGUMENTS;
772     }
773     if (IsVirtual()) {
774         if (modeIdx >= static_cast<int32_t>(supportedVirtualColorGamuts_.size())) {
775             return StatusCode::INVALID_ARGUMENTS;
776         }
777         currentVirtualColorGamutIdx_ = modeIdx;
778         return StatusCode::SUCCESS;
779     }
780     if (!hdiScreen_) {
781         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
782         return StatusCode::HDI_ERROR;
783     }
784     std::vector<GraphicColorGamut> hdiMode;
785     if (hdiScreen_->GetScreenSupportedColorGamuts(hdiMode) != GRAPHIC_DISPLAY_SUCCESS) {
786         return StatusCode::HDI_ERROR;
787     }
788     if (modeIdx >= static_cast<int32_t>(hdiMode.size())) {
789         return StatusCode::INVALID_ARGUMENTS;
790     }
791     int32_t result = hdiScreen_->SetScreenColorGamut(hdiMode[modeIdx]);
792     if (result == GRAPHIC_DISPLAY_SUCCESS) {
793         currentPhysicalColorGamutIdx_ = modeIdx;
794         return StatusCode::SUCCESS;
795     }
796     return StatusCode::HDI_ERROR;
797 }
798 
SetScreenGamutMap(ScreenGamutMap mode)799 int32_t RSScreen::SetScreenGamutMap(ScreenGamutMap mode)
800 {
801     if (IsVirtual()) {
802         currentVirtualGamutMap_ = mode;
803         return StatusCode::SUCCESS;
804     }
805     if (!hdiScreen_) {
806         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
807         return StatusCode::HDI_ERROR;
808     }
809     int32_t result = hdiScreen_->SetScreenGamutMap(static_cast<GraphicGamutMap>(mode));
810     if (result == GRAPHIC_DISPLAY_SUCCESS) {
811         return StatusCode::SUCCESS;
812     }
813     return StatusCode::HDI_ERROR;
814 }
815 
SetScreenCorrection(ScreenRotation screenRotation)816 void RSScreen::SetScreenCorrection(ScreenRotation screenRotation)
817 {
818     RS_LOGD("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") ,ScreenRotation: %{public}d.",
819             __func__, id_, static_cast<uint32_t>(screenRotation));
820     screenRotation_ = screenRotation;
821 }
822 
GetScreenCorrection() const823 ScreenRotation RSScreen::GetScreenCorrection() const
824 {
825     return screenRotation_;
826 }
827 
GetScreenGamutMap(ScreenGamutMap & mode) const828 int32_t RSScreen::GetScreenGamutMap(ScreenGamutMap &mode) const
829 {
830     if (IsVirtual()) {
831         mode = currentVirtualGamutMap_;
832         return StatusCode::SUCCESS;
833     }
834     if (!hdiScreen_) {
835         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
836         return StatusCode::HDI_ERROR;
837     }
838     GraphicGamutMap hdiMode;
839     int32_t result = hdiScreen_->GetScreenGamutMap(hdiMode);
840     if (result == GRAPHIC_DISPLAY_SUCCESS) {
841         mode = static_cast<ScreenGamutMap>(hdiMode);
842         return StatusCode::SUCCESS;
843     }
844     return StatusCode::HDI_ERROR;
845 }
846 
GetHDRCapability()847 const GraphicHDRCapability& RSScreen::GetHDRCapability()
848 {
849     hdrCapability_.maxLum = MAX_LUM; // mock data
850     return hdrCapability_;
851 }
852 
GetScreenType() const853 const RSScreenType& RSScreen::GetScreenType() const
854 {
855     return screenType_;
856 }
857 
SetScreenSkipFrameInterval(uint32_t skipFrameInterval)858 void RSScreen::SetScreenSkipFrameInterval(uint32_t skipFrameInterval)
859 {
860     std::lock_guard<std::mutex> lock(skipFrameMutex_);
861     skipFrameInterval_ = skipFrameInterval;
862     skipFrameStrategy_ = SKIP_FRAME_BY_INTERVAL;
863 }
864 
SetScreenExpectedRefreshRate(uint32_t expectedRefreshRate)865 void RSScreen::SetScreenExpectedRefreshRate(uint32_t expectedRefreshRate)
866 {
867     std::lock_guard<std::mutex> lock(skipFrameMutex_);
868     expectedRefreshRate_ = expectedRefreshRate;
869     skipFrameStrategy_ = SKIP_FRAME_BY_REFRESH_RATE;
870 }
871 
SetEqualVsyncPeriod(bool isEqualVsyncPeriod)872 void RSScreen::SetEqualVsyncPeriod(bool isEqualVsyncPeriod)
873 {
874     std::lock_guard<std::mutex> lock(skipFrameMutex_);
875     isEqualVsyncPeriod_ = isEqualVsyncPeriod;
876 }
877 
GetScreenSkipFrameInterval() const878 uint32_t RSScreen::GetScreenSkipFrameInterval() const
879 {
880     std::lock_guard<std::mutex> lock(skipFrameMutex_);
881     return skipFrameInterval_;
882 }
883 
GetScreenExpectedRefreshRate() const884 uint32_t RSScreen::GetScreenExpectedRefreshRate() const
885 {
886     std::lock_guard<std::mutex> lock(skipFrameMutex_);
887     return expectedRefreshRate_;
888 }
889 
GetScreenSkipFrameStrategy() const890 SkipFrameStrategy RSScreen::GetScreenSkipFrameStrategy() const
891 {
892     std::lock_guard<std::mutex> lock(skipFrameMutex_);
893     return skipFrameStrategy_;
894 }
895 
GetEqualVsyncPeriod() const896 bool RSScreen::GetEqualVsyncPeriod() const
897 {
898     std::lock_guard<std::mutex> lock(skipFrameMutex_);
899     return isEqualVsyncPeriod_;
900 }
901 
SetScreenVsyncEnabled(bool enabled) const902 void RSScreen::SetScreenVsyncEnabled(bool enabled) const
903 {
904     if (IsVirtual()) {
905         return;
906     }
907     if (hdiScreen_ != nullptr) {
908         hdiScreen_->SetScreenVsyncEnabled(enabled);
909     }
910 }
911 
SetVirtualMirrorScreenCanvasRotation(bool canvasRotation)912 bool RSScreen::SetVirtualMirrorScreenCanvasRotation(bool canvasRotation)
913 {
914     if (IsVirtual()) {
915         canvasRotation_ = canvasRotation;
916         return true;
917     }
918     return false;
919 }
920 
GetCanvasRotation() const921 bool RSScreen::GetCanvasRotation() const
922 {
923     return canvasRotation_;
924 }
925 
SetVirtualMirrorScreenScaleMode(ScreenScaleMode scaleMode)926 bool RSScreen::SetVirtualMirrorScreenScaleMode(ScreenScaleMode scaleMode)
927 {
928     if (IsVirtual()) {
929         scaleMode_ = scaleMode;
930         return true;
931     }
932     return false;
933 }
934 
GetScaleMode() const935 ScreenScaleMode RSScreen::GetScaleMode() const
936 {
937     return scaleMode_;
938 }
939 
GetScreenSupportedHDRFormats(std::vector<ScreenHDRFormat> & hdrFormats) const940 int32_t RSScreen::GetScreenSupportedHDRFormats(std::vector<ScreenHDRFormat>& hdrFormats) const
941 {
942     hdrFormats.clear();
943     if (IsVirtual()) {
944         hdrFormats = supportedVirtualHDRFormats_;
945     } else {
946         hdrFormats = supportedPhysicalHDRFormats_;
947     }
948     if (hdrFormats.size() == 0) {
949         return StatusCode::HDI_ERROR;
950     }
951     return StatusCode::SUCCESS;
952 }
953 
GetScreenHDRFormat(ScreenHDRFormat & hdrFormat) const954 int32_t RSScreen::GetScreenHDRFormat(ScreenHDRFormat& hdrFormat) const
955 {
956     if (IsVirtual()) {
957         hdrFormat = supportedVirtualHDRFormats_[currentVirtualHDRFormatIdx_];
958         return StatusCode::SUCCESS;
959     } else {
960         if (supportedPhysicalHDRFormats_.size() == 0) {
961             return StatusCode::HDI_ERROR;
962         }
963         hdrFormat = supportedPhysicalHDRFormats_[currentPhysicalHDRFormatIdx_];
964         return StatusCode::SUCCESS;
965     }
966     return StatusCode::HDI_ERROR;
967 }
968 
SetScreenHDRFormat(int32_t modeIdx)969 int32_t RSScreen::SetScreenHDRFormat(int32_t modeIdx)
970 {
971     if (modeIdx < 0) {
972         return StatusCode::INVALID_ARGUMENTS;
973     }
974     if (IsVirtual()) {
975         if (modeIdx >= static_cast<int32_t>(supportedVirtualHDRFormats_.size())) {
976             return StatusCode::INVALID_ARGUMENTS;
977         }
978         currentVirtualHDRFormatIdx_ = modeIdx;
979         return StatusCode::SUCCESS;
980     } else {
981         // There should be some hdi operation
982         if (modeIdx >= static_cast<int32_t>(hdrCapability_.formats.size())) {
983             return StatusCode::INVALID_ARGUMENTS;
984         }
985         currentPhysicalHDRFormatIdx_ = modeIdx;
986         return StatusCode::SUCCESS;
987     }
988     return StatusCode::HDI_ERROR;
989 }
990 
GetPixelFormat(GraphicPixelFormat & pixelFormat) const991 int32_t RSScreen::GetPixelFormat(GraphicPixelFormat& pixelFormat) const
992 {
993     pixelFormat = pixelFormat_;
994     return StatusCode::SUCCESS;
995 }
996 
SetPixelFormat(GraphicPixelFormat pixelFormat)997 int32_t RSScreen::SetPixelFormat(GraphicPixelFormat pixelFormat)
998 {
999     pixelFormat_ = pixelFormat;
1000     return StatusCode::SUCCESS;
1001 }
1002 
GetScreenSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType> & colorSpaces) const1003 int32_t RSScreen::GetScreenSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType>& colorSpaces) const
1004 {
1005     colorSpaces.clear();
1006     if (IsVirtual()) {
1007         std::transform(supportedVirtualColorGamuts_.begin(), supportedVirtualColorGamuts_.end(),
1008                        back_inserter(colorSpaces),
1009                        [](ScreenColorGamut item) -> GraphicCM_ColorSpaceType {
1010                             return RS_TO_COMMON_COLOR_SPACE_TYPE_MAP[static_cast<GraphicColorGamut>(item)];
1011                         });
1012     } else {
1013         std::transform(supportedPhysicalColorGamuts_.begin(), supportedPhysicalColorGamuts_.end(),
1014                        back_inserter(colorSpaces),
1015                        [](ScreenColorGamut item) -> GraphicCM_ColorSpaceType {
1016                             return RS_TO_COMMON_COLOR_SPACE_TYPE_MAP[static_cast<GraphicColorGamut>(item)];
1017                         });
1018     }
1019     if (colorSpaces.size() == 0) {
1020         return StatusCode::HDI_ERROR;
1021     }
1022     return StatusCode::SUCCESS;
1023 }
1024 
GetScreenColorSpace(GraphicCM_ColorSpaceType & colorSpace) const1025 int32_t RSScreen::GetScreenColorSpace(GraphicCM_ColorSpaceType& colorSpace) const
1026 {
1027     ScreenColorGamut curGamut;
1028     int32_t result = GetScreenColorGamut(curGamut);
1029     colorSpace = RS_TO_COMMON_COLOR_SPACE_TYPE_MAP[static_cast<GraphicColorGamut>(curGamut)];
1030     return result;
1031 }
1032 
SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace)1033 int32_t RSScreen::SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace)
1034 {
1035     auto iter = COMMON_COLOR_SPACE_TYPE_TO_RS_MAP.find(colorSpace);
1036     if (iter == COMMON_COLOR_SPACE_TYPE_TO_RS_MAP.end()) {
1037         return StatusCode::INVALID_ARGUMENTS;
1038     }
1039     ScreenColorGamut dstColorGamut = static_cast<ScreenColorGamut>(iter->second);
1040     int32_t curIdx;
1041     if (IsVirtual()) {
1042         auto it = std::find(supportedVirtualColorGamuts_.begin(), supportedVirtualColorGamuts_.end(), dstColorGamut);
1043         if (it == supportedVirtualColorGamuts_.end()) {
1044             return StatusCode::INVALID_ARGUMENTS;
1045         }
1046         curIdx = std::distance(supportedVirtualColorGamuts_.begin(), it);
1047         currentVirtualColorGamutIdx_ = curIdx;
1048         return StatusCode::SUCCESS;
1049     }
1050     if (!hdiScreen_) {
1051         RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr",  __func__);
1052         return StatusCode::HDI_ERROR;
1053     }
1054     std::vector<GraphicColorGamut> hdiMode;
1055     if (hdiScreen_->GetScreenSupportedColorGamuts(hdiMode) != GRAPHIC_DISPLAY_SUCCESS) {
1056         return StatusCode::HDI_ERROR;
1057     }
1058     auto it = std::find(hdiMode.begin(), hdiMode.end(), static_cast<GraphicColorGamut>(dstColorGamut));
1059     if (it == hdiMode.end()) {
1060         return StatusCode::INVALID_ARGUMENTS;
1061     }
1062     curIdx = std::distance(hdiMode.begin(), it);
1063     int32_t result = hdiScreen_->SetScreenColorGamut(hdiMode[curIdx]);
1064     if (result == GRAPHIC_DISPLAY_SUCCESS) {
1065         currentPhysicalColorGamutIdx_ = curIdx;
1066         return StatusCode::SUCCESS;
1067     }
1068     return StatusCode::HDI_ERROR;
1069 }
GetWhiteList() const1070 const std::unordered_set<uint64_t>& RSScreen::GetWhiteList() const
1071 {
1072     return whiteList_;
1073 }
1074 
SetBlackList(const std::unordered_set<uint64_t> & blackList)1075 void RSScreen::SetBlackList(const std::unordered_set<uint64_t>& blackList)
1076 {
1077     blackList_ = blackList;
1078 }
1079 
AddBlackList(const std::vector<uint64_t> & blackList)1080 void RSScreen::AddBlackList(const std::vector<uint64_t>& blackList)
1081 {
1082     for (auto& list : blackList) {
1083         blackList_.emplace(list);
1084     }
1085 }
1086 
RemoveBlackList(const std::vector<uint64_t> & blackList)1087 void RSScreen::RemoveBlackList(const std::vector<uint64_t>& blackList)
1088 {
1089     for (auto& list : blackList) {
1090         blackList_.erase(list);
1091     }
1092 }
1093 
SetCastScreenEnableSkipWindow(bool enable)1094 void RSScreen::SetCastScreenEnableSkipWindow(bool enable)
1095 {
1096     skipWindow_ = enable;
1097 }
1098 
GetCastScreenEnableSkipWindow()1099 bool RSScreen::GetCastScreenEnableSkipWindow()
1100 {
1101     return skipWindow_;
1102 }
1103 
GetBlackList() const1104 const std::unordered_set<uint64_t>& RSScreen::GetBlackList() const
1105 {
1106     return blackList_;
1107 }
1108 
SetScreenConstraint(uint64_t frameId,uint64_t timestamp,ScreenConstraintType type)1109 int32_t RSScreen::SetScreenConstraint(uint64_t frameId, uint64_t timestamp, ScreenConstraintType type)
1110 {
1111     if (IsVirtual()) {
1112         return StatusCode::SUCCESS;
1113     }
1114     if (hdiScreen_ != nullptr) {
1115         int32_t result = hdiScreen_->SetScreenConstraint(frameId, timestamp, static_cast<uint32_t>(type));
1116         if (result == GRAPHIC_DISPLAY_SUCCESS) {
1117             return StatusCode::SUCCESS;
1118         }
1119     }
1120     return StatusCode::HDI_ERROR;
1121 }
1122 
SetSecurityExemptionList(const std::vector<uint64_t> & securityExemptionList)1123 void RSScreen::SetSecurityExemptionList(const std::vector<uint64_t>& securityExemptionList)
1124 {
1125     securityExemptionList_ = securityExemptionList;
1126 }
1127 
GetSecurityExemptionList() const1128 const std::vector<uint64_t>& RSScreen::GetSecurityExemptionList() const
1129 {
1130     return securityExemptionList_;
1131 }
1132 
SetDisplayPropertyForHardCursor()1133 void RSScreen::SetDisplayPropertyForHardCursor()
1134 {
1135     isHardCursorSupport_ = false;
1136     if (hdiScreen_) {
1137         isHardCursorSupport_ = hdiScreen_->GetDisplayPropertyForHardCursor(id_);
1138     }
1139     RS_LOGI("%{public}s, RSScreen(id %{public}" PRIu64 ", isHardCursorSupport:%{public}d)",
1140         __func__, id_, isHardCursorSupport_);
1141 }
1142 
GetDisplayPropertyForHardCursor()1143 bool RSScreen::GetDisplayPropertyForHardCursor()
1144 {
1145     return isHardCursorSupport_;
1146 }
1147 } // namespace impl
1148 } // namespace Rosen
1149 } // namespace OHOS
1150