• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
TearDown()27     void TearDown() {
28         mLayer = nullptr;
29         LayerTransactionTest::TearDown();
30     }
31 
CreateLayer(uint32_t layerType)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 
PostBuffers(const Color & color)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 uint32_t mLayerWidth = 32;
50     const uint32_t mLayerHeight = 32;
51     sp<SurfaceControl> mLayer;
52     uint32_t mLayerType;
53 };
54 
TEST_F(SetFrameRateTest,BufferQueueLayerSetFrameRate)55 TEST_F(SetFrameRateTest, BufferQueueLayerSetFrameRate) {
56     CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferQueue);
57     native_window_set_frame_rate(mLayer->getSurface().get(), 100.f,
58                                  ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
59                                  /* shouldBeSeamless */ true);
60     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
61     Transaction()
62             .setFrameRate(mLayer, 200.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
63                           /* shouldBeSeamless */ true)
64             .apply();
65     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
66     native_window_set_frame_rate(mLayer->getSurface().get(), 300.f,
67                                  ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
68                                  /* shouldBeSeamless */ true);
69     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::RED));
70 }
71 
TEST_F(SetFrameRateTest,BufferStateLayerSetFrameRate)72 TEST_F(SetFrameRateTest, BufferStateLayerSetFrameRate) {
73     CreateLayer(ISurfaceComposerClient::eFXSurfaceBufferState);
74     Transaction()
75             .setFrameRate(mLayer, 400.f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
76                           /* shouldBeSeamless */ true)
77             .apply();
78     ASSERT_NO_FATAL_FAILURE(PostBuffers(Color::GREEN));
79 }
80 
81 } // namespace android
82