From 14dce8b6d509dce296d15935cd71468b4f4453ba Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Mon, 16 Apr 2012 17:06:14 +0000 Subject: [PATCH] Update GraphicsContext3DOpenGLES.cpp and fix some issues to build with GLES. https://bugs.webkit.org/show_bug.cgi?id=83982 Patch by ChangSeok Oh on 2012-04-16 Reviewed by Martin Robinson. GL_BGRA is not defined in GLESv2, so it causes build-break at readRenderingResults. To resolve this, a helper function readPixelsAndConvertToBGRAIfNecessary is added in GC3DOpenGL.cpp & GC3DOpenGLES.cpp and it's used in GC3DOpenGLCommon.cpp. And some other issues to build with GLES are gone with this patch. No new tests, since no new feature. * platform/graphics/GraphicsContext3D.h: * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp: (WebCore::GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary): (WebCore): * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::GraphicsContext3D::readRenderingResults): * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp: (WebCore::GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary): (WebCore): (WebCore::GraphicsContext3D::reshapeFBOs): (WebCore::GraphicsContext3D::resolveMultisamplingIfNecessary): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114268 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 26 ++++++++++++++++++++++ .../WebCore/platform/graphics/GraphicsContext3D.h | 1 + .../graphics/opengl/GraphicsContext3DOpenGL.cpp | 5 +++++ .../opengl/GraphicsContext3DOpenGLCommon.cpp | 9 ++------ .../graphics/opengl/GraphicsContext3DOpenGLES.cpp | 19 ++++++++++++---- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index ee4d3c8..0503aa8 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,29 @@ +2012-04-16 ChangSeok Oh + + Update GraphicsContext3DOpenGLES.cpp and fix some issues to build with GLES. + https://bugs.webkit.org/show_bug.cgi?id=83982 + + Reviewed by Martin Robinson. + + GL_BGRA is not defined in GLESv2, so it causes build-break at readRenderingResults. + To resolve this, a helper function readPixelsAndConvertToBGRAIfNecessary is added + in GC3DOpenGL.cpp & GC3DOpenGLES.cpp and it's used in GC3DOpenGLCommon.cpp. + And some other issues to build with GLES are gone with this patch. + + No new tests, since no new feature. + + * platform/graphics/GraphicsContext3D.h: + * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp: + (WebCore::GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary): + (WebCore): + * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: + (WebCore::GraphicsContext3D::readRenderingResults): + * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp: + (WebCore::GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary): + (WebCore): + (WebCore::GraphicsContext3D::reshapeFBOs): + (WebCore::GraphicsContext3D::resolveMultisamplingIfNecessary): + 2012-04-16 Xiaomei Ji [chromium] wrong justification for arabic/persian page in cr-win. diff --git a/Source/WebCore/platform/graphics/GraphicsContext3D.h b/Source/WebCore/platform/graphics/GraphicsContext3D.h index c2293e4..2ab07ab 100644 --- a/Source/WebCore/platform/graphics/GraphicsContext3D.h +++ b/Source/WebCore/platform/graphics/GraphicsContext3D.h @@ -907,6 +907,7 @@ public: // Read rendering results into a pixel array with the same format as the // backbuffer. void readRenderingResults(unsigned char* pixels, int pixelsSize); + void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels); #endif bool reshapeFBOs(const IntSize&); diff --git a/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp b/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp index 65912e2..e8519d5 100644 --- a/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp +++ b/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp @@ -42,6 +42,11 @@ namespace WebCore { +void GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels) +{ + ::glReadPixels(x, y, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); +} + bool GraphicsContext3D::reshapeFBOs(const IntSize& size) { const int width = size.width(); diff --git a/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp b/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp index 1762d22..90d2332 100644 --- a/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp +++ b/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp @@ -184,8 +184,7 @@ void GraphicsContext3D::prepareTexture() void GraphicsContext3D::readRenderingResults(unsigned char *pixels, int pixelsSize) { - int totalBytes = m_currentWidth * m_currentHeight * 4; - if (pixelsSize < totalBytes) + if (pixelsSize < m_currentWidth * m_currentHeight * 4) return; makeContextCurrent(); @@ -210,11 +209,7 @@ void GraphicsContext3D::readRenderingResults(unsigned char *pixels, int pixelsSi mustRestorePackAlignment = true; } - ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); - if (isGLES2Compliant()) { - for (int i = 0; i < totalBytes; i += 4) - std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA. - } + readPixelsAndConvertToBGRAIfNecessary(0, 0, m_currentWidth, m_currentHeight, pixels); if (mustRestorePackAlignment) ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment); diff --git a/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp b/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp index 5641662..b5657ad 100644 --- a/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp +++ b/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp @@ -30,6 +30,7 @@ #include "GraphicsContext3D.h" +#include "Extensions3DOpenGL.h" #include "IntRect.h" #include "IntSize.h" #include "NotImplemented.h" @@ -40,6 +41,14 @@ namespace WebCore { +void GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels) +{ + const int totalBytes = m_currentWidth * m_currentHeight * 4; + ::glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + for (int i = 0; i < totalBytes; i += 4) + std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA. +} + bool GraphicsContext3D::reshapeFBOs(const IntSize& size) { const int width = size.width(); @@ -80,7 +89,7 @@ bool GraphicsContext3D::reshapeFBOs(const IntSize& size) if (m_attrs.stencil || m_attrs.depth) { // Use a 24 bit depth buffer where we know we have it. if (supportPackedDepthStencilBuffer) { - ::glBindTexture(GL_TEXTURE_2D, m_depthStencilBuffr); + ::glBindTexture(GL_TEXTURE_2D, m_depthStencilBuffer); ::glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, width, height, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, 0); if (m_attrs.stencil) ::glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_depthStencilBuffer, 0); @@ -88,12 +97,12 @@ bool GraphicsContext3D::reshapeFBOs(const IntSize& size) ::glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthStencilBuffer, 0); ::glBindTexture(GL_TEXTURE_2D, 0); } else { - if (m_attributes.stencil) { + if (m_attrs.stencil) { ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_stencilBuffer); ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX8, width, height); ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_stencilBuffer); } - if (m_attributes.depth) { + if (m_attrs.depth) { ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer); ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, width, height); ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer); @@ -109,7 +118,7 @@ bool GraphicsContext3D::reshapeFBOs(const IntSize& size) return mustRestoreFBO; } -void GraphicsContext3D::resolveMultisamplingIfNecessary(IntRect& rect) +void GraphicsContext3D::resolveMultisamplingIfNecessary(const IntRect& rect) { // FIXME: We don't support antialiasing yet. notImplemented(); @@ -147,4 +156,6 @@ bool GraphicsContext3D::texImage2D(GC3Denum target, GC3Dint level, GC3Denum inte return true; } +} // namespace WebCore + #endif // ENABLE(WEBGL) -- 2.7.4