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

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

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://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.cc » ('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 13 matching lines...) Expand all
24 #include "third_party/skia/include/core/SkSurface.h" 24 #include "third_party/skia/include/core/SkSurface.h"
25 #include "third_party/skia/include/gpu/GrContext.h" 25 #include "third_party/skia/include/gpu/GrContext.h"
26 26
27 namespace cc { 27 namespace cc {
28 28
29 // static 29 // static
30 scoped_ptr<GpuRasterizer> GpuRasterizer::Create( 30 scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
31 ContextProvider* context_provider, 31 ContextProvider* context_provider,
32 ResourceProvider* resource_provider, 32 ResourceProvider* resource_provider,
33 bool use_distance_field_text, 33 bool use_distance_field_text,
34 bool tile_prepare_enabled) { 34 bool tile_prepare_enabled,
35 return make_scoped_ptr<GpuRasterizer>( 35 int msaa_sample_count) {
36 new GpuRasterizer(context_provider, resource_provider, 36 return make_scoped_ptr<GpuRasterizer>(new GpuRasterizer(
37 use_distance_field_text, tile_prepare_enabled)); 37 context_provider, resource_provider, use_distance_field_text,
38 tile_prepare_enabled, msaa_sample_count));
38 } 39 }
39 40
40 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, 41 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
41 ResourceProvider* resource_provider, 42 ResourceProvider* resource_provider,
42 bool use_distance_field_text, 43 bool use_distance_field_text,
43 bool tile_prepare_enabled) 44 bool tile_prepare_enabled,
45 int msaa_sample_count)
44 : context_provider_(context_provider), 46 : context_provider_(context_provider),
45 resource_provider_(resource_provider), 47 resource_provider_(resource_provider),
46 use_distance_field_text_(use_distance_field_text), 48 use_distance_field_text_(use_distance_field_text),
47 tile_prepare_enabled_(tile_prepare_enabled) { 49 tile_prepare_enabled_(tile_prepare_enabled),
50 msaa_sample_count_(msaa_sample_count) {
48 DCHECK(context_provider_); 51 DCHECK(context_provider_);
49 } 52 }
50 53
51 GpuRasterizer::~GpuRasterizer() { 54 GpuRasterizer::~GpuRasterizer() {
52 } 55 }
53 56
54 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { 57 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() {
55 return tile_prepare_enabled_ ? PrepareTilesMode::PREPARE_PRIORITIZED_TILES 58 return tile_prepare_enabled_ ? PrepareTilesMode::PREPARE_PRIORITIZED_TILES
56 : PrepareTilesMode::PREPARE_NONE; 59 : PrepareTilesMode::PREPARE_NONE;
57 } 60 }
58 61
59 void GpuRasterizer::RasterizeTiles( 62 void GpuRasterizer::RasterizeTiles(
60 const TileVector& tiles, 63 const TileVector& tiles,
61 ResourcePool* resource_pool, 64 ResourcePool* resource_pool,
62 ResourceFormat resource_format, 65 ResourceFormat resource_format,
63 const UpdateTileDrawInfoCallback& update_tile_draw_info) { 66 const UpdateTileDrawInfoCallback& update_tile_draw_info) {
64 ScopedGpuRaster gpu_raster(context_provider_); 67 ScopedGpuRaster gpu_raster(context_provider_);
65 68
66 ScopedResourceWriteLocks locks; 69 ScopedResourceWriteLocks locks;
67 70
68 for (Tile* tile : tiles) { 71 for (Tile* tile : tiles) {
69 // TODO(hendrikw): Don't create resources for solid color tiles.
70 // See crbug.com/445919
71 scoped_ptr<ScopedResource> resource =
72 resource_pool->AcquireResource(tile->desired_texture_size(),
73 resource_format);
74 const ScopedResource* const_resource = resource.get();
75
76 RasterSource::SolidColorAnalysis analysis; 72 RasterSource::SolidColorAnalysis analysis;
77 73
78 if (tile->use_picture_analysis()) 74 if (tile->use_picture_analysis())
79 PerformSolidColorAnalysis(tile, &analysis); 75 PerformSolidColorAnalysis(tile, &analysis);
80 76
81 if (!analysis.is_solid_color) 77 scoped_ptr<ScopedResource> resource;
82 AddToMultiPictureDraw(tile, const_resource, &locks); 78 if (!analysis.is_solid_color) {
83 79 resource = resource_pool->AcquireResource(tile->desired_texture_size(),
80 resource_format);
81 AddToMultiPictureDraw(tile, resource.get(), &locks);
82 }
84 update_tile_draw_info.Run(tile, resource.Pass(), analysis); 83 update_tile_draw_info.Run(tile, resource.Pass(), analysis);
85 } 84 }
86 85
87 multi_picture_draw_.draw(); 86 // If MSAA is enabled, tell Skia to resolve each render target after draw.
87 multi_picture_draw_.draw(msaa_sample_count_ > 0);
88 } 88 }
89 89
90 void GpuRasterizer::PerformSolidColorAnalysis( 90 void GpuRasterizer::PerformSolidColorAnalysis(
91 const Tile* tile, 91 const Tile* tile,
92 RasterSource::SolidColorAnalysis* analysis) { 92 RasterSource::SolidColorAnalysis* analysis) {
93 const void* tile_id = static_cast<const void*>(tile); 93 const void* tile_id = static_cast<const void*>(tile);
94 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( 94 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task(
95 tile_id, tile->combined_priority().resolution, 95 tile_id, tile->combined_priority().resolution,
96 tile->source_frame_number(), tile->layer_id()); 96 tile->source_frame_number(), tile->layer_id());
97 97
(...skipping 15 matching lines...) Expand all
113 tile_id, tile->combined_priority().resolution, 113 tile_id, tile->combined_priority().resolution,
114 tile->source_frame_number(), tile->layer_id()); 114 tile->source_frame_number(), tile->layer_id());
115 115
116 DCHECK(tile->raster_source()); 116 DCHECK(tile->raster_source());
117 117
118 // Turn on distance fields for layers that have ever animated. 118 // Turn on distance fields for layers that have ever animated.
119 bool use_distance_field_text = 119 bool use_distance_field_text =
120 use_distance_field_text_ || 120 use_distance_field_text_ ||
121 tile->raster_source()->ShouldAttemptToUseDistanceFieldText(); 121 tile->raster_source()->ShouldAttemptToUseDistanceFieldText();
122 scoped_ptr<ResourceProvider::ScopedWriteLockGr> lock( 122 scoped_ptr<ResourceProvider::ScopedWriteLockGr> lock(
123 new ResourceProvider::ScopedWriteLockGr(resource_provider_, 123 new ResourceProvider::ScopedWriteLockGr(
124 resource->id())); 124 resource_provider_, resource->id(), use_distance_field_text,
125 SkSurface* sk_surface = lock->GetSkSurface( 125 tile->raster_source()->CanUseLCDText(), msaa_sample_count_));
126 use_distance_field_text, tile->raster_source()->CanUseLCDText()); 126
127 SkSurface* sk_surface = lock->get_sk_surface();
128 if (!sk_surface)
129 return;
127 130
128 locks->push_back(lock.Pass()); 131 locks->push_back(lock.Pass());
129 132
130 if (!sk_surface)
131 return;
132
133 SkRTreeFactory factory; 133 SkRTreeFactory factory;
134 SkPictureRecorder recorder; 134 SkPictureRecorder recorder;
135 gfx::Size size = resource->size(); 135 gfx::Size size = resource->size();
136 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; 136 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
137 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( 137 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
138 recorder.beginRecording(size.width(), size.height(), &factory, flags)); 138 recorder.beginRecording(size.width(), size.height(), &factory, flags));
139 139
140 canvas->save(); 140 canvas->save();
141 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), 141 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(),
142 tile->contents_scale()); 142 tile->contents_scale());
143 canvas->restore(); 143 canvas->restore();
144 144
145 // Add the canvas and recorded picture to |multi_picture_draw_|. 145 // Add the canvas and recorded picture to |multi_picture_draw_|.
146 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); 146 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
147 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); 147 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
148 } 148 }
149 149
150 } // namespace cc 150 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/gpu_tile_task_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698