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