blob: 02ba9e290d95d463565578ec5316b830e4fe21ea [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
Ady Abrahamfbb86a62020-01-16 17:17:14 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Steven Thomas3172e202020-01-06 19:25:30 -080021#include <system/window.h>
22
23#include <thread>
24
25#include "LayerTransactionTest.h"
26
27namespace android {
28
29class SetFrameRateTest : public LayerTransactionTest {
30protected:
31 void TearDown() {
32 mLayer = nullptr;
33 LayerTransactionTest::TearDown();
34 }
35
36 void CreateLayer(uint32_t layerType) {
37 ASSERT_EQ(nullptr, mLayer.get());
38 mLayerType = layerType;
39 ASSERT_NO_FATAL_FAILURE(mLayer = createLayer("TestLayer", mLayerWidth, mLayerHeight,
40 /*flags=*/mLayerType));
41 ASSERT_NE(nullptr, mLayer.get());
42 }
43
44 void PostBuffers(const Color& color) {
45 auto startTime = systemTime();
46 while (systemTime() - startTime < s2ns(1)) {
47 ASSERT_NO_FATAL_FAILURE(
48 fillLayerColor(mLayerType, mLayer, color, mLayerWidth, mLayerHeight));
49 std::this_thread::sleep_for(100ms);
50 }
51 }
52
53 const int mLayerWidth = 32;
54 const int mLayerHeight = 32;
55 sp<SurfaceControl> mLayer;
56 uint32_t mLayerType;
57};
58
59TEST_F(SetFrameRateTest, BufferQueueLayerSetFrameRate) {
60 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferQueue);
Steven Thomas62a4cf82020-01-31 12:04:03 -080061 native_window_set_frame_rate(mLayer->getSurface().get(), 100.f,
62 ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT);
Steven Thomas3172e202020-01-06 19:25:30 -080063 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
Steven Thomas62a4cf82020-01-31 12:04:03 -080064 Transaction()
65 .setFrameRate(mLayer, 200.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT)
66 .apply();
Steven Thomas3172e202020-01-06 19:25:30 -080067 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
Steven Thomas62a4cf82020-01-31 12:04:03 -080068 native_window_set_frame_rate(mLayer->getSurface().get(), 300.f,
69 ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT);
Steven Thomas3172e202020-01-06 19:25:30 -080070 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
71}
72
73TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) {
74 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState);
Steven Thomas62a4cf82020-01-31 12:04:03 -080075 Transaction()
76 .setFrameRate(mLayer, 400.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT)
77 .apply();
Steven Thomas3172e202020-01-06 19:25:30 -080078 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::GREEN));
79}
80
81} // namespace android
Ady Abrahamfbb86a62020-01-16 17:17:14 -080082
83// TODO(b/129481165): remove the #pragma below and fix conversion issues
84#pragma clang diagnostic pop // ignored "-Wconversion"