1c5e268c6Sopenharmony_ci/* 2c5e268c6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3c5e268c6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c5e268c6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c5e268c6Sopenharmony_ci * You may obtain a copy of the License at 6c5e268c6Sopenharmony_ci * 7c5e268c6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c5e268c6Sopenharmony_ci * 9c5e268c6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c5e268c6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c5e268c6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c5e268c6Sopenharmony_ci * See the License for the specific language governing permissions and 13c5e268c6Sopenharmony_ci * limitations under the License. 14c5e268c6Sopenharmony_ci */ 15c5e268c6Sopenharmony_ci 16c5e268c6Sopenharmony_ci#ifndef OHOS_HDI_DISPLAY_V1_0_LAYER_CACHE_H 17c5e268c6Sopenharmony_ci#define OHOS_HDI_DISPLAY_V1_0_LAYER_CACHE_H 18c5e268c6Sopenharmony_ci 19c5e268c6Sopenharmony_ci#include <functional> 20c5e268c6Sopenharmony_ci#include <memory> 21c5e268c6Sopenharmony_ci#include <unordered_map> 22c5e268c6Sopenharmony_ci#include "base/native_buffer.h" 23c5e268c6Sopenharmony_ci#include "cache_manager.h" 24c5e268c6Sopenharmony_ci#include "nocopyable.h" 25c5e268c6Sopenharmony_ci#include "v1_2/mapper_stub.h" 26c5e268c6Sopenharmony_ci#include "v1_1/imetadata.h" 27c5e268c6Sopenharmony_ci 28c5e268c6Sopenharmony_cinamespace OHOS { 29c5e268c6Sopenharmony_cinamespace HDI { 30c5e268c6Sopenharmony_cinamespace Display { 31c5e268c6Sopenharmony_cinamespace Composer { 32c5e268c6Sopenharmony_ciusing namespace OHOS::HDI::Base; 33c5e268c6Sopenharmony_ciclass LayerCache : public NoCopyable { 34c5e268c6Sopenharmony_cipublic: 35c5e268c6Sopenharmony_ci ~LayerCache(); 36c5e268c6Sopenharmony_ci static LayerCache* Create(uint32_t id); 37c5e268c6Sopenharmony_ci int32_t SetLayerBuffer(BufferHandle*& buffer, uint32_t seqNo, bool &needFreeBuffer, 38c5e268c6Sopenharmony_ci const std::vector<uint32_t>& deletingList, std::function<int32_t (const BufferHandle&)> realFunc); 39c5e268c6Sopenharmony_ci int32_t SetBufferCacheMaxCount(uint32_t cacheCount); 40c5e268c6Sopenharmony_ci int32_t ResetLayerBuffer(); 41c5e268c6Sopenharmony_ci void Dump() const; 42c5e268c6Sopenharmony_ci static void NativeBufferInit(sptr<NativeBuffer>& buffer); 43c5e268c6Sopenharmony_ci static void NativeBufferCleanUp(sptr<NativeBuffer>& buffer); 44c5e268c6Sopenharmony_ciprivate: 45c5e268c6Sopenharmony_ci explicit LayerCache(uint32_t id); 46c5e268c6Sopenharmony_ci int32_t Init(); 47c5e268c6Sopenharmony_ci static sptr<Buffer::V1_2::IMapper> GetMapperService(); 48c5e268c6Sopenharmony_ci static sptr<Buffer::V1_1::IMetadata> GetMetaService(); 49c5e268c6Sopenharmony_ci static int32_t Mmap(sptr<NativeBuffer>& buffer); 50c5e268c6Sopenharmony_ci static int32_t Unmap(sptr<NativeBuffer>& buffer); 51c5e268c6Sopenharmony_ci static int32_t FreeMem(sptr<NativeBuffer>& buffer); 52c5e268c6Sopenharmony_ci static int32_t RegisterBuffer(sptr<NativeBuffer>& buffer); 53c5e268c6Sopenharmony_ci uint32_t layerId_; 54c5e268c6Sopenharmony_ci std::shared_ptr<CacheManager<uint32_t, NativeBuffer>> bufferCaches_; 55c5e268c6Sopenharmony_ci}; 56c5e268c6Sopenharmony_ci} // namespace Composer 57c5e268c6Sopenharmony_ci} // namespace Display 58c5e268c6Sopenharmony_ci} // namespace HDI 59c5e268c6Sopenharmony_ci} // namespace OHOS 60c5e268c6Sopenharmony_ci#endif // OHOS_HDI_DISPLAY_V1_0_LAYER_CACHE_H 61