Chromium Code Reviews| Index: cc/resources/display_list_recording_source_unittest.cc |
| diff --git a/cc/resources/display_list_recording_source_unittest.cc b/cc/resources/display_list_recording_source_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b7e7efe933c63f0967edb7c757ce9a88ff54a65 |
| --- /dev/null |
| +++ b/cc/resources/display_list_recording_source_unittest.cc |
| @@ -0,0 +1,624 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
vmpstr
2015/03/31 17:10:31
nit 2015
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <vector> |
| + |
| +#include "cc/resources/display_list_raster_source.h" |
| +#include "cc/resources/display_list_recording_source.h" |
| +#include "cc/test/fake_content_layer_client.h" |
| +#include "cc/test/impl_side_painting_settings.h" |
| +#include "cc/test/skia_common.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +// This class provides method for test to add bitmap and draw rect to content |
| +// layer client. This class also provides function to rerecord to generate a new |
| +// display list. |
| +class FakeDisplayListRecordingSource : public DisplayListRecordingSource { |
| + public: |
| + explicit FakeDisplayListRecordingSource(const gfx::Size& grid_cell_size) |
| + : DisplayListRecordingSource(grid_cell_size) {} |
| + ~FakeDisplayListRecordingSource() override {} |
| + |
| + static scoped_ptr<FakeDisplayListRecordingSource> CreateRecordingSource( |
| + const gfx::Rect& recorded_viewport) { |
| + scoped_ptr<FakeDisplayListRecordingSource> recording_source( |
| + new FakeDisplayListRecordingSource( |
| + ImplSidePaintingSettings().default_tile_grid_size)); |
| + recording_source->SetRecordedViewport(recorded_viewport); |
| + return recording_source; |
| + } |
| + |
| + void SetRecordedViewport(const gfx::Rect& recorded_viewport) { |
| + recorded_viewport_ = recorded_viewport; |
| + } |
| + |
| + void SetGridCellSize(const gfx::Size& grid_cell_size) { |
| + grid_cell_size_ = grid_cell_size; |
| + } |
| + |
| + void RerecordDisplayList() { |
| + ContentLayerClient::PaintingControlSetting painting_control = |
| + ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; |
| + display_list_ = client_.PaintContentsToDisplayList(recorded_viewport_, |
| + painting_control); |
| + display_list_->set_layer_rect(recorded_viewport_); |
| + display_list_->CreateAndCacheSkPicture(); |
| + display_list_->GatherPixelRefs(grid_cell_size_); |
| + } |
| + |
| + void add_draw_rect(const gfx::RectF& rect) { |
| + client_.add_draw_rect(rect, default_paint_); |
| + } |
| + |
| + void add_draw_rect_with_paint(const gfx::RectF& rect, const SkPaint& paint) { |
| + client_.add_draw_rect(rect, paint); |
| + } |
| + |
| + void add_draw_bitmap(const SkBitmap& bitmap, const gfx::Point& point) { |
| + client_.add_draw_bitmap(bitmap, point, default_paint_); |
| + } |
| + |
| + void add_draw_bitmap_with_transform(const SkBitmap& bitmap, |
| + const gfx::Transform& transform) { |
| + client_.add_draw_bitmap_with_transform(bitmap, transform, default_paint_); |
| + } |
| + |
| + void add_draw_bitmap_with_paint(const SkBitmap& bitmap, |
| + const gfx::Point& point, |
| + const SkPaint& paint) { |
| + client_.add_draw_bitmap(bitmap, point, paint); |
| + } |
| + |
| + void add_draw_bitmap_with_paint_and_transform(const SkBitmap& bitmap, |
| + const gfx::Transform& transform, |
| + const SkPaint& paint) { |
| + client_.add_draw_bitmap_with_transform(bitmap, transform, paint); |
| + } |
| + |
| + void set_default_paint(const SkPaint& paint) { default_paint_ = paint; } |
| + |
| + private: |
| + FakeContentLayerClient client_; |
| + SkPaint default_paint_; |
| +}; |
| + |
| +TEST(DisplayListRecordingSourceTest, EmptyPixelRefs) { |
| + gfx::Size grid_cell_size(128, 128); |
| + gfx::Rect recorded_viewport(0, 0, 256, 256); |
| + |
| + scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
| + FakeDisplayListRecordingSource::CreateRecordingSource(recorded_viewport); |
| + recording_source->SetGridCellSize(grid_cell_size); |
| + recording_source->RerecordDisplayList(); |
| + |
| + bool can_use_lcd_text = true; |
| + scoped_refptr<DisplayListRasterSource> raster_source = |
| + DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| + recording_source.get(), can_use_lcd_text); |
| + |
| + // Tile sized iterators. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + // Shifted tile sized iterators. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0, |
| + &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0, |
| + &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + // Layer sized iterators. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| +} |
| + |
| +TEST(DisplayListRecordingSourceTest, NoDiscardablePixelRefs) { |
| + gfx::Size grid_cell_size(128, 128); |
| + gfx::Rect recorded_viewport(0, 0, 256, 256); |
| + |
| + scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
| + FakeDisplayListRecordingSource::CreateRecordingSource(recorded_viewport); |
| + recording_source->SetGridCellSize(grid_cell_size); |
| + SkPaint simple_paint; |
| + simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
| + |
| + SkBitmap non_discardable_bitmap; |
| + CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap); |
| + |
| + recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), |
| + simple_paint); |
| + recording_source->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), |
| + simple_paint); |
| + recording_source->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), |
| + simple_paint); |
| + recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), |
| + simple_paint); |
| + recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0)); |
| + recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128)); |
| + recording_source->add_draw_bitmap(non_discardable_bitmap, |
| + gfx::Point(150, 150)); |
| + recording_source->RerecordDisplayList(); |
| + |
| + bool can_use_lcd_text = true; |
| + scoped_refptr<DisplayListRasterSource> raster_source = |
| + DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| + recording_source.get(), can_use_lcd_text); |
| + |
| + // Tile sized iterators. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + // Shifted tile sized iterators. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0, |
| + &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0, |
| + &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + // Layer sized iterators. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| +} |
| + |
| +TEST(DisplayListRecordingSourceTest, DiscardablePixelRefs) { |
| + gfx::Size grid_cell_size(128, 128); |
| + gfx::Rect recorded_viewport(0, 0, 256, 256); |
| + |
| + scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
| + FakeDisplayListRecordingSource::CreateRecordingSource(recorded_viewport); |
| + recording_source->SetGridCellSize(grid_cell_size); |
| + SkBitmap discardable_bitmap[2][2]; |
| + CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
| + CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]); |
| + CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
| + |
| + // Discardable pixel refs are found in the following cells: |
| + // |---|---| |
| + // | x | | |
| + // |---|---| |
| + // | x | x | |
| + // |---|---| |
| + recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
| + recording_source->add_draw_bitmap(discardable_bitmap[1][0], |
| + gfx::Point(0, 130)); |
| + recording_source->add_draw_bitmap(discardable_bitmap[1][1], |
| + gfx::Point(140, 140)); |
| + recording_source->RerecordDisplayList(); |
| + |
| + bool can_use_lcd_text = true; |
| + scoped_refptr<DisplayListRasterSource> raster_source = |
| + DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| + recording_source.get(), can_use_lcd_text); |
| + |
| + // Tile sized iterators. These should find only one pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + |
| + // Shifted tile sized iterators. These should find only one pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + |
| + // Ensure there's no discardable pixel refs in the empty cell |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(140, 0, 128, 128), 1.0, |
| + &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + |
| + // Layer sized iterators. These should find all 3 pixel refs. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(3u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(3u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(3u, pixel_refs.size()); |
| + } |
| +} |
| + |
| +TEST(DisplayListRecordingSourceTest, DiscardablePixelRefsWithTransform) { |
| + gfx::Size grid_cell_size(128, 128); |
| + gfx::Rect recorded_viewport(0, 0, 256, 256); |
| + |
| + scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
| + FakeDisplayListRecordingSource::CreateRecordingSource(recorded_viewport); |
| + recording_source->SetGridCellSize(grid_cell_size); |
| + SkBitmap discardable_bitmap[2][2]; |
| + gfx::Transform identity_transform; |
| + CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
| + // Translate transform is equivalent to moving using point. |
| + gfx::Transform translate_transform; |
| + translate_transform.Translate(0, 130); |
| + CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]); |
| + // This moves the bitmap to center of viewport and rotate, this would make |
| + // this bitmap in all four tile grids. |
| + gfx::Transform rotate_transform; |
| + rotate_transform.Translate(112, 112); |
| + rotate_transform.Rotate(45); |
| + CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
| + |
| + recording_source->add_draw_bitmap_with_transform(discardable_bitmap[0][0], |
| + identity_transform); |
| + recording_source->add_draw_bitmap_with_transform(discardable_bitmap[1][0], |
| + translate_transform); |
| + recording_source->add_draw_bitmap_with_transform(discardable_bitmap[1][1], |
| + rotate_transform); |
| + recording_source->RerecordDisplayList(); |
| + |
| + bool can_use_lcd_text = true; |
| + scoped_refptr<DisplayListRasterSource> raster_source = |
| + DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| + recording_source.get(), can_use_lcd_text); |
| + |
| + // Tile sized iterators. These should find only one pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(2u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(2u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(2u, pixel_refs.size()); |
| + } |
| + |
| + // Shifted tile sized iterators. These should find only one pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + |
| + // The rotated bitmap would still be in the top right tile. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(140, 0, 128, 128), 1.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + |
| + // Layer sized iterators. These should find all 6 pixel refs, including 1 |
| + // pixel ref bitmap[0][0], 1 pixel ref for bitmap[1][0], and 4 pixel refs for |
| + // bitmap[1][1]. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + // Top left tile with bitmap[0][0] and bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][1].pixelRef()); |
| + // Top right tile with bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + // Bottom left tile with bitmap[1][0] and bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[3] == discardable_bitmap[1][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[4] == discardable_bitmap[1][1].pixelRef()); |
| + // Bottom right tile with bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[5] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(6u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + // Top left tile with bitmap[0][0] and bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][1].pixelRef()); |
| + // Top right tile with bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + // Bottom left tile with bitmap[1][0] and bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[3] == discardable_bitmap[1][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[4] == discardable_bitmap[1][1].pixelRef()); |
| + // Bottom right tile with bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[5] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(6u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + // Top left tile with bitmap[0][0] and bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][1].pixelRef()); |
| + // Top right tile with bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + // Bottom left tile with bitmap[1][0] and bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[3] == discardable_bitmap[1][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[4] == discardable_bitmap[1][1].pixelRef()); |
| + // Bottom right tile with bitmap[1][1]. |
| + EXPECT_TRUE(pixel_refs[5] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(6u, pixel_refs.size()); |
| + } |
| +} |
| + |
| +TEST(DisplayListRecordingSourceTest, DiscardablePixelRefsBaseNonDiscardable) { |
| + gfx::Size grid_cell_size(256, 256); |
| + gfx::Rect recorded_viewport(0, 0, 512, 512); |
| + |
| + scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
| + FakeDisplayListRecordingSource::CreateRecordingSource(recorded_viewport); |
| + recording_source->SetGridCellSize(grid_cell_size); |
| + SkBitmap non_discardable_bitmap; |
| + CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap); |
| + |
| + SkBitmap discardable_bitmap[2][2]; |
| + CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]); |
| + CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]); |
| + CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]); |
| + |
| + // One large non-discardable bitmap covers the whole grid. |
| + // Discardable pixel refs are found in the following cells: |
| + // |---|---| |
| + // | x | x | |
| + // |---|---| |
| + // | | x | |
| + // |---|---| |
| + recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0)); |
| + recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
| + recording_source->add_draw_bitmap(discardable_bitmap[0][1], |
| + gfx::Point(260, 0)); |
| + recording_source->add_draw_bitmap(discardable_bitmap[1][1], |
| + gfx::Point(260, 260)); |
| + recording_source->RerecordDisplayList(); |
| + |
| + bool can_use_lcd_text = true; |
| + scoped_refptr<DisplayListRasterSource> raster_source = |
| + DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| + recording_source.get(), can_use_lcd_text); |
| + |
| + // Tile sized iterators. These should find only one pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + // Shifted tile sized iterators. These should find only one pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), 1.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(520, 520, 512, 512), 2.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(130, 130, 128, 128), 0.5, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(1u, pixel_refs.size()); |
| + } |
| + // Ensure there's no discardable pixel refs in the empty cell |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), 1.0, |
| + &pixel_refs); |
| + EXPECT_TRUE(pixel_refs.empty()); |
| + } |
| + // Layer sized iterators. These should find three pixel ref. |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 1.0, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(3u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 1024, 1024), 2.0, |
| + &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(3u, pixel_refs.size()); |
| + } |
| + { |
| + std::vector<SkPixelRef*> pixel_refs; |
| + raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 0.5, &pixel_refs); |
| + EXPECT_FALSE(pixel_refs.empty()); |
| + EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef()); |
| + EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef()); |
| + EXPECT_EQ(3u, pixel_refs.size()); |
| + } |
| +} |
| + |
| +} // namespace |
| +} // namespace cc |