Title: [125349] trunk/Source
Revision
125349
Author
[email protected]
Date
2012-08-10 19:45:06 -0700 (Fri, 10 Aug 2012)

Log Message

[WebGL] Add support for EXT_robustness
https://bugs.webkit.org/show_bug.cgi?id=93379

Patch by Joshua Netterfield <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125348 => 125349)


--- trunk/Source/WebCore/ChangeLog	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/ChangeLog	2012-08-11 02:45:06 UTC (rev 125349)
@@ -1,3 +1,71 @@
+2012-08-10  Joshua Netterfield  <[email protected]>
+
+        [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  <[email protected]>
 
         Microdata: item with itemprop attribute should not include the item itself in the HTMLPropertiesCollection.

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (125348 => 125349)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2012-08-11 02:45:06 UTC (rev 125349)
@@ -548,6 +548,7 @@
         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 @@
                 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 @@
         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;
+    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;
+        }
     }
-    if (pixels->byteLength() < totalBytesRequired) {
-        synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "ArrayBufferView not large enough for dimensions");
-        return;
-    }
+
     clearIfComposited();
     void* data = ""
 
     {
         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.

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h (125348 => 125349)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h	2012-08-11 02:45:06 UTC (rev 125349)
@@ -494,6 +494,7 @@
     bool m_isErrorGeneratedOnOutOfBoundsAccesses;
     bool m_isResourceSafe;
     bool m_isDepthStencilSupported;
+    bool m_isRobustnessEXTSupported;
 
     bool m_synthesizedErrorsToConsole;
     int m_numGLErrorsToConsoleAllowed;

Modified: trunk/Source/WebCore/platform/chromium/support/Extensions3DChromium.cpp (125348 => 125349)


--- trunk/Source/WebCore/platform/chromium/support/Extensions3DChromium.cpp	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/chromium/support/Extensions3DChromium.cpp	2012-08-11 02:45:06 UTC (rev 125349)
@@ -29,6 +29,7 @@
 
 #include "GraphicsContext3D.h"
 #include "GraphicsContext3DPrivate.h"
+#include "NotImplemented.h"
 #include <public/WebGraphicsContext3D.h>
 
 namespace WebCore {
@@ -181,4 +182,20 @@
     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

Modified: trunk/Source/WebCore/platform/graphics/Extensions3D.h (125348 => 125349)


--- trunk/Source/WebCore/platform/graphics/Extensions3D.h	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/Extensions3D.h	2012-08-11 02:45:06 UTC (rev 125349)
@@ -177,6 +177,11 @@
 
     // 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

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


--- trunk/Source/WebCore/platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp	2012-08-11 02:45:06 UTC (rev 125349)
@@ -388,8 +388,9 @@
     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>)

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp (125348 => 125349)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp	2012-08-11 02:45:06 UTC (rev 125349)
@@ -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 @@
     , 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 @@
 
 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

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h (125348 => 125349)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h	2012-08-11 02:45:06 UTC (rev 125349)
@@ -29,12 +29,12 @@
  * 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 @@
 
     BlackBerry::Platform::Graphics::GLES2Context* m_context;
 
+    bool m_isRobustnessSupported;
+    PFNGLGETGRAPHICSRESETSTATUSEXTPROC m_glGetGraphicsResetStatusEXT;
+
     LayerRenderingResults m_lastRenderingResults;
     bool m_needsCommit;
 };

Modified: trunk/Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h (125348 => 125349)


--- trunk/Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h	2012-08-11 02:45:06 UTC (rev 125349)
@@ -126,6 +126,11 @@
     // 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.

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


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp	2012-08-11 02:45:06 UTC (rev 125349)
@@ -143,6 +143,21 @@
     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)

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


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h	2012-08-11 02:45:06 UTC (rev 125349)
@@ -52,6 +52,11 @@
 
     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*);

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


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp	2012-08-11 02:45:06 UTC (rev 125349)
@@ -33,11 +33,15 @@
 #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 @@
     , m_glDeleteVertexArraysOES(0)
     , m_glGenVertexArraysOES(0)
     , m_glIsVertexArrayOES(0)
+    , m_glGetGraphicsResetStatusEXT(0)
+    , m_glReadnPixelsEXT(0)
+    , m_glGetnUniformfvEXT(0)
+    , m_glGetnUniformivEXT(0)
 {
 }
 
@@ -137,7 +145,78 @@
         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)
 {
     if (m_availableExtensions.contains(name)) {
@@ -151,6 +230,11 @@
             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;
     }

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


--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h	2012-08-11 02:45:06 UTC (rev 125349)
@@ -38,6 +38,31 @@
 #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 @@
     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 @@
     virtual bool supportsExtension(const String&);
     virtual String getExtensions();
 
+    GC3Denum m_contextResetStatus;
+
     bool m_supportsOESvertexArrayObject;
     bool m_supportsIMGMultisampledRenderToTexture;
 
@@ -74,6 +110,12 @@
     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

Modified: trunk/Source/WebKit/CMakeLists.txt (125348 => 125349)


--- trunk/Source/WebKit/CMakeLists.txt	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebKit/CMakeLists.txt	2012-08-11 02:45:06 UTC (rev 125349)
@@ -31,6 +31,7 @@
     "${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"

Modified: trunk/Source/WebKit/ChangeLog (125348 => 125349)


--- trunk/Source/WebKit/ChangeLog	2012-08-11 02:33:14 UTC (rev 125348)
+++ trunk/Source/WebKit/ChangeLog	2012-08-11 02:45:06 UTC (rev 125349)
@@ -1,3 +1,15 @@
+2012-08-10  Joshua Netterfield  <[email protected]>
+
+        [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  <[email protected]>
 
         Introduce _javascript_Variant object.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to