Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 41 gfx::Rect content_rect, | 55 gfx::Rect content_rect, |
| 42 float contents_scale, | 56 float contents_scale, |
| 43 RasterMode raster_mode, | 57 RasterMode raster_mode, |
| 44 bool is_tile_in_pending_tree_now_bin, | 58 bool is_tile_in_pending_tree_now_bin, |
| 45 TileResolution tile_resolution, | 59 TileResolution tile_resolution, |
| 46 int layer_id, | 60 int layer_id, |
| 47 const void* tile_id, | 61 const void* tile_id, |
| 48 int source_frame_number, | 62 int source_frame_number, |
| 49 RenderingStatsInstrumentation* rendering_stats, | 63 RenderingStatsInstrumentation* rendering_stats, |
| 50 const RasterWorkerPool::RasterTask::Reply& reply, | 64 const RasterWorkerPool::RasterTask::Reply& reply, |
| 51 TaskVector* dependencies) | 65 TaskVector* dependencies, |
| 66 bool use_16bit_tiles) | |
| 52 : internal::RasterWorkerPoolTask(resource, dependencies), | 67 : internal::RasterWorkerPoolTask(resource, dependencies), |
| 53 picture_pile_(picture_pile), | 68 picture_pile_(picture_pile), |
| 54 content_rect_(content_rect), | 69 content_rect_(content_rect), |
| 55 contents_scale_(contents_scale), | 70 contents_scale_(contents_scale), |
| 56 raster_mode_(raster_mode), | 71 raster_mode_(raster_mode), |
| 57 is_tile_in_pending_tree_now_bin_(is_tile_in_pending_tree_now_bin), | 72 is_tile_in_pending_tree_now_bin_(is_tile_in_pending_tree_now_bin), |
| 58 tile_resolution_(tile_resolution), | 73 tile_resolution_(tile_resolution), |
| 59 layer_id_(layer_id), | 74 layer_id_(layer_id), |
| 60 tile_id_(tile_id), | 75 tile_id_(tile_id), |
| 61 source_frame_number_(source_frame_number), | 76 source_frame_number_(source_frame_number), |
| 62 rendering_stats_(rendering_stats), | 77 rendering_stats_(rendering_stats), |
| 63 reply_(reply) {} | 78 reply_(reply), |
| 79 use_16bit_tiles_(use_16bit_tiles) {} | |
| 64 | 80 |
| 65 void RunAnalysisOnThread(unsigned thread_index) { | 81 void RunAnalysisOnThread(unsigned thread_index) { |
| 66 TRACE_EVENT1("cc", | 82 TRACE_EVENT1("cc", |
| 67 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", | 83 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", |
| 68 "data", | 84 "data", |
| 69 TracedValue::FromValue(DataAsValue().release())); | 85 TracedValue::FromValue(DataAsValue().release())); |
| 70 | 86 |
| 71 DCHECK(picture_pile_.get()); | 87 DCHECK(picture_pile_.get()); |
| 72 DCHECK(rendering_stats_); | 88 DCHECK(rendering_stats_); |
| 73 | 89 |
| 74 PicturePileImpl* picture_clone = | 90 PicturePileImpl* picture_clone = |
| 75 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 91 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| 76 | 92 |
| 77 DCHECK(picture_clone); | 93 DCHECK(picture_clone); |
| 78 | 94 |
| 79 base::TimeTicks start_time = rendering_stats_->StartRecording(); | 95 base::TimeTicks start_time = rendering_stats_->StartRecording(); |
| 80 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_); | 96 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_); |
| 81 base::TimeDelta duration = rendering_stats_->EndRecording(start_time); | 97 base::TimeDelta duration = rendering_stats_->EndRecording(start_time); |
| 82 | 98 |
| 83 // Record the solid color prediction. | 99 // Record the solid color prediction. |
| 84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 100 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
| 85 analysis_.is_solid_color); | 101 analysis_.is_solid_color); |
| 86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); | 102 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); |
| 87 | 103 |
| 88 // Clear the flag if we're not using the estimator. | 104 // Clear the flag if we're not using the estimator. |
| 89 analysis_.is_solid_color &= kUseColorEstimator; | 105 analysis_.is_solid_color &= kUseColorEstimator; |
| 90 } | 106 } |
| 91 | 107 |
| 92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { | 108 bool RunRasterOnThread(unsigned thread_index, |
| 109 void* buffer, | |
| 110 gfx::Size size) { | |
| 93 TRACE_EVENT2( | 111 TRACE_EVENT2( |
| 94 benchmark_instrumentation::kCategory, | 112 benchmark_instrumentation::kCategory, |
| 95 benchmark_instrumentation::kRunRasterOnThread, | 113 benchmark_instrumentation::kRunRasterOnThread, |
| 96 benchmark_instrumentation::kData, | 114 benchmark_instrumentation::kData, |
| 97 TracedValue::FromValue(DataAsValue().release()), | 115 TracedValue::FromValue(DataAsValue().release()), |
| 98 "raster_mode", | 116 "raster_mode", |
| 99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 117 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
| 100 | 118 |
| 101 devtools_instrumentation::ScopedLayerTask raster_task( | 119 devtools_instrumentation::ScopedLayerTask raster_task( |
| 102 devtools_instrumentation::kRasterTask, layer_id_); | 120 devtools_instrumentation::kRasterTask, layer_id_); |
| 103 | 121 |
| 104 DCHECK(picture_pile_.get()); | 122 DCHECK(picture_pile_.get()); |
| 105 DCHECK(device); | 123 DCHECK(buffer); |
| 106 | 124 |
| 107 if (analysis_.is_solid_color) | 125 if (analysis_.is_solid_color) |
| 108 return false; | 126 return false; |
| 109 | 127 |
| 110 PicturePileImpl* picture_clone = | 128 PicturePileImpl* picture_clone = |
| 111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 129 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| 112 | 130 |
| 113 SkCanvas canvas(device); | 131 SkBitmap bitmap_32; |
|
Sami
2013/09/05 14:13:26
If we gave this function an SkBitmapDevice instead
kaanb
2013/09/06 02:05:54
Apparently getPixelRef is protected not public, so
| |
| 132 bitmap_32.setConfig(SkBitmap::kARGB_8888_Config, | |
| 133 size.width(), | |
| 134 size.height()); | |
| 135 bitmap_32.allocPixels(); | |
|
reveman
2013/09/05 16:24:17
we shouldn't be allocating a temporary bitmap unle
kaanb
2013/09/06 02:05:54
Good point. Fixed.
| |
| 136 SkBitmapDevice device_32(bitmap_32); | |
| 114 | 137 |
| 138 SkCanvas canvas(&device_32); | |
| 115 skia::RefPtr<SkDrawFilter> draw_filter; | 139 skia::RefPtr<SkDrawFilter> draw_filter; |
| 116 switch (raster_mode_) { | 140 switch (raster_mode_) { |
| 117 case LOW_QUALITY_RASTER_MODE: | 141 case LOW_QUALITY_RASTER_MODE: |
| 118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 142 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
| 119 break; | 143 break; |
| 120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 144 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
| 121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 145 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
| 122 break; | 146 break; |
| 123 case HIGH_QUALITY_RASTER_MODE: | 147 case HIGH_QUALITY_RASTER_MODE: |
| 124 break; | 148 break; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 HISTOGRAM_CUSTOM_COUNTS( | 166 HISTOGRAM_CUSTOM_COUNTS( |
| 143 "Renderer4.PictureRasterTimeUS", | 167 "Renderer4.PictureRasterTimeUS", |
| 144 raster_stats.total_rasterize_time.InMicroseconds(), | 168 raster_stats.total_rasterize_time.InMicroseconds(), |
| 145 0, | 169 0, |
| 146 100000, | 170 100000, |
| 147 100); | 171 100); |
| 148 } else { | 172 } else { |
| 149 picture_clone->RasterToBitmap( | 173 picture_clone->RasterToBitmap( |
| 150 &canvas, content_rect_, contents_scale_, NULL); | 174 &canvas, content_rect_, contents_scale_, NULL); |
| 151 } | 175 } |
| 176 | |
| 177 if (use_16bit_tiles_) { | |
| 178 SkBitmap bitmap_16; | |
| 179 IdentityAllocator allocator(buffer); | |
| 180 bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); | |
|
enne (OOO)
2013/09/05 02:01:19
Just to be clear, this is copying from the 8888 bi
Sami
2013/09/05 14:13:26
If I read this right we're copying from bitmap_32
kaanb
2013/09/06 02:05:54
Also, note that we want the destination of the buf
kaanb
2013/09/06 02:05:54
Actually 8888 bitmap uses temporary heap memory in
| |
| 181 } | |
| 182 | |
| 152 return true; | 183 return true; |
| 153 } | 184 } |
| 154 | 185 |
| 155 // Overridden from internal::RasterWorkerPoolTask: | 186 // Overridden from internal::RasterWorkerPoolTask: |
| 156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 187 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 188 void* buffer, | |
| 189 gfx::Size size) | |
| 157 OVERRIDE { | 190 OVERRIDE { |
| 158 RunAnalysisOnThread(thread_index); | 191 RunAnalysisOnThread(thread_index); |
| 159 return RunRasterOnThread(device, thread_index); | 192 return RunRasterOnThread(thread_index, buffer, size); |
| 160 } | 193 } |
| 161 virtual void CompleteOnOriginThread() OVERRIDE { | 194 virtual void CompleteOnOriginThread() OVERRIDE { |
| 162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 195 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
| 163 } | 196 } |
| 164 | 197 |
| 165 protected: | 198 protected: |
| 166 virtual ~RasterWorkerPoolTaskImpl() {} | 199 virtual ~RasterWorkerPoolTaskImpl() {} |
| 167 | 200 |
| 168 private: | 201 private: |
| 169 scoped_ptr<base::Value> DataAsValue() const { | 202 scoped_ptr<base::Value> DataAsValue() const { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 182 gfx::Rect content_rect_; | 215 gfx::Rect content_rect_; |
| 183 float contents_scale_; | 216 float contents_scale_; |
| 184 RasterMode raster_mode_; | 217 RasterMode raster_mode_; |
| 185 bool is_tile_in_pending_tree_now_bin_; | 218 bool is_tile_in_pending_tree_now_bin_; |
| 186 TileResolution tile_resolution_; | 219 TileResolution tile_resolution_; |
| 187 int layer_id_; | 220 int layer_id_; |
| 188 const void* tile_id_; | 221 const void* tile_id_; |
| 189 int source_frame_number_; | 222 int source_frame_number_; |
| 190 RenderingStatsInstrumentation* rendering_stats_; | 223 RenderingStatsInstrumentation* rendering_stats_; |
| 191 const RasterWorkerPool::RasterTask::Reply reply_; | 224 const RasterWorkerPool::RasterTask::Reply reply_; |
| 225 bool use_16bit_tiles_; | |
| 192 | 226 |
| 193 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); | 227 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
| 194 }; | 228 }; |
| 195 | 229 |
| 196 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { | 230 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { |
| 197 public: | 231 public: |
| 198 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, | 232 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, |
| 199 int layer_id, | 233 int layer_id, |
| 200 RenderingStatsInstrumentation* rendering_stats, | 234 RenderingStatsInstrumentation* rendering_stats, |
| 201 const RasterWorkerPool::Task::Reply& reply) | 235 const RasterWorkerPool::Task::Reply& reply) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 gfx::Rect content_rect, | 406 gfx::Rect content_rect, |
| 373 float contents_scale, | 407 float contents_scale, |
| 374 RasterMode raster_mode, | 408 RasterMode raster_mode, |
| 375 bool is_tile_in_pending_tree_now_bin, | 409 bool is_tile_in_pending_tree_now_bin, |
| 376 TileResolution tile_resolution, | 410 TileResolution tile_resolution, |
| 377 int layer_id, | 411 int layer_id, |
| 378 const void* tile_id, | 412 const void* tile_id, |
| 379 int source_frame_number, | 413 int source_frame_number, |
| 380 RenderingStatsInstrumentation* rendering_stats, | 414 RenderingStatsInstrumentation* rendering_stats, |
| 381 const RasterTask::Reply& reply, | 415 const RasterTask::Reply& reply, |
| 382 Task::Set* dependencies) { | 416 Task::Set* dependencies, |
| 417 bool use_16bit_tiles) { | |
| 383 return RasterTask( | 418 return RasterTask( |
| 384 new RasterWorkerPoolTaskImpl(resource, | 419 new RasterWorkerPoolTaskImpl(resource, |
| 385 picture_pile, | 420 picture_pile, |
| 386 content_rect, | 421 content_rect, |
| 387 contents_scale, | 422 contents_scale, |
| 388 raster_mode, | 423 raster_mode, |
| 389 is_tile_in_pending_tree_now_bin, | 424 is_tile_in_pending_tree_now_bin, |
| 390 tile_resolution, | 425 tile_resolution, |
| 391 layer_id, | 426 layer_id, |
| 392 tile_id, | 427 tile_id, |
| 393 source_frame_number, | 428 source_frame_number, |
| 394 rendering_stats, | 429 rendering_stats, |
| 395 reply, | 430 reply, |
| 396 &dependencies->tasks_)); | 431 &dependencies->tasks_, |
| 432 use_16bit_tiles)); | |
| 397 } | 433 } |
| 398 | 434 |
| 399 // static | 435 // static |
| 400 RasterWorkerPool::Task RasterWorkerPool::CreateImageDecodeTask( | 436 RasterWorkerPool::Task RasterWorkerPool::CreateImageDecodeTask( |
| 401 skia::LazyPixelRef* pixel_ref, | 437 skia::LazyPixelRef* pixel_ref, |
| 402 int layer_id, | 438 int layer_id, |
| 403 RenderingStatsInstrumentation* stats_instrumentation, | 439 RenderingStatsInstrumentation* stats_instrumentation, |
| 404 const Task::Reply& reply) { | 440 const Task::Reply& reply) { |
| 405 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, | 441 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, |
| 406 layer_id, | 442 layer_id, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 570 |
| 535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 571 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
| 536 decode_task, priority, graph); | 572 decode_task, priority, graph); |
| 537 decode_node->add_dependent(raster_node); | 573 decode_node->add_dependent(raster_node); |
| 538 } | 574 } |
| 539 | 575 |
| 540 return raster_node; | 576 return raster_node; |
| 541 } | 577 } |
| 542 | 578 |
| 543 } // namespace cc | 579 } // namespace cc |
| OLD | NEW |