Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Unified Diff: tests/RecordDrawTest.cpp

Issue 1424553002: SkRecord refactor: fill bounds array instead of BBH directly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RecordDrawTest.cpp
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp
index d8ca48d7969c0904275bad925fc62fe1a9d6a07d..13be115253f4ac8bacee3680ed98a04a5a256745 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<int>* results) const override {}
- size_t bytesUsed() const override { return 0; }
- SkRect getRootBound() const override { return SkRect::MakeEmpty(); }
-
- struct Entry {
- int opIndex;
- SkRect bounds;
- };
- SkTDArray<Entry> 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<SkRect> 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<SkRect> 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<SkRect> 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<SkRect> 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)));
}
}
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698