| 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 opIndex, const SkRect& bounds, bool defer) SK_O
VERRIDE { |
| 102 Entry e = { (uintptr_t)data, bounds }; | 102 Entry e = { opIndex, bounds }; |
| 103 entries.push(e); | 103 fEntries.push(e); |
| 104 } | 104 } |
| 105 virtual int getCount() const SK_OVERRIDE { return entries.count(); } | 105 virtual int getCount() const SK_OVERRIDE { return fEntries.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 opIndex; |
| 116 SkRect bounds; | 115 SkRect bounds; |
| 117 }; | 116 }; |
| 118 SkTDArray<Entry> entries; | 117 SkTDArray<Entry> fEntries; |
| 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.fEntries.count() == 5); |
| 144 for (int i = 0; i < bbh.entries.count(); i++) { | 143 for (int i = 0; i < bbh.fEntries.count(); i++) { |
| 145 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); | 144 REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == (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.fEntries
[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 |
| 156 // Two Chinese characters in UTF-8. | 155 // Two Chinese characters in UTF-8. |
| 157 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' }; | 156 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' }; |
| 158 const size_t bytes = SK_ARRAY_COUNT(text); | 157 const size_t bytes = SK_ARRAY_COUNT(text); |
| 159 | 158 |
| 160 const SkScalar xpos[] = { 10, 20 }; | 159 const SkScalar xpos[] = { 10, 20 }; |
| 161 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint()); | 160 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint()); |
| 162 | 161 |
| 163 const SkPoint pos[] = { {40, 50}, {60, 70} }; | 162 const SkPoint pos[] = { {40, 50}, {60, 70} }; |
| 164 recorder.drawPosText(text, bytes, pos, SkPaint()); | 163 recorder.drawPosText(text, bytes, pos, SkPaint()); |
| 165 | 164 |
| 166 TestBBH bbh; | 165 TestBBH bbh; |
| 167 SkRecordFillBounds(record, &bbh); | 166 SkRecordFillBounds(record, &bbh); |
| 168 REPORTER_ASSERT(r, bbh.entries.count() == 2); | 167 REPORTER_ASSERT(r, bbh.fEntries.count() == 2); |
| 169 | 168 |
| 170 // We can make these next assertions confidently because SkRecordFillBounds | 169 // We can make these next assertions confidently because SkRecordFillBounds |
| 171 // builds its bounds by overestimating font metrics in a platform-independen
t way. | 170 // builds its bounds by overestimating font metrics in a platform-independen
t way. |
| 172 // If that changes, these tests will need to be more flexible. | 171 // If that changes, these tests will need to be more flexible. |
| 173 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(-8
6, 6, 116, 54))); | 172 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(-
86, 6, 116, 54))); |
| 174 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(-5
6, 26, 156, 94))); | 173 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(-
56, 26, 156, 94))); |
| 175 } | 174 } |
| 176 | 175 |
| 177 // Base test to ensure start/stop range is respected | 176 // Base test to ensure start/stop range is respected |
| 178 DEF_TEST(RecordDraw_PartialStartStop, r) { | 177 DEF_TEST(RecordDraw_PartialStartStop, r) { |
| 179 static const int kWidth = 10, kHeight = 10; | 178 static const int kWidth = 10, kHeight = 10; |
| 180 | 179 |
| 181 SkRect r1 = { 0, 0, kWidth, kHeight }; | 180 SkRect r1 = { 0, 0, kWidth, kHeight }; |
| 182 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; | 181 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; |
| 183 SkRect r3 = { 0, 0, kWidth/2, kHeight }; | 182 SkRect r3 = { 0, 0, kWidth/2, kHeight }; |
| 184 SkPaint p; | 183 SkPaint p; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); | 244 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); |
| 246 recorder.restore(); | 245 recorder.restore(); |
| 247 | 246 |
| 248 // Under the original bug, the right edge value of the drawRect would be 20
less than asserted | 247 // Under the original bug, the right edge value of the drawRect would be 20
less than asserted |
| 249 // here because we intersected it with a clip that had not been adjusted for
the drop shadow. | 248 // here because we intersected it with a clip that had not been adjusted for
the drop shadow. |
| 250 // | 249 // |
| 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.fEntries.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.fEntries[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.fEntries[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.fEntries[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.fEntries[3].bounds, SkRect::MakeLTRB(0
, 0, 50, 50))); |
| 260 } | 259 } |
| OLD | NEW |