| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); | 119 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
| 120 SkMatrix expected = scale; | 120 SkMatrix expected = scale; |
| 121 expected.postConcat(translate); | 121 expected.postConcat(translate); |
| 122 REPORTER_ASSERT(r, setMatrix->matrix == expected); | 122 REPORTER_ASSERT(r, setMatrix->matrix == expected); |
| 123 } | 123 } |
| 124 | 124 |
| 125 struct TestBBH : public SkBBoxHierarchy { | 125 struct TestBBH : public SkBBoxHierarchy { |
| 126 void insert(const SkRect boundsArray[], int N) override { | 126 void insert(const SkRect boundsArray[], int N) override { |
| 127 fEntries.setCount(N); | 127 fEntries.setCount(N); |
| 128 for (int i = 0; i < N; i++) { | 128 for (int i = 0; i < N; i++) { |
| 129 Entry e = { (unsigned)i, boundsArray[i] }; | 129 Entry e = { i, boundsArray[i] }; |
| 130 fEntries[i] = e; | 130 fEntries[i] = e; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 void search(const SkRect& query, SkTDArray<unsigned>* results) const overrid
e {} | 134 void search(const SkRect& query, SkTDArray<int>* results) const override {} |
| 135 size_t bytesUsed() const override { return 0; } | 135 size_t bytesUsed() const override { return 0; } |
| 136 SkRect getRootBound() const override { return SkRect::MakeEmpty(); } | 136 SkRect getRootBound() const override { return SkRect::MakeEmpty(); } |
| 137 | 137 |
| 138 struct Entry { | 138 struct Entry { |
| 139 unsigned opIndex; | 139 int opIndex; |
| 140 SkRect bounds; | 140 SkRect bounds; |
| 141 }; | 141 }; |
| 142 SkTDArray<Entry> fEntries; | 142 SkTDArray<Entry> fEntries; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 // Like a==b, with a little slop recognizing that float equality can be weird. | 145 // Like a==b, with a little slop recognizing that float equality can be weird. |
| 146 static bool sloppy_rect_eq(SkRect a, SkRect b) { | 146 static bool sloppy_rect_eq(SkRect a, SkRect b) { |
| 147 SkRect inset(a), outset(a); | 147 SkRect inset(a), outset(a); |
| 148 inset.inset(1, 1); | 148 inset.inset(1, 1); |
| 149 outset.outset(1, 1); | 149 outset.outset(1, 1); |
| 150 return outset.contains(b) && !inset.contains(b); | 150 return outset.contains(b) && !inset.contains(b); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // This test is not meant to make total sense yet. It's testing the status quo | 153 // This test is not meant to make total sense yet. It's testing the status quo |
| 154 // of SkRecordFillBounds(), which itself doesn't make total sense yet. | 154 // of SkRecordFillBounds(), which itself doesn't make total sense yet. |
| 155 DEF_TEST(RecordDraw_BBH, r) { | 155 DEF_TEST(RecordDraw_BBH, r) { |
| 156 SkRecord record; | 156 SkRecord record; |
| 157 SkRecorder recorder(&record, W, H); | 157 SkRecorder recorder(&record, W, H); |
| 158 recorder.save(); | 158 recorder.save(); |
| 159 recorder.clipRect(SkRect::MakeWH(400, 500)); | 159 recorder.clipRect(SkRect::MakeWH(400, 500)); |
| 160 recorder.scale(2, 2); | 160 recorder.scale(2, 2); |
| 161 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); | 161 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); |
| 162 recorder.restore(); | 162 recorder.restore(); |
| 163 | 163 |
| 164 TestBBH bbh; | 164 TestBBH bbh; |
| 165 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor
d, &bbh); | 165 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor
d, &bbh); |
| 166 | 166 |
| 167 REPORTER_ASSERT(r, bbh.fEntries.count() == 5); | 167 REPORTER_ASSERT(r, bbh.fEntries.count() == 5); |
| 168 for (int i = 0; i < bbh.fEntries.count(); i++) { | 168 for (int i = 0; i < bbh.fEntries.count(); i++) { |
| 169 REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == (unsigned)i); | 169 REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == i); |
| 170 | 170 |
| 171 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries
[i].bounds)); | 171 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries
[i].bounds)); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 // A regression test for crbug.com/409110. | 175 // A regression test for crbug.com/409110. |
| 176 DEF_TEST(RecordDraw_TextBounds, r) { | 176 DEF_TEST(RecordDraw_TextBounds, r) { |
| 177 SkRecord record; | 177 SkRecord record; |
| 178 SkRecorder recorder(&record, W, H); | 178 SkRecorder recorder(&record, W, H); |
| 179 | 179 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 { | 325 { |
| 326 SkRecord record; | 326 SkRecord record; |
| 327 SkRecorder recorder(&record, 10, 10); | 327 SkRecorder recorder(&record, 10, 10); |
| 328 recorder.drawImageRect(image, SkRect::MakeWH(10, 10), nullptr); | 328 recorder.drawImageRect(image, SkRect::MakeWH(10, 10), nullptr); |
| 329 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); | 329 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); |
| 330 } | 330 } |
| 331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); | 331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); |
| 332 | 332 |
| 333 } | 333 } |
| OLD | NEW |