1/* 2 * Copyright (c) 2023 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 16#ifndef OHOS_HDI_DISPLAY_V1_0_DEVICE_CACHE_H 17#define OHOS_HDI_DISPLAY_V1_0_DEVICE_CACHE_H 18 19#include <functional> 20#include <memory> 21#include <unordered_map> 22#include "base/native_buffer.h" 23#include "cache_manager.h" 24#include "layer_cache.h" 25#include "nocopyable.h" 26 27namespace OHOS { 28namespace HDI { 29namespace Display { 30namespace Composer { 31using namespace OHOS::HDI::Base; 32class DeviceCache : public NoCopyable { 33public: 34 enum DeviceType { 35 DEVICE_TYPE_DEVICE = 0, 36 DEVICE_TYPE_VIRTUAL, 37 DEVICE_TYPE_BUTT 38 }; 39 40 ~DeviceCache(); 41 static DeviceCache* Create(uint32_t id, DeviceType type); 42 int32_t SetClientBufferCacheCount(uint32_t bufferCacheCount); 43 LayerCache* LayerCacheInstance(uint32_t layerId) const; 44 int32_t AddLayerCache(uint32_t id, uint32_t bufferCacheCount); 45 int32_t RemoveLayerCache(uint32_t id); 46 int32_t ClearClientCache(); 47 int32_t ClearLayerBuffer(uint32_t layerId); 48 int32_t SetDisplayClientBuffer(BufferHandle*& buffer, uint32_t seqNo, bool &needFreeBuffer, 49 std::function<int32_t (const BufferHandle&)> realFunc); 50 int32_t SetVirtualDisplayBuffer(BufferHandle*& buffer, uint32_t seqNo, bool &needFreeBuffer, 51 std::function<int32_t (const BufferHandle&)> realFunc); 52 DeviceType CacheType() const; 53 void Dump() const; 54private: 55 DeviceCache(uint32_t id, DeviceType type); 56 int32_t Init(); 57 uint32_t deviceId_; 58 DeviceType cacheType_; 59 std::shared_ptr<CacheManager<uint32_t, NativeBuffer>> clientBufferCaches_; 60 std::shared_ptr<CacheManager<uint32_t, NativeBuffer>> outputBufferCaches_; 61 std::shared_ptr<CacheManager<uint32_t, LayerCache>> layerCaches_; 62}; 63} // namespace Composer 64} // namespace Display 65} // namespace HDI 66} // namespace OHOS 67#endif // OHOS_HDI_DISPLAY_V1_0_DEVICE_CACHE_H 68