• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H
17 #define INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H
18 
19 #include <functional>
20 
21 #include <memory>
22 #include <refbase.h>
23 
24 #include "buffer_handle_utils.h"
25 #include "surface_type.h"
26 #include "egl_data.h"
27 #include "buffer_extra_data.h"
28 #include "native_buffer.h"
29 
30 struct BufferWrapper;
31 
32 namespace OHOS {
33 class MessageParcel;
34 class SurfaceBuffer : public RefBase {
35 public:
36     virtual BufferHandle *GetBufferHandle() const = 0;
37     virtual int32_t GetWidth() const = 0;
38     virtual int32_t GetHeight() const = 0;
39     virtual int32_t GetStride() const = 0;
40     virtual int32_t GetFormat() const = 0;
41     virtual uint64_t GetUsage() const = 0;
42     virtual uint64_t GetPhyAddr() const = 0;
43     virtual void *GetVirAddr() = 0;
44     virtual int32_t GetFileDescriptor() const = 0;
45     virtual uint32_t GetSize() const = 0;
46 
47     virtual const GraphicColorGamut& GetSurfaceBufferColorGamut() const = 0;
48     virtual const GraphicTransformType& GetSurfaceBufferTransform() const = 0;
49     virtual void SetSurfaceBufferColorGamut(const GraphicColorGamut& colorGamut) = 0;
50     virtual void SetSurfaceBufferTransform(const GraphicTransformType& transform) = 0;
51 
52     virtual int32_t GetSurfaceBufferWidth() const = 0;
53     virtual int32_t GetSurfaceBufferHeight() const = 0;
54     virtual void SetSurfaceBufferWidth(int32_t width) = 0;
55     virtual void SetSurfaceBufferHeight(int32_t width) = 0;
56 
57     virtual uint32_t GetSeqNum() const = 0;
58 
59     // opt EglData
60     virtual sptr<EglData> GetEglData() const = 0;
61     virtual void SetEglData(const sptr<EglData>& data) = 0;
62 
63     virtual void SetExtraData(const sptr<BufferExtraData> &bedata) = 0;
64     virtual const sptr<BufferExtraData>& GetExtraData() const = 0;
65     virtual GSError WriteToMessageParcel(MessageParcel &parcel) = 0;
66     virtual GSError ReadFromMessageParcel(MessageParcel &parcel) = 0;
67     virtual void SetBufferHandle(BufferHandle *handle) = 0;
68 
69     virtual BufferWrapper GetBufferWrapper() = 0;
70     virtual void SetBufferWrapper(BufferWrapper wrapper) = 0;
71 
72     // gralloc
73     virtual GSError Alloc(const BufferRequestConfig &config) = 0;
74     virtual GSError Map() = 0;
75     virtual GSError Unmap() = 0;
76     virtual GSError FlushCache() = 0;
77     virtual GSError InvalidateCache() = 0;
78 
79     // metadata
80     virtual GSError SetMetadata(uint32_t key, const std::vector<uint8_t>& value) = 0;
81     virtual GSError GetMetadata(uint32_t key, std::vector<uint8_t>& value) = 0;
82     virtual GSError ListMetadataKeys(std::vector<uint32_t>& keys) = 0;
83     virtual GSError EraseMetadataKey(uint32_t key) = 0;
84 
NativeBufferToSurfaceBuffer(OH_NativeBuffer * buffer)85     static SurfaceBuffer* NativeBufferToSurfaceBuffer(OH_NativeBuffer* buffer)
86     {
87         return reinterpret_cast<SurfaceBuffer *>(buffer);
88     };
89 
NativeBufferToSurfaceBuffer(OH_NativeBuffer const * buffer)90     static const SurfaceBuffer* NativeBufferToSurfaceBuffer(OH_NativeBuffer const* buffer)
91     {
92         return reinterpret_cast<SurfaceBuffer const*>(buffer);
93     };
94 
95     virtual OH_NativeBuffer* SurfaceBufferToNativeBuffer() = 0;
96 
97     static sptr<SurfaceBuffer> Create();
98 
99 protected:
SurfaceBuffer()100     SurfaceBuffer(){}
101     SurfaceBuffer(const SurfaceBuffer&) = delete;
102     SurfaceBuffer& operator=(const SurfaceBuffer&) = delete;
~SurfaceBuffer()103     virtual ~SurfaceBuffer(){}
104 };
105 
106 using OnReleaseFunc = std::function<GSError(sptr<SurfaceBuffer> &)>;
107 using OnDeleteBufferFunc = std::function<void(int32_t)>;
108 } // namespace OHOS
109 
110 #endif // INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H
111