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"
12 #include "base/debug/trace_event_argument.h"
13 #include "base/time/time.h"
14 #include "cc/base/math_util.h"
15 #include "cc/base/util.h"
16 #include "cc/debug/debug_colors.h"
17 #include "cc/debug/micro_benchmark_impl.h"
18 #include "cc/debug/traced_value.h"
19 #include "cc/layers/append_quads_data.h"
20 #include "cc/layers/solid_color_layer_impl.h"
21 #include "cc/output/begin_frame_args.h"
22 #include "cc/quads/checkerboard_draw_quad.h"
23 #include "cc/quads/debug_border_draw_quad.h"
24 #include "cc/quads/picture_draw_quad.h"
25 #include "cc/quads/solid_color_draw_quad.h"
26 #include "cc/quads/tile_draw_quad.h"
27 #include "cc/resources/tile_manager.h"
28 #include "cc/resources/tiling_set_raster_queue_all.h"
29 #include "cc/trees/layer_tree_impl.h"
30 #include "cc/trees/occlusion.h"
31 #include "ui/gfx/geometry/quad_f.h"
32 #include "ui/gfx/geometry/rect_conversions.h"
33 #include "ui/gfx/geometry/size_conversions.h"
36 // This must be > 1 as we multiply or divide by this to find a new raster
37 // scale during pinch.
38 const float kMaxScaleRatioDuringPinch
= 2.0f
;
40 // When creating a new tiling during pinch, snap to an existing
41 // tiling's scale if the desired scale is within this ratio.
42 const float kSnapToExistingTilingRatio
= 1.2f
;
44 // Even for really wide viewports, at some point GPU raster should use
45 // less than 4 tiles to fill the viewport. This is set to 256 as a
46 // sane minimum for now, but we might want to tune this for low-end.
47 const int kMinHeightForGpuRasteredTile
= 256;
49 // When making odd-sized tiles, round them up to increase the chances
50 // of using the same tile size.
51 const int kTileRoundUp
= 64;
57 PictureLayerImpl::Pair::Pair() : active(nullptr), pending(nullptr) {
60 PictureLayerImpl::Pair::Pair(PictureLayerImpl
* active_layer
,
61 PictureLayerImpl
* pending_layer
)
62 : active(active_layer
), pending(pending_layer
) {
65 PictureLayerImpl::Pair::~Pair() {
68 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl
* tree_impl
,
71 : LayerImpl(tree_impl
, id
),
73 tilings_(CreatePictureLayerTilingSet()),
74 ideal_page_scale_(0.f
),
75 ideal_device_scale_(0.f
),
76 ideal_source_scale_(0.f
),
77 ideal_contents_scale_(0.f
),
78 raster_page_scale_(0.f
),
79 raster_device_scale_(0.f
),
80 raster_source_scale_(0.f
),
81 raster_contents_scale_(0.f
),
82 low_res_raster_contents_scale_(0.f
),
83 raster_source_scale_is_fixed_(false),
84 was_screen_space_transform_animating_(false),
85 should_update_tile_priorities_(false),
86 only_used_low_res_last_append_quads_(false),
88 nearest_neighbor_(false) {
89 layer_tree_impl()->RegisterPictureLayerImpl(this);
92 PictureLayerImpl::~PictureLayerImpl() {
94 twin_layer_
->twin_layer_
= nullptr;
95 layer_tree_impl()->UnregisterPictureLayerImpl(this);
98 const char* PictureLayerImpl::LayerTypeAsString() const {
99 return "cc::PictureLayerImpl";
102 scoped_ptr
<LayerImpl
> PictureLayerImpl::CreateLayerImpl(
103 LayerTreeImpl
* tree_impl
) {
104 return PictureLayerImpl::Create(tree_impl
, id(), is_mask_
);
107 void PictureLayerImpl::PushPropertiesTo(LayerImpl
* base_layer
) {
108 PictureLayerImpl
* layer_impl
= static_cast<PictureLayerImpl
*>(base_layer
);
109 DCHECK_EQ(layer_impl
->is_mask_
, is_mask_
);
111 LayerImpl::PushPropertiesTo(base_layer
);
113 // Twin relationships should never change once established.
114 DCHECK_IMPLIES(twin_layer_
, twin_layer_
== layer_impl
);
115 DCHECK_IMPLIES(twin_layer_
, layer_impl
->twin_layer_
== this);
116 // The twin relationship does not need to exist before the first
117 // PushPropertiesTo from pending to active layer since before that the active
118 // layer can not have a pile or tilings, it has only been created and inserted
119 // into the tree at that point.
120 twin_layer_
= layer_impl
;
121 layer_impl
->twin_layer_
= this;
123 layer_impl
->SetNearestNeighbor(nearest_neighbor_
);
125 // Solid color layers have no tilings.
126 DCHECK_IMPLIES(raster_source_
->IsSolidColor(), tilings_
->num_tilings() == 0);
127 // The pending tree should only have a high res (and possibly low res) tiling.
128 DCHECK_LE(tilings_
->num_tilings(),
129 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
131 layer_impl
->UpdateRasterSource(raster_source_
, &invalidation_
,
133 DCHECK(invalidation_
.IsEmpty());
135 // After syncing a solid color layer, the active layer has no tilings.
136 DCHECK_IMPLIES(raster_source_
->IsSolidColor(),
137 layer_impl
->tilings_
->num_tilings() == 0);
139 layer_impl
->raster_page_scale_
= raster_page_scale_
;
140 layer_impl
->raster_device_scale_
= raster_device_scale_
;
141 layer_impl
->raster_source_scale_
= raster_source_scale_
;
142 layer_impl
->raster_contents_scale_
= raster_contents_scale_
;
143 layer_impl
->low_res_raster_contents_scale_
= low_res_raster_contents_scale_
;
145 layer_impl
->SanityCheckTilingState();
147 // We always need to push properties.
148 // See http://crbug.com/303943
149 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
150 needs_push_properties_
= true;
153 void PictureLayerImpl::AppendQuads(RenderPass
* render_pass
,
154 const Occlusion
& occlusion_in_content_space
,
155 AppendQuadsData
* append_quads_data
) {
156 // The bounds and the pile size may differ if the pile wasn't updated (ie.
157 // PictureLayer::Update didn't happen). In that case the pile will be empty.
158 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
159 bounds() == raster_source_
->GetSize())
160 << " bounds " << bounds().ToString() << " pile "
161 << raster_source_
->GetSize().ToString();
163 SharedQuadState
* shared_quad_state
=
164 render_pass
->CreateAndAppendSharedQuadState();
166 if (raster_source_
->IsSolidColor()) {
167 PopulateSharedQuadState(shared_quad_state
);
169 AppendDebugBorderQuad(
170 render_pass
, bounds(), shared_quad_state
, append_quads_data
);
172 SolidColorLayerImpl::AppendSolidQuads(
173 render_pass
, occlusion_in_content_space
, shared_quad_state
,
174 visible_content_rect(), raster_source_
->GetSolidColor(),
179 float max_contents_scale
= MaximumTilingContentsScale();
180 gfx::Transform scaled_draw_transform
= draw_transform();
181 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
182 SK_MScalar1
/ max_contents_scale
);
183 gfx::Size scaled_content_bounds
=
184 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), max_contents_scale
));
185 gfx::Rect scaled_visible_content_rect
=
186 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale
);
187 scaled_visible_content_rect
.Intersect(gfx::Rect(scaled_content_bounds
));
188 Occlusion scaled_occlusion
=
189 occlusion_in_content_space
.GetOcclusionWithGivenDrawTransform(
190 scaled_draw_transform
);
192 shared_quad_state
->SetAll(
193 scaled_draw_transform
, scaled_content_bounds
, scaled_visible_content_rect
,
194 draw_properties().clip_rect
, draw_properties().is_clipped
,
195 draw_properties().opacity
, draw_properties().blend_mode
,
196 sorting_context_id_
);
198 if (current_draw_mode_
== DRAW_MODE_RESOURCELESS_SOFTWARE
) {
199 AppendDebugBorderQuad(
201 scaled_content_bounds
,
204 DebugColors::DirectPictureBorderColor(),
205 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
207 gfx::Rect geometry_rect
= scaled_visible_content_rect
;
208 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
209 gfx::Rect visible_geometry_rect
=
210 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
211 if (visible_geometry_rect
.IsEmpty())
214 gfx::Size texture_size
= scaled_visible_content_rect
.size();
215 gfx::RectF texture_rect
= gfx::RectF(texture_size
);
216 gfx::Rect quad_content_rect
= scaled_visible_content_rect
;
218 PictureDrawQuad
* quad
=
219 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
220 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
221 visible_geometry_rect
, texture_rect
, texture_size
,
222 nearest_neighbor_
, RGBA_8888
, quad_content_rect
,
223 max_contents_scale
, raster_source_
);
227 AppendDebugBorderQuad(
228 render_pass
, scaled_content_bounds
, shared_quad_state
, append_quads_data
);
230 if (ShowDebugBorders()) {
231 for (PictureLayerTilingSet::CoverageIterator
iter(
234 scaled_visible_content_rect
,
235 ideal_contents_scale_
);
240 if (*iter
&& iter
->IsReadyToDraw()) {
241 TileDrawInfo::Mode mode
= iter
->draw_info().mode();
242 if (mode
== TileDrawInfo::SOLID_COLOR_MODE
) {
243 color
= DebugColors::SolidColorTileBorderColor();
244 width
= DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
245 } else if (mode
== TileDrawInfo::PICTURE_PILE_MODE
) {
246 color
= DebugColors::PictureTileBorderColor();
247 width
= DebugColors::PictureTileBorderWidth(layer_tree_impl());
248 } else if (iter
.resolution() == HIGH_RESOLUTION
) {
249 color
= DebugColors::HighResTileBorderColor();
250 width
= DebugColors::HighResTileBorderWidth(layer_tree_impl());
251 } else if (iter
.resolution() == LOW_RESOLUTION
) {
252 color
= DebugColors::LowResTileBorderColor();
253 width
= DebugColors::LowResTileBorderWidth(layer_tree_impl());
254 } else if (iter
->contents_scale() > max_contents_scale
) {
255 color
= DebugColors::ExtraHighResTileBorderColor();
256 width
= DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
258 color
= DebugColors::ExtraLowResTileBorderColor();
259 width
= DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
262 color
= DebugColors::MissingTileBorderColor();
263 width
= DebugColors::MissingTileBorderWidth(layer_tree_impl());
266 DebugBorderDrawQuad
* debug_border_quad
=
267 render_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
268 gfx::Rect geometry_rect
= iter
.geometry_rect();
269 gfx::Rect visible_geometry_rect
= geometry_rect
;
270 debug_border_quad
->SetNew(shared_quad_state
,
272 visible_geometry_rect
,
278 // Keep track of the tilings that were used so that tilings that are
279 // unused can be considered for removal.
280 std::vector
<PictureLayerTiling
*> seen_tilings
;
282 // Ignore missing tiles outside of viewport for tile priority. This is
283 // normally the same as draw viewport but can be independently overridden by
284 // embedders like Android WebView with SetExternalDrawConstraints.
285 gfx::Rect scaled_viewport_for_tile_priority
= gfx::ScaleToEnclosingRect(
286 viewport_rect_for_tile_priority_in_content_space_
, max_contents_scale
);
288 size_t missing_tile_count
= 0u;
289 size_t on_demand_missing_tile_count
= 0u;
290 only_used_low_res_last_append_quads_
= true;
291 for (PictureLayerTilingSet::CoverageIterator
iter(tilings_
.get(),
293 scaled_visible_content_rect
,
294 ideal_contents_scale_
);
297 gfx::Rect geometry_rect
= iter
.geometry_rect();
298 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
299 gfx::Rect visible_geometry_rect
=
300 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
301 if (visible_geometry_rect
.IsEmpty())
304 append_quads_data
->visible_content_area
+=
305 visible_geometry_rect
.width() * visible_geometry_rect
.height();
307 bool has_draw_quad
= false;
308 if (*iter
&& iter
->IsReadyToDraw()) {
309 const TileDrawInfo
& draw_info
= iter
->draw_info();
310 switch (draw_info
.mode()) {
311 case TileDrawInfo::RESOURCE_MODE
: {
312 gfx::RectF texture_rect
= iter
.texture_rect();
314 // The raster_contents_scale_ is the best scale that the layer is
315 // trying to produce, even though it may not be ideal. Since that's
316 // the best the layer can promise in the future, consider those as
317 // complete. But if a tile is ideal scale, we don't want to consider
318 // it incomplete and trying to replace it with a tile at a worse
320 if (iter
->contents_scale() != raster_contents_scale_
&&
321 iter
->contents_scale() != ideal_contents_scale_
&&
322 geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
323 append_quads_data
->num_incomplete_tiles
++;
327 render_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
328 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
329 visible_geometry_rect
, draw_info
.resource_id(),
330 texture_rect
, draw_info
.resource_size(),
331 draw_info
.contents_swizzled(), nearest_neighbor_
);
332 has_draw_quad
= true;
335 case TileDrawInfo::PICTURE_PILE_MODE
: {
336 if (!layer_tree_impl()
337 ->GetRendererCapabilities()
338 .allow_rasterize_on_demand
) {
339 ++on_demand_missing_tile_count
;
343 gfx::RectF texture_rect
= iter
.texture_rect();
345 ResourceProvider
* resource_provider
=
346 layer_tree_impl()->resource_provider();
347 ResourceFormat format
=
348 resource_provider
->memory_efficient_texture_format();
349 PictureDrawQuad
* quad
=
350 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
351 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
352 visible_geometry_rect
, texture_rect
,
353 iter
->desired_texture_size(), nearest_neighbor_
, format
,
354 iter
->content_rect(), iter
->contents_scale(),
356 has_draw_quad
= true;
359 case TileDrawInfo::SOLID_COLOR_MODE
: {
360 SolidColorDrawQuad
* quad
=
361 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
362 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
363 draw_info
.solid_color(), false);
364 has_draw_quad
= true;
370 if (!has_draw_quad
) {
371 if (draw_checkerboard_for_missing_tiles()) {
372 CheckerboardDrawQuad
* quad
=
373 render_pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
374 SkColor color
= DebugColors::DefaultCheckerboardColor();
376 shared_quad_state
, geometry_rect
, visible_geometry_rect
, color
);
378 SkColor color
= SafeOpaqueBackgroundColor();
379 SolidColorDrawQuad
* quad
=
380 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
381 quad
->SetNew(shared_quad_state
,
383 visible_geometry_rect
,
388 if (geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
389 append_quads_data
->num_missing_tiles
++;
390 ++missing_tile_count
;
392 append_quads_data
->approximated_visible_content_area
+=
393 visible_geometry_rect
.width() * visible_geometry_rect
.height();
397 if (iter
.resolution() != HIGH_RESOLUTION
) {
398 append_quads_data
->approximated_visible_content_area
+=
399 visible_geometry_rect
.width() * visible_geometry_rect
.height();
402 // If we have a draw quad, but it's not low resolution, then
403 // mark that we've used something other than low res to draw.
404 if (iter
.resolution() != LOW_RESOLUTION
)
405 only_used_low_res_last_append_quads_
= false;
407 if (seen_tilings
.empty() || seen_tilings
.back() != iter
.CurrentTiling())
408 seen_tilings
.push_back(iter
.CurrentTiling());
411 if (missing_tile_count
) {
412 TRACE_EVENT_INSTANT2("cc",
413 "PictureLayerImpl::AppendQuads checkerboard",
414 TRACE_EVENT_SCOPE_THREAD
,
415 "missing_tile_count",
417 "on_demand_missing_tile_count",
418 on_demand_missing_tile_count
);
421 // Aggressively remove any tilings that are not seen to save memory. Note
422 // that this is at the expense of doing cause more frequent re-painting. A
423 // better scheme would be to maintain a tighter visible_content_rect for the
425 CleanUpTilingsOnActiveLayer(seen_tilings
);
428 bool PictureLayerImpl::UpdateTiles(const Occlusion
& occlusion_in_content_space
,
429 bool resourceless_software_draw
) {
430 DCHECK_EQ(1.f
, contents_scale_x());
431 DCHECK_EQ(1.f
, contents_scale_y());
433 if (!resourceless_software_draw
) {
434 visible_rect_for_tile_priority_
= visible_content_rect();
437 if (!CanHaveTilings()) {
438 ideal_page_scale_
= 0.f
;
439 ideal_device_scale_
= 0.f
;
440 ideal_contents_scale_
= 0.f
;
441 ideal_source_scale_
= 0.f
;
442 SanityCheckTilingState();
448 if (!raster_contents_scale_
|| ShouldAdjustRasterScale()) {
449 RecalculateRasterScales();
450 AddTilingsForRasterScale();
453 DCHECK(raster_page_scale_
);
454 DCHECK(raster_device_scale_
);
455 DCHECK(raster_source_scale_
);
456 DCHECK(raster_contents_scale_
);
457 DCHECK(low_res_raster_contents_scale_
);
459 was_screen_space_transform_animating_
=
460 draw_properties().screen_space_transform_is_animating
;
462 if (draw_transform_is_animating())
463 raster_source_
->SetShouldAttemptToUseDistanceFieldText();
465 should_update_tile_priorities_
= true;
467 return UpdateTilePriorities(occlusion_in_content_space
);
470 bool PictureLayerImpl::UpdateTilePriorities(
471 const Occlusion
& occlusion_in_content_space
) {
472 DCHECK_IMPLIES(raster_source_
->IsSolidColor(), tilings_
->num_tilings() == 0);
474 double current_frame_time_in_seconds
=
475 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time
-
476 base::TimeTicks()).InSecondsF();
477 UpdateViewportRectForTilePriorityInContentSpace();
479 // The tiling set can require tiles for activation any of the following
480 // conditions are true:
481 // - This layer produced a high-res or non-ideal-res tile last frame.
482 // - We're in requires high res to draw mode.
483 // - We're not in smoothness takes priority mode.
484 // To put different, the tiling set can't require tiles for activation if
485 // we're in smoothness mode and only used low-res or checkerboard to draw last
486 // frame and we don't need high res to draw.
488 // The reason for this is that we should be able to activate sooner and get a
489 // more up to date recording, so we don't run out of recording on the active
491 bool can_require_tiles_for_activation
=
492 !only_used_low_res_last_append_quads_
|| RequiresHighResToDraw() ||
493 !layer_tree_impl()->SmoothnessTakesPriority();
495 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
496 // they are the same space in picture layer, as contents scale is always 1.
497 bool updated
= tilings_
->UpdateTilePriorities(
498 viewport_rect_for_tile_priority_in_content_space_
, ideal_contents_scale_
,
499 current_frame_time_in_seconds
, occlusion_in_content_space
,
500 can_require_tiles_for_activation
);
504 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
505 // If visible_rect_for_tile_priority_ is empty or
506 // viewport_rect_for_tile_priority is set to be different from the device
507 // viewport, try to inverse project the viewport into layer space and use
508 // that. Otherwise just use visible_rect_for_tile_priority_
509 gfx::Rect visible_rect_in_content_space
= visible_rect_for_tile_priority_
;
510 gfx::Rect viewport_rect_for_tile_priority
=
511 layer_tree_impl()->ViewportRectForTilePriority();
512 if (visible_rect_in_content_space
.IsEmpty() ||
513 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority
) {
514 gfx::Transform
view_to_layer(gfx::Transform::kSkipInitialization
);
515 if (screen_space_transform().GetInverse(&view_to_layer
)) {
516 // Transform from view space to content space.
517 visible_rect_in_content_space
=
518 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
519 view_to_layer
, viewport_rect_for_tile_priority
));
522 viewport_rect_for_tile_priority_in_content_space_
=
523 visible_rect_in_content_space
;
526 PictureLayerImpl
* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
527 if (!twin_layer_
|| !twin_layer_
->IsOnActiveOrPendingTree())
532 PictureLayerImpl
* PictureLayerImpl::GetRecycledTwinLayer() const {
533 if (!twin_layer_
|| twin_layer_
->IsOnActiveOrPendingTree())
538 void PictureLayerImpl::UpdateRasterSource(
539 scoped_refptr
<RasterSource
> raster_source
,
540 Region
* new_invalidation
,
541 const PictureLayerTilingSet
* pending_set
) {
542 // The bounds and the pile size may differ if the pile wasn't updated (ie.
543 // PictureLayer::Update didn't happen). In that case the pile will be empty.
544 DCHECK_IMPLIES(!raster_source
->GetSize().IsEmpty(),
545 bounds() == raster_source
->GetSize())
546 << " bounds " << bounds().ToString() << " pile "
547 << raster_source
->GetSize().ToString();
549 // The |raster_source_| is initially null, so have to check for that for the
551 bool could_have_tilings
= raster_source_
.get() && CanHaveTilings();
552 raster_source_
.swap(raster_source
);
554 // The |new_invalidation| must be cleared before updating tilings since they
555 // access the invalidation through the PictureLayerTilingClient interface.
556 invalidation_
.Clear();
557 invalidation_
.Swap(new_invalidation
);
559 bool can_have_tilings
= CanHaveTilings();
561 // Need to call UpdateTiles again if CanHaveTilings changed.
562 if (could_have_tilings
!= can_have_tilings
)
563 layer_tree_impl()->set_needs_update_draw_properties();
565 if (!can_have_tilings
) {
570 // We could do this after doing UpdateTiles, which would avoid doing this for
571 // tilings that are going to disappear on the pending tree (if scale changed).
572 // But that would also be more complicated, so we just do it here for now.
573 tilings_
->UpdateTilingsToCurrentRasterSource(
574 raster_source_
, pending_set
, invalidation_
, MinimumContentsScale(),
575 MaximumContentsScale());
578 void PictureLayerImpl::NotifyTileStateChanged(const Tile
* tile
) {
579 if (layer_tree_impl()->IsActiveTree()) {
580 gfx::RectF layer_damage_rect
=
581 gfx::ScaleRect(tile
->content_rect(), 1.f
/ tile
->contents_scale());
582 AddDamageRect(layer_damage_rect
);
586 void PictureLayerImpl::DidBeginTracing() {
587 raster_source_
->DidBeginTracing();
590 void PictureLayerImpl::ReleaseResources() {
591 // Recreate tilings with new settings, since some of those might change when
592 // we release resources. If tilings_ is null, then leave it as null.
594 tilings_
= CreatePictureLayerTilingSet();
597 // To avoid an edge case after lost context where the tree is up to date but
598 // the tilings have not been managed, request an update draw properties
599 // to force tilings to get managed.
600 layer_tree_impl()->set_needs_update_draw_properties();
603 skia::RefPtr
<SkPicture
> PictureLayerImpl::GetPicture() {
604 return raster_source_
->GetFlattenedPicture();
607 scoped_refptr
<Tile
> PictureLayerImpl::CreateTile(
608 float contents_scale
,
609 const gfx::Rect
& content_rect
) {
612 // We don't handle solid color masks, so we shouldn't bother analyzing those.
613 // Otherwise, always analyze to maximize memory savings.
615 flags
= Tile::USE_PICTURE_ANALYSIS
;
617 return layer_tree_impl()->tile_manager()->CreateTile(
618 raster_source_
.get(), content_rect
.size(), content_rect
, contents_scale
,
619 id(), layer_tree_impl()->source_frame_number(), flags
);
622 const Region
* PictureLayerImpl::GetPendingInvalidation() {
623 if (layer_tree_impl()->IsPendingTree())
624 return &invalidation_
;
625 if (layer_tree_impl()->IsRecycleTree())
627 DCHECK(layer_tree_impl()->IsActiveTree());
628 if (PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer())
629 return &twin_layer
->invalidation_
;
633 const PictureLayerTiling
* PictureLayerImpl::GetPendingOrActiveTwinTiling(
634 const PictureLayerTiling
* tiling
) const {
635 PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer();
638 return twin_layer
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
641 PictureLayerTiling
* PictureLayerImpl::GetRecycledTwinTiling(
642 const PictureLayerTiling
* tiling
) {
643 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
644 if (!recycled_twin
|| !recycled_twin
->tilings_
)
646 return recycled_twin
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
649 TilePriority::PriorityBin
PictureLayerImpl::GetMaxTilePriorityBin() const {
650 if (!HasValidTilePriorities())
651 return TilePriority::EVENTUALLY
;
652 return TilePriority::NOW
;
655 bool PictureLayerImpl::RequiresHighResToDraw() const {
656 return layer_tree_impl()->RequiresHighResToDraw();
659 gfx::Size
PictureLayerImpl::CalculateTileSize(
660 const gfx::Size
& content_bounds
) const {
661 int max_texture_size
=
662 layer_tree_impl()->resource_provider()->max_texture_size();
665 // Masks are not tiled, so if we can't cover the whole mask with one tile,
666 // we shouldn't have such a tiling at all.
667 DCHECK_LE(content_bounds
.width(), max_texture_size
);
668 DCHECK_LE(content_bounds
.height(), max_texture_size
);
669 return content_bounds
;
672 int default_tile_width
= 0;
673 int default_tile_height
= 0;
674 if (layer_tree_impl()->use_gpu_rasterization()) {
675 // For GPU rasterization, we pick an ideal tile size using the viewport
676 // so we don't need any settings. The current approach uses 4 tiles
677 // to cover the viewport vertically.
678 int viewport_width
= layer_tree_impl()->device_viewport_size().width();
679 int viewport_height
= layer_tree_impl()->device_viewport_size().height();
680 default_tile_width
= viewport_width
;
681 // Also, increase the height proportionally as the width decreases, and
682 // pad by our border texels to make the tiles exactly match the viewport.
684 if (content_bounds
.width() <= viewport_width
/ 2)
686 if (content_bounds
.width() <= viewport_width
/ 4)
688 default_tile_height
= RoundUp(viewport_height
, divisor
) / divisor
;
689 default_tile_height
+= 2 * PictureLayerTiling::kBorderTexels
;
690 default_tile_height
=
691 std::max(default_tile_height
, kMinHeightForGpuRasteredTile
);
693 // For CPU rasterization we use tile-size settings.
694 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
695 int max_untiled_content_width
= settings
.max_untiled_layer_size
.width();
696 int max_untiled_content_height
= settings
.max_untiled_layer_size
.height();
697 default_tile_width
= settings
.default_tile_size
.width();
698 default_tile_height
= settings
.default_tile_size
.height();
700 // If the content width is small, increase tile size vertically.
701 // If the content height is small, increase tile size horizontally.
702 // If both are less than the untiled-size, use a single tile.
703 if (content_bounds
.width() < default_tile_width
)
704 default_tile_height
= max_untiled_content_height
;
705 if (content_bounds
.height() < default_tile_height
)
706 default_tile_width
= max_untiled_content_width
;
707 if (content_bounds
.width() < max_untiled_content_width
&&
708 content_bounds
.height() < max_untiled_content_height
) {
709 default_tile_height
= max_untiled_content_height
;
710 default_tile_width
= max_untiled_content_width
;
714 int tile_width
= default_tile_width
;
715 int tile_height
= default_tile_height
;
717 // Clamp the tile width/height to the content width/height to save space.
718 if (content_bounds
.width() < default_tile_width
) {
719 tile_width
= std::min(tile_width
, content_bounds
.width());
720 tile_width
= RoundUp(tile_width
, kTileRoundUp
);
721 tile_width
= std::min(tile_width
, default_tile_width
);
723 if (content_bounds
.height() < default_tile_height
) {
724 tile_height
= std::min(tile_height
, content_bounds
.height());
725 tile_height
= RoundUp(tile_height
, kTileRoundUp
);
726 tile_height
= std::min(tile_height
, default_tile_height
);
729 // Under no circumstance should we be larger than the max texture size.
730 tile_width
= std::min(tile_width
, max_texture_size
);
731 tile_height
= std::min(tile_height
, max_texture_size
);
732 return gfx::Size(tile_width
, tile_height
);
735 void PictureLayerImpl::GetContentsResourceId(
736 ResourceProvider::ResourceId
* resource_id
,
737 gfx::Size
* resource_size
) const {
738 // The bounds and the pile size may differ if the pile wasn't updated (ie.
739 // PictureLayer::Update didn't happen). In that case the pile will be empty.
740 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
741 bounds() == raster_source_
->GetSize())
742 << " bounds " << bounds().ToString() << " pile "
743 << raster_source_
->GetSize().ToString();
744 gfx::Rect
content_rect(bounds());
745 PictureLayerTilingSet::CoverageIterator
iter(
746 tilings_
.get(), 1.f
, content_rect
, ideal_contents_scale_
);
748 // Mask resource not ready yet.
749 if (!iter
|| !*iter
) {
754 // Masks only supported if they fit on exactly one tile.
755 DCHECK(iter
.geometry_rect() == content_rect
)
756 << "iter rect " << iter
.geometry_rect().ToString() << " content rect "
757 << content_rect
.ToString();
759 const TileDrawInfo
& draw_info
= iter
->draw_info();
760 if (!draw_info
.IsReadyToDraw() ||
761 draw_info
.mode() != TileDrawInfo::RESOURCE_MODE
) {
766 *resource_id
= draw_info
.resource_id();
767 *resource_size
= draw_info
.resource_size();
770 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor
) {
771 if (nearest_neighbor_
== nearest_neighbor
)
774 nearest_neighbor_
= nearest_neighbor
;
775 NoteLayerPropertyChanged();
778 PictureLayerTiling
* PictureLayerImpl::AddTiling(float contents_scale
) {
779 DCHECK(CanHaveTilings());
780 DCHECK_GE(contents_scale
, MinimumContentsScale());
781 DCHECK_LE(contents_scale
, MaximumContentsScale());
782 DCHECK(raster_source_
->HasRecordings());
783 return tilings_
->AddTiling(contents_scale
, raster_source_
);
786 void PictureLayerImpl::RemoveAllTilings() {
788 tilings_
->RemoveAllTilings();
789 // If there are no tilings, then raster scales are no longer meaningful.
793 void PictureLayerImpl::AddTilingsForRasterScale() {
794 // Reset all resolution enums on tilings, we'll be setting new values in this
796 tilings_
->MarkAllTilingsNonIdeal();
798 PictureLayerTiling
* high_res
=
799 tilings_
->FindTilingWithScale(raster_contents_scale_
);
800 // We always need a high res tiling, so create one if it doesn't exist.
802 high_res
= AddTiling(raster_contents_scale_
);
804 // Try and find a low res tiling.
805 PictureLayerTiling
* low_res
= nullptr;
806 if (raster_contents_scale_
== low_res_raster_contents_scale_
)
809 low_res
= tilings_
->FindTilingWithScale(low_res_raster_contents_scale_
);
811 // Only create new low res tilings when the transform is static. This
812 // prevents wastefully creating a paired low res tiling for every new high res
813 // tiling during a pinch or a CSS animation.
814 bool can_have_low_res
= layer_tree_impl()->create_low_res_tiling();
815 bool needs_low_res
= !low_res
;
816 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
817 bool is_animating
= draw_properties().screen_space_transform_is_animating
;
818 if (can_have_low_res
&& needs_low_res
&& !is_pinching
&& !is_animating
)
819 low_res
= AddTiling(low_res_raster_contents_scale_
);
821 // Set low-res if we have one.
822 if (low_res
&& low_res
!= high_res
)
823 low_res
->set_resolution(LOW_RESOLUTION
);
825 // Make sure we always have one high-res (even if high == low).
826 high_res
->set_resolution(HIGH_RESOLUTION
);
828 if (layer_tree_impl()->IsPendingTree()) {
829 // On the pending tree, drop any tilings that are non-ideal since we don't
830 // need them to activate anyway.
831 tilings_
->RemoveNonIdealTilings();
834 SanityCheckTilingState();
837 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
838 if (was_screen_space_transform_animating_
!=
839 draw_properties().screen_space_transform_is_animating
)
842 if (draw_properties().screen_space_transform_is_animating
&&
843 raster_contents_scale_
!= ideal_contents_scale_
&&
844 ShouldAdjustRasterScaleDuringScaleAnimations())
847 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
848 if (is_pinching
&& raster_page_scale_
) {
849 // We change our raster scale when it is:
850 // - Higher than ideal (need a lower-res tiling available)
851 // - Too far from ideal (need a higher-res tiling available)
852 float ratio
= ideal_page_scale_
/ raster_page_scale_
;
853 if (raster_page_scale_
> ideal_page_scale_
||
854 ratio
> kMaxScaleRatioDuringPinch
)
859 // When not pinching, match the ideal page scale factor.
860 if (raster_page_scale_
!= ideal_page_scale_
)
864 // Always match the ideal device scale factor.
865 if (raster_device_scale_
!= ideal_device_scale_
)
868 // When the source scale changes we want to match it, but not when animating
869 // or when we've fixed the scale in place.
870 if (!draw_properties().screen_space_transform_is_animating
&&
871 !raster_source_scale_is_fixed_
&&
872 raster_source_scale_
!= ideal_source_scale_
)
875 if (raster_contents_scale_
> MaximumContentsScale())
877 if (raster_contents_scale_
< MinimumContentsScale())
883 void PictureLayerImpl::RecalculateRasterScales() {
884 float old_raster_contents_scale
= raster_contents_scale_
;
885 float old_raster_page_scale
= raster_page_scale_
;
886 float old_raster_source_scale
= raster_source_scale_
;
888 raster_device_scale_
= ideal_device_scale_
;
889 raster_page_scale_
= ideal_page_scale_
;
890 raster_source_scale_
= ideal_source_scale_
;
891 raster_contents_scale_
= ideal_contents_scale_
;
893 // If we're not animating, or leaving an animation, and the
894 // ideal_source_scale_ changes, then things are unpredictable, and we fix
895 // the raster_source_scale_ in place.
896 if (old_raster_source_scale
&&
897 !draw_properties().screen_space_transform_is_animating
&&
898 !was_screen_space_transform_animating_
&&
899 old_raster_source_scale
!= ideal_source_scale_
)
900 raster_source_scale_is_fixed_
= true;
902 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
903 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
904 // tree. This will allow CSS scale changes to get re-rastered at an
905 // appropriate rate. (crbug.com/413636)
906 if (raster_source_scale_is_fixed_
) {
907 raster_contents_scale_
/= raster_source_scale_
;
908 raster_source_scale_
= 1.f
;
911 // During pinch we completely ignore the current ideal scale, and just use
912 // a multiple of the previous scale.
913 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
914 if (is_pinching
&& old_raster_contents_scale
) {
915 // See ShouldAdjustRasterScale:
916 // - When zooming out, preemptively create new tiling at lower resolution.
917 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
918 bool zooming_out
= old_raster_page_scale
> ideal_page_scale_
;
919 float desired_contents_scale
= old_raster_contents_scale
;
921 while (desired_contents_scale
> ideal_contents_scale_
)
922 desired_contents_scale
/= kMaxScaleRatioDuringPinch
;
924 while (desired_contents_scale
< ideal_contents_scale_
)
925 desired_contents_scale
*= kMaxScaleRatioDuringPinch
;
927 raster_contents_scale_
= tilings_
->GetSnappedContentsScale(
928 desired_contents_scale
, kSnapToExistingTilingRatio
);
930 raster_contents_scale_
/ raster_device_scale_
/ raster_source_scale_
;
933 // If we're not re-rasterizing during animation, rasterize at the maximum
934 // scale that will occur during the animation, if the maximum scale is
935 // known. However we want to avoid excessive memory use. If the scale is
936 // smaller than what we would choose otherwise, then it's always better off
937 // for us memory-wise. But otherwise, we don't choose a scale at which this
938 // layer's rastered content would become larger than the viewport.
939 if (draw_properties().screen_space_transform_is_animating
&&
940 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
941 bool can_raster_at_maximum_scale
= false;
942 // TODO(ajuma): If we need to deal with scale-down animations starting right
943 // as a layer gets promoted, then we'd want to have the
944 // |starting_animation_contents_scale| passed in here as a separate draw
945 // property so we could try use that when the max is too large.
946 // See crbug.com/422341.
947 float maximum_scale
= draw_properties().maximum_animation_contents_scale
;
949 gfx::Size bounds_at_maximum_scale
= gfx::ToCeiledSize(
950 gfx::ScaleSize(raster_source_
->GetSize(), maximum_scale
));
951 int64 maximum_area
= static_cast<int64
>(bounds_at_maximum_scale
.width()) *
952 static_cast<int64
>(bounds_at_maximum_scale
.height());
953 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
954 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
955 static_cast<int64
>(viewport
.height());
956 if (maximum_area
<= viewport_area
)
957 can_raster_at_maximum_scale
= true;
959 // Use the computed scales for the raster scale directly, do not try to use
960 // the ideal scale here. The current ideal scale may be way too large in the
961 // case of an animation with scale, and will be constantly changing.
962 if (can_raster_at_maximum_scale
)
963 raster_contents_scale_
= maximum_scale
;
965 raster_contents_scale_
= 1.f
* ideal_page_scale_
* ideal_device_scale_
;
968 raster_contents_scale_
=
969 std::max(raster_contents_scale_
, MinimumContentsScale());
970 raster_contents_scale_
=
971 std::min(raster_contents_scale_
, MaximumContentsScale());
972 DCHECK_GE(raster_contents_scale_
, MinimumContentsScale());
973 DCHECK_LE(raster_contents_scale_
, MaximumContentsScale());
975 // If this layer would create zero or one tiles at this content scale,
976 // don't create a low res tiling.
977 gfx::Size raster_bounds
= gfx::ToCeiledSize(
978 gfx::ScaleSize(raster_source_
->GetSize(), raster_contents_scale_
));
979 gfx::Size tile_size
= CalculateTileSize(raster_bounds
);
980 bool tile_covers_bounds
= tile_size
.width() >= raster_bounds
.width() &&
981 tile_size
.height() >= raster_bounds
.height();
982 if (tile_size
.IsEmpty() || tile_covers_bounds
) {
983 low_res_raster_contents_scale_
= raster_contents_scale_
;
987 float low_res_factor
=
988 layer_tree_impl()->settings().low_res_contents_scale_factor
;
989 low_res_raster_contents_scale_
=
990 std::max(raster_contents_scale_
* low_res_factor
, MinimumContentsScale());
991 DCHECK_LE(low_res_raster_contents_scale_
, raster_contents_scale_
);
992 DCHECK_GE(low_res_raster_contents_scale_
, MinimumContentsScale());
993 DCHECK_LE(low_res_raster_contents_scale_
, MaximumContentsScale());
996 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
997 std::vector
<PictureLayerTiling
*> used_tilings
) {
998 DCHECK(layer_tree_impl()->IsActiveTree());
999 if (tilings_
->num_tilings() == 0)
1002 float min_acceptable_high_res_scale
= std::min(
1003 raster_contents_scale_
, ideal_contents_scale_
);
1004 float max_acceptable_high_res_scale
= std::max(
1005 raster_contents_scale_
, ideal_contents_scale_
);
1007 PictureLayerImpl
* twin
= GetPendingOrActiveTwinLayer();
1008 if (twin
&& twin
->CanHaveTilings()) {
1009 min_acceptable_high_res_scale
= std::min(
1010 min_acceptable_high_res_scale
,
1011 std::min(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1012 max_acceptable_high_res_scale
= std::max(
1013 max_acceptable_high_res_scale
,
1014 std::max(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1017 PictureLayerTilingSet
* twin_set
= twin
? twin
->tilings_
.get() : nullptr;
1018 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
1019 PictureLayerTilingSet
* recycled_twin_set
=
1020 recycled_twin
? recycled_twin
->tilings_
.get() : nullptr;
1022 tilings_
->CleanUpTilings(min_acceptable_high_res_scale
,
1023 max_acceptable_high_res_scale
, used_tilings
,
1024 layer_tree_impl()->create_low_res_tiling(), twin_set
,
1027 if (recycled_twin_set
&& recycled_twin_set
->num_tilings() == 0)
1028 recycled_twin
->ResetRasterScale();
1030 DCHECK_GT(tilings_
->num_tilings(), 0u);
1031 SanityCheckTilingState();
1034 float PictureLayerImpl::MinimumContentsScale() const {
1035 float setting_min
= layer_tree_impl()->settings().minimum_contents_scale
;
1037 // If the contents scale is less than 1 / width (also for height),
1038 // then it will end up having less than one pixel of content in that
1039 // dimension. Bump the minimum contents scale up in this case to prevent
1040 // this from happening.
1041 int min_dimension
= std::min(raster_source_
->GetSize().width(),
1042 raster_source_
->GetSize().height());
1046 return std::max(1.f
/ min_dimension
, setting_min
);
1049 float PictureLayerImpl::MaximumContentsScale() const {
1050 // Masks can not have tilings that would become larger than the
1051 // max_texture_size since they use a single tile for the entire
1052 // tiling. Other layers can have tilings of any scale.
1054 return std::numeric_limits
<float>::max();
1056 int max_texture_size
=
1057 layer_tree_impl()->resource_provider()->max_texture_size();
1058 float max_scale_width
=
1059 static_cast<float>(max_texture_size
) / bounds().width();
1060 float max_scale_height
=
1061 static_cast<float>(max_texture_size
) / bounds().height();
1062 float max_scale
= std::min(max_scale_width
, max_scale_height
);
1063 // We require that multiplying the layer size by the contents scale and
1064 // ceiling produces a value <= |max_texture_size|. Because for large layer
1065 // sizes floating point ambiguity may crop up, making the result larger or
1066 // smaller than expected, we use a slightly smaller floating point value for
1067 // the scale, to help ensure that the resulting content bounds will never end
1068 // up larger than |max_texture_size|.
1069 return nextafterf(max_scale
, 0.f
);
1072 void PictureLayerImpl::ResetRasterScale() {
1073 raster_page_scale_
= 0.f
;
1074 raster_device_scale_
= 0.f
;
1075 raster_source_scale_
= 0.f
;
1076 raster_contents_scale_
= 0.f
;
1077 low_res_raster_contents_scale_
= 0.f
;
1078 raster_source_scale_is_fixed_
= false;
1080 // When raster scales aren't valid, don't update tile priorities until
1081 // this layer has been updated via UpdateDrawProperties.
1082 should_update_tile_priorities_
= false;
1085 bool PictureLayerImpl::CanHaveTilings() const {
1086 if (raster_source_
->IsSolidColor())
1088 if (!DrawsContent())
1090 if (!raster_source_
->HasRecordings())
1092 // If the |raster_source_| has a recording it should have non-empty bounds.
1093 DCHECK(!raster_source_
->GetSize().IsEmpty());
1094 if (MaximumContentsScale() < MinimumContentsScale())
1099 void PictureLayerImpl::SanityCheckTilingState() const {
1101 // Recycle tree doesn't have any restrictions.
1102 if (layer_tree_impl()->IsRecycleTree())
1105 if (!CanHaveTilings()) {
1106 DCHECK_EQ(0u, tilings_
->num_tilings());
1109 if (tilings_
->num_tilings() == 0)
1112 // We should only have one high res tiling.
1113 DCHECK_EQ(1, tilings_
->NumHighResTilings());
1117 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1118 return layer_tree_impl()->use_gpu_rasterization();
1121 float PictureLayerImpl::MaximumTilingContentsScale() const {
1122 float max_contents_scale
= tilings_
->GetMaximumContentsScale();
1123 return std::max(max_contents_scale
, MinimumContentsScale());
1126 scoped_ptr
<PictureLayerTilingSet
>
1127 PictureLayerImpl::CreatePictureLayerTilingSet() {
1128 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
1129 return PictureLayerTilingSet::Create(
1130 this, settings
.max_tiles_for_interest_area
,
1131 layer_tree_impl()->use_gpu_rasterization()
1133 : settings
.skewport_target_time_in_seconds
,
1134 settings
.skewport_extrapolation_limit_in_content_pixels
);
1137 void PictureLayerImpl::UpdateIdealScales() {
1138 DCHECK(CanHaveTilings());
1140 float min_contents_scale
= MinimumContentsScale();
1141 DCHECK_GT(min_contents_scale
, 0.f
);
1142 float min_page_scale
= layer_tree_impl()->min_page_scale_factor();
1143 DCHECK_GT(min_page_scale
, 0.f
);
1144 float min_device_scale
= 1.f
;
1145 float min_source_scale
=
1146 min_contents_scale
/ min_page_scale
/ min_device_scale
;
1148 float ideal_page_scale
= draw_properties().page_scale_factor
;
1149 float ideal_device_scale
= draw_properties().device_scale_factor
;
1150 float ideal_source_scale
= draw_properties().ideal_contents_scale
/
1151 ideal_page_scale
/ ideal_device_scale
;
1152 ideal_contents_scale_
=
1153 std::max(draw_properties().ideal_contents_scale
, min_contents_scale
);
1154 ideal_page_scale_
= draw_properties().page_scale_factor
;
1155 ideal_device_scale_
= draw_properties().device_scale_factor
;
1156 ideal_source_scale_
= std::max(ideal_source_scale
, min_source_scale
);
1159 void PictureLayerImpl::GetDebugBorderProperties(
1161 float* width
) const {
1162 *color
= DebugColors::TiledContentLayerBorderColor();
1163 *width
= DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1166 void PictureLayerImpl::GetAllTilesForTracing(
1167 std::set
<const Tile
*>* tiles
) const {
1170 tilings_
->GetAllTilesForTracing(tiles
);
1173 void PictureLayerImpl::AsValueInto(base::debug::TracedValue
* state
) const {
1174 LayerImpl::AsValueInto(state
);
1175 state
->SetDouble("ideal_contents_scale", ideal_contents_scale_
);
1176 state
->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1177 state
->BeginArray("tilings");
1178 tilings_
->AsValueInto(state
);
1181 MathUtil::AddToTracedValue("tile_priority_rect",
1182 viewport_rect_for_tile_priority_in_content_space_
,
1184 MathUtil::AddToTracedValue("visible_rect", visible_content_rect(), state
);
1186 state
->BeginArray("pictures");
1187 raster_source_
->AsValueInto(state
);
1190 state
->BeginArray("invalidation");
1191 invalidation_
.AsValueInto(state
);
1194 state
->BeginArray("coverage_tiles");
1195 for (PictureLayerTilingSet::CoverageIterator
iter(
1196 tilings_
.get(), 1.f
, gfx::Rect(raster_source_
->GetSize()),
1197 ideal_contents_scale_
);
1199 state
->BeginDictionary();
1201 MathUtil::AddToTracedValue("geometry_rect", iter
.geometry_rect(), state
);
1204 TracedValue::SetIDRef(*iter
, state
, "tile");
1206 state
->EndDictionary();
1211 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1212 return tilings_
->GPUMemoryUsageInBytes();
1215 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1216 benchmark
->RunOnLayer(this);
1219 WhichTree
PictureLayerImpl::GetTree() const {
1220 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
1223 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1224 return !layer_tree_impl()->IsRecycleTree();
1227 bool PictureLayerImpl::HasValidTilePriorities() const {
1228 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();
1231 bool PictureLayerImpl::AllTilesRequiredAreReadyToDraw(
1232 TileRequirementCheck is_tile_required_callback
) const {
1233 if (!HasValidTilePriorities())
1239 if (visible_rect_for_tile_priority_
.IsEmpty())
1242 gfx::Rect rect
= viewport_rect_for_tile_priority_in_content_space_
;
1243 rect
.Intersect(visible_rect_for_tile_priority_
);
1245 // The high resolution tiling is the only tiling that can mark tiles as
1246 // requiring either draw or activation. There is an explicit check in those
1247 // callbacks to return false if they are not high resolution tilings. This
1248 // check needs to remain since there are other callers of that function that
1249 // rely on it. However, for the purposes of this function, we don't have to
1250 // check other tilings.
1251 PictureLayerTiling
* tiling
=
1252 tilings_
->FindTilingWithResolution(HIGH_RESOLUTION
);
1256 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
, rect
); iter
;
1258 const Tile
* tile
= *iter
;
1259 // A null tile (i.e. missing recording) can just be skipped.
1260 // TODO(vmpstr): Verify this is true if we create tiles in raster
1265 // We can't check tile->required_for_activation, because that value might
1266 // be out of date. It is updated in the raster/eviction iterators.
1267 // TODO(vmpstr): Remove the comment once you can't access this information
1269 if ((tiling
->*is_tile_required_callback
)(tile
) && !tile
->IsReadyToDraw()) {
1270 TRACE_EVENT_INSTANT0("cc", "Tile required, but not ready to draw.",
1271 TRACE_EVENT_SCOPE_THREAD
);
1279 bool PictureLayerImpl::AllTilesRequiredForActivationAreReadyToDraw() const {
1280 if (!layer_tree_impl()->IsPendingTree())
1283 return AllTilesRequiredAreReadyToDraw(
1284 &PictureLayerTiling::IsTileRequiredForActivationIfVisible
);
1287 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const {
1288 if (!layer_tree_impl()->IsActiveTree())
1291 return AllTilesRequiredAreReadyToDraw(
1292 &PictureLayerTiling::IsTileRequiredForDrawIfVisible
);