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 23 matching lines...) Expand all Loading... |
34 likely_to_be_used_for_transform_animation_(false) { | 34 likely_to_be_used_for_transform_animation_(false) { |
35 } | 35 } |
36 | 36 |
37 PicturePileImpl::~PicturePileImpl() { | 37 PicturePileImpl::~PicturePileImpl() { |
38 } | 38 } |
39 | 39 |
40 void PicturePileImpl::RasterDirect( | 40 void PicturePileImpl::RasterDirect( |
41 SkCanvas* canvas, | 41 SkCanvas* canvas, |
42 const gfx::Rect& canvas_rect, | 42 const gfx::Rect& canvas_rect, |
43 float contents_scale, | 43 float contents_scale, |
44 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | 44 RenderingStatsInstrumentation* rendering_stats_instrumentation) const { |
45 RasterCommon(canvas, | 45 RasterCommon(canvas, |
46 NULL, | 46 NULL, |
47 canvas_rect, | 47 canvas_rect, |
48 contents_scale, | 48 contents_scale, |
49 rendering_stats_instrumentation, | 49 rendering_stats_instrumentation, |
50 false); | 50 false); |
51 } | 51 } |
52 | 52 |
53 void PicturePileImpl::RasterForAnalysis( | 53 void PicturePileImpl::RasterForAnalysis( |
54 skia::AnalysisCanvas* canvas, | 54 skia::AnalysisCanvas* canvas, |
55 const gfx::Rect& canvas_rect, | 55 const gfx::Rect& canvas_rect, |
56 float contents_scale, | 56 float contents_scale, |
57 RenderingStatsInstrumentation* stats_instrumentation) const { | 57 RenderingStatsInstrumentation* stats_instrumentation) const { |
58 RasterCommon( | 58 RasterCommon( |
59 canvas, canvas, canvas_rect, contents_scale, stats_instrumentation, true); | 59 canvas, canvas, canvas_rect, contents_scale, stats_instrumentation, true); |
60 } | 60 } |
61 | 61 |
62 void PicturePileImpl::RasterToBitmap( | 62 void PicturePileImpl::PlaybackToCanvas( |
63 SkCanvas* canvas, | 63 SkCanvas* canvas, |
64 const gfx::Rect& canvas_rect, | 64 const gfx::Rect& canvas_rect, |
65 float contents_scale, | 65 float contents_scale, |
66 RenderingStatsInstrumentation* rendering_stats_instrumentation) const { | 66 RenderingStatsInstrumentation* rendering_stats_instrumentation) const { |
67 canvas->discard(); | 67 canvas->discard(); |
68 if (clear_canvas_with_debug_color_) { | 68 if (clear_canvas_with_debug_color_) { |
69 // Any non-painted areas in the content bounds will be left in this color. | 69 // Any non-painted areas in the content bounds will be left in this color. |
70 canvas->clear(DebugColors::NonPaintedFillColor()); | 70 canvas->clear(DebugColors::NonPaintedFillColor()); |
71 } | 71 } |
72 | 72 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { | 311 skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { |
312 TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture"); | 312 TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture"); |
313 | 313 |
314 gfx::Rect tiling_rect(tiling_.tiling_size()); | 314 gfx::Rect tiling_rect(tiling_.tiling_size()); |
315 SkPictureRecorder recorder; | 315 SkPictureRecorder recorder; |
316 SkCanvas* canvas = | 316 SkCanvas* canvas = |
317 recorder.beginRecording(tiling_rect.width(), tiling_rect.height()); | 317 recorder.beginRecording(tiling_rect.width(), tiling_rect.height()); |
318 if (!tiling_rect.IsEmpty()) | 318 if (!tiling_rect.IsEmpty()) |
319 RasterToBitmap(canvas, tiling_rect, 1.0, NULL); | 319 PlaybackToCanvas(canvas, tiling_rect, 1.0, NULL); |
320 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 320 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
321 | 321 |
322 return picture; | 322 return picture; |
323 } | 323 } |
324 | 324 |
325 void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect, | 325 void PicturePileImpl::PerformSolidColorAnalysis( |
326 float contents_scale, | |
327 PicturePileImpl::Analysis* analysis) const { | |
328 AnalyzeInRect(content_rect, contents_scale, analysis, NULL); | |
329 } | |
330 | |
331 void PicturePileImpl::AnalyzeInRect( | |
332 const gfx::Rect& content_rect, | 326 const gfx::Rect& content_rect, |
333 float contents_scale, | 327 float contents_scale, |
334 PicturePileImpl::Analysis* analysis, | 328 RasterSource::SolidColorAnalysis* analysis, |
335 RenderingStatsInstrumentation* stats_instrumentation) const { | 329 RenderingStatsInstrumentation* stats_instrumentation) const { |
336 DCHECK(analysis); | 330 DCHECK(analysis); |
337 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); | 331 TRACE_EVENT0("cc", "PicturePileImpl::PerformSolidColorAnalysis"); |
338 | 332 |
339 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 333 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
340 content_rect, 1.0f / contents_scale); | 334 content_rect, 1.0f / contents_scale); |
341 | 335 |
342 layer_rect.Intersect(gfx::Rect(tiling_.tiling_size())); | 336 layer_rect.Intersect(gfx::Rect(tiling_.tiling_size())); |
343 | 337 |
344 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); | 338 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); |
345 | 339 |
346 RasterForAnalysis(&canvas, layer_rect, 1.0f, stats_instrumentation); | 340 RasterForAnalysis(&canvas, layer_rect, 1.0f, stats_instrumentation); |
347 | 341 |
348 analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); | 342 analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); |
349 } | 343 } |
350 | 344 |
351 // Since there are situations when we can skip analysis, the variables have to | 345 void PicturePileImpl::GatherPixelRefs( |
352 // be set to their safest values. That is, we have to assume that the tile is | 346 const gfx::Rect& content_rect, |
353 // not solid color. As well, we have to assume that the tile has text so we | 347 float contents_scale, |
354 // don't early out incorrectly. | 348 std::vector<SkPixelRef*>* pixel_refs) const { |
355 PicturePileImpl::Analysis::Analysis() : is_solid_color(false) { | 349 DCHECK_EQ(0u, pixel_refs->size()); |
| 350 for (PixelRefIterator iter(content_rect, contents_scale, this); iter; |
| 351 ++iter) { |
| 352 pixel_refs->push_back(*iter); |
| 353 } |
356 } | 354 } |
357 | 355 |
358 PicturePileImpl::Analysis::~Analysis() { | 356 bool PicturePileImpl::CoversRect(const gfx::Rect& content_rect, |
| 357 float contents_scale) const { |
| 358 return CanRaster(contents_scale, content_rect); |
| 359 } |
| 360 |
| 361 bool PicturePileImpl::SuitableForDistanceFieldText() const { |
| 362 return likely_to_be_used_for_transform_animation_; |
359 } | 363 } |
360 | 364 |
361 PicturePileImpl::PixelRefIterator::PixelRefIterator( | 365 PicturePileImpl::PixelRefIterator::PixelRefIterator( |
362 const gfx::Rect& content_rect, | 366 const gfx::Rect& content_rect, |
363 float contents_scale, | 367 float contents_scale, |
364 const PicturePileImpl* picture_pile) | 368 const PicturePileImpl* picture_pile) |
365 : picture_pile_(picture_pile), | 369 : picture_pile_(picture_pile), |
366 layer_rect_( | 370 layer_rect_( |
367 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale)), | 371 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale)), |
368 tile_iterator_(&picture_pile_->tiling_, | 372 tile_iterator_(&picture_pile_->tiling_, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 ++it) { | 419 ++it) { |
416 const Picture* picture = it->second.GetPicture(); | 420 const Picture* picture = it->second.GetPicture(); |
417 if (picture && (processed_pictures.count(picture) == 0)) { | 421 if (picture && (processed_pictures.count(picture) == 0)) { |
418 picture->EmitTraceSnapshot(); | 422 picture->EmitTraceSnapshot(); |
419 processed_pictures.insert(picture); | 423 processed_pictures.insert(picture); |
420 } | 424 } |
421 } | 425 } |
422 } | 426 } |
423 | 427 |
424 } // namespace cc | 428 } // namespace cc |
OLD | NEW |