Title: [122754] trunk/Source
Revision
122754
Author
[email protected]
Date
2012-07-16 13:29:07 -0700 (Mon, 16 Jul 2012)

Log Message

[BlackBerry] Upstream WebGL Code
https://bugs.webkit.org/show_bug.cgi?id=91143

Patch by Joshua Netterfield <[email protected]> on 2012-07-16
Reviewed by Rob Buis.

This patch includes BlackBerry-specific fixes for anti-aliasing, logging, and shader compilation.

Source/WebCore:

No new tests, because there is no new functionality.

* platform/graphics/GraphicsContext3D.h: Add a value for TI Imagination chipsets on BlackBerry platforms
* platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp: Multiple downstream changes
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::reshapeFBOs):
(WebCore):
(WebCore::GraphicsContext3D::logFrameBufferStatus):
(WebCore::GraphicsContext3D::readPixelsIMG): BlackBerry-specific fix for Imagination hardware.
(WebCore::GraphicsContext3D::paintsIntoCanvasBuffer):
(WebCore::GraphicsContext3D::platformTexture):
(WebCore::GraphicsContext3D::platformGraphicsContext3D):
(WebCore::GraphicsContext3D::paintToCanvas):
* platform/graphics/opengl/Extensions3DOpenGL.h: Remove unnecessary whitespace.
(Extensions3DOpenGL):
* platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
(WebCore::Extensions3DOpenGLCommon::getTranslatedShaderSourceANGLE): Hack to fix ANGLE-generated code on BlackBerry platforms.
* platform/graphics/opengl/Extensions3DOpenGLCommon.h:
(Extensions3DOpenGLCommon):
* platform/graphics/opengl/Extensions3DOpenGLES.cpp: I am not in a position to change system headers from correct to incorrect.
(WebCore::Extensions3DOpenGLES::renderbufferStorageMultisample):
(WebCore::Extensions3DOpenGLES::supportsExtension):
* platform/graphics/opengl/Extensions3DOpenGLES.h: I am not in a position to change system headers from correct to incorrect.
(Extensions3DOpenGLES):
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: Add a BlackBerry-specific anti-aliasing fix.
(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3D::prepareTexture):
(WebCore::GraphicsContext3D::bindFramebuffer):
(WebCore::GraphicsContext3D::compileShader):
(WebCore::GraphicsContext3D::copyTexImage2D):
(WebCore::GraphicsContext3D::copyTexSubImage2D):
(WebCore):
* platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
(WebCore):

Source/WebKit:

* PlatformBlackBerry.cmake: Define WTF_USE_OPENGL_ES_2 on WebGL-enabled builds.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (122753 => 122754)


--- trunk/Source/WebCore/ChangeLog	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/ChangeLog	2012-07-16 20:29:07 UTC (rev 122754)
@@ -1,3 +1,47 @@
+2012-07-16  Joshua Netterfield  <[email protected]>
+
+        [BlackBerry] Upstream WebGL Code
+        https://bugs.webkit.org/show_bug.cgi?id=91143
+
+        Reviewed by Rob Buis.
+
+        This patch includes BlackBerry-specific fixes for anti-aliasing, logging, and shader compilation.
+
+        No new tests, because there is no new functionality.
+
+        * platform/graphics/GraphicsContext3D.h: Add a value for TI Imagination chipsets on BlackBerry platforms
+        * platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp: Multiple downstream changes
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+        (WebCore::GraphicsContext3D::reshapeFBOs):
+        (WebCore):
+        (WebCore::GraphicsContext3D::logFrameBufferStatus):
+        (WebCore::GraphicsContext3D::readPixelsIMG): BlackBerry-specific fix for Imagination hardware.
+        (WebCore::GraphicsContext3D::paintsIntoCanvasBuffer):
+        (WebCore::GraphicsContext3D::platformTexture):
+        (WebCore::GraphicsContext3D::platformGraphicsContext3D):
+        (WebCore::GraphicsContext3D::paintToCanvas):
+        * platform/graphics/opengl/Extensions3DOpenGL.h: Remove unnecessary whitespace.
+        (Extensions3DOpenGL):
+        * platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
+        (WebCore::Extensions3DOpenGLCommon::getTranslatedShaderSourceANGLE): Hack to fix ANGLE-generated code on BlackBerry platforms.
+        * platform/graphics/opengl/Extensions3DOpenGLCommon.h:
+        (Extensions3DOpenGLCommon):
+        * platform/graphics/opengl/Extensions3DOpenGLES.cpp: I am not in a position to change system headers from correct to incorrect.
+        (WebCore::Extensions3DOpenGLES::renderbufferStorageMultisample):
+        (WebCore::Extensions3DOpenGLES::supportsExtension):
+        * platform/graphics/opengl/Extensions3DOpenGLES.h: I am not in a position to change system headers from correct to incorrect.
+        (Extensions3DOpenGLES):
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: Add a BlackBerry-specific anti-aliasing fix.
+        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
+        (WebCore::GraphicsContext3D::prepareTexture):
+        (WebCore::GraphicsContext3D::bindFramebuffer):
+        (WebCore::GraphicsContext3D::compileShader):
+        (WebCore::GraphicsContext3D::copyTexImage2D):
+        (WebCore::GraphicsContext3D::copyTexSubImage2D):
+        (WebCore):
+        * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
+        (WebCore):
+
 2012-07-16  Tony Chang  <[email protected]>
 
         Position grid items by row/column index

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2012-07-16 20:29:07 UTC (rev 122754)
@@ -931,6 +931,11 @@
     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
 #endif
 
+#if PLATFORM(BLACKBERRY)
+    void logFrameBufferStatus(int line);
+    void readPixelsIMG(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
+#endif
+
     bool reshapeFBOs(const IntSize&);
     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
 #if PLATFORM(QT) && USE(GRAPHICS_SURFACE)
@@ -943,7 +948,12 @@
 #if PLATFORM(MAC)
     CGLContextObj m_contextObj;
     RetainPtr<WebGLLayer> m_webGLLayer;
+#elif PLATFORM(BLACKBERRY)
+#if USE(ACCELERATED_COMPOSITING)
+    RefPtr<PlatformLayer> m_compositingLayer;
 #endif
+    void* m_context;
+#endif
 
 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY)
     typedef struct {
@@ -996,9 +1006,14 @@
     // Errors raised by synthesizeGLError().
     ListHashSet<GC3Denum> m_syntheticErrors;
 
+#if PLATFORM(BLACKBERRY)
+    bool m_isImaginationHardware;
+#endif
+
+#if !PLATFORM(BLACKBERRY)
     friend class GraphicsContext3DPrivate;
     OwnPtr<GraphicsContext3DPrivate> m_private;
-
+#endif
     bool systemAllowsMultisamplingOnATICards() const;
 };
 

Modified: trunk/Source/WebCore/platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp	2012-07-16 20:29:07 UTC (rev 122754)
@@ -31,11 +31,13 @@
 #include "GraphicsContext3D.h"
 
 #include "BitmapImageSingleFrameSkia.h"
-#include "Extensions3DOpenGL.h"
+#include "Extensions3DOpenGLES.h"
 #include "GraphicsContext.h"
+#include "OpenGLESShims.h"
 #include "WebGLLayerWebKitThread.h"
 
 #include <BlackBerryPlatformGraphics.h>
+#include <BlackBerryPlatformLog.h>
 
 namespace WebCore {
 
@@ -48,22 +50,21 @@
     return adoptRef(new GraphicsContext3D(attribs, hostWindow, false));
 }
 
-GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, bool renderDirectlyToHostWindow)
+GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow*, bool renderDirectlyToHostWindow)
     : m_currentWidth(0)
     , m_currentHeight(0)
-    , m_hostWindow(hostWindow)
     , m_context(BlackBerry::Platform::Graphics::createWebGLContext())
-    , m_extensions(adoptPtr(new Extensions3DOpenGL(this)))
+    , m_extensions(adoptPtr(new Extensions3DOpenGLES(this)))
     , m_attrs(attrs)
     , m_texture(0)
     , m_fbo(0)
     , m_depthStencilBuffer(0)
+    , m_layerComposited(false)
+    , m_internalColorFormat(GL_RGBA)
     , m_boundFBO(0)
     , m_activeTexture(GL_TEXTURE0)
     , m_boundTexture0(0)
-    , m_multisampleFBO(0)
-    , m_multisampleDepthStencilBuffer(0)
-    , m_multisampleColorBuffer(0)
+    , m_isImaginationHardware(0)
 {
     if (!renderDirectlyToHostWindow) {
 #if USE(ACCELERATED_COMPOSITING)
@@ -71,10 +72,6 @@
 #endif
         makeContextCurrent();
 
-        Extensions3D* extensions = getExtensions();
-        if (!extensions->supports("GL_IMG_multisampled_render_to_texture"))
-            m_attrs.antialias = false;
-
         // Create a texture to render into.
         ::glGenTextures(1, &m_texture);
         ::glBindTexture(GL_TEXTURE_2D, m_texture);
@@ -96,12 +93,29 @@
 #endif
     }
 
-    // FIXME: If GraphicsContext3D is created with renderDirectlyToHostWindow == true,
-    // makeContextCurrent() will make the shared context current.
     makeContextCurrent();
 
-    // FIXME: Do we need to enable GL_VERTEX_PROGRAM_POINT_SIZE with GL ES2? See PR #120141.
+    const char* renderer = reinterpret_cast<const char*>(::glGetString(GL_RENDERER));
+    m_isImaginationHardware = std::strstr(renderer, "PowerVR SGX");
 
+    // ANGLE initialization.
+    ShBuiltInResources ANGLEResources;
+    ShInitBuiltInResources(&ANGLEResources);
+
+    getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs);
+    getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors);
+    getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors);
+    getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits);
+    getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits);
+    getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits);
+    getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors);
+
+    ANGLEResources.MaxDrawBuffers = 1; // Always set to 1 for OpenGL ES.
+    ANGLEResources.OES_standard_derivatives = m_extensions->supports("GL_OES_standard_derivatives");
+    ANGLEResources.OES_EGL_image_external = m_extensions->supports("GL_EGL_image_external");
+    ANGLEResources.ARB_texture_rectangle = m_extensions->supports("GL_ARB_texture_rectangle");
+    m_compiler.setResources(ANGLEResources);
+
     ::glClearColor(0, 0, 0, 0);
 }
 
@@ -118,9 +132,187 @@
     BlackBerry::Platform::Graphics::destroyWebGLContext(m_context);
 }
 
+bool GraphicsContext3D::reshapeFBOs(const IntSize& size)
+{
+    // A BlackBerry-specific implementation of reshapeFBOs is necessary because it contains:
+    //  - an Imagination-specific implementation of anti-aliasing
+    //  - an Imagination-specific fix for FBOs of size less than (16,16)
+
+    int fboWidth = size.width();
+    int fboHeight = size.height();
+
+    // Imagination-specific fix
+    if (m_isImaginationHardware) {
+        fboWidth = std::max(fboWidth, 16);
+        fboHeight = std::max(fboHeight, 16);
+    }
+
+    GLuint internalColorFormat, colorFormat, internalDepthStencilFormat = 0;
+    if (m_attrs.alpha) {
+        internalColorFormat = GL_RGBA;
+        colorFormat = GL_RGBA;
+    } else {
+        internalColorFormat = GL_RGB;
+        colorFormat = GL_RGB;
+    }
+    if (m_attrs.stencil || m_attrs.depth) {
+        // We don't allow the logic where stencil is required and depth is not.
+        // See GraphicsContext3D constructor.
+        if (m_attrs.stencil && m_attrs.depth)
+            internalDepthStencilFormat = GL_DEPTH24_STENCIL8_EXT;
+        else
+            internalDepthStencilFormat = GL_DEPTH_COMPONENT16;
+    }
+
+    GLint sampleCount = 8;
+    if (m_attrs.antialias) {
+        GLint maxSampleCount;
+        // Hardcode the maximum number of samples due to header issue (PR132183)
+        // ::glGetIntegerv(GL_MAX_SAMPLES_IMG, &maxSampleCount);
+        maxSampleCount = 4;
+        sampleCount = std::min(8, maxSampleCount);
+    }
+
+    ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
+
+    ::glBindTexture(GL_TEXTURE_2D, m_texture);
+    ::glTexImage2D(GL_TEXTURE_2D, 0, internalColorFormat, fboWidth, fboHeight, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+
+    Extensions3D* extensions = getExtensions();
+    if (m_attrs.antialias) {
+        extensions->framebufferTexture2DMultisampleIMG(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0, sampleCount);
+
+        if (m_attrs.stencil || m_attrs.depth) {
+            ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
+            extensions->renderbufferStorageMultisampleIMG(GL_RENDERBUFFER_EXT, sampleCount, internalDepthStencilFormat, fboWidth, fboHeight);
+
+            if (m_attrs.stencil)
+                ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
+            if (m_attrs.depth)
+                ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
+            ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+        }
+    } else {
+        ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0);
+
+        if (m_attrs.stencil || m_attrs.depth) {
+            ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
+            ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalDepthStencilFormat, fboWidth, fboHeight);
+
+            if (m_attrs.stencil)
+                ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
+            if (m_attrs.depth)
+                ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
+            ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+        }
+    }
+    ::glBindTexture(GL_TEXTURE_2D, 0);
+
+
+    logFrameBufferStatus(__LINE__);
+
+    return true;
+}
+
+void GraphicsContext3D::logFrameBufferStatus(int line)
+{
+    BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "Checking FrameBuffer status at line %d: ", line);
+    switch (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)) {
+    case GL_FRAMEBUFFER_COMPLETE:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "COMPLETE | ");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "INCOMPLETE ATTACHMENT | ");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "MISSING ATTACHMENT | ");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "INCOMPLETE DIMENSIONS | ");
+        break;
+    case GL_FRAMEBUFFER_UNSUPPORTED:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "UNSUPPORTED | ");
+        break;
+    case FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "INCOMPLETE MULTISAMPLE | ");
+        break;
+    }
+
+    switch (glGetError()) {
+    case GL_NO_ERROR:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "NO ERROR");
+        break;
+    case GL_INVALID_ENUM:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "INVALID ENUM");
+        break;
+    case GL_INVALID_VALUE:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "INVALID VALUE");
+        break;
+    case GL_INVALID_OPERATION:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "INVALID OPERATION");
+        break;
+    case GL_OUT_OF_MEMORY:
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "OUT OF MEMORY");
+        break;
+    }
+    BlackBerry::Platform::log(BlackBerry::Platform::LogLevelInfo, "\n");
+}
+
+void GraphicsContext3D::readPixelsIMG(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
+{
+    // Currently only format=RGBA, type=UNSIGNED_BYTE is supported by the specification: http://www.khronos.org/registry/webgl/specs/latest/
+    // If this ever changes, this code will need to be updated.
+
+    // Calculate the strides of our data and canvas
+    unsigned int formatSize = 4; // RGBA UNSIGNED_BYTE
+    unsigned int dataStride = width * formatSize;
+    unsigned int canvasStride = m_currentWidth * formatSize;
+
+    // If we are using a pack alignment of 8, then we need to align our strides to 8 byte boundaries
+    // See: http://en.wikipedia.org/wiki/Data_structure_alignment (computing padding)
+    int packAlignment;
+    glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
+    if (8 == packAlignment) {
+        dataStride = (dataStride + 7) & ~7;
+        canvasStride = (canvasStride + 7) & ~7;
+    }
+
+    unsigned char* canvasData = new unsigned char[canvasStride * m_currentHeight];
+    ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, format, type, canvasData);
+
+    // If we failed to read our canvas data due to a GL error, don't continue
+    int error = glGetError();
+    if (GL_NO_ERROR != error) {
+        synthesizeGLError(error);
+        return;
+    }
+
+    // Clear our data in case some of it lies outside the bounds of our canvas
+    // TODO: don't do this if all of the data lies inside the bounds of the canvas
+    memset(data, 0, dataStride * height);
+
+    // Calculate the intersection of our canvas and data bounds
+    IntRect dataRect(x, y, width, height);
+    IntRect canvasRect(0, 0, m_currentWidth, m_currentHeight);
+    IntRect nonZeroDataRect = intersection(dataRect, canvasRect);
+
+    unsigned int xDataOffset = x < 0 ? -x * formatSize : 0;
+    unsigned int yDataOffset = y < 0 ? -y * dataStride : 0;
+    unsigned int xCanvasOffset = nonZeroDataRect.x() * formatSize;
+    unsigned int yCanvasOffset = nonZeroDataRect.y() * canvasStride;
+    unsigned char* dst = static_cast<unsigned char*>(data) + xDataOffset + yDataOffset;
+    unsigned char* src = "" + xCanvasOffset + yCanvasOffset;
+    for (int row = 0; row < nonZeroDataRect.height(); row++) {
+        memcpy(dst, src, nonZeroDataRect.width() * formatSize);
+        dst += dataStride;
+        src += canvasStride;
+    }
+
+    delete [] canvasData;
+}
+
 bool GraphicsContext3D::paintsIntoCanvasBuffer() const
 {
-    // See PR #120141.
     return true;
 }
 
@@ -147,9 +339,14 @@
 
 Platform3DObject GraphicsContext3D::platformTexture() const
 {
-    return m_texture;
+    return m_compositingLayer->getTextureID();
 }
 
+PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
+{
+    return m_context;
+}
+
 #if USE(ACCELERATED_COMPOSITING)
 PlatformLayer* GraphicsContext3D::platformLayer() const
 {
@@ -196,7 +393,7 @@
     FloatRect dst(0, 0, imageWidth, imageHeight);
 
     RefPtr<BitmapImageSingleFrameSkia> bitmapImage = BitmapImageSingleFrameSkia::create(canvasBitmap, false);
-    context->drawImage(bitmapImage.get(), ColorSpaceDeviceRGB, dst, src, CompositeCopy, DoNotRespectImageOrientation, false);
+    context->drawImage(bitmapImage.get(), ColorSpaceDeviceRGB, dst, src, CompositeCopy, RespectImageOrientation, false);
 }
 
 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>)

Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h	2012-07-16 20:29:07 UTC (rev 122754)
@@ -41,7 +41,7 @@
     // Extensions3D methods.
     virtual void blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter);
     virtual void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
-    
+
     virtual Platform3DObject createVertexArrayOES();
     virtual void deleteVertexArrayOES(Platform3DObject);
     virtual GC3Dboolean isVertexArrayOES(Platform3DObject);

Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp	2012-07-16 20:29:07 UTC (rev 122754)
@@ -130,6 +130,16 @@
     if (!isValid)
         return "";
 
+#if PLATFORM(BLACKBERRY)
+    // Our hardware really likes being told what precision to have (i.e., with "precision * float")
+    // ANGLE strips this information.
+    if (entry.source.contains("precision lowp float"))
+        translatedShaderSource = "precision lowp float;\n" + translatedShaderSource;
+    else if (entry.source.contains("precision mediump float"))
+        translatedShaderSource = "precision mediump float;\n" + translatedShaderSource;
+    else
+        translatedShaderSource = "precision highp float;\n" + translatedShaderSource;
+#endif
     return translatedShaderSource;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h	2012-07-16 20:29:07 UTC (rev 122754)
@@ -53,13 +53,13 @@
     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
 
 protected:
+    friend class Extensions3DOpenGLES;
     Extensions3DOpenGLCommon(GraphicsContext3D*);
 
     virtual bool supportsExtension(const String&) = 0;
     virtual String getExtensions() = 0;
 
     virtual void initializeAvailableExtensions();
-
     bool m_initializedAvailableExtensions;
     HashSet<String> m_availableExtensions;
 

Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp	2012-07-16 20:29:07 UTC (rev 122754)
@@ -76,7 +76,10 @@
 
 void Extensions3DOpenGLES::renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height)
 {
-    notImplemented();
+    if (m_glRenderbufferStorageMultisampleIMG)
+        renderbufferStorageMultisampleIMG(target, samples, internalformat, width, height);
+    else
+        notImplemented();
 }
 
 void Extensions3DOpenGLES::copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum)

Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h	2012-07-16 20:29:07 UTC (rev 122754)
@@ -32,6 +32,12 @@
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
+#if PLATFORM(BLACKBERRY)
+// See https://bugs.webkit.org/show_bug.cgi?id=91030.
+#define PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMG PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC
+#define PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC
+#endif
+
 namespace WebCore {
 
 class Extensions3DOpenGLES : public Extensions3DOpenGLCommon {

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2012-07-16 20:29:07 UTC (rev 122754)
@@ -120,8 +120,13 @@
         }
     }
 
+#if PLATFORM(BLACKBERRY)
     paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
+                  imageBuffer->internalSize().width(), imageBuffer->internalSize().height(), imageBuffer->context(), true);
+#else
+    paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
                   imageBuffer->internalSize().width(), imageBuffer->internalSize().height(), imageBuffer->context()->platformContext());
+#endif
 }
 
 bool GraphicsContext3D::paintCompositedResultsToCanvas(ImageBuffer*)
@@ -161,11 +166,27 @@
 
     ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     ::glActiveTexture(GL_TEXTURE0);
+#if PLATFORM(BLACKBERRY)
+    if (!platformTexture()) {
+        GLuint tex = 0;
+        ::glGenTextures(1, &tex);
+        ::glBindTexture(GL_TEXTURE_2D, tex);
+        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_currentWidth, m_currentHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+        m_compositingLayer->setTextureID(tex);
+    }
+    ::glBindTexture(GL_TEXTURE_2D, platformTexture());
+#else
     ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
+#endif
     ::glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, 0, 0, m_currentWidth, m_currentHeight, 0);
     ::glBindTexture(GL_TEXTURE_2D, m_boundTexture0);
     ::glActiveTexture(m_activeTexture);
-    ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_boundFBO);
+    if (m_boundFBO != m_fbo)
+        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_boundFBO);
     ::glFinish();
     m_layerComposited = true;
 }
@@ -325,7 +346,11 @@
     if (buffer)
         fbo = buffer;
     else
+#if PLATFORM(BLACKBERRY)
+        fbo = m_fbo;
+#else
         fbo = (m_attrs.antialias ? m_multisampleFBO : m_fbo);
+#endif
     if (fbo != m_boundFBO) {
         ::glBindFramebufferEXT(target, fbo);
         m_boundFBO = fbo;
@@ -448,33 +473,60 @@
     int GLCompileSuccess;
     
     ::glGetShaderiv(shader, COMPILE_STATUS, &GLCompileSuccess);
+
+    // Populate the shader log
+    GLint length = 0;
+    ::glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
+
+    if (length) {
+        HashMap<Platform3DObject, GraphicsContext3D::ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
+        GraphicsContext3D::ShaderSourceEntry& entry = result->second;
+
+        GLsizei size = 0;
+        OwnArrayPtr<GLchar> info = adoptArrayPtr(new GLchar[length]);
+        ::glGetShaderInfoLog(shader, length, &size, info.get());
+
+        entry.log = info.get();
+    }
     
     // ASSERT that ANGLE generated GLSL will be accepted by OpenGL.
     ASSERT(GLCompileSuccess == GL_TRUE);
+#if PLATFORM(BLACKBERRY)
+    if (GLCompileSuccess != GL_TRUE)
+        BlackBerry::Platform::log(BlackBerry::Platform::LogLevelWarn, "The shader validated, but didn't compile.\n");
+#endif
 }
 
 void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
 {
     makeContextCurrent();
+#if !PLATFORM(BLACKBERRY)
     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
         resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     }
+#endif
     ::glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
+#if !PLATFORM(BLACKBERRY)
     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
+#endif
 }
 
 void GraphicsContext3D::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
 {
     makeContextCurrent();
+#if !PLATFORM(BLACKBERRY)
     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
         resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     }
+#endif
     ::glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+#if !PLATFORM(BLACKBERRY)
     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
+#endif
 }
 
 void GraphicsContext3D::cullFace(GC3Denum mode)

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp (122753 => 122754)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp	2012-07-16 20:29:07 UTC (rev 122754)
@@ -99,10 +99,20 @@
     }
 
     delete [] canvasData;
+#if PLATFORM(BLACKBERRY)
+    // Imagination specific fix
+    if (m_isImaginationHardware)
+        readPixelsIMG(x, y, width, height, format, type, data);
+    else
+        ::glReadPixels(x, y, width, height, format, type, data);
+
+    // Note: BlackBerries have a different anti-aliasing pipeline.
+#else
     ::glReadPixels(x, y, width, height, format, type, data);
 
     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
+#endif
 }
 
 void GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels)
@@ -115,6 +125,8 @@
     }
 }
 
+#if !PLATFORM(BLACKBERRY)
+// The BlackBerry port uses a special implementation of reshapeFBOs. See GraphicsContext3DBlackBerry.cpp
 bool GraphicsContext3D::reshapeFBOs(const IntSize& size)
 {
     const int width = size.width();
@@ -183,6 +195,7 @@
 
     return mustRestoreFBO;
 }
+#endif
 
 void GraphicsContext3D::resolveMultisamplingIfNecessary(const IntRect& rect)
 {

Modified: trunk/Source/WebKit/ChangeLog (122753 => 122754)


--- trunk/Source/WebKit/ChangeLog	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebKit/ChangeLog	2012-07-16 20:29:07 UTC (rev 122754)
@@ -1,3 +1,14 @@
+2012-07-16  Joshua Netterfield  <[email protected]>
+
+        [BlackBerry] Upstream WebGL Code
+        https://bugs.webkit.org/show_bug.cgi?id=91143
+
+        Reviewed by Rob Buis.
+
+        This patch includes BlackBerry-specific fixes for anti-aliasing, logging, and shader compilation.
+
+        * PlatformBlackBerry.cmake: Define WTF_USE_OPENGL_ES_2 on WebGL-enabled builds.
+
 2012-07-16  Frederik Gladhorn  <[email protected]>
 
         Add accessible for QWebView.

Modified: trunk/Source/WebKit/PlatformBlackBerry.cmake (122753 => 122754)


--- trunk/Source/WebKit/PlatformBlackBerry.cmake	2012-07-16 20:06:15 UTC (rev 122753)
+++ trunk/Source/WebKit/PlatformBlackBerry.cmake	2012-07-16 20:29:07 UTC (rev 122754)
@@ -109,6 +109,7 @@
 )
 
 IF (ENABLE_WEBGL)
+    ADD_DEFINITIONS (-DWTF_USE_OPENGL_ES_2=1)
     LIST(APPEND WebKit_INCLUDE_DIRECTORIES
         ${OPENGL_INCLUDE_DIR}
         ${THIRDPARTY_DIR}/ANGLE/src
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to