| 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 | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 17 | #include <compositionengine/impl/HwcBufferCache.h> | 
|  | 18 |  | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 19 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 20 | #pragma clang diagnostic push | 
|  | 21 | #pragma clang diagnostic ignored "-Wconversion" | 
|  | 22 |  | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 23 | #include <gui/BufferQueue.h> | 
| Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 24 | #include <ui/GraphicBuffer.h> | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 25 |  | 
| Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 26 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 27 | #pragma clang diagnostic pop // ignored "-Wconversion" | 
|  | 28 |  | 
| Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 29 | namespace android::compositionengine::impl { | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 30 |  | 
| Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 31 | HwcBufferCache::HwcBufferCache() { | 
| Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 32 | std::fill(std::begin(mBuffers), std::end(mBuffers), wp<GraphicBuffer>(nullptr)); | 
| Valerie Hau | 6f89c37 | 2019-03-02 00:13:33 +0000 | [diff] [blame] | 33 | } | 
|  | 34 |  | 
| Valerie Hau | 13f0d1a | 2019-03-22 10:35:42 -0700 | [diff] [blame] | 35 | void HwcBufferCache::getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, uint32_t* outSlot, | 
| Wale Ogunwale | 5723fbd | 2019-02-28 15:53:59 +0000 | [diff] [blame] | 36 | sp<GraphicBuffer>* outBuffer) { | 
| Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 37 | // default is 0 | 
|  | 38 | if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0 || | 
| Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 39 | slot >= static_cast<int32_t>(kMaxLayerBufferCount)) { | 
| Valerie Hau | 13f0d1a | 2019-03-22 10:35:42 -0700 | [diff] [blame] | 40 | *outSlot = 0; | 
|  | 41 | } else { | 
| Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 42 | *outSlot = static_cast<uint32_t>(slot); | 
| Valerie Hau | 13f0d1a | 2019-03-22 10:35:42 -0700 | [diff] [blame] | 43 | } | 
| Valerie Hau | b28f007 | 2019-02-20 10:36:29 -0800 | [diff] [blame] | 44 |  | 
| Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 45 | auto& currentBuffer = mBuffers[*outSlot]; | 
| Valerie Hau | 13f0d1a | 2019-03-22 10:35:42 -0700 | [diff] [blame] | 46 | wp<GraphicBuffer> weakCopy(buffer); | 
|  | 47 | if (currentBuffer == weakCopy) { | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 48 | // already cached in HWC, skip sending the buffer | 
|  | 49 | *outBuffer = nullptr; | 
|  | 50 | } else { | 
|  | 51 | *outBuffer = buffer; | 
|  | 52 |  | 
|  | 53 | // update cache | 
| Valerie Hau | 6f89c37 | 2019-03-02 00:13:33 +0000 | [diff] [blame] | 54 | currentBuffer = buffer; | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 55 | } | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
| Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 58 | } // namespace android::compositionengine::impl |