Tweak the condition of 'FML_DCHECK' to solve the issue caused by round-off error (flutter/engine#34660)

This commit is contained in:
ColdPaleLight 2022-07-18 13:00:04 +08:00 committed by GitHub
parent 676e99c1f4
commit cd73f4378c

View File

@ -34,8 +34,17 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
SkRect bounds =
RasterCacheUtil::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
FML_DCHECK(std::abs(bounds.width() - image_->dimensions().width()) <= 1 &&
std::abs(bounds.height() - image_->dimensions().height()) <= 1);
#ifndef NDEBUG
// The image dimensions should always be larger than the device bounds and
// smaller than the device bounds plus one pixel, at the same time, we must
// introduce epsilon to solve the round-off error. The value of epsilon is
// 1/512, which represents half of an AA sample.
float epsilon = 1 / 512.0;
FML_DCHECK(image_->dimensions().width() - bounds.width() > -epsilon &&
image_->dimensions().height() - bounds.height() > -epsilon &&
image_->dimensions().width() - bounds.width() < 1 + epsilon &&
image_->dimensions().height() - bounds.height() < 1 + epsilon);
#endif
canvas.resetMatrix();
flow_.Step();
canvas.drawImage(image_, bounds.fLeft, bounds.fTop, SkSamplingOptions(),