From b0b010349e810cdb75db11b1e0b131de8d755231 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 17 Jul 2017 23:42:40 -0700 Subject: [PATCH] Ensure that the source rect used for the the raster cache replacement is the same as the size of the N32Premul surface. (flutter/engine#3889) Also adds debug printers for SkRect and SkPoint. --- engine/src/flutter/flow/debug_print.cc | 11 +++++++++++ engine/src/flutter/flow/debug_print.h | 2 ++ engine/src/flutter/flow/raster_cache.cc | 23 ++++++++++++----------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/flow/debug_print.cc b/engine/src/flutter/flow/debug_print.cc index 368194b866..d1b7f25392 100644 --- a/engine/src/flutter/flow/debug_print.cc +++ b/engine/src/flutter/flow/debug_print.cc @@ -53,6 +53,17 @@ std::ostream& operator<<(std::ostream& os, const SkVector4& v) { return os; } +std::ostream& operator<<(std::ostream& os, const SkRect& r) { + os << "LTRB: " << r.fLeft << ", " << r.fTop << ", " << r.fRight << ", " + << r.fBottom; + return os; +} + +std::ostream& operator<<(std::ostream& os, const SkPoint& r) { + os << "XY: " << r.fX << ", " << r.fY; + return os; +} + std::ostream& operator<<(std::ostream& os, const flow::RasterCacheKey& k) { os << "Picture: " << k.picture_id() << " Scale: " << k.scale_key().width() << ", " << k.scale_key().height(); diff --git a/engine/src/flutter/flow/debug_print.h b/engine/src/flutter/flow/debug_print.h index 32d0738060..c54bcc5457 100644 --- a/engine/src/flutter/flow/debug_print.h +++ b/engine/src/flutter/flow/debug_print.h @@ -20,5 +20,7 @@ DEF_PRINTER(SkMatrix); DEF_PRINTER(SkMatrix44); DEF_PRINTER(SkVector3); DEF_PRINTER(SkVector4); +DEF_PRINTER(SkRect); +DEF_PRINTER(SkPoint); #endif // FLUTTER_FLOW_DEBUG_PRINT_H_ diff --git a/engine/src/flutter/flow/raster_cache.cc b/engine/src/flutter/flow/raster_cache.cc index eb11e1cdb5..b92dc983a7 100644 --- a/engine/src/flutter/flow/raster_cache.cc +++ b/engine/src/flutter/flow/raster_cache.cc @@ -75,14 +75,17 @@ RasterCacheResult RasterizePicture(SkPicture* picture, TRACE_EVENT0("flutter", "RasterCachePopulate"); const SkVector3& scale = matrix.scale(); - SkRect logical_rect = picture->cullRect(); - const SkImageInfo image_info = SkImageInfo::MakeN32Premul( - std::ceil(logical_rect.width() * std::abs(scale.x())), // physical width - std::ceil(logical_rect.height() * - std::abs(scale.y())), // physical height - nullptr // colorspace - ); + const SkRect logical_rect = picture->cullRect(); + const SkRect physical_rect = + SkRect::MakeWH(std::ceil(std::labs(logical_rect.width() * scale.x())), + std::ceil(std::labs(logical_rect.height() * scale.y()))); + + const SkImageInfo image_info = + SkImageInfo::MakeN32Premul(physical_rect.width(), // physical width + physical_rect.height(), // physical height + nullptr // colorspace + ); sk_sp surface = context @@ -107,10 +110,8 @@ RasterCacheResult RasterizePicture(SkPicture* picture, return { surface->makeImageSnapshot(), // image - SkRect::MakeWH( - logical_rect.width() * std::abs(scale.x()), - logical_rect.height() * std::abs(scale.y())), // source rect - logical_rect // destination rect + physical_rect, // source rect + logical_rect // destination rect }; }