• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include "surface_native_mock.h"
17 #include "ui/rs_surface_node.h"
18 #include "window_option.h"
19 
20 namespace OHOS {
21 namespace Media {
22 namespace {
23     constexpr uint32_t DEFAULT_WIDTH = 480;
24     constexpr uint32_t DEFAULT_HEIGHT = 360;
25 }
~SurfaceNativeMock()26 SurfaceNativeMock::~SurfaceNativeMock()
27 {
28     if (window_ != nullptr) {
29         window_->Destroy();
30         window_ = nullptr;
31     }
32 }
GetSurface()33 sptr<Surface> SurfaceNativeMock::GetSurface()
34 {
35     if (surface_ == nullptr) {
36         sptr<Rosen::WindowOption> option = new Rosen::WindowOption();
37         option->SetWindowRect({ 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT });
38         option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_LAUNCHING);
39         option->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
40         window_ = Rosen::Window::Create("avcodec_unittest", option);
41         if (window_ == nullptr || window_->GetSurfaceNode() == nullptr) {
42             return nullptr;
43         }
44         window_->Show();
45         surface_ = window_->GetSurfaceNode()->GetSurface();
46     }
47     return surface_;
48 }
49 } // Media
50 } // OHOS