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, BufferFlushConfig &config) override; 47 48 GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override; 49 50 GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override; 51 52 uint32_t GetQueueSize() override; 53 GSError SetQueueSize(uint32_t queueSize) override; 54 55 GSError GetName(std::string &name) override; 56 uint64_t GetUniqueId() override; 57 GSError GetNameAndUniqueId(std::string& name, uint64_t& uniqueId) override; 58 59 int32_t GetDefaultWidth() override; 60 int32_t GetDefaultHeight() override; 61 uint32_t GetDefaultUsage() override; 62 63 GSError CleanCache() override; 64 GSError GoBackground() override; 65 66 GSError RegisterReleaseListener(OnReleaseFunc func) override; 67 68 GSError SetTransform(GraphicTransformType transform) override; 69 70 GSError IsSupportedAlloc(const std::vector<BufferVerifyAllocInfo> &infos, std::vector<bool> &supporteds) override; 71 72 GSError Disconnect() override; 73 74 GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override; 75 GSError SetMetaData(uint32_t sequence, const std::vector<GraphicHDRMetaData> &metaData) override; 76 GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key, 77 const std::vector<uint8_t> &metaData) override; 78 GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override; 79 GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) override; 80 81 bool GetStatus() const; 82 void SetStatus(bool status); 83 84 sptr<NativeSurface> GetNativeSurface() override; 85 86 private: 87 GSError CheckConnectLocked(); 88 GSError SetTunnelHandle(const sptr<SurfaceTunnelHandle> &handle); 89 90 int32_t RequestBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 91 int32_t CancelBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 92 int32_t FlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 93 int32_t AttachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 94 int32_t DetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 95 int32_t GetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 96 int32_t SetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 97 int32_t GetNameRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 98 int32_t GetDefaultWidthRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 99 int32_t GetDefaultHeightRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 100 int32_t GetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 101 int32_t GetUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 102 int32_t CleanCacheRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 103 int32_t RegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 104 int32_t SetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 105 int32_t IsSupportedAllocRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 106 int32_t GetNameAndUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 107 int32_t DisconnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 108 int32_t SetScalingModeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 109 int32_t SetMetaDataRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 110 int32_t SetMetaDataSetRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 111 int32_t SetTunnelHandleRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 112 int32_t GoBackgroundRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 113 int32_t GetPresentTimestampRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); 114 115 using BufferQueueProducerFunc = int32_t (BufferQueueProducer::*)(MessageParcel &arguments, 116 MessageParcel &reply, MessageOption &option); 117 std::map<uint32_t, BufferQueueProducerFunc> memberFuncMap_; 118 119 int32_t connectedPid_ = 0; 120 sptr<BufferQueue> bufferQueue_ = nullptr; 121 std::string name_ = "not init"; 122 std::mutex mutex_; 123 }; 124 }; // namespace OHOS 125 126 #endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H 127