132a6e48fSopenharmony_ci/*
232a6e48fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
332a6e48fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
432a6e48fSopenharmony_ci * you may not use this file except in compliance with the License.
532a6e48fSopenharmony_ci * You may obtain a copy of the License at
632a6e48fSopenharmony_ci *
732a6e48fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
832a6e48fSopenharmony_ci *
932a6e48fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1032a6e48fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1132a6e48fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1232a6e48fSopenharmony_ci * See the License for the specific language governing permissions and
1332a6e48fSopenharmony_ci * limitations under the License.
1432a6e48fSopenharmony_ci */
1532a6e48fSopenharmony_ci
1632a6e48fSopenharmony_ci#ifndef FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
1732a6e48fSopenharmony_ci#define FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
1832a6e48fSopenharmony_ci
1932a6e48fSopenharmony_ci#include <vector>
2032a6e48fSopenharmony_ci#include <mutex>
2132a6e48fSopenharmony_ci#include <refbase.h>
2232a6e48fSopenharmony_ci#include <iremote_stub.h>
2332a6e48fSopenharmony_ci#include <message_parcel.h>
2432a6e48fSopenharmony_ci#include <message_option.h>
2532a6e48fSopenharmony_ci
2632a6e48fSopenharmony_ci#include "surface_type.h"
2732a6e48fSopenharmony_ci#include <ibuffer_producer.h>
2832a6e48fSopenharmony_ci
2932a6e48fSopenharmony_ci#include "buffer_queue.h"
3032a6e48fSopenharmony_ci
3132a6e48fSopenharmony_cinamespace OHOS {
3232a6e48fSopenharmony_ciclass BufferQueueProducer : public IRemoteStub<IBufferProducer> {
3332a6e48fSopenharmony_cipublic:
3432a6e48fSopenharmony_ci    BufferQueueProducer(sptr<BufferQueue> bufferQueue);
3532a6e48fSopenharmony_ci    virtual ~BufferQueueProducer();
3632a6e48fSopenharmony_ci
3732a6e48fSopenharmony_ci    virtual int OnRemoteRequest(uint32_t code, MessageParcel &arguments,
3832a6e48fSopenharmony_ci                                MessageParcel &reply, MessageOption &option) override;
3932a6e48fSopenharmony_ci
4032a6e48fSopenharmony_ci    virtual GSError RequestBuffer(const BufferRequestConfig &config, sptr<BufferExtraData> &bedata,
4132a6e48fSopenharmony_ci                                  RequestBufferReturnValue &retval) override;
4232a6e48fSopenharmony_ci    GSError RequestBuffers(const BufferRequestConfig &config, std::vector<sptr<BufferExtraData>> &bedata,
4332a6e48fSopenharmony_ci        std::vector<RequestBufferReturnValue> &retvalues) override;
4432a6e48fSopenharmony_ci
4532a6e48fSopenharmony_ci    GSError GetProducerInitInfo(ProducerInitInfo &info) override;
4632a6e48fSopenharmony_ci
4732a6e48fSopenharmony_ci    GSError CancelBuffer(uint32_t sequence, sptr<BufferExtraData> bedata) override;
4832a6e48fSopenharmony_ci
4932a6e48fSopenharmony_ci    GSError FlushBuffer(uint32_t sequence, sptr<BufferExtraData> bedata,
5032a6e48fSopenharmony_ci                        sptr<SyncFence> fence, BufferFlushConfigWithDamages &config) override;
5132a6e48fSopenharmony_ci
5232a6e48fSopenharmony_ci    GSError FlushBuffers(const std::vector<uint32_t> &sequences,
5332a6e48fSopenharmony_ci        const std::vector<sptr<BufferExtraData>> &bedata,
5432a6e48fSopenharmony_ci        const std::vector<sptr<SyncFence>> &fences,
5532a6e48fSopenharmony_ci        const std::vector<BufferFlushConfigWithDamages> &configs) override;
5632a6e48fSopenharmony_ci    GSError GetLastFlushedBuffer(sptr<SurfaceBuffer>& buffer, sptr<SyncFence>& fence,
5732a6e48fSopenharmony_ci        float matrix[16], bool isUseNewMatrix) override;
5832a6e48fSopenharmony_ci
5932a6e48fSopenharmony_ci    GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override;
6032a6e48fSopenharmony_ci    GSError AttachBuffer(sptr<SurfaceBuffer>& buffer, int32_t timeOut) override;
6132a6e48fSopenharmony_ci
6232a6e48fSopenharmony_ci    GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override;
6332a6e48fSopenharmony_ci
6432a6e48fSopenharmony_ci    uint32_t GetQueueSize() override;
6532a6e48fSopenharmony_ci    GSError SetQueueSize(uint32_t queueSize) override;
6632a6e48fSopenharmony_ci
6732a6e48fSopenharmony_ci    GSError GetName(std::string &name) override;
6832a6e48fSopenharmony_ci    uint64_t GetUniqueId() override;
6932a6e48fSopenharmony_ci    GSError GetNameAndUniqueId(std::string& name, uint64_t& uniqueId) override;
7032a6e48fSopenharmony_ci
7132a6e48fSopenharmony_ci    int32_t GetDefaultWidth() override;
7232a6e48fSopenharmony_ci    int32_t GetDefaultHeight() override;
7332a6e48fSopenharmony_ci    GSError SetDefaultUsage(uint64_t usage) override;
7432a6e48fSopenharmony_ci    uint64_t GetDefaultUsage() override;
7532a6e48fSopenharmony_ci
7632a6e48fSopenharmony_ci    GSError CleanCache(bool cleanAll) override;
7732a6e48fSopenharmony_ci    GSError GoBackground() override;
7832a6e48fSopenharmony_ci
7932a6e48fSopenharmony_ci    GSError RegisterReleaseListener(sptr<IProducerListener> listener) override;
8032a6e48fSopenharmony_ci    GSError UnRegisterReleaseListener() override;
8132a6e48fSopenharmony_ci
8232a6e48fSopenharmony_ci    GSError SetTransform(GraphicTransformType transform) override;
8332a6e48fSopenharmony_ci    GSError GetTransform(GraphicTransformType &transform) override;
8432a6e48fSopenharmony_ci
8532a6e48fSopenharmony_ci    GSError IsSupportedAlloc(const std::vector<BufferVerifyAllocInfo> &infos, std::vector<bool> &supporteds) override;
8632a6e48fSopenharmony_ci
8732a6e48fSopenharmony_ci    GSError Connect() override;
8832a6e48fSopenharmony_ci    GSError Disconnect() override;
8932a6e48fSopenharmony_ci
9032a6e48fSopenharmony_ci    GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) override;
9132a6e48fSopenharmony_ci    GSError SetBufferHold(bool hold) override;
9232a6e48fSopenharmony_ci    GSError SetMetaData(uint32_t sequence, const std::vector<GraphicHDRMetaData> &metaData) override;
9332a6e48fSopenharmony_ci    GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key,
9432a6e48fSopenharmony_ci                           const std::vector<uint8_t> &metaData) override;
9532a6e48fSopenharmony_ci    GSError SetGlobalAlpha(int32_t alpha) override;
9632a6e48fSopenharmony_ci    GSError SetTunnelHandle(const GraphicExtDataHandle *handle) override;
9732a6e48fSopenharmony_ci    GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) override;
9832a6e48fSopenharmony_ci
9932a6e48fSopenharmony_ci    bool GetStatus() const;
10032a6e48fSopenharmony_ci    void SetStatus(bool status);
10132a6e48fSopenharmony_ci
10232a6e48fSopenharmony_ci    sptr<NativeSurface> GetNativeSurface() override;
10332a6e48fSopenharmony_ci
10432a6e48fSopenharmony_ci    void OnBufferProducerRemoteDied();
10532a6e48fSopenharmony_ci    GSError AttachBufferToQueue(sptr<SurfaceBuffer> buffer) override;
10632a6e48fSopenharmony_ci    GSError DetachBufferFromQueue(sptr<SurfaceBuffer> buffer) override;
10732a6e48fSopenharmony_ci
10832a6e48fSopenharmony_ci    GSError SetTransformHint(GraphicTransformType transformHint) override;
10932a6e48fSopenharmony_ci    GSError GetTransformHint(GraphicTransformType &transformHint) override;
11032a6e48fSopenharmony_ci    GSError SetScalingMode(ScalingMode scalingMode) override;
11132a6e48fSopenharmony_ci
11232a6e48fSopenharmony_ci    GSError SetSurfaceSourceType(OHSurfaceSource sourceType) override;
11332a6e48fSopenharmony_ci    GSError GetSurfaceSourceType(OHSurfaceSource &sourceType) override;
11432a6e48fSopenharmony_ci
11532a6e48fSopenharmony_ci    GSError SetSurfaceAppFrameworkType(std::string appFrameworkType) override;
11632a6e48fSopenharmony_ci    GSError GetSurfaceAppFrameworkType(std::string &appFrameworkType) override;
11732a6e48fSopenharmony_ci
11832a6e48fSopenharmony_ci    GSError SetHdrWhitePointBrightness(float brightness) override;
11932a6e48fSopenharmony_ci    GSError SetSdrWhitePointBrightness(float brightness) override;
12032a6e48fSopenharmony_ci
12132a6e48fSopenharmony_ci    GSError AcquireLastFlushedBuffer(sptr<SurfaceBuffer> &buffer, sptr<SyncFence> &fence,
12232a6e48fSopenharmony_ci        float matrix[16], uint32_t matrixSize, bool isUseNewMatrix) override;
12332a6e48fSopenharmony_ci    GSError ReleaseLastFlushedBuffer(uint32_t sequence) override;
12432a6e48fSopenharmony_ci
12532a6e48fSopenharmony_ciprivate:
12632a6e48fSopenharmony_ci    GSError CheckConnectLocked();
12732a6e48fSopenharmony_ci    GSError SetTunnelHandle(const sptr<SurfaceTunnelHandle> &handle);
12832a6e48fSopenharmony_ci    bool HandleDeathRecipient(sptr<IRemoteObject> token);
12932a6e48fSopenharmony_ci
13032a6e48fSopenharmony_ci    int32_t GetProducerInitInfoRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13132a6e48fSopenharmony_ci    int32_t RequestBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13232a6e48fSopenharmony_ci    int32_t RequestBuffersRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13332a6e48fSopenharmony_ci    int32_t CancelBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13432a6e48fSopenharmony_ci    int32_t FlushBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13532a6e48fSopenharmony_ci    int32_t FlushBuffersRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13632a6e48fSopenharmony_ci    int32_t AttachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13732a6e48fSopenharmony_ci    int32_t DetachBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13832a6e48fSopenharmony_ci    int32_t GetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
13932a6e48fSopenharmony_ci    int32_t SetQueueSizeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14032a6e48fSopenharmony_ci    int32_t GetNameRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14132a6e48fSopenharmony_ci    int32_t GetDefaultWidthRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14232a6e48fSopenharmony_ci    int32_t GetDefaultHeightRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14332a6e48fSopenharmony_ci    int32_t GetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14432a6e48fSopenharmony_ci    int32_t SetDefaultUsageRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14532a6e48fSopenharmony_ci    int32_t GetUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14632a6e48fSopenharmony_ci    int32_t CleanCacheRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14732a6e48fSopenharmony_ci    int32_t RegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14832a6e48fSopenharmony_ci    int32_t UnRegisterReleaseListenerRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
14932a6e48fSopenharmony_ci    int32_t SetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15032a6e48fSopenharmony_ci    int32_t IsSupportedAllocRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15132a6e48fSopenharmony_ci    int32_t GetNameAndUniqueIdRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15232a6e48fSopenharmony_ci    int32_t DisconnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15332a6e48fSopenharmony_ci    int32_t ConnectRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15432a6e48fSopenharmony_ci    int32_t SetScalingModeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15532a6e48fSopenharmony_ci    int32_t SetMetaDataRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15632a6e48fSopenharmony_ci    int32_t SetMetaDataSetRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15732a6e48fSopenharmony_ci    int32_t SetTunnelHandleRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15832a6e48fSopenharmony_ci    int32_t GoBackgroundRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
15932a6e48fSopenharmony_ci    int32_t GetPresentTimestampRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16032a6e48fSopenharmony_ci    int32_t GetLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16132a6e48fSopenharmony_ci    int32_t GetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16232a6e48fSopenharmony_ci    int32_t AttachBufferToQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16332a6e48fSopenharmony_ci    int32_t DetachBufferFromQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16432a6e48fSopenharmony_ci    int32_t SetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16532a6e48fSopenharmony_ci    int32_t GetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16632a6e48fSopenharmony_ci    int32_t SetBufferHoldRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16732a6e48fSopenharmony_ci    int32_t SetScalingModeV2Remote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16832a6e48fSopenharmony_ci    int32_t SetSurfaceSourceTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
16932a6e48fSopenharmony_ci    int32_t GetSurfaceSourceTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17032a6e48fSopenharmony_ci
17132a6e48fSopenharmony_ci    int32_t SetSurfaceAppFrameworkTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17232a6e48fSopenharmony_ci    int32_t GetSurfaceAppFrameworkTypeRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17332a6e48fSopenharmony_ci    int32_t SetHdrWhitePointBrightnessRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17432a6e48fSopenharmony_ci    int32_t SetSdrWhitePointBrightnessRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17532a6e48fSopenharmony_ci    int32_t AcquireLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17632a6e48fSopenharmony_ci    int32_t ReleaseLastFlushedBufferRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17732a6e48fSopenharmony_ci    int32_t SetGlobalAlphaRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option);
17832a6e48fSopenharmony_ci
17932a6e48fSopenharmony_ci    std::map<uint32_t, std::function<int32_t(BufferQueueProducer *that, MessageParcel &arguments,
18032a6e48fSopenharmony_ci        MessageParcel &reply, MessageOption &option)>> memberFuncMap_;
18132a6e48fSopenharmony_ci
18232a6e48fSopenharmony_ci    class ProducerSurfaceDeathRecipient : public IRemoteObject::DeathRecipient {
18332a6e48fSopenharmony_ci    public:
18432a6e48fSopenharmony_ci        explicit ProducerSurfaceDeathRecipient(wptr<BufferQueueProducer> producer);
18532a6e48fSopenharmony_ci        virtual ~ProducerSurfaceDeathRecipient() = default;
18632a6e48fSopenharmony_ci
18732a6e48fSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject>& remoteObject) override;
18832a6e48fSopenharmony_ci    private:
18932a6e48fSopenharmony_ci        wptr<BufferQueueProducer> producer_;
19032a6e48fSopenharmony_ci        std::string name_ = "DeathRecipient";
19132a6e48fSopenharmony_ci    };
19232a6e48fSopenharmony_ci    sptr<ProducerSurfaceDeathRecipient> producerSurfaceDeathRecipient_ = nullptr;
19332a6e48fSopenharmony_ci    sptr<IRemoteObject> token_ = nullptr;
19432a6e48fSopenharmony_ci
19532a6e48fSopenharmony_ci    int32_t connectedPid_ = 0;
19632a6e48fSopenharmony_ci    sptr<BufferQueue> bufferQueue_ = nullptr;
19732a6e48fSopenharmony_ci    std::string name_ = "not init";
19832a6e48fSopenharmony_ci    std::mutex mutex_;
19932a6e48fSopenharmony_ci    uint64_t uniqueId_ = 0;
20032a6e48fSopenharmony_ci};
20132a6e48fSopenharmony_ci}; // namespace OHOS
20232a6e48fSopenharmony_ci
20332a6e48fSopenharmony_ci#endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_PRODUCER_H
204