diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 21:35:29 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 21:35:29 +0000 |
commit | 206b4aef073e25af30ca9e2097889b7d65151520 (patch) | |
tree | 57919a3d36c5e527af64ccc33182656d4fc293b0 /cc | |
parent | 1ea96d9ab9ef4e4d8cd460ac01664af583a2e024 (diff) | |
download | chromium_src-206b4aef073e25af30ca9e2097889b7d65151520.zip chromium_src-206b4aef073e25af30ca9e2097889b7d65151520.tar.gz chromium_src-206b4aef073e25af30ca9e2097889b7d65151520.tar.bz2 |
cc: Combine analysis and raster
This changes the analysis of PicturePiles from optimistic (hoping to
save raster work by checking if a rastered bitmap would be a solid
color) to pessimistic (assuming most bitmaps are not solid colors and
just checking afterwards). It does this by rastering to both an
AnalysisCanvas and a normal SkCanvas via SkNWayCanvas and then
checking the results afterwards.
R=reveman@chromium.org, senorblanco@chromium.org
BUG=310796
Review URL: https://codereview.chromium.org/63443003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/resources/picture.cc | 3 | ||||
-rw-r--r-- | cc/resources/picture.h | 1 | ||||
-rw-r--r-- | cc/resources/picture_pile_impl.cc | 49 | ||||
-rw-r--r-- | cc/resources/picture_pile_impl.h | 16 | ||||
-rw-r--r-- | cc/resources/raster_worker_pool.cc | 79 | ||||
-rw-r--r-- | cc/test/fake_picture_pile_impl.cc | 23 | ||||
-rw-r--r-- | cc/test/fake_picture_pile_impl.h | 4 | ||||
-rw-r--r-- | cc/test/skia_common.cc | 2 |
8 files changed, 78 insertions, 99 deletions
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc index 7e278f8..1b4c43c 100644 --- a/cc/resources/picture.cc +++ b/cc/resources/picture.cc @@ -296,7 +296,6 @@ void Picture::GatherPixelRefs( int Picture::Raster( SkCanvas* canvas, - SkDrawPictureCallback* callback, const Region& negated_content_region, float contents_scale) { TRACE_EVENT_BEGIN1( @@ -314,7 +313,7 @@ int Picture::Raster( canvas->scale(contents_scale, contents_scale); canvas->translate(layer_rect_.x(), layer_rect_.y()); - picture_->draw(canvas, callback); + picture_->draw(canvas); SkIRect bounds; canvas->getClipDeviceBounds(&bounds); canvas->restore(); diff --git a/cc/resources/picture.h b/cc/resources/picture.h index 4eb238a..b2e5b29 100644 --- a/cc/resources/picture.h +++ b/cc/resources/picture.h @@ -71,7 +71,6 @@ 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); diff --git a/cc/resources/picture_pile_impl.cc b/cc/resources/picture_pile_impl.cc index 44a52b8..c540f6c 100644 --- a/cc/resources/picture_pile_impl.cc +++ b/cc/resources/picture_pile_impl.cc @@ -74,19 +74,11 @@ void PicturePileImpl::RasterDirect( float contents_scale, RenderingStatsInstrumentation* rendering_stats_instrumentation) { RasterCommon(canvas, - NULL, canvas_rect, contents_scale, rendering_stats_instrumentation); } -void PicturePileImpl::RasterForAnalysis( - skia::AnalysisCanvas* canvas, - gfx::Rect canvas_rect, - float contents_scale) { - RasterCommon(canvas, canvas, canvas_rect, contents_scale, NULL); -} - void PicturePileImpl::RasterToBitmap( SkCanvas* canvas, gfx::Rect canvas_rect, @@ -135,7 +127,6 @@ void PicturePileImpl::RasterToBitmap( } RasterCommon(canvas, - NULL, canvas_rect, contents_scale, rendering_stats_instrumentation); @@ -201,7 +192,6 @@ 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) { @@ -250,7 +240,7 @@ void PicturePileImpl::RasterCommon( start_time = rendering_stats_instrumentation->StartRecording(); rasterized_pixel_count = picture->Raster( - canvas, callback, negated_clip_region, contents_scale); + canvas, negated_clip_region, contents_scale); if (rendering_stats_instrumentation) { base::TimeDelta duration = @@ -297,30 +287,6 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { return picture; } -void PicturePileImpl::AnalyzeInRect(gfx::Rect content_rect, - float contents_scale, - PicturePileImpl::Analysis* analysis) { - 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); - - analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); - analysis->has_text = canvas.HasText(); -} - PicturePileImpl::Analysis::Analysis() : is_solid_color(false), has_text(false) { @@ -376,6 +342,19 @@ 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; diff --git a/cc/resources/picture_pile_impl.h b/cc/resources/picture_pile_impl.h index 66b5f72..b99e996 100644 --- a/cc/resources/picture_pile_impl.h +++ b/cc/resources/picture_pile_impl.h @@ -52,14 +52,6 @@ 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); - - skia::RefPtr<SkPicture> GetFlattenedPicture(); struct CC_EXPORT Analysis { @@ -71,10 +63,6 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase { SkColor solid_color; }; - void AnalyzeInRect(gfx::Rect content_rect, - float contents_scale, - Analysis* analysis); - class CC_EXPORT PixelRefIterator { public: PixelRefIterator(gfx::Rect content_rect, @@ -97,6 +85,9 @@ 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: @@ -131,7 +122,6 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase { void RasterCommon( SkCanvas* canvas, - SkDrawPictureCallback* callback, gfx::Rect canvas_rect, float contents_scale, RenderingStatsInstrumentation* rendering_stats_instrumentation); diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc index 67c548f..671271c 100644 --- a/cc/resources/raster_worker_pool.cc +++ b/cc/resources/raster_worker_pool.cc @@ -13,6 +13,8 @@ #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 { @@ -31,10 +33,6 @@ 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. @@ -73,34 +71,11 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { rendering_stats_(rendering_stats), reply_(reply) {} - 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_); - - // 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) { + // Overridden from internal::RasterWorkerPoolTask: + virtual bool RunOnWorkerThread(unsigned thread_index, + void* buffer, + gfx::Size size, + int stride) OVERRIDE { TRACE_EVENT2( "cc", "RasterWorkerPoolTaskImpl::RunRasterOnThread", "data", @@ -114,9 +89,6 @@ 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); @@ -145,8 +117,22 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { break; } - SkBitmapDevice device(bitmap); - SkCanvas canvas(&device); + 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); + skia::RefPtr<SkDrawFilter> draw_filter; switch (raster_mode_) { case LOW_QUALITY_RASTER_MODE: @@ -192,18 +178,17 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { ChangeBitmapConfigIfNeeded(bitmap, buffer); - return true; - } + analysis_.is_solid_color = + analysis_canvas.GetColorIfSolid(&analysis_.solid_color); + analysis_.has_text = analysis_canvas.HasText(); - // 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); + // Record the solid color prediction. + UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", + analysis_.is_solid_color); + + return !analysis_.is_solid_color; } + virtual void CompleteOnOriginThread() OVERRIDE { reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); } diff --git a/cc/test/fake_picture_pile_impl.cc b/cc/test/fake_picture_pile_impl.cc index 989c4f9..1694b68 100644 --- a/cc/test/fake_picture_pile_impl.cc +++ b/cc/test/fake_picture_pile_impl.cc @@ -9,6 +9,7 @@ #include "cc/test/impl_side_painting_settings.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/skia_util.h" namespace cc { @@ -94,4 +95,26 @@ void FakePicturePileImpl::RerecordPile() { } } +void FakePicturePileImpl::AnalyzeInRect(gfx::Rect content_rect, + float contents_scale, + Analysis* analysis) { + // Create and raster to a bitmap of content_rect size, even though the + // analysis_rect may be smaller to simulate edge tiles where recorded content + // doesn't cover the entire content_rect. + SkBitmap empty_bitmap; + empty_bitmap.setConfig(SkBitmap::kNo_Config, + content_rect.width(), + content_rect.height()); + + gfx::Rect analysis_rect( + AnalysisRectForRaster(content_rect, contents_scale)); + skia::AnalysisDevice device(empty_bitmap, gfx::RectToSkRect(analysis_rect)); + skia::AnalysisCanvas canvas(&device); + + RasterDirect(&canvas, content_rect, contents_scale, NULL); + + analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); + analysis->has_text = canvas.HasText(); +} + } // namespace cc diff --git a/cc/test/fake_picture_pile_impl.h b/cc/test/fake_picture_pile_impl.h index ae8729e..e5750e7 100644 --- a/cc/test/fake_picture_pile_impl.h +++ b/cc/test/fake_picture_pile_impl.h @@ -29,6 +29,10 @@ class FakePicturePileImpl : public PicturePileImpl { void RemoveRecordingAt(int x, int y); void RerecordPile(); + void AnalyzeInRect(gfx::Rect content_rect, + float contents_scale, + Analysis* analysis); + void add_draw_rect(const gfx::RectF& rect) { client_.add_draw_rect(rect, default_paint_); } diff --git a/cc/test/skia_common.cc b/cc/test/skia_common.cc index 49c984d..033e625 100644 --- a/cc/test/skia_common.cc +++ b/cc/test/skia_common.cc @@ -68,7 +68,7 @@ void DrawPicture(unsigned char* buffer, SkBitmapDevice device(bitmap); SkCanvas canvas(&device); canvas.clipRect(gfx::RectToSkRect(layer_rect)); - picture->Raster(&canvas, NULL, layer_rect, 1.0f); + picture->Raster(&canvas, layer_rect, 1.0f); } void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { |