diff options
Diffstat (limited to 'libs/ui')
-rw-r--r-- | libs/ui/Android.mk | 5 | ||||
-rw-r--r-- | libs/ui/GraphicBuffer.cpp | 213 | ||||
-rw-r--r-- | libs/ui/GraphicBufferAllocator.cpp | 129 | ||||
-rw-r--r-- | libs/ui/GraphicBufferMapper.cpp (renamed from libs/ui/BufferMapper.cpp) | 16 | ||||
-rw-r--r-- | libs/ui/ISurface.cpp | 10 | ||||
-rw-r--r-- | libs/ui/Surface.cpp | 30 | ||||
-rw-r--r-- | libs/ui/SurfaceBuffer.cpp | 134 |
7 files changed, 373 insertions, 164 deletions
diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk index 9577044..73d86ea 100644 --- a/libs/ui/Android.mk +++ b/libs/ui/Android.mk @@ -2,13 +2,15 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - BufferMapper.cpp \ Camera.cpp \ CameraParameters.cpp \ EGLUtils.cpp \ EventHub.cpp \ EventRecurrence.cpp \ FramebufferNativeWindow.cpp \ + GraphicBuffer.cpp \ + GraphicBufferAllocator.cpp \ + GraphicBufferMapper.cpp \ KeyLayoutMap.cpp \ KeyCharacterMap.cpp \ ICamera.cpp \ @@ -25,7 +27,6 @@ LOCAL_SRC_FILES:= \ Region.cpp \ SharedBufferStack.cpp \ Surface.cpp \ - SurfaceBuffer.cpp \ SurfaceComposerClient.cpp \ SurfaceFlingerSynchro.cpp diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp new file mode 100644 index 0000000..1cf20d7 --- /dev/null +++ b/libs/ui/GraphicBuffer.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> + +#include <binder/Parcel.h> + +#include <utils/Errors.h> +#include <utils/Log.h> + +#include <ui/GraphicBuffer.h> +#include <ui/GraphicBufferAllocator.h> +#include <ui/GraphicBufferMapper.h> +#include <ui/PixelFormat.h> + +#include <pixelflinger/pixelflinger.h> + +namespace android { + +// =========================================================================== +// Buffer and implementation of android_native_buffer_t +// =========================================================================== + +GraphicBuffer::GraphicBuffer() + : BASE(), mOwner(false), mBufferMapper(GraphicBufferMapper::get()), + mInitCheck(NO_ERROR), mVStride(0), mIndex(-1) +{ + width = + height = + stride = + format = + usage = 0; + handle = NULL; +} + +GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h, + PixelFormat reqFormat, uint32_t reqUsage) + : BASE(), mOwner(false), mBufferMapper(GraphicBufferMapper::get()), + mInitCheck(NO_ERROR), mVStride(0), mIndex(-1) +{ + width = + height = + stride = + format = + usage = 0; + handle = NULL; + mInitCheck = initSize(w, h, reqFormat, reqUsage); +} + +GraphicBuffer::GraphicBuffer(const Parcel& data) + : BASE(), mOwner(true), mBufferMapper(GraphicBufferMapper::get()), + mInitCheck(NO_ERROR), mVStride(0), mIndex(-1) +{ + // we own the handle in this case + width = data.readInt32(); + if (width < 0) { + width = height = stride = format = usage = 0; + handle = 0; + } else { + height = data.readInt32(); + stride = data.readInt32(); + format = data.readInt32(); + usage = data.readInt32(); + handle = data.readNativeHandle(); + } +} + +GraphicBuffer::~GraphicBuffer() +{ + if (handle) { + if (mOwner) { + native_handle_close(handle); + native_handle_delete(const_cast<native_handle*>(handle)); + } else { + GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); + allocator.free(handle); + } + } +} + +status_t GraphicBuffer::initCheck() const { + return mInitCheck; +} + +android_native_buffer_t* GraphicBuffer::getNativeBuffer() const +{ + return static_cast<android_native_buffer_t*>( + const_cast<GraphicBuffer*>(this)); +} + +status_t GraphicBuffer::reallocate(uint32_t w, uint32_t h, PixelFormat f, + uint32_t reqUsage) +{ + if (handle) { + GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); + allocator.free(handle); + handle = 0; + } + return initSize(w, h, f, reqUsage); +} + +status_t GraphicBuffer::initSize(uint32_t w, uint32_t h, PixelFormat format, + uint32_t reqUsage) +{ + if (format == PIXEL_FORMAT_RGBX_8888) + format = PIXEL_FORMAT_RGBA_8888; + + GraphicBufferAllocator& allocator = GraphicBufferAllocator::get(); + status_t err = allocator.alloc(w, h, format, reqUsage, &handle, &stride); + if (err == NO_ERROR) { + this->width = w; + this->height = h; + this->format = format; + this->usage = reqUsage; + mVStride = 0; + } + return err; +} + +status_t GraphicBuffer::lock(uint32_t usage, void** vaddr) +{ + const Rect lockBounds(width, height); + status_t res = lock(usage, lockBounds, vaddr); + return res; +} + +status_t GraphicBuffer::lock(uint32_t usage, const Rect& rect, void** vaddr) +{ + if (rect.left < 0 || rect.right > this->width || + rect.top < 0 || rect.bottom > this->height) { + LOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", + rect.left, rect.top, rect.right, rect.bottom, + this->width, this->height); + return BAD_VALUE; + } + status_t res = getBufferMapper().lock(handle, usage, rect, vaddr); + return res; +} + +status_t GraphicBuffer::unlock() +{ + status_t res = getBufferMapper().unlock(handle); + return res; +} + +status_t GraphicBuffer::lock(GGLSurface* sur, uint32_t usage) +{ + void* vaddr; + status_t res = GraphicBuffer::lock(usage, &vaddr); + if (res == NO_ERROR && sur) { + sur->version = sizeof(GGLSurface); + sur->width = width; + sur->height = height; + sur->stride = stride; + sur->format = format; + sur->vstride = mVStride; + sur->data = static_cast<GGLubyte*>(vaddr); + } + return res; +} + + +status_t GraphicBuffer::writeToParcel(Parcel* reply, + android_native_buffer_t const* buffer) +{ + if (buffer == NULL) + return BAD_VALUE; + + if (buffer->width < 0 || buffer->height < 0) + return BAD_VALUE; + + status_t err = NO_ERROR; + if (buffer->handle == NULL) { + // this buffer doesn't have a handle + reply->writeInt32(NO_MEMORY); + } else { + reply->writeInt32(buffer->width); + reply->writeInt32(buffer->height); + reply->writeInt32(buffer->stride); + reply->writeInt32(buffer->format); + reply->writeInt32(buffer->usage); + err = reply->writeNativeHandle(buffer->handle); + } + return err; +} + + +void GraphicBuffer::setIndex(int index) { + mIndex = index; +} + +int GraphicBuffer::getIndex() const { + return mIndex; +} + +// --------------------------------------------------------------------------- + +}; // namespace android diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp new file mode 100644 index 0000000..10b1051 --- /dev/null +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -0,0 +1,129 @@ +/* +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#include <cutils/log.h> + +#include <utils/Singleton.h> +#include <utils/String8.h> + +#include <ui/GraphicBufferAllocator.h> + + +namespace android { +// --------------------------------------------------------------------------- + +ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator ) + +Mutex GraphicBufferAllocator::sLock; +KeyedVector<buffer_handle_t, GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList; + +GraphicBufferAllocator::GraphicBufferAllocator() + : mAllocDev(0) +{ + hw_module_t const* module; + int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); + LOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); + if (err == 0) { + gralloc_open(module, &mAllocDev); + } +} + +GraphicBufferAllocator::~GraphicBufferAllocator() +{ + gralloc_close(mAllocDev); +} + +void GraphicBufferAllocator::dump(String8& result) const +{ + Mutex::Autolock _l(sLock); + KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); + size_t total = 0; + const size_t SIZE = 512; + char buffer[SIZE]; + snprintf(buffer, SIZE, "Allocated buffers:\n"); + result.append(buffer); + const size_t c = list.size(); + for (size_t i=0 ; i<c ; i++) { + const alloc_rec_t& rec(list.valueAt(i)); + snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u x %4u | %2d | 0x%08x\n", + list.keyAt(i), rec.size/1024.0f, + rec.w, rec.h, rec.format, rec.usage); + result.append(buffer); + total += rec.size; + } + snprintf(buffer, SIZE, "Total allocated: %.2f KB\n", total/1024.0f); + result.append(buffer); +} + +static inline uint32_t clamp(uint32_t c) { + return c>0 ? c : 1; +} + +status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat format, + int usage, buffer_handle_t* handle, int32_t* stride) +{ + Mutex::Autolock _l(mLock); + + // make sure to not allocate a 0 x 0 buffer + w = clamp(w); + h = clamp(h); + + // we have a h/w allocator and h/w buffer is requested + status_t err = mAllocDev->alloc(mAllocDev, + w, h, format, usage, handle, stride); + + LOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)", + w, h, format, usage, err, strerror(-err)); + + if (err == NO_ERROR) { + Mutex::Autolock _l(sLock); + KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); + alloc_rec_t rec; + rec.w = w; + rec.h = h; + rec.format = format; + rec.usage = usage; + rec.vaddr = 0; + rec.size = h * stride[0] * bytesPerPixel(format); + list.add(*handle, rec); + } else { + String8 s; + dump(s); + LOGD("%s", s.string()); + } + + return err; +} + +status_t GraphicBufferAllocator::free(buffer_handle_t handle) +{ + Mutex::Autolock _l(mLock); + + status_t err = mAllocDev->free(mAllocDev, handle); + LOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err)); + + if (err == NO_ERROR) { + Mutex::Autolock _l(sLock); + KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); + list.removeItem(handle); + } + + return err; +} + +// --------------------------------------------------------------------------- +}; // namespace android diff --git a/libs/ui/BufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 4add8f9..dd529e6 100644 --- a/libs/ui/BufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "BufferMapper" +#define LOG_TAG "GraphicBufferMapper" #include <stdint.h> #include <errno.h> @@ -22,7 +22,7 @@ #include <utils/Errors.h> #include <utils/Log.h> -#include <ui/BufferMapper.h> +#include <ui/GraphicBufferMapper.h> #include <ui/Rect.h> #include <hardware/gralloc.h> @@ -31,9 +31,9 @@ namespace android { // --------------------------------------------------------------------------- -ANDROID_SINGLETON_STATIC_INSTANCE( BufferMapper ) +ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) -BufferMapper::BufferMapper() +GraphicBufferMapper::GraphicBufferMapper() : mAllocMod(0) { hw_module_t const* module; @@ -44,7 +44,7 @@ BufferMapper::BufferMapper() } } -status_t BufferMapper::registerBuffer(buffer_handle_t handle) +status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle) { status_t err = mAllocMod->registerBuffer(mAllocMod, handle); LOGW_IF(err, "registerBuffer(%p) failed %d (%s)", @@ -52,7 +52,7 @@ status_t BufferMapper::registerBuffer(buffer_handle_t handle) return err; } -status_t BufferMapper::unregisterBuffer(buffer_handle_t handle) +status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle) { status_t err = mAllocMod->unregisterBuffer(mAllocMod, handle); LOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)", @@ -60,7 +60,7 @@ status_t BufferMapper::unregisterBuffer(buffer_handle_t handle) return err; } -status_t BufferMapper::lock(buffer_handle_t handle, +status_t GraphicBufferMapper::lock(buffer_handle_t handle, int usage, const Rect& bounds, void** vaddr) { status_t err = mAllocMod->lock(mAllocMod, handle, usage, @@ -69,7 +69,7 @@ status_t BufferMapper::lock(buffer_handle_t handle, return err; } -status_t BufferMapper::unlock(buffer_handle_t handle) +status_t GraphicBufferMapper::unlock(buffer_handle_t handle) { status_t err = mAllocMod->unlock(mAllocMod, handle); LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); diff --git a/libs/ui/ISurface.cpp b/libs/ui/ISurface.cpp index a2dbe7f..4fb38ed 100644 --- a/libs/ui/ISurface.cpp +++ b/libs/ui/ISurface.cpp @@ -27,7 +27,7 @@ #include <ui/Overlay.h> #include <ui/Surface.h> -#include <private/ui/SurfaceBuffer.h> +#include <ui/GraphicBuffer.h> namespace android { @@ -71,14 +71,14 @@ public: { } - virtual sp<SurfaceBuffer> requestBuffer(int bufferIdx, int usage) + virtual sp<GraphicBuffer> requestBuffer(int bufferIdx, int usage) { Parcel data, reply; data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); data.writeInt32(bufferIdx); data.writeInt32(usage); remote()->transact(REQUEST_BUFFER, data, &reply); - sp<SurfaceBuffer> buffer = new SurfaceBuffer(reply); + sp<GraphicBuffer> buffer = new GraphicBuffer(reply); return buffer; } @@ -139,8 +139,8 @@ status_t BnSurface::onTransact( CHECK_INTERFACE(ISurface, data, reply); int bufferIdx = data.readInt32(); int usage = data.readInt32(); - sp<SurfaceBuffer> buffer(requestBuffer(bufferIdx, usage)); - return SurfaceBuffer::writeToParcel(reply, buffer.get()); + sp<GraphicBuffer> buffer(requestBuffer(bufferIdx, usage)); + return GraphicBuffer::writeToParcel(reply, buffer.get()); } case REGISTER_BUFFERS: { CHECK_INTERFACE(ISurface, data, reply); diff --git a/libs/ui/Surface.cpp b/libs/ui/Surface.cpp index 285edb4..7822533 100644 --- a/libs/ui/Surface.cpp +++ b/libs/ui/Surface.cpp @@ -31,7 +31,8 @@ #include <utils/Log.h> #include <ui/DisplayInfo.h> -#include <ui/BufferMapper.h> +#include <ui/GraphicBuffer.h> +#include <ui/GraphicBufferMapper.h> #include <ui/ISurface.h> #include <ui/Surface.h> #include <ui/SurfaceComposerClient.h> @@ -41,15 +42,14 @@ #include <private/ui/SharedBufferStack.h> #include <private/ui/LayerState.h> -#include <private/ui/SurfaceBuffer.h> namespace android { // ---------------------------------------------------------------------- static status_t copyBlt( - const sp<SurfaceBuffer>& dst, - const sp<SurfaceBuffer>& src, + const sp<GraphicBuffer>& dst, + const sp<GraphicBuffer>& src, const Region& reg) { status_t err; @@ -310,7 +310,7 @@ Surface::Surface(const sp<SurfaceControl>& surface) : mClient(surface->mClient), mSurface(surface->mSurface), mToken(surface->mToken), mIdentity(surface->mIdentity), mFormat(surface->mFormat), mFlags(surface->mFlags), - mBufferMapper(BufferMapper::get()), mSharedBufferClient(NULL), + mBufferMapper(GraphicBufferMapper::get()), mSharedBufferClient(NULL), mWidth(surface->mWidth), mHeight(surface->mHeight) { mSharedBufferClient = new SharedBufferClient( @@ -320,7 +320,7 @@ Surface::Surface(const sp<SurfaceControl>& surface) } Surface::Surface(const Parcel& parcel) - : mBufferMapper(BufferMapper::get()), mSharedBufferClient(NULL) + : mBufferMapper(GraphicBufferMapper::get()), mSharedBufferClient(NULL) { sp<IBinder> clientBinder = parcel.readStrongBinder(); mSurface = interface_cast<ISurface>(parcel.readStrongBinder()); @@ -473,11 +473,11 @@ int Surface::perform(android_native_window_t* window, // ---------------------------------------------------------------------------- -status_t Surface::dequeueBuffer(sp<SurfaceBuffer>* buffer) { +status_t Surface::dequeueBuffer(sp<GraphicBuffer>* buffer) { android_native_buffer_t* out; status_t err = dequeueBuffer(&out); if (err == NO_ERROR) { - *buffer = SurfaceBuffer::getSelf(out); + *buffer = GraphicBuffer::getSelf(out); } return err; } @@ -500,7 +500,7 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer) // below we make sure we AT LEAST have the usage flags we want const uint32_t usage(getUsage()); - const sp<SurfaceBuffer>& backBuffer(mBuffers[bufIdx]); + const sp<GraphicBuffer>& backBuffer(mBuffers[bufIdx]); if (backBuffer == 0 || ((uint32_t(backBuffer->usage) & usage) != usage) || mSharedBufferClient->needNewBuffer(bufIdx)) @@ -537,7 +537,7 @@ int Surface::lockBuffer(android_native_buffer_t* buffer) if (err != NO_ERROR) return err; - int32_t bufIdx = SurfaceBuffer::getSelf(buffer)->getIndex(); + int32_t bufIdx = GraphicBuffer::getSelf(buffer)->getIndex(); err = mSharedBufferClient->lock(bufIdx); LOGE_IF(err, "error locking buffer %d (%s)", bufIdx, strerror(-err)); return err; @@ -554,7 +554,7 @@ int Surface::queueBuffer(android_native_buffer_t* buffer) mDirtyRegion.set(mSwapRectangle); } - int32_t bufIdx = SurfaceBuffer::getSelf(buffer)->getIndex(); + int32_t bufIdx = GraphicBuffer::getSelf(buffer)->getIndex(); mSharedBufferClient->setDirtyRegion(bufIdx, mDirtyRegion); err = mSharedBufferClient->queue(bufIdx); LOGE_IF(err, "error queuing buffer %d (%s)", bufIdx, strerror(-err)); @@ -627,7 +627,7 @@ status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn, bool blocking) // we're intending to do software rendering from this point setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); - sp<SurfaceBuffer> backBuffer; + sp<GraphicBuffer> backBuffer; status_t err = dequeueBuffer(&backBuffer); LOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err)); if (err == NO_ERROR) { @@ -652,7 +652,7 @@ status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn, bool blocking) newDirtyRegion.andSelf(bounds); } - const sp<SurfaceBuffer>& frontBuffer(mPostedBuffer); + const sp<GraphicBuffer>& frontBuffer(mPostedBuffer); if (frontBuffer !=0 && backBuffer->width == frontBuffer->width && backBuffer->height == frontBuffer->height && @@ -721,13 +721,13 @@ status_t Surface::getBufferLocked(int index, int usage) status_t err = NO_MEMORY; // free the current buffer - sp<SurfaceBuffer>& currentBuffer(mBuffers[index]); + sp<GraphicBuffer>& currentBuffer(mBuffers[index]); if (currentBuffer != 0) { getBufferMapper().unregisterBuffer(currentBuffer->handle); currentBuffer.clear(); } - sp<SurfaceBuffer> buffer = s->requestBuffer(index, usage); + sp<GraphicBuffer> buffer = s->requestBuffer(index, usage); LOGE_IF(buffer==0, "ISurface::getBuffer(%d, %08x) returned NULL", index, usage); diff --git a/libs/ui/SurfaceBuffer.cpp b/libs/ui/SurfaceBuffer.cpp deleted file mode 100644 index 0510bc1..0000000 --- a/libs/ui/SurfaceBuffer.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "SurfaceBuffer" - -#include <stdint.h> -#include <errno.h> -#include <sys/types.h> - -#include <utils/Errors.h> -#include <utils/Log.h> -#include <binder/Parcel.h> - -#include <ui/BufferMapper.h> -#include <ui/Rect.h> -#include <private/ui/SurfaceBuffer.h> - -namespace android { - -// ============================================================================ -// SurfaceBuffer -// ============================================================================ - -SurfaceBuffer::SurfaceBuffer() - : BASE(), mOwner(false), mBufferMapper(BufferMapper::get()), mIndex(-1) -{ - width = - height = - stride = - format = - usage = 0; - handle = NULL; -} - -SurfaceBuffer::SurfaceBuffer(const Parcel& data) - : BASE(), mOwner(true), mBufferMapper(BufferMapper::get()) -{ - // we own the handle in this case - width = data.readInt32(); - if (width < 0) { - width = height = stride = format = usage = 0; - handle = 0; - } else { - height = data.readInt32(); - stride = data.readInt32(); - format = data.readInt32(); - usage = data.readInt32(); - handle = data.readNativeHandle(); - } -} - -SurfaceBuffer::~SurfaceBuffer() -{ - if (handle && mOwner) { - native_handle_close(handle); - native_handle_delete(const_cast<native_handle*>(handle)); - } -} - -status_t SurfaceBuffer::lock(uint32_t usage, void** vaddr) -{ - const Rect lockBounds(width, height); - status_t res = lock(usage, lockBounds, vaddr); - return res; -} - -status_t SurfaceBuffer::lock(uint32_t usage, const Rect& rect, void** vaddr) -{ - if (rect.left < 0 || rect.right > this->width || - rect.top < 0 || rect.bottom > this->height) { - LOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", - rect.left, rect.top, rect.right, rect.bottom, - this->width, this->height); - return BAD_VALUE; - } - status_t res = getBufferMapper().lock(handle, usage, rect, vaddr); - return res; -} - -status_t SurfaceBuffer::unlock() -{ - status_t res = getBufferMapper().unlock(handle); - return res; -} - -status_t SurfaceBuffer::writeToParcel(Parcel* reply, - android_native_buffer_t const* buffer) -{ - if (buffer == NULL) - return BAD_VALUE; - - if (buffer->width < 0 || buffer->height < 0) - return BAD_VALUE; - - status_t err = NO_ERROR; - if (buffer->handle == NULL) { - // this buffer doesn't have a handle - reply->writeInt32(NO_MEMORY); - } else { - reply->writeInt32(buffer->width); - reply->writeInt32(buffer->height); - reply->writeInt32(buffer->stride); - reply->writeInt32(buffer->format); - reply->writeInt32(buffer->usage); - err = reply->writeNativeHandle(buffer->handle); - } - return err; -} - - -void SurfaceBuffer::setIndex(int index) { - mIndex = index; -} - -int SurfaceBuffer::getIndex() const { - return mIndex; -} - - -}; // namespace android - |