summaryrefslogtreecommitdiffstats
path: root/cc/picture_pile_impl.cc
blob: 217a5eb4ee4e2922bbf9b85f77cbbfe791c91e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/debug/trace_event.h"
#include "cc/picture_pile_impl.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace cc {

scoped_refptr<PicturePileImpl> PicturePileImpl::Create() {
  return make_scoped_refptr(new PicturePileImpl());
}

PicturePileImpl::PicturePileImpl() {
}

PicturePileImpl::~PicturePileImpl() {
}

scoped_refptr<PicturePileImpl> PicturePileImpl::CloneForDrawing() const {
  TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing");
  scoped_refptr<PicturePileImpl> clone = Create();
  clone->pile_.resize(pile_.size());
  for (size_t i = 0; i < pile_.size(); ++i)
    clone->pile_[i] = pile_[i]->Clone();

  return clone;
}

void PicturePileImpl::Raster(SkCanvas* canvas, gfx::Rect rect) {
  // TODO(enne): do this more efficiently, i.e. top down with Skia clips
  canvas->save();
  canvas->translate(-rect.x(), -rect.y());
  SkRect layer_skrect = SkRect::MakeXYWH(rect.x(), rect.y(),
                                         rect.width(), rect.height());
  canvas->clipRect(layer_skrect);
  for (size_t i = 0; i < pile_.size(); ++i) {
    if (!pile_[i]->LayerRect().Intersects(rect))
      continue;
    pile_[i]->Raster(canvas);
  }
  canvas->restore();
}

}  // namespace cc