Source/WebCore/ChangeLog

 12018-07-24 Simon Fraser <simon.fraser@apple.com>
 2
 3 Animation stops with object-fit:contain on an animated 2d canvas
 4 https://bugs.webkit.org/show_bug.cgi?id=187840
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 If a canvas has object-fit: cover or contain, repaints need to mapped through
 9 the rect that is used to position the canvas in the element bounds, which is replacedContentRect().
 10
 11 Add a version of replacedContentRect() that doesn't require passing the intrinsicSize() since
 12 all but RenderVideo just pass the RenderReplaced's intrinsicSize.
 13
 14 Test: fast/repaint/canvas-object-fit.html
 15
 16 * html/HTMLCanvasElement.cpp:
 17 (WebCore::HTMLCanvasElement::didDraw):
 18 * rendering/RenderHTMLCanvas.cpp:
 19 (WebCore::RenderHTMLCanvas::paintReplaced):
 20 * rendering/RenderImage.cpp:
 21 (WebCore::RenderImage::updateInnerContentRect):
 22 (WebCore::RenderImage::paintReplaced):
 23 * rendering/RenderLayerBacking.cpp:
 24 (WebCore::RenderLayerBacking::contentsBox const):
 25 * rendering/RenderReplaced.h:
 26 (WebCore::RenderReplaced::replacedContentRect const):
 27 * rendering/shapes/ShapeOutsideInfo.cpp:
 28 (WebCore::ShapeOutsideInfo::createShapeForImage const):
 29
1302018-07-21 Zalan Bujtas <zalan@apple.com>
231
332 [LFC][IFC] Add verification for inline text runs.

Source/WebCore/html/HTMLCanvasElement.cpp

@@void HTMLCanvasElement::didDraw(const FloatRect& rect)
508508 clearCopiedImage();
509509
510510 FloatRect dirtyRect = rect;
511  if (RenderBox* ro = renderBox()) {
512  FloatRect destRect = ro->contentBoxRect();
 511 if (is<RenderReplaced>(renderBox())) {
 512 auto& renderer = downcast<RenderReplaced>(*renderBox());
 513 FloatRect destRect = renderer.replacedContentRect();
513514 // Inflate dirty rect to cover antialiasing on image buffers.
514515 if (drawingContext() && drawingContext()->shouldAntialias())
515516 dirtyRect.inflate(1);

@@void HTMLCanvasElement::didDraw(const FloatRect& rect)
517518 r.intersect(destRect);
518519 if (!r.isEmpty() && !m_dirtyRect.contains(r)) {
519520 m_dirtyRect.unite(r);
520  ro->repaintRectangle(enclosingIntRect(m_dirtyRect));
 521 renderer.repaintRectangle(enclosingIntRect(m_dirtyRect));
521522 }
522523 }
523524 notifyObserversCanvasChanged(dirtyRect);

Source/WebCore/rendering/RenderHTMLCanvas.cpp

@@void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
7474
7575 LayoutRect contentBoxRect = this->contentBoxRect();
7676 contentBoxRect.moveBy(paintOffset);
77  LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize());
 77 LayoutRect replacedContentRect = this->replacedContentRect();
7878 replacedContentRect.moveBy(paintOffset);
7979
8080 // Not allowed to overflow the content box.

Source/WebCore/rendering/RenderImage.cpp

@@void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize)
285285void RenderImage::updateInnerContentRect()
286286{
287287 // Propagate container size to image resource.
288  IntSize containerSize(replacedContentRect(intrinsicSize()).size());
 288 IntSize containerSize(replacedContentRect().size());
289289 if (!containerSize.isEmpty()) {
290290 URL imageSourceURL;
291291 if (HTMLImageElement* imageElement = is<HTMLImageElement>(element()) ? downcast<HTMLImageElement>(element()) : nullptr)

@@void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
497497
498498 LayoutRect contentBoxRect = this->contentBoxRect();
499499 contentBoxRect.moveBy(paintOffset);
500  LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize());
 500 LayoutRect replacedContentRect = this->replacedContentRect();
501501 replacedContentRect.moveBy(paintOffset);
502502 bool clip = !contentBoxRect.contains(replacedContentRect);
503503 GraphicsContextStateSaver stateSaver(context, clip);

Source/WebCore/rendering/RenderLayerBacking.cpp

@@LayoutRect RenderLayerBacking::contentsBox() const
23442344#endif
23452345 if (is<RenderReplaced>(renderBox)) {
23462346 RenderReplaced& renderReplaced = downcast<RenderReplaced>(renderBox);
2347  contentsRect = renderReplaced.replacedContentRect(renderBox.intrinsicSize());
 2347 contentsRect = renderReplaced.replacedContentRect();
23482348 } else
23492349 contentsRect = renderBox.contentBoxRect();
23502350

Source/WebCore/rendering/RenderReplaced.h

@@public:
3434 LayoutUnit computeReplacedLogicalHeight(std::optional<LayoutUnit> estimatedUsedWidth = std::nullopt) const override;
3535
3636 LayoutRect replacedContentRect(const LayoutSize& intrinsicSize) const;
 37 LayoutRect replacedContentRect() const { return replacedContentRect(intrinsicSize()); }
3738
3839 bool hasReplacedLogicalWidth() const;
3940 bool hasReplacedLogicalHeight() const;

Source/WebCore/rendering/shapes/ShapeOutsideInfo.cpp

@@std::unique_ptr<Shape> ShapeOutsideInfo::createShapeForImage(StyleImage* styleIm
151151
152152 const LayoutRect& marginRect = getShapeImageMarginRect(m_renderer, m_referenceBoxLogicalSize);
153153 const LayoutRect& imageRect = is<RenderImage>(m_renderer)
154  ? downcast<RenderImage>(m_renderer).replacedContentRect(m_renderer.intrinsicSize())
 154 ? downcast<RenderImage>(m_renderer).replacedContentRect()
155155 : LayoutRect(LayoutPoint(), imageSize);
156156
157157 ASSERT(!styleImage->isPending());

LayoutTests/ChangeLog

 12018-07-24 Simon Fraser <simon.fraser@apple.com>
 2
 3 Animation stops with object-fit:contain on an animated 2d canvas
 4 https://bugs.webkit.org/show_bug.cgi?id=187840
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * fast/repaint/canvas-object-fit-expected.txt: Added.
 9 * fast/repaint/canvas-object-fit.html: Added.
 10
1112018-07-20 John Wilander <wilander@apple.com>
212
313 Resource Load Statistics: Enable basic functionality in experimental debug mode

LayoutTests/fast/repaint/canvas-object-fit-expected.txt

 1 (GraphicsLayer
 2 (anchor 0.00 0.00)
 3 (bounds 800.00 600.00)
 4 (children 1
 5 (GraphicsLayer
 6 (bounds 800.00 600.00)
 7 (contentsOpaque 1)
 8 (children 1
 9 (GraphicsLayer
 10 (position 8.00 8.00)
 11 (bounds 202.00 102.00)
 12 (drawsContent 1)
 13 (repaint rects
 14 (rect 70.00 20.00 7.00 7.00)
 15 )
 16 )
 17 )
 18 )
 19 )
 20)
 21

LayoutTests/fast/repaint/canvas-object-fit.html

 1<!-- Test for https://bugs.webkit.org/show_bug.cgi?id=46319 -->
 2<head>
 3 <style>
 4 canvas {
 5 object-fit: contain;
 6 border: 1px solid black;
 7 width: 200px;
 8 height: 100px;
 9 }
 10 </style>
 11</head>
 12<body>
 13 <canvas id="canvas" width="200" height="200"></canvas>
 14<pre id="layers"></pre>
 15 <script>
 16 if (window.testRunner) {
 17 testRunner.dumpAsText();
 18 testRunner.waitUntilDone();
 19 }
 20
 21 var canvas = document.getElementById('canvas');
 22 var ctx = canvas.getContext('2d');
 23
 24 ctx.fillStyle = "rgb(0, 128, 0)";
 25 ctx.fillRect(0, 0, 200, 200);
 26
 27 function repaintTest()
 28 {
 29 if (window.internals)
 30 window.internals.startTrackingRepaints();
 31
 32 ctx.fillStyle = "rgb(0, 0, 128)";
 33 ctx.fillRect(40, 40, 10, 10);
 34
 35 if (window.internals)
 36 document.getElementById('layers').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
 37
 38 if (window.testRunner)
 39 testRunner.notifyDone();
 40 }
 41
 42 function startTest()
 43 {
 44 setTimeout(function() {
 45 repaintTest();
 46 }, 0)
 47 }
 48 window.addEventListener('load', startTest, false);
 49 </script>
 50</body>