OLD | NEW |
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 bool use_distance_field_text = | 113 bool use_distance_field_text = |
114 use_distance_field_text_ || | 114 use_distance_field_text_ || |
115 raster_source->ShouldAttemptToUseDistanceFieldText(); | 115 raster_source->ShouldAttemptToUseDistanceFieldText(); |
116 | 116 |
117 // Playback picture into resource. | 117 // Playback picture into resource. |
118 { | 118 { |
119 ScopedGpuRaster gpu_raster(GetContextProvider(use_worker_context)); | 119 ScopedGpuRaster gpu_raster(GetContextProvider(use_worker_context)); |
120 write_lock->InitSkSurface(use_worker_context, use_distance_field_text, | 120 write_lock->InitSkSurface(use_worker_context, use_distance_field_text, |
121 raster_source->CanUseLCDText(), | 121 raster_source->CanUseLCDText(), |
122 msaa_sample_count_); | 122 msaa_sample_count_); |
| 123 |
| 124 SkSurface* sk_surface = write_lock->sk_surface(); |
| 125 |
| 126 // Allocating an SkSurface will fail after a lost context. Pretend we |
| 127 // rasterized, as the contents of the resource don't matter anymore. |
| 128 if (!sk_surface) |
| 129 return; |
| 130 |
123 SkMultiPictureDraw multi_picture_draw; | 131 SkMultiPictureDraw multi_picture_draw; |
124 multi_picture_draw.add(write_lock->sk_surface()->getCanvas(), | 132 multi_picture_draw.add(sk_surface->getCanvas(), picture.get()); |
125 picture.get()); | |
126 multi_picture_draw.draw(msaa_sample_count_ > 0); | 133 multi_picture_draw.draw(msaa_sample_count_ > 0); |
127 write_lock->ReleaseSkSurface(); | 134 write_lock->ReleaseSkSurface(); |
128 } | 135 } |
129 } | 136 } |
130 | 137 |
131 void GpuRasterizer::PerformSolidColorAnalysis( | 138 void GpuRasterizer::PerformSolidColorAnalysis( |
132 const Tile* tile, | 139 const Tile* tile, |
133 RasterSource::SolidColorAnalysis* analysis) { | 140 RasterSource::SolidColorAnalysis* analysis) { |
134 const void* tile_id = static_cast<const void*>(tile); | 141 const void* tile_id = static_cast<const void*>(tile); |
135 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( | 142 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( |
(...skipping 26 matching lines...) Expand all Loading... |
162 tile->raster_source()->ShouldAttemptToUseDistanceFieldText(); | 169 tile->raster_source()->ShouldAttemptToUseDistanceFieldText(); |
163 scoped_ptr<ResourceProvider::ScopedWriteLockGr> lock( | 170 scoped_ptr<ResourceProvider::ScopedWriteLockGr> lock( |
164 new ResourceProvider::ScopedWriteLockGr(resource_provider_, | 171 new ResourceProvider::ScopedWriteLockGr(resource_provider_, |
165 resource->id())); | 172 resource->id())); |
166 | 173 |
167 lock->InitSkSurface(false, use_distance_field_text, | 174 lock->InitSkSurface(false, use_distance_field_text, |
168 tile->raster_source()->CanUseLCDText(), | 175 tile->raster_source()->CanUseLCDText(), |
169 msaa_sample_count_); | 176 msaa_sample_count_); |
170 | 177 |
171 SkSurface* sk_surface = lock->sk_surface(); | 178 SkSurface* sk_surface = lock->sk_surface(); |
| 179 |
| 180 // Allocating an SkSurface will fail after a lost context. Pretend we |
| 181 // rasterized, as the contents of the resource don't matter anymore. |
172 if (!sk_surface) | 182 if (!sk_surface) |
173 return; | 183 return; |
174 | 184 |
175 locks->push_back(lock.Pass()); | 185 locks->push_back(lock.Pass()); |
176 | 186 |
177 SkRTreeFactory factory; | 187 SkRTreeFactory factory; |
178 SkPictureRecorder recorder; | 188 SkPictureRecorder recorder; |
179 gfx::Size size = resource->size(); | 189 gfx::Size size = resource->size(); |
180 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; | 190 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; |
181 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 191 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( |
182 recorder.beginRecording(size.width(), size.height(), &factory, flags)); | 192 recorder.beginRecording(size.width(), size.height(), &factory, flags)); |
183 | 193 |
184 canvas->save(); | 194 canvas->save(); |
185 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), | 195 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), |
186 tile->contents_scale()); | 196 tile->contents_scale()); |
187 canvas->restore(); | 197 canvas->restore(); |
188 | 198 |
189 // Add the canvas and recorded picture to |multi_picture_draw_|. | 199 // Add the canvas and recorded picture to |multi_picture_draw_|. |
190 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 200 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
191 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); | 201 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); |
192 } | 202 } |
193 | 203 |
194 } // namespace cc | 204 } // namespace cc |
OLD | NEW |