Bug 89134 - [chromium] Use SkBitmap in ImageLayerChromium
Summary: [chromium] Use SkBitmap in ImageLayerChromium
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: James Robinson
URL:
Keywords:
Depends on:
Blocks: 89150
  Show dependency treegraph
 
Reported: 2012-06-14 15:36 PDT by James Robinson
Modified: 2012-06-15 16:13 PDT (History)
5 users (show)

See Also:


Attachments
Patch (15.61 KB, patch)
2012-06-14 15:44 PDT, James Robinson
no flags Details | Formatted Diff | Diff
Patch (15.59 KB, patch)
2012-06-15 15:42 PDT, James Robinson
enne: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Robinson 2012-06-14 15:36:32 PDT
[chromium] Use SkBitmap in ImageLayerChromium
Comment 1 James Robinson 2012-06-14 15:44:54 PDT
Created attachment 147666 [details]
Patch
Comment 2 James Robinson 2012-06-14 15:45:51 PDT
I'm using pixelRef() to see if two SkBitmaps represent the same underlying thing - can you tell me if that's crazy or not, Stephen?  It appears to work for animated .gifs which is the case that's most relevant here.
Comment 3 Dana Jansens 2012-06-14 16:08:48 PDT
Comment on attachment 147666 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147666&action=review

> Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp:-147
> -void ImageLayerChromium::setContents(Image* contents)

yay for removing the word "contents" :)
Comment 4 Adrienne Walker 2012-06-14 18:58:39 PDT
Comment on attachment 147666 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147666&action=review

> Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp:469
> +        NativeImageSkia* nativeImage = image->nativeImageForCurrentFrame();
> +        imageLayer->setBitmap(nativeImage->bitmap());

What's the lifetime of the pixels in image->nativeImageForCurrentFrame()->bitmap() with respect to ImageLayerChromium's use of the SkBitmap's pixels? I don't understand SkBitmap enough to know what happens when the source of a copy goes away.
Comment 5 James Robinson 2012-06-14 19:18:27 PDT
SkBitmap holds a reference to the underlying data, I believe (right Stephen), so by holding an SkBitmap I believe I'm keeping the actual image data alive.
Comment 6 Stephen White 2012-06-15 07:52:47 PDT
Comment on attachment 147666 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147666&action=review

>> Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp:469
>> +        imageLayer->setBitmap(nativeImage->bitmap());
> 
> What's the lifetime of the pixels in image->nativeImageForCurrentFrame()->bitmap() with respect to ImageLayerChromium's use of the SkBitmap's pixels? I don't understand SkBitmap enough to know what happens when the source of a copy goes away.

There are two cases:  SkBitmaps can be exclusive owners of their pixels (where they have a non-NULL fPixels but a NULL fPixelRef), or they can have shared (non-exclusive) ownership, via fPixelRef.

The SkBitmap copy constructor will simply incref the SkPixelRef in the latter case, which I believe is the case for all bitmaps owned by NativeImageSkia.

> Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp:139
> +    if (bitmap.pixelRef() == m_bitmap.pixelRef())

As above, this will work as long as the SkBitmaps have non-exclusive pixel ownership, which I believe is the case here.

If you want to be conservative, you could do:

if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef())
    return;

> Source/WebCore/platform/graphics/chromium/PlatformImage.cpp:-60
> -} // namespace WebCore

Yay for negative linecount patches.  :)
Comment 7 Adrienne Walker 2012-06-15 08:36:19 PDT
(In reply to comment #6)
> (From update of attachment 147666 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=147666&action=review
> 
> >> Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp:469
> >> +        imageLayer->setBitmap(nativeImage->bitmap());
> > 
> > What's the lifetime of the pixels in image->nativeImageForCurrentFrame()->bitmap() with respect to ImageLayerChromium's use of the SkBitmap's pixels? I don't understand SkBitmap enough to know what happens when the source of a copy goes away.
> 
> There are two cases:  SkBitmaps can be exclusive owners of their pixels (where they have a non-NULL fPixels but a NULL fPixelRef), or they can have shared (non-exclusive) ownership, via fPixelRef.
> 
> The SkBitmap copy constructor will simply incref the SkPixelRef in the latter case, which I believe is the case for all bitmaps owned by NativeImageSkia.

Thanks for the explanation.  :)
Comment 8 James Robinson 2012-06-15 14:25:54 PDT
(In reply to comment #6)
> (From update of attachment 147666 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=147666&action=review
> 
> >> Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp:469
> >> +        imageLayer->setBitmap(nativeImage->bitmap());
> > 
> > What's the lifetime of the pixels in image->nativeImageForCurrentFrame()->bitmap() with respect to ImageLayerChromium's use of the SkBitmap's pixels? I don't understand SkBitmap enough to know what happens when the source of a copy goes away.
> 
> There are two cases:  SkBitmaps can be exclusive owners of their pixels (where they have a non-NULL fPixels but a NULL fPixelRef), or they can have shared (non-exclusive) ownership, via fPixelRef.
> 
> The SkBitmap copy constructor will simply incref the SkPixelRef in the latter case, which I believe is the case for all bitmaps owned by NativeImageSkia.
> 
> > Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp:139
> > +    if (bitmap.pixelRef() == m_bitmap.pixelRef())
> 
> As above, this will work as long as the SkBitmaps have non-exclusive pixel ownership, which I believe is the case here.

I believe that's the case for this as well, but I'll add the defensive check anyway (since I plan to expose this to the general compositor API and people might pass in other sorts of bitmaps).

> 
> If you want to be conservative, you could do:
> 
> if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef())
>     return;

Will do. Mind setting the review flag if you're happy otherwise? :)

> 
> > Source/WebCore/platform/graphics/chromium/PlatformImage.cpp:-60
> > -} // namespace WebCore
> 
> Yay for negative linecount patches.  :)
Comment 9 James Robinson 2012-06-15 15:42:09 PDT
Created attachment 147914 [details]
Patch
Comment 10 Adrienne Walker 2012-06-15 15:52:35 PDT
Comment on attachment 147914 [details]
Patch

R=me.  I don't think there's anything controversial here.  If senorblanco wants to change something about this, there can always be a follow-up patch.
Comment 11 James Robinson 2012-06-15 16:13:09 PDT
Committed r120507: <http://trac.webkit.org/changeset/120507>