blob: 1e7c97cc350c600349594643e9f5124f7ce5840d [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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Pique76ed7032018-12-04 17:24:28 -080021#include <compositionengine/impl/HwcBufferCache.h>
Chia-I Wuaaff73f2017-02-13 12:28:24 -080022#include <gui/BufferQueue.h>
Lloyd Pique76ed7032018-12-04 17:24:28 -080023#include <ui/GraphicBuffer.h>
Chia-I Wuaaff73f2017-02-13 12:28:24 -080024
Lloyd Pique76ed7032018-12-04 17:24:28 -080025namespace android::compositionengine::impl {
Chia-I Wuaaff73f2017-02-13 12:28:24 -080026
Lloyd Pique76ed7032018-12-04 17:24:28 -080027HwcBufferCache::HwcBufferCache() {
Marissa Wall947d34e2019-03-29 14:03:53 -070028 std::fill(std::begin(mBuffers), std::end(mBuffers), wp<GraphicBuffer>(nullptr));
Valerie Hau6f89c372019-03-02 00:13:33 +000029}
30
Valerie Hau13f0d1a2019-03-22 10:35:42 -070031void HwcBufferCache::getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer, uint32_t* outSlot,
Wale Ogunwale5723fbd2019-02-28 15:53:59 +000032 sp<GraphicBuffer>* outBuffer) {
Marissa Wall947d34e2019-03-29 14:03:53 -070033 // default is 0
34 if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0 ||
35 slot >= BufferQueue::NUM_BUFFER_SLOTS) {
Valerie Hau13f0d1a2019-03-22 10:35:42 -070036 *outSlot = 0;
37 } else {
Lloyd Pique0a456232020-01-16 17:51:13 -080038 *outSlot = static_cast<uint32_t>(slot);
Valerie Hau13f0d1a2019-03-22 10:35:42 -070039 }
Valerie Haub28f0072019-02-20 10:36:29 -080040
Marissa Wall947d34e2019-03-29 14:03:53 -070041 auto& currentBuffer = mBuffers[*outSlot];
Valerie Hau13f0d1a2019-03-22 10:35:42 -070042 wp<GraphicBuffer> weakCopy(buffer);
43 if (currentBuffer == weakCopy) {
Chia-I Wuaaff73f2017-02-13 12:28:24 -080044 // already cached in HWC, skip sending the buffer
45 *outBuffer = nullptr;
46 } else {
47 *outBuffer = buffer;
48
49 // update cache
Valerie Hau6f89c372019-03-02 00:13:33 +000050 currentBuffer = buffer;
Chia-I Wuaaff73f2017-02-13 12:28:24 -080051 }
Chia-I Wuaaff73f2017-02-13 12:28:24 -080052}
53
Lloyd Pique76ed7032018-12-04 17:24:28 -080054} // namespace android::compositionengine::impl
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080055
56// TODO(b/129481165): remove the #pragma below and fix conversion issues
57#pragma clang diagnostic pop // ignored "-Wconversion"