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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/gpu_rasterizer.h" 5 #include "cc/resources/gpu_rasterizer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 25 matching lines...) Expand all
36 return make_scoped_ptr<GpuRasterizer>(new GpuRasterizer( 36 return make_scoped_ptr<GpuRasterizer>(new GpuRasterizer(
37 context_provider, resource_provider, use_distance_field_text, 37 context_provider, resource_provider, use_distance_field_text,
38 threaded_gpu_rasterization_enabled, msaa_sample_count)); 38 threaded_gpu_rasterization_enabled, msaa_sample_count));
39 } 39 }
40 40
41 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, 41 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
42 ResourceProvider* resource_provider, 42 ResourceProvider* resource_provider,
43 bool use_distance_field_text, 43 bool use_distance_field_text,
44 bool threaded_gpu_rasterization_enabled, 44 bool threaded_gpu_rasterization_enabled,
45 int msaa_sample_count) 45 int msaa_sample_count)
46 : context_provider_(context_provider), 46 : resource_provider_(resource_provider),
47 resource_provider_(resource_provider),
48 use_distance_field_text_(use_distance_field_text), 47 use_distance_field_text_(use_distance_field_text),
49 threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled), 48 threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled),
50 msaa_sample_count_(msaa_sample_count) { 49 msaa_sample_count_(msaa_sample_count) {
51 DCHECK(context_provider_);
52 } 50 }
53 51
54 GpuRasterizer::~GpuRasterizer() { 52 GpuRasterizer::~GpuRasterizer() {
55 } 53 }
56 54
57 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { 55 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() {
58 return PrepareTilesMode::PREPARE_NONE; 56 return threaded_gpu_rasterization_enabled_
57 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES
58 : PrepareTilesMode::PREPARE_NONE;
59 }
60
61 ContextProvider* GpuRasterizer::GetContextProvider(bool worker_context) {
62 return worker_context
63 ? resource_provider_->output_surface()->worker_context_provider()
64 : resource_provider_->output_surface()->context_provider();
59 } 65 }
60 66
61 void GpuRasterizer::RasterizeTiles( 67 void GpuRasterizer::RasterizeTiles(
62 const TileVector& tiles, 68 const TileVector& tiles,
63 ResourcePool* resource_pool, 69 ResourcePool* resource_pool,
64 ResourceFormat resource_format, 70 ResourceFormat resource_format,
65 const UpdateTileDrawInfoCallback& update_tile_draw_info) { 71 const UpdateTileDrawInfoCallback& update_tile_draw_info) {
66 ScopedGpuRaster gpu_raster(context_provider_); 72 ScopedGpuRaster gpu_raster(GetContextProvider(false));
67 73
68 ScopedResourceWriteLocks locks; 74 ScopedResourceWriteLocks locks;
69 75
70 for (Tile* tile : tiles) { 76 for (Tile* tile : tiles) {
71 RasterSource::SolidColorAnalysis analysis; 77 RasterSource::SolidColorAnalysis analysis;
72 78
73 if (tile->use_picture_analysis()) 79 if (tile->use_picture_analysis())
74 PerformSolidColorAnalysis(tile, &analysis); 80 PerformSolidColorAnalysis(tile, &analysis);
75 81
76 scoped_ptr<ScopedResource> resource; 82 scoped_ptr<ScopedResource> resource;
77 if (!analysis.is_solid_color) { 83 if (!analysis.is_solid_color) {
78 resource = resource_pool->AcquireResource(tile->desired_texture_size(), 84 resource = resource_pool->AcquireResource(tile->desired_texture_size(),
79 resource_format); 85 resource_format);
80 AddToMultiPictureDraw(tile, resource.get(), &locks); 86 AddToMultiPictureDraw(tile, resource.get(), &locks);
81 } 87 }
82 update_tile_draw_info.Run(tile, resource.Pass(), analysis); 88 update_tile_draw_info.Run(tile, resource.Pass(), analysis);
83 } 89 }
84 90
85 // If MSAA is enabled, tell Skia to resolve each render target after draw. 91 // If MSAA is enabled, tell Skia to resolve each render target after draw.
86 multi_picture_draw_.draw(msaa_sample_count_ > 0); 92 multi_picture_draw_.draw(msaa_sample_count_ > 0);
87 } 93 }
88 94
95 void GpuRasterizer::RasterizeSource(
96 bool use_worker_context,
97 ResourceProvider::ScopedWriteLockGr* write_lock,
98 const RasterSource* raster_source,
99 const gfx::Rect& rect,
100 float scale) {
101 // Play back raster_source into temp SkPicture.
102 SkPictureRecorder recorder;
103 gfx::Size size = write_lock->resource()->size;
104 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
105 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
106 recorder.beginRecording(size.width(), size.height(), NULL, flags));
107 canvas->save();
108 raster_source->PlaybackToCanvas(canvas.get(), rect, scale);
109 canvas->restore();
110 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
111
112 // Turn on distance fields for layers that have ever animated.
113 bool use_distance_field_text =
114 use_distance_field_text_ ||
115 raster_source->ShouldAttemptToUseDistanceFieldText();
116
117 // Playback picture into resource.
118 {
119 ScopedGpuRaster gpu_raster(GetContextProvider(use_worker_context));
120 write_lock->InitSkSurface(use_worker_context, use_distance_field_text,
121 raster_source->CanUseLCDText(),
122 msaa_sample_count_);
123 SkMultiPictureDraw multi_picture_draw;
124 multi_picture_draw.add(write_lock->sk_surface()->getCanvas(),
125 picture.get());
126 multi_picture_draw.draw(false);
127 write_lock->ReleaseSkSurface();
128 }
129 }
130
89 void GpuRasterizer::PerformSolidColorAnalysis( 131 void GpuRasterizer::PerformSolidColorAnalysis(
90 const Tile* tile, 132 const Tile* tile,
91 RasterSource::SolidColorAnalysis* analysis) { 133 RasterSource::SolidColorAnalysis* analysis) {
92 const void* tile_id = static_cast<const void*>(tile); 134 const void* tile_id = static_cast<const void*>(tile);
93 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( 135 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task(
94 tile_id, tile->combined_priority().resolution, 136 tile_id, tile->combined_priority().resolution,
95 tile->source_frame_number(), tile->layer_id()); 137 tile->source_frame_number(), tile->layer_id());
96 138
97 DCHECK(tile->raster_source()); 139 DCHECK(tile->raster_source());
98 140
(...skipping 13 matching lines...) Expand all
112 tile_id, tile->combined_priority().resolution, 154 tile_id, tile->combined_priority().resolution,
113 tile->source_frame_number(), tile->layer_id()); 155 tile->source_frame_number(), tile->layer_id());
114 156
115 DCHECK(tile->raster_source()); 157 DCHECK(tile->raster_source());
116 158
117 // Turn on distance fields for layers that have ever animated. 159 // Turn on distance fields for layers that have ever animated.
118 bool use_distance_field_text = 160 bool use_distance_field_text =
119 use_distance_field_text_ || 161 use_distance_field_text_ ||
120 tile->raster_source()->ShouldAttemptToUseDistanceFieldText(); 162 tile->raster_source()->ShouldAttemptToUseDistanceFieldText();
121 scoped_ptr<ResourceProvider::ScopedWriteLockGr> lock( 163 scoped_ptr<ResourceProvider::ScopedWriteLockGr> lock(
122 new ResourceProvider::ScopedWriteLockGr( 164 new ResourceProvider::ScopedWriteLockGr(resource_provider_,
123 resource_provider_, resource->id(), use_distance_field_text, 165 resource->id()));
124 tile->raster_source()->CanUseLCDText(), msaa_sample_count_));
125 166
126 SkSurface* sk_surface = lock->get_sk_surface(); 167 lock->InitSkSurface(false, use_distance_field_text,
168 tile->raster_source()->CanUseLCDText(),
169 msaa_sample_count_);
170
171 SkSurface* sk_surface = lock->sk_surface();
127 if (!sk_surface) 172 if (!sk_surface)
128 return; 173 return;
129 174
130 locks->push_back(lock.Pass()); 175 locks->push_back(lock.Pass());
131 176
132 SkRTreeFactory factory; 177 SkRTreeFactory factory;
133 SkPictureRecorder recorder; 178 SkPictureRecorder recorder;
134 gfx::Size size = resource->size(); 179 gfx::Size size = resource->size();
135 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; 180 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
136 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( 181 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
137 recorder.beginRecording(size.width(), size.height(), &factory, flags)); 182 recorder.beginRecording(size.width(), size.height(), &factory, flags));
138 183
139 canvas->save(); 184 canvas->save();
140 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), 185 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(),
141 tile->contents_scale()); 186 tile->contents_scale());
142 canvas->restore(); 187 canvas->restore();
143 188
144 // Add the canvas and recorded picture to |multi_picture_draw_|. 189 // Add the canvas and recorded picture to |multi_picture_draw_|.
145 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); 190 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
146 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); 191 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
147 } 192 }
148 193
149 } // namespace cc 194 } // 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