[WebGL] Add support for EXT_robustness
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Aug 2012 02:45:06 +0000 (02:45 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Aug 2012 02:45:06 +0000 (02:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93379

Patch by Joshua Netterfield <jnetterfield@rim.com> on 2012-08-10
Reviewed by George Staikos.

Source/WebCore:

Take advantage of EXT robustness in WebKit.

This commit makes WebKit use readnPixelsEXT, getnUniformfvEXT and
getnUniformivEXT instead of readPixels, getUniformfv and getUniformiv
when possible, and sets up the reset notification behaviour for
GLES platforms.

The reset behaviour has not yet been implemented in the BlackBerry
compositing thread, so for now on BlackBerry we just abort when
the context has been reset. This prevents undefined behaviour, but
can be improved in the future.

No new tests are needed because no new functionality is introduced.
Support for ARB robustness reset notification behaviour is already
in WebKit, and EXT robustness' reset notifcation behaviour is the
same. readnPixelsEXT replaces WebKit's existing mechanisms of
preventing buffer overflows.

RIM PR# 147510
Internally reviewed by Arvid Nilsson.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore):
(WebCore::WebGLRenderingContext::setupFlags):
(WebCore::WebGLRenderingContext::getUniform):
(WebCore::WebGLRenderingContext::readPixels):
* html/canvas/WebGLRenderingContext.h:
(WebGLRenderingContext):
* platform/chromium/support/Extensions3DChromium.cpp:
(WebCore::Extensions3DChromium::readnPixelsEXT):
(WebCore):
(WebCore::Extensions3DChromium::getnUniformfvEXT):
(WebCore::Extensions3DChromium::getnUniformivEXT):
* platform/graphics/Extensions3D.h:
* platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp:
(WebCore::GraphicsContext3D::setContextLostCallback):
* platform/graphics/blackberry/LayerRenderer.cpp:
(WebCore::LayerRenderer::LayerRenderer):
(WebCore::LayerRenderer::makeContextCurrent):
* platform/graphics/blackberry/LayerRenderer.h:
(LayerRenderer):
* platform/graphics/chromium/Extensions3DChromium.h:
* platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
(WebCore::Extensions3DOpenGLCommon::readnPixelsEXT):
(WebCore):
(WebCore::Extensions3DOpenGLCommon::getnUniformfvEXT):
(WebCore::Extensions3DOpenGLCommon::getnUniformivEXT):
* platform/graphics/opengl/Extensions3DOpenGLCommon.h:
(Extensions3DOpenGLCommon):
* platform/graphics/opengl/Extensions3DOpenGLES.cpp:
(WebCore::Extensions3DOpenGLES::Extensions3DOpenGLES):
(WebCore::Extensions3DOpenGLES::getGraphicsResetStatusARB):
(WebCore):
(WebCore::Extensions3DOpenGLES::setEXTContextLostCallback):
(WebCore::Extensions3DOpenGLES::readnPixelsEXT):
(WebCore::Extensions3DOpenGLES::getnUniformfvEXT):
(WebCore::Extensions3DOpenGLES::getnUniformivEXT):
(WebCore::Extensions3DOpenGLES::supportsExtension):
* platform/graphics/opengl/Extensions3DOpenGLES.h:
(Extensions3DOpenGLES):

Source/WebKit:

RIM PR# 147510
Internally reviewed by Arvid Nilsson.

* CMakeLists.txt: Build system adaptation.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125349 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Source/WebCore/html/canvas/WebGLRenderingContext.h
Source/WebCore/platform/chromium/support/Extensions3DChromium.cpp
Source/WebCore/platform/graphics/Extensions3D.h
Source/WebCore/platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp
Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp
Source/WebCore/platform/graphics/blackberry/LayerRenderer.h
Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h
Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h
Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp
Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog

index 89fd4d1..3329bb6 100644 (file)
@@ -1,3 +1,71 @@
+2012-08-10  Joshua Netterfield  <jnetterfield@rim.com>
+
+        [WebGL] Add support for EXT_robustness
+        https://bugs.webkit.org/show_bug.cgi?id=93379
+
+        Reviewed by George Staikos.
+
+        Take advantage of EXT robustness in WebKit.
+
+        This commit makes WebKit use readnPixelsEXT, getnUniformfvEXT and
+        getnUniformivEXT instead of readPixels, getUniformfv and getUniformiv
+        when possible, and sets up the reset notification behaviour for
+        GLES platforms.
+
+        The reset behaviour has not yet been implemented in the BlackBerry
+        compositing thread, so for now on BlackBerry we just abort when
+        the context has been reset. This prevents undefined behaviour, but
+        can be improved in the future.
+
+        No new tests are needed because no new functionality is introduced.
+        Support for ARB robustness reset notification behaviour is already
+        in WebKit, and EXT robustness' reset notifcation behaviour is the
+        same. readnPixelsEXT replaces WebKit's existing mechanisms of
+        preventing buffer overflows.
+
+        RIM PR# 147510
+        Internally reviewed by Arvid Nilsson.
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore):
+        (WebCore::WebGLRenderingContext::setupFlags):
+        (WebCore::WebGLRenderingContext::getUniform):
+        (WebCore::WebGLRenderingContext::readPixels):
+        * html/canvas/WebGLRenderingContext.h:
+        (WebGLRenderingContext):
+        * platform/chromium/support/Extensions3DChromium.cpp:
+        (WebCore::Extensions3DChromium::readnPixelsEXT):
+        (WebCore):
+        (WebCore::Extensions3DChromium::getnUniformfvEXT):
+        (WebCore::Extensions3DChromium::getnUniformivEXT):
+        * platform/graphics/Extensions3D.h:
+        * platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp:
+        (WebCore::GraphicsContext3D::setContextLostCallback):
+        * platform/graphics/blackberry/LayerRenderer.cpp:
+        (WebCore::LayerRenderer::LayerRenderer):
+        (WebCore::LayerRenderer::makeContextCurrent):
+        * platform/graphics/blackberry/LayerRenderer.h:
+        (LayerRenderer):
+        * platform/graphics/chromium/Extensions3DChromium.h:
+        * platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
+        (WebCore::Extensions3DOpenGLCommon::readnPixelsEXT):
+        (WebCore):
+        (WebCore::Extensions3DOpenGLCommon::getnUniformfvEXT):
+        (WebCore::Extensions3DOpenGLCommon::getnUniformivEXT):
+        * platform/graphics/opengl/Extensions3DOpenGLCommon.h:
+        (Extensions3DOpenGLCommon):
+        * platform/graphics/opengl/Extensions3DOpenGLES.cpp:
+        (WebCore::Extensions3DOpenGLES::Extensions3DOpenGLES):
+        (WebCore::Extensions3DOpenGLES::getGraphicsResetStatusARB):
+        (WebCore):
+        (WebCore::Extensions3DOpenGLES::setEXTContextLostCallback):
+        (WebCore::Extensions3DOpenGLES::readnPixelsEXT):
+        (WebCore::Extensions3DOpenGLES::getnUniformfvEXT):
+        (WebCore::Extensions3DOpenGLES::getnUniformivEXT):
+        (WebCore::Extensions3DOpenGLES::supportsExtension):
+        * platform/graphics/opengl/Extensions3DOpenGLES.h:
+        (Extensions3DOpenGLES):
+
 2012-08-10  Arko Saha  <arko@motorola.com>
 
         Microdata: item with itemprop attribute should not include the item itself in the HTMLPropertiesCollection.
index c0abf0f..1ee6215 100644 (file)
@@ -548,6 +548,7 @@ void WebGLRenderingContext::setupFlags()
         m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_ARB_texture_non_power_of_two");
         m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_EXT_packed_depth_stencil");
     }
+    m_isRobustnessEXTSupported = m_context->getExtensions()->isEnabled("GL_EXT_robustness");
 }
 
 bool WebGLRenderingContext::allowPrivilegedExtensions() const
@@ -2975,21 +2976,30 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG
                 switch (baseType) {
                 case GraphicsContext3D::FLOAT: {
                     GC3Dfloat value[16] = {0};
-                    m_context->getUniformfv(objectOrZero(program), location, value);
+                    if (m_isRobustnessEXTSupported)
+                        m_context->getExtensions()->getnUniformfvEXT(objectOrZero(program), location, 16, value);
+                    else
+                        m_context->getUniformfv(objectOrZero(program), location, value);
                     if (length == 1)
                         return WebGLGetInfo(value[0]);
                     return WebGLGetInfo(Float32Array::create(value, length));
                 }
                 case GraphicsContext3D::INT: {
                     GC3Dint value[4] = {0};
-                    m_context->getUniformiv(objectOrZero(program), location, value);
+                    if (m_isRobustnessEXTSupported)
+                        m_context->getExtensions()->getnUniformivEXT(objectOrZero(program), location, 4, value);
+                    else
+                        m_context->getUniformiv(objectOrZero(program), location, value);
                     if (length == 1)
                         return WebGLGetInfo(value[0]);
                     return WebGLGetInfo(Int32Array::create(value, length));
                 }
                 case GraphicsContext3D::BOOL: {
                     GC3Dint value[4] = {0};
-                    m_context->getUniformiv(objectOrZero(program), location, value);
+                    if (m_isRobustnessEXTSupported)
+                        m_context->getExtensions()->getnUniformivEXT(objectOrZero(program), location, 4, value);
+                    else
+                        m_context->getUniformiv(objectOrZero(program), location, value);
                     if (length > 1) {
                         bool boolValue[16] = {0};
                         for (unsigned j = 0; j < length; j++)
@@ -3290,26 +3300,34 @@ void WebGLRenderingContext::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC
         return;
     }
     // Calculate array size, taking into consideration of PACK_ALIGNMENT.
-    unsigned int totalBytesRequired;
-    unsigned int padding;
-    GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, height, m_packAlignment, &totalBytesRequired, &padding);
-    if (error != GraphicsContext3D::NO_ERROR) {
-        synthesizeGLError(error, "readPixels", "invalid dimensions");
-        return;
-    }
-    if (pixels->byteLength() < totalBytesRequired) {
-        synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "ArrayBufferView not large enough for dimensions");
-        return;
+    unsigned int totalBytesRequired = 0;
+    unsigned int padding = 0;
+    if (!m_isRobustnessEXTSupported) {
+        GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, height, m_packAlignment, &totalBytesRequired, &padding);
+        if (error != GraphicsContext3D::NO_ERROR) {
+            synthesizeGLError(error, "readPixels", "invalid dimensions");
+            return;
+        }
+        if (pixels->byteLength() < totalBytesRequired) {
+            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "ArrayBufferView not large enough for dimensions");
+            return;
+        }
     }
+
     clearIfComposited();
     void* data = pixels->baseAddress();
 
     {
         ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding.get());
-        m_context->readPixels(x, y, width, height, format, type, data);
+        if (m_isRobustnessEXTSupported)
+            m_context->getExtensions()->readnPixelsEXT(x, y, width, height, format, type, pixels->byteLength(), data);
+        else
+            m_context->readPixels(x, y, width, height, format, type, data);
     }
 
 #if OS(DARWIN) || OS(QNX)
+    if (m_isRobustnessEXTSupported) // we haven't computed padding
+        m_context->computeImageSizeInBytes(format, type, width, height, m_packAlignment, &totalBytesRequired, &padding);
     // FIXME: remove this section when GL driver bug on Mac AND the GLES driver bug
     // on QC & Imagination QNX is fixed, i.e., when alpha is off, readPixels should
     // set alpha to 255 instead of 0.
index 4c890ea..c72ac59 100644 (file)
@@ -494,6 +494,7 @@ public:
     bool m_isErrorGeneratedOnOutOfBoundsAccesses;
     bool m_isResourceSafe;
     bool m_isDepthStencilSupported;
+    bool m_isRobustnessEXTSupported;
 
     bool m_synthesizedErrorsToConsole;
     int m_numGLErrorsToConsoleAllowed;
index e7b1a22..bfc145d 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "GraphicsContext3D.h"
 #include "GraphicsContext3DPrivate.h"
+#include "NotImplemented.h"
 #include <public/WebGraphicsContext3D.h>
 
 namespace WebCore {
@@ -181,4 +182,20 @@ void Extensions3DChromium::shallowFlushCHROMIUM()
     return m_private->webContext()->shallowFlushCHROMIUM();
 }
 
+void Extensions3DChromium::readnPixelsEXT(int x, int y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data)
+{
+    notImplemented();
+}
+
+void Extensions3DChromium::getnUniformfvEXT(GC3Duint program, int location, GC3Dsizei bufSize, float *params)
+{
+    notImplemented();
+}
+
+void Extensions3DChromium::getnUniformivEXT(GC3Duint program, int location, GC3Dsizei bufSize, int *params)
+{
+    notImplemented();
+}
+
+
 } // namespace WebCore
index 7cf9420..05f30fd 100644 (file)
@@ -177,6 +177,11 @@ public:
 
     // GL_CHROMIUM_copy_texture
     virtual void copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum) = 0;
+
+    // EXT Robustness - uses getGraphicsResetStatusARB
+    virtual void readnPixelsEXT(int x, int y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data) = 0;
+    virtual void getnUniformfvEXT(GC3Duint program, int location, GC3Dsizei bufSize, float *params) = 0;
+    virtual void getnUniformivEXT(GC3Duint program, int location, GC3Dsizei bufSize, int *params) = 0;
 };
 
 } // namespace WebCore
index 3698fd2..234e68f 100644 (file)
@@ -388,8 +388,9 @@ void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imag
     context->drawImage(bitmapImage.get(), ColorSpaceDeviceRGB, dst, src, CompositeCopy, RespectImageOrientation, false);
 }
 
-void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>)
+void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback> callback)
 {
+    static_cast<Extensions3DOpenGLES*>(getExtensions())->setEXTContextLostCallback(callback);
 }
 
 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>)
index b3ce235..db218a5 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <BlackBerryPlatformGraphics.h>
 #include <BlackBerryPlatformLog.h>
+#include <EGL/egl.h>
 #include <limits>
 #include <wtf/text/CString.h>
 
@@ -159,8 +160,15 @@ LayerRenderer::LayerRenderer(GLES2Context* context)
     , m_currentLayerRendererSurface(0)
     , m_clearSurfaceOnDrawLayers(true)
     , m_context(context)
+    , m_isRobustnessSupported(false)
     , m_needsCommit(false)
 {
+    if (makeContextCurrent()) {
+        m_isRobustnessSupported = String(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS))).contains("GL_EXT_robustness");
+        if (m_isRobustnessSupported)
+            m_glGetGraphicsResetStatusEXT = reinterpret_cast<PFNGLGETGRAPHICSRESETSTATUSEXTPROC>(eglGetProcAddress("glGetGraphicsResetStatusEXT"));
+    }
+
     for (int i = 0; i < LayerData::NumberOfLayerProgramShaders; ++i)
         m_layerProgramObject[i] = 0;
 
@@ -998,7 +1006,14 @@ void LayerRenderer::updateScissorIfNeeded(const FloatRect& clipRect)
 
 bool LayerRenderer::makeContextCurrent()
 {
-    return m_context->makeCurrent();
+    bool ret = m_context->makeCurrent();
+    if (ret && m_isRobustnessSupported) {
+        if (m_glGetGraphicsResetStatusEXT() != GL_NO_ERROR) {
+            BlackBerry::Platform::logAlways(BlackBerry::Platform::LogLevelCritical, "Robust OpenGL context has been reset. Aborting.");
+            CRASH();
+        }
+    }
+    return ret;
 }
 
 // Binds the given attribute name to a common location across all programs
index 437927b..353b7ec 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 #ifndef LayerRenderer_h
 #define LayerRenderer_h
 
 #if USE(ACCELERATED_COMPOSITING)
 
+#include "Extensions3DOpenGLES.h"
 #include "IntRect.h"
 #include "LayerData.h"
 #include "LayerFilterRenderer.h"
@@ -207,6 +207,9 @@ private:
 
     BlackBerry::Platform::Graphics::GLES2Context* m_context;
 
+    bool m_isRobustnessSupported;
+    PFNGLGETGRAPHICSRESETSTATUSEXTPROC m_glGetGraphicsResetStatusEXT;
+
     LayerRenderingResults m_lastRenderingResults;
     bool m_needsCommit;
 };
index 805e20a..2df3156 100644 (file)
@@ -126,6 +126,11 @@ public:
     // GL_CHROMIUM_shallow_flush
     virtual void shallowFlushCHROMIUM();
 
+    // GL_EXT_robustness
+    virtual void readnPixelsEXT(int x, int y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data);
+    virtual void getnUniformfvEXT(GC3Duint program, int location, GC3Dsizei bufSize, float *params);
+    virtual void getnUniformivEXT(GC3Duint program, int location, GC3Dsizei bufSize, int *params);
+
 private:
     // Instances of this class are strictly owned by the GraphicsContext3D implementation and do not
     // need to be instantiated by any other code.
index 5a62881..3bbb6c7 100644 (file)
@@ -143,6 +143,21 @@ void Extensions3DOpenGLCommon::initializeAvailableExtensions()
     m_initializedAvailableExtensions = true;
 }
 
+void Extensions3DOpenGLCommon::readnPixelsEXT(int, int, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, GC3Dsizei, void *)
+{
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+}
+
+void Extensions3DOpenGLCommon::getnUniformfvEXT(GC3Duint, int, GC3Dsizei, float *)
+{
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+}
+
+void Extensions3DOpenGLCommon::getnUniformivEXT(GC3Duint, int, GC3Dsizei, int *)
+{
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+}
+
 } // namespace WebCore
 
 #endif // USE(3D_GRAPHICS)
index 6a61e46..75869de 100644 (file)
@@ -52,6 +52,11 @@ public:
 
     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
 
+    // EXT Robustness - uses getGraphicsResetStatusARB()
+    virtual void readnPixelsEXT(int x, int y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data);
+    virtual void getnUniformfvEXT(GC3Duint program, int location, GC3Dsizei bufSize, float *params);
+    virtual void getnUniformivEXT(GC3Duint program, int location, GC3Dsizei bufSize, int *params);
+
 protected:
     friend class Extensions3DOpenGLES;
     Extensions3DOpenGLCommon(GraphicsContext3D*);
index b3a9300..4ade7e5 100644 (file)
 #include <EGL/egl.h>
 #include <wtf/Vector.h>
 
+#if PLATFORM(BLACKBERRY)
+#include <BlackBerryPlatformLog.h>
+#endif
 
 namespace WebCore {
 
 Extensions3DOpenGLES::Extensions3DOpenGLES(GraphicsContext3D* context)
     : Extensions3DOpenGLCommon(context)
+    , m_contextResetStatus(GL_NO_ERROR)
     , m_supportsOESvertexArrayObject(false)
     , m_supportsIMGMultisampledRenderToTexture(false)
     , m_glFramebufferTexture2DMultisampleIMG(0)
@@ -46,6 +50,10 @@ Extensions3DOpenGLES::Extensions3DOpenGLES(GraphicsContext3D* context)
     , m_glDeleteVertexArraysOES(0)
     , m_glGenVertexArraysOES(0)
     , m_glIsVertexArrayOES(0)
+    , m_glGetGraphicsResetStatusEXT(0)
+    , m_glReadnPixelsEXT(0)
+    , m_glGetnUniformfvEXT(0)
+    , m_glGetnUniformivEXT(0)
 {
 }
 
@@ -137,6 +145,77 @@ void Extensions3DOpenGLES::bindVertexArrayOES(Platform3DObject array)
         m_context->synthesizeGLError(GL_INVALID_OPERATION);
 }
 
+int Extensions3DOpenGLES::getGraphicsResetStatusARB()
+{
+    // FIXME: This does not call getGraphicsResetStatusARB, but instead getGraphicsResetStatusEXT.
+    // The return codes from the two extensions are identical and their purpose is the same, so it
+    // may be best to rename getGraphicsResetStatusARB() to getGraphicsResetStatus().
+    if (m_contextResetStatus != GL_NO_ERROR)
+        return m_contextResetStatus;
+    if (m_glGetGraphicsResetStatusEXT) {
+        m_context->makeContextCurrent();
+        int reasonForReset = m_glGetGraphicsResetStatusEXT();
+        if (reasonForReset != GL_NO_ERROR) {
+#if PLATFORM(BLACKBERRY)
+            // We cannot yet recreate our compositing thread, so just quit.
+            BlackBerry::Platform::logAlways(BlackBerry::Platform::LogLevelCritical, "Robust OpenGL context has been reset. Aborting.");
+            CRASH();
+#endif
+            ASSERT(m_contextLostCallback);
+            if (m_contextLostCallback)
+                m_contextLostCallback->onContextLost();
+            m_contextResetStatus = reasonForReset;
+        }
+        return reasonForReset;
+    }
+
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+    return false;
+}
+
+void Extensions3DOpenGLES::setEXTContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback> callback)
+{
+    m_contextLostCallback = callback;
+}
+
+void Extensions3DOpenGLES::readnPixelsEXT(int x, int y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data)
+{
+    if (m_glReadnPixelsEXT) {
+        m_context->makeContextCurrent();
+        // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
+        // all previous rendering calls should be done before reading pixels.
+        ::glFlush();
+
+        // FIXME: If non-BlackBerry platforms use this, they will need to implement
+        // their anti-aliasing code here.
+        m_glReadnPixelsEXT(x, y, width, height, format, type, bufSize, data);
+        return;
+    }
+
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+}
+
+void Extensions3DOpenGLES::getnUniformfvEXT(GC3Duint program, int location, GC3Dsizei bufSize, float *params)
+{
+    if (m_glGetnUniformfvEXT) {
+        m_context->makeContextCurrent();
+        m_glGetnUniformfvEXT(program, location, bufSize, params);
+        return;
+    }
+
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+}
+
+void Extensions3DOpenGLES::getnUniformivEXT(GC3Duint program, int location, GC3Dsizei bufSize, int *params)
+{
+    if (m_glGetnUniformivEXT) {
+        m_context->makeContextCurrent();
+        m_glGetnUniformivEXT(program, location, bufSize, params);
+        return;
+    }
+
+    m_context->synthesizeGLError(GL_INVALID_OPERATION);
+}
 
 bool Extensions3DOpenGLES::supportsExtension(const String& name)
 {
@@ -151,6 +230,11 @@ bool Extensions3DOpenGLES::supportsExtension(const String& name)
             m_glFramebufferTexture2DMultisampleIMG = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMG>(eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"));
             m_glRenderbufferStorageMultisampleIMG = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG>(eglGetProcAddress("glRenderbufferStorageMultisampleIMG"));
             m_supportsIMGMultisampledRenderToTexture = true;
+        } else if (name == "GL_EXT_robustness" && !m_glGetGraphicsResetStatusEXT) {
+            m_glGetGraphicsResetStatusEXT = reinterpret_cast<PFNGLGETGRAPHICSRESETSTATUSEXTPROC>(eglGetProcAddress("glGetGraphicsResetStatusEXT"));
+            m_glReadnPixelsEXT = reinterpret_cast<PFNGLREADNPIXELSEXTPROC>(eglGetProcAddress("glReadnPixelsEXT"));
+            m_glGetnUniformfvEXT = reinterpret_cast<PFNGLGETNUNIFORMFVEXTPROC>(eglGetProcAddress("glGetnUniformfvEXT"));
+            m_glGetnUniformivEXT = reinterpret_cast<PFNGLGETNUNIFORMIVEXTPROC>(eglGetProcAddress("glGetnUniformivEXT"));
         }
         return true;
     }
index fcf72d6..1885880 100644 (file)
 #define PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC
 #endif
 
+#ifndef GL_EXT_robustness
+/* reuse GL_NO_ERROR */
+#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255
+#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3
+#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256
+#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252
+#define GL_NO_RESET_NOTIFICATION_EXT 0x8261
+#endif
+
+#ifndef GL_EXT_robustness
+#define GL_EXT_robustness 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GC3Denum GL_APIENTRY glGetGraphicsResetStatusEXT(void);
+GL_APICALL void GL_APIENTRY glReadnPixelsEXT(GLint x, GLint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data);
+GL_APICALL void GL_APIENTRY glGetnUniformfvEXT(GLuint program, GLint location, GC3Dsizei bufSize, float *params);
+GL_APICALL void GL_APIENTRY glGetnUniformivEXT(GLuint program, GLint location, GC3Dsizei bufSize, GLint *params);
+#endif
+typedef GC3Denum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSEXTPROC) (void);
+typedef void (GL_APIENTRYP PFNGLREADNPIXELSEXTPROC) (GLint x, GLint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVEXTPROC) (GLuint program, GLint location, GC3Dsizei bufSize, float *params);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVEXTPROC) (GLuint program, GLint location, GC3Dsizei bufSize, GLint *params);
+#endif
+
 namespace WebCore {
 
 class Extensions3DOpenGLES : public Extensions3DOpenGLCommon {
@@ -57,6 +82,15 @@ public:
     virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
     virtual void bindVertexArrayOES(Platform3DObject);
 
+    // EXT Robustness - reset
+    virtual int getGraphicsResetStatusARB();
+    void setEXTContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback>);
+
+    // EXT Robustness - etc
+    virtual void readnPixelsEXT(int x, int y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, GC3Dsizei bufSize, void *data);
+    virtual void getnUniformfvEXT(GC3Duint program, int location, GC3Dsizei bufSize, float *params);
+    virtual void getnUniformivEXT(GC3Duint program, int location, GC3Dsizei bufSize, int *params);
+
 protected:
     // This class only needs to be instantiated by GraphicsContext3D implementations.
     friend class GraphicsContext3D;
@@ -65,6 +99,8 @@ protected:
     virtual bool supportsExtension(const String&);
     virtual String getExtensions();
 
+    GC3Denum m_contextResetStatus;
+
     bool m_supportsOESvertexArrayObject;
     bool m_supportsIMGMultisampledRenderToTexture;
 
@@ -74,6 +110,12 @@ protected:
     PFNGLDELETEVERTEXARRAYSOESPROC m_glDeleteVertexArraysOES;
     PFNGLGENVERTEXARRAYSOESPROC m_glGenVertexArraysOES;
     PFNGLISVERTEXARRAYOESPROC m_glIsVertexArrayOES;
+    PFNGLGETGRAPHICSRESETSTATUSEXTPROC m_glGetGraphicsResetStatusEXT;
+    PFNGLREADNPIXELSEXTPROC m_glReadnPixelsEXT;
+    PFNGLGETNUNIFORMFVEXTPROC m_glGetnUniformfvEXT;
+    PFNGLGETNUNIFORMIVEXTPROC m_glGetnUniformivEXT;
+
+    OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
 };
 
 } // namespace WebCore
index 03797a3..a7983d9 100644 (file)
@@ -31,6 +31,7 @@ SET(WebKit_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/filters"
     "${WEBCORE_DIR}/platform/graphics/harfbuzz"
     "${WEBCORE_DIR}/platform/graphics/harfbuzz/ng"
+    "${WEBCORE_DIR}/platform/graphics/opengl"
     "${WEBCORE_DIR}/platform/graphics/transforms"
     "${WEBCORE_DIR}/platform/network"
     "${WEBCORE_DIR}/platform/sql"
index 9049dbc..3c5e06c 100644 (file)
@@ -1,3 +1,15 @@
+2012-08-10  Joshua Netterfield  <jnetterfield@rim.com>
+
+        [WebGL] Add support for EXT_robustness
+        https://bugs.webkit.org/show_bug.cgi?id=93379
+
+        Reviewed by George Staikos.
+
+        RIM PR# 147510
+        Internally reviewed by Arvid Nilsson.
+
+        * CMakeLists.txt: Build system adaptation.
+
 2012-08-10  Benjamin C Meyer  <bmeyer@rim.com>
 
         Introduce JavaScriptVariant object.