blob: f2c0e0ca7f30c89a50d2f15922718a0cd323aabb [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());
35 mDisplayToken = mComposerClient->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain);
36 ASSERT_TRUE(mDisplayToken);
37 }
38
39 bool shouldSkipTest(status_t status) {
40 if (status == PERMISSION_DENIED) {
41 SUCCEED() << "permissions denial, skipping test";
42 return true;
43 }
44 if (status == INVALID_OPERATION) {
45 SUCCEED() << "optional function not supported, skipping test";
46 return true;
47 }
48 return false;
49 }
50
51 sp<SurfaceComposerClient> mComposerClient;
52 sp<IBinder> mDisplayToken;
53};
54
55TEST_F(DisplayedContentSamplingTest, GetDisplayedContentSamplingAttributesAreSane) {
56 ui::PixelFormat format;
57 ui::Dataspace dataspace;
58 uint8_t componentMask = 0;
59 status_t status =
60 mComposerClient->getDisplayedContentSamplingAttributes(mDisplayToken, &format,
61 &dataspace, &componentMask);
62 if (shouldSkipTest(status)) {
63 return;
64 }
65 EXPECT_EQ(OK, status);
66 EXPECT_LE(componentMask, INVALID_MASK);
67}
68} // namespace android