• 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 
43     GSError CancelBuffer(uint32_t sequence, const sptr<BufferExtraData> &bedata) override;
44 
45     GSError FlushBuffer(uint32_t sequence, const sptr<BufferExtraData> &bedata,
46                         const sptr<SyncFence>& fence, BufferFlushConfigWithDamages &config) override;
47 
48     GSError GetLastFlushedBuffer(sptr<SurfaceBuffer>& buffer, sptr<SyncFence>& fence, float matrix[16]) override;
49 
50     GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override;
51 
52     GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override;
53 
54     uint32_t GetQueueSize() override;
55     GSError SetQueueSize(uint32_t queueSize) override;
56 
57     GSError GetName(std::string &name) override;
58     uint64_t GetUniqueId() override;
59     GSError GetNameAndUniqueId(std::string& name, uint64_t& uniqueId) override;
60 
61     int32_t GetDefaultWidth() override;
62     int32_t GetDefaultHeight() override;
63     uint32_t GetDefaultUsage() override;
64 
65     GSError CleanCache() override;
66     GSError GoBackground() override;
67 
68     GSError RegisterReleaseListener(sptr<IProducerListener> listener) override;
69     GSError UnRegisterReleaseListener() override;
70 
71     GSError SetTransform(GraphicTransformType transform) override;
72 
73     GSError IsSupportedAlloc(const std::vector<BufferVerifyAllocInfo> &infos, std::vector<bool> &supporteds) override;
74 
75     GSError Disconnect() override;
76 
77     GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override;
78     GSError SetMetaData(uint32_t sequence, const std::vector<GraphicHDRMetaData> &metaData) override;
79     GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key,
80                            const std::vector<uint8_t> &metaData) override;
81     GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override;
82     GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) override;
83 
84     bool GetStatus() const;
85     void SetStatus(bool status);
86 
87     sptr<NativeSurface> GetNativeSurface() override;
88 
89     GSError SendDeathRecipientObject() override;
90     void OnBufferProducerRemoteDied();
91 
92 private:
93     GSError CheckConnectLocked();
94     GSError SetTunnelHandle(const sptr<SurfaceTunnelHandle> &handle);
95 
96     int32_t RequestBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
97     int32_t CancelBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
98     int32_t FlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
99     int32_t AttachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
100     int32_t DetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
101     int32_t GetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
102     int32_t SetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
103     int32_t GetNameRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
104     int32_t GetDefaultWidthRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
105     int32_t GetDefaultHeightRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
106     int32_t GetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
107     int32_t GetUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
108     int32_t CleanCacheRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
109     int32_t RegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
110     int32_t UnRegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
111     int32_t SetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
112     int32_t IsSupportedAllocRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
113     int32_t GetNameAndUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
114     int32_t DisconnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
115     int32_t SetScalingModeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
116     int32_t SetMetaDataRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
117     int32_t SetMetaDataSetRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
118     int32_t SetTunnelHandleRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
119     int32_t GoBackgroundRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
120     int32_t GetPresentTimestampRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
121     int32_t GetLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
122     int32_t RegisterDeathRecipient(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
123 
124     using BufferQueueProducerFunc = int32_t (BufferQueueProducer::*)(MessageParcel &arguments,
125         MessageParcel &reply, MessageOption &option);
126     std::map<uint32_t, BufferQueueProducerFunc> memberFuncMap_;
127 
128     class ProducerSurfaceDeathRecipient : public IRemoteObject::DeathRecipient {
129     public:
130         explicit ProducerSurfaceDeathRecipient(wptr<BufferQueueProducer> producer);
131         virtual ~ProducerSurfaceDeathRecipient() = default;
132 
133         void OnRemoteDied(const wptr<IRemoteObject>& remoteObject) override;
134     private:
135         wptr<BufferQueueProducer> producer_;
136         std::string name_ = "DeathRecipient";
137     };
138     sptr<ProducerSurfaceDeathRecipient> producerSurfaceDeathRecipient_ = nullptr;
139     sptr<IRemoteObject> token_;
140 
141     int32_t connectedPid_ = 0;
142     sptr<BufferQueue> bufferQueue_ = nullptr;
143     std::string name_ = "not init";
144     std::mutex mutex_;
145 };
146 }; // namespace OHOS
147 
148 #endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
149