blob: a66743435893c9430fff181489a0dc6e89f420d7 [file] [log] [blame]
[email protected]d98c0242012-11-08 06:22:351// 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]cc3cfaa2013-03-18 09:05:525#include "cc/layers/picture_layer.h"
[email protected]f117a4c2012-12-16 04:53:106
[email protected]5c6739c2013-07-15 23:33:297#include "cc/debug/benchmark_instrumentation.h"
[email protected]6e84de22013-03-18 06:54:278#include "cc/debug/devtools_instrumentation.h"
[email protected]cc3cfaa2013-03-18 09:05:529#include "cc/layers/picture_layer_impl.h"
[email protected]556fd292013-03-18 08:03:0410#include "cc/trees/layer_tree_impl.h"
[email protected]3621e182012-11-09 22:37:0911#include "ui/gfx/rect_conversions.h"
[email protected]d98c0242012-11-08 06:22:3512
13namespace cc {
14
[email protected]7aba6662013-03-12 10:17:3415scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
[email protected]d98c0242012-11-08 06:22:3516 return make_scoped_refptr(new PictureLayer(client));
17}
18
[email protected]bf691c22013-03-26 21:15:0619PictureLayer::PictureLayer(ContentLayerClient* client)
20 : client_(client),
21 pile_(make_scoped_refptr(new PicturePile())),
22 instrumentation_object_tracker_(id()),
23 is_mask_(false) {
[email protected]d98c0242012-11-08 06:22:3524}
25
26PictureLayer::~PictureLayer() {
27}
28
[email protected]7aba6662013-03-12 10:17:3429bool PictureLayer::DrawsContent() const {
30 return Layer::DrawsContent() && client_;
[email protected]d98c0242012-11-08 06:22:3531}
32
[email protected]8c406cda32013-03-14 16:20:3233scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
34 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
[email protected]d98c0242012-11-08 06:22:3535}
36
[email protected]7aba6662013-03-12 10:17:3437void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
38 Layer::PushPropertiesTo(base_layer);
[email protected]f117a4c2012-12-16 04:53:1039
[email protected]3621e182012-11-09 22:37:0940 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
[email protected]23257682013-05-17 22:53:0341 // This should be first so others can use it.
42 layer_impl->UpdateTwinLayer();
43
[email protected]f6776532012-12-21 20:24:3344 layer_impl->SetIsMask(is_mask_);
[email protected]63989042013-07-01 22:44:5145 layer_impl->CreateTilingSetIfNeeded();
[email protected]90536172013-05-14 00:23:0646 // Unlike other properties, invalidation must always be set on layer_impl.
47 // See PictureLayerImpl::PushPropertiesTo for more details.
[email protected]f117a4c2012-12-16 04:53:1048 layer_impl->invalidation_.Clear();
[email protected]d002dd02013-03-27 07:40:4049 layer_impl->invalidation_.Swap(&pile_invalidation_);
[email protected]59460132013-06-26 20:04:0250 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get());
[email protected]f117a4c2012-12-16 04:53:1051 layer_impl->SyncFromActiveLayer();
[email protected]f4e25f92013-07-13 20:54:5352
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;
[email protected]3621e182012-11-09 22:37:0958}
59
[email protected]7aba6662013-03-12 10:17:3460void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
61 Layer::SetLayerTreeHost(host);
[email protected]f974be62013-02-28 19:12:2662 if (host) {
[email protected]8e0176d2013-03-21 03:14:5263 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);
[email protected]e6ac3a72013-03-13 03:50:5366 pile_->set_slow_down_raster_scale_factor(
[email protected]846f455b2013-03-18 19:07:4167 host->debug_state().slow_down_raster_scale_factor);
[email protected]334a7722013-04-04 11:51:5868 pile_->set_show_debug_picture_borders(
69 host->debug_state().show_picture_borders);
[email protected]f974be62013-02-28 19:12:2670 }
[email protected]ce37a152013-01-08 17:12:3371}
72
[email protected]7aba6662013-03-12 10:17:3473void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) {
[email protected]3621e182012-11-09 22:37:0974 gfx::Rect rect = gfx::ToEnclosedRect(layer_rect);
[email protected]7a9fc132013-01-10 00:54:5875 if (!rect.IsEmpty()) {
76 // Clamp invalidation to the layer bounds.
77 rect.Intersect(gfx::Rect(bounds()));
78 pending_invalidation_.Union(rect);
79 }
[email protected]7aba6662013-03-12 10:17:3480 Layer::SetNeedsDisplayRect(layer_rect);
[email protected]3621e182012-11-09 22:37:0981}
82
[email protected]49304bde2013-07-08 21:31:2283bool PictureLayer::Update(ResourceUpdateQueue*,
[email protected]09185be12013-06-29 01:11:3984 const OcclusionTracker*) {
[email protected]fd3eec62013-01-24 19:54:0385 // 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.
[email protected]0e630ea32012-11-28 03:29:1787
[email protected]5c6739c2013-07-15 23:33:2988 TRACE_EVENT1(benchmark_instrumentation::kCategory,
89 benchmark_instrumentation::kPictureLayerUpdate,
90 benchmark_instrumentation::kCommitNumber,
91 layer_tree_host()->commit_number());
92
[email protected]445881f2013-04-16 01:11:5993 pile_->Resize(paint_properties().bounds);
[email protected]0e630ea32012-11-28 03:29:1794
95 // Calling paint in WebKit can sometimes cause invalidations, so save
96 // off the invalidation prior to calling update.
[email protected]d002dd02013-03-27 07:40:4097 pile_invalidation_.Swap(&pending_invalidation_);
[email protected]0e630ea32012-11-28 03:29:1798 pending_invalidation_.Clear();
99
[email protected]935ba272013-05-20 03:50:21100 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect(
101 visible_content_rect(), 1.f / contents_scale_x());
[email protected]c1079b532013-07-18 01:22:31102 if (layer_tree_host()->settings().using_synchronous_renderer_compositor) {
103 // Workaround for http://crbug.com/235910 - to retain backwards compat
104 // the full page content must always be provided in the picture layer.
105 visible_layer_rect = gfx::Rect(bounds());
106 }
[email protected]7f395142013-05-22 15:45:03107 devtools_instrumentation::ScopedLayerTask paint_layer(
108 devtools_instrumentation::kPaintLayer, id());
[email protected]49304bde2013-07-08 21:31:22109 bool updated = pile_->Update(client_,
110 SafeOpaqueBackgroundColor(),
111 contents_opaque(),
112 pile_invalidation_,
113 visible_layer_rect,
[email protected]5c6739c2013-07-15 23:33:29114 rendering_stats_instrumentation());
[email protected]49304bde2013-07-08 21:31:22115 if (!updated) {
116 // If this invalidation did not affect the pile, then it can be cleared as
117 // an optimization.
118 pile_invalidation_.Clear();
119 }
120 return updated;
[email protected]d98c0242012-11-08 06:22:35121}
122
[email protected]7aba6662013-03-12 10:17:34123void PictureLayer::SetIsMask(bool is_mask) {
[email protected]f6776532012-12-21 20:24:33124 is_mask_ = is_mask;
125}
126
[email protected]7924c1852013-05-24 16:18:43127bool PictureLayer::SupportsLCDText() const {
128 return true;
129}
130
[email protected]d98c0242012-11-08 06:22:35131} // namespace cc