blob: d1bed0cc833492cc9386bfd88826af84392a6ff5 [file] [log] [blame]
Steven Thomas3172e202020-01-06 19:25:30 -08001/*
2 * Copyright (C) 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#include <system/window.h>
18
19#include <thread>
20
21#include "LayerTransactionTest.h"
22
23namespace android {
24
25class SetFrameRateTest : public LayerTransactionTest {
26protected:
27 void TearDown() {
28 mLayer = nullptr;
29 LayerTransactionTest::TearDown();
30 }
31
32 void CreateLayer(uint32_t layerType) {
33 ASSERT_EQ(nullptr, mLayer.get());
34 mLayerType = layerType;
35 ASSERT_NO_FATAL_FAILURE(mLayer = createLayer("TestLayer", mLayerWidth, mLayerHeight,
36 /*flags=*/mLayerType));
37 ASSERT_NE(nullptr, mLayer.get());
38 }
39
40 void PostBuffers(const Color& color) {
41 auto startTime = systemTime();
42 while (systemTime() - startTime < s2ns(1)) {
43 ASSERT_NO_FATAL_FAILURE(
44 fillLayerColor(mLayerType, mLayer, color, mLayerWidth, mLayerHeight));
45 std::this_thread::sleep_for(100ms);
46 }
47 }
48
Marin Shalamanov46084422020-10-13 12:33:42 +020049 const uint32_t mLayerWidth = 32;
50 const uint32_t mLayerHeight = 32;
Steven Thomas3172e202020-01-06 19:25:30 -080051 sp<SurfaceControl> mLayer;
52 uint32_t mLayerType;
53};
54
55TEST_F(SetFrameRateTest, BufferQueueLayerSetFrameRate) {
56 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferQueue);
Steven Thomas62a4cf82020-01-31 12:04:03 -080057 native_window_set_frame_rate(mLayer->getSurface().get(), 100.f,
Marin Shalamanov46084422020-10-13 12:33:42 +020058 ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
59 /* shouldBeSeamless */ true);
Steven Thomas3172e202020-01-06 19:25:30 -080060 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
Steven Thomas62a4cf82020-01-31 12:04:03 -080061 Transaction()
Marin Shalamanov46084422020-10-13 12:33:42 +020062 .setFrameRate(mLayer, 200.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
63 /* shouldBeSeamless */ true)
Steven Thomas62a4cf82020-01-31 12:04:03 -080064 .apply();
Steven Thomas3172e202020-01-06 19:25:30 -080065 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
Steven Thomas62a4cf82020-01-31 12:04:03 -080066 native_window_set_frame_rate(mLayer->getSurface().get(), 300.f,
Marin Shalamanov46084422020-10-13 12:33:42 +020067 ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
68 /* shouldBeSeamless */ true);
Steven Thomas3172e202020-01-06 19:25:30 -080069 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
70}
71
72TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) {
73 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState);
Steven Thomas62a4cf82020-01-31 12:04:03 -080074 Transaction()
Marin Shalamanov46084422020-10-13 12:33:42 +020075 .setFrameRate(mLayer, 400.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
76 /* shouldBeSeamless */ true)
Steven Thomas62a4cf82020-01-31 12:04:03 -080077 .apply();
Steven Thomas3172e202020-01-06 19:25:30 -080078 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::GREEN));
79}
80
81} // namespace android