OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/base/region.h" | 9 #include "cc/base/region.h" |
10 #include "cc/debug/benchmark_instrumentation.h" | 10 #include "cc/debug/benchmark_instrumentation.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( | 66 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( |
67 unsigned thread_index) const { | 67 unsigned thread_index) const { |
68 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); | 68 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); |
69 return clones_for_drawing_.clones_[thread_index].get(); | 69 return clones_for_drawing_.clones_[thread_index].get(); |
70 } | 70 } |
71 | 71 |
72 void PicturePileImpl::RasterDirect( | 72 void PicturePileImpl::RasterDirect( |
73 SkCanvas* canvas, | 73 SkCanvas* canvas, |
74 gfx::Rect canvas_rect, | 74 gfx::Rect canvas_rect, |
75 float contents_scale, | 75 float contents_scale, |
76 RasterStats* raster_stats) { | 76 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
77 RasterCommon(canvas, NULL, canvas_rect, contents_scale, raster_stats); | 77 RasterCommon(canvas, |
| 78 NULL, |
| 79 canvas_rect, |
| 80 contents_scale, |
| 81 rendering_stats_instrumentation); |
78 } | 82 } |
79 | 83 |
80 void PicturePileImpl::RasterForAnalysis( | 84 void PicturePileImpl::RasterForAnalysis( |
81 skia::AnalysisCanvas* canvas, | 85 skia::AnalysisCanvas* canvas, |
82 gfx::Rect canvas_rect, | 86 gfx::Rect canvas_rect, |
83 float contents_scale) { | 87 float contents_scale) { |
84 RasterCommon(canvas, canvas, canvas_rect, contents_scale, NULL); | 88 RasterCommon(canvas, canvas, canvas_rect, contents_scale, NULL); |
85 } | 89 } |
86 | 90 |
87 void PicturePileImpl::RasterToBitmap( | 91 void PicturePileImpl::RasterToBitmap( |
88 SkCanvas* canvas, | 92 SkCanvas* canvas, |
89 gfx::Rect canvas_rect, | 93 gfx::Rect canvas_rect, |
90 float contents_scale, | 94 float contents_scale, |
91 RasterStats* raster_stats) { | 95 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
92 #ifndef NDEBUG | 96 #ifndef NDEBUG |
93 // Any non-painted areas will be left in this color. | 97 // Any non-painted areas will be left in this color. |
94 canvas->clear(DebugColors::NonPaintedFillColor()); | 98 canvas->clear(DebugColors::NonPaintedFillColor()); |
95 #endif // NDEBUG | 99 #endif // NDEBUG |
96 | 100 |
97 // If this picture has opaque contents, it is guaranteeing that it will | 101 // If this picture has opaque contents, it is guaranteeing that it will |
98 // draw an opaque rect the size of the layer. If it is not, then we must | 102 // draw an opaque rect the size of the layer. If it is not, then we must |
99 // clear this canvas ourselves. | 103 // clear this canvas ourselves. |
100 if (!contents_opaque_) { | 104 if (!contents_opaque_) { |
101 // Clearing is about ~4x faster than drawing a rect even if the content | 105 // Clearing is about ~4x faster than drawing a rect even if the content |
(...skipping 23 matching lines...) Expand all Loading... |
125 inflated_content_rect.Inset(0, 0, -1, -1); | 129 inflated_content_rect.Inset(0, 0, -1, -1); |
126 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), | 130 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), |
127 SkRegion::kReplace_Op); | 131 SkRegion::kReplace_Op); |
128 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), | 132 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), |
129 SkRegion::kDifference_Op); | 133 SkRegion::kDifference_Op); |
130 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | 134 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); |
131 canvas->restore(); | 135 canvas->restore(); |
132 } | 136 } |
133 } | 137 } |
134 | 138 |
135 RasterCommon(canvas, NULL, canvas_rect, contents_scale, raster_stats); | 139 RasterCommon(canvas, |
| 140 NULL, |
| 141 canvas_rect, |
| 142 contents_scale, |
| 143 rendering_stats_instrumentation); |
136 } | 144 } |
137 | 145 |
138 void PicturePileImpl::RasterCommon( | 146 void PicturePileImpl::RasterCommon( |
139 SkCanvas* canvas, | 147 SkCanvas* canvas, |
140 SkDrawPictureCallback* callback, | 148 SkDrawPictureCallback* callback, |
141 gfx::Rect canvas_rect, | 149 gfx::Rect canvas_rect, |
142 float contents_scale, | 150 float contents_scale, |
143 RasterStats* raster_stats) { | 151 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
144 DCHECK(contents_scale >= min_contents_scale_); | 152 DCHECK(contents_scale >= min_contents_scale_); |
145 | 153 |
146 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 154 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); |
147 | 155 |
148 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), | 156 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), |
149 contents_scale); | 157 contents_scale); |
150 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); | 158 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); |
151 gfx::Rect content_rect = total_content_rect; | 159 gfx::Rect content_rect = total_content_rect; |
152 content_rect.Intersect(canvas_rect); | 160 content_rect.Intersect(canvas_rect); |
153 | 161 |
154 // Rasterize the collection of relevant picture piles. | 162 // Rasterize the collection of relevant picture piles. |
155 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 163 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
156 content_rect, 1.f / contents_scale); | 164 content_rect, 1.f / contents_scale); |
157 | 165 |
158 canvas->clipRect(gfx::RectToSkRect(content_rect), | 166 canvas->clipRect(gfx::RectToSkRect(content_rect), |
159 SkRegion::kIntersect_Op); | 167 SkRegion::kIntersect_Op); |
160 Region unclipped(content_rect); | 168 Region unclipped(content_rect); |
161 | 169 |
162 if (raster_stats) { | |
163 raster_stats->total_pixels_rasterized = 0; | |
164 raster_stats->total_rasterize_time = base::TimeDelta::FromSeconds(0); | |
165 raster_stats->best_rasterize_time = base::TimeDelta::FromSeconds(0); | |
166 } | |
167 | |
168 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); | 170 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); |
169 tile_iter; ++tile_iter) { | 171 tile_iter; ++tile_iter) { |
170 PictureListMap::iterator map_iter = | 172 PictureListMap::iterator map_iter = |
171 picture_list_map_.find(tile_iter.index()); | 173 picture_list_map_.find(tile_iter.index()); |
172 if (map_iter == picture_list_map_.end()) | 174 if (map_iter == picture_list_map_.end()) |
173 continue; | 175 continue; |
174 PictureList& pic_list= map_iter->second; | 176 PictureList& pic_list= map_iter->second; |
175 if (pic_list.empty()) | 177 if (pic_list.empty()) |
176 continue; | 178 continue; |
177 | 179 |
(...skipping 11 matching lines...) Expand all Loading... |
189 | 191 |
190 DCHECK(!content_clip.IsEmpty()) << | 192 DCHECK(!content_clip.IsEmpty()) << |
191 "Layer rect: " << (*i)->LayerRect().ToString() << | 193 "Layer rect: " << (*i)->LayerRect().ToString() << |
192 "Contents scale: " << contents_scale; | 194 "Contents scale: " << contents_scale; |
193 | 195 |
194 content_clip.Intersect(canvas_rect); | 196 content_clip.Intersect(canvas_rect); |
195 | 197 |
196 if (!unclipped.Intersects(content_clip)) | 198 if (!unclipped.Intersects(content_clip)) |
197 continue; | 199 continue; |
198 | 200 |
199 base::TimeDelta total_duration = | |
200 base::TimeDelta::FromInternalValue(0); | |
201 base::TimeDelta best_duration = | 201 base::TimeDelta best_duration = |
202 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); | 202 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); |
203 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 203 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
204 | 204 |
205 TRACE_EVENT0(benchmark_instrumentation::kCategory, | 205 TRACE_EVENT0(benchmark_instrumentation::kCategory, |
206 benchmark_instrumentation::kRasterLoop); | 206 benchmark_instrumentation::kRasterLoop); |
207 for (int j = 0; j < repeat_count; ++j) { | 207 for (int j = 0; j < repeat_count; ++j) { |
208 base::TimeTicks start_time; | 208 base::TimeTicks start_time; |
209 if (raster_stats) | 209 if (rendering_stats_instrumentation) |
210 start_time = base::TimeTicks::HighResNow(); | 210 start_time = rendering_stats_instrumentation->StartRecording(); |
211 | |
212 (*i)->Raster(canvas, callback, content_clip, contents_scale); | 211 (*i)->Raster(canvas, callback, content_clip, contents_scale); |
213 | 212 if (rendering_stats_instrumentation) { |
214 if (raster_stats) { | 213 base::TimeDelta duration = |
215 base::TimeDelta duration = base::TimeTicks::HighResNow() - start_time; | 214 rendering_stats_instrumentation->EndRecording(start_time); |
216 total_duration += duration; | |
217 best_duration = std::min(best_duration, duration); | 215 best_duration = std::min(best_duration, duration); |
218 } | 216 } |
219 } | 217 } |
220 | 218 if (rendering_stats_instrumentation) { |
221 if (raster_stats) { | 219 int64 rasterized_pixel_count = |
222 raster_stats->total_pixels_rasterized += | |
223 repeat_count * content_clip.width() * content_clip.height(); | 220 repeat_count * content_clip.width() * content_clip.height(); |
224 raster_stats->total_rasterize_time += total_duration; | 221 rendering_stats_instrumentation->AddRaster(best_duration, |
225 raster_stats->best_rasterize_time += best_duration; | 222 rasterized_pixel_count); |
226 } | 223 } |
227 | 224 |
228 if (show_debug_picture_borders_) { | 225 if (show_debug_picture_borders_) { |
229 gfx::Rect border = gfx::ScaleToEnclosedRect( | 226 gfx::Rect border = gfx::ScaleToEnclosedRect( |
230 (*i)->LayerRect(), contents_scale); | 227 (*i)->LayerRect(), contents_scale); |
231 border.Inset(0, 0, 1, 1); | 228 border.Inset(0, 0, 1, 1); |
232 | 229 |
233 SkPaint picture_border_paint; | 230 SkPaint picture_border_paint; |
234 picture_border_paint.setColor(DebugColors::PictureBorderColor()); | 231 picture_border_paint.setColor(DebugColors::PictureBorderColor()); |
235 canvas->drawLine(border.x(), border.y(), border.right(), border.y(), | 232 canvas->drawLine(border.x(), border.y(), border.right(), border.y(), |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 PictureList& picture_list = (*pli).second; | 380 PictureList& picture_list = (*pli).second; |
384 for (PictureList::iterator picture = picture_list.begin(); | 381 for (PictureList::iterator picture = picture_list.begin(); |
385 picture != picture_list.end(); | 382 picture != picture_list.end(); |
386 picture++) { | 383 picture++) { |
387 (*picture)->EmitTraceSnapshot(); | 384 (*picture)->EmitTraceSnapshot(); |
388 } | 385 } |
389 } | 386 } |
390 } | 387 } |
391 | 388 |
392 } // namespace cc | 389 } // namespace cc |
OLD | NEW |