Patch Set 6 : review #34 fixes.
pkasting@, thanks and sorry for the delay on this.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/core/frame/ImageBitmap.cppFile third_party/WebKit/Source/core/frame/ImageBitmap.cpp (right):
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/core/frame/ImageBitmap.cpp#newcode177third_party/WebKit/Source/core/frame/ImageBitmap.cpp:177:
DCHECK_EQ(frame->bitmap().colorType(), kN32_SkColorType);
On 2016/08/30 06:59:40, Peter Kasting wrote:
> The old code handled this conditionally, so this is a behavior change.
Is this
> safe?
>
> Nit: (expected, actual)
Done. Didn't see how it could be different from kN32 but agree - no need
to introduce behavior change.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cppFile
third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp
(right):
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp#newcode98third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp:98:
DCHECK(decoder->failed() || imageFrame->getStatus() ==
ImageFrame::FrameComplete);
On 2016/08/30 06:59:40, Peter Kasting wrote:
> This check isn't safe if somehow failed() is false but |imageFrame| is
null.
>
> If that should never happen, I'd change this to:
>
> if (imageFrame && imageFrame->getStatus() ==
ImageFrame::FrameComplete) {
> ...
> } else {
> DCHECK(decoder->failed());
> }
Done. Reverted. As allDataReceived is set to true it is expected that
either it is complete or failed. Didn't see in code how it could be
null.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp#newcode101third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp:101:
bitmap.setImmutable();
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Why is setting the bitmap as immutable here important? At the very
least this
> needs a comment.
>
> This question basically applies to everywhere in this CL that does
this. I was
> under the impression only people getting an SkImage needed to do this
(to avoid
> a copy), but we seem to be doing it many other places.
>
> If this is because we're passing the bitmap to places that will turn
it into an
> image, can we change to passing an SkImage now?
Reverted this to original implementation - in
ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale) where this
code leads to, bitmap is set to immutable.
[1]
https://cs.chromium.org/chromium/src/ui/gfx/image/image_skia_rep.cc?rcl=1474442403&l=27https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp#newcode101third_party/WebKit/Source/modules/notifications/NotificationImageLoader.cpp:101:
bitmap.setImmutable();
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Why is setting the bitmap as immutable here important? At the very
least this
> needs a comment.
>
> This question basically applies to everywhere in this CL that does
this. I was
> under the impression only people getting an SkImage needed to do this
(to avoid
> a copy), but we seem to be doing it many other places.
>
> If this is because we're passing the bitmap to places that will turn
it into an
> image, can we change to passing an SkImage now?
That was my plan too, with all the cases where SkBitmap was ported to
SkImage.
After this patch, only remaining case where we do this is with
WebImage(SkBitmap) construction:
https://cs.chromium.org/chromium/src/third_party/WebKit/public/platform/WebImage.h?type=cs&q=WebImage&sq=package:chromium&l=94and there is WebImage::getSkBitmap API that would need to be replaced
with SkImage variant.
The reason I left the SkBitmap/setImmutable used here is that it is
WebKit public/platform API and don't know the deprecation policy here /
if anybody else outside chromium codebase is using it.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/graphics/PictureSnapshot.cppFile third_party/WebKit/Source/platform/graphics/PictureSnapshot.cpp
(right):
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/graphics/PictureSnapshot.cpp#newcode74third_party/WebKit/Source/platform/graphics/PictureSnapshot.cpp:74:
*result = frame->bitmap();
Original code seems to be used only by devtools.
After this patch, it should be fine to remove that skia legacy code
under:
https://cs.chromium.org/chromium/src/third_party/skia/src/core/SkPicture.cpp?rcl=1474471143&l=36#ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF
class InstallProcImageDeserializer : public SkImageDeserializer {
...
Drawback: now we have unnecessary path here only - toSkSp(fromSkSp()) -
this is the price for not having
fromSkSp(frame->finalizePixelsAndGetImage()) everywhere else.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cppFile
third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp
(right):
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp#newcode2148third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp:2148:
// allow ImageFrame::finalizePixelsAndGetImage to make a copy.
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Isn't it already allowed to make a copy? Does this comment mean
something like
> "We could potentially relax this if we decided it was OK for the
conversion from
> bitmap to image to make a copy in this case."?
By early return if "frame->getStatus() != ImageFrame::FrameComplete" we
ensure that there is no copy done by finalizePixelsAndGetImage. This
means that if don't want to prevent copy by finalizePixelsAndGetImage,
we can relax the check to e.g.:
if (!frame)
return;
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp#newcode2154third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp:2154:
DCHECK_EQ(bitmap.colorType(), kN32_SkColorType);
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Same comment as in ImageBitmap.cpp.
Done.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cppFile third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
(right):
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp#newcode103third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp:103: if
(other->m_bitmap.isImmutable() || this == other)
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Tiny efficiency nit: Reverse order of checks
It isn't obvious when/if this could happen (this == other) so while
debugging most common use cases I found that the current order is
leaving the check earlier.
"this == other" I copied from copyBitmapData.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp#newcode139third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp:139: //
next animation frame by calling takeBitmapDataIfWritable.
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Nit: The header comments should already justify any functional
difference
> between these two, so I'd remove this comment and just inline the
method into
> the header.
Done.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/image-decoders/ImageFrame.hFile third_party/WebKit/Source/platform/image-decoders/ImageFrame.h
(right):
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/image-decoders/ImageFrame.h#newcode103third_party/WebKit/Source/platform/image-decoders/ImageFrame.h:103: //
marked as done (immutable). Returns whether the move succeeded.
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Nit: Maybe better second sentence: "This fails if the provided frame's
bitmap is
> marked immutable, since moving its data out from under it
destructively modifies
> it."
The issue here is not in destructive modification (we don't need that
frame data) but if it is done we cannot write to it when decoding the
next frame.
https://codereview.chromium.org/2155973002/diff/80001/third_party/WebKit/Source/platform/image-decoders/ImageFrame.h#newcode141third_party/WebKit/Source/platform/image-decoders/ImageFrame.h:141:
PassRefPtr<SkImage> finalizePixelsAndGetImage();
On 2016/08/30 06:59:40, Peter Kasting wrote:
> Given that this doesn't always finalize the pixels (if decoding isn't
complete),
> maybe combining these two pieces of functionality isn't a good idea.
It's
> convenient, but it's less clear than I thought it would be since I had
thought
> we were only calling this when the frame was complete, and would thus
finalize
> unconditionally.
>
> It looks like all but one caller knows the frame is complete already.
So we
> could make these do something like:
>
> frame->finalizePixels(); // or ->markBitmapImmutable(), if you
want to be
> more literal
> frame->image();
>
> And that one put the finalizePixels() call under a conditional. Then
it's clear
> when callers are finalizing vs. not.
>
> finalizePixels() could DCHECK that the frame is complete, so people
don't
> accidentally call it for incomplete frames, which would be bad. It
would be
> useful for the places that are currently doing this manually (by
getting the
> bitmap and calling setImmutable() on it) as well, assuming we want to
keep
> those, because it's a bit briefer and clearer than that code (and it
has the
> DCHECK() guard). Finally we could put a comment on the declaration of
> finalizePixels() that this results in saving a copy when image() is
used, but
> disables passing this frame to takeBitmapDataIfWriteable(), so callers
need to
> decide carefully what will result in best performance. (It would be
nice to
> know, in practice, what sorts of sequences of calls can result in
these
> optimization cases overlapping.)
>
> Then we could put a comment on image() that calling it when things are
not
> finalized incurs a copy. If you wanted, this could even be split into
two
> functions, e.g. finalizedImage() and nonFinalizedImage() (or image()
and
> copyImage(), or something), each of which would simply DCHECK whether
or not the
> bitmap was immutable. This would force callers to be explicit about
which one
> they thought they were doing, so as to avoid unintentional copies.
I like finalizePixelsAndGetImage as it explains what it is doing (and as
you said, the only problem is the condition inside). Handled that one
caller separately, updated the comment here and added DCHECK as you
suggested.
https://codereview.chromium.org/2155973002/