• 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 FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
17 #define FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
18 
19 #include <vector>
20 #include <mutex>
21 #include <refbase.h>
22 #include <iremote_stub.h>
23 #include <message_parcel.h>
24 #include <message_option.h>
25 
26 #include "surface_type.h"
27 #include <ibuffer_producer.h>
28 
29 #include "buffer_queue.h"
30 
31 namespace OHOS {
32 class BufferQueueProducer : public IRemoteStub<IBufferProducer> {
33 public:
34     BufferQueueProducer(sptr<BufferQueue> bufferQueue);
35     virtual ~BufferQueueProducer();
36 
37     virtual int OnRemoteRequest(uint32_t code, MessageParcel &arguments,
38                                 MessageParcel &reply, MessageOption &option) override;
39 
40     virtual GSError RequestBuffer(const BufferRequestConfig &config, sptr<BufferExtraData> &bedata,
41                                   RequestBufferReturnValue &retval) override;
42     GSError RequestBuffers(const BufferRequestConfig &config, std::vector<sptr<BufferExtraData>> &bedata,
43         std::vector<RequestBufferReturnValue> &retvalues) override;
44 
45     GSError GetProducerInitInfo(ProducerInitInfo &info) override;
46 
47     GSError CancelBuffer(uint32_t sequence, sptr<BufferExtraData> bedata) override;
48 
49     GSError FlushBuffer(uint32_t sequence, sptr<BufferExtraData> bedata,
50                         sptr<SyncFence> fence, BufferFlushConfigWithDamages &config) override;
51 
52     GSError FlushBuffers(const std::vector<uint32_t> &sequences,
53         const std::vector<sptr<BufferExtraData>> &bedata,
54         const std::vector<sptr<SyncFence>> &fences,
55         const std::vector<BufferFlushConfigWithDamages> &configs) override;
56     GSError GetLastFlushedBuffer(sptr<SurfaceBuffer>& buffer, sptr<SyncFence>& fence,
57         float matrix[16], bool isUseNewMatrix) override;
58 
59     GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override;
60     GSError AttachBuffer(sptr<SurfaceBuffer>& buffer, int32_t timeOut) override;
61 
62     GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override;
63 
64     uint32_t GetQueueSize() override;
65     GSError SetQueueSize(uint32_t queueSize) override;
66 
67     GSError GetName(std::string &name) override;
68     uint64_t GetUniqueId() override;
69     GSError GetNameAndUniqueId(std::string& name, uint64_t& uniqueId) override;
70 
71     int32_t GetDefaultWidth() override;
72     int32_t GetDefaultHeight() override;
73     GSError SetDefaultUsage(uint64_t usage) override;
74     uint64_t GetDefaultUsage() override;
75 
76     GSError CleanCache(bool cleanAll, uint32_t *bufSeqNum) override;
77     GSError GoBackground() override;
78 
79     GSError RegisterReleaseListener(sptr<IProducerListener> listener) override;
80     GSError RegisterReleaseListenerBackup(sptr<IProducerListener> listener) override;
81     GSError UnRegisterReleaseListener() override;
82     GSError UnRegisterReleaseListenerBackup() override;
83     GSError RegisterPropertyListener(sptr<IProducerListener> listener, uint64_t producerId) override;
84     GSError UnRegisterPropertyListener(uint64_t producerId) override;
85 
86     GSError SetTransform(GraphicTransformType transform) override;
87     GSError GetTransform(GraphicTransformType &transform) override;
88 
89     GSError Connect() override;
90     GSError Disconnect(uint32_t *bufSeqNum) override;
91 
92     GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override;
93     GSError SetBufferHold(bool hold) override;
94     GSError SetBufferName(const std::string &bufferName) override;
95     GSError SetMetaData(uint32_t sequence, const std::vector<GraphicHDRMetaData> &metaData) override;
96     GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key,
97                            const std::vector<uint8_t> &metaData) override;
98     GSError SetGlobalAlpha(int32_t alpha) override;
99     GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override;
100     GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) override;
101 
102     bool GetStatus() const;
103     void SetStatus(bool status);
104 
105     sptr<NativeSurface> GetNativeSurface() override;
106 
107     void OnBufferProducerRemoteDied();
108     GSError AttachBufferToQueue(sptr<SurfaceBuffer> buffer) override;
109     GSError DetachBufferFromQueue(sptr<SurfaceBuffer> buffer) override;
110 
111     GSError SetTransformHint(GraphicTransformType transformHint, uint64_t fromId) override;
112     GSError GetTransformHint(GraphicTransformType &transformHint) override;
113     GSError SetScalingMode(ScalingMode scalingMode) override;
114 
115     GSError SetSurfaceSourceType(OHSurfaceSource sourceType) override;
116     GSError GetSurfaceSourceType(OHSurfaceSource &sourceType) override;
117 
118     GSError SetSurfaceAppFrameworkType(std::string appFrameworkType) override;
119     GSError GetSurfaceAppFrameworkType(std::string &appFrameworkType) override;
120 
121     GSError SetHdrWhitePointBrightness(float brightness) override;
122     GSError SetSdrWhitePointBrightness(float brightness) override;
123 
124     GSError AcquireLastFlushedBuffer(sptr<SurfaceBuffer> &buffer, sptr<SyncFence> &fence,
125         float matrix[16], uint32_t matrixSize, bool isUseNewMatrix) override;
126     GSError ReleaseLastFlushedBuffer(uint32_t sequence) override;
127     GSError RequestAndDetachBuffer(const BufferRequestConfig& config, sptr<BufferExtraData>& bedata,
128         RequestBufferReturnValue& retval) override;
129     GSError AttachAndFlushBuffer(sptr<SurfaceBuffer>& buffer, sptr<BufferExtraData>& bedata,
130         const sptr<SyncFence>& fence, BufferFlushConfigWithDamages& config, bool needMap) override;
131     GSError GetCycleBuffersNumber(uint32_t& cycleBuffersNumber) override;
132     GSError SetCycleBuffersNumber(uint32_t cycleBuffersNumber) override;
133 
134     GSError ConnectStrictly() override;
135     GSError DisconnectStrictly() override;
136 private:
137     GSError CheckConnectLocked();
138     GSError SetTunnelHandle(const sptr<SurfaceTunnelHandle> &handle);
139     bool HandleDeathRecipient(sptr<IRemoteObject> token);
140 
141     int32_t GetProducerInitInfoRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
142     int32_t RequestBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
143     int32_t RequestBuffersRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
144     int32_t CancelBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
145     int32_t FlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
146     int32_t FlushBuffersRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
147     int32_t AttachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
148     int32_t DetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
149     int32_t GetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
150     int32_t SetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
151     int32_t GetNameRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
152     int32_t GetDefaultWidthRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
153     int32_t GetDefaultHeightRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
154     int32_t SetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
155     int32_t GetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
156     int32_t GetUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
157     int32_t CleanCacheRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
158     int32_t RegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
159     int32_t RegisterReleaseListenerBackupRemote(MessageParcel &arguments, MessageParcel &reply,
160                                                    MessageOption &option);
161     int32_t UnRegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
162     int32_t UnRegisterReleaseListenerBackupRemote(MessageParcel &arguments, MessageParcel &reply,
163                                                      MessageOption &option);
164     int32_t SetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
165     int32_t GetNameAndUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
166     int32_t DisconnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
167     int32_t ConnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
168     int32_t SetScalingModeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
169     int32_t SetMetaDataRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
170     int32_t SetMetaDataSetRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
171     int32_t SetTunnelHandleRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
172     int32_t GoBackgroundRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
173     int32_t GetPresentTimestampRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
174     int32_t GetLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
175     int32_t GetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
176     int32_t AttachBufferToQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
177     int32_t DetachBufferFromQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
178     int32_t SetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
179     int32_t GetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
180     int32_t SetBufferHoldRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
181     int32_t SetBufferNameRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
182     int32_t SetSurfaceSourceTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
183     int32_t GetSurfaceSourceTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
184     int32_t SetSurfaceAppFrameworkTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
185     int32_t GetSurfaceAppFrameworkTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
186 
187     int32_t SetScalingModeV2Remote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
188     int32_t SetHdrWhitePointBrightnessRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
189     int32_t SetSdrWhitePointBrightnessRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
190     int32_t AcquireLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
191     int32_t ReleaseLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
192     int32_t SetGlobalAlphaRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
193     int32_t RequestAndDetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
194     int32_t AttachAndFlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
195     int32_t GetRotatingBuffersNumberRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
196     int32_t SetRotatingBuffersNumberRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
197     int32_t DisconnectStrictlyRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
198     int32_t ConnectStrictlyRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
199     int32_t RegisterPropertyListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
200     int32_t UnRegisterPropertyListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
201 
202     void SetConnectedPid(int32_t connectedPid);
203     int32_t AttachBufferToQueueReadBuffer(MessageParcel &arguments,
204         MessageParcel &reply, MessageOption &option, sptr<SurfaceBuffer> &buffer);
205     bool CheckIsAlive();
206 
207     static const std::map<uint32_t, std::function<int32_t(BufferQueueProducer *that, MessageParcel &arguments,
208         MessageParcel &reply, MessageOption &option)>> memberFuncMap_;
209 
210     class ProducerSurfaceDeathRecipient : public IRemoteObject::DeathRecipient {
211     public:
212         explicit ProducerSurfaceDeathRecipient(wptr<BufferQueueProducer> producer);
213         virtual ~ProducerSurfaceDeathRecipient() = default;
214 
215         void OnRemoteDied(const wptr<IRemoteObject>& remoteObject) override;
216     private:
217         wptr<BufferQueueProducer> producer_;
218         std::string name_ = "DeathRecipient";
219     };
220     sptr<ProducerSurfaceDeathRecipient> producerSurfaceDeathRecipient_ = nullptr;
221     sptr<IRemoteObject> token_ = nullptr;
222 
223     int32_t connectedPid_ = 0;
224     bool isDisconnectStrictly_ = false;
225     sptr<BufferQueue> bufferQueue_ = nullptr;
226     std::string name_ = "not init";
227     std::mutex mutex_;
228     uint64_t uniqueId_ = 0;
229     static const uint32_t MAGIC_INIT = 0x16273849;
230     uint32_t magicNum_ = MAGIC_INIT;
231 };
232 }; // namespace OHOS
233 
234 #endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
235