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

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

Issue 733773005: cc: GPU rasterize tiles synchronously in PrepareToDraw (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/tile.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 return make_scoped_ptr<GpuRasterizer>(new GpuRasterizer(
42 context_provider, resource_provider, use_distance_field_text));
43 }
44
45 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
46 ResourceProvider* resource_provider,
47 bool use_distance_field_text)
48 : context_provider_(context_provider),
49 resource_provider_(resource_provider),
50 use_distance_field_text_(use_distance_field_text) {
51 DCHECK(context_provider_);
52 }
53
54 GpuRasterizer::~GpuRasterizer() {
55 }
56
57 void GpuRasterizer::RasterizeTiles(const TileVector& tiles,
58 ResourcePool* resource_pool,
59 TileManager* tile_manager) {
60 ScopedGpuRaster gpu_raster(context_provider_);
61
62 std::vector<base::Closure> completion_callbacks;
63 completion_callbacks.reserve(tiles.size());
64
65 for (auto tile : tiles) {
66 scoped_ptr<ScopedResource> resource =
67 resource_pool->AcquireResource(tile->size());
68 const ScopedResource* const_resource = resource.get();
69
70 RasterSource::SolidColorAnalysis analysis;
71
72 if (tile->use_picture_analysis())
73 Analyze(tile, &analysis);
74
75 if (!analysis.is_solid_color)
76 Raster(tile, const_resource);
77
78 completion_callbacks.push_back(base::Bind(
79 &TileManager::CompleteRasterTask, base::Unretained(tile_manager),
80 tile->id(), base::Passed(&resource), analysis));
81 }
82
83 multi_picture_draw_.draw();
84
85 for (auto callback : completion_callbacks) {
86 callback.Run();
87 }
88 }
89
90 void GpuRasterizer::Analyze(const Tile* tile,
91 RasterSource::SolidColorAnalysis* analysis) {
92 const void* tile_id = static_cast<const void*>(tile);
93 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task(
94 tile_id, tile->resolution(), tile->source_frame_number(),
95 tile->layer_id());
96
97 DCHECK(tile->raster_source());
98
99 tile->raster_source()->PerformSolidColorAnalysis(
100 tile->content_rect(), tile->contents_scale(), analysis);
101
102 // Record the solid color prediction.
103 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
104 analysis->is_solid_color);
105
106 // Clear the flag if we're not using the estimator.
107 analysis->is_solid_color &= kUseColorEstimator;
108 }
109
110 void GpuRasterizer::Raster(const Tile* tile, const ScopedResource* resource) {
111 const void* tile_id = static_cast<const void*>(tile);
112 frame_viewer_instrumentation::ScopedRasterTask raster_task(
113 tile_id, tile->resolution(), tile->source_frame_number(),
114 tile->layer_id());
115 devtools_instrumentation::ScopedLayerTask layer_task(
116 devtools_instrumentation::kRasterTask, tile->layer_id());
117
118 DCHECK(tile->raster_source());
119
120 ResourceProvider::ScopedWriteLockGr lock(resource_provider_, resource->id());
121
122 // Turn on distance fields for layers that have ever animated.
123 bool use_distance_field_text =
124 use_distance_field_text_ ||
125 tile->raster_source()->ShouldAttemptToUseDistanceFieldText();
126 SkSurface* sk_surface = lock.GetSkSurface(
127 use_distance_field_text, tile->raster_source()->CanUseLCDText());
128
129 if (!sk_surface)
130 return;
131
132 SkPictureRecorder recorder;
133 gfx::Size size = resource->size();
134 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
135 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
136 recorder.beginRecording(size.width(), size.height(), NULL, flags));
137
138 canvas->save();
139 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(),
140 tile->contents_scale());
141 canvas->restore();
142
143 // Add the canvas and recorded picture to |multi_picture_draw_|.
144 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
145 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
146 }
147
148 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/tile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698