OLD | NEW |
| (Empty) |
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/picture_layer.h" | |
6 | |
7 #include "cc/debug/devtools_instrumentation.h" | |
8 #include "cc/picture_layer_impl.h" | |
9 #include "cc/trees/layer_tree_impl.h" | |
10 #include "ui/gfx/rect_conversions.h" | |
11 | |
12 namespace cc { | |
13 | |
14 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | |
15 return make_scoped_refptr(new PictureLayer(client)); | |
16 } | |
17 | |
18 PictureLayer::PictureLayer(ContentLayerClient* client) : | |
19 client_(client), | |
20 pile_(make_scoped_refptr(new PicturePile())), | |
21 instrumentation_object_tracker_(id()), | |
22 is_mask_(false) { | |
23 } | |
24 | |
25 PictureLayer::~PictureLayer() { | |
26 } | |
27 | |
28 bool PictureLayer::DrawsContent() const { | |
29 return Layer::DrawsContent() && client_; | |
30 } | |
31 | |
32 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | |
33 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | |
34 } | |
35 | |
36 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | |
37 Layer::PushPropertiesTo(base_layer); | |
38 | |
39 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | |
40 layer_impl->SetIsMask(is_mask_); | |
41 layer_impl->CreateTilingSet(); | |
42 layer_impl->invalidation_.Clear(); | |
43 layer_impl->invalidation_.Swap(pile_invalidation_); | |
44 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_); | |
45 | |
46 layer_impl->SyncFromActiveLayer(); | |
47 } | |
48 | |
49 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | |
50 Layer::SetLayerTreeHost(host); | |
51 if (host) { | |
52 pile_->SetMinContentsScale(host->settings().minimumContentsScale); | |
53 pile_->SetTileGridSize(host->settings().defaultTileSize); | |
54 pile_->set_num_raster_threads(host->settings().numRasterThreads); | |
55 pile_->set_slow_down_raster_scale_factor( | |
56 host->debug_state().slowDownRasterScaleFactor); | |
57 } | |
58 } | |
59 | |
60 void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) { | |
61 gfx::Rect rect = gfx::ToEnclosedRect(layer_rect); | |
62 if (!rect.IsEmpty()) { | |
63 // Clamp invalidation to the layer bounds. | |
64 rect.Intersect(gfx::Rect(bounds())); | |
65 pending_invalidation_.Union(rect); | |
66 } | |
67 Layer::SetNeedsDisplayRect(layer_rect); | |
68 } | |
69 | |
70 void PictureLayer::Update(ResourceUpdateQueue*, | |
71 const OcclusionTracker*, | |
72 RenderingStats* stats) { | |
73 // Do not early-out of this function so that PicturePile::Update has a chance | |
74 // to record pictures due to changing visibility of this layer. | |
75 | |
76 pile_->Resize(bounds()); | |
77 | |
78 // Calling paint in WebKit can sometimes cause invalidations, so save | |
79 // off the invalidation prior to calling update. | |
80 pile_invalidation_.Swap(pending_invalidation_); | |
81 pending_invalidation_.Clear(); | |
82 | |
83 gfx::Rect visible_layer_rect = gfx::ToEnclosingRect( | |
84 gfx::ScaleRect(visible_content_rect(), 1.f / contents_scale_x())); | |
85 devtools_instrumentation::ScopedPaintLayer paint_layer(id()); | |
86 pile_->Update(client_, | |
87 background_color(), | |
88 pile_invalidation_, | |
89 visible_layer_rect, | |
90 stats); | |
91 } | |
92 | |
93 void PictureLayer::SetIsMask(bool is_mask) { | |
94 is_mask_ = is_mask; | |
95 } | |
96 | |
97 } // namespace cc | |
OLD | NEW |