haikuwebkit/LayoutTests/fast/images/decode-render-static-image....

57 lines
2.2 KiB
HTML
Raw Permalink Normal View History

Implement HTMLImageElement.decoode() method https://bugs.webkit.org/show_bug.cgi?id=176016 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2017-09-08 Reviewed by Simon Fraser. Source/WebCore: The specs is: https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode. -- img.decode() waits till loading the image finishes. Otherwise it starts decoding the image immediately. -- If the image frame is already decoded, the promise will be resolved before return. -- If an error happens in loading the image or decoding the image frame, the promise will be rejected with 'EncodingError' exception. -- Animated image resolves the promise when the next frame is decoded and the animation is advanced it. If the image is not displayed, decode() will request the decoding the first frame and start animating the image. Tests: fast/images/decode-animated-image.html fast/images/decode-render-animated-image.html fast/images/decode-render-static-image.html fast/images/decode-static-image-reject.html fast/images/decode-static-image-resolve.html * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::decode): * html/HTMLImageElement.h: * html/HTMLImageElement.idl: * loader/ImageLoader.cpp: (WebCore::ImageLoader::notifyFinished): (WebCore::ImageLoader::decode): (WebCore::ImageLoader::decodeError): * loader/ImageLoader.h: (WebCore::ImageLoader::hasPendingDecodePromise const): * platform/graphics/BitmapImage.cpp: (WebCore::BitmapImage::internalStartAnimation): (WebCore::BitmapImage::internalAdvanceAnimation): (WebCore::BitmapImage::decode): (WebCore::BitmapImage::imageFrameAvailableAtIndex): * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: (WebCore::Image::decode): LayoutTests: * fast/images/decode-animated-image-expected.html: Added. * fast/images/decode-animated-image.html: Added. * fast/images/decode-render-animated-image-expected.html: Added. * fast/images/decode-render-animated-image.html: Added. * fast/images/decode-render-static-image-expected.html: Added. * fast/images/decode-render-static-image.html: Added. * fast/images/decode-static-image-reject-expected.txt: Added. * fast/images/decode-static-image-reject.html: Added. * fast/images/decode-static-image-resolve-expected.html: Added. * fast/images/decode-static-image-resolve.html: Added. Canonical link: https://commits.webkit.org/193158@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221805 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-09 03:09:09 +00:00
<style>
div {
width: 100px;
height: 100px;
}
img {
max-width: 100%;
max-height: 100%;
}
</style>
<body>
<p>This tests calling decode() for a static image which is also an element in the DOM tree.</p>
<div></div>
<script>
if (window.internals && window.testRunner) {
internals.clearMemoryCache();
internals.settings.setWebkitImageReadyEventEnabled(true);
internals.settings.setLargeImageAsyncDecodingEnabled(true);
testRunner.waitUntilDone();
}
var image = new Image;
var parent = document.querySelector("div");
parent.appendChild(image);
image.onload = (() => {
if (window.internals && window.testRunner) {
// Force async image decoding for this image.
internals.setLargeImageAsyncDecodingEnabledForTesting(image, true);
// Force layout and display so the image gets drawn.
document.body.offsetHeight;
testRunner.display();
// testRunner.display() requests an async image decoding. Wait till it finishes.
image.addEventListener("webkitImageFrameReady", function() {
// Execute this code in the next loop run.
setTimeout(function() {
testRunner.display();
// The image frame was decoded for the renderer which is (100x100). This
// decode() will request a new decoding with the native size which is (400x400).
image.decode().then(() => {
parent.style.width = "200px";
parent.style.height = "200px";
// No extra decoding is required to display the image after changing its size.
// The image frame was decoded with the native size which is the maximum size
// that an image can be decoded with.
testRunner.notifyDone();
});
}, 0);
});
}
});
image.src = "resources/green-400x400.png";
</script>
</body>