Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: cc/playback/picture_pile_impl_unittest.cc

Issue 1318733006: cc: Do the math for a tile's content rect in layer space once. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "cc/test/fake_picture_pile_impl.h" 6 #include "cc/test/fake_picture_pile_impl.h"
7 #include "cc/test/skia_common.h" 7 #include "cc/test/skia_common.h"
8 #include "skia/ext/refptr.h" 8 #include "skia/ext/refptr.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkPixelRef.h" 10 #include "third_party/skia/include/core/SkPixelRef.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 recording_source->add_draw_bitmap(discardable_bitmap[1][1], 183 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
184 gfx::Point(260, 260)); 184 gfx::Point(260, 260));
185 recording_source->SetGatherPixelRefs(true); 185 recording_source->SetGatherPixelRefs(true);
186 recording_source->Rerecord(); 186 recording_source->Rerecord();
187 187
188 scoped_refptr<FakePicturePileImpl> pile = 188 scoped_refptr<FakePicturePileImpl> pile =
189 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 189 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
190 190
191 // Tile sized iterators. These should find only one pixel ref. 191 // Tile sized iterators. These should find only one pixel ref.
192 { 192 {
193 PicturePileImpl::PixelRefIterator iterator( 193 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256),
194 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); 194 pile.get());
195 EXPECT_TRUE(iterator); 195 EXPECT_TRUE(iterator);
196 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef()); 196 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
197 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), 197 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
198 gfx::RectF(32, 32).ToString());
199 EXPECT_FALSE(++iterator);
200 }
201 {
202 PicturePileImpl::PixelRefIterator iterator(
203 gfx::Rect(0, 0, 512, 512), 2.0, pile.get());
204 EXPECT_TRUE(iterator);
205 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
206 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
207 gfx::RectF(32, 32).ToString());
208 EXPECT_FALSE(++iterator);
209 }
210 {
211 PicturePileImpl::PixelRefIterator iterator(
212 gfx::Rect(0, 0, 128, 128), 0.5, pile.get());
213 EXPECT_TRUE(iterator);
214 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
215 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
216 gfx::RectF(32, 32).ToString()); 198 gfx::RectF(32, 32).ToString());
217 EXPECT_FALSE(++iterator); 199 EXPECT_FALSE(++iterator);
218 } 200 }
219 // Shifted tile sized iterators. These should find only one pixel ref. 201 // Shifted tile sized iterators. These should find only one pixel ref.
220 { 202 {
221 PicturePileImpl::PixelRefIterator iterator( 203 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(260, 260, 256, 256),
222 gfx::Rect(260, 260, 256, 256), 1.0, pile.get()); 204 pile.get());
223 EXPECT_TRUE(iterator); 205 EXPECT_TRUE(iterator);
224 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef()); 206 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef());
225 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), 207 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
226 gfx::RectF(260, 260, 32, 32).ToString());
227 EXPECT_FALSE(++iterator);
228 }
229 {
230 PicturePileImpl::PixelRefIterator iterator(
231 gfx::Rect(520, 520, 512, 512), 2.0, pile.get());
232 EXPECT_TRUE(iterator);
233 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef());
234 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
235 gfx::RectF(260, 260, 32, 32).ToString());
236 EXPECT_FALSE(++iterator);
237 }
238 {
239 PicturePileImpl::PixelRefIterator iterator(
240 gfx::Rect(130, 130, 128, 128), 0.5, pile.get());
241 EXPECT_TRUE(iterator);
242 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef());
243 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
244 gfx::RectF(260, 260, 32, 32).ToString()); 208 gfx::RectF(260, 260, 32, 32).ToString());
245 EXPECT_FALSE(++iterator); 209 EXPECT_FALSE(++iterator);
246 } 210 }
247 // Ensure there's no discardable pixel refs in the empty cell 211 // Ensure there's no discardable pixel refs in the empty cell
248 { 212 {
249 PicturePileImpl::PixelRefIterator iterator( 213 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 256, 256, 256),
250 gfx::Rect(0, 256, 256, 256), 1.0, pile.get()); 214 pile.get());
251 EXPECT_FALSE(iterator); 215 EXPECT_FALSE(iterator);
252 } 216 }
253 // Layer sized iterators. These should find three pixel ref. 217 // Layer sized iterators. These should find three pixel ref.
254 { 218 {
255 PicturePileImpl::PixelRefIterator iterator( 219 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512),
256 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); 220 pile.get());
257 EXPECT_TRUE(iterator); 221 EXPECT_TRUE(iterator);
258 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef()); 222 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
259 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), 223 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
260 gfx::RectF(32, 32).ToString());
261 EXPECT_TRUE(++iterator);
262 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef());
263 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
264 gfx::RectF(260, 0, 32, 32).ToString());
265 EXPECT_TRUE(++iterator);
266 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef());
267 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
268 gfx::RectF(260, 260, 32, 32).ToString());
269 EXPECT_FALSE(++iterator);
270 }
271 {
272 PicturePileImpl::PixelRefIterator iterator(
273 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get());
274 EXPECT_TRUE(iterator);
275 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
276 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
277 gfx::RectF(32, 32).ToString()); 224 gfx::RectF(32, 32).ToString());
278 EXPECT_TRUE(++iterator); 225 EXPECT_TRUE(++iterator);
279 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef()); 226 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef());
280 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), 227 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
281 gfx::RectF(260, 0, 32, 32).ToString()); 228 gfx::RectF(260, 0, 32, 32).ToString());
282 EXPECT_TRUE(++iterator); 229 EXPECT_TRUE(++iterator);
283 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef()); 230 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef());
284 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), 231 EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(),
285 gfx::RectF(260, 260, 32, 32).ToString()); 232 gfx::RectF(260, 260, 32, 32).ToString());
286 EXPECT_FALSE(++iterator); 233 EXPECT_FALSE(++iterator);
287 } 234 }
288 {
289 PicturePileImpl::PixelRefIterator iterator(
290 gfx::Rect(0, 0, 256, 256), 0.5, pile.get());
291 EXPECT_TRUE(iterator);
292 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
293 EXPECT_EQ(gfx::RectF(32, 32).ToString(),
294 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
295 EXPECT_TRUE(++iterator);
296 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef());
297 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(),
298 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
299 EXPECT_TRUE(++iterator);
300 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef());
301 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(),
302 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
303 EXPECT_FALSE(++iterator);
304 }
305 235
306 { 236 {
307 // Copy test. 237 // Copy test.
308 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), 1.0, 238 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512),
309 pile.get()); 239 pile.get());
310 EXPECT_TRUE(iterator); 240 EXPECT_TRUE(iterator);
311 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef()); 241 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef());
312 EXPECT_EQ(gfx::RectF(32, 32).ToString(), 242 EXPECT_EQ(gfx::RectF(32, 32).ToString(),
313 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 243 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
314 EXPECT_TRUE(++iterator); 244 EXPECT_TRUE(++iterator);
315 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef()); 245 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef());
316 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), 246 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(),
317 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 247 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
318 248
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 bitmap_rects[1].Intersects(pile->tiling().TileBoundsWithBorder(2, 0))); 483 bitmap_rects[1].Intersects(pile->tiling().TileBoundsWithBorder(2, 0)));
554 EXPECT_FALSE(bitmap_rects[1].Intersects(pile->tiling().TileBounds(2, 0))); 484 EXPECT_FALSE(bitmap_rects[1].Intersects(pile->tiling().TileBounds(2, 0)));
555 EXPECT_TRUE( 485 EXPECT_TRUE(
556 bitmap_rects[2].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); 486 bitmap_rects[2].Intersects(pile->tiling().TileBoundsWithBorder(1, 0)));
557 EXPECT_FALSE(bitmap_rects[2].Intersects(pile->tiling().TileBounds(1, 0))); 487 EXPECT_FALSE(bitmap_rects[2].Intersects(pile->tiling().TileBounds(1, 0)));
558 488
559 // Tile-sized iterators. 489 // Tile-sized iterators.
560 { 490 {
561 // Because tile 0's borders extend onto tile 1, it will include both 491 // Because tile 0's borders extend onto tile 1, it will include both
562 // bitmap 0 and 1. However, it should *not* include bitmap 2. 492 // bitmap 0 and 1. However, it should *not* include bitmap 2.
563 PicturePileImpl::PixelRefIterator iterator( 493 PicturePileImpl::PixelRefIterator iterator(pile->tiling().TileBounds(0, 0),
564 pile->tiling().TileBounds(0, 0), 1.f, pile.get()); 494 pile.get());
565 EXPECT_TRUE(iterator); 495 EXPECT_TRUE(iterator);
566 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0].pixelRef()); 496 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0].pixelRef());
567 EXPECT_EQ(expected_rects[0].ToString(), 497 EXPECT_EQ(expected_rects[0].ToString(),
568 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 498 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
569 EXPECT_TRUE(++iterator); 499 EXPECT_TRUE(++iterator);
570 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef()); 500 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef());
571 EXPECT_EQ(expected_rects[1].ToString(), 501 EXPECT_EQ(expected_rects[1].ToString(),
572 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 502 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
573 EXPECT_FALSE(++iterator); 503 EXPECT_FALSE(++iterator);
574 } 504 }
575 { 505 {
576 // Tile 1 + borders hits all bitmaps. 506 // Tile 1 + borders hits all bitmaps.
577 PicturePileImpl::PixelRefIterator iterator( 507 PicturePileImpl::PixelRefIterator iterator(pile->tiling().TileBounds(1, 0),
578 pile->tiling().TileBounds(1, 0), 1.f, pile.get()); 508 pile.get());
579 EXPECT_TRUE(iterator); 509 EXPECT_TRUE(iterator);
580 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0].pixelRef()); 510 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0].pixelRef());
581 EXPECT_EQ(expected_rects[0].ToString(), 511 EXPECT_EQ(expected_rects[0].ToString(),
582 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 512 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
583 EXPECT_TRUE(++iterator); 513 EXPECT_TRUE(++iterator);
584 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef()); 514 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef());
585 EXPECT_EQ(expected_rects[1].ToString(), 515 EXPECT_EQ(expected_rects[1].ToString(),
586 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 516 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
587 EXPECT_TRUE(++iterator); 517 EXPECT_TRUE(++iterator);
588 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2].pixelRef()); 518 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2].pixelRef());
589 EXPECT_EQ(expected_rects[2].ToString(), 519 EXPECT_EQ(expected_rects[2].ToString(),
590 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 520 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
591 EXPECT_FALSE(++iterator); 521 EXPECT_FALSE(++iterator);
592 } 522 }
593 { 523 {
594 // Tile 2 should not include bitmap 0, which is only on tile 0 and the 524 // Tile 2 should not include bitmap 0, which is only on tile 0 and the
595 // borders of tile 1. 525 // borders of tile 1.
596 PicturePileImpl::PixelRefIterator iterator( 526 PicturePileImpl::PixelRefIterator iterator(pile->tiling().TileBounds(2, 0),
597 pile->tiling().TileBounds(2, 0), 1.f, pile.get()); 527 pile.get());
598 EXPECT_TRUE(iterator); 528 EXPECT_TRUE(iterator);
599 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef()); 529 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef());
600 EXPECT_EQ(expected_rects[1].ToString(), 530 EXPECT_EQ(expected_rects[1].ToString(),
601 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 531 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
602 EXPECT_TRUE(++iterator); 532 EXPECT_TRUE(++iterator);
603 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2].pixelRef()); 533 EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2].pixelRef());
604 EXPECT_EQ(expected_rects[2].ToString(), 534 EXPECT_EQ(expected_rects[2].ToString(),
605 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); 535 gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString());
606 EXPECT_FALSE(++iterator); 536 EXPECT_FALSE(++iterator);
607 } 537 }
608 } 538 }
609 539
610 } // namespace 540 } // namespace
611 } // namespace cc 541 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698