[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 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. | ||||
4 | |||||
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 5 | #include "cc/picture_layer.h" |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 6 | |
7 | #include "cc/layer_tree_impl.h" | ||||
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 8 | #include "cc/picture_layer_impl.h" |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 9 | #include "ui/gfx/rect_conversions.h" |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 10 | |
11 | namespace cc { | ||||
12 | |||||
13 | scoped_refptr<PictureLayer> PictureLayer::create(ContentLayerClient* client) { | ||||
14 | return make_scoped_refptr(new PictureLayer(client)); | ||||
15 | } | ||||
16 | |||||
17 | PictureLayer::PictureLayer(ContentLayerClient* client) : | ||||
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 18 | client_(client), |
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame^] | 19 | pile_(make_scoped_refptr(new PicturePile())), |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 20 | is_mask_(false) { |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 21 | } |
22 | |||||
23 | PictureLayer::~PictureLayer() { | ||||
24 | } | ||||
25 | |||||
26 | bool PictureLayer::drawsContent() const { | ||||
27 | return Layer::drawsContent() && client_; | ||||
28 | } | ||||
29 | |||||
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 30 | scoped_ptr<LayerImpl> PictureLayer::createLayerImpl(LayerTreeImpl* treeImpl) { |
31 | return PictureLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>(); | ||||
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 32 | } |
33 | |||||
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 34 | void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) { |
[email protected] | c96e821 | 2012-11-27 22:48:08 | [diff] [blame] | 35 | Layer::pushPropertiesTo(base_layer); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 36 | |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 37 | PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 38 | layer_impl->SetIsMask(is_mask_); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 39 | layer_impl->tilings_.SetLayerBounds(bounds()); |
40 | layer_impl->invalidation_.Clear(); | ||||
41 | layer_impl->invalidation_.Swap(pile_invalidation_); | ||||
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame^] | 42 | pile_->PushPropertiesTo(layer_impl->pile_); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 43 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 44 | layer_impl->SyncFromActiveLayer(); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 45 | } |
46 | |||||
[email protected] | ce37a15 | 2013-01-08 17:12:33 | [diff] [blame] | 47 | void PictureLayer::setLayerTreeHost(LayerTreeHost* host) { |
48 | Layer::setLayerTreeHost(host); | ||||
49 | if (host) | ||||
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame^] | 50 | pile_->SetMinContentsScale(host->settings().minimumContentsScale); |
[email protected] | ce37a15 | 2013-01-08 17:12:33 | [diff] [blame] | 51 | } |
52 | |||||
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 53 | void PictureLayer::setNeedsDisplayRect(const gfx::RectF& layer_rect) { |
54 | gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); | ||||
[email protected] | 7a9fc13 | 2013-01-10 00:54:58 | [diff] [blame] | 55 | if (!rect.IsEmpty()) { |
56 | // Clamp invalidation to the layer bounds. | ||||
57 | rect.Intersect(gfx::Rect(bounds())); | ||||
58 | pending_invalidation_.Union(rect); | ||||
59 | } | ||||
[email protected] | 0c4271a | 2012-11-30 01:40:31 | [diff] [blame] | 60 | Layer::setNeedsDisplayRect(layer_rect); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 61 | } |
62 | |||||
63 | void PictureLayer::update(ResourceUpdateQueue&, const OcclusionTracker*, | ||||
64 | RenderingStats& stats) { | ||||
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame^] | 65 | if (pile_->size() == bounds() && pending_invalidation_.IsEmpty()) |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 66 | return; |
67 | |||||
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame^] | 68 | pile_->Resize(bounds()); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 69 | |
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] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame^] | 75 | pile_->Update(client_, pile_invalidation_, stats); |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 76 | } |
77 | |||||
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 78 | void PictureLayer::setIsMask(bool is_mask) { |
79 | is_mask_ = is_mask; | ||||
80 | } | ||||
81 | |||||
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 82 | } // namespace cc |