blob: 6b9122473f08233b3ad798f745ccc3d21fb727d3 [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
17#include "HWComposerBufferCache.h"
18
19#include <gui/BufferQueue.h>
20
21namespace android {
22
23HWComposerBufferCache::HWComposerBufferCache()
24{
25 mBuffers.reserve(BufferQueue::NUM_BUFFER_SLOTS);
26}
27
28void HWComposerBufferCache::getHwcBuffer(int slot,
29 const sp<GraphicBuffer>& buffer,
30 uint32_t* outSlot, sp<GraphicBuffer>* outBuffer)
31{
32#ifdef BYPASS_IHWC
33 *outSlot = slot;
34 *outBuffer = buffer;
35#else
36 if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0) {
37 // default to slot 0
38 slot = 0;
39 }
40
41 if (static_cast<size_t>(slot) >= mBuffers.size()) {
42 mBuffers.resize(slot + 1);
43 }
44
45 *outSlot = slot;
46
47 if (mBuffers[slot] == buffer) {
48 // already cached in HWC, skip sending the buffer
49 *outBuffer = nullptr;
50 } else {
51 *outBuffer = buffer;
52
53 // update cache
54 mBuffers[slot] = buffer;
55 }
56#endif
57}
58
59} // namespace android