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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 REPORTER_ASSERT(r, bbh.entries.count() == 5); | 136 REPORTER_ASSERT(r, bbh.entries.count() == 5); |
137 for (int i = 0; i < bbh.entries.count(); i++) { | 137 for (int i = 0; i < bbh.entries.count(); i++) { |
138 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); | 138 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); |
139 | 139 |
140 // We'd like to assert bounds == SkRect::MakeWH(400, 480). | 140 // We'd like to assert bounds == SkRect::MakeWH(400, 480). |
141 // But we allow a little slop in recognition that float equality can be
weird. | 141 // But we allow a little slop in recognition that float equality can be
weird. |
142 REPORTER_ASSERT(r, SkRect::MakeLTRB(-1, -1, 401, 481).contains(bbh.entr
ies[i].bounds)); | 142 REPORTER_ASSERT(r, SkRect::MakeLTRB(-1, -1, 401, 481).contains(bbh.entr
ies[i].bounds)); |
143 REPORTER_ASSERT(r, !SkRect::MakeLTRB(+1, +1, 399, 479).contains(bbh.entr
ies[i].bounds)); | 143 REPORTER_ASSERT(r, !SkRect::MakeLTRB(+1, +1, 399, 479).contains(bbh.entr
ies[i].bounds)); |
144 } | 144 } |
145 } | 145 } |
| 146 |
| 147 // Base test to ensure start/stop range is respected |
| 148 DEF_TEST(RecordDraw_PartialStartStop, r) { |
| 149 static const int kWidth = 10, kHeight = 10; |
| 150 |
| 151 SkRect r1 = { 0, 0, kWidth, kHeight }; |
| 152 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; |
| 153 SkRect r3 = { 0, 0, kWidth/2, kHeight }; |
| 154 SkPaint p; |
| 155 |
| 156 SkRecord record; |
| 157 SkRecorder recorder(&record, kWidth, kHeight); |
| 158 recorder.drawRect(r1, p); |
| 159 recorder.drawRect(r2, p); |
| 160 recorder.drawRect(r3, p); |
| 161 |
| 162 SkRecord rerecord; |
| 163 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 164 SkRecordPartialDraw(record, &canvas, r1, 1, 2); // replay just drawRect of r
2 |
| 165 |
| 166 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 167 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 168 assert_type<SkRecords::DrawRect> (r, rerecord, 1); |
| 169 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 170 |
| 171 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, 1); |
| 172 REPORTER_ASSERT(r, drawRect->rect == r2); |
| 173 } |
| 174 |
| 175 // Check that clears are converted to drawRects |
| 176 DEF_TEST(RecordDraw_PartialClear, r) { |
| 177 static const int kWidth = 10, kHeight = 10; |
| 178 |
| 179 SkRect rect = { 0, 0, kWidth, kHeight }; |
| 180 |
| 181 SkRecord record; |
| 182 SkRecorder recorder(&record, kWidth, kHeight); |
| 183 recorder.clear(SK_ColorRED); |
| 184 |
| 185 SkRecord rerecord; |
| 186 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 187 SkRecordPartialDraw(record, &canvas, rect, 0, 1); // replay just the clear |
| 188 |
| 189 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 190 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 191 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
| 192 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 193 |
| 194 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, 1); |
| 195 REPORTER_ASSERT(r, drawRect->rect == rect); |
| 196 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED); |
| 197 } |
OLD | NEW |