Changeset 228092 in webkit


Ignore:
Timestamp:
Feb 5, 2018 2:24:57 AM (6 years ago)
Author:
Ms2ger@igalia.com
Message:

Implement createImageBitmap(HTMLVideoElement)
https://bugs.webkit.org/show_bug.cgi?id=182388

Reviewed by Žan Doberšek.

LayoutTests/imported/w3c:

  • web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage-expected.txt:
  • web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html: Update from upstream to make the test pass on macOS.
  • web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:

Source/WebCore:

The implementation is inspired by CanvasRenderingContext2DBase::drawImage().

Tests:

  • web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html
  • web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html
  • html/ImageBitmap.cpp:

(WebCore::taintsOrigin): Add function to help with the implementation.
(WebCore::ImageBitmap::createPromise): Fill in implementation.

LayoutTests:

  • platform/gtk/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
  • platform/ios/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
  • platform/wpe/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r228042 r228092  
     12018-02-05  Ms2ger  <Ms2ger@igalia.com>
     2
     3        Implement createImageBitmap(HTMLVideoElement)
     4        https://bugs.webkit.org/show_bug.cgi?id=182388
     5
     6        Reviewed by Žan Doberšek.
     7
     8        * platform/gtk/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
     9        * platform/ios/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
     10        * platform/wpe/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
     11
    1122018-02-02  Ryan Haddad  <ryanhaddad@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r228015 r228092  
     12018-02-05  Ms2ger  <Ms2ger@igalia.com>
     2
     3        Implement createImageBitmap(HTMLVideoElement)
     4        https://bugs.webkit.org/show_bug.cgi?id=182388
     5
     6        Reviewed by Žan Doberšek.
     7
     8        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage-expected.txt:
     9        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html:
     10          Update from upstream to make the test pass on macOS.
     11        * web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt:
     12
    1132018-02-02  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage-expected.txt

    r228003 r228092  
    55PASS createImageBitmap from an HTMLCanvasElement resized, and drawImage on the created ImageBitmap
    66FAIL createImageBitmap from an HTMLCanvasElement with negative sw/sh, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "RangeError: Cannot create ImageBitmap with a negative width or height"
    7 FAIL createImageBitmap from an HTMLVideoElement, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
    8 FAIL createImageBitmap from an HTMLVideoElement scaled down, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
    9 FAIL createImageBitmap from an HTMLVideoElement scaled up, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
    10 FAIL createImageBitmap from an HTMLVideoElement resized, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
     7PASS createImageBitmap from an HTMLVideoElement, and drawImage on the created ImageBitmap
     8PASS createImageBitmap from an HTMLVideoElement scaled down, and drawImage on the created ImageBitmap
     9PASS createImageBitmap from an HTMLVideoElement scaled up, and drawImage on the created ImageBitmap
     10PASS createImageBitmap from an HTMLVideoElement resized, and drawImage on the created ImageBitmap
    1111FAIL createImageBitmap from an HTMLVideoElement with negative sw/sh, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "RangeError: Cannot create ImageBitmap with a negative width or height"
    12 FAIL createImageBitmap from an HTMLVideoElement from a data URL, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
    13 FAIL createImageBitmap from an HTMLVideoElement from a data URL scaled down, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
    14 FAIL createImageBitmap from an HTMLVideoElement from a data URL scaled up, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
    15 FAIL createImageBitmap from an HTMLVideoElement from a data URL resized, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: createImageBitmap with HTMLVideoElement is not implemented"
     12PASS createImageBitmap from an HTMLVideoElement from a data URL, and drawImage on the created ImageBitmap
     13PASS createImageBitmap from an HTMLVideoElement from a data URL scaled down, and drawImage on the created ImageBitmap
     14PASS createImageBitmap from an HTMLVideoElement from a data URL scaled up, and drawImage on the created ImageBitmap
     15PASS createImageBitmap from an HTMLVideoElement from a data URL resized, and drawImage on the created ImageBitmap
    1616FAIL createImageBitmap from an HTMLVideoElement from a data URL with negative sw/sh, and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "RangeError: Cannot create ImageBitmap with a negative width or height"
    1717PASS createImageBitmap from a bitmap HTMLImageElement, and drawImage on the created ImageBitmap
  • trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html

    r228003 r228092  
    1313function testCanvasDisplayingPattern(canvas, width, height)
    1414{
    15     var tolerance = 5; // for creating ImageBitmap from a video, the tolerance needs to be high
     15    var tolerance = 10; // for creating ImageBitmap from a video, the tolerance needs to be high
    1616    const check = (x, y, r, g, b, a) =>
    1717        _assertPixelApprox(canvas, x,y, r,g,b,a, `${x},${y}`, `${r},${g},${b},${a}`, tolerance);
  • trunk/LayoutTests/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt

    r228003 r228092  
    66PASS createImageBitmap with a an HTMLVideoElement source and sw set to 0
    77PASS createImageBitmap with a an HTMLVideoElement source and sh set to 0
    8 FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     8FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    99PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sw set to 0
    1010PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sh set to 0
    11 FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     11FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    1212PASS createImageBitmap with a a bitmap HTMLImageElement source and sw set to 0
    1313PASS createImageBitmap with a a bitmap HTMLImageElement source and sh set to 0
     
    4141PASS createImageBitmap with ArrayBuffer image source.
    4242PASS createImageBitmap with empty image source.
    43 FAIL createImageBitmap with empty video source. assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
     43PASS createImageBitmap with empty video source.
    4444PASS createImageBitmap with an oversized canvas source.
    4545FAIL createImageBitmap with an invalid OffscreenCanvas source. assert_throws: function "function () { throw e }" threw object "TypeError: Type error" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
  • trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt

    r228003 r228092  
    66PASS createImageBitmap with a an HTMLVideoElement source and sw set to 0
    77PASS createImageBitmap with a an HTMLVideoElement source and sh set to 0
    8 FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     8FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    99PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sw set to 0
    1010PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sh set to 0
    11 FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     11FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    1212PASS createImageBitmap with a a bitmap HTMLImageElement source and sw set to 0
    1313PASS createImageBitmap with a a bitmap HTMLImageElement source and sh set to 0
     
    4141PASS createImageBitmap with ArrayBuffer image source.
    4242PASS createImageBitmap with empty image source.
    43 FAIL createImageBitmap with empty video source. assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
     43PASS createImageBitmap with empty video source.
    4444PASS createImageBitmap with an oversized canvas source.
    4545FAIL createImageBitmap with an invalid OffscreenCanvas source. assert_throws: function "function () { throw e }" threw object "TypeError: Type error" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
  • trunk/LayoutTests/platform/ios/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt

    r228026 r228092  
    66PASS createImageBitmap with a an HTMLVideoElement source and sw set to 0
    77PASS createImageBitmap with a an HTMLVideoElement source and sh set to 0
    8 FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     8FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    99PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sw set to 0
    1010PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sh set to 0
    11 FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     11FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    1212PASS createImageBitmap with a a bitmap HTMLImageElement source and sw set to 0
    1313PASS createImageBitmap with a a bitmap HTMLImageElement source and sh set to 0
     
    4141PASS createImageBitmap with ArrayBuffer image source.
    4242PASS createImageBitmap with empty image source.
    43 FAIL createImageBitmap with empty video source. assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
     43PASS createImageBitmap with empty video source.
    4444PASS createImageBitmap with an oversized canvas source.
    4545FAIL createImageBitmap with an invalid OffscreenCanvas source. assert_throws: function "function () { throw e }" threw object "TypeError: Type error" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
  • trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt

    r228003 r228092  
    66PASS createImageBitmap with a an HTMLVideoElement source and sw set to 0
    77PASS createImageBitmap with a an HTMLVideoElement source and sh set to 0
    8 FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     8FAIL createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    99PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sw set to 0
    1010PASS createImageBitmap with a an HTMLVideoElement from a data URL source and sh set to 0
    11 FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" ("TypeError") expected object "InvalidStateError" ("InvalidStateError")
     11FAIL createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region assert_unreached: Should have rejected: undefined Reached unreachable code
    1212PASS createImageBitmap with a a bitmap HTMLImageElement source and sw set to 0
    1313PASS createImageBitmap with a a bitmap HTMLImageElement source and sh set to 0
     
    4141PASS createImageBitmap with ArrayBuffer image source.
    4242PASS createImageBitmap with empty image source.
    43 FAIL createImageBitmap with empty video source. assert_throws: function "function () { throw e }" threw object "TypeError: createImageBitmap with HTMLVideoElement is not implemented" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
     43PASS createImageBitmap with empty video source.
    4444PASS createImageBitmap with an oversized canvas source.
    4545FAIL createImageBitmap with an invalid OffscreenCanvas source. assert_throws: function "function () { throw e }" threw object "TypeError: Type error" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
  • trunk/Source/WebCore/ChangeLog

    r228091 r228092  
     12018-02-05  Ms2ger  <Ms2ger@igalia.com>
     2
     3        Implement createImageBitmap(HTMLVideoElement)
     4        https://bugs.webkit.org/show_bug.cgi?id=182388
     5
     6        Reviewed by Žan Doberšek.
     7
     8        The implementation is inspired by CanvasRenderingContext2DBase::drawImage().
     9
     10        Tests:
     11
     12        - web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html
     13        - web-platform-tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html
     14
     15
     16        * html/ImageBitmap.cpp:
     17        (WebCore::taintsOrigin): Add function to help with the implementation.
     18        (WebCore::ImageBitmap::createPromise): Fill in implementation.
     19
    1202018-02-05  Zan Dobersek  <zdobersek@igalia.com>
    221
  • trunk/Source/WebCore/html/ImageBitmap.cpp

    r226599 r228092  
    115115}
    116116
     117static bool taintsOrigin(SecurityOrigin* origin, HTMLVideoElement& video)
     118{
     119    if (!video.hasSingleSecurityOrigin())
     120        return true;
     121
     122    if (video.player()->didPassCORSAccessCheck())
     123        return false;
     124
     125    auto url = video.currentSrc();
     126    if (url.protocolIsData())
     127        return false;
     128
     129    return !origin->canRequest(url);
     130}
     131
    117132// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#cropped-to-the-source-rectangle-with-formatting
    118133static ExceptionOr<IntRect> croppedSourceRectangleWithFormatting(IntSize inputSize, ImageBitmapOptions& options, std::optional<IntRect> rect)
     
    364379
    365380#if ENABLE(VIDEO)
    366 void ImageBitmap::createPromise(ScriptExecutionContext&, RefPtr<HTMLVideoElement>& videoElement, ImageBitmapOptions&& options, std::optional<IntRect> rect, ImageBitmap::Promise&& promise)
    367 {
    368     UNUSED_PARAM(videoElement);
    369     UNUSED_PARAM(options);
    370     UNUSED_PARAM(rect);
    371 
    372     // 2. If the video element's networkState attribute is NETWORK_EMPTY, then return
    373     //    a promise rejected with an "InvalidStateError" DOMException and abort these
    374     //    steps.
    375 
    376     // 3. If the video element's readyState attribute is either HAVE_NOTHING or
    377     //    HAVE_METADATA, then return a promise rejected with an "InvalidStateError"
    378     //    DOMException and abort these steps.
    379 
    380     // 4. Create a new ImageBitmap object.
    381 
    382     // 5. Let the ImageBitmap object's bitmap data be a copy of the frame at the current
    383     //    playback position, at the media resource's intrinsic width and intrinsic height
    384     //    (i.e. after any aspect-ratio correction has been applied), cropped to the source
    385     //    rectangle with formatting.
    386 
    387     // 6. If the origin of the video element is not the same origin as the origin specified
    388     //    by the entry settings object, then set the origin-clean flag of the ImageBitmap
    389     //    object's bitmap to false.
    390 
    391     // 7. Return a new promise, but continue running these steps in parallel.
    392 
    393     // 8. Resolve the promise with the new ImageBitmap object as the value.
    394     promise.reject(TypeError, "createImageBitmap with HTMLVideoElement is not implemented");
     381void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, RefPtr<HTMLVideoElement>& video, ImageBitmapOptions&& options, std::optional<IntRect> rect, ImageBitmap::Promise&& promise)
     382{
     383    // https://html.spec.whatwg.org/multipage/#dom-createimagebitmap
     384    // WHATWG HTML 2102913b313078cd8eeac7e81e6a8756cbd3e773
     385    // Steps 3-7.
     386    // (Step 3 is handled in croppedSourceRectangleWithFormatting.)
     387
     388    // 4. Check the usability of the image argument. If this throws an exception
     389    //    or returns bad, then return p rejected with an "InvalidStateError"
     390    //    DOMException.
     391    if (video->readyState() == HTMLMediaElement::HAVE_NOTHING || video->readyState() == HTMLMediaElement::HAVE_METADATA) {
     392        promise.reject(InvalidStateError, "Cannot create ImageBitmap before the HTMLVideoElement has data");
     393        return;
     394    }
     395
     396    // 5. Let imageBitmap be a new ImageBitmap object.
     397    auto imageBitmap = create();
     398
     399    // 6.1. If image's networkState attribute is NETWORK_EMPTY, then return p
     400    //      rejected with an "InvalidStateError" DOMException.
     401    if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) {
     402        promise.reject(InvalidStateError, "Cannot create ImageBitmap before the HTMLVideoElement has data");
     403        return;
     404    }
     405
     406    // 6.2. Set imageBitmap's bitmap data to a copy of the frame at the current
     407    //      playback position, at the media resource's intrinsic width and
     408    //      intrinsic height (i.e., after any aspect-ratio correction has been
     409    //      applied), cropped to the source rectangle with formatting.
     410    auto size = video->player() ? roundedIntSize(video->player()->naturalSize()) : IntSize();
     411    auto maybeSourceRectangle = croppedSourceRectangleWithFormatting(size, options, WTFMove(rect));
     412    if (maybeSourceRectangle.hasException()) {
     413        promise.reject(maybeSourceRectangle.releaseException());
     414        return;
     415    }
     416    auto sourceRectangle = maybeSourceRectangle.releaseReturnValue();
     417
     418    auto outputSize = outputSizeForSourceRectangle(sourceRectangle, options);
     419    auto bitmapData = ImageBuffer::create(FloatSize(outputSize.width(), outputSize.height()), bufferRenderingMode);
     420
     421    {
     422        GraphicsContext& c = bitmapData->context();
     423        GraphicsContextStateSaver stateSaver(c);
     424        c.clip(FloatRect(FloatPoint(), outputSize));
     425        auto scaleX = float(outputSize.width()) / float(sourceRectangle.width());
     426        auto scaleY = float(outputSize.height()) / float(sourceRectangle.height());
     427        c.scale(FloatSize(scaleX, scaleY));
     428        c.translate(-sourceRectangle.location());
     429        video->paintCurrentFrameInContext(c, FloatRect(FloatPoint(), size));
     430    }
     431
     432    imageBitmap->m_bitmapData = WTFMove(bitmapData);
     433
     434    // 6.3. If the origin of image's video is not same origin with entry
     435    //      settings object's origin, then set the origin-clean flag of
     436    //      image's bitmap to false.
     437    imageBitmap->m_originClean = !taintsOrigin(scriptExecutionContext.securityOrigin(), *video);
     438
     439    // 6.4.1. Resolve p with imageBitmap.
     440    promise.resolve(WTFMove(imageBitmap));
    395441}
    396442#endif
Note: See TracChangeset for help on using the changeset viewer.