Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "RecordTestUtils.h" | 9 #include "RecordTestUtils.h" |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 91 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
| 92 REPORTER_ASSERT(r, setMatrix->matrix == translate); | 92 REPORTER_ASSERT(r, setMatrix->matrix == translate); |
| 93 | 93 |
| 94 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); | 94 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
| 95 SkMatrix expected = scale; | 95 SkMatrix expected = scale; |
| 96 expected.postConcat(translate); | 96 expected.postConcat(translate); |
| 97 REPORTER_ASSERT(r, setMatrix->matrix == expected); | 97 REPORTER_ASSERT(r, setMatrix->matrix == expected); |
| 98 } | 98 } |
| 99 | 99 |
| 100 struct TestBBH : public SkBBoxHierarchy { | 100 struct TestBBH : public SkBBoxHierarchy { |
| 101 virtual void insert(void* data, const SkRect& bounds, bool defer) SK_OVERRID E { | 101 virtual void insert(unsigned data, const SkRect& bounds, bool defer) SK_OVER RIDE { |
| 102 Entry e = { (uintptr_t)data, bounds }; | 102 Entry e = { data, bounds }; |
| 103 entries.push(e); | 103 entries.push(e); |
| 104 } | 104 } |
| 105 virtual int getCount() const SK_OVERRIDE { return entries.count(); } | 105 virtual int getCount() const SK_OVERRIDE { return entries.count(); } |
| 106 | 106 |
| 107 virtual void flushDeferredInserts() SK_OVERRIDE {} | 107 virtual void flushDeferredInserts() SK_OVERRIDE {} |
| 108 | 108 |
| 109 virtual void search(const SkRect& query, SkTDArray<void*>* results) const SK _OVERRIDE {} | 109 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE {} |
| 110 virtual void clear() SK_OVERRIDE {} | 110 virtual void clear() SK_OVERRIDE {} |
| 111 virtual void rewindInserts() SK_OVERRIDE {} | |
| 112 virtual int getDepth() const SK_OVERRIDE { return -1; } | 111 virtual int getDepth() const SK_OVERRIDE { return -1; } |
| 113 | 112 |
| 114 struct Entry { | 113 struct Entry { |
| 115 uintptr_t data; | 114 unsigned data; |
| 116 SkRect bounds; | 115 SkRect bounds; |
| 117 }; | 116 }; |
|
robertphillips
2014/10/02 12:27:35
fEntries ?
mtklein
2014/10/02 14:32:09
Done.
| |
| 118 SkTDArray<Entry> entries; | 117 SkTDArray<Entry> entries; |
| 119 }; | 118 }; |
| 120 | 119 |
| 121 // Like a==b, with a little slop recognizing that float equality can be weird. | 120 // Like a==b, with a little slop recognizing that float equality can be weird. |
| 122 static bool sloppy_rect_eq(SkRect a, SkRect b) { | 121 static bool sloppy_rect_eq(SkRect a, SkRect b) { |
| 123 SkRect inset(a), outset(a); | 122 SkRect inset(a), outset(a); |
| 124 inset.inset(1, 1); | 123 inset.inset(1, 1); |
| 125 outset.outset(1, 1); | 124 outset.outset(1, 1); |
| 126 return outset.contains(b) && !inset.contains(b); | 125 return outset.contains(b) && !inset.contains(b); |
| 127 } | 126 } |
| 128 | 127 |
| 129 // This test is not meant to make total sense yet. It's testing the status quo | 128 // This test is not meant to make total sense yet. It's testing the status quo |
| 130 // of SkRecordFillBounds(), which itself doesn't make total sense yet. | 129 // of SkRecordFillBounds(), which itself doesn't make total sense yet. |
| 131 DEF_TEST(RecordDraw_BBH, r) { | 130 DEF_TEST(RecordDraw_BBH, r) { |
| 132 SkRecord record; | 131 SkRecord record; |
| 133 SkRecorder recorder(&record, W, H); | 132 SkRecorder recorder(&record, W, H); |
| 134 recorder.save(); | 133 recorder.save(); |
| 135 recorder.clipRect(SkRect::MakeWH(400, 500)); | 134 recorder.clipRect(SkRect::MakeWH(400, 500)); |
| 136 recorder.scale(2, 2); | 135 recorder.scale(2, 2); |
| 137 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); | 136 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); |
| 138 recorder.restore(); | 137 recorder.restore(); |
| 139 | 138 |
| 140 TestBBH bbh; | 139 TestBBH bbh; |
| 141 SkRecordFillBounds(record, &bbh); | 140 SkRecordFillBounds(record, &bbh); |
| 142 | 141 |
| 143 REPORTER_ASSERT(r, bbh.entries.count() == 5); | 142 REPORTER_ASSERT(r, bbh.entries.count() == 5); |
| 144 for (int i = 0; i < bbh.entries.count(); i++) { | 143 for (int i = 0; i < bbh.entries.count(); i++) { |
| 145 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); | 144 REPORTER_ASSERT(r, bbh.entries[i].data == (unsigned)i); |
| 146 | 145 |
| 147 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.entries[ i].bounds)); | 146 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.entries[ i].bounds)); |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 | 149 |
| 151 // A regression test for crbug.com/409110. | 150 // A regression test for crbug.com/409110. |
| 152 DEF_TEST(RecordDraw_TextBounds, r) { | 151 DEF_TEST(RecordDraw_TextBounds, r) { |
| 153 SkRecord record; | 152 SkRecord record; |
| 154 SkRecorder recorder(&record, W, H); | 153 SkRecorder recorder(&record, W, H); |
| 155 | 154 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too. | 250 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too. |
| 252 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). | 251 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). |
| 253 TestBBH bbh; | 252 TestBBH bbh; |
| 254 SkRecordFillBounds(record, &bbh); | 253 SkRecordFillBounds(record, &bbh); |
| 255 REPORTER_ASSERT(r, bbh.entries.count() == 4); | 254 REPORTER_ASSERT(r, bbh.entries.count() == 4); |
| 256 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); | 255 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); |
| 257 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); | 256 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); |
| 258 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[2].bounds, SkRect::MakeLTRB(0, 0, 40, 40))); | 257 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[2].bounds, SkRect::MakeLTRB(0, 0, 40, 40))); |
| 259 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); | 258 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); |
| 260 } | 259 } |
| OLD | NEW |