| 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/debug_colors.h" | 10 #include "cc/debug/debug_colors.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); | 67 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); |
| 68 return clones_for_drawing_.clones_[thread_index].get(); | 68 return clones_for_drawing_.clones_[thread_index].get(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void PicturePileImpl::RasterDirect( | 71 void PicturePileImpl::RasterDirect( |
| 72 SkCanvas* canvas, | 72 SkCanvas* canvas, |
| 73 gfx::Rect canvas_rect, | 73 gfx::Rect canvas_rect, |
| 74 float contents_scale, | 74 float contents_scale, |
| 75 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | 75 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
| 76 RasterCommon(canvas, | 76 RasterCommon(canvas, |
| 77 NULL, | |
| 78 canvas_rect, | 77 canvas_rect, |
| 79 contents_scale, | 78 contents_scale, |
| 80 rendering_stats_instrumentation, | 79 rendering_stats_instrumentation); |
| 81 false); | |
| 82 } | |
| 83 | |
| 84 void PicturePileImpl::RasterForAnalysis( | |
| 85 skia::AnalysisCanvas* canvas, | |
| 86 gfx::Rect canvas_rect, | |
| 87 float contents_scale, | |
| 88 RenderingStatsInstrumentation* stats_instrumentation) { | |
| 89 RasterCommon( | |
| 90 canvas, canvas, canvas_rect, contents_scale, stats_instrumentation, true); | |
| 91 } | 80 } |
| 92 | 81 |
| 93 void PicturePileImpl::RasterToBitmap( | 82 void PicturePileImpl::RasterToBitmap( |
| 94 SkCanvas* canvas, | 83 SkCanvas* canvas, |
| 95 gfx::Rect canvas_rect, | 84 gfx::Rect canvas_rect, |
| 96 float contents_scale, | 85 float contents_scale, |
| 97 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | 86 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
| 98 if (clear_canvas_with_debug_color_) { | 87 if (clear_canvas_with_debug_color_) { |
| 99 // Any non-painted areas will be left in this color. | 88 // Any non-painted areas will be left in this color. |
| 100 canvas->clear(DebugColors::NonPaintedFillColor()); | 89 canvas->clear(DebugColors::NonPaintedFillColor()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 131 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), | 120 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), |
| 132 SkRegion::kReplace_Op); | 121 SkRegion::kReplace_Op); |
| 133 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), | 122 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), |
| 134 SkRegion::kDifference_Op); | 123 SkRegion::kDifference_Op); |
| 135 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | 124 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); |
| 136 canvas->restore(); | 125 canvas->restore(); |
| 137 } | 126 } |
| 138 } | 127 } |
| 139 | 128 |
| 140 RasterCommon(canvas, | 129 RasterCommon(canvas, |
| 141 NULL, | |
| 142 canvas_rect, | 130 canvas_rect, |
| 143 contents_scale, | 131 contents_scale, |
| 144 rendering_stats_instrumentation, | 132 rendering_stats_instrumentation); |
| 145 false); | |
| 146 } | 133 } |
| 147 | 134 |
| 148 void PicturePileImpl::CoalesceRasters(gfx::Rect canvas_rect, | 135 void PicturePileImpl::CoalesceRasters(gfx::Rect canvas_rect, |
| 149 gfx::Rect content_rect, | 136 gfx::Rect content_rect, |
| 150 float contents_scale, | 137 float contents_scale, |
| 151 PictureRegionMap* results) { | 138 PictureRegionMap* results) { |
| 152 DCHECK(results); | 139 DCHECK(results); |
| 153 // Rasterize the collection of relevant picture piles. | 140 // Rasterize the collection of relevant picture piles. |
| 154 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 141 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
| 155 content_rect, 1.f / contents_scale); | 142 content_rect, 1.f / contents_scale); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 continue; | 186 continue; |
| 200 } | 187 } |
| 201 | 188 |
| 202 Region& region = it->second; | 189 Region& region = it->second; |
| 203 region.Subtract(content_clip); | 190 region.Subtract(content_clip); |
| 204 } | 191 } |
| 205 } | 192 } |
| 206 | 193 |
| 207 void PicturePileImpl::RasterCommon( | 194 void PicturePileImpl::RasterCommon( |
| 208 SkCanvas* canvas, | 195 SkCanvas* canvas, |
| 209 SkDrawPictureCallback* callback, | |
| 210 gfx::Rect canvas_rect, | 196 gfx::Rect canvas_rect, |
| 211 float contents_scale, | 197 float contents_scale, |
| 212 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 198 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
| 213 bool is_analysis) { | |
| 214 DCHECK(contents_scale >= min_contents_scale_); | 199 DCHECK(contents_scale >= min_contents_scale_); |
| 215 | 200 |
| 216 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 201 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); |
| 217 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), | 202 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), |
| 218 contents_scale); | 203 contents_scale); |
| 219 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); | 204 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); |
| 220 gfx::Rect content_rect = total_content_rect; | 205 gfx::Rect content_rect = total_content_rect; |
| 221 content_rect.Intersect(canvas_rect); | 206 content_rect.Intersect(canvas_rect); |
| 222 | 207 |
| 223 canvas->clipRect(gfx::RectToSkRect(content_rect), | 208 canvas->clipRect(gfx::RectToSkRect(content_rect), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 249 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); | 234 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); |
| 250 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 235 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
| 251 int rasterized_pixel_count = 0; | 236 int rasterized_pixel_count = 0; |
| 252 | 237 |
| 253 for (int j = 0; j < repeat_count; ++j) { | 238 for (int j = 0; j < repeat_count; ++j) { |
| 254 base::TimeTicks start_time; | 239 base::TimeTicks start_time; |
| 255 if (rendering_stats_instrumentation) | 240 if (rendering_stats_instrumentation) |
| 256 start_time = rendering_stats_instrumentation->StartRecording(); | 241 start_time = rendering_stats_instrumentation->StartRecording(); |
| 257 | 242 |
| 258 rasterized_pixel_count = picture->Raster( | 243 rasterized_pixel_count = picture->Raster( |
| 259 canvas, callback, negated_clip_region, contents_scale); | 244 canvas, negated_clip_region, contents_scale); |
| 260 | 245 |
| 261 if (rendering_stats_instrumentation) { | 246 if (rendering_stats_instrumentation) { |
| 262 base::TimeDelta duration = | 247 base::TimeDelta duration = |
| 263 rendering_stats_instrumentation->EndRecording(start_time); | 248 rendering_stats_instrumentation->EndRecording(start_time); |
| 264 best_duration = std::min(best_duration, duration); | 249 best_duration = std::min(best_duration, duration); |
| 265 } | 250 } |
| 266 } | 251 } |
| 267 | 252 |
| 268 if (rendering_stats_instrumentation) { | 253 if (rendering_stats_instrumentation) { |
| 269 if (is_analysis) { | 254 rendering_stats_instrumentation->AddRaster(best_duration, |
| 270 rendering_stats_instrumentation->AddAnalysis(best_duration, | 255 rasterized_pixel_count); |
| 271 rasterized_pixel_count); | |
| 272 } else { | |
| 273 rendering_stats_instrumentation->AddRaster(best_duration, | |
| 274 rasterized_pixel_count); | |
| 275 } | |
| 276 } | 256 } |
| 277 } | 257 } |
| 278 | 258 |
| 279 #ifndef NDEBUG | 259 #ifndef NDEBUG |
| 280 // Fill the clip with debug color. This allows us to | 260 // Fill the clip with debug color. This allows us to |
| 281 // distinguish between non painted areas and problems with missing | 261 // distinguish between non painted areas and problems with missing |
| 282 // pictures. | 262 // pictures. |
| 283 SkPaint paint; | 263 SkPaint paint; |
| 284 for (Region::Iterator it(total_clip); it.has_rect(); it.next()) | 264 for (Region::Iterator it(total_clip); it.has_rect(); it.next()) |
| 285 canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op); | 265 canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 301 layer_rect.width(), | 281 layer_rect.width(), |
| 302 layer_rect.height(), | 282 layer_rect.height(), |
| 303 SkPicture::kUsePathBoundsForClip_RecordingFlag); | 283 SkPicture::kUsePathBoundsForClip_RecordingFlag); |
| 304 | 284 |
| 305 RasterToBitmap(canvas, layer_rect, 1.0, NULL); | 285 RasterToBitmap(canvas, layer_rect, 1.0, NULL); |
| 306 picture->endRecording(); | 286 picture->endRecording(); |
| 307 | 287 |
| 308 return picture; | 288 return picture; |
| 309 } | 289 } |
| 310 | 290 |
| 311 void PicturePileImpl::AnalyzeInRect( | |
| 312 gfx::Rect content_rect, | |
| 313 float contents_scale, | |
| 314 PicturePileImpl::Analysis* analysis) { | |
| 315 AnalyzeInRect(content_rect, contents_scale, analysis, NULL); | |
| 316 } | |
| 317 | |
| 318 void PicturePileImpl::AnalyzeInRect( | |
| 319 gfx::Rect content_rect, | |
| 320 float contents_scale, | |
| 321 PicturePileImpl::Analysis* analysis, | |
| 322 RenderingStatsInstrumentation* stats_instrumentation) { | |
| 323 DCHECK(analysis); | |
| 324 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); | |
| 325 | |
| 326 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | |
| 327 content_rect, 1.0f / contents_scale); | |
| 328 | |
| 329 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); | |
| 330 | |
| 331 SkBitmap empty_bitmap; | |
| 332 empty_bitmap.setConfig(SkBitmap::kNo_Config, | |
| 333 layer_rect.width(), | |
| 334 layer_rect.height()); | |
| 335 skia::AnalysisDevice device(empty_bitmap); | |
| 336 skia::AnalysisCanvas canvas(&device); | |
| 337 | |
| 338 RasterForAnalysis(&canvas, layer_rect, 1.0f, stats_instrumentation); | |
| 339 | |
| 340 analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); | |
| 341 analysis->has_text = canvas.HasText(); | |
| 342 } | |
| 343 | |
| 344 PicturePileImpl::Analysis::Analysis() | 291 PicturePileImpl::Analysis::Analysis() |
| 345 : is_solid_color(false), | 292 : is_solid_color(false), |
| 346 has_text(false) { | 293 has_text(false) { |
| 347 } | 294 } |
| 348 | 295 |
| 349 PicturePileImpl::Analysis::~Analysis() { | 296 PicturePileImpl::Analysis::~Analysis() { |
| 350 } | 297 } |
| 351 | 298 |
| 352 PicturePileImpl::PixelRefIterator::PixelRefIterator( | 299 PicturePileImpl::PixelRefIterator::PixelRefIterator( |
| 353 gfx::Rect content_rect, | 300 gfx::Rect content_rect, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 !picture->WillPlayBackBitmaps()) | 337 !picture->WillPlayBackBitmaps()) |
| 391 continue; | 338 continue; |
| 392 | 339 |
| 393 processed_pictures_.insert(picture); | 340 processed_pictures_.insert(picture); |
| 394 pixel_ref_iterator_ = Picture::PixelRefIterator(layer_rect_, picture); | 341 pixel_ref_iterator_ = Picture::PixelRefIterator(layer_rect_, picture); |
| 395 if (pixel_ref_iterator_) | 342 if (pixel_ref_iterator_) |
| 396 break; | 343 break; |
| 397 } | 344 } |
| 398 } | 345 } |
| 399 | 346 |
| 347 gfx::Rect PicturePileImpl::AnalysisRectForRaster(gfx::Rect content_rect, |
| 348 float contents_scale) const { |
| 349 // Bound the analysis rect to just the pile content. |
| 350 gfx::Rect content_bounds( |
| 351 gfx::ScaleToEnclosingRect(gfx::Rect(size()), contents_scale)); |
| 352 gfx::Rect analysis_rect(content_rect); |
| 353 analysis_rect.Intersect(content_bounds); |
| 354 // Move to canvas space. |
| 355 analysis_rect.set_origin(gfx::Point()); |
| 356 |
| 357 return analysis_rect; |
| 358 } |
| 359 |
| 400 void PicturePileImpl::DidBeginTracing() { | 360 void PicturePileImpl::DidBeginTracing() { |
| 401 gfx::Rect layer_rect(tiling_.total_size()); | 361 gfx::Rect layer_rect(tiling_.total_size()); |
| 402 std::set<void*> processed_pictures; | 362 std::set<void*> processed_pictures; |
| 403 for (PictureMap::iterator it = picture_map_.begin(); | 363 for (PictureMap::iterator it = picture_map_.begin(); |
| 404 it != picture_map_.end(); | 364 it != picture_map_.end(); |
| 405 ++it) { | 365 ++it) { |
| 406 Picture* picture = it->second.GetPicture(); | 366 Picture* picture = it->second.GetPicture(); |
| 407 if (picture && (processed_pictures.count(picture) == 0)) { | 367 if (picture && (processed_pictures.count(picture) == 0)) { |
| 408 picture->EmitTraceSnapshot(); | 368 picture->EmitTraceSnapshot(); |
| 409 processed_pictures.insert(picture); | 369 processed_pictures.insert(picture); |
| 410 } | 370 } |
| 411 } | 371 } |
| 412 } | 372 } |
| 413 | 373 |
| 414 } // namespace cc | 374 } // namespace cc |
| OLD | NEW |