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"
13 scoped_refptr
<PicturePileImpl
> PicturePileImpl::Create() {
14 return make_scoped_refptr(new PicturePileImpl());
17 PicturePileImpl::PicturePileImpl() {
20 PicturePileImpl::~PicturePileImpl() {
23 scoped_refptr
<PicturePileImpl
> PicturePileImpl::CloneForDrawing() const {
24 TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing");
25 scoped_refptr
<PicturePileImpl
> clone
= Create();
26 for (PicturePile::Pile::const_iterator i
= pile_
.begin();
27 i
!= pile_
.end(); ++i
)
28 clone
->pile_
.push_back((*i
)->Clone());
33 void PicturePileImpl::Raster(SkCanvas
* canvas
, gfx::Rect rect
,
34 RenderingStats
* stats
) {
35 base::TimeTicks rasterizeBeginTime
= base::TimeTicks::Now();
37 // TODO(enne): do this more efficiently, i.e. top down with Skia clips
39 canvas
->translate(-rect
.x(), -rect
.y());
40 SkRect layer_skrect
= SkRect::MakeXYWH(rect
.x(), rect
.y(),
41 rect
.width(), rect
.height());
42 canvas
->clipRect(layer_skrect
);
43 for (PicturePile::Pile::const_iterator i
= pile_
.begin();
44 i
!= pile_
.end(); ++i
) {
45 if (!(*i
)->LayerRect().Intersects(rect
))
49 SkISize deviceSize
= canvas
->getDeviceSize();
50 stats
->totalPixelsRasterized
+= deviceSize
.width() * deviceSize
.height();
54 stats
->totalRasterizeTimeInSeconds
+= (base::TimeTicks::Now() -
55 rasterizeBeginTime
).InSecondsF();