Bug 159721 - Get rid of the m_premultiplyAlpha flag of the ImageFrame class
Summary: Get rid of the m_premultiplyAlpha flag of the ImageFrame class
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: 159699
Blocks: 155322 159795
  Show dependency treegraph
 
Reported: 2016-07-13 09:22 PDT by Said Abou-Hallawa
Modified: 2016-09-13 13:58 PDT (History)
5 users (show)

See Also:


Attachments
Patch (166.18 KB, patch)
2016-07-13 09:30 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (166.59 KB, patch)
2016-07-13 12:19 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (171.63 KB, patch)
2016-07-13 14:32 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (171.09 KB, patch)
2016-07-13 14:50 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (170.55 KB, patch)
2016-07-13 14:55 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (171.74 KB, patch)
2016-07-13 15:04 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (171.90 KB, patch)
2016-07-13 15:20 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (171.75 KB, patch)
2016-07-13 15:31 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch for review (25.45 KB, patch)
2016-07-13 17:04 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (13.53 KB, patch)
2016-09-12 17:11 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (19.82 KB, patch)
2016-09-13 10:32 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (20.46 KB, patch)
2016-09-13 10:43 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (20.46 KB, patch)
2016-09-13 10:51 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (20.58 KB, patch)
2016-09-13 10:55 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (20.82 KB, patch)
2016-09-13 12:41 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (21.04 KB, patch)
2016-09-13 12:54 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-13 09:22:05 PDT
This flag was only needed when calling BitmapPixels::setSize(). Instead we can pass the ImageDecoder::m_premultiplyAlpha to ImageFrame::setSize() which will pass it to BitmapPixels::setSize().
Comment 1 Said Abou-Hallawa 2016-07-13 09:30:56 PDT
Created attachment 283537 [details]
Patch
Comment 2 Said Abou-Hallawa 2016-07-13 12:19:10 PDT
Created attachment 283557 [details]
Patch
Comment 3 Said Abou-Hallawa 2016-07-13 14:32:10 PDT
Created attachment 283565 [details]
Patch
Comment 4 Said Abou-Hallawa 2016-07-13 14:50:18 PDT
Created attachment 283569 [details]
Patch
Comment 5 Said Abou-Hallawa 2016-07-13 14:55:08 PDT
Created attachment 283571 [details]
Patch
Comment 6 Said Abou-Hallawa 2016-07-13 15:04:53 PDT
Created attachment 283577 [details]
Patch
Comment 7 Said Abou-Hallawa 2016-07-13 15:20:04 PDT
Created attachment 283578 [details]
Patch
Comment 8 Said Abou-Hallawa 2016-07-13 15:31:08 PDT
Created attachment 283580 [details]
Patch
Comment 9 Said Abou-Hallawa 2016-07-13 17:04:58 PDT
Created attachment 283589 [details]
Patch for review
Comment 10 Said Abou-Hallawa 2016-09-12 17:11:25 PDT
Created attachment 288644 [details]
Patch
Comment 11 Simon Fraser (smfr) 2016-09-12 17:13:46 PDT
Comment on attachment 288644 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        This flag was only needed when calling ImageBackingStore::setSize(). Instead
> +        we can pass the ImageDecoder::m_premultiplyAlpha to ImageFrame::setSize()
> +        which will pass it to ImageBackingStore::setSize().

Why does setting the size care about premultiplied alpha?
Comment 12 Carlos Garcia Campos 2016-09-12 23:27:14 PDT
(In reply to comment #11)
> Comment on attachment 288644 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=288644&action=review
> 
> > Source/WebCore/ChangeLog:10
> > +        This flag was only needed when calling ImageBackingStore::setSize(). Instead
> > +        we can pass the ImageDecoder::m_premultiplyAlpha to ImageFrame::setSize()
> > +        which will pass it to ImageBackingStore::setSize().
> 
> Why does setting the size care about premultiplied alpha?

It doesn't, I think it's because we only want the m_premultiplyAlpha to be passed to the ImageBackingStore constructor and ImageBackingStore is created in setSize().
Comment 13 Carlos Garcia Campos 2016-09-12 23:42:46 PDT
I agree that passing premultiplyAlpha to setSize() is weird from the API point of view. But also because setSize() is weird as it is implemented. It can't be called if the ImageFrame already has a backing store, and it always creates a new  ImageBackingStore. So, maybe if we rename the method as initializeBackingStore or simply initialize() it makes more sense to pass a size and premultiplyalpha as initialization parameters. We could probably rename copyBitmapData() also as initialize(). Another possibility (in addition to the rename that I think we should do anyway, because setSize and copyBitmapData are confusing), would be to let the decoder pass premultiplyAlpha to setPixel and blendPixel methods, that would just pass it to the backing store, since those are the only methods needing it.
Comment 14 Said Abou-Hallawa 2016-09-13 10:32:44 PDT
Created attachment 288695 [details]
Patch
Comment 15 Said Abou-Hallawa 2016-09-13 10:43:39 PDT
Created attachment 288696 [details]
Patch
Comment 16 Said Abou-Hallawa 2016-09-13 10:51:19 PDT
Created attachment 288697 [details]
Patch
Comment 17 Said Abou-Hallawa 2016-09-13 10:55:11 PDT
Created attachment 288698 [details]
Patch
Comment 18 Said Abou-Hallawa 2016-09-13 11:43:01 PDT
(In reply to comment #13)
> I agree that passing premultiplyAlpha to setSize() is weird from the API
> point of view. But also because setSize() is weird as it is implemented. It
> can't be called if the ImageFrame already has a backing store, and it always
> creates a new  ImageBackingStore. So, maybe if we rename the method as
> initializeBackingStore or simply initialize() it makes more sense to pass a
> size and premultiplyalpha as initialization parameters. We could probably
> rename copyBitmapData() also as initialize().

I like this suggestion. I renamed setSize() and copyBitmapData() to initializeBackingStore(). I preferred it over initialize() because ImageFrame will be shared between CG and non-CG code and initialize() is very generic name. Calling initializeBackingStore() makes it clearer that we want to initialize the backing store only which is only needed by non CG ports.

> Another possibility (in
> addition to the rename that I think we should do anyway, because setSize and
> copyBitmapData are confusing), would be to let the decoder pass
> premultiplyAlpha to setPixel and blendPixel methods, that would just pass it
> to the backing store, since those are the only methods needing it.

I am not sure about this suggestion. It can actually make creating the backing store simpler and can make setPixel() and blendPixel() static or even global functions. But having the backing store not aware whether its pixels are premultiplied or not, seems weird to me. Anyway this seems a big change and I can do it in a separate patch if we need it.
Comment 19 Simon Fraser (smfr) 2016-09-13 11:52:57 PDT
Comment on attachment 288698 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        to ImageFrame::setSize(), which should be renamed ImageFrame::initializeBackingStore().

s/should be/is/

> Source/WebCore/platform/image-decoders/ImageDecoder.cpp:179
> +    if (!backingStore)
> +        return false;

Should backingStore just be a reference instead?

> Source/WebCore/platform/image-decoders/ImageDecoder.h:174
> +        bool premultiplyAlpha() const { return m_premultiplyAlpha; }

premultipiesAlpha()?
Comment 20 Said Abou-Hallawa 2016-09-13 12:41:41 PDT
Created attachment 288717 [details]
Patch
Comment 21 Said Abou-Hallawa 2016-09-13 12:54:23 PDT
Created attachment 288719 [details]
Patch
Comment 22 WebKit Commit Bot 2016-09-13 13:58:28 PDT
Comment on attachment 288719 [details]
Patch

Clearing flags on attachment: 288719

Committed r205877: <http://trac.webkit.org/changeset/205877>
Comment 23 WebKit Commit Bot 2016-09-13 13:58:34 PDT
All reviewed patches have been landed.  Closing bug.