Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 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 | |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 17 | #include <compositionengine/impl/HwcBufferCache.h> |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 18 | #include <gui/BufferQueue.h> |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 19 | #include <ui/GraphicBuffer.h> |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 20 | |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 21 | namespace android::compositionengine::impl { |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 22 | |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 23 | HwcBufferCache::HwcBufferCache() { |
Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame^] | 24 | mBuffers.reserve(BufferQueue::NUM_BUFFER_SLOTS); |
Valerie Hau | b28f007 | 2019-02-20 10:36:29 -0800 | [diff] [blame] | 25 | } |
Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame^] | 26 | |
| 27 | void HwcBufferCache::getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, uint32_t* outSlot, |
| 28 | sp<GraphicBuffer>* outBuffer) { |
| 29 | if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0) { |
| 30 | // default to slot 0 |
| 31 | slot = 0; |
Valerie Hau | b28f007 | 2019-02-20 10:36:29 -0800 | [diff] [blame] | 32 | } |
| 33 | |
Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame^] | 34 | if (static_cast<size_t>(slot) >= mBuffers.size()) { |
| 35 | mBuffers.resize(slot + 1); |
| 36 | } |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 37 | |
Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame^] | 38 | *outSlot = slot; |
Valerie Hau | b28f007 | 2019-02-20 10:36:29 -0800 | [diff] [blame] | 39 | |
Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame^] | 40 | if (mBuffers[slot] == buffer) { |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 41 | // already cached in HWC, skip sending the buffer |
| 42 | *outBuffer = nullptr; |
| 43 | } else { |
| 44 | *outBuffer = buffer; |
| 45 | |
| 46 | // update cache |
Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame^] | 47 | mBuffers[slot] = buffer; |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 48 | } |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 51 | } // namespace android::compositionengine::impl |