Changeset 249162 in webkit


Ignore:
Timestamp:
Aug 27, 2019 12:50:47 PM (5 years ago)
Author:
clopez@igalia.com
Message:

Drawing an animated image to a canvas via drawImage should draw the first frame
https://bugs.webkit.org/show_bug.cgi?id=74779
<rdar://problem/42282454>

Reviewed by Said Abou-Hallawa.

Source/WebCore:

After this patch, when an animated image is drawn into a canvas via
drawImage, the actual image that the canvas will receive will be
a new Image object with the contents of the first frame of the animation.

It also adds an internal setting to keep the previous behaviour
(draw the current frame playing) because there are several layout
tests that rely on canvas.drawImage() to check that animated images
play properly.

Test: fast/canvas/drawImage-animated-gif-draws-first-frame-and-no-reset-image.html

  • html/canvas/CanvasRenderingContext2DBase.cpp:

(WebCore::CanvasRenderingContext2DBase::drawImage):

  • page/Settings.yaml:
  • testing/InternalSettings.cpp:

(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setAnimatedImageDebugCanvasDrawingEnabled):

  • testing/InternalSettings.h:
  • testing/InternalSettings.idl:

LayoutTests:

Adds a test that checks that when drawing an animated image into a canvas
it draws the first frame and that the animation doesn't reset or pause.

Also enable the new internal setting setAnimatedImageDebugCanvasDrawingEnabled()
for the tests that rely on canvas.drawImage() drawing the current frame instead
of the first one.

  • fast/canvas/drawImage-animated-gif-draws-first-frame-and-no-reset-image-expected.txt: Added.
  • fast/canvas/drawImage-animated-gif-draws-first-frame-and-no-reset-image.html: Added.

The above test checks that when drawing an animated image to a canvas it draws the first frame
and that the playing image doesn't get reseted and finish playing.

  • fast/canvas/resources/animated-red-green-blue-yellow-cyan-black-repeat-1.gif: Added.
  • fast/images/animated-gif-restored-from-bfcache.html: Enable internals.settings.setAnimatedImageDebugCanvasDrawingEnabled().
  • fast/images/animated-image-different-dest-size.html: Ditto.
  • fast/images/animated-image-loop-count.html: Ditto.
  • fast/images/animated-image-mp4.html: Ditto.
  • fast/images/decode-animated-image.html: Ditto.
  • fast/images/decode-render-animated-image.html: Ditto.
  • fast/images/ordered-animated-image-frames.html: Ditto.
  • fast/images/reset-image-animation.html: Ditto.
  • fast/images/slower-animation-than-decoding-image.html: Ditto.
  • fast/images/slower-decoding-than-animation-image.html: Ditto.
Location:
trunk
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249157 r249162  
     12019-08-27  Carlos Alberto Lopez Perez  <clopez@igalia.com>
     2
     3        Drawing an animated image to a canvas via drawImage should draw the first frame
     4        https://bugs.webkit.org/show_bug.cgi?id=74779
     5        <rdar://problem/42282454>
     6
     7        Reviewed by Said Abou-Hallawa.
     8
     9        Adds a test that checks that when drawing an animated image into a canvas
     10        it draws the first frame and that the animation doesn't reset or pause.
     11
     12        Also enable the new internal setting setAnimatedImageDebugCanvasDrawingEnabled()
     13        for the tests that rely on canvas.drawImage() drawing the current frame instead
     14        of the first one.
     15
     16        * fast/canvas/drawImage-animated-gif-draws-first-frame-and-no-reset-image-expected.txt: Added.
     17        * fast/canvas/drawImage-animated-gif-draws-first-frame-and-no-reset-image.html: Added.
     18        The above test checks that when drawing an animated image to a canvas it draws the first frame
     19        and that the playing image doesn't get reseted and finish playing.
     20        * fast/canvas/resources/animated-red-green-blue-yellow-cyan-black-repeat-1.gif: Added.
     21        * fast/images/animated-gif-restored-from-bfcache.html: Enable internals.settings.setAnimatedImageDebugCanvasDrawingEnabled().
     22        * fast/images/animated-image-different-dest-size.html: Ditto.
     23        * fast/images/animated-image-loop-count.html: Ditto.
     24        * fast/images/animated-image-mp4.html: Ditto.
     25        * fast/images/decode-animated-image.html: Ditto.
     26        * fast/images/decode-render-animated-image.html: Ditto.
     27        * fast/images/ordered-animated-image-frames.html: Ditto.
     28        * fast/images/reset-image-animation.html: Ditto.
     29        * fast/images/slower-animation-than-decoding-image.html: Ditto.
     30        * fast/images/slower-decoding-than-animation-image.html: Ditto.
     31
    1322019-08-27  Ryan Haddad  <ryanhaddad@apple.com>
    233
  • trunk/LayoutTests/fast/images/animated-gif-restored-from-bfcache.html

    r214706 r249162  
    66
    77    function runTest() {
    8         if (window.testRunner)
     8        if (window.internals && window.testRunner) {
     9            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
    910            testRunner.waitUntilDone();
     11        }
    1012
    1113        var image = document.getElementById("image");
  • trunk/LayoutTests/fast/images/animated-image-different-dest-size.html

    r218019 r249162  
    5050                    if (window.internals) {
    5151                        internals.setImageFrameDecodingDuration(image, 0.030);
     52                        internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
    5253                        internals.settings.setWebkitImageReadyEventEnabled(true);
    5354                    }
  • trunk/LayoutTests/fast/images/animated-image-loop-count.html

    r230712 r249162  
    6868
    6969        (function() {
    70             if (window.internals)
     70            if (window.internals) {
    7171                internals.clearMemoryCache();
     72                internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
     73            }
    7274
    7375            if (window.testRunner)
  • trunk/LayoutTests/fast/images/animated-image-mp4.html

    r222225 r249162  
    66    <script>
    77        window.jsTestIsAsync = true;
     8
     9        if (window.internals)
     10            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
     11
    812        var imageData;
    913
  • trunk/LayoutTests/fast/images/decode-animated-image.html

    r221805 r249162  
    99    <canvas></canvas>
    1010    <script>
    11         if (window.testRunner)
     11        if (window.internals && window.testRunner) {
     12            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
    1213            testRunner.waitUntilDone();
     14        }
     15
    1316        var image = new Image;
    1417        image.src = "resources/animated-red-green-blue-repeat-2.gif";
  • trunk/LayoutTests/fast/images/decode-render-animated-image.html

    r221805 r249162  
    2121        if (window.internals && window.testRunner) {
    2222            internals.clearMemoryCache();
     23            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
    2324            internals.settings.setWebkitImageReadyEventEnabled(true);
    2425            testRunner.waitUntilDone();
  • trunk/LayoutTests/fast/images/ordered-animated-image-frames.html

    r214450 r249162  
    1010    <canvas id="canvas"></canvas>
    1111    <script>
    12         if (window.internals)
     12        if (window.internals && window.testRunner) {
     13            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
    1314            internals.clearMemoryCache();
    14 
    15         if (window.testRunner)
    1615            testRunner.waitUntilDone();
     16        }
    1717
    1818        var image = new Image;
  • trunk/LayoutTests/fast/images/reset-image-animation.html

    r214450 r249162  
    3434            return new Promise((resolve) => {
    3535                image.onload = (() => {
    36                     if (window.internals)
     36                    if (window.internals) {
    3737                        internals.setImageFrameDecodingDuration(image, 0.020);
     38                        internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
     39                    }
    3840                    drawImage(Math.ceil(frameCount / 2), 0).then(() => {
    3941                        internals.resetImageAnimation(image);
  • trunk/LayoutTests/fast/images/slower-animation-than-decoding-image.html

    r208511 r249162  
    2121                return;
    2222            internals.setImageFrameDecodingDuration(image, 0.040);
     23            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
    2324            drawImage();
    2425            drawLoop();
  • trunk/LayoutTests/fast/images/slower-decoding-than-animation-image.html

    r208511 r249162  
    1010        jsTestIsAsync = true;
    1111
    12         internals.clearMemoryCache();
     12        if (window.internals) {
     13            internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
     14            internals.clearMemoryCache();
     15        }
    1316
    1417        var image = new Image;
  • trunk/Source/WebCore/ChangeLog

    r249160 r249162  
     12019-08-27  Carlos Alberto Lopez Perez  <clopez@igalia.com>
     2
     3        Drawing an animated image to a canvas via drawImage should draw the first frame
     4        https://bugs.webkit.org/show_bug.cgi?id=74779
     5        <rdar://problem/42282454>
     6
     7        Reviewed by Said Abou-Hallawa.
     8
     9        After this patch, when an animated image is drawn into a canvas via
     10        drawImage, the actual image that the canvas will receive will be
     11        a new Image object with the contents of the first frame of the animation.
     12
     13        It also adds an internal setting to keep the previous behaviour
     14        (draw the current frame playing) because there are several layout
     15        tests that rely on canvas.drawImage() to check that animated images
     16        play properly.
     17
     18        Test: fast/canvas/drawImage-animated-gif-draws-first-frame-and-no-reset-image.html
     19
     20        * html/canvas/CanvasRenderingContext2DBase.cpp:
     21        (WebCore::CanvasRenderingContext2DBase::drawImage):
     22        * page/Settings.yaml:
     23        * testing/InternalSettings.cpp:
     24        (WebCore::InternalSettings::Backup::Backup):
     25        (WebCore::InternalSettings::Backup::restoreTo):
     26        (WebCore::InternalSettings::setAnimatedImageDebugCanvasDrawingEnabled):
     27        * testing/InternalSettings.h:
     28        * testing/InternalSettings.idl:
     29
    1302019-08-27  Antti Koivisto  <antti@apple.com>
    231
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp

    r248846 r249162  
    5858#include "RenderTheme.h"
    5959#include "SecurityOrigin.h"
     60#include "Settings.h"
    6061#include "StrokeStyleApplier.h"
    6162#include "StyleProperties.h"
     
    15711572    }
    15721573
    1573     if (image->isBitmapImage())
     1574    if (image->isBitmapImage()) {
     1575        // Drawing an animated image to a canvas should draw the first frame (except for a few layout tests)
     1576        if (image->isAnimated() && !document.settings().animatedImageDebugCanvasDrawingEnabled())
     1577            image = BitmapImage::create(image->nativeImage());
    15741578        downcast<BitmapImage>(*image).updateFromSettings(document.settings());
     1579    }
    15751580
    15761581    if (rectContainsCanvas(normalizedDstRect)) {
  • trunk/Source/WebCore/page/Settings.yaml

    r248640 r249162  
    760760  onChange: mediaTypeOverrideChanged
    761761
     762animatedImageDebugCanvasDrawingEnabled:
     763  initial: false
    762764
    763765fontRenderingMode:
  • trunk/Source/WebCore/testing/InternalSettings.cpp

    r248846 r249162  
    104104    , m_shouldDispatchSyntheticMouseOutAfterSyntheticClick(settings.shouldDispatchSyntheticMouseOutAfterSyntheticClick())
    105105    , m_shouldDeactivateAudioSession(PlatformMediaSessionManager::shouldDeactivateAudioSession())
     106    , m_animatedImageDebugCanvasDrawingEnabled(settings.animatedImageDebugCanvasDrawingEnabled())
    106107    , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
    107108    , m_systemLayoutDirection(settings.systemLayoutDirection())
     
    213214    settings.setShouldDispatchSyntheticMouseOutAfterSyntheticClick(m_shouldDispatchSyntheticMouseOutAfterSyntheticClick);
    214215    PlatformMediaSessionManager::setShouldDeactivateAudioSession(m_shouldDeactivateAudioSession);
     216    settings.setAnimatedImageDebugCanvasDrawingEnabled(m_animatedImageDebugCanvasDrawingEnabled);
    215217
    216218#if ENABLE(INDEXED_DATABASE_IN_WORKERS)
     
    777779}
    778780
     781ExceptionOr<void> InternalSettings::setAnimatedImageDebugCanvasDrawingEnabled(bool ignore)
     782{
     783    if (!m_page)
     784        return Exception { InvalidAccessError };
     785    settings().setAnimatedImageDebugCanvasDrawingEnabled(ignore);
     786    return { };
     787}
     788
    779789void InternalSettings::setIndexedDBWorkersEnabled(bool enabled)
    780790{
  • trunk/Source/WebCore/testing/InternalSettings.h

    r247145 r249162  
    106106    ExceptionOr<void> setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(bool);
    107107    ExceptionOr<void> setShouldDispatchSyntheticMouseOutAfterSyntheticClick(bool);
     108    ExceptionOr<void> setAnimatedImageDebugCanvasDrawingEnabled(bool);
    108109
    109110    using FrameFlatteningValue = FrameFlattening;
     
    204205        bool m_shouldDispatchSyntheticMouseOutAfterSyntheticClick { false };
    205206        bool m_shouldDeactivateAudioSession;
     207        bool m_animatedImageDebugCanvasDrawingEnabled;
    206208        UserInterfaceDirectionPolicy m_userInterfaceDirectionPolicy;
    207209        TextDirection m_systemLayoutDirection;
  • trunk/Source/WebCore/testing/InternalSettings.idl

    r247145 r249162  
    8282    [MayThrowException] void setScrollingTreeIncludesFrames(boolean enabled);
    8383    [MayThrowException] void setAllowUnclampedScrollPosition(boolean allowUnclamped);
     84    [MayThrowException] void setAnimatedImageDebugCanvasDrawingEnabled(boolean enable);
    8485
    8586    [MayThrowException] void setMinimumTimerInterval(unrestricted double intervalInSeconds);
Note: See TracChangeset for help on using the changeset viewer.