Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reason for revert: Caused a 30% rasterization regression

TBR=reveman@chromium.org,senorblanco@chromium.org,vangelis@google.com,reed@google.com
BUG=310796,332137

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243466 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
enne@chromium.org committed Jan 8, 2014
1 parent ec4a71c commit 1d80199
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 114 deletions.
2 changes: 2 additions & 0 deletions cc/debug/rasterize_and_record_benchmark_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void RasterizeAndRecordBenchmarkImpl::RunOnLayer(PictureLayerImpl* layer) {
PicturePileImpl::Analysis analysis;

base::TimeTicks start = Now();
picture_pile->AnalyzeInRect(
content_rect, contents_scale, &analysis, NULL);
picture_pile->RasterToBitmap(&canvas, content_rect, contents_scale, NULL);
base::TimeTicks end = Now();
base::TimeDelta duration = end - start;
Expand Down
6 changes: 5 additions & 1 deletion cc/debug/rendering_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ImplThreadRenderingStats::AsTraceableData() const {
void ImplThreadRenderingStats::Add(const ImplThreadRenderingStats& other) {
frame_count += other.frame_count;
rasterize_time += other.rasterize_time;
analysis_time += other.analysis_time;
rasterized_pixel_count += other.rasterized_pixel_count;
}

Expand All @@ -61,8 +62,11 @@ void RenderingStats::EnumerateFields(Enumerator* enumerator) const {
main_stats.record_time.InSecondsF());
enumerator->AddInt64("recordedPixelCount",
main_stats.recorded_pixel_count);
// Combine rasterization and analysis time as a precursor to combining
// them in the same step internally.
enumerator->AddDouble("rasterizeTime",
impl_stats.rasterize_time.InSecondsF());
impl_stats.rasterize_time.InSecondsF() +
impl_stats.analysis_time.InSecondsF());
enumerator->AddInt64("rasterizedPixelCount",
impl_stats.rasterized_pixel_count);
}
Expand Down
1 change: 1 addition & 0 deletions cc/debug/rendering_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct CC_EXPORT ImplThreadRenderingStats {

int64 frame_count;
base::TimeDelta rasterize_time;
base::TimeDelta analysis_time;
int64 rasterized_pixel_count;

ImplThreadRenderingStats();
Expand Down
9 changes: 9 additions & 0 deletions cc/debug/rendering_stats_instrumentation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ void RenderingStatsInstrumentation::AddRaster(base::TimeDelta duration,
impl_stats_.rasterized_pixel_count += pixels;
}

void RenderingStatsInstrumentation::AddAnalysis(base::TimeDelta duration,
int64 pixels) {
if (!record_rendering_stats_)
return;

base::AutoLock scoped_lock(lock_);
impl_stats_.analysis_time += duration;
}

} // namespace cc
1 change: 1 addition & 0 deletions cc/debug/rendering_stats_instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CC_EXPORT RenderingStatsInstrumentation {
void AddPaint(base::TimeDelta duration, int64 pixels);
void AddRecord(base::TimeDelta duration, int64 pixels);
void AddRaster(base::TimeDelta duration, int64 pixels);
void AddAnalysis(base::TimeDelta duration, int64 pixels);

protected:
RenderingStatsInstrumentation();
Expand Down
3 changes: 2 additions & 1 deletion cc/resources/picture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ void Picture::GatherPixelRefs(

int Picture::Raster(
SkCanvas* canvas,
SkDrawPictureCallback* callback,
const Region& negated_content_region,
float contents_scale) {
TRACE_EVENT_BEGIN1(
Expand All @@ -315,7 +316,7 @@ int Picture::Raster(

canvas->scale(contents_scale, contents_scale);
canvas->translate(layer_rect_.x(), layer_rect_.y());
picture_->draw(canvas);
picture_->draw(canvas, callback);
SkIRect bounds;
canvas->getClipDeviceBounds(&bounds);
canvas->restore();
Expand Down
1 change: 1 addition & 0 deletions cc/resources/picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CC_EXPORT Picture
// Apply this scale and raster the negated region into the canvas. See comment
// in PicturePileImpl::RasterCommon for explanation on negated content region.
int Raster(SkCanvas* canvas,
SkDrawPictureCallback* callback,
const Region& negated_content_region,
float contents_scale);

Expand Down
78 changes: 59 additions & 19 deletions cc/resources/picture_pile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,20 @@ void PicturePileImpl::RasterDirect(
float contents_scale,
RenderingStatsInstrumentation* rendering_stats_instrumentation) {
RasterCommon(canvas,
NULL,
canvas_rect,
contents_scale,
rendering_stats_instrumentation);
rendering_stats_instrumentation,
false);
}

void PicturePileImpl::RasterForAnalysis(
skia::AnalysisCanvas* canvas,
gfx::Rect canvas_rect,
float contents_scale,
RenderingStatsInstrumentation* stats_instrumentation) {
RasterCommon(
canvas, canvas, canvas_rect, contents_scale, stats_instrumentation, true);
}

void PicturePileImpl::RasterToBitmap(
Expand Down Expand Up @@ -127,9 +138,11 @@ void PicturePileImpl::RasterToBitmap(
}

RasterCommon(canvas,
NULL,
canvas_rect,
contents_scale,
rendering_stats_instrumentation);
rendering_stats_instrumentation,
false);
}

void PicturePileImpl::CoalesceRasters(gfx::Rect canvas_rect,
Expand Down Expand Up @@ -193,9 +206,11 @@ void PicturePileImpl::CoalesceRasters(gfx::Rect canvas_rect,

void PicturePileImpl::RasterCommon(
SkCanvas* canvas,
SkDrawPictureCallback* callback,
gfx::Rect canvas_rect,
float contents_scale,
RenderingStatsInstrumentation* rendering_stats_instrumentation) {
RenderingStatsInstrumentation* rendering_stats_instrumentation,
bool is_analysis) {
DCHECK(contents_scale >= min_contents_scale_);

canvas->translate(-canvas_rect.x(), -canvas_rect.y());
Expand Down Expand Up @@ -241,7 +256,7 @@ void PicturePileImpl::RasterCommon(
start_time = rendering_stats_instrumentation->StartRecording();

rasterized_pixel_count = picture->Raster(
canvas, negated_clip_region, contents_scale);
canvas, callback, negated_clip_region, contents_scale);

if (rendering_stats_instrumentation) {
base::TimeDelta duration =
Expand All @@ -251,8 +266,13 @@ void PicturePileImpl::RasterCommon(
}

if (rendering_stats_instrumentation) {
rendering_stats_instrumentation->AddRaster(best_duration,
rasterized_pixel_count);
if (is_analysis) {
rendering_stats_instrumentation->AddAnalysis(best_duration,
rasterized_pixel_count);
} else {
rendering_stats_instrumentation->AddRaster(best_duration,
rasterized_pixel_count);
}
}
}

Expand Down Expand Up @@ -288,6 +308,39 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() {
return picture;
}

void PicturePileImpl::AnalyzeInRect(
gfx::Rect content_rect,
float contents_scale,
PicturePileImpl::Analysis* analysis) {
AnalyzeInRect(content_rect, contents_scale, analysis, NULL);
}

void PicturePileImpl::AnalyzeInRect(
gfx::Rect content_rect,
float contents_scale,
PicturePileImpl::Analysis* analysis,
RenderingStatsInstrumentation* stats_instrumentation) {
DCHECK(analysis);
TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect");

gfx::Rect layer_rect = gfx::ScaleToEnclosingRect(
content_rect, 1.0f / contents_scale);

layer_rect.Intersect(gfx::Rect(tiling_.total_size()));

SkBitmap empty_bitmap;
empty_bitmap.setConfig(SkBitmap::kNo_Config,
layer_rect.width(),
layer_rect.height());
skia::AnalysisDevice device(empty_bitmap);
skia::AnalysisCanvas canvas(&device);

RasterForAnalysis(&canvas, layer_rect, 1.0f, stats_instrumentation);

analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color);
analysis->has_text = canvas.HasText();
}

PicturePileImpl::Analysis::Analysis()
: is_solid_color(false),
has_text(false) {
Expand Down Expand Up @@ -344,19 +397,6 @@ void PicturePileImpl::PixelRefIterator::AdvanceToTilePictureWithPixelRefs() {
}
}

gfx::Rect PicturePileImpl::AnalysisRectForRaster(gfx::Rect content_rect,
float contents_scale) const {
// Bound the analysis rect to just the pile content.
gfx::Rect content_bounds(
gfx::ScaleToEnclosingRect(gfx::Rect(size()), contents_scale));
gfx::Rect analysis_rect(content_rect);
analysis_rect.Intersect(content_bounds);
// Move to canvas space.
analysis_rect.set_origin(gfx::Point());

return analysis_rect;
}

void PicturePileImpl::DidBeginTracing() {
gfx::Rect layer_rect(tiling_.total_size());
std::set<void*> processed_pictures;
Expand Down
24 changes: 20 additions & 4 deletions cc/resources/picture_pile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
float contents_scale,
RenderingStatsInstrumentation* stats_instrumentation);

// Called when analyzing a tile. We can use AnalysisCanvas as
// SkDrawPictureCallback, which allows us to early out from analysis.
void RasterForAnalysis(
skia::AnalysisCanvas* canvas,
gfx::Rect canvas_rect,
float contents_scale,
RenderingStatsInstrumentation* stats_instrumentation);

skia::RefPtr<SkPicture> GetFlattenedPicture();

struct CC_EXPORT Analysis {
Expand All @@ -63,6 +71,15 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
SkColor solid_color;
};

void AnalyzeInRect(gfx::Rect content_rect,
float contents_scale,
Analysis* analysis);

void AnalyzeInRect(gfx::Rect content_rect,
float contents_scale,
Analysis* analysis,
RenderingStatsInstrumentation* stats_instrumentation);

class CC_EXPORT PixelRefIterator {
public:
PixelRefIterator(gfx::Rect content_rect,
Expand All @@ -85,9 +102,6 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
std::set<const void*> processed_pictures_;
};

gfx::Rect AnalysisRectForRaster(gfx::Rect content_rect,
float contents_scale) const;

void DidBeginTracing();

protected:
Expand Down Expand Up @@ -122,9 +136,11 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {

void RasterCommon(
SkCanvas* canvas,
SkDrawPictureCallback* callback,
gfx::Rect canvas_rect,
float contents_scale,
RenderingStatsInstrumentation* rendering_stats_instrumentation);
RenderingStatsInstrumentation* rendering_stats_instrumentation,
bool is_analysis);

// Once instantiated, |clones_for_drawing_| can't be modified. This
// guarantees thread-safe access during the life time of a PicturePileImpl
Expand Down
80 changes: 48 additions & 32 deletions cc/resources/raster_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "skia/ext/lazy_pixel_ref.h"
#include "skia/ext/paint_simplifier.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/utils/SkNWayCanvas.h"
#include "ui/gfx/skia_util.h"

namespace cc {

Expand All @@ -33,6 +31,10 @@ class IdentityAllocator : public SkBitmap::Allocator {
void* buffer_;
};

// Flag to indicate whether we should try and detect that
// a tile is of solid color.
const bool kUseColorEstimator = true;

class DisableLCDTextFilter : public SkDrawFilter {
public:
// SkDrawFilter interface.
Expand Down Expand Up @@ -71,11 +73,35 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
rendering_stats_(rendering_stats),
reply_(reply) {}

// Overridden from internal::RasterWorkerPoolTask:
virtual bool RunOnWorkerThread(unsigned thread_index,
void* buffer,
gfx::Size size,
int stride) OVERRIDE {
void RunAnalysisOnThread(unsigned thread_index) {
TRACE_EVENT1("cc",
"RasterWorkerPoolTaskImpl::RunAnalysisOnThread",
"data",
TracedValue::FromValue(DataAsValue().release()));

DCHECK(picture_pile_.get());
DCHECK(rendering_stats_);

PicturePileImpl* picture_clone =
picture_pile_->GetCloneForDrawingOnThread(thread_index);

DCHECK(picture_clone);

picture_clone->AnalyzeInRect(
content_rect_, contents_scale_, &analysis_, rendering_stats_);

// Record the solid color prediction.
UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
analysis_.is_solid_color);

// Clear the flag if we're not using the estimator.
analysis_.is_solid_color &= kUseColorEstimator;
}

bool RunRasterOnThread(unsigned thread_index,
void* buffer,
gfx::Size size,
int stride) {
TRACE_EVENT2(
"cc", "RasterWorkerPoolTaskImpl::RunRasterOnThread",
"data",
Expand All @@ -89,6 +115,9 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
DCHECK(picture_pile_.get());
DCHECK(buffer);

if (analysis_.is_solid_color)
return false;

PicturePileImpl* picture_clone =
picture_pile_->GetCloneForDrawingOnThread(thread_index);

Expand Down Expand Up @@ -117,22 +146,8 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
break;
}

SkBitmap empty_bitmap;
empty_bitmap.setConfig(
SkBitmap::kNo_Config, content_rect_.width(), content_rect_.height());
gfx::Rect analysis_rect(
picture_clone->AnalysisRectForRaster(content_rect_, contents_scale_));
skia::AnalysisDevice analysis_device(empty_bitmap,
gfx::RectToSkRect(analysis_rect));
skia::AnalysisCanvas analysis_canvas(&analysis_device);

SkBitmapDevice raster_device(bitmap);
SkCanvas raster_canvas(&raster_device);

SkNWayCanvas canvas(content_rect_.width(), content_rect_.height());
canvas.addCanvas(&analysis_canvas);
canvas.addCanvas(&raster_canvas);

SkBitmapDevice device(bitmap);
SkCanvas canvas(&device);
skia::RefPtr<SkDrawFilter> draw_filter;
switch (raster_mode_) {
case LOW_QUALITY_RASTER_MODE:
Expand Down Expand Up @@ -178,17 +193,18 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {

ChangeBitmapConfigIfNeeded(bitmap, buffer);

analysis_.is_solid_color =
analysis_canvas.GetColorIfSolid(&analysis_.solid_color);
analysis_.has_text = analysis_canvas.HasText();

// Record the solid color prediction.
UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
analysis_.is_solid_color);

return !analysis_.is_solid_color;
return true;
}

// Overridden from internal::RasterWorkerPoolTask:
virtual bool RunOnWorkerThread(unsigned thread_index,
void* buffer,
gfx::Size size,
int stride)
OVERRIDE {
RunAnalysisOnThread(thread_index);
return RunRasterOnThread(thread_index, buffer, size, stride);
}
virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled());
}
Expand Down
Loading

0 comments on commit 1d80199

Please sign in to comment.