blob: 8c5bc91c721c91aa9527a3c379de6a3f83f9d231 [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
[email protected]df41c042013-02-27 16:01:297#include "cc/devtools_instrumentation.h"
[email protected]f117a4c2012-12-16 04:53:108#include "cc/layer_tree_impl.h"
[email protected]d98c0242012-11-08 06:22:359#include "cc/picture_layer_impl.h"
[email protected]3621e182012-11-09 22:37:0910#include "ui/gfx/rect_conversions.h"
[email protected]d98c0242012-11-08 06:22:3511
12namespace cc {
13
14scoped_refptr<PictureLayer> PictureLayer::create(ContentLayerClient* client) {
15 return make_scoped_refptr(new PictureLayer(client));
16}
17
18PictureLayer::PictureLayer(ContentLayerClient* client) :
[email protected]f6776532012-12-21 20:24:3319 client_(client),
[email protected]84339432013-01-17 03:00:1120 pile_(make_scoped_refptr(new PicturePile())),
[email protected]df41c042013-02-27 16:01:2921 instrumentation_object_tracker_(id()),
[email protected]f6776532012-12-21 20:24:3322 is_mask_(false) {
[email protected]d98c0242012-11-08 06:22:3523}
24
25PictureLayer::~PictureLayer() {
26}
27
28bool PictureLayer::drawsContent() const {
29 return Layer::drawsContent() && client_;
30}
31
[email protected]8bef40572012-12-11 21:38:0832scoped_ptr<LayerImpl> PictureLayer::createLayerImpl(LayerTreeImpl* treeImpl) {
33 return PictureLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>();
[email protected]d98c0242012-11-08 06:22:3534}
35
[email protected]3621e182012-11-09 22:37:0936void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) {
[email protected]c96e8212012-11-27 22:48:0837 Layer::pushPropertiesTo(base_layer);
[email protected]f117a4c2012-12-16 04:53:1038
[email protected]3621e182012-11-09 22:37:0939 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
[email protected]f6776532012-12-21 20:24:3340 layer_impl->SetIsMask(is_mask_);
[email protected]48871fc2013-01-23 07:36:5141 layer_impl->CreateTilingSet();
[email protected]f117a4c2012-12-16 04:53:1042 layer_impl->invalidation_.Clear();
43 layer_impl->invalidation_.Swap(pile_invalidation_);
[email protected]84339432013-01-17 03:00:1144 pile_->PushPropertiesTo(layer_impl->pile_);
[email protected]3621e182012-11-09 22:37:0945
[email protected]f117a4c2012-12-16 04:53:1046 layer_impl->SyncFromActiveLayer();
[email protected]3621e182012-11-09 22:37:0947}
48
[email protected]ce37a152013-01-08 17:12:3349void PictureLayer::setLayerTreeHost(LayerTreeHost* host) {
50 Layer::setLayerTreeHost(host);
51 if (host)
[email protected]84339432013-01-17 03:00:1152 pile_->SetMinContentsScale(host->settings().minimumContentsScale);
[email protected]ce37a152013-01-08 17:12:3353}
54
[email protected]3621e182012-11-09 22:37:0955void PictureLayer::setNeedsDisplayRect(const gfx::RectF& layer_rect) {
56 gfx::Rect rect = gfx::ToEnclosedRect(layer_rect);
[email protected]7a9fc132013-01-10 00:54:5857 if (!rect.IsEmpty()) {
58 // Clamp invalidation to the layer bounds.
59 rect.Intersect(gfx::Rect(bounds()));
60 pending_invalidation_.Union(rect);
61 }
[email protected]0c4271a2012-11-30 01:40:3162 Layer::setNeedsDisplayRect(layer_rect);
[email protected]3621e182012-11-09 22:37:0963}
64
65void PictureLayer::update(ResourceUpdateQueue&, const OcclusionTracker*,
[email protected]dc6c5522013-02-02 01:10:3066 RenderingStats* stats) {
[email protected]fd3eec62013-01-24 19:54:0367 // Do not early-out of this function so that PicturePile::Update has a chance
68 // to record pictures due to changing visibility of this layer.
[email protected]0e630ea32012-11-28 03:29:1769
[email protected]84339432013-01-17 03:00:1170 pile_->Resize(bounds());
[email protected]0e630ea32012-11-28 03:29:1771
72 // Calling paint in WebKit can sometimes cause invalidations, so save
73 // off the invalidation prior to calling update.
74 pile_invalidation_.Swap(pending_invalidation_);
75 pending_invalidation_.Clear();
76
[email protected]fd3eec62013-01-24 19:54:0377 gfx::Rect visible_layer_rect = gfx::ToEnclosingRect(
78 gfx::ScaleRect(visibleContentRect(), 1.f / contentsScaleX()));
[email protected]df41c042013-02-27 16:01:2979 devtools_instrumentation::ScopedPaintLayer paint_layer(id());
[email protected]fd3eec62013-01-24 19:54:0380 pile_->Update(client_, pile_invalidation_, visible_layer_rect, stats);
[email protected]d98c0242012-11-08 06:22:3581}
82
[email protected]f6776532012-12-21 20:24:3383void PictureLayer::setIsMask(bool is_mask) {
84 is_mask_ = is_mask;
85}
86
[email protected]d98c0242012-11-08 06:22:3587} // namespace cc