1 /* 2 * Copyright (C) 2024 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 #include "gtest/gtest.h" 17 18 #include "render_environment.h" 19 #include "effect_context.h" 20 #include "graphic/render_frame_buffer.h" 21 #include "mock_producer_surface.h" 22 23 using namespace testing::ext; 24 25 namespace OHOS { 26 namespace Media { 27 namespace Effect { 28 namespace Test { 29 30 constexpr uint32_t WIDTH = 960; 31 constexpr uint32_t HEIGHT = 1280; 32 constexpr IEffectFormat FORMATE_TYPE = IEffectFormat::RGBA8888; 33 constexpr uint32_t ROW_STRIDE = WIDTH * 4; 34 constexpr uint32_t LEN = ROW_STRIDE * HEIGHT; 35 36 class TestRenderEnvironment : public testing::Test { 37 public: 38 TestRenderEnvironment() = default; 39 40 ~TestRenderEnvironment() override = default; SetUpTestCase()41 static void SetUpTestCase() {} 42 TearDownTestCase()43 static void TearDownTestCase() {} 44 SetUp()45 void SetUp() override 46 { 47 renderEnvironment = std::make_shared<RenderEnvironment>(); 48 renderEnvironment->Init(); 49 renderEnvironment->Prepare(); 50 51 std::shared_ptr<BufferInfo> bufferInfo = std::make_unique<BufferInfo>(); 52 bufferInfo->width_ = WIDTH; 53 bufferInfo->height_ = HEIGHT; 54 bufferInfo->rowStride_ = ROW_STRIDE; 55 bufferInfo->len_ = LEN; 56 bufferInfo->formatType_ = FORMATE_TYPE; 57 bufferInfo->surfaceBuffer_ = nullptr; 58 void *addr = malloc(bufferInfo->len_); 59 60 std::shared_ptr<ExtraInfo> extraInfo = std::make_unique<ExtraInfo>(); 61 extraInfo->dataType = DataType::PIXEL_MAP; 62 extraInfo->bufferType = BufferType::HEAP_MEMORY; 63 effectBuffer = std::make_shared<EffectBuffer>(bufferInfo, addr, extraInfo); 64 65 free(addr); 66 addr = nullptr; 67 } 68 TearDown()69 void TearDown() override 70 { 71 effectBuffer = nullptr; 72 if (renderEnvironment == nullptr) { 73 return; 74 } 75 renderEnvironment->ReleaseParam(); 76 renderEnvironment->Release(); 77 } 78 79 std::shared_ptr<EffectBuffer> effectBuffer; 80 std::shared_ptr<RenderEnvironment> renderEnvironment; 81 }; 82 83 HWTEST_F(TestRenderEnvironment, TestRenderEnvironment002, TestSize.Level1) 84 { 85 IEffectFormat format = IEffectFormat::YUVNV12; 86 GLuint tex = renderEnvironment->ConvertFromYUVToRGB(effectBuffer.get(), format); 87 EXPECT_NE(tex, 0); 88 89 GraphicTransformType type = GraphicTransformType::GRAPHIC_ROTATE_NONE; 90 renderEnvironment->DrawFrame(tex, type); 91 renderEnvironment->DrawFrameWithTransform(effectBuffer, type); 92 effectBuffer->bufferInfo_->tex_ = renderEnvironment->RequestBuffer(WIDTH, HEIGHT); 93 EXPECT_NE(effectBuffer->bufferInfo_->tex_, nullptr); 94 95 type = GraphicTransformType::GRAPHIC_ROTATE_90; 96 renderEnvironment->DrawFrame(tex, type); 97 renderEnvironment->DrawFrameWithTransform(effectBuffer, type); 98 type = GraphicTransformType::GRAPHIC_FLIP_H_ROT90; 99 renderEnvironment->DrawFrame(tex, type); 100 type = GraphicTransformType::GRAPHIC_FLIP_V_ROT90; 101 renderEnvironment->DrawFrame(tex, type); 102 103 type = GraphicTransformType::GRAPHIC_ROTATE_180; 104 renderEnvironment->DrawFrame(tex, type); 105 renderEnvironment->DrawFrameWithTransform(effectBuffer, type); 106 type = GraphicTransformType::GRAPHIC_FLIP_H_ROT180; 107 renderEnvironment->DrawFrame(tex, type); 108 type = GraphicTransformType::GRAPHIC_FLIP_V_ROT180; 109 renderEnvironment->DrawFrame(tex, type); 110 111 type = GraphicTransformType::GRAPHIC_ROTATE_270; 112 renderEnvironment->DrawFrame(tex, type); 113 renderEnvironment->DrawFrameWithTransform(effectBuffer, type); 114 type = GraphicTransformType::GRAPHIC_FLIP_H_ROT270; 115 renderEnvironment->DrawFrame(tex, type); 116 type = GraphicTransformType::GRAPHIC_FLIP_V_ROT270; 117 renderEnvironment->DrawFrame(tex, type); 118 } 119 120 } 121 } 122 } 123 }