Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1 | /* |
| 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 Abraham | fbb86a6 | 2020-01-16 17:17:14 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 21 | #include <system/window.h> |
| 22 | |
| 23 | #include <thread> |
| 24 | |
| 25 | #include "LayerTransactionTest.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | class SetFrameRateTest : public LayerTransactionTest { |
| 30 | protected: |
| 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 | |
| 59 | TEST_F(SetFrameRateTest, BufferQueueLayerSetFrameRate) { |
| 60 | CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferQueue); |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 61 | native_window_set_frame_rate(mLayer->getSurface().get(), 100.f, |
| 62 | ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 63 | ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED)); |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 64 | Transaction() |
| 65 | .setFrameRate(mLayer, 200.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT) |
| 66 | .apply(); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 67 | ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED)); |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 68 | native_window_set_frame_rate(mLayer->getSurface().get(), 300.f, |
| 69 | ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 70 | ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED)); |
| 71 | } |
| 72 | |
| 73 | TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) { |
| 74 | CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState); |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 75 | Transaction() |
| 76 | .setFrameRate(mLayer, 400.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT) |
| 77 | .apply(); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 78 | ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::GREEN)); |
| 79 | } |
| 80 | |
| 81 | } // namespace android |
Ady Abraham | fbb86a6 | 2020-01-16 17:17:14 -0800 | [diff] [blame] | 82 | |
| 83 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 84 | #pragma clang diagnostic pop // ignored "-Wconversion" |