Chromium Code Reviews| Index: cc/resources/gpu_rasterizer.cc |
| diff --git a/cc/resources/gpu_rasterizer.cc b/cc/resources/gpu_rasterizer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b8dda89807cc4bdc74f9beb7f3bca421cb494c6f |
| --- /dev/null |
| +++ b/cc/resources/gpu_rasterizer.cc |
| @@ -0,0 +1,146 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/resources/gpu_rasterizer.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/bind.h" |
| +#include "base/debug/trace_event.h" |
| +#include "base/metrics/histogram.h" |
| +#include "cc/debug/devtools_instrumentation.h" |
| +#include "cc/debug/frame_viewer_instrumentation.h" |
| +#include "cc/output/context_provider.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" |
| +#include "cc/resources/tile_manager.h" |
| +#include "gpu/command_buffer/client/gles2_interface.h" |
| +#include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| +#include "third_party/skia/include/core/SkPictureRecorder.h" |
| +#include "third_party/skia/include/core/SkSurface.h" |
| +#include "third_party/skia/include/gpu/GrContext.h" |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +// Flag to indicate whether we should try and detect that |
| +// a tile is of solid color. |
| +const bool kUseColorEstimator = true; |
|
vmpstr
2014/12/23 09:51:02
I know we have this elsewhere, but can you remove
hendrikw
2014/12/23 18:10:33
Sure, do you want me to remove the one in tilemana
|
| + |
| +} // namespace |
| + |
| +// static |
| +scoped_ptr<GpuRasterizer> GpuRasterizer::Create( |
| + ContextProvider* context_provider, |
| + ResourceProvider* resource_provider, |
| + bool use_distance_field_text, |
| + bool tile_prepare_enabled) { |
| + return make_scoped_ptr<GpuRasterizer>( |
| + new GpuRasterizer(context_provider, resource_provider, |
| + use_distance_field_text, tile_prepare_enabled)); |
| +} |
| + |
| +GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, |
| + ResourceProvider* resource_provider, |
| + bool use_distance_field_text, |
| + bool tile_prepare_enabled) |
| + : context_provider_(context_provider), |
| + resource_provider_(resource_provider), |
| + use_distance_field_text_(use_distance_field_text), |
| + tile_prepare_enabled_(tile_prepare_enabled) { |
| + DCHECK(context_provider_); |
| +} |
| + |
| +GpuRasterizer::~GpuRasterizer() { |
| +} |
| + |
| +PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { |
| + return tile_prepare_enabled_ ? PrepareTilesMode::PREPARE_PRIORITIZED_TILES |
|
vmpstr
2014/12/23 09:51:02
It feels a bit awkward to pass this bool, since we
hendrikw
2014/12/23 18:10:33
I don't know what the plans for this are, I though
vmiura
2014/12/23 18:33:13
In my patch it's turned on by a "--enable-tile-pre
|
| + : PrepareTilesMode::PREPARE_NONE; |
| +} |
| + |
| +void GpuRasterizer::RasterizeTiles(const TileVector& tiles, |
| + ResourcePool* resource_pool, |
| + TileManager* tile_manager) { |
|
vmpstr
2014/12/23 09:51:02
:\ I'm not really a fan of rasterizer being owned
hendrikw
2014/12/23 18:10:33
Not a fan? We do this _EVERYWHERE_! :)
Sure, I'
|
| + ScopedGpuRaster gpu_raster(context_provider_); |
| + |
| + for (auto tile : tiles) { |
| + scoped_ptr<ScopedResource> resource = |
| + resource_pool->AcquireResource(tile->size()); |
| + const ScopedResource* const_resource = resource.get(); |
| + |
| + RasterSource::SolidColorAnalysis analysis; |
| + |
| + if (tile->use_picture_analysis()) |
| + Analyze(tile, &analysis); |
| + |
| + if (!analysis.is_solid_color) |
| + Raster(tile, const_resource); |
|
vmpstr
2014/12/23 09:51:02
Should this be called something like "AppendToMult
hendrikw
2014/12/23 18:10:33
Yes!
I'll also rename Analyze to PerformSolidColo
|
| + |
| + tile_manager->CompleteRasterTask(tile->id(), resource.Pass(), analysis); |
| + } |
| + |
| + multi_picture_draw_.draw(); |
| +} |
| + |
| +void GpuRasterizer::Analyze(const Tile* tile, |
| + RasterSource::SolidColorAnalysis* analysis) { |
| + const void* tile_id = static_cast<const void*>(tile); |
| + frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( |
| + tile_id, tile->combined_priority().resolution, |
| + tile->source_frame_number(), tile->layer_id()); |
| + |
| + DCHECK(tile->raster_source()); |
| + |
| + tile->raster_source()->PerformSolidColorAnalysis( |
| + tile->content_rect(), tile->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; |
| +} |
| + |
| +void GpuRasterizer::Raster(const Tile* tile, const ScopedResource* resource) { |
| + const void* tile_id = static_cast<const void*>(tile); |
| + frame_viewer_instrumentation::ScopedRasterTask raster_task( |
| + tile_id, tile->combined_priority().resolution, |
| + tile->source_frame_number(), tile->layer_id()); |
| + |
| + DCHECK(tile->raster_source()); |
| + |
| + ResourceProvider::ScopedWriteLockGr lock(resource_provider_, resource->id()); |
| + |
| + // Turn on distance fields for layers that have ever animated. |
| + bool use_distance_field_text = |
| + use_distance_field_text_ || |
| + tile->raster_source()->ShouldAttemptToUseDistanceFieldText(); |
| + SkSurface* sk_surface = lock.GetSkSurface( |
| + use_distance_field_text, tile->raster_source()->CanUseLCDText()); |
| + |
| + if (!sk_surface) |
| + return; |
| + |
| + SkPictureRecorder recorder; |
| + gfx::Size size = resource->size(); |
| + const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; |
| + skia::RefPtr<SkCanvas> canvas = skia::SharePtr( |
| + recorder.beginRecording(size.width(), size.height(), NULL, flags)); |
| + |
| + canvas->save(); |
| + tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), |
| + tile->contents_scale()); |
| + canvas->restore(); |
| + |
| + // Add the canvas and recorded picture to |multi_picture_draw_|. |
| + skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| + multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); |
| +} |
| + |
| +} // namespace cc |