OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/raster_worker_pool.h" | 5 #include "cc/resources/raster_worker_pool.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "cc/debug/benchmark_instrumentation.h" | 10 #include "cc/debug/benchmark_instrumentation.h" |
11 #include "cc/debug/devtools_instrumentation.h" | 11 #include "cc/debug/devtools_instrumentation.h" |
12 #include "cc/debug/traced_value.h" | 12 #include "cc/debug/traced_value.h" |
13 #include "cc/resources/picture_pile_impl.h" | 13 #include "cc/resources/picture_pile_impl.h" |
| 14 #include "cc/resources/resource_provider.h" |
14 #include "skia/ext/lazy_pixel_ref.h" | 15 #include "skia/ext/lazy_pixel_ref.h" |
15 #include "skia/ext/paint_simplifier.h" | 16 #include "skia/ext/paint_simplifier.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" |
16 | 18 |
17 namespace cc { | 19 namespace cc { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
| 23 // Subclass of Allocator that takes a suitably allocated pointer and uses |
| 24 // it as the pixel memory for the bitmap. |
| 25 class IdentityAllocator : public SkBitmap::Allocator { |
| 26 public: |
| 27 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
| 28 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
| 29 dst->setPixels(buffer_); |
| 30 return true; |
| 31 } |
| 32 private: |
| 33 void* buffer_; |
| 34 }; |
| 35 |
21 // Flag to indicate whether we should try and detect that | 36 // Flag to indicate whether we should try and detect that |
22 // a tile is of solid color. | 37 // a tile is of solid color. |
23 const bool kUseColorEstimator = true; | 38 const bool kUseColorEstimator = true; |
24 | 39 |
25 class DisableLCDTextFilter : public SkDrawFilter { | 40 class DisableLCDTextFilter : public SkDrawFilter { |
26 public: | 41 public: |
27 // SkDrawFilter interface. | 42 // SkDrawFilter interface. |
28 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { | 43 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { |
29 if (type != SkDrawFilter::kText_Type) | 44 if (type != SkDrawFilter::kText_Type) |
30 return true; | 45 return true; |
(...skipping 22 matching lines...) Expand all Loading... |
53 picture_pile_(picture_pile), | 68 picture_pile_(picture_pile), |
54 content_rect_(content_rect), | 69 content_rect_(content_rect), |
55 contents_scale_(contents_scale), | 70 contents_scale_(contents_scale), |
56 raster_mode_(raster_mode), | 71 raster_mode_(raster_mode), |
57 is_tile_in_pending_tree_now_bin_(is_tile_in_pending_tree_now_bin), | 72 is_tile_in_pending_tree_now_bin_(is_tile_in_pending_tree_now_bin), |
58 tile_resolution_(tile_resolution), | 73 tile_resolution_(tile_resolution), |
59 layer_id_(layer_id), | 74 layer_id_(layer_id), |
60 tile_id_(tile_id), | 75 tile_id_(tile_id), |
61 source_frame_number_(source_frame_number), | 76 source_frame_number_(source_frame_number), |
62 rendering_stats_(rendering_stats), | 77 rendering_stats_(rendering_stats), |
63 reply_(reply) {} | 78 reply_(reply), |
| 79 texture_format_(resource->format()) {} |
64 | 80 |
65 void RunAnalysisOnThread(unsigned thread_index) { | 81 void RunAnalysisOnThread(unsigned thread_index) { |
66 TRACE_EVENT1("cc", | 82 TRACE_EVENT1("cc", |
67 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", | 83 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", |
68 "data", | 84 "data", |
69 TracedValue::FromValue(DataAsValue().release())); | 85 TracedValue::FromValue(DataAsValue().release())); |
70 | 86 |
71 DCHECK(picture_pile_.get()); | 87 DCHECK(picture_pile_.get()); |
72 DCHECK(rendering_stats_); | 88 DCHECK(rendering_stats_); |
73 | 89 |
74 PicturePileImpl* picture_clone = | 90 PicturePileImpl* picture_clone = |
75 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 91 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
76 | 92 |
77 DCHECK(picture_clone); | 93 DCHECK(picture_clone); |
78 | 94 |
79 base::TimeTicks start_time = rendering_stats_->StartRecording(); | 95 base::TimeTicks start_time = rendering_stats_->StartRecording(); |
80 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_); | 96 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_); |
81 base::TimeDelta duration = rendering_stats_->EndRecording(start_time); | 97 base::TimeDelta duration = rendering_stats_->EndRecording(start_time); |
82 | 98 |
83 // Record the solid color prediction. | 99 // Record the solid color prediction. |
84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 100 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
85 analysis_.is_solid_color); | 101 analysis_.is_solid_color); |
86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); | 102 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); |
87 | 103 |
88 // Clear the flag if we're not using the estimator. | 104 // Clear the flag if we're not using the estimator. |
89 analysis_.is_solid_color &= kUseColorEstimator; | 105 analysis_.is_solid_color &= kUseColorEstimator; |
90 } | 106 } |
91 | 107 |
92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { | 108 bool RunRasterOnThread(unsigned thread_index, |
| 109 void* buffer, |
| 110 gfx::Size size, |
| 111 int stride) { |
93 TRACE_EVENT2( | 112 TRACE_EVENT2( |
94 benchmark_instrumentation::kCategory, | 113 benchmark_instrumentation::kCategory, |
95 benchmark_instrumentation::kRunRasterOnThread, | 114 benchmark_instrumentation::kRunRasterOnThread, |
96 benchmark_instrumentation::kData, | 115 benchmark_instrumentation::kData, |
97 TracedValue::FromValue(DataAsValue().release()), | 116 TracedValue::FromValue(DataAsValue().release()), |
98 "raster_mode", | 117 "raster_mode", |
99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 118 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
100 | 119 |
101 devtools_instrumentation::ScopedLayerTask raster_task( | 120 devtools_instrumentation::ScopedLayerTask raster_task( |
102 devtools_instrumentation::kRasterTask, layer_id_); | 121 devtools_instrumentation::kRasterTask, layer_id_); |
103 | 122 |
104 DCHECK(picture_pile_.get()); | 123 DCHECK(picture_pile_.get()); |
105 DCHECK(device); | 124 DCHECK(buffer); |
106 | 125 |
107 if (analysis_.is_solid_color) | 126 if (analysis_.is_solid_color) |
108 return false; | 127 return false; |
109 | 128 |
110 PicturePileImpl* picture_clone = | 129 PicturePileImpl* picture_clone = |
111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 130 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
112 | 131 |
113 SkCanvas canvas(device); | 132 SkBitmap bitmap_32; |
| 133 bitmap_32.setConfig(SkBitmap::kARGB_8888_Config, |
| 134 size.width(), |
| 135 size.height(), |
| 136 stride); |
| 137 switch (texture_format_) { |
| 138 case ResourceProvider::RGBA_4444: |
| 139 bitmap_32.allocPixels(); |
| 140 break; |
| 141 case ResourceProvider::RGBA_8888: |
| 142 case ResourceProvider::BGRA_8888: |
| 143 case ResourceProvider::LUMINANCE_8: |
| 144 bitmap_32.setPixels(buffer); |
| 145 break; |
| 146 } |
114 | 147 |
| 148 SkBitmapDevice device_32(bitmap_32); |
| 149 SkCanvas canvas(&device_32); |
115 skia::RefPtr<SkDrawFilter> draw_filter; | 150 skia::RefPtr<SkDrawFilter> draw_filter; |
116 switch (raster_mode_) { | 151 switch (raster_mode_) { |
117 case LOW_QUALITY_RASTER_MODE: | 152 case LOW_QUALITY_RASTER_MODE: |
118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 153 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
119 break; | 154 break; |
120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 155 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 156 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
122 break; | 157 break; |
123 case HIGH_QUALITY_RASTER_MODE: | 158 case HIGH_QUALITY_RASTER_MODE: |
124 break; | 159 break; |
(...skipping 17 matching lines...) Expand all Loading... |
142 HISTOGRAM_CUSTOM_COUNTS( | 177 HISTOGRAM_CUSTOM_COUNTS( |
143 "Renderer4.PictureRasterTimeUS", | 178 "Renderer4.PictureRasterTimeUS", |
144 raster_stats.total_rasterize_time.InMicroseconds(), | 179 raster_stats.total_rasterize_time.InMicroseconds(), |
145 0, | 180 0, |
146 100000, | 181 100000, |
147 100); | 182 100); |
148 } else { | 183 } else { |
149 picture_clone->RasterToBitmap( | 184 picture_clone->RasterToBitmap( |
150 &canvas, content_rect_, contents_scale_, NULL); | 185 &canvas, content_rect_, contents_scale_, NULL); |
151 } | 186 } |
| 187 |
| 188 if (texture_format_ == ResourceProvider::RGBA_4444) { |
| 189 SkBitmap bitmap_16; |
| 190 IdentityAllocator allocator(buffer); |
| 191 bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); |
| 192 } |
| 193 |
152 return true; | 194 return true; |
153 } | 195 } |
154 | 196 |
155 // Overridden from internal::RasterWorkerPoolTask: | 197 // Overridden from internal::RasterWorkerPoolTask: |
156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 198 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 199 void* buffer, |
| 200 gfx::Size size, |
| 201 int stride) |
157 OVERRIDE { | 202 OVERRIDE { |
158 RunAnalysisOnThread(thread_index); | 203 RunAnalysisOnThread(thread_index); |
159 return RunRasterOnThread(device, thread_index); | 204 return RunRasterOnThread(thread_index, buffer, size, stride); |
160 } | 205 } |
161 virtual void CompleteOnOriginThread() OVERRIDE { | 206 virtual void CompleteOnOriginThread() OVERRIDE { |
162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 207 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
163 } | 208 } |
164 | 209 |
165 protected: | 210 protected: |
166 virtual ~RasterWorkerPoolTaskImpl() {} | 211 virtual ~RasterWorkerPoolTaskImpl() {} |
167 | 212 |
168 private: | 213 private: |
169 scoped_ptr<base::Value> DataAsValue() const { | 214 scoped_ptr<base::Value> DataAsValue() const { |
(...skipping 12 matching lines...) Expand all Loading... |
182 gfx::Rect content_rect_; | 227 gfx::Rect content_rect_; |
183 float contents_scale_; | 228 float contents_scale_; |
184 RasterMode raster_mode_; | 229 RasterMode raster_mode_; |
185 bool is_tile_in_pending_tree_now_bin_; | 230 bool is_tile_in_pending_tree_now_bin_; |
186 TileResolution tile_resolution_; | 231 TileResolution tile_resolution_; |
187 int layer_id_; | 232 int layer_id_; |
188 const void* tile_id_; | 233 const void* tile_id_; |
189 int source_frame_number_; | 234 int source_frame_number_; |
190 RenderingStatsInstrumentation* rendering_stats_; | 235 RenderingStatsInstrumentation* rendering_stats_; |
191 const RasterWorkerPool::RasterTask::Reply reply_; | 236 const RasterWorkerPool::RasterTask::Reply reply_; |
| 237 ResourceProvider::Format texture_format_; |
192 | 238 |
193 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); | 239 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
194 }; | 240 }; |
195 | 241 |
196 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { | 242 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { |
197 public: | 243 public: |
198 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, | 244 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, |
199 int layer_id, | 245 int layer_id, |
200 RenderingStatsInstrumentation* rendering_stats, | 246 RenderingStatsInstrumentation* rendering_stats, |
201 const RasterWorkerPool::Task::Reply& reply) | 247 const RasterWorkerPool::Task::Reply& reply) |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 580 |
535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 581 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
536 decode_task, priority, graph); | 582 decode_task, priority, graph); |
537 decode_node->add_dependent(raster_node); | 583 decode_node->add_dependent(raster_node); |
538 } | 584 } |
539 | 585 |
540 return raster_node; | 586 return raster_node; |
541 } | 587 } |
542 | 588 |
543 } // namespace cc | 589 } // namespace cc |
OLD | NEW |