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 "test_native_buffer_utils.h"
17
18 namespace OHOS {
19 namespace Media {
20 namespace Effect {
21 namespace Test {
22 namespace {
23 constexpr int32_t WIDTH = 1920;
24 constexpr int32_t HEIGHT = 1080;
25 constexpr uint64_t USAGE = 43;
26 }
27
CreateNativeBuffer(GraphicPixelFormat format)28 std::shared_ptr<OH_NativeBuffer> TestNativeBufferUtils::CreateNativeBuffer(GraphicPixelFormat format)
29 {
30 OH_NativeBuffer_Config config = {
31 .width = WIDTH,
32 .height = HEIGHT,
33 .format = format,
34 .usage = USAGE,
35 };
36 OH_NativeBuffer *nativeBuffer = OH_NativeBuffer_Alloc(&config);
37 if (nativeBuffer == nullptr) {
38 return nullptr;
39 }
40
41 auto res = OH_NativeBuffer_Reference(nativeBuffer);
42 if (res != 0) {
43 return nullptr;
44 }
45
46 std::shared_ptr<OH_NativeBuffer> pNativeBuffer(nativeBuffer, [](OH_NativeBuffer *nb) {
47 OH_NativeBuffer_Unreference(nb);
48 });
49
50 return pNativeBuffer;
51 }
52 }
53 }
54 }
55 }