Title: [213344] trunk
Revision
213344
Author
aes...@apple.com
Date
2017-03-02 20:12:15 -0800 (Thu, 02 Mar 2017)

Log Message

Add support for canvas.toBlob
https://bugs.webkit.org/show_bug.cgi?id=148878
<rdar://problem/22590406>

Reviewed by Tim Horton.

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg-expected.txt:
* web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png-expected.txt:

Source/WebCore:

These tests now pass:
imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg.html
imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png.html

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* fileapi/BlobCallback.cpp: Added.
(WebCore::BlobCallback::scheduleCallback):
* fileapi/BlobCallback.h: Added.
(WebCore::BlobCallback::~BlobCallback):
* fileapi/BlobCallback.idl: Added.
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::toBlob):
* html/HTMLCanvasElement.h:
* html/HTMLCanvasElement.idl:
* platform/graphics/ImageBuffer.h:
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::writeFunction):
(WebCore::encodeImage):
(WebCore::ImageBuffer::toDataURL):
(WebCore::ImageBuffer::toData):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::data):
(WebCore::ImageBuffer::toDataURL):
(WebCore::ImageBuffer::toData):
(WebCore::ImageBuffer::toCGImage):
(WebCore::cgImage):
(WebCore::dataURL):
* platform/graphics/gtk/ImageBufferGtk.cpp:
(WebCore::ImageBuffer::toDataURL):
(WebCore::ImageBuffer::toData):
* platform/graphics/win/ImageBufferDirect2D.cpp:
(WebCore::ImageBuffer::toData):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (213343 => 213344)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-03-03 04:12:15 UTC (rev 213344)
@@ -1,3 +1,14 @@
+2017-03-02  Andy Estes  <aes...@apple.com>
+
+        Add support for canvas.toBlob
+        https://bugs.webkit.org/show_bug.cgi?id=148878
+        <rdar://problem/22590406>
+
+        Reviewed by Tim Horton.
+
+        * web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg-expected.txt:
+        * web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png-expected.txt:
+
 2017-03-02  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r213301.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg-expected.txt (213343 => 213344)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg-expected.txt	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg-expected.txt	2017-03-03 04:12:15 UTC (rev 213344)
@@ -1,5 +1,3 @@
 
-FAIL toBlob with image/jpeg returns a JPEG Blob canvas.toBlob is not a function. (In 'canvas.toBlob(this.step_func_done(function(data) {
-            assert_equals(data.type, "image/jpeg");
-        }), 'image/jpeg')', 'canvas.toBlob' is undefined)
+PASS toBlob with image/jpeg returns a JPEG Blob 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png-expected.txt (213343 => 213344)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png-expected.txt	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png-expected.txt	2017-03-03 04:12:15 UTC (rev 213344)
@@ -1,5 +1,3 @@
 
-FAIL toBlob with image/png returns a PNG Blob canvas.toBlob is not a function. (In 'canvas.toBlob(this.step_func_done(function(data) {
-            assert_equals(data.type, "image/png");
-        }), 'image/png')', 'canvas.toBlob' is undefined)
+PASS toBlob with image/png returns a PNG Blob 
 

Modified: trunk/Source/WebCore/CMakeLists.txt (213343 => 213344)


--- trunk/Source/WebCore/CMakeLists.txt	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-03-03 04:12:15 UTC (rev 213344)
@@ -474,6 +474,7 @@
     dom/XMLDocument.idl
 
     fileapi/Blob.idl
+    fileapi/BlobCallback.idl
     fileapi/BlobLineEndings.idl
     fileapi/BlobPropertyBag.idl
     fileapi/File.idl
@@ -1604,6 +1605,7 @@
     fileapi/AsyncFileStream.cpp
     fileapi/Blob.cpp
     fileapi/BlobBuilder.cpp
+    fileapi/BlobCallback.cpp
     fileapi/BlobURL.cpp
     fileapi/File.cpp
     fileapi/FileException.cpp

Modified: trunk/Source/WebCore/ChangeLog (213343 => 213344)


--- trunk/Source/WebCore/ChangeLog	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/ChangeLog	2017-03-03 04:12:15 UTC (rev 213344)
@@ -1,3 +1,46 @@
+2017-03-02  Andy Estes  <aes...@apple.com>
+
+        Add support for canvas.toBlob
+        https://bugs.webkit.org/show_bug.cgi?id=148878
+        <rdar://problem/22590406>
+
+        Reviewed by Tim Horton.
+
+        These tests now pass:
+        imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.jpeg.html
+        imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/toBlob.png.html
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * WebCore.xcodeproj/project.pbxproj:
+        * fileapi/BlobCallback.cpp: Added.
+        (WebCore::BlobCallback::scheduleCallback):
+        * fileapi/BlobCallback.h: Added.
+        (WebCore::BlobCallback::~BlobCallback):
+        * fileapi/BlobCallback.idl: Added.
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::toBlob):
+        * html/HTMLCanvasElement.h:
+        * html/HTMLCanvasElement.idl:
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::writeFunction):
+        (WebCore::encodeImage):
+        (WebCore::ImageBuffer::toDataURL):
+        (WebCore::ImageBuffer::toData):
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::data):
+        (WebCore::ImageBuffer::toDataURL):
+        (WebCore::ImageBuffer::toData):
+        (WebCore::ImageBuffer::toCGImage):
+        (WebCore::cgImage):
+        (WebCore::dataURL):
+        * platform/graphics/gtk/ImageBufferGtk.cpp:
+        (WebCore::ImageBuffer::toDataURL):
+        (WebCore::ImageBuffer::toData):
+        * platform/graphics/win/ImageBufferDirect2D.cpp:
+        (WebCore::ImageBuffer::toData):
+
 2017-03-02  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Migrate font-stretch to use fixed-point values

Modified: trunk/Source/WebCore/DerivedSources.make (213343 => 213344)


--- trunk/Source/WebCore/DerivedSources.make	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/DerivedSources.make	2017-03-03 04:12:15 UTC (rev 213344)
@@ -403,6 +403,7 @@
     $(WebCore)/dom/WheelEvent.idl \
     $(WebCore)/dom/XMLDocument.idl \
     $(WebCore)/fileapi/Blob.idl \
+    $(WebCore)/fileapi/BlobCallback.idl \
     $(WebCore)/fileapi/BlobLineEndings.idl \
     $(WebCore)/fileapi/BlobPropertyBag.idl \
     $(WebCore)/fileapi/File.idl \

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (213343 => 213344)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-03-03 04:12:15 UTC (rev 213344)
@@ -4027,6 +4027,10 @@
 		A149786E1ABAF33800CEF7E4 /* ContentFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */; };
 		A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A149786D1ABAF33800CEF7E4 /* ContentFilter.h */; };
 		A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */; };
+		A15D75151E68F7C400A35FBC /* BlobCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A15D75121E68F7B100A35FBC /* BlobCallback.cpp */; };
+		A15D75161E68F7C800A35FBC /* BlobCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = A15D75131E68F7B100A35FBC /* BlobCallback.h */; };
+		A15D751A1E68F89E00A35FBC /* JSBlobCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A15D75171E68F83600A35FBC /* JSBlobCallback.cpp */; };
+		A15D751B1E68F8A300A35FBC /* JSBlobCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = A15D75181E68F83600A35FBC /* JSBlobCallback.h */; };
 		A15E31F31E0CB0B2004B371C /* QuickLook.mm in Sources */ = {isa = PBXBuildFile; fileRef = A15E31F21E0CB0AA004B371C /* QuickLook.mm */; };
 		A15E31F41E0CB0B5004B371C /* QuickLook.h in Headers */ = {isa = PBXBuildFile; fileRef = A15E31F11E0CB0AA004B371C /* QuickLook.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A15E6BF11E212A6A0080AF34 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A15E6BF01E212A6A0080AF34 /* Foundation.framework */; };
@@ -11883,6 +11887,11 @@
 		A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentFilter.cpp; sourceTree = "<group>"; };
 		A149786D1ABAF33800CEF7E4 /* ContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilter.h; sourceTree = "<group>"; };
 		A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformContentFilter.h; sourceTree = "<group>"; };
+		A15D75121E68F7B100A35FBC /* BlobCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobCallback.cpp; sourceTree = "<group>"; };
+		A15D75131E68F7B100A35FBC /* BlobCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobCallback.h; sourceTree = "<group>"; };
+		A15D75141E68F7B100A35FBC /* BlobCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = BlobCallback.idl; sourceTree = "<group>"; };
+		A15D75171E68F83600A35FBC /* JSBlobCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSBlobCallback.cpp; sourceTree = "<group>"; };
+		A15D75181E68F83600A35FBC /* JSBlobCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBlobCallback.h; sourceTree = "<group>"; };
 		A15E31F11E0CB0AA004B371C /* QuickLook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLook.h; sourceTree = "<group>"; };
 		A15E31F21E0CB0AA004B371C /* QuickLook.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QuickLook.mm; sourceTree = "<group>"; };
 		A15E6BF01E212A6A0080AF34 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -18938,6 +18947,8 @@
 			children = (
 				2E2D99CB10E2BBDA00496337 /* JSBlob.cpp */,
 				2E2D99CC10E2BBDA00496337 /* JSBlob.h */,
+				A15D75171E68F83600A35FBC /* JSBlobCallback.cpp */,
+				A15D75181E68F83600A35FBC /* JSBlobCallback.h */,
 				7C77C3D91DEF86D700A50BFA /* JSBlobLineEndings.cpp */,
 				7C77C3DA1DEF86D700A50BFA /* JSBlobLineEndings.h */,
 				7C77C3D21DEF178E00A50BFA /* JSBlobPropertyBag.cpp */,
@@ -19872,6 +19883,9 @@
 				14A98E05136386A200C9FED2 /* Blob.idl */,
 				976D6C5C122B8A3D001FD1F7 /* BlobBuilder.cpp */,
 				976D6C5D122B8A3D001FD1F7 /* BlobBuilder.h */,
+				A15D75121E68F7B100A35FBC /* BlobCallback.cpp */,
+				A15D75131E68F7B100A35FBC /* BlobCallback.h */,
+				A15D75141E68F7B100A35FBC /* BlobCallback.idl */,
 				7C77C3D61DEF850A00A50BFA /* BlobLineEndings.h */,
 				7C77C3D81DEF854000A50BFA /* BlobLineEndings.idl */,
 				7C77C3D01DEE472400A50BFA /* BlobPropertyBag.h */,
@@ -26896,6 +26910,7 @@
 				1AE2ABAB0A1CE90500B42B25 /* JSHTMLPreElement.h in Headers */,
 				A4226E5C1163D695008B8397 /* JSHTMLProgressElement.h in Headers */,
 				1AE2AEC80A1D297B00B42B25 /* JSHTMLQuoteElement.h in Headers */,
+				A15D751B1E68F8A300A35FBC /* JSBlobCallback.h in Headers */,
 				1AE2ABAD0A1CE90500B42B25 /* JSHTMLScriptElement.h in Headers */,
 				E1E6EEA80B628DB3005F2F70 /* JSHTMLSelectElement.h in Headers */,
 				AB4CB4EB0B8BDA3D009F40B0 /* JSHTMLSelectElementCustom.h in Headers */,
@@ -28290,6 +28305,7 @@
 				FEE1811416C319E800084849 /* SQLTransactionBackend.h in Headers */,
 				97BC6A521505F081001B74AC /* SQLTransactionCallback.h in Headers */,
 				97BC6A571505F081001B74AC /* SQLTransactionCoordinator.h in Headers */,
+				A15D75161E68F7C800A35FBC /* BlobCallback.h in Headers */,
 				97BC6A581505F081001B74AC /* SQLTransactionErrorCallback.h in Headers */,
 				FE36FD1816C7826500F887C1 /* SQLTransactionState.h in Headers */,
 				FE36FD1716C7826500F887C1 /* SQLTransactionStateMachine.h in Headers */,
@@ -31071,6 +31087,7 @@
 				B2FA3E080AB75A6F000E5AC4 /* JSSVGTitleElement.cpp in Sources */,
 				B2FA3E0A0AB75A6F000E5AC4 /* JSSVGTransform.cpp in Sources */,
 				B2FA3E0C0AB75A6F000E5AC4 /* JSSVGTransformList.cpp in Sources */,
+				A15D75151E68F7C400A35FBC /* BlobCallback.cpp in Sources */,
 				B2FA3E0E0AB75A6F000E5AC4 /* JSSVGTRefElement.cpp in Sources */,
 				B2FA3E100AB75A6F000E5AC4 /* JSSVGTSpanElement.cpp in Sources */,
 				B2FA3E120AB75A6F000E5AC4 /* JSSVGUnitTypes.cpp in Sources */,
@@ -32420,6 +32437,7 @@
 				444D4E230F708B2E003158E0 /* WebCoreURLResponseIOS.mm in Sources */,
 				93F19B0708245E59001E9ABC /* WebCoreView.m in Sources */,
 				A5E616731894581F009ADF50 /* WebDebuggerAgent.cpp in Sources */,
+				A15D751A1E68F89E00A35FBC /* JSBlobCallback.cpp in Sources */,
 				FE0D84EB1048436E001A179E /* WebEvent.mm in Sources */,
 				225A16B60D5C11E900090295 /* WebEventRegion.mm in Sources */,
 				D3F3D36D1A69B7DC0059FC2B /* WebGL2RenderingContext.cpp in Sources */,

Added: trunk/Source/WebCore/fileapi/BlobCallback.cpp (0 => 213344)


--- trunk/Source/WebCore/fileapi/BlobCallback.cpp	                        (rev 0)
+++ trunk/Source/WebCore/fileapi/BlobCallback.cpp	2017-03-03 04:12:15 UTC (rev 213344)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "BlobCallback.h"
+
+#include "Blob.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+void BlobCallback::scheduleCallback(ScriptExecutionContext& context, RefPtr<Blob>&& blob)
+{
+    context.postTask([this, protectedThis = makeRef(*this), blob = WTFMove(blob)](ScriptExecutionContext&) {
+        handleEvent(blob.get());
+    });
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/fileapi/BlobCallback.h (0 => 213344)


--- trunk/Source/WebCore/fileapi/BlobCallback.h	                        (rev 0)
+++ trunk/Source/WebCore/fileapi/BlobCallback.h	2017-03-03 04:12:15 UTC (rev 213344)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Blob;
+class ScriptExecutionContext;
+
+class BlobCallback : public RefCounted<BlobCallback> {
+public:
+    virtual ~BlobCallback() { }
+    virtual bool handleEvent(Blob*) = 0;
+
+    void scheduleCallback(ScriptExecutionContext&, RefPtr<Blob>&&);
+};
+
+} // namespace WebCore

Added: trunk/Source/WebCore/fileapi/BlobCallback.idl (0 => 213344)


--- trunk/Source/WebCore/fileapi/BlobCallback.idl	                        (rev 0)
+++ trunk/Source/WebCore/fileapi/BlobCallback.idl	2017-03-03 04:12:15 UTC (rev 213344)
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+callback BlobCallback = void (Blob? blob);

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (213343 => 213344)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2017-03-03 04:12:15 UTC (rev 213344)
@@ -28,6 +28,8 @@
 #include "config.h"
 #include "HTMLCanvasElement.h"
 
+#include "Blob.h"
+#include "BlobCallback.h"
 #include "CanvasGradient.h"
 #include "CanvasPattern.h"
 #include "CanvasRenderingContext2D.h"
@@ -485,6 +487,36 @@
     return buffer()->toDataURL(encodingMIMEType, quality);
 }
 
+ExceptionOr<void> HTMLCanvasElement::toBlob(ScriptExecutionContext& context, Ref<BlobCallback>&& callback, const String& mimeType, JSC::JSValue qualityValue)
+{
+    if (!m_originClean)
+        return Exception { SECURITY_ERR };
+
+    if (m_size.isEmpty() || !buffer()) {
+        callback->scheduleCallback(context, nullptr);
+        return { };
+    }
+
+    String encodingMIMEType = toEncodingMimeType(mimeType);
+    std::optional<double> quality;
+    if (qualityValue.isNumber())
+        quality = qualityValue.toNumber(context.execState());
+
+#if USE(CG)
+    if (auto imageData = getImageData()) {
+        Vector<uint8_t> blobData = data(*imageData, encodingMIMEType, quality);
+        callback->scheduleCallback(context, Blob::create(WTFMove(blobData), encodingMIMEType));
+        return { };
+    }
+#endif
+
+    makeRenderingResultsAvailable();
+
+    Vector<uint8_t> blobData = buffer()->toData(encodingMIMEType, quality);
+    callback->scheduleCallback(context, Blob::create(WTFMove(blobData), encodingMIMEType));
+    return { };
+}
+
 RefPtr<ImageData> HTMLCanvasElement::getImageData()
 {
 #if ENABLE(WEBGL)

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (213343 => 213344)


--- trunk/Source/WebCore/html/HTMLCanvasElement.h	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h	2017-03-03 04:12:15 UTC (rev 213344)
@@ -39,6 +39,7 @@
 
 namespace WebCore {
 
+class BlobCallback;
 class CanvasRenderingContext;
 class GraphicsContext;
 class GraphicsContextStateSaver;
@@ -101,6 +102,7 @@
     static String toEncodingMimeType(const String& mimeType);
     WEBCORE_EXPORT ExceptionOr<String> toDataURL(const String& mimeType, std::optional<double> quality);
     ExceptionOr<String> toDataURL(const String& mimeType) { return toDataURL(mimeType, std::nullopt); }
+    ExceptionOr<void> toBlob(ScriptExecutionContext&, Ref<BlobCallback>&&, const String& mimeType, JSC::JSValue qualityValue);
 
     // Used for rendering
     void didDraw(const FloatRect&);

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.idl (213343 => 213344)


--- trunk/Source/WebCore/html/HTMLCanvasElement.idl	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.idl	2017-03-03 04:12:15 UTC (rev 213344)
@@ -37,4 +37,5 @@
     [Custom] RenderingContext? getContext(DOMString contextId, any... arguments);
 
     [Custom, MayThrowException] DOMString toDataURL(optional DOMString? type);
+    [CallWith=ScriptExecutionContext, MayThrowException] void toBlob(BlobCallback callback, optional DOMString type, optional any quality);
 };

Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (213343 => 213344)


--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2017-03-03 04:12:15 UTC (rev 213344)
@@ -112,6 +112,7 @@
     void convertToLuminanceMask();
     
     String toDataURL(const String& mimeType, std::optional<double> quality = std::nullopt, CoordinateSystem = LogicalCoordinateSystem) const;
+    Vector<uint8_t> toData(const String& mimeType, std::optional<double> quality = std::nullopt) const;
 #if !USE(CG)
     AffineTransform baseTransform() const { return AffineTransform(); }
     void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace);
@@ -174,6 +175,7 @@
     WEBCORE_EXPORT ImageBuffer(const FloatSize&, float resolutionScale, ColorSpace, RenderingMode, bool& success);
 #if USE(CG)
     ImageBuffer(const FloatSize&, float resolutionScale, CGColorSpaceRef, RenderingMode, bool& success);
+    RetainPtr<CGImageRef> toCGImage(const String& mimeType) const;
 #elif USE(DIRECT2D)
     ImageBuffer(const FloatSize&, float resolutionScale, ColorSpace, RenderingMode, const GraphicsContext*, bool& success);
 #endif
@@ -181,6 +183,7 @@
 
 #if USE(CG)
 String dataURL(const ImageData&, const String& mimeType, std::optional<double> quality);
+Vector<uint8_t> data(const ImageData&, const String& mimeType, std::optional<double> quality);
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (213343 => 213344)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-03-03 04:12:15 UTC (rev 213344)
@@ -539,12 +539,12 @@
 #if !PLATFORM(GTK)
 static cairo_status_t writeFunction(void* output, const unsigned char* data, unsigned int length)
 {
-    if (!reinterpret_cast<Vector<unsigned char>*>(output)->tryAppend(data, length))
+    if (!reinterpret_cast<Vector<uint8_t>*>(output)->tryAppend(data, length))
         return CAIRO_STATUS_WRITE_ERROR;
     return CAIRO_STATUS_SUCCESS;
 }
 
-static bool encodeImage(cairo_surface_t* image, const String& mimeType, Vector<char>* output)
+static bool encodeImage(cairo_surface_t* image, const String& mimeType, Vector<uint8_t>* output)
 {
     ASSERT_UNUSED(mimeType, mimeType == "image/png"); // Only PNG output is supported for now.
 
@@ -553,19 +553,29 @@
 
 String ImageBuffer::toDataURL(const String& mimeType, std::optional<double>, CoordinateSystem) const
 {
+    Vector<uint8_t> encodedImage = toData(mimeType, quality);
+    if (encodedImage.isEmpty())
+        return "data:,";
+
+    Vector<char> base64Data;
+    base64Encode(encodedImage.data(), encodedImage.size(), base64Data);
+
+    return "data:" + mimeType + ";base64," + base64Data;
+}
+
+Vector<uint8_t> ImageBuffer::toData(const String& mimeType, std::optional<double> quality) const
+{
     ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
 
     cairo_surface_t* image = cairo_get_target(context().platformContext()->cr());
 
-    Vector<char> encodedImage;
+    Vector<uint8_t> encodedImage;
     if (!image || !encodeImage(image, mimeType, &encodedImage))
-        return "data:,";
+        return { };
 
-    Vector<char> base64Data;
-    base64Encode(encodedImage, base64Data);
+    return encodedImage;
+}
 
-    return "data:" + mimeType + ";base64," + base64Data;
-}
 #endif
 
 #if ENABLE(ACCELERATED_2D_CANVAS) && !USE(COORDINATED_GRAPHICS_THREADED)

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp (213343 => 213344)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp	2017-03-03 04:12:15 UTC (rev 213344)
@@ -498,8 +498,36 @@
     return "data:" + mimeType + ";base64," + base64Data;
 }
 
+static Vector<uint8_t> data(CGImageRef image, const String& mimeType, std::optional<double> quality)
+{
+    auto uti = utiFromMIMEType(mimeType);
+    ASSERT(uti);
+
+    auto cfData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
+    if (!encodeImage(image, uti.get(), quality, cfData.get()))
+        return { };
+
+    Vector<uint8_t> data;
+    data.append(CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()));
+    return data;
+}
+
 String ImageBuffer::toDataURL(const String& mimeType, std::optional<double> quality, CoordinateSystem) const
 {
+    if (auto image = toCGImage(mimeType))
+        return dataURL(image.get(), mimeType, quality);
+    return ASCIILiteral("data:,");
+}
+
+Vector<uint8_t> ImageBuffer::toData(const String& mimeType, std::optional<double> quality) const
+{
+    if (auto image = toCGImage(mimeType))
+        return data(image.get(), mimeType, quality);
+    return { };
+}
+
+RetainPtr<CGImageRef> ImageBuffer::toCGImage(const String& mimeType) const
+{
     ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
 
     if (context().isAcceleratedContext())
@@ -515,14 +543,13 @@
         // JPEGs don't have an alpha channel, so we have to manually composite on top of black.
         premultipliedData = getPremultipliedImageData(IntRect(IntPoint(0, 0), logicalSize()));
         if (!premultipliedData)
-            return ASCIILiteral("data:,");
+            return nullptr;
 
         auto dataProvider = adoptCF(CGDataProviderCreateWithData(0, premultipliedData->data(), 4 * logicalSize().width() * logicalSize().height(), 0));
         if (!dataProvider)
-            return ASCIILiteral("data:,");
+            return nullptr;
 
-        image = adoptCF(CGImageCreate(logicalSize().width(), logicalSize().height(), 8, 32, 4 * logicalSize().width(),
-            sRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
+        image = adoptCF(CGImageCreate(logicalSize().width(), logicalSize().height(), 8, 32, 4 * logicalSize().width(), sRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
     } else if (m_resolutionScale == 1) {
         image = copyNativeImage(CopyBackingStore);
         image = createCroppedImageIfNecessary(image.get(), internalSize());
@@ -536,10 +563,10 @@
         image = adoptCF(CGBitmapContextCreateImage(context.get()));
     }
 
-    return dataURL(image.get(), mimeType, quality);
+    return image;
 }
 
-String dataURL(const ImageData& source, const String& mimeType, std::optional<double> quality)
+static RetainPtr<CGImageRef> cgImage(const ImageData& source, const String& mimeType)
 {
     ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
 
@@ -554,7 +581,7 @@
         // JPEGs don't have an alpha channel, so we have to manually composite on top of black.
         size_t size = 4 * source.width() * source.height();
         if (!premultipliedData.tryReserveCapacity(size))
-            return ASCIILiteral("data:,");
+            return nullptr;
 
         premultipliedData.resize(size);
         unsigned char *buffer = premultipliedData.data();
@@ -577,13 +604,26 @@
 
     auto dataProvider = adoptCF(CGDataProviderCreateWithData(0, data, 4 * source.width() * source.height(), 0));
     if (!dataProvider)
-        return ASCIILiteral("data:,");
+        return nullptr;
 
-    auto image = adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(),
-        sRGBColorSpaceRef(), kCGBitmapByteOrderDefault | dataAlphaInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
-    return dataURL(image.get(), mimeType, quality);
+    auto image = adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(), sRGBColorSpaceRef(), kCGBitmapByteOrderDefault | dataAlphaInfo, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
+    return image;
 }
 
+String dataURL(const ImageData& source, const String& mimeType, std::optional<double> quality)
+{
+    if (auto image = cgImage(source, mimeType))
+        return dataURL(image.get(), mimeType, quality);
+    return ASCIILiteral("data:,");
+}
+
+Vector<uint8_t> data(const ImageData& source, const String& mimeType, std::optional<double> quality)
+{
+    if (auto image = cgImage(source, mimeType))
+        return data(image.get(), mimeType, quality);
+    return { };
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp (213343 => 213344)


--- trunk/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp	2017-03-03 04:12:15 UTC (rev 213344)
@@ -77,17 +77,28 @@
 
 String ImageBuffer::toDataURL(const String& mimeType, std::optional<double> quality, CoordinateSystem) const
 {
+    Vector<uint8_t> imageData = toData(mimeType, quality);
+    if (imageData.isEmpty())
+        return "data:,";
+
+    Vector<char> base64Data;
+    base64Encode(imageData.data(), imageData.size(), base64Data);
+
+    return "data:" + mimeType + ";base64," + base64Data;
+}
+
+Vector<uint8_t> ImageBuffer::toData(const String& mimeType, std::optional<double> quality) const
+{
     ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
 
     GUniqueOutPtr<gchar> buffer;
     gsize bufferSize;
     if (!encodeImage(m_data.m_surface.get(), mimeType, quality, buffer, bufferSize))
-        return "data:,";
+        return { };
 
-    Vector<char> base64Data;
-    base64Encode(buffer.get(), bufferSize, base64Data);
-
-    return "data:" + mimeType + ";base64," + base64Data;
+    Vector<uint8_t> imageData;
+    imageData.append(buffer.get(), bufferSize);
+    return imageData;
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp (213343 => 213344)


--- trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp	2017-03-03 03:59:01 UTC (rev 213343)
+++ trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp	2017-03-03 04:12:15 UTC (rev 213344)
@@ -260,6 +260,12 @@
     return ASCIILiteral("data:,");
 }
 
+Vector<uint8_t> ImageBuffer::toData(const String& mimeType, std::optional<double> quality) const
+{
+    notImplemented();
+    return { };
+}
+
 String ImageDataToDataURL(const ImageData& source, const String& mimeType, const double* quality)
 {
     notImplemented();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to