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; |
| 31 | 45 |
| 32 paint->setLCDRenderText(false); | 46 paint->setLCDRenderText(false); |
| 33 return true; | 47 return true; |
| 34 } | 48 } |
| 35 }; | 49 }; |
| 36 | 50 |
| 51 void ChangeBitmapConfigIfNeeded(const SkBitmap& bitmap, | |
| 52 void* buffer, | |
| 53 ResourceFormat format) { | |
|
reveman
2013/09/16 15:55:14
You can remove the format parameter if you make th
kaanb
2013/09/16 18:36:37
Done.
| |
| 54 TRACE_EVENT0("cc", "ChangeBitmapConfigIfNeeded"); | |
| 55 SkBitmap::Config config = SkBitmapConfigFromFormat(format); | |
| 56 if (bitmap.getConfig() != config) { | |
| 57 SkBitmap bitmap_dest; | |
| 58 IdentityAllocator allocator(buffer); | |
| 59 bitmap.copyTo(&bitmap_dest, config, &allocator); | |
| 60 } | |
| 61 } | |
| 62 | |
| 37 class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { | 63 class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { |
| 38 public: | 64 public: |
| 39 RasterWorkerPoolTaskImpl(const Resource* resource, | 65 RasterWorkerPoolTaskImpl(const Resource* resource, |
| 40 PicturePileImpl* picture_pile, | 66 PicturePileImpl* picture_pile, |
| 41 gfx::Rect content_rect, | 67 gfx::Rect content_rect, |
| 42 float contents_scale, | 68 float contents_scale, |
| 43 RasterMode raster_mode, | 69 RasterMode raster_mode, |
| 44 bool is_tile_in_pending_tree_now_bin, | 70 bool is_tile_in_pending_tree_now_bin, |
| 45 TileResolution tile_resolution, | 71 TileResolution tile_resolution, |
| 46 int layer_id, | 72 int layer_id, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 108 |
| 83 // Record the solid color prediction. | 109 // Record the solid color prediction. |
| 84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | 110 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", |
| 85 analysis_.is_solid_color); | 111 analysis_.is_solid_color); |
| 86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); | 112 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); |
| 87 | 113 |
| 88 // Clear the flag if we're not using the estimator. | 114 // Clear the flag if we're not using the estimator. |
| 89 analysis_.is_solid_color &= kUseColorEstimator; | 115 analysis_.is_solid_color &= kUseColorEstimator; |
| 90 } | 116 } |
| 91 | 117 |
| 92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { | 118 bool RunRasterOnThread(unsigned thread_index, |
| 119 void* buffer, | |
| 120 gfx::Size size, | |
| 121 int stride) { | |
| 93 TRACE_EVENT2( | 122 TRACE_EVENT2( |
| 94 benchmark_instrumentation::kCategory, | 123 benchmark_instrumentation::kCategory, |
| 95 benchmark_instrumentation::kRunRasterOnThread, | 124 benchmark_instrumentation::kRunRasterOnThread, |
| 96 benchmark_instrumentation::kData, | 125 benchmark_instrumentation::kData, |
| 97 TracedValue::FromValue(DataAsValue().release()), | 126 TracedValue::FromValue(DataAsValue().release()), |
| 98 "raster_mode", | 127 "raster_mode", |
| 99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); | 128 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); |
| 100 | 129 |
| 101 devtools_instrumentation::ScopedLayerTask raster_task( | 130 devtools_instrumentation::ScopedLayerTask raster_task( |
| 102 devtools_instrumentation::kRasterTask, layer_id_); | 131 devtools_instrumentation::kRasterTask, layer_id_); |
| 103 | 132 |
| 104 DCHECK(picture_pile_.get()); | 133 DCHECK(picture_pile_.get()); |
| 105 DCHECK(device); | 134 DCHECK(buffer); |
| 106 | 135 |
| 107 if (analysis_.is_solid_color) | 136 if (analysis_.is_solid_color) |
| 108 return false; | 137 return false; |
| 109 | 138 |
| 110 PicturePileImpl* picture_clone = | 139 PicturePileImpl* picture_clone = |
| 111 picture_pile_->GetCloneForDrawingOnThread(thread_index); | 140 picture_pile_->GetCloneForDrawingOnThread(thread_index); |
| 112 | 141 |
| 113 SkCanvas canvas(device); | 142 SkBitmap bitmap; |
| 143 switch (resource()->format()) { | |
| 144 case RGBA_4444: | |
| 145 // Use the default stride if we will eventually convert this | |
| 146 // bitmap to 4444. | |
| 147 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
| 148 size.width(), | |
| 149 size.height()); | |
| 150 bitmap.allocPixels(); | |
| 151 break; | |
| 152 case RGBA_8888: | |
| 153 case BGRA_8888: | |
| 154 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
| 155 size.width(), | |
| 156 size.height(), | |
| 157 stride); | |
| 158 bitmap.setPixels(buffer); | |
| 159 break; | |
| 160 case LUMINANCE_8: | |
| 161 NOTREACHED(); | |
| 162 break; | |
| 163 } | |
| 114 | 164 |
| 165 SkBitmapDevice device(bitmap); | |
| 166 SkCanvas canvas(&device); | |
| 115 skia::RefPtr<SkDrawFilter> draw_filter; | 167 skia::RefPtr<SkDrawFilter> draw_filter; |
| 116 switch (raster_mode_) { | 168 switch (raster_mode_) { |
| 117 case LOW_QUALITY_RASTER_MODE: | 169 case LOW_QUALITY_RASTER_MODE: |
| 118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); | 170 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); |
| 119 break; | 171 break; |
| 120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: | 172 case HIGH_QUALITY_NO_LCD_RASTER_MODE: |
| 121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); | 173 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); |
| 122 break; | 174 break; |
| 123 case HIGH_QUALITY_RASTER_MODE: | 175 case HIGH_QUALITY_RASTER_MODE: |
| 124 break; | 176 break; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 HISTOGRAM_CUSTOM_COUNTS( | 194 HISTOGRAM_CUSTOM_COUNTS( |
| 143 "Renderer4.PictureRasterTimeUS", | 195 "Renderer4.PictureRasterTimeUS", |
| 144 raster_stats.total_rasterize_time.InMicroseconds(), | 196 raster_stats.total_rasterize_time.InMicroseconds(), |
| 145 0, | 197 0, |
| 146 100000, | 198 100000, |
| 147 100); | 199 100); |
| 148 } else { | 200 } else { |
| 149 picture_clone->RasterToBitmap( | 201 picture_clone->RasterToBitmap( |
| 150 &canvas, content_rect_, contents_scale_, NULL); | 202 &canvas, content_rect_, contents_scale_, NULL); |
| 151 } | 203 } |
| 204 | |
| 205 ChangeBitmapConfigIfNeeded(bitmap, buffer, resource()->format()); | |
| 206 | |
| 152 return true; | 207 return true; |
| 153 } | 208 } |
| 154 | 209 |
| 155 // Overridden from internal::RasterWorkerPoolTask: | 210 // Overridden from internal::RasterWorkerPoolTask: |
| 156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) | 211 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 212 void* buffer, | |
| 213 gfx::Size size, | |
| 214 int stride) | |
| 157 OVERRIDE { | 215 OVERRIDE { |
| 158 RunAnalysisOnThread(thread_index); | 216 RunAnalysisOnThread(thread_index); |
| 159 return RunRasterOnThread(device, thread_index); | 217 return RunRasterOnThread(thread_index, buffer, size, stride); |
| 160 } | 218 } |
| 161 virtual void CompleteOnOriginThread() OVERRIDE { | 219 virtual void CompleteOnOriginThread() OVERRIDE { |
| 162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); | 220 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); |
| 163 } | 221 } |
| 164 | 222 |
| 165 protected: | 223 protected: |
| 166 virtual ~RasterWorkerPoolTaskImpl() {} | 224 virtual ~RasterWorkerPoolTaskImpl() {} |
| 167 | 225 |
| 168 private: | 226 private: |
| 169 scoped_ptr<base::Value> DataAsValue() const { | 227 scoped_ptr<base::Value> DataAsValue() const { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 592 |
| 535 internal::GraphNode* decode_node = CreateGraphNodeForTask( | 593 internal::GraphNode* decode_node = CreateGraphNodeForTask( |
| 536 decode_task, priority, graph); | 594 decode_task, priority, graph); |
| 537 decode_node->add_dependent(raster_node); | 595 decode_node->add_dependent(raster_node); |
| 538 } | 596 } |
| 539 | 597 |
| 540 return raster_node; | 598 return raster_node; |
| 541 } | 599 } |
| 542 | 600 |
| 543 } // namespace cc | 601 } // namespace cc |
| OLD | NEW |