1 /* 2 * Copyright (c) 2021 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 constexpr uint32_t DISPLAY_DEAULT_W = 480; 29 constexpr uint32_t DISPLAY_DEAULT_H = 960; 30 constexpr uint32_t RED = 0xff0000ff; 31 constexpr uint32_t GREEN = 0x00ff00ff; 32 constexpr uint32_t BLUE = 0x0000ffff; 33 constexpr uint32_t TRANSPARENT = 0; 34 constexpr uint32_t YELLOW = 0xffff29ff; 35 36 struct FRect { 37 float x = 0; 38 float y = 0; 39 float w = 0; // ratio 40 float h = 0; // ratio 41 }; 42 43 struct BufferRatio { 44 float w; 45 float h; 46 }; 47 48 struct Size { 49 uint32_t w; 50 uint32_t h; 51 }; 52 53 struct LayerSettings { 54 IRect displayRect; 55 IRect displayCrop; 56 FRect rectRatio = { 0.0f }; 57 uint32_t color; 58 uint32_t zorder = 0; 59 Size bufferSize = { 0 }; 60 BufferRatio bufferRatio { 0 }; 61 int32_t alpha = -1; 62 CompositionType compositionType = COMPOSITION_DEVICE; 63 BlendType blendType = BLEND_SRC; 64 TransformType rotate = ROTATE_NONE; 65 }; 66 67 struct TestParemeter { GetInstanceTestParemeter68 static TestParemeter &GetInstance() 69 { 70 static TestParemeter instance; 71 return instance; 72 } 73 int32_t mTestSleep = 0; 74 }; 75 76 using LayersSetting = std::vector<LayerSettings>; 77 class DeviceLayerDisplay : public ::testing::TestWithParam<std::vector<LayerSettings>> { 78 protected: SetUp()79 void SetUp() {} 80 void TearDown(); 81 }; 82 83 class DeviceTest : public ::testing::Test { 84 protected: 85 void TearDown(); 86 }; 87 88 // only support single layer test 89 class LayerRotateTest : public ::testing::TestWithParam<LayerSettings> { 90 protected: 91 void TearDown(); 92 }; 93 94 class VblankTest : public ::testing::Test { 95 protected: 96 void TearDown(); 97 }; 98 99 class VblankCtr { 100 public: GetInstance()101 static VblankCtr &GetInstance() 102 { 103 static VblankCtr instance; 104 return instance; 105 } 106 void NotifyVblank(unsigned int sequence, uint64_t ns, void *data); 107 int32_t WaitVblank(uint32_t ms); 108 109 protected: 110 void TearDown(); 111 112 private: 113 std::mutex mVblankMutex; 114 std::condition_variable mVblankCondition; VblankCtr()115 VblankCtr() {} 116 ~VblankCtr(); 117 bool mHasVblank = false; 118 }; 119 } // OHOS 120 } // HDI 121 } // DISPLAY 122 } // TEST 123 124 #endif // HDI_DEVICE_TEST_H