Home | History | Annotate | Download | only in impl
      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 #include <gui/BufferQueue.h>
     23 #include <utils/StrongPointer.h>
     24 
     25 namespace android {
     26 
     27 class GraphicBuffer;
     28 
     29 namespace compositionengine::impl {
     30 
     31 // With HIDLized hwcomposer HAL, the HAL can maintain a buffer cache for each
     32 // HWC display and layer.  When updating a display target or a layer buffer,
     33 // we have the option to send the buffer handle over or to request the HAL to
     34 // retrieve it from its cache.  The latter is cheaper since it eliminates the
     35 // overhead to transfer the handle over the trasport layer, and the overhead
     36 // for the HAL to clone and retain the handle.
     37 //
     38 // To be able to find out whether a buffer is already in the HAL's cache, we
     39 // use HWComposerBufferCache to mirror the cache in SF.
     40 class HwcBufferCache {
     41 public:
     42     HwcBufferCache();
     43     // Given a buffer, return the HWC cache slot and
     44     // buffer to be sent to HWC.
     45     //
     46     // outBuffer is set to buffer when buffer is not in the HWC cache;
     47     // otherwise, outBuffer is set to nullptr.
     48     void getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, uint32_t* outSlot,
     49                       sp<GraphicBuffer>* outBuffer);
     50 
     51 private:
     52     // an array where the index corresponds to a slot and the value corresponds to a (counter,
     53     // buffer) pair. "counter" is a unique value that indicates the last time this slot was updated
     54     // or used and allows us to keep track of the least-recently used buffer.
     55     wp<GraphicBuffer> mBuffers[BufferQueue::NUM_BUFFER_SLOTS];
     56 };
     57 
     58 } // namespace compositionengine::impl
     59 } // namespace android
     60