[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 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 14 | scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 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 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 28 | bool PictureLayer::DrawsContent() const { |
| 29 | return Layer::DrawsContent() && client_; |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 30 | } |
| 31 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 36 | void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
| 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 49 | void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 50 | Layer::SetLayerTreeHost(host); |
[email protected] | f974be6 | 2013-02-28 19:12:26 | [diff] [blame] | 51 | if (host) { |
| 52 | pile_->SetMinContentsScale(host->settings().minimumContentsScale); |
| 53 | pile_->SetTileGridSize(host->settings().defaultTileSize); |
[email protected] | 81b6f56 | 2013-03-02 19:12:11 | [diff] [blame] | 54 | pile_->set_num_raster_threads(host->settings().numRasterThreads); |
[email protected] | f974be6 | 2013-02-28 19:12:26 | [diff] [blame] | 55 | } |
[email protected] | ce37a15 | 2013-01-08 17:12:33 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 58 | void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) { |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 59 | gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); |
[email protected] | 7a9fc13 | 2013-01-10 00:54:58 | [diff] [blame] | 60 | if (!rect.IsEmpty()) { |
| 61 | // Clamp invalidation to the layer bounds. |
| 62 | rect.Intersect(gfx::Rect(bounds())); |
| 63 | pending_invalidation_.Union(rect); |
| 64 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 65 | Layer::SetNeedsDisplayRect(layer_rect); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 66 | } |
| 67 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 68 | void PictureLayer::Update(ResourceUpdateQueue*, |
| 69 | const OcclusionTracker*, |
[email protected] | dc6c552 | 2013-02-02 01:10:30 | [diff] [blame] | 70 | RenderingStats* stats) { |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 71 | // Do not early-out of this function so that PicturePile::Update has a chance |
| 72 | // to record pictures due to changing visibility of this layer. |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 73 | |
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame] | 74 | pile_->Resize(bounds()); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 75 | |
| 76 | // Calling paint in WebKit can sometimes cause invalidations, so save |
| 77 | // off the invalidation prior to calling update. |
| 78 | pile_invalidation_.Swap(pending_invalidation_); |
| 79 | pending_invalidation_.Clear(); |
| 80 | |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 81 | gfx::Rect visible_layer_rect = gfx::ToEnclosingRect( |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 82 | gfx::ScaleRect(visible_content_rect(), 1.f / contents_scale_x())); |
[email protected] | df41c04 | 2013-02-27 16:01:29 | [diff] [blame] | 83 | devtools_instrumentation::ScopedPaintLayer paint_layer(id()); |
[email protected] | 43f7c3d | 2013-03-02 18:00:40 | [diff] [blame] | 84 | pile_->Update(client_, |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 85 | background_color(), |
[email protected] | 43f7c3d | 2013-03-02 18:00:40 | [diff] [blame] | 86 | pile_invalidation_, |
| 87 | visible_layer_rect, |
| 88 | stats); |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame^] | 91 | void PictureLayer::SetIsMask(bool is_mask) { |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 92 | is_mask_ = is_mask; |
| 93 | } |
| 94 | |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 95 | } // namespace cc |