<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[164744] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/164744">164744</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2014-02-26 13:31:38 -0800 (Wed, 26 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WebGL] Protect more WebGL entry points for pending contexts
https://bugs.webkit.org/show_bug.cgi?id=129386

Reviewed by Tim Horton.

There are entry points into a WebGLRenderingContext that don't
come from the web-exposed API directly, such as drawImage with
the WebGL canvas. Protect these by returning early if we're
a pending context.

Also a bunch of drive-by 0 -&gt; nullptr changes.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::markLayerComposited):
(WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
(WebCore::WebGLRenderingContext::paintRenderingResultsToImageData):
(WebCore::WebGLRenderingContext::reshape):
(WebCore::WebGLRenderingContext::createBuffer):
(WebCore::WebGLRenderingContext::createFramebuffer):
(WebCore::WebGLRenderingContext::createTexture):
(WebCore::WebGLRenderingContext::createProgram):
(WebCore::WebGLRenderingContext::createRenderbuffer):
(WebCore::WebGLRenderingContext::createShader):
(WebCore::WebGLRenderingContext::getActiveAttrib):
(WebCore::WebGLRenderingContext::getActiveUniform):
(WebCore::WebGLRenderingContext::getContextAttributes):
(WebCore::WebGLRenderingContext::getError):
(WebCore::WebGLRenderingContext::getExtension):
(WebCore::WebGLRenderingContext::getShaderPrecisionFormat):
(WebCore::WebGLRenderingContext::getUniformLocation):
(WebCore::WebGLRenderingContext::drawImageIntoBuffer):
(WebCore::WebGLRenderingContext::videoFrameToImage):
(WebCore::WebGLRenderingContext::validateBufferDataParameters):
(WebCore::WebGLRenderingContext::LRUImageBufferCache::imageBuffer):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlcanvasWebGLRenderingContextcpp">trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164743 => 164744)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-26 21:27:10 UTC (rev 164743)
+++ trunk/Source/WebCore/ChangeLog        2014-02-26 21:31:38 UTC (rev 164744)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2014-02-26  Dean Jackson  &lt;dino@apple.com&gt;
+
+        [WebGL] Protect more WebGL entry points for pending contexts
+        https://bugs.webkit.org/show_bug.cgi?id=129386
+
+        Reviewed by Tim Horton.
+
+        There are entry points into a WebGLRenderingContext that don't
+        come from the web-exposed API directly, such as drawImage with
+        the WebGL canvas. Protect these by returning early if we're
+        a pending context.
+
+        Also a bunch of drive-by 0 -&gt; nullptr changes.
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::markLayerComposited):
+        (WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
+        (WebCore::WebGLRenderingContext::paintRenderingResultsToImageData):
+        (WebCore::WebGLRenderingContext::reshape):
+        (WebCore::WebGLRenderingContext::createBuffer):
+        (WebCore::WebGLRenderingContext::createFramebuffer):
+        (WebCore::WebGLRenderingContext::createTexture):
+        (WebCore::WebGLRenderingContext::createProgram):
+        (WebCore::WebGLRenderingContext::createRenderbuffer):
+        (WebCore::WebGLRenderingContext::createShader):
+        (WebCore::WebGLRenderingContext::getActiveAttrib):
+        (WebCore::WebGLRenderingContext::getActiveUniform):
+        (WebCore::WebGLRenderingContext::getContextAttributes):
+        (WebCore::WebGLRenderingContext::getError):
+        (WebCore::WebGLRenderingContext::getExtension):
+        (WebCore::WebGLRenderingContext::getShaderPrecisionFormat):
+        (WebCore::WebGLRenderingContext::getUniformLocation):
+        (WebCore::WebGLRenderingContext::drawImageIntoBuffer):
+        (WebCore::WebGLRenderingContext::videoFrameToImage):
+        (WebCore::WebGLRenderingContext::validateBufferDataParameters):
+        (WebCore::WebGLRenderingContext::LRUImageBufferCache::imageBuffer):
+
</ins><span class="cx"> 2014-02-26  Bem Jones-Bey  &lt;bjonesbe@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Shapes] inset and inset-rectangle trigger assert with replaced element and large percentage dimension
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlcanvasWebGLRenderingContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (164743 => 164744)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp        2014-02-26 21:27:10 UTC (rev 164743)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp        2014-02-26 21:31:38 UTC (rev 164744)
</span><span class="lines">@@ -764,11 +764,16 @@
</span><span class="cx"> 
</span><span class="cx"> void WebGLRenderingContext::markLayerComposited()
</span><span class="cx"> {
</span><ins>+    if (isContextLostOrPending())
+        return;
</ins><span class="cx">     m_context-&gt;markLayerComposited();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebGLRenderingContext::paintRenderingResultsToCanvas()
</span><span class="cx"> {
</span><ins>+    if (isContextLostOrPending())
+        return;
+
</ins><span class="cx">     if (canvas()-&gt;document().printing())
</span><span class="cx">         canvas()-&gt;clearPresentationCopy();
</span><span class="cx"> 
</span><span class="lines">@@ -802,6 +807,8 @@
</span><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;ImageData&gt; WebGLRenderingContext::paintRenderingResultsToImageData()
</span><span class="cx"> {
</span><ins>+    if (isContextLostOrPending())
+        return nullptr;
</ins><span class="cx">     clearIfComposited();
</span><span class="cx">     if (m_drawingBuffer)
</span><span class="cx">         m_drawingBuffer-&gt;commit();
</span><span class="lines">@@ -819,6 +826,9 @@
</span><span class="cx"> 
</span><span class="cx"> void WebGLRenderingContext::reshape(int width, int height)
</span><span class="cx"> {
</span><ins>+    if (isContextLostOrPending())
+        return;
+
</ins><span class="cx">     // This is an approximation because at WebGLRenderingContext level we don't
</span><span class="cx">     // know if the underlying FBO uses textures or renderbuffers.
</span><span class="cx">     GC3Dint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize);
</span><span class="lines">@@ -1508,7 +1518,7 @@
</span><span class="cx"> PassRefPtr&lt;WebGLBuffer&gt; WebGLRenderingContext::createBuffer()
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     RefPtr&lt;WebGLBuffer&gt; o = WebGLBuffer::create(this);
</span><span class="cx">     addSharedObject(o.get());
</span><span class="cx">     return o;
</span><span class="lines">@@ -1517,7 +1527,7 @@
</span><span class="cx"> PassRefPtr&lt;WebGLFramebuffer&gt; WebGLRenderingContext::createFramebuffer()
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     RefPtr&lt;WebGLFramebuffer&gt; o = WebGLFramebuffer::create(this);
</span><span class="cx">     addContextObject(o.get());
</span><span class="cx">     return o;
</span><span class="lines">@@ -1526,7 +1536,7 @@
</span><span class="cx"> PassRefPtr&lt;WebGLTexture&gt; WebGLRenderingContext::createTexture()
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     RefPtr&lt;WebGLTexture&gt; o = WebGLTexture::create(this);
</span><span class="cx">     addSharedObject(o.get());
</span><span class="cx">     return o;
</span><span class="lines">@@ -1535,7 +1545,7 @@
</span><span class="cx"> PassRefPtr&lt;WebGLProgram&gt; WebGLRenderingContext::createProgram()
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     RefPtr&lt;WebGLProgram&gt; o = WebGLProgram::create(this);
</span><span class="cx">     addSharedObject(o.get());
</span><span class="cx">     return o;
</span><span class="lines">@@ -1544,7 +1554,7 @@
</span><span class="cx"> PassRefPtr&lt;WebGLRenderbuffer&gt; WebGLRenderingContext::createRenderbuffer()
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     RefPtr&lt;WebGLRenderbuffer&gt; o = WebGLRenderbuffer::create(this);
</span><span class="cx">     addSharedObject(o.get());
</span><span class="cx">     return o;
</span><span class="lines">@@ -1554,10 +1564,10 @@
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(ec);
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     if (type != GraphicsContext3D::VERTEX_SHADER &amp;&amp; type != GraphicsContext3D::FRAGMENT_SHADER) {
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, &quot;createShader&quot;, &quot;invalid shader type&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;WebGLShader&gt; o = WebGLShader::create(this, type);
</span><span class="lines">@@ -2266,10 +2276,10 @@
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(ec);
</span><span class="cx">     if (isContextLostOrPending() || !validateWebGLObject(&quot;getActiveAttrib&quot;, program))
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     ActiveInfo info;
</span><span class="cx">     if (!m_context-&gt;getActiveAttrib(objectOrZero(program), index, info))
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx"> 
</span><span class="cx">     LOG(WebGL, &quot;Returning active attribute %d: %s&quot;, index, info.name.utf8().data());
</span><span class="cx"> 
</span><span class="lines">@@ -2283,7 +2293,7 @@
</span><span class="cx">         return 0;
</span><span class="cx">     ActiveInfo info;
</span><span class="cx">     if (!m_context-&gt;getActiveUniform(objectOrZero(program), index, info))
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     if (!isGLES2Compliant())
</span><span class="cx">         if (info.size &gt; 1 &amp;&amp; !info.name.endsWith(&quot;[0]&quot;))
</span><span class="cx">             info.name.append(&quot;[0]&quot;);
</span><span class="lines">@@ -2354,7 +2364,7 @@
</span><span class="cx"> PassRefPtr&lt;WebGLContextAttributes&gt; WebGLRenderingContext::getContextAttributes()
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     // We always need to return a new WebGLContextAttributes object to
</span><span class="cx">     // prevent the user from mutating any cached version.
</span><span class="cx"> 
</span><span class="lines">@@ -2376,13 +2386,15 @@
</span><span class="cx"> 
</span><span class="cx"> GC3Denum WebGLRenderingContext::getError()
</span><span class="cx"> {
</span><ins>+    if (isContextLostOrPending())
+        return GraphicsContext3D::NO_ERROR;
</ins><span class="cx">     return m_context-&gt;getError();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebGLExtension* WebGLRenderingContext::getExtension(const String&amp; name)
</span><span class="cx"> {
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx"> 
</span><span class="cx">     if (equalIgnoringCase(name, &quot;WEBKIT_EXT_texture_filter_anisotropic&quot;)
</span><span class="cx">         &amp;&amp; m_context-&gt;getExtensions()-&gt;supports(&quot;GL_EXT_texture_filter_anisotropic&quot;)) {
</span><span class="lines">@@ -2506,7 +2518,7 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return 0;
</del><ins>+    return nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebGLGetInfo WebGLRenderingContext::getFramebufferAttachmentParameter(GC3Denum target, GC3Denum attachment, GC3Denum pname, ExceptionCode&amp; ec)
</span><span class="lines">@@ -2938,14 +2950,14 @@
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(ec);
</span><span class="cx">     if (isContextLostOrPending())
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     switch (shaderType) {
</span><span class="cx">     case GraphicsContext3D::VERTEX_SHADER:
</span><span class="cx">     case GraphicsContext3D::FRAGMENT_SHADER:
</span><span class="cx">         break;
</span><span class="cx">     default:
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, &quot;getShaderPrecisionFormat&quot;, &quot;invalid shader type&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx">     switch (precisionType) {
</span><span class="cx">     case GraphicsContext3D::LOW_FLOAT:
</span><span class="lines">@@ -2957,7 +2969,7 @@
</span><span class="cx">         break;
</span><span class="cx">     default:
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, &quot;getShaderPrecisionFormat&quot;, &quot;invalid precision type&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     GC3Dint range[2] = {0, 0};
</span><span class="lines">@@ -3199,7 +3211,7 @@
</span><span class="cx">     for (GC3Dint i = 0; i &lt; activeUniforms; i++) {
</span><span class="cx">         ActiveInfo info;
</span><span class="cx">         if (!m_context-&gt;getActiveUniform(objectOrZero(program), i, info))
</span><del>-            return 0;
</del><ins>+            return nullptr;
</ins><span class="cx">         // Strip &quot;[0]&quot; from the name if it's an array.
</span><span class="cx">         if (info.name.endsWith(&quot;[0]&quot;))
</span><span class="cx">             info.name = info.name.left(info.name.length() - 3);
</span><span class="lines">@@ -3860,7 +3872,7 @@
</span><span class="cx">     ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
</span><span class="cx">     if (!buf) {
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, &quot;texImage2D&quot;, &quot;out of memory&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     IntRect srcRect(IntPoint(), image-&gt;size());
</span><span class="lines">@@ -3922,7 +3934,7 @@
</span><span class="cx">     ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
</span><span class="cx">     if (!buf) {
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, &quot;texImage2D&quot;, &quot;out of memory&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx">     IntRect destRect(0, 0, size.width(), size.height());
</span><span class="cx">     // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback.
</span><span class="lines">@@ -5612,11 +5624,11 @@
</span><span class="cx">         break;
</span><span class="cx">     default:
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, &quot;invalid target&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx">     if (!buffer) {
</span><span class="cx">         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, &quot;no buffer&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx">     switch (usage) {
</span><span class="cx">     case GraphicsContext3D::STREAM_DRAW:
</span><span class="lines">@@ -5625,7 +5637,7 @@
</span><span class="cx">         return buffer;
</span><span class="cx">     }
</span><span class="cx">     synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, &quot;invalid usage&quot;);
</span><del>-    return 0;
</del><ins>+    return nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, HTMLImageElement* image, ExceptionCode&amp; ec)
</span><span class="lines">@@ -5953,7 +5965,7 @@
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;ImageBuffer&gt; temp = ImageBuffer::create(size, 1);
</span><span class="cx">     if (!temp)
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     i = std::min(m_capacity - 1, i);
</span><span class="cx">     m_buffers[i] = std::move(temp);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>