Title: [254291] trunk
Revision
254291
Author
[email protected]
Date
2020-01-09 12:52:33 -0800 (Thu, 09 Jan 2020)

Log Message

ImageBitmap can't be created in workers in some cases due to main-thread assert in ImageSource
https://bugs.webkit.org/show_bug.cgi?id=205850

Patch by Chris Lord <[email protected]> on 2020-01-09
Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer-expected.txt: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html: Added.
* web-platform-tests/2dcontext/imagebitmap/createImageBitmap-worker.js: Added.

Source/WebCore:

Assert that we're destroyed on the creation thread, rather than on the
main thread. This is required for ImageBitmap creation in workers in
debug builds.

Test: imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html

* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::ImageSource):
(WebCore::ImageSource::~ImageSource):
(WebCore::ImageSource::startAsyncDecodingQueue):
* platform/graphics/ImageSource.h:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (254290 => 254291)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-01-09 20:35:06 UTC (rev 254290)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-01-09 20:52:33 UTC (rev 254291)
@@ -1,3 +1,14 @@
+2020-01-09  Chris Lord  <[email protected]>
+
+        ImageBitmap can't be created in workers in some cases due to main-thread assert in ImageSource
+        https://bugs.webkit.org/show_bug.cgi?id=205850
+
+        Reviewed by Dean Jackson.
+
+        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer-expected.txt: Added.
+        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html: Added.
+        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-worker.js: Added.
+
 2020-01-09  Pablo Saavedra  <[email protected]>
 
         Bad baseline for Catalina on xhr web-platform-tests imported in r254154

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer-expected.txt (0 => 254291)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer-expected.txt	2020-01-09 20:52:33 UTC (rev 254291)
@@ -0,0 +1,3 @@
+
+PASS Transfer ImageBitmap created in worker 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html (0 => 254291)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html	2020-01-09 20:52:33 UTC (rev 254291)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>createImageBitmap in worker and transfer</title>
+<script src=""
+<script src=""
+<div id=log></div>
+<script>
+promise_test(function(t) {
+    return new Promise(function(resolve, reject) {
+        var worker = new Worker("createImageBitmap-worker.js");
+        worker.addEventListener("message", function(evt) {
+            var bitmap = evt.data;
+            assert_equals(bitmap.width, 20);
+            assert_equals(bitmap.height, 20);
+            resolve();
+        });
+        worker.postMessage('test');
+    });
+}, 'Transfer ImageBitmap created in worker');
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-worker.js (0 => 254291)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-worker.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-worker.js	2020-01-09 20:52:33 UTC (rev 254291)
@@ -0,0 +1,17 @@
+function makeBlob() {
+    return new Promise(function(resolve, reject) {
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", '/images/pattern.png');
+        xhr.responseType = 'blob';
+        xhr.send();
+        xhr._onload_ = function() {
+            resolve(xhr.response);
+        };
+    });
+}
+
+addEventListener("message", () => {
+    makeBlob().then(createImageBitmap).then(bitmap => {
+        postMessage(bitmap, [bitmap]);
+    });
+});

Modified: trunk/Source/WebCore/ChangeLog (254290 => 254291)


--- trunk/Source/WebCore/ChangeLog	2020-01-09 20:35:06 UTC (rev 254290)
+++ trunk/Source/WebCore/ChangeLog	2020-01-09 20:52:33 UTC (rev 254291)
@@ -1,3 +1,22 @@
+2020-01-09  Chris Lord  <[email protected]>
+
+        ImageBitmap can't be created in workers in some cases due to main-thread assert in ImageSource
+        https://bugs.webkit.org/show_bug.cgi?id=205850
+
+        Reviewed by Dean Jackson.
+
+        Assert that we're destroyed on the creation thread, rather than on the
+        main thread. This is required for ImageBitmap creation in workers in
+        debug builds.
+
+        Test: imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-in-worker-transfer.html
+
+        * platform/graphics/ImageSource.cpp:
+        (WebCore::ImageSource::ImageSource):
+        (WebCore::ImageSource::~ImageSource):
+        (WebCore::ImageSource::startAsyncDecodingQueue):
+        * platform/graphics/ImageSource.h:
+
 2020-01-09  Jer Noble  <[email protected]>
 
         [Cocoa] persistent-usage-record message fails first time; succeeds subsequent times

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.cpp (254290 => 254291)


--- trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2020-01-09 20:35:06 UTC (rev 254290)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2020-01-09 20:52:33 UTC (rev 254291)
@@ -31,8 +31,6 @@
 #include "ImageObserver.h"
 #include "Logging.h"
 #include <wtf/CheckedArithmetic.h>
-#include <wtf/MainThread.h>
-#include <wtf/RunLoop.h>
 #include <wtf/SystemTracing.h>
 #include <wtf/URL.h>
 
@@ -47,14 +45,13 @@
     : m_image(image)
     , m_alphaOption(alphaOption)
     , m_gammaAndColorProfileOption(gammaAndColorProfileOption)
+    , m_runLoop(RunLoop::current())
 {
-    ASSERT(isMainThread());
 }
 
 ImageSource::ImageSource(NativeImagePtr&& nativeImage)
+    : m_runLoop(RunLoop::current())
 {
-    ASSERT(isMainThread());
-
     m_frameCount = 1;
     m_encodedDataStatus = EncodedDataStatus::Complete;
     growFrames();
@@ -70,7 +67,7 @@
 ImageSource::~ImageSource()
 {
     ASSERT(!hasAsyncDecodingQueue());
-    ASSERT(isMainThread());
+    ASSERT(&m_runLoop == &RunLoop::current());
 }
 
 bool ImageSource::ensureDecoderAvailable(SharedBuffer* data)
@@ -373,8 +370,8 @@
             if (minDecodingDuration > 0_s)
                 sleep(minDecodingDuration - (MonotonicTime::now() - startingTime));
 
-            // Update the cached frames on the main thread to avoid updating the MemoryCache from a different thread.
-            callOnMainThread([protectedThis = protectedThis.copyRef(), protectedQueue = protectedDecodingQueue.copyRef(), protectedDecoder = protectedDecoder.copyRef(), sourceURL = sourceURL.isolatedCopy(), nativeImage = WTFMove(nativeImage), frameRequest] () mutable {
+            // Update the cached frames on the creation thread to avoid updating the MemoryCache from a different thread.
+            protectedThis->m_runLoop.dispatch([protectedThis = protectedThis.copyRef(), protectedQueue = protectedDecodingQueue.copyRef(), protectedDecoder = protectedDecoder.copyRef(), sourceURL = sourceURL.isolatedCopy(), nativeImage = WTFMove(nativeImage), frameRequest] () mutable {
                 // The queue may have been closed if after we got the frame NativeImage, stopAsyncDecodingQueue() was called.
                 if (protectedQueue.ptr() == protectedThis->m_decodingQueue && protectedDecoder.ptr() == protectedThis->m_decoder) {
                     ASSERT(protectedThis->m_frameCommitQueue.first() == frameRequest);

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (254290 => 254291)


--- trunk/Source/WebCore/platform/graphics/ImageSource.h	2020-01-09 20:35:06 UTC (rev 254290)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h	2020-01-09 20:52:33 UTC (rev 254291)
@@ -29,6 +29,7 @@
 
 #include <wtf/Forward.h>
 #include <wtf/Optional.h>
+#include <wtf/RunLoop.h>
 #include <wtf/SynchronizedFixedQueue.h>
 #include <wtf/WeakPtr.h>
 #include <wtf/WorkQueue.h>
@@ -40,7 +41,7 @@
 class GraphicsContext;
 class ImageDecoder;
 
-class ImageSource : public ThreadSafeRefCounted<ImageSource, WTF::DestructionThread::Main>, public CanMakeWeakPtr<ImageSource> {
+class ImageSource : public ThreadSafeRefCounted<ImageSource>, public CanMakeWeakPtr<ImageSource> {
     friend class BitmapImage;
 public:
     ~ImageSource();
@@ -200,6 +201,8 @@
     Optional<ImageOrientation> m_orientation;
     Optional<Color> m_singlePixelSolidColor;
     Optional<SubsamplingLevel> m_maximumSubsamplingLevel;
+
+    RunLoop& m_runLoop;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to