1 /* 2 * Copyright (C) 2023 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 "surface_inner_mock.h" 17 #include "ui/rs_surface_node.h" 18 #include "window_option.h" 19 20 namespace OHOS { 21 namespace MediaAVCodec { 22 namespace { 23 constexpr uint32_t DEFAULT_WIDTH = 480; 24 constexpr uint32_t DEFAULT_HEIGHT = 360; 25 } // namespace CreateSurface()26std::shared_ptr<SurfaceMock> SurfaceMockFactory::CreateSurface() 27 { 28 return std::make_shared<SurfaceInnerMock>(); 29 } 30 CreateSurface(sptr<Surface> & surface)31std::shared_ptr<SurfaceMock> SurfaceMockFactory::CreateSurface(sptr<Surface> &surface) 32 { 33 return std::make_shared<SurfaceInnerMock>(surface); 34 } 35 ~SurfaceInnerMock()36SurfaceInnerMock::~SurfaceInnerMock() 37 { 38 if (window_ != nullptr) { 39 window_->Destroy(); 40 window_ = nullptr; 41 } 42 } GetSurface()43sptr<Surface> SurfaceInnerMock::GetSurface() 44 { 45 if (surface_ == nullptr) { 46 sptr<Rosen::WindowOption> option = new Rosen::WindowOption(); 47 option->SetWindowRect({0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT}); 48 option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_LAUNCHING); 49 option->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); 50 window_ = Rosen::Window::Create("vcodec_unittest", option); 51 if (window_ == nullptr || window_->GetSurfaceNode() == nullptr) { 52 return nullptr; 53 } 54 window_->Show(); 55 surface_ = window_->GetSurfaceNode()->GetSurface(); 56 } 57 return surface_; 58 } 59 } // namespace MediaAVCodec 60 } // namespace OHOS