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 #ifndef PRODUCER_SURFACE_DELEGATOR_H 16 #define PRODUCER_SURFACE_DELEGATOR_H 17 18 #include <map> 19 #include <vector> 20 #include <mutex> 21 #include <unordered_set> 22 23 #include "transact_surface_delegator_stub.h" 24 25 namespace OHOS { 26 class ProducerSurfaceDelegator : public TransactSurfaceDelegatorStub { 27 public: 28 ~ProducerSurfaceDelegator(); Create()29 static sptr<ProducerSurfaceDelegator> Create() 30 { 31 return sptr<ProducerSurfaceDelegator>(new ProducerSurfaceDelegator()); 32 } 33 GSError DequeueBuffer(int32_t slot, sptr<SurfaceBuffer> buffer); 34 GSError QueueBuffer(int32_t slot, int32_t acquireFence); 35 GSError ReleaseBuffer(const sptr<SurfaceBuffer> &buffer, const sptr<SyncFence> &fence); 36 GSError ClearBufferSlot(int32_t slot); 37 GSError ClearAllBuffers(); 38 GSError CancelBuffer(int32_t slot, int32_t fenceFd); 39 GSError DetachBuffer(int32_t slot); 40 int OnSetBufferQueueSize(MessageParcel& data, MessageParcel& reply); 41 int OnSetDataspace(MessageParcel& data, MessageParcel& reply); 42 int OnDequeueBuffer(MessageParcel &data, MessageParcel &reply); 43 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 44 45 private: 46 std::map<int32_t, std::vector<sptr<SurfaceBuffer>>> map_; 47 std::vector<sptr<SurfaceBuffer>> pendingReleaseBuffer_; 48 std::unordered_set<int> dequeueFailedSet_; 49 std::mutex dequeueFailedSetMutex_; 50 std::mutex mapMutex_; 51 std::mutex mstate_; 52 uint32_t mAncoDataspace = 0; 53 54 void AddBufferLocked(const sptr<SurfaceBuffer>& buffer, int32_t slot); 55 sptr<SurfaceBuffer> GetBufferLocked(int32_t slot); 56 int32_t GetSlotLocked(const sptr<SurfaceBuffer>& buffer); 57 GSError RetryFlushBuffer(sptr<SurfaceBuffer>& buffer, int32_t fence, BufferFlushConfig& config); 58 bool HasSlotInSet(int32_t slot); 59 void InsertSlotIntoSet(int32_t slot); 60 void EraseSlotFromSet(int32_t slot); 61 }; 62 } // namespace OHOS 63 #endif // PRODUCER_SURFACE_DELEGATOR_H 64