Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 1 | #if defined(__clang__) |
| 2 | #pragma clang diagnostic push |
| 3 | #pragma clang diagnostic ignored "-Weverything" |
| 4 | #endif |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 5 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 6 | // The following headers are included without checking every warning. |
| 7 | // TODO(b/72172820): Remove the workaround once we have enforced -Weverything |
| 8 | // in these headers and their dependencies. |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 9 | #include <dvr/dvr_api.h> |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 10 | #include <gui/BufferHubProducer.h> |
| 11 | |
| 12 | #if defined(__clang__) |
| 13 | #pragma clang diagnostic pop |
| 14 | #endif |
| 15 | |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 16 | #include <inttypes.h> |
| 17 | #include <log/log.h> |
Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 18 | #include <system/window.h> |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 19 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 20 | namespace android { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 21 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 22 | /* static */ |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 23 | sp<BufferHubProducer> BufferHubProducer::Create( |
| 24 | const std::shared_ptr<dvr::ProducerQueue>& queue) { |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 25 | if (queue->metadata_size() != sizeof(DvrNativeBufferMetadata)) { |
| 26 | ALOGE( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 27 | "BufferHubProducer::Create producer's metadata size is different " |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 28 | "than the size of DvrNativeBufferMetadata"); |
| 29 | return nullptr; |
| 30 | } |
| 31 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 32 | sp<BufferHubProducer> producer = new BufferHubProducer; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 33 | producer->queue_ = queue; |
| 34 | return producer; |
| 35 | } |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 36 | |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 37 | /* static */ |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 38 | sp<BufferHubProducer> BufferHubProducer::Create( |
| 39 | dvr::ProducerQueueParcelable parcelable) { |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 40 | if (!parcelable.IsValid()) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 41 | ALOGE("BufferHubProducer::Create: Invalid producer parcelable."); |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 42 | return nullptr; |
| 43 | } |
| 44 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 45 | sp<BufferHubProducer> producer = new BufferHubProducer; |
| 46 | producer->queue_ = dvr::ProducerQueue::Import(parcelable.TakeChannelHandle()); |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 47 | return producer; |
| 48 | } |
| 49 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 50 | status_t BufferHubProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) { |
| 51 | ALOGV("requestBuffer: slot=%d", slot); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 52 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 53 | std::unique_lock<std::mutex> lock(mutex_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 54 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 55 | if (connected_api_ == kNoConnectedApi) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 56 | ALOGE("requestBuffer: BufferHubProducer has no connected producer"); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 57 | return NO_INIT; |
| 58 | } |
| 59 | |
| 60 | if (slot < 0 || slot >= max_buffer_count_) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 61 | ALOGE("requestBuffer: slot index %d out of range [0, %d)", slot, |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 62 | max_buffer_count_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 63 | return BAD_VALUE; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 64 | } else if (!buffers_[slot].mBufferState.isDequeued()) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 65 | ALOGE("requestBuffer: slot %d is not owned by the producer (state = %s)", |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 66 | slot, buffers_[slot].mBufferState.string()); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 67 | return BAD_VALUE; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 68 | } else if (buffers_[slot].mGraphicBuffer != nullptr) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 69 | ALOGE("requestBuffer: slot %d is not empty.", slot); |
| 70 | return BAD_VALUE; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 71 | } else if (buffers_[slot].mBufferProducer == nullptr) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 72 | ALOGE("requestBuffer: slot %d is not dequeued.", slot); |
| 73 | return BAD_VALUE; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 76 | const auto& buffer_producer = buffers_[slot].mBufferProducer; |
Corey Tabaka | cd52dd9 | 2017-04-07 18:03:57 -0700 | [diff] [blame] | 77 | sp<GraphicBuffer> graphic_buffer = buffer_producer->buffer()->buffer(); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 78 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 79 | buffers_[slot].mGraphicBuffer = graphic_buffer; |
| 80 | buffers_[slot].mRequestBufferCalled = true; |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 81 | |
| 82 | *buf = graphic_buffer; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 83 | return NO_ERROR; |
| 84 | } |
| 85 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 86 | status_t BufferHubProducer::setMaxDequeuedBufferCount( |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 87 | int max_dequeued_buffers) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 88 | ALOGV("setMaxDequeuedBufferCount: max_dequeued_buffers=%d", |
| 89 | max_dequeued_buffers); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 90 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 91 | std::unique_lock<std::mutex> lock(mutex_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 92 | |
| 93 | if (max_dequeued_buffers <= 0 || |
| 94 | max_dequeued_buffers > |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 95 | int(dvr::BufferHubQueue::kMaxQueueCapacity - kDefaultUndequeuedBuffers)) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 96 | ALOGE("setMaxDequeuedBufferCount: %d out of range (0, %zu]", |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 97 | max_dequeued_buffers, dvr::BufferHubQueue::kMaxQueueCapacity); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 98 | return BAD_VALUE; |
| 99 | } |
| 100 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 101 | // The new dequeued_buffers count should not be violated by the number |
| 102 | // of currently dequeued buffers. |
| 103 | int dequeued_count = 0; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 104 | for (const auto& buf : buffers_) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 105 | if (buf.mBufferState.isDequeued()) { |
| 106 | dequeued_count++; |
| 107 | } |
| 108 | } |
| 109 | if (dequeued_count > max_dequeued_buffers) { |
| 110 | ALOGE( |
| 111 | "setMaxDequeuedBufferCount: the requested dequeued_buffers" |
| 112 | "count (%d) exceeds the current dequeued buffer count (%d)", |
| 113 | max_dequeued_buffers, dequeued_count); |
| 114 | return BAD_VALUE; |
| 115 | } |
| 116 | |
| 117 | max_dequeued_buffer_count_ = max_dequeued_buffers; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 118 | return NO_ERROR; |
| 119 | } |
| 120 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 121 | status_t BufferHubProducer::setAsyncMode(bool async) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 122 | if (async) { |
| 123 | // TODO(b/36724099) BufferHubQueue's consumer end always acquires the buffer |
| 124 | // automatically and behaves differently from IGraphicBufferConsumer. Thus, |
| 125 | // android::BufferQueue's async mode (a.k.a. allocating an additional buffer |
| 126 | // to prevent dequeueBuffer from being blocking) technically does not apply |
| 127 | // here. |
| 128 | // |
| 129 | // In Daydream, non-blocking producer side dequeue is guaranteed by careful |
| 130 | // buffer consumer implementations. In another word, BufferHubQueue based |
| 131 | // dequeueBuffer should never block whether setAsyncMode(true) is set or |
| 132 | // not. |
| 133 | // |
| 134 | // See: IGraphicBufferProducer::setAsyncMode and |
| 135 | // BufferQueueProducer::setAsyncMode for more about original implementation. |
| 136 | ALOGW( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 137 | "BufferHubProducer::setAsyncMode: BufferHubQueue should always be " |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 138 | "asynchronous. This call makes no effact."); |
| 139 | return NO_ERROR; |
| 140 | } |
| 141 | return NO_ERROR; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 144 | status_t BufferHubProducer::dequeueBuffer( |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 145 | int* out_slot, sp<Fence>* out_fence, uint32_t width, uint32_t height, |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 146 | PixelFormat format, uint64_t usage, uint64_t* /*outBufferAge*/, |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 147 | FrameEventHistoryDelta* /* out_timestamps */) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 148 | ALOGV("dequeueBuffer: w=%u, h=%u, format=%d, usage=%" PRIu64, width, height, |
| 149 | format, usage); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 150 | |
| 151 | status_t ret; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 152 | std::unique_lock<std::mutex> lock(mutex_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 153 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 154 | if (connected_api_ == kNoConnectedApi) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 155 | ALOGE("dequeueBuffer: BufferQueue has no connected producer"); |
| 156 | return NO_INIT; |
| 157 | } |
| 158 | |
Hendrik Wagenaar | 108e84f | 2017-05-07 22:19:17 -0700 | [diff] [blame] | 159 | const uint32_t kLayerCount = 1; |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 160 | if (int32_t(queue_->capacity()) < max_dequeued_buffer_count_ + kDefaultUndequeuedBuffers) { |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 161 | // Lazy allocation. When the capacity of |queue_| has not reached |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 162 | // |max_dequeued_buffer_count_|, allocate new buffer. |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 163 | // TODO(jwcai) To save memory, the really reasonable thing to do is to go |
| 164 | // over existing slots and find first existing one to dequeue. |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 165 | ret = AllocateBuffer(width, height, kLayerCount, format, usage); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 166 | if (ret < 0) |
| 167 | return ret; |
| 168 | } |
| 169 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 170 | size_t slot = 0; |
| 171 | std::shared_ptr<dvr::BufferProducer> buffer_producer; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 172 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 173 | for (size_t retry = 0; retry < dvr::BufferHubQueue::kMaxQueueCapacity; |
| 174 | retry++) { |
Jiwen 'Steve' Cai | ed65432 | 2017-03-13 17:04:43 -0700 | [diff] [blame] | 175 | LocalHandle fence; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 176 | auto buffer_status = queue_->Dequeue(dequeue_timeout_ms_, &slot, &fence); |
Corey Tabaka | b7ca5de | 2017-05-08 18:55:02 -0700 | [diff] [blame] | 177 | if (!buffer_status) |
| 178 | return NO_MEMORY; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 179 | |
Corey Tabaka | 9d8bd09 | 2017-04-25 16:47:44 -0700 | [diff] [blame] | 180 | buffer_producer = buffer_status.take(); |
Jiwen 'Steve' Cai | b850821 | 2017-05-08 16:02:36 -0700 | [diff] [blame] | 181 | if (!buffer_producer) |
| 182 | return NO_MEMORY; |
Corey Tabaka | 9d8bd09 | 2017-04-25 16:47:44 -0700 | [diff] [blame] | 183 | |
Corey Tabaka | cd52dd9 | 2017-04-07 18:03:57 -0700 | [diff] [blame] | 184 | if (width == buffer_producer->width() && |
| 185 | height == buffer_producer->height() && |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 186 | uint32_t(format) == buffer_producer->format()) { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 187 | // The producer queue returns a buffer producer matches the request. |
| 188 | break; |
| 189 | } |
| 190 | |
| 191 | // Needs reallocation. |
| 192 | // TODO(jwcai) Consider use VLOG instead if we find this log is not useful. |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 193 | ALOGI( |
Corey Tabaka | cd52dd9 | 2017-04-07 18:03:57 -0700 | [diff] [blame] | 194 | "dequeueBuffer: requested buffer (w=%u, h=%u, format=%u) is different " |
| 195 | "from the buffer returned at slot: %zu (w=%u, h=%u, format=%u). Need " |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 196 | "re-allocattion.", |
| 197 | width, height, format, slot, buffer_producer->width(), |
| 198 | buffer_producer->height(), buffer_producer->format()); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 199 | // Mark the slot as reallocating, so that later we can set |
| 200 | // BUFFER_NEEDS_REALLOCATION when the buffer actually get dequeued. |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 201 | buffers_[slot].mIsReallocating = true; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 202 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 203 | // Remove the old buffer once the allocation before allocating its |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 204 | // replacement. |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 205 | RemoveBuffer(slot); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 206 | |
| 207 | // Allocate a new producer buffer with new buffer configs. Note that if |
| 208 | // there are already multiple buffers in the queue, the next one returned |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 209 | // from |queue_->Dequeue| may not be the new buffer we just reallocated. |
| 210 | // Retry up to BufferHubQueue::kMaxQueueCapacity times. |
| 211 | ret = AllocateBuffer(width, height, kLayerCount, format, usage); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 212 | if (ret < 0) |
| 213 | return ret; |
| 214 | } |
| 215 | |
| 216 | // With the BufferHub backed solution. Buffer slot returned from |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 217 | // |queue_->Dequeue| is guaranteed to avaiable for producer's use. |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 218 | // It's either in free state (if the buffer has never been used before) or |
| 219 | // in queued state (if the buffer has been dequeued and queued back to |
| 220 | // BufferHubQueue). |
Jiwen 'Steve' Cai | 005f45d | 2017-08-04 17:34:37 -0700 | [diff] [blame] | 221 | LOG_ALWAYS_FATAL_IF( |
| 222 | (!buffers_[slot].mBufferState.isFree() && |
| 223 | !buffers_[slot].mBufferState.isQueued()), |
| 224 | "dequeueBuffer: slot %zu is not free or queued, actual state: %s.", slot, |
| 225 | buffers_[slot].mBufferState.string()); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 226 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 227 | buffers_[slot].mBufferState.freeQueued(); |
| 228 | buffers_[slot].mBufferState.dequeue(); |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 229 | ALOGV("dequeueBuffer: slot=%zu", slot); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 230 | |
| 231 | // TODO(jwcai) Handle fence properly. |BufferHub| has full fence support, we |
| 232 | // just need to exopose that through |BufferHubQueue| once we need fence. |
| 233 | *out_fence = Fence::NO_FENCE; |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 234 | *out_slot = int(slot); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 235 | ret = NO_ERROR; |
| 236 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 237 | if (buffers_[slot].mIsReallocating) { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 238 | ret |= BUFFER_NEEDS_REALLOCATION; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 239 | buffers_[slot].mIsReallocating = false; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return ret; |
| 243 | } |
| 244 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 245 | status_t BufferHubProducer::detachBuffer(int /* slot */) { |
| 246 | ALOGE("BufferHubProducer::detachBuffer not implemented."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 247 | return INVALID_OPERATION; |
| 248 | } |
| 249 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 250 | status_t BufferHubProducer::detachNextBuffer( |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 251 | sp<GraphicBuffer>* /* out_buffer */, sp<Fence>* /* out_fence */) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 252 | ALOGE("BufferHubProducer::detachNextBuffer not implemented."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 253 | return INVALID_OPERATION; |
| 254 | } |
| 255 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 256 | status_t BufferHubProducer::attachBuffer( |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 257 | int* /* out_slot */, const sp<GraphicBuffer>& /* buffer */) { |
| 258 | // With this BufferHub backed implementation, we assume (for now) all buffers |
| 259 | // are allocated and owned by the BufferHub. Thus the attempt of transfering |
| 260 | // ownership of a buffer to the buffer queue is intentionally unsupported. |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 261 | LOG_ALWAYS_FATAL("BufferHubProducer::attachBuffer not supported."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 262 | return INVALID_OPERATION; |
| 263 | } |
| 264 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 265 | status_t BufferHubProducer::queueBuffer(int slot, const QueueBufferInput& input, |
| 266 | QueueBufferOutput* output) { |
| 267 | ALOGV("queueBuffer: slot %d", slot); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 268 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 269 | if (output == nullptr) { |
| 270 | return BAD_VALUE; |
| 271 | } |
| 272 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 273 | int64_t timestamp; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 274 | bool is_auto_timestamp; |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 275 | android_dataspace dataspace; |
| 276 | Rect crop(Rect::EMPTY_RECT); |
| 277 | int scaling_mode; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 278 | uint32_t transform; |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 279 | sp<Fence> fence; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 280 | |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 281 | input.deflate(×tamp, &is_auto_timestamp, &dataspace, &crop, |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 282 | &scaling_mode, &transform, &fence); |
| 283 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 284 | // Check input scaling mode is valid. |
| 285 | switch (scaling_mode) { |
| 286 | case NATIVE_WINDOW_SCALING_MODE_FREEZE: |
| 287 | case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: |
| 288 | case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: |
| 289 | case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP: |
| 290 | break; |
| 291 | default: |
| 292 | ALOGE("queueBuffer: unknown scaling mode %d", scaling_mode); |
| 293 | return BAD_VALUE; |
| 294 | } |
| 295 | |
| 296 | // Check input fence is valid. |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 297 | if (fence == nullptr) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 298 | ALOGE("queueBuffer: fence is NULL"); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 299 | return BAD_VALUE; |
| 300 | } |
| 301 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 302 | std::unique_lock<std::mutex> lock(mutex_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 303 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 304 | if (connected_api_ == kNoConnectedApi) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 305 | ALOGE("queueBuffer: BufferQueue has no connected producer"); |
| 306 | return NO_INIT; |
| 307 | } |
| 308 | |
| 309 | if (slot < 0 || slot >= max_buffer_count_) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 310 | ALOGE("queueBuffer: slot index %d out of range [0, %d)", slot, |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 311 | max_buffer_count_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 312 | return BAD_VALUE; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 313 | } else if (!buffers_[slot].mBufferState.isDequeued()) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 314 | ALOGE("queueBuffer: slot %d is not owned by the producer (state = %s)", |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 315 | slot, buffers_[slot].mBufferState.string()); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 316 | return BAD_VALUE; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 317 | } else if ((!buffers_[slot].mRequestBufferCalled || |
| 318 | buffers_[slot].mGraphicBuffer == nullptr)) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 319 | ALOGE( |
| 320 | "queueBuffer: slot %d is not requested (mRequestBufferCalled=%d, " |
| 321 | "mGraphicBuffer=%p)", |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 322 | slot, buffers_[slot].mRequestBufferCalled, |
| 323 | buffers_[slot].mGraphicBuffer.get()); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 324 | return BAD_VALUE; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // Post the buffer producer with timestamp in the metadata. |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 328 | const auto& buffer_producer = buffers_[slot].mBufferProducer; |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 329 | |
| 330 | // Check input crop is not out of boundary of current buffer. |
| 331 | Rect buffer_rect(buffer_producer->width(), buffer_producer->height()); |
| 332 | Rect cropped_rect(Rect::EMPTY_RECT); |
| 333 | crop.intersect(buffer_rect, &cropped_rect); |
| 334 | if (cropped_rect != crop) { |
| 335 | ALOGE("queueBuffer: slot %d has out-of-boundary crop.", slot); |
| 336 | return BAD_VALUE; |
| 337 | } |
| 338 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 339 | LocalHandle fence_fd(fence->isValid() ? fence->dup() : -1); |
| 340 | |
Corey Tabaka | 52ea25c | 2017-09-13 18:02:48 -0700 | [diff] [blame] | 341 | DvrNativeBufferMetadata meta_data; |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 342 | meta_data.timestamp = timestamp; |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 343 | meta_data.is_auto_timestamp = int32_t(is_auto_timestamp); |
| 344 | meta_data.dataspace = int32_t(dataspace); |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 345 | meta_data.crop_left = crop.left; |
| 346 | meta_data.crop_top = crop.top; |
| 347 | meta_data.crop_right = crop.right; |
| 348 | meta_data.crop_bottom = crop.bottom; |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 349 | meta_data.scaling_mode = int32_t(scaling_mode); |
| 350 | meta_data.transform = int32_t(transform); |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 351 | |
Corey Tabaka | 52ea25c | 2017-09-13 18:02:48 -0700 | [diff] [blame] | 352 | buffer_producer->PostAsync(&meta_data, fence_fd); |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 353 | buffers_[slot].mBufferState.queue(); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 354 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 355 | output->width = buffer_producer->width(); |
| 356 | output->height = buffer_producer->height(); |
Corey Tabaka | cd52dd9 | 2017-04-07 18:03:57 -0700 | [diff] [blame] | 357 | output->transformHint = 0; // default value, we don't use it yet. |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 358 | |
| 359 | // |numPendingBuffers| counts of the number of buffers that has been enqueued |
| 360 | // by the producer but not yet acquired by the consumer. Due to the nature |
| 361 | // of BufferHubQueue design, this is hard to trace from the producer's client |
| 362 | // side, but it's safe to assume it's zero. |
| 363 | output->numPendingBuffers = 0; |
| 364 | |
| 365 | // Note that we are not setting nextFrameNumber here as it seems to be only |
| 366 | // used by surface flinger. See more at b/22802885, ag/791760. |
| 367 | output->nextFrameNumber = 0; |
| 368 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 369 | return NO_ERROR; |
| 370 | } |
| 371 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 372 | status_t BufferHubProducer::cancelBuffer(int slot, const sp<Fence>& fence) { |
| 373 | ALOGV(__FUNCTION__); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 374 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 375 | std::unique_lock<std::mutex> lock(mutex_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 376 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 377 | if (connected_api_ == kNoConnectedApi) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 378 | ALOGE("cancelBuffer: BufferQueue has no connected producer"); |
| 379 | return NO_INIT; |
| 380 | } |
| 381 | |
| 382 | if (slot < 0 || slot >= max_buffer_count_) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 383 | ALOGE("cancelBuffer: slot index %d out of range [0, %d)", slot, |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 384 | max_buffer_count_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 385 | return BAD_VALUE; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 386 | } else if (!buffers_[slot].mBufferState.isDequeued()) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 387 | ALOGE("cancelBuffer: slot %d is not owned by the producer (state = %s)", |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 388 | slot, buffers_[slot].mBufferState.string()); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 389 | return BAD_VALUE; |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 390 | } else if (fence == nullptr) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 391 | ALOGE("cancelBuffer: fence is NULL"); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 392 | return BAD_VALUE; |
| 393 | } |
| 394 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 395 | auto buffer_producer = buffers_[slot].mBufferProducer; |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 396 | queue_->Enqueue(buffer_producer, size_t(slot), 0ULL); |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 397 | buffers_[slot].mBufferState.cancel(); |
| 398 | buffers_[slot].mFence = fence; |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 399 | ALOGV("cancelBuffer: slot %d", slot); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 400 | |
| 401 | return NO_ERROR; |
| 402 | } |
| 403 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 404 | status_t BufferHubProducer::query(int what, int* out_value) { |
| 405 | ALOGV(__FUNCTION__); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 406 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 407 | std::unique_lock<std::mutex> lock(mutex_); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 408 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 409 | if (out_value == nullptr) { |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 410 | ALOGE("query: out_value was NULL"); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 411 | return BAD_VALUE; |
| 412 | } |
| 413 | |
| 414 | int value = 0; |
| 415 | switch (what) { |
| 416 | case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS: |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 417 | // TODO(b/36187402) This should be the maximum number of buffers that this |
| 418 | // producer queue's consumer can acquire. Set to be at least one. Need to |
| 419 | // find a way to set from the consumer side. |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 420 | value = kDefaultUndequeuedBuffers; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 421 | break; |
| 422 | case NATIVE_WINDOW_BUFFER_AGE: |
| 423 | value = 0; |
| 424 | break; |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 425 | case NATIVE_WINDOW_WIDTH: |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 426 | value = int32_t(queue_->default_width()); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 427 | break; |
| 428 | case NATIVE_WINDOW_HEIGHT: |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 429 | value = int32_t(queue_->default_height()); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 430 | break; |
| 431 | case NATIVE_WINDOW_FORMAT: |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 432 | value = int32_t(queue_->default_format()); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 433 | break; |
| 434 | case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: |
| 435 | // BufferHubQueue is always operating in async mode, thus semantically |
| 436 | // consumer can never be running behind. See BufferQueueCore.cpp core |
| 437 | // for more information about the original meaning of this flag. |
| 438 | value = 0; |
| 439 | break; |
| 440 | case NATIVE_WINDOW_CONSUMER_USAGE_BITS: |
| 441 | // TODO(jwcai) This is currently not implement as we don't need |
| 442 | // IGraphicBufferConsumer parity. |
| 443 | value = 0; |
| 444 | break; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 445 | case NATIVE_WINDOW_DEFAULT_DATASPACE: |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 446 | // TODO(jwcai) Return the default value android::BufferQueue is using as |
| 447 | // there is no way dvr::ConsumerQueue can set it. |
| 448 | value = 0; // HAL_DATASPACE_UNKNOWN |
| 449 | break; |
| 450 | case NATIVE_WINDOW_STICKY_TRANSFORM: |
| 451 | // TODO(jwcai) Return the default value android::BufferQueue is using as |
| 452 | // there is no way dvr::ConsumerQueue can set it. |
| 453 | value = 0; |
| 454 | break; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 455 | case NATIVE_WINDOW_CONSUMER_IS_PROTECTED: |
| 456 | // In Daydream's implementation, the consumer end (i.e. VR Compostior) |
| 457 | // knows how to handle protected buffers. |
| 458 | value = 1; |
| 459 | break; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 460 | default: |
| 461 | return BAD_VALUE; |
| 462 | } |
| 463 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 464 | ALOGV("query: key=%d, v=%d", what, value); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 465 | *out_value = value; |
| 466 | return NO_ERROR; |
| 467 | } |
| 468 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 469 | status_t BufferHubProducer::connect(const sp<IProducerListener>& /* listener */, |
| 470 | int api, |
| 471 | bool /* producer_controlled_by_app */, |
| 472 | QueueBufferOutput* output) { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 473 | // Consumer interaction are actually handled by buffer hub, and we need |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 474 | // to maintain consumer operations here. We only need to perform basic input |
| 475 | // parameter checks here. |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 476 | ALOGV(__FUNCTION__); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 477 | |
| 478 | if (output == nullptr) { |
| 479 | return BAD_VALUE; |
| 480 | } |
| 481 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 482 | std::unique_lock<std::mutex> lock(mutex_); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 483 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 484 | if (connected_api_ != kNoConnectedApi) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 485 | return BAD_VALUE; |
| 486 | } |
| 487 | |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 488 | if (!queue_->is_connected()) { |
| 489 | ALOGE( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 490 | "BufferHubProducer::connect: This BufferHubProducer is not " |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 491 | "connected to bufferhud. Has it been taken out as a parcelable?"); |
| 492 | return BAD_VALUE; |
| 493 | } |
| 494 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 495 | switch (api) { |
| 496 | case NATIVE_WINDOW_API_EGL: |
| 497 | case NATIVE_WINDOW_API_CPU: |
| 498 | case NATIVE_WINDOW_API_MEDIA: |
| 499 | case NATIVE_WINDOW_API_CAMERA: |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 500 | connected_api_ = api; |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 501 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 502 | output->width = queue_->default_width(); |
| 503 | output->height = queue_->default_height(); |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 504 | |
| 505 | // default values, we don't use them yet. |
| 506 | output->transformHint = 0; |
| 507 | output->numPendingBuffers = 0; |
| 508 | output->nextFrameNumber = 0; |
| 509 | output->bufferReplaced = false; |
| 510 | |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 511 | break; |
| 512 | default: |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 513 | ALOGE("BufferHubProducer::connect: unknow API %d", api); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 514 | return BAD_VALUE; |
| 515 | } |
| 516 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 517 | return NO_ERROR; |
| 518 | } |
| 519 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 520 | status_t BufferHubProducer::disconnect(int api, DisconnectMode /*mode*/) { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 521 | // Consumer interaction are actually handled by buffer hub, and we need |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 522 | // to maintain consumer operations here. We only need to perform basic input |
| 523 | // parameter checks here. |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 524 | ALOGV(__FUNCTION__); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 525 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 526 | std::unique_lock<std::mutex> lock(mutex_); |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 527 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 528 | if (kNoConnectedApi == connected_api_) { |
Wonsik Kim | 3e198b2 | 2017-04-07 15:43:16 -0700 | [diff] [blame] | 529 | return NO_INIT; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 530 | } else if (api != connected_api_) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 531 | return BAD_VALUE; |
| 532 | } |
| 533 | |
Jiwen 'Steve' Cai | 005f45d | 2017-08-04 17:34:37 -0700 | [diff] [blame] | 534 | FreeAllBuffers(); |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 535 | connected_api_ = kNoConnectedApi; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 536 | return NO_ERROR; |
| 537 | } |
| 538 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 539 | status_t BufferHubProducer::setSidebandStream(const sp<NativeHandle>& stream) { |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 540 | if (stream != nullptr) { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 541 | // TODO(jwcai) Investigate how is is used, maybe use BufferHubBuffer's |
| 542 | // metadata. |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 543 | ALOGE("SidebandStream is not currently supported."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 544 | return INVALID_OPERATION; |
| 545 | } |
| 546 | return NO_ERROR; |
| 547 | } |
| 548 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 549 | void BufferHubProducer::allocateBuffers(uint32_t /* width */, |
| 550 | uint32_t /* height */, |
| 551 | PixelFormat /* format */, |
| 552 | uint64_t /* usage */) { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 553 | // TODO(jwcai) |allocateBuffers| aims to preallocate up to the maximum number |
| 554 | // of buffers permitted by the current BufferQueue configuration (aka |
Jiwen 'Steve' Cai | 1601bcf | 2017-03-24 14:03:06 -0700 | [diff] [blame] | 555 | // |max_buffer_count_|). |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 556 | ALOGE("BufferHubProducer::allocateBuffers not implemented."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 559 | status_t BufferHubProducer::allowAllocation(bool /* allow */) { |
| 560 | ALOGE("BufferHubProducer::allowAllocation not implemented."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 561 | return INVALID_OPERATION; |
| 562 | } |
| 563 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 564 | status_t BufferHubProducer::setGenerationNumber(uint32_t generation_number) { |
| 565 | ALOGV(__FUNCTION__); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 566 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 567 | std::unique_lock<std::mutex> lock(mutex_); |
| 568 | generation_number_ = generation_number; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 569 | return NO_ERROR; |
| 570 | } |
| 571 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 572 | String8 BufferHubProducer::getConsumerName() const { |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 573 | // BufferHub based implementation could have one to many producer/consumer |
| 574 | // relationship, thus |getConsumerName| from the producer side does not |
| 575 | // make any sense. |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 576 | ALOGE("BufferHubProducer::getConsumerName not supported."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 577 | return String8("BufferHubQueue::DummyConsumer"); |
| 578 | } |
| 579 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 580 | status_t BufferHubProducer::setSharedBufferMode(bool shared_buffer_mode) { |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 581 | if (shared_buffer_mode) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 582 | ALOGE("BufferHubProducer::setSharedBufferMode(true) is not supported."); |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 583 | // TODO(b/36373181) Front buffer mode for buffer hub queue as ANativeWindow. |
| 584 | return INVALID_OPERATION; |
| 585 | } |
| 586 | // Setting to default should just work as a no-op. |
| 587 | return NO_ERROR; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 590 | status_t BufferHubProducer::setAutoRefresh(bool auto_refresh) { |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 591 | if (auto_refresh) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 592 | ALOGE("BufferHubProducer::setAutoRefresh(true) is not supported."); |
Jiwen 'Steve' Cai | cb4751c | 2017-04-14 17:56:55 -0700 | [diff] [blame] | 593 | return INVALID_OPERATION; |
| 594 | } |
| 595 | // Setting to default should just work as a no-op. |
| 596 | return NO_ERROR; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 599 | status_t BufferHubProducer::setDequeueTimeout(nsecs_t timeout) { |
| 600 | ALOGV(__FUNCTION__); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 601 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 602 | std::unique_lock<std::mutex> lock(mutex_); |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 603 | dequeue_timeout_ms_ = int(timeout / (1000 * 1000)); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 604 | return NO_ERROR; |
| 605 | } |
| 606 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 607 | status_t BufferHubProducer::getLastQueuedBuffer( |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 608 | sp<GraphicBuffer>* /* out_buffer */, sp<Fence>* /* out_fence */, |
| 609 | float /*out_transform_matrix*/[16]) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 610 | ALOGE("BufferHubProducer::getLastQueuedBuffer not implemented."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 611 | return INVALID_OPERATION; |
| 612 | } |
| 613 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 614 | void BufferHubProducer::getFrameTimestamps( |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 615 | FrameEventHistoryDelta* /*outDelta*/) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 616 | ALOGE("BufferHubProducer::getFrameTimestamps not implemented."); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 619 | status_t BufferHubProducer::getUniqueId(uint64_t* out_id) const { |
| 620 | ALOGV(__FUNCTION__); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 621 | |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 622 | *out_id = unique_id_; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 623 | return NO_ERROR; |
| 624 | } |
| 625 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 626 | status_t BufferHubProducer::getConsumerUsage(uint64_t* out_usage) const { |
| 627 | ALOGV(__FUNCTION__); |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 628 | |
| 629 | // same value as returned by querying NATIVE_WINDOW_CONSUMER_USAGE_BITS |
| 630 | *out_usage = 0; |
| 631 | return NO_ERROR; |
| 632 | } |
| 633 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 634 | status_t BufferHubProducer::TakeAsParcelable( |
| 635 | dvr::ProducerQueueParcelable* out_parcelable) { |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 636 | if (!out_parcelable || out_parcelable->IsValid()) |
| 637 | return BAD_VALUE; |
| 638 | |
| 639 | if (connected_api_ != kNoConnectedApi) { |
| 640 | ALOGE( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 641 | "BufferHubProducer::TakeAsParcelable: BufferHubProducer has " |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 642 | "connected client. Must disconnect first."); |
| 643 | return BAD_VALUE; |
| 644 | } |
| 645 | |
| 646 | if (!queue_->is_connected()) { |
| 647 | ALOGE( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 648 | "BufferHubProducer::TakeAsParcelable: This BufferHubProducer " |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 649 | "is not connected to bufferhud. Has it been taken out as a " |
| 650 | "parcelable?"); |
| 651 | return BAD_VALUE; |
| 652 | } |
| 653 | |
| 654 | auto status = queue_->TakeAsParcelable(); |
| 655 | if (!status) { |
| 656 | ALOGE( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 657 | "BufferHubProducer::TakeAsParcelable: Failed to take out " |
Jiwen 'Steve' Cai | 5afb740 | 2017-11-09 18:50:32 -0800 | [diff] [blame] | 658 | "ProducuerQueueParcelable from the producer queue, error: %s.", |
| 659 | status.GetErrorMessage().c_str()); |
| 660 | return BAD_VALUE; |
| 661 | } |
| 662 | |
| 663 | *out_parcelable = status.take(); |
| 664 | return NO_ERROR; |
| 665 | } |
| 666 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 667 | status_t BufferHubProducer::AllocateBuffer(uint32_t width, uint32_t height, |
| 668 | uint32_t layer_count, |
| 669 | PixelFormat format, uint64_t usage) { |
| 670 | auto status = queue_->AllocateBuffer(width, height, layer_count, |
| 671 | uint32_t(format), usage); |
Corey Tabaka | b7ca5de | 2017-05-08 18:55:02 -0700 | [diff] [blame] | 672 | if (!status) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 673 | ALOGE("BufferHubProducer::AllocateBuffer: Failed to allocate buffer: %s", |
| 674 | status.GetErrorMessage().c_str()); |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 675 | return NO_MEMORY; |
| 676 | } |
| 677 | |
Jiwen 'Steve' Cai | 8fa4e10 | 2017-05-24 23:16:54 -0700 | [diff] [blame] | 678 | size_t slot = status.get(); |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 679 | auto buffer_producer = queue_->GetBuffer(slot); |
| 680 | |
| 681 | LOG_ALWAYS_FATAL_IF(buffer_producer == nullptr, |
| 682 | "Failed to get buffer producer at slot: %zu", slot); |
| 683 | |
| 684 | buffers_[slot].mBufferProducer = buffer_producer; |
| 685 | |
| 686 | return NO_ERROR; |
| 687 | } |
| 688 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 689 | status_t BufferHubProducer::RemoveBuffer(size_t slot) { |
Jiwen 'Steve' Cai | bb701db | 2017-05-23 11:15:33 -0700 | [diff] [blame] | 690 | auto status = queue_->RemoveBuffer(slot); |
Corey Tabaka | b7ca5de | 2017-05-08 18:55:02 -0700 | [diff] [blame] | 691 | if (!status) { |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 692 | ALOGE("BufferHubProducer::RemoveBuffer: Failed to remove buffer: %s", |
Corey Tabaka | b7ca5de | 2017-05-08 18:55:02 -0700 | [diff] [blame] | 693 | status.GetErrorMessage().c_str()); |
| 694 | return INVALID_OPERATION; |
Jiwen 'Steve' Cai | d6cb17f | 2017-05-08 16:15:35 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | // Reset in memory objects related the the buffer. |
| 698 | buffers_[slot].mBufferProducer = nullptr; |
| 699 | buffers_[slot].mGraphicBuffer = nullptr; |
| 700 | buffers_[slot].mBufferState.detachProducer(); |
| 701 | return NO_ERROR; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 704 | status_t BufferHubProducer::FreeAllBuffers() { |
| 705 | for (size_t slot = 0; slot < dvr::BufferHubQueue::kMaxQueueCapacity; slot++) { |
Jiwen 'Steve' Cai | 005f45d | 2017-08-04 17:34:37 -0700 | [diff] [blame] | 706 | // Reset in memory objects related the the buffer. |
| 707 | buffers_[slot].mGraphicBuffer = nullptr; |
| 708 | buffers_[slot].mBufferState.reset(); |
| 709 | buffers_[slot].mRequestBufferCalled = false; |
| 710 | buffers_[slot].mBufferProducer = nullptr; |
| 711 | buffers_[slot].mFence = Fence::NO_FENCE; |
| 712 | } |
| 713 | |
| 714 | auto status = queue_->FreeAllBuffers(); |
| 715 | if (!status) { |
| 716 | ALOGE( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 717 | "BufferHubProducer::FreeAllBuffers: Failed to free all buffers on " |
Jiwen 'Steve' Cai | 005f45d | 2017-08-04 17:34:37 -0700 | [diff] [blame] | 718 | "the queue: %s", |
| 719 | status.GetErrorMessage().c_str()); |
| 720 | } |
| 721 | |
| 722 | if (queue_->capacity() != 0 || queue_->count() != 0) { |
| 723 | LOG_ALWAYS_FATAL( |
Jiwen 'Steve' Cai | 0f95084 | 2018-01-16 17:05:54 -0800 | [diff] [blame^] | 724 | "BufferHubProducer::FreeAllBuffers: Not all buffers are freed."); |
Jiwen 'Steve' Cai | 005f45d | 2017-08-04 17:34:37 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | return NO_ERROR; |
| 728 | } |
| 729 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 730 | } // namespace android |