[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] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame^] | 5 | #include "cc/layers/picture_layer.h" |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 6 | |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 7 | #include "cc/debug/devtools_instrumentation.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame^] | 8 | #include "cc/layers/picture_layer_impl.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 9 | #include "cc/trees/layer_tree_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] | 8c406cda3 | 2013-03-14 16:20:32 | [diff] [blame] | 32 | scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 33 | return PictureLayerImpl::Create(tree_impl, 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] | 1b53ba7 | 2013-03-17 06:22:17 | [diff] [blame] | 44 | layer_impl->pile_ = PicturePileImpl::CreateFromOther(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] | e6ac3a7 | 2013-03-13 03:50:53 | [diff] [blame] | 55 | pile_->set_slow_down_raster_scale_factor( |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 56 | host->debug_state().slowDownRasterScaleFactor); |
[email protected] | f974be6 | 2013-02-28 19:12:26 | [diff] [blame] | 57 | } |
[email protected] | ce37a15 | 2013-01-08 17:12:33 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 60 | void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) { |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 61 | gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); |
[email protected] | 7a9fc13 | 2013-01-10 00:54:58 | [diff] [blame] | 62 | if (!rect.IsEmpty()) { |
| 63 | // Clamp invalidation to the layer bounds. |
| 64 | rect.Intersect(gfx::Rect(bounds())); |
| 65 | pending_invalidation_.Union(rect); |
| 66 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 67 | Layer::SetNeedsDisplayRect(layer_rect); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 70 | void PictureLayer::Update(ResourceUpdateQueue*, |
| 71 | const OcclusionTracker*, |
[email protected] | dc6c552 | 2013-02-02 01:10:30 | [diff] [blame] | 72 | RenderingStats* stats) { |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 73 | // Do not early-out of this function so that PicturePile::Update has a chance |
| 74 | // to record pictures due to changing visibility of this layer. |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 75 | |
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame] | 76 | pile_->Resize(bounds()); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 77 | |
| 78 | // Calling paint in WebKit can sometimes cause invalidations, so save |
| 79 | // off the invalidation prior to calling update. |
| 80 | pile_invalidation_.Swap(pending_invalidation_); |
| 81 | pending_invalidation_.Clear(); |
| 82 | |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 83 | gfx::Rect visible_layer_rect = gfx::ToEnclosingRect( |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 84 | gfx::ScaleRect(visible_content_rect(), 1.f / contents_scale_x())); |
[email protected] | df41c04 | 2013-02-27 16:01:29 | [diff] [blame] | 85 | devtools_instrumentation::ScopedPaintLayer paint_layer(id()); |
[email protected] | 43f7c3d | 2013-03-02 18:00:40 | [diff] [blame] | 86 | pile_->Update(client_, |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 87 | background_color(), |
[email protected] | 43f7c3d | 2013-03-02 18:00:40 | [diff] [blame] | 88 | pile_invalidation_, |
| 89 | visible_layer_rect, |
| 90 | stats); |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 93 | void PictureLayer::SetIsMask(bool is_mask) { |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 94 | is_mask_ = is_mask; |
| 95 | } |
| 96 | |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 97 | } // namespace cc |