1/*
2 * Copyright (c) 2024 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#include <message_option.h>
16#include <message_parcel.h>
17#include "producer_surface_delegator.h"
18#include "buffer_log.h"
19#include "sync_fence.h"
20
21namespace OHOS {
22ProducerSurfaceDelegator::~ProducerSurfaceDelegator()
23{
24    map_.clear();
25}
26GSError ProducerSurfaceDelegator::DequeueBuffer(int32_t slot, sptr<SurfaceBuffer> buffer)
27{
28    return GSERROR_OK;
29}
30
31GSError ProducerSurfaceDelegator::QueueBuffer(int32_t slot, int32_t acquireFence)
32{
33    return GSERROR_OK;
34}
35
36GSError ProducerSurfaceDelegator::ReleaseBuffer(const sptr<SurfaceBuffer> &buffer, const sptr<SyncFence> &fence)
37{
38    return GSERROR_OK;
39}
40
41GSError ProducerSurfaceDelegator::ClearBufferSlot(int32_t slot)
42{
43    (void)slot;
44    return GSERROR_OK;
45}
46
47GSError ProducerSurfaceDelegator::ClearAllBuffers()
48{
49    return GSERROR_OK;
50}
51
52void ProducerSurfaceDelegator::AddBufferLocked(const sptr<SurfaceBuffer>& buffer, int32_t slot)
53{
54    (void)buffer;
55    (void)slot;
56}
57
58sptr<SurfaceBuffer> ProducerSurfaceDelegator::GetBufferLocked(int32_t slot)
59{
60    (void)slot;
61    return nullptr;
62}
63
64int32_t ProducerSurfaceDelegator::GetSlotLocked(const sptr<SurfaceBuffer>& buffer)
65{
66    (void)buffer;
67    return 0;
68}
69
70GSError ProducerSurfaceDelegator::CancelBuffer(int32_t slot, int32_t fenceFd)
71{
72    return GSERROR_OK;
73}
74
75GSError ProducerSurfaceDelegator::DetachBuffer(int32_t slot)
76{
77    return GSERROR_OK;
78}
79
80int ProducerSurfaceDelegator::OnSetBufferQueueSize(MessageParcel &data, MessageParcel &reply)
81{
82    return ERR_NONE;
83}
84
85int ProducerSurfaceDelegator::OnDequeueBuffer(MessageParcel &data, MessageParcel &reply)
86{
87    return ERR_NONE;
88}
89
90int ProducerSurfaceDelegator::OnSetDataspace(MessageParcel& data, MessageParcel& reply)
91{
92    mAncoDataspace = 0;
93    return ERR_NONE;
94}
95
96int ProducerSurfaceDelegator::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
97    MessageOption &option)
98{
99    return ERR_NONE;
100}
101
102GSError ProducerSurfaceDelegator::RetryFlushBuffer(sptr<SurfaceBuffer>& buffer, int32_t fence,
103                                                   BufferFlushConfig& config)
104{
105    return GSERROR_OK;
106}
107
108bool ProducerSurfaceDelegator::HasSlotInSet(int32_t slot)
109{
110    std::lock_guard<std::mutex> setLock(dequeueFailedSetMutex_);
111    return dequeueFailedSet_.find(slot) != dequeueFailedSet_.end();
112}
113
114void ProducerSurfaceDelegator::InsertSlotIntoSet(int32_t slot)
115{
116    std::lock_guard<std::mutex> setLock(dequeueFailedSetMutex_);
117    dequeueFailedSet_.insert(slot);
118}
119
120void ProducerSurfaceDelegator::EraseSlotFromSet(int32_t slot)
121{
122    std::lock_guard<std::mutex> setLock(dequeueFailedSetMutex_);
123    dequeueFailedSet_.erase(slot);
124}
125
126} // namespace OHOS
127