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 "skia/ext/lazy_pixel_ref.h" | 14 #include "skia/ext/lazy_pixel_ref.h" |
15 #include "skia/ext/paint_simplifier.h" | 15 #include "skia/ext/paint_simplifier.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
| 22 // Subclass of Allocator that takes a suitably allocated pointer and uses |
| 23 // it as the pixel memory for the bitmap. |
| 24 class IdentityAllocator : public SkBitmap::Allocator { |
| 25 public: |
| 26 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
| 27 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
| 28 dst->setPixels(buffer_); |
| 29 return true; |
| 30 } |
| 31 private: |
| 32 void* buffer_; |
| 33 }; |
| 34 |
21 // Flag to indicate whether we should try and detect that | 35 // Flag to indicate whether we should try and detect that |
22 // a tile is of solid color. | 36 // a tile is of solid color. |
23 const bool kUseColorEstimator = true; | 37 const bool kUseColorEstimator = true; |
24 | 38 |
25 class DisableLCDTextFilter : public SkDrawFilter { | 39 class DisableLCDTextFilter : public SkDrawFilter { |
26 public: | 40 public: |
27 // SkDrawFilter interface. | 41 // SkDrawFilter interface. |
28 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { | 42 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { |
29 if (type != SkDrawFilter::kText_Type) | 43 if (type != SkDrawFilter::kText_Type) |
30 return true; | 44 return true; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 96 |
83 // Record the solid color prediction. | 97 // Record the solid color prediction. |
84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 98 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
85 analysis_.is_solid_color); | 99 analysis_.is_solid_color); |
86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); | 100 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); |
87 | 101 |
88 // Clear the flag if we're not using the estimator. | 102 // Clear the flag if we're not using the estimator. |
89 analysis_.is_solid_color &= kUseColorEstimator; | 103 analysis_.is_solid_color &= kUseColorEstimator; |
90 } | 104 } |
91 | 105 |
92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { | 106 bool RunRasterOnThread(unsigned thread_index, |
| 107 void* buffer, |
| 108 gfx::Size size, |
| 109 int stride) { |
93 TRACE_EVENT2( | 110 TRACE_EVENT2( |
94 benchmark_instrumentation::kCategory, | 111 benchmark_instrumentation::kCategory, |
95 benchmark_instrumentation::kRunRasterOnThread, | 112 benchmark_instrumentation::kRunRasterOnThread, |
96 benchmark_instrumentation::kData, | 113 benchmark_instrumentation::kData, |
97 TracedValue::FromValue(DataAsValue().release()), | 114 TracedValue::FromValue(DataAsValue().release()), |
98 "raster_mode", | 115 "raster_mode", |
99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 116 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
100 | 117 |
101 devtools_instrumentation::ScopedLayerTask raster_task( | 118 devtools_instrumentation::ScopedLayerTask raster_task( |
102 devtools_instrumentation::kRasterTask, layer_id_); | 119 devtools_instrumentation::kRasterTask, layer_id_); |
103 | 120 |
104 DCHECK(picture_pile_.get()); | 121 DCHECK(picture_pile_.get()); |
105 DCHECK(device); | 122 DCHECK(buffer); |
106 | 123 |
107 if (analysis_.is_solid_color) | 124 if (analysis_.is_solid_color) |
108 return false; | 125 return false; |
109 | 126 |
110 PicturePileImpl* picture_clone = | 127 PicturePileImpl* picture_clone = |
111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 128 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
112 | 129 |
113 SkCanvas canvas(device); | 130 SkBitmap bitmap; |
| 131 switch (resource()->format()) { |
| 132 case RGBA_4444: |
| 133 // Use the default stride if we will eventually convert this |
| 134 // bitmap to 4444. |
| 135 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 136 size.width(), |
| 137 size.height()); |
| 138 bitmap.allocPixels(); |
| 139 break; |
| 140 case RGBA_8888: |
| 141 case BGRA_8888: |
| 142 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 143 size.width(), |
| 144 size.height(), |
| 145 stride); |
| 146 bitmap.setPixels(buffer); |
| 147 break; |
| 148 case LUMINANCE_8: |
| 149 NOTREACHED(); |
| 150 break; |
| 151 } |
114 | 152 |
| 153 SkBitmapDevice device(bitmap); |
| 154 SkCanvas canvas(&device); |
115 skia::RefPtr<SkDrawFilter> draw_filter; | 155 skia::RefPtr<SkDrawFilter> draw_filter; |
116 switch (raster_mode_) { | 156 switch (raster_mode_) { |
117 case LOW_QUALITY_RASTER_MODE: | 157 case LOW_QUALITY_RASTER_MODE: |
118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 158 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
119 break; | 159 break; |
120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 160 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 161 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
122 break; | 162 break; |
123 case HIGH_QUALITY_RASTER_MODE: | 163 case HIGH_QUALITY_RASTER_MODE: |
124 break; | 164 break; |
(...skipping 17 matching lines...) Expand all Loading... |
142 HISTOGRAM_CUSTOM_COUNTS( | 182 HISTOGRAM_CUSTOM_COUNTS( |
143 "Renderer4.PictureRasterTimeUS", | 183 "Renderer4.PictureRasterTimeUS", |
144 raster_stats.total_rasterize_time.InMicroseconds(), | 184 raster_stats.total_rasterize_time.InMicroseconds(), |
145 0, | 185 0, |
146 100000, | 186 100000, |
147 100); | 187 100); |
148 } else { | 188 } else { |
149 picture_clone->RasterToBitmap( | 189 picture_clone->RasterToBitmap( |
150 &canvas, content_rect_, contents_scale_, NULL); | 190 &canvas, content_rect_, contents_scale_, NULL); |
151 } | 191 } |
| 192 |
| 193 ChangeBitmapConfigIfNeeded(bitmap, buffer); |
| 194 |
152 return true; | 195 return true; |
153 } | 196 } |
154 | 197 |
155 // Overridden from internal::RasterWorkerPoolTask: | 198 // Overridden from internal::RasterWorkerPoolTask: |
156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 199 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 200 void* buffer, |
| 201 gfx::Size size, |
| 202 int stride) |
157 OVERRIDE { | 203 OVERRIDE { |
158 RunAnalysisOnThread(thread_index); | 204 RunAnalysisOnThread(thread_index); |
159 return RunRasterOnThread(device, thread_index); | 205 return RunRasterOnThread(thread_index, buffer, size, stride); |
160 } | 206 } |
161 virtual void CompleteOnOriginThread() OVERRIDE { | 207 virtual void CompleteOnOriginThread() OVERRIDE { |
162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 208 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
163 } | 209 } |
164 | 210 |
165 protected: | 211 protected: |
166 virtual ~RasterWorkerPoolTaskImpl() {} | 212 virtual ~RasterWorkerPoolTaskImpl() {} |
167 | 213 |
168 private: | 214 private: |
169 scoped_ptr<base::Value> DataAsValue() const { | 215 scoped_ptr<base::Value> DataAsValue() const { |
170 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 216 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
171 res->Set("tile_id", TracedValue::CreateIDRef(tile_id_).release()); | 217 res->Set("tile_id", TracedValue::CreateIDRef(tile_id_).release()); |
172 res->SetBoolean("is_tile_in_pending_tree_now_bin", | 218 res->SetBoolean("is_tile_in_pending_tree_now_bin", |
173 is_tile_in_pending_tree_now_bin_); | 219 is_tile_in_pending_tree_now_bin_); |
174 res->Set("resolution", TileResolutionAsValue(tile_resolution_).release()); | 220 res->Set("resolution", TileResolutionAsValue(tile_resolution_).release()); |
175 res->SetInteger("source_frame_number", source_frame_number_); | 221 res->SetInteger("source_frame_number", source_frame_number_); |
176 res->SetInteger("layer_id", layer_id_); | 222 res->SetInteger("layer_id", layer_id_); |
177 return res.PassAs<base::Value>(); | 223 return res.PassAs<base::Value>(); |
178 } | 224 } |
179 | 225 |
| 226 void ChangeBitmapConfigIfNeeded(const SkBitmap& bitmap, |
| 227 void* buffer) { |
| 228 TRACE_EVENT0("cc", "RasterWorkerPoolTaskImpl::ChangeBitmapConfigIfNeeded"); |
| 229 SkBitmap::Config config = SkBitmapConfigFromFormat( |
| 230 resource()->format()); |
| 231 if (bitmap.getConfig() != config) { |
| 232 SkBitmap bitmap_dest; |
| 233 IdentityAllocator allocator(buffer); |
| 234 bitmap.copyTo(&bitmap_dest, config, &allocator); |
| 235 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 236 // bitmap data. This check will be removed once crbug.com/293728 is fixed. |
| 237 CHECK_EQ(0u, bitmap_dest.rowBytes() % 4); |
| 238 } |
| 239 } |
| 240 |
180 PicturePileImpl::Analysis analysis_; | 241 PicturePileImpl::Analysis analysis_; |
181 scoped_refptr<PicturePileImpl> picture_pile_; | 242 scoped_refptr<PicturePileImpl> picture_pile_; |
182 gfx::Rect content_rect_; | 243 gfx::Rect content_rect_; |
183 float contents_scale_; | 244 float contents_scale_; |
184 RasterMode raster_mode_; | 245 RasterMode raster_mode_; |
185 bool is_tile_in_pending_tree_now_bin_; | 246 bool is_tile_in_pending_tree_now_bin_; |
186 TileResolution tile_resolution_; | 247 TileResolution tile_resolution_; |
187 int layer_id_; | 248 int layer_id_; |
188 const void* tile_id_; | 249 const void* tile_id_; |
189 int source_frame_number_; | 250 int source_frame_number_; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 595 |
535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 596 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
536 decode_task, priority, graph); | 597 decode_task, priority, graph); |
537 decode_node->add_dependent(raster_node); | 598 decode_node->add_dependent(raster_node); |
538 } | 599 } |
539 | 600 |
540 return raster_node; | 601 return raster_node; |
541 } | 602 } |
542 | 603 |
543 } // namespace cc | 604 } // namespace cc |
OLD | NEW |