Bug 159679 - Move the pixel data of ImageFrame to a separate class named ImageBackingStore
Summary: Move the pixel data of ImageFrame to a separate class named ImageBackingStore
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords:
Depends on: 155444
Blocks: 155322 159699
  Show dependency treegraph
 
Reported: 2016-07-12 10:21 PDT by Said Abou-Hallawa
Modified: 2016-09-12 16:54 PDT (History)
5 users (show)

See Also:


Attachments
Patch (124.32 KB, patch)
2016-07-12 10:23 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (124.27 KB, patch)
2016-07-12 10:44 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (124.78 KB, patch)
2016-07-12 11:14 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (124.79 KB, patch)
2016-07-12 11:25 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (124.82 KB, patch)
2016-07-12 11:35 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (124.83 KB, patch)
2016-07-12 12:05 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (125.20 KB, patch)
2016-07-12 12:34 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (125.20 KB, patch)
2016-07-12 12:42 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (131.69 KB, patch)
2016-07-12 13:04 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (142.22 KB, patch)
2016-07-12 14:48 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (142.22 KB, patch)
2016-07-12 14:55 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (141.90 KB, patch)
2016-07-12 15:29 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (141.90 KB, patch)
2016-07-12 15:59 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (141.95 KB, patch)
2016-07-12 16:08 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch for review (46.75 KB, patch)
2016-07-12 16:51 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (42.82 KB, patch)
2016-09-09 12:03 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (42.92 KB, patch)
2016-09-09 12:31 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (42.92 KB, patch)
2016-09-09 12:37 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (44.53 KB, patch)
2016-09-09 16:18 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.93 KB, patch)
2016-09-09 17:02 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.95 KB, patch)
2016-09-09 17:40 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.97 KB, patch)
2016-09-09 17:50 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.99 KB, patch)
2016-09-09 18:01 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (56.00 KB, patch)
2016-09-09 18:11 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.28 KB, patch)
2016-09-09 18:35 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.28 KB, patch)
2016-09-09 18:46 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (55.33 KB, patch)
2016-09-09 19:08 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (60.87 KB, patch)
2016-09-12 12:16 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (60.87 KB, patch)
2016-09-12 13:12 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (67.30 KB, patch)
2016-09-12 15:44 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2016-07-12 10:21:23 PDT
The goal is to have one class for the ImageFrame. Currently we have two very similar implementations: one is defined for non CG ports "ImageFrame", which is defined in /platform/image-decoders/ImageDecoder.h, and the second is "FrameData", which is defined in platform/graphics/BitmapImage.h.

We begin by moving the pixel data manipulation part in ImageFrame into a separate class and then make it optional (allocated on demand). So for the CG case, BitmapPixels object will not be allocated because all the decoding is done by CG.
Comment 1 Said Abou-Hallawa 2016-07-12 10:23:58 PDT
Created attachment 283425 [details]
Patch
Comment 2 Said Abou-Hallawa 2016-07-12 10:44:06 PDT
Created attachment 283427 [details]
Patch
Comment 3 Said Abou-Hallawa 2016-07-12 11:14:13 PDT
Created attachment 283429 [details]
Patch
Comment 4 Said Abou-Hallawa 2016-07-12 11:25:39 PDT
Created attachment 283431 [details]
Patch
Comment 5 Said Abou-Hallawa 2016-07-12 11:35:17 PDT
Created attachment 283433 [details]
Patch
Comment 6 Said Abou-Hallawa 2016-07-12 12:05:25 PDT
Created attachment 283437 [details]
Patch
Comment 7 Said Abou-Hallawa 2016-07-12 12:34:00 PDT
Created attachment 283439 [details]
Patch
Comment 8 Said Abou-Hallawa 2016-07-12 12:42:15 PDT
Created attachment 283440 [details]
Patch
Comment 9 Said Abou-Hallawa 2016-07-12 13:04:03 PDT
Created attachment 283443 [details]
Patch
Comment 10 Said Abou-Hallawa 2016-07-12 14:48:45 PDT
Created attachment 283449 [details]
Patch
Comment 11 Said Abou-Hallawa 2016-07-12 14:55:44 PDT
Created attachment 283450 [details]
Patch
Comment 12 Said Abou-Hallawa 2016-07-12 15:29:02 PDT
Created attachment 283461 [details]
Patch
Comment 13 Said Abou-Hallawa 2016-07-12 15:59:10 PDT
Created attachment 283466 [details]
Patch
Comment 14 Said Abou-Hallawa 2016-07-12 16:08:59 PDT
Created attachment 283467 [details]
Patch
Comment 15 Said Abou-Hallawa 2016-07-12 16:51:14 PDT
Created attachment 283469 [details]
Patch for review
Comment 16 Said Abou-Hallawa 2016-09-09 12:03:15 PDT
Created attachment 288426 [details]
Patch
Comment 17 Said Abou-Hallawa 2016-09-09 12:31:04 PDT
Created attachment 288428 [details]
Patch
Comment 18 Said Abou-Hallawa 2016-09-09 12:37:50 PDT
Created attachment 288429 [details]
Patch
Comment 19 Said Abou-Hallawa 2016-09-09 16:18:00 PDT
Created attachment 288447 [details]
Patch
Comment 20 Said Abou-Hallawa 2016-09-09 17:02:32 PDT
Created attachment 288451 [details]
Patch
Comment 21 Said Abou-Hallawa 2016-09-09 17:40:55 PDT
Created attachment 288459 [details]
Patch
Comment 22 Said Abou-Hallawa 2016-09-09 17:50:08 PDT
Created attachment 288461 [details]
Patch
Comment 23 Said Abou-Hallawa 2016-09-09 18:01:40 PDT
Created attachment 288463 [details]
Patch
Comment 24 Said Abou-Hallawa 2016-09-09 18:11:31 PDT
Created attachment 288466 [details]
Patch
Comment 25 Said Abou-Hallawa 2016-09-09 18:35:59 PDT
Created attachment 288468 [details]
Patch
Comment 26 Said Abou-Hallawa 2016-09-09 18:46:38 PDT
Created attachment 288472 [details]
Patch
Comment 27 Said Abou-Hallawa 2016-09-09 19:08:09 PDT
Created attachment 288475 [details]
Patch
Comment 28 Carlos Garcia Campos 2016-09-12 00:46:04 PDT
Comment on attachment 288475 [details]
Patch

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

I ran the tests for GTK+ and got mostly the same results, so I don't think this is introducing any regression.

> Source/WebCore/platform/graphics/ImageBackingStore.h:38
> +class ImageBackingStore {
> +public:

This could probably be fast allocated.

> Source/WebCore/platform/graphics/ImageBackingStore.h:47
> +    static std::unique_ptr<ImageBackingStore> create(const IntSize& size, bool premultiplyAlpha)
> +    {
> +        return std::make_unique<ImageBackingStore>(size, premultiplyAlpha);
> +    }
> +
> +    static std::unique_ptr<ImageBackingStore> create(const ImageBackingStore& other)
> +    {
> +        return std::make_unique<ImageBackingStore>(other);
> +    }

Do we need create methods if they just call macke_unique and constructors are public?

> Source/WebCore/platform/graphics/ImageBackingStore.h:49
> +    ImageBackingStore(const IntSize& size, bool premultiplyAlpha = true)

So, premultiplyAlpha is optional here but not in the create method.

> Source/WebCore/platform/graphics/ImageBackingStore.h:59
> +        if (this == &other)
> +            return;

I don't understand this.

> Source/WebCore/platform/graphics/ImageBackingStore.h:71
> +    {
> +        if (!m_pixels.tryReserveCapacity(size.area()))

Is it ok to set an empty size? otherwise I would add an assert here.

> Source/WebCore/platform/graphics/ImageBackingStore.h:89
> +    IntSize size() const { return m_size; }

Could we return const IntSize& here?

> Source/WebCore/platform/graphics/ImageBackingStore.h:90
> +    IntRect frameRect() const { return m_frameRect; }

And const IntRect& here?

> Source/WebCore/platform/image-decoders/ImageDecoder.h:93
> +        IntSize size() const { return m_backingStore->size(); }

const IntSize& ?

> Source/WebCore/platform/image-decoders/ImageDecoder.h:110
> +        void setBackingStore(const ImageBackingStore*);

Where is this implemented?

> Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp:38
> +NativeImagePtr ImageBackingStore::image() const
> +{
> +    return adoptRef(cairo_image_surface_create_for_data(
> +        reinterpret_cast<unsigned char*>(const_cast<RGBA32*>(m_pixelsPtr)),
> +        CAIRO_FORMAT_ARGB32, size().width(), size().height(), size().width() * sizeof(RGBA32)));
> +}

So, I guess we can remove ImageDecoderCairo.cpp now.
Comment 29 Said Abou-Hallawa 2016-09-12 12:16:14 PDT
Created attachment 288598 [details]
Patch
Comment 30 Said Abou-Hallawa 2016-09-12 12:25:21 PDT
Comment on attachment 288475 [details]
Patch

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

Thanks for the code review and for verifying the layout tests.

>> Source/WebCore/platform/graphics/ImageBackingStore.h:38
>> +public:
> 
> This could probably be fast allocated.

Done.

>> Source/WebCore/platform/graphics/ImageBackingStore.h:47
>> +    }
> 
> Do we need create methods if they just call macke_unique and constructors are public?

Done. Constructors became private and I have to abandon calling std::make_unique() since it requires the constructor to be public.

>> Source/WebCore/platform/graphics/ImageBackingStore.h:49
>> +    ImageBackingStore(const IntSize& size, bool premultiplyAlpha = true)
> 
> So, premultiplyAlpha is optional here but not in the create method.

Done. The premultiplyAlpha is now optional in both the constructor and the create method.

>> Source/WebCore/platform/graphics/ImageBackingStore.h:59
>> +            return;
> 
> I don't understand this.

You are right. This constructor was originally implemented as an assignment operator. I forgot to change its body to be suitable for a copy constructor.

>> Source/WebCore/platform/graphics/ImageBackingStore.h:71
>> +        if (!m_pixels.tryReserveCapacity(size.area()))
> 
> Is it ok to set an empty size? otherwise I would add an assert here.

A check for !size.isEmpty() its added to this if-statment.

>> Source/WebCore/platform/image-decoders/ImageDecoder.h:93
>> +        IntSize size() const { return m_backingStore->size(); }
> 
> const IntSize& ?

Done.

>> Source/WebCore/platform/image-decoders/ImageDecoder.h:110
>> +        void setBackingStore(const ImageBackingStore*);
> 
> Where is this implemented?

setBackingStore() is not implemented and this declaration is not needed.

>> Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp:38
>> +}
> 
> So, I guess we can remove ImageDecoderCairo.cpp now.

You are right. ImageDecoderCairo.cpp is now deleted.
Comment 31 Said Abou-Hallawa 2016-09-12 13:12:21 PDT
Created attachment 288604 [details]
Patch
Comment 32 Simon Fraser (smfr) 2016-09-12 14:32:35 PDT
Comment on attachment 288604 [details]
Patch

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

> Source/WebCore/platform/graphics/ImageBackingStore.h:37
> +class ImageBackingStore {

I'm surprised that this class doesn't pad rowBytes to some multiple of 4 or 8 bytes.

> Source/WebCore/platform/graphics/ImageBackingStore.h:85
> +        size_t rectWidthInBytes = rect.width() * sizeof(RGBA32);

This is normally called rowBytes

> Source/WebCore/platform/graphics/ImageBackingStore.h:98
> +        size_t rectWidthInBytes = rect.width() * sizeof(RGBA32);

Ditto.

> Source/WebCore/platform/graphics/ImageBackingStore.h:107
> +    RGBA32* at(int x, int y) const

I don't like this name.

> Source/WebCore/platform/graphics/ImageBackingStore.h:112
> +    void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)

I would call this setPixel()

> Source/WebCore/platform/graphics/ImageBackingStore.h:127
> +    void overRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)

I don't like this name.
Comment 33 Said Abou-Hallawa 2016-09-12 15:44:29 PDT
Created attachment 288626 [details]
Patch
Comment 34 WebKit Commit Bot 2016-09-12 16:54:02 PDT
Comment on attachment 288626 [details]
Patch

Clearing flags on attachment: 288626

Committed r205841: <http://trac.webkit.org/changeset/205841>
Comment 35 WebKit Commit Bot 2016-09-12 16:54:09 PDT
All reviewed patches have been landed.  Closing bug.