Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 37ed78a

Browse files
committed
Allow drawing raster cache results whose device rect is one pixel larger than the cached image
RasterCacheResult::draw constructs the device target rectangle by calling SkRect::roundOut, which rounds down the left/top coordinates and rounds up the right/bottom coordinates. The rounding can produce a device rect whose width and/or height differs from the cache result image's width/height by one pixel.
1 parent 8a5c8c3 commit 37ed78a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

flow/raster_cache.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
2626
SkAutoCanvasRestore auto_restore(&canvas, true);
2727
SkIRect bounds =
2828
RasterCache::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
29-
FML_DCHECK(bounds.size() == image_->dimensions());
29+
FML_DCHECK(
30+
std::abs(bounds.size().width() - image_->dimensions().width()) <= 1 &&
31+
std::abs(bounds.size().height() - image_->dimensions().height()) <= 1);
3032
canvas.resetMatrix();
3133
canvas.drawImage(image_, bounds.fLeft, bounds.fTop, paint);
3234
}

flow/raster_cache_unittests.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,37 @@ TEST(RasterCache, SweepsRemoveUnusedFrames) {
122122
ASSERT_FALSE(cache.Get(*picture, matrix).is_valid());
123123
}
124124

125+
// Construct a cache result whose device target rectangle rounds out to be one
126+
// pixel wider than the cached image. Verify that it can be drawn without
127+
// triggering any assertions.
128+
TEST(RasterCache, DeviceRectRoundOut) {
129+
size_t threshold = 1;
130+
flutter::RasterCache cache(threshold);
131+
132+
SkPictureRecorder recorder;
133+
SkRect logical_rect = SkRect::MakeLTRB(28, 0, 354.56731, 310.288);
134+
recorder.beginRecording(logical_rect);
135+
SkPaint paint;
136+
paint.setColor(SK_ColorRED);
137+
recorder.getRecordingCanvas()->drawRect(logical_rect, paint);
138+
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
139+
140+
SkMatrix ctm = SkMatrix::MakeAll(1.3312, 0, 233, 0, 1.3312, 206, 0, 0, 1);
141+
142+
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
143+
ASSERT_FALSE(
144+
cache.Prepare(NULL, picture.get(), ctm, srgb.get(), true, false));
145+
ASSERT_FALSE(cache.Get(*picture, ctm).is_valid());
146+
cache.SweepAfterFrame();
147+
ASSERT_TRUE(cache.Prepare(NULL, picture.get(), ctm, srgb.get(), true, false));
148+
ASSERT_TRUE(cache.Get(*picture, ctm).is_valid());
149+
150+
SkCanvas canvas(100, 100, nullptr);
151+
canvas.setMatrix(ctm);
152+
canvas.translate(248, 0);
153+
154+
cache.Get(*picture, ctm).draw(canvas);
155+
}
156+
125157
} // namespace testing
126158
} // namespace flutter

0 commit comments

Comments
 (0)