• 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 
NativeBufferToSurfaceBuffer(OH_NativeBuffer * buffer)79     static SurfaceBuffer* NativeBufferToSurfaceBuffer(OH_NativeBuffer* buffer)
80     {
81         return reinterpret_cast<SurfaceBuffer *>(buffer);
82     };
83 
NativeBufferToSurfaceBuffer(OH_NativeBuffer const * buffer)84     static const SurfaceBuffer* NativeBufferToSurfaceBuffer(OH_NativeBuffer const* buffer)
85     {
86         return reinterpret_cast<SurfaceBuffer const*>(buffer);
87     };
88 
89     virtual OH_NativeBuffer* SurfaceBufferToNativeBuffer() = 0;
90 
91     static sptr<SurfaceBuffer> Create();
92 
93 protected:
SurfaceBuffer()94     SurfaceBuffer(){}
95     SurfaceBuffer(const SurfaceBuffer&) = delete;
96     SurfaceBuffer& operator=(const SurfaceBuffer&) = delete;
~SurfaceBuffer()97     virtual ~SurfaceBuffer(){}
98 };
99 
100 using OnReleaseFunc = std::function<GSError(sptr<SurfaceBuffer> &)>;
101 using OnDeleteBufferFunc = std::function<void(int32_t)>;
102 } // namespace OHOS
103 
104 #endif // INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H
105