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; |
31 | 46 |
32 paint->setLCDRenderText(false); | 47 paint->setLCDRenderText(false); |
33 return true; | 48 return true; |
34 } | 49 } |
35 }; | 50 }; |
36 | 51 |
| 52 SkBitmap::Config SkBitmapConfigFromFormat(ResourceProvider::Format format) { |
| 53 switch (format) { |
| 54 case ResourceProvider::RGBA_4444: |
| 55 return SkBitmap::kARGB_4444_Config; |
| 56 case ResourceProvider::RGBA_8888: |
| 57 case ResourceProvider::BGRA_8888: |
| 58 return SkBitmap::kARGB_8888_Config; |
| 59 case ResourceProvider::LUMINANCE_8: |
| 60 NOTREACHED(); |
| 61 break; |
| 62 } |
| 63 NOTREACHED(); |
| 64 return SkBitmap::kARGB_8888_Config; |
| 65 } |
| 66 |
| 67 void ChangeBitmapConfigIfPossible(const SkBitmap& bitmap, |
| 68 void* buffer, |
| 69 ResourceProvider::Format format) { |
| 70 TRACE_EVENT0("cc", "ChangeBitmapConfig"); |
| 71 if (bitmap.getConfig() != SkBitmapConfigFromFormat(format)) { |
| 72 SkBitmap bitmap_dest; |
| 73 IdentityAllocator allocator(buffer); |
| 74 bitmap.copyTo(&bitmap_dest, SkBitmapConfigFromFormat(format), &allocator); |
| 75 } |
| 76 } |
| 77 |
37 class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { | 78 class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
38 public: | 79 public: |
39 RasterWorkerPoolTaskImpl(const Resource* resource, | 80 RasterWorkerPoolTaskImpl(const Resource* resource, |
40 PicturePileImpl* picture_pile, | 81 PicturePileImpl* picture_pile, |
41 gfx::Rect content_rect, | 82 gfx::Rect content_rect, |
42 float contents_scale, | 83 float contents_scale, |
43 RasterMode raster_mode, | 84 RasterMode raster_mode, |
44 bool is_tile_in_pending_tree_now_bin, | 85 bool is_tile_in_pending_tree_now_bin, |
45 TileResolution tile_resolution, | 86 TileResolution tile_resolution, |
46 int layer_id, | 87 int layer_id, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 123 |
83 // Record the solid color prediction. | 124 // Record the solid color prediction. |
84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 125 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
85 analysis_.is_solid_color); | 126 analysis_.is_solid_color); |
86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); | 127 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); |
87 | 128 |
88 // Clear the flag if we're not using the estimator. | 129 // Clear the flag if we're not using the estimator. |
89 analysis_.is_solid_color &= kUseColorEstimator; | 130 analysis_.is_solid_color &= kUseColorEstimator; |
90 } | 131 } |
91 | 132 |
92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { | 133 bool RunRasterOnThread(unsigned thread_index, |
| 134 void* buffer, |
| 135 gfx::Size size, |
| 136 int stride) { |
93 TRACE_EVENT2( | 137 TRACE_EVENT2( |
94 benchmark_instrumentation::kCategory, | 138 benchmark_instrumentation::kCategory, |
95 benchmark_instrumentation::kRunRasterOnThread, | 139 benchmark_instrumentation::kRunRasterOnThread, |
96 benchmark_instrumentation::kData, | 140 benchmark_instrumentation::kData, |
97 TracedValue::FromValue(DataAsValue().release()), | 141 TracedValue::FromValue(DataAsValue().release()), |
98 "raster_mode", | 142 "raster_mode", |
99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 143 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
100 | 144 |
101 devtools_instrumentation::ScopedLayerTask raster_task( | 145 devtools_instrumentation::ScopedLayerTask raster_task( |
102 devtools_instrumentation::kRasterTask, layer_id_); | 146 devtools_instrumentation::kRasterTask, layer_id_); |
103 | 147 |
104 DCHECK(picture_pile_.get()); | 148 DCHECK(picture_pile_.get()); |
105 DCHECK(device); | 149 DCHECK(buffer); |
106 | 150 |
107 if (analysis_.is_solid_color) | 151 if (analysis_.is_solid_color) |
108 return false; | 152 return false; |
109 | 153 |
110 PicturePileImpl* picture_clone = | 154 PicturePileImpl* picture_clone = |
111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 155 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
112 | 156 |
113 SkCanvas canvas(device); | 157 SkBitmap bitmap; |
| 158 switch (resource()->format()) { |
| 159 case ResourceProvider::RGBA_4444: |
| 160 // Use the default stride if we will eventually convert this |
| 161 // bitmap to 4444. |
| 162 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 163 size.width(), |
| 164 size.height()); |
| 165 bitmap.allocPixels(); |
| 166 break; |
| 167 case ResourceProvider::RGBA_8888: |
| 168 case ResourceProvider::BGRA_8888: |
| 169 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 170 size.width(), |
| 171 size.height(), |
| 172 stride); |
| 173 bitmap.setPixels(buffer); |
| 174 break; |
| 175 case ResourceProvider::LUMINANCE_8: |
| 176 NOTREACHED(); |
| 177 break; |
| 178 } |
114 | 179 |
| 180 SkBitmapDevice device(bitmap); |
| 181 SkCanvas canvas(&device); |
115 skia::RefPtr<SkDrawFilter> draw_filter; | 182 skia::RefPtr<SkDrawFilter> draw_filter; |
116 switch (raster_mode_) { | 183 switch (raster_mode_) { |
117 case LOW_QUALITY_RASTER_MODE: | 184 case LOW_QUALITY_RASTER_MODE: |
118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 185 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
119 break; | 186 break; |
120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 187 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 188 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
122 break; | 189 break; |
123 case HIGH_QUALITY_RASTER_MODE: | 190 case HIGH_QUALITY_RASTER_MODE: |
124 break; | 191 break; |
(...skipping 17 matching lines...) Expand all Loading... |
142 HISTOGRAM_CUSTOM_COUNTS( | 209 HISTOGRAM_CUSTOM_COUNTS( |
143 "Renderer4.PictureRasterTimeUS", | 210 "Renderer4.PictureRasterTimeUS", |
144 raster_stats.total_rasterize_time.InMicroseconds(), | 211 raster_stats.total_rasterize_time.InMicroseconds(), |
145 0, | 212 0, |
146 100000, | 213 100000, |
147 100); | 214 100); |
148 } else { | 215 } else { |
149 picture_clone->RasterToBitmap( | 216 picture_clone->RasterToBitmap( |
150 &canvas, content_rect_, contents_scale_, NULL); | 217 &canvas, content_rect_, contents_scale_, NULL); |
151 } | 218 } |
| 219 |
| 220 ChangeBitmapConfigIfPossible(bitmap, buffer, resource()->format()); |
| 221 |
152 return true; | 222 return true; |
153 } | 223 } |
154 | 224 |
155 // Overridden from internal::RasterWorkerPoolTask: | 225 // Overridden from internal::RasterWorkerPoolTask: |
156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 226 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 227 void* buffer, |
| 228 gfx::Size size, |
| 229 int stride) |
157 OVERRIDE { | 230 OVERRIDE { |
158 RunAnalysisOnThread(thread_index); | 231 RunAnalysisOnThread(thread_index); |
159 return RunRasterOnThread(device, thread_index); | 232 return RunRasterOnThread(thread_index, buffer, size, stride); |
160 } | 233 } |
161 virtual void CompleteOnOriginThread() OVERRIDE { | 234 virtual void CompleteOnOriginThread() OVERRIDE { |
162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 235 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
163 } | 236 } |
164 | 237 |
165 protected: | 238 protected: |
166 virtual ~RasterWorkerPoolTaskImpl() {} | 239 virtual ~RasterWorkerPoolTaskImpl() {} |
167 | 240 |
168 private: | 241 private: |
169 scoped_ptr<base::Value> DataAsValue() const { | 242 scoped_ptr<base::Value> DataAsValue() const { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 607 |
535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 608 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
536 decode_task, priority, graph); | 609 decode_task, priority, graph); |
537 decode_node->add_dependent(raster_node); | 610 decode_node->add_dependent(raster_node); |
538 } | 611 } |
539 | 612 |
540 return raster_node; | 613 return raster_node; |
541 } | 614 } |
542 | 615 |
543 } // namespace cc | 616 } // namespace cc |
OLD | NEW |