blob: b647aaba8fe3337aa38c4d33579c37be7a0b9581 [file] [log] [blame]
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001/*
2 * Copyright 2018 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#include <gtest/gtest.h>
18
19#include <binder/ProcessState.h>
20#include <gui/ISurfaceComposer.h>
21#include <gui/Surface.h>
22#include <gui/SurfaceComposerClient.h>
23#include <inttypes.h>
24
25namespace android {
26
27using Transaction = SurfaceComposerClient::Transaction;
28
29static constexpr uint32_t INVALID_MASK = 0x10;
30class DisplayedContentSamplingTest : public ::testing::Test {
31protected:
32 void SetUp() {
33 mComposerClient = new SurfaceComposerClient;
34 ASSERT_EQ(OK, mComposerClient->initCheck());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080035 mDisplayToken = mComposerClient->getInternalDisplayToken();
Kevin DuBois9c0a1762018-10-16 13:32:31 -070036 ASSERT_TRUE(mDisplayToken);
37 }
38
Kevin DuBois74e53772018-11-19 10:52:38 -080039 bool shouldSkipTest() {
40 ui::PixelFormat format;
41 ui::Dataspace dataspace;
42 status_t status =
43 mComposerClient->getDisplayedContentSamplingAttributes(mDisplayToken, &format,
44 &dataspace, &componentMask);
Kevin DuBois9c0a1762018-10-16 13:32:31 -070045 if (status == PERMISSION_DENIED) {
46 SUCCEED() << "permissions denial, skipping test";
47 return true;
48 }
49 if (status == INVALID_OPERATION) {
50 SUCCEED() << "optional function not supported, skipping test";
51 return true;
52 }
53 return false;
54 }
55
56 sp<SurfaceComposerClient> mComposerClient;
57 sp<IBinder> mDisplayToken;
Kevin DuBois74e53772018-11-19 10:52:38 -080058 uint8_t componentMask = 0;
Kevin DuBois9c0a1762018-10-16 13:32:31 -070059};
60
61TEST_F(DisplayedContentSamplingTest, GetDisplayedContentSamplingAttributesAreSane) {
Kevin DuBois74e53772018-11-19 10:52:38 -080062 // tradefed infrastructure does not support use of GTEST_SKIP
63 if (shouldSkipTest()) return;
64
Kevin DuBois9c0a1762018-10-16 13:32:31 -070065 ui::PixelFormat format;
66 ui::Dataspace dataspace;
Kevin DuBois9c0a1762018-10-16 13:32:31 -070067 status_t status =
68 mComposerClient->getDisplayedContentSamplingAttributes(mDisplayToken, &format,
69 &dataspace, &componentMask);
Kevin DuBois9c0a1762018-10-16 13:32:31 -070070 EXPECT_EQ(OK, status);
71 EXPECT_LE(componentMask, INVALID_MASK);
72}
Kevin DuBois74e53772018-11-19 10:52:38 -080073
74TEST_F(DisplayedContentSamplingTest, EnableWithInvalidMaskReturnsBadValue) {
75 if (shouldSkipTest()) return;
76
77 status_t status =
78 mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, true, INVALID_MASK, 0);
79 EXPECT_EQ(BAD_VALUE, status);
80}
81
82TEST_F(DisplayedContentSamplingTest, EnableAndDisableSucceed) {
83 if (shouldSkipTest()) return;
84
85 status_t status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, true,
86 componentMask, 10);
87 EXPECT_EQ(OK, status);
88
89 status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, false, componentMask,
90 0);
91 EXPECT_EQ(OK, status);
92}
93
94TEST_F(DisplayedContentSamplingTest, SelectivelyDisableComponentOk) {
95 if (shouldSkipTest()) return;
96
97 status_t status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, true,
98 componentMask, 0);
99 EXPECT_EQ(OK, status);
100
101 // Clear the lowest bit.
102 componentMask &= (componentMask - 1);
103 status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, false, componentMask,
104 0);
105 EXPECT_EQ(OK, status);
106}
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700107
108TEST_F(DisplayedContentSamplingTest, SampleCollectionCoherentWithSupportMask) {
109 if (shouldSkipTest()) return;
110
111 DisplayedFrameStats stats;
112 status_t status = mComposerClient->getDisplayedContentSample(mDisplayToken, 0, 0, &stats);
113 EXPECT_EQ(OK, status);
114 if (stats.numFrames <= 0) return;
115
116 if (componentMask & (0x1 << 0)) EXPECT_NE(0, stats.component_0_sample.size());
117 if (componentMask & (0x1 << 1)) EXPECT_NE(0, stats.component_1_sample.size());
118 if (componentMask & (0x1 << 2)) EXPECT_NE(0, stats.component_2_sample.size());
119 if (componentMask & (0x1 << 3)) EXPECT_NE(0, stats.component_3_sample.size());
120}
121
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700122} // namespace android