<!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>[166563] 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/166563">166563</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-03-31 22:37:12 -0700 (Mon, 31 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WebGL][OpenGLES] Enable MSAA support for WebGL Canvas
https://bugs.webkit.org/show_bug.cgi?id=130955

Patch by Byungseon Shin &lt;sun.shin@lge.com&gt; on 2014-03-31
Reviewed by Dean Jackson.

To avoid aliasing issues when we render content to WebGL canvas,
 we need to implement MSAA support.
- Imagination OpenGLES GPU Driver already support MSAA, so we
 need a separate code path to enable it.

* platform/graphics/Extensions3D.h:
* platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
(WebCore::Extensions3DOpenGLCommon::Extensions3DOpenGLCommon):
* platform/graphics/opengl/Extensions3DOpenGLCommon.h:
(WebCore::Extensions3DOpenGLCommon::isImagination):
* platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
(WebCore::GraphicsContext3D::reshapeFBOs):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsExtensions3Dh">trunk/Source/WebCore/platform/graphics/Extensions3D.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsopenglExtensions3DOpenGLCommoncpp">trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsopenglExtensions3DOpenGLCommonh">trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsopenglGraphicsContext3DOpenGLEScpp">trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (166562 => 166563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-01 02:45:28 UTC (rev 166562)
+++ trunk/Source/WebCore/ChangeLog        2014-04-01 05:37:12 UTC (rev 166563)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2014-03-31  Byungseon Shin  &lt;sun.shin@lge.com&gt;
+
+        [WebGL][OpenGLES] Enable MSAA support for WebGL Canvas
+        https://bugs.webkit.org/show_bug.cgi?id=130955
+
+        Reviewed by Dean Jackson.
+
+        To avoid aliasing issues when we render content to WebGL canvas,
+         we need to implement MSAA support.
+        - Imagination OpenGLES GPU Driver already support MSAA, so we
+         need a separate code path to enable it.
+
+        * platform/graphics/Extensions3D.h:
+        * platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
+        (WebCore::Extensions3DOpenGLCommon::Extensions3DOpenGLCommon):
+        * platform/graphics/opengl/Extensions3DOpenGLCommon.h:
+        (WebCore::Extensions3DOpenGLCommon::isImagination):
+        * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
+        (WebCore::GraphicsContext3D::reshapeFBOs):
+
</ins><span class="cx"> 2014-03-31  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Crashes in PageConsole::addMessage
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsExtensions3Dh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Extensions3D.h (166562 => 166563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Extensions3D.h        2014-04-01 02:45:28 UTC (rev 166562)
+++ trunk/Source/WebCore/platform/graphics/Extensions3D.h        2014-04-01 05:37:12 UTC (rev 166563)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx">     //   GL_ARB_texture_non_power_of_two / GL_OES_texture_npot
</span><span class="cx">     //   GL_EXT_packed_depth_stencil / GL_OES_packed_depth_stencil
</span><span class="cx">     //   GL_ANGLE_framebuffer_blit / GL_ANGLE_framebuffer_multisample
</span><ins>+    //   GL_IMG_multisampled_render_to_texture
</ins><span class="cx">     //   GL_OES_texture_float
</span><span class="cx">     //   GL_OES_texture_float_linear
</span><span class="cx">     //   GL_OES_texture_half_float
</span><span class="lines">@@ -111,6 +112,12 @@
</span><span class="cx">         FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56,
</span><span class="cx">         MAX_SAMPLES = 0x8D57,
</span><span class="cx"> 
</span><ins>+        // GL_IMG_multisampled_render_to_texture
+        RENDERBUFFER_SAMPLES_IMG = 0x9133,
+        FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG = 0x9134,
+        MAX_SAMPLES_IMG = 0x9135,
+        TEXTURE_SAMPLES_IMG = 0x9136,
+
</ins><span class="cx">         // GL_OES_standard_derivatives names
</span><span class="cx">         FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B,
</span><span class="cx"> 
</span><span class="lines">@@ -235,6 +242,7 @@
</span><span class="cx">     virtual bool isNVIDIA() = 0;
</span><span class="cx">     virtual bool isAMD() = 0;
</span><span class="cx">     virtual bool isIntel() = 0;
</span><ins>+    virtual bool isImagination() = 0;
</ins><span class="cx">     virtual String vendor() = 0;
</span><span class="cx"> 
</span><span class="cx">     // If this method returns false then the system *definitely* does not support multisampling.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsopenglExtensions3DOpenGLCommoncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp (166562 => 166563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp        2014-04-01 02:45:28 UTC (rev 166562)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp        2014-04-01 05:37:12 UTC (rev 166563)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx">     , m_isNVIDIA(false)
</span><span class="cx">     , m_isAMD(false)
</span><span class="cx">     , m_isIntel(false)
</span><ins>+    , m_isImagination(false)
</ins><span class="cx">     , m_maySupportMultisampling(true)
</span><span class="cx">     , m_requiresBuiltInFunctionEmulation(false)
</span><span class="cx"> {
</span><span class="lines">@@ -70,6 +71,8 @@
</span><span class="cx">         m_isAMD = true;
</span><span class="cx">     if (vendorComponents.contains(&quot;intel&quot;))
</span><span class="cx">         m_isIntel = true;
</span><ins>+    if (vendorComponents.contains(&quot;imagination&quot;))
+        m_isImagination = true;
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     if (m_isAMD || m_isIntel)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsopenglExtensions3DOpenGLCommonh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h (166562 => 166563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h        2014-04-01 02:45:28 UTC (rev 166562)
+++ trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h        2014-04-01 05:37:12 UTC (rev 166563)
</span><span class="lines">@@ -62,6 +62,7 @@
</span><span class="cx">     virtual bool isNVIDIA() { return m_isNVIDIA; }
</span><span class="cx">     virtual bool isAMD() { return m_isAMD; }
</span><span class="cx">     virtual bool isIntel() { return m_isIntel; }
</span><ins>+    virtual bool isImagination() { return m_isImagination; }
</ins><span class="cx">     virtual String vendor() { return m_vendor; }
</span><span class="cx"> 
</span><span class="cx">     virtual bool maySupportMultisampling() { return m_maySupportMultisampling; }
</span><span class="lines">@@ -84,6 +85,7 @@
</span><span class="cx">     bool m_isNVIDIA;
</span><span class="cx">     bool m_isAMD;
</span><span class="cx">     bool m_isIntel;
</span><ins>+    bool m_isImagination;
</ins><span class="cx">     bool m_maySupportMultisampling;
</span><span class="cx">     bool m_requiresBuiltInFunctionEmulation;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsopenglGraphicsContext3DOpenGLEScpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp (166562 => 166563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp        2014-04-01 02:45:28 UTC (rev 166562)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp        2014-04-01 05:37:12 UTC (rev 166563)
</span><span class="lines">@@ -110,30 +110,58 @@
</span><span class="cx">         ::glBindTexture(GL_TEXTURE_2D, 0);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // We don't support antialiasing yet. See GraphicsContext3D::validateAttributes.
-    ASSERT(!m_attrs.antialias);
</del><ins>+    if (extensions-&gt;isImagination() &amp;&amp; m_attrs.antialias) {
+        GLint maxSampleCount;
+        ::glGetIntegerv(Extensions3D::MAX_SAMPLES_IMG, &amp;maxSampleCount); 
+        GLint sampleCount = std::min(8, maxSampleCount);
</ins><span class="cx"> 
</span><del>-    if (m_attrs.stencil || m_attrs.depth) {
-        // Use a 24 bit depth buffer where we know we have it.
-        if (supportPackedDepthStencilBuffer) {
-            ::glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
-            ::glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
-            if (m_attrs.stencil)
-                ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
-            if (m_attrs.depth)
-                ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
</del><ins>+        extensions-&gt;framebufferTexture2DMultisampleIMG(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0, sampleCount);
+
+        if (m_attrs.stencil || m_attrs.depth) {
+            // Use a 24 bit depth buffer where we know we have it.
+            if (supportPackedDepthStencilBuffer) {
+                ::glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
+                extensions-&gt;renderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_DEPTH24_STENCIL8_OES, width, height);
+                if (m_attrs.stencil)
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
+                if (m_attrs.depth)
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
+            } else {
+                if (m_attrs.stencil) {
+                    ::glBindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer);
+                    extensions-&gt;renderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_STENCIL_INDEX8, width, height);
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilBuffer);
+                }
+                if (m_attrs.depth) {
+                    ::glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
+                    extensions-&gt;renderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_DEPTH_COMPONENT16, width, height);
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer);
+                }
+            }
</ins><span class="cx">             ::glBindRenderbuffer(GL_RENDERBUFFER, 0);
</span><del>-        } else {
-            if (m_attrs.stencil) {
-                ::glBindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer);
-                ::glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
-                ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilBuffer);
</del><ins>+        }
+    } else {
+        if (m_attrs.stencil || m_attrs.depth) {
+            // Use a 24 bit depth buffer where we know we have it.
+            if (supportPackedDepthStencilBuffer) {
+                ::glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
+                ::glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
+                if (m_attrs.stencil)
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
+                if (m_attrs.depth)
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
+            } else {
+                if (m_attrs.stencil) {
+                    ::glBindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer);
+                    ::glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilBuffer);
+                }
+                if (m_attrs.depth) {
+                    ::glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
+                    ::glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
+                    ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer);
+                }
</ins><span class="cx">             }
</span><del>-            if (m_attrs.depth) {
-                ::glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
-                ::glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
-                ::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer);
-            }
</del><span class="cx">             ::glBindRenderbuffer(GL_RENDERBUFFER, 0);
</span><span class="cx">         }
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>