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" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { | 14 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { |
15 return make_scoped_refptr(new PicturePileImpl()); | 15 return make_scoped_refptr(new PicturePileImpl()); |
16 } | 16 } |
17 | 17 |
18 PicturePileImpl::PicturePileImpl() { | 18 PicturePileImpl::PicturePileImpl() |
19 : min_contents_scale_(1) { | |
19 } | 20 } |
20 | 21 |
21 PicturePileImpl::~PicturePileImpl() { | 22 PicturePileImpl::~PicturePileImpl() { |
22 } | 23 } |
23 | 24 |
24 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( | 25 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( |
25 base::Thread* thread) { | 26 base::Thread* thread) { |
26 // Do we have a clone for this thread yet? | 27 // Do we have a clone for this thread yet? |
27 CloneMap::iterator it = clones_.find(thread->thread_id()); | 28 CloneMap::iterator it = clones_.find(thread->thread_id()); |
28 if (it != clones_.end()) | 29 if (it != clones_.end()) |
29 return it->second; | 30 return it->second; |
30 | 31 |
31 // Create clone for this thread. | 32 // Create clone for this thread. |
32 scoped_refptr<PicturePileImpl> clone = CloneForDrawing(); | 33 scoped_refptr<PicturePileImpl> clone = CloneForDrawing(); |
33 clones_[thread->thread_id()] = clone; | 34 clones_[thread->thread_id()] = clone; |
34 return clone; | 35 return clone; |
35 } | 36 } |
36 | 37 |
37 scoped_refptr<PicturePileImpl> PicturePileImpl::CloneForDrawing() const { | 38 scoped_refptr<PicturePileImpl> PicturePileImpl::CloneForDrawing() const { |
38 TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing"); | 39 TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing"); |
39 scoped_refptr<PicturePileImpl> clone = Create(); | 40 scoped_refptr<PicturePileImpl> clone = Create(); |
40 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 41 for (PicturePile::Pile::const_iterator i = pile_.begin(); |
41 i != pile_.end(); ++i) | 42 i != pile_.end(); ++i) |
42 clone->pile_.push_back((*i)->Clone()); | 43 clone->pile_.push_back((*i)->Clone()); |
44 clone->min_contents_scale_ = min_contents_scale_; | |
43 | 45 |
44 return clone; | 46 return clone; |
45 } | 47 } |
46 | 48 |
47 void PicturePileImpl::Raster( | 49 void PicturePileImpl::Raster( |
48 SkCanvas* canvas, | 50 SkCanvas* canvas, |
49 gfx::Rect content_rect, | 51 gfx::Rect content_rect, |
50 float contents_scale, | 52 float contents_scale, |
51 RenderingStats* stats) { | 53 RenderingStats* stats) { |
54 | |
55 if (!pile_.size()) | |
56 return; | |
57 | |
58 DCHECK(contents_scale >= min_contents_scale_); | |
59 | |
52 base::TimeTicks rasterizeBeginTime = base::TimeTicks::Now(); | 60 base::TimeTicks rasterizeBeginTime = base::TimeTicks::Now(); |
53 | 61 |
54 // TODO(enne): do this more efficiently, i.e. top down with Skia clips | 62 // TODO(enne): do this more efficiently, i.e. top down with Skia clips |
55 canvas->save(); | 63 canvas->save(); |
56 canvas->translate(-content_rect.x(), -content_rect.y()); | 64 canvas->translate(-content_rect.x(), -content_rect.y()); |
57 SkRect layer_skrect = SkRect::MakeXYWH( | 65 canvas->clipRect(gfx::RectToSkRect(content_rect)); |
danakj
2013/01/05 00:04:58
Is this right after the translate() ? Or should th
enne (OOO)
2013/01/06 03:57:18
Hmm. This should go before. Done.
enne (OOO)
2013/01/06 04:30:31
I was right the first time, sorry.
The translatio
| |
58 content_rect.x(), | |
59 content_rect.y(), | |
60 content_rect.width(), | |
61 content_rect.height()); | |
62 canvas->clipRect(layer_skrect); | |
63 canvas->scale(contents_scale, contents_scale); | |
64 | 66 |
65 gfx::Rect layer_rect = gfx::ToEnclosedRect(gfx::ScaleRect(gfx::RectF(content_r ect), 1 / contents_scale)); | 67 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
danakj
2013/01/05 00:04:58
Why enclosing? We do enclosing when going from lay
enne (OOO)
2013/01/06 03:57:18
Good question. I think what I should do is just s
| |
68 gfx::ScaleRect(gfx::RectF(content_rect), 1 / contents_scale)); | |
66 | 69 |
67 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 70 for (PicturePile::Pile::const_iterator i = pile_.begin(); |
68 i != pile_.end(); ++i) { | 71 i != pile_.end(); ++i) { |
69 if (!(*i)->LayerRect().Intersects(layer_rect)) | 72 gfx::Rect picture_layer_rect = (*i)->LayerRect(); |
73 if (!picture_layer_rect.Intersects(layer_rect)) | |
70 continue; | 74 continue; |
71 (*i)->Raster(canvas); | 75 |
76 // This is intentionally *enclosed* rect, so that the clip is aligned on | |
77 // integral post-scale content pixels and does not extend past the edges of | |
78 // the picture's layer rect. The min_contents_scale enforces that enough | |
79 // buffer pixels have been added such that the enclosed rect encompasses all | |
80 // invalidated pixels at that scale level. | |
81 gfx::Rect content_clip = gfx::ToEnclosedRect( | |
82 gfx::ScaleRect(picture_layer_rect, contents_scale)); | |
83 (*i)->Raster(canvas, content_clip, contents_scale); | |
72 | 84 |
73 SkISize deviceSize = canvas->getDeviceSize(); | 85 SkISize deviceSize = canvas->getDeviceSize(); |
74 stats->totalPixelsRasterized += deviceSize.width() * deviceSize.height(); | 86 stats->totalPixelsRasterized += deviceSize.width() * deviceSize.height(); |
75 } | 87 } |
76 canvas->restore(); | 88 canvas->restore(); |
77 | 89 |
78 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() - | 90 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() - |
79 rasterizeBeginTime).InSecondsF(); | 91 rasterizeBeginTime).InSecondsF(); |
80 } | 92 } |
81 | 93 |
82 void PicturePileImpl::GatherPixelRefs( | 94 void PicturePileImpl::GatherPixelRefs( |
83 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) { | 95 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) { |
84 std::list<skia::LazyPixelRef*> result; | 96 std::list<skia::LazyPixelRef*> result; |
85 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 97 for (PicturePile::Pile::const_iterator i = pile_.begin(); |
86 i != pile_.end(); ++i) { | 98 i != pile_.end(); ++i) { |
87 (*i)->GatherPixelRefs(rect, result); | 99 (*i)->GatherPixelRefs(rect, result); |
88 pixel_refs.splice(pixel_refs.end(), result); | 100 pixel_refs.splice(pixel_refs.end(), result); |
89 } | 101 } |
90 } | 102 } |
91 | 103 |
92 } // namespace cc | 104 } // namespace cc |
OLD | NEW |