From 40732b34a1bf94eb44ee4b2327eece8d97735f11 Mon Sep 17 00:00:00 2001 From: mtklein Date: Sat, 24 Oct 2015 07:45:47 -0700 Subject: SkRecord refactor: fill bounds array instead of BBH directly This should be a strict refactor, just pulling out the bounds array. (It's the rescued nice parts of a dead-end CL targeting skia:4492.) BUG=skia: Review URL: https://codereview.chromium.org/1424553002 --- tests/RecordDrawTest.cpp | 72 +++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 50 deletions(-) (limited to 'tests/RecordDrawTest.cpp') diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp index d8ca48d796..13be115253 100644 --- a/tests/RecordDrawTest.cpp +++ b/tests/RecordDrawTest.cpp @@ -122,26 +122,6 @@ DEF_TEST(RecordDraw_SetMatrixClobber, r) { REPORTER_ASSERT(r, setMatrix->matrix == expected); } -struct TestBBH : public SkBBoxHierarchy { - void insert(const SkRect boundsArray[], int N) override { - fEntries.setCount(N); - for (int i = 0; i < N; i++) { - Entry e = { i, boundsArray[i] }; - fEntries[i] = e; - } - } - - void search(const SkRect& query, SkTDArray* results) const override {} - size_t bytesUsed() const override { return 0; } - SkRect getRootBound() const override { return SkRect::MakeEmpty(); } - - struct Entry { - int opIndex; - SkRect bounds; - }; - SkTDArray fEntries; -}; - // Like a==b, with a little slop recognizing that float equality can be weird. static bool sloppy_rect_eq(SkRect a, SkRect b) { SkRect inset(a), outset(a); @@ -150,9 +130,7 @@ static bool sloppy_rect_eq(SkRect a, SkRect b) { return outset.contains(b) && !inset.contains(b); } -// This test is not meant to make total sense yet. It's testing the status quo -// of SkRecordFillBounds(), which itself doesn't make total sense yet. -DEF_TEST(RecordDraw_BBH, r) { +DEF_TEST(RecordDraw_BasicBounds, r) { SkRecord record; SkRecorder recorder(&record, W, H); recorder.save(); @@ -161,14 +139,11 @@ DEF_TEST(RecordDraw_BBH, r) { recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); recorder.restore(); - TestBBH 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++) { - REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == i); + SkAutoTMalloc bounds(record.count()); + SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, bounds); - REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries[i].bounds)); + for (int i = 0; i < record.count(); i++) { + REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bounds[i])); } } @@ -187,15 +162,14 @@ DEF_TEST(RecordDraw_TextBounds, r) { const SkPoint pos[] = { {40, 50}, {60, 70} }; recorder.drawPosText(text, bytes, pos, SkPaint()); - TestBBH bbh; - SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, &bbh); - REPORTER_ASSERT(r, bbh.fEntries.count() == 2); + SkAutoTMalloc bounds(record.count()); + SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, bounds); // 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(0, 0, 140, 60))); - REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0, 20, 180, 100))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[0], SkRect::MakeLTRB(0, 0, 140, 60))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[1], SkRect::MakeLTRB(0, 20, 180, 100))); } // Base test to ensure start/stop range is respected @@ -248,13 +222,12 @@ 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(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))); - REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0, 0, 40, 40))); - REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); + SkAutoTMalloc bounds(record.count()); + SkRecordFillBounds(SkRect::MakeWH(50, 50), record, bounds); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[0], SkRect::MakeLTRB(0, 0, 50, 50))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[1], SkRect::MakeLTRB(0, 0, 50, 50))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[2], SkRect::MakeLTRB(0, 0, 40, 40))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[3], SkRect::MakeLTRB(0, 0, 50, 50))); } // When a saveLayer provides an explicit bound and has a complex paint (e.g., one that @@ -267,18 +240,17 @@ DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) { SkPaint p; p.setXfermodeMode(SkXfermode::kSrc_Mode); - SkRect bounds = SkRect::MakeLTRB(10, 10, 40, 40); - recorder.saveLayer(&bounds, &p); + SkRect layerBounds = SkRect::MakeLTRB(10, 10, 40, 40); + recorder.saveLayer(&layerBounds, &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); + SkAutoTMalloc bounds(record.count()); + SkRecordFillBounds(SkRect::MakeWH(50, 50), record, bounds); if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { - 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))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[0], SkRect::MakeLTRB(10, 10, 40, 40))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[1], SkRect::MakeLTRB(20, 20, 30, 30))); + REPORTER_ASSERT(r, sloppy_rect_eq(bounds[2], SkRect::MakeLTRB(10, 10, 40, 40))); } } -- cgit v1.2.3