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