From ffe5781a8645d2fcb9f15a218aca4a3be5fe452c Mon Sep 17 00:00:00 2001 From: enne Date: Fri, 13 Feb 2015 18:37:20 -0800 Subject: cc: Make raster source members const Both PicturePileImpl and DisplayListRasterSource get used on multiple threads, so should not be mutable. Unfortunately, many tests try to mutate either the recordings or the state of PicturePileImpl, so they all need to be changed to touch the recording source and a bunch of state setters need to be moved from raster source to recording source. Review URL: https://codereview.chromium.org/930503002 Cr-Commit-Position: refs/heads/master@{#316364} --- cc/layers/picture_layer.cc | 7 +- cc/layers/picture_layer_impl_unittest.cc | 64 +++++--- cc/output/renderer_pixeltest.cc | 104 ++++++++----- cc/resources/display_list_raster_source.cc | 12 +- cc/resources/display_list_raster_source.h | 29 ++-- cc/resources/display_list_recording_source.cc | 10 ++ cc/resources/display_list_recording_source.h | 4 + cc/resources/picture_pile.cc | 17 ++ cc/resources/picture_pile.h | 5 + cc/resources/picture_pile_impl.cc | 33 +--- cc/resources/picture_pile_impl.h | 33 ++-- cc/resources/picture_pile_impl_unittest.cc | 213 ++++++++++++++++---------- cc/resources/raster_source.h | 3 - cc/resources/recording_source.h | 2 + cc/test/fake_picture_pile.cc | 89 +++++++++++ cc/test/fake_picture_pile.h | 44 ++++++ cc/test/fake_picture_pile_impl.cc | 119 +++----------- cc/test/fake_picture_pile_impl.h | 59 ++----- 18 files changed, 481 insertions(+), 366 deletions(-) (limited to 'cc') diff --git a/cc/layers/picture_layer.cc b/cc/layers/picture_layer.cc index 52288e9..0ca2ae7 100644 --- a/cc/layers/picture_layer.cc +++ b/cc/layers/picture_layer.cc @@ -71,9 +71,6 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { scoped_refptr raster_source = recording_source_->CreateRasterSource(); - raster_source->SetBackgoundColor(SafeOpaqueBackgroundColor()); - raster_source->SetRequiresClear(!contents_opaque() && - !client_->FillsBoundsCompletely()); layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_, nullptr); DCHECK(recording_invalidation_.IsEmpty()); @@ -123,6 +120,10 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue, return updated; } + recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); + recording_source_->SetRequiresClear(!contents_opaque() && + !client_->FillsBoundsCompletely()); + TRACE_EVENT1("cc", "PictureLayer::Update", "source_frame_number", layer_tree_host()->source_frame_number()); diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc index 51177c0..f00b2e4 100644 --- a/cc/layers/picture_layer_impl_unittest.cc +++ b/cc/layers/picture_layer_impl_unittest.cc @@ -332,8 +332,11 @@ TEST_F(PictureLayerImplTest, TileGridAlignment) { scoped_refptr pending_pile = FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); + + scoped_ptr active_recording = + FakePicturePile::CreateFilledPile(layer_size, layer_size); scoped_refptr active_pile = - FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); + FakePicturePileImpl::CreateFromPile(active_recording.get(), nullptr); SetupTrees(pending_pile, active_pile); @@ -347,18 +350,22 @@ TEST_F(PictureLayerImplTest, TileGridAlignment) { for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1); - active_pile->add_draw_rect(rect); + active_recording->add_draw_rect(rect); rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); } + // Force re-raster with newly injected content - active_pile->RemoveRecordingAt(0, 0); - active_pile->AddRecordingAt(0, 0); + active_recording->RemoveRecordingAt(0, 0); + active_recording->AddRecordingAt(0, 0); + + scoped_refptr updated_active_pile = + FakePicturePileImpl::CreateFromPile(active_recording.get(), nullptr); std::vector::const_iterator rect_iter = rects.begin(); for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { MockCanvas mock_canvas(1000, 1000); - active_pile->PlaybackToSharedCanvas(&mock_canvas, - (*tile_iter)->content_rect(), 1.0f); + updated_active_pile->PlaybackToSharedCanvas( + &mock_canvas, (*tile_iter)->content_rect(), 1.0f); // This test verifies that when drawing the contents of a specific tile // at content scale 1.0, the playback canvas never receives content from @@ -1631,13 +1638,14 @@ TEST_F(PictureLayerImplTest, SolidColorLayerHasVisibleFullCoverage) { gfx::Size layer_bounds(1500, 1500); gfx::Rect visible_rect(250, 250, 1000, 1000); + scoped_ptr empty_recording = + FakePicturePile::CreateEmptyPile(tile_size, layer_bounds); + empty_recording->SetIsSolidColor(true); + scoped_refptr pending_pile = - FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); + FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr); scoped_refptr active_pile = - FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); - - pending_pile->set_is_solid_color(true); - active_pile->set_is_solid_color(true); + FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr); SetupTrees(pending_pile, active_pile); @@ -1663,13 +1671,11 @@ TEST_F(PictureLayerImplTest, TileScalesWithSolidColorPile) { gfx::Size tile_size(host_impl_.settings().default_tile_size); scoped_refptr pending_pile = FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( - tile_size, layer_bounds); + tile_size, layer_bounds, false); scoped_refptr active_pile = FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( - tile_size, layer_bounds); + tile_size, layer_bounds, true); - pending_pile->set_is_solid_color(false); - active_pile->set_is_solid_color(true); SetupTrees(pending_pile, active_pile); // Solid color pile should not allow tilings at any scale. EXPECT_FALSE(active_layer_->CanHaveTilings()); @@ -2105,9 +2111,10 @@ TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { // tiles. This is attempting to simulate scrolling past the end of recorded // content on the active layer, where the recordings are so far away that // no tiles are created. + bool is_solid_color = false; scoped_refptr active_pile = FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( - tile_size, layer_bounds); + tile_size, layer_bounds, is_solid_color); SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region()); @@ -3030,10 +3037,13 @@ TEST_F(PictureLayerImplTest, TilingSetRasterQueueActiveTree) { } TEST_F(PictureLayerImplTest, TilingSetRasterQueueRequiredNoHighRes) { + scoped_ptr empty_recording = + FakePicturePile::CreateEmptyPile(gfx::Size(256, 256), + gfx::Size(1024, 1024)); + empty_recording->SetIsSolidColor(true); + scoped_refptr pending_pile = - FakePicturePileImpl::CreateEmptyPile(gfx::Size(256, 256), - gfx::Size(1024, 1024)); - pending_pile->set_is_solid_color(true); + FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr); SetupPendingTree(pending_pile); EXPECT_FALSE( @@ -3521,9 +3531,10 @@ TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { // tiles. This is attempting to simulate scrolling past the end of recorded // content on the active layer, where the recordings are so far away that // no tiles are created. + bool is_solid_color = false; scoped_refptr active_pile = FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( - tile_size, layer_bounds); + tile_size, layer_bounds, is_solid_color); SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region()); @@ -4819,12 +4830,15 @@ TEST_F(PictureLayerImplTest, CloneMissingRecordings) { scoped_refptr filled_pile = FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); - scoped_refptr partial_pile = - FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); - for (int i = 1; i < partial_pile->tiling().num_tiles_x(); ++i) { - for (int j = 1; j < partial_pile->tiling().num_tiles_y(); ++j) - partial_pile->AddRecordingAt(i, j); + + scoped_ptr partial_recording = + FakePicturePile::CreateEmptyPile(tile_size, layer_bounds); + for (int i = 1; i < partial_recording->tiling().num_tiles_x(); ++i) { + for (int j = 1; j < partial_recording->tiling().num_tiles_y(); ++j) + partial_recording->AddRecordingAt(i, j); } + scoped_refptr partial_pile = + FakePicturePileImpl::CreateFromPile(partial_recording.get(), nullptr); SetupPendingTreeWithFixedTileSize(filled_pile, tile_size, Region()); ActivateTree(); diff --git a/cc/output/renderer_pixeltest.cc b/cc/output/renderer_pixeltest.cc index d503cc4..36765ce 100644 --- a/cc/output/renderer_pixeltest.cc +++ b/cc/output/renderer_pixeltest.cc @@ -1843,15 +1843,19 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadIdentityScale) { // is red, which should not appear. gfx::Rect blue_rect(gfx::Size(100, 100)); gfx::Rect blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50)); - scoped_refptr blue_pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, blue_rect.size()); + + scoped_ptr blue_recording = + FakePicturePile::CreateFilledPile(pile_tile_size, blue_rect.size()); SkPaint red_paint; red_paint.setColor(SK_ColorRED); - blue_pile->add_draw_rect_with_paint(blue_rect, red_paint); + blue_recording->add_draw_rect_with_paint(blue_rect, red_paint); SkPaint blue_paint; blue_paint.setColor(SK_ColorBLUE); - blue_pile->add_draw_rect_with_paint(blue_clip_rect, blue_paint); - blue_pile->RerecordPile(); + blue_recording->add_draw_rect_with_paint(blue_clip_rect, blue_paint); + blue_recording->RerecordPile(); + + scoped_refptr blue_pile = + FakePicturePileImpl::CreateFromPile(blue_recording.get(), nullptr); gfx::Transform blue_content_to_target_transform; gfx::Vector2d offset(viewport.bottom_right() - blue_rect.bottom_right()); @@ -1873,12 +1877,14 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadIdentityScale) { 1.f, blue_pile.get()); // One viewport-filling green quad. - scoped_refptr green_pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + scoped_ptr green_recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); SkPaint green_paint; green_paint.setColor(SK_ColorGREEN); - green_pile->add_draw_rect_with_paint(viewport, green_paint); - green_pile->RerecordPile(); + green_recording->add_draw_rect_with_paint(viewport, green_paint); + green_recording->RerecordPile(); + scoped_refptr green_pile = + FakePicturePileImpl::CreateFromPile(green_recording.get(), nullptr); gfx::Transform green_content_to_target_transform; SharedQuadState* green_shared_state = CreateTestSharedQuadState( @@ -1913,12 +1919,14 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) { CreateTestRenderPass(id, viewport, transform_to_root); // One viewport-filling 0.5-opacity green quad. - scoped_refptr green_pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + scoped_ptr green_recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); SkPaint green_paint; green_paint.setColor(SK_ColorGREEN); - green_pile->add_draw_rect_with_paint(viewport, green_paint); - green_pile->RerecordPile(); + green_recording->add_draw_rect_with_paint(viewport, green_paint); + green_recording->RerecordPile(); + scoped_refptr green_pile = + FakePicturePileImpl::CreateFromPile(green_recording.get(), nullptr); gfx::Transform green_content_to_target_transform; SharedQuadState* green_shared_state = CreateTestSharedQuadState( @@ -1932,12 +1940,14 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) { texture_format, viewport, 1.f, green_pile.get()); // One viewport-filling white quad. - scoped_refptr white_pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + scoped_ptr white_recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); SkPaint white_paint; white_paint.setColor(SK_ColorWHITE); - white_pile->add_draw_rect_with_paint(viewport, white_paint); - white_pile->RerecordPile(); + white_recording->add_draw_rect_with_paint(viewport, white_paint); + white_recording->RerecordPile(); + scoped_refptr white_pile = + FakePicturePileImpl::CreateFromPile(white_recording.get(), nullptr); gfx::Transform white_content_to_target_transform; SharedQuadState* white_shared_state = CreateTestSharedQuadState( @@ -2001,12 +2011,14 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadDisableImageFiltering) { canvas.drawPoint(1, 1, SK_ColorGREEN); } - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + scoped_ptr recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); SkPaint paint; paint.setFilterLevel(SkPaint::kLow_FilterLevel); - pile->add_draw_bitmap_with_paint(bitmap, gfx::Point(), paint); - pile->RerecordPile(); + recording->add_draw_bitmap_with_paint(bitmap, gfx::Point(), paint); + recording->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording.get(), nullptr); gfx::Transform content_to_target_transform; SharedQuadState* shared_state = CreateTestSharedQuadState( @@ -2051,12 +2063,14 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadNearestNeighbor) { canvas.drawPoint(1, 1, SK_ColorGREEN); } - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + scoped_ptr recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); SkPaint paint; paint.setFilterLevel(SkPaint::kLow_FilterLevel); - pile->add_draw_bitmap_with_paint(bitmap, gfx::Point(), paint); - pile->RerecordPile(); + recording->add_draw_bitmap_with_paint(bitmap, gfx::Point(), paint); + recording->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording.get(), nullptr); gfx::Transform content_to_target_transform; SharedQuadState* shared_state = CreateTestSharedQuadState( @@ -2153,16 +2167,20 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadNonIdentityScale) { gfx::Transform green_content_to_target_transform; gfx::Rect green_rect1(gfx::Point(80, 0), gfx::Size(20, 100)); gfx::Rect green_rect2(gfx::Point(0, 80), gfx::Size(100, 20)); - scoped_refptr green_pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + + scoped_ptr green_recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); + SkPaint red_paint; red_paint.setColor(SK_ColorRED); - green_pile->add_draw_rect_with_paint(viewport, red_paint); + green_recording->add_draw_rect_with_paint(viewport, red_paint); SkPaint green_paint; green_paint.setColor(SK_ColorGREEN); - green_pile->add_draw_rect_with_paint(green_rect1, green_paint); - green_pile->add_draw_rect_with_paint(green_rect2, green_paint); - green_pile->RerecordPile(); + green_recording->add_draw_rect_with_paint(green_rect1, green_paint); + green_recording->add_draw_rect_with_paint(green_rect2, green_paint); + green_recording->RerecordPile(); + scoped_refptr green_pile = + FakePicturePileImpl::CreateFromPile(green_recording.get(), nullptr); SharedQuadState* top_right_green_shared_quad_state = CreateTestSharedQuadState( @@ -2217,20 +2235,22 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadNonIdentityScale) { blue_layer_rect1.Inset(inset, inset, inset, inset); blue_layer_rect2.Inset(inset, inset, inset, inset); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_rect.size()); + scoped_ptr recording = + FakePicturePile::CreateFilledPile(pile_tile_size, layer_rect.size()); Region outside(layer_rect); outside.Subtract(gfx::ToEnclosingRect(union_layer_rect)); for (Region::Iterator iter(outside); iter.has_rect(); iter.next()) { - pile->add_draw_rect_with_paint(iter.rect(), red_paint); + recording->add_draw_rect_with_paint(iter.rect(), red_paint); } SkPaint blue_paint; blue_paint.setColor(SK_ColorBLUE); - pile->add_draw_rect_with_paint(blue_layer_rect1, blue_paint); - pile->add_draw_rect_with_paint(blue_layer_rect2, blue_paint); - pile->RerecordPile(); + recording->add_draw_rect_with_paint(blue_layer_rect1, blue_paint); + recording->add_draw_rect_with_paint(blue_layer_rect2, blue_paint); + recording->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording.get(), nullptr); gfx::Rect content_rect( gfx::ScaleToEnclosingRect(layer_rect, contents_scale)); @@ -2441,12 +2461,14 @@ TEST_F(GLRendererPixelTest, PictureDrawQuadTexture4444) { CreateTestRenderPass(id, viewport, transform_to_root); // One viewport-filling blue quad - scoped_refptr blue_pile = - FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); + scoped_ptr blue_recording = + FakePicturePile::CreateFilledPile(pile_tile_size, viewport.size()); SkPaint blue_paint; blue_paint.setColor(SK_ColorBLUE); - blue_pile->add_draw_rect_with_paint(viewport, blue_paint); - blue_pile->RerecordPile(); + blue_recording->add_draw_rect_with_paint(viewport, blue_paint); + blue_recording->RerecordPile(); + scoped_refptr blue_pile = + FakePicturePileImpl::CreateFromPile(blue_recording.get(), nullptr); gfx::Transform blue_content_to_target_transform; SharedQuadState* blue_shared_state = CreateTestSharedQuadState( diff --git a/cc/resources/display_list_raster_source.cc b/cc/resources/display_list_raster_source.cc index e4cd6f3..4479a16 100644 --- a/cc/resources/display_list_raster_source.cc +++ b/cc/resources/display_list_raster_source.cc @@ -50,8 +50,8 @@ DisplayListRasterSource::DisplayListRasterSource() DisplayListRasterSource::DisplayListRasterSource( const DisplayListRecordingSource* other) : display_list_(other->display_list_), - background_color_(SK_ColorTRANSPARENT), - requires_clear_(true), + background_color_(other->background_color_), + requires_clear_(other->requires_clear_), can_use_lcd_text_(other->can_use_lcd_text_), is_solid_color_(other->is_solid_color_), solid_color_(other->solid_color_), @@ -178,14 +178,6 @@ void DisplayListRasterSource::SetShouldAttemptToUseDistanceFieldText() { should_attempt_to_use_distance_field_text_ = true; } -void DisplayListRasterSource::SetBackgoundColor(SkColor background_color) { - background_color_ = background_color; -} - -void DisplayListRasterSource::SetRequiresClear(bool requires_clear) { - requires_clear_ = requires_clear; -} - bool DisplayListRasterSource::ShouldAttemptToUseDistanceFieldText() const { return should_attempt_to_use_distance_field_text_; } diff --git a/cc/resources/display_list_raster_source.h b/cc/resources/display_list_raster_source.h index a8d58c4..f095231 100644 --- a/cc/resources/display_list_raster_source.h +++ b/cc/resources/display_list_raster_source.h @@ -46,8 +46,6 @@ class CC_EXPORT DisplayListRasterSource : public RasterSource { float contents_scale) const override; bool HasRecordings() const override; void SetShouldAttemptToUseDistanceFieldText() override; - void SetBackgoundColor(SkColor background_color) override; - void SetRequiresClear(bool requires_clear) override; bool ShouldAttemptToUseDistanceFieldText() const override; void DidBeginTracing() override; void AsValueInto(base::trace_event::TracedValue* array) const override; @@ -60,16 +58,21 @@ class CC_EXPORT DisplayListRasterSource : public RasterSource { explicit DisplayListRasterSource(const DisplayListRecordingSource* other); ~DisplayListRasterSource() override; - scoped_refptr display_list_; - SkColor background_color_; - bool requires_clear_; - bool can_use_lcd_text_; - bool is_solid_color_; - SkColor solid_color_; - gfx::Rect recorded_viewport_; - gfx::Size size_; - bool clear_canvas_with_debug_color_; - int slow_down_raster_scale_factor_for_debug_; + // These members are const as this raster source may be in use on another + // thread and so should not be touched after construction. + const scoped_refptr display_list_; + const SkColor background_color_; + const bool requires_clear_; + const bool can_use_lcd_text_; + const bool is_solid_color_; + const SkColor solid_color_; + const gfx::Rect recorded_viewport_; + const gfx::Size size_; + const bool clear_canvas_with_debug_color_; + const int slow_down_raster_scale_factor_for_debug_; + // TODO(enne/vmiura): this has a read/write race between raster and compositor + // threads with multi-threaded Ganesh. Make this const or remove it. + bool should_attempt_to_use_distance_field_text_; private: // Called when analyzing a tile. We can use AnalysisCanvas as @@ -84,8 +87,6 @@ class CC_EXPORT DisplayListRasterSource : public RasterSource { float contents_scale, bool is_analysis) const; - bool should_attempt_to_use_distance_field_text_; - DISALLOW_COPY_AND_ASSIGN(DisplayListRasterSource); }; diff --git a/cc/resources/display_list_recording_source.cc b/cc/resources/display_list_recording_source.cc index 9c63217..01a3bce 100644 --- a/cc/resources/display_list_recording_source.cc +++ b/cc/resources/display_list_recording_source.cc @@ -29,8 +29,10 @@ namespace cc { DisplayListRecordingSource::DisplayListRecordingSource() : slow_down_raster_scale_factor_for_debug_(0), can_use_lcd_text_(true), + requires_clear_(false), is_solid_color_(false), solid_color_(SK_ColorTRANSPARENT), + background_color_(SK_ColorTRANSPARENT), pixel_record_distance_(kPixelDistanceToRecord), is_suitable_for_gpu_rasterization_(true) { } @@ -134,6 +136,14 @@ void DisplayListRecordingSource::SetSlowdownRasterScaleFactor(int factor) { slow_down_raster_scale_factor_for_debug_ = factor; } +void DisplayListRecordingSource::SetBackgroundColor(SkColor background_color) { + background_color_ = background_color; +} + +void DisplayListRecordingSource::SetRequiresClear(bool requires_clear) { + requires_clear_ = requires_clear; +} + void DisplayListRecordingSource::SetUnsuitableForGpuRasterizationForTesting() { is_suitable_for_gpu_rasterization_ = false; } diff --git a/cc/resources/display_list_recording_source.h b/cc/resources/display_list_recording_source.h index 05e2ed7..21a24fb 100644 --- a/cc/resources/display_list_recording_source.h +++ b/cc/resources/display_list_recording_source.h @@ -29,6 +29,8 @@ class CC_EXPORT DisplayListRecordingSource : public RecordingSource { gfx::Size GetSize() const final; void SetEmptyBounds() override; void SetSlowdownRasterScaleFactor(int factor) override; + void SetBackgroundColor(SkColor background_color) override; + void SetRequiresClear(bool requires_clear) override; bool IsSuitableForGpuRasterization() const override; void SetUnsuitableForGpuRasterizationForTesting() override; gfx::Size GetTileGridSizeForTesting() const override; @@ -40,8 +42,10 @@ class CC_EXPORT DisplayListRecordingSource : public RecordingSource { gfx::Size size_; int slow_down_raster_scale_factor_for_debug_; bool can_use_lcd_text_; + bool requires_clear_; bool is_solid_color_; SkColor solid_color_; + SkColor background_color_; int pixel_record_distance_; scoped_refptr display_list_; diff --git a/cc/resources/picture_pile.cc b/cc/resources/picture_pile.cc index dcfe49e..7e94e18 100644 --- a/cc/resources/picture_pile.cc +++ b/cc/resources/picture_pile.cc @@ -152,6 +152,12 @@ void ClusterTiles(const std::vector& invalid_tiles, *record_rects = vertical_clustering; } +#ifdef NDEBUG +const bool kDefaultClearCanvasSetting = false; +#else +const bool kDefaultClearCanvasSetting = true; +#endif + } // namespace namespace cc { @@ -162,8 +168,11 @@ PicturePile::PicturePile(float min_contents_scale, slow_down_raster_scale_factor_for_debug_(0), can_use_lcd_text_(true), has_any_recordings_(false), + clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), + requires_clear_(true), is_solid_color_(false), solid_color_(SK_ColorTRANSPARENT), + background_color_(SK_ColorTRANSPARENT), pixel_record_distance_(kPixelDistanceToRecord), is_suitable_for_gpu_rasterization_(true) { tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); @@ -623,6 +632,14 @@ void PicturePile::SetSlowdownRasterScaleFactor(int factor) { slow_down_raster_scale_factor_for_debug_ = factor; } +void PicturePile::SetBackgroundColor(SkColor background_color) { + background_color_ = background_color; +} + +void PicturePile::SetRequiresClear(bool requires_clear) { + requires_clear_ = requires_clear; +} + bool PicturePile::IsSuitableForGpuRasterization() const { return is_suitable_for_gpu_rasterization_; } diff --git a/cc/resources/picture_pile.h b/cc/resources/picture_pile.h index 8000c42..2a9a3ce 100644 --- a/cc/resources/picture_pile.h +++ b/cc/resources/picture_pile.h @@ -34,6 +34,8 @@ class CC_EXPORT PicturePile : public RecordingSource { gfx::Size GetSize() const final; void SetEmptyBounds() override; void SetSlowdownRasterScaleFactor(int factor) override; + void SetBackgroundColor(SkColor background_color) override; + void SetRequiresClear(bool requires_clear) override; bool IsSuitableForGpuRasterization() const override; void SetUnsuitableForGpuRasterizationForTesting() override; gfx::Size GetTileGridSizeForTesting() const override; @@ -97,8 +99,11 @@ class CC_EXPORT PicturePile : public RecordingSource { // A hint about whether there are any recordings. This may be a false // positive. bool has_any_recordings_; + bool clear_canvas_with_debug_color_; + bool requires_clear_; bool is_solid_color_; SkColor solid_color_; + SkColor background_color_; int pixel_record_distance_; private: diff --git a/cc/resources/picture_pile_impl.cc b/cc/resources/picture_pile_impl.cc index 01c069b..d629888 100644 --- a/cc/resources/picture_pile_impl.cc +++ b/cc/resources/picture_pile_impl.cc @@ -16,16 +16,6 @@ #include "third_party/skia/include/core/SkPictureRecorder.h" #include "ui/gfx/geometry/rect_conversions.h" -namespace { - -#ifdef NDEBUG -const bool kDefaultClearCanvasSetting = false; -#else -const bool kDefaultClearCanvasSetting = true; -#endif - -} // namespace - namespace cc { scoped_refptr PicturePileImpl::CreateFromPicturePile( @@ -40,7 +30,7 @@ PicturePileImpl::PicturePileImpl() is_solid_color_(false), solid_color_(SK_ColorTRANSPARENT), has_any_recordings_(false), - clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), + clear_canvas_with_debug_color_(false), min_contents_scale_(0.f), slow_down_raster_scale_factor_for_debug_(0), should_attempt_to_use_distance_field_text_(false) { @@ -49,14 +39,14 @@ PicturePileImpl::PicturePileImpl() PicturePileImpl::PicturePileImpl(const PicturePile* other) : picture_map_(other->picture_map_), tiling_(other->tiling_), - background_color_(SK_ColorTRANSPARENT), - requires_clear_(true), + background_color_(other->background_color_), + requires_clear_(other->requires_clear_), can_use_lcd_text_(other->can_use_lcd_text_), is_solid_color_(other->is_solid_color_), solid_color_(other->solid_color_), recorded_viewport_(other->recorded_viewport_), has_any_recordings_(other->has_any_recordings_), - clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), + clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), min_contents_scale_(other->min_contents_scale_), slow_down_raster_scale_factor_for_debug_( other->slow_down_raster_scale_factor_for_debug_), @@ -88,7 +78,6 @@ void PicturePileImpl::PlaybackToCanvas(SkCanvas* canvas, RasterSourceHelper::PrepareForPlaybackToCanvas( canvas, canvas_rect, gfx::Rect(tiling_.tiling_size()), contents_scale, background_color_, clear_canvas_with_debug_color_, requires_clear_); - RasterCommon(canvas, NULL, canvas_rect, @@ -367,14 +356,6 @@ void PicturePileImpl::SetShouldAttemptToUseDistanceFieldText() { should_attempt_to_use_distance_field_text_ = true; } -void PicturePileImpl::SetBackgoundColor(SkColor background_color) { - background_color_ = background_color; -} - -void PicturePileImpl::SetRequiresClear(bool requires_clear) { - requires_clear_ = requires_clear; -} - bool PicturePileImpl::ShouldAttemptToUseDistanceFieldText() const { return should_attempt_to_use_distance_field_text_; } @@ -454,10 +435,8 @@ void PicturePileImpl::PixelRefIterator::AdvanceToTilePictureWithPixelRefs() { void PicturePileImpl::DidBeginTracing() { std::set processed_pictures; - for (PictureMap::iterator it = picture_map_.begin(); - it != picture_map_.end(); - ++it) { - const Picture* picture = it->second.GetPicture(); + for (const auto& map_pair : picture_map_) { + const Picture* picture = map_pair.second.GetPicture(); if (picture && (processed_pictures.count(picture) == 0)) { picture->EmitTraceSnapshot(); processed_pictures.insert(picture); diff --git a/cc/resources/picture_pile_impl.h b/cc/resources/picture_pile_impl.h index 6f76bc1..1f94cec 100644 --- a/cc/resources/picture_pile_impl.h +++ b/cc/resources/picture_pile_impl.h @@ -52,8 +52,6 @@ class CC_EXPORT PicturePileImpl : public RasterSource { bool CoversRect(const gfx::Rect& content_rect, float contents_scale) const override; void SetShouldAttemptToUseDistanceFieldText() override; - void SetBackgoundColor(SkColor background_color) override; - void SetRequiresClear(bool requires_clear) override; bool ShouldAttemptToUseDistanceFieldText() const override; gfx::Size GetSize() const override; bool IsSolidColor() const override; @@ -106,18 +104,23 @@ class CC_EXPORT PicturePileImpl : public RasterSource { int buffer_pixels() const { return tiling_.border_texels(); } - PictureMap picture_map_; - TilingData tiling_; - SkColor background_color_; - bool requires_clear_; - bool can_use_lcd_text_; - bool is_solid_color_; - SkColor solid_color_; - gfx::Rect recorded_viewport_; - bool has_any_recordings_; - bool clear_canvas_with_debug_color_; - float min_contents_scale_; - int slow_down_raster_scale_factor_for_debug_; + // These members are const as this raster source may be in use on another + // thread and so should not be touched after construction. + const PictureMap picture_map_; + const TilingData tiling_; + const SkColor background_color_; + const bool requires_clear_; + const bool can_use_lcd_text_; + const bool is_solid_color_; + const SkColor solid_color_; + const gfx::Rect recorded_viewport_; + const bool has_any_recordings_; + const bool clear_canvas_with_debug_color_; + const float min_contents_scale_; + const int slow_down_raster_scale_factor_for_debug_; + // TODO(enne/vmiura): this has a read/write race between raster and compositor + // threads with multi-threaded Ganesh. Make this const or remove it. + bool should_attempt_to_use_distance_field_text_; private: typedef std::map PictureRegionMap; @@ -146,8 +149,6 @@ class CC_EXPORT PicturePileImpl : public RasterSource { gfx::Rect PaddedRect(const PictureMapKey& key) const; - bool should_attempt_to_use_distance_field_text_; - DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); }; diff --git a/cc/resources/picture_pile_impl_unittest.cc b/cc/resources/picture_pile_impl_unittest.cc index 6e9afc7..72a8158 100644 --- a/cc/resources/picture_pile_impl_unittest.cc +++ b/cc/resources/picture_pile_impl_unittest.cc @@ -19,21 +19,25 @@ TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { gfx::Size tile_size(100, 100); gfx::Size layer_bounds(400, 400); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); - SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); SkPaint solid_paint; + SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); solid_paint.setColor(solid_color); SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); SkPaint non_solid_paint; non_solid_paint.setColor(non_solid_color); - pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); - pile->RerecordPile(); + recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), + solid_paint); + recording_source->RerecordPile(); + + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); - // Ensure everything is solid + // Ensure everything is solid. for (int y = 0; y <= 300; y += 100) { for (int x = 0; x <= 300; x += 100) { RasterSource::SolidColorAnalysis analysis; @@ -44,9 +48,11 @@ TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { } } - // One pixel non solid - pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); - pile->RerecordPile(); + // Add one non-solid pixel and recreate the raster source. + recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), + non_solid_paint); + recording_source->RerecordPile(); + pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); RasterSource::SolidColorAnalysis analysis; pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); @@ -56,7 +62,7 @@ TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { EXPECT_TRUE(analysis.is_solid_color); EXPECT_EQ(analysis.solid_color, solid_color); - // Boundaries should be clipped + // Boundaries should be clipped. analysis.is_solid_color = false; pile->PerformSolidColorAnalysis(gfx::Rect(350, 0, 100, 100), 1.0, &analysis); EXPECT_TRUE(analysis.is_solid_color); @@ -78,8 +84,8 @@ TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { gfx::Size tile_size(100, 100); gfx::Size layer_bounds(400, 400); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); SkPaint solid_paint; @@ -89,10 +95,14 @@ TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { SkPaint non_solid_paint; non_solid_paint.setColor(non_solid_color); - pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); - pile->RerecordPile(); + recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), + solid_paint); + recording_source->RerecordPile(); - // Ensure everything is solid + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); + + // Ensure everything is solid. for (int y = 0; y <= 30; y += 10) { for (int x = 0; x <= 30; x += 10) { RasterSource::SolidColorAnalysis analysis; @@ -103,9 +113,11 @@ TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { } } - // One pixel non solid - pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); - pile->RerecordPile(); + // Add one non-solid pixel and recreate the raster source. + recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), + non_solid_paint); + recording_source->RerecordPile(); + pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); RasterSource::SolidColorAnalysis analysis; pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); @@ -115,7 +127,7 @@ TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { EXPECT_TRUE(analysis.is_solid_color); EXPECT_EQ(analysis.solid_color, solid_color); - // Boundaries should be clipped + // Boundaries should be clipped. analysis.is_solid_color = false; pile->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); EXPECT_TRUE(analysis.is_solid_color); @@ -209,24 +221,30 @@ TEST(PicturePileImplTest, PixelRefIteratorNoDiscardableRefs) { gfx::Size tile_size(128, 128); gfx::Size layer_bounds(256, 256); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); - + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); SkPaint simple_paint; simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); SkBitmap non_discardable_bitmap; CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap); - pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); - pile->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), simple_paint); - pile->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), simple_paint); - pile->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint); - pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0)); - pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128)); - pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(150, 150)); + 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->RerecordPile(); - pile->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); // Tile sized iterators. { @@ -282,8 +300,8 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefs) { gfx::Size tile_size(128, 128); gfx::Size layer_bounds(256, 256); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); SkBitmap discardable_bitmap[2][2]; CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); @@ -296,11 +314,15 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefs) { // |---|---| // | x | x | // |---|---| - pile->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - pile->add_draw_bitmap(discardable_bitmap[1][0], gfx::Point(0, 130)); - pile->add_draw_bitmap(discardable_bitmap[1][1], gfx::Point(140, 140)); + 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->RerecordPile(); - pile->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); // Tile sized iterators. These should find only one pixel ref. { @@ -392,8 +414,8 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { gfx::Size tile_size(256, 256); gfx::Size layer_bounds(512, 512); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); SkBitmap discardable_bitmap[2][2]; CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); @@ -406,11 +428,15 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { // |---|---| // | | x | // |---|---| - pile->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - pile->add_draw_bitmap(discardable_bitmap[0][1], gfx::Point(260, 0)); - pile->add_draw_bitmap(discardable_bitmap[1][1], gfx::Point(260, 260)); + 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->RerecordPile(); - pile->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); // Tile sized iterators. These should find only one pixel ref. { @@ -523,8 +549,8 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsBaseNonDiscardable) { gfx::Size tile_size(256, 256); gfx::Size layer_bounds(512, 512); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); SkBitmap non_discardable_bitmap; CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap); @@ -541,12 +567,16 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsBaseNonDiscardable) { // |---|---| // | | x | // |---|---| - pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0)); - pile->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - pile->add_draw_bitmap(discardable_bitmap[0][1], gfx::Point(260, 0)); - pile->add_draw_bitmap(discardable_bitmap[1][1], gfx::Point(260, 260)); + 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->RerecordPile(); - pile->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); // Tile sized iterators. These should find only one pixel ref. { @@ -640,19 +670,25 @@ TEST(PicturePileImplTest, RasterFullContents) { float contents_scale = 1.5f; float raster_divisions = 2.f; - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); + recording_source->SetBackgroundColor(SK_ColorBLACK); + recording_source->SetIsSolidColor(false); + recording_source->SetRequiresClear(false); + recording_source->SetClearCanvasWithDebugColor(false); + // Because the caller sets content opaque, it also promises that it // has at least filled in layer_bounds opaquely. SkPaint white_paint; white_paint.setColor(SK_ColorWHITE); - pile->add_draw_rect_with_paint(gfx::Rect(layer_bounds), white_paint); + recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), + white_paint); - pile->SetMinContentsScale(contents_scale); - pile->set_background_color(SK_ColorBLACK); - pile->SetRequiresClear(false); - pile->set_clear_canvas_with_debug_color(false); - pile->RerecordPile(); + recording_source->SetMinContentsScale(contents_scale); + recording_source->RerecordPile(); + + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); gfx::Size content_bounds( gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); @@ -703,14 +739,16 @@ TEST(PicturePileImpl, RasterContentsTransparent) { gfx::Size layer_bounds(5, 3); float contents_scale = 0.5f; - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); - pile->set_background_color(SK_ColorTRANSPARENT); - pile->SetRequiresClear(true); - pile->SetMinContentsScale(contents_scale); - pile->set_clear_canvas_with_debug_color(false); - pile->RerecordPile(); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); + recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); + recording_source->SetRequiresClear(true); + recording_source->SetMinContentsScale(contents_scale); + recording_source->SetClearCanvasWithDebugColor(false); + recording_source->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); gfx::Size content_bounds( gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); @@ -743,21 +781,24 @@ TEST_P(OverlapTest, NoOverlap) { // Pick an opaque color to not have to deal with premultiplication off-by-one. SkColor test_color = SkColorSetARGB(255, 45, 56, 67); - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); - pile->set_background_color(SK_ColorTRANSPARENT); - pile->SetRequiresClear(true); - pile->SetMinContentsScale(MinContentsScale()); - pile->set_clear_canvas_with_debug_color(true); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); + recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); + recording_source->SetRequiresClear(true); + recording_source->SetMinContentsScale(MinContentsScale()); + recording_source->SetClearCanvasWithDebugColor(true); + SkPaint color_paint; color_paint.setColor(test_color); // Additive paint, so that if two paints overlap, the color will change. color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); // Paint outside the layer to make sure that blending works. - pile->add_draw_rect_with_paint(gfx::RectF(bigger_than_layer_bounds), - color_paint); - pile->RerecordPile(); + recording_source->add_draw_rect_with_paint( + gfx::RectF(bigger_than_layer_bounds), color_paint); + recording_source->RerecordPile(); + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); gfx::Size content_bounds( gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); @@ -793,25 +834,33 @@ TEST(PicturePileImplTest, PixelRefIteratorBorders) { gfx::Size tile_size(128, 128); gfx::Size layer_bounds(320, 128); - // Fake picture pile impl uses a tile grid the size of the tile. So, + // Fake picture pile uses a tile grid the size of the tile. So, // any iteration that intersects with a tile will return all pixel refs // inside of it. - scoped_refptr pile = - FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); - pile->SetMinContentsScale(0.5f); + scoped_ptr recording_source = + FakePicturePile::CreateFilledPile(tile_size, layer_bounds); + recording_source->SetMinContentsScale(0.5f); // Bitmaps 0-2 are exactly on tiles 0-2, so that they overlap the borders // of adjacent tiles. - gfx::Rect bitmap_rects[] = {pile->tiling().TileBounds(0, 0), - pile->tiling().TileBounds(1, 0), - pile->tiling().TileBounds(2, 0), }; + gfx::Rect bitmap_rects[] = { + recording_source->tiling().TileBounds(0, 0), + recording_source->tiling().TileBounds(1, 0), + recording_source->tiling().TileBounds(2, 0), + }; SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]); - pile->add_draw_bitmap(discardable_bitmap[i], bitmap_rects[i].origin()); + recording_source->add_draw_bitmap(discardable_bitmap[i], + bitmap_rects[i].origin()); } + recording_source->RerecordPile(); + + scoped_refptr pile = + FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); + // Sanity check that bitmaps 0-2 intersect the borders of their adjacent // tiles, but not the actual tiles. EXPECT_TRUE( @@ -827,8 +876,6 @@ TEST(PicturePileImplTest, PixelRefIteratorBorders) { bitmap_rects[2].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); EXPECT_FALSE(bitmap_rects[2].Intersects(pile->tiling().TileBounds(1, 0))); - pile->RerecordPile(); - // Tile-sized iterators. { // Because tile 0's borders extend onto tile 1, it will include both diff --git a/cc/resources/raster_source.h b/cc/resources/raster_source.h index 85341bac..929e49d 100644 --- a/cc/resources/raster_source.h +++ b/cc/resources/raster_source.h @@ -86,9 +86,6 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe { // during rasterization. virtual void SetShouldAttemptToUseDistanceFieldText() = 0; - virtual void SetBackgoundColor(SkColor background_color) = 0; - virtual void SetRequiresClear(bool requires_clear) = 0; - // Return true iff this raster source would benefit from using distance // field text. virtual bool ShouldAttemptToUseDistanceFieldText() const = 0; diff --git a/cc/resources/recording_source.h b/cc/resources/recording_source.h index d96c0fa..8915361 100644 --- a/cc/resources/recording_source.h +++ b/cc/resources/recording_source.h @@ -45,6 +45,8 @@ class CC_EXPORT RecordingSource { virtual gfx::Size GetSize() const = 0; virtual void SetEmptyBounds() = 0; virtual void SetSlowdownRasterScaleFactor(int factor) = 0; + virtual void SetBackgroundColor(SkColor background_color) = 0; + virtual void SetRequiresClear(bool requires_clear) = 0; virtual bool IsSuitableForGpuRasterization() const = 0; // TODO(hendrikw): Figure out how to remove this. diff --git a/cc/test/fake_picture_pile.cc b/cc/test/fake_picture_pile.cc index 912ec06..cc0a7ba 100644 --- a/cc/test/fake_picture_pile.cc +++ b/cc/test/fake_picture_pile.cc @@ -4,12 +4,101 @@ #include "cc/test/fake_picture_pile.h" +#include + #include "cc/test/fake_picture_pile_impl.h" +#include "testing/gtest/include/gtest/gtest.h" namespace cc { +namespace { + +scoped_ptr CreatePile(const gfx::Size& tile_size, + const gfx::Size& layer_bounds, + bool is_filled) { + scoped_ptr pile( + new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, + ImplSidePaintingSettings().default_tile_grid_size)); + pile->tiling().SetBorderTexels(0); + pile->tiling().SetTilingSize(layer_bounds); + pile->tiling().SetMaxTextureSize(tile_size); + pile->SetRecordedViewport(is_filled ? gfx::Rect(layer_bounds) : gfx::Rect()); + pile->SetHasAnyRecordings(is_filled); + if (is_filled) { + for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { + for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) + pile->AddRecordingAt(x, y); + } + } + return pile; +} + +} // namespace + +scoped_ptr FakePicturePile::CreateFilledPile( + const gfx::Size& tile_size, + const gfx::Size& layer_bounds) { + bool is_filled = true; + return CreatePile(tile_size, layer_bounds, is_filled); +} + +scoped_ptr FakePicturePile::CreateEmptyPile( + const gfx::Size& tile_size, + const gfx::Size& layer_bounds) { + bool is_filled = false; + return CreatePile(tile_size, layer_bounds, is_filled); +} + scoped_refptr FakePicturePile::CreateRasterSource() const { return FakePicturePileImpl::CreateFromPile(this, playback_allowed_event_); } +void FakePicturePile::AddRecordingAt(int x, int y) { + EXPECT_GE(x, 0); + EXPECT_GE(y, 0); + EXPECT_LT(x, tiling_.num_tiles_x()); + EXPECT_LT(y, tiling_.num_tiles_y()); + + if (HasRecordingAt(x, y)) + return; + gfx::Rect bounds(tiling().TileBounds(x, y)); + bounds.Inset(-buffer_pixels(), -buffer_pixels()); + + scoped_refptr picture( + Picture::Create(bounds, &client_, tile_grid_size_, true, + RecordingSource::RECORD_NORMALLY)); + picture_map_[std::pair(x, y)].SetPicture(picture); + EXPECT_TRUE(HasRecordingAt(x, y)); + + has_any_recordings_ = true; +} + +void FakePicturePile::RemoveRecordingAt(int x, int y) { + EXPECT_GE(x, 0); + EXPECT_GE(y, 0); + EXPECT_LT(x, tiling_.num_tiles_x()); + EXPECT_LT(y, tiling_.num_tiles_y()); + + if (!HasRecordingAt(x, y)) + return; + picture_map_.erase(std::pair(x, y)); + EXPECT_FALSE(HasRecordingAt(x, y)); +} + +bool FakePicturePile::HasRecordingAt(int x, int y) const { + PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); + if (found == picture_map_.end()) + return false; + return !!found->second.GetPicture(); +} + +void FakePicturePile::RerecordPile() { + for (int y = 0; y < num_tiles_y(); ++y) { + for (int x = 0; x < num_tiles_x(); ++x) { + RemoveRecordingAt(x, y); + AddRecordingAt(x, y); + } + } +} + } // namespace cc diff --git a/cc/test/fake_picture_pile.h b/cc/test/fake_picture_pile.h index 55b4c36..054eaa2 100644 --- a/cc/test/fake_picture_pile.h +++ b/cc/test/fake_picture_pile.h @@ -6,6 +6,8 @@ #define CC_TEST_FAKE_PICTURE_PILE_H_ #include "cc/resources/picture_pile.h" +#include "cc/test/fake_content_layer_client.h" +#include "cc/test/impl_side_painting_settings.h" namespace base { class WaitableEvent; @@ -24,6 +26,13 @@ class FakePicturePile : public PicturePile { playback_allowed_event_(nullptr) {} ~FakePicturePile() override {} + static scoped_ptr CreateFilledPile( + const gfx::Size& tile_size, + const gfx::Size& layer_bounds); + static scoped_ptr CreateEmptyPile( + const gfx::Size& tile_size, + const gfx::Size& layer_bounds); + // PicturePile overrides. scoped_refptr CreateRasterSource() const override; @@ -53,6 +62,10 @@ class FakePicturePile : public PicturePile { has_any_recordings_ = has_recordings; } + void SetClearCanvasWithDebugColor(bool clear) { + clear_canvas_with_debug_color_ = clear; + } + void SetPlaybackAllowedEvent(base::WaitableEvent* event) { playback_allowed_event_ = event; } @@ -61,11 +74,42 @@ class FakePicturePile : public PicturePile { bool is_solid_color() const { return is_solid_color_; } SkColor solid_color() const { return solid_color_; } + void SetIsSolidColor(bool is_solid) { is_solid_color_ = is_solid; } void SetPixelRecordDistance(int d) { pixel_record_distance_ = d; } + void add_draw_rect(const gfx::RectF& rect) { + client_.add_draw_rect(rect, default_paint_); + } + + void add_draw_bitmap(const SkBitmap& bitmap, const gfx::Point& point) { + client_.add_draw_bitmap(bitmap, point, 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_with_paint(const SkBitmap& bitmap, + const gfx::Point& point, + const SkPaint& paint) { + client_.add_draw_bitmap(bitmap, point, paint); + } + + void set_default_paint(const SkPaint& paint) { default_paint_ = paint; } + + void AddRecordingAt(int x, int y); + void RemoveRecordingAt(int x, int y); + bool HasRecordingAt(int x, int y) const; + int num_tiles_x() const { return tiling_.num_tiles_x(); } + int num_tiles_y() const { return tiling_.num_tiles_y(); } + void RerecordPile(); + private: base::WaitableEvent* playback_allowed_event_; + + FakeContentLayerClient client_; + SkPaint default_paint_; }; } // namespace cc diff --git a/cc/test/fake_picture_pile_impl.cc b/cc/test/fake_picture_pile_impl.cc index bdba092..8353d27 100644 --- a/cc/test/fake_picture_pile_impl.cc +++ b/cc/test/fake_picture_pile_impl.cc @@ -10,7 +10,6 @@ #include "base/synchronization/waitable_event.h" #include "cc/resources/picture_pile.h" -#include "cc/test/fake_picture_pile.h" #include "cc/test/impl_side_painting_settings.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,43 +28,47 @@ FakePicturePileImpl::FakePicturePileImpl( FakePicturePileImpl::~FakePicturePileImpl() {} -scoped_refptr FakePicturePileImpl::CreateFilledPile( +scoped_refptr FakePicturePileImpl::CreatePile( const gfx::Size& tile_size, - const gfx::Size& layer_bounds) { + const gfx::Size& layer_bounds, + bool is_filled) { FakePicturePile pile(ImplSidePaintingSettings().minimum_contents_scale, ImplSidePaintingSettings().default_tile_grid_size); pile.tiling().SetBorderTexels(0); pile.tiling().SetTilingSize(layer_bounds); pile.tiling().SetMaxTextureSize(tile_size); - pile.SetRecordedViewport(gfx::Rect(layer_bounds)); - pile.SetHasAnyRecordings(true); - + pile.SetRecordedViewport(is_filled ? gfx::Rect(layer_bounds) : gfx::Rect()); + pile.SetHasAnyRecordings(is_filled); + if (is_filled) { + for (int x = 0; x < pile.tiling().num_tiles_x(); ++x) { + for (int y = 0; y < pile.tiling().num_tiles_y(); ++y) + pile.AddRecordingAt(x, y); + } + } scoped_refptr pile_impl( new FakePicturePileImpl(&pile, nullptr)); - for (int x = 0; x < pile_impl->tiling().num_tiles_x(); ++x) { - for (int y = 0; y < pile_impl->tiling().num_tiles_y(); ++y) - pile_impl->AddRecordingAt(x, y); - } return pile_impl; } +scoped_refptr FakePicturePileImpl::CreateFilledPile( + const gfx::Size& tile_size, + const gfx::Size& layer_bounds) { + bool is_filled = true; + return CreatePile(tile_size, layer_bounds, is_filled); +} + scoped_refptr FakePicturePileImpl::CreateEmptyPile( const gfx::Size& tile_size, const gfx::Size& layer_bounds) { - FakePicturePile pile(ImplSidePaintingSettings().minimum_contents_scale, - ImplSidePaintingSettings().default_tile_grid_size); - pile.tiling().SetBorderTexels(0); - pile.tiling().SetTilingSize(layer_bounds); - pile.tiling().SetMaxTextureSize(tile_size); - pile.SetRecordedViewport(gfx::Rect()); - pile.SetHasAnyRecordings(false); - return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); + bool is_filled = false; + return CreatePile(tile_size, layer_bounds, is_filled); } scoped_refptr FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( const gfx::Size& tile_size, - const gfx::Size& layer_bounds) { + const gfx::Size& layer_bounds, + bool is_solid_color) { FakePicturePile pile(ImplSidePaintingSettings().minimum_contents_scale, ImplSidePaintingSettings().default_tile_grid_size); pile.tiling().SetBorderTexels(0); @@ -74,6 +77,7 @@ FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( // This simulates a false positive for this flag. pile.SetRecordedViewport(gfx::Rect()); pile.SetHasAnyRecordings(true); + pile.SetIsSolidColor(is_solid_color); return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); } @@ -87,10 +91,9 @@ FakePicturePileImpl::CreateInfiniteFilledPile() { pile.tiling().SetMaxTextureSize(size); pile.SetRecordedViewport(gfx::Rect(size)); pile.SetHasAnyRecordings(true); - + pile.AddRecordingAt(0, 0); scoped_refptr pile_impl( new FakePicturePileImpl(&pile, nullptr)); - pile_impl->AddRecordingAt(0, 0); return pile_impl; } @@ -109,38 +112,6 @@ void FakePicturePileImpl::PlaybackToCanvas(SkCanvas* canvas, PicturePileImpl::PlaybackToCanvas(canvas, canvas_rect, contents_scale); } -void FakePicturePileImpl::AddRecordingAt(int x, int y) { - EXPECT_GE(x, 0); - EXPECT_GE(y, 0); - EXPECT_LT(x, tiling_.num_tiles_x()); - EXPECT_LT(y, tiling_.num_tiles_y()); - - if (HasRecordingAt(x, y)) - return; - gfx::Rect bounds(tiling().TileBounds(x, y)); - bounds.Inset(-buffer_pixels(), -buffer_pixels()); - - scoped_refptr picture( - Picture::Create(bounds, &client_, tile_grid_size_, true, - RecordingSource::RECORD_NORMALLY)); - picture_map_[std::pair(x, y)].SetPicture(picture); - EXPECT_TRUE(HasRecordingAt(x, y)); - - has_any_recordings_ = true; -} - -void FakePicturePileImpl::RemoveRecordingAt(int x, int y) { - EXPECT_GE(x, 0); - EXPECT_GE(y, 0); - EXPECT_LT(x, tiling_.num_tiles_x()); - EXPECT_LT(y, tiling_.num_tiles_y()); - - if (!HasRecordingAt(x, y)) - return; - picture_map_.erase(std::pair(x, y)); - EXPECT_FALSE(HasRecordingAt(x, y)); -} - bool FakePicturePileImpl::HasRecordingAt(int x, int y) const { PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); if (found == picture_map_.end()) @@ -148,46 +119,4 @@ bool FakePicturePileImpl::HasRecordingAt(int x, int y) const { return !!found->second.GetPicture(); } -void FakePicturePileImpl::RerecordPile() { - for (int y = 0; y < num_tiles_y(); ++y) { - for (int x = 0; x < num_tiles_x(); ++x) { - RemoveRecordingAt(x, y); - AddRecordingAt(x, y); - } - } -} - -void FakePicturePileImpl::SetMinContentsScale(float min_contents_scale) { - if (min_contents_scale_ == min_contents_scale) - return; - - // Picture contents are played back scaled. When the final contents scale is - // less than 1 (i.e. low res), then multiple recorded pixels will be used - // to raster one final pixel. To avoid splitting a final pixel across - // pictures (which would result in incorrect rasterization due to blending), a - // buffer margin is added so that any picture can be snapped to integral - // final pixels. - // - // For example, if a 1/4 contents scale is used, then that would be 3 buffer - // pixels, since that's the minimum number of pixels to add so that resulting - // content can be snapped to a four pixel aligned grid. - int buffer_pixels = static_cast(ceil(1 / min_contents_scale) - 1); - buffer_pixels = std::max(0, buffer_pixels); - SetBufferPixels(buffer_pixels); - min_contents_scale_ = min_contents_scale; -} - -void FakePicturePileImpl::SetBufferPixels(int new_buffer_pixels) { - if (new_buffer_pixels == buffer_pixels()) - return; - - Clear(); - tiling_.SetBorderTexels(new_buffer_pixels); -} - -void FakePicturePileImpl::Clear() { - picture_map_.clear(); - recorded_viewport_ = gfx::Rect(); -} - } // namespace cc diff --git a/cc/test/fake_picture_pile_impl.h b/cc/test/fake_picture_pile_impl.h index 3a43702..a21509a0 100644 --- a/cc/test/fake_picture_pile_impl.h +++ b/cc/test/fake_picture_pile_impl.h @@ -7,7 +7,7 @@ #include "base/memory/ref_counted.h" #include "cc/resources/picture_pile_impl.h" -#include "cc/test/fake_content_layer_client.h" +#include "cc/test/fake_picture_pile.h" namespace base { class WaitableEvent; @@ -17,6 +17,11 @@ namespace cc { class FakePicturePileImpl : public PicturePileImpl { public: + static scoped_refptr CreatePile( + const gfx::Size& tile_size, + const gfx::Size& layer_bounds, + bool is_filled); + static scoped_refptr CreateFilledPileWithDefaultTileSize( const gfx::Size& layer_bounds) { return CreateFilledPile(gfx::Size(512, 512), layer_bounds); @@ -32,8 +37,9 @@ class FakePicturePileImpl : public PicturePileImpl { const gfx::Size& tile_size, const gfx::Size& layer_bounds); static scoped_refptr - CreateEmptyPileThatThinksItHasRecordings(const gfx::Size& tile_size, - const gfx::Size& layer_bounds); + CreateEmptyPileThatThinksItHasRecordings(const gfx::Size& tile_size, + const gfx::Size& layer_bounds, + bool is_solid_color); static scoped_refptr CreateInfiniteFilledPile(); static scoped_refptr CreateFromPile( const PicturePile* other, @@ -44,63 +50,18 @@ class FakePicturePileImpl : public PicturePileImpl { const gfx::Rect& canvas_rect, float contents_scale) const override; - TilingData& tiling() { return tiling_; } - - void AddRecordingAt(int x, int y); - void RemoveRecordingAt(int x, int y); - void RerecordPile(); - - void add_draw_rect(const gfx::RectF& rect) { - client_.add_draw_rect(rect, default_paint_); - } - - void add_draw_bitmap(const SkBitmap& bitmap, const gfx::Point& point) { - client_.add_draw_bitmap(bitmap, point, 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_with_paint(const SkBitmap& bitmap, - const gfx::Point& point, - const SkPaint& paint) { - client_.add_draw_bitmap(bitmap, point, paint); - } - - void set_default_paint(const SkPaint& paint) { - default_paint_ = paint; - } - - void set_background_color(SkColor color) { - background_color_ = color; - } - - void set_clear_canvas_with_debug_color(bool clear) { - clear_canvas_with_debug_color_ = clear; - } - - void set_is_solid_color(bool is_solid_color) { - is_solid_color_ = is_solid_color; - } + const TilingData& tiling() { return tiling_; } bool HasRecordingAt(int x, int y) const; - int num_tiles_x() const { return tiling_.num_tiles_x(); } int num_tiles_y() const { return tiling_.num_tiles_y(); } - void SetMinContentsScale(float scale); - void SetBufferPixels(int new_buffer_pixels); - void Clear(); - protected: FakePicturePileImpl(); FakePicturePileImpl(const PicturePile* other, base::WaitableEvent* playback_allowed_event); ~FakePicturePileImpl() override; - FakeContentLayerClient client_; - SkPaint default_paint_; base::WaitableEvent* playback_allowed_event_; gfx::Size tile_grid_size_; }; -- cgit v1.1