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/devtools_instrumentation.h" | 10 #include "cc/debug/devtools_instrumentation.h" |
11 #include "cc/debug/traced_value.h" | 11 #include "cc/debug/traced_value.h" |
12 #include "cc/resources/picture_pile_impl.h" | 12 #include "cc/resources/picture_pile_impl.h" |
13 #include "skia/ext/lazy_pixel_ref.h" | 13 #include "skia/ext/lazy_pixel_ref.h" |
14 #include "skia/ext/paint_simplifier.h" | 14 #include "skia/ext/paint_simplifier.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "third_party/skia/include/utils/SkNWayCanvas.h" | |
17 #include "ui/gfx/skia_util.h" | |
18 | 16 |
19 namespace cc { | 17 namespace cc { |
20 | 18 |
21 namespace { | 19 namespace { |
22 | 20 |
23 // Subclass of Allocator that takes a suitably allocated pointer and uses | 21 // Subclass of Allocator that takes a suitably allocated pointer and uses |
24 // it as the pixel memory for the bitmap. | 22 // it as the pixel memory for the bitmap. |
25 class IdentityAllocator : public SkBitmap::Allocator { | 23 class IdentityAllocator : public SkBitmap::Allocator { |
26 public: | 24 public: |
27 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | 25 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
28 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { | 26 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
29 dst->setPixels(buffer_); | 27 dst->setPixels(buffer_); |
30 return true; | 28 return true; |
31 } | 29 } |
32 private: | 30 private: |
33 void* buffer_; | 31 void* buffer_; |
34 }; | 32 }; |
35 | 33 |
| 34 // Flag to indicate whether we should try and detect that |
| 35 // a tile is of solid color. |
| 36 const bool kUseColorEstimator = true; |
| 37 |
36 class DisableLCDTextFilter : public SkDrawFilter { | 38 class DisableLCDTextFilter : public SkDrawFilter { |
37 public: | 39 public: |
38 // SkDrawFilter interface. | 40 // SkDrawFilter interface. |
39 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { | 41 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { |
40 if (type != SkDrawFilter::kText_Type) | 42 if (type != SkDrawFilter::kText_Type) |
41 return true; | 43 return true; |
42 | 44 |
43 paint->setLCDRenderText(false); | 45 paint->setLCDRenderText(false); |
44 return true; | 46 return true; |
45 } | 47 } |
(...skipping 18 matching lines...) Expand all Loading... |
64 content_rect_(content_rect), | 66 content_rect_(content_rect), |
65 contents_scale_(contents_scale), | 67 contents_scale_(contents_scale), |
66 raster_mode_(raster_mode), | 68 raster_mode_(raster_mode), |
67 tile_resolution_(tile_resolution), | 69 tile_resolution_(tile_resolution), |
68 layer_id_(layer_id), | 70 layer_id_(layer_id), |
69 tile_id_(tile_id), | 71 tile_id_(tile_id), |
70 source_frame_number_(source_frame_number), | 72 source_frame_number_(source_frame_number), |
71 rendering_stats_(rendering_stats), | 73 rendering_stats_(rendering_stats), |
72 reply_(reply) {} | 74 reply_(reply) {} |
73 | 75 |
74 // Overridden from internal::RasterWorkerPoolTask: | 76 void RunAnalysisOnThread(unsigned thread_index) { |
75 virtual bool RunOnWorkerThread(unsigned thread_index, | 77 TRACE_EVENT1("cc", |
76 void* buffer, | 78 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", |
77 gfx::Size size, | 79 "data", |
78 int stride) OVERRIDE { | 80 TracedValue::FromValue(DataAsValue().release())); |
| 81 |
| 82 DCHECK(picture_pile_.get()); |
| 83 DCHECK(rendering_stats_); |
| 84 |
| 85 PicturePileImpl* picture_clone = |
| 86 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| 87 |
| 88 DCHECK(picture_clone); |
| 89 |
| 90 picture_clone->AnalyzeInRect( |
| 91 content_rect_, contents_scale_, &analysis_, rendering_stats_); |
| 92 |
| 93 // Record the solid color prediction. |
| 94 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
| 95 analysis_.is_solid_color); |
| 96 |
| 97 // Clear the flag if we're not using the estimator. |
| 98 analysis_.is_solid_color &= kUseColorEstimator; |
| 99 } |
| 100 |
| 101 bool RunRasterOnThread(unsigned thread_index, |
| 102 void* buffer, |
| 103 gfx::Size size, |
| 104 int stride) { |
79 TRACE_EVENT2( | 105 TRACE_EVENT2( |
80 "cc", "RasterWorkerPoolTaskImpl::RunRasterOnThread", | 106 "cc", "RasterWorkerPoolTaskImpl::RunRasterOnThread", |
81 "data", | 107 "data", |
82 TracedValue::FromValue(DataAsValue().release()), | 108 TracedValue::FromValue(DataAsValue().release()), |
83 "raster_mode", | 109 "raster_mode", |
84 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 110 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
85 | 111 |
86 devtools_instrumentation::ScopedLayerTask raster_task( | 112 devtools_instrumentation::ScopedLayerTask raster_task( |
87 devtools_instrumentation::kRasterTask, layer_id_); | 113 devtools_instrumentation::kRasterTask, layer_id_); |
88 | 114 |
89 DCHECK(picture_pile_.get()); | 115 DCHECK(picture_pile_.get()); |
90 DCHECK(buffer); | 116 DCHECK(buffer); |
91 | 117 |
| 118 if (analysis_.is_solid_color) |
| 119 return false; |
| 120 |
92 PicturePileImpl* picture_clone = | 121 PicturePileImpl* picture_clone = |
93 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 122 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
94 | 123 |
95 SkBitmap bitmap; | 124 SkBitmap bitmap; |
96 switch (resource()->format()) { | 125 switch (resource()->format()) { |
97 case RGBA_4444: | 126 case RGBA_4444: |
98 // Use the default stride if we will eventually convert this | 127 // Use the default stride if we will eventually convert this |
99 // bitmap to 4444. | 128 // bitmap to 4444. |
100 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 129 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
101 size.width(), | 130 size.width(), |
102 size.height()); | 131 size.height()); |
103 bitmap.allocPixels(); | 132 bitmap.allocPixels(); |
104 break; | 133 break; |
105 case RGBA_8888: | 134 case RGBA_8888: |
106 case BGRA_8888: | 135 case BGRA_8888: |
107 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 136 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
108 size.width(), | 137 size.width(), |
109 size.height(), | 138 size.height(), |
110 stride); | 139 stride); |
111 bitmap.setPixels(buffer); | 140 bitmap.setPixels(buffer); |
112 break; | 141 break; |
113 case LUMINANCE_8: | 142 case LUMINANCE_8: |
114 case RGB_565: | 143 case RGB_565: |
115 case ETC1: | 144 case ETC1: |
116 NOTREACHED(); | 145 NOTREACHED(); |
117 break; | 146 break; |
118 } | 147 } |
119 | 148 |
120 SkBitmap empty_bitmap; | 149 SkBitmapDevice device(bitmap); |
121 empty_bitmap.setConfig( | 150 SkCanvas canvas(&device); |
122 SkBitmap::kNo_Config, content_rect_.width(), content_rect_.height()); | |
123 gfx::Rect analysis_rect( | |
124 picture_clone->AnalysisRectForRaster(content_rect_, contents_scale_)); | |
125 skia::AnalysisDevice analysis_device(empty_bitmap, | |
126 gfx::RectToSkRect(analysis_rect)); | |
127 skia::AnalysisCanvas analysis_canvas(&analysis_device); | |
128 | |
129 SkBitmapDevice raster_device(bitmap); | |
130 SkCanvas raster_canvas(&raster_device); | |
131 | |
132 SkNWayCanvas canvas(content_rect_.width(), content_rect_.height()); | |
133 canvas.addCanvas(&analysis_canvas); | |
134 canvas.addCanvas(&raster_canvas); | |
135 | |
136 skia::RefPtr<SkDrawFilter> draw_filter; | 151 skia::RefPtr<SkDrawFilter> draw_filter; |
137 switch (raster_mode_) { | 152 switch (raster_mode_) { |
138 case LOW_QUALITY_RASTER_MODE: | 153 case LOW_QUALITY_RASTER_MODE: |
139 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 154 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
140 break; | 155 break; |
141 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 156 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
142 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 157 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
143 break; | 158 break; |
144 case HIGH_QUALITY_RASTER_MODE: | 159 case HIGH_QUALITY_RASTER_MODE: |
145 break; | 160 break; |
(...skipping 25 matching lines...) Expand all Loading... |
171 HISTOGRAM_CUSTOM_COUNTS( | 186 HISTOGRAM_CUSTOM_COUNTS( |
172 "Renderer4.PictureRasterTimeUS", | 187 "Renderer4.PictureRasterTimeUS", |
173 (current_rasterize_time - prev_rasterize_time).InMicroseconds(), | 188 (current_rasterize_time - prev_rasterize_time).InMicroseconds(), |
174 0, | 189 0, |
175 100000, | 190 100000, |
176 100); | 191 100); |
177 } | 192 } |
178 | 193 |
179 ChangeBitmapConfigIfNeeded(bitmap, buffer); | 194 ChangeBitmapConfigIfNeeded(bitmap, buffer); |
180 | 195 |
181 analysis_.is_solid_color = | 196 return true; |
182 analysis_canvas.GetColorIfSolid(&analysis_.solid_color); | |
183 analysis_.has_text = analysis_canvas.HasText(); | |
184 | |
185 // Record the solid color prediction. | |
186 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | |
187 analysis_.is_solid_color); | |
188 | |
189 return !analysis_.is_solid_color; | |
190 } | 197 } |
191 | 198 |
| 199 // Overridden from internal::RasterWorkerPoolTask: |
| 200 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 201 void* buffer, |
| 202 gfx::Size size, |
| 203 int stride) |
| 204 OVERRIDE { |
| 205 RunAnalysisOnThread(thread_index); |
| 206 return RunRasterOnThread(thread_index, buffer, size, stride); |
| 207 } |
192 virtual void CompleteOnOriginThread() OVERRIDE { | 208 virtual void CompleteOnOriginThread() OVERRIDE { |
193 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 209 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
194 } | 210 } |
195 | 211 |
196 protected: | 212 protected: |
197 virtual ~RasterWorkerPoolTaskImpl() {} | 213 virtual ~RasterWorkerPoolTaskImpl() {} |
198 | 214 |
199 private: | 215 private: |
200 scoped_ptr<base::Value> DataAsValue() const { | 216 scoped_ptr<base::Value> DataAsValue() const { |
201 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 217 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 587 |
572 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 588 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
573 decode_task, priority, graph); | 589 decode_task, priority, graph); |
574 decode_node->add_dependent(raster_node); | 590 decode_node->add_dependent(raster_node); |
575 } | 591 } |
576 | 592 |
577 return raster_node; | 593 return raster_node; |
578 } | 594 } |
579 | 595 |
580 } // namespace cc | 596 } // namespace cc |
OLD | NEW |