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 22 matching lines...) Expand all Loading... | |
| 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 texture_format_(resource->format()) {} | |
| 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, | |
| 111 int stride) { | |
| 93 TRACE_EVENT2( | 112 TRACE_EVENT2( |
| 94 benchmark_instrumentation::kCategory, | 113 benchmark_instrumentation::kCategory, |
| 95 benchmark_instrumentation::kRunRasterOnThread, | 114 benchmark_instrumentation::kRunRasterOnThread, |
| 96 benchmark_instrumentation::kData, | 115 benchmark_instrumentation::kData, |
| 97 TracedValue::FromValue(DataAsValue().release()), | 116 TracedValue::FromValue(DataAsValue().release()), |
| 98 "raster_mode", | 117 "raster_mode", |
| 99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 118 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
| 100 | 119 |
| 101 devtools_instrumentation::ScopedLayerTask raster_task( | 120 devtools_instrumentation::ScopedLayerTask raster_task( |
| 102 devtools_instrumentation::kRasterTask, layer_id_); | 121 devtools_instrumentation::kRasterTask, layer_id_); |
| 103 | 122 |
| 104 DCHECK(picture_pile_.get()); | 123 DCHECK(picture_pile_.get()); |
| 105 DCHECK(device); | 124 DCHECK(buffer); |
| 106 | 125 |
| 107 if (analysis_.is_solid_color) | 126 if (analysis_.is_solid_color) |
| 108 return false; | 127 return false; |
| 109 | 128 |
| 110 PicturePileImpl* picture_clone = | 129 PicturePileImpl* picture_clone = |
| 111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 130 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| 112 | 131 |
| 113 SkCanvas canvas(device); | 132 SkBitmap bitmap_32; |
|
reveman
2013/09/13 14:32:49
can we drop the _32 suffix here?
kaanb
2013/09/13 19:57:39
Done.
| |
| 133 bitmap_32.setConfig(SkBitmap::kARGB_8888_Config, | |
| 134 size.width(), | |
| 135 size.height(), | |
| 136 stride); | |
|
reveman
2013/09/13 14:32:49
stride is not going to be correct here unless form
kaanb
2013/09/13 19:57:39
Done.
| |
| 137 switch (texture_format_) { | |
| 138 case ResourceProvider::RGBA_4444: | |
| 139 bitmap_32.allocPixels(); | |
| 140 break; | |
| 141 case ResourceProvider::RGBA_8888: | |
| 142 case ResourceProvider::BGRA_8888: | |
| 143 case ResourceProvider::LUMINANCE_8: | |
|
reveman
2013/09/13 14:32:49
Using SkBitmap::kARGB_8888_Config for LUMINANCE_8
kaanb
2013/09/13 19:57:39
Done.
| |
| 144 bitmap_32.setPixels(buffer); | |
| 145 break; | |
| 146 } | |
| 114 | 147 |
| 148 SkBitmapDevice device_32(bitmap_32); | |
|
reveman
2013/09/13 14:32:49
drop _32?
kaanb
2013/09/13 19:57:39
Done.
| |
| 149 SkCanvas canvas(&device_32); | |
| 115 skia::RefPtr<SkDrawFilter> draw_filter; | 150 skia::RefPtr<SkDrawFilter> draw_filter; |
| 116 switch (raster_mode_) { | 151 switch (raster_mode_) { |
| 117 case LOW_QUALITY_RASTER_MODE: | 152 case LOW_QUALITY_RASTER_MODE: |
| 118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 153 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
| 119 break; | 154 break; |
| 120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 155 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
| 121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 156 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
| 122 break; | 157 break; |
| 123 case HIGH_QUALITY_RASTER_MODE: | 158 case HIGH_QUALITY_RASTER_MODE: |
| 124 break; | 159 break; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 HISTOGRAM_CUSTOM_COUNTS( | 177 HISTOGRAM_CUSTOM_COUNTS( |
| 143 "Renderer4.PictureRasterTimeUS", | 178 "Renderer4.PictureRasterTimeUS", |
| 144 raster_stats.total_rasterize_time.InMicroseconds(), | 179 raster_stats.total_rasterize_time.InMicroseconds(), |
| 145 0, | 180 0, |
| 146 100000, | 181 100000, |
| 147 100); | 182 100); |
| 148 } else { | 183 } else { |
| 149 picture_clone->RasterToBitmap( | 184 picture_clone->RasterToBitmap( |
| 150 &canvas, content_rect_, contents_scale_, NULL); | 185 &canvas, content_rect_, contents_scale_, NULL); |
| 151 } | 186 } |
| 187 | |
| 188 if (texture_format_ == ResourceProvider::RGBA_4444) { | |
| 189 TRACE_EVENT0("cc", | |
| 190 "RasterWorkerPoolTaskImpl::RunRasterOnThread::Downsample"); | |
|
reveman
2013/09/13 14:32:49
If this is worth a trace event then I prefer if yo
kaanb
2013/09/13 19:57:39
Done.
| |
| 191 SkBitmap bitmap_16; | |
| 192 IdentityAllocator allocator(buffer); | |
| 193 bitmap_32.copyTo(&bitmap_16, SkBitmap::kARGB_4444_Config, &allocator); | |
| 194 } | |
|
reveman
2013/09/13 14:32:49
This is currently hardcoded to only support RGBA_4
kaanb
2013/09/13 19:57:39
Done.
| |
| 195 | |
| 152 return true; | 196 return true; |
| 153 } | 197 } |
| 154 | 198 |
| 155 // Overridden from internal::RasterWorkerPoolTask: | 199 // Overridden from internal::RasterWorkerPoolTask: |
| 156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 200 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 201 void* buffer, | |
| 202 gfx::Size size, | |
| 203 int stride) | |
| 157 OVERRIDE { | 204 OVERRIDE { |
| 158 RunAnalysisOnThread(thread_index); | 205 RunAnalysisOnThread(thread_index); |
| 159 return RunRasterOnThread(device, thread_index); | 206 return RunRasterOnThread(thread_index, buffer, size, stride); |
| 160 } | 207 } |
| 161 virtual void CompleteOnOriginThread() OVERRIDE { | 208 virtual void CompleteOnOriginThread() OVERRIDE { |
| 162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 209 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
| 163 } | 210 } |
| 164 | 211 |
| 165 protected: | 212 protected: |
| 166 virtual ~RasterWorkerPoolTaskImpl() {} | 213 virtual ~RasterWorkerPoolTaskImpl() {} |
| 167 | 214 |
| 168 private: | 215 private: |
| 169 scoped_ptr<base::Value> DataAsValue() const { | 216 scoped_ptr<base::Value> DataAsValue() const { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 182 gfx::Rect content_rect_; | 229 gfx::Rect content_rect_; |
| 183 float contents_scale_; | 230 float contents_scale_; |
| 184 RasterMode raster_mode_; | 231 RasterMode raster_mode_; |
| 185 bool is_tile_in_pending_tree_now_bin_; | 232 bool is_tile_in_pending_tree_now_bin_; |
| 186 TileResolution tile_resolution_; | 233 TileResolution tile_resolution_; |
| 187 int layer_id_; | 234 int layer_id_; |
| 188 const void* tile_id_; | 235 const void* tile_id_; |
| 189 int source_frame_number_; | 236 int source_frame_number_; |
| 190 RenderingStatsInstrumentation* rendering_stats_; | 237 RenderingStatsInstrumentation* rendering_stats_; |
| 191 const RasterWorkerPool::RasterTask::Reply reply_; | 238 const RasterWorkerPool::RasterTask::Reply reply_; |
| 239 ResourceProvider::Format texture_format_; | |
|
reveman
2013/09/13 14:32:49
I don't think you need this. You can get the forma
kaanb
2013/09/13 19:57:39
Done.
| |
| 192 | 240 |
| 193 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); | 241 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPoolTaskImpl); |
| 194 }; | 242 }; |
| 195 | 243 |
| 196 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { | 244 class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask { |
| 197 public: | 245 public: |
| 198 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, | 246 ImageDecodeWorkerPoolTaskImpl(skia::LazyPixelRef* pixel_ref, |
| 199 int layer_id, | 247 int layer_id, |
| 200 RenderingStatsInstrumentation* rendering_stats, | 248 RenderingStatsInstrumentation* rendering_stats, |
| 201 const RasterWorkerPool::Task::Reply& reply) | 249 const RasterWorkerPool::Task::Reply& reply) |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 582 |
| 535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 583 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
| 536 decode_task, priority, graph); | 584 decode_task, priority, graph); |
| 537 decode_node->add_dependent(raster_node); | 585 decode_node->add_dependent(raster_node); |
| 538 } | 586 } |
| 539 | 587 |
| 540 return raster_node; | 588 return raster_node; |
| 541 } | 589 } |
| 542 | 590 |
| 543 } // namespace cc | 591 } // namespace cc |
| OLD | NEW |