<!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>[269381] trunk/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/269381">269381</a></dd>
<dt>Author</dt> <dd>said@apple.com</dd>
<dt>Date</dt> <dd>2020-11-04 13:31:51 -0800 (Wed, 04 Nov 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GPU Process] Enable Document based ImageBitmap and OffscreenCanvas drawing to use GPU Process rendering
https://bugs.webkit.org/show_bug.cgi?id=217735

Reviewed by Simon Fraser.

Source/WebCore:

Add a new static method ImageBitmap::createImageBuffer() which takes a
ScriptExecutionContext. It gets HostWindow from ScriptExecutionContext.
If a HostWindow exists, creating the ImageBuffer will be delegated to
WebChromeClient which will create a RemoteImageBuffer in Web Process and
a RemoteImageBufferProxy in the GPU Process.

Rename all the variables of type ScriptExecutionContext to 'scriptExecutionContext'
to avoid confusing it with GraphicsContext, CanvasRenderingContext and
WebGLRenderingContext.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readImageBitmap):
* html/ImageBitmap.cpp:
(WebCore::ImageBitmap::create):
(WebCore::ImageBitmap::createImageBuffer):
(WebCore::ImageBitmap::resolveWithBlankImageBuffer):
(WebCore::ImageBitmap::createPromise):
(WebCore::ImageBitmap::createFromBuffer):
* html/ImageBitmap.h:
* html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::create):
(WebCore::OffscreenCanvas::OffscreenCanvas):
(WebCore::OffscreenCanvas::createContextWebGL):
(WebCore::OffscreenCanvas::transferToImageBitmap):
(WebCore::OffscreenCanvas::securityOrigin const):
(WebCore::OffscreenCanvas::cssValuePool):
(WebCore::OffscreenCanvas::createImageBuffer const):
(WebCore::OffscreenCanvas::takeImageBuffer const):

Source/WebKit:

* WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
putImageData() might be called immediately after creating the ImageBuffer
and before receiving the RemoteRenderingBackend.CreateImageBufferBackend
message. We need to handle for this case and avoid asserting.

* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::createImageBuffer):
If the size of the ImageBuffer is very big, no remote ImageBuffer can be
created. So we have to be bail out quietly in this case.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsSerializedScriptValuecpp">trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlImageBitmapcpp">trunk/Source/WebCore/html/ImageBitmap.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlImageBitmaph">trunk/Source/WebCore/html/ImageBitmap.h</a></li>
<li><a href="#trunkSourceWebCorehtmlOffscreenCanvascpp">trunk/Source/WebCore/html/OffscreenCanvas.cpp</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitWebProcessGPUgraphicsRemoteImageBufferProxyh">trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessGPUgraphicsRemoteRenderingBackendProxycpp">trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebCore/ChangeLog      2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2020-11-04  Said Abou-Hallawa  <said@apple.com>
+
+        [GPU Process] Enable Document based ImageBitmap and OffscreenCanvas drawing to use GPU Process rendering
+        https://bugs.webkit.org/show_bug.cgi?id=217735
+
+        Reviewed by Simon Fraser.
+
+        Add a new static method ImageBitmap::createImageBuffer() which takes a
+        ScriptExecutionContext. It gets HostWindow from ScriptExecutionContext.
+        If a HostWindow exists, creating the ImageBuffer will be delegated to
+        WebChromeClient which will create a RemoteImageBuffer in Web Process and
+        a RemoteImageBufferProxy in the GPU Process.
+
+        Rename all the variables of type ScriptExecutionContext to 'scriptExecutionContext'
+        to avoid confusing it with GraphicsContext, CanvasRenderingContext and
+        WebGLRenderingContext.
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneDeserializer::readImageBitmap):
+        * html/ImageBitmap.cpp:
+        (WebCore::ImageBitmap::create):
+        (WebCore::ImageBitmap::createImageBuffer):
+        (WebCore::ImageBitmap::resolveWithBlankImageBuffer):
+        (WebCore::ImageBitmap::createPromise):
+        (WebCore::ImageBitmap::createFromBuffer):
+        * html/ImageBitmap.h:
+        * html/OffscreenCanvas.cpp:
+        (WebCore::OffscreenCanvas::create):
+        (WebCore::OffscreenCanvas::OffscreenCanvas):
+        (WebCore::OffscreenCanvas::createContextWebGL):
+        (WebCore::OffscreenCanvas::transferToImageBitmap):
+        (WebCore::OffscreenCanvas::securityOrigin const):
+        (WebCore::OffscreenCanvas::cssValuePool):
+        (WebCore::OffscreenCanvas::createImageBuffer const):
+        (WebCore::OffscreenCanvas::takeImageBuffer const):
+
</ins><span class="cx"> 2020-11-04  David Kilzer  <ddkilzer@apple.com>
</span><span class="cx"> 
</span><span class="cx">         WebKit should remove unused debug variant support
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsSerializedScriptValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp       2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp  2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -2988,7 +2988,7 @@
</span><span class="cx">             return JSValue();
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        auto buffer = ImageBuffer::create(FloatSize(logicalSize), RenderingMode::Unaccelerated, resolutionScale);
</del><ins>+        auto buffer = ImageBitmap::createImageBuffer(*scriptExecutionContextFromExecState(m_lexicalGlobalObject), logicalSize, RenderingMode::Unaccelerated, resolutionScale);
</ins><span class="cx">         if (!buffer) {
</span><span class="cx">             fail();
</span><span class="cx">             return JSValue();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlImageBitmapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/ImageBitmap.cpp        2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp   2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #include "ExceptionOr.h"
</span><span class="cx"> #include "FileReaderLoader.h"
</span><span class="cx"> #include "FileReaderLoaderClient.h"
</span><ins>+#include "FrameView.h"
</ins><span class="cx"> #include "GraphicsContext.h"
</span><span class="cx"> #include "HTMLCanvasElement.h"
</span><span class="cx"> #include "HTMLImageElement.h"
</span><span class="lines">@@ -67,9 +68,9 @@
</span><span class="cx"> static RenderingMode bufferRenderingMode = RenderingMode::Unaccelerated;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-Ref<ImageBitmap> ImageBitmap::create(IntSize size)
</del><ins>+Ref<ImageBitmap> ImageBitmap::create(ScriptExecutionContext& scriptExecutionContext, const IntSize& size)
</ins><span class="cx"> {
</span><del>-    return create({ ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode) });
</del><ins>+    return create({ createImageBuffer(scriptExecutionContext, size, bufferRenderingMode) });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Ref<ImageBitmap> ImageBitmap::create(Optional<ImageBitmapBacking>&& backingStore)
</span><span class="lines">@@ -77,6 +78,20 @@
</span><span class="cx">     return adoptRef(*new ImageBitmap(WTFMove(backingStore)));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr<ImageBuffer> ImageBitmap::createImageBuffer(ScriptExecutionContext& scriptExecutionContext, const FloatSize& size, RenderingMode renderingMode, float resolutionScale)
+{
+    if (scriptExecutionContext.isDocument()) {
+        auto& document = downcast<Document>(scriptExecutionContext);
+        if (document.view() && document.view()->root()) {
+            auto hostWindow = document.view()->root()->hostWindow();
+            return ImageBuffer::create(size, renderingMode, ShouldUseDisplayList::No, RenderingPurpose::Canvas, resolutionScale, ColorSpace::SRGB, hostWindow);
+        }
+    }
+
+    // FIXME <https://webkit.org/b/218482> Enable worker based ImageBitmap and OffscreenCanvas drawing to use GPU Process rendering
+    return ImageBuffer::create(size, renderingMode, resolutionScale);
+}
+
</ins><span class="cx"> void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, ImageBitmap::Source&& source, ImageBitmapOptions&& options, ImageBitmap::Promise&& promise)
</span><span class="cx"> {
</span><span class="cx">     WTF::switchOn(source,
</span><span class="lines">@@ -226,12 +241,12 @@
</span><span class="cx">     return AlphaPremultiplication::Premultiplied;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ImageBitmap::resolveWithBlankImageBuffer(bool originClean, Promise&& promise)
</del><ins>+void ImageBitmap::resolveWithBlankImageBuffer(ScriptExecutionContext& scriptExecutionContext, bool originClean, Promise&& promise)
</ins><span class="cx"> {
</span><span class="cx">     // Source rectangle likely doesn't intersect the source image.
</span><span class="cx">     // Behavior isn't well specified, but WPT tests expect no Promise rejection (and of course no crashes).
</span><span class="cx">     // Resolve Promise with a blank 1x1 ImageBitmap.
</span><del>-    auto bitmapData = ImageBuffer::create(FloatSize(1, 1), bufferRenderingMode);
</del><ins>+    auto bitmapData = createImageBuffer(scriptExecutionContext, FloatSize(1, 1), bufferRenderingMode);
</ins><span class="cx"> 
</span><span class="cx">     // 9. If the origin of image's image is not the same origin as the origin specified by the
</span><span class="cx">     //    entry settings object, then set the origin-clean flag of the ImageBitmap object's
</span><span class="lines">@@ -291,7 +306,7 @@
</span><span class="cx"> 
</span><span class="cx"> // 13. Return output.
</span><span class="cx"> 
</span><del>-void ImageBitmap::createPromise(ScriptExecutionContext&, RefPtr<HTMLImageElement>& imageElement, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, RefPtr<HTMLImageElement>& imageElement, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</ins><span class="cx"> {
</span><span class="cx">     // 2. If image is not completely available, then return a promise rejected with
</span><span class="cx">     // an "InvalidStateError" DOMException and abort these steps.
</span><span class="lines">@@ -350,7 +365,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto outputSize = outputSizeForSourceRectangle(sourceRectangle.returnValue(), options);
</span><del>-    auto bitmapData = ImageBuffer::create(FloatSize(outputSize.width(), outputSize.height()), bufferRenderingMode);
</del><ins>+    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode);
</ins><span class="cx">     auto imageForRender = cachedImage->imageForRenderer(imageElement->renderer());
</span><span class="cx">     if (!imageForRender) {
</span><span class="cx">         promise.reject(InvalidStateError, "Cannot create ImageBitmap from image that can't be rendered");
</span><span class="lines">@@ -358,7 +373,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (!bitmapData) {
</span><del>-        resolveWithBlankImageBuffer(!taintsOrigin(*cachedImage), WTFMove(promise));
</del><ins>+        resolveWithBlankImageBuffer(scriptExecutionContext, !taintsOrigin(*cachedImage), WTFMove(promise));
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -384,19 +399,19 @@
</span><span class="cx">     promise.resolve(WTFMove(imageBitmap));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ImageBitmap::createPromise(ScriptExecutionContext& context, RefPtr<HTMLCanvasElement>& canvasElement, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, RefPtr<HTMLCanvasElement>& canvasElement, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</ins><span class="cx"> {
</span><del>-    createPromise(context, *canvasElement, WTFMove(options), WTFMove(rect), WTFMove(promise));
</del><ins>+    createPromise(scriptExecutionContext, *canvasElement, WTFMove(options), WTFMove(rect), WTFMove(promise));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(OFFSCREEN_CANVAS)
</span><del>-void ImageBitmap::createPromise(ScriptExecutionContext& context, RefPtr<OffscreenCanvas>& canvasElement, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, RefPtr<OffscreenCanvas>& canvasElement, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</ins><span class="cx"> {
</span><del>-    createPromise(context, *canvasElement, WTFMove(options), WTFMove(rect), WTFMove(promise));
</del><ins>+    createPromise(scriptExecutionContext, *canvasElement, WTFMove(options), WTFMove(rect), WTFMove(promise));
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-void ImageBitmap::createPromise(ScriptExecutionContext&, CanvasBase& canvas, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, CanvasBase& canvas, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</ins><span class="cx"> {
</span><span class="cx">     // 2. If the canvas element's bitmap has either a horizontal dimension or a vertical
</span><span class="cx">     //    dimension equal to zero, then return a promise rejected with an "InvalidStateError"
</span><span class="lines">@@ -417,7 +432,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto outputSize = outputSizeForSourceRectangle(sourceRectangle.returnValue(), options);
</span><del>-    auto bitmapData = ImageBuffer::create(FloatSize(outputSize.width(), outputSize.height()), bufferRenderingMode);
</del><ins>+    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode);
</ins><span class="cx"> 
</span><span class="cx">     auto imageForRender = canvas.copiedImage();
</span><span class="cx">     if (!imageForRender) {
</span><span class="lines">@@ -426,7 +441,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (!bitmapData) {
</span><del>-        resolveWithBlankImageBuffer(canvas.originClean(), WTFMove(promise));
</del><ins>+        resolveWithBlankImageBuffer(scriptExecutionContext, canvas.originClean(), WTFMove(promise));
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -489,7 +504,7 @@
</span><span class="cx">     auto outputSize = outputSizeForSourceRectangle(sourceRectangle, options);
</span><span class="cx">     auto bitmapData = video->createBufferForPainting(outputSize, bufferRenderingMode);
</span><span class="cx">     if (!bitmapData) {
</span><del>-        resolveWithBlankImageBuffer(!taintsOrigin(scriptExecutionContext.securityOrigin(), *video), WTFMove(promise));
</del><ins>+        resolveWithBlankImageBuffer(scriptExecutionContext, !taintsOrigin(scriptExecutionContext.securityOrigin(), *video), WTFMove(promise));
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -534,7 +549,7 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-void ImageBitmap::createPromise(ScriptExecutionContext&, RefPtr<ImageBitmap>& existingImageBitmap, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, RefPtr<ImageBitmap>& existingImageBitmap, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</ins><span class="cx"> {
</span><span class="cx">     // 2. If image's [[Detached]] internal slot value is true, return a promise
</span><span class="cx">     //    rejected with an "InvalidStateError" DOMException and abort these steps.
</span><span class="lines">@@ -552,10 +567,10 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto outputSize = outputSizeForSourceRectangle(sourceRectangle.returnValue(), options);
</span><del>-    auto bitmapData = ImageBuffer::create(FloatSize(outputSize.width(), outputSize.height()), bufferRenderingMode);
</del><ins>+    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode);
</ins><span class="cx"> 
</span><span class="cx">     if (!bitmapData) {
</span><del>-        resolveWithBlankImageBuffer(existingImageBitmap->originClean(), WTFMove(promise));
</del><ins>+        resolveWithBlankImageBuffer(scriptExecutionContext, existingImageBitmap->originClean(), WTFMove(promise));
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -698,7 +713,7 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        ImageBitmap::createFromBuffer(m_arrayBufferToProcess.releaseNonNull(), m_blob->type(), m_blob->size(), m_blobLoader.url(), WTFMove(m_options), WTFMove(m_rect), WTFMove(m_promise));
</del><ins>+        ImageBitmap::createFromBuffer(*scriptExecutionContext(), m_arrayBufferToProcess.releaseNonNull(), m_blob->type(), m_blob->size(), m_blobLoader.url(), WTFMove(m_options), WTFMove(m_rect), WTFMove(m_promise));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     FileReaderLoader m_blobLoader;
</span><span class="lines">@@ -710,14 +725,7 @@
</span><span class="cx">     RefPtr<ArrayBuffer> m_arrayBufferToProcess;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-void ImageBitmap::createFromBuffer(
-    Ref<ArrayBuffer>&& arrayBuffer,
-    String mimeType,
-    long long expectedContentLength,
-    const URL& sourceUrl,
-    ImageBitmapOptions&& options,
-    Optional<IntRect> rect,
-    ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createFromBuffer(ScriptExecutionContext& scriptExecutionContext, Ref<ArrayBuffer>&& arrayBuffer, String mimeType, long long expectedContentLength, const URL& sourceURL, ImageBitmapOptions&& options, Optional<IntRect> rect, Promise&& promise)
</ins><span class="cx"> {
</span><span class="cx">     if (!arrayBuffer->byteLength()) {
</span><span class="cx">         promise.reject(InvalidStateError, "Cannot create an ImageBitmap from an empty buffer");
</span><span class="lines">@@ -725,7 +733,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto sharedBuffer = SharedBuffer::create(static_cast<const char*>(arrayBuffer->data()), arrayBuffer->byteLength());
</span><del>-    auto observer = ImageBitmapImageObserver::create(mimeType, expectedContentLength, sourceUrl);
</del><ins>+    auto observer = ImageBitmapImageObserver::create(mimeType, expectedContentLength, sourceURL);
</ins><span class="cx">     auto image = Image::create(observer.get());
</span><span class="cx">     if (!image) {
</span><span class="cx">         promise.reject(InvalidStateError, "The type of the argument to createImageBitmap is not supported");
</span><span class="lines">@@ -745,7 +753,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto outputSize = outputSizeForSourceRectangle(sourceRectangle.returnValue(), options);
</span><del>-    auto bitmapData = ImageBuffer::create(FloatSize(outputSize.width(), outputSize.height()), bufferRenderingMode);
</del><ins>+    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode);
</ins><span class="cx">     if (!bitmapData) {
</span><span class="cx">         promise.reject(InvalidStateError, "Cannot create an image buffer from the argument to createImageBitmap");
</span><span class="cx">         return;
</span><span class="lines">@@ -769,7 +777,7 @@
</span><span class="cx">     PendingImageBitmap::fetch(scriptExecutionContext, WTFMove(blob), WTFMove(options), WTFMove(rect), WTFMove(promise));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ImageBitmap::createPromise(ScriptExecutionContext&, RefPtr<ImageData>& imageData, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</del><ins>+void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, RefPtr<ImageData>& imageData, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
</ins><span class="cx"> {
</span><span class="cx">     // 6.1. Let buffer be image's data attribute value's [[ViewedArrayBuffer]]
</span><span class="cx">     //      internal slot.
</span><span class="lines">@@ -789,10 +797,10 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto outputSize = outputSizeForSourceRectangle(sourceRectangle.returnValue(), options);
</span><del>-    auto bitmapData = ImageBuffer::create(FloatSize(outputSize.width(), outputSize.height()), bufferRenderingMode);
</del><ins>+    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode);
</ins><span class="cx"> 
</span><span class="cx">     if (!bitmapData) {
</span><del>-        resolveWithBlankImageBuffer(true, WTFMove(promise));
</del><ins>+        resolveWithBlankImageBuffer(scriptExecutionContext, true, WTFMove(promise));
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -811,7 +819,7 @@
</span><span class="cx"> 
</span><span class="cx">     // 6.3. Set imageBitmap's bitmap data to image's image data, cropped to the
</span><span class="cx">     //      source rectangle with formatting.
</span><del>-    auto tempBitmapData = ImageBuffer::create(FloatSize(imageData->width(), imageData->height()), bufferRenderingMode);
</del><ins>+    auto tempBitmapData = createImageBuffer(scriptExecutionContext, imageData->size(), bufferRenderingMode);
</ins><span class="cx">     tempBitmapData->putImageData(AlphaPremultiplication::Unpremultiplied, *imageData, IntRect(0, 0, imageData->width(), imageData->height()), { }, alphaPremultiplication);
</span><span class="cx">     FloatRect destRect(FloatPoint(), outputSize);
</span><span class="cx">     bitmapData->context().drawImageBuffer(*tempBitmapData, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlImageBitmaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/ImageBitmap.h (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/ImageBitmap.h  2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebCore/html/ImageBitmap.h     2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -82,7 +82,9 @@
</span><span class="cx">     static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, Promise&&);
</span><span class="cx">     static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, int sx, int sy, int sw, int sh, Promise&&);
</span><span class="cx"> 
</span><del>-    static Ref<ImageBitmap> create(IntSize);
</del><ins>+    static RefPtr<ImageBuffer> createImageBuffer(ScriptExecutionContext&, const FloatSize&, RenderingMode, float resolutionScale = 1);
+
+    static Ref<ImageBitmap> create(ScriptExecutionContext&, const IntSize&);
</ins><span class="cx">     static Ref<ImageBitmap> create(Optional<ImageBitmapBacking>&&);
</span><span class="cx"> 
</span><span class="cx">     ~ImageBitmap();
</span><span class="lines">@@ -112,7 +114,7 @@
</span><span class="cx"> 
</span><span class="cx">     ImageBitmap(Optional<ImageBitmapBacking>&&);
</span><span class="cx"> 
</span><del>-    static void resolveWithBlankImageBuffer(bool originClean, Promise&&);
</del><ins>+    static void resolveWithBlankImageBuffer(ScriptExecutionContext&, bool originClean, Promise&&);
</ins><span class="cx"> 
</span><span class="cx">     static void createPromise(ScriptExecutionContext&, RefPtr<HTMLImageElement>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
</span><span class="cx"> #if ENABLE(VIDEO)
</span><span class="lines">@@ -127,7 +129,7 @@
</span><span class="cx">     static void createPromise(ScriptExecutionContext&, RefPtr<Blob>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
</span><span class="cx">     static void createPromise(ScriptExecutionContext&, RefPtr<ImageData>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
</span><span class="cx">     static void createPromise(ScriptExecutionContext&, RefPtr<TypedOMCSSImageValue>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
</span><del>-    static void createFromBuffer(Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
</del><ins>+    static void createFromBuffer(ScriptExecutionContext&, Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
</ins><span class="cx"> 
</span><span class="cx">     Optional<ImageBitmapBacking> m_backingStore;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlOffscreenCanvascpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/OffscreenCanvas.cpp    2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp       2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -73,14 +73,14 @@
</span><span class="cx">     return std::exchange(m_placeholderCanvas, nullptr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& context, unsigned width, unsigned height)
</del><ins>+Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& scriptExecutionContext, unsigned width, unsigned height)
</ins><span class="cx"> {
</span><del>-    return adoptRef(*new OffscreenCanvas(context, width, height));
</del><ins>+    return adoptRef(*new OffscreenCanvas(scriptExecutionContext, width, height));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& context, std::unique_ptr<DetachedOffscreenCanvas>&& detachedCanvas)
</del><ins>+Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& scriptExecutionContext, std::unique_ptr<DetachedOffscreenCanvas>&& detachedCanvas)
</ins><span class="cx"> {
</span><del>-    Ref<OffscreenCanvas> clone = adoptRef(*new OffscreenCanvas(context, detachedCanvas->size().width(), detachedCanvas->size().height()));
</del><ins>+    Ref<OffscreenCanvas> clone = adoptRef(*new OffscreenCanvas(scriptExecutionContext, detachedCanvas->size().width(), detachedCanvas->size().height()));
</ins><span class="cx">     clone->setImageBuffer(detachedCanvas->takeImageBuffer());
</span><span class="cx">     if (!detachedCanvas->originClean())
</span><span class="cx">         clone->setOriginTainted();
</span><span class="lines">@@ -98,16 +98,16 @@
</span><span class="cx">     return clone;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& context, HTMLCanvasElement& canvas)
</del><ins>+Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& scriptExecutionContext, HTMLCanvasElement& canvas)
</ins><span class="cx"> {
</span><del>-    auto offscreen = adoptRef(*new OffscreenCanvas(context, canvas.width(), canvas.height()));
</del><ins>+    auto offscreen = adoptRef(*new OffscreenCanvas(scriptExecutionContext, canvas.width(), canvas.height()));
</ins><span class="cx">     offscreen->setPlaceholderCanvas(canvas);
</span><span class="cx">     return offscreen;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-OffscreenCanvas::OffscreenCanvas(ScriptExecutionContext& context, unsigned width, unsigned height)
</del><ins>+OffscreenCanvas::OffscreenCanvas(ScriptExecutionContext& scriptExecutionContext, unsigned width, unsigned height)
</ins><span class="cx">     : CanvasBase(IntSize(width, height))
</span><del>-    , ContextDestructionObserver(&context)
</del><ins>+    , ContextDestructionObserver(&scriptExecutionContext)
</ins><span class="cx">     , m_placeholderData(PlaceholderData::create())
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -179,13 +179,13 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!m_context);
</span><span class="cx"> 
</span><del>-    auto context = scriptExecutionContext();
-    if (context->isWorkerGlobalScope()) {
-        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(*context);
</del><ins>+    auto scriptExecutionContext = this->scriptExecutionContext();
+    if (scriptExecutionContext->isWorkerGlobalScope()) {
+        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(*scriptExecutionContext);
</ins><span class="cx">         if (!shouldEnableWebGL(workerGlobalScope.webGLEnabled(), workerGlobalScope.acceleratedCompositingEnabled()))
</span><span class="cx">             return;
</span><del>-    } else if (context->isDocument()) {
-        auto& settings = downcast<Document>(*context).settings();
</del><ins>+    } else if (scriptExecutionContext->isDocument()) {
+        auto& settings = downcast<Document>(*scriptExecutionContext).settings();
</ins><span class="cx">         if (!shouldEnableWebGL(settings.webGLEnabled(), settings.acceleratedCompositingEnabled()))
</span><span class="cx">             return;
</span><span class="cx">     } else
</span><span class="lines">@@ -254,8 +254,10 @@
</span><span class="cx">         if (!width() || !height())
</span><span class="cx">             return { RefPtr<ImageBitmap> { nullptr } };
</span><span class="cx"> 
</span><del>-        if (!m_hasCreatedImageBuffer)
-            return { ImageBitmap::create(ImageBitmapBacking(ImageBuffer::create(size(), RenderingMode::Unaccelerated))) };
</del><ins>+        if (!m_hasCreatedImageBuffer) {
+            auto buffer = ImageBitmap::createImageBuffer(*canvasBaseScriptExecutionContext(), size(), RenderingMode::Unaccelerated);
+            return { ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer))) };
+        }
</ins><span class="cx"> 
</span><span class="cx">         auto buffer = takeImageBuffer();
</span><span class="cx">         if (!buffer)
</span><span class="lines">@@ -272,7 +274,7 @@
</span><span class="cx">         // store from this canvas (or its context), but for now we'll just
</span><span class="cx">         // create a new bitmap and paint into it.
</span><span class="cx"> 
</span><del>-        auto imageBitmap = ImageBitmap::create(size());
</del><ins>+        auto imageBitmap = ImageBitmap::create(*canvasBaseScriptExecutionContext(), size());
</ins><span class="cx">         if (!imageBitmap->buffer())
</span><span class="cx">             return { RefPtr<ImageBitmap> { nullptr } };
</span><span class="cx"> 
</span><span class="lines">@@ -368,11 +370,11 @@
</span><span class="cx"> 
</span><span class="cx"> SecurityOrigin* OffscreenCanvas::securityOrigin() const
</span><span class="cx"> {
</span><del>-    auto& context = *canvasBaseScriptExecutionContext();
-    if (is<WorkerGlobalScope>(context))
-        return &downcast<WorkerGlobalScope>(context).topOrigin();
</del><ins>+    auto& scriptExecutionContext = *canvasBaseScriptExecutionContext();
+    if (is<WorkerGlobalScope>(scriptExecutionContext))
+        return &downcast<WorkerGlobalScope>(scriptExecutionContext).topOrigin();
</ins><span class="cx"> 
</span><del>-    return &downcast<Document>(context).securityOrigin();
</del><ins>+    return &downcast<Document>(scriptExecutionContext).securityOrigin();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool OffscreenCanvas::canDetach() const
</span><span class="lines">@@ -451,11 +453,11 @@
</span><span class="cx"> 
</span><span class="cx"> CSSValuePool& OffscreenCanvas::cssValuePool()
</span><span class="cx"> {
</span><del>-    auto* context = canvasBaseScriptExecutionContext();
-    if (context->isWorkerGlobalScope())
-        return downcast<WorkerGlobalScope>(*context).cssValuePool();
</del><ins>+    auto* scriptExecutionContext = canvasBaseScriptExecutionContext();
+    if (scriptExecutionContext->isWorkerGlobalScope())
+        return downcast<WorkerGlobalScope>(*scriptExecutionContext).cssValuePool();
</ins><span class="cx"> 
</span><del>-    ASSERT(context->isDocument());
</del><ins>+    ASSERT(scriptExecutionContext->isDocument());
</ins><span class="cx">     return CSSValuePool::singleton();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -466,7 +468,7 @@
</span><span class="cx">     if (!width() || !height())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    setImageBuffer(ImageBuffer::create(size(), RenderingMode::Unaccelerated));
</del><ins>+    setImageBuffer(ImageBitmap::createImageBuffer(*canvasBaseScriptExecutionContext(), size(), RenderingMode::Unaccelerated));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> RefPtr<ImageBuffer> OffscreenCanvas::takeImageBuffer() const
</span><span class="lines">@@ -482,7 +484,7 @@
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><span class="cx">     clearCopiedImage();
</span><del>-    return setImageBuffer(m_detached ? nullptr : ImageBuffer::create(size(), RenderingMode::Unaccelerated));
</del><ins>+    return setImageBuffer(m_detached ? nullptr : ImageBitmap::createImageBuffer(*canvasBaseScriptExecutionContext(), size(), RenderingMode::Unaccelerated));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void OffscreenCanvas::reset()
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebKit/ChangeLog       2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2020-11-04  Said Abou-Hallawa  <said@apple.com>
+
+        [GPU Process] Enable Document based ImageBitmap and OffscreenCanvas drawing to use GPU Process rendering
+        https://bugs.webkit.org/show_bug.cgi?id=217735
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
+        putImageData() might be called immediately after creating the ImageBuffer
+        and before receiving the RemoteRenderingBackend.CreateImageBufferBackend
+        message. We need to handle for this case and avoid asserting.
+
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
+        (WebKit::RemoteRenderingBackendProxy::createImageBuffer):
+        If the size of the ImageBuffer is very big, no remote ImageBuffer can be
+        created. So we have to be bail out quietly in this case.
+
</ins><span class="cx"> 2020-11-04  David Kilzer  <ddkilzer@apple.com>
</span><span class="cx"> 
</span><span class="cx">         WebKit should remove unused debug variant support
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessGPUgraphicsRemoteImageBufferProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h     2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h        2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -120,7 +120,7 @@
</span><span class="cx">     {
</span><span class="cx">         // The math inside ImageData::create() doesn't agree with the math inside ImageBufferBackend::putImageData() about how m_resolutionScale interacts with the data in the ImageBuffer.
</span><span class="cx">         // This means that putImageData() is only called when m_resolutionScale == 1.
</span><del>-        ASSERT(m_backend->resolutionScale() == 1);
</del><ins>+        ASSERT_IMPLIES(m_backend, m_backend->resolutionScale() == 1);
</ins><span class="cx">         m_drawingContext.recorder().putImageData(inputFormat, imageData, srcRect, destPoint, destFormat);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessGPUgraphicsRemoteRenderingBackendProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp (269380 => 269381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp      2020-11-04 21:17:51 UTC (rev 269380)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp 2020-11-04 21:31:51 UTC (rev 269381)
</span><span class="lines">@@ -103,7 +103,6 @@
</span><span class="cx">         return imageBuffer;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ASSERT_NOT_REACHED();
</del><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>