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.
5 #include "cc/layers/picture_layer_impl.h"
10 #include "base/time/time.h"
11 #include "cc/base/math_util.h"
12 #include "cc/base/util.h"
13 #include "cc/debug/debug_colors.h"
14 #include "cc/debug/micro_benchmark_impl.h"
15 #include "cc/debug/traced_value.h"
16 #include "cc/layers/append_quads_data.h"
17 #include "cc/layers/quad_sink.h"
18 #include "cc/quads/checkerboard_draw_quad.h"
19 #include "cc/quads/debug_border_draw_quad.h"
20 #include "cc/quads/picture_draw_quad.h"
21 #include "cc/quads/solid_color_draw_quad.h"
22 #include "cc/quads/tile_draw_quad.h"
23 #include "cc/resources/tile_manager.h"
24 #include "cc/trees/layer_tree_impl.h"
25 #include "ui/gfx/quad_f.h"
26 #include "ui/gfx/rect_conversions.h"
27 #include "ui/gfx/size_conversions.h"
30 const float kMaxScaleRatioDuringPinch = 2.0f;
32 // When creating a new tiling during pinch, snap to an existing
33 // tiling's scale if the desired scale is within this ratio.
34 const float kSnapToExistingTilingRatio = 0.2f;
39 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id)
40 : LayerImpl(tree_impl, id),
42 pile_(PicturePileImpl::Create()),
44 ideal_page_scale_(0.f),
45 ideal_device_scale_(0.f),
46 ideal_source_scale_(0.f),
47 ideal_contents_scale_(0.f),
48 raster_page_scale_(0.f),
49 raster_device_scale_(0.f),
50 raster_source_scale_(0.f),
51 raster_contents_scale_(0.f),
52 low_res_raster_contents_scale_(0.f),
53 raster_source_scale_was_animating_(false),
54 is_using_lcd_text_(tree_impl->settings().can_use_lcd_text),
55 needs_post_commit_initialization_(true),
56 should_update_tile_priorities_(false),
57 has_gpu_rasterization_hint_(false),
58 should_use_low_res_tiling_(tree_impl->settings().create_low_res_tiling),
59 layer_needs_to_register_itself_(true) {}
61 PictureLayerImpl::~PictureLayerImpl() {
62 if (!layer_needs_to_register_itself_)
63 layer_tree_impl()->tile_manager()->UnregisterPictureLayerImpl(this);
66 const char* PictureLayerImpl::LayerTypeAsString() const {
67 return "cc::PictureLayerImpl";
70 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
71 LayerTreeImpl* tree_impl) {
72 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
75 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
76 // It's possible this layer was never drawn or updated (e.g. because it was
77 // a descendant of an opacity 0 layer).
78 DoPostCommitInitializationIfNeeded();
79 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
81 // We have already synced the important bits from the the active layer, and
82 // we will soon swap out its tilings and use them for recycling. However,
83 // there are now tiles in this layer's tilings that were unref'd and replaced
84 // with new tiles (due to invalidation). This resets all active priorities on
85 // the to-be-recycled tiling to ensure replaced tiles don't linger and take
86 // memory (due to a stale 'active' priority).
87 if (layer_impl->tilings_)
88 layer_impl->tilings_->DidBecomeRecycled();
90 LayerImpl::PushPropertiesTo(base_layer);
92 // When the pending tree pushes to the active tree, the pending twin
94 layer_impl->twin_layer_ = NULL;
97 layer_impl->SetIsMask(is_mask_);
98 layer_impl->pile_ = pile_;
99 layer_impl->SetHasGpuRasterizationHint(has_gpu_rasterization_hint_);
101 // Tilings would be expensive to push, so we swap. This optimization requires
102 // an extra invalidation in SyncFromActiveLayer.
103 layer_impl->tilings_.swap(tilings_);
104 layer_impl->tilings_->SetClient(layer_impl);
106 tilings_->SetClient(this);
108 layer_impl->raster_page_scale_ = raster_page_scale_;
109 layer_impl->raster_device_scale_ = raster_device_scale_;
110 layer_impl->raster_source_scale_ = raster_source_scale_;
111 layer_impl->raster_contents_scale_ = raster_contents_scale_;
112 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_;
114 layer_impl->UpdateLCDTextStatus(is_using_lcd_text_);
115 layer_impl->needs_post_commit_initialization_ = false;
117 // The invalidation on this soon-to-be-recycled layer must be cleared to
118 // mirror clearing the invalidation in PictureLayer's version of this function
119 // in case push properties is skipped.
120 layer_impl->invalidation_.Swap(&invalidation_);
121 invalidation_.Clear();
122 needs_post_commit_initialization_ = true;
124 // We always need to push properties.
125 // See http://crbug.com/303943
126 needs_push_properties_ = true;
129 void PictureLayerImpl::AppendQuads(QuadSink* quad_sink,
130 AppendQuadsData* append_quads_data) {
131 DCHECK(!needs_post_commit_initialization_);
132 gfx::Rect rect(visible_content_rect());
133 gfx::Rect content_rect(content_bounds());
135 SharedQuadState* shared_quad_state =
136 quad_sink->UseSharedQuadState(CreateSharedQuadState());
138 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) {
139 AppendDebugBorderQuad(
143 DebugColors::DirectPictureBorderColor(),
144 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
146 gfx::Rect geometry_rect = rect;
147 gfx::Rect opaque_rect = contents_opaque() ? geometry_rect : gfx::Rect();
148 gfx::Rect visible_geometry_rect = geometry_rect;
149 gfx::Size texture_size = rect.size();
150 gfx::RectF texture_rect = gfx::RectF(texture_size);
151 gfx::Rect quad_content_rect = rect;
152 float contents_scale = contents_scale_x();
154 scoped_ptr<PictureDrawQuad> quad = PictureDrawQuad::Create();
155 quad->SetNew(shared_quad_state,
158 visible_geometry_rect,
165 if (quad_sink->MaybeAppend(quad.PassAs<DrawQuad>()))
166 append_quads_data->num_missing_tiles++;
170 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
172 if (ShowDebugBorders()) {
173 for (PictureLayerTilingSet::CoverageIterator iter(
174 tilings_.get(), contents_scale_x(), rect, ideal_contents_scale_);
179 if (*iter && iter->IsReadyToDraw()) {
180 ManagedTileState::TileVersion::Mode mode =
181 iter->GetTileVersionForDrawing().mode();
182 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) {
183 color = DebugColors::SolidColorTileBorderColor();
184 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
185 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) {
186 color = DebugColors::PictureTileBorderColor();
187 width = DebugColors::PictureTileBorderWidth(layer_tree_impl());
188 } else if (iter->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) {
189 color = DebugColors::HighResTileBorderColor();
190 width = DebugColors::HighResTileBorderWidth(layer_tree_impl());
191 } else if (iter->priority(ACTIVE_TREE).resolution == LOW_RESOLUTION) {
192 color = DebugColors::LowResTileBorderColor();
193 width = DebugColors::LowResTileBorderWidth(layer_tree_impl());
194 } else if (iter->contents_scale() > contents_scale_x()) {
195 color = DebugColors::ExtraHighResTileBorderColor();
196 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
198 color = DebugColors::ExtraLowResTileBorderColor();
199 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
202 color = DebugColors::MissingTileBorderColor();
203 width = DebugColors::MissingTileBorderWidth(layer_tree_impl());
206 scoped_ptr<DebugBorderDrawQuad> debug_border_quad =
207 DebugBorderDrawQuad::Create();
208 gfx::Rect geometry_rect = iter.geometry_rect();
209 gfx::Rect visible_geometry_rect = geometry_rect;
210 debug_border_quad->SetNew(shared_quad_state,
212 visible_geometry_rect,
215 quad_sink->MaybeAppend(debug_border_quad.PassAs<DrawQuad>());
219 // Keep track of the tilings that were used so that tilings that are
220 // unused can be considered for removal.
221 std::vector<PictureLayerTiling*> seen_tilings;
223 for (PictureLayerTilingSet::CoverageIterator iter(
224 tilings_.get(), contents_scale_x(), rect, ideal_contents_scale_);
227 gfx::Rect geometry_rect = iter.geometry_rect();
228 gfx::Rect visible_geometry_rect = geometry_rect;
229 if (!*iter || !iter->IsReadyToDraw()) {
230 if (draw_checkerboard_for_missing_tiles()) {
231 // TODO(enne): Figure out how to show debug "invalidated checker" color
232 scoped_ptr<CheckerboardDrawQuad> quad = CheckerboardDrawQuad::Create();
233 SkColor color = DebugColors::DefaultCheckerboardColor();
235 shared_quad_state, geometry_rect, visible_geometry_rect, color);
236 if (quad_sink->MaybeAppend(quad.PassAs<DrawQuad>()))
237 append_quads_data->num_missing_tiles++;
239 SkColor color = SafeOpaqueBackgroundColor();
240 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
241 quad->SetNew(shared_quad_state,
243 visible_geometry_rect,
246 if (quad_sink->MaybeAppend(quad.PassAs<DrawQuad>()))
247 append_quads_data->num_missing_tiles++;
250 append_quads_data->had_incomplete_tile = true;
254 const ManagedTileState::TileVersion& tile_version =
255 iter->GetTileVersionForDrawing();
256 scoped_ptr<DrawQuad> draw_quad;
257 switch (tile_version.mode()) {
258 case ManagedTileState::TileVersion::RESOURCE_MODE: {
259 gfx::RectF texture_rect = iter.texture_rect();
260 gfx::Rect opaque_rect = iter->opaque_rect();
261 opaque_rect.Intersect(geometry_rect);
263 if (iter->contents_scale() != ideal_contents_scale_)
264 append_quads_data->had_incomplete_tile = true;
266 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create();
267 quad->SetNew(shared_quad_state,
270 visible_geometry_rect,
271 tile_version.get_resource_id(),
274 tile_version.contents_swizzled());
275 draw_quad = quad.PassAs<DrawQuad>();
278 case ManagedTileState::TileVersion::PICTURE_PILE_MODE: {
279 gfx::RectF texture_rect = iter.texture_rect();
280 gfx::Rect opaque_rect = iter->opaque_rect();
281 opaque_rect.Intersect(geometry_rect);
283 ResourceProvider* resource_provider =
284 layer_tree_impl()->resource_provider();
285 ResourceFormat format =
286 resource_provider->memory_efficient_texture_format();
287 scoped_ptr<PictureDrawQuad> quad = PictureDrawQuad::Create();
288 quad->SetNew(shared_quad_state,
291 visible_geometry_rect,
295 iter->content_rect(),
296 iter->contents_scale(),
298 draw_quad = quad.PassAs<DrawQuad>();
301 case ManagedTileState::TileVersion::SOLID_COLOR_MODE: {
302 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
303 quad->SetNew(shared_quad_state,
305 visible_geometry_rect,
306 tile_version.get_solid_color(),
308 draw_quad = quad.PassAs<DrawQuad>();
314 quad_sink->MaybeAppend(draw_quad.Pass());
316 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling())
317 seen_tilings.push_back(iter.CurrentTiling());
320 // Aggressively remove any tilings that are not seen to save memory. Note
321 // that this is at the expense of doing cause more frequent re-painting. A
322 // better scheme would be to maintain a tighter visible_content_rect for the
324 CleanUpTilingsOnActiveLayer(seen_tilings);
327 void PictureLayerImpl::DidUnregisterLayer() {
328 layer_needs_to_register_itself_ = true;
331 void PictureLayerImpl::UpdateTilePriorities() {
332 DCHECK(!needs_post_commit_initialization_);
333 CHECK(should_update_tile_priorities_);
335 if (layer_needs_to_register_itself_) {
336 layer_tree_impl()->tile_manager()->RegisterPictureLayerImpl(this);
337 layer_needs_to_register_itself_ = false;
340 if (!layer_tree_impl()->device_viewport_valid_for_tile_management()) {
341 for (size_t i = 0; i < tilings_->num_tilings(); ++i)
342 DCHECK(tilings_->tiling_at(i)->has_ever_been_updated());
346 if (!tilings_->num_tilings())
349 double current_frame_time_in_seconds =
350 (layer_tree_impl()->CurrentFrameTimeTicks() -
351 base::TimeTicks()).InSecondsF();
353 bool tiling_needs_update = false;
354 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
355 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime(
356 current_frame_time_in_seconds)) {
357 tiling_needs_update = true;
361 if (!tiling_needs_update)
364 UpdateLCDTextStatus(can_use_lcd_text());
366 // Use visible_content_rect, unless it's empty. If it's empty, then
367 // try to inverse project the viewport into layer space and use that.
368 gfx::Rect visible_rect_in_content_space = visible_content_rect();
369 if (visible_rect_in_content_space.IsEmpty()) {
370 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization);
371 if (screen_space_transform().GetInverse(&screen_to_layer)) {
372 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize();
373 visible_rect_in_content_space =
374 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
375 screen_to_layer, gfx::Rect(viewport_size)));
376 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds()));
381 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
383 tilings_->UpdateTilePriorities(tree,
384 visible_rect_in_content_space,
386 current_frame_time_in_seconds);
388 if (layer_tree_impl()->IsPendingTree())
389 MarkVisibleResourcesAsRequired();
391 // Tile priorities were modified.
392 layer_tree_impl()->DidModifyTilePriorities();
395 void PictureLayerImpl::DidBecomeActive() {
396 LayerImpl::DidBecomeActive();
397 tilings_->DidBecomeActive();
398 layer_tree_impl()->DidModifyTilePriorities();
401 void PictureLayerImpl::DidBeginTracing() {
402 pile_->DidBeginTracing();
405 void PictureLayerImpl::ReleaseResources() {
412 void PictureLayerImpl::CalculateContentsScale(
413 float ideal_contents_scale,
414 float device_scale_factor,
415 float page_scale_factor,
416 bool animating_transform_to_screen,
417 float* contents_scale_x,
418 float* contents_scale_y,
419 gfx::Size* content_bounds) {
420 DoPostCommitInitializationIfNeeded();
422 // This function sets valid raster scales and manages tilings, so tile
423 // priorities can now be updated.
424 should_update_tile_priorities_ = true;
426 if (!CanHaveTilings()) {
427 ideal_page_scale_ = page_scale_factor;
428 ideal_device_scale_ = device_scale_factor;
429 ideal_contents_scale_ = ideal_contents_scale;
430 ideal_source_scale_ =
431 ideal_contents_scale_ / ideal_page_scale_ / ideal_device_scale_;
432 *contents_scale_x = ideal_contents_scale_;
433 *contents_scale_y = ideal_contents_scale_;
434 *content_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(),
435 ideal_contents_scale_,
436 ideal_contents_scale_));
440 float min_contents_scale = MinimumContentsScale();
441 DCHECK_GT(min_contents_scale, 0.f);
442 float min_page_scale = layer_tree_impl()->min_page_scale_factor();
443 DCHECK_GT(min_page_scale, 0.f);
444 float min_device_scale = 1.f;
445 float min_source_scale =
446 min_contents_scale / min_page_scale / min_device_scale;
448 float ideal_page_scale = page_scale_factor;
449 float ideal_device_scale = device_scale_factor;
450 float ideal_source_scale =
451 ideal_contents_scale / ideal_page_scale / ideal_device_scale;
453 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale);
454 ideal_page_scale_ = ideal_page_scale;
455 ideal_device_scale_ = ideal_device_scale;
456 ideal_source_scale_ = std::max(ideal_source_scale, min_source_scale);
458 ManageTilings(animating_transform_to_screen);
460 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious.
461 // There are (usually) several tilings at different scales. However, the
462 // content bounds is the (integer!) space in which quads are generated.
463 // In order to guarantee that we can fill this integer space with any set of
464 // tilings (and then map back to floating point texture coordinates), the
465 // contents scale must be at least as large as the largest of the tilings.
466 float max_contents_scale = min_contents_scale;
467 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
468 const PictureLayerTiling* tiling = tilings_->tiling_at(i);
469 max_contents_scale = std::max(max_contents_scale, tiling->contents_scale());
472 *contents_scale_x = max_contents_scale;
473 *contents_scale_y = max_contents_scale;
474 *content_bounds = gfx::ToCeiledSize(
475 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale));
478 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() {
479 return pile_->GetFlattenedPicture();
482 void PictureLayerImpl::SetHasGpuRasterizationHint(bool has_hint) {
483 bool old_should_use_gpu_rasterization = ShouldUseGpuRasterization();
484 has_gpu_rasterization_hint_ = has_hint;
485 if (ShouldUseGpuRasterization() != old_should_use_gpu_rasterization)
489 bool PictureLayerImpl::ShouldUseGpuRasterization() const {
490 switch (layer_tree_impl()->settings().rasterization_site) {
491 case LayerTreeSettings::CpuRasterization:
493 case LayerTreeSettings::HybridRasterization:
494 return has_gpu_rasterization_hint_;
495 case LayerTreeSettings::GpuRasterization:
502 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
503 const gfx::Rect& content_rect) {
504 if (!pile_->CanRaster(tiling->contents_scale(), content_rect))
505 return scoped_refptr<Tile>();
508 if (is_using_lcd_text_)
509 flags |= Tile::USE_LCD_TEXT;
510 if (ShouldUseGpuRasterization())
511 flags |= Tile::USE_GPU_RASTERIZATION;
512 return layer_tree_impl()->tile_manager()->CreateTile(
516 contents_opaque() ? content_rect : gfx::Rect(),
517 tiling->contents_scale(),
519 layer_tree_impl()->source_frame_number(),
523 void PictureLayerImpl::UpdatePile(Tile* tile) {
524 tile->set_picture_pile(pile_);
527 const Region* PictureLayerImpl::GetInvalidation() {
528 return &invalidation_;
531 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
532 const PictureLayerTiling* tiling) const {
535 twin_layer_->ShouldUseGpuRasterization() != ShouldUseGpuRasterization())
537 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i)
538 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() ==
539 tiling->contents_scale())
540 return twin_layer_->tilings_->tiling_at(i);
544 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const {
545 return layer_tree_impl()->settings().max_tiles_for_interest_area;
548 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const {
549 return layer_tree_impl()->settings().skewport_target_time_in_seconds;
552 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const {
553 return layer_tree_impl()
555 .skewport_extrapolation_limit_in_content_pixels;
558 gfx::Size PictureLayerImpl::CalculateTileSize(
559 const gfx::Size& content_bounds) const {
561 int max_size = layer_tree_impl()->MaxTextureSize();
563 std::min(max_size, content_bounds.width()),
564 std::min(max_size, content_bounds.height()));
567 int max_texture_size =
568 layer_tree_impl()->resource_provider()->max_texture_size();
570 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size;
571 default_tile_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
573 gfx::Size max_untiled_content_size =
574 layer_tree_impl()->settings().max_untiled_layer_size;
575 max_untiled_content_size.SetToMin(
576 gfx::Size(max_texture_size, max_texture_size));
578 bool any_dimension_too_large =
579 content_bounds.width() > max_untiled_content_size.width() ||
580 content_bounds.height() > max_untiled_content_size.height();
582 bool any_dimension_one_tile =
583 content_bounds.width() <= default_tile_size.width() ||
584 content_bounds.height() <= default_tile_size.height();
586 // If long and skinny, tile at the max untiled content size, and clamp
587 // the smaller dimension to the content size, e.g. 1000x12 layer with
588 // 500x500 max untiled size would get 500x12 tiles. Also do this
589 // if the layer is small.
590 if (any_dimension_one_tile || !any_dimension_too_large) {
592 std::min(max_untiled_content_size.width(), content_bounds.width());
594 std::min(max_untiled_content_size.height(), content_bounds.height());
595 // Round width and height up to the closest multiple of 64, or 56 if
596 // we should avoid power-of-two textures. This helps reduce the number
597 // of different textures sizes to help recycling, and also keeps all
598 // textures multiple-of-eight, which is preferred on some drivers (IMG).
600 layer_tree_impl()->GetRendererCapabilities().avoid_pow2_textures;
601 int round_up_to = avoid_pow2 ? 56 : 64;
602 width = RoundUp(width, round_up_to);
603 height = RoundUp(height, round_up_to);
604 return gfx::Size(width, height);
607 return default_tile_size;
610 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) {
611 DCHECK(!other->needs_post_commit_initialization_);
612 DCHECK(other->tilings_);
614 UpdateLCDTextStatus(other->is_using_lcd_text_);
616 if (!DrawsContent()) {
621 raster_page_scale_ = other->raster_page_scale_;
622 raster_device_scale_ = other->raster_device_scale_;
623 raster_source_scale_ = other->raster_source_scale_;
624 raster_contents_scale_ = other->raster_contents_scale_;
625 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_;
627 // Add synthetic invalidations for any recordings that were dropped. As
628 // tiles are updated to point to this new pile, this will force the dropping
629 // of tiles that can no longer be rastered. This is not ideal, but is a
630 // trade-off for memory (use the same pile as much as possible, by switching
631 // during DidBecomeActive) and for time (don't bother checking every tile
632 // during activation to see if the new pile can still raster it).
633 for (int x = 0; x < pile_->num_tiles_x(); ++x) {
634 for (int y = 0; y < pile_->num_tiles_y(); ++y) {
635 bool previously_had = other->pile_->HasRecordingAt(x, y);
636 bool now_has = pile_->HasRecordingAt(x, y);
637 if (now_has || !previously_had)
639 gfx::Rect layer_rect = pile_->tile_bounds(x, y);
640 invalidation_.Union(layer_rect);
644 // Union in the other newly exposed regions as invalid.
645 Region difference_region = Region(gfx::Rect(bounds()));
646 difference_region.Subtract(gfx::Rect(other->bounds()));
647 invalidation_.Union(difference_region);
649 if (CanHaveTilings()) {
650 // The recycle tree's tiling set is two frames out of date, so it needs to
651 // have both this frame's invalidation and the previous frame's invalidation
652 // (stored on the active layer).
653 Region tiling_invalidation = other->invalidation_;
654 tiling_invalidation.Union(invalidation_);
655 tilings_->SyncTilings(*other->tilings_,
658 MinimumContentsScale());
663 SanityCheckTilingState();
666 void PictureLayerImpl::SyncTiling(
667 const PictureLayerTiling* tiling) {
668 if (!CanHaveTilingWithScale(tiling->contents_scale()))
670 tilings_->AddTiling(tiling->contents_scale());
672 // If this tree needs update draw properties, then the tiling will
673 // get updated prior to drawing or activation. If this tree does not
674 // need update draw properties, then its transforms are up to date and
675 // we can create tiles for this tiling immediately.
676 if (!layer_tree_impl()->needs_update_draw_properties() &&
677 should_update_tile_priorities_)
678 UpdateTilePriorities();
681 void PictureLayerImpl::SetIsMask(bool is_mask) {
682 if (is_mask_ == is_mask)
686 tilings_->RemoveAllTiles();
689 ResourceProvider::ResourceId PictureLayerImpl::ContentsResourceId() const {
690 gfx::Rect content_rect(content_bounds());
691 float scale = contents_scale_x();
692 PictureLayerTilingSet::CoverageIterator iter(
693 tilings_.get(), scale, content_rect, ideal_contents_scale_);
695 // Mask resource not ready yet.
699 // Masks only supported if they fit on exactly one tile.
700 if (iter.geometry_rect() != content_rect)
703 const ManagedTileState::TileVersion& tile_version =
704 iter->GetTileVersionForDrawing();
705 if (!tile_version.IsReadyToDraw() ||
706 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE)
709 return tile_version.get_resource_id();
712 void PictureLayerImpl::MarkVisibleResourcesAsRequired() const {
713 DCHECK(layer_tree_impl()->IsPendingTree());
714 DCHECK(!layer_tree_impl()->needs_update_draw_properties());
715 DCHECK(ideal_contents_scale_);
716 DCHECK_GT(tilings_->num_tilings(), 0u);
718 // The goal of this function is to find the minimum set of tiles that need to
719 // be ready to draw in order to activate without flashing content from a
720 // higher res on the active tree to a lower res on the pending tree.
722 gfx::Rect rect(visible_content_rect());
724 float min_acceptable_scale =
725 std::min(raster_contents_scale_, ideal_contents_scale_);
727 if (PictureLayerImpl* twin = twin_layer_) {
728 float twin_min_acceptable_scale =
729 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_);
730 // Ignore 0 scale in case CalculateContentsScale() has never been
731 // called for active twin.
732 if (twin_min_acceptable_scale != 0.0f) {
733 min_acceptable_scale =
734 std::min(min_acceptable_scale, twin_min_acceptable_scale);
738 PictureLayerTiling* high_res = NULL;
739 PictureLayerTiling* low_res = NULL;
741 // First pass: ready to draw tiles in acceptable but non-ideal tilings are
742 // marked as required for activation so that their textures are not thrown
743 // away; any non-ready tiles are not marked as required.
744 Region missing_region = rect;
745 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
746 PictureLayerTiling* tiling = tilings_->tiling_at(i);
747 DCHECK(tiling->has_ever_been_updated());
749 if (tiling->resolution() == LOW_RESOLUTION) {
750 DCHECK(!low_res) << "There can only be one low res tiling";
753 if (tiling->contents_scale() < min_acceptable_scale)
755 if (tiling->resolution() == HIGH_RESOLUTION) {
756 DCHECK(!high_res) << "There can only be one high res tiling";
760 for (PictureLayerTiling::CoverageIterator iter(tiling,
765 if (!*iter || !iter->IsReadyToDraw())
768 missing_region.Subtract(iter.geometry_rect());
769 iter->MarkRequiredForActivation();
772 DCHECK(high_res) << "There must be one high res tiling";
774 // If these pointers are null (because no twin, no matching tiling, or the
775 // simpification just below), then high res tiles will be required to fill any
776 // holes left by the first pass above. If the pointers are valid, then this
777 // layer is allowed to skip any tiles that are not ready on its twin.
778 const PictureLayerTiling* twin_high_res = NULL;
779 const PictureLayerTiling* twin_low_res = NULL;
781 // As a simplification, only allow activating to skip twin tiles that the
782 // active layer is also missing when both this layer and its twin have 2
783 // tilings (high and low). This avoids having to iterate/track coverage of
784 // non-ideal tilings during the last draw call on the active layer.
785 if (high_res && low_res && tilings_->num_tilings() == 2 &&
786 twin_layer_ && twin_layer_->tilings_->num_tilings() == 2) {
787 twin_low_res = GetTwinTiling(low_res);
789 twin_high_res = GetTwinTiling(high_res);
791 // If this layer and its twin have different transforms, then don't compare
792 // them and only allow activating to high res tiles, since tiles on each layer
793 // will be in different places on screen.
794 if (!twin_high_res || !twin_low_res ||
795 twin_layer_->layer_tree_impl()->RequiresHighResToDraw() ||
796 draw_properties().screen_space_transform !=
797 twin_layer_->draw_properties().screen_space_transform) {
798 twin_high_res = NULL;
802 // As a second pass, mark as required any visible high res tiles not filled in
803 // by acceptable non-ideal tiles from the first pass.
804 if (MarkVisibleTilesAsRequired(
805 high_res, twin_high_res, contents_scale_x(), rect, missing_region)) {
806 // As an optional third pass, if a high res tile was skipped because its
807 // twin was also missing, then fall back to mark low res tiles as required
808 // in case the active twin is substituting those for missing high res
810 MarkVisibleTilesAsRequired(
811 low_res, twin_low_res, contents_scale_x(), rect, missing_region);
815 bool PictureLayerImpl::MarkVisibleTilesAsRequired(
816 PictureLayerTiling* tiling,
817 const PictureLayerTiling* optional_twin_tiling,
818 float contents_scale,
819 const gfx::Rect& rect,
820 const Region& missing_region) const {
821 bool twin_had_missing_tile = false;
822 for (PictureLayerTiling::CoverageIterator iter(tiling,
828 // A null tile (i.e. missing recording) can just be skipped.
832 // If the missing region doesn't cover it, this tile is fully
833 // covered by acceptable tiles at other scales.
834 if (!missing_region.Intersects(iter.geometry_rect()))
837 // If the twin tile doesn't exist (i.e. missing recording or so far away
838 // that it is outside the visible tile rect) or this tile is shared between
839 // with the twin, then this tile isn't required to prevent flashing.
840 if (optional_twin_tiling) {
841 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j());
842 if (!twin_tile || twin_tile == tile) {
843 twin_had_missing_tile = true;
848 tile->MarkRequiredForActivation();
850 return twin_had_missing_tile;
853 void PictureLayerImpl::DoPostCommitInitialization() {
854 DCHECK(needs_post_commit_initialization_);
855 DCHECK(layer_tree_impl()->IsPendingTree());
858 tilings_.reset(new PictureLayerTilingSet(this, bounds()));
860 DCHECK(!twin_layer_);
861 twin_layer_ = static_cast<PictureLayerImpl*>(
862 layer_tree_impl()->FindActiveTreeLayerById(id()));
864 DCHECK(!twin_layer_->twin_layer_);
865 twin_layer_->twin_layer_ = this;
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_);
872 needs_post_commit_initialization_ = false;
875 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
876 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
877 "contents_scale: " << contents_scale;
879 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
881 DCHECK(pile_->HasRecordings());
884 twin_layer_->ShouldUseGpuRasterization() == ShouldUseGpuRasterization())
885 twin_layer_->SyncTiling(tiling);
890 void PictureLayerImpl::RemoveTiling(float contents_scale) {
891 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
892 PictureLayerTiling* tiling = tilings_->tiling_at(i);
893 if (tiling->contents_scale() == contents_scale) {
894 tilings_->Remove(tiling);
898 if (tilings_->num_tilings() == 0)
900 SanityCheckTilingState();
903 void PictureLayerImpl::RemoveAllTilings() {
905 tilings_->RemoveAllTilings();
906 // If there are no tilings, then raster scales are no longer meaningful.
912 inline float PositiveRatio(float float1, float float2) {
913 DCHECK_GT(float1, 0);
914 DCHECK_GT(float2, 0);
915 return float1 > float2 ? float1 / float2 : float2 / float1;
920 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) {
921 DCHECK(ideal_contents_scale_);
922 DCHECK(ideal_page_scale_);
923 DCHECK(ideal_device_scale_);
924 DCHECK(ideal_source_scale_);
925 DCHECK(CanHaveTilings());
926 DCHECK(!needs_post_commit_initialization_);
928 bool change_target_tiling =
929 raster_page_scale_ == 0.f ||
930 raster_device_scale_ == 0.f ||
931 raster_source_scale_ == 0.f ||
932 raster_contents_scale_ == 0.f ||
933 low_res_raster_contents_scale_ == 0.f ||
934 ShouldAdjustRasterScale(animating_transform_to_screen);
936 if (tilings_->num_tilings() == 0) {
937 DCHECK(change_target_tiling)
938 << "A layer with no tilings shouldn't have valid raster scales";
941 // Store the value for the next time ShouldAdjustRasterScale is called.
942 raster_source_scale_was_animating_ = animating_transform_to_screen;
944 if (!change_target_tiling)
947 if (!layer_tree_impl()->device_viewport_valid_for_tile_management())
950 RecalculateRasterScales(animating_transform_to_screen);
952 PictureLayerTiling* high_res = NULL;
953 PictureLayerTiling* low_res = NULL;
955 PictureLayerTiling* previous_low_res = NULL;
956 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
957 PictureLayerTiling* tiling = tilings_->tiling_at(i);
958 if (tiling->contents_scale() == raster_contents_scale_)
960 if (tiling->contents_scale() == low_res_raster_contents_scale_)
962 if (tiling->resolution() == LOW_RESOLUTION)
963 previous_low_res = tiling;
965 // Reset all tilings to non-ideal until the end of this function.
966 tiling->set_resolution(NON_IDEAL_RESOLUTION);
970 high_res = AddTiling(raster_contents_scale_);
971 if (raster_contents_scale_ == low_res_raster_contents_scale_)
975 // Only create new low res tilings when the transform is static. This
976 // prevents wastefully creating a paired low res tiling for every new high res
977 // tiling during a pinch or a CSS animation.
978 bool is_pinching = layer_tree_impl()->PinchGestureActive();
979 if (ShouldHaveLowResTiling() && !is_pinching &&
980 !animating_transform_to_screen &&
981 !low_res && low_res != high_res)
982 low_res = AddTiling(low_res_raster_contents_scale_);
984 // Set low-res if we have one.
986 low_res = previous_low_res;
987 if (low_res && low_res != high_res)
988 low_res->set_resolution(LOW_RESOLUTION);
990 // Make sure we always have one high-res (even if high == low).
991 high_res->set_resolution(HIGH_RESOLUTION);
993 SanityCheckTilingState();
996 bool PictureLayerImpl::ShouldAdjustRasterScale(
997 bool animating_transform_to_screen) const {
998 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
999 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
1000 // tree. This will allow CSS scale changes to get re-rastered at an
1001 // appropriate rate.
1003 if (raster_source_scale_was_animating_ && !animating_transform_to_screen)
1006 bool is_pinching = layer_tree_impl()->PinchGestureActive();
1007 if (is_pinching && raster_page_scale_) {
1008 // We change our raster scale when it is:
1009 // - Higher than ideal (need a lower-res tiling available)
1010 // - Too far from ideal (need a higher-res tiling available)
1011 float ratio = ideal_page_scale_ / raster_page_scale_;
1012 if (raster_page_scale_ > ideal_page_scale_ ||
1013 ratio > kMaxScaleRatioDuringPinch)
1018 // When not pinching, match the ideal page scale factor.
1019 if (raster_page_scale_ != ideal_page_scale_)
1023 // Always match the ideal device scale factor.
1024 if (raster_device_scale_ != ideal_device_scale_)
1030 float PictureLayerImpl::SnappedContentsScale(float scale) {
1031 // If a tiling exists within the max snapping ratio, snap to its scale.
1032 float snapped_contents_scale = scale;
1033 float snapped_ratio = kSnapToExistingTilingRatio;
1034 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
1035 float tiling_contents_scale = tilings_->tiling_at(i)->contents_scale();
1036 float ratio = PositiveRatio(tiling_contents_scale, scale);
1037 if (ratio < snapped_ratio) {
1038 snapped_contents_scale = tiling_contents_scale;
1039 snapped_ratio = ratio;
1042 return snapped_contents_scale;
1045 void PictureLayerImpl::RecalculateRasterScales(
1046 bool animating_transform_to_screen) {
1047 raster_device_scale_ = ideal_device_scale_;
1048 raster_source_scale_ = ideal_source_scale_;
1050 bool is_pinching = layer_tree_impl()->PinchGestureActive();
1051 if (!is_pinching || raster_contents_scale_ == 0.f) {
1052 // When not pinching or when we have no previous scale, we use ideal scale:
1053 raster_page_scale_ = ideal_page_scale_;
1054 raster_contents_scale_ = ideal_contents_scale_;
1056 // See ShouldAdjustRasterScale:
1057 // - When zooming out, preemptively create new tiling at lower resolution.
1058 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
1059 bool zooming_out = raster_page_scale_ > ideal_page_scale_;
1060 float desired_contents_scale =
1061 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch
1062 : raster_contents_scale_ * kMaxScaleRatioDuringPinch;
1063 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale);
1064 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_;
1067 raster_contents_scale_ =
1068 std::max(raster_contents_scale_, MinimumContentsScale());
1070 // Don't allow animating CSS scales to drop below 1. This is needed because
1071 // changes in raster source scale aren't handled. See the comment in
1072 // ShouldAdjustRasterScale.
1073 if (animating_transform_to_screen) {
1074 raster_contents_scale_ = std::max(
1075 raster_contents_scale_, 1.f * ideal_page_scale_ * ideal_device_scale_);
1078 // If this layer would only create one tile at this content scale,
1079 // don't create a low res tiling.
1080 gfx::Size content_bounds =
1081 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_));
1082 gfx::Size tile_size = CalculateTileSize(content_bounds);
1083 if (tile_size.width() >= content_bounds.width() &&
1084 tile_size.height() >= content_bounds.height()) {
1085 low_res_raster_contents_scale_ = raster_contents_scale_;
1089 float low_res_factor =
1090 layer_tree_impl()->settings().low_res_contents_scale_factor;
1091 low_res_raster_contents_scale_ = std::max(
1092 raster_contents_scale_ * low_res_factor,
1093 MinimumContentsScale());
1096 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
1097 std::vector<PictureLayerTiling*> used_tilings) {
1098 DCHECK(layer_tree_impl()->IsActiveTree());
1099 if (tilings_->num_tilings() == 0)
1102 float min_acceptable_high_res_scale = std::min(
1103 raster_contents_scale_, ideal_contents_scale_);
1104 float max_acceptable_high_res_scale = std::max(
1105 raster_contents_scale_, ideal_contents_scale_);
1107 PictureLayerImpl* twin = twin_layer_;
1109 min_acceptable_high_res_scale = std::min(
1110 min_acceptable_high_res_scale,
1111 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1112 max_acceptable_high_res_scale = std::max(
1113 max_acceptable_high_res_scale,
1114 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1117 std::vector<PictureLayerTiling*> to_remove;
1118 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
1119 PictureLayerTiling* tiling = tilings_->tiling_at(i);
1121 // Keep multiple high resolution tilings even if not used to help
1122 // activate earlier at non-ideal resolutions.
1123 if (tiling->contents_scale() >= min_acceptable_high_res_scale &&
1124 tiling->contents_scale() <= max_acceptable_high_res_scale)
1127 // Keep low resolution tilings, if the layer should have them.
1128 if (tiling->resolution() == LOW_RESOLUTION && ShouldHaveLowResTiling())
1131 // Don't remove tilings that are being used (and thus would cause a flash.)
1132 if (std::find(used_tilings.begin(), used_tilings.end(), tiling) !=
1136 to_remove.push_back(tiling);
1139 for (size_t i = 0; i < to_remove.size(); ++i) {
1140 const PictureLayerTiling* twin_tiling = GetTwinTiling(to_remove[i]);
1141 // Only remove tilings from the twin layer if they have
1142 // NON_IDEAL_RESOLUTION.
1143 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION)
1144 twin->RemoveTiling(to_remove[i]->contents_scale());
1145 tilings_->Remove(to_remove[i]);
1147 DCHECK_GT(tilings_->num_tilings(), 0u);
1149 SanityCheckTilingState();
1152 float PictureLayerImpl::MinimumContentsScale() const {
1153 float setting_min = layer_tree_impl()->settings().minimum_contents_scale;
1155 // If the contents scale is less than 1 / width (also for height),
1156 // then it will end up having less than one pixel of content in that
1157 // dimension. Bump the minimum contents scale up in this case to prevent
1158 // this from happening.
1159 int min_dimension = std::min(bounds().width(), bounds().height());
1163 return std::max(1.f / min_dimension, setting_min);
1166 void PictureLayerImpl::UpdateLCDTextStatus(bool new_status) {
1167 // Once this layer is not using lcd text, don't switch back.
1168 if (!is_using_lcd_text_)
1171 if (is_using_lcd_text_ == new_status)
1174 is_using_lcd_text_ = new_status;
1175 tilings_->SetCanUseLCDText(is_using_lcd_text_);
1178 void PictureLayerImpl::ResetRasterScale() {
1179 raster_page_scale_ = 0.f;
1180 raster_device_scale_ = 0.f;
1181 raster_source_scale_ = 0.f;
1182 raster_contents_scale_ = 0.f;
1183 low_res_raster_contents_scale_ = 0.f;
1185 // When raster scales aren't valid, don't update tile priorities until
1186 // this layer has been updated via UpdateDrawProperties.
1187 should_update_tile_priorities_ = false;
1190 bool PictureLayerImpl::CanHaveTilings() const {
1191 if (!DrawsContent())
1193 if (!pile_->HasRecordings())
1198 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const {
1199 if (!CanHaveTilings())
1201 if (contents_scale < MinimumContentsScale())
1206 void PictureLayerImpl::SanityCheckTilingState() const {
1208 if (!CanHaveTilings()) {
1209 DCHECK_EQ(0u, tilings_->num_tilings());
1212 if (tilings_->num_tilings() == 0)
1215 // MarkVisibleResourcesAsRequired depends on having exactly 1 high res
1216 // tiling to mark its tiles as being required for activation.
1217 DCHECK_EQ(1, tilings_->NumHighResTilings());
1221 void PictureLayerImpl::GetDebugBorderProperties(
1223 float* width) const {
1224 *color = DebugColors::TiledContentLayerBorderColor();
1225 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1228 void PictureLayerImpl::AsValueInto(base::DictionaryValue* state) const {
1229 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded();
1230 LayerImpl::AsValueInto(state);
1231 state->SetDouble("ideal_contents_scale", ideal_contents_scale_);
1232 state->SetDouble("geometry_contents_scale", contents_scale_x());
1233 state->Set("tilings", tilings_->AsValue().release());
1234 state->Set("pictures", pile_->AsValue().release());
1235 state->Set("invalidation", invalidation_.AsValue().release());
1237 scoped_ptr<base::ListValue> coverage_tiles(new base::ListValue);
1238 for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(),
1240 gfx::Rect(content_bounds()),
1241 ideal_contents_scale_);
1244 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue);
1245 tile_data->Set("geometry_rect",
1246 MathUtil::AsValue(iter.geometry_rect()).release());
1248 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release());
1250 coverage_tiles->Append(tile_data.release());
1252 state->Set("coverage_tiles", coverage_tiles.release());
1253 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_);
1254 state->SetBoolean("using_gpu_rasterization", ShouldUseGpuRasterization());
1257 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1258 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded();
1259 return tilings_->GPUMemoryUsageInBytes();
1262 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1263 benchmark->RunOnLayer(this);
1266 WhichTree PictureLayerImpl::GetTree() const {
1267 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
1270 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1271 return !layer_tree_impl()->IsRecycleTree();
1274 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator()
1277 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator(
1278 PictureLayerImpl* layer,
1279 bool prioritize_low_res)
1280 : layer_(layer), current_stage_(0) {
1282 if (!layer_->tilings_ || !layer_->tilings_->num_tilings())
1286 layer_->layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
1288 // Find high and low res tilings and initialize the iterators.
1289 for (size_t i = 0; i < layer_->tilings_->num_tilings(); ++i) {
1290 PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i);
1291 if (tiling->resolution() == HIGH_RESOLUTION) {
1292 iterators_[HIGH_RES] =
1293 PictureLayerTiling::TilingRasterTileIterator(tiling, tree);
1296 if (tiling->resolution() == LOW_RESOLUTION) {
1297 iterators_[LOW_RES] =
1298 PictureLayerTiling::TilingRasterTileIterator(tiling, tree);
1302 if (prioritize_low_res) {
1303 stages_[0].iterator_type = LOW_RES;
1304 stages_[0].tile_type =
1305 PictureLayerTiling::TilingRasterTileIterator::VISIBLE;
1307 stages_[1].iterator_type = HIGH_RES;
1308 stages_[1].tile_type =
1309 PictureLayerTiling::TilingRasterTileIterator::VISIBLE;
1311 stages_[0].iterator_type = HIGH_RES;
1312 stages_[0].tile_type =
1313 PictureLayerTiling::TilingRasterTileIterator::VISIBLE;
1315 stages_[1].iterator_type = LOW_RES;
1316 stages_[1].tile_type =
1317 PictureLayerTiling::TilingRasterTileIterator::VISIBLE;
1320 stages_[2].iterator_type = HIGH_RES;
1321 stages_[2].tile_type = PictureLayerTiling::TilingRasterTileIterator::SKEWPORT;
1323 stages_[3].iterator_type = HIGH_RES;
1324 stages_[3].tile_type =
1325 PictureLayerTiling::TilingRasterTileIterator::EVENTUALLY;
1327 IteratorType index = stages_[current_stage_].iterator_type;
1328 PictureLayerTiling::TilingRasterTileIterator::Type tile_type =
1329 stages_[current_stage_].tile_type;
1330 if (!iterators_[index] || iterators_[index].get_type() != tile_type)
1334 PictureLayerImpl::LayerRasterTileIterator::~LayerRasterTileIterator() {}
1336 PictureLayerImpl::LayerRasterTileIterator::operator bool() const {
1337 return layer_ && static_cast<size_t>(current_stage_) < arraysize(stages_);
1340 PictureLayerImpl::LayerRasterTileIterator&
1341 PictureLayerImpl::LayerRasterTileIterator::
1343 IteratorType index = stages_[current_stage_].iterator_type;
1344 PictureLayerTiling::TilingRasterTileIterator::Type tile_type =
1345 stages_[current_stage_].tile_type;
1347 // First advance the iterator.
1348 if (iterators_[index])
1349 ++iterators_[index];
1351 if (iterators_[index] && iterators_[index].get_type() == tile_type)
1354 // Next, advance the stage.
1355 int stage_count = arraysize(stages_);
1357 while (current_stage_ < stage_count) {
1358 index = stages_[current_stage_].iterator_type;
1359 tile_type = stages_[current_stage_].tile_type;
1361 if (iterators_[index] && iterators_[index].get_type() == tile_type)
1368 Tile* PictureLayerImpl::LayerRasterTileIterator::operator*() {
1371 IteratorType index = stages_[current_stage_].iterator_type;
1372 DCHECK(iterators_[index]);
1373 DCHECK(iterators_[index].get_type() == stages_[current_stage_].tile_type);
1375 return *iterators_[index];