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 "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
6 #include "cc/picture_pile_impl.h" | 6 #include "cc/picture_pile_impl.h" |
7 #include "cc/rendering_stats.h" | 7 #include "cc/rendering_stats.h" |
8 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
9 #include "third_party/skia/include/core/SkSize.h" | 9 #include "third_party/skia/include/core/SkSize.h" |
10 #include "ui/gfx/rect_conversions.h" | 10 #include "ui/gfx/rect_conversions.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 float contents_scale, | 52 float contents_scale, |
53 RenderingStats* stats) { | 53 RenderingStats* stats) { |
54 | 54 |
55 if (!pile_.size()) | 55 if (!pile_.size()) |
56 return; | 56 return; |
57 | 57 |
58 DCHECK(contents_scale >= min_contents_scale_); | 58 DCHECK(contents_scale >= min_contents_scale_); |
59 | 59 |
60 base::TimeTicks rasterizeBeginTime = base::TimeTicks::Now(); | 60 base::TimeTicks rasterizeBeginTime = base::TimeTicks::Now(); |
61 | 61 |
62 // TODO(enne): do this more efficiently, i.e. top down with Skia clips | |
63 canvas->save(); | 62 canvas->save(); |
64 canvas->translate(-content_rect.x(), -content_rect.y()); | 63 canvas->translate(-content_rect.x(), -content_rect.y()); |
65 canvas->clipRect(gfx::RectToSkRect(content_rect)); | 64 canvas->clipRect(gfx::RectToSkRect(content_rect)); |
66 | 65 |
67 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 66 // Raster through the pile top down, using clips to make sure that |
68 i != pile_.end(); ++i) { | 67 // pictures on top are not overdrawn by pictures on the bottom. |
| 68 Region unclipped(content_rect); |
| 69 for (PicturePile::Pile::reverse_iterator i = pile_.rbegin(); |
| 70 i != pile_.rend(); ++i) { |
69 // This is intentionally *enclosed* rect, so that the clip is aligned on | 71 // This is intentionally *enclosed* rect, so that the clip is aligned on |
70 // integral post-scale content pixels and does not extend past the edges of | 72 // integral post-scale content pixels and does not extend past the edges of |
71 // the picture's layer rect. The min_contents_scale enforces that enough | 73 // the picture's layer rect. The min_contents_scale enforces that enough |
72 // buffer pixels have been added such that the enclosed rect encompasses all | 74 // buffer pixels have been added such that the enclosed rect encompasses all |
73 // invalidated pixels at any larger scale level. | 75 // invalidated pixels at any larger scale level. |
74 gfx::Rect content_clip = gfx::ToEnclosedRect( | 76 gfx::Rect content_clip = gfx::ToEnclosedRect( |
75 gfx::ScaleRect((*i)->LayerRect(), contents_scale)); | 77 gfx::ScaleRect((*i)->LayerRect(), contents_scale)); |
76 if (!content_rect.Intersects(content_clip)) | 78 if (!unclipped.Intersects(content_clip)) |
77 continue; | 79 continue; |
78 | |
79 (*i)->Raster(canvas, content_clip, contents_scale); | 80 (*i)->Raster(canvas, content_clip, contents_scale); |
80 | 81 |
81 SkISize deviceSize = canvas->getDeviceSize(); | 82 // Don't allow pictures underneath to draw where this picture did. |
82 stats->totalPixelsRasterized += deviceSize.width() * deviceSize.height(); | 83 canvas->clipRect(gfx::RectToSkRect(content_clip), SkRegion::kDifference_Op); |
| 84 unclipped.Subtract(content_clip); |
| 85 |
| 86 stats->totalPixelsRasterized += |
| 87 content_clip.width() * content_clip.height(); |
83 } | 88 } |
84 canvas->restore(); | 89 canvas->restore(); |
85 | 90 |
86 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() - | 91 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() - |
87 rasterizeBeginTime).InSecondsF(); | 92 rasterizeBeginTime).InSecondsF(); |
88 } | 93 } |
89 | 94 |
90 void PicturePileImpl::GatherPixelRefs( | 95 void PicturePileImpl::GatherPixelRefs( |
91 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) { | 96 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) { |
92 std::list<skia::LazyPixelRef*> result; | 97 std::list<skia::LazyPixelRef*> result; |
93 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 98 for (PicturePile::Pile::const_iterator i = pile_.begin(); |
94 i != pile_.end(); ++i) { | 99 i != pile_.end(); ++i) { |
95 (*i)->GatherPixelRefs(rect, result); | 100 (*i)->GatherPixelRefs(rect, result); |
96 pixel_refs.splice(pixel_refs.end(), result); | 101 pixel_refs.splice(pixel_refs.end(), result); |
97 } | 102 } |
98 } | 103 } |
99 | 104 |
100 } // namespace cc | 105 } // namespace cc |
OLD | NEW |