Title: [230348] trunk
Revision
230348
Author
ms2...@igalia.com
Date
2018-04-06 12:20:35 -0700 (Fri, 06 Apr 2018)

Log Message

Support transferring ImageBitmap objects
https://bugs.webkit.org/show_bug.cgi?id=183131

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

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

Source/WebCore:

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

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::serialize): thread through ImageBitmaps.
(WebCore::CloneSerializer::CloneSerializer): thread through ImageBitmaps.
(WebCore::CloneSerializer::fillTransferMap): don't require a mutable reference.
(WebCore::CloneSerializer::dumpImageBitmap): add.
(WebCore::CloneSerializer::dumpIfTerminal): check for ImageBitmap.
(WebCore::CloneDeserializer::deserialize): thread through ImageBitmaps.
(WebCore::CloneDeserializer::CloneDeserializer): thread through ImageBitmaps.
(WebCore::CloneDeserializer::readImageBitmap): add.
(WebCore::CloneDeserializer::readTerminal): check for ImageBitmap.
(WebCore::SerializedScriptValue::SerializedScriptValue): thread through ImageBitmaps.
(WebCore::SerializedScriptValue::create): thread through ImageBitmaps.
(WebCore::containsDuplicates): add.
(WebCore::SerializedScriptValue::deserialize): handle ImageBitmap arguments.
* bindings/js/SerializedScriptValue.h: update signatures, add member.
* html/ImageBitmap.cpp:
(WebCore::ImageBitmap::create): add.
(WebCore::ImageBitmap::detachBitmaps): add.
* html/ImageBitmap.h: add signatures.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (230347 => 230348)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-04-06 19:19:41 UTC (rev 230347)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-04-06 19:20:35 UTC (rev 230348)
@@ -1,3 +1,14 @@
+2018-04-06  Ms2ger  <ms2...@igalia.com>
+
+        Support transferring ImageBitmap objects
+        https://bugs.webkit.org/show_bug.cgi?id=183131
+
+        Reviewed by Dean Jackson.
+
+        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer-expected.txt: Added.
+        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer.html: Added.
+        * web-platform-tests/2dcontext/imagebitmap/transfer-worker.js: Added.
+
 2018-04-06  Brendan McLoughlin  <bren...@bocoup.com>
 
         Sync 2dcontext, FileAPI, IndexedDB, background-fetch, credential-management, custom-elements, dom, encoding, and fetch web-platform-tests to 94b33b573a069ae5170104ca581a354a35762536

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer-expected.txt	2018-04-06 19:20:35 UTC (rev 230348)
@@ -0,0 +1,13 @@
+
+PASS Transfer ImageBitmap created from an HTMLCanvasElement 
+PASS Transfer ImageBitmap created from an HTMLVideoElement 
+PASS Transfer ImageBitmap created from an HTMLVideoElement from a data URL 
+PASS Transfer ImageBitmap created from a bitmap HTMLImageElement 
+PASS Transfer ImageBitmap created from a vector HTMLImageElement 
+FAIL Transfer ImageBitmap created from a bitmap SVGImageElement promise_test: Unhandled rejection with value: object "TypeError: Type error"
+FAIL Transfer ImageBitmap created from a vector SVGImageElement promise_test: Unhandled rejection with value: object "TypeError: Type error"
+FAIL Transfer ImageBitmap created from an OffscreenCanvas promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'testCtx.fillStyle = "rgb(255, 0, 0)"')"
+FAIL Transfer ImageBitmap created from an ImageData promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with ImageData is not implemented"
+PASS Transfer ImageBitmap created from an ImageBitmap 
+FAIL Transfer ImageBitmap created from a Blob promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with ArrayBuffer or Blob is not implemented"
+

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer.html	2018-04-06 19:20:35 UTC (rev 230348)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>createImageBitmap transferring test</title>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<div id=log></div>
+<script>
+let worker, tests = {};
+setup(function() {
+    worker = new Worker("transfer-worker.js");
+    worker.addEventListener("message", function(event) {
+        let { name, bitmap } = event.data;
+        tests[name](bitmap);
+    });
+});
+
+for (let { name, factory } of imageSourceTypes) {
+    promise_test(function(t) {
+        let message_handler = new Promise(function(resolve) {
+            tests[t.name] = resolve;
+        });
+        return factory().then(createImageBitmap).then(function(bitmap) {
+            assert_equals(bitmap.width, 20);
+            assert_equals(bitmap.height, 20);
+
+            worker.postMessage({ name: t.name, bitmap: bitmap }, [bitmap]);
+
+            assert_equals(bitmap.width, 0);
+            assert_equals(bitmap.height, 0);
+
+            return message_handler;
+        }).then(function(bitmap) {
+            assert_class_string(bitmap, "ImageBitmap");
+            assert_equals(bitmap.width, 20);
+            assert_equals(bitmap.height, 20);
+        });
+    }, `Transfer ImageBitmap created from ${name}`);
+}
+</script>

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/transfer-worker.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/transfer-worker.js	2018-04-06 19:20:35 UTC (rev 230348)
@@ -0,0 +1,3 @@
+addEventListener('message', evt => {
+    postMessage(evt.data, [evt.data.bitmap]);
+});

Modified: trunk/Source/WebCore/ChangeLog (230347 => 230348)


--- trunk/Source/WebCore/ChangeLog	2018-04-06 19:19:41 UTC (rev 230347)
+++ trunk/Source/WebCore/ChangeLog	2018-04-06 19:20:35 UTC (rev 230348)
@@ -1,3 +1,32 @@
+2018-04-06  Ms2ger  <ms2...@igalia.com>
+
+        Support transferring ImageBitmap objects
+        https://bugs.webkit.org/show_bug.cgi?id=183131
+
+        Reviewed by Dean Jackson.
+
+        Test: imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-transfer.html
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::serialize): thread through ImageBitmaps.
+        (WebCore::CloneSerializer::CloneSerializer): thread through ImageBitmaps.
+        (WebCore::CloneSerializer::fillTransferMap): don't require a mutable reference.
+        (WebCore::CloneSerializer::dumpImageBitmap): add.
+        (WebCore::CloneSerializer::dumpIfTerminal): check for ImageBitmap.
+        (WebCore::CloneDeserializer::deserialize): thread through ImageBitmaps.
+        (WebCore::CloneDeserializer::CloneDeserializer): thread through ImageBitmaps.
+        (WebCore::CloneDeserializer::readImageBitmap): add.
+        (WebCore::CloneDeserializer::readTerminal): check for ImageBitmap.
+        (WebCore::SerializedScriptValue::SerializedScriptValue): thread through ImageBitmaps.
+        (WebCore::SerializedScriptValue::create): thread through ImageBitmaps.
+        (WebCore::containsDuplicates): add.
+        (WebCore::SerializedScriptValue::deserialize): handle ImageBitmap arguments.
+        * bindings/js/SerializedScriptValue.h: update signatures, add member.
+        * html/ImageBitmap.cpp:
+        (WebCore::ImageBitmap::create): add.
+        (WebCore::ImageBitmap::detachBitmaps): add.
+        * html/ImageBitmap.h: add signatures.
+
 2018-04-06  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         When recording the drawing, the DisplayList should be initialized with the GraphicsContextState of the underlying GraphicsContext

Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (230347 => 230348)


--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2018-04-06 19:19:41 UTC (rev 230347)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2018-04-06 19:20:35 UTC (rev 230348)
@@ -46,6 +46,7 @@
 #include "JSDOMRect.h"
 #include "JSFile.h"
 #include "JSFileList.h"
+#include "JSImageBitmap.h"
 #include "JSImageData.h"
 #include "JSMessagePort.h"
 #include "JSNavigator.h"
@@ -160,6 +161,7 @@
     DOMMatrixReadOnlyTag = 40,
     DOMMatrixTag = 41,
     DOMQuadTag = 42,
+    ImageBitmapTransferTag = 43,
     ErrorTag = 255
 };
 
@@ -339,6 +341,7 @@
  *    | DOMRect
  *    | DOMMatrix
  *    | DOMQuad
+ *    | ImageBitmapTransferTag <value:uint32_t>
  *
  * Inside wrapped crypto key, data is serialized in this format:
  *
@@ -530,13 +533,13 @@
 
 class CloneSerializer : CloneBase {
 public:
-    static SerializationReturnCode serialize(ExecState* exec, JSValue value, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers,
+    static SerializationReturnCode serialize(ExecState* exec, JSValue value, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers, const Vector<RefPtr<ImageBitmap>>& imageBitmaps,
 #if ENABLE(WEBASSEMBLY)
             WasmModuleArray& wasmModules,
 #endif
             Vector<String>& blobURLs, Vector<uint8_t>& out, SerializationContext context, ArrayBufferContentsArray& sharedBuffers)
     {
-        CloneSerializer serializer(exec, messagePorts, arrayBuffers,
+        CloneSerializer serializer(exec, messagePorts, arrayBuffers, imageBitmaps,
 #if ENABLE(WEBASSEMBLY)
             wasmModules,
 #endif
@@ -563,7 +566,7 @@
 private:
     typedef HashMap<JSObject*, uint32_t> ObjectPool;
 
-    CloneSerializer(ExecState* exec, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers,
+    CloneSerializer(ExecState* exec, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers, const Vector<RefPtr<ImageBitmap>>& imageBitmaps,
 #if ENABLE(WEBASSEMBLY)
             WasmModuleArray& wasmModules,
 #endif
@@ -581,10 +584,11 @@
         write(CurrentVersion);
         fillTransferMap(messagePorts, m_transferredMessagePorts);
         fillTransferMap(arrayBuffers, m_transferredArrayBuffers);
+        fillTransferMap(imageBitmaps, m_transferredImageBitmaps);
     }
 
     template <class T>
-    void fillTransferMap(Vector<RefPtr<T>>& input, ObjectPool& result)
+    void fillTransferMap(const Vector<RefPtr<T>>& input, ObjectPool& result)
     {
         if (input.isEmpty())
             return;
@@ -872,6 +876,19 @@
         dumpDOMPoint(quad.p4());
     }
 
+    void dumpImageBitmap(JSObject* obj, SerializationReturnCode& code)
+    {
+        auto index = m_transferredImageBitmaps.find(obj);
+        if (index != m_transferredImageBitmaps.end()) {
+            write(ImageBitmapTransferTag);
+            write(index->value);
+            return;
+        }
+
+        // Copying ImageBitmaps is not yet supported.
+        code = SerializationReturnCode::ValidationError;
+    }
+
     bool dumpIfTerminal(JSValue value, SerializationReturnCode& code)
     {
         if (!value.isCell()) {
@@ -1022,7 +1039,7 @@
                 WasmModuleArray dummyModules;
 #endif
                 ArrayBufferContentsArray dummySharedBuffers;
-                CloneSerializer rawKeySerializer(m_exec, dummyMessagePorts, dummyArrayBuffers,
+                CloneSerializer rawKeySerializer(m_exec, dummyMessagePorts, dummyArrayBuffers, { },
 #if ENABLE(WEBASSEMBLY)
                     dummyModules,
 #endif
@@ -1064,6 +1081,10 @@
                 dumpDOMQuad(obj);
                 return true;
             }
+            if (obj->inherits(vm, JSImageBitmap::info())) {
+                dumpImageBitmap(obj, code);
+                return true;
+            }
             return false;
         }
         // Any other types are expected to serialize as null.
@@ -1409,6 +1430,7 @@
     ObjectPool m_objectPool;
     ObjectPool m_transferredMessagePorts;
     ObjectPool m_transferredArrayBuffers;
+    ObjectPool m_transferredImageBitmaps;
     typedef HashMap<RefPtr<UniquedStringImpl>, uint32_t, IdentifierRepHash> StringConstantPool;
     StringConstantPool m_constantPool;
     Identifier m_emptyIdentifier;
@@ -1688,7 +1710,7 @@
         return str;
     }
 
-    static DeserializationResult deserialize(ExecState* exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContentsArray, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers
+    static DeserializationResult deserialize(ExecState* exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>>&& imageBuffers, ArrayBufferContentsArray* arrayBufferContentsArray, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers
 #if ENABLE(WEBASSEMBLY)
         , WasmModuleArray* wasmModules
 #endif
@@ -1696,7 +1718,7 @@
     {
         if (!buffer.size())
             return std::make_pair(jsNull(), SerializationReturnCode::UnspecifiedError);
-        CloneDeserializer deserializer(exec, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers
+        CloneDeserializer deserializer(exec, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTFMove(imageBuffers)
 #if ENABLE(WEBASSEMBLY)
             , wasmModules
 #endif
@@ -1745,7 +1767,7 @@
         size_t m_index;
     };
 
-    CloneDeserializer(ExecState* exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents,
+    CloneDeserializer(ExecState* exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>>&& imageBuffers,
 #if ENABLE(WEBASSEMBLY)
         WasmModuleArray* wasmModules,
 #endif
@@ -1759,6 +1781,8 @@
         , m_messagePorts(messagePorts)
         , m_arrayBufferContents(arrayBufferContents)
         , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0)
+        , m_imageBuffers(WTFMove(imageBuffers))
+        , m_imageBitmaps(m_imageBuffers.size())
 #if ENABLE(WEBASSEMBLY)
         , m_wasmModules(wasmModules)
 #endif
@@ -1767,7 +1791,7 @@
             m_version = 0xFFFFFFFF;
     }
 
-    CloneDeserializer(ExecState* exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers
+    CloneDeserializer(ExecState* exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers, Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>>&& imageBuffers
 #if ENABLE(WEBASSEMBLY)
         , WasmModuleArray* wasmModules
 #endif
@@ -1784,6 +1808,8 @@
         , m_blobURLs(blobURLs)
         , m_blobFilePaths(blobFilePaths)
         , m_sharedBuffers(sharedBuffers)
+        , m_imageBuffers(WTFMove(imageBuffers))
+        , m_imageBitmaps(m_imageBuffers.size())
 #if ENABLE(WEBASSEMBLY)
         , m_wasmModules(wasmModules)
 #endif
@@ -2598,6 +2624,22 @@
         return toJSNewlyCreated(m_exec, jsCast<JSDOMGlobalObject*>(m_globalObject), DOMQuad::create(p1.value(), p2.value(), p3.value(), p4.value()));
     }
 
+    JSValue readImageBitmap()
+    {
+        uint32_t index;
+        bool indexSuccessfullyRead = read(index);
+        if (!indexSuccessfullyRead || index >= m_imageBuffers.size()) {
+            fail();
+            return JSValue();
+        }
+
+        if (!m_imageBitmaps[index])
+            m_imageBitmaps[index] = ImageBitmap::create(WTFMove(m_imageBuffers.at(index)));
+
+        auto bitmap = m_imageBitmaps[index].get();
+        return getJSValue(bitmap);
+    }
+
     JSValue readTerminal()
     {
         SerializationTag tag = readTag();
@@ -2859,7 +2901,7 @@
             }
             JSValue cryptoKey;
             Vector<RefPtr<MessagePort>> dummyMessagePorts;
-            CloneDeserializer rawKeyDeserializer(m_exec, m_globalObject, dummyMessagePorts, nullptr,
+            CloneDeserializer rawKeyDeserializer(m_exec, m_globalObject, dummyMessagePorts, nullptr, { },
 #if ENABLE(WEBASSEMBLY)
                 nullptr,
 #endif
@@ -2886,6 +2928,8 @@
             return readDOMMatrix<DOMMatrix>();
         case DOMQuadTag:
             return readDOMQuad();
+        case ImageBitmapTransferTag:
+            return readImageBitmap();
         default:
             m_ptr--; // Push the tag back
             return JSValue();
@@ -2913,6 +2957,8 @@
     Vector<String> m_blobURLs;
     Vector<String> m_blobFilePaths;
     ArrayBufferContentsArray* m_sharedBuffers;
+    Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>> m_imageBuffers;
+    Vector<RefPtr<ImageBitmap>> m_imageBitmaps;
 #if ENABLE(WEBASSEMBLY)
     WasmModuleArray* m_wasmModules;
 #endif
@@ -3123,7 +3169,7 @@
 {
 }
 
-SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray, std::unique_ptr<ArrayBufferContentsArray> sharedBufferContentsArray
+SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray, std::unique_ptr<ArrayBufferContentsArray> sharedBufferContentsArray, Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>>&& imageBuffers
 #if ENABLE(WEBASSEMBLY)
         , std::unique_ptr<WasmModuleArray> wasmModulesArray
 #endif
@@ -3131,6 +3177,7 @@
     : m_data(WTFMove(buffer))
     , m_arrayBufferContentsArray(WTFMove(arrayBufferContentsArray))
     , m_sharedBufferContentsArray(WTFMove(sharedBufferContentsArray))
+    , m_imageBuffers(WTFMove(imageBuffers))
 #if ENABLE(WEBASSEMBLY)
     , m_wasmModulesArray(WTFMove(wasmModulesArray))
 #endif
@@ -3217,12 +3264,13 @@
     Vector<uint8_t> buffer;
     Vector<String> blobURLs;
     Vector<RefPtr<MessagePort>> dummyMessagePorts;
+    Vector<RefPtr<ImageBitmap>> dummyImageBitmaps;
     Vector<RefPtr<JSC::ArrayBuffer>> dummyArrayBuffers;
 #if ENABLE(WEBASSEMBLY)
     WasmModuleArray dummyModules;
 #endif
     ArrayBufferContentsArray dummySharedBuffers;
-    auto code = CloneSerializer::serialize(&exec, value, dummyMessagePorts, dummyArrayBuffers,
+    auto code = CloneSerializer::serialize(&exec, value, dummyMessagePorts, dummyArrayBuffers, dummyImageBitmaps,
 #if ENABLE(WEBASSEMBLY)
         dummyModules,
 #endif
@@ -3238,7 +3286,7 @@
     if (code != SerializationReturnCode::SuccessfullyCompleted)
         return nullptr;
 
-    return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, nullptr, nullptr
+    return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, nullptr, nullptr, { }
 #if ENABLE(WEBASSEMBLY)
         , nullptr
 #endif
@@ -3245,10 +3293,21 @@
             ));
 }
 
+static bool containsDuplicates(const Vector<RefPtr<ImageBitmap>>& imageBitmaps)
+{
+    HashSet<ImageBitmap*> visited;
+    for (auto& imageBitmap : imageBitmaps) {
+        if (!visited.add(imageBitmap.get()))
+            return true;
+    }
+    return false;
+}
+
 ExceptionOr<Ref<SerializedScriptValue>> SerializedScriptValue::create(ExecState& state, JSValue value, Vector<JSC::Strong<JSC::JSObject>>&& transferList, Vector<RefPtr<MessagePort>>& messagePorts, SerializationContext context)
 {
     VM& vm = state.vm();
     Vector<RefPtr<JSC::ArrayBuffer>> arrayBuffers;
+    Vector<RefPtr<ImageBitmap>> imageBitmaps;
     for (auto& transferable : transferList) {
         if (auto arrayBuffer = toPossiblySharedArrayBuffer(vm, transferable.get())) {
             if (arrayBuffer->isNeutered())
@@ -3267,9 +3326,20 @@
             continue;
         }
 
+        if (auto imageBitmap = JSImageBitmap::toWrapped(vm, transferable.get())) {
+            if (imageBitmap->isDetached())
+                return Exception { DataCloneError };
+
+            imageBitmaps.append(WTFMove(imageBitmap));
+            continue;
+        }
+
         return Exception { DataCloneError };
     }
 
+    if (containsDuplicates(imageBitmaps))
+        return Exception { DataCloneError };
+
     Vector<uint8_t> buffer;
     Vector<String> blobURLs;
 #if ENABLE(WEBASSEMBLY)
@@ -3276,7 +3346,7 @@
     WasmModuleArray wasmModules;
 #endif
     std::unique_ptr<ArrayBufferContentsArray> sharedBuffers = std::make_unique<ArrayBufferContentsArray>();
-    auto code = CloneSerializer::serialize(&state, value, messagePorts, arrayBuffers, 
+    auto code = CloneSerializer::serialize(&state, value, messagePorts, arrayBuffers, imageBitmaps,
 #if ENABLE(WEBASSEMBLY)
         wasmModules, 
 #endif
@@ -3289,7 +3359,9 @@
     if (arrayBufferContentsArray.hasException())
         return arrayBufferContentsArray.releaseException();
 
-    return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr
+    auto imageBuffers = ImageBitmap::detachBitmaps(WTFMove(imageBitmaps));
+
+    return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr, WTFMove(imageBuffers)
 #if ENABLE(WEBASSEMBLY)
                 , std::make_unique<WasmModuleArray>(wasmModules)
 #endif
@@ -3342,7 +3414,7 @@
 
 JSValue SerializedScriptValue::deserialize(ExecState& exec, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths, SerializationErrorMode throwExceptions)
 {
-    DeserializationResult result = CloneDeserializer::deserialize(&exec, globalObject, messagePorts, m_arrayBufferContentsArray.get(), m_data, blobURLs, blobFilePaths, m_sharedBufferContentsArray.get()
+    DeserializationResult result = CloneDeserializer::deserialize(&exec, globalObject, messagePorts, WTFMove(m_imageBuffers), m_arrayBufferContentsArray.get(), m_data, blobURLs, blobFilePaths, m_sharedBufferContentsArray.get()
 #if ENABLE(WEBASSEMBLY)
         , m_wasmModulesArray.get()
 #endif

Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.h (230347 => 230348)


--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.h	2018-04-06 19:19:41 UTC (rev 230347)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.h	2018-04-06 19:20:35 UTC (rev 230348)
@@ -27,6 +27,7 @@
 #pragma once
 
 #include "ExceptionOr.h"
+#include "ImageBuffer.h"
 #include <_javascript_Core/ArrayBuffer.h>
 #include <_javascript_Core/JSCJSValue.h>
 #include <_javascript_Core/Strong.h>
@@ -46,6 +47,7 @@
 namespace WebCore {
 
 class IDBValue;
+class ImageBitmap;
 class MessagePort;
 class SharedBuffer;
 enum class SerializationReturnCode;
@@ -103,7 +105,7 @@
 
 private:
     WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&);
-    SerializedScriptValue(Vector<unsigned char>&&, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers
+    SerializedScriptValue(Vector<unsigned char>&&, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers, Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>>&& imageBuffers
 #if ENABLE(WEBASSEMBLY)
         , std::unique_ptr<WasmModuleArray>
 #endif
@@ -112,6 +114,7 @@
     Vector<unsigned char> m_data;
     std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
     std::unique_ptr<ArrayBufferContentsArray> m_sharedBufferContentsArray;
+    Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>> m_imageBuffers;
 #if ENABLE(WEBASSEMBLY)
     std::unique_ptr<WasmModuleArray> m_wasmModulesArray;
 #endif

Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (230347 => 230348)


--- trunk/Source/WebCore/html/ImageBitmap.cpp	2018-04-06 19:19:41 UTC (rev 230347)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp	2018-04-06 19:20:35 UTC (rev 230348)
@@ -59,6 +59,13 @@
     return create(ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode));
 }
 
+Ref<ImageBitmap> ImageBitmap::create(std::pair<std::unique_ptr<ImageBuffer>, bool>&& buffer)
+{
+    auto imageBitmap = create(WTFMove(buffer.first));
+    imageBitmap->m_originClean = buffer.second;
+    return imageBitmap;
+}
+
 Ref<ImageBitmap> ImageBitmap::create(std::unique_ptr<ImageBuffer>&& buffer)
 {
     return adoptRef(*new ImageBitmap(WTFMove(buffer)));
@@ -73,6 +80,15 @@
     );
 }
 
+Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>> ImageBitmap::detachBitmaps(Vector<RefPtr<ImageBitmap>>&& bitmaps)
+{
+    Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>> buffers;
+    for (auto& bitmap : bitmaps)
+        buffers.append(std::make_pair(bitmap->transferOwnershipAndClose(), bitmap->originClean()));
+    return buffers;
+}
+
+
 void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, ImageBitmap::Source&& source, ImageBitmapOptions&& options, int sx, int sy, int sw, int sh, ImageBitmap::Promise&& promise)
 {
     // 1. If either the sw or sh arguments are specified but zero, return a promise

Modified: trunk/Source/WebCore/html/ImageBitmap.h (230347 => 230348)


--- trunk/Source/WebCore/html/ImageBitmap.h	2018-04-06 19:19:41 UTC (rev 230347)
+++ trunk/Source/WebCore/html/ImageBitmap.h	2018-04-06 19:20:35 UTC (rev 230348)
@@ -64,6 +64,7 @@
     static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, int sx, int sy, int sw, int sh, Promise&&);
 
     static Ref<ImageBitmap> create(IntSize);
+    static Ref<ImageBitmap> create(std::pair<std::unique_ptr<ImageBuffer>, bool>&&);
 
     ~ImageBitmap();
 
@@ -79,6 +80,8 @@
 
     std::unique_ptr<ImageBuffer> transferOwnershipAndClose();
 
+    static Vector<std::pair<std::unique_ptr<ImageBuffer>, bool>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
+
 private:
     friend class PendingImageBitmap;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to