OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 replayCanvas.flush(); | 1241 replayCanvas.flush(); |
1242 | 1242 |
1243 // With the bug present, at (55, 55) we would get a fully opaque red | 1243 // With the bug present, at (55, 55) we would get a fully opaque red |
1244 // intead of a dark red. | 1244 // intead of a dark red. |
1245 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); | 1245 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); |
1246 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); | 1246 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); |
1247 } | 1247 } |
1248 | 1248 |
1249 struct CountingBBH : public SkBBoxHierarchy { | 1249 struct CountingBBH : public SkBBoxHierarchy { |
1250 mutable int searchCalls; | 1250 mutable int searchCalls; |
1251 SkRect rootBound; | |
1252 | 1251 |
1253 CountingBBH(const SkRect& bound) : searchCalls(0), rootBound(bound) {} | 1252 CountingBBH() : searchCalls(0) {} |
1254 | 1253 |
1255 void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVER
RIDE { | 1254 void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVER
RIDE { |
1256 this->searchCalls++; | 1255 this->searchCalls++; |
1257 } | 1256 } |
1258 | 1257 |
1259 void insert(const SkRect[], int) SK_OVERRIDE {} | 1258 void insert(const SkRect[], int) SK_OVERRIDE {} |
1260 virtual size_t bytesUsed() const SK_OVERRIDE { return 0; } | 1259 virtual size_t bytesUsed() const SK_OVERRIDE { return 0; } |
1261 SkRect getRootBound() const SK_OVERRIDE { return rootBound; } | |
1262 }; | 1260 }; |
1263 | 1261 |
1264 class SpoonFedBBHFactory : public SkBBHFactory { | 1262 class SpoonFedBBHFactory : public SkBBHFactory { |
1265 public: | 1263 public: |
1266 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} | 1264 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} |
1267 SkBBoxHierarchy* operator()(const SkRect&) const SK_OVERRIDE { | 1265 SkBBoxHierarchy* operator()(const SkRect&) const SK_OVERRIDE { |
1268 return SkRef(fBBH); | 1266 return SkRef(fBBH); |
1269 } | 1267 } |
1270 private: | 1268 private: |
1271 SkBBoxHierarchy* fBBH; | 1269 SkBBoxHierarchy* fBBH; |
1272 }; | 1270 }; |
1273 | 1271 |
1274 // When the canvas clip covers the full picture, we don't need to call the BBH. | 1272 // When the canvas clip covers the full picture, we don't need to call the BBH. |
1275 DEF_TEST(Picture_SkipBBH, r) { | 1273 DEF_TEST(Picture_SkipBBH, r) { |
1276 SkRect bound = SkRect::MakeWH(320, 240); | 1274 CountingBBH bbh; |
1277 CountingBBH bbh(bound); | |
1278 SpoonFedBBHFactory factory(&bbh); | 1275 SpoonFedBBHFactory factory(&bbh); |
1279 | 1276 |
1280 SkPictureRecorder recorder; | 1277 SkPictureRecorder recorder; |
1281 recorder.beginRecording(bound, &factory); | 1278 recorder.beginRecording(320, 240, &factory); |
1282 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1279 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
1283 | 1280 |
1284 SkCanvas big(640, 480), small(300, 200); | 1281 SkCanvas big(640, 480), small(300, 200); |
1285 | 1282 |
1286 picture->playback(&big); | 1283 picture->playback(&big); |
1287 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1284 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
1288 | 1285 |
1289 picture->playback(&small); | 1286 picture->playback(&small); |
1290 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1287 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
1291 } | 1288 } |
(...skipping 23 matching lines...) Expand all Loading... |
1315 | 1312 |
1316 // The picture shares the immutable pixels but copies the mutable ones. | 1313 // The picture shares the immutable pixels but copies the mutable ones. |
1317 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1314 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1318 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1315 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1319 | 1316 |
1320 // When the picture goes away, it's just our bitmaps holding the refs. | 1317 // When the picture goes away, it's just our bitmaps holding the refs. |
1321 pic.reset(NULL); | 1318 pic.reset(NULL); |
1322 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1319 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1323 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1320 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1324 } | 1321 } |
OLD | NEW |