blob: fc652636edb086b469a980b878c2ba887775524b [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);
61 native_window_set_frame_rate(mLayer->getSurface().get(), 100.f);
62 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
63 Transaction().setFrameRate(mLayer, 200.f).apply();
64 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
65 native_window_set_frame_rate(mLayer->getSurface().get(), 300.f);
66 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
67}
68
69TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) {
70 CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState);
71 Transaction().setFrameRate(mLayer, 400.f).apply();
72 ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::GREEN));
73}
74
75} // namespace android
Ady Abrahamfbb86a62020-01-16 17:17:14 -080076
77// TODO(b/129481165): remove the #pragma below and fix conversion issues
78#pragma clang diagnostic pop // ignored "-Wconversion"