blob: 4d1477cf8db99e47605d53b7fd3996a9d298e6df [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
49 const int mLayerWidth = 32;
50 const int mLayerHeight = 32;
51 sp<SurfaceControl> mLayer;
52 uint32_t mLayerType;
53};
54
55TEST_F(SetFrameRateTest, BufferQueueLayerSetFrameRate) {
56 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferQueue);
57 native_window_set_frame_rate(mLayer->getSurface().get(), 100.f);
58 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
59 Transaction().setFrameRate(mLayer, 200.f).apply();
60 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
61 native_window_set_frame_rate(mLayer->getSurface().get(), 300.f);
62 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
63}
64
65TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) {
66 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState);
67 Transaction().setFrameRate(mLayer, 400.f).apply();
68 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::GREEN));
69}
70
71} // namespace android