The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [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 "Surface" |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <unistd.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <errno.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/stat.h> |
| 25 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <utils/Errors.h> |
| 27 | #include <utils/threads.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 28 | #include <binder/IPCThreadState.h> |
| 29 | #include <binder/IMemory.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | #include <utils/Log.h> |
| 31 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | #include <ui/DisplayInfo.h> |
| 33 | #include <ui/BufferMapper.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <ui/ISurface.h> |
| 35 | #include <ui/Surface.h> |
| 36 | #include <ui/SurfaceComposerClient.h> |
| 37 | #include <ui/Rect.h> |
| 38 | |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 39 | #include <pixelflinger/pixelflinger.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 40 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include <private/ui/SharedState.h> |
| 42 | #include <private/ui/LayerState.h> |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 43 | #include <private/ui/SurfaceBuffer.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 44 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 47 | // ============================================================================ |
| 48 | // SurfaceBuffer |
| 49 | // ============================================================================ |
| 50 | |
| 51 | SurfaceBuffer::SurfaceBuffer() |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 52 | : BASE(), mOwner(false), mBufferMapper(BufferMapper::get()) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 53 | { |
| 54 | width = |
| 55 | height = |
| 56 | stride = |
| 57 | format = |
| 58 | usage = 0; |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 59 | handle = NULL; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | SurfaceBuffer::SurfaceBuffer(const Parcel& data) |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 63 | : BASE(), mOwner(true), mBufferMapper(BufferMapper::get()) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 64 | { |
| 65 | // we own the handle in this case |
| 66 | width = data.readInt32(); |
| 67 | height = data.readInt32(); |
| 68 | stride = data.readInt32(); |
| 69 | format = data.readInt32(); |
| 70 | usage = data.readInt32(); |
| 71 | handle = data.readNativeHandle(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | SurfaceBuffer::~SurfaceBuffer() |
| 75 | { |
| 76 | if (handle && mOwner) { |
| 77 | native_handle_close(handle); |
| 78 | native_handle_delete(const_cast<native_handle*>(handle)); |
| 79 | } |
| 80 | } |
| 81 | |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 82 | status_t SurfaceBuffer::lock(uint32_t usage, void** vaddr) |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 83 | { |
| 84 | const Rect lockBounds(width, height); |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 85 | status_t res = lock(usage, lockBounds, vaddr); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 86 | return res; |
| 87 | } |
| 88 | |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 89 | status_t SurfaceBuffer::lock(uint32_t usage, const Rect& rect, void** vaddr) |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 90 | { |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 91 | if (rect.left < 0 || rect.right > this->width || |
| 92 | rect.top < 0 || rect.bottom > this->height) { |
| 93 | LOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", |
| 94 | rect.left, rect.top, rect.right, rect.bottom, |
| 95 | this->width, this->height); |
| 96 | return BAD_VALUE; |
| 97 | } |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 98 | status_t res = getBufferMapper().lock(handle, usage, rect, vaddr); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 99 | return res; |
| 100 | } |
| 101 | |
| 102 | status_t SurfaceBuffer::unlock() |
| 103 | { |
| 104 | status_t res = getBufferMapper().unlock(handle); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 105 | return res; |
| 106 | } |
| 107 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 108 | status_t SurfaceBuffer::writeToParcel(Parcel* reply, |
| 109 | android_native_buffer_t const* buffer) |
| 110 | { |
Mathias Agopian | 3eded94 | 2009-08-04 20:53:59 -0700 | [diff] [blame^] | 111 | if (buffer == NULL) { |
| 112 | return BAD_VALUE; |
| 113 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 114 | reply->writeInt32(buffer->width); |
| 115 | reply->writeInt32(buffer->height); |
| 116 | reply->writeInt32(buffer->stride); |
| 117 | reply->writeInt32(buffer->format); |
| 118 | reply->writeInt32(buffer->usage); |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 119 | reply->writeNativeHandle(buffer->handle); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 120 | return NO_ERROR; |
| 121 | } |
| 122 | |
| 123 | // ---------------------------------------------------------------------- |
| 124 | |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 125 | static status_t copyBlt( |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 126 | const sp<SurfaceBuffer>& dst, |
| 127 | const sp<SurfaceBuffer>& src, |
| 128 | const Region& reg) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 129 | { |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 130 | status_t err; |
| 131 | uint8_t const * src_bits = NULL; |
| 132 | err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), (void**)&src_bits); |
| 133 | LOGE_IF(err, "error locking src buffer %s", strerror(-err)); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 134 | |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 135 | uint8_t* dst_bits = NULL; |
| 136 | err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), (void**)&dst_bits); |
| 137 | LOGE_IF(err, "error locking dst buffer %s", strerror(-err)); |
| 138 | |
| 139 | Region::const_iterator head(reg.begin()); |
| 140 | Region::const_iterator tail(reg.end()); |
| 141 | if (head != tail && src_bits && dst_bits) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 142 | // NOTE: dst and src must be the same format |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 143 | const size_t bpp = bytesPerPixel(src->format); |
| 144 | const size_t dbpr = dst->stride * bpp; |
| 145 | const size_t sbpr = src->stride * bpp; |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 146 | |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 147 | while (head != tail) { |
| 148 | const Rect& r(*head++); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 149 | ssize_t h = r.height(); |
| 150 | if (h <= 0) continue; |
| 151 | size_t size = r.width() * bpp; |
| 152 | uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp; |
| 153 | uint8_t * d = dst_bits + (r.left + dst->stride * r.top) * bpp; |
| 154 | if (dbpr==sbpr && size==sbpr) { |
| 155 | size *= h; |
| 156 | h = 1; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 157 | } |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 158 | do { |
| 159 | memcpy(d, s, size); |
| 160 | d += dbpr; |
| 161 | s += sbpr; |
| 162 | } while (--h > 0); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 165 | |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 166 | if (src_bits) |
| 167 | src->unlock(); |
| 168 | |
| 169 | if (dst_bits) |
| 170 | dst->unlock(); |
| 171 | |
| 172 | return err; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 175 | // ============================================================================ |
| 176 | // SurfaceControl |
| 177 | // ============================================================================ |
| 178 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 179 | SurfaceControl::SurfaceControl( |
| 180 | const sp<SurfaceComposerClient>& client, |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 181 | const sp<ISurface>& surface, |
| 182 | const ISurfaceFlingerClient::surface_data_t& data, |
Mathias Agopian | 18d8446 | 2009-04-16 20:30:22 -0700 | [diff] [blame] | 183 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 184 | : mClient(client), mSurface(surface), |
| 185 | mToken(data.token), mIdentity(data.identity), |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 186 | mWidth(w), mHeight(h), mFormat(format), mFlags(flags) |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 187 | { |
| 188 | } |
Mathias Agopian | 18d8446 | 2009-04-16 20:30:22 -0700 | [diff] [blame] | 189 | |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 190 | SurfaceControl::~SurfaceControl() |
| 191 | { |
| 192 | destroy(); |
| 193 | } |
| 194 | |
| 195 | void SurfaceControl::destroy() |
| 196 | { |
Mathias Agopian | 18d8446 | 2009-04-16 20:30:22 -0700 | [diff] [blame] | 197 | if (isValid()) { |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 198 | mClient->destroySurface(mToken); |
| 199 | } |
| 200 | |
| 201 | // clear all references and trigger an IPC now, to make sure things |
| 202 | // happen without delay, since these resources are quite heavy. |
| 203 | mClient.clear(); |
| 204 | mSurface.clear(); |
| 205 | IPCThreadState::self()->flushCommands(); |
| 206 | } |
| 207 | |
| 208 | void SurfaceControl::clear() |
| 209 | { |
| 210 | // here, the window manager tells us explicitly that we should destroy |
| 211 | // the surface's resource. Soon after this call, it will also release |
| 212 | // its last reference (which will call the dtor); however, it is possible |
| 213 | // that a client living in the same process still holds references which |
| 214 | // would delay the call to the dtor -- that is why we need this explicit |
| 215 | // "clear()" call. |
| 216 | destroy(); |
| 217 | } |
| 218 | |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 219 | bool SurfaceControl::isSameSurface( |
| 220 | const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs) |
| 221 | { |
| 222 | if (lhs == 0 || rhs == 0) |
| 223 | return false; |
| 224 | return lhs->mSurface->asBinder() == rhs->mSurface->asBinder(); |
| 225 | } |
| 226 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 227 | status_t SurfaceControl::setLayer(int32_t layer) { |
| 228 | const sp<SurfaceComposerClient>& client(mClient); |
| 229 | if (client == 0) return NO_INIT; |
| 230 | status_t err = validate(client->mControl); |
| 231 | if (err < 0) return err; |
| 232 | return client->setLayer(mToken, layer); |
| 233 | } |
| 234 | status_t SurfaceControl::setPosition(int32_t x, int32_t y) { |
| 235 | const sp<SurfaceComposerClient>& client(mClient); |
| 236 | if (client == 0) return NO_INIT; |
| 237 | status_t err = validate(client->mControl); |
| 238 | if (err < 0) return err; |
| 239 | return client->setPosition(mToken, x, y); |
| 240 | } |
| 241 | status_t SurfaceControl::setSize(uint32_t w, uint32_t h) { |
| 242 | const sp<SurfaceComposerClient>& client(mClient); |
| 243 | if (client == 0) return NO_INIT; |
| 244 | status_t err = validate(client->mControl); |
| 245 | if (err < 0) return err; |
| 246 | return client->setSize(mToken, w, h); |
| 247 | } |
| 248 | status_t SurfaceControl::hide() { |
| 249 | const sp<SurfaceComposerClient>& client(mClient); |
| 250 | if (client == 0) return NO_INIT; |
| 251 | status_t err = validate(client->mControl); |
| 252 | if (err < 0) return err; |
| 253 | return client->hide(mToken); |
| 254 | } |
| 255 | status_t SurfaceControl::show(int32_t layer) { |
| 256 | const sp<SurfaceComposerClient>& client(mClient); |
| 257 | if (client == 0) return NO_INIT; |
| 258 | status_t err = validate(client->mControl); |
| 259 | if (err < 0) return err; |
| 260 | return client->show(mToken, layer); |
| 261 | } |
| 262 | status_t SurfaceControl::freeze() { |
| 263 | const sp<SurfaceComposerClient>& client(mClient); |
| 264 | if (client == 0) return NO_INIT; |
| 265 | status_t err = validate(client->mControl); |
| 266 | if (err < 0) return err; |
| 267 | return client->freeze(mToken); |
| 268 | } |
| 269 | status_t SurfaceControl::unfreeze() { |
| 270 | const sp<SurfaceComposerClient>& client(mClient); |
| 271 | if (client == 0) return NO_INIT; |
| 272 | status_t err = validate(client->mControl); |
| 273 | if (err < 0) return err; |
| 274 | return client->unfreeze(mToken); |
| 275 | } |
| 276 | status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) { |
| 277 | const sp<SurfaceComposerClient>& client(mClient); |
| 278 | if (client == 0) return NO_INIT; |
| 279 | status_t err = validate(client->mControl); |
| 280 | if (err < 0) return err; |
| 281 | return client->setFlags(mToken, flags, mask); |
| 282 | } |
| 283 | status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) { |
| 284 | const sp<SurfaceComposerClient>& client(mClient); |
| 285 | if (client == 0) return NO_INIT; |
| 286 | status_t err = validate(client->mControl); |
| 287 | if (err < 0) return err; |
| 288 | return client->setTransparentRegionHint(mToken, transparent); |
| 289 | } |
| 290 | status_t SurfaceControl::setAlpha(float alpha) { |
| 291 | const sp<SurfaceComposerClient>& client(mClient); |
| 292 | if (client == 0) return NO_INIT; |
| 293 | status_t err = validate(client->mControl); |
| 294 | if (err < 0) return err; |
| 295 | return client->setAlpha(mToken, alpha); |
| 296 | } |
| 297 | status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 298 | const sp<SurfaceComposerClient>& client(mClient); |
| 299 | if (client == 0) return NO_INIT; |
| 300 | status_t err = validate(client->mControl); |
| 301 | if (err < 0) return err; |
| 302 | return client->setMatrix(mToken, dsdx, dtdx, dsdy, dtdy); |
| 303 | } |
| 304 | status_t SurfaceControl::setFreezeTint(uint32_t tint) { |
| 305 | const sp<SurfaceComposerClient>& client(mClient); |
| 306 | if (client == 0) return NO_INIT; |
| 307 | status_t err = validate(client->mControl); |
| 308 | if (err < 0) return err; |
| 309 | return client->setFreezeTint(mToken, tint); |
| 310 | } |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 311 | |
| 312 | status_t SurfaceControl::validate(per_client_cblk_t const* cblk) const |
| 313 | { |
| 314 | if (mToken<0 || mClient==0) { |
| 315 | LOGE("invalid token (%d, identity=%u) or client (%p)", |
| 316 | mToken, mIdentity, mClient.get()); |
| 317 | return NO_INIT; |
| 318 | } |
| 319 | if (cblk == 0) { |
| 320 | LOGE("cblk is null (surface id=%d, identity=%u)", mToken, mIdentity); |
| 321 | return NO_INIT; |
| 322 | } |
| 323 | status_t err = cblk->validate(mToken); |
| 324 | if (err != NO_ERROR) { |
| 325 | LOGE("surface (id=%d, identity=%u) is invalid, err=%d (%s)", |
| 326 | mToken, mIdentity, err, strerror(-err)); |
| 327 | return err; |
| 328 | } |
| 329 | if (mIdentity != uint32_t(cblk->layers[mToken].identity)) { |
| 330 | LOGE("using an invalid surface id=%d, identity=%u should be %d", |
| 331 | mToken, mIdentity, cblk->layers[mToken].identity); |
| 332 | return NO_INIT; |
| 333 | } |
| 334 | return NO_ERROR; |
| 335 | } |
| 336 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 337 | status_t SurfaceControl::writeSurfaceToParcel( |
| 338 | const sp<SurfaceControl>& control, Parcel* parcel) |
| 339 | { |
| 340 | uint32_t flags = 0; |
| 341 | uint32_t format = 0; |
| 342 | SurfaceID token = -1; |
| 343 | uint32_t identity = 0; |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 344 | uint32_t width = 0; |
| 345 | uint32_t height = 0; |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 346 | sp<SurfaceComposerClient> client; |
| 347 | sp<ISurface> sur; |
| 348 | if (SurfaceControl::isValid(control)) { |
| 349 | token = control->mToken; |
| 350 | identity = control->mIdentity; |
| 351 | client = control->mClient; |
| 352 | sur = control->mSurface; |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 353 | width = control->mWidth; |
| 354 | height = control->mHeight; |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 355 | format = control->mFormat; |
| 356 | flags = control->mFlags; |
| 357 | } |
| 358 | parcel->writeStrongBinder(client!=0 ? client->connection() : NULL); |
| 359 | parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL); |
| 360 | parcel->writeInt32(token); |
| 361 | parcel->writeInt32(identity); |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 362 | parcel->writeInt32(width); |
| 363 | parcel->writeInt32(height); |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 364 | parcel->writeInt32(format); |
| 365 | parcel->writeInt32(flags); |
| 366 | return NO_ERROR; |
| 367 | } |
| 368 | |
| 369 | sp<Surface> SurfaceControl::getSurface() const |
| 370 | { |
| 371 | Mutex::Autolock _l(mLock); |
| 372 | if (mSurfaceData == 0) { |
| 373 | mSurfaceData = new Surface(const_cast<SurfaceControl*>(this)); |
| 374 | } |
| 375 | return mSurfaceData; |
| 376 | } |
| 377 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 378 | // ============================================================================ |
| 379 | // Surface |
| 380 | // ============================================================================ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 382 | Surface::Surface(const sp<SurfaceControl>& surface) |
| 383 | : mClient(surface->mClient), mSurface(surface->mSurface), |
| 384 | mToken(surface->mToken), mIdentity(surface->mIdentity), |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 385 | mWidth(surface->mWidth), mHeight(surface->mHeight), |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 386 | mFormat(surface->mFormat), mFlags(surface->mFlags), |
| 387 | mBufferMapper(BufferMapper::get()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | { |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 389 | init(); |
| 390 | } |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 391 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 392 | Surface::Surface(const Parcel& parcel) |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 393 | : mBufferMapper(BufferMapper::get()) |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 394 | { |
| 395 | sp<IBinder> clientBinder = parcel.readStrongBinder(); |
| 396 | mSurface = interface_cast<ISurface>(parcel.readStrongBinder()); |
| 397 | mToken = parcel.readInt32(); |
| 398 | mIdentity = parcel.readInt32(); |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 399 | mWidth = parcel.readInt32(); |
| 400 | mHeight = parcel.readInt32(); |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 401 | mFormat = parcel.readInt32(); |
| 402 | mFlags = parcel.readInt32(); |
| 403 | |
| 404 | if (clientBinder != NULL) |
| 405 | mClient = SurfaceComposerClient::clientForConnection(clientBinder); |
| 406 | |
| 407 | init(); |
| 408 | } |
| 409 | |
| 410 | void Surface::init() |
| 411 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 412 | android_native_window_t::setSwapInterval = setSwapInterval; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 413 | android_native_window_t::dequeueBuffer = dequeueBuffer; |
| 414 | android_native_window_t::lockBuffer = lockBuffer; |
| 415 | android_native_window_t::queueBuffer = queueBuffer; |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 416 | android_native_window_t::query = query; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | mSwapRectangle.makeInvalid(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 418 | DisplayInfo dinfo; |
| 419 | SurfaceComposerClient::getDisplayInfo(0, &dinfo); |
| 420 | const_cast<float&>(android_native_window_t::xdpi) = dinfo.xdpi; |
| 421 | const_cast<float&>(android_native_window_t::ydpi) = dinfo.ydpi; |
| 422 | // FIXME: set real values here |
| 423 | const_cast<int&>(android_native_window_t::minSwapInterval) = 1; |
| 424 | const_cast<int&>(android_native_window_t::maxSwapInterval) = 1; |
| 425 | const_cast<uint32_t&>(android_native_window_t::flags) = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | Surface::~Surface() |
| 430 | { |
Mathias Agopian | 40b7f6e | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 431 | // this is a client-side operation, the surface is destroyed, unmap |
| 432 | // its buffers in this process. |
| 433 | for (int i=0 ; i<2 ; i++) { |
| 434 | if (mBuffers[i] != 0) { |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 435 | getBufferMapper().unregisterBuffer(mBuffers[i]->handle); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 436 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | } |
Mathias Agopian | 40b7f6e | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 438 | |
Mathias Agopian | 40b7f6e | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 439 | // clear all references and trigger an IPC now, to make sure things |
| 440 | // happen without delay, since these resources are quite heavy. |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | mClient.clear(); |
| 442 | mSurface.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | IPCThreadState::self()->flushCommands(); |
| 444 | } |
| 445 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 446 | status_t Surface::validate(per_client_cblk_t const* cblk) const |
| 447 | { |
Mathias Agopian | 40b7f6e | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 448 | if (mToken<0 || mClient==0) { |
| 449 | LOGE("invalid token (%d, identity=%u) or client (%p)", |
| 450 | mToken, mIdentity, mClient.get()); |
| 451 | return NO_INIT; |
| 452 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 453 | if (cblk == 0) { |
| 454 | LOGE("cblk is null (surface id=%d, identity=%u)", mToken, mIdentity); |
| 455 | return NO_INIT; |
| 456 | } |
| 457 | status_t err = cblk->validate(mToken); |
| 458 | if (err != NO_ERROR) { |
| 459 | LOGE("surface (id=%d, identity=%u) is invalid, err=%d (%s)", |
| 460 | mToken, mIdentity, err, strerror(-err)); |
| 461 | return err; |
| 462 | } |
| 463 | if (mIdentity != uint32_t(cblk->layers[mToken].identity)) { |
| 464 | LOGE("using an invalid surface id=%d, identity=%u should be %d", |
| 465 | mToken, mIdentity, cblk->layers[mToken].identity); |
| 466 | return NO_INIT; |
| 467 | } |
| 468 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 471 | |
| 472 | bool Surface::isSameSurface( |
| 473 | const sp<Surface>& lhs, const sp<Surface>& rhs) |
| 474 | { |
| 475 | if (lhs == 0 || rhs == 0) |
| 476 | return false; |
| 477 | return lhs->mSurface->asBinder() == rhs->mSurface->asBinder(); |
| 478 | } |
| 479 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 480 | // ---------------------------------------------------------------------------- |
| 481 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 482 | int Surface::setSwapInterval(android_native_window_t* window, int interval) |
| 483 | { |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | int Surface::dequeueBuffer(android_native_window_t* window, |
| 488 | android_native_buffer_t** buffer) |
| 489 | { |
| 490 | Surface* self = getSelf(window); |
| 491 | return self->dequeueBuffer(buffer); |
| 492 | } |
| 493 | |
| 494 | int Surface::lockBuffer(android_native_window_t* window, |
| 495 | android_native_buffer_t* buffer) |
| 496 | { |
| 497 | Surface* self = getSelf(window); |
| 498 | return self->lockBuffer(buffer); |
| 499 | } |
| 500 | |
| 501 | int Surface::queueBuffer(android_native_window_t* window, |
| 502 | android_native_buffer_t* buffer) |
| 503 | { |
| 504 | Surface* self = getSelf(window); |
| 505 | return self->queueBuffer(buffer); |
| 506 | } |
| 507 | |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 508 | int Surface::query(android_native_window_t* window, |
| 509 | int what, int* value) |
| 510 | { |
| 511 | Surface* self = getSelf(window); |
| 512 | return self->query(what, value); |
| 513 | } |
| 514 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 515 | // ---------------------------------------------------------------------------- |
| 516 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 517 | status_t Surface::dequeueBuffer(sp<SurfaceBuffer>* buffer) |
| 518 | { |
| 519 | android_native_buffer_t* out; |
| 520 | status_t err = dequeueBuffer(&out); |
| 521 | *buffer = SurfaceBuffer::getSelf(out); |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 522 | // reset the width/height with the what we get from the buffer |
| 523 | mWidth = uint32_t(out->width); |
| 524 | mHeight = uint32_t(out->height); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 525 | return err; |
| 526 | } |
| 527 | |
| 528 | status_t Surface::lockBuffer(const sp<SurfaceBuffer>& buffer) |
| 529 | { |
| 530 | return lockBuffer(buffer.get()); |
| 531 | } |
| 532 | |
| 533 | status_t Surface::queueBuffer(const sp<SurfaceBuffer>& buffer) |
| 534 | { |
| 535 | return queueBuffer(buffer.get()); |
| 536 | } |
| 537 | |
| 538 | // ---------------------------------------------------------------------------- |
| 539 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 540 | int Surface::dequeueBuffer(android_native_buffer_t** buffer) |
| 541 | { |
| 542 | // FIXME: dequeueBuffer() needs proper implementation |
| 543 | |
| 544 | Mutex::Autolock _l(mSurfaceLock); |
| 545 | |
| 546 | per_client_cblk_t* const cblk = mClient->mControl; |
| 547 | status_t err = validate(cblk); |
| 548 | if (err != NO_ERROR) |
| 549 | return err; |
| 550 | |
| 551 | SurfaceID index(mToken); |
| 552 | |
| 553 | int32_t backIdx = cblk->lock_layer(size_t(index), |
| 554 | per_client_cblk_t::BLOCKING); |
| 555 | |
| 556 | if (backIdx < 0) |
| 557 | return status_t(backIdx); |
| 558 | |
| 559 | mBackbufferIndex = backIdx; |
| 560 | layer_cblk_t* const lcblk = &(cblk->layers[index]); |
| 561 | |
| 562 | volatile const surface_info_t* const back = lcblk->surface + backIdx; |
| 563 | if (back->flags & surface_info_t::eNeedNewBuffer) { |
Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 564 | err = getBufferLocked(backIdx); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 567 | if (err == NO_ERROR) { |
| 568 | const sp<SurfaceBuffer>& backBuffer(mBuffers[backIdx]); |
| 569 | mDirtyRegion.set(backBuffer->width, backBuffer->height); |
| 570 | *buffer = backBuffer.get(); |
| 571 | } |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 572 | |
Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 573 | return err; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | int Surface::lockBuffer(android_native_buffer_t* buffer) |
| 577 | { |
Mathias Agopian | 40b7f6e | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 578 | Mutex::Autolock _l(mSurfaceLock); |
| 579 | |
| 580 | per_client_cblk_t* const cblk = mClient->mControl; |
| 581 | status_t err = validate(cblk); |
| 582 | if (err != NO_ERROR) |
| 583 | return err; |
| 584 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 585 | // FIXME: lockBuffer() needs proper implementation |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | int Surface::queueBuffer(android_native_buffer_t* buffer) |
| 590 | { |
| 591 | Mutex::Autolock _l(mSurfaceLock); |
| 592 | |
| 593 | per_client_cblk_t* const cblk = mClient->mControl; |
| 594 | status_t err = validate(cblk); |
| 595 | if (err != NO_ERROR) |
| 596 | return err; |
| 597 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 598 | if (mSwapRectangle.isValid()) { |
| 599 | mDirtyRegion.set(mSwapRectangle); |
| 600 | } |
| 601 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 602 | // transmit the dirty region |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 603 | SurfaceID index(mToken); |
| 604 | layer_cblk_t* const lcblk = &(cblk->layers[index]); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 605 | _send_dirty_region(lcblk, mDirtyRegion); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 606 | |
| 607 | uint32_t newstate = cblk->unlock_layer_and_post(size_t(index)); |
| 608 | if (!(newstate & eNextFlipPending)) |
| 609 | mClient->signalServer(); |
| 610 | |
| 611 | return NO_ERROR; |
| 612 | } |
| 613 | |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 614 | int Surface::query(int what, int* value) |
| 615 | { |
| 616 | switch (what) { |
| 617 | case NATIVE_WINDOW_WIDTH: |
| 618 | *value = int(mWidth); |
| 619 | return NO_ERROR; |
| 620 | case NATIVE_WINDOW_HEIGHT: |
| 621 | *value = int(mHeight); |
| 622 | return NO_ERROR; |
| 623 | } |
| 624 | return BAD_VALUE; |
| 625 | } |
| 626 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 627 | // ---------------------------------------------------------------------------- |
| 628 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | status_t Surface::lock(SurfaceInfo* info, bool blocking) { |
| 630 | return Surface::lock(info, NULL, blocking); |
| 631 | } |
| 632 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 633 | status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn, bool blocking) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 634 | { |
| 635 | // FIXME: needs some locking here |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 636 | |
| 637 | sp<SurfaceBuffer> backBuffer; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 638 | status_t err = dequeueBuffer(&backBuffer); |
| 639 | if (err == NO_ERROR) { |
| 640 | err = lockBuffer(backBuffer); |
| 641 | if (err == NO_ERROR) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 642 | // we handle copy-back here... |
| 643 | |
| 644 | const Rect bounds(backBuffer->width, backBuffer->height); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 645 | Region scratch(bounds); |
| 646 | Region& newDirtyRegion(dirtyIn ? *dirtyIn : scratch); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 647 | |
| 648 | per_client_cblk_t* const cblk = mClient->mControl; |
| 649 | layer_cblk_t* const lcblk = &(cblk->layers[SurfaceID(mToken)]); |
| 650 | volatile const surface_info_t* const back = lcblk->surface + mBackbufferIndex; |
| 651 | if (back->flags & surface_info_t::eBufferDirty) { |
| 652 | // content is meaningless in this case and the whole surface |
| 653 | // needs to be redrawn. |
| 654 | newDirtyRegion.set(bounds); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 655 | } else { |
| 656 | newDirtyRegion.andSelf(bounds); |
Mathias Agopian | 1499859 | 2009-07-13 18:29:59 -0700 | [diff] [blame] | 657 | const sp<SurfaceBuffer>& frontBuffer(mBuffers[1-mBackbufferIndex]); |
| 658 | if (backBuffer->width == frontBuffer->width && |
| 659 | backBuffer->height == frontBuffer->height && |
| 660 | !(lcblk->flags & eNoCopyBack)) |
| 661 | { |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 662 | const Region copyback(mOldDirtyRegion.subtract(newDirtyRegion)); |
| 663 | if (!copyback.isEmpty() && frontBuffer!=0) { |
| 664 | // copy front to back |
| 665 | copyBlt(backBuffer, frontBuffer, copyback); |
| 666 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 669 | mDirtyRegion = newDirtyRegion; |
| 670 | mOldDirtyRegion = newDirtyRegion; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 671 | |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 672 | void* vaddr; |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 673 | status_t res = backBuffer->lock( |
| 674 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 675 | newDirtyRegion.bounds(), &vaddr); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 676 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 677 | LOGW_IF(res, "failed locking buffer %d (%p)", |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 678 | mBackbufferIndex, backBuffer->handle); |
| 679 | |
| 680 | mLockedBuffer = backBuffer; |
| 681 | other->w = backBuffer->width; |
| 682 | other->h = backBuffer->height; |
| 683 | other->s = backBuffer->stride; |
| 684 | other->usage = backBuffer->usage; |
| 685 | other->format = backBuffer->format; |
Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 686 | other->bits = vaddr; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | return err; |
| 690 | } |
| 691 | |
| 692 | status_t Surface::unlockAndPost() |
| 693 | { |
| 694 | // FIXME: needs some locking here |
| 695 | |
| 696 | if (mLockedBuffer == 0) |
| 697 | return BAD_VALUE; |
| 698 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 699 | status_t res = mLockedBuffer->unlock(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 700 | LOGW_IF(res, "failed unlocking buffer %d (%p)", |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 701 | mBackbufferIndex, mLockedBuffer->handle); |
| 702 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 703 | status_t err = queueBuffer(mLockedBuffer); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 704 | mLockedBuffer = 0; |
| 705 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | } |
| 707 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 708 | void Surface::_send_dirty_region( |
| 709 | layer_cblk_t* lcblk, const Region& dirty) |
| 710 | { |
| 711 | const int32_t index = (lcblk->flags & eBufferIndex) >> eBufferIndexShift; |
| 712 | flat_region_t* flat_region = lcblk->region + index; |
| 713 | status_t err = dirty.write(flat_region, sizeof(flat_region_t)); |
| 714 | if (err < NO_ERROR) { |
| 715 | // region doesn't fit, use the bounds |
| 716 | const Region reg(dirty.bounds()); |
| 717 | reg.write(flat_region, sizeof(flat_region_t)); |
| 718 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | } |
| 720 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | void Surface::setSwapRectangle(const Rect& r) { |
| 722 | mSwapRectangle = r; |
| 723 | } |
| 724 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 725 | status_t Surface::getBufferLocked(int index) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 727 | status_t err = NO_MEMORY; |
| 728 | sp<SurfaceBuffer> buffer = mSurface->getBuffer(); |
| 729 | LOGE_IF(buffer==0, "ISurface::getBuffer() returned NULL"); |
| 730 | if (buffer != 0) { |
| 731 | sp<SurfaceBuffer>& currentBuffer(mBuffers[index]); |
| 732 | if (currentBuffer != 0) { |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 733 | getBufferMapper().unregisterBuffer(currentBuffer->handle); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 734 | currentBuffer.clear(); |
| 735 | } |
Mathias Agopian | 21c59d0 | 2009-05-05 00:59:23 -0700 | [diff] [blame] | 736 | err = getBufferMapper().registerBuffer(buffer->handle); |
Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 737 | LOGW_IF(err, "registerBuffer(...) failed %d (%s)", err, strerror(-err)); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 738 | if (err == NO_ERROR) { |
| 739 | currentBuffer = buffer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | } |
| 741 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 742 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | }; // namespace android |
| 746 | |