/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H #define FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H #include #include #include #include #include #include #include "surface_type.h" #include #include "buffer_queue.h" namespace OHOS { class BufferQueueProducer : public IRemoteStub { public: BufferQueueProducer(sptr bufferQueue); virtual ~BufferQueueProducer(); virtual int OnRemoteRequest(uint32_t code, MessageParcel &arguments, MessageParcel &reply, MessageOption &option) override; virtual GSError RequestBuffer(const BufferRequestConfig &config, sptr &bedata, RequestBufferReturnValue &retval) override; GSError RequestBuffers(const BufferRequestConfig &config, std::vector> &bedata, std::vector &retvalues) override; GSError GetProducerInitInfo(ProducerInitInfo &info) override; GSError CancelBuffer(uint32_t sequence, sptr bedata) override; GSError FlushBuffer(uint32_t sequence, sptr bedata, sptr fence, BufferFlushConfigWithDamages &config) override; GSError FlushBuffers(const std::vector &sequences, const std::vector> &bedata, const std::vector> &fences, const std::vector &configs) override; GSError GetLastFlushedBuffer(sptr& buffer, sptr& fence, float matrix[16], bool isUseNewMatrix) override; GSError AttachBuffer(sptr& buffer) override; GSError AttachBuffer(sptr& buffer, int32_t timeOut) override; GSError DetachBuffer(sptr& buffer) override; uint32_t GetQueueSize() override; GSError SetQueueSize(uint32_t queueSize) override; GSError GetName(std::string &name) override; uint64_t GetUniqueId() override; GSError GetNameAndUniqueId(std::string& name, uint64_t& uniqueId) override; int32_t GetDefaultWidth() override; int32_t GetDefaultHeight() override; GSError SetDefaultUsage(uint64_t usage) override; uint64_t GetDefaultUsage() override; GSError CleanCache(bool cleanAll) override; GSError GoBackground() override; GSError RegisterReleaseListener(sptr listener) override; GSError UnRegisterReleaseListener() override; GSError SetTransform(GraphicTransformType transform) override; GSError GetTransform(GraphicTransformType &transform) override; GSError IsSupportedAlloc(const std::vector &infos, std::vector &supporteds) override; GSError Connect() override; GSError Disconnect() override; GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override; GSError SetBufferHold(bool hold) override; GSError SetMetaData(uint32_t sequence, const std::vector &metaData) override; GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key, const std::vector &metaData) override; GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override; GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) override; bool GetStatus() const; void SetStatus(bool status); sptr GetNativeSurface() override; void OnBufferProducerRemoteDied(); GSError AttachBufferToQueue(sptr buffer) override; GSError DetachBufferFromQueue(sptr buffer) override; GSError SetTransformHint(GraphicTransformType transformHint) override; GSError GetTransformHint(GraphicTransformType &transformHint) override; GSError SetScalingMode(ScalingMode scalingMode) override; GSError SetSurfaceSourceType(OHSurfaceSource sourceType) override; GSError GetSurfaceSourceType(OHSurfaceSource &sourceType) override; GSError SetSurfaceAppFrameworkType(std::string appFrameworkType) override; GSError GetSurfaceAppFrameworkType(std::string &appFrameworkType) override; GSError SetHdrWhitePointBrightness(float brightness) override; GSError SetSdrWhitePointBrightness(float brightness) override; GSError AcquireLastFlushedBuffer(sptr &buffer, sptr &fence, float matrix[16], uint32_t matrixSize, bool isUseNewMatrix) override; GSError ReleaseLastFlushedBuffer(uint32_t sequence) override; GSError RequestAndDetachBuffer(const BufferRequestConfig& config, sptr& bedata, RequestBufferReturnValue& retval) override; GSError AttachAndFlushBuffer(sptr& buffer, sptr& bedata, const sptr& fence, BufferFlushConfigWithDamages& config, bool needMap) override; private: GSError CheckConnectLocked(); GSError SetTunnelHandle(const sptr &handle); bool HandleDeathRecipient(sptr token); int32_t GetProducerInitInfoRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t RequestBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t RequestBuffersRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t CancelBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t FlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t FlushBuffersRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t AttachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t DetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetNameRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetDefaultWidthRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetDefaultHeightRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t CleanCacheRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t RegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t UnRegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t IsSupportedAllocRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetNameAndUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t DisconnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t ConnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetScalingModeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetMetaDataRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetMetaDataSetRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetTunnelHandleRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GoBackgroundRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetPresentTimestampRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t AttachBufferToQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t DetachBufferFromQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetBufferHoldRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetSurfaceSourceTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetSurfaceSourceTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetSurfaceAppFrameworkTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t GetSurfaceAppFrameworkTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetScalingModeV2Remote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetHdrWhitePointBrightnessRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t SetSdrWhitePointBrightnessRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t AcquireLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t ReleaseLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t RequestAndDetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t AttachAndFlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t AttachBufferToQueueReadBuffer(MessageParcel &arguments, MessageParcel &reply, MessageOption &option, sptr &buffer); using BufferQueueProducerFunc = int32_t (BufferQueueProducer::*)(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); std::map> memberFuncMap_; class ProducerSurfaceDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit ProducerSurfaceDeathRecipient(wptr producer); virtual ~ProducerSurfaceDeathRecipient() = default; void OnRemoteDied(const wptr& remoteObject) override; private: wptr producer_; std::string name_ = "DeathRecipient"; }; sptr producerSurfaceDeathRecipient_ = nullptr; sptr token_ = nullptr; int32_t connectedPid_ = 0; sptr bufferQueue_ = nullptr; std::string name_ = "not init"; std::mutex mutex_; uint64_t uniqueId_ = 0; }; }; // namespace OHOS #endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H