1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HDI_DEVICE_TEST_H 17 #define HDI_DEVICE_TEST_H 18 #include <condition_variable> 19 #include <vector> 20 #include <mutex> 21 #include "gtest/gtest.h" 22 #include "display_type.h" 23 24 namespace OHOS { 25 namespace HDI { 26 namespace DISPLAY { 27 namespace TEST { 28 struct FRect { 29 float x = 0; 30 float y = 0; 31 float w = 0; // ratio 32 float h = 0; // ratio 33 }; 34 35 struct BufferRatio { 36 float w; 37 float h; 38 }; 39 40 struct Size { 41 uint32_t w; 42 uint32_t h; 43 }; 44 45 struct LayerSettings { 46 IRect displayRect; 47 IRect displayCrop; 48 FRect rectRatio = { 0.0f }; 49 uint32_t color; 50 uint32_t zorder = 0; 51 Size bufferSize = { 0 }; 52 BufferRatio bufferRatio { 0 }; 53 int32_t alpha = -1; 54 CompositionType compositionType = COMPOSITION_DEVICE; 55 BlendType blendType = BLEND_SRC; 56 TransformType rotate = ROTATE_NONE; 57 }; 58 59 struct TestParemeter { GetInstanceTestParemeter60 static TestParemeter &GetInstance() 61 { 62 static TestParemeter instance; 63 return instance; 64 } 65 int32_t mTestSleep = 0; 66 }; 67 68 using LayersSetting = std::vector<LayerSettings>; 69 class DeviceLayerDisplay : public ::testing::TestWithParam<std::vector<LayerSettings>> { 70 protected: SetUp()71 void SetUp() {} 72 void TearDown(); 73 }; 74 75 class DeviceTest : public ::testing::Test { 76 protected: 77 void TearDown(); 78 }; 79 80 // only support single layer test 81 class LayerRotateTest : public ::testing::TestWithParam<LayerSettings> { 82 protected: 83 void TearDown(); 84 }; 85 86 class VblankTest : public ::testing::Test { 87 protected: 88 void TearDown(); 89 }; 90 91 class VblankCtr { 92 public: GetInstance()93 static VblankCtr &GetInstance() 94 { 95 static VblankCtr instance; 96 return instance; 97 } 98 void NotifyVblank(unsigned int sequence, uint64_t ns, void *data); 99 int32_t WaitVblank(uint32_t ms); 100 101 protected: 102 void TearDown(); 103 104 private: 105 std::mutex mVblankMutex; 106 std::condition_variable mVblankCondition; VblankCtr()107 VblankCtr() {} 108 ~VblankCtr(); 109 bool mHasVblank = false; 110 }; 111 } // OHOS 112 } // HDI 113 } // DISPLAY 114 } // TEST 115 116 #endif // HDI_DEVICE_TEST_H