| 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)); |
| 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 | |
| 65 gfx::Rect layer_rect = gfx::ToEnclosedRect(gfx::ScaleRect(gfx::RectF(content_r
ect), 1 / contents_scale)); | |
| 66 | 66 |
| 67 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 67 for (PicturePile::Pile::const_iterator i = pile_.begin(); |
| 68 i != pile_.end(); ++i) { | 68 i != pile_.end(); ++i) { |
| 69 if (!(*i)->LayerRect().Intersects(layer_rect)) | 69 // 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 |
| 71 // 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 |
| 73 // invalidated pixels at any larger scale level. |
| 74 gfx::Rect content_clip = gfx::ToEnclosedRect( |
| 75 gfx::ScaleRect((*i)->LayerRect(), contents_scale)); |
| 76 if (!content_rect.Intersects(content_clip)) |
| 70 continue; | 77 continue; |
| 71 (*i)->Raster(canvas); | 78 |
| 79 (*i)->Raster(canvas, content_clip, contents_scale); |
| 72 | 80 |
| 73 SkISize deviceSize = canvas->getDeviceSize(); | 81 SkISize deviceSize = canvas->getDeviceSize(); |
| 74 stats->totalPixelsRasterized += deviceSize.width() * deviceSize.height(); | 82 stats->totalPixelsRasterized += deviceSize.width() * deviceSize.height(); |
| 75 } | 83 } |
| 76 canvas->restore(); | 84 canvas->restore(); |
| 77 | 85 |
| 78 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() - | 86 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() - |
| 79 rasterizeBeginTime).InSecondsF(); | 87 rasterizeBeginTime).InSecondsF(); |
| 80 } | 88 } |
| 81 | 89 |
| 82 void PicturePileImpl::GatherPixelRefs( | 90 void PicturePileImpl::GatherPixelRefs( |
| 83 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) { | 91 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) { |
| 84 std::list<skia::LazyPixelRef*> result; | 92 std::list<skia::LazyPixelRef*> result; |
| 85 for (PicturePile::Pile::const_iterator i = pile_.begin(); | 93 for (PicturePile::Pile::const_iterator i = pile_.begin(); |
| 86 i != pile_.end(); ++i) { | 94 i != pile_.end(); ++i) { |
| 87 (*i)->GatherPixelRefs(rect, result); | 95 (*i)->GatherPixelRefs(rect, result); |
| 88 pixel_refs.splice(pixel_refs.end(), result); | 96 pixel_refs.splice(pixel_refs.end(), result); |
| 89 } | 97 } |
| 90 } | 98 } |
| 91 | 99 |
| 92 } // namespace cc | 100 } // namespace cc |
| OLD | NEW |