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 10 matching lines...) Expand all Loading... | |
41 gfx::Rect content_rect, | 56 gfx::Rect content_rect, |
42 float contents_scale, | 57 float contents_scale, |
43 RasterMode raster_mode, | 58 RasterMode raster_mode, |
44 bool is_tile_in_pending_tree_now_bin, | 59 bool is_tile_in_pending_tree_now_bin, |
45 TileResolution tile_resolution, | 60 TileResolution tile_resolution, |
46 int layer_id, | 61 int layer_id, |
47 const void* tile_id, | 62 const void* tile_id, |
48 int source_frame_number, | 63 int source_frame_number, |
49 RenderingStatsInstrumentation* rendering_stats, | 64 RenderingStatsInstrumentation* rendering_stats, |
50 const RasterWorkerPool::RasterTask::Reply& reply, | 65 const RasterWorkerPool::RasterTask::Reply& reply, |
51 TaskVector* dependencies) | 66 TaskVector* dependencies, |
67 ResourceProvider::TextureFormat format) | |
52 : internal::RasterWorkerPoolTask(resource, dependencies), | 68 : internal::RasterWorkerPoolTask(resource, dependencies), |
53 picture_pile_(picture_pile), | 69 picture_pile_(picture_pile), |
54 content_rect_(content_rect), | 70 content_rect_(content_rect), |
55 contents_scale_(contents_scale), | 71 contents_scale_(contents_scale), |
56 raster_mode_(raster_mode), | 72 raster_mode_(raster_mode), |
57 is_tile_in_pending_tree_now_bin_(is_tile_in_pending_tree_now_bin), | 73 is_tile_in_pending_tree_now_bin_(is_tile_in_pending_tree_now_bin), |
58 tile_resolution_(tile_resolution), | 74 tile_resolution_(tile_resolution), |
59 layer_id_(layer_id), | 75 layer_id_(layer_id), |
60 tile_id_(tile_id), | 76 tile_id_(tile_id), |
61 source_frame_number_(source_frame_number), | 77 source_frame_number_(source_frame_number), |
62 rendering_stats_(rendering_stats), | 78 rendering_stats_(rendering_stats), |
63 reply_(reply) {} | 79 reply_(reply), |
80 texture_format_(format) {} | |
64 | 81 |
65 void RunAnalysisOnThread(unsigned thread_index) { | 82 void RunAnalysisOnThread(unsigned thread_index) { |
66 TRACE_EVENT1("cc", | 83 TRACE_EVENT1("cc", |
67 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", | 84 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", |
68 "data", | 85 "data", |
69 TracedValue::FromValue(DataAsValue().release())); | 86 TracedValue::FromValue(DataAsValue().release())); |
70 | 87 |
71 DCHECK(picture_pile_.get()); | 88 DCHECK(picture_pile_.get()); |
72 DCHECK(rendering_stats_); | 89 DCHECK(rendering_stats_); |
73 | 90 |
74 PicturePileImpl* picture_clone = | 91 PicturePileImpl* picture_clone = |
75 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 92 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
76 | 93 |
77 DCHECK(picture_clone); | 94 DCHECK(picture_clone); |
78 | 95 |
79 base::TimeTicks start_time = rendering_stats_->StartRecording(); | 96 base::TimeTicks start_time = rendering_stats_->StartRecording(); |
80 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_); | 97 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_); |
81 base::TimeDelta duration = rendering_stats_->EndRecording(start_time); | 98 base::TimeDelta duration = rendering_stats_->EndRecording(start_time); |
82 | 99 |
83 // Record the solid color prediction. | 100 // Record the solid color prediction. |
84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 101 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
85 analysis_.is_solid_color); | 102 analysis_.is_solid_color); |
86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); | 103 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); |
87 | 104 |
88 // Clear the flag if we're not using the estimator. | 105 // Clear the flag if we're not using the estimator. |
89 analysis_.is_solid_color &= kUseColorEstimator; | 106 analysis_.is_solid_color &= kUseColorEstimator; |
90 } | 107 } |
91 | 108 |
92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { | 109 bool RunRasterOnThread(unsigned thread_index, |
110 void* buffer, | |
111 gfx::Size size, | |
112 int stride) { | |
93 TRACE_EVENT2( | 113 TRACE_EVENT2( |
94 benchmark_instrumentation::kCategory, | 114 benchmark_instrumentation::kCategory, |
95 benchmark_instrumentation::kRunRasterOnThread, | 115 benchmark_instrumentation::kRunRasterOnThread, |
96 benchmark_instrumentation::kData, | 116 benchmark_instrumentation::kData, |
97 TracedValue::FromValue(DataAsValue().release()), | 117 TracedValue::FromValue(DataAsValue().release()), |
98 "raster_mode", | 118 "raster_mode", |
99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 119 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
100 | 120 |
101 devtools_instrumentation::ScopedLayerTask raster_task( | 121 devtools_instrumentation::ScopedLayerTask raster_task( |
102 devtools_instrumentation::kRasterTask, layer_id_); | 122 devtools_instrumentation::kRasterTask, layer_id_); |
103 | 123 |
104 DCHECK(picture_pile_.get()); | 124 DCHECK(picture_pile_.get()); |
105 DCHECK(device); | 125 DCHECK(buffer); |
106 | 126 |
107 if (analysis_.is_solid_color) | 127 if (analysis_.is_solid_color) |
108 return false; | 128 return false; |
109 | 129 |
110 PicturePileImpl* picture_clone = | 130 PicturePileImpl* picture_clone = |
111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 131 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
112 | 132 |
113 SkCanvas canvas(device); | 133 SkBitmap bitmap_32; |
134 bitmap_32.setConfig(SkBitmap::kARGB_8888_Config, | |
135 size.width(), | |
136 size.height(), | |
137 stride); | |
138 if (texture_format_ == ResourceProvider::RGBA_4444) { | |
139 bitmap_32.allocPixels(); | |
140 } else { | |
141 bitmap_32.setPixels(buffer); | |
142 } | |
143 SkBitmapDevice device_32(bitmap_32); | |
114 | 144 |
145 SkCanvas canvas(&device_32); | |
115 skia::RefPtr<SkDrawFilter> draw_filter; | 146 skia::RefPtr<SkDrawFilter> draw_filter; |
116 switch (raster_mode_) { | 147 switch (raster_mode_) { |
117 case LOW_QUALITY_RASTER_MODE: | 148 case LOW_QUALITY_RASTER_MODE: |
118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 149 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
119 break; | 150 break; |
120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 151 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 152 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
122 break; | 153 break; |
123 case HIGH_QUALITY_RASTER_MODE: | 154 case HIGH_QUALITY_RASTER_MODE: |
124 break; | 155 break; |
(...skipping 17 matching lines...) Expand all Loading... | |
142 HISTOGRAM_CUSTOM_COUNTS( | 173 HISTOGRAM_CUSTOM_COUNTS( |
143 "Renderer4.PictureRasterTimeUS", | 174 "Renderer4.PictureRasterTimeUS", |
144 raster_stats.total_rasterize_time.InMicroseconds(), | 175 raster_stats.total_rasterize_time.InMicroseconds(), |
145 0, | 176 0, |
146 100000, | 177 100000, |
147 100); | 178 100); |
148 } else { | 179 } else { |
149 picture_clone->RasterToBitmap( | 180 picture_clone->RasterToBitmap( |
150 &canvas, content_rect_, contents_scale_, NULL); | 181 &canvas, content_rect_, contents_scale_, NULL); |
151 } | 182 } |
183 | |
184 if (texture_format_ == ResourceProvider::RGBA_4444) { | |
185 SkBitmap bitmap_16; | |
186 IdentityAllocator allocator(buffer); | |
187 bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); | |
188 } | |
189 | |
152 return true; | 190 return true; |
153 } | 191 } |
154 | 192 |
155 // Overridden from internal::RasterWorkerPoolTask: | 193 // Overridden from internal::RasterWorkerPoolTask: |
156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 194 virtual bool RunOnWorkerThread(unsigned thread_index, |
195 void* buffer, | |
196 gfx::Size size, | |
197 int stride) | |
157 OVERRIDE { | 198 OVERRIDE { |
158 RunAnalysisOnThread(thread_index); | 199 RunAnalysisOnThread(thread_index); |
159 return RunRasterOnThread(device, thread_index); | 200 return RunRasterOnThread(thread_index, buffer, size, stride); |
160 } | 201 } |
161 virtual void CompleteOnOriginThread() OVERRIDE { | 202 virtual void CompleteOnOriginThread() OVERRIDE { |
162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 203 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
163 } | 204 } |
164 | 205 |
165 protected: | 206 protected: |
166 virtual ~RasterWorkerPoolTaskImpl() {} | 207 virtual ~RasterWorkerPoolTaskImpl() {} |
167 | 208 |
168 private: | 209 private: |
169 scoped_ptr<base::Value> DataAsValue() const { | 210 scoped_ptr<base::Value> DataAsValue() const { |
(...skipping 12 matching lines...) Expand all Loading... | |
182 gfx::Rect content_rect_; | 223 gfx::Rect content_rect_; |
183 float contents_scale_; | 224 float contents_scale_; |
184 RasterMode raster_mode_; | 225 RasterMode raster_mode_; |
185 bool is_tile_in_pending_tree_now_bin_; | 226 bool is_tile_in_pending_tree_now_bin_; |
186 TileResolution tile_resolution_; | 227 TileResolution tile_resolution_; |
187 int layer_id_; | 228 int layer_id_; |
188 const void* tile_id_; | 229 const void* tile_id_; |
189 int source_frame_number_; | 230 int source_frame_number_; |
190 RenderingStatsInstrumentation* rendering_stats_; | 231 RenderingStatsInstrumentation* rendering_stats_; |
191 const RasterWorkerPool::RasterTask::Reply reply_; | 232 const RasterWorkerPool::RasterTask::Reply reply_; |
233 ResourceProvider::TextureFormat texture_format_; | |
reveman
2013/09/12 15:57:40
Don't think you need this. You can get the format
kaanb
2013/09/13 00:11:08
Done.
| |
192 | 234 |
193 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); | 235 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
194 }; | 236 }; |
195 | 237 |
196 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { | 238 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { |
197 public: | 239 public: |
198 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, | 240 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, |
199 int layer_id, | 241 int layer_id, |
200 RenderingStatsInstrumentation* rendering_stats, | 242 RenderingStatsInstrumentation* rendering_stats, |
201 const RasterWorkerPool::Task::Reply& reply) | 243 const RasterWorkerPool::Task::Reply& reply) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 gfx::Rect content_rect, | 414 gfx::Rect content_rect, |
373 float contents_scale, | 415 float contents_scale, |
374 RasterMode raster_mode, | 416 RasterMode raster_mode, |
375 bool is_tile_in_pending_tree_now_bin, | 417 bool is_tile_in_pending_tree_now_bin, |
376 TileResolution tile_resolution, | 418 TileResolution tile_resolution, |
377 int layer_id, | 419 int layer_id, |
378 const void* tile_id, | 420 const void* tile_id, |
379 int source_frame_number, | 421 int source_frame_number, |
380 RenderingStatsInstrumentation* rendering_stats, | 422 RenderingStatsInstrumentation* rendering_stats, |
381 const RasterTask::Reply& reply, | 423 const RasterTask::Reply& reply, |
382 Task::Set* dependencies) { | 424 Task::Set* dependencies, |
425 ResourceProvider::TextureFormat texture_type) { | |
383 return RasterTask( | 426 return RasterTask( |
384 new RasterWorkerPoolTaskImpl(resource, | 427 new RasterWorkerPoolTaskImpl(resource, |
385 picture_pile, | 428 picture_pile, |
386 content_rect, | 429 content_rect, |
387 contents_scale, | 430 contents_scale, |
388 raster_mode, | 431 raster_mode, |
389 is_tile_in_pending_tree_now_bin, | 432 is_tile_in_pending_tree_now_bin, |
390 tile_resolution, | 433 tile_resolution, |
391 layer_id, | 434 layer_id, |
392 tile_id, | 435 tile_id, |
393 source_frame_number, | 436 source_frame_number, |
394 rendering_stats, | 437 rendering_stats, |
395 reply, | 438 reply, |
396 &dependencies->tasks_)); | 439 &dependencies->tasks_, |
440 texture_type)); | |
397 } | 441 } |
398 | 442 |
399 // static | 443 // static |
400 RasterWorkerPool::Task RasterWorkerPool::CreateImageDecodeTask( | 444 RasterWorkerPool::Task RasterWorkerPool::CreateImageDecodeTask( |
401 skia::LazyPixelRef* pixel_ref, | 445 skia::LazyPixelRef* pixel_ref, |
402 int layer_id, | 446 int layer_id, |
403 RenderingStatsInstrumentation* stats_instrumentation, | 447 RenderingStatsInstrumentation* stats_instrumentation, |
404 const Task::Reply& reply) { | 448 const Task::Reply& reply) { |
405 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, | 449 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, |
406 layer_id, | 450 layer_id, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 | 578 |
535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 579 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
536 decode_task, priority, graph); | 580 decode_task, priority, graph); |
537 decode_node->add_dependent(raster_node); | 581 decode_node->add_dependent(raster_node); |
538 } | 582 } |
539 | 583 |
540 return raster_node; | 584 return raster_node; |
541 } | 585 } |
542 | 586 |
543 } // namespace cc | 587 } // namespace cc |
OLD | NEW |