Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: cc/resources/gpu_rasterizer.cc

Issue 807233002: cc: GPU rasterize tiles synchronously in PrepareToDraw. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed 2 lines when splitting this from patch 743023002. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/gpu_tile_task_worker_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/gpu_rasterizer.h"
6
7 #include <algorithm>
8
9 #include "base/bind.h"
10 #include "base/debug/trace_event.h"
11 #include "base/metrics/histogram.h"
12 #include "cc/debug/devtools_instrumentation.h"
13 #include "cc/debug/frame_viewer_instrumentation.h"
14 #include "cc/output/context_provider.h"
15 #include "cc/resources/raster_buffer.h"
16 #include "cc/resources/raster_source.h"
17 #include "cc/resources/resource.h"
18 #include "cc/resources/resource_provider.h"
19 #include "cc/resources/scoped_gpu_raster.h"
20 #include "cc/resources/tile_manager.h"
21 #include "gpu/command_buffer/client/gles2_interface.h"
22 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
23 #include "third_party/skia/include/core/SkPictureRecorder.h"
24 #include "third_party/skia/include/core/SkSurface.h"
25 #include "third_party/skia/include/gpu/GrContext.h"
26
27 namespace cc {
28 namespace {
29
30 // Flag to indicate whether we should try and detect that
31 // a tile is of solid color.
32 const bool kUseColorEstimator = true;
33
34 } // namespace
35
36 // static
37 scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
38 ContextProvider* context_provider,
39 ResourceProvider* resource_provider,
40 bool use_distance_field_text,
41 bool tile_prepare_enabled) {
42 return make_scoped_ptr<GpuRasterizer>(
43 new GpuRasterizer(context_provider, resource_provider,
44 use_distance_field_text, tile_prepare_enabled));
45 }
46
47 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
48 ResourceProvider* resource_provider,
49 bool use_distance_field_text,
50 bool tile_prepare_enabled)
51 : context_provider_(context_provider),
52 resource_provider_(resource_provider),
53 use_distance_field_text_(use_distance_field_text),
54 tile_prepare_enabled_(tile_prepare_enabled) {
55 DCHECK(context_provider_);
56 }
57
58 GpuRasterizer::~GpuRasterizer() {
59 }
60
61 enum Rasterizer::PrepareTilesMode GpuRasterizer::PrepareTilesMode() {
62 return tile_prepare_enabled_ ? PREPARE_PRIORITIZED_TILES : PREPARE_NONE;
63 }
64
65 void GpuRasterizer::RasterizeTiles(const TileVector& tiles,
66 ResourcePool* resource_pool,
67 TileManager* tile_manager) {
68 ScopedGpuRaster gpu_raster(context_provider_);
69
70 std::vector<base::Closure> completion_callbacks;
71 completion_callbacks.reserve(tiles.size());
72
73 for (auto tile : tiles) {
74 scoped_ptr<ScopedResource> resource =
75 resource_pool->AcquireResource(tile->size());
76 const ScopedResource* const_resource = resource.get();
77
78 RasterSource::SolidColorAnalysis analysis;
79
80 if (tile->use_picture_analysis())
81 Analyze(tile, &analysis);
82
83 if (!analysis.is_solid_color)
84 Raster(tile, const_resource);
85
86 completion_callbacks.push_back(base::Bind(
87 &TileManager::CompleteRasterTask, base::Unretained(tile_manager),
88 tile->id(), base::Passed(&resource), analysis));
89 }
90
91 multi_picture_draw_.draw();
92
93 for (auto callback : completion_callbacks) {
94 callback.Run();
95 }
96 }
97
98 void GpuRasterizer::Analyze(const Tile* tile,
99 RasterSource::SolidColorAnalysis* analysis) {
100 const ManagedTileState& mts = tile->managed_state();
101 const void* tile_id = static_cast<const void*>(tile);
102 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task(
103 tile_id, mts.resolution, tile->source_frame_number(), tile->layer_id());
104
105 DCHECK(tile->raster_source());
106
107 tile->raster_source()->PerformSolidColorAnalysis(
108 tile->content_rect(), tile->contents_scale(), analysis);
109
110 // Record the solid color prediction.
111 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
112 analysis->is_solid_color);
113
114 // Clear the flag if we're not using the estimator.
115 analysis->is_solid_color &= kUseColorEstimator;
116 }
117
118 void GpuRasterizer::Raster(const Tile* tile, const ScopedResource* resource) {
119 const ManagedTileState& mts = tile->managed_state();
120 const void* tile_id = static_cast<const void*>(tile);
121 frame_viewer_instrumentation::ScopedRasterTask raster_task(
122 tile_id, mts.resolution, tile->source_frame_number(), tile->layer_id());
123 devtools_instrumentation::ScopedLayerTask layer_task(
124 devtools_instrumentation::kRasterTask, tile->layer_id());
125
126 DCHECK(tile->raster_source());
127
128 ResourceProvider::ScopedWriteLockGr lock(resource_provider_, resource->id());
129
130 // Turn on distance fields for layers that have ever animated.
131 bool use_distance_field_text =
132 use_distance_field_text_ ||
133 tile->raster_source()->ShouldAttemptToUseDistanceFieldText();
134 SkSurface* sk_surface = lock.GetSkSurface(
135 use_distance_field_text, tile->raster_source()->CanUseLCDText());
136
137 if (!sk_surface)
138 return;
139
140 SkPictureRecorder recorder;
141 gfx::Size size = resource->size();
142 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
143 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
144 recorder.beginRecording(size.width(), size.height(), NULL, flags));
145
146 canvas->save();
147 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(),
148 tile->contents_scale());
149 canvas->restore();
150
151 // Add the canvas and recorded picture to |multi_picture_draw_|.
152 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
153 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
154 }
155
156 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/gpu_tile_task_worker_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698