Skip to content

Commit

Permalink
cc: Added features for more accurate raster benchmark
Browse files Browse the repository at this point in the history
- Added debug switch to rasterize only visible tiles
- Tagged all tiles and raster tasks with their source frame number

BUG=226489

Review URL: https://chromiumcodereview.appspot.com/14975007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200736 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ernstm@chromium.org committed May 17, 2013
1 parent 884e4d7 commit 206a392
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 8 deletions.
4 changes: 4 additions & 0 deletions cc/debug/layer_tree_debug_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ LayerTreeDebugState::LayerTreeDebugState()
show_occluding_rects(false),
show_non_occluding_rects(false),
slow_down_raster_scale_factor(0),
rasterize_only_visible_content(false),
show_picture_borders(false),
record_rendering_stats_(false) {}

Expand Down Expand Up @@ -66,6 +67,8 @@ bool LayerTreeDebugState::Equal(const LayerTreeDebugState& a,
a.show_occluding_rects == b.show_occluding_rects &&
a.show_non_occluding_rects == b.show_non_occluding_rects &&
a.slow_down_raster_scale_factor == b.slow_down_raster_scale_factor &&
a.rasterize_only_visible_content ==
b.rasterize_only_visible_content &&
a.show_picture_borders == b.show_picture_borders &&
a.record_rendering_stats_ == b.record_rendering_stats_);
}
Expand All @@ -89,6 +92,7 @@ LayerTreeDebugState LayerTreeDebugState::Unite(const LayerTreeDebugState& a,

if (b.slow_down_raster_scale_factor)
r.slow_down_raster_scale_factor = b.slow_down_raster_scale_factor;
r.rasterize_only_visible_content |= b.rasterize_only_visible_content;
r.show_picture_borders |= b.show_picture_borders;

r.record_rendering_stats_ |= b.record_rendering_stats_;
Expand Down
1 change: 1 addition & 0 deletions cc/debug/layer_tree_debug_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CC_EXPORT LayerTreeDebugState {
bool show_non_occluding_rects;

int slow_down_raster_scale_factor;
bool rasterize_only_visible_content;
bool show_picture_borders;

void SetRecordRenderingStats(bool enabled);
Expand Down
3 changes: 2 additions & 1 deletion cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
content_rect,
contents_opaque() ? content_rect : gfx::Rect(),
tiling->contents_scale(),
id()));
id(),
layer_tree_impl()->source_frame_number()));
}

void PictureLayerImpl::UpdatePile(Tile* tile) {
Expand Down
6 changes: 4 additions & 2 deletions cc/resources/tile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ Tile::Tile(TileManager* tile_manager,
gfx::Rect content_rect,
gfx::Rect opaque_rect,
float contents_scale,
int layer_id)
int layer_id,
int source_frame_number)
: tile_manager_(tile_manager),
tile_size_(tile_size),
content_rect_(content_rect),
contents_scale_(contents_scale),
opaque_rect_(opaque_rect),
layer_id_(layer_id) {
layer_id_(layer_id),
source_frame_number_(source_frame_number) {
set_picture_pile(picture_pile);
tile_manager_->RegisterTile(this);
}
Expand Down
6 changes: 5 additions & 1 deletion cc/resources/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class CC_EXPORT Tile : public base::RefCounted<Tile> {
gfx::Rect content_rect,
gfx::Rect opaque_rect,
float contents_scale,
int layer_id);
int layer_id,
int source_frame_number);

PicturePileImpl* picture_pile() {
return picture_pile_.get();
Expand Down Expand Up @@ -64,6 +65,8 @@ class CC_EXPORT Tile : public base::RefCounted<Tile> {

int layer_id() const { return layer_id_; }

int source_frame_number() const { return source_frame_number_; }

void set_picture_pile(scoped_refptr<PicturePileImpl> pile) {
DCHECK(pile->CanRaster(contents_scale_, content_rect_));
picture_pile_ = pile;
Expand Down Expand Up @@ -99,6 +102,7 @@ class CC_EXPORT Tile : public base::RefCounted<Tile> {
TilePriority priority_[NUM_BIN_PRIORITIES];
ManagedTileState managed_state_;
int layer_id_;
int source_frame_number_;

DISALLOW_COPY_AND_ASSIGN(Tile);
};
Expand Down
1 change: 1 addition & 0 deletions cc/resources/tile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata(
metadata.tile_resolution = mts.resolution;
metadata.layer_id = tile.layer_id();
metadata.tile_id = &tile;
metadata.source_frame_number = tile.source_frame_number();
return metadata;
}

Expand Down
1 change: 1 addition & 0 deletions cc/resources/tile_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class CC_EXPORT TileManager : public WorkerPoolClient {
TileResolution tile_resolution;
int layer_id;
const void* tile_id;
int source_frame_number;
};

RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const;
Expand Down
2 changes: 2 additions & 0 deletions cc/resources/tile_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ TEST(TileManagerTest, OOM) {
gfx::Rect(),
gfx::Rect(),
1.0,
0,
0));
tile->SetPriority(PENDING_TREE, TilePriority());
tile->SetPriority(ACTIVE_TREE, eventual_prio);
Expand All @@ -84,6 +85,7 @@ TEST(TileManagerTest, OOM) {
gfx::Rect(),
gfx::Rect(),
1.0,
0,
0));
tile->SetPriority(PENDING_TREE, now_prio);
tile->SetPriority(ACTIVE_TREE, TilePriority());
Expand Down
1 change: 1 addition & 0 deletions cc/test/fake_picture_layer_tiling_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ scoped_refptr<Tile> FakePictureLayerTilingClient::CreateTile(
rect,
gfx::Rect(),
1,
0,
0);
}

Expand Down
21 changes: 17 additions & 4 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ bool LayerTreeHostImpl::PrepareToDraw(FrameData* frame,

void LayerTreeHostImpl::EnforceManagedMemoryPolicy(
const ManagedMemoryPolicy& policy) {

bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread(
visible_ ? policy.bytes_limit_when_visible
: policy.bytes_limit_when_not_visible,
Expand Down Expand Up @@ -996,10 +997,10 @@ void LayerTreeHostImpl::SetManagedMemoryPolicy(
// In single-thread mode, this can be called on the main thread by
// GLRenderer::OnMemoryAllocationChanged.
DebugScopedSetImplThread impl_thread(proxy_);
EnforceManagedMemoryPolicy(managed_memory_policy_);
EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
} else {
DCHECK(proxy_->IsImplThread());
EnforceManagedMemoryPolicy(managed_memory_policy_);
EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
}

if (needs_commit)
Expand Down Expand Up @@ -1345,14 +1346,26 @@ void LayerTreeHostImpl::SetVisible(bool visible) {
return;
visible_ = visible;
DidVisibilityChange(this, visible_);
EnforceManagedMemoryPolicy(managed_memory_policy_);
EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());

if (!renderer_)
return;

renderer_->SetVisible(visible);
}

ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const {
if (!debug_state_.rasterize_only_visible_content)
return managed_memory_policy_;

ManagedMemoryPolicy actual = managed_memory_policy_;
actual.priority_cutoff_when_not_visible =
ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING;
actual.priority_cutoff_when_visible =
ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY;
return actual;
}

bool LayerTreeHostImpl::InitializeRenderer(
scoped_ptr<OutputSurface> output_surface) {
// Since we will create a new resource provider, we cannot continue to use
Expand Down Expand Up @@ -1389,7 +1402,7 @@ bool LayerTreeHostImpl::InitializeRenderer(
settings_.num_raster_threads,
settings_.use_color_estimator,
rendering_stats_instrumentation_));
UpdateTileManagerMemoryPolicy(managed_memory_policy_);
UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
}

if (output_surface->capabilities().has_parent_compositor) {
Expand Down
2 changes: 2 additions & 0 deletions cc/trees/layer_tree_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler,
void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
void SetNeedsRedraw() { client_->SetNeedsRedrawOnImplThread(); }

ManagedMemoryPolicy ActualManagedMemoryPolicy() const;

size_t memory_allocation_limit_bytes() const {
return managed_memory_policy_.bytes_limit_when_visible;
}
Expand Down
29 changes: 29 additions & 0 deletions content/renderer/gpu/gpu_benchmarking_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class GpuBenchmarkingWrapper : public v8::Extension {
" native function SetNeedsDisplayOnAllLayers();"
" return SetNeedsDisplayOnAllLayers();"
"};"
"chrome.gpuBenchmarking.setRasterizeOnlyVisibleContent = function() {"
" native function SetRasterizeOnlyVisibleContent();"
" return SetRasterizeOnlyVisibleContent();"
"};"
"chrome.gpuBenchmarking.renderingStats = function() {"
" native function GetRenderingStats();"
" return GetRenderingStats();"
Expand Down Expand Up @@ -166,6 +170,8 @@ class GpuBenchmarkingWrapper : public v8::Extension {
v8::Handle<v8::String> name) OVERRIDE {
if (name->Equals(v8::String::New("SetNeedsDisplayOnAllLayers")))
return v8::FunctionTemplate::New(SetNeedsDisplayOnAllLayers);
if (name->Equals(v8::String::New("SetRasterizeOnlyVisibleContent")))
return v8::FunctionTemplate::New(SetRasterizeOnlyVisibleContent);
if (name->Equals(v8::String::New("GetRenderingStats")))
return v8::FunctionTemplate::New(GetRenderingStats);
if (name->Equals(v8::String::New("PrintToSkPicture")))
Expand Down Expand Up @@ -203,6 +209,29 @@ class GpuBenchmarkingWrapper : public v8::Extension {
return v8::Undefined();
}

static v8::Handle<v8::Value> SetRasterizeOnlyVisibleContent(
const v8::Arguments& args) {
WebFrame* web_frame = WebFrame::frameForCurrentContext();
if (!web_frame)
return v8::Undefined();

WebView* web_view = web_frame->view();
if (!web_view)
return v8::Undefined();

RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view);
if (!render_view_impl)
return v8::Undefined();

RenderWidgetCompositor* compositor = render_view_impl->compositor();
if (!compositor)
return v8::Undefined();

compositor->SetRasterizeOnlyVisibleContent();

return v8::Undefined();
}

static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) {

WebFrame* web_frame = WebFrame::frameForCurrentContext();
Expand Down
6 changes: 6 additions & 0 deletions content/renderer/gpu/render_widget_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ void RenderWidgetCompositor::SetNeedsDisplayOnAllLayers() {
layer_tree_host_->SetNeedsDisplayOnAllLayers();
}

void RenderWidgetCompositor::SetRasterizeOnlyVisibleContent() {
cc::LayerTreeDebugState current = layer_tree_host_->debug_state();
current.rasterize_only_visible_content = true;
layer_tree_host_->SetDebugState(current);
}

void RenderWidgetCompositor::GetRenderingStats(cc::RenderingStats* stats) {
layer_tree_host_->CollectRenderingStats(stats);
}
Expand Down
1 change: 1 addition & 0 deletions content/renderer/gpu/render_widget_compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RenderWidgetCompositor : public WebKit::WebLayerTreeView,
void Animate(base::TimeTicks time);
void Composite(base::TimeTicks frame_begin_time);
void SetNeedsDisplayOnAllLayers();
void SetRasterizeOnlyVisibleContent();
void GetRenderingStats(cc::RenderingStats* stats);
skia::RefPtr<SkPicture> CapturePicture();
void UpdateTopControlsState(bool enable_hiding,
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/perf_tools/rasterize_and_record_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def CustomizeBrowserOptions(self, options):
def MeasurePage(self, page, tab, results):
self._metrics = smoothness_metrics.SmoothnessMetrics(tab)

# Rasterize only what's visible
tab.ExecuteJavaScript(
'chrome.gpuBenchmarking.setRasterizeOnlyVisibleContent();')

# Wait until the page has loaded and come to a somewhat steady state
# (empirical wait time)
time.sleep(5)
Expand Down

0 comments on commit 206a392

Please sign in to comment.