Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_raster_worker_pool.h" | 5 #include "cc/resources/gpu_raster_worker_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| 11 #include "cc/resources/picture_pile_impl.h" | 11 #include "cc/resources/picture_pile_impl.h" |
| 12 #include "cc/resources/raster_buffer.h" | 12 #include "cc/resources/raster_buffer.h" |
| 13 #include "cc/resources/resource.h" | 13 #include "cc/resources/resource.h" |
| 14 #include "cc/resources/resource_provider.h" | 14 #include "cc/resources/resource_provider.h" |
| 15 #include "cc/resources/scoped_gpu_raster.h" | 15 #include "cc/resources/scoped_gpu_raster.h" |
| 16 #include "gpu/command_buffer/client/gles2_interface.h" | 16 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 17 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 18 #include "third_party/skia/include/core/SkPictureRecorder.h" | 18 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 19 #include "third_party/skia/include/core/SkSurface.h" | 19 #include "third_party/skia/include/core/SkSurface.h" |
| 20 #include "third_party/skia/include/gpu/GrContext.h" | 20 #include "third_party/skia/include/gpu/GrContext.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class RasterBufferImpl : public RasterBuffer { | 25 class RasterBufferImpl : public RasterBuffer { |
| 26 public: | 26 public: |
| 27 RasterBufferImpl(ResourceProvider* resource_provider, | 27 RasterBufferImpl(ResourceProvider* resource_provider, |
| 28 const Resource* resource, | 28 const Resource* resource, |
| 29 SkMultiPictureDraw* multi_picture_draw) | 29 SkMultiPictureDraw* multi_picture_draw, |
| 30 bool use_distance_field_text) | |
| 30 : lock_(resource_provider, resource->id()), | 31 : lock_(resource_provider, resource->id()), |
| 31 resource_(resource), | 32 resource_(resource), |
| 32 multi_picture_draw_(multi_picture_draw) {} | 33 multi_picture_draw_(multi_picture_draw), |
| 34 use_distance_field_text_(use_distance_field_text) {} | |
| 33 | 35 |
| 34 // Overridden from RasterBuffer: | 36 // Overridden from RasterBuffer: |
| 35 virtual void Playback(const PicturePileImpl* picture_pile, | 37 virtual void Playback(const PicturePileImpl* picture_pile, |
| 36 const gfx::Rect& rect, | 38 const gfx::Rect& rect, |
| 37 float scale, | 39 float scale, |
| 38 RenderingStatsInstrumentation* stats) override { | 40 RenderingStatsInstrumentation* stats) override { |
| 39 if (!lock_.sk_surface()) | 41 // Turn on distance fields for layers that have ever animated. |
| 42 bool use_distance_field_text = | |
| 43 use_distance_field_text_ || | |
|
reveman
2014/10/20 20:27:13
&& ?
hendrikw
2014/10/20 20:34:11
||. That comes from the global dff flag (--enable-
reveman
2014/10/20 21:04:26
hm, why do we need both modes? can we remove the g
| |
| 44 picture_pile->likely_to_be_used_for_transform_animation(); | |
| 45 SkSurface* sk_surface = lock_.GetSkSurface(use_distance_field_text); | |
| 46 | |
| 47 if (!sk_surface) | |
| 40 return; | 48 return; |
| 41 | 49 |
| 42 SkPictureRecorder recorder; | 50 SkPictureRecorder recorder; |
| 43 gfx::Size size = resource_->size(); | 51 gfx::Size size = resource_->size(); |
| 44 skia::RefPtr<SkCanvas> canvas = | 52 skia::RefPtr<SkCanvas> canvas = |
| 45 skia::SharePtr(recorder.beginRecording(size.width(), size.height())); | 53 skia::SharePtr(recorder.beginRecording(size.width(), size.height())); |
| 46 | 54 |
| 47 canvas->save(); | 55 canvas->save(); |
| 48 picture_pile->RasterToBitmap(canvas.get(), rect, scale, stats); | 56 picture_pile->RasterToBitmap(canvas.get(), rect, scale, stats); |
| 49 canvas->restore(); | 57 canvas->restore(); |
| 50 | 58 |
| 51 // Add the canvas and recorded picture to |multi_picture_draw_|. | 59 // Add the canvas and recorded picture to |multi_picture_draw_|. |
| 52 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 60 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 53 multi_picture_draw_->add(lock_.sk_surface()->getCanvas(), picture.get()); | 61 multi_picture_draw_->add(sk_surface->getCanvas(), picture.get()); |
| 54 } | 62 } |
| 55 | 63 |
| 56 private: | 64 private: |
| 57 ResourceProvider::ScopedWriteLockGr lock_; | 65 ResourceProvider::ScopedWriteLockGr lock_; |
| 58 const Resource* resource_; | 66 const Resource* resource_; |
| 59 SkMultiPictureDraw* multi_picture_draw_; | 67 SkMultiPictureDraw* multi_picture_draw_; |
| 68 bool use_distance_field_text_; | |
| 60 | 69 |
| 61 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 70 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 62 }; | 71 }; |
| 63 | 72 |
| 64 } // namespace | 73 } // namespace |
| 65 | 74 |
| 66 // static | 75 // static |
| 67 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( | 76 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( |
| 68 base::SequencedTaskRunner* task_runner, | 77 base::SequencedTaskRunner* task_runner, |
| 69 ContextProvider* context_provider, | 78 ContextProvider* context_provider, |
| 70 ResourceProvider* resource_provider) { | 79 ResourceProvider* resource_provider, |
| 71 return make_scoped_ptr<RasterWorkerPool>(new GpuRasterWorkerPool( | 80 bool use_distance_field_text) { |
| 72 task_runner, context_provider, resource_provider)); | 81 return make_scoped_ptr<RasterWorkerPool>( |
| 82 new GpuRasterWorkerPool(task_runner, | |
| 83 context_provider, | |
| 84 resource_provider, | |
| 85 use_distance_field_text)); | |
| 73 } | 86 } |
| 74 | 87 |
| 75 GpuRasterWorkerPool::GpuRasterWorkerPool(base::SequencedTaskRunner* task_runner, | 88 GpuRasterWorkerPool::GpuRasterWorkerPool(base::SequencedTaskRunner* task_runner, |
| 76 ContextProvider* context_provider, | 89 ContextProvider* context_provider, |
| 77 ResourceProvider* resource_provider) | 90 ResourceProvider* resource_provider, |
| 91 bool use_distance_field_text) | |
| 78 : task_runner_(task_runner), | 92 : task_runner_(task_runner), |
| 79 task_graph_runner_(new TaskGraphRunner), | 93 task_graph_runner_(new TaskGraphRunner), |
| 80 namespace_token_(task_graph_runner_->GetNamespaceToken()), | 94 namespace_token_(task_graph_runner_->GetNamespaceToken()), |
| 81 context_provider_(context_provider), | 95 context_provider_(context_provider), |
| 82 resource_provider_(resource_provider), | 96 resource_provider_(resource_provider), |
| 83 run_tasks_on_origin_thread_pending_(false), | 97 run_tasks_on_origin_thread_pending_(false), |
| 98 use_distance_field_text_(use_distance_field_text), | |
| 84 raster_finished_weak_ptr_factory_(this), | 99 raster_finished_weak_ptr_factory_(this), |
| 85 weak_ptr_factory_(this) { | 100 weak_ptr_factory_(this) { |
| 86 DCHECK(context_provider_); | 101 DCHECK(context_provider_); |
| 87 } | 102 } |
| 88 | 103 |
| 89 GpuRasterWorkerPool::~GpuRasterWorkerPool() { | 104 GpuRasterWorkerPool::~GpuRasterWorkerPool() { |
| 90 DCHECK_EQ(0u, completed_tasks_.size()); | 105 DCHECK_EQ(0u, completed_tasks_.size()); |
| 91 } | 106 } |
| 92 | 107 |
| 93 Rasterizer* GpuRasterWorkerPool::AsRasterizer() { | 108 Rasterizer* GpuRasterWorkerPool::AsRasterizer() { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 task->DidComplete(); | 198 task->DidComplete(); |
| 184 | 199 |
| 185 task->RunReplyOnOriginThread(); | 200 task->RunReplyOnOriginThread(); |
| 186 } | 201 } |
| 187 completed_tasks_.clear(); | 202 completed_tasks_.clear(); |
| 188 } | 203 } |
| 189 | 204 |
| 190 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( | 205 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( |
| 191 const Resource* resource) { | 206 const Resource* resource) { |
| 192 return make_scoped_ptr<RasterBuffer>( | 207 return make_scoped_ptr<RasterBuffer>( |
| 193 new RasterBufferImpl(resource_provider_, resource, &multi_picture_draw_)); | 208 new RasterBufferImpl(resource_provider_, |
| 209 resource, | |
| 210 &multi_picture_draw_, | |
| 211 use_distance_field_text_)); | |
| 194 } | 212 } |
| 195 | 213 |
| 196 void GpuRasterWorkerPool::ReleaseBufferForRaster( | 214 void GpuRasterWorkerPool::ReleaseBufferForRaster( |
| 197 scoped_ptr<RasterBuffer> buffer) { | 215 scoped_ptr<RasterBuffer> buffer) { |
| 198 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 216 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 199 } | 217 } |
| 200 | 218 |
| 201 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { | 219 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { |
| 202 TRACE_EVENT1( | 220 TRACE_EVENT1( |
| 203 "cc", "GpuRasterWorkerPool::OnRasterFinished", "task_set", task_set); | 221 "cc", "GpuRasterWorkerPool::OnRasterFinished", "task_set", task_set); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 226 | 244 |
| 227 ScopedGpuRaster gpu_raster(context_provider_); | 245 ScopedGpuRaster gpu_raster(context_provider_); |
| 228 task_graph_runner_->RunUntilIdle(); | 246 task_graph_runner_->RunUntilIdle(); |
| 229 | 247 |
| 230 // Draw each all of the pictures that were collected. This will also clear | 248 // Draw each all of the pictures that were collected. This will also clear |
| 231 // the pictures and canvases added to |multi_picture_draw_| | 249 // the pictures and canvases added to |multi_picture_draw_| |
| 232 multi_picture_draw_.draw(); | 250 multi_picture_draw_.draw(); |
| 233 } | 251 } |
| 234 | 252 |
| 235 } // namespace cc | 253 } // namespace cc |
| OLD | NEW |