1 /*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #undef LOG_TAG
18 #define LOG_TAG "LibSurfaceFlingerUnittests"
19
20 #include "DisplayTransactionTestHelpers.h"
21
22 namespace android {
23 namespace {
24
25 using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
26
27 class ExcludeDolbyVisionTest : public DisplayTransactionTest {
28 public:
injectDisplayModes(std::vector<DisplayModePtr> displayModePtrs)29 void injectDisplayModes(std::vector<DisplayModePtr> displayModePtrs) {
30 DisplayModes modes;
31 for (DisplayModePtr displayMode : displayModePtrs) {
32 modes.try_emplace(displayMode->getId(), displayMode);
33 }
34
35 mDisplay = PrimaryDisplayVariant::makeFakeExistingDisplayInjector(this)
36 .setDisplayModes(std::move(modes), displayModePtrs[0]->getId())
37 .inject();
38 mDisplay->overrideHdrTypes(types);
39 }
40
41 protected:
42 sp<DisplayDevice> mDisplay;
43
44 static constexpr DisplayModeId modeId1080p60{0};
45 static constexpr DisplayModeId modeId4k30{1};
46 static constexpr DisplayModeId modeId4k60{2};
47
48 static inline const DisplayModePtr mode1080p60 =
49 createDisplayMode(modeId1080p60, 60_Hz, 0, ui::Size(1920, 1080));
50 static inline const DisplayModePtr mode4k30 =
51 createDisplayMode(modeId4k30, 30_Hz, 1, ui::Size(3840, 2160));
52 static inline const DisplayModePtr mode4k30NonStandard =
53 createDisplayMode(modeId4k30, 30.1_Hz, 1, ui::Size(3840, 2160));
54 static inline const DisplayModePtr mode4k60 =
55 createDisplayMode(modeId4k60, 60_Hz, 2, ui::Size(3840, 2160));
56
57 const std::vector<ui::Hdr> types = {ui::Hdr::DOLBY_VISION, ui::Hdr::DOLBY_VISION_4K30,
58 ui::Hdr::HDR10_PLUS};
59 };
60
TEST_F(ExcludeDolbyVisionTest,excludesDolbyVisionOnModesHigherThan4k30)61 TEST_F(ExcludeDolbyVisionTest, excludesDolbyVisionOnModesHigherThan4k30) {
62 injectDisplayModes({mode4k60});
63 ui::DynamicDisplayInfo info;
64 mFlinger.getDynamicDisplayInfoFromToken(mDisplay->getDisplayToken().promote(), &info);
65
66 std::vector<ui::DisplayMode> displayModes = info.supportedDisplayModes;
67
68 ASSERT_EQ(1, displayModes.size());
69 ASSERT_TRUE(std::any_of(displayModes[0].supportedHdrTypes.begin(),
70 displayModes[0].supportedHdrTypes.end(),
71 [](ui::Hdr type) { return type == ui::Hdr::HDR10_PLUS; }));
72 ASSERT_TRUE(displayModes[0].supportedHdrTypes.size() == 1);
73 }
74
TEST_F(ExcludeDolbyVisionTest,includesDolbyVisionOnModesLowerThanOrEqualTo4k30)75 TEST_F(ExcludeDolbyVisionTest, includesDolbyVisionOnModesLowerThanOrEqualTo4k30) {
76 injectDisplayModes({mode1080p60, mode4k30, mode4k30NonStandard});
77 ui::DynamicDisplayInfo info;
78 mFlinger.getDynamicDisplayInfoFromToken(mDisplay->getDisplayToken().promote(), &info);
79
80 std::vector<ui::DisplayMode> displayModes = info.supportedDisplayModes;
81
82 ASSERT_EQ(2, displayModes.size());
83 for (size_t i = 0; i < displayModes.size(); i++) {
84 ASSERT_TRUE(std::any_of(displayModes[i].supportedHdrTypes.begin(),
85 displayModes[i].supportedHdrTypes.end(),
86 [](ui::Hdr type) { return type == ui::Hdr::HDR10_PLUS; }));
87 ASSERT_TRUE(std::any_of(displayModes[i].supportedHdrTypes.begin(),
88 displayModes[i].supportedHdrTypes.end(),
89 [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION; }));
90 ASSERT_TRUE(displayModes[i].supportedHdrTypes.size() == 2);
91 }
92 }
93
94 TEST_F(ExcludeDolbyVisionTest, 4k30IsNotReportedAsAValidHdrType) {
95 injectDisplayModes({mode4k60});
96 ui::DynamicDisplayInfo info;
97 mFlinger.getDynamicDisplayInfoFromToken(mDisplay->getDisplayToken().promote(), &info);
98
99 std::vector<ui::Hdr> displayHdrTypes = info.hdrCapabilities.getSupportedHdrTypes();
100
101 ASSERT_EQ(2, displayHdrTypes.size());
102 ASSERT_TRUE(std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(),
__anon0962197c0502(ui::Hdr type) 103 [](ui::Hdr type) { return type == ui::Hdr::HDR10_PLUS; }));
104 ASSERT_TRUE(std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(),
__anon0962197c0602(ui::Hdr type) 105 [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION; }));
106 }
107
108 } // namespace
109 } // namespace android
110