Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [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 | |
| 5 | #include "cc/layers/picture_layer.h" |
| 6 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 7 | #include "cc/debug/benchmark_instrumentation.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 8 | #include "cc/debug/devtools_instrumentation.h" |
| 9 | #include "cc/layers/picture_layer_impl.h" |
| 10 | #include "cc/trees/layer_tree_impl.h" |
| 11 | #include "ui/gfx/rect_conversions.h" |
| 12 | |
| 13 | namespace cc { |
| 14 | |
| 15 | scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
| 16 | return make_scoped_refptr(new PictureLayer(client)); |
| 17 | } |
| 18 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 19 | PictureLayer::PictureLayer(ContentLayerClient* client) |
| 20 | : client_(client), |
| 21 | pile_(make_scoped_refptr(new PicturePile())), |
| 22 | instrumentation_object_tracker_(id()), |
| 23 | is_mask_(false) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | PictureLayer::~PictureLayer() { |
| 27 | } |
| 28 | |
| 29 | bool PictureLayer::DrawsContent() const { |
| 30 | return Layer::DrawsContent() && client_; |
| 31 | } |
| 32 | |
| 33 | scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 34 | return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 35 | } |
| 36 | |
| 37 | void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
| 38 | Layer::PushPropertiesTo(base_layer); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 39 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 40 | PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 41 | // This should be first so others can use it. |
| 42 | layer_impl->UpdateTwinLayer(); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 43 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 44 | layer_impl->SetIsMask(is_mask_); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 45 | layer_impl->CreateTilingSetIfNeeded(); |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 46 | // Unlike other properties, invalidation must always be set on layer_impl. |
| 47 | // See PictureLayerImpl::PushPropertiesTo for more details. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 48 | layer_impl->invalidation_.Clear(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 49 | layer_impl->invalidation_.Swap(&pile_invalidation_); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 50 | layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 51 | layer_impl->SyncFromActiveLayer(); |
| 52 | |
| 53 | // PictureLayer must push properties every frame. |
| 54 | // TODO(danakj): If we can avoid requiring to do CreateTilingSetIfNeeded() and |
| 55 | // SyncFromActiveLayer() on every commit then this could go away, maybe |
| 56 | // conditionally. crbug.com/259402 |
| 57 | needs_push_properties_ = true; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 61 | Layer::SetLayerTreeHost(host); |
| 62 | if (host) { |
| 63 | pile_->SetMinContentsScale(host->settings().minimum_contents_scale); |
| 64 | pile_->SetTileGridSize(host->settings().default_tile_size); |
| 65 | pile_->set_num_raster_threads(host->settings().num_raster_threads); |
| 66 | pile_->set_slow_down_raster_scale_factor( |
| 67 | host->debug_state().slow_down_raster_scale_factor); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 68 | pile_->set_show_debug_picture_borders( |
| 69 | host->debug_state().show_picture_borders); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) { |
| 74 | gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); |
| 75 | if (!rect.IsEmpty()) { |
| 76 | // Clamp invalidation to the layer bounds. |
| 77 | rect.Intersect(gfx::Rect(bounds())); |
| 78 | pending_invalidation_.Union(rect); |
| 79 | } |
| 80 | Layer::SetNeedsDisplayRect(layer_rect); |
| 81 | } |
| 82 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 83 | bool PictureLayer::Update(ResourceUpdateQueue* queue, |
| 84 | const OcclusionTracker* occlusion) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 85 | // Do not early-out of this function so that PicturePile::Update has a chance |
| 86 | // to record pictures due to changing visibility of this layer. |
| 87 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 88 | TRACE_EVENT1(benchmark_instrumentation::kCategory, |
| 89 | benchmark_instrumentation::kPictureLayerUpdate, |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 90 | benchmark_instrumentation::kSourceFrameNumber, |
| 91 | layer_tree_host()->source_frame_number()); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 92 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 93 | bool updated = Layer::Update(queue, occlusion); |
| 94 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 95 | pile_->Resize(paint_properties().bounds); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 96 | |
| 97 | // Calling paint in WebKit can sometimes cause invalidations, so save |
| 98 | // off the invalidation prior to calling update. |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 99 | pending_invalidation_.Swap(&pile_invalidation_); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 100 | pending_invalidation_.Clear(); |
| 101 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 102 | gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
| 103 | visible_content_rect(), 1.f / contents_scale_x()); |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 104 | if (layer_tree_host()->settings().using_synchronous_renderer_compositor) { |
| 105 | // Workaround for http://crbug.com/235910 - to retain backwards compat |
| 106 | // the full page content must always be provided in the picture layer. |
| 107 | visible_layer_rect = gfx::Rect(bounds()); |
| 108 | } |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 109 | devtools_instrumentation::ScopedLayerTask paint_layer( |
| 110 | devtools_instrumentation::kPaintLayer, id()); |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 111 | updated |= pile_->Update(client_, |
| 112 | SafeOpaqueBackgroundColor(), |
| 113 | contents_opaque(), |
| 114 | pile_invalidation_, |
| 115 | visible_layer_rect, |
| 116 | rendering_stats_instrumentation()); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 117 | if (!updated) { |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 118 | // If this invalidation did not affect the pile, then it can be cleared as |
| 119 | // an optimization. |
| 120 | pile_invalidation_.Clear(); |
| 121 | } |
| 122 | return updated; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void PictureLayer::SetIsMask(bool is_mask) { |
| 126 | is_mask_ = is_mask; |
| 127 | } |
| 128 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 129 | bool PictureLayer::SupportsLCDText() const { |
| 130 | return true; |
| 131 | } |
| 132 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 133 | } // namespace cc |