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 "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::TextureType type) | |
| 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_type_(type) {} | |
| 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_type_ == ResourceProvider::RGBA_4444) { | |
|
reveman
2013/09/12 15:57:39
please make this a switch statement. that way the
kaanb
2013/09/13 00:11:08
Done.
| |
| 139 bitmap_32.allocPixels(); | |
|
vangelis
2013/09/11 06:11:37
Is there some way we could avoid re-allocating thi
kaanb
2013/09/12 07:53:44
It may be difficult as this method could get calle
reveman
2013/09/12 15:57:39
you could keep an array of cached bitmaps based on
kaanb
2013/09/13 00:11:08
Okay.
| |
| 140 } else if (texture_type_ == ResourceProvider::RGBA_8888) { | |
| 141 bitmap_32.setPixels(buffer); | |
| 142 } else { | |
| 143 NOTREACHED(); | |
| 144 } | |
| 145 SkBitmapDevice device_32(bitmap_32); | |
| 114 | 146 |
| 147 SkCanvas canvas(&device_32); | |
| 115 skia::RefPtr<SkDrawFilter> draw_filter; | 148 skia::RefPtr<SkDrawFilter> draw_filter; |
| 116 switch (raster_mode_) { | 149 switch (raster_mode_) { |
| 117 case LOW_QUALITY_RASTER_MODE: | 150 case LOW_QUALITY_RASTER_MODE: |
| 118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 151 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
| 119 break; | 152 break; |
| 120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 153 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
| 121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 154 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
| 122 break; | 155 break; |
| 123 case HIGH_QUALITY_RASTER_MODE: | 156 case HIGH_QUALITY_RASTER_MODE: |
| 124 break; | 157 break; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 HISTOGRAM_CUSTOM_COUNTS( | 175 HISTOGRAM_CUSTOM_COUNTS( |
| 143 "Renderer4.PictureRasterTimeUS", | 176 "Renderer4.PictureRasterTimeUS", |
| 144 raster_stats.total_rasterize_time.InMicroseconds(), | 177 raster_stats.total_rasterize_time.InMicroseconds(), |
| 145 0, | 178 0, |
| 146 100000, | 179 100000, |
| 147 100); | 180 100); |
| 148 } else { | 181 } else { |
| 149 picture_clone->RasterToBitmap( | 182 picture_clone->RasterToBitmap( |
| 150 &canvas, content_rect_, contents_scale_, NULL); | 183 &canvas, content_rect_, contents_scale_, NULL); |
| 151 } | 184 } |
| 185 | |
| 186 if (texture_type_ == ResourceProvider::RGBA_4444) { | |
| 187 SkBitmap bitmap_16; | |
| 188 IdentityAllocator allocator(buffer); | |
| 189 bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); | |
| 190 } | |
| 191 | |
| 152 return true; | 192 return true; |
| 153 } | 193 } |
| 154 | 194 |
| 155 // Overridden from internal::RasterWorkerPoolTask: | 195 // Overridden from internal::RasterWorkerPoolTask: |
| 156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 196 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 197 void* buffer, | |
| 198 gfx::Size size, | |
| 199 int stride) | |
| 157 OVERRIDE { | 200 OVERRIDE { |
| 158 RunAnalysisOnThread(thread_index); | 201 RunAnalysisOnThread(thread_index); |
| 159 return RunRasterOnThread(device, thread_index); | 202 return RunRasterOnThread(thread_index, buffer, size, stride); |
| 160 } | 203 } |
| 161 virtual void CompleteOnOriginThread() OVERRIDE { | 204 virtual void CompleteOnOriginThread() OVERRIDE { |
| 162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 205 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
| 163 } | 206 } |
| 164 | 207 |
| 165 protected: | 208 protected: |
| 166 virtual ~RasterWorkerPoolTaskImpl() {} | 209 virtual ~RasterWorkerPoolTaskImpl() {} |
| 167 | 210 |
| 168 private: | 211 private: |
| 169 scoped_ptr<base::Value> DataAsValue() const { | 212 scoped_ptr<base::Value> DataAsValue() const { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 182 gfx::Rect content_rect_; | 225 gfx::Rect content_rect_; |
| 183 float contents_scale_; | 226 float contents_scale_; |
| 184 RasterMode raster_mode_; | 227 RasterMode raster_mode_; |
| 185 bool is_tile_in_pending_tree_now_bin_; | 228 bool is_tile_in_pending_tree_now_bin_; |
| 186 TileResolution tile_resolution_; | 229 TileResolution tile_resolution_; |
| 187 int layer_id_; | 230 int layer_id_; |
| 188 const void* tile_id_; | 231 const void* tile_id_; |
| 189 int source_frame_number_; | 232 int source_frame_number_; |
| 190 RenderingStatsInstrumentation* rendering_stats_; | 233 RenderingStatsInstrumentation* rendering_stats_; |
| 191 const RasterWorkerPool::RasterTask::Reply reply_; | 234 const RasterWorkerPool::RasterTask::Reply reply_; |
| 235 ResourceProvider::TextureType texture_type_; | |
| 192 | 236 |
| 193 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); | 237 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
| 194 }; | 238 }; |
| 195 | 239 |
| 196 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { | 240 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { |
| 197 public: | 241 public: |
| 198 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, | 242 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, |
| 199 int layer_id, | 243 int layer_id, |
| 200 RenderingStatsInstrumentation* rendering_stats, | 244 RenderingStatsInstrumentation* rendering_stats, |
| 201 const RasterWorkerPool::Task::Reply& reply) | 245 const RasterWorkerPool::Task::Reply& reply) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 gfx::Rect content_rect, | 416 gfx::Rect content_rect, |
| 373 float contents_scale, | 417 float contents_scale, |
| 374 RasterMode raster_mode, | 418 RasterMode raster_mode, |
| 375 bool is_tile_in_pending_tree_now_bin, | 419 bool is_tile_in_pending_tree_now_bin, |
| 376 TileResolution tile_resolution, | 420 TileResolution tile_resolution, |
| 377 int layer_id, | 421 int layer_id, |
| 378 const void* tile_id, | 422 const void* tile_id, |
| 379 int source_frame_number, | 423 int source_frame_number, |
| 380 RenderingStatsInstrumentation* rendering_stats, | 424 RenderingStatsInstrumentation* rendering_stats, |
| 381 const RasterTask::Reply& reply, | 425 const RasterTask::Reply& reply, |
| 382 Task::Set* dependencies) { | 426 Task::Set* dependencies, |
| 427 ResourceProvider::TextureType texture_type) { | |
| 383 return RasterTask( | 428 return RasterTask( |
| 384 new RasterWorkerPoolTaskImpl(resource, | 429 new RasterWorkerPoolTaskImpl(resource, |
| 385 picture_pile, | 430 picture_pile, |
| 386 content_rect, | 431 content_rect, |
| 387 contents_scale, | 432 contents_scale, |
| 388 raster_mode, | 433 raster_mode, |
| 389 is_tile_in_pending_tree_now_bin, | 434 is_tile_in_pending_tree_now_bin, |
| 390 tile_resolution, | 435 tile_resolution, |
| 391 layer_id, | 436 layer_id, |
| 392 tile_id, | 437 tile_id, |
| 393 source_frame_number, | 438 source_frame_number, |
| 394 rendering_stats, | 439 rendering_stats, |
| 395 reply, | 440 reply, |
| 396 &dependencies->tasks_)); | 441 &dependencies->tasks_, |
| 442 texture_type)); | |
| 397 } | 443 } |
| 398 | 444 |
| 399 // static | 445 // static |
| 400 RasterWorkerPool::Task RasterWorkerPool::CreateImageDecodeTask( | 446 RasterWorkerPool::Task RasterWorkerPool::CreateImageDecodeTask( |
| 401 skia::LazyPixelRef* pixel_ref, | 447 skia::LazyPixelRef* pixel_ref, |
| 402 int layer_id, | 448 int layer_id, |
| 403 RenderingStatsInstrumentation* stats_instrumentation, | 449 RenderingStatsInstrumentation* stats_instrumentation, |
| 404 const Task::Reply& reply) { | 450 const Task::Reply& reply) { |
| 405 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, | 451 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, |
| 406 layer_id, | 452 layer_id, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 580 |
| 535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 581 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
| 536 decode_task, priority, graph); | 582 decode_task, priority, graph); |
| 537 decode_node->add_dependent(raster_node); | 583 decode_node->add_dependent(raster_node); |
| 538 } | 584 } |
| 539 | 585 |
| 540 return raster_node; | 586 return raster_node; |
| 541 } | 587 } |
| 542 | 588 |
| 543 } // namespace cc | 589 } // namespace cc |
| OLD | NEW |