Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | #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__) |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | BufferItemConsumer::BufferItemConsumer(uint32_t consumerUsage, |
| 33 | int bufferCount, bool synchronousMode) : |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 34 | ConsumerBase(new BufferQueue(true) ) |
Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 35 | { |
| 36 | mBufferQueue->setConsumerUsageBits(consumerUsage); |
| 37 | mBufferQueue->setSynchronousMode(synchronousMode); |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 38 | mBufferQueue->setMaxAcquiredBufferCount(bufferCount); |
Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | BufferItemConsumer::~BufferItemConsumer() { |
| 42 | } |
| 43 | |
| 44 | void BufferItemConsumer::setName(const String8& name) { |
| 45 | Mutex::Autolock _l(mMutex); |
| 46 | mName = name; |
| 47 | mBufferQueue->setConsumerName(name); |
| 48 | } |
| 49 | |
| 50 | status_t BufferItemConsumer::acquireBuffer(BufferItem *item, bool waitForFence) { |
| 51 | status_t err; |
| 52 | |
| 53 | if (!item) return BAD_VALUE; |
| 54 | |
| 55 | Mutex::Autolock _l(mMutex); |
| 56 | |
| 57 | err = acquireBufferLocked(item); |
| 58 | 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 Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 65 | if (waitForFence) { |
Jesse Hall | ba607d5 | 2012-10-01 14:05:20 -0700 | [diff] [blame] | 66 | err = item->mFence->waitForever(1000, "BufferItemConsumer::acquireBuffer"); |
Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 67 | 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 | |
| 79 | status_t BufferItemConsumer::releaseBuffer(const BufferItem &item, |
| 80 | const sp<Fence>& releaseFence) { |
| 81 | status_t err; |
| 82 | |
| 83 | Mutex::Autolock _l(mMutex); |
| 84 | |
Jesse Hall | 9504eb9 | 2012-10-05 14:34:21 -0700 | [diff] [blame] | 85 | err = addReleaseFenceLocked(item.mBuf, releaseFence); |
Jamie Gennis | b272541 | 2012-09-05 20:09:05 -0700 | [diff] [blame] | 86 | |
Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 87 | err = releaseBufferLocked(item.mBuf, EGL_NO_DISPLAY, |
Jamie Gennis | b272541 | 2012-09-05 20:09:05 -0700 | [diff] [blame] | 88 | EGL_NO_SYNC_KHR); |
Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 89 | if (err != OK) { |
| 90 | BI_LOGE("Failed to release buffer: %s (%d)", |
| 91 | strerror(-err), err); |
| 92 | } |
| 93 | return err; |
| 94 | } |
| 95 | |
Igor Murashkin | 87d1e34 | 2013-04-16 11:24:40 -0700 | [diff] [blame^] | 96 | status_t BufferItemConsumer::setDefaultBufferSize(uint32_t w, uint32_t h) { |
| 97 | Mutex::Autolock _l(mMutex); |
| 98 | return mBufferQueue->setDefaultBufferSize(w, h); |
| 99 | } |
| 100 | |
| 101 | status_t BufferItemConsumer::setDefaultBufferFormat(uint32_t defaultFormat) { |
| 102 | Mutex::Autolock _l(mMutex); |
| 103 | return mBufferQueue->setDefaultBufferFormat(defaultFormat); |
| 104 | } |
| 105 | |
Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 106 | } // namespace android |