Skip to content

Commit

Permalink
[composite-bgcolor-animation] Return empty result when PaintWorkletIn…
Browse files Browse the repository at this point in the history
…put not found

The root cause of the problem is that there is an early exit in the
DiscardableImageMap::GatherDiscardableImages(), happening when the
paint rect for the op is empty. This makes sense because there is
nothing to draw.

Note that this is different than the empty element case. In fact,
we already have "background-color-animation-zero-size-element.html"
under css-backgrounds/animations/ and there is no problem with that.
The bug happens when the element is not empty, but its intersection
with the SkCanvas that it draws into is empty. Please see the notes
in this doc for more details:
https://docs.google.com/document/d/1Da9d7ai5xt4nPX7NDZnqaaTSoFitRSeYxw1qxGjtdeQ/edit

The |PaintWorkletImageProvider::records_| contains the records for
all the discardable images that can draw. Meaning that the ones that
early exits won't be included in the |records_|. But, when the
PaintWorkletImageProvider::GetPaintRecordResult() is called, the
input parameter |PaintWorkletInput| would contain all possible
PaintWorkletInput that is passed from Blink to CC, which obviously
contains the ones that cannot draw. As a result, these
PaintWorkletInputs won't exists in the |records_|.

We handle these cases by returning an empty record because there
is nothing to draw (like empty container cases).

Bug: 1216210
Change-Id: I9630aa4b55fd1322f641f42b05c20aab8c7234c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2954479
Reviewed-by: Philip Rogers <pdr@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#894050}
  • Loading branch information
xidachen authored and Chromium LUCI CQ committed Jun 19, 2021
1 parent 0090f94 commit d43f760
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cc/raster/paint_worklet_image_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ PaintWorkletImageProvider& PaintWorkletImageProvider::operator=(

ImageProvider::ScopedResult PaintWorkletImageProvider::GetPaintRecordResult(
scoped_refptr<PaintWorkletInput> input) {
// The |records_| contains all known PaintWorkletInputs, whether they are
// painted or not, so |input| should always exist in it.
auto it = records_.find(input);
DCHECK(it != records_.end());
// In the DiscardableImageMap::GatherDiscardableImages(), a DrawImageRect can
// early exit the for loop if its paint rect is empty. In that case, the
// |records_| will not contain that PaintWorkletInput, and we should return
// an empty result.
if (it == records_.end())
return ImageProvider::ScopedResult();
return ImageProvider::ScopedResult(it->second.second);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-backgrounds-3/#background-color">
<style>
@keyframes bgcolor {

0% { background: blue; }
100% { background: none; }
}
.target {
animation: bgcolor 50ms;
opacity: 0.9;
height: 0.4px;
margin: 21.6px;
}
</style>
<div class="target"></div>

0 comments on commit d43f760

Please sign in to comment.