blob: 80b1f321b879b7384b3918ac8faa53ba2f06a2ae [file] [log] [blame]
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -07001/*
2 * Copyright (C) 2012 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//#define LOG_NDEBUG 0
18#define LOG_TAG "BufferItemConsumer"
19#define ATRACE_TAG ATRACE_TAG_GRAPHICS
20#include <utils/Log.h>
21
22#include <gui/BufferItemConsumer.h>
23
Dan Albert8b491252014-09-08 18:53:39 -070024#define BI_LOGV(x, ...) ALOGV("[%s] " x, mName.string(), ##__VA_ARGS__)
25#define BI_LOGD(x, ...) ALOGD("[%s] " x, mName.string(), ##__VA_ARGS__)
26#define BI_LOGI(x, ...) ALOGI("[%s] " x, mName.string(), ##__VA_ARGS__)
27#define BI_LOGW(x, ...) ALOGW("[%s] " x, mName.string(), ##__VA_ARGS__)
28#define BI_LOGE(x, ...) ALOGE("[%s] " x, mName.string(), ##__VA_ARGS__)
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070029
30namespace android {
31
Mathias Agopian8f938a52013-07-12 22:06:26 -070032BufferItemConsumer::BufferItemConsumer(const sp<BufferQueue>& bq,
Mathias Agopian595264f2013-07-16 22:56:09 -070033 uint32_t consumerUsage, int bufferCount, bool controlledByApp) :
34 ConsumerBase(bq, controlledByApp)
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070035{
Mathias Agopiandb89edc2013-08-02 01:40:18 -070036 mConsumer->setConsumerUsageBits(consumerUsage);
37 mConsumer->setMaxAcquiredBufferCount(bufferCount);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070038}
39
40BufferItemConsumer::~BufferItemConsumer() {
41}
42
43void BufferItemConsumer::setName(const String8& name) {
44 Mutex::Autolock _l(mMutex);
45 mName = name;
Mathias Agopiandb89edc2013-08-02 01:40:18 -070046 mConsumer->setConsumerName(name);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070047}
48
Andy McFadden1585c4d2013-06-28 13:52:40 -070049status_t BufferItemConsumer::acquireBuffer(BufferItem *item,
50 nsecs_t presentWhen, bool waitForFence) {
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070051 status_t err;
52
53 if (!item) return BAD_VALUE;
54
55 Mutex::Autolock _l(mMutex);
56
Andy McFadden1585c4d2013-06-28 13:52:40 -070057 err = acquireBufferLocked(item, presentWhen);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070058 if (err != OK) {
59 if (err != NO_BUFFER_AVAILABLE) {
60 BI_LOGE("Error acquiring buffer: %s (%d)", strerror(err), err);
61 }
62 return err;
63 }
64
Jamie Gennis1df8c342012-12-20 14:05:45 -080065 if (waitForFence) {
Mathias Agopianea74d3b2013-05-16 18:03:22 -070066 err = item->mFence->waitForever("BufferItemConsumer::acquireBuffer");
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070067 if (err != OK) {
68 BI_LOGE("Failed to wait for fence of acquired buffer: %s (%d)",
69 strerror(-err), err);
70 return err;
71 }
72 }
73
74 item->mGraphicBuffer = mSlots[item->mBuf].mGraphicBuffer;
75
76 return OK;
77}
78
79status_t BufferItemConsumer::releaseBuffer(const BufferItem &item,
80 const sp<Fence>& releaseFence) {
81 status_t err;
82
83 Mutex::Autolock _l(mMutex);
84
Lajos Molnarc5d7b7d2013-05-03 14:50:50 -070085 err = addReleaseFenceLocked(item.mBuf, item.mGraphicBuffer, releaseFence);
Jamie Gennisb2725412012-09-05 20:09:05 -070086
Lajos Molnarc5d7b7d2013-05-03 14:50:50 -070087 err = releaseBufferLocked(item.mBuf, item.mGraphicBuffer, EGL_NO_DISPLAY,
Jamie Gennisb2725412012-09-05 20:09:05 -070088 EGL_NO_SYNC_KHR);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070089 if (err != OK) {
90 BI_LOGE("Failed to release buffer: %s (%d)",
91 strerror(-err), err);
92 }
93 return err;
94}
95
Igor Murashkin87d1e342013-04-16 11:24:40 -070096status_t BufferItemConsumer::setDefaultBufferSize(uint32_t w, uint32_t h) {
97 Mutex::Autolock _l(mMutex);
Mathias Agopiandb89edc2013-08-02 01:40:18 -070098 return mConsumer->setDefaultBufferSize(w, h);
Igor Murashkin87d1e342013-04-16 11:24:40 -070099}
100
101status_t BufferItemConsumer::setDefaultBufferFormat(uint32_t defaultFormat) {
102 Mutex::Autolock _l(mMutex);
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700103 return mConsumer->setDefaultBufferFormat(defaultFormat);
Igor Murashkin87d1e342013-04-16 11:24:40 -0700104}
105
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -0700106} // namespace android