Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: cc/layers/picture_layer_impl.cc

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/picture_layer_impl.h" 5 #include "cc/layers/picture_layer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, 58 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer,
59 PictureLayerImpl* pending_layer) 59 PictureLayerImpl* pending_layer)
60 : active(active_layer), pending(pending_layer) { 60 : active(active_layer), pending(pending_layer) {
61 } 61 }
62 62
63 PictureLayerImpl::Pair::~Pair() { 63 PictureLayerImpl::Pair::~Pair() {
64 } 64 }
65 65
66 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) 66 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl,
67 int id,
68 bool is_mask)
67 : LayerImpl(tree_impl, id), 69 : LayerImpl(tree_impl, id),
68 twin_layer_(nullptr), 70 twin_layer_(nullptr),
71 tilings_(CreatePictureLayerTilingSet()),
72 // TODO(danakj): Can this be null to start?
69 raster_source_(PicturePileImpl::Create()), 73 raster_source_(PicturePileImpl::Create()),
70 ideal_page_scale_(0.f), 74 ideal_page_scale_(0.f),
71 ideal_device_scale_(0.f), 75 ideal_device_scale_(0.f),
72 ideal_source_scale_(0.f), 76 ideal_source_scale_(0.f),
73 ideal_contents_scale_(0.f), 77 ideal_contents_scale_(0.f),
74 raster_page_scale_(0.f), 78 raster_page_scale_(0.f),
75 raster_device_scale_(0.f), 79 raster_device_scale_(0.f),
76 raster_source_scale_(0.f), 80 raster_source_scale_(0.f),
77 raster_contents_scale_(0.f), 81 raster_contents_scale_(0.f),
78 low_res_raster_contents_scale_(0.f), 82 low_res_raster_contents_scale_(0.f),
79 raster_source_scale_is_fixed_(false), 83 raster_source_scale_is_fixed_(false),
80 was_screen_space_transform_animating_(false), 84 was_screen_space_transform_animating_(false),
81 needs_post_commit_initialization_(true), 85 needs_post_commit_initialization_(true),
82 should_update_tile_priorities_(false), 86 should_update_tile_priorities_(false),
83 only_used_low_res_last_append_quads_(false), 87 only_used_low_res_last_append_quads_(false),
84 is_mask_(false) { 88 is_mask_(is_mask),
89 nearest_neighbor_(false) {
85 layer_tree_impl()->RegisterPictureLayerImpl(this); 90 layer_tree_impl()->RegisterPictureLayerImpl(this);
86 } 91 }
87 92
88 PictureLayerImpl::~PictureLayerImpl() { 93 PictureLayerImpl::~PictureLayerImpl() {
89 if (twin_layer_) 94 if (twin_layer_)
90 twin_layer_->twin_layer_ = nullptr; 95 twin_layer_->twin_layer_ = nullptr;
91 layer_tree_impl()->UnregisterPictureLayerImpl(this); 96 layer_tree_impl()->UnregisterPictureLayerImpl(this);
92 } 97 }
93 98
94 scoped_ptr<TilingSetEvictionQueue> PictureLayerImpl::CreateEvictionQueue( 99 scoped_ptr<TilingSetEvictionQueue> PictureLayerImpl::CreateEvictionQueue(
95 TreePriority tree_priority) { 100 TreePriority tree_priority) {
96 if (!tilings_) 101 if (!tilings_)
97 return make_scoped_ptr(new TilingSetEvictionQueue()); 102 return make_scoped_ptr(new TilingSetEvictionQueue());
98 return make_scoped_ptr( 103 bool skip_shared_out_of_order_tiles =
99 new TilingSetEvictionQueue(tilings_.get(), tree_priority)); 104 GetPendingOrActiveTwinLayer() != nullptr;
105 return make_scoped_ptr(new TilingSetEvictionQueue(
106 tilings_.get(), tree_priority, skip_shared_out_of_order_tiles));
100 } 107 }
101 108
102 scoped_ptr<TilingSetRasterQueue> PictureLayerImpl::CreateRasterQueue( 109 scoped_ptr<TilingSetRasterQueue> PictureLayerImpl::CreateRasterQueue(
103 bool prioritize_low_res) { 110 bool prioritize_low_res) {
104 if (!tilings_) 111 if (!tilings_)
105 return make_scoped_ptr(new TilingSetRasterQueue()); 112 return make_scoped_ptr(new TilingSetRasterQueue());
106 return make_scoped_ptr( 113 return make_scoped_ptr(
107 new TilingSetRasterQueue(tilings_.get(), prioritize_low_res)); 114 new TilingSetRasterQueue(tilings_.get(), prioritize_low_res));
108 } 115 }
109 116
110 const char* PictureLayerImpl::LayerTypeAsString() const { 117 const char* PictureLayerImpl::LayerTypeAsString() const {
111 return "cc::PictureLayerImpl"; 118 return "cc::PictureLayerImpl";
112 } 119 }
113 120
114 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( 121 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
115 LayerTreeImpl* tree_impl) { 122 LayerTreeImpl* tree_impl) {
116 return PictureLayerImpl::Create(tree_impl, id()); 123 return PictureLayerImpl::Create(tree_impl, id(), is_mask_);
117 } 124 }
118 125
119 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { 126 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
120 // It's possible this layer was never drawn or updated (e.g. because it was 127 // It's possible this layer was never drawn or updated (e.g. because it was
121 // a descendant of an opacity 0 layer). 128 // a descendant of an opacity 0 layer).
122 DoPostCommitInitializationIfNeeded(); 129 DoPostCommitInitializationIfNeeded();
123 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 130 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
131 DCHECK_EQ(layer_impl->is_mask_, is_mask_);
124 132
125 LayerImpl::PushPropertiesTo(base_layer); 133 LayerImpl::PushPropertiesTo(base_layer);
126 134
127 // Twin relationships should never change once established. 135 // Twin relationships should never change once established.
128 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); 136 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl);
129 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); 137 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this);
130 // The twin relationship does not need to exist before the first 138 // The twin relationship does not need to exist before the first
131 // PushPropertiesTo from pending to active layer since before that the active 139 // PushPropertiesTo from pending to active layer since before that the active
132 // layer can not have a pile or tilings, it has only been created and inserted 140 // layer can not have a pile or tilings, it has only been created and inserted
133 // into the tree at that point. 141 // into the tree at that point.
134 twin_layer_ = layer_impl; 142 twin_layer_ = layer_impl;
135 layer_impl->twin_layer_ = this; 143 layer_impl->twin_layer_ = this;
136 144
137 layer_impl->set_is_mask(is_mask_); 145 layer_impl->SetNearestNeighbor(nearest_neighbor_);
138 layer_impl->UpdateRasterSource(raster_source_);
139 146
147 // Solid color layers have no tilings.
140 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); 148 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0);
141 // Tilings would be expensive to push, so we swap. 149 // The pending tree should only have a high res (and possibly low res) tiling.
142 layer_impl->tilings_.swap(tilings_); 150 DCHECK_LE(tilings_->num_tilings(),
143 layer_impl->tilings_->SetClient(layer_impl); 151 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
144 if (tilings_)
145 tilings_->SetClient(this);
146 152
147 // Ensure that the recycle tree doesn't have any unshared tiles. 153 layer_impl->UpdateRasterSource(raster_source_, &invalidation_,
148 if (tilings_ && raster_source_->IsSolidColor()) 154 tilings_.get());
149 tilings_->RemoveAllTilings(); 155 DCHECK(invalidation_.IsEmpty());
150 156
151 // Remove invalidated tiles from what will become a recycle tree. 157 // After syncing a solid color layer, the active layer has no tilings.
152 if (tilings_) 158 DCHECK_IMPLIES(raster_source_->IsSolidColor(),
153 tilings_->RemoveTilesInRegion(invalidation_); 159 layer_impl->tilings_->num_tilings() == 0);
154 160
155 layer_impl->raster_page_scale_ = raster_page_scale_; 161 layer_impl->raster_page_scale_ = raster_page_scale_;
156 layer_impl->raster_device_scale_ = raster_device_scale_; 162 layer_impl->raster_device_scale_ = raster_device_scale_;
157 layer_impl->raster_source_scale_ = raster_source_scale_; 163 layer_impl->raster_source_scale_ = raster_source_scale_;
158 layer_impl->raster_contents_scale_ = raster_contents_scale_; 164 layer_impl->raster_contents_scale_ = raster_contents_scale_;
159 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; 165 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_;
166
167 layer_impl->SanityCheckTilingState();
168
160 layer_impl->needs_post_commit_initialization_ = false; 169 layer_impl->needs_post_commit_initialization_ = false;
161
162 // The invalidation on this soon-to-be-recycled layer must be cleared to
163 // mirror clearing the invalidation in PictureLayer's version of this function
164 // in case push properties is skipped.
165 layer_impl->invalidation_.Swap(&invalidation_);
166 invalidation_.Clear();
167 needs_post_commit_initialization_ = true; 170 needs_post_commit_initialization_ = true;
168 171
169 // We always need to push properties. 172 // We always need to push properties.
170 // See http://crbug.com/303943 173 // See http://crbug.com/303943
174 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
171 needs_push_properties_ = true; 175 needs_push_properties_ = true;
172 } 176 }
173 177
174 void PictureLayerImpl::UpdateRasterSource(
175 scoped_refptr<RasterSource> raster_source) {
176 bool could_have_tilings = CanHaveTilings();
177 raster_source_.swap(raster_source);
178
179 // Need to call UpdateTiles again if CanHaveTilings changed.
180 if (could_have_tilings != CanHaveTilings()) {
181 layer_tree_impl()->set_needs_update_draw_properties();
182 }
183 }
184
185 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, 178 void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
186 const Occlusion& occlusion_in_content_space, 179 const Occlusion& occlusion_in_content_space,
187 AppendQuadsData* append_quads_data) { 180 AppendQuadsData* append_quads_data) {
188 DCHECK(!needs_post_commit_initialization_); 181 DCHECK(!needs_post_commit_initialization_);
189 // The bounds and the pile size may differ if the pile wasn't updated (ie. 182 // The bounds and the pile size may differ if the pile wasn't updated (ie.
190 // PictureLayer::Update didn't happen). In that case the pile will be empty. 183 // PictureLayer::Update didn't happen). In that case the pile will be empty.
191 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), 184 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(),
192 bounds() == raster_source_->GetSize()) 185 bounds() == raster_source_->GetSize())
193 << " bounds " << bounds().ToString() << " pile " 186 << " bounds " << bounds().ToString() << " pile "
194 << raster_source_->GetSize().ToString(); 187 << raster_source_->GetSize().ToString();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (visible_geometry_rect.IsEmpty()) 237 if (visible_geometry_rect.IsEmpty())
245 return; 238 return;
246 239
247 gfx::Size texture_size = scaled_visible_content_rect.size(); 240 gfx::Size texture_size = scaled_visible_content_rect.size();
248 gfx::RectF texture_rect = gfx::RectF(texture_size); 241 gfx::RectF texture_rect = gfx::RectF(texture_size);
249 gfx::Rect quad_content_rect = scaled_visible_content_rect; 242 gfx::Rect quad_content_rect = scaled_visible_content_rect;
250 243
251 PictureDrawQuad* quad = 244 PictureDrawQuad* quad =
252 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>(); 245 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
253 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, 246 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect,
254 visible_geometry_rect, texture_rect, texture_size, RGBA_8888, 247 visible_geometry_rect, texture_rect, texture_size,
255 quad_content_rect, max_contents_scale, raster_source_); 248 nearest_neighbor_, RGBA_8888, quad_content_rect,
249 max_contents_scale, raster_source_);
256 return; 250 return;
257 } 251 }
258 252
259 AppendDebugBorderQuad( 253 AppendDebugBorderQuad(
260 render_pass, scaled_content_bounds, shared_quad_state, append_quads_data); 254 render_pass, scaled_content_bounds, shared_quad_state, append_quads_data);
261 255
262 if (ShowDebugBorders()) { 256 if (ShowDebugBorders()) {
263 for (PictureLayerTilingSet::CoverageIterator iter( 257 for (PictureLayerTilingSet::CoverageIterator iter(
264 tilings_.get(), 258 tilings_.get(),
265 max_contents_scale, 259 max_contents_scale,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 351
358 TileDrawQuad* quad = 352 TileDrawQuad* quad =
359 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); 353 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
360 quad->SetNew(shared_quad_state, 354 quad->SetNew(shared_quad_state,
361 geometry_rect, 355 geometry_rect,
362 opaque_rect, 356 opaque_rect,
363 visible_geometry_rect, 357 visible_geometry_rect,
364 draw_info.get_resource_id(), 358 draw_info.get_resource_id(),
365 texture_rect, 359 texture_rect,
366 iter.texture_size(), 360 iter.texture_size(),
367 draw_info.contents_swizzled()); 361 draw_info.contents_swizzled(),
362 nearest_neighbor_);
368 has_draw_quad = true; 363 has_draw_quad = true;
369 break; 364 break;
370 } 365 }
371 case ManagedTileState::DrawInfo::PICTURE_PILE_MODE: { 366 case ManagedTileState::DrawInfo::PICTURE_PILE_MODE: {
372 if (!layer_tree_impl() 367 if (!layer_tree_impl()
373 ->GetRendererCapabilities() 368 ->GetRendererCapabilities()
374 .allow_rasterize_on_demand) { 369 .allow_rasterize_on_demand) {
375 ++on_demand_missing_tile_count; 370 ++on_demand_missing_tile_count;
376 break; 371 break;
377 } 372 }
378 373
379 gfx::RectF texture_rect = iter.texture_rect(); 374 gfx::RectF texture_rect = iter.texture_rect();
380 375
381 ResourceProvider* resource_provider = 376 ResourceProvider* resource_provider =
382 layer_tree_impl()->resource_provider(); 377 layer_tree_impl()->resource_provider();
383 ResourceFormat format = 378 ResourceFormat format =
384 resource_provider->memory_efficient_texture_format(); 379 resource_provider->memory_efficient_texture_format();
385 PictureDrawQuad* quad = 380 PictureDrawQuad* quad =
386 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>(); 381 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
387 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, 382 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect,
388 visible_geometry_rect, texture_rect, iter.texture_size(), 383 visible_geometry_rect, texture_rect, iter.texture_size(),
389 format, iter->content_rect(), iter->contents_scale(), 384 nearest_neighbor_, format, iter->content_rect(),
390 raster_source_); 385 iter->contents_scale(), raster_source_);
391 has_draw_quad = true; 386 has_draw_quad = true;
392 break; 387 break;
393 } 388 }
394 case ManagedTileState::DrawInfo::SOLID_COLOR_MODE: { 389 case ManagedTileState::DrawInfo::SOLID_COLOR_MODE: {
395 SolidColorDrawQuad* quad = 390 SolidColorDrawQuad* quad =
396 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); 391 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
397 quad->SetNew(shared_quad_state, 392 quad->SetNew(shared_quad_state,
398 geometry_rect, 393 geometry_rect,
399 visible_geometry_rect, 394 visible_geometry_rect,
400 draw_info.get_solid_color(), 395 draw_info.get_solid_color(),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 ideal_page_scale_ = 0.f; 473 ideal_page_scale_ = 0.f;
479 ideal_device_scale_ = 0.f; 474 ideal_device_scale_ = 0.f;
480 ideal_contents_scale_ = 0.f; 475 ideal_contents_scale_ = 0.f;
481 ideal_source_scale_ = 0.f; 476 ideal_source_scale_ = 0.f;
482 SanityCheckTilingState(); 477 SanityCheckTilingState();
483 return; 478 return;
484 } 479 }
485 480
486 UpdateIdealScales(); 481 UpdateIdealScales();
487 482
488 DCHECK_IMPLIES(tilings_->num_tilings() == 0, raster_contents_scale_ == 0.f)
489 << "A layer with no tilings shouldn't have valid raster scales";
490 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { 483 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) {
491 RecalculateRasterScales(); 484 RecalculateRasterScales();
492 AddTilingsForRasterScale(); 485 AddTilingsForRasterScale();
493 } 486 }
494 487
495 DCHECK(raster_page_scale_); 488 DCHECK(raster_page_scale_);
496 DCHECK(raster_device_scale_); 489 DCHECK(raster_device_scale_);
497 DCHECK(raster_source_scale_); 490 DCHECK(raster_source_scale_);
498 DCHECK(raster_contents_scale_); 491 DCHECK(raster_contents_scale_);
499 DCHECK(low_res_raster_contents_scale_); 492 DCHECK(low_res_raster_contents_scale_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return nullptr; 567 return nullptr;
575 return twin_layer_; 568 return twin_layer_;
576 } 569 }
577 570
578 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { 571 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const {
579 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) 572 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree())
580 return nullptr; 573 return nullptr;
581 return twin_layer_; 574 return twin_layer_;
582 } 575 }
583 576
577 void PictureLayerImpl::UpdateRasterSource(
578 scoped_refptr<RasterSource> raster_source,
579 Region* new_invalidation,
580 const PictureLayerTilingSet* pending_set) {
581 // The bounds and the pile size may differ if the pile wasn't updated (ie.
582 // PictureLayer::Update didn't happen). In that case the pile will be empty.
583 DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(),
584 bounds() == raster_source->GetSize())
585 << " bounds " << bounds().ToString() << " pile "
586 << raster_source->GetSize().ToString();
587
588 bool could_have_tilings = CanHaveTilings();
589 raster_source_.swap(raster_source);
590
591 // The |new_invalidation| must be cleared before updating tilings since they
592 // access the invalidation through the PictureLayerTilingClient interface.
593 invalidation_.Clear();
594 invalidation_.Swap(new_invalidation);
595
596 bool can_have_tilings = CanHaveTilings();
597
598 // Need to call UpdateTiles again if CanHaveTilings changed.
599 if (could_have_tilings != can_have_tilings)
600 layer_tree_impl()->set_needs_update_draw_properties();
601
602 if (!can_have_tilings) {
603 RemoveAllTilings();
604 return;
605 }
606
607 // We could do this after doing UpdateTiles, which would avoid doing this for
608 // tilings that are going to disappear on the pending tree (if scale changed).
609 // But that would also be more complicated, so we just do it here for now.
610 tilings_->UpdateTilingsToCurrentRasterSource(
611 raster_source_.get(), pending_set, raster_source_->GetSize(),
612 invalidation_, MinimumContentsScale());
613 }
614
584 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { 615 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) {
585 if (layer_tree_impl()->IsActiveTree()) { 616 if (layer_tree_impl()->IsActiveTree()) {
586 gfx::RectF layer_damage_rect = 617 gfx::RectF layer_damage_rect =
587 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); 618 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale());
588 AddDamageRect(layer_damage_rect); 619 AddDamageRect(layer_damage_rect);
589 } 620 }
590 } 621 }
591 622
592 void PictureLayerImpl::DidBecomeActive() { 623 void PictureLayerImpl::DidBecomeActive() {
593 LayerImpl::DidBecomeActive(); 624 LayerImpl::DidBecomeActive();
594 // TODO(vmpstr): See if this can be removed in favour of calling it from LTHI 625 // TODO(vmpstr): See if this can be removed in favour of calling it from LTHI
595 layer_tree_impl()->DidModifyTilePriorities(); 626 layer_tree_impl()->DidModifyTilePriorities();
596 } 627 }
597 628
598 void PictureLayerImpl::DidBeginTracing() { 629 void PictureLayerImpl::DidBeginTracing() {
599 raster_source_->DidBeginTracing(); 630 raster_source_->DidBeginTracing();
600 } 631 }
601 632
602 void PictureLayerImpl::ReleaseResources() { 633 void PictureLayerImpl::ReleaseResources() {
634 // Recreate tilings with new settings, since some of those might change when
635 // we release resources. If tilings_ is null, then leave it as null.
603 if (tilings_) 636 if (tilings_)
604 RemoveAllTilings(); 637 tilings_ = CreatePictureLayerTilingSet();
605
606 ResetRasterScale(); 638 ResetRasterScale();
607 639
608 // To avoid an edge case after lost context where the tree is up to date but 640 // To avoid an edge case after lost context where the tree is up to date but
609 // the tilings have not been managed, request an update draw properties 641 // the tilings have not been managed, request an update draw properties
610 // to force tilings to get managed. 642 // to force tilings to get managed.
611 layer_tree_impl()->set_needs_update_draw_properties(); 643 layer_tree_impl()->set_needs_update_draw_properties();
612 } 644 }
613 645
614 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { 646 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() {
615 return raster_source_->GetFlattenedPicture(); 647 return raster_source_->GetFlattenedPicture();
(...skipping 14 matching lines...) Expand all
630 662
631 return layer_tree_impl()->tile_manager()->CreateTile( 663 return layer_tree_impl()->tile_manager()->CreateTile(
632 raster_source_.get(), content_rect.size(), content_rect, 664 raster_source_.get(), content_rect.size(), content_rect,
633 tiling->contents_scale(), id(), layer_tree_impl()->source_frame_number(), 665 tiling->contents_scale(), id(), layer_tree_impl()->source_frame_number(),
634 flags); 666 flags);
635 } 667 }
636 668
637 const Region* PictureLayerImpl::GetPendingInvalidation() { 669 const Region* PictureLayerImpl::GetPendingInvalidation() {
638 if (layer_tree_impl()->IsPendingTree()) 670 if (layer_tree_impl()->IsPendingTree())
639 return &invalidation_; 671 return &invalidation_;
672 if (layer_tree_impl()->IsRecycleTree())
673 return nullptr;
640 DCHECK(layer_tree_impl()->IsActiveTree()); 674 DCHECK(layer_tree_impl()->IsActiveTree());
641 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) 675 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer())
642 return &twin_layer->invalidation_; 676 return &twin_layer->invalidation_;
643 return nullptr; 677 return nullptr;
644 } 678 }
645 679
646 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( 680 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling(
647 const PictureLayerTiling* tiling) const { 681 const PictureLayerTiling* tiling) const {
648 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); 682 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
649 if (!twin_layer) 683 if (!twin_layer)
650 return nullptr; 684 return nullptr;
651 // TODO(danakj): Remove this when no longer swapping tilings.
652 if (!twin_layer->tilings_)
653 return nullptr;
654 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale()); 685 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale());
655 } 686 }
656 687
657 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( 688 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling(
658 const PictureLayerTiling* tiling) { 689 const PictureLayerTiling* tiling) {
659 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); 690 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer();
660 if (!recycled_twin || !recycled_twin->tilings_) 691 if (!recycled_twin || !recycled_twin->tilings_)
661 return nullptr; 692 return nullptr;
662 return recycled_twin->tilings_->FindTilingWithScale(tiling->contents_scale()); 693 return recycled_twin->tilings_->FindTilingWithScale(tiling->contents_scale());
663 } 694 }
664 695
665 TilePriority::PriorityBin PictureLayerImpl::GetMaxTilePriorityBin() const { 696 TilePriority::PriorityBin PictureLayerImpl::GetMaxTilePriorityBin() const {
666 if (!HasValidTilePriorities()) 697 if (!HasValidTilePriorities())
667 return TilePriority::EVENTUALLY; 698 return TilePriority::EVENTUALLY;
668 return TilePriority::NOW; 699 return TilePriority::NOW;
669 } 700 }
670 701
671 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const {
672 return layer_tree_impl()->settings().max_tiles_for_interest_area;
673 }
674
675 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const {
676 return layer_tree_impl()->use_gpu_rasterization()
677 ? 0.f
678 : layer_tree_impl()->settings().skewport_target_time_in_seconds;
679 }
680
681 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const {
682 return layer_tree_impl()
683 ->settings()
684 .skewport_extrapolation_limit_in_content_pixels;
685 }
686
687 bool PictureLayerImpl::RequiresHighResToDraw() const { 702 bool PictureLayerImpl::RequiresHighResToDraw() const {
688 return layer_tree_impl()->RequiresHighResToDraw(); 703 return layer_tree_impl()->RequiresHighResToDraw();
689 } 704 }
690 705
691 gfx::Size PictureLayerImpl::CalculateTileSize( 706 gfx::Size PictureLayerImpl::CalculateTileSize(
692 const gfx::Size& content_bounds) const { 707 const gfx::Size& content_bounds) const {
693 int max_texture_size = 708 int max_texture_size =
694 layer_tree_impl()->resource_provider()->max_texture_size(); 709 layer_tree_impl()->resource_provider()->max_texture_size();
695 710
696 if (is_mask_) { 711 if (is_mask_) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 tile_height = RoundUp(tile_height, kTileRoundUp); 773 tile_height = RoundUp(tile_height, kTileRoundUp);
759 tile_height = std::min(tile_height, default_tile_height); 774 tile_height = std::min(tile_height, default_tile_height);
760 } 775 }
761 776
762 // Under no circumstance should we be larger than the max texture size. 777 // Under no circumstance should we be larger than the max texture size.
763 tile_width = std::min(tile_width, max_texture_size); 778 tile_width = std::min(tile_width, max_texture_size);
764 tile_height = std::min(tile_height, max_texture_size); 779 tile_height = std::min(tile_height, max_texture_size);
765 return gfx::Size(tile_width, tile_height); 780 return gfx::Size(tile_width, tile_height);
766 } 781 }
767 782
768 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) {
769 DCHECK(!other->needs_post_commit_initialization_);
770 DCHECK(other->tilings_);
771
772 if (!DrawsContent()) {
773 RemoveAllTilings();
774 return;
775 }
776
777 raster_page_scale_ = other->raster_page_scale_;
778 raster_device_scale_ = other->raster_device_scale_;
779 raster_source_scale_ = other->raster_source_scale_;
780 raster_contents_scale_ = other->raster_contents_scale_;
781 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_;
782
783 bool synced_high_res_tiling = false;
784 if (CanHaveTilings()) {
785 synced_high_res_tiling = tilings_->SyncTilings(
786 *other->tilings_, raster_source_->GetSize(), invalidation_,
787 MinimumContentsScale(), raster_source_.get());
788 } else {
789 RemoveAllTilings();
790 }
791
792 // If our MinimumContentsScale has changed to prevent the twin's high res
793 // tiling from being synced, we should reset the raster scale and let it be
794 // recalculated (1) again. This can happen if our bounds shrink to the point
795 // where min contents scale grows.
796 // (1) - TODO(vmpstr) Instead of hoping that this will be recalculated, we
797 // should refactor this code a little bit and actually recalculate this.
798 // However, this is a larger undertaking, so this will work for now.
799 if (!synced_high_res_tiling)
800 ResetRasterScale();
801 else
802 SanityCheckTilingState();
803 }
804
805 void PictureLayerImpl::SyncTiling(
806 const PictureLayerTiling* tiling) {
807 if (!tilings_)
808 return;
809 if (!CanHaveTilingWithScale(tiling->contents_scale()))
810 return;
811 tilings_->AddTiling(tiling->contents_scale(), raster_source_->GetSize());
812
813 // If this tree needs update draw properties, then the tiling will
814 // get updated prior to drawing or activation. If this tree does not
815 // need update draw properties, then its transforms are up to date and
816 // we can create tiles for this tiling immediately.
817 if (!layer_tree_impl()->needs_update_draw_properties() &&
818 should_update_tile_priorities_) {
819 // TODO(danakj): Add a DCHECK() that we are not using occlusion tracking
820 // when we stop using the pending tree in the browser compositor. If we want
821 // to support occlusion tracking here, we need to dirty the draw properties
822 // or save occlusion as a draw property.
823 UpdateTilePriorities(Occlusion());
824 }
825 }
826
827 void PictureLayerImpl::GetContentsResourceId( 783 void PictureLayerImpl::GetContentsResourceId(
828 ResourceProvider::ResourceId* resource_id, 784 ResourceProvider::ResourceId* resource_id,
829 gfx::Size* resource_size) const { 785 gfx::Size* resource_size) const {
830 DCHECK_EQ(bounds().ToString(), raster_source_->GetSize().ToString()); 786 // The bounds and the pile size may differ if the pile wasn't updated (ie.
787 // PictureLayer::Update didn't happen). In that case the pile will be empty.
788 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(),
789 bounds() == raster_source_->GetSize())
790 << " bounds " << bounds().ToString() << " pile "
791 << raster_source_->GetSize().ToString();
831 gfx::Rect content_rect(bounds()); 792 gfx::Rect content_rect(bounds());
832 PictureLayerTilingSet::CoverageIterator iter( 793 PictureLayerTilingSet::CoverageIterator iter(
833 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); 794 tilings_.get(), 1.f, content_rect, ideal_contents_scale_);
834 795
835 // Mask resource not ready yet. 796 // Mask resource not ready yet.
836 if (!iter || !*iter) { 797 if (!iter || !*iter) {
837 *resource_id = 0; 798 *resource_id = 0;
838 return; 799 return;
839 } 800 }
840 801
841 // Masks only supported if they fit on exactly one tile. 802 // Masks only supported if they fit on exactly one tile.
842 DCHECK(iter.geometry_rect() == content_rect) 803 DCHECK(iter.geometry_rect() == content_rect)
843 << "iter rect " << iter.geometry_rect().ToString() << " content rect " 804 << "iter rect " << iter.geometry_rect().ToString() << " content rect "
844 << content_rect.ToString(); 805 << content_rect.ToString();
845 806
846 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); 807 const ManagedTileState::DrawInfo& draw_info = iter->draw_info();
847 if (!draw_info.IsReadyToDraw() || 808 if (!draw_info.IsReadyToDraw() ||
848 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) { 809 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) {
849 *resource_id = 0; 810 *resource_id = 0;
850 return; 811 return;
851 } 812 }
852 813
853 *resource_id = draw_info.get_resource_id(); 814 *resource_id = draw_info.get_resource_id();
854 *resource_size = iter.texture_size(); 815 *resource_size = iter.texture_size();
855 } 816 }
856 817
818 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) {
819 if (nearest_neighbor_ == nearest_neighbor)
820 return;
821
822 nearest_neighbor_ = nearest_neighbor;
823 NoteLayerPropertyChanged();
824 }
825
857 void PictureLayerImpl::DoPostCommitInitialization() { 826 void PictureLayerImpl::DoPostCommitInitialization() {
827 // TODO(danakj): Remove this.
858 DCHECK(needs_post_commit_initialization_); 828 DCHECK(needs_post_commit_initialization_);
859 DCHECK(layer_tree_impl()->IsPendingTree()); 829 DCHECK(layer_tree_impl()->IsPendingTree());
860
861 if (!tilings_)
862 tilings_ = PictureLayerTilingSet::Create(this);
863
864 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
865 if (twin_layer) {
866 // If the twin has never been pushed to, do not sync from it.
867 // This can happen if this function is called during activation.
868 if (!twin_layer->needs_post_commit_initialization_)
869 SyncFromActiveLayer(twin_layer);
870 }
871
872 needs_post_commit_initialization_ = false; 830 needs_post_commit_initialization_ = false;
873 } 831 }
874 832
875 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 833 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
876 DCHECK(CanHaveTilingWithScale(contents_scale)) << 834 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
877 "contents_scale: " << contents_scale; 835 "contents_scale: " << contents_scale;
878 836
879 PictureLayerTiling* tiling = 837 PictureLayerTiling* tiling =
880 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); 838 tilings_->AddTiling(contents_scale, raster_source_->GetSize());
881 839
882 DCHECK(raster_source_->HasRecordings()); 840 DCHECK(raster_source_->HasRecordings());
883 841
884 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer())
885 twin_layer->SyncTiling(tiling);
886
887 return tiling; 842 return tiling;
888 } 843 }
889 844
890 void PictureLayerImpl::RemoveAllTilings() { 845 void PictureLayerImpl::RemoveAllTilings() {
891 if (tilings_) 846 if (tilings_)
892 tilings_->RemoveAllTilings(); 847 tilings_->RemoveAllTilings();
893 // If there are no tilings, then raster scales are no longer meaningful. 848 // If there are no tilings, then raster scales are no longer meaningful.
894 ResetRasterScale(); 849 ResetRasterScale();
895 } 850 }
896 851
(...skipping 25 matching lines...) Expand all
922 if (can_have_low_res && needs_low_res && !is_pinching && !is_animating) 877 if (can_have_low_res && needs_low_res && !is_pinching && !is_animating)
923 low_res = AddTiling(low_res_raster_contents_scale_); 878 low_res = AddTiling(low_res_raster_contents_scale_);
924 879
925 // Set low-res if we have one. 880 // Set low-res if we have one.
926 if (low_res && low_res != high_res) 881 if (low_res && low_res != high_res)
927 low_res->set_resolution(LOW_RESOLUTION); 882 low_res->set_resolution(LOW_RESOLUTION);
928 883
929 // Make sure we always have one high-res (even if high == low). 884 // Make sure we always have one high-res (even if high == low).
930 high_res->set_resolution(HIGH_RESOLUTION); 885 high_res->set_resolution(HIGH_RESOLUTION);
931 886
887 if (layer_tree_impl()->IsPendingTree()) {
888 // On the pending tree, drop any tilings that are non-ideal since we don't
889 // need them to activate anyway.
890 tilings_->RemoveNonIdealTilings();
891 }
892
932 SanityCheckTilingState(); 893 SanityCheckTilingState();
933 } 894 }
934 895
935 bool PictureLayerImpl::ShouldAdjustRasterScale() const { 896 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
936 if (was_screen_space_transform_animating_ != 897 if (was_screen_space_transform_animating_ !=
937 draw_properties().screen_space_transform_is_animating) 898 draw_properties().screen_space_transform_is_animating)
938 return true; 899 return true;
939 900
940 if (draw_properties().screen_space_transform_is_animating && 901 if (draw_properties().screen_space_transform_is_animating &&
941 raster_contents_scale_ != ideal_contents_scale_ && 902 raster_contents_scale_ != ideal_contents_scale_ &&
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; 1067 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr;
1107 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); 1068 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer();
1108 PictureLayerTilingSet* recycled_twin_set = 1069 PictureLayerTilingSet* recycled_twin_set =
1109 recycled_twin ? recycled_twin->tilings_.get() : nullptr; 1070 recycled_twin ? recycled_twin->tilings_.get() : nullptr;
1110 1071
1111 tilings_->CleanUpTilings(min_acceptable_high_res_scale, 1072 tilings_->CleanUpTilings(min_acceptable_high_res_scale,
1112 max_acceptable_high_res_scale, used_tilings, 1073 max_acceptable_high_res_scale, used_tilings,
1113 layer_tree_impl()->create_low_res_tiling(), twin_set, 1074 layer_tree_impl()->create_low_res_tiling(), twin_set,
1114 recycled_twin_set); 1075 recycled_twin_set);
1115 1076
1116 if (twin_set && twin_set->num_tilings() == 0)
1117 twin->ResetRasterScale();
1118
1119 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) 1077 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0)
1120 recycled_twin->ResetRasterScale(); 1078 recycled_twin->ResetRasterScale();
1121 1079
1122 DCHECK_GT(tilings_->num_tilings(), 0u); 1080 DCHECK_GT(tilings_->num_tilings(), 0u);
1123 SanityCheckTilingState(); 1081 SanityCheckTilingState();
1124 } 1082 }
1125 1083
1126 float PictureLayerImpl::MinimumContentsScale() const { 1084 float PictureLayerImpl::MinimumContentsScale() const {
1127 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; 1085 float setting_min = layer_tree_impl()->settings().minimum_contents_scale;
1128 1086
(...skipping 22 matching lines...) Expand all
1151 should_update_tile_priorities_ = false; 1109 should_update_tile_priorities_ = false;
1152 } 1110 }
1153 1111
1154 bool PictureLayerImpl::CanHaveTilings() const { 1112 bool PictureLayerImpl::CanHaveTilings() const {
1155 if (raster_source_->IsSolidColor()) 1113 if (raster_source_->IsSolidColor())
1156 return false; 1114 return false;
1157 if (!DrawsContent()) 1115 if (!DrawsContent())
1158 return false; 1116 return false;
1159 if (!raster_source_->HasRecordings()) 1117 if (!raster_source_->HasRecordings())
1160 return false; 1118 return false;
1119 // If the |raster_source_| has a recording it should have non-empty bounds.
1120 DCHECK(!raster_source_->GetSize().IsEmpty());
1161 return true; 1121 return true;
1162 } 1122 }
1163 1123
1164 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { 1124 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const {
1165 if (!CanHaveTilings()) 1125 if (!CanHaveTilings())
1166 return false; 1126 return false;
1167 if (contents_scale < MinimumContentsScale()) 1127 if (contents_scale < MinimumContentsScale())
1168 return false; 1128 return false;
1169 return true; 1129 return true;
1170 } 1130 }
(...skipping 18 matching lines...) Expand all
1189 1149
1190 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const { 1150 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1191 return layer_tree_impl()->use_gpu_rasterization(); 1151 return layer_tree_impl()->use_gpu_rasterization();
1192 } 1152 }
1193 1153
1194 float PictureLayerImpl::MaximumTilingContentsScale() const { 1154 float PictureLayerImpl::MaximumTilingContentsScale() const {
1195 float max_contents_scale = tilings_->GetMaximumContentsScale(); 1155 float max_contents_scale = tilings_->GetMaximumContentsScale();
1196 return std::max(max_contents_scale, MinimumContentsScale()); 1156 return std::max(max_contents_scale, MinimumContentsScale());
1197 } 1157 }
1198 1158
1159 scoped_ptr<PictureLayerTilingSet>
1160 PictureLayerImpl::CreatePictureLayerTilingSet() {
1161 const LayerTreeSettings& settings = layer_tree_impl()->settings();
1162 return PictureLayerTilingSet::Create(
1163 this, settings.max_tiles_for_interest_area,
1164 layer_tree_impl()->use_gpu_rasterization()
1165 ? 0.f
1166 : settings.skewport_target_time_in_seconds,
1167 settings.skewport_extrapolation_limit_in_content_pixels);
1168 }
1169
1199 void PictureLayerImpl::UpdateIdealScales() { 1170 void PictureLayerImpl::UpdateIdealScales() {
1200 DCHECK(CanHaveTilings()); 1171 DCHECK(CanHaveTilings());
1201 1172
1202 float min_contents_scale = MinimumContentsScale(); 1173 float min_contents_scale = MinimumContentsScale();
1203 DCHECK_GT(min_contents_scale, 0.f); 1174 DCHECK_GT(min_contents_scale, 0.f);
1204 float min_page_scale = layer_tree_impl()->min_page_scale_factor(); 1175 float min_page_scale = layer_tree_impl()->min_page_scale_factor();
1205 DCHECK_GT(min_page_scale, 0.f); 1176 DCHECK_GT(min_page_scale, 0.f);
1206 float min_device_scale = 1.f; 1177 float min_device_scale = 1.f;
1207 float min_source_scale = 1178 float min_source_scale =
1208 min_contents_scale / min_page_scale / min_device_scale; 1179 min_contents_scale / min_page_scale / min_device_scale;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 1326
1356 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { 1327 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const {
1357 if (!layer_tree_impl()->IsActiveTree()) 1328 if (!layer_tree_impl()->IsActiveTree())
1358 return true; 1329 return true;
1359 1330
1360 return AllTilesRequiredAreReadyToDraw( 1331 return AllTilesRequiredAreReadyToDraw(
1361 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); 1332 &PictureLayerTiling::IsTileRequiredForDrawIfVisible);
1362 } 1333 }
1363 1334
1364 } // namespace cc 1335 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698