Merge "Fix savelayer rounding" into nyc-mr1-dev

This commit is contained in:
Chris Craik
2016-06-28 17:33:26 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 1 deletions

View File

@@ -127,7 +127,8 @@ int RecordingCanvas::saveLayer(float left, float top, float right, float bottom,
// operations will be able to store and restore the current clip and transform info, and
// quick rejection will be correct (for display lists)
const Rect unmappedBounds(left, top, right, bottom);
Rect unmappedBounds(left, top, right, bottom);
unmappedBounds.roundOut();
// determine clipped bounds relative to previous viewport.
Rect visibleBounds = unmappedBounds;

View File

@@ -340,6 +340,36 @@ TEST(RecordingCanvas, saveLayer_simple) {
EXPECT_EQ(3, count);
}
TEST(RecordingCanvas, saveLayer_rounding) {
auto dl = TestUtils::createDisplayList<RecordingCanvas>(100, 100, [](RecordingCanvas& canvas) {
canvas.saveLayerAlpha(10.25f, 10.75f, 89.25f, 89.75f, 128, SaveFlags::ClipToLayer);
canvas.drawRect(20, 20, 80, 80, SkPaint());
canvas.restore();
});
int count = 0;
playbackOps(*dl, [&count](const RecordedOp& op) {
Matrix4 expectedMatrix;
switch(count++) {
case 0:
EXPECT_EQ(RecordedOpId::BeginLayerOp, op.opId);
EXPECT_EQ(Rect(10, 10, 90, 90), op.unmappedBounds) << "Expect bounds rounded out";
break;
case 1:
EXPECT_EQ(RecordedOpId::RectOp, op.opId);
expectedMatrix.loadTranslate(-10, -10, 0);
EXPECT_MATRIX_APPROX_EQ(expectedMatrix, op.localMatrix) << "Expect rounded offset";
break;
case 2:
EXPECT_EQ(RecordedOpId::EndLayerOp, op.opId);
// Don't bother asserting recording state data - it's not used
break;
default:
ADD_FAILURE();
}
});
EXPECT_EQ(3, count);
}
TEST(RecordingCanvas, saveLayer_missingRestore) {
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
canvas.saveLayerAlpha(0, 0, 200, 200, 128, SaveFlags::ClipToLayer);