<!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>[203862] branches/safari-602-branch/Source</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/203862">203862</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2016-07-29 00:11:14 -0700 (Fri, 29 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/203631">r203631</a>. rdar://problem/24606557</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebCoreChangeLog">branches/safari-602-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformgraphicscgImageBufferCGcpp">branches/safari-602-branch/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformgraphicscocoaIOSurfaceh">branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformgraphicscocoaIOSurfacemm">branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2ChangeLog">branches/safari-602-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebKit2SharedmacRemoteLayerBackingStoremm">branches/safari-602-branch/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessAPICocoaWKWebViewmm">branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/ChangeLog        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -1,5 +1,30 @@
</span><span class="cx"> 2016-07-28  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r203631. rdar://problem/24606557
+
+    2016-07-22  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+            Handle cases when IOSurface initialization fails.
+            https://bugs.webkit.org/show_bug.cgi?id=160006
+            &lt;rdar://problem/27495102&gt;
+
+            Reviewed by Tim Horton and Simon Fraser.
+
+            This is an additional fix to r203514 to check if IOSurface initialization was successful.
+
+            Unable to test.
+
+            * platform/graphics/cg/ImageBufferCG.cpp:
+            (WebCore::ImageBuffer::ImageBuffer):
+            * platform/graphics/cocoa/IOSurface.h: Merge 2 c'tors.
+            * platform/graphics/cocoa/IOSurface.mm: Remove redundant IOSurface::create() code.
+            (WebCore::IOSurface::create):
+            (WebCore::IOSurface::createFromImage):
+            (WebCore::IOSurface::IOSurface):
+            (WebCore::IOSurface::convertToFormat):
+
+2016-07-28  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
</ins><span class="cx">         Merge r203629. rdar://problem/27438936
</span><span class="cx"> 
</span><span class="cx">     2016-07-22  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformgraphicscgImageBufferCGcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -154,13 +154,14 @@
</span><span class="cx"> #if USE(IOSURFACE_CANVAS_BACKING_STORE)
</span><span class="cx">         FloatSize userBounds = sizeForDestinationSize(FloatSize(width.unsafeGet(), height.unsafeGet()));
</span><span class="cx">         m_data.surface = IOSurface::create(m_data.backingStoreSize, IntSize(userBounds), colorSpace);
</span><del>-        cgContext = m_data.surface-&gt;ensurePlatformContext();
-        if (cgContext)
-            CGContextClearRect(cgContext.get(), FloatRect(FloatPoint(), userBounds));
-        else
-            m_data.surface = nullptr;
</del><ins>+        if (m_data.surface) {
+            cgContext = m_data.surface-&gt;ensurePlatformContext();
+            if (cgContext)
+                CGContextClearRect(cgContext.get(), FloatRect(FloatPoint(), userBounds));
+            else
+                m_data.surface = nullptr;
+        }
</ins><span class="cx"> #endif
</span><del>-
</del><span class="cx">         if (!cgContext)
</span><span class="cx">             accelerateRendering = false; // If allocation fails, fall back to non-accelerated path.
</span><span class="cx">     }
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformgraphicscocoaIOSurfaceh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -100,8 +100,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    IOSurface(IntSize, CGColorSpaceRef, Format);
-    IOSurface(IntSize, IntSize contextSize, CGColorSpaceRef, Format);
</del><ins>+    IOSurface(IntSize, IntSize contextSize, CGColorSpaceRef, Format, bool&amp; success);
</ins><span class="cx">     IOSurface(IOSurfaceRef, CGColorSpaceRef);
</span><span class="cx"> 
</span><span class="cx">     static std::unique_ptr&lt;IOSurface&gt; surfaceFromPool(IntSize, IntSize contextSize, CGColorSpaceRef, Format);
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformgraphicscocoaIOSurfacemm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -57,10 +57,7 @@
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;WebCore::IOSurface&gt; WebCore::IOSurface::create(IntSize size, CGColorSpaceRef colorSpace, Format pixelFormat)
</span><span class="cx"> {
</span><del>-    if (auto cachedSurface = surfaceFromPool(size, size, colorSpace, pixelFormat))
-        return cachedSurface;
-
-    return std::unique_ptr&lt;IOSurface&gt;(new IOSurface(size, colorSpace, pixelFormat));
</del><ins>+    return IOSurface::create(size, size, colorSpace, pixelFormat);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;WebCore::IOSurface&gt; WebCore::IOSurface::create(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format pixelFormat)
</span><span class="lines">@@ -67,7 +64,11 @@
</span><span class="cx"> {
</span><span class="cx">     if (auto cachedSurface = surfaceFromPool(size, contextSize, colorSpace, pixelFormat))
</span><span class="cx">         return cachedSurface;
</span><del>-    return std::unique_ptr&lt;IOSurface&gt;(new IOSurface(size, contextSize, colorSpace, pixelFormat));
</del><ins>+    bool success = false;
+    auto surface = std::unique_ptr&lt;IOSurface&gt;(new IOSurface(size, contextSize, colorSpace, pixelFormat, success));
+    if (!success)
+        return nullptr;
+    return surface;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;WebCore::IOSurface&gt; WebCore::IOSurface::createFromSendRight(const MachSendRight&amp; sendRight, CGColorSpaceRef colorSpace)
</span><span class="lines">@@ -90,10 +91,11 @@
</span><span class="cx">     size_t height = CGImageGetHeight(image);
</span><span class="cx"> 
</span><span class="cx">     auto surface = IOSurface::create(IntSize(width, height), sRGBColorSpaceRef());
</span><ins>+    if (!surface)
+        return nullptr;
</ins><span class="cx">     auto surfaceContext = surface-&gt;ensurePlatformContext();
</span><span class="cx">     CGContextDrawImage(surfaceContext, CGRectMake(0, 0, width, height), image);
</span><span class="cx">     CGContextFlush(surfaceContext);
</span><del>-
</del><span class="cx">     return surface;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -179,11 +181,15 @@
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebCore::IOSurface::IOSurface(IntSize size, CGColorSpaceRef colorSpace, Format format)
</del><ins>+WebCore::IOSurface::IOSurface(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format format, bool&amp; success)
</ins><span class="cx">     : m_colorSpace(colorSpace)
</span><span class="cx">     , m_size(size)
</span><del>-    , m_contextSize(size)
</del><ins>+    , m_contextSize(contextSize)
</ins><span class="cx"> {
</span><ins>+    ASSERT(!success);
+    ASSERT(contextSize.width() &lt;= size.width());
+    ASSERT(contextSize.height() &lt;= size.height());
+
</ins><span class="cx">     NSDictionary *options;
</span><span class="cx"> 
</span><span class="cx">     switch (format) {
</span><span class="lines">@@ -200,21 +206,14 @@
</span><span class="cx">         options = optionsForBiplanarSurface(size, '422f', 1, 1);
</span><span class="cx">         break;
</span><span class="cx">     }
</span><del>-    
</del><span class="cx">     m_surface = adoptCF(IOSurfaceCreate((CFDictionaryRef)options));
</span><del>-    m_totalBytes = IOSurfaceGetAllocSize(m_surface.get());
-    if (!m_surface)
-        NSLog(@&quot;Surface creation failed for options %@&quot;, options);
</del><ins>+    success = !!m_surface;
+    if (success)
+        m_totalBytes = IOSurfaceGetAllocSize(m_surface.get());
+    else
+        LOG_ALWAYS_ERROR(true, &quot;Surface creation failed for size: (%d %d) and format: (%d)&quot;, size.width(), size.height(), format);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebCore::IOSurface::IOSurface(IntSize size, IntSize contextSize, CGColorSpaceRef colorSpace, Format pixelFormat)
-    : IOSurface(size, colorSpace, pixelFormat)
-{
-    ASSERT(contextSize.width() &lt;= size.width());
-    ASSERT(contextSize.height() &lt;= size.height());
-    m_contextSize = contextSize;
-}
-
</del><span class="cx"> WebCore::IOSurface::IOSurface(IOSurfaceRef surface, CGColorSpaceRef colorSpace)
</span><span class="cx">     : m_colorSpace(colorSpace)
</span><span class="cx">     , m_surface(surface)
</span><span class="lines">@@ -396,8 +395,12 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto destinationSurface = IOSurface::create(inSurface-&gt;size(), inSurface-&gt;colorSpace(), format);
</span><ins>+    if (!destinationSurface) {
+        callback(nullptr);
+        return;
+    }
+
</ins><span class="cx">     IOSurfaceRef destinationIOSurfaceRef = destinationSurface-&gt;surface();
</span><del>-
</del><span class="cx">     IOSurfaceAcceleratorCompletion completion;
</span><span class="cx">     completion.completionRefCon = new std::function&lt;void(std::unique_ptr&lt;WebCore::IOSurface&gt;)&gt; (WTFMove(callback));
</span><span class="cx">     completion.completionRefCon2 = destinationSurface.release();
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/ChangeLog (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/ChangeLog        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebKit2/ChangeLog        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -1,5 +1,29 @@
</span><span class="cx"> 2016-07-28  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r203631. rdar://problem/24606557
+
+    2016-07-22  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+            Handle cases when IOSurface initialization fails.
+            https://bugs.webkit.org/show_bug.cgi?id=160006
+            &lt;rdar://problem/27495102&gt;
+
+            Reviewed by Tim Horton and Simon Fraser.
+
+            This is an additional fix to r203514 to check if IOSurface initialization was successful.
+
+            Unable to test.
+
+            * Shared/mac/RemoteLayerBackingStore.mm:
+            (WebKit::RemoteLayerBackingStore::encode):
+            (WebKit::RemoteLayerBackingStore::display):
+            (WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
+            * UIProcess/API/Cocoa/WKWebView.mm:
+            (-[WKWebView _takeViewSnapshot]):
+            (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
+
+2016-07-28  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
</ins><span class="cx">         Merge r203630. rdar://problem/27504958
</span><span class="cx"> 
</span><span class="cx">     2016-07-22  Chelsea Pugh  &lt;cpugh@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2SharedmacRemoteLayerBackingStoremm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -119,7 +119,10 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(IOSURFACE)
</span><span class="cx">     if (m_acceleratesDrawing) {
</span><del>-        encoder &lt;&lt; m_frontBuffer.surface-&gt;createSendRight();
</del><ins>+        if (m_frontBuffer.surface)
+            encoder &lt;&lt; m_frontBuffer.surface-&gt;createSendRight();
+        else
+            encoder &lt;&lt; WebCore::MachSendRight();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="lines">@@ -262,13 +265,15 @@
</span><span class="cx">         if (m_backBuffer.surface &amp;&amp; !willPaintEntireBackingStore)
</span><span class="cx">             backImage = m_backBuffer.surface-&gt;createImage();
</span><span class="cx"> 
</span><del>-        GraphicsContext&amp; context = m_frontBuffer.surface-&gt;ensureGraphicsContext();
</del><ins>+        if (m_frontBuffer.surface) {
+            GraphicsContext&amp; context = m_frontBuffer.surface-&gt;ensureGraphicsContext();
</ins><span class="cx"> 
</span><del>-        context.scale(FloatSize(1, -1));
-        context.translate(0, -expandedScaledSize.height());
-        drawInContext(context, backImage.get());
</del><ins>+            context.scale(FloatSize(1, -1));
+            context.translate(0, -expandedScaledSize.height());
+            drawInContext(context, backImage.get());
</ins><span class="cx"> 
</span><del>-        m_frontBuffer.surface-&gt;releaseGraphicsContext();
</del><ins>+            m_frontBuffer.surface-&gt;releaseGraphicsContext();
+        }
</ins><span class="cx">     } else
</span><span class="cx"> #endif
</span><span class="cx">     {
</span><span class="lines">@@ -400,7 +405,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(IOSURFACE)
</span><span class="cx">     if (acceleratesDrawing()) {
</span><del>-        layer.contents = m_frontBuffer.surface-&gt;asLayerContents();
</del><ins>+        layer.contents = m_frontBuffer.surface ? m_frontBuffer.surface-&gt;asLayerContents() : nil;
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (203861 => 203862)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2016-07-29 07:11:10 UTC (rev 203861)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2016-07-29 07:11:14 UTC (rev 203862)
</span><span class="lines">@@ -1388,6 +1388,8 @@
</span><span class="cx"> #if USE(IOSURFACE)
</span><span class="cx">     WebCore::IOSurface::Format snapshotFormat = WebCore::screenSupportsExtendedColor() ? WebCore::IOSurface::Format::RGB10 : WebCore::IOSurface::Format::RGBA;
</span><span class="cx">     auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(snapshotSize), WebCore::sRGBColorSpaceRef(), snapshotFormat);
</span><ins>+    if (!surface)
+        return nullptr;
</ins><span class="cx">     CARenderServerRenderLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, reinterpret_cast&lt;uint64_t&gt;(self.layer), surface-&gt;surface(), 0, 0, &amp;transform);
</span><span class="cx"> 
</span><span class="cx">     WebCore::IOSurface::Format compressedFormat = WebCore::IOSurface::Format::YUV422;
</span><span class="lines">@@ -1394,7 +1396,8 @@
</span><span class="cx">     if (WebCore::IOSurface::allowConversionFromFormatToFormat(snapshotFormat, compressedFormat)) {
</span><span class="cx">         RefPtr&lt;WebKit::ViewSnapshot&gt; viewSnapshot = WebKit::ViewSnapshot::create(nullptr);
</span><span class="cx">         WebCore::IOSurface::convertToFormat(WTFMove(surface), WebCore::IOSurface::Format::YUV422, [viewSnapshot](std::unique_ptr&lt;WebCore::IOSurface&gt; convertedSurface) {
</span><del>-            viewSnapshot-&gt;setSurface(WTFMove(convertedSurface));
</del><ins>+            if (convertedSurface)
+                viewSnapshot-&gt;setSurface(WTFMove(convertedSurface));
</ins><span class="cx">         });
</span><span class="cx"> 
</span><span class="cx">         return viewSnapshot;
</span><span class="lines">@@ -4235,6 +4238,10 @@
</span><span class="cx">     // If we are parented and thus won't incur a significant penalty from paging in tiles, snapshot the view hierarchy directly.
</span><span class="cx">     if (CADisplay *display = self.window.screen._display) {
</span><span class="cx">         auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebCore::sRGBColorSpaceRef());
</span><ins>+        if (!surface) {
+            completionHandler(nullptr);
+            return;
+        }
</ins><span class="cx">         CGFloat imageScaleInViewCoordinates = imageWidth / rectInViewCoordinates.size.width;
</span><span class="cx">         CATransform3D transform = CATransform3DMakeScale(imageScaleInViewCoordinates, imageScaleInViewCoordinates, 1);
</span><span class="cx">         transform = CATransform3DTranslate(transform, -rectInViewCoordinates.origin.x, -rectInViewCoordinates.origin.y, 0);
</span></span></pre>
</div>
</div>

</body>
</html>