Enabling tests which should be fixed by r173829.
[chromium-blink-merge.git] / cc / picture_pile_impl.cc
blob05f9584ae58bb1f82306f7d244053b42a32909d1
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
3 // found in the LICENSE file.
5 #include "base/debug/trace_event.h"
6 #include "cc/picture_pile_impl.h"
7 #include "cc/rendering_stats.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkSize.h"
10 #include "ui/gfx/rect_conversions.h"
12 namespace cc {
14 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() {
15 return make_scoped_refptr(new PicturePileImpl());
18 PicturePileImpl::PicturePileImpl() {
21 PicturePileImpl::~PicturePileImpl() {
24 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread(
25 base::Thread* thread) {
26 // Do we have a clone for this thread yet?
27 CloneMap::iterator it = clones_.find(thread->thread_id());
28 if (it != clones_.end())
29 return it->second;
31 // Create clone for this thread.
32 scoped_refptr<PicturePileImpl> clone = CloneForDrawing();
33 clones_[thread->thread_id()] = clone;
34 return clone;
37 scoped_refptr<PicturePileImpl> PicturePileImpl::CloneForDrawing() const {
38 TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing");
39 scoped_refptr<PicturePileImpl> clone = Create();
40 for (PicturePile::Pile::const_iterator i = pile_.begin();
41 i != pile_.end(); ++i)
42 clone->pile_.push_back((*i)->Clone());
44 return clone;
47 void PicturePileImpl::Raster(
48 SkCanvas* canvas,
49 gfx::Rect content_rect,
50 float contents_scale,
51 RenderingStats* stats) {
52 base::TimeTicks rasterizeBeginTime = base::TimeTicks::Now();
54 // TODO(enne): do this more efficiently, i.e. top down with Skia clips
55 canvas->save();
56 canvas->translate(-content_rect.x(), -content_rect.y());
57 SkRect layer_skrect = SkRect::MakeXYWH(
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);
65 gfx::Rect layer_rect = gfx::ToEnclosedRect(gfx::ScaleRect(gfx::RectF(content_rect), 1 / contents_scale));
67 for (PicturePile::Pile::const_iterator i = pile_.begin();
68 i != pile_.end(); ++i) {
69 if (!(*i)->LayerRect().Intersects(layer_rect))
70 continue;
71 (*i)->Raster(canvas);
73 SkISize deviceSize = canvas->getDeviceSize();
74 stats->totalPixelsRasterized += deviceSize.width() * deviceSize.height();
76 canvas->restore();
78 stats->totalRasterizeTimeInSeconds += (base::TimeTicks::Now() -
79 rasterizeBeginTime).InSecondsF();
82 void PicturePileImpl::GatherPixelRefs(
83 const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) {
84 std::list<skia::LazyPixelRef*> result;
85 for (PicturePile::Pile::const_iterator i = pile_.begin();
86 i != pile_.end(); ++i) {
87 (*i)->GatherPixelRefs(rect, result);
88 pixel_refs.splice(pixel_refs.end(), result);
92 } // namespace cc