blob: 9114d6f2cd0cbb3cfd937ee8b7ebc7a779140726 [file] [log] [blame]
[email protected]d98c0242012-11-08 06:22:351// 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.
4
[email protected]d98c0242012-11-08 06:22:355#include "cc/picture_layer.h"
[email protected]f117a4c2012-12-16 04:53:106
7#include "cc/layer_tree_impl.h"
[email protected]d98c0242012-11-08 06:22:358#include "cc/picture_layer_impl.h"
[email protected]3621e182012-11-09 22:37:099#include "ui/gfx/rect_conversions.h"
[email protected]d98c0242012-11-08 06:22:3510
11namespace cc {
12
13scoped_refptr<PictureLayer> PictureLayer::create(ContentLayerClient* client) {
14 return make_scoped_refptr(new PictureLayer(client));
15}
16
17PictureLayer::PictureLayer(ContentLayerClient* client) :
[email protected]f6776532012-12-21 20:24:3318 client_(client),
[email protected]84339432013-01-17 03:00:1119 pile_(make_scoped_refptr(new PicturePile())),
[email protected]f6776532012-12-21 20:24:3320 is_mask_(false) {
[email protected]d98c0242012-11-08 06:22:3521}
22
23PictureLayer::~PictureLayer() {
24}
25
26bool PictureLayer::drawsContent() const {
27 return Layer::drawsContent() && client_;
28}
29
[email protected]8bef40572012-12-11 21:38:0830scoped_ptr<LayerImpl> PictureLayer::createLayerImpl(LayerTreeImpl* treeImpl) {
31 return PictureLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>();
[email protected]d98c0242012-11-08 06:22:3532}
33
[email protected]3621e182012-11-09 22:37:0934void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) {
[email protected]c96e8212012-11-27 22:48:0835 Layer::pushPropertiesTo(base_layer);
[email protected]f117a4c2012-12-16 04:53:1036
[email protected]3621e182012-11-09 22:37:0937 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
[email protected]f6776532012-12-21 20:24:3338 layer_impl->SetIsMask(is_mask_);
[email protected]f117a4c2012-12-16 04:53:1039 layer_impl->tilings_.SetLayerBounds(bounds());
40 layer_impl->invalidation_.Clear();
41 layer_impl->invalidation_.Swap(pile_invalidation_);
[email protected]84339432013-01-17 03:00:1142 pile_->PushPropertiesTo(layer_impl->pile_);
[email protected]3621e182012-11-09 22:37:0943
[email protected]f117a4c2012-12-16 04:53:1044 layer_impl->SyncFromActiveLayer();
[email protected]3621e182012-11-09 22:37:0945}
46
[email protected]ce37a152013-01-08 17:12:3347void PictureLayer::setLayerTreeHost(LayerTreeHost* host) {
48 Layer::setLayerTreeHost(host);
49 if (host)
[email protected]84339432013-01-17 03:00:1150 pile_->SetMinContentsScale(host->settings().minimumContentsScale);
[email protected]ce37a152013-01-08 17:12:3351}
52
[email protected]3621e182012-11-09 22:37:0953void PictureLayer::setNeedsDisplayRect(const gfx::RectF& layer_rect) {
54 gfx::Rect rect = gfx::ToEnclosedRect(layer_rect);
[email protected]7a9fc132013-01-10 00:54:5855 if (!rect.IsEmpty()) {
56 // Clamp invalidation to the layer bounds.
57 rect.Intersect(gfx::Rect(bounds()));
58 pending_invalidation_.Union(rect);
59 }
[email protected]0c4271a2012-11-30 01:40:3160 Layer::setNeedsDisplayRect(layer_rect);
[email protected]3621e182012-11-09 22:37:0961}
62
63void PictureLayer::update(ResourceUpdateQueue&, const OcclusionTracker*,
64 RenderingStats& stats) {
[email protected]84339432013-01-17 03:00:1165 if (pile_->size() == bounds() && pending_invalidation_.IsEmpty())
[email protected]0e630ea32012-11-28 03:29:1766 return;
67
[email protected]84339432013-01-17 03:00:1168 pile_->Resize(bounds());
[email protected]0e630ea32012-11-28 03:29:1769
70 // Calling paint in WebKit can sometimes cause invalidations, so save
71 // off the invalidation prior to calling update.
72 pile_invalidation_.Swap(pending_invalidation_);
73 pending_invalidation_.Clear();
74
[email protected]84339432013-01-17 03:00:1175 pile_->Update(client_, pile_invalidation_, stats);
[email protected]d98c0242012-11-08 06:22:3576}
77
[email protected]f6776532012-12-21 20:24:3378void PictureLayer::setIsMask(bool is_mask) {
79 is_mask_ = is_mask;
80}
81
[email protected]d98c0242012-11-08 06:22:3582} // namespace cc