⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 179340 in webkit


Ignore:
Timestamp:
Jan 29, 2015, 3:32:53 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

CachedImage: ensure clients overrides imageChanged instead of notifyFinished
https://bugs.webkit.org/show_bug.cgi?id=140722

Patch by Julien Isorce <j.isorce@samsung.com> on 2015-01-29
Reviewed by Tim Horton.

imageChanged is called whenever a frame of an image changes
because we got more data from the network.

notifyFinished was called when the image was entirely loaded.

The problem was that some clients were implementing only
imageChanged (ex: RenderBox), some only notifyFinished and
some both (ex: RenderImage) which made the situation difficult
to understand and to maintain.

For example when the image finished loading, both imageChanged
and notifyFinished were called with the difference that for the
first one isLoaded() returned false.
It could result in functions being called twice in a row,
ex: contentChanged(ImageChanged).

So this patch tries to simplify the situation by marking
CachedImageClient::notifyFinished final in order to prevent
clients from implementing it.
Indeed this patch ensure that CachedImage clients implement
and only implement imageChanged function.

Also Clients can now differentiate intermediate and end
calls by checking isLoaded() in imageChanged.

  • html/HTMLImageLoader.cpp:

(WebCore::HTMLImageLoader::imageChanged): Added instead
of notifyFinished.
(WebCore::HTMLImageLoader::notifyFinished): Deleted.

  • html/HTMLImageLoader.h:
  • loader/ImageLoader.cpp:

(WebCore::ImageLoader::imageChanged): Added instead
of notifyFinished.
(WebCore::ImageLoader::notifyFinished): Deleted.

  • loader/ImageLoader.h:
  • loader/cache/CachedImage.cpp:

(WebCore::CachedImage::finishLoading): Explicilty mark image as
loaded and before notifying observers. So that it avoids to call
notifyFinished (from CachedResource::finishLoading).

  • loader/cache/CachedImageClient.h:

Make CachedImageClient::notifyFinished final to make sure
sub classes implement imageChanged instead.

  • rendering/RenderImage.cpp:

(WebCore::RenderImage::notifyFinished): Deleted.
ImageChanged already exists and is more clever than notifyFinished.
Indeed invalidateBackgroundObscurationStatus() will be called by
RenderReplaced::layout() upon call to setNeedsLayout() in
RenderImage::imageDimensionsChanged.
Also contentChanged(ImageChanged) is now called only when necessary.

  • rendering/RenderImage.h:
  • svg/SVGFEImageElement.cpp:

(WebCore::SVGFEImageElement::imageChanged): Added instead
of notifyFinished.
(WebCore::SVGFEImageElement::notifyFinished): Deleted.

  • svg/SVGFEImageElement.h:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r179335 r179340  
     12015-01-29  Julien Isorce  <j.isorce@samsung.com>
     2
     3        CachedImage: ensure clients overrides imageChanged instead of notifyFinished
     4        https://bugs.webkit.org/show_bug.cgi?id=140722
     5
     6        Reviewed by Tim Horton.
     7
     8        imageChanged is called whenever a frame of an image changes
     9        because we got more data from the network.
     10
     11        notifyFinished was called when the image was entirely loaded.
     12
     13        The problem was that some clients were implementing only
     14        imageChanged (ex: RenderBox), some only notifyFinished and
     15        some both (ex: RenderImage) which made the situation difficult
     16        to understand and to maintain.
     17
     18        For example when the image finished loading, both imageChanged
     19        and notifyFinished were called with the difference that for the
     20        first one isLoaded() returned false.
     21        It could result in functions being called twice in a row,
     22        ex: contentChanged(ImageChanged).
     23
     24        So this patch tries to simplify the situation by marking
     25        CachedImageClient::notifyFinished final in order to prevent
     26        clients from implementing it.
     27        Indeed this patch ensure that CachedImage clients implement
     28        and only implement imageChanged function.
     29
     30        Also Clients can now differentiate intermediate and end
     31        calls by checking isLoaded() in imageChanged.
     32
     33        * html/HTMLImageLoader.cpp:
     34        (WebCore::HTMLImageLoader::imageChanged): Added instead
     35        of notifyFinished.
     36        (WebCore::HTMLImageLoader::notifyFinished): Deleted.
     37        * html/HTMLImageLoader.h:
     38
     39        * loader/ImageLoader.cpp:
     40        (WebCore::ImageLoader::imageChanged): Added instead
     41        of notifyFinished.
     42        (WebCore::ImageLoader::notifyFinished): Deleted.
     43        * loader/ImageLoader.h:
     44
     45        * loader/cache/CachedImage.cpp:
     46        (WebCore::CachedImage::finishLoading): Explicilty mark image as
     47        loaded and before notifying observers. So that it avoids to call
     48        notifyFinished (from CachedResource::finishLoading).
     49
     50        * loader/cache/CachedImageClient.h:
     51        Make CachedImageClient::notifyFinished final to make sure
     52        sub classes implement imageChanged instead.
     53
     54        * rendering/RenderImage.cpp:
     55        (WebCore::RenderImage::notifyFinished): Deleted.
     56        ImageChanged already exists and is more clever than notifyFinished.
     57        Indeed invalidateBackgroundObscurationStatus() will be called by
     58        RenderReplaced::layout() upon call to setNeedsLayout() in
     59        RenderImage::imageDimensionsChanged.
     60        Also contentChanged(ImageChanged) is now called only when necessary.
     61        * rendering/RenderImage.h:
     62
     63        * svg/SVGFEImageElement.cpp:
     64        (WebCore::SVGFEImageElement::imageChanged): Added instead
     65        of notifyFinished.
     66        (WebCore::SVGFEImageElement::notifyFinished): Deleted.
     67        * svg/SVGFEImageElement.h:
     68
    1692015-01-28  Said Abou-Hallawa  <sabouhallawa@apple.com>
    270
  • trunk/Source/WebCore/html/HTMLImageLoader.cpp

    r175527 r179340  
    7373}
    7474
    75 void HTMLImageLoader::notifyFinished(CachedResource*)
     75void HTMLImageLoader::imageChanged(CachedImage* cachedImage, const IntRect*)
    7676{
    77     CachedImage* cachedImage = image();
     77    ASSERT(cachedImage == image().get());
     78
     79    if (!cachedImage->isLoaded())
     80        return;
    7881
    7982    Ref<Element> protect(element());
    80     ImageLoader::notifyFinished(cachedImage);
     83    ImageLoader::imageChanged(cachedImage);
    8184
    8285    bool loadError = cachedImage->errorOccurred() || cachedImage->response().httpStatusCode() >= 400;
  • trunk/Source/WebCore/html/HTMLImageLoader.h

    r165676 r179340  
    3636    virtual String sourceURI(const AtomicString&) const override;
    3737
    38     virtual void notifyFinished(CachedResource*) override;
     38    virtual void imageChanged(CachedImage*, const IntRect* = nullptr) override;
    3939};
    4040
  • trunk/Source/WebCore/loader/ImageLoader.cpp

    r179242 r179340  
    273273}
    274274
    275 void ImageLoader::notifyFinished(CachedResource* resource)
     275void ImageLoader::imageChanged(CachedImage* cachedImage, const IntRect*)
    276276{
    277277    ASSERT(m_failedLoadURL.isEmpty());
    278     ASSERT(resource == m_image.get());
     278    ASSERT(cachedImage == m_image.get());
     279
     280    if (!cachedImage->isLoaded())
     281        return;
    279282
    280283    m_imageComplete = true;
     
    287290    if (element().fastHasAttribute(HTMLNames::crossoriginAttr)
    288291        && !element().document().securityOrigin()->canRequest(image()->response().url())
    289         && !resource->passesAccessControlCheck(element().document().securityOrigin())) {
     292        && !cachedImage->passesAccessControlCheck(element().document().securityOrigin())) {
    290293
    291294        setImageWithoutConsideringPendingLoadEvent(0);
     
    305308    }
    306309
    307     if (resource->wasCanceled()) {
     310    if (cachedImage->wasCanceled()) {
    308311        m_hasPendingLoadEvent = false;
    309312        // Only consider updating the protection ref-count of the Element immediately before returning
  • trunk/Source/WebCore/loader/ImageLoader.h

    r176459 r179340  
    7474protected:
    7575    explicit ImageLoader(Element&);
    76     virtual void notifyFinished(CachedResource*) override;
     76    virtual void imageChanged(CachedImage*, const IntRect* = nullptr) override;
    7777
    7878private:
  • trunk/Source/WebCore/loader/cache/CachedImage.cpp

    r179242 r179340  
    427427    }
    428428
     429    if (m_image)
     430        setEncodedSize(m_image->data() ? m_image->data()->size() : 0);
     431
     432    setLoading(false);
    429433    notifyObservers();
    430     if (m_image)
    431         setEncodedSize(m_image->data() ? m_image->data()->size() : 0);
    432     CachedResource::finishLoading(data);
    433434}
    434435
  • trunk/Source/WebCore/loader/cache/CachedImageClient.h

    r163928 r179340  
    3939    // Called whenever a frame of an image changes because we got more data from the network.
    4040    // If not null, the IntRect is the changed rect of the image.
    41     virtual void imageChanged(CachedImage*, const IntRect* = 0) { }
     41    virtual void imageChanged(CachedImage*, const IntRect* = nullptr) { }
    4242
    4343    // Called when GIF animation progresses.
    4444    virtual void newImageAnimationFrameAvailable(CachedImage& image) { imageChanged(&image); }
     45
     46    // Use imageChanged instead.
     47    virtual void notifyFinished(CachedResource*) override final { }
    4548};
    4649
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r178510 r179340  
    366366}
    367367
    368 void RenderImage::notifyFinished(CachedResource* newImage)
    369 {
    370     if (documentBeingDestroyed())
    371         return;
    372 
    373     invalidateBackgroundObscurationStatus();
    374 
    375     if (newImage == imageResource().cachedImage()) {
    376         // tell any potential compositing layers
    377         // that the image is done and they can reference it directly.
    378         contentChanged(ImageChanged);
    379     }
    380 }
    381 
    382368void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    383369{
  • trunk/Source/WebCore/rendering/RenderImage.h

    r177259 r179340  
    100100    virtual LayoutUnit minimumReplacedHeight() const override;
    101101
    102     virtual void notifyFinished(CachedResource*) override final;
    103102    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override final;
    104103
  • trunk/Source/WebCore/svg/SVGFEImageElement.cpp

    r179242 r179340  
    192192}
    193193
    194 void SVGFEImageElement::notifyFinished(CachedResource*)
    195 {
     194void SVGFEImageElement::imageChanged(CachedImage* cachedImage, const IntRect*)
     195{
     196    if (!cachedImage || !cachedImage->isLoaded())
     197        return;
     198
    196199    if (!inDocument())
    197200        return;
  • trunk/Source/WebCore/svg/SVGFEImageElement.h

    r178048 r179340  
    5252    virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
    5353    virtual void svgAttributeChanged(const QualifiedName&) override;
    54     virtual void notifyFinished(CachedResource*) override;
     54    virtual void imageChanged(CachedImage*, const IntRect* = nullptr) override;
    5555
    5656    virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
Note: See TracChangeset for help on using the changeset viewer.