blob: f72862be07c509e8644921e90fee5f381f9e9f8b [file] [log] [blame]
Chia-I Wuaaff73f2017-02-13 12:28:24 -08001/*
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 Pique76ed7032018-12-04 17:24:28 -080017#include <compositionengine/impl/HwcBufferCache.h>
Chia-I Wuaaff73f2017-02-13 12:28:24 -080018#include <gui/BufferQueue.h>
Lloyd Pique76ed7032018-12-04 17:24:28 -080019#include <ui/GraphicBuffer.h>
Chia-I Wuaaff73f2017-02-13 12:28:24 -080020
Lloyd Pique76ed7032018-12-04 17:24:28 -080021namespace android::compositionengine::impl {
Chia-I Wuaaff73f2017-02-13 12:28:24 -080022
Lloyd Pique76ed7032018-12-04 17:24:28 -080023HwcBufferCache::HwcBufferCache() {
Marissa Wall947d34e2019-03-29 14:03:53 -070024 std::fill(std::begin(mBuffers), std::end(mBuffers), wp<GraphicBuffer>(nullptr));
Valerie Hau6f89c372019-03-02 00:13:33 +000025}
26
Valerie Hau13f0d1a2019-03-22 10:35:42 -070027void HwcBufferCache::getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, uint32_t* outSlot,
Wale Ogunwale5723fbd2019-02-28 15:53:59 +000028 sp<GraphicBuffer>* outBuffer) {
Marissa Wall947d34e2019-03-29 14:03:53 -070029 // default is 0
30 if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0 ||
31 slot >= BufferQueue::NUM_BUFFER_SLOTS) {
Valerie Hau13f0d1a2019-03-22 10:35:42 -070032 *outSlot = 0;
33 } else {
34 *outSlot = slot;
35 }
Valerie Haub28f0072019-02-20 10:36:29 -080036
Marissa Wall947d34e2019-03-29 14:03:53 -070037 auto& currentBuffer = mBuffers[*outSlot];
Valerie Hau13f0d1a2019-03-22 10:35:42 -070038 wp<GraphicBuffer> weakCopy(buffer);
39 if (currentBuffer == weakCopy) {
Chia-I Wuaaff73f2017-02-13 12:28:24 -080040 // already cached in HWC, skip sending the buffer
41 *outBuffer = nullptr;
42 } else {
43 *outBuffer = buffer;
44
45 // update cache
Valerie Hau6f89c372019-03-02 00:13:33 +000046 currentBuffer = buffer;
Chia-I Wuaaff73f2017-02-13 12:28:24 -080047 }
Chia-I Wuaaff73f2017-02-13 12:28:24 -080048}
49
Lloyd Pique76ed7032018-12-04 17:24:28 -080050} // namespace android::compositionengine::impl