[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 | |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 18 | PictureLayer::PictureLayer(ContentLayerClient* client) |
| 19 | : client_(client), |
| 20 | pile_(make_scoped_refptr(new PicturePile())), |
| 21 | instrumentation_object_tracker_(id()), |
| 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] | 2325768 | 2013-05-17 22:53:03 | [diff] [blame] | 40 | // This should be first so others can use it. |
| 41 | layer_impl->UpdateTwinLayer(); |
| 42 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 43 | layer_impl->SetIsMask(is_mask_); |
[email protected] | 6398904 | 2013-07-01 22:44:51 | [diff] [blame] | 44 | layer_impl->CreateTilingSetIfNeeded(); |
[email protected] | 9053617 | 2013-05-14 00:23:06 | [diff] [blame] | 45 | // Unlike other properties, invalidation must always be set on layer_impl. |
| 46 | // See PictureLayerImpl::PushPropertiesTo for more details. |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 47 | layer_impl->invalidation_.Clear(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 48 | layer_impl->invalidation_.Swap(&pile_invalidation_); |
[email protected] | 5946013 | 2013-06-26 20:04:02 | [diff] [blame] | 49 | layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 50 | layer_impl->SyncFromActiveLayer(); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 53 | void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 54 | Layer::SetLayerTreeHost(host); |
[email protected] | f974be6 | 2013-02-28 19:12:26 | [diff] [blame] | 55 | if (host) { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 56 | pile_->SetMinContentsScale(host->settings().minimum_contents_scale); |
| 57 | pile_->SetTileGridSize(host->settings().default_tile_size); |
| 58 | pile_->set_num_raster_threads(host->settings().num_raster_threads); |
[email protected] | e6ac3a7 | 2013-03-13 03:50:53 | [diff] [blame] | 59 | pile_->set_slow_down_raster_scale_factor( |
[email protected] | 846f455b | 2013-03-18 19:07:41 | [diff] [blame] | 60 | host->debug_state().slow_down_raster_scale_factor); |
[email protected] | 334a772 | 2013-04-04 11:51:58 | [diff] [blame] | 61 | pile_->set_show_debug_picture_borders( |
| 62 | host->debug_state().show_picture_borders); |
[email protected] | f974be6 | 2013-02-28 19:12:26 | [diff] [blame] | 63 | } |
[email protected] | ce37a15 | 2013-01-08 17:12:33 | [diff] [blame] | 64 | } |
| 65 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 66 | void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) { |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 67 | gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); |
[email protected] | 7a9fc13 | 2013-01-10 00:54:58 | [diff] [blame] | 68 | if (!rect.IsEmpty()) { |
| 69 | // Clamp invalidation to the layer bounds. |
| 70 | rect.Intersect(gfx::Rect(bounds())); |
| 71 | pending_invalidation_.Union(rect); |
| 72 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 73 | Layer::SetNeedsDisplayRect(layer_rect); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 74 | } |
| 75 | |
[email protected] | 49304bde | 2013-07-08 21:31:22 | [diff] [blame^] | 76 | bool PictureLayer::Update(ResourceUpdateQueue*, |
[email protected] | 09185be1 | 2013-06-29 01:11:39 | [diff] [blame] | 77 | const OcclusionTracker*) { |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 78 | // Do not early-out of this function so that PicturePile::Update has a chance |
| 79 | // to record pictures due to changing visibility of this layer. |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 80 | |
[email protected] | 445881f | 2013-04-16 01:11:59 | [diff] [blame] | 81 | pile_->Resize(paint_properties().bounds); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 82 | |
| 83 | // Calling paint in WebKit can sometimes cause invalidations, so save |
| 84 | // off the invalidation prior to calling update. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 85 | pile_invalidation_.Swap(&pending_invalidation_); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 86 | pending_invalidation_.Clear(); |
| 87 | |
[email protected] | 935ba27 | 2013-05-20 03:50:21 | [diff] [blame] | 88 | gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
| 89 | visible_content_rect(), 1.f / contents_scale_x()); |
[email protected] | 7f39514 | 2013-05-22 15:45:03 | [diff] [blame] | 90 | devtools_instrumentation::ScopedLayerTask paint_layer( |
| 91 | devtools_instrumentation::kPaintLayer, id()); |
[email protected] | 49304bde | 2013-07-08 21:31:22 | [diff] [blame^] | 92 | bool updated = pile_->Update(client_, |
| 93 | SafeOpaqueBackgroundColor(), |
| 94 | contents_opaque(), |
| 95 | pile_invalidation_, |
| 96 | visible_layer_rect, |
| 97 | rendering_stats_instrumentation()); |
| 98 | if (!updated) { |
| 99 | // If this invalidation did not affect the pile, then it can be cleared as |
| 100 | // an optimization. |
| 101 | pile_invalidation_.Clear(); |
| 102 | } |
| 103 | return updated; |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 104 | } |
| 105 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 106 | void PictureLayer::SetIsMask(bool is_mask) { |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 107 | is_mask_ = is_mask; |
| 108 | } |
| 109 | |
[email protected] | 7924c185 | 2013-05-24 16:18:43 | [diff] [blame] | 110 | bool PictureLayer::SupportsLCDText() const { |
| 111 | return true; |
| 112 | } |
| 113 | |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 114 | } // namespace cc |