Home | History | Annotate | Download | only in DisplayHardware
      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 #ifndef ANDROID_SF_HWCOMPOSERBUFFERCACHE_H
     18 #define ANDROID_SF_HWCOMPOSERBUFFERCACHE_H
     19 
     20 #include <stdint.h>
     21 
     22 #include <utils/StrongPointer.h>
     23 
     24 #include <vector>
     25 
     26 namespace android {
     27 // ---------------------------------------------------------------------------
     28 
     29 class GraphicBuffer;
     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 HWComposerBufferCache {
     41 public:
     42     HWComposerBufferCache();
     43 
     44     // Given a buffer queue slot and buffer, return the HWC cache slot and
     45     // buffer to be sent to HWC.
     46     //
     47     // outBuffer is set to buffer when buffer is not in the HWC cache;
     48     // otherwise, outBuffer is set to nullptr.
     49     void getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer,
     50             uint32_t* outSlot, sp<GraphicBuffer>* outBuffer);
     51 
     52 private:
     53     // a vector as we expect "slot" to be in the range of [0, 63] (that is,
     54     // less than BufferQueue::NUM_BUFFER_SLOTS).
     55     std::vector<sp<GraphicBuffer>> mBuffers;
     56 };
     57 
     58 // ---------------------------------------------------------------------------
     59 }; // namespace android
     60 
     61 #endif // ANDROID_SF_HWCOMPOSERBUFFERCACHE_H
     62