blob: 889e2fbd3f6e3ebac325bc35895276ac759c312e [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// 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 Murdoch7dbb3d52013-07-17 14:55:54 +01007#include "cc/debug/benchmark_instrumentation.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00008#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
13namespace cc {
14
15scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
16 return make_scoped_refptr(new PictureLayer(client));
17}
18
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010019PictureLayer::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)2a99a7e2013-03-28 15:31:22 +000024}
25
26PictureLayer::~PictureLayer() {
27}
28
29bool PictureLayer::DrawsContent() const {
30 return Layer::DrawsContent() && client_;
31}
32
33scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
34 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
35}
36
37void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
38 Layer::PushPropertiesTo(base_layer);
Ben Murdochbb1529c2013-08-08 10:24:53 +010039
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000040 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
Ben Murdochbb1529c2013-08-08 10:24:53 +010041 // This should be first so others can use it.
42 layer_impl->UpdateTwinLayer();
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010043
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000044 layer_impl->SetIsMask(is_mask_);
Ben Murdochbb1529c2013-08-08 10:24:53 +010045 layer_impl->CreateTilingSetIfNeeded();
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +010046 // Unlike other properties, invalidation must always be set on layer_impl.
47 // See PictureLayerImpl::PushPropertiesTo for more details.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000048 layer_impl->invalidation_.Clear();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010049 layer_impl->invalidation_.Swap(&pile_invalidation_);
Ben Murdocheb525c52013-07-10 11:40:50 +010050 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get());
Ben Murdochbb1529c2013-08-08 10:24:53 +010051 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)2a99a7e2013-03-28 15:31:22 +000058}
59
60void 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)c2e0dbd2013-05-09 18:35:53 +010068 pile_->set_show_debug_picture_borders(
69 host->debug_state().show_picture_borders);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000070 }
71}
72
73void 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)a36e5922013-08-05 13:57:33 +010083bool PictureLayer::Update(ResourceUpdateQueue* queue,
84 const OcclusionTracker* occlusion) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000085 // 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 Murdoch7dbb3d52013-07-17 14:55:54 +010088 TRACE_EVENT1(benchmark_instrumentation::kCategory,
89 benchmark_instrumentation::kPictureLayerUpdate,
Ben Murdochbbcdd452013-07-25 10:06:34 +010090 benchmark_instrumentation::kSourceFrameNumber,
91 layer_tree_host()->source_frame_number());
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010092
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010093 bool updated = Layer::Update(queue, occlusion);
94
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010095 pile_->Resize(paint_properties().bounds);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000096
97 // Calling paint in WebKit can sometimes cause invalidations, so save
98 // off the invalidation prior to calling update.
Ben Murdochca12bfa2013-07-23 11:17:05 +010099 pending_invalidation_.Swap(&pile_invalidation_);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000100 pending_invalidation_.Clear();
101
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100102 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect(
103 visible_content_rect(), 1.f / contents_scale_x());
Ben Murdoch9ab55632013-07-18 11:57:30 +0100104 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)90dce4d2013-05-29 14:40:03 +0100109 devtools_instrumentation::ScopedLayerTask paint_layer(
110 devtools_instrumentation::kPaintLayer, id());
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100111 updated |= pile_->Update(client_,
112 SafeOpaqueBackgroundColor(),
113 contents_opaque(),
114 pile_invalidation_,
115 visible_layer_rect,
116 rendering_stats_instrumentation());
Ben Murdochbb1529c2013-08-08 10:24:53 +0100117 if (!updated) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100118 // 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)2a99a7e2013-03-28 15:31:22 +0000123}
124
125void PictureLayer::SetIsMask(bool is_mask) {
126 is_mask_ = is_mask;
127}
128
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100129bool PictureLayer::SupportsLCDText() const {
130 return true;
131}
132
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000133} // namespace cc