| 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..138386247fbd1bc5af50230cc64b2e9c46e24d40
|
| --- /dev/null
|
| +++ b/cc/resources/gpu_rasterizer.cc
|
| @@ -0,0 +1,156 @@
|
| +// 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;
|
| +
|
| +} // 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() {
|
| +}
|
| +
|
| +enum Rasterizer::PrepareTilesMode GpuRasterizer::PrepareTilesMode() {
|
| + return tile_prepare_enabled_ ? PREPARE_PRIORITIZED_TILES : PREPARE_NONE;
|
| +}
|
| +
|
| +void GpuRasterizer::RasterizeTiles(const TileVector& tiles,
|
| + ResourcePool* resource_pool,
|
| + TileManager* tile_manager) {
|
| + ScopedGpuRaster gpu_raster(context_provider_);
|
| +
|
| + std::vector<base::Closure> completion_callbacks;
|
| + completion_callbacks.reserve(tiles.size());
|
| +
|
| + 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);
|
| +
|
| + completion_callbacks.push_back(base::Bind(
|
| + &TileManager::CompleteRasterTask, base::Unretained(tile_manager),
|
| + tile->id(), base::Passed(&resource), analysis));
|
| + }
|
| +
|
| + multi_picture_draw_.draw();
|
| +
|
| + for (auto callback : completion_callbacks) {
|
| + callback.Run();
|
| + }
|
| +}
|
| +
|
| +void GpuRasterizer::Analyze(const Tile* tile,
|
| + RasterSource::SolidColorAnalysis* analysis) {
|
| + const ManagedTileState& mts = tile->managed_state();
|
| + const void* tile_id = static_cast<const void*>(tile);
|
| + frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task(
|
| + tile_id, mts.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 ManagedTileState& mts = tile->managed_state();
|
| + const void* tile_id = static_cast<const void*>(tile);
|
| + frame_viewer_instrumentation::ScopedRasterTask raster_task(
|
| + tile_id, mts.resolution, tile->source_frame_number(), tile->layer_id());
|
| + devtools_instrumentation::ScopedLayerTask layer_task(
|
| + devtools_instrumentation::kRasterTask, 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
|
|
|