Skip to content

Commit

Permalink
Ensure that the source rect used for the the raster cache replacement…
Browse files Browse the repository at this point in the history
… is the same as the size of the N32Premul surface. (flutter#3889)

Also adds debug printers for SkRect and SkPoint.
  • Loading branch information
chinmaygarde authored Jul 18, 2017
1 parent c757fc7 commit 015e8cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
11 changes: 11 additions & 0 deletions flow/debug_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions flow/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
23 changes: 12 additions & 11 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkSurface> surface =
context
Expand All @@ -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
};
}

Expand Down

0 comments on commit 015e8cf

Please sign in to comment.