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

Commit ba5f49c

Browse files
author
Jonah Williams
committed
Partial revert of fractional translation
1 parent b94120d commit ba5f49c

File tree

9 files changed

+22
-149
lines changed

9 files changed

+22
-149
lines changed

flow/layer_snapshot_store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace flutter {
1212
LayerSnapshotData::LayerSnapshotData(int64_t layer_unique_id,
1313
const fml::TimeDelta& duration,
1414
const sk_sp<SkData>& snapshot,
15-
const SkRect& bounds)
15+
const SkIRect& bounds)
1616
: layer_unique_id_(layer_unique_id),
1717
duration_(duration),
1818
snapshot_(snapshot),

flow/layer_snapshot_store.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LayerSnapshotData {
2626
LayerSnapshotData(int64_t layer_unique_id,
2727
const fml::TimeDelta& duration,
2828
const sk_sp<SkData>& snapshot,
29-
const SkRect& bounds);
29+
const SkIRect& bounds);
3030

3131
~LayerSnapshotData() = default;
3232

@@ -36,13 +36,13 @@ class LayerSnapshotData {
3636

3737
sk_sp<SkData> GetSnapshot() const { return snapshot_; }
3838

39-
SkRect GetBounds() const { return bounds_; }
39+
SkIRect GetBounds() const { return bounds_; }
4040

4141
private:
4242
const int64_t layer_unique_id_;
4343
const fml::TimeDelta duration_;
4444
const sk_sp<SkData> snapshot_;
45-
const SkRect bounds_;
45+
const SkIRect bounds_;
4646
};
4747

4848
/// Collects snapshots of layers during frame rasterization.

flow/layers/display_list_layer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void DisplayListLayer::Paint(PaintContext& context) const {
141141
const fml::TimeDelta offscreen_render_time =
142142
fml::TimePoint::Now() - start_time;
143143

144-
const SkRect device_bounds =
144+
const SkIRect device_bounds =
145145
RasterCacheUtil::GetDeviceBounds(paint_bounds(), ctm);
146146
sk_sp<SkData> raster_data = offscreen_surface->GetRasterData(true);
147147
LayerSnapshotData snapshot_data(unique_id(), offscreen_render_time,

flow/raster_cache.cc

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
3232
TRACE_EVENT0("flutter", "RasterCacheResult::draw");
3333
SkAutoCanvasRestore auto_restore(&canvas, true);
3434

35-
SkRect bounds =
35+
SkIRect bounds =
3636
RasterCacheUtil::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
3737
#ifndef NDEBUG
3838
// The image dimensions should always be larger than the device bounds and
@@ -47,23 +47,8 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
4747
#endif
4848
canvas.resetMatrix();
4949
flow_.Step();
50-
51-
bool exceeds_bounds = bounds.fLeft + image_->dimensions().width() >
52-
SkScalarCeilToScalar(bounds.fRight) ||
53-
bounds.fTop + image_->dimensions().height() >
54-
SkScalarCeilToScalar(bounds.fBottom);
55-
56-
// Make sure raster cache doesn't bleed to physical pixels outside of
57-
// original bounds. https://github.com/flutter/flutter/issues/110002
58-
if (exceeds_bounds) {
59-
canvas.save();
60-
canvas.clipRect(SkRect::Make(bounds.roundOut()));
61-
}
6250
canvas.drawImage(image_, bounds.fLeft, bounds.fTop, SkSamplingOptions(),
6351
paint);
64-
if (exceeds_bounds) {
65-
canvas.restore();
66-
}
6752
}
6853

6954
RasterCache::RasterCache(size_t access_threshold,
@@ -80,14 +65,11 @@ std::unique_ptr<RasterCacheResult> RasterCache::Rasterize(
8065
const {
8166
TRACE_EVENT0("flutter", "RasterCachePopulate");
8267

83-
SkRect dest_rect =
68+
SkIRect cache_rect =
8469
RasterCacheUtil::GetDeviceBounds(context.logical_rect, context.matrix);
85-
// we always round out here so that the texture is integer sized.
86-
int width = SkScalarCeilToInt(dest_rect.width());
87-
int height = SkScalarCeilToInt(dest_rect.height());
88-
89-
const SkImageInfo image_info = SkImageInfo::MakeN32Premul(
90-
width, height, sk_ref_sp(context.dst_color_space));
70+
const SkImageInfo image_info =
71+
SkImageInfo::MakeN32Premul(cache_rect.width(), cache_rect.height(),
72+
sk_ref_sp(context.dst_color_space));
9173

9274
sk_sp<SkSurface> surface =
9375
context.gr_context ? SkSurface::MakeRenderTarget(
@@ -100,7 +82,7 @@ std::unique_ptr<RasterCacheResult> RasterCache::Rasterize(
10082

10183
SkCanvas* canvas = surface->getCanvas();
10284
canvas->clear(SK_ColorTRANSPARENT);
103-
canvas->translate(-dest_rect.left(), -dest_rect.top());
85+
canvas->translate(-cache_rect.left(), -cache_rect.top());
10486
canvas->concat(context.matrix);
10587
draw_function(canvas);
10688

flow/raster_cache_unittests.cc

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -402,56 +402,7 @@ TEST(RasterCache, ComputeDeviceRectBasedOnFractionalTranslation) {
402402
SkRect logical_rect = SkRect::MakeLTRB(0, 0, 300.2, 300.3);
403403
SkMatrix ctm = SkMatrix::MakeAll(2.0, 0, 0, 0, 2.0, 0, 0, 0, 1);
404404
auto result = RasterCacheUtil::GetDeviceBounds(logical_rect, ctm);
405-
ASSERT_EQ(result, SkRect::MakeLTRB(0.0, 0.0, 600.4, 600.6));
406-
}
407-
408-
// Construct a cache result whose device target rectangle rounds out to be one
409-
// pixel wider than the cached image. Verify that it can be drawn without
410-
// triggering any assertions.
411-
TEST(RasterCache, DeviceRectRoundOutForDisplayList) {
412-
size_t threshold = 1;
413-
flutter::RasterCache cache(threshold);
414-
415-
SkRect logical_rect = SkRect::MakeLTRB(28, 0, 354.56731, 310.288);
416-
DisplayListBuilder builder(logical_rect);
417-
builder.setColor(SK_ColorRED);
418-
builder.drawRect(logical_rect);
419-
sk_sp<DisplayList> display_list = builder.Build();
420-
421-
SkMatrix ctm = SkMatrix::MakeAll(1.3312, 0, 233, 0, 1.3312, 206, 0, 0, 1);
422-
SkPaint paint;
423-
424-
SkCanvas canvas(100, 100, nullptr);
425-
canvas.setMatrix(ctm);
426-
427-
FixedRefreshRateStopwatch raster_time;
428-
FixedRefreshRateStopwatch ui_time;
429-
MutatorsStack mutators_stack;
430-
PrerollContextHolder preroll_context_holder = GetSamplePrerollContextHolder(
431-
&cache, &raster_time, &ui_time, &mutators_stack);
432-
PaintContextHolder paint_context_holder =
433-
GetSamplePaintContextHolder(&cache, &raster_time, &ui_time);
434-
auto& preroll_context = preroll_context_holder.preroll_context;
435-
auto& paint_context = paint_context_holder.paint_context;
436-
437-
cache.BeginFrame();
438-
DisplayListRasterCacheItem display_list_item(display_list.get(), SkPoint(),
439-
true, false);
440-
441-
ASSERT_FALSE(RasterCacheItemPrerollAndTryToRasterCache(
442-
display_list_item, preroll_context, paint_context, ctm));
443-
ASSERT_FALSE(display_list_item.Draw(paint_context, &canvas, &paint));
444-
445-
cache.EndFrame();
446-
cache.BeginFrame();
447-
448-
ASSERT_TRUE(RasterCacheItemPrerollAndTryToRasterCache(
449-
display_list_item, preroll_context, paint_context, ctm));
450-
ASSERT_TRUE(display_list_item.Draw(paint_context, &canvas, &paint));
451-
452-
canvas.translate(248, 0);
453-
ASSERT_TRUE(cache.Draw(display_list_item.GetId().value(), canvas, &paint));
454-
ASSERT_TRUE(display_list_item.Draw(paint_context, &canvas, &paint));
405+
ASSERT_EQ(result, SkIRect::MakeLTRB(0, 0, 601, 601));
455406
}
456407

457408
TEST(RasterCache, NestedOpCountMetricUsedForDisplayList) {
@@ -787,67 +738,5 @@ TEST_F(RasterCacheTest, RasterCacheKeyID_LayerChildrenIds) {
787738
ASSERT_EQ(ids, expected_ids);
788739
}
789740

790-
TEST_F(RasterCacheTest, RasterCacheBleedingNoClipNeeded) {
791-
SkImageInfo info =
792-
SkImageInfo::MakeN32(40, 40, SkAlphaType::kOpaque_SkAlphaType);
793-
794-
auto image = SkImage::MakeRasterData(
795-
info, SkData::MakeUninitialized(40 * 40 * 4), 40 * 4);
796-
auto canvas = MockCanvas();
797-
canvas.setMatrix(SkMatrix::Scale(2, 2));
798-
// Drawing cached image does not exceeds physical pixels of the original
799-
// bounds and does not need to be clipped.
800-
auto cache_result =
801-
RasterCacheResult(image, SkRect::MakeXYWH(100.3, 100.3, 20, 20), "");
802-
auto paint = SkPaint();
803-
cache_result.draw(canvas, &paint);
804-
805-
EXPECT_EQ(canvas.draw_calls(),
806-
std::vector({
807-
MockCanvas::DrawCall{
808-
0, MockCanvas::SetMatrixData{SkM44::Scale(2, 2)}},
809-
MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
810-
MockCanvas::DrawCall{1, MockCanvas::SetMatrixData{SkM44()}},
811-
MockCanvas::DrawCall{
812-
1, MockCanvas::DrawImageData{image, 200.6, 200.6,
813-
SkSamplingOptions(), paint}},
814-
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}},
815-
}));
816-
}
817-
818-
TEST_F(RasterCacheTest, RasterCacheBleedingClipNeeded) {
819-
SkImageInfo info =
820-
SkImageInfo::MakeN32(40, 40, SkAlphaType::kOpaque_SkAlphaType);
821-
822-
auto image = SkImage::MakeRasterData(
823-
info, SkData::MakeUninitialized(40 * 40 * 4), 40 * 4);
824-
auto canvas = MockCanvas();
825-
canvas.setMatrix(SkMatrix::Scale(2, 2));
826-
827-
auto cache_result =
828-
RasterCacheResult(image, SkRect::MakeXYWH(100.3, 100.3, 19.6, 19.6), "");
829-
auto paint = SkPaint();
830-
cache_result.draw(canvas, &paint);
831-
832-
EXPECT_EQ(
833-
canvas.draw_calls(),
834-
std::vector({
835-
MockCanvas::DrawCall{0,
836-
MockCanvas::SetMatrixData{SkM44::Scale(2, 2)}},
837-
MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
838-
MockCanvas::DrawCall{1, MockCanvas::SetMatrixData{SkM44()}},
839-
MockCanvas::DrawCall{1, MockCanvas::SaveData{2}},
840-
MockCanvas::DrawCall{
841-
2, MockCanvas::ClipRectData{SkRect::MakeLTRB(200, 200, 240, 240),
842-
SkClipOp::kIntersect,
843-
MockCanvas::kHard_ClipEdgeStyle}},
844-
MockCanvas::DrawCall{
845-
2, MockCanvas::DrawImageData{image, 200.6, 200.6,
846-
SkSamplingOptions(), paint}},
847-
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
848-
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}},
849-
}));
850-
}
851-
852741
} // namespace testing
853742
} // namespace flutter

flow/raster_cache_util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ struct RasterCacheUtil {
4949
return true;
5050
}
5151

52-
static SkRect GetDeviceBounds(const SkRect& rect, const SkMatrix& ctm) {
52+
static SkIRect GetDeviceBounds(const SkRect& rect, const SkMatrix& ctm) {
5353
SkRect device_rect;
5454
ctm.mapRect(&device_rect, rect);
55-
return device_rect;
55+
SkIRect bounds;
56+
device_rect.roundOut(&bounds);
57+
return bounds;
5658
}
5759
};
5860

flow/testing/mock_raster_cache.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace flutter {
1717
namespace testing {
1818

19-
MockRasterCacheResult::MockRasterCacheResult(SkRect device_rect)
19+
MockRasterCacheResult::MockRasterCacheResult(SkIRect device_rect)
2020
: RasterCacheResult(nullptr, SkRect::MakeEmpty(), "RasterCacheFlow::test"),
2121
device_rect_(device_rect) {}
2222

@@ -40,7 +40,7 @@ void MockRasterCache::AddMockLayer(int width, int height) {
4040
UpdateCacheEntry(
4141
RasterCacheKeyID(layer.unique_id(), RasterCacheKeyType::kLayer),
4242
r_context, [&](SkCanvas* canvas) {
43-
SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
43+
SkIRect cache_rect = RasterCacheUtil::GetDeviceBounds(
4444
r_context.logical_rect, r_context.matrix);
4545
return std::make_unique<MockRasterCacheResult>(cache_rect);
4646
});
@@ -78,7 +78,7 @@ void MockRasterCache::AddMockPicture(int width, int height) {
7878
UpdateCacheEntry(RasterCacheKeyID(display_list->unique_id(),
7979
RasterCacheKeyType::kDisplayList),
8080
r_context, [&](SkCanvas* canvas) {
81-
SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
81+
SkIRect cache_rect = RasterCacheUtil::GetDeviceBounds(
8282
r_context.logical_rect, r_context.matrix);
8383
return std::make_unique<MockRasterCacheResult>(cache_rect);
8484
});

flow/testing/mock_raster_cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace testing {
2929
*/
3030
class MockRasterCacheResult : public RasterCacheResult {
3131
public:
32-
explicit MockRasterCacheResult(SkRect device_rect);
32+
explicit MockRasterCacheResult(SkIRect device_rect);
3333

3434
void draw(SkCanvas& canvas, const SkPaint* paint = nullptr) const override{};
3535

@@ -43,7 +43,7 @@ class MockRasterCacheResult : public RasterCacheResult {
4343
}
4444

4545
private:
46-
SkRect device_rect_;
46+
SkIRect device_rect_;
4747
};
4848

4949
static std::vector<RasterCacheItem*> raster_cache_items_;

shell/common/shell.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ static rapidjson::Value SerializeLayerSnapshot(
18401840
result.AddMember("duration_micros", snapshot.GetDuration().ToMicroseconds(),
18411841
allocator);
18421842

1843-
const SkRect bounds = snapshot.GetBounds();
1843+
const SkIRect bounds = snapshot.GetBounds();
18441844
result.AddMember("top", bounds.top(), allocator);
18451845
result.AddMember("left", bounds.left(), allocator);
18461846
result.AddMember("width", bounds.width(), allocator);

0 commit comments

Comments
 (0)