• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cinttypes>
19 
20 #include "platform/common/rs_log.h"
21 #include "string_utils.h"
22 #include "hisysevent.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 using namespace HiviewDFX;
27 
28 namespace impl {
RSScreen(ScreenId id,bool isVirtual,std::shared_ptr<HdiOutput> output,sptr<Surface> surface)29 RSScreen::RSScreen(ScreenId id,
30     bool isVirtual,
31     std::shared_ptr<HdiOutput> output,
32     sptr<Surface> surface)
33     : id_(id),
34       isVirtual_(isVirtual),
35       hdiOutput_(std::move(output)),
36       producerSurface_(std::move(surface))
37 {
38     if (!IsVirtual()) {
39         hdrCapability_.formatCount = 0;
40         name_ = "Screen_" + std::to_string(id_);
41         PhysicalScreenInit();
42     }
43     capability_.props.clear();
44 }
45 
RSScreen(const VirtualScreenConfigs & configs)46 RSScreen::RSScreen(const VirtualScreenConfigs &configs)
47     : id_(configs.id),
48       mirrorId_(configs.mirrorId),
49       name_(configs.name),
50       width_(configs.width),
51       height_(configs.height),
52       isVirtual_(true),
53       producerSurface_(configs.surface),
54       screenType_(RSScreenType::VIRTUAL_TYPE_SCREEN)
55 {
56     hdrCapability_.formatCount = 0;
57 }
58 
~RSScreen()59 RSScreen::~RSScreen() noexcept
60 {
61 }
62 
PhysicalScreenInit()63 void RSScreen::PhysicalScreenInit() noexcept
64 {
65     hdiScreen_ = HdiScreen::CreateHdiScreen(ScreenPhysicalId(id_));
66     if (hdiScreen_ == nullptr) {
67         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") failed to CreateHdiScreens.",
68             __func__, id_);
69         return;
70     }
71 
72     hdiScreen_->Init();
73     if (hdiScreen_->GetScreenSupportedModes(supportedModes_) < 0) {
74         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") failed to GetScreenSupportedModes.",
75             __func__, id_);
76     }
77 
78     if (hdiScreen_->GetHDRCapabilityInfos(hdrCapability_) < 0) {
79         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") failed to GetHDRCapabilityInfos.",
80             __func__, id_);
81     }
82     auto status = GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON;
83     if (hdiScreen_->SetScreenPowerStatus(status) < 0) {
84         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") failed to SetScreenPowerStatus.",
85             __func__, id_);
86     }
87     auto activeMode = GetActiveMode();
88     if (activeMode) {
89         width_ = activeMode->width;
90         height_ = activeMode->height;
91     }
92     if (hdiScreen_->GetScreenPowerStatus(powerStatus_) < 0) {
93         powerStatus_ = static_cast<GraphicDispPowerStatus>(INVALID_POWER_STATUS);
94     }
95     if (capability_.type == GraphicInterfaceType::GRAPHIC_DISP_INTF_MIPI) {
96         screenType_ = RSScreenType::BUILT_IN_TYPE_SCREEN;
97     } else {
98         screenType_ = RSScreenType::EXTERNAL_TYPE_SCREEN;
99     }
100     ScreenCapabilityInit();
101 
102     std::vector<GraphicColorGamut> supportedColorGamuts;
103     if (hdiScreen_->GetScreenSupportedColorGamuts(supportedColorGamuts) != GRAPHIC_DISPLAY_SUCCESS) {
104         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") failed to GetScreenSupportedColorGamuts.",
105             __func__, id_);
106     } else {
107         for (auto item : supportedColorGamuts) {
108             supportedPhysicalColorGamuts_.push_back(static_cast<ScreenColorGamut>(item));
109         }
110     }
111 }
112 
ScreenCapabilityInit()113 void RSScreen::ScreenCapabilityInit() noexcept
114 {
115     if (IsVirtual()) {
116         RS_LOGW("RSScreen %s: this is virtual screen, use the default display capability.",  __func__);
117         return;
118     }
119     int32_t ret = hdiScreen_->GetScreenCapability(capability_);
120     if (ret != GRAPHIC_DISPLAY_SUCCESS) {
121         RS_LOGW("RSScreen %s: get display capability failed, ret is %d, use the default display capability.",
122                 __func__, ret);
123         capability_ = {
124             .name = "test1",
125             .type = GRAPHIC_DISP_INTF_HDMI,
126             .phyWidth = 1921,
127             .phyHeight = 1081,
128             .supportLayers = 0,
129             .virtualDispCount = 0,
130             .supportWriteBack = true,
131             .propertyCount = 0
132         };
133     }
134 }
135 
Id() const136 ScreenId RSScreen::Id() const
137 {
138     return id_;
139 }
140 
MirrorId() const141 ScreenId RSScreen::MirrorId() const
142 {
143     return mirrorId_;
144 }
145 
SetMirror(ScreenId mirrorId)146 void RSScreen::SetMirror(ScreenId mirrorId)
147 {
148     mirrorId_ = mirrorId;
149 }
150 
Name() const151 const std::string& RSScreen::Name() const
152 {
153     return name_;
154 }
155 
Width() const156 uint32_t RSScreen::Width() const
157 {
158     return width_;
159 }
160 
Height() const161 uint32_t RSScreen::Height() const
162 {
163     return height_;
164 }
165 
IsEnable() const166 bool RSScreen::IsEnable() const
167 {
168     if (id_ == INVALID_SCREEN_ID) {
169         return false;
170     }
171 
172     if (!hdiOutput_ && !producerSurface_) {
173         return false;
174     }
175 
176     // [PLANNING]: maybe need more information to judge whether this screen is enable.
177     return true;
178 }
179 
IsVirtual() const180 bool RSScreen::IsVirtual() const
181 {
182     return isVirtual_;
183 }
184 
SetActiveMode(uint32_t modeId)185 void RSScreen::SetActiveMode(uint32_t modeId)
186 {
187     if (IsVirtual()) {
188         RS_LOGW("RSScreen %s: virtual screen not support SetActiveMode.", __func__);
189         return;
190     }
191 
192     if (modeId >= supportedModes_.size()) {
193         RS_LOGE("RSScreen %s: set fails because the index is out of bounds.", __func__);
194         return;
195     }
196     int32_t selectModeId = supportedModes_[modeId].id;
197     if (hdiScreen_->SetScreenMode(static_cast<uint32_t>(selectModeId)) < 0) {
198         RS_LOGE("RSScreen %s: Hdi SetScreenMode fails.", __func__);
199         return;
200     }
201     auto activeMode = GetActiveMode();
202     if (activeMode) {
203         width_ = activeMode->width;
204         height_ = activeMode->height;
205         static GraphicDisplayModeInfo modeInfo;
206         if ((modeInfo.freshRate != activeMode->freshRate)
207             || modeInfo.width != activeMode->width || modeInfo.height != activeMode->height) {
208             HiSysEventWrite(HiSysEvent::Domain::GRAPHIC, "EPS_LCD_FREQ",
209                 HiSysEvent::EventType::STATISTIC, "SOURCERATE", modeInfo.freshRate,
210                 "TARGETRATE", activeMode->freshRate, "WIDTH", width_, "HEIGHT", height_);
211             modeInfo = activeMode.value();
212         }
213     }
214 }
215 
SetResolution(uint32_t width,uint32_t height)216 void RSScreen::SetResolution(uint32_t width, uint32_t height)
217 {
218     if (!IsVirtual()) {
219         RS_LOGW("RSScreen %s: physical screen not support SetResolution.", __func__);
220         return;
221     }
222     width_ = static_cast<int32_t>(width);
223     height_ = static_cast<int32_t>(height);
224 }
225 
GetActiveModePosByModeId(int32_t modeId) const226 int32_t RSScreen::GetActiveModePosByModeId(int32_t modeId) const
227 {
228     decltype(supportedModes_.size()) modeIndex = 0;
229     for (; modeIndex < supportedModes_.size(); ++modeIndex) {
230         if (supportedModes_[modeIndex].id == modeId) {
231             return static_cast<int32_t>(modeIndex);
232         }
233     }
234     return -1;
235 }
236 
SetPowerStatus(uint32_t powerStatus)237 void RSScreen::SetPowerStatus(uint32_t powerStatus)
238 {
239     if (IsVirtual()) {
240         RS_LOGW("RSScreen %s: virtual screen not support SetPowerStatus.", __func__);
241         return;
242     }
243 
244     RS_LOGD("RSScreen %s SetPowerStatus, status is %u", __func__, powerStatus);
245     if (hdiScreen_->SetScreenPowerStatus(static_cast<GraphicDispPowerStatus>(powerStatus)) < 0) {
246         return;
247     }
248 
249     if (powerStatus == GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON) {
250         RS_LOGD("RSScreen %s Enable hardware vsync", __func__);
251         if (hdiScreen_->SetScreenVsyncEnabled(true) != GRAPHIC_DISPLAY_SUCCESS) {
252             RS_LOGE("RSScreen %s SetScreenVsyncEnabled failed", __func__);
253         }
254     }
255 }
256 
GetActiveMode() const257 std::optional<GraphicDisplayModeInfo> RSScreen::GetActiveMode() const
258 {
259     if (IsVirtual()) {
260         RS_LOGW("RSScreen %s: virtual screen not support GetActiveMode.", __func__);
261         return {};
262     }
263 
264     uint32_t modeId = 0;
265 
266     if (hdiScreen_ == nullptr) {
267         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") hdiScreen is null.",
268             __func__, id_);
269         return {};
270     }
271 
272     if (hdiScreen_->GetScreenMode(modeId) < 0) {
273         RS_LOGE("RSScreen %s: RSScreen(id %" PRIu64 ") GetScreenMode failed.",
274             __func__, id_);
275         return {};
276     }
277 
278     auto iter = std::find_if(supportedModes_.cbegin(), supportedModes_.cend(),
279         [modeId](const auto &mode) { return static_cast<uint32_t>(mode.id) == modeId; });
280     if (iter == supportedModes_.cend()) {
281         return {};
282     }
283 
284     return *iter;
285 }
286 
GetSupportedModes() const287 const std::vector<GraphicDisplayModeInfo>& RSScreen::GetSupportedModes() const
288 {
289     return supportedModes_;
290 }
291 
GetCapability() const292 const GraphicDisplayCapability& RSScreen::GetCapability() const
293 {
294     return capability_;
295 }
296 
GetPowerStatus() const297 uint32_t RSScreen::GetPowerStatus() const
298 {
299     if (IsVirtual()) {
300         RS_LOGW("RSScreen %s: virtual screen not support GetPowerStatus.", __func__);
301         return ScreenPowerStatus::INVALID_POWER_STATUS;
302     }
303 
304     GraphicDispPowerStatus status;
305     if (hdiScreen_->GetScreenPowerStatus(status) < 0) {
306         return INVALID_POWER_STATUS;
307     }
308     return static_cast<uint32_t>(status);
309 }
310 
GetOutput() const311 std::shared_ptr<HdiOutput> RSScreen::GetOutput() const
312 {
313     return hdiOutput_;
314 }
315 
GetProducerSurface() const316 sptr<Surface> RSScreen::GetProducerSurface() const
317 {
318     return producerSurface_;
319 }
320 
SetProducerSurface(sptr<Surface> producerSurface)321 void RSScreen::SetProducerSurface(sptr<Surface> producerSurface)
322 {
323     producerSurface_ = producerSurface;
324 }
325 
ModeInfoDump(std::string & dumpString)326 void RSScreen::ModeInfoDump(std::string& dumpString)
327 {
328     decltype(supportedModes_.size()) modeIndex = 0;
329     for (; modeIndex < supportedModes_.size(); ++modeIndex) {
330         AppendFormat(dumpString, "  supportedMode[%d]: %dx%d, refreshrate=%d\n",
331                      modeIndex, supportedModes_[modeIndex].width,
332                      supportedModes_[modeIndex].height, supportedModes_[modeIndex].freshRate);
333     }
334     std::optional<GraphicDisplayModeInfo> activeMode = GetActiveMode();
335     if (activeMode) {
336         AppendFormat(dumpString, "  activeMode: %dx%d, refreshrate=%d\n",
337             activeMode->width, activeMode->height, activeMode->freshRate);
338     }
339 }
340 
CapabilityTypeDump(GraphicInterfaceType capabilityType,std::string & dumpString)341 void RSScreen::CapabilityTypeDump(GraphicInterfaceType capabilityType, std::string& dumpString)
342 {
343     dumpString += "type=";
344     switch (capabilityType) {
345         case GRAPHIC_DISP_INTF_HDMI: {
346             dumpString += "DISP_INTF_HDMI, ";
347             break;
348         }
349         case GRAPHIC_DISP_INTF_LCD: {
350             dumpString += "DISP_INTF_LCD, ";
351             break;
352         }
353         case GRAPHIC_DISP_INTF_BT1120: {
354             dumpString += "DISP_INTF_BT1120, ";
355             break;
356         }
357         case GRAPHIC_DISP_INTF_BT656: {
358             dumpString += "DISP_INTF_BT656, ";
359             break;
360         }
361         default:
362             dumpString += "INVILID_DISP_INTF, ";
363             break;
364     }
365 }
366 
CapabilityDump(std::string & dumpString)367 void RSScreen::CapabilityDump(std::string& dumpString)
368 {
369     AppendFormat(dumpString, "  capability: name=%s, phywidth=%d, phyheight=%d,"
370                  "supportlayers=%d, virtualDispCount=%d, propCount=%d, ",
371                  capability_.name.c_str(), capability_.phyWidth, capability_.phyHeight,
372                  capability_.supportLayers, capability_.virtualDispCount, capability_.propertyCount);
373     CapabilityTypeDump(capability_.type, dumpString);
374     dumpString += "supportWriteBack=";
375     dumpString += (capability_.supportWriteBack) ? "true" : "false";
376     dumpString += "\n";
377     PropDump(dumpString);
378 }
379 
PropDump(std::string & dumpString)380 void RSScreen::PropDump(std::string& dumpString)
381 {
382     decltype(capability_.propertyCount) propIndex = 0;
383     for (; propIndex < capability_.propertyCount; ++propIndex) {
384         AppendFormat(dumpString, "prop[%u]: name=%s, propid=%d, value=%d\n",
385                      propIndex, capability_.props[propIndex].name.c_str(), capability_.props[propIndex].propId,
386                      capability_.props[propIndex].value);
387     }
388 }
389 
PowerStatusDump(std::string & dumpString)390 void RSScreen::PowerStatusDump(std::string& dumpString)
391 {
392     dumpString += "powerstatus=";
393     switch (powerStatus_) {
394         case GRAPHIC_POWER_STATUS_ON: {
395             dumpString += "POWER_STATUS_ON";
396             break;
397         }
398         case GRAPHIC_POWER_STATUS_STANDBY: {
399             dumpString += "POWER_STATUS_STANDBY";
400             break;
401         }
402         case GRAPHIC_POWER_STATUS_SUSPEND: {
403             dumpString += "POWER_STATUS_SUSPEND";
404             break;
405         }
406         case GRAPHIC_POWER_STATUS_OFF: {
407             dumpString += "POWER_STATUS_OFF";
408             break;
409         }
410         case GRAPHIC_POWER_STATUS_BUTT: {
411             dumpString += "POWER_STATUS_BUTT";
412             break;
413         }
414         default: {
415             dumpString += "INVALID_POWER_STATUS";
416             break;
417         }
418     }
419 }
420 
421 
DisplayDump(int32_t screenIndex,std::string & dumpString)422 void RSScreen::DisplayDump(int32_t screenIndex, std::string& dumpString)
423 {
424     dumpString += "-- ScreenInfo\n";
425     if (IsVirtual()) {
426         dumpString += "screen[" + std::to_string(screenIndex) + "]: ";
427         dumpString += "id=";
428         dumpString += (id_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(id_);
429         dumpString += ", ";
430         dumpString += "mirrorId=";
431         dumpString += (mirrorId_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(mirrorId_);
432         dumpString += ", ";
433         AppendFormat(dumpString, "%dx%d, isvirtual=true\n", width_, height_);
434     } else {
435         dumpString += "screen[" + std::to_string(screenIndex) + "]: ";
436         dumpString += "id=";
437         dumpString += (id_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(id_);
438         dumpString += ", ";
439         PowerStatusDump(dumpString);
440         dumpString += ", ";
441         dumpString += "backlight=" + std::to_string(GetScreenBacklight());
442         dumpString += ", ";
443         ScreenTypeDump(dumpString);
444         dumpString += "\n";
445         ModeInfoDump(dumpString);
446         CapabilityDump(dumpString);
447     }
448 }
449 
ScreenTypeDump(std::string & dumpString)450 void RSScreen::ScreenTypeDump(std::string& dumpString)
451 {
452     dumpString += "screenType=";
453     switch (screenType_) {
454         case RSScreenType::BUILT_IN_TYPE_SCREEN: {
455             dumpString += "BUILT_IN_TYPE";
456             break;
457         }
458         case RSScreenType::EXTERNAL_TYPE_SCREEN: {
459             dumpString += "EXTERNAL_TYPE";
460             break;
461         }
462         case RSScreenType::VIRTUAL_TYPE_SCREEN: {
463             dumpString += "VIRTUAL_TYPE";
464             break;
465         }
466         default: {
467             dumpString += "UNKNOWN_TYPE";
468             break;
469         }
470     }
471 }
472 
SurfaceDump(int32_t screenIndex,std::string & dumpString)473 void RSScreen::SurfaceDump(int32_t screenIndex, std::string& dumpString)
474 {
475     if (hdiOutput_ == nullptr) {
476         RS_LOGW("RSScreen %s: hdiOutput_ is nullptr.", __func__);
477         return;
478     }
479     hdiOutput_->Dump(dumpString);
480 }
481 
FpsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)482 void RSScreen::FpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
483 {
484     if (hdiOutput_ == nullptr) {
485         RS_LOGW("RSScreen %s: hdiOutput_ is nullptr.", __func__);
486         return;
487     }
488     hdiOutput_->DumpFps(dumpString, arg);
489 }
490 
ClearFpsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)491 void RSScreen::ClearFpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
492 {
493     if (hdiOutput_ == nullptr) {
494         RS_LOGW("RSScreen %s: hdiOutput_ is nullptr.", __func__);
495         return;
496     }
497     hdiOutput_->ClearFpsDump(dumpString, arg);
498 }
499 
SetScreenBacklight(uint32_t level)500 void RSScreen::SetScreenBacklight(uint32_t level)
501 {
502     if (IsVirtual()) {
503         RS_LOGW("RSScreen %s: virtual screen not support SetScreenBacklight.", __func__);
504         return;
505     }
506     if (hdiScreen_->SetScreenBacklight(level) < 0) {
507         return;
508     }
509 }
510 
GetScreenBacklight() const511 int32_t RSScreen::GetScreenBacklight() const
512 {
513     if (IsVirtual()) {
514         RS_LOGW("RSScreen %s: virtual screen not support GetScreenBacklight.", __func__);
515         return INVALID_BACKLIGHT_VALUE;
516     }
517     uint32_t level = 0;
518     if (hdiScreen_->GetScreenBacklight(level) < 0) {
519         return INVALID_BACKLIGHT_VALUE;
520     }
521     return static_cast<int32_t>(level);
522 }
523 
GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> & mode) const524 int32_t RSScreen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> &mode) const
525 {
526     mode.clear();
527     if (IsVirtual()) {
528         mode = supportedVirtualColorGamuts_;
529     } else {
530         mode = supportedPhysicalColorGamuts_;
531     }
532     if (mode.size() == 0) {
533         return StatusCode::HDI_ERROR;
534     }
535     return StatusCode::SUCCESS;
536 }
537 
GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> & keys) const538 int32_t RSScreen::GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> &keys) const
539 {
540     if (IsVirtual()) {
541         RS_LOGW("RSScreen %s: virtual screen not support GetScreenSupportedMetaDataKeys.", __func__);
542         return INVALID_BACKLIGHT_VALUE;
543     }
544 
545     // ScreenHDRMetadataKey now is mock data.
546     keys.push_back(ScreenHDRMetadataKey::MATAKEY_RED_PRIMARY_X);
547     keys.push_back(ScreenHDRMetadataKey::MATAKEY_RED_PRIMARY_Y);
548     keys.push_back(ScreenHDRMetadataKey::MATAKEY_GREEN_PRIMARY_X);
549     keys.push_back(ScreenHDRMetadataKey::MATAKEY_GREEN_PRIMARY_Y);
550     keys.push_back(ScreenHDRMetadataKey::MATAKEY_BLUE_PRIMARY_X);
551     keys.push_back(ScreenHDRMetadataKey::MATAKEY_BLUE_PRIMARY_Y);
552     keys.push_back(ScreenHDRMetadataKey::MATAKEY_WHITE_PRIMARY_X);
553     keys.push_back(ScreenHDRMetadataKey::MATAKEY_WHITE_PRIMARY_Y);
554     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_LUMINANCE);
555     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MIN_LUMINANCE);
556     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_CONTENT_LIGHT_LEVEL);
557     keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL);
558     keys.push_back(ScreenHDRMetadataKey::MATAKEY_HDR10_PLUS);
559     keys.push_back(ScreenHDRMetadataKey::MATAKEY_HDR_VIVID);
560     return StatusCode::SUCCESS;
561 }
562 
GetScreenColorGamut(ScreenColorGamut & mode) const563 int32_t RSScreen::GetScreenColorGamut(ScreenColorGamut &mode) const
564 {
565     if (IsVirtual()) {
566         mode = supportedVirtualColorGamuts_[currentVirtualColorGamutIdx_];
567         return StatusCode::SUCCESS;
568     } else {
569         if (supportedPhysicalColorGamuts_.size() == 0) {
570             return StatusCode::HDI_ERROR;
571         }
572         mode = supportedPhysicalColorGamuts_[currentPhysicalColorGamutIdx_];
573         return StatusCode::SUCCESS;
574     }
575     return StatusCode::HDI_ERROR;
576 }
577 
SetScreenColorGamut(int32_t modeIdx)578 int32_t RSScreen::SetScreenColorGamut(int32_t modeIdx)
579 {
580     if (modeIdx < 0) {
581         return StatusCode::INVALID_ARGUMENTS;
582     }
583     if (IsVirtual()) {
584         if (modeIdx >= static_cast<int32_t>(supportedVirtualColorGamuts_.size())) {
585             return StatusCode::INVALID_ARGUMENTS;
586         }
587         currentVirtualColorGamutIdx_ = modeIdx;
588         return StatusCode::SUCCESS;
589     }
590     std::vector<GraphicColorGamut> hdiMode;
591     if (hdiScreen_->GetScreenSupportedColorGamuts(hdiMode) != GRAPHIC_DISPLAY_SUCCESS) {
592         return StatusCode::HDI_ERROR;
593     }
594     if (modeIdx >= static_cast<int32_t>(hdiMode.size())) {
595         return StatusCode::INVALID_ARGUMENTS;
596     }
597     int32_t result = hdiScreen_->SetScreenColorGamut(hdiMode[modeIdx]);
598     if (result == GRAPHIC_DISPLAY_SUCCESS) {
599         currentPhysicalColorGamutIdx_ = modeIdx;
600         return StatusCode::SUCCESS;
601     }
602     return StatusCode::HDI_ERROR;
603 }
604 
SetScreenGamutMap(ScreenGamutMap mode)605 int32_t RSScreen::SetScreenGamutMap(ScreenGamutMap mode)
606 {
607     if (IsVirtual()) {
608         currentVirtualGamutMap_ = mode;
609         return StatusCode::SUCCESS;
610     }
611     int32_t result = hdiScreen_->SetScreenGamutMap(static_cast<GraphicGamutMap>(mode));
612     if (result == GRAPHIC_DISPLAY_SUCCESS) {
613         return StatusCode::SUCCESS;
614     }
615     return StatusCode::HDI_ERROR;
616 }
617 
GetScreenGamutMap(ScreenGamutMap & mode) const618 int32_t RSScreen::GetScreenGamutMap(ScreenGamutMap &mode) const
619 {
620     if (IsVirtual()) {
621         mode = currentVirtualGamutMap_;
622         return StatusCode::SUCCESS;
623     }
624     GraphicGamutMap hdiMode;
625     int32_t result = hdiScreen_->GetScreenGamutMap(hdiMode);
626     if (result == GRAPHIC_DISPLAY_SUCCESS) {
627         mode = static_cast<ScreenGamutMap>(hdiMode);
628         return StatusCode::SUCCESS;
629     }
630     return StatusCode::HDI_ERROR;
631 }
632 
GetHDRCapability()633 const GraphicHDRCapability& RSScreen::GetHDRCapability()
634 {
635     hdrCapability_.maxLum = 1000; // mock data
636     return hdrCapability_;
637 }
638 
GetScreenType() const639 const RSScreenType& RSScreen::GetScreenType() const
640 {
641     return screenType_;
642 }
643 
SetScreenSkipFrameInterval(uint32_t skipFrameInterval)644 void RSScreen::SetScreenSkipFrameInterval(uint32_t skipFrameInterval)
645 {
646     skipFrameInterval_ = skipFrameInterval;
647 }
648 
GetScreenSkipFrameInterval() const649 uint32_t RSScreen::GetScreenSkipFrameInterval() const
650 {
651     return skipFrameInterval_;
652 }
653 
SetScreenVsyncEnabled(bool enabled) const654 void RSScreen::SetScreenVsyncEnabled(bool enabled) const
655 {
656     if (IsVirtual()) {
657         return;
658     }
659     if (hdiScreen_ != nullptr) {
660         hdiScreen_->SetScreenVsyncEnabled(enabled);
661     }
662 }
663 } // namespace impl
664 } // namespace Rosen
665 } // namespace OHOS
666