• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
24 
25 namespace android {
26 namespace {
27 
28 class GetDisplayNativePrimaries : public DisplayTransactionTest {
29 public:
30     GetDisplayNativePrimaries();
31     void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
32     void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
33 
34 private:
35     static constexpr float mStartingTestValue = 1.0f;
36 };
37 
GetDisplayNativePrimaries()38 GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
39     SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
40     injectFakeNativeWindowSurfaceFactory();
41 }
42 
populateDummyDisplayNativePrimaries(ui::DisplayPrimaries & primaries)43 void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
44         ui::DisplayPrimaries& primaries) {
45     float startingVal = mStartingTestValue;
46     primaries.red.X = startingVal++;
47     primaries.red.Y = startingVal++;
48     primaries.red.Z = startingVal++;
49     primaries.green.X = startingVal++;
50     primaries.green.Y = startingVal++;
51     primaries.green.Z = startingVal++;
52     primaries.blue.X = startingVal++;
53     primaries.blue.Y = startingVal++;
54     primaries.blue.Z = startingVal++;
55     primaries.white.X = startingVal++;
56     primaries.white.Y = startingVal++;
57     primaries.white.Z = startingVal++;
58 }
59 
checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries & primaries)60 void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
61         const ui::DisplayPrimaries& primaries) {
62     float startingVal = mStartingTestValue;
63     EXPECT_EQ(primaries.red.X, startingVal++);
64     EXPECT_EQ(primaries.red.Y, startingVal++);
65     EXPECT_EQ(primaries.red.Z, startingVal++);
66     EXPECT_EQ(primaries.green.X, startingVal++);
67     EXPECT_EQ(primaries.green.Y, startingVal++);
68     EXPECT_EQ(primaries.green.Z, startingVal++);
69     EXPECT_EQ(primaries.blue.X, startingVal++);
70     EXPECT_EQ(primaries.blue.Y, startingVal++);
71     EXPECT_EQ(primaries.blue.Z, startingVal++);
72     EXPECT_EQ(primaries.white.X, startingVal++);
73     EXPECT_EQ(primaries.white.Y, startingVal++);
74     EXPECT_EQ(primaries.white.Z, startingVal++);
75 }
76 
TEST_F(GetDisplayNativePrimaries,nullDisplayToken)77 TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
78     ui::DisplayPrimaries primaries;
79     EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
80 }
81 
TEST_F(GetDisplayNativePrimaries,internalDisplayWithPrimariesData)82 TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
83     auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
84     injector.inject();
85     auto internalDisplayToken = injector.token();
86 
87     ui::DisplayPrimaries expectedPrimaries;
88     populateDummyDisplayNativePrimaries(expectedPrimaries);
89     mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
90 
91     ui::DisplayPrimaries primaries;
92     EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
93 
94     checkDummyDisplayNativePrimaries(primaries);
95 }
96 
TEST_F(GetDisplayNativePrimaries,notInternalDisplayToken)97 TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
98     sp<BBinder> notInternalDisplayToken = new BBinder();
99 
100     ui::DisplayPrimaries primaries;
101     populateDummyDisplayNativePrimaries(primaries);
102     EXPECT_EQ(NAME_NOT_FOUND,
103               mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
104 
105     // Check primaries argument wasn't modified in case of failure
106     checkDummyDisplayNativePrimaries(primaries);
107 }
108 
109 } // namespace
110 } // namespace android
111