<!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>[170271] 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/170271">170271</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2014-06-22 17:00:03 -0700 (Sun, 22 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Apple] WebGL layer may use GC3D after free with remote layer hosting
https://bugs.webkit.org/show_bug.cgi?id=134179
&lt;rdar://problem/17412931&gt;

Reviewed by Tim Horton.

With remote layer hosting, a WebGLLayer may attempt to draw after
the GraphicsContext3D has been destroyed. We need to make sure
the GC3D tells the WebGLLayer that it is no longer valid.

While here, I changed some return 0 to return nullptr, the
name of the ObjC property member from m_context to _context,
and removed some unnecessary .get() calls.

This is tested by run-webkit-tests with the --remote-layer-tree
option.

* platform/graphics/mac/GraphicsContext3DMac.mm:
(WebCore::GraphicsContext3D::GraphicsContext3D): No need for .get().
(WebCore::GraphicsContext3D::~GraphicsContext3D): Set the context reference on WebGLLayer
to be null.
(WebCore::GraphicsContext3D::setRenderbufferStorageFromDrawable): No need for .get().
* platform/graphics/mac/WebGLLayer.h: Set the context reference on WebGLLayer
to be null.
* platform/graphics/mac/WebGLLayer.mm:
(-[WebGLLayer initWithGraphicsContext3D:]): Rename m_context to _context.
(-[WebGLLayer copyCGLPixelFormatForDisplayMask:]): Check for null.
(-[WebGLLayer copyCGLContextForPixelFormat:]): Rename to _context.
(-[WebGLLayer drawInCGLContext:pixelFormat:forLayerTime:displayTime:]): Check for null.
(-[WebGLLayer copyImageSnapshotWithColorSpace:]): Ditto.
(-[WebGLLayer display]): Ditto.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacGraphicsContext3DMacmm">trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacWebGLLayerh">trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacWebGLLayermm">trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (170270 => 170271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-06-22 18:35:32 UTC (rev 170270)
+++ trunk/Source/WebCore/ChangeLog        2014-06-23 00:00:03 UTC (rev 170271)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2014-06-22  Dean Jackson  &lt;dino@apple.com&gt;
+
+        [Apple] WebGL layer may use GC3D after free with remote layer hosting
+        https://bugs.webkit.org/show_bug.cgi?id=134179
+        &lt;rdar://problem/17412931&gt;
+
+        Reviewed by Tim Horton.
+
+        With remote layer hosting, a WebGLLayer may attempt to draw after
+        the GraphicsContext3D has been destroyed. We need to make sure
+        the GC3D tells the WebGLLayer that it is no longer valid.
+
+        While here, I changed some return 0 to return nullptr, the
+        name of the ObjC property member from m_context to _context,
+        and removed some unnecessary .get() calls.
+
+        This is tested by run-webkit-tests with the --remote-layer-tree
+        option.
+
+        * platform/graphics/mac/GraphicsContext3DMac.mm:
+        (WebCore::GraphicsContext3D::GraphicsContext3D): No need for .get().
+        (WebCore::GraphicsContext3D::~GraphicsContext3D): Set the context reference on WebGLLayer
+        to be null.
+        (WebCore::GraphicsContext3D::setRenderbufferStorageFromDrawable): No need for .get().
+        * platform/graphics/mac/WebGLLayer.h: Set the context reference on WebGLLayer
+        to be null.
+        * platform/graphics/mac/WebGLLayer.mm:
+        (-[WebGLLayer initWithGraphicsContext3D:]): Rename m_context to _context.
+        (-[WebGLLayer copyCGLPixelFormatForDisplayMask:]): Check for null.
+        (-[WebGLLayer copyCGLContextForPixelFormat:]): Rename to _context.
+        (-[WebGLLayer drawInCGLContext:pixelFormat:forLayerTime:displayTime:]): Check for null.
+        (-[WebGLLayer copyImageSnapshotWithColorSpace:]): Ditto.
+        (-[WebGLLayer display]): Ditto.
+
</ins><span class="cx"> 2014-06-20  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2] Frameset frames are not scrollable after loading (and should be)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacGraphicsContext3DMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm (170270 => 170271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm        2014-06-22 18:35:32 UTC (rev 170270)
+++ trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm        2014-06-23 00:00:03 UTC (rev 170271)
</span><span class="lines">@@ -223,11 +223,11 @@
</span><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS
</span><span class="cx">         m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithGraphicsContext3D:this]);
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-        [m_webGLLayer.get() setOpaque:0];
</del><ins>+        [m_webGLLayer setOpaque:0];
</ins><span class="cx"> #endif
</span><span class="cx"> #ifndef NDEBUG
</span><del>-        [m_webGLLayer.get() setName:@&quot;WebGL Layer&quot;];
-#endif    
</del><ins>+        [m_webGLLayer setName:@&quot;WebGL Layer&quot;];
+#endif
</ins><span class="cx">     END_BLOCK_OBJC_EXCEPTIONS
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="lines">@@ -332,6 +332,7 @@
</span><span class="cx">         CGLSetCurrentContext(0);
</span><span class="cx">         CGLDestroyContext(m_contextObj);
</span><span class="cx"> #endif
</span><ins>+        [m_webGLLayer setContext:nullptr];
</ins><span class="cx">         numActiveContexts--;
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -339,7 +340,7 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> bool GraphicsContext3D::setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height)
</span><span class="cx"> {
</span><del>-    [m_webGLLayer.get() setBounds:CGRectMake(0, 0, width, height)];
</del><ins>+    [m_webGLLayer setBounds:CGRectMake(0, 0, width, height)];
</ins><span class="cx">     return [m_contextObj renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast&lt;NSObject&lt;EAGLDrawable&gt;*&gt;(m_webGLLayer.get())];
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacWebGLLayerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.h (170270 => 170271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.h        2014-06-22 18:35:32 UTC (rev 170270)
+++ trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.h        2014-06-23 00:00:03 UTC (rev 170271)
</span><span class="lines">@@ -39,9 +39,11 @@
</span><span class="cx"> @interface WebGLLayer : CAOpenGLLayer
</span><span class="cx"> #endif
</span><span class="cx"> {
</span><del>-    WebCore::GraphicsContext3D* m_context;
</del><ins>+    WebCore::GraphicsContext3D* _context;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+@property (nonatomic) WebCore::GraphicsContext3D* context;
+
</ins><span class="cx"> - (id)initWithGraphicsContext3D:(WebCore::GraphicsContext3D*)context;
</span><span class="cx"> 
</span><span class="cx"> - (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacWebGLLayermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.mm (170270 => 170271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.mm        2014-06-22 18:35:32 UTC (rev 170270)
+++ trunk/Source/WebCore/platform/graphics/mac/WebGLLayer.mm        2014-06-23 00:00:03 UTC (rev 170271)
</span><span class="lines">@@ -42,9 +42,11 @@
</span><span class="cx"> 
</span><span class="cx"> @implementation WebGLLayer
</span><span class="cx"> 
</span><ins>+@synthesize context=_context;
+
</ins><span class="cx"> -(id)initWithGraphicsContext3D:(GraphicsContext3D*)context
</span><span class="cx"> {
</span><del>-    m_context = context;
</del><ins>+    _context = context;
</ins><span class="cx">     self = [super init];
</span><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="lines">@@ -59,20 +61,23 @@
</span><span class="cx">     // If needed we will have to set the display mask in the Canvas CGLContext and
</span><span class="cx">     // make sure it matches.
</span><span class="cx">     UNUSED_PARAM(mask);
</span><del>-    return CGLRetainPixelFormat(CGLGetPixelFormat(m_context-&gt;platformGraphicsContext3D()));
</del><ins>+    return CGLRetainPixelFormat(CGLGetPixelFormat(_context-&gt;platformGraphicsContext3D()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> -(CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat
</span><span class="cx"> {
</span><span class="cx">     CGLContextObj contextObj;
</span><del>-    CGLCreateContext(pixelFormat, m_context-&gt;platformGraphicsContext3D(), &amp;contextObj);
</del><ins>+    CGLCreateContext(pixelFormat, _context-&gt;platformGraphicsContext3D(), &amp;contextObj);
</ins><span class="cx">     return contextObj;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
</span><span class="cx"> {
</span><del>-    m_context-&gt;prepareTexture();
</del><ins>+    if (!_context)
+        return;
</ins><span class="cx"> 
</span><ins>+    _context-&gt;prepareTexture();
+
</ins><span class="cx">     CGLSetCurrentContext(glContext);
</span><span class="cx"> 
</span><span class="cx">     CGRect frame = [self frame];
</span><span class="lines">@@ -86,7 +91,7 @@
</span><span class="cx">     glLoadIdentity();
</span><span class="cx"> 
</span><span class="cx">     glEnable(GL_TEXTURE_2D);
</span><del>-    glBindTexture(GL_TEXTURE_2D, m_context-&gt;platformTexture());
</del><ins>+    glBindTexture(GL_TEXTURE_2D, _context-&gt;platformTexture());
</ins><span class="cx">     
</span><span class="cx">     glBegin(GL_TRIANGLE_FAN);
</span><span class="cx">         glTexCoord2f(0, 0);
</span><span class="lines">@@ -114,11 +119,14 @@
</span><span class="cx"> 
</span><span class="cx"> -(CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace
</span><span class="cx"> {
</span><ins>+    if (!_context)
+        return nullptr;
+
</ins><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     UNUSED_PARAM(colorSpace);
</span><del>-    return 0;
</del><ins>+    return nullptr;
</ins><span class="cx"> #else
</span><del>-    CGLSetCurrentContext(m_context-&gt;platformGraphicsContext3D());
</del><ins>+    CGLSetCurrentContext(_context-&gt;platformGraphicsContext3D());
</ins><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;CGColorSpaceRef&gt; imageColorSpace = colorSpace;
</span><span class="cx">     if (!imageColorSpace)
</span><span class="lines">@@ -133,7 +141,7 @@
</span><span class="cx">     size_t dataSize = rowBytes * height;
</span><span class="cx">     void* data = fastMalloc(dataSize);
</span><span class="cx">     if (!data)
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx"> 
</span><span class="cx">     glPixelStorei(GL_PACK_ROW_LENGTH, rowBytes / 4);
</span><span class="cx">     glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
</span><span class="lines">@@ -150,12 +158,15 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)display
</span><span class="cx"> {
</span><ins>+    if (!_context)
+        return;
+
</ins><span class="cx"> #if PLATFORM(IOS)
</span><del>-    m_context-&gt;endPaint();
</del><ins>+    _context-&gt;endPaint();
</ins><span class="cx"> #else
</span><span class="cx">     [super display];
</span><span class="cx"> #endif
</span><del>-    m_context-&gt;markLayerComposited();
</del><ins>+    _context-&gt;markLayerComposited();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre>
</div>
</div>

</body>
</html>