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" | |
12 #include "cc/resources/raster_buffer.h" | 11 #include "cc/resources/raster_buffer.h" |
| 12 #include "cc/resources/raster_source.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 bool use_distance_field_text) |
31 : lock_(resource_provider, resource->id()), | 31 : lock_(resource_provider, resource->id()), |
32 resource_(resource), | 32 resource_(resource), |
33 multi_picture_draw_(multi_picture_draw), | 33 multi_picture_draw_(multi_picture_draw), |
34 use_distance_field_text_(use_distance_field_text) {} | 34 use_distance_field_text_(use_distance_field_text) {} |
35 | 35 |
36 // Overridden from RasterBuffer: | 36 // Overridden from RasterBuffer: |
37 void Playback(const PicturePileImpl* picture_pile, | 37 void Playback(const RasterSource* raster_source, |
38 const gfx::Rect& rect, | 38 const gfx::Rect& rect, |
39 float scale, | 39 float scale, |
40 RenderingStatsInstrumentation* stats) override { | 40 RenderingStatsInstrumentation* stats) override { |
41 // Turn on distance fields for layers that have ever animated. | 41 // Turn on distance fields for layers that have ever animated. |
42 bool use_distance_field_text = | 42 bool use_distance_field_text = |
43 use_distance_field_text_ || | 43 use_distance_field_text_ || |
44 picture_pile->likely_to_be_used_for_transform_animation(); | 44 raster_source->SuitableForDistanceFieldText(); |
45 SkSurface* sk_surface = lock_.GetSkSurface(use_distance_field_text); | 45 SkSurface* sk_surface = lock_.GetSkSurface(use_distance_field_text); |
46 | 46 |
47 if (!sk_surface) | 47 if (!sk_surface) |
48 return; | 48 return; |
49 | 49 |
50 SkPictureRecorder recorder; | 50 SkPictureRecorder recorder; |
51 gfx::Size size = resource_->size(); | 51 gfx::Size size = resource_->size(); |
52 skia::RefPtr<SkCanvas> canvas = | 52 skia::RefPtr<SkCanvas> canvas = |
53 skia::SharePtr(recorder.beginRecording(size.width(), size.height())); | 53 skia::SharePtr(recorder.beginRecording(size.width(), size.height())); |
54 | 54 |
55 canvas->save(); | 55 canvas->save(); |
56 picture_pile->RasterToBitmap(canvas.get(), rect, scale, stats); | 56 raster_source->PlaybackToCanvas(canvas.get(), rect, scale, stats); |
57 canvas->restore(); | 57 canvas->restore(); |
58 | 58 |
59 // Add the canvas and recorded picture to |multi_picture_draw_|. | 59 // Add the canvas and recorded picture to |multi_picture_draw_|. |
60 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 60 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
61 multi_picture_draw_->add(sk_surface->getCanvas(), picture.get()); | 61 multi_picture_draw_->add(sk_surface->getCanvas(), picture.get()); |
62 } | 62 } |
63 | 63 |
64 private: | 64 private: |
65 ResourceProvider::ScopedWriteLockGr lock_; | 65 ResourceProvider::ScopedWriteLockGr lock_; |
66 const Resource* resource_; | 66 const Resource* resource_; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 ScopedGpuRaster gpu_raster(context_provider_); | 245 ScopedGpuRaster gpu_raster(context_provider_); |
246 task_graph_runner_->RunUntilIdle(); | 246 task_graph_runner_->RunUntilIdle(); |
247 | 247 |
248 // 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 |
249 // the pictures and canvases added to |multi_picture_draw_| | 249 // the pictures and canvases added to |multi_picture_draw_| |
250 multi_picture_draw_.draw(); | 250 multi_picture_draw_.draw(); |
251 } | 251 } |
252 | 252 |
253 } // namespace cc | 253 } // namespace cc |
OLD | NEW |