Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: cc/resources/raster_worker_pool.cc

Issue 63443003: cc: Combine analysis and raster (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Chunk mismatch Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/devtools_instrumentation.h" 10 #include "cc/debug/devtools_instrumentation.h"
11 #include "cc/debug/traced_value.h" 11 #include "cc/debug/traced_value.h"
12 #include "cc/resources/picture_pile_impl.h" 12 #include "cc/resources/picture_pile_impl.h"
13 #include "skia/ext/lazy_pixel_ref.h" 13 #include "skia/ext/lazy_pixel_ref.h"
14 #include "skia/ext/paint_simplifier.h" 14 #include "skia/ext/paint_simplifier.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "third_party/skia/include/utils/SkNWayCanvas.h"
17 #include "ui/gfx/skia_util.h"
16 18
17 namespace cc { 19 namespace cc {
18 20
19 namespace { 21 namespace {
20 22
21 // Subclass of Allocator that takes a suitably allocated pointer and uses 23 // Subclass of Allocator that takes a suitably allocated pointer and uses
22 // it as the pixel memory for the bitmap. 24 // it as the pixel memory for the bitmap.
23 class IdentityAllocator : public SkBitmap::Allocator { 25 class IdentityAllocator : public SkBitmap::Allocator {
24 public: 26 public:
25 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} 27 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {}
26 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { 28 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE {
27 dst->setPixels(buffer_); 29 dst->setPixels(buffer_);
28 return true; 30 return true;
29 } 31 }
30 private: 32 private:
31 void* buffer_; 33 void* buffer_;
32 }; 34 };
33 35
34 // Flag to indicate whether we should try and detect that
35 // a tile is of solid color.
36 const bool kUseColorEstimator = true;
37
38 class DisableLCDTextFilter : public SkDrawFilter { 36 class DisableLCDTextFilter : public SkDrawFilter {
39 public: 37 public:
40 // SkDrawFilter interface. 38 // SkDrawFilter interface.
41 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { 39 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE {
42 if (type != SkDrawFilter::kText_Type) 40 if (type != SkDrawFilter::kText_Type)
43 return true; 41 return true;
44 42
45 paint->setLCDRenderText(false); 43 paint->setLCDRenderText(false);
46 return true; 44 return true;
47 } 45 }
(...skipping 18 matching lines...) Expand all
66 content_rect_(content_rect), 64 content_rect_(content_rect),
67 contents_scale_(contents_scale), 65 contents_scale_(contents_scale),
68 raster_mode_(raster_mode), 66 raster_mode_(raster_mode),
69 tile_resolution_(tile_resolution), 67 tile_resolution_(tile_resolution),
70 layer_id_(layer_id), 68 layer_id_(layer_id),
71 tile_id_(tile_id), 69 tile_id_(tile_id),
72 source_frame_number_(source_frame_number), 70 source_frame_number_(source_frame_number),
73 rendering_stats_(rendering_stats), 71 rendering_stats_(rendering_stats),
74 reply_(reply) {} 72 reply_(reply) {}
75 73
76 void RunAnalysisOnThread(unsigned thread_index) { 74 // Overridden from internal::RasterWorkerPoolTask:
77 TRACE_EVENT1("cc", 75 virtual bool RunOnWorkerThread(unsigned thread_index,
78 "RasterWorkerPoolTaskImpl::RunAnalysisOnThread", 76 void* buffer,
79 "data", 77 gfx::Size size,
80 TracedValue::FromValue(DataAsValue().release())); 78 int stride) OVERRIDE {
81
82 DCHECK(picture_pile_.get());
83 DCHECK(rendering_stats_);
84
85 PicturePileImpl* picture_clone =
86 picture_pile_->GetCloneForDrawingOnThread(thread_index);
87
88 DCHECK(picture_clone);
89
90 picture_clone->AnalyzeInRect(content_rect_, contents_scale_, &analysis_);
91
92 // Record the solid color prediction.
93 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
94 analysis_.is_solid_color);
95
96 // Clear the flag if we're not using the estimator.
97 analysis_.is_solid_color &= kUseColorEstimator;
98 }
99
100 bool RunRasterOnThread(unsigned thread_index,
101 void* buffer,
102 gfx::Size size,
103 int stride) {
104 TRACE_EVENT2( 79 TRACE_EVENT2(
105 "cc", "RasterWorkerPoolTaskImpl::RunRasterOnThread", 80 "cc", "RasterWorkerPoolTaskImpl::RunRasterOnThread",
106 "data", 81 "data",
107 TracedValue::FromValue(DataAsValue().release()), 82 TracedValue::FromValue(DataAsValue().release()),
108 "raster_mode", 83 "raster_mode",
109 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); 84 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release()));
110 85
111 devtools_instrumentation::ScopedLayerTask raster_task( 86 devtools_instrumentation::ScopedLayerTask raster_task(
112 devtools_instrumentation::kRasterTask, layer_id_); 87 devtools_instrumentation::kRasterTask, layer_id_);
113 88
114 DCHECK(picture_pile_.get()); 89 DCHECK(picture_pile_.get());
115 DCHECK(buffer); 90 DCHECK(buffer);
116 91
117 if (analysis_.is_solid_color)
118 return false;
119
120 PicturePileImpl* picture_clone = 92 PicturePileImpl* picture_clone =
121 picture_pile_->GetCloneForDrawingOnThread(thread_index); 93 picture_pile_->GetCloneForDrawingOnThread(thread_index);
122 94
123 SkBitmap bitmap; 95 SkBitmap bitmap;
124 switch (resource()->format()) { 96 switch (resource()->format()) {
125 case RGBA_4444: 97 case RGBA_4444:
126 // Use the default stride if we will eventually convert this 98 // Use the default stride if we will eventually convert this
127 // bitmap to 4444. 99 // bitmap to 4444.
128 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
129 size.width(), 101 size.width(),
130 size.height()); 102 size.height());
131 bitmap.allocPixels(); 103 bitmap.allocPixels();
132 break; 104 break;
133 case RGBA_8888: 105 case RGBA_8888:
134 case BGRA_8888: 106 case BGRA_8888:
135 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 107 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
136 size.width(), 108 size.width(),
137 size.height(), 109 size.height(),
138 stride); 110 stride);
139 bitmap.setPixels(buffer); 111 bitmap.setPixels(buffer);
140 break; 112 break;
141 case LUMINANCE_8: 113 case LUMINANCE_8:
142 case RGB_565: 114 case RGB_565:
143 case ETC1: 115 case ETC1:
144 NOTREACHED(); 116 NOTREACHED();
145 break; 117 break;
146 } 118 }
147 119
148 SkBitmapDevice device(bitmap); 120 SkBitmap empty_bitmap;
149 SkCanvas canvas(&device); 121 empty_bitmap.setConfig(
122 SkBitmap::kNo_Config, content_rect_.width(), content_rect_.height());
123 gfx::Rect analysis_rect(
124 picture_clone->AnalysisRectForRaster(content_rect_, contents_scale_));
125 skia::AnalysisDevice analysis_device(empty_bitmap,
126 gfx::RectToSkRect(analysis_rect));
127 skia::AnalysisCanvas analysis_canvas(&analysis_device);
128
129 SkBitmapDevice raster_device(bitmap);
130 SkCanvas raster_canvas(&raster_device);
131
132 SkNWayCanvas canvas(content_rect_.width(), content_rect_.height());
133 canvas.addCanvas(&analysis_canvas);
134 canvas.addCanvas(&raster_canvas);
135
150 skia::RefPtr<SkDrawFilter> draw_filter; 136 skia::RefPtr<SkDrawFilter> draw_filter;
151 switch (raster_mode_) { 137 switch (raster_mode_) {
152 case LOW_QUALITY_RASTER_MODE: 138 case LOW_QUALITY_RASTER_MODE:
153 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); 139 draw_filter = skia::AdoptRef(new skia::PaintSimplifier);
154 break; 140 break;
155 case HIGH_QUALITY_NO_LCD_RASTER_MODE: 141 case HIGH_QUALITY_NO_LCD_RASTER_MODE:
156 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); 142 draw_filter = skia::AdoptRef(new DisableLCDTextFilter);
157 break; 143 break;
158 case HIGH_QUALITY_RASTER_MODE: 144 case HIGH_QUALITY_RASTER_MODE:
159 break; 145 break;
(...skipping 25 matching lines...) Expand all
185 HISTOGRAM_CUSTOM_COUNTS( 171 HISTOGRAM_CUSTOM_COUNTS(
186 "Renderer4.PictureRasterTimeUS", 172 "Renderer4.PictureRasterTimeUS",
187 (current_rasterize_time - prev_rasterize_time).InMicroseconds(), 173 (current_rasterize_time - prev_rasterize_time).InMicroseconds(),
188 0, 174 0,
189 100000, 175 100000,
190 100); 176 100);
191 } 177 }
192 178
193 ChangeBitmapConfigIfNeeded(bitmap, buffer); 179 ChangeBitmapConfigIfNeeded(bitmap, buffer);
194 180
195 return true; 181 analysis_.is_solid_color =
182 analysis_canvas.GetColorIfSolid(&analysis_.solid_color);
183 analysis_.has_text = analysis_canvas.HasText();
184
185 // Record the solid color prediction.
186 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
187 analysis_.is_solid_color);
188
189 return !analysis_.is_solid_color;
196 } 190 }
197 191
198 // Overridden from internal::RasterWorkerPoolTask:
199 virtual bool RunOnWorkerThread(unsigned thread_index,
200 void* buffer,
201 gfx::Size size,
202 int stride)
203 OVERRIDE {
204 RunAnalysisOnThread(thread_index);
205 return RunRasterOnThread(thread_index, buffer, size, stride);
206 }
207 virtual void CompleteOnOriginThread() OVERRIDE { 192 virtual void CompleteOnOriginThread() OVERRIDE {
208 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); 193 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled());
209 } 194 }
210 195
211 protected: 196 protected:
212 virtual ~RasterWorkerPoolTaskImpl() {} 197 virtual ~RasterWorkerPoolTaskImpl() {}
213 198
214 private: 199 private:
215 scoped_ptr<base::Value> DataAsValue() const { 200 scoped_ptr<base::Value> DataAsValue() const {
216 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 201 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 571
587 internal::GraphNode* decode_node = CreateGraphNodeForTask( 572 internal::GraphNode* decode_node = CreateGraphNodeForTask(
588 decode_task, priority, graph); 573 decode_task, priority, graph);
589 decode_node->add_dependent(raster_node); 574 decode_node->add_dependent(raster_node);
590 } 575 }
591 576
592 return raster_node; 577 return raster_node;
593 } 578 }
594 579
595 } // namespace cc 580 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698