Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Issue 2016043002: Avoid copy pixel data in texImage2D(ImageBitmap) (Closed)

Created:
4 years, 7 months ago by xidachen
Modified:
4 years, 6 months ago
CC:
chromium-reviews, krit, pdr+graphicswatchlist_chromium.org, drott+blinkwatch_chromium.org, blink-reviews-platform-graphics_chromium.org, dshwang, jbroman, haraken, Rik, f(malita), blink-reviews, piman+watch_chromium.org, Stephen Chennney, ajuma+watch_chromium.org, danakj+watch_chromium.org, rwlbuis
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Avoid copy pixel data in texImage2D(ImageBitmap) This is the first patch in order to avoid reading back GPU texture. Currently in texImage2D(ImageBitmap), it makes a copy of the pixel data stored inside the ImageBitmap (copyBitmapData). We should avoid that. To solve that, we use SkImage's peekPixels() API. peekPixels() returns true only when the ImageBitmap is stored in the CPU-side RAM. In the case when an ImageBitmap is texture backed, this approach will not work. I will have a follow up patch right after this, to handles the case where an ImageBitmap is texture backed. BUG=613411, 613409 CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel Committed: https://crrev.com/c44bccbcfded3d5906dc0fa79c9b0e810369b36c Cr-Commit-Position: refs/heads/master@{#396529}

Patch Set 1 #

Patch Set 2 : remove redundant code #

Patch Set 3 : ImageBitmap is always decoded #

Patch Set 4 : initialize to nullptr #

Total comments: 15

Patch Set 5 : address comments #

Patch Set 6 : change to OwnPtr #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+96 lines, -24 lines) Patch
M third_party/WebKit/LayoutTests/TestExpectations View 1 2 3 1 chunk +4 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/core/frame/ImageBitmap.cpp View 1 2 3 4 5 8 chunks +30 lines, -7 lines 4 comments Download
M third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp View 1 2 3 4 5 2 chunks +19 lines, -5 lines 0 comments Download
M third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp View 1 2 3 4 5 5 chunks +40 lines, -10 lines 0 comments Download
M third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.h View 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp View 2 chunks +2 lines, -1 line 0 comments Download

Messages

Total messages: 24 (8 generated)
xidachen
PTAL
4 years, 6 months ago (2016-05-27 01:49:07 UTC) #3
Zhenyao Mo
https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp File third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp#newcode1162 third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp:1162: if (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType) || !peekSucceed) && ...
4 years, 6 months ago (2016-05-27 13:49:21 UTC) #4
xidachen
https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp File third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp#newcode1162 third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp:1162: if (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType) || !peekSucceed) && ...
4 years, 6 months ago (2016-05-27 13:54:44 UTC) #5
Zhenyao Mo
lgtm https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp File third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp#newcode1162 third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.cpp:1162: if (((peekSucceed && pixmap.colorType() == SkColorType::kRGBA_8888_SkColorType) || !peekSucceed) ...
4 years, 6 months ago (2016-05-27 14:08:30 UTC) #6
Justin Novosad
https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp File third_party/WebKit/Source/core/frame/ImageBitmap.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp#newcode151 third_party/WebKit/Source/core/frame/ImageBitmap.cpp:151: if (premultiplyAlpha && imageFormat == PremultiplyAlpha) Unless I am ...
4 years, 6 months ago (2016-05-27 14:16:19 UTC) #7
xidachen
https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp File third_party/WebKit/Source/core/frame/ImageBitmap.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp#newcode151 third_party/WebKit/Source/core/frame/ImageBitmap.cpp:151: if (premultiplyAlpha && imageFormat == PremultiplyAlpha) On 2016/05/27 14:16:18, ...
4 years, 6 months ago (2016-05-27 15:10:13 UTC) #8
Justin Novosad
https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp File third_party/WebKit/Source/core/frame/ImageBitmap.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp#newcode199 third_party/WebKit/Source/core/frame/ImageBitmap.cpp:199: if (!skImage->peekPixels(&pixmap)) { That is not what I meant. ...
4 years, 6 months ago (2016-05-27 16:13:48 UTC) #9
xidachen
https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp File third_party/WebKit/Source/core/frame/ImageBitmap.cpp (right): https://codereview.chromium.org/2016043002/diff/60001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp#newcode199 third_party/WebKit/Source/core/frame/ImageBitmap.cpp:199: if (!skImage->peekPixels(&pixmap)) { On 2016/05/27 16:13:47, Justin Novosad wrote: ...
4 years, 6 months ago (2016-05-27 17:14:56 UTC) #10
Justin Novosad
lgtm
4 years, 6 months ago (2016-05-27 17:25:42 UTC) #11
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/2016043002/100001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/2016043002/100001
4 years, 6 months ago (2016-05-27 17:27:40 UTC) #13
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
4 years, 6 months ago (2016-05-27 19:06:50 UTC) #15
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/2016043002/100001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/2016043002/100001
4 years, 6 months ago (2016-05-27 19:07:30 UTC) #19
commit-bot: I haz the power
Committed patchset #6 (id:100001)
4 years, 6 months ago (2016-05-27 19:12:54 UTC) #20
commit-bot: I haz the power
Patchset 6 (id:??) landed as https://crrev.com/c44bccbcfded3d5906dc0fa79c9b0e810369b36c Cr-Commit-Position: refs/heads/master@{#396529}
4 years, 6 months ago (2016-05-27 19:14:47 UTC) #22
Ken Russell (switch to Gerrit)
Are all of these code paths well tested? My primary concern is the possibility that ...
4 years, 6 months ago (2016-05-27 21:17:08 UTC) #23
xidachen
4 years, 6 months ago (2016-05-28 00:51:11 UTC) #24
Message was sent while issue was closed.
Hi Ken,

Thanks for your comments. I do believe that we have enough conformance(2) tests
and layout tests in our code base to cover all cases. Basically we have
createImageBitmap() from all possible sources, and with all combination of flipY
and premultiplyAlpha.

https://codereview.chromium.org/2016043002/diff/100001/third_party/WebKit/Sou...
File third_party/WebKit/Source/core/frame/ImageBitmap.cpp (right):

https://codereview.chromium.org/2016043002/diff/100001/third_party/WebKit/Sou...
third_party/WebKit/Source/core/frame/ImageBitmap.cpp:193: m_image =
cropImage(image->cachedImage()->getImage(), cropRect, flipY, premultiplyAlpha,
PremultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied);
On 2016/05/27 21:17:08, Ken Russell wrote:
> This change is concerning. It's important that PNGs with an alpha channel can
be
> used to construct an ImageBitmap without multiplying the alpha channel into
the
> color channels. Perhaps the new code supports this semantic, but it's
difficult
> to tell just by reading the code. Is this well tested?

Actually there is no change in here in terms of code execution. Please refer to
the change in cropImage() function, I changed all the code that uses this
parameter from "DontPremultiplyAlpha" to "PremultiplyAlpha". The only reason for
this change is to make the code more readable. After this change, the 
"PremultiplyAlpha" indicates that the first parameter of cropImage() is already
in premultiplied format, which is more readable.

https://codereview.chromium.org/2016043002/diff/100001/third_party/WebKit/Sou...
third_party/WebKit/Source/core/frame/ImageBitmap.cpp:202:
surface->getCanvas()->drawImage(skImage.get(), 0, 0);
On 2016/05/27 21:17:08, Ken Russell wrote:
> This looks to me like it will always force the alpha channel to be multiplied
in
> to the color channels, which is supposed to be a configurable option. How is
> this code path tested?

I think the concern here is that this piece of code might be executed when
caller request the premultiplyAlpha=none. However, the code in cropImage() makes
sure that this won't happen. The reason is that the SkImage extracted from an
HTMLImageElement is always in premultiplied format, and if caller request
premultiplyAlpha=none, it will go into the part of code in cropImage() where a
decoder is generated to decode the SkImage. After that, the return value of
cropImage() is always in decoded state and peekPixels() always succeed.

As a matter of fact, I looked into the layout test:
tex-image-and-sub-image-2d-image-bitmap-from-image-bitmap-from-image.html, 
and this drawImage only gets called when premultiplyAlpha is set to
"premultiply" or "default". In the case when premultiplyAlpha="none", this piece
of code is never reached.

Powered by Google App Engine
This is Rietveld 408576698