blob: f7d81a37bf78c1472764fbdc2f6f765533dd6449 [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]cc3cfaa2013-03-18 09:05:528#include "cc/layers/picture_layer_impl.h"
[email protected]556fd292013-03-18 08:03:049#include "cc/trees/layer_tree_impl.h"
[email protected]3621e182012-11-09 22:37:0910#include "ui/gfx/rect_conversions.h"
[email protected]d98c0242012-11-08 06:22:3511
12namespace cc {
13
[email protected]7aba6662013-03-12 10:17:3414scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
[email protected]d98c0242012-11-08 06:22:3515 return make_scoped_refptr(new PictureLayer(client));
16}
17
[email protected]bf691c22013-03-26 21:15:0618PictureLayer::PictureLayer(ContentLayerClient* client)
19 : client_(client),
20 pile_(make_scoped_refptr(new PicturePile())),
21 instrumentation_object_tracker_(id()),
22 is_mask_(false) {
[email protected]d98c0242012-11-08 06:22:3523}
24
25PictureLayer::~PictureLayer() {
26}
27
[email protected]7aba6662013-03-12 10:17:3428bool PictureLayer::DrawsContent() const {
29 return Layer::DrawsContent() && client_;
[email protected]d98c0242012-11-08 06:22:3530}
31
[email protected]8c406cda32013-03-14 16:20:3232scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
33 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
[email protected]d98c0242012-11-08 06:22:3534}
35
[email protected]7aba6662013-03-12 10:17:3436void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
37 Layer::PushPropertiesTo(base_layer);
[email protected]f117a4c2012-12-16 04:53:1038
[email protected]3621e182012-11-09 22:37:0939 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
[email protected]f6776532012-12-21 20:24:3340 layer_impl->SetIsMask(is_mask_);
[email protected]48871fc2013-01-23 07:36:5141 layer_impl->CreateTilingSet();
[email protected]f117a4c2012-12-16 04:53:1042 layer_impl->invalidation_.Clear();
[email protected]d002dd02013-03-27 07:40:4043 layer_impl->invalidation_.Swap(&pile_invalidation_);
[email protected]d7eb8c72013-03-23 22:57:1344 layer_impl->pile_ =
45 PicturePileImpl::CreateFromOther(pile_, layer_impl->is_using_lcd_text_);
[email protected]f117a4c2012-12-16 04:53:1046 layer_impl->SyncFromActiveLayer();
[email protected]3621e182012-11-09 22:37:0947}
48
[email protected]7aba6662013-03-12 10:17:3449void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
50 Layer::SetLayerTreeHost(host);
[email protected]f974be62013-02-28 19:12:2651 if (host) {
[email protected]8e0176d2013-03-21 03:14:5252 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]e6ac3a72013-03-13 03:50:5355 pile_->set_slow_down_raster_scale_factor(
[email protected]846f455b2013-03-18 19:07:4156 host->debug_state().slow_down_raster_scale_factor);
[email protected]334a7722013-04-04 11:51:5857 pile_->set_show_debug_picture_borders(
58 host->debug_state().show_picture_borders);
[email protected]f974be62013-02-28 19:12:2659 }
[email protected]ce37a152013-01-08 17:12:3360}
61
[email protected]7aba6662013-03-12 10:17:3462void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) {
[email protected]3621e182012-11-09 22:37:0963 gfx::Rect rect = gfx::ToEnclosedRect(layer_rect);
[email protected]7a9fc132013-01-10 00:54:5864 if (!rect.IsEmpty()) {
65 // Clamp invalidation to the layer bounds.
66 rect.Intersect(gfx::Rect(bounds()));
67 pending_invalidation_.Union(rect);
68 }
[email protected]7aba6662013-03-12 10:17:3469 Layer::SetNeedsDisplayRect(layer_rect);
[email protected]3621e182012-11-09 22:37:0970}
71
[email protected]7aba6662013-03-12 10:17:3472void PictureLayer::Update(ResourceUpdateQueue*,
[email protected]b3b5d0a2013-03-28 03:53:2973 const OcclusionTracker*,
74 RenderingStats* stats) {
[email protected]fd3eec62013-01-24 19:54:0375 // 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]0e630ea32012-11-28 03:29:1777
[email protected]84339432013-01-17 03:00:1178 pile_->Resize(bounds());
[email protected]0e630ea32012-11-28 03:29:1779
80 // Calling paint in WebKit can sometimes cause invalidations, so save
81 // off the invalidation prior to calling update.
[email protected]d002dd02013-03-27 07:40:4082 pile_invalidation_.Swap(&pending_invalidation_);
[email protected]0e630ea32012-11-28 03:29:1783 pending_invalidation_.Clear();
84
[email protected]fd3eec62013-01-24 19:54:0385 gfx::Rect visible_layer_rect = gfx::ToEnclosingRect(
[email protected]7aba6662013-03-12 10:17:3486 gfx::ScaleRect(visible_content_rect(), 1.f / contents_scale_x()));
[email protected]df41c042013-02-27 16:01:2987 devtools_instrumentation::ScopedPaintLayer paint_layer(id());
[email protected]43f7c3d2013-03-02 18:00:4088 pile_->Update(client_,
[email protected]7aba6662013-03-12 10:17:3489 background_color(),
[email protected]43f7c3d2013-03-02 18:00:4090 pile_invalidation_,
91 visible_layer_rect,
[email protected]b3b5d0a2013-03-28 03:53:2992 stats);
[email protected]d98c0242012-11-08 06:22:3593}
94
[email protected]7aba6662013-03-12 10:17:3495void PictureLayer::SetIsMask(bool is_mask) {
[email protected]f6776532012-12-21 20:24:3396 is_mask_ = is_mask;
97}
98
[email protected]d98c0242012-11-08 06:22:3599} // namespace cc