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

Issue 1694263003: Add Image::updateConcreteSize() (Closed)

Created:
4 years, 10 months ago by davve
Modified:
4 years, 10 months ago
Reviewers:
pdr., fs, Justin Novosad
CC:
fs, ajuma+watch-canvas_chromium.org, blink-reviews, blink-reviews-html_chromium.org, blink-reviews-platform-graphics_chromium.org, Rik, chromium-reviews, danakj+watch_chromium.org, dglazkov+blink, dshwang, drott+blinkwatch_chromium.org, krit, f(malita), gavinp+loader_chromium.org, gyuyoung2, Nate Chapin, jbroman, kinuko+watch, kouhei+svg_chromium.org, loading-reviews+fetch_chromium.org, pdr+graphicswatchlist_chromium.org, pdr+svgwatchlist_chromium.org, rwlbuis, Stephen Chennney, tyoshino+watch_chromium.org, vmpstr+blinkwatch_chromium.org, Yoav Weiss
Base URL:
https://chromium.googlesource.com/chromium/src.git@refactor-size-calculation-in
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add Image::updateConcreteSize() For SVG and generated images using the default sizing algorithm to determine size, a "default object size" is needed to resolve the final size, also called the concrete object size. https://drafts.csswg.org/css-images/#default-sizing This is done in a somewhat adhoc way in Blink, mainly by letting Image::imageSize() return a bogus* size for these kind of images and in selected places using LayoutBoxModelObject::calculateImageIntrinsicDimensions to compute the real size. But when using canvas.drawImage with an <img> pointing to an SVG, the bogus size was used when determining the default size leading to the wrong size being used. This patch adds an updateConcreteObjectSize method to Image so that the image can properly size in the context it's in, according to the specification and use that to size images drawn with canvas.drawImage(). BUG=581357, 475009

Patch Set 1 #

Patch Set 2 : Rebase #

Patch Set 3 : Add test #

Patch Set 4 : Add some documentation and polish title of test. #

Total comments: 7

Patch Set 5 : Pull test for now, needs changes in upcoming CL to pass. Address nits. #

Total comments: 6
Unified diffs Side-by-side diffs Delta from patch set Stats (+47 lines, -2 lines) Patch
M third_party/WebKit/Source/core/fetch/ImageResource.h View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M third_party/WebKit/Source/core/fetch/ImageResource.cpp View 1 2 3 4 1 chunk +8 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/core/html/HTMLImageElement.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M third_party/WebKit/Source/core/html/HTMLImageElement.cpp View 1 1 chunk +9 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/core/html/canvas/CanvasImageSource.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M third_party/WebKit/Source/core/svg/graphics/SVGImage.h View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp View 1 2 3 4 2 chunks +7 lines, -2 lines 0 comments Download
M third_party/WebKit/Source/core/svg/graphics/SVGImageForContainer.h View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M third_party/WebKit/Source/core/svg/graphics/SVGImageForContainer.cpp View 1 1 chunk +6 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp View 1 2 3 2 chunks +2 lines, -0 lines 6 comments Download
M third_party/WebKit/Source/platform/graphics/Image.h View 1 2 3 4 1 chunk +10 lines, -0 lines 0 comments Download

Dependent Patchsets:

Messages

Total messages: 19 (5 generated)
davve
+fs and +pdr for SVG and image wisdom. +senorblanco for modules/canvas2d.
4 years, 10 months ago (2016-02-23 10:23:56 UTC) #4
fs
LGTM w/ thoughts, nits and other ramblings. https://codereview.chromium.org/1694263003/diff/60001/third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html File third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html (right): https://codereview.chromium.org/1694263003/diff/60001/third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html#newcode6 third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html:6: sx = ...
4 years, 10 months ago (2016-02-23 11:44:23 UTC) #5
davve
On 2016/02/23 11:44:23, fs wrote: > LGTM w/ thoughts, nits and other ramblings. Note: I'm ...
4 years, 10 months ago (2016-02-23 12:57:21 UTC) #6
davve
https://codereview.chromium.org/1694263003/diff/60001/third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html File third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html (right): https://codereview.chromium.org/1694263003/diff/60001/third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html#newcode6 third_party/WebKit/LayoutTests/svg/canvas/canvas-default-object-sizing-expected.html:6: sx = typeof sx !== 'undefined' ? sx : ...
4 years, 10 months ago (2016-02-23 13:15:31 UTC) #7
fs
https://codereview.chromium.org/1694263003/diff/60001/third_party/WebKit/Source/core/fetch/ImageResource.h File third_party/WebKit/Source/core/fetch/ImageResource.h (right): https://codereview.chromium.org/1694263003/diff/60001/third_party/WebKit/Source/core/fetch/ImageResource.h#newcode83 third_party/WebKit/Source/core/fetch/ImageResource.h:83: void updateConcreteObjectSize(const LayoutSize& defaultObjectSize); On 2016/02/23 at 13:15:30, David ...
4 years, 10 months ago (2016-02-23 14:52:00 UTC) #8
Justin Novosad
https://codereview.chromium.org/1694263003/diff/80001/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp File third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp (right): https://codereview.chromium.org/1694263003/diff/80001/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp#newcode1270 third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp:1270: imageSourceInternal->updateConcreteObjectSize(FloatSize(canvas()->width(), canvas()->height())); I did some spec analysis on this. ...
4 years, 10 months ago (2016-02-23 15:53:04 UTC) #10
davve
https://codereview.chromium.org/1694263003/diff/80001/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp File third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp (right): https://codereview.chromium.org/1694263003/diff/80001/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp#newcode1270 third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp:1270: imageSourceInternal->updateConcreteObjectSize(FloatSize(canvas()->width(), canvas()->height())); On 2016/02/23 15:53:04, Justin Novosad wrote: > ...
4 years, 10 months ago (2016-02-23 18:40:31 UTC) #11
Justin Novosad
Test in follow-up sgtm. There is one thing I would like to resolve in this ...
4 years, 10 months ago (2016-02-23 19:40:35 UTC) #12
Stephen White
Deferring to Justin for the <canvas> changes.
4 years, 10 months ago (2016-02-23 20:25:03 UTC) #14
Justin Novosad
Rebase required. Conflicts with this: https://chromium.googlesource.com/chromium/src/+/4333ef80f90f702a0571c030f15f0e317931ee7d
4 years, 10 months ago (2016-02-23 21:02:01 UTC) #15
Justin Novosad
On 2016/02/23 21:02:01, Justin Novosad wrote: > Rebase required. Conflicts with this: > https://chromium.googlesource.com/chromium/src/+/4333ef80f90f702a0571c030f15f0e317931ee7d This ...
4 years, 10 months ago (2016-02-23 21:07:14 UTC) #16
davve
Responding in reverse order: On 2016/02/23 19:40:35, Justin Novosad wrote: > Also, I just looked ...
4 years, 10 months ago (2016-02-24 14:53:18 UTC) #17
Justin Novosad
On 2016/02/24 14:53:18, David Vest wrote: > Responding in reverse order: > > On 2016/02/23 ...
4 years, 10 months ago (2016-02-24 15:51:41 UTC) #18
davve
4 years, 10 months ago (2016-02-26 13:40:39 UTC) #19
Thinking about this patch a bit I don't think it's the right
direction.

For the SVG case we end up in a really strange order of events:

 1. We call updateConcreteObjectSize() on the SVGImage with the
    default object size. SVGImage keeps the concrete object size as
    state.

 2. A while later (for canvas in the getSourceImageForCanvas call) we
    extract the size from the SVGImage and put it in a
    SVGImageForContainer that wraps the SVGImage with that particular
    size.  Bonkers.

    Also, if I try to extrapolate this strategy to backgrounds or
    border-image I get into zooming problems since the default sizing
    algorithm will be done in unzoomed coordinates while it's
    currently done in zoomed coordinates.

Let's find something better. I currently see two ways:

 a. Wrap SVGImage inside SVGImageForContainer earlier, before
    accessing the image size. One way would be to add support to
    CanvasImageSource to start a "default sizing context" so that the
    implementation (HTMLImageElement) may wrap SVGImage with the
    concrete object size inside a SVGImageForContainer while the
    context is alive.

 b. Skip SVGImageForContainer and keep all the state inside
    SVGImage...

Neither is super tempting but a) feels like it would fit best with the
current system.

Closing for now.

Powered by Google App Engine
This is Rietveld 408576698