Skip to content

Commit

Permalink
cc: Add RecordingSource and replace references to PicturePiles
Browse files Browse the repository at this point in the history
Adds the RecordingSource base class and replaces many
references to PicturePile in the tests.  Replace the pile_
member in PictureLayer with a scoped_ptr to the new interface.

This is the other side of: https://codereview.chromium.org/707193007/

TODO: Disconnect from PicturePileBase
TODO: Clean up the new interface so that it will work for both
approaches

Review URL: https://codereview.chromium.org/711843003

Cr-Commit-Position: refs/heads/master@{#303708}
  • Loading branch information
hendrikw authored and Commit bot committed Nov 11, 2014
1 parent aea8be3 commit 9d909aa
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 125 deletions.
1 change: 1 addition & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
'resources/raster_worker_pool.h',
'resources/rasterizer.cc',
'resources/rasterizer.h',
'resources/recording_source.h',
'resources/release_callback.h',
'resources/resource.cc',
'resources/resource.h',
Expand Down
40 changes: 21 additions & 19 deletions cc/layers/picture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {

PictureLayer::PictureLayer(ContentLayerClient* client)
: client_(client),
recording_source_(new PicturePile),
instrumentation_object_tracker_(id()),
update_source_frame_number_(-1),
can_use_lcd_text_last_frame_(can_use_lcd_text()) {
Expand All @@ -37,38 +38,38 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {

int source_frame_number = layer_tree_host()->source_frame_number();
gfx::Size impl_bounds = layer_impl->bounds();
gfx::Size pile_bounds = pile_.tiling_size();
gfx::Size recording_source_bounds = recording_source_->GetSize();

// If update called, then pile size must match bounds pushed to impl layer.
DCHECK_IMPLIES(update_source_frame_number_ == source_frame_number,
impl_bounds == pile_bounds)
impl_bounds == recording_source_bounds)
<< " bounds " << impl_bounds.ToString() << " pile "
<< pile_bounds.ToString();
<< recording_source_bounds.ToString();

if (update_source_frame_number_ != source_frame_number &&
pile_bounds != impl_bounds) {
recording_source_bounds != impl_bounds) {
// Update may not get called for the layer (if it's not in the viewport
// for example, even though it has resized making the pile no longer
// valid. In this case just destroy the pile.
pile_.SetEmptyBounds();
recording_source_->SetEmptyBounds();
}

// Unlike other properties, invalidation must always be set on layer_impl.
// See PictureLayerImpl::PushPropertiesTo for more details.
layer_impl->invalidation_.Clear();
layer_impl->invalidation_.Swap(&pile_invalidation_);
layer_impl->UpdateRasterSource(PicturePileImpl::CreateFromOther(&pile_));
layer_impl->invalidation_.Swap(&recording_invalidation_);
layer_impl->UpdateRasterSource(recording_source_->CreateRasterSource());
}

void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
Layer::SetLayerTreeHost(host);
if (host) {
pile_.SetMinContentsScale(host->settings().minimum_contents_scale);
pile_.SetTileGridSize(host->settings().default_tile_grid_size);
pile_.set_slow_down_raster_scale_factor(
// TODO(hendrikw): Perhaps use and initialization function to do this work.
recording_source_->SetMinContentsScale(
host->settings().minimum_contents_scale);
recording_source_->SetTileGridSize(host->settings().default_tile_grid_size);
recording_source_->SetSlowdownRasterScaleFactor(
host->debug_state().slow_down_raster_scale_factor);
pile_.set_show_debug_picture_borders(
host->debug_state().show_picture_borders);
}
}

Expand Down Expand Up @@ -97,7 +98,8 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
gfx::Size layer_size = paint_properties().bounds;

if (last_updated_visible_content_rect_ == visible_content_rect() &&
pile_.tiling_size() == layer_size && pending_invalidation_.IsEmpty()) {
recording_source_->GetSize() == layer_size &&
pending_invalidation_.IsEmpty()) {
// Only early out if the visible content rect of this layer hasn't changed.
return updated;
}
Expand All @@ -110,7 +112,7 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,

// Calling paint in WebKit can sometimes cause invalidations, so save
// off the invalidation prior to calling update.
pending_invalidation_.Swap(&pile_invalidation_);
pending_invalidation_.Swap(&recording_invalidation_);
pending_invalidation_.Clear();

if (layer_tree_host()->settings().record_full_layer) {
Expand All @@ -124,8 +126,8 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
// to the impl side so that it drops tiles that may not have a recording
// for them.
DCHECK(client_);
updated |= pile_.UpdateAndExpandInvalidation(
client_, &pile_invalidation_, SafeOpaqueBackgroundColor(),
updated |= recording_source_->UpdateAndExpandInvalidation(
client_, &recording_invalidation_, SafeOpaqueBackgroundColor(),
contents_opaque(), client_->FillsBoundsCompletely(), layer_size,
visible_layer_rect, update_source_frame_number_,
Picture::RECORD_NORMALLY);
Expand All @@ -136,14 +138,14 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
} else {
// If this invalidation did not affect the pile, then it can be cleared as
// an optimization.
pile_invalidation_.Clear();
recording_invalidation_.Clear();
}

return updated;
}

void PictureLayer::SetIsMask(bool is_mask) {
pile_.set_is_mask(is_mask);
recording_source_->SetIsMask(is_mask);
}

bool PictureLayer::SupportsLCDText() const {
Expand Down Expand Up @@ -179,7 +181,7 @@ skia::RefPtr<SkPicture> PictureLayer::GetPicture() const {
}

bool PictureLayer::IsSuitableForGpuRasterization() const {
return pile_.is_suitable_for_gpu_rasterization();
return recording_source_->IsSuitableForGpuRasterization();
}

void PictureLayer::ClearClient() {
Expand Down
8 changes: 5 additions & 3 deletions cc/layers/picture_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class CC_EXPORT PictureLayer : public Layer {

ContentLayerClient* client() { return client_; }

PicturePile* GetPicturePileForTesting() { return &pile_; }
RecordingSource* GetRecordingSourceForTesting() {
return recording_source_.get();
}

protected:
explicit PictureLayer(ContentLayerClient* client);
Expand All @@ -50,13 +52,13 @@ class CC_EXPORT PictureLayer : public Layer {

private:
ContentLayerClient* client_;
PicturePile pile_;
scoped_ptr<RecordingSource> recording_source_;
devtools_instrumentation::
ScopedLayerObjectTracker instrumentation_object_tracker_;
// Invalidation to use the next time update is called.
InvalidationRegion pending_invalidation_;
// Invalidation from the last time update was called.
Region pile_invalidation_;
Region recording_invalidation_;
gfx::Rect last_updated_visible_content_rect_;

int update_source_frame_number_;
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/picture_layer_impl_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PictureLayerImplPerfTest : public testing::Test {
pending_tree->DetachLayerTree();

scoped_ptr<FakePictureLayerImpl> pending_layer =
FakePictureLayerImpl::CreateWithPile(pending_tree, 7, pile);
FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 7, pile);
pending_layer->SetDrawsContent(true);
pending_tree->SetRootLayer(pending_layer.Pass());

Expand Down
56 changes: 29 additions & 27 deletions cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class PictureLayerImplTest : public testing::Test {
pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
}

void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) {
void SetupPendingTree(scoped_refptr<RasterSource> raster_source) {
host_impl_.CreatePendingTree();
host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
LayerTreeImpl* pending_tree = host_impl_.pending_tree();
Expand All @@ -147,10 +147,10 @@ class PictureLayerImplTest : public testing::Test {
if (old_pending_root) {
pending_layer.reset(
static_cast<FakePictureLayerImpl*>(old_pending_root.release()));
pending_layer->SetRasterSource(pile);
pending_layer->SetRasterSource(raster_source);
} else {
pending_layer =
FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile);
pending_layer = FakePictureLayerImpl::CreateWithRasterSource(
pending_tree, id_, raster_source);
pending_layer->SetDrawsContent(true);
}
// The bounds() just mirror the pile size.
Expand Down Expand Up @@ -2051,7 +2051,8 @@ TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) {
LayerTreeImpl* pending_tree = host_impl_.pending_tree();

scoped_ptr<FakePictureLayerImpl> pending_layer =
FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pending_pile);
FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_,
pending_pile);
pending_layer->SetDrawsContent(true);
pending_tree->SetRootLayer(pending_layer.Pass());

Expand Down Expand Up @@ -3716,8 +3717,9 @@ TEST_F(PictureLayerImplTest, UpdateTilesForMasksWithNoVisibleContent) {
scoped_refptr<FakePicturePileImpl> pending_pile =
FakePicturePileImpl::CreateFilledPile(tile_size, bounds);
pending_pile->SetIsMask(true);
scoped_ptr<FakePictureLayerImpl> mask = FakePictureLayerImpl::CreateWithPile(
host_impl_.pending_tree(), 3, pending_pile);
scoped_ptr<FakePictureLayerImpl> mask =
FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 3,
pending_pile);

mask->SetBounds(bounds);
mask->SetContentBounds(bounds);
Expand Down Expand Up @@ -4492,7 +4494,7 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
host->SetRootLayer(layer);
PicturePile* pile = layer->GetPicturePileForTesting();
RecordingSource* recording_source = layer->GetRecordingSourceForTesting();

host_impl_.SetViewportSize(layer_bounds);

Expand All @@ -4501,14 +4503,14 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
client.set_fill_with_nonsolid_color(!test_for_solid);

Region invalidation(layer_rect);
pile->UpdateAndExpandInvalidation(&client, &invalidation, SK_ColorWHITE,
false, false, layer_bounds, layer_rect,
frame_number++, Picture::RECORD_NORMALLY);
recording_source->UpdateAndExpandInvalidation(
&client, &invalidation, SK_ColorWHITE, false, false, layer_bounds,
layer_rect, frame_number++, Picture::RECORD_NORMALLY);

scoped_refptr<PicturePileImpl> pending_pile =
PicturePileImpl::CreateFromOther(pile);
scoped_refptr<RasterSource> pending_raster_source =
recording_source->CreateRasterSource();

SetupPendingTree(pending_pile);
SetupPendingTree(pending_raster_source);
ActivateTree();

active_layer_->set_fixed_tile_size(tile_size);
Expand Down Expand Up @@ -4559,7 +4561,7 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
host->SetRootLayer(layer);
PicturePile* pile = layer->GetPicturePileForTesting();
RecordingSource* recording_source = layer->GetRecordingSourceForTesting();

host_impl_.SetViewportSize(layer_bounds);

Expand All @@ -4568,14 +4570,14 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
client.set_fill_with_nonsolid_color(true);

Region invalidation1(layer_rect);
pile->UpdateAndExpandInvalidation(&client, &invalidation1, SK_ColorWHITE,
false, false, layer_bounds, layer_rect,
frame_number++, Picture::RECORD_NORMALLY);
recording_source->UpdateAndExpandInvalidation(
&client, &invalidation1, SK_ColorWHITE, false, false, layer_bounds,
layer_rect, frame_number++, Picture::RECORD_NORMALLY);

scoped_refptr<PicturePileImpl> pending_pile1 =
PicturePileImpl::CreateFromOther(pile);
scoped_refptr<RasterSource> raster_source1 =
recording_source->CreateRasterSource();

SetupPendingTree(pending_pile1);
SetupPendingTree(raster_source1);
ActivateTree();
host_impl_.active_tree()->UpdateDrawProperties();

Expand All @@ -4586,14 +4588,14 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
client.set_fill_with_nonsolid_color(false);

Region invalidation2(layer_rect);
pile->UpdateAndExpandInvalidation(&client, &invalidation2, SK_ColorWHITE,
false, false, layer_bounds, layer_rect,
frame_number++, Picture::RECORD_NORMALLY);
recording_source->UpdateAndExpandInvalidation(
&client, &invalidation2, SK_ColorWHITE, false, false, layer_bounds,
layer_rect, frame_number++, Picture::RECORD_NORMALLY);

scoped_refptr<PicturePileImpl> pending_pile2 =
PicturePileImpl::CreateFromOther(pile);
scoped_refptr<RasterSource> raster_source2 =
recording_source->CreateRasterSource();

SetupPendingTree(pending_pile2);
SetupPendingTree(raster_source2);
ActivateTree();

// We've switched to a solid color, so we should end up with no tilings.
Expand Down
10 changes: 5 additions & 5 deletions cc/layers/picture_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
TEST(PictureLayerTest, SuitableForGpuRasterization) {
MockContentLayerClient client;
scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
PicturePile* pile = layer->GetPicturePileForTesting();
RecordingSource* recording_source = layer->GetRecordingSourceForTesting();

// Layer is suitable for gpu rasterization by default.
EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization());
EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization());
EXPECT_TRUE(layer->IsSuitableForGpuRasterization());

// Veto gpu rasterization.
pile->SetUnsuitableForGpuRasterizationForTesting();
EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization());
recording_source->SetUnsuitableForGpuRasterizationForTesting();
EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization());
EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
}

Expand All @@ -99,7 +99,7 @@ TEST(PictureLayerTest, UseTileGridSize) {

// Tile-grid is set according to its setting.
SkTileGridFactory::TileGridInfo info =
layer->GetPicturePileForTesting()->GetTileGridInfoForTesting();
layer->GetRecordingSourceForTesting()->GetTileGridInfoForTesting();
EXPECT_EQ(info.fTileInterval.width(), 123 - 2 * info.fMargin.width());
EXPECT_EQ(info.fTileInterval.height(), 123 - 2 * info.fMargin.height());
}
Expand Down
41 changes: 41 additions & 0 deletions cc/resources/picture_pile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#include "cc/base/region.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/raster_worker_pool.h"
#include "skia/ext/analysis_canvas.h"

Expand Down Expand Up @@ -537,11 +538,51 @@ bool PicturePile::UpdateAndExpandInvalidation(
return true;
}

gfx::Size PicturePile::GetSize() const {
return tiling_size();
}

void PicturePile::SetEmptyBounds() {
tiling_.SetTilingSize(gfx::Size());
Clear();
}

void PicturePile::SetMinContentsScale(float min_contents_scale) {
PicturePileBase::SetMinContentsScale(min_contents_scale);
}

void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) {
PicturePileBase::SetTileGridSize(tile_grid_size);
}

void PicturePile::SetSlowdownRasterScaleFactor(int factor) {
slow_down_raster_scale_factor_for_debug_ = factor;
}

void PicturePile::SetShowDebugPictureBorders(bool show) {
show_debug_picture_borders_ = show;
}

void PicturePile::SetIsMask(bool is_mask) {
set_is_mask(is_mask);
}

void PicturePile::SetUnsuitableForGpuRasterizationForTesting() {
is_suitable_for_gpu_rasterization_ = false;
}

bool PicturePile::IsSuitableForGpuRasterization() const {
return is_suitable_for_gpu_rasterization_;
}

scoped_refptr<RasterSource> PicturePile::CreateRasterSource() const {
return PicturePileImpl::CreateFromOther(this);
}

SkTileGridFactory::TileGridInfo PicturePile::GetTileGridInfoForTesting() const {
return PicturePileBase::GetTileGridInfoForTesting();
}

bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const {
bool include_borders = false;
for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders);
Expand Down
Loading

0 comments on commit 9d909aa

Please sign in to comment.