1fa7767c5Sopenharmony_ci/*
2fa7767c5Sopenharmony_ci * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License.
5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at
6fa7767c5Sopenharmony_ci *
7fa7767c5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fa7767c5Sopenharmony_ci *
9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and
13fa7767c5Sopenharmony_ci * limitations under the License.
14fa7767c5Sopenharmony_ci */
15fa7767c5Sopenharmony_ci
16fa7767c5Sopenharmony_ci#ifndef HISTREAMER_PLUGIN_COMMON_SURFACE_MEMORY_H
17fa7767c5Sopenharmony_ci#define HISTREAMER_PLUGIN_COMMON_SURFACE_MEMORY_H
18fa7767c5Sopenharmony_ci
19fa7767c5Sopenharmony_ci#if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT)
20fa7767c5Sopenharmony_ci
21fa7767c5Sopenharmony_ci#include "osal/task/task.h"
22fa7767c5Sopenharmony_ci#include "osal/task/mutex.h"
23fa7767c5Sopenharmony_ci#include "plugin//plugin_buffer.h"
24fa7767c5Sopenharmony_ci#include "common/surface_allocator.h"
25fa7767c5Sopenharmony_ci#include "refbase.h"
26fa7767c5Sopenharmony_ci#include "surface/surface.h"
27fa7767c5Sopenharmony_ci
28fa7767c5Sopenharmony_cinamespace OHOS {
29fa7767c5Sopenharmony_cinamespace Media {
30fa7767c5Sopenharmony_cinamespace Plugins {
31fa7767c5Sopenharmony_ciclass SurfaceMemory : public Memory {
32fa7767c5Sopenharmony_cipublic:
33fa7767c5Sopenharmony_ci    ~SurfaceMemory();
34fa7767c5Sopenharmony_ci
35fa7767c5Sopenharmony_ci    sptr<SurfaceBuffer> GetSurfaceBuffer();
36fa7767c5Sopenharmony_ci
37fa7767c5Sopenharmony_ci    int32_t GetFlushFence();
38fa7767c5Sopenharmony_ci
39fa7767c5Sopenharmony_ci    BufferHandle *GetBufferHandle();
40fa7767c5Sopenharmony_ci
41fa7767c5Sopenharmony_ci    uint32_t GetSurfaceBufferStride();
42fa7767c5Sopenharmony_ci
43fa7767c5Sopenharmony_ci    void SetNeedRender(bool needRender);
44fa7767c5Sopenharmony_ci
45fa7767c5Sopenharmony_ciprotected:
46fa7767c5Sopenharmony_ci    uint8_t* GetRealAddr() const override;
47fa7767c5Sopenharmony_ci
48fa7767c5Sopenharmony_ciprivate:
49fa7767c5Sopenharmony_ci    explicit SurfaceMemory(size_t capacity, std::shared_ptr<Allocator> allocator = nullptr, size_t align = 1);
50fa7767c5Sopenharmony_ci    explicit SurfaceMemory(sptr<SurfaceBuffer> surfaceBuffer, int32_t surfaceCapacity);
51fa7767c5Sopenharmony_ci
52fa7767c5Sopenharmony_ci    void AllocSurfaceBuffer();
53fa7767c5Sopenharmony_ci    void ReleaseSurfaceBuffer();
54fa7767c5Sopenharmony_ci
55fa7767c5Sopenharmony_ci    mutable Mutex memMutex_ {};
56fa7767c5Sopenharmony_ci
57fa7767c5Sopenharmony_ci    /// Surface buffer
58fa7767c5Sopenharmony_ci    sptr<SurfaceBuffer> surfaceBuffer_ {nullptr};
59fa7767c5Sopenharmony_ci
60fa7767c5Sopenharmony_ci    std::shared_ptr<SurfaceAllocator> surfaceAllocator_ {nullptr};
61fa7767c5Sopenharmony_ci
62fa7767c5Sopenharmony_ci    /// the fence fd for Surface
63fa7767c5Sopenharmony_ci    int32_t fence_ {-1};
64fa7767c5Sopenharmony_ci
65fa7767c5Sopenharmony_ci    uint32_t stride_ {0};
66fa7767c5Sopenharmony_ci
67fa7767c5Sopenharmony_ci    bool needRender_ {false};
68fa7767c5Sopenharmony_ci
69fa7767c5Sopenharmony_ci    friend class Buffer;
70fa7767c5Sopenharmony_ci};
71fa7767c5Sopenharmony_ci} // namespace Plugins
72fa7767c5Sopenharmony_ci} // namespace Media
73fa7767c5Sopenharmony_ci} // namespace OHOS
74fa7767c5Sopenharmony_ci
75fa7767c5Sopenharmony_ci#endif
76fa7767c5Sopenharmony_ci#endif // HISTREAMER_PLUGIN_COMMON_SURFACE_MEMORY_H
77