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

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

Issue 820743002: cc: GPU rasterize tiles synchronously in PrepareToDraw. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 5 years, 11 months 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
29 // static
30 scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
31 ContextProvider* context_provider,
32 ResourceProvider* resource_provider,
33 bool use_distance_field_text,
34 bool tile_prepare_enabled) {
35 return make_scoped_ptr<GpuRasterizer>(
36 new GpuRasterizer(context_provider, resource_provider,
37 use_distance_field_text, tile_prepare_enabled));
38 }
39
40 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
41 ResourceProvider* resource_provider,
42 bool use_distance_field_text,
43 bool tile_prepare_enabled)
44 : context_provider_(context_provider),
45 resource_provider_(resource_provider),
46 use_distance_field_text_(use_distance_field_text),
47 tile_prepare_enabled_(tile_prepare_enabled) {
48 DCHECK(context_provider_);
49 }
50
51 GpuRasterizer::~GpuRasterizer() {
52 }
53
54 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() {
55 return tile_prepare_enabled_ ? PrepareTilesMode::PREPARE_PRIORITIZED_TILES
56 : PrepareTilesMode::PREPARE_NONE;
57 }
58
59 void GpuRasterizer::RasterizeTiles(
60 const TileVector& tiles,
61 ResourcePool* resource_pool,
62 const UpdateTileDrawInfoCallback& update_tile_draw_info) {
63 ScopedGpuRaster gpu_raster(context_provider_);
64
65 ResourceWriteLocks locks;
66
67 for (auto tile : tiles) {
68 // TODO(hendrikw): Don't create resources for solid color tiles.
69 scoped_ptr<ScopedResource> resource =
70 resource_pool->AcquireResource(tile->size());
71 const ScopedResource* const_resource = resource.get();
72
73 RasterSource::SolidColorAnalysis analysis;
74
75 if (tile->use_picture_analysis())
76 PerformSolidColorAnalysis(tile, &analysis);
77
78 if (!analysis.is_solid_color)
79 AddToMultiPictureDraw(tile, const_resource, &locks);
80
81 update_tile_draw_info.Run(tile, resource.Pass(), analysis);
82 }
83
84 multi_picture_draw_.draw();
85 }
86
87 void GpuRasterizer::PerformSolidColorAnalysis(
88 const Tile* tile,
89 RasterSource::SolidColorAnalysis* analysis) {
90 const void* tile_id = static_cast<const void*>(tile);
91 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task(
92 tile_id, tile->combined_priority().resolution,
93 tile->source_frame_number(), tile->layer_id());
94
95 DCHECK(tile->raster_source());
96
97 tile->raster_source()->PerformSolidColorAnalysis(
98 tile->content_rect(), tile->contents_scale(), analysis);
99
100 // Record the solid color prediction.
101 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
102 analysis->is_solid_color);
103 }
104
105 void GpuRasterizer::AddToMultiPictureDraw(const Tile* tile,
106 const ScopedResource* resource,
107 ResourceWriteLocks* locks) {
108 const void* tile_id = static_cast<const void*>(tile);
109 frame_viewer_instrumentation::ScopedRasterTask raster_task(
110 tile_id, tile->combined_priority().resolution,
111 tile->source_frame_number(), tile->layer_id());
112
113 DCHECK(tile->raster_source());
114
115 ResourceProvider::ScopedWriteLockGr* lock =
vmpstr 2014/12/31 00:22:56 This should already be a scoped ptr, and Pass to l
116 new ResourceProvider::ScopedWriteLockGr(resource_provider_,
117 resource->id());
118 locks->push_back(make_scoped_ptr(lock));
119
120 // Turn on distance fields for layers that have ever animated.
121 bool use_distance_field_text =
122 use_distance_field_text_ ||
123 tile->raster_source()->ShouldAttemptToUseDistanceFieldText();
124 SkSurface* sk_surface = lock->GetSkSurface(
125 use_distance_field_text, tile->raster_source()->CanUseLCDText());
126
127 if (!sk_surface)
128 return;
129
130 SkPictureRecorder recorder;
131 gfx::Size size = resource->size();
132 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
133 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
134 recorder.beginRecording(size.width(), size.height(), NULL, flags));
135
136 canvas->save();
137 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(),
138 tile->contents_scale());
139 canvas->restore();
140
141 // Add the canvas and recorded picture to |multi_picture_draw_|.
142 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
143 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
144 }
145
146 } // 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