1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 #include <vector> 21 22 // TODO(b/129481165): remove the #pragma below and fix conversion issues 23 #pragma clang diagnostic push 24 #pragma clang diagnostic ignored "-Wconversion" 25 #pragma clang diagnostic ignored "-Wextra" 26 27 #include <gui/BufferQueue.h> 28 29 // TODO(b/129481165): remove the #pragma below and fix conversion issues 30 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" 31 32 #include <utils/StrongPointer.h> 33 34 namespace android { 35 36 class GraphicBuffer; 37 38 namespace compositionengine::impl { 39 40 // With HIDLized hwcomposer HAL, the HAL can maintain a buffer cache for each 41 // HWC display and layer. When updating a display target or a layer buffer, 42 // we have the option to send the buffer handle over or to request the HAL to 43 // retrieve it from its cache. The latter is cheaper since it eliminates the 44 // overhead to transfer the handle over the trasport layer, and the overhead 45 // for the HAL to clone and retain the handle. 46 // 47 // To be able to find out whether a buffer is already in the HAL's cache, we 48 // use HWComposerBufferCache to mirror the cache in SF. 49 class HwcBufferCache { 50 public: 51 HwcBufferCache(); 52 // Given a buffer, return the HWC cache slot and 53 // buffer to be sent to HWC. 54 // 55 // outBuffer is set to buffer when buffer is not in the HWC cache; 56 // otherwise, outBuffer is set to nullptr. 57 void getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, uint32_t* outSlot, 58 sp<GraphicBuffer>* outBuffer); 59 60 // Special caching slot for the layer caching feature. 61 static const constexpr size_t FLATTENER_CACHING_SLOT = BufferQueue::NUM_BUFFER_SLOTS; 62 63 private: 64 // an array where the index corresponds to a slot and the value corresponds to a (counter, 65 // buffer) pair. "counter" is a unique value that indicates the last time this slot was updated 66 // or used and allows us to keep track of the least-recently used buffer. 67 static const constexpr size_t kMaxLayerBufferCount = BufferQueue::NUM_BUFFER_SLOTS + 1; 68 wp<GraphicBuffer> mBuffers[kMaxLayerBufferCount]; 69 }; 70 71 } // namespace compositionengine::impl 72 } // namespace android 73