From f0e3a5c2ed05701bffd2e85c8c87337a9f5d2d52 Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Wed, 17 Aug 2011 14:55:16 -0700 Subject: refactor the nativeWindow handling in TransferQueue bug:5161750 Change-Id: I33735f258abf850fa3afd7769385b38691365da3 --- .../platform/graphics/android/TransferQueue.cpp | 64 +++++++++------------- 1 file changed, 26 insertions(+), 38 deletions(-) (limited to 'Source/WebCore/platform/graphics/android/TransferQueue.cpp') diff --git a/Source/WebCore/platform/graphics/android/TransferQueue.cpp b/Source/WebCore/platform/graphics/android/TransferQueue.cpp index 1a377f2..8b4b596 100644 --- a/Source/WebCore/platform/graphics/android/TransferQueue.cpp +++ b/Source/WebCore/platform/graphics/android/TransferQueue.cpp @@ -297,50 +297,38 @@ void TransferQueue::updateQueueWithBitmap(const TileRenderInfo* renderInfo, renderInfo->x, renderInfo->y); return; } - // Dequeue the Surface Texture. - sp ANW = m_ANW; - if (!ANW.get()) { + + // a) Dequeue the Surface Texture and write into the buffer + if (!m_ANW.get()) { XLOG("ERROR: ANW is null"); return; } - ANativeWindowBuffer* anb; - - int status = ANW->dequeueBuffer(ANW.get(), &anb); - GLUtils::checkSurfaceTextureError("dequeueBuffer", status); - // a) Update surface texture - sp buf(new android::GraphicBuffer(anb, false)); - status |= ANW->lockBuffer(ANW.get(), buf->getNativeBuffer()); // Mutex Lock - GLUtils::checkSurfaceTextureError("lockBuffer", status); - - // Fill the buffer with the content of the bitmap - uint8_t* img = 0; - status |= buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img)); - GLUtils::checkSurfaceTextureError("lock", status); - - if (status == NO_ERROR) { - int row, col; - int bpp = 4; // Now we only deal with RGBA8888 format. - int width = TilesManager::instance()->tileWidth(); - int height = TilesManager::instance()->tileHeight(); - if (!x && !y && bitmap.width() == width && bitmap.height() == height) { - bitmap.lockPixels(); - uint8_t* bitmapOrigin = static_cast(bitmap.getPixels()); - // Copied line by line since we need to handle the offsets and stride. - for (row = 0 ; row < bitmap.height(); row ++) { - uint8_t* dst = &(img[(buf->getStride() * (row + x) + y) * bpp]); - uint8_t* src = &(bitmapOrigin[bitmap.width() * row * bpp]); - memcpy(dst, src, bpp * bitmap.width()); - } - bitmap.unlockPixels(); - } else { - // TODO: implement the partial invalidate here! - XLOG("ERROR: don't expect to get here yet before we support partial inval"); + + ANativeWindow_Buffer buffer; + if (ANativeWindow_lock(m_ANW.get(), &buffer, 0)) + return; + + uint8_t* img = (uint8_t*)buffer.bits; + int row, col; + int bpp = 4; // Now we only deal with RGBA8888 format. + int width = TilesManager::instance()->tileWidth(); + int height = TilesManager::instance()->tileHeight(); + if (!x && !y && bitmap.width() == width && bitmap.height() == height) { + bitmap.lockPixels(); + uint8_t* bitmapOrigin = static_cast(bitmap.getPixels()); + // Copied line by line since we need to handle the offsets and stride. + for (row = 0 ; row < bitmap.height(); row ++) { + uint8_t* dst = &(img[(buffer.stride * (row + x) + y) * bpp]); + uint8_t* src = &(bitmapOrigin[bitmap.width() * row * bpp]); + memcpy(dst, src, bpp * bitmap.width()); } + bitmap.unlockPixels(); + } else { + // TODO: implement the partial invalidate here! + XLOG("ERROR: don't expect to get here yet before we support partial inval"); } - buf->unlock(); - status = ANW->queueBuffer(ANW.get(), buf->getNativeBuffer()); - GLUtils::checkSurfaceTextureError("queueBuffer", status); + ANativeWindow_unlockAndPost(m_ANW.get()); // b) After update the Surface Texture, now udpate the transfer queue info. addItemInTransferQueue(renderInfo); -- cgit v1.1