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