Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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_TAG "SharedBufferStack" |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #include <utils/Debug.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <utils/threads.h> |
| 25 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 26 | #include <private/surfaceflinger/SharedBufferStack.h> |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 27 | |
| 28 | #include <ui/Rect.h> |
| 29 | #include <ui/Region.h> |
| 30 | |
| 31 | #define DEBUG_ATOMICS 0 |
| 32 | |
| 33 | namespace android { |
| 34 | // ---------------------------------------------------------------------------- |
| 35 | |
| 36 | SharedClient::SharedClient() |
Mathias Agopian | 26d2442 | 2010-03-19 16:14:13 -0700 | [diff] [blame] | 37 | : lock(Mutex::SHARED), cv(Condition::SHARED) |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
| 41 | SharedClient::~SharedClient() { |
| 42 | } |
| 43 | |
| 44 | |
| 45 | // these functions are used by the clients |
| 46 | status_t SharedClient::validate(size_t i) const { |
| 47 | if (uint32_t(i) >= uint32_t(NUM_LAYERS_MAX)) |
| 48 | return BAD_INDEX; |
| 49 | return surfaces[i].status; |
| 50 | } |
| 51 | |
| 52 | uint32_t SharedClient::getIdentity(size_t token) const { |
| 53 | return uint32_t(surfaces[token].identity); |
| 54 | } |
| 55 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 56 | // ---------------------------------------------------------------------------- |
| 57 | |
| 58 | |
| 59 | SharedBufferStack::SharedBufferStack() |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 60 | { |
| 61 | } |
| 62 | |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 63 | void SharedBufferStack::init(int32_t i) |
| 64 | { |
| 65 | inUse = -1; |
| 66 | status = NO_ERROR; |
| 67 | identity = i; |
| 68 | } |
| 69 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 70 | status_t SharedBufferStack::setDirtyRegion(int buffer, const Region& dirty) |
| 71 | { |
| 72 | if (uint32_t(buffer) >= NUM_BUFFER_MAX) |
| 73 | return BAD_INDEX; |
| 74 | |
| 75 | // in the current implementation we only send a single rectangle |
Mathias Agopian | 1100c8b | 2010-04-05 16:21:53 -0700 | [diff] [blame^] | 76 | size_t count; |
| 77 | Rect const* r = dirty.getArray(&count); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 78 | FlatRegion& reg(dirtyRegion[buffer]); |
Mathias Agopian | 1100c8b | 2010-04-05 16:21:53 -0700 | [diff] [blame^] | 79 | if (count > FlatRegion::NUM_RECT_MAX) { |
| 80 | const Rect bounds(dirty.getBounds()); |
| 81 | reg.count = 1; |
| 82 | reg.rects[0] = uint16_t(bounds.left); |
| 83 | reg.rects[1] = uint16_t(bounds.top); |
| 84 | reg.rects[2] = uint16_t(bounds.right); |
| 85 | reg.rects[3] = uint16_t(bounds.bottom); |
| 86 | } else { |
| 87 | reg.count = count; |
| 88 | for (size_t i=0 ; i<count ; i++) { |
| 89 | reg.rects[i*4 + 0] = uint16_t(r[i].left); |
| 90 | reg.rects[i*4 + 1] = uint16_t(r[i].top); |
| 91 | reg.rects[i*4 + 2] = uint16_t(r[i].right); |
| 92 | reg.rects[i*4 + 3] = uint16_t(r[i].bottom); |
| 93 | } |
| 94 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 95 | return NO_ERROR; |
| 96 | } |
| 97 | |
| 98 | Region SharedBufferStack::getDirtyRegion(int buffer) const |
| 99 | { |
| 100 | Region res; |
| 101 | if (uint32_t(buffer) >= NUM_BUFFER_MAX) |
| 102 | return res; |
| 103 | |
| 104 | const FlatRegion& reg(dirtyRegion[buffer]); |
Mathias Agopian | 1100c8b | 2010-04-05 16:21:53 -0700 | [diff] [blame^] | 105 | if (reg.count > FlatRegion::NUM_RECT_MAX) |
| 106 | return res; |
| 107 | |
| 108 | if (reg.count == 1) { |
| 109 | res.set(Rect(reg.rects[0], reg.rects[1], reg.rects[2], reg.rects[3])); |
| 110 | } else { |
| 111 | for (size_t i=0 ; i<reg.count ; i++) { |
| 112 | const Rect r( |
| 113 | reg.rects[i*4 + 0], |
| 114 | reg.rects[i*4 + 1], |
| 115 | reg.rects[i*4 + 2], |
| 116 | reg.rects[i*4 + 3]); |
| 117 | res.orSelf(r); |
| 118 | } |
| 119 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 120 | return res; |
| 121 | } |
| 122 | |
| 123 | // ---------------------------------------------------------------------------- |
| 124 | |
| 125 | SharedBufferBase::SharedBufferBase(SharedClient* sharedClient, |
Mathias Agopian | 9ec430a | 2009-10-06 19:00:57 -0700 | [diff] [blame] | 126 | int surface, int num, int32_t identity) |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 127 | : mSharedClient(sharedClient), |
| 128 | mSharedStack(sharedClient->surfaces + surface), |
Mathias Agopian | 9ec430a | 2009-10-06 19:00:57 -0700 | [diff] [blame] | 129 | mNumBuffers(num), mIdentity(identity) |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 130 | { |
| 131 | } |
| 132 | |
| 133 | SharedBufferBase::~SharedBufferBase() |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | uint32_t SharedBufferBase::getIdentity() |
| 138 | { |
| 139 | SharedBufferStack& stack( *mSharedStack ); |
| 140 | return stack.identity; |
| 141 | } |
| 142 | |
Mathias Agopian | 0b3ad46 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 143 | status_t SharedBufferBase::getStatus() const |
| 144 | { |
| 145 | SharedBufferStack& stack( *mSharedStack ); |
| 146 | return stack.status; |
| 147 | } |
| 148 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 149 | size_t SharedBufferBase::getFrontBuffer() const |
| 150 | { |
| 151 | SharedBufferStack& stack( *mSharedStack ); |
| 152 | return size_t( stack.head ); |
| 153 | } |
| 154 | |
| 155 | String8 SharedBufferBase::dump(char const* prefix) const |
| 156 | { |
| 157 | const size_t SIZE = 1024; |
| 158 | char buffer[SIZE]; |
| 159 | String8 result; |
| 160 | SharedBufferStack& stack( *mSharedStack ); |
Mathias Agopian | c2e30de | 2010-03-08 19:23:26 -0800 | [diff] [blame] | 161 | int tail = (mNumBuffers + stack.head - stack.available + 1) % mNumBuffers; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 162 | snprintf(buffer, SIZE, |
Mathias Agopian | c2e30de | 2010-03-08 19:23:26 -0800 | [diff] [blame] | 163 | "%s[ head=%2d, available=%2d, queued=%2d, tail=%2d ] " |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 164 | "reallocMask=%08x, inUse=%2d, identity=%d, status=%d\n", |
Mathias Agopian | c2e30de | 2010-03-08 19:23:26 -0800 | [diff] [blame] | 165 | prefix, stack.head, stack.available, stack.queued, tail, |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 166 | stack.reallocMask, stack.inUse, stack.identity, stack.status); |
| 167 | result.append(buffer); |
| 168 | return result; |
| 169 | } |
| 170 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 171 | // ============================================================================ |
| 172 | // conditions and updates |
| 173 | // ============================================================================ |
| 174 | |
| 175 | SharedBufferClient::DequeueCondition::DequeueCondition( |
| 176 | SharedBufferClient* sbc) : ConditionBase(sbc) { |
| 177 | } |
| 178 | bool SharedBufferClient::DequeueCondition::operator()() { |
| 179 | return stack.available > 0; |
| 180 | } |
| 181 | |
| 182 | SharedBufferClient::LockCondition::LockCondition( |
| 183 | SharedBufferClient* sbc, int buf) : ConditionBase(sbc), buf(buf) { |
| 184 | } |
| 185 | bool SharedBufferClient::LockCondition::operator()() { |
| 186 | return (buf != stack.head || |
| 187 | (stack.queued > 0 && stack.inUse != buf)); |
| 188 | } |
| 189 | |
| 190 | SharedBufferServer::ReallocateCondition::ReallocateCondition( |
| 191 | SharedBufferBase* sbb, int buf) : ConditionBase(sbb), buf(buf) { |
| 192 | } |
| 193 | bool SharedBufferServer::ReallocateCondition::operator()() { |
| 194 | // TODO: we should also check that buf has been dequeued |
| 195 | return (buf != stack.head); |
| 196 | } |
| 197 | |
| 198 | // ---------------------------------------------------------------------------- |
| 199 | |
| 200 | SharedBufferClient::QueueUpdate::QueueUpdate(SharedBufferBase* sbb) |
| 201 | : UpdateBase(sbb) { |
| 202 | } |
| 203 | ssize_t SharedBufferClient::QueueUpdate::operator()() { |
| 204 | android_atomic_inc(&stack.queued); |
| 205 | return NO_ERROR; |
| 206 | } |
| 207 | |
| 208 | SharedBufferClient::UndoDequeueUpdate::UndoDequeueUpdate(SharedBufferBase* sbb) |
| 209 | : UpdateBase(sbb) { |
| 210 | } |
| 211 | ssize_t SharedBufferClient::UndoDequeueUpdate::operator()() { |
| 212 | android_atomic_inc(&stack.available); |
| 213 | return NO_ERROR; |
| 214 | } |
| 215 | |
| 216 | SharedBufferServer::UnlockUpdate::UnlockUpdate( |
| 217 | SharedBufferBase* sbb, int lockedBuffer) |
| 218 | : UpdateBase(sbb), lockedBuffer(lockedBuffer) { |
| 219 | } |
| 220 | ssize_t SharedBufferServer::UnlockUpdate::operator()() { |
| 221 | if (stack.inUse != lockedBuffer) { |
| 222 | LOGE("unlocking %d, but currently locked buffer is %d", |
| 223 | lockedBuffer, stack.inUse); |
| 224 | return BAD_VALUE; |
| 225 | } |
| 226 | android_atomic_write(-1, &stack.inUse); |
| 227 | return NO_ERROR; |
| 228 | } |
| 229 | |
| 230 | SharedBufferServer::RetireUpdate::RetireUpdate( |
| 231 | SharedBufferBase* sbb, int numBuffers) |
| 232 | : UpdateBase(sbb), numBuffers(numBuffers) { |
| 233 | } |
| 234 | ssize_t SharedBufferServer::RetireUpdate::operator()() { |
| 235 | // head is only written in this function, which is single-thread. |
| 236 | int32_t head = stack.head; |
| 237 | |
| 238 | // Preventively lock the current buffer before updating queued. |
| 239 | android_atomic_write(head, &stack.inUse); |
| 240 | |
| 241 | // Decrement the number of queued buffers |
| 242 | int32_t queued; |
| 243 | do { |
| 244 | queued = stack.queued; |
| 245 | if (queued == 0) { |
| 246 | return NOT_ENOUGH_DATA; |
| 247 | } |
| 248 | } while (android_atomic_cmpxchg(queued, queued-1, &stack.queued)); |
| 249 | |
| 250 | // update the head pointer |
| 251 | head = ((head+1 >= numBuffers) ? 0 : head+1); |
| 252 | |
| 253 | // lock the buffer before advancing head, which automatically unlocks |
| 254 | // the buffer we preventively locked upon entering this function |
| 255 | android_atomic_write(head, &stack.inUse); |
| 256 | |
| 257 | // advance head |
| 258 | android_atomic_write(head, &stack.head); |
| 259 | |
| 260 | // now that head has moved, we can increment the number of available buffers |
| 261 | android_atomic_inc(&stack.available); |
| 262 | return head; |
| 263 | } |
| 264 | |
Mathias Agopian | b58b5d7 | 2009-09-10 16:55:13 -0700 | [diff] [blame] | 265 | SharedBufferServer::StatusUpdate::StatusUpdate( |
| 266 | SharedBufferBase* sbb, status_t status) |
| 267 | : UpdateBase(sbb), status(status) { |
| 268 | } |
| 269 | |
| 270 | ssize_t SharedBufferServer::StatusUpdate::operator()() { |
| 271 | android_atomic_write(status, &stack.status); |
| 272 | return NO_ERROR; |
| 273 | } |
| 274 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 275 | // ============================================================================ |
| 276 | |
| 277 | SharedBufferClient::SharedBufferClient(SharedClient* sharedClient, |
Mathias Agopian | 9ec430a | 2009-10-06 19:00:57 -0700 | [diff] [blame] | 278 | int surface, int num, int32_t identity) |
| 279 | : SharedBufferBase(sharedClient, surface, num, identity), tail(0) |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 280 | { |
Mathias Agopian | c7d5601 | 2009-09-14 15:48:42 -0700 | [diff] [blame] | 281 | tail = computeTail(); |
| 282 | } |
| 283 | |
| 284 | int32_t SharedBufferClient::computeTail() const |
| 285 | { |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 286 | SharedBufferStack& stack( *mSharedStack ); |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 287 | // we need to make sure we read available and head coherently, |
| 288 | // w.r.t RetireUpdate. |
Mathias Agopian | c7d5601 | 2009-09-14 15:48:42 -0700 | [diff] [blame] | 289 | int32_t newTail; |
| 290 | int32_t avail; |
| 291 | int32_t head; |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 292 | do { |
| 293 | avail = stack.available; |
| 294 | head = stack.head; |
| 295 | } while (stack.available != avail); |
Mathias Agopian | c7d5601 | 2009-09-14 15:48:42 -0700 | [diff] [blame] | 296 | newTail = head - avail + 1; |
| 297 | if (newTail < 0) { |
| 298 | newTail += mNumBuffers; |
Mathias Agopian | c2e30de | 2010-03-08 19:23:26 -0800 | [diff] [blame] | 299 | } else if (newTail >= mNumBuffers) { |
| 300 | newTail -= mNumBuffers; |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 301 | } |
Mathias Agopian | c7d5601 | 2009-09-14 15:48:42 -0700 | [diff] [blame] | 302 | return newTail; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | ssize_t SharedBufferClient::dequeue() |
| 306 | { |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 307 | SharedBufferStack& stack( *mSharedStack ); |
| 308 | |
Mathias Agopian | 1100c8b | 2010-04-05 16:21:53 -0700 | [diff] [blame^] | 309 | if (stack.head == tail && stack.available == mNumBuffers) { |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 310 | LOGW("dequeue: tail=%d, head=%d, avail=%d, queued=%d", |
| 311 | tail, stack.head, stack.available, stack.queued); |
| 312 | } |
Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 313 | |
| 314 | const nsecs_t dequeueTime = systemTime(SYSTEM_TIME_THREAD); |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 315 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 316 | //LOGD("[%d] about to dequeue a buffer", |
| 317 | // mSharedStack->identity); |
| 318 | DequeueCondition condition(this); |
| 319 | status_t err = waitForCondition(condition); |
| 320 | if (err != NO_ERROR) |
| 321 | return ssize_t(err); |
| 322 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 323 | // NOTE: 'stack.available' is part of the conditions, however |
| 324 | // decrementing it, never changes any conditions, so we don't need |
| 325 | // to do this as part of an update. |
| 326 | if (android_atomic_dec(&stack.available) == 0) { |
| 327 | LOGW("dequeue probably called from multiple threads!"); |
| 328 | } |
| 329 | |
| 330 | int dequeued = tail; |
| 331 | tail = ((tail+1 >= mNumBuffers) ? 0 : tail+1); |
| 332 | LOGD_IF(DEBUG_ATOMICS, "dequeued=%d, tail=%d, %s", |
| 333 | dequeued, tail, dump("").string()); |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 334 | |
Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 335 | mDequeueTime[dequeued] = dequeueTime; |
| 336 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 337 | return dequeued; |
| 338 | } |
| 339 | |
| 340 | status_t SharedBufferClient::undoDequeue(int buf) |
| 341 | { |
| 342 | UndoDequeueUpdate update(this); |
| 343 | status_t err = updateCondition( update ); |
Mathias Agopian | c7d5601 | 2009-09-14 15:48:42 -0700 | [diff] [blame] | 344 | if (err == NO_ERROR) { |
| 345 | tail = computeTail(); |
| 346 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 347 | return err; |
| 348 | } |
| 349 | |
| 350 | status_t SharedBufferClient::lock(int buf) |
| 351 | { |
| 352 | LockCondition condition(this, buf); |
Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 353 | status_t err = waitForCondition(condition); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 354 | return err; |
| 355 | } |
| 356 | |
| 357 | status_t SharedBufferClient::queue(int buf) |
| 358 | { |
| 359 | QueueUpdate update(this); |
| 360 | status_t err = updateCondition( update ); |
| 361 | LOGD_IF(DEBUG_ATOMICS, "queued=%d, %s", buf, dump("").string()); |
Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 362 | SharedBufferStack& stack( *mSharedStack ); |
| 363 | const nsecs_t now = systemTime(SYSTEM_TIME_THREAD); |
| 364 | stack.stats.totalTime = ns2us(now - mDequeueTime[buf]); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 365 | return err; |
| 366 | } |
| 367 | |
| 368 | bool SharedBufferClient::needNewBuffer(int buffer) const |
| 369 | { |
| 370 | SharedBufferStack& stack( *mSharedStack ); |
| 371 | const uint32_t mask = 1<<buffer; |
| 372 | return (android_atomic_and(~mask, &stack.reallocMask) & mask) != 0; |
| 373 | } |
| 374 | |
| 375 | status_t SharedBufferClient::setDirtyRegion(int buffer, const Region& reg) |
| 376 | { |
| 377 | SharedBufferStack& stack( *mSharedStack ); |
| 378 | return stack.setDirtyRegion(buffer, reg); |
| 379 | } |
| 380 | |
| 381 | // ---------------------------------------------------------------------------- |
| 382 | |
| 383 | SharedBufferServer::SharedBufferServer(SharedClient* sharedClient, |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 384 | int surface, int num, int32_t identity) |
Mathias Agopian | 9ec430a | 2009-10-06 19:00:57 -0700 | [diff] [blame] | 385 | : SharedBufferBase(sharedClient, surface, num, identity) |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 386 | { |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 387 | mSharedStack->init(identity); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 388 | mSharedStack->head = num-1; |
| 389 | mSharedStack->available = num; |
| 390 | mSharedStack->queued = 0; |
| 391 | mSharedStack->reallocMask = 0; |
| 392 | memset(mSharedStack->dirtyRegion, 0, sizeof(mSharedStack->dirtyRegion)); |
| 393 | } |
| 394 | |
| 395 | ssize_t SharedBufferServer::retireAndLock() |
| 396 | { |
| 397 | RetireUpdate update(this, mNumBuffers); |
| 398 | ssize_t buf = updateCondition( update ); |
Mathias Agopian | 40d5799 | 2009-09-11 19:18:20 -0700 | [diff] [blame] | 399 | LOGD_IF(DEBUG_ATOMICS && buf>=0, "retire=%d, %s", int(buf), dump("").string()); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 400 | return buf; |
| 401 | } |
| 402 | |
| 403 | status_t SharedBufferServer::unlock(int buffer) |
| 404 | { |
| 405 | UnlockUpdate update(this, buffer); |
| 406 | status_t err = updateCondition( update ); |
| 407 | return err; |
| 408 | } |
| 409 | |
Mathias Agopian | b58b5d7 | 2009-09-10 16:55:13 -0700 | [diff] [blame] | 410 | void SharedBufferServer::setStatus(status_t status) |
| 411 | { |
Mathias Agopian | 0b3ad46 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 412 | if (status < NO_ERROR) { |
| 413 | StatusUpdate update(this, status); |
| 414 | updateCondition( update ); |
| 415 | } |
Mathias Agopian | b58b5d7 | 2009-09-10 16:55:13 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 418 | status_t SharedBufferServer::reallocate() |
| 419 | { |
| 420 | SharedBufferStack& stack( *mSharedStack ); |
| 421 | uint32_t mask = (1<<mNumBuffers)-1; |
| 422 | android_atomic_or(mask, &stack.reallocMask); |
| 423 | return NO_ERROR; |
| 424 | } |
| 425 | |
Mathias Agopian | e700501 | 2009-10-07 16:44:10 -0700 | [diff] [blame] | 426 | int32_t SharedBufferServer::getQueuedCount() const |
| 427 | { |
| 428 | SharedBufferStack& stack( *mSharedStack ); |
| 429 | return stack.queued; |
| 430 | } |
| 431 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 432 | status_t SharedBufferServer::assertReallocate(int buffer) |
| 433 | { |
| 434 | ReallocateCondition condition(this, buffer); |
| 435 | status_t err = waitForCondition(condition); |
| 436 | return err; |
| 437 | } |
| 438 | |
| 439 | Region SharedBufferServer::getDirtyRegion(int buffer) const |
| 440 | { |
| 441 | SharedBufferStack& stack( *mSharedStack ); |
| 442 | return stack.getDirtyRegion(buffer); |
| 443 | } |
| 444 | |
Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 445 | SharedBufferStack::Statistics SharedBufferServer::getStats() const |
| 446 | { |
| 447 | SharedBufferStack& stack( *mSharedStack ); |
| 448 | return stack.stats; |
| 449 | } |
| 450 | |
| 451 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 452 | // --------------------------------------------------------------------------- |
| 453 | }; // namespace android |