Skip to content

Commit

Permalink
cc: Added raster source.
Browse files Browse the repository at this point in the history
This patch adds a raster source that is an opaque interface
for picture pile impl. It also removes the picture pile base
ref count and adds it to the raster source. This makes it
possible to use a member picture pile, instead of a ref
pointer with one owner.

What is missing here is the next step: removing picture pile
base in favour of keeping shared data on the pile and copying
it over. This should allow us to clean up the data and only
share what is actually shared.

R=danakj, enne, reveman

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

Cr-Commit-Position: refs/heads/master@{#301667}
  • Loading branch information
vmpstr authored and Commit bot committed Oct 28, 2014
1 parent 5c8274d commit 394e2b5
Show file tree
Hide file tree
Showing 36 changed files with 586 additions and 509 deletions.
1 change: 1 addition & 0 deletions cc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ component("cc") {
"resources/priority_calculator.h",
"resources/raster_buffer.cc",
"resources/raster_buffer.h",
"resources/raster_source.h",
"resources/raster_tile_priority_queue.cc",
"resources/raster_tile_priority_queue.h",
"resources/raster_worker_pool.cc",
Expand Down
1 change: 1 addition & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
'resources/priority_calculator.h',
'resources/raster_buffer.cc',
'resources/raster_buffer.h',
'resources/raster_source.h',
'resources/raster_tile_priority_queue.cc',
'resources/raster_tile_priority_queue.h',
'resources/raster_worker_pool.cc',
Expand Down
20 changes: 11 additions & 9 deletions cc/debug/rasterize_and_record_benchmark_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const int kDefaultRasterizeRepeatCount = 100;

class BenchmarkRasterTask : public Task {
public:
BenchmarkRasterTask(PicturePileImpl* picture_pile,
BenchmarkRasterTask(RasterSource* raster_source,
const gfx::Rect& content_rect,
float contents_scale,
size_t repeat_count)
: picture_pile_(picture_pile),
: raster_source_(raster_source),
content_rect_(content_rect),
contents_scale_(contents_scale),
repeat_count_(repeat_count),
Expand All @@ -54,11 +54,11 @@ class BenchmarkRasterTask : public Task {
bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect_.width(),
content_rect_.height()));
SkCanvas canvas(bitmap);
PicturePileImpl::Analysis analysis;
RasterSource::SolidColorAnalysis analysis;

picture_pile_->AnalyzeInRect(
raster_source_->PerformSolidColorAnalysis(
content_rect_, contents_scale_, &analysis, nullptr);
picture_pile_->RasterToBitmap(
raster_source_->PlaybackToCanvas(
&canvas, content_rect_, contents_scale_, nullptr);

is_solid_color_ = analysis.is_solid_color;
Expand All @@ -78,7 +78,7 @@ class BenchmarkRasterTask : public Task {
private:
~BenchmarkRasterTask() override {}

PicturePileImpl* picture_pile_;
RasterSource* raster_source_;
gfx::Rect content_rect_;
float contents_scale_;
size_t repeat_count_;
Expand All @@ -99,7 +99,9 @@ class FixedInvalidationPictureLayerTilingClient
return base_client_->CreateTile(tiling, content_rect);
}

PicturePileImpl* GetPile() override { return base_client_->GetPile(); }
RasterSource* GetRasterSource() override {
return base_client_->GetRasterSource();
}

gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override {
return base_client_->CalculateTileSize(content_bounds);
Expand Down Expand Up @@ -222,12 +224,12 @@ void RasterizeAndRecordBenchmarkImpl::RunOnLayer(PictureLayerImpl* layer) {
++it) {
DCHECK(*it);

PicturePileImpl* picture_pile = (*it)->picture_pile();
RasterSource* raster_source = (*it)->raster_source();
gfx::Rect content_rect = (*it)->content_rect();
float contents_scale = (*it)->contents_scale();

scoped_refptr<BenchmarkRasterTask> benchmark_raster_task(
new BenchmarkRasterTask(picture_pile,
new BenchmarkRasterTask(raster_source,
content_rect,
contents_scale,
rasterize_repeat_count_));
Expand Down
41 changes: 20 additions & 21 deletions cc/layers/picture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {

PictureLayer::PictureLayer(ContentLayerClient* client)
: client_(client),
pile_(make_scoped_refptr(new PicturePile())),
instrumentation_object_tracker_(id()),
update_source_frame_number_(-1),
can_use_lcd_text_last_frame_(can_use_lcd_text()) {
Expand All @@ -40,29 +39,29 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
// Update may not get called for an empty layer, so resize here instead.
// Using layer_impl because either bounds() or paint_properties().bounds
// may disagree and either one could have been pushed to layer_impl.
pile_->SetEmptyBounds();
pile_.SetEmptyBounds();
} else {
// If update called, then pile size must match bounds pushed to impl layer.
DCHECK_IMPLIES(
update_source_frame_number_ == layer_tree_host()->source_frame_number(),
layer_impl->bounds().ToString() == pile_->tiling_size().ToString());
layer_impl->bounds().ToString() == pile_.tiling_size().ToString());
}

// 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->pile_ = PicturePileImpl::CreateFromOther(pile_.get());
layer_impl->pile_ = PicturePileImpl::CreateFromOther(&pile_);
}

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(
pile_.SetMinContentsScale(host->settings().minimum_contents_scale);
pile_.SetTileGridSize(host->settings().default_tile_grid_size);
pile_.set_slow_down_raster_scale_factor(
host->debug_state().slow_down_raster_scale_factor);
pile_->set_show_debug_picture_borders(
pile_.set_show_debug_picture_borders(
host->debug_state().show_picture_borders);
}
}
Expand Down Expand Up @@ -92,7 +91,7 @@ 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()) {
pile_.tiling_size() == layer_size && pending_invalidation_.IsEmpty()) {
// Only early out if the visible content rect of this layer hasn't changed.
return updated;
}
Expand Down Expand Up @@ -120,16 +119,16 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
// for them.
DCHECK(client_);
updated |=
pile_->UpdateAndExpandInvalidation(client_,
&pile_invalidation_,
SafeOpaqueBackgroundColor(),
contents_opaque(),
client_->FillsBoundsCompletely(),
layer_size,
visible_layer_rect,
update_source_frame_number_,
Picture::RECORD_NORMALLY,
rendering_stats_instrumentation());
pile_.UpdateAndExpandInvalidation(client_,
&pile_invalidation_,
SafeOpaqueBackgroundColor(),
contents_opaque(),
client_->FillsBoundsCompletely(),
layer_size,
visible_layer_rect,
update_source_frame_number_,
Picture::RECORD_NORMALLY,
rendering_stats_instrumentation());
last_updated_visible_content_rect_ = visible_content_rect();

if (updated) {
Expand All @@ -144,7 +143,7 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
}

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

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

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

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

ContentLayerClient* client() { return client_; }

PicturePile* GetPicturePileForTesting() const { return pile_.get(); }
PicturePile* GetPicturePileForTesting() { return &pile_; }

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

private:
ContentLayerClient* client_;
scoped_refptr<PicturePile> pile_;
PicturePile pile_;
devtools_instrumentation::
ScopedLayerObjectTracker instrumentation_object_tracker_;
// Invalidation to use the next time update is called.
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
flags);
}

PicturePileImpl* PictureLayerImpl::GetPile() {
RasterSource* PictureLayerImpl::GetRasterSource() {
return pile_.get();
}

Expand Down
2 changes: 1 addition & 1 deletion cc/layers/picture_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CC_EXPORT PictureLayerImpl
// PictureLayerTilingClient overrides.
scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling,
const gfx::Rect& content_rect) override;
PicturePileImpl* GetPile() override;
RasterSource* GetRasterSource() override;
gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override;
const Region* GetPendingInvalidation() override;
const PictureLayerTiling* GetPendingOrActiveTwinTiling(
Expand Down
14 changes: 7 additions & 7 deletions cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class PictureLayerImplTest : public testing::Test {
iter;
++iter) {
EXPECT_TRUE(*iter);
EXPECT_EQ(pile, iter->picture_pile());
EXPECT_EQ(pile, iter->raster_source());
}
}

Expand Down Expand Up @@ -540,9 +540,9 @@ TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
EXPECT_TRUE(*iter);
EXPECT_FALSE(iter.geometry_rect().IsEmpty());
if (iter.geometry_rect().Intersects(content_invalidation))
EXPECT_EQ(pending_pile.get(), iter->picture_pile());
EXPECT_EQ(pending_pile.get(), iter->raster_source());
else
EXPECT_EQ(active_pile.get(), iter->picture_pile());
EXPECT_EQ(active_pile.get(), iter->raster_source());
}
}
}
Expand Down Expand Up @@ -609,9 +609,9 @@ TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) {
iter.geometry_rect().bottom() >= active_content_bounds.height() ||
active_tiles[0]->content_rect().size() !=
pending_tiles[0]->content_rect().size()) {
EXPECT_EQ(pending_pile.get(), iter->picture_pile());
EXPECT_EQ(pending_pile.get(), iter->raster_source());
} else {
EXPECT_EQ(active_pile.get(), iter->picture_pile());
EXPECT_EQ(active_pile.get(), iter->raster_source());
}
}
}
Expand Down Expand Up @@ -664,9 +664,9 @@ TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) {
iter.full_tile_geometry_rect());

if (in_pending && !in_active)
EXPECT_EQ(pending_pile.get(), iter->picture_pile());
EXPECT_EQ(pending_pile.get(), iter->raster_source());
else if (in_active)
EXPECT_EQ(active_pile.get(), iter->picture_pile());
EXPECT_EQ(active_pile.get(), iter->raster_source());
else
EXPECT_FALSE(*iter);
}
Expand Down
2 changes: 1 addition & 1 deletion cc/output/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ void GLRenderer::DrawPictureQuad(const DrawingFrame* frame,
}

SkCanvas canvas(on_demand_tile_raster_bitmap_);
quad->picture_pile->RasterToBitmap(
quad->picture_pile->PlaybackToCanvas(
&canvas, quad->content_rect, quad->contents_scale, NULL);

uint8_t* bitmap_pixels = NULL;
Expand Down
6 changes: 3 additions & 3 deletions cc/resources/bitmap_raster_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "base/debug/trace_event_argument.h"
#include "base/strings/stringprintf.h"
#include "cc/debug/traced_value.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/raster_buffer.h"
#include "cc/resources/raster_source.h"
#include "cc/resources/resource.h"

namespace cc {
Expand All @@ -24,11 +24,11 @@ class RasterBufferImpl : public RasterBuffer {
: lock_(resource_provider, resource->id()) {}

// Overridden from RasterBuffer:
void Playback(const PicturePileImpl* picture_pile,
void Playback(const RasterSource* raster_source,
const gfx::Rect& rect,
float scale,
RenderingStatsInstrumentation* stats) override {
picture_pile->RasterToBitmap(lock_.sk_canvas(), rect, scale, stats);
raster_source->PlaybackToCanvas(lock_.sk_canvas(), rect, scale, stats);
}

private:
Expand Down
8 changes: 4 additions & 4 deletions cc/resources/gpu_raster_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "base/debug/trace_event.h"
#include "cc/output/context_provider.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/raster_buffer.h"
#include "cc/resources/raster_source.h"
#include "cc/resources/resource.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/scoped_gpu_raster.h"
Expand All @@ -34,14 +34,14 @@ class RasterBufferImpl : public RasterBuffer {
use_distance_field_text_(use_distance_field_text) {}

// Overridden from RasterBuffer:
void Playback(const PicturePileImpl* picture_pile,
void Playback(const RasterSource* raster_source,
const gfx::Rect& rect,
float scale,
RenderingStatsInstrumentation* stats) override {
// Turn on distance fields for layers that have ever animated.
bool use_distance_field_text =
use_distance_field_text_ ||
picture_pile->likely_to_be_used_for_transform_animation();
raster_source->SuitableForDistanceFieldText();
SkSurface* sk_surface = lock_.GetSkSurface(use_distance_field_text);

if (!sk_surface)
Expand All @@ -53,7 +53,7 @@ class RasterBufferImpl : public RasterBuffer {
skia::SharePtr(recorder.beginRecording(size.width(), size.height()));

canvas->save();
picture_pile->RasterToBitmap(canvas.get(), rect, scale, stats);
raster_source->PlaybackToCanvas(canvas.get(), rect, scale, stats);
canvas->restore();

// Add the canvas and recorded picture to |multi_picture_draw_|.
Expand Down
4 changes: 2 additions & 2 deletions cc/resources/one_copy_raster_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RasterBufferImpl : public RasterBuffer {
}

// Overridden from RasterBuffer:
void Playback(const PicturePileImpl* picture_pile,
void Playback(const RasterSource* raster_source,
const gfx::Rect& rect,
float scale,
RenderingStatsInstrumentation* stats) override {
Expand All @@ -63,7 +63,7 @@ class RasterBufferImpl : public RasterBuffer {
raster_resource_->format(),
raster_resource_->size(),
gpu_memory_buffer->GetStride(),
picture_pile,
raster_source,
rect,
scale,
stats);
Expand Down
4 changes: 2 additions & 2 deletions cc/resources/picture_layer_tiling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ void PictureLayerTiling::UpdateTilesToCurrentPile(
Invalidate(layer_invalidation);
}

PicturePileImpl* pile = client_->GetPile();
RasterSource* raster_source = client_->GetRasterSource();
for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it)
it->second->set_picture_pile(pile);
it->second->set_raster_source(raster_source);
VerifyLiveTilesRect();
}

Expand Down
2 changes: 1 addition & 1 deletion cc/resources/picture_layer_tiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CC_EXPORT PictureLayerTilingClient {
virtual scoped_refptr<Tile> CreateTile(
PictureLayerTiling* tiling,
const gfx::Rect& content_rect) = 0;
virtual PicturePileImpl* GetPile() = 0;
virtual RasterSource* GetRasterSource() = 0;
virtual gfx::Size CalculateTileSize(
const gfx::Size& content_bounds) const = 0;
// This invalidation region defines the area (if any, it can by null) that
Expand Down
6 changes: 3 additions & 3 deletions cc/resources/picture_layer_tiling_set_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ class PictureLayerTilingSetSyncTest : public testing::Test {
}

for (size_t i = 0; i < target_->num_tilings(); ++i)
ValidateTiling(target_->tiling_at(i), target_client_.GetPile());
ValidateTiling(target_->tiling_at(i), target_client_.GetRasterSource());
}

void ValidateTiling(const PictureLayerTiling* tiling,
const PicturePileImpl* pile) {
const RasterSource* raster_source) {
if (tiling->tiling_size().IsEmpty()) {
EXPECT_TRUE(tiling->live_tiles_rect().IsEmpty());
} else if (!tiling->live_tiles_rect().IsEmpty()) {
Expand All @@ -370,7 +370,7 @@ class PictureLayerTilingSetSyncTest : public testing::Test {
for (size_t i = 0; i < tiles.size(); ++i) {
const Tile* tile = tiles[i];
ASSERT_TRUE(!!tile);
EXPECT_EQ(tile->picture_pile(), pile);
EXPECT_EQ(tile->raster_source(), raster_source);
EXPECT_TRUE(tile->content_rect().Intersects(tiling->live_tiles_rect()))
<< "All tiles must be inside the live tiles rect."
<< " Tile rect: " << tile->content_rect().ToString()
Expand Down
Loading

0 comments on commit 394e2b5

Please sign in to comment.