diff options
Diffstat (limited to 'Source/WebCore')
-rw-r--r-- | Source/WebCore/platform/graphics/android/TransferQueue.cpp | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/Source/WebCore/platform/graphics/android/TransferQueue.cpp b/Source/WebCore/platform/graphics/android/TransferQueue.cpp index a6b2e26..d84033c 100644 --- a/Source/WebCore/platform/graphics/android/TransferQueue.cpp +++ b/Source/WebCore/platform/graphics/android/TransferQueue.cpp @@ -52,6 +52,10 @@ #define ST_BUFFER_NUMBER 4 +// Set this to 1 if we would like to take the new GpuUpload approach which +// relied on the glCopyTexSubImage2D instead of a glDraw call +#define GPU_UPLOAD_WITHOUT_DRAW 0 + namespace WebCore { TransferQueue::TransferQueue() @@ -86,7 +90,11 @@ void TransferQueue::initSharedSurfaceTextures(int width, int height) if (!m_sharedSurfaceTextureId) { glGenTextures(1, &m_sharedSurfaceTextureId); m_sharedSurfaceTexture = +#if GPU_UPLOAD_WITHOUT_DRAW + new android::SurfaceTexture(m_sharedSurfaceTextureId, true, GL_TEXTURE_2D); +#else new android::SurfaceTexture(m_sharedSurfaceTextureId); +#endif m_ANW = new android::SurfaceTextureClient(m_sharedSurfaceTexture); m_sharedSurfaceTexture->setSynchronousMode(true); m_sharedSurfaceTexture->setBufferCount(ST_BUFFER_NUMBER+1); @@ -137,6 +145,18 @@ void TransferQueue::blitTileFromQueue(GLuint fboID, BaseTileTexture* destTex, GLuint srcTexId, GLenum srcTexTarget, int index) { +#if GPU_UPLOAD_WITHOUT_DRAW + glBindFramebuffer(GL_FRAMEBUFFER, fboID); + glFramebufferTexture2D(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + srcTexId, + 0); + glBindTexture(GL_TEXTURE_2D, destTex->m_ownTextureId); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, + destTex->getSize().width(), + destTex->getSize().height()); +#else // Then set up the FBO and copy the SurfTex content in. glBindFramebuffer(GL_FRAMEBUFFER, fboID); glFramebufferTexture2D(GL_FRAMEBUFFER, @@ -174,10 +194,7 @@ void TransferQueue::blitTileFromQueue(GLuint fboID, BaseTileTexture* destTex, 0); } GLUtils::checkEglError("CreateSyncKHR"); - // Clean up FBO setup. - glBindFramebuffer(GL_FRAMEBUFFER, 0); // rebind the standard FBO - - GLUtils::checkGlError("copy the surface texture into the normal one"); +#endif } void TransferQueue::interruptTransferQueue(bool interrupt) @@ -261,8 +278,6 @@ void TransferQueue::discardQueue() // Call on UI thread to copy from the shared Surface Texture to the BaseTile's texture. void TransferQueue::updateDirtyBaseTiles() { - if (m_currentUploadType == GpuUpload) - saveGLState(); android::Mutex::Autolock lock(m_transferQueueItemLocks); cleanupTransportQueue(); @@ -273,6 +288,7 @@ void TransferQueue::updateDirtyBaseTiles() // the texture and blit that into each BaseTile's texture. const int nextItemIndex = getNextTransferQueueIndex(); int index = nextItemIndex; + bool usedFboForUpload = false; for (int k = 0; k < ST_BUFFER_NUMBER ; k++) { if (m_transferQueue[index].status == pendingBlit) { bool obsoleteBaseTile = checkObsolete(index); @@ -299,6 +315,10 @@ void TransferQueue::updateDirtyBaseTiles() GLUtils::updateTextureWithBitmap(destTexture->m_ownTextureId, 0, 0, *m_transferQueue[index].bitmap); } else { + if (!usedFboForUpload) { + saveGLState(); + usedFboForUpload = true; + } blitTileFromQueue(m_fboID, destTexture, m_sharedSurfaceTextureId, m_sharedSurfaceTexture->getCurrentTextureTarget(), @@ -321,8 +341,14 @@ void TransferQueue::updateDirtyBaseTiles() index = (index + 1) % ST_BUFFER_NUMBER; } - if (m_currentUploadType == GpuUpload) + // Clean up FBO setup. Doing this for both CPU/GPU upload can make the + // dynamic switch possible. Moving this out from the loop can save some + // milli-seconds. + if (usedFboForUpload) { + glBindFramebuffer(GL_FRAMEBUFFER, 0); // rebind the standard FBO restoreGLState(); + GLUtils::checkGlError("updateDirtyBaseTiles"); + } m_emptyItemCount = ST_BUFFER_NUMBER; m_transferQueueItemCond.signal(); @@ -462,7 +488,9 @@ void TransferQueue::saveGLState() glGetIntegerv(GL_VIEWPORT, m_GLStateBeforeBlit.viewport); glGetBooleanv(GL_SCISSOR_TEST, m_GLStateBeforeBlit.scissor); glGetBooleanv(GL_DEPTH_TEST, m_GLStateBeforeBlit.depth); +#if DEBUG glGetFloatv(GL_COLOR_CLEAR_VALUE, m_GLStateBeforeBlit.clearColor); +#endif } void TransferQueue::setGLStateForCopy(int width, int height) @@ -471,9 +499,11 @@ void TransferQueue::setGLStateForCopy(int width, int height) glViewport(0, 0, width, height); glDisable(GL_SCISSOR_TEST); glDisable(GL_DEPTH_TEST); - + // Clear the content is only for debug purpose. +#if DEBUG glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); +#endif } void TransferQueue::restoreGLState() @@ -488,11 +518,12 @@ void TransferQueue::restoreGLState() if (m_GLStateBeforeBlit.depth[0]) glEnable(GL_DEPTH_TEST); - +#if DEBUG glClearColor(m_GLStateBeforeBlit.clearColor[0], m_GLStateBeforeBlit.clearColor[1], m_GLStateBeforeBlit.clearColor[2], m_GLStateBeforeBlit.clearColor[3]); +#endif } int TransferQueue::getNextTransferQueueIndex() |