Bug 24864 - Tidy up some accelerated compositing code related to direct image compositing
Summary: Tidy up some accelerated compositing code related to direct image compositing
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-26 17:44 PDT by Simon Fraser (smfr)
Modified: 2009-03-26 18:12 PDT (History)
1 user (show)

See Also:


Attachments
Patch, changelog (9.96 KB, patch)
2009-03-26 17:46 PDT, Simon Fraser (smfr)
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2009-03-26 17:44:13 PDT
We have some cleanup of code related to "direct compositing" of images.
Comment 1 Simon Fraser (smfr) 2009-03-26 17:46:44 PDT
Created attachment 28995 [details]
Patch, changelog
Comment 2 Darin Adler 2009-03-26 18:03:31 PDT
Comment on attachment 28995 [details]
Patch, changelog

> -// A layer can use an inner content layer if the render layer's object is a replaced object and has no children.
> +// A layer can use direct composoting if the render layer's object is a replaced object and has no children.

Typo here.

> +void RenderLayerBacking::updateImageContents()
> +{
> +    ASSERT(renderer()->isImage());
> +    RenderImage* imageRenderer = static_cast<RenderImage*>(renderer());
> +    if (imageRenderer->cachedImage() &&
> +        imageRenderer->cachedImage()->image() &&
> +        imageRenderer->cachedImage()->isLoaded()) {
> +        // We have to wait until the image is fully loaded before setting it on the layer.
> +        
> +        // This is a no-op if the layer doesn't have an inner layer for the image.
> +        m_graphicsLayer->setContentsToImage(imageRenderer->cachedImage()->image());
> +        
> +        // Image animation is "lazy", in that it automatically stops unless someone is drawing
> +        // the image. So we have to kick the animation each time; this has the downside that the
> +        // image will keep animating, even if its layer is not visible.
> +        imageRenderer->cachedImage()->image()->startAnimation();
>      }
>  }

Now that this is in its own function, you can use early returns to get rid of that cascaded &&, make space to comment about each return if you like, and even put things into local variables instead of repeating imageRenderer->cachedImage()->image(). Look how attractive it is!

    CachedImage* cachedImage = imageRenderer->cachedImage();
    if (!cachedImage)
        return;

    Image* image = cachedImage->image();
    if (!image)
        return;

    // We have to wait until the image is fully loaded before setting it on the layer.
    if (!cachedImage->isLoaded())
        return;

    // This is a no-op if the layer doesn't have an inner layer for the image.
    m_graphicsLayer->setContentsToImage(image);

    // Image animation is "lazy", in that it automatically stops unless someone is drawing
    // the image. So we have to kick the animation each time; this has the downside that the
    // image will keep animating, even if its layer is not visible.
    image)->startAnimation();

r=me
Comment 3 Simon Fraser (smfr) 2009-03-26 18:12:32 PDT
http://trac.webkit.org/changeset/42024