1aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu/* 2aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * Copyright (C) 2017 The Android Open Source Project 3aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * 4aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * Licensed under the Apache License, Version 2.0 (the "License"); 5aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * you may not use this file except in compliance with the License. 6aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * You may obtain a copy of the License at 7aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * 8aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * http://www.apache.org/licenses/LICENSE-2.0 9aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * 10aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * Unless required by applicable law or agreed to in writing, software 11aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * distributed under the License is distributed on an "AS IS" BASIS, 12aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * See the License for the specific language governing permissions and 14aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu * limitations under the License. 15aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu */ 16aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 17aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu#ifndef ANDROID_SF_HWCOMPOSERBUFFERCACHE_H 18aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu#define ANDROID_SF_HWCOMPOSERBUFFERCACHE_H 19aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 20aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu#include <stdint.h> 21aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 22aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu#include <utils/StrongPointer.h> 23aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 24aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu#include <vector> 25aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 26aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wunamespace android { 27aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// --------------------------------------------------------------------------- 28aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 29aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wuclass GraphicBuffer; 30aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 31aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// With HIDLized hwcomposer HAL, the HAL can maintain a buffer cache for each 32aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// HWC display and layer. When updating a display target or a layer buffer, 33aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// we have the option to send the buffer handle over or to request the HAL to 34aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// retrieve it from its cache. The latter is cheaper since it eliminates the 35aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// overhead to transfer the handle over the trasport layer, and the overhead 36aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// for the HAL to clone and retain the handle. 37aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// 38aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// To be able to find out whether a buffer is already in the HAL's cache, we 39aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// use HWComposerBufferCache to mirror the cache in SF. 40aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wuclass HWComposerBufferCache { 41aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wupublic: 42aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu HWComposerBufferCache(); 43aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 44aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // Given a buffer queue slot and buffer, return the HWC cache slot and 45aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // buffer to be sent to HWC. 46aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // 47aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // outBuffer is set to buffer when buffer is not in the HWC cache; 48aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // otherwise, outBuffer is set to nullptr. 49aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu void getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, 50aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu uint32_t* outSlot, sp<GraphicBuffer>* outBuffer); 51aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 52aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wuprivate: 53aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // a vector as we expect "slot" to be in the range of [0, 63] (that is, 54aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu // less than BufferQueue::NUM_BUFFER_SLOTS). 55aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu std::vector<sp<GraphicBuffer>> mBuffers; 56aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu}; 57aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 58aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu// --------------------------------------------------------------------------- 59aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu}; // namespace android 60aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu 61aaff73f92a2fcadda8c765eb9b02f2849418a873Chia-I Wu#endif // ANDROID_SF_HWCOMPOSERBUFFERCACHE_H 62