aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecordDrawTest.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2014-11-03 08:19:44 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-03 08:19:44 -0800
commit4d52afef5cf90a2fed3bb69db71675c6450ab397 (patch)
tree2f9a90b273a9ed597f5e5817b11b567d77ecc537 /tests/RecordDrawTest.cpp
parent66cad7669be6c47768d084090a3d498014dfc847 (diff)
Shrink saveLayer device bounds when it supplies an explicit bounds and has a complex paint
This CL shrinks the bound computed for saveLayers that possess both an explicit bound and a complex paint (e.g., one that affects transparent black). In this case the bound of the layer should be the clipped explicit bound rather then the clip prior/after the saveLayer/restore block. In the following the first bound is the currently computed bound while the second is the new/desired one: For a 100x100 picture saveLayer (no bound, no paint) [ 0 0 100 100 ] [ 50 50 100 100 ] setMatrix (translate 50, 50) [ 0 0 100 100 ] [ 50 50 100 100 ] saveLayer (bound of 0, 0, 50, 50 - complex paint) [ 0 0 100 100 ] [ 50 50 100 100 ] restore [ 0 0 100 100 ] [ 50 50 100 100 ] restore [ 0 0 100 100 ] [ 50 50 100 100 ] Review URL: https://codereview.chromium.org/696763002
Diffstat (limited to 'tests/RecordDrawTest.cpp')
-rw-r--r--tests/RecordDrawTest.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp
index 6105c00f7f..1dcd133131 100644
--- a/tests/RecordDrawTest.cpp
+++ b/tests/RecordDrawTest.cpp
@@ -137,7 +137,7 @@ DEF_TEST(RecordDraw_BBH, r) {
recorder.restore();
TestBBH bbh;
- SkRecordFillBounds(record, &bbh);
+ SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, &bbh);
REPORTER_ASSERT(r, bbh.fEntries.count() == 5);
for (int i = 0; i < bbh.fEntries.count(); i++) {
@@ -163,14 +163,14 @@ DEF_TEST(RecordDraw_TextBounds, r) {
recorder.drawPosText(text, bytes, pos, SkPaint());
TestBBH bbh;
- SkRecordFillBounds(record, &bbh);
+ SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, &bbh);
REPORTER_ASSERT(r, bbh.fEntries.count() == 2);
// We can make these next assertions confidently because SkRecordFillBounds
// builds its bounds by overestimating font metrics in a platform-independent way.
// If that changes, these tests will need to be more flexible.
- REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(-110, 0, 140, 60)));
- REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(-80, 20, 180, 100)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0, 0, 140, 60)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0, 20, 180, 100)));
}
// Base test to ensure start/stop range is respected
@@ -251,7 +251,7 @@ DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) {
// The second bug showed up as adjusting the picture bounds (0,0,50,50) by the drop shadow too.
// The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50).
TestBBH bbh;
- SkRecordFillBounds(record, &bbh);
+ SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh);
REPORTER_ASSERT(r, bbh.fEntries.count() == 4);
REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
@@ -259,6 +259,29 @@ DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) {
REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
}
+// When a saveLayer provides an explicit bound and has a complex paint (e.g., one that
+// affects transparent black), that bound should serve to shrink the area of the required
+// backing store.
+DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) {
+ SkRecord record;
+ SkRecorder recorder(&record, 50, 50);
+
+ SkPaint p;
+ p.setXfermodeMode(SkXfermode::kSrc_Mode);
+
+ SkRect bounds = SkRect::MakeLTRB(10, 10, 40, 40);
+ recorder.saveLayer(&bounds, &p);
+ recorder.drawRect(SkRect::MakeLTRB(20, 20, 30, 30), SkPaint());
+ recorder.restore();
+
+ TestBBH bbh;
+ SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh);
+ REPORTER_ASSERT(r, bbh.fEntries.count() == 3);
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(10, 10, 40, 40)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(20, 20, 30, 30)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(10, 10, 40, 40)));
+}
+
DEF_TEST(RecordDraw_drawImage, r){
class SkCanvasMock : public SkCanvas {
public: