| 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 |  | 
 | 17 | #include <system/window.h> | 
 | 18 |  | 
 | 19 | #include <thread> | 
 | 20 |  | 
 | 21 | #include "LayerTransactionTest.h" | 
 | 22 |  | 
 | 23 | namespace android { | 
 | 24 |  | 
 | 25 | class SetFrameRateTest : public LayerTransactionTest { | 
 | 26 | protected: | 
 | 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 Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 49 |     const uint32_t mLayerWidth = 32; | 
 | 50 |     const uint32_t mLayerHeight = 32; | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 51 |     sp<SurfaceControl> mLayer; | 
 | 52 |     uint32_t mLayerType; | 
 | 53 | }; | 
 | 54 |  | 
 | 55 | TEST_F(SetFrameRateTest, BufferQueueLayerSetFrameRate) { | 
 | 56 |     CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferQueue); | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 57 |     native_window_set_frame_rate(mLayer->getSurface().get(), 100.f, | 
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 58 |                                  ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, | 
 | 59 |                                  /* shouldBeSeamless */ true); | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 60 |     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED)); | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 61 |     Transaction() | 
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 62 |             .setFrameRate(mLayer, 200.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, | 
 | 63 |                           /* shouldBeSeamless */ true) | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 64 |             .apply(); | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 65 |     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED)); | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 66 |     native_window_set_frame_rate(mLayer->getSurface().get(), 300.f, | 
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 67 |                                  ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, | 
 | 68 |                                  /* shouldBeSeamless */ true); | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 69 |     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED)); | 
 | 70 | } | 
 | 71 |  | 
 | 72 | TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) { | 
 | 73 |     CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState); | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 74 |     Transaction() | 
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 75 |             .setFrameRate(mLayer, 400.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, | 
 | 76 |                           /* shouldBeSeamless */ true) | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 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 |