[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] | 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(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 43 | layer_impl->invalidation_.Swap(&pile_invalidation_); |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 44 | layer_impl->pile_ = |
| 45 | PicturePileImpl::CreateFromOther(pile_, layer_impl->is_using_lcd_text_); |
[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) { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 52 | pile_->SetMinContentsScale(host->settings().minimum_contents_scale); |
| 53 | pile_->SetTileGridSize(host->settings().default_tile_size); |
| 54 | pile_->set_num_raster_threads(host->settings().num_raster_threads); |
[email protected] | e6ac3a7 | 2013-03-13 03:50:53 | [diff] [blame] | 55 | pile_->set_slow_down_raster_scale_factor( |
[email protected] | 846f455b | 2013-03-18 19:07:41 | [diff] [blame] | 56 | host->debug_state().slow_down_raster_scale_factor); |
[email protected] | 334a772 | 2013-04-04 11:51:58 | [diff] [blame^] | 57 | pile_->set_show_debug_picture_borders( |
| 58 | host->debug_state().show_picture_borders); |
[email protected] | f974be6 | 2013-02-28 19:12:26 | [diff] [blame] | 59 | } |
[email protected] | ce37a15 | 2013-01-08 17:12:33 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 62 | void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) { |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 63 | gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); |
[email protected] | 7a9fc13 | 2013-01-10 00:54:58 | [diff] [blame] | 64 | if (!rect.IsEmpty()) { |
| 65 | // Clamp invalidation to the layer bounds. |
| 66 | rect.Intersect(gfx::Rect(bounds())); |
| 67 | pending_invalidation_.Union(rect); |
| 68 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 69 | Layer::SetNeedsDisplayRect(layer_rect); |
[email protected] | 3621e18 | 2012-11-09 22:37:09 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 72 | void PictureLayer::Update(ResourceUpdateQueue*, |
[email protected] | b3b5d0a | 2013-03-28 03:53:29 | [diff] [blame] | 73 | const OcclusionTracker*, |
| 74 | RenderingStats* stats) { |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 75 | // Do not early-out of this function so that PicturePile::Update has a chance |
| 76 | // to record pictures due to changing visibility of this layer. |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 77 | |
[email protected] | 8433943 | 2013-01-17 03:00:11 | [diff] [blame] | 78 | pile_->Resize(bounds()); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 79 | |
| 80 | // Calling paint in WebKit can sometimes cause invalidations, so save |
| 81 | // off the invalidation prior to calling update. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 82 | pile_invalidation_.Swap(&pending_invalidation_); |
[email protected] | 0e630ea3 | 2012-11-28 03:29:17 | [diff] [blame] | 83 | pending_invalidation_.Clear(); |
| 84 | |
[email protected] | fd3eec6 | 2013-01-24 19:54:03 | [diff] [blame] | 85 | gfx::Rect visible_layer_rect = gfx::ToEnclosingRect( |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 86 | gfx::ScaleRect(visible_content_rect(), 1.f / contents_scale_x())); |
[email protected] | df41c04 | 2013-02-27 16:01:29 | [diff] [blame] | 87 | devtools_instrumentation::ScopedPaintLayer paint_layer(id()); |
[email protected] | 43f7c3d | 2013-03-02 18:00:40 | [diff] [blame] | 88 | pile_->Update(client_, |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 89 | background_color(), |
[email protected] | 43f7c3d | 2013-03-02 18:00:40 | [diff] [blame] | 90 | pile_invalidation_, |
| 91 | visible_layer_rect, |
[email protected] | b3b5d0a | 2013-03-28 03:53:29 | [diff] [blame] | 92 | stats); |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 93 | } |
| 94 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 95 | void PictureLayer::SetIsMask(bool is_mask) { |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 96 | is_mask_ = is_mask; |
| 97 | } |
| 98 | |
[email protected] | d98c024 | 2012-11-08 06:22:35 | [diff] [blame] | 99 | } // namespace cc |