blob: bc311a36c0d86e97d6f3db9b32e259ffa6695273 [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]6e84de22013-03-18 06:54:277#include "cc/debug/devtools_instrumentation.h"
[email protected]f7837a92013-08-21 03:00:058#include "cc/layers/content_layer_client.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()),
[email protected]abe51342013-10-28 22:04:3823 is_mask_(false),
24 update_source_frame_number_(-1) {
[email protected]d98c0242012-11-08 06:22:3525}
26
27PictureLayer::~PictureLayer() {
28}
29
[email protected]7aba6662013-03-12 10:17:3430bool PictureLayer::DrawsContent() const {
31 return Layer::DrawsContent() && client_;
[email protected]d98c0242012-11-08 06:22:3532}
33
[email protected]8c406cda32013-03-14 16:20:3234scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
35 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
[email protected]d98c0242012-11-08 06:22:3536}
37
[email protected]7aba6662013-03-12 10:17:3438void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
39 Layer::PushPropertiesTo(base_layer);
[email protected]3621e182012-11-09 22:37:0940 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
[email protected]23257682013-05-17 22:53:0341
[email protected]eda36f02013-10-23 08:15:3142 if (layer_impl->bounds().IsEmpty()) {
43 // Update may not get called for an empty layer, so resize here instead.
44 // Using layer_impl because either bounds() or paint_properties().bounds
45 // may disagree and either one could have been pushed to layer_impl.
[email protected]c736c1c202013-10-24 06:46:1946 pile_->Resize(gfx::Size());
[email protected]eda36f02013-10-23 08:15:3147 pile_->UpdateRecordedRegion();
[email protected]abe51342013-10-28 22:04:3848 } else if (update_source_frame_number_ ==
49 layer_tree_host()->source_frame_number()) {
50 // If update called, then pile size must match bounds pushed to impl layer.
51 DCHECK_EQ(layer_impl->bounds().ToString(), pile_->size().ToString());
[email protected]eda36f02013-10-23 08:15:3152 }
53
[email protected]f6776532012-12-21 20:24:3354 layer_impl->SetIsMask(is_mask_);
[email protected]90536172013-05-14 00:23:0655 // Unlike other properties, invalidation must always be set on layer_impl.
56 // See PictureLayerImpl::PushPropertiesTo for more details.
[email protected]f117a4c2012-12-16 04:53:1057 layer_impl->invalidation_.Clear();
[email protected]d002dd02013-03-27 07:40:4058 layer_impl->invalidation_.Swap(&pile_invalidation_);
[email protected]59460132013-06-26 20:04:0259 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get());
[email protected]3621e182012-11-09 22:37:0960}
61
[email protected]7aba6662013-03-12 10:17:3462void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
63 Layer::SetLayerTreeHost(host);
[email protected]f974be62013-02-28 19:12:2664 if (host) {
[email protected]8e0176d2013-03-21 03:14:5265 pile_->SetMinContentsScale(host->settings().minimum_contents_scale);
66 pile_->SetTileGridSize(host->settings().default_tile_size);
67 pile_->set_num_raster_threads(host->settings().num_raster_threads);
[email protected]e6ac3a72013-03-13 03:50:5368 pile_->set_slow_down_raster_scale_factor(
[email protected]846f455b2013-03-18 19:07:4169 host->debug_state().slow_down_raster_scale_factor);
[email protected]334a7722013-04-04 11:51:5870 pile_->set_show_debug_picture_borders(
71 host->debug_state().show_picture_borders);
[email protected]f974be62013-02-28 19:12:2672 }
[email protected]ce37a152013-01-08 17:12:3373}
74
[email protected]7aba6662013-03-12 10:17:3475void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) {
[email protected]3621e182012-11-09 22:37:0976 gfx::Rect rect = gfx::ToEnclosedRect(layer_rect);
[email protected]7a9fc132013-01-10 00:54:5877 if (!rect.IsEmpty()) {
78 // Clamp invalidation to the layer bounds.
79 rect.Intersect(gfx::Rect(bounds()));
80 pending_invalidation_.Union(rect);
81 }
[email protected]7aba6662013-03-12 10:17:3482 Layer::SetNeedsDisplayRect(layer_rect);
[email protected]3621e182012-11-09 22:37:0983}
84
[email protected]c50b997292013-08-03 18:44:3085bool PictureLayer::Update(ResourceUpdateQueue* queue,
86 const OcclusionTracker* occlusion) {
[email protected]fd3eec62013-01-24 19:54:0387 // Do not early-out of this function so that PicturePile::Update has a chance
88 // to record pictures due to changing visibility of this layer.
[email protected]0e630ea32012-11-28 03:29:1789
[email protected]adbe30f2013-10-11 21:12:3390 TRACE_EVENT1("cc", "PictureLayer::Update",
91 "source_frame_number",
[email protected]7445a2a2013-07-24 20:45:4592 layer_tree_host()->source_frame_number());
[email protected]5c6739c2013-07-15 23:33:2993
[email protected]abe51342013-10-28 22:04:3894 update_source_frame_number_ = layer_tree_host()->source_frame_number();
[email protected]c50b997292013-08-03 18:44:3095 bool updated = Layer::Update(queue, occlusion);
96
[email protected]445881f2013-04-16 01:11:5997 pile_->Resize(paint_properties().bounds);
[email protected]0e630ea32012-11-28 03:29:1798
99 // Calling paint in WebKit can sometimes cause invalidations, so save
100 // off the invalidation prior to calling update.
[email protected]78ad45542013-07-19 01:48:25101 pending_invalidation_.Swap(&pile_invalidation_);
[email protected]0e630ea32012-11-28 03:29:17102 pending_invalidation_.Clear();
103
[email protected]935ba272013-05-20 03:50:21104 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect(
105 visible_content_rect(), 1.f / contents_scale_x());
[email protected]c1079b532013-07-18 01:22:31106 if (layer_tree_host()->settings().using_synchronous_renderer_compositor) {
107 // Workaround for http://crbug.com/235910 - to retain backwards compat
108 // the full page content must always be provided in the picture layer.
109 visible_layer_rect = gfx::Rect(bounds());
110 }
[email protected]7f395142013-05-22 15:45:03111 devtools_instrumentation::ScopedLayerTask paint_layer(
112 devtools_instrumentation::kPaintLayer, id());
[email protected]c50b997292013-08-03 18:44:30113 updated |= pile_->Update(client_,
114 SafeOpaqueBackgroundColor(),
115 contents_opaque(),
116 pile_invalidation_,
117 visible_layer_rect,
118 rendering_stats_instrumentation());
[email protected]214c86972013-08-20 23:43:06119 if (updated) {
120 SetNeedsPushProperties();
121 } else {
[email protected]49304bde2013-07-08 21:31:22122 // If this invalidation did not affect the pile, then it can be cleared as
123 // an optimization.
124 pile_invalidation_.Clear();
125 }
[email protected]214c86972013-08-20 23:43:06126
[email protected]49304bde2013-07-08 21:31:22127 return updated;
[email protected]d98c0242012-11-08 06:22:35128}
129
[email protected]7aba6662013-03-12 10:17:34130void PictureLayer::SetIsMask(bool is_mask) {
[email protected]f6776532012-12-21 20:24:33131 is_mask_ = is_mask;
132}
133
[email protected]7924c1852013-05-24 16:18:43134bool PictureLayer::SupportsLCDText() const {
135 return true;
136}
137
[email protected]f7837a92013-08-21 03:00:05138skia::RefPtr<SkPicture> PictureLayer::GetPicture() const {
139 // We could either flatten the PicturePile into a single SkPicture,
140 // or paint a fresh one depending on what we intend to do with the
141 // picture. For now we just paint a fresh one to get consistent results.
142 if (!DrawsContent())
143 return skia::RefPtr<SkPicture>();
144
145 int width = bounds().width();
146 int height = bounds().height();
147 gfx::RectF opaque;
148
149 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
150 SkCanvas* canvas = picture->beginRecording(width, height);
151 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque);
152 picture->endRecording();
153 return picture;
154}
155
[email protected]1a55d7dc2013-10-12 07:52:20156void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
157 benchmark->RunOnLayer(this);
158}
159
[email protected]d98c0242012-11-08 06:22:35160} // namespace cc