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