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
IsSamplingOn() const252 bool RSScreen::IsSamplingOn() const
253 {
254 return isSamplingOn_;
255 }
256
GetSamplingTranslateX() const257 float RSScreen::GetSamplingTranslateX() const
258 {
259 return samplingTranslateX_;
260 }
261
GetSamplingTranslateY() const262 float RSScreen::GetSamplingTranslateY() const
263 {
264 return samplingTranslateY_;
265 }
266
GetSamplingScale() const267 float RSScreen::GetSamplingScale() const
268 {
269 return samplingScale_;
270 }
271
GetActiveRect() const272 RectI RSScreen::GetActiveRect() const
273 {
274 return activeRect_;
275 }
276
IsEnable() const277 bool RSScreen::IsEnable() const
278 {
279 if (id_ == INVALID_SCREEN_ID) {
280 return false;
281 }
282
283 if (!hdiOutput_ && !producerSurface_) {
284 return false;
285 }
286
287 // [PLANNING]: maybe need more information to judge whether this screen is enable.
288 return true;
289 }
290
IsVirtual() const291 bool RSScreen::IsVirtual() const
292 {
293 return isVirtual_;
294 }
295
SetActiveMode(uint32_t modeId)296 void RSScreen::SetActiveMode(uint32_t modeId)
297 {
298 if (IsVirtual()) {
299 RS_LOGW("RSScreen %{public}s: virtual screen not support SetActiveMode.", __func__);
300 return;
301 }
302 if (!hdiScreen_) {
303 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
304 return;
305 }
306
307 if (modeId >= supportedModes_.size()) {
308 RS_LOGE("RSScreen %{public}s: set fails because the index is out of bounds.", __func__);
309 return;
310 }
311 RS_LOGD_IF(DEBUG_SCREEN, "RSScreen set active mode: %{public}u", modeId);
312 int32_t selectModeId = supportedModes_[modeId].id;
313 if (hdiScreen_->SetScreenMode(static_cast<uint32_t>(selectModeId)) < 0) {
314 RS_LOGE("RSScreen %{public}s: Hdi SetScreenMode fails.", __func__);
315 return;
316 }
317 auto activeMode = GetActiveMode();
318 if (activeMode) {
319 phyWidth_ = activeMode->width;
320 phyHeight_ = activeMode->height;
321 static GraphicDisplayModeInfo modeInfo;
322 if ((modeInfo.freshRate != activeMode->freshRate)
323 || modeInfo.width != activeMode->width || modeInfo.height != activeMode->height) {
324 HiSysEventWrite(HiSysEvent::Domain::GRAPHIC, "EPS_LCD_FREQ",
325 HiSysEvent::EventType::STATISTIC, "SOURCERATE", modeInfo.freshRate,
326 "TARGETRATE", activeMode->freshRate, "WIDTH", phyWidth_, "HEIGHT", phyHeight_);
327 modeInfo = activeMode.value();
328 }
329 }
330 }
331
SetScreenActiveRect(const GraphicIRect & activeRect)332 uint32_t RSScreen::SetScreenActiveRect(const GraphicIRect& activeRect)
333 {
334 if (IsVirtual()) {
335 RS_LOGW("RSScreen %{public}s failed: virtual screen not support", __func__);
336 return StatusCode::HDI_ERROR;
337 }
338 if (hdiScreen_ == nullptr) {
339 RS_LOGE("RSScreen %{public}s failed: hdiScreen_ is nullptr", __func__);
340 return StatusCode::HDI_ERROR;
341 }
342
343 if (hdiScreen_->SetScreenActiveRect(activeRect) < 0) {
344 RS_LOGE("RSScreen %{public}s failed: hdi SetScreenActiveRect failed, "
345 "activeRect: (%{public}" PRId32 ", %{public}" PRId32 ", %{public}" PRId32 ", %{public}" PRId32 ")",
346 __func__, activeRect.x, activeRect.y, activeRect.w, activeRect.h);
347 return StatusCode::HDI_ERROR;
348 }
349
350 activeRect_ = RectI(activeRect.x, activeRect.y, activeRect.w, activeRect.h);
351 RS_LOGI("RSScreen %{public}s success, activeRect: (%{public}" PRId32 ", %{public}" PRId32 ", "
352 "%{public}" PRId32 ", %{public}" PRId32 ")", __func__, activeRect.x, activeRect.y, activeRect.w, activeRect.h);
353 return StatusCode::SUCCESS;
354 }
355
SetRogResolution(uint32_t width,uint32_t height)356 void RSScreen::SetRogResolution(uint32_t width, uint32_t height)
357 {
358 if (!hdiScreen_) {
359 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
360 return;
361 }
362 if ((width == 0 || height == 0) ||
363 (width == width_ && height == height_) ||
364 (width > phyWidth_ || height > phyHeight_)) {
365 RS_LOGD("RSScreen:%{public}s: width: %{public}d, height: %{public}d.", __func__, width, height);
366 return;
367 }
368 if (hdiScreen_->SetScreenOverlayResolution(width, height) < 0) {
369 RS_LOGD("RSScreen:%{public}s: hdi set screen rog resolution failed.", __func__);
370 }
371 width_ = width;
372 height_ = height;
373 RS_LOGI("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 "), width: %{public}d,"
374 " height: %{public}d, phywidth: %{public}d, phyHeight: %{public}d.",
375 __func__, id_, width_, height_, phyWidth_, phyHeight_);
376 }
377
SetResolution(uint32_t width,uint32_t height)378 int32_t RSScreen::SetResolution(uint32_t width, uint32_t height)
379 {
380 RS_LOGI("RSScreen set resolution [%{public}u * %{public}u]", width, height);
381 if (IsVirtual()) {
382 width_ = width;
383 height_ = height;
384 return StatusCode::SUCCESS;
385 }
386 if (width < phyWidth_ || height < phyHeight_) {
387 return StatusCode::INVALID_ARGUMENTS;
388 }
389 width_ = width;
390 height_ = height;
391 isSamplingOn_ = width > phyWidth_ || height > phyHeight_;
392 if (isSamplingOn_ && width_ > 0 && height_ > 0) {
393 samplingScale_ = std::min(static_cast<float>(phyWidth_) / width_,
394 static_cast<float>(phyHeight_) / height_);
395 samplingTranslateX_ = (phyWidth_ - width_ * samplingScale_) / 2.f;
396 samplingTranslateY_ = (phyHeight_ - height_ * samplingScale_) / 2.f;
397 RS_LOGI("RSScreen %{public}s: sampling is enabled. "
398 "scale: %{public}f, translateX: %{public}f, translateY: %{public}f",
399 __func__, samplingScale_, samplingTranslateX_, samplingTranslateY_);
400 }
401 return StatusCode::SUCCESS;
402 }
403
GetActiveModePosByModeId(int32_t modeId) const404 int32_t RSScreen::GetActiveModePosByModeId(int32_t modeId) const
405 {
406 decltype(supportedModes_.size()) modeIndex = 0;
407 for (; modeIndex < supportedModes_.size(); ++modeIndex) {
408 if (supportedModes_[modeIndex].id == modeId) {
409 return static_cast<int32_t>(modeIndex);
410 }
411 }
412 return -1;
413 }
414
SetPowerStatus(uint32_t powerStatus)415 void RSScreen::SetPowerStatus(uint32_t powerStatus)
416 {
417 if (!hdiScreen_) {
418 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
419 return;
420 }
421 if (IsVirtual()) {
422 RS_LOGW("[UL_POWER]RSScreen %{public}s: virtual screen not support SetPowerStatus.", __func__);
423 return;
424 }
425
426 RS_LOGI("[UL_POWER]RSScreen_%{public}" PRIu64 " SetPowerStatus, status is %{public}u", id_, powerStatus);
427 RS_TRACE_NAME_FMT("[UL_POWER]Screen_%llu SetPowerStatus %u", id_, powerStatus);
428 if (hdiScreen_->SetScreenPowerStatus(static_cast<GraphicDispPowerStatus>(powerStatus)) < 0) {
429 return;
430 }
431
432 if (powerStatus == GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON ||
433 powerStatus == GraphicDispPowerStatus::GRAPHIC_POWER_STATUS_ON_ADVANCED) {
434 RS_LOGD("RSScreen %{public}s Enable hardware vsync", __func__);
435 if (hdiScreen_->SetScreenVsyncEnabled(true) != GRAPHIC_DISPLAY_SUCCESS) {
436 RS_LOGE("RSScreen %{public}s SetScreenVsyncEnabled failed", __func__);
437 }
438 }
439 }
440
GetActiveMode() const441 std::optional<GraphicDisplayModeInfo> RSScreen::GetActiveMode() const
442 {
443 if (IsVirtual()) {
444 RS_LOGW("RSScreen %{public}s: virtual screen not support GetActiveMode.", __func__);
445 return {};
446 }
447
448 uint32_t modeId = 0;
449
450 if (hdiScreen_ == nullptr) {
451 RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") hdiScreen is null.",
452 __func__, id_);
453 return {};
454 }
455
456 if (hdiScreen_->GetScreenMode(modeId) < 0) {
457 RS_LOGE("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") GetScreenMode failed.",
458 __func__, id_);
459 return {};
460 }
461
462 auto iter = std::find_if(supportedModes_.cbegin(), supportedModes_.cend(),
463 [modeId](const auto &mode) { return static_cast<uint32_t>(mode.id) == modeId; });
464 if (iter == supportedModes_.cend()) {
465 return {};
466 }
467
468 return *iter;
469 }
470
GetSupportedModes() const471 const std::vector<GraphicDisplayModeInfo>& RSScreen::GetSupportedModes() const
472 {
473 return supportedModes_;
474 }
475
GetCapability() const476 const GraphicDisplayCapability& RSScreen::GetCapability() const
477 {
478 return capability_;
479 }
480
GetPowerStatus() const481 uint32_t RSScreen::GetPowerStatus() const
482 {
483 if (IsVirtual()) {
484 RS_LOGW("RSScreen %{public}s: virtual screen not support GetPowerStatus.", __func__);
485 return ScreenPowerStatus::INVALID_POWER_STATUS;
486 }
487
488 if (!hdiScreen_) {
489 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
490 return INVALID_POWER_STATUS;
491 }
492 GraphicDispPowerStatus status;
493 if (!hdiScreen_) {
494 RS_LOGW("RSScreen %{public}s: hdiScreen_ is nullptr.", __func__);
495 return INVALID_POWER_STATUS;
496 }
497 if (hdiScreen_->GetScreenPowerStatus(status) < 0) {
498 return INVALID_POWER_STATUS;
499 }
500 return static_cast<uint32_t>(status);
501 }
502
GetOutput() const503 std::shared_ptr<HdiOutput> RSScreen::GetOutput() const
504 {
505 return hdiOutput_;
506 }
507
GetProducerSurface() const508 sptr<Surface> RSScreen::GetProducerSurface() const
509 {
510 return producerSurface_;
511 }
512
SetProducerSurface(sptr<Surface> producerSurface)513 void RSScreen::SetProducerSurface(sptr<Surface> producerSurface)
514 {
515 producerSurface_ = producerSurface;
516 isVirtualSurfaceUpdateFlag_ = true;
517 }
518
GetAndResetVirtualSurfaceUpdateFlag()519 bool RSScreen::GetAndResetVirtualSurfaceUpdateFlag()
520 {
521 if (isVirtualSurfaceUpdateFlag_) {
522 isVirtualSurfaceUpdateFlag_ = false;
523 return true;
524 }
525 return false;
526 }
527
ModeInfoDump(std::string & dumpString)528 void RSScreen::ModeInfoDump(std::string& dumpString)
529 {
530 decltype(supportedModes_.size()) modeIndex = 0;
531 for (; modeIndex < supportedModes_.size(); ++modeIndex) {
532 AppendFormat(dumpString, " supportedMode[%d]: %dx%d, refreshrate=%d\n",
533 modeIndex, supportedModes_[modeIndex].width,
534 supportedModes_[modeIndex].height, supportedModes_[modeIndex].freshRate);
535 }
536 std::optional<GraphicDisplayModeInfo> activeMode = GetActiveMode();
537 if (activeMode) {
538 AppendFormat(dumpString, " activeMode: %dx%d, refreshrate=%d\n",
539 activeMode->width, activeMode->height, activeMode->freshRate);
540 }
541 }
542
CapabilityTypeDump(GraphicInterfaceType capabilityType,std::string & dumpString)543 void RSScreen::CapabilityTypeDump(GraphicInterfaceType capabilityType, std::string& dumpString)
544 {
545 dumpString += "type=";
546 switch (capabilityType) {
547 case GRAPHIC_DISP_INTF_HDMI: {
548 dumpString += "DISP_INTF_HDMI, ";
549 break;
550 }
551 case GRAPHIC_DISP_INTF_LCD: {
552 dumpString += "DISP_INTF_LCD, ";
553 break;
554 }
555 case GRAPHIC_DISP_INTF_BT1120: {
556 dumpString += "DISP_INTF_BT1120, ";
557 break;
558 }
559 case GRAPHIC_DISP_INTF_BT656: {
560 dumpString += "DISP_INTF_BT656, ";
561 break;
562 }
563 default:
564 dumpString += "INVILID_DISP_INTF, ";
565 break;
566 }
567 }
568
CapabilityDump(std::string & dumpString)569 void RSScreen::CapabilityDump(std::string& dumpString)
570 {
571 AppendFormat(dumpString, " capability: name=%s, phywidth=%d, phyheight=%d,"
572 "supportlayers=%d, virtualDispCount=%d, propCount=%d, ",
573 capability_.name.c_str(), capability_.phyWidth, capability_.phyHeight,
574 capability_.supportLayers, capability_.virtualDispCount, capability_.propertyCount);
575 CapabilityTypeDump(capability_.type, dumpString);
576 dumpString += "supportWriteBack=";
577 dumpString += (capability_.supportWriteBack) ? "true" : "false";
578 dumpString += "\n";
579 PropDump(dumpString);
580 }
581
PropDump(std::string & dumpString)582 void RSScreen::PropDump(std::string& dumpString)
583 {
584 decltype(capability_.propertyCount) propIndex = 0;
585 for (; propIndex < capability_.propertyCount; ++propIndex) {
586 AppendFormat(dumpString, "prop[%u]: name=%s, propid=%d, value=%d\n",
587 propIndex, capability_.props[propIndex].name.c_str(), capability_.props[propIndex].propId,
588 capability_.props[propIndex].value);
589 }
590 }
591
PowerStatusDump(std::string & dumpString)592 void RSScreen::PowerStatusDump(std::string& dumpString)
593 {
594 dumpString += "powerstatus=";
595 switch (GetPowerStatus()) {
596 case GRAPHIC_POWER_STATUS_ON: {
597 dumpString += "POWER_STATUS_ON";
598 break;
599 }
600 case GRAPHIC_POWER_STATUS_STANDBY: {
601 dumpString += "POWER_STATUS_STANDBY";
602 break;
603 }
604 case GRAPHIC_POWER_STATUS_SUSPEND: {
605 dumpString += "POWER_STATUS_SUSPEND";
606 break;
607 }
608 case GRAPHIC_POWER_STATUS_OFF: {
609 dumpString += "POWER_STATUS_OFF";
610 break;
611 }
612 case GRAPHIC_POWER_STATUS_OFF_FAKE: {
613 dumpString += "POWER_STATUS_OFF_FAKE";
614 break;
615 }
616 case GRAPHIC_POWER_STATUS_BUTT: {
617 dumpString += "POWER_STATUS_BUTT";
618 break;
619 }
620 case GRAPHIC_POWER_STATUS_ON_ADVANCED: {
621 dumpString += "POWER_STATUS_ON_ADVANCED";
622 break;
623 }
624 case GRAPHIC_POWER_STATUS_OFF_ADVANCED: {
625 dumpString += "POWER_STATUS_OFF_ADVANCED";
626 break;
627 }
628 default: {
629 dumpString += "INVALID_POWER_STATUS";
630 break;
631 }
632 }
633 }
634
635
DisplayDump(int32_t screenIndex,std::string & dumpString)636 void RSScreen::DisplayDump(int32_t screenIndex, std::string& dumpString)
637 {
638 dumpString += "-- ScreenInfo\n";
639 if (IsVirtual()) {
640 dumpString += "screen[" + std::to_string(screenIndex) + "]: ";
641 dumpString += "id=";
642 dumpString += (id_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(id_);
643 dumpString += ", ";
644 dumpString += "mirrorId=";
645 dumpString += (mirrorId_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(mirrorId_);
646 dumpString += ", ";
647 AppendFormat(dumpString, ", render size: %dx%d, isvirtual=true, skipFrameInterval_:%d"
648 ", expectedRefreshRate_:%d, skipFrameStrategy_:%d\n",
649 width_, height_, skipFrameInterval_, expectedRefreshRate_, skipFrameStrategy_);
650 } else {
651 dumpString += "screen[" + std::to_string(screenIndex) + "]: ";
652 dumpString += "id=";
653 dumpString += (id_ == INVALID_SCREEN_ID) ? "INVALID_SCREEN_ID" : std::to_string(id_);
654 dumpString += ", ";
655 PowerStatusDump(dumpString);
656 dumpString += ", ";
657 dumpString += "backlight=" + std::to_string(GetScreenBacklight());
658 dumpString += ", ";
659 ScreenTypeDump(dumpString);
660 AppendFormat(dumpString,
661 ", render size: %dx%d, physical screen resolution: %dx%d, isvirtual=false, skipFrameInterval_:%d"
662 ", expectedRefreshRate_:%d, skipFrameStrategy_:%d\n",
663 width_, height_, phyWidth_, phyHeight_, skipFrameInterval_, expectedRefreshRate_, skipFrameStrategy_);
664 dumpString += "\n";
665 ModeInfoDump(dumpString);
666 CapabilityDump(dumpString);
667 }
668 }
669
ScreenTypeDump(std::string & dumpString)670 void RSScreen::ScreenTypeDump(std::string& dumpString)
671 {
672 dumpString += "screenType=";
673 switch (screenType_) {
674 case RSScreenType::BUILT_IN_TYPE_SCREEN: {
675 dumpString += "BUILT_IN_TYPE";
676 break;
677 }
678 case RSScreenType::EXTERNAL_TYPE_SCREEN: {
679 dumpString += "EXTERNAL_TYPE";
680 break;
681 }
682 case RSScreenType::VIRTUAL_TYPE_SCREEN: {
683 dumpString += "VIRTUAL_TYPE";
684 break;
685 }
686 default: {
687 dumpString += "UNKNOWN_TYPE";
688 break;
689 }
690 }
691 }
692
SurfaceDump(int32_t screenIndex,std::string & dumpString)693 void RSScreen::SurfaceDump(int32_t screenIndex, std::string& dumpString)
694 {
695 if (hdiOutput_ == nullptr) {
696 RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
697 return;
698 }
699 hdiOutput_->Dump(dumpString);
700 }
701
FpsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)702 void RSScreen::FpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
703 {
704 if (hdiOutput_ == nullptr) {
705 RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
706 return;
707 }
708 hdiOutput_->DumpFps(dumpString, arg);
709 }
710
ClearFpsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)711 void RSScreen::ClearFpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
712 {
713 if (hdiOutput_ == nullptr) {
714 RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
715 return;
716 }
717 hdiOutput_->ClearFpsDump(dumpString, arg);
718 }
719
HitchsDump(int32_t screenIndex,std::string & dumpString,std::string & arg)720 void RSScreen::HitchsDump(int32_t screenIndex, std::string& dumpString, std::string& arg)
721 {
722 if (hdiOutput_ == nullptr) {
723 RS_LOGW("RSScreen %{public}s: hdiOutput_ is nullptr.", __func__);
724 return;
725 }
726 hdiOutput_->DumpHitchs(dumpString, arg);
727 }
728
ResizeVirtualScreen(uint32_t width,uint32_t height)729 void RSScreen::ResizeVirtualScreen(uint32_t width, uint32_t height)
730 {
731 if (!IsVirtual()) {
732 RS_LOGW("RSScreen %{public}s: physical screen not support ResizeVirtualScreen.", __func__);
733 return;
734 }
735 width_ = width;
736 height_ = height;
737 }
738
SetScreenBacklight(uint32_t level)739 void RSScreen::SetScreenBacklight(uint32_t level)
740 {
741 if (!hdiScreen_) {
742 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
743 return;
744 }
745 if (IsVirtual()) {
746 RS_LOGW("RSScreen %{public}s: virtual screen not support SetScreenBacklight.", __func__);
747 return;
748 }
749
750 RS_LOGD("RSScreen_%{public}" PRIu64 " SetScreenBacklight, level is %{public}u", id_, level);
751 if (hdiScreen_->SetScreenBacklight(level) < 0) {
752 return;
753 }
754 screenBacklightLevel_ = static_cast<int32_t>(level);
755 }
756
GetScreenBacklight() const757 int32_t RSScreen::GetScreenBacklight() const
758 {
759 if (IsVirtual()) {
760 RS_LOGW("RSScreen %{public}s: virtual screen not support GetScreenBacklight.", __func__);
761 return INVALID_BACKLIGHT_VALUE;
762 }
763 uint32_t level = 0;
764 if (screenBacklightLevel_ != INVALID_BACKLIGHT_VALUE) {
765 return screenBacklightLevel_;
766 }
767 if (!hdiScreen_) {
768 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
769 return INVALID_BACKLIGHT_VALUE;
770 }
771 if (hdiScreen_->GetScreenBacklight(level) < 0) {
772 return INVALID_BACKLIGHT_VALUE;
773 }
774 return static_cast<int32_t>(level);
775 }
776
GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> & mode) const777 int32_t RSScreen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> &mode) const
778 {
779 mode.clear();
780 if (IsVirtual()) {
781 mode = supportedVirtualColorGamuts_;
782 } else {
783 mode = supportedPhysicalColorGamuts_;
784 }
785 if (mode.size() == 0) {
786 return StatusCode::HDI_ERROR;
787 }
788 return StatusCode::SUCCESS;
789 }
790
GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> & keys) const791 int32_t RSScreen::GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> &keys) const
792 {
793 if (IsVirtual()) {
794 RS_LOGW("RSScreen %{public}s: virtual screen not support GetScreenSupportedMetaDataKeys.", __func__);
795 return INVALID_BACKLIGHT_VALUE;
796 }
797
798 // ScreenHDRMetadataKey now is mock data.
799 keys.push_back(ScreenHDRMetadataKey::MATAKEY_RED_PRIMARY_X);
800 keys.push_back(ScreenHDRMetadataKey::MATAKEY_RED_PRIMARY_Y);
801 keys.push_back(ScreenHDRMetadataKey::MATAKEY_GREEN_PRIMARY_X);
802 keys.push_back(ScreenHDRMetadataKey::MATAKEY_GREEN_PRIMARY_Y);
803 keys.push_back(ScreenHDRMetadataKey::MATAKEY_BLUE_PRIMARY_X);
804 keys.push_back(ScreenHDRMetadataKey::MATAKEY_BLUE_PRIMARY_Y);
805 keys.push_back(ScreenHDRMetadataKey::MATAKEY_WHITE_PRIMARY_X);
806 keys.push_back(ScreenHDRMetadataKey::MATAKEY_WHITE_PRIMARY_Y);
807 keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_LUMINANCE);
808 keys.push_back(ScreenHDRMetadataKey::MATAKEY_MIN_LUMINANCE);
809 keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_CONTENT_LIGHT_LEVEL);
810 keys.push_back(ScreenHDRMetadataKey::MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL);
811 keys.push_back(ScreenHDRMetadataKey::MATAKEY_HDR10_PLUS);
812 keys.push_back(ScreenHDRMetadataKey::MATAKEY_HDR_VIVID);
813 return StatusCode::SUCCESS;
814 }
815
GetScreenColorGamut(ScreenColorGamut & mode) const816 int32_t RSScreen::GetScreenColorGamut(ScreenColorGamut &mode) const
817 {
818 if (IsVirtual()) {
819 mode = supportedVirtualColorGamuts_[currentVirtualColorGamutIdx_];
820 return StatusCode::SUCCESS;
821 } else {
822 if (supportedPhysicalColorGamuts_.size() == 0) {
823 return StatusCode::HDI_ERROR;
824 }
825 mode = supportedPhysicalColorGamuts_[currentPhysicalColorGamutIdx_];
826 return StatusCode::SUCCESS;
827 }
828 return StatusCode::HDI_ERROR;
829 }
830
SetScreenColorGamut(int32_t modeIdx)831 int32_t RSScreen::SetScreenColorGamut(int32_t modeIdx)
832 {
833 if (modeIdx < 0) {
834 return StatusCode::INVALID_ARGUMENTS;
835 }
836 if (IsVirtual()) {
837 if (modeIdx >= static_cast<int32_t>(supportedVirtualColorGamuts_.size())) {
838 return StatusCode::INVALID_ARGUMENTS;
839 }
840 currentVirtualColorGamutIdx_ = modeIdx;
841 return StatusCode::SUCCESS;
842 }
843 if (!hdiScreen_) {
844 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
845 return StatusCode::HDI_ERROR;
846 }
847 std::vector<GraphicColorGamut> hdiMode;
848 if (hdiScreen_->GetScreenSupportedColorGamuts(hdiMode) != GRAPHIC_DISPLAY_SUCCESS) {
849 return StatusCode::HDI_ERROR;
850 }
851 if (modeIdx >= static_cast<int32_t>(hdiMode.size())) {
852 return StatusCode::INVALID_ARGUMENTS;
853 }
854 int32_t result = hdiScreen_->SetScreenColorGamut(hdiMode[modeIdx]);
855 if (result == GRAPHIC_DISPLAY_SUCCESS) {
856 currentPhysicalColorGamutIdx_ = modeIdx;
857 return StatusCode::SUCCESS;
858 }
859 return StatusCode::HDI_ERROR;
860 }
861
SetScreenGamutMap(ScreenGamutMap mode)862 int32_t RSScreen::SetScreenGamutMap(ScreenGamutMap mode)
863 {
864 if (IsVirtual()) {
865 currentVirtualGamutMap_ = mode;
866 return StatusCode::SUCCESS;
867 }
868 if (!hdiScreen_) {
869 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
870 return StatusCode::HDI_ERROR;
871 }
872 int32_t result = hdiScreen_->SetScreenGamutMap(static_cast<GraphicGamutMap>(mode));
873 if (result == GRAPHIC_DISPLAY_SUCCESS) {
874 return StatusCode::SUCCESS;
875 }
876 return StatusCode::HDI_ERROR;
877 }
878
SetScreenCorrection(ScreenRotation screenRotation)879 void RSScreen::SetScreenCorrection(ScreenRotation screenRotation)
880 {
881 RS_LOGD("RSScreen %{public}s: RSScreen(id %{public}" PRIu64 ") ,ScreenRotation: %{public}d.",
882 __func__, id_, static_cast<uint32_t>(screenRotation));
883 screenRotation_ = screenRotation;
884 }
885
GetScreenCorrection() const886 ScreenRotation RSScreen::GetScreenCorrection() const
887 {
888 return screenRotation_;
889 }
890
GetScreenGamutMap(ScreenGamutMap & mode) const891 int32_t RSScreen::GetScreenGamutMap(ScreenGamutMap &mode) const
892 {
893 if (IsVirtual()) {
894 mode = currentVirtualGamutMap_;
895 return StatusCode::SUCCESS;
896 }
897 if (!hdiScreen_) {
898 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
899 return StatusCode::HDI_ERROR;
900 }
901 GraphicGamutMap hdiMode;
902 int32_t result = hdiScreen_->GetScreenGamutMap(hdiMode);
903 if (result == GRAPHIC_DISPLAY_SUCCESS) {
904 mode = static_cast<ScreenGamutMap>(hdiMode);
905 return StatusCode::SUCCESS;
906 }
907 return StatusCode::HDI_ERROR;
908 }
909
GetHDRCapability()910 const GraphicHDRCapability& RSScreen::GetHDRCapability()
911 {
912 hdrCapability_.maxLum = MAX_LUM; // mock data
913 return hdrCapability_;
914 }
915
GetScreenType() const916 const RSScreenType& RSScreen::GetScreenType() const
917 {
918 return screenType_;
919 }
920
SetScreenSkipFrameInterval(uint32_t skipFrameInterval)921 void RSScreen::SetScreenSkipFrameInterval(uint32_t skipFrameInterval)
922 {
923 std::lock_guard<std::mutex> lock(skipFrameMutex_);
924 skipFrameInterval_ = skipFrameInterval;
925 skipFrameStrategy_ = SKIP_FRAME_BY_INTERVAL;
926 }
927
SetScreenExpectedRefreshRate(uint32_t expectedRefreshRate)928 void RSScreen::SetScreenExpectedRefreshRate(uint32_t expectedRefreshRate)
929 {
930 std::lock_guard<std::mutex> lock(skipFrameMutex_);
931 expectedRefreshRate_ = expectedRefreshRate;
932 skipFrameStrategy_ = SKIP_FRAME_BY_REFRESH_RATE;
933 }
934
SetEqualVsyncPeriod(bool isEqualVsyncPeriod)935 void RSScreen::SetEqualVsyncPeriod(bool isEqualVsyncPeriod)
936 {
937 std::lock_guard<std::mutex> lock(skipFrameMutex_);
938 isEqualVsyncPeriod_ = isEqualVsyncPeriod;
939 }
940
GetScreenSkipFrameInterval() const941 uint32_t RSScreen::GetScreenSkipFrameInterval() const
942 {
943 std::lock_guard<std::mutex> lock(skipFrameMutex_);
944 return skipFrameInterval_;
945 }
946
GetScreenExpectedRefreshRate() const947 uint32_t RSScreen::GetScreenExpectedRefreshRate() const
948 {
949 std::lock_guard<std::mutex> lock(skipFrameMutex_);
950 return expectedRefreshRate_;
951 }
952
GetScreenSkipFrameStrategy() const953 SkipFrameStrategy RSScreen::GetScreenSkipFrameStrategy() const
954 {
955 std::lock_guard<std::mutex> lock(skipFrameMutex_);
956 return skipFrameStrategy_;
957 }
958
GetEqualVsyncPeriod() const959 bool RSScreen::GetEqualVsyncPeriod() const
960 {
961 std::lock_guard<std::mutex> lock(skipFrameMutex_);
962 return isEqualVsyncPeriod_;
963 }
964
SetScreenVsyncEnabled(bool enabled) const965 void RSScreen::SetScreenVsyncEnabled(bool enabled) const
966 {
967 if (IsVirtual()) {
968 return;
969 }
970 if (hdiScreen_ != nullptr) {
971 hdiScreen_->SetScreenVsyncEnabled(enabled);
972 }
973 }
974
SetVirtualMirrorScreenCanvasRotation(bool canvasRotation)975 bool RSScreen::SetVirtualMirrorScreenCanvasRotation(bool canvasRotation)
976 {
977 if (IsVirtual()) {
978 canvasRotation_ = canvasRotation;
979 return true;
980 }
981 return false;
982 }
983
GetCanvasRotation() const984 bool RSScreen::GetCanvasRotation() const
985 {
986 return canvasRotation_;
987 }
988
SetVirtualMirrorScreenScaleMode(ScreenScaleMode scaleMode)989 bool RSScreen::SetVirtualMirrorScreenScaleMode(ScreenScaleMode scaleMode)
990 {
991 if (IsVirtual()) {
992 scaleMode_ = scaleMode;
993 return true;
994 }
995 return false;
996 }
997
GetScaleMode() const998 ScreenScaleMode RSScreen::GetScaleMode() const
999 {
1000 return scaleMode_;
1001 }
1002
GetScreenSupportedHDRFormats(std::vector<ScreenHDRFormat> & hdrFormats) const1003 int32_t RSScreen::GetScreenSupportedHDRFormats(std::vector<ScreenHDRFormat>& hdrFormats) const
1004 {
1005 hdrFormats.clear();
1006 if (IsVirtual()) {
1007 hdrFormats = supportedVirtualHDRFormats_;
1008 } else {
1009 hdrFormats = supportedPhysicalHDRFormats_;
1010 }
1011 if (hdrFormats.size() == 0) {
1012 return StatusCode::HDI_ERROR;
1013 }
1014 return StatusCode::SUCCESS;
1015 }
1016
GetScreenHDRFormat(ScreenHDRFormat & hdrFormat) const1017 int32_t RSScreen::GetScreenHDRFormat(ScreenHDRFormat& hdrFormat) const
1018 {
1019 if (IsVirtual()) {
1020 hdrFormat = supportedVirtualHDRFormats_[currentVirtualHDRFormatIdx_];
1021 return StatusCode::SUCCESS;
1022 } else {
1023 if (supportedPhysicalHDRFormats_.size() == 0) {
1024 return StatusCode::HDI_ERROR;
1025 }
1026 hdrFormat = supportedPhysicalHDRFormats_[currentPhysicalHDRFormatIdx_];
1027 return StatusCode::SUCCESS;
1028 }
1029 return StatusCode::HDI_ERROR;
1030 }
1031
SetScreenHDRFormat(int32_t modeIdx)1032 int32_t RSScreen::SetScreenHDRFormat(int32_t modeIdx)
1033 {
1034 if (modeIdx < 0) {
1035 return StatusCode::INVALID_ARGUMENTS;
1036 }
1037 if (IsVirtual()) {
1038 if (modeIdx >= static_cast<int32_t>(supportedVirtualHDRFormats_.size())) {
1039 return StatusCode::INVALID_ARGUMENTS;
1040 }
1041 currentVirtualHDRFormatIdx_ = modeIdx;
1042 return StatusCode::SUCCESS;
1043 } else {
1044 // There should be some hdi operation
1045 if (modeIdx >= static_cast<int32_t>(hdrCapability_.formats.size())) {
1046 return StatusCode::INVALID_ARGUMENTS;
1047 }
1048 currentPhysicalHDRFormatIdx_ = modeIdx;
1049 return StatusCode::SUCCESS;
1050 }
1051 return StatusCode::HDI_ERROR;
1052 }
1053
GetPixelFormat(GraphicPixelFormat & pixelFormat) const1054 int32_t RSScreen::GetPixelFormat(GraphicPixelFormat& pixelFormat) const
1055 {
1056 pixelFormat = pixelFormat_;
1057 return StatusCode::SUCCESS;
1058 }
1059
SetPixelFormat(GraphicPixelFormat pixelFormat)1060 int32_t RSScreen::SetPixelFormat(GraphicPixelFormat pixelFormat)
1061 {
1062 pixelFormat_ = pixelFormat;
1063 return StatusCode::SUCCESS;
1064 }
1065
GetScreenSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType> & colorSpaces) const1066 int32_t RSScreen::GetScreenSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType>& colorSpaces) const
1067 {
1068 colorSpaces.clear();
1069 if (IsVirtual()) {
1070 std::transform(supportedVirtualColorGamuts_.begin(), supportedVirtualColorGamuts_.end(),
1071 back_inserter(colorSpaces),
1072 [](ScreenColorGamut item) -> GraphicCM_ColorSpaceType {
1073 return RS_TO_COMMON_COLOR_SPACE_TYPE_MAP[static_cast<GraphicColorGamut>(item)];
1074 });
1075 } else {
1076 std::transform(supportedPhysicalColorGamuts_.begin(), supportedPhysicalColorGamuts_.end(),
1077 back_inserter(colorSpaces),
1078 [](ScreenColorGamut item) -> GraphicCM_ColorSpaceType {
1079 return RS_TO_COMMON_COLOR_SPACE_TYPE_MAP[static_cast<GraphicColorGamut>(item)];
1080 });
1081 }
1082 if (colorSpaces.size() == 0) {
1083 return StatusCode::HDI_ERROR;
1084 }
1085 return StatusCode::SUCCESS;
1086 }
1087
GetScreenColorSpace(GraphicCM_ColorSpaceType & colorSpace) const1088 int32_t RSScreen::GetScreenColorSpace(GraphicCM_ColorSpaceType& colorSpace) const
1089 {
1090 ScreenColorGamut curGamut;
1091 int32_t result = GetScreenColorGamut(curGamut);
1092 colorSpace = RS_TO_COMMON_COLOR_SPACE_TYPE_MAP[static_cast<GraphicColorGamut>(curGamut)];
1093 return result;
1094 }
1095
SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace)1096 int32_t RSScreen::SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace)
1097 {
1098 auto iter = COMMON_COLOR_SPACE_TYPE_TO_RS_MAP.find(colorSpace);
1099 if (iter == COMMON_COLOR_SPACE_TYPE_TO_RS_MAP.end()) {
1100 return StatusCode::INVALID_ARGUMENTS;
1101 }
1102 ScreenColorGamut dstColorGamut = static_cast<ScreenColorGamut>(iter->second);
1103 int32_t curIdx;
1104 if (IsVirtual()) {
1105 auto it = std::find(supportedVirtualColorGamuts_.begin(), supportedVirtualColorGamuts_.end(), dstColorGamut);
1106 if (it == supportedVirtualColorGamuts_.end()) {
1107 return StatusCode::INVALID_ARGUMENTS;
1108 }
1109 curIdx = std::distance(supportedVirtualColorGamuts_.begin(), it);
1110 currentVirtualColorGamutIdx_ = curIdx;
1111 return StatusCode::SUCCESS;
1112 }
1113 if (!hdiScreen_) {
1114 RS_LOGE("RSScreen %{public}s failed, hdiScreen_ is nullptr", __func__);
1115 return StatusCode::HDI_ERROR;
1116 }
1117 std::vector<GraphicColorGamut> hdiMode;
1118 if (hdiScreen_->GetScreenSupportedColorGamuts(hdiMode) != GRAPHIC_DISPLAY_SUCCESS) {
1119 return StatusCode::HDI_ERROR;
1120 }
1121 auto it = std::find(hdiMode.begin(), hdiMode.end(), static_cast<GraphicColorGamut>(dstColorGamut));
1122 if (it == hdiMode.end()) {
1123 return StatusCode::INVALID_ARGUMENTS;
1124 }
1125 curIdx = std::distance(hdiMode.begin(), it);
1126 int32_t result = hdiScreen_->SetScreenColorGamut(hdiMode[curIdx]);
1127 if (result == GRAPHIC_DISPLAY_SUCCESS) {
1128 currentPhysicalColorGamutIdx_ = curIdx;
1129 return StatusCode::SUCCESS;
1130 }
1131 return StatusCode::HDI_ERROR;
1132 }
GetWhiteList() const1133 const std::unordered_set<uint64_t>& RSScreen::GetWhiteList() const
1134 {
1135 return whiteList_;
1136 }
1137
SetBlackList(const std::unordered_set<uint64_t> & blackList)1138 void RSScreen::SetBlackList(const std::unordered_set<uint64_t>& blackList)
1139 {
1140 blackList_ = blackList;
1141 }
1142
AddBlackList(const std::vector<uint64_t> & blackList)1143 void RSScreen::AddBlackList(const std::vector<uint64_t>& blackList)
1144 {
1145 for (auto& list : blackList) {
1146 blackList_.emplace(list);
1147 }
1148 }
1149
RemoveBlackList(const std::vector<uint64_t> & blackList)1150 void RSScreen::RemoveBlackList(const std::vector<uint64_t>& blackList)
1151 {
1152 for (auto& list : blackList) {
1153 blackList_.erase(list);
1154 }
1155 }
1156
SetCastScreenEnableSkipWindow(bool enable)1157 void RSScreen::SetCastScreenEnableSkipWindow(bool enable)
1158 {
1159 skipWindow_ = enable;
1160 }
1161
GetCastScreenEnableSkipWindow()1162 bool RSScreen::GetCastScreenEnableSkipWindow()
1163 {
1164 return skipWindow_;
1165 }
1166
GetBlackList() const1167 const std::unordered_set<uint64_t>& RSScreen::GetBlackList() const
1168 {
1169 return blackList_;
1170 }
1171
SetScreenConstraint(uint64_t frameId,uint64_t timestamp,ScreenConstraintType type)1172 int32_t RSScreen::SetScreenConstraint(uint64_t frameId, uint64_t timestamp, ScreenConstraintType type)
1173 {
1174 if (IsVirtual()) {
1175 return StatusCode::SUCCESS;
1176 }
1177 if (hdiScreen_ != nullptr) {
1178 int32_t result = hdiScreen_->SetScreenConstraint(frameId, timestamp, static_cast<uint32_t>(type));
1179 if (result == GRAPHIC_DISPLAY_SUCCESS) {
1180 return StatusCode::SUCCESS;
1181 }
1182 }
1183 return StatusCode::HDI_ERROR;
1184 }
1185
SetSecurityExemptionList(const std::vector<uint64_t> & securityExemptionList)1186 void RSScreen::SetSecurityExemptionList(const std::vector<uint64_t>& securityExemptionList)
1187 {
1188 securityExemptionList_ = securityExemptionList;
1189 }
1190
GetSecurityExemptionList() const1191 const std::vector<uint64_t>& RSScreen::GetSecurityExemptionList() const
1192 {
1193 return securityExemptionList_;
1194 }
1195 } // namespace impl
1196 } // namespace Rosen
1197 } // namespace OHOS
1198