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/time/time.h"
13 #include "base/trace_event/trace_event_argument.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(
69 LayerTreeImpl
* tree_impl
,
72 scoped_refptr
<SyncedScrollOffset
> scroll_offset
)
73 : LayerImpl(tree_impl
, id
, scroll_offset
),
75 tilings_(CreatePictureLayerTilingSet()),
76 ideal_page_scale_(0.f
),
77 ideal_device_scale_(0.f
),
78 ideal_source_scale_(0.f
),
79 ideal_contents_scale_(0.f
),
80 raster_page_scale_(0.f
),
81 raster_device_scale_(0.f
),
82 raster_source_scale_(0.f
),
83 raster_contents_scale_(0.f
),
84 low_res_raster_contents_scale_(0.f
),
85 raster_source_scale_is_fixed_(false),
86 was_screen_space_transform_animating_(false),
87 only_used_low_res_last_append_quads_(false),
89 nearest_neighbor_(false) {
90 layer_tree_impl()->RegisterPictureLayerImpl(this);
93 PictureLayerImpl::~PictureLayerImpl() {
95 twin_layer_
->twin_layer_
= nullptr;
96 layer_tree_impl()->UnregisterPictureLayerImpl(this);
99 const char* PictureLayerImpl::LayerTypeAsString() const {
100 return "cc::PictureLayerImpl";
103 scoped_ptr
<LayerImpl
> PictureLayerImpl::CreateLayerImpl(
104 LayerTreeImpl
* tree_impl
) {
105 return PictureLayerImpl::Create(tree_impl
, id(), is_mask_
,
106 synced_scroll_offset());
109 void PictureLayerImpl::PushPropertiesTo(LayerImpl
* base_layer
) {
110 PictureLayerImpl
* layer_impl
= static_cast<PictureLayerImpl
*>(base_layer
);
111 DCHECK_EQ(layer_impl
->is_mask_
, is_mask_
);
113 LayerImpl::PushPropertiesTo(base_layer
);
115 // Twin relationships should never change once established.
116 DCHECK_IMPLIES(twin_layer_
, twin_layer_
== layer_impl
);
117 DCHECK_IMPLIES(twin_layer_
, layer_impl
->twin_layer_
== this);
118 // The twin relationship does not need to exist before the first
119 // PushPropertiesTo from pending to active layer since before that the active
120 // layer can not have a pile or tilings, it has only been created and inserted
121 // into the tree at that point.
122 twin_layer_
= layer_impl
;
123 layer_impl
->twin_layer_
= this;
125 layer_impl
->SetNearestNeighbor(nearest_neighbor_
);
127 // Solid color layers have no tilings.
128 DCHECK_IMPLIES(raster_source_
->IsSolidColor(), tilings_
->num_tilings() == 0);
129 // The pending tree should only have a high res (and possibly low res) tiling.
130 DCHECK_LE(tilings_
->num_tilings(),
131 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
133 layer_impl
->UpdateRasterSource(raster_source_
, &invalidation_
,
135 DCHECK(invalidation_
.IsEmpty());
137 // After syncing a solid color layer, the active layer has no tilings.
138 DCHECK_IMPLIES(raster_source_
->IsSolidColor(),
139 layer_impl
->tilings_
->num_tilings() == 0);
141 layer_impl
->raster_page_scale_
= raster_page_scale_
;
142 layer_impl
->raster_device_scale_
= raster_device_scale_
;
143 layer_impl
->raster_source_scale_
= raster_source_scale_
;
144 layer_impl
->raster_contents_scale_
= raster_contents_scale_
;
145 layer_impl
->low_res_raster_contents_scale_
= low_res_raster_contents_scale_
;
147 layer_impl
->SanityCheckTilingState();
149 // We always need to push properties.
150 // See http://crbug.com/303943
151 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
152 needs_push_properties_
= true;
155 void PictureLayerImpl::AppendQuads(RenderPass
* render_pass
,
156 const Occlusion
& occlusion_in_content_space
,
157 AppendQuadsData
* append_quads_data
) {
158 // The bounds and the pile size may differ if the pile wasn't updated (ie.
159 // PictureLayer::Update didn't happen). In that case the pile will be empty.
160 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
161 bounds() == raster_source_
->GetSize())
162 << " bounds " << bounds().ToString() << " pile "
163 << raster_source_
->GetSize().ToString();
165 SharedQuadState
* shared_quad_state
=
166 render_pass
->CreateAndAppendSharedQuadState();
168 if (raster_source_
->IsSolidColor()) {
169 PopulateSharedQuadState(shared_quad_state
);
171 AppendDebugBorderQuad(
172 render_pass
, bounds(), shared_quad_state
, append_quads_data
);
174 SolidColorLayerImpl::AppendSolidQuads(
175 render_pass
, occlusion_in_content_space
, shared_quad_state
,
176 visible_content_rect(), raster_source_
->GetSolidColor(),
181 float max_contents_scale
= MaximumTilingContentsScale();
182 gfx::Transform scaled_draw_transform
= draw_transform();
183 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
184 SK_MScalar1
/ max_contents_scale
);
185 gfx::Size scaled_content_bounds
=
186 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), max_contents_scale
));
187 gfx::Rect scaled_visible_content_rect
=
188 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale
);
189 scaled_visible_content_rect
.Intersect(gfx::Rect(scaled_content_bounds
));
190 Occlusion scaled_occlusion
=
191 occlusion_in_content_space
.GetOcclusionWithGivenDrawTransform(
192 scaled_draw_transform
);
194 shared_quad_state
->SetAll(
195 scaled_draw_transform
, scaled_content_bounds
, scaled_visible_content_rect
,
196 draw_properties().clip_rect
, draw_properties().is_clipped
,
197 draw_properties().opacity
, draw_properties().blend_mode
,
198 sorting_context_id_
);
200 if (current_draw_mode_
== DRAW_MODE_RESOURCELESS_SOFTWARE
) {
201 AppendDebugBorderQuad(
203 scaled_content_bounds
,
206 DebugColors::DirectPictureBorderColor(),
207 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
209 gfx::Rect geometry_rect
= scaled_visible_content_rect
;
210 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
211 gfx::Rect visible_geometry_rect
=
212 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
213 if (visible_geometry_rect
.IsEmpty())
216 gfx::Size texture_size
= scaled_visible_content_rect
.size();
217 gfx::RectF texture_rect
= gfx::RectF(texture_size
);
218 gfx::Rect quad_content_rect
= scaled_visible_content_rect
;
220 PictureDrawQuad
* quad
=
221 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
222 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
223 visible_geometry_rect
, texture_rect
, texture_size
,
224 nearest_neighbor_
, RGBA_8888
, quad_content_rect
,
225 max_contents_scale
, raster_source_
);
229 AppendDebugBorderQuad(
230 render_pass
, scaled_content_bounds
, shared_quad_state
, append_quads_data
);
232 if (ShowDebugBorders()) {
233 for (PictureLayerTilingSet::CoverageIterator
iter(
236 scaled_visible_content_rect
,
237 ideal_contents_scale_
);
242 if (*iter
&& iter
->IsReadyToDraw()) {
243 TileDrawInfo::Mode mode
= iter
->draw_info().mode();
244 if (mode
== TileDrawInfo::SOLID_COLOR_MODE
) {
245 color
= DebugColors::SolidColorTileBorderColor();
246 width
= DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
247 } else if (mode
== TileDrawInfo::PICTURE_PILE_MODE
) {
248 color
= DebugColors::PictureTileBorderColor();
249 width
= DebugColors::PictureTileBorderWidth(layer_tree_impl());
250 } else if (iter
.resolution() == HIGH_RESOLUTION
) {
251 color
= DebugColors::HighResTileBorderColor();
252 width
= DebugColors::HighResTileBorderWidth(layer_tree_impl());
253 } else if (iter
.resolution() == LOW_RESOLUTION
) {
254 color
= DebugColors::LowResTileBorderColor();
255 width
= DebugColors::LowResTileBorderWidth(layer_tree_impl());
256 } else if (iter
->contents_scale() > max_contents_scale
) {
257 color
= DebugColors::ExtraHighResTileBorderColor();
258 width
= DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
260 color
= DebugColors::ExtraLowResTileBorderColor();
261 width
= DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
264 color
= DebugColors::MissingTileBorderColor();
265 width
= DebugColors::MissingTileBorderWidth(layer_tree_impl());
268 DebugBorderDrawQuad
* debug_border_quad
=
269 render_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
270 gfx::Rect geometry_rect
= iter
.geometry_rect();
271 gfx::Rect visible_geometry_rect
= geometry_rect
;
272 debug_border_quad
->SetNew(shared_quad_state
,
274 visible_geometry_rect
,
280 // Keep track of the tilings that were used so that tilings that are
281 // unused can be considered for removal.
282 last_append_quads_tilings_
.clear();
284 // Ignore missing tiles outside of viewport for tile priority. This is
285 // normally the same as draw viewport but can be independently overridden by
286 // embedders like Android WebView with SetExternalDrawConstraints.
287 gfx::Rect scaled_viewport_for_tile_priority
= gfx::ScaleToEnclosingRect(
288 viewport_rect_for_tile_priority_in_content_space_
, max_contents_scale
);
290 size_t missing_tile_count
= 0u;
291 size_t on_demand_missing_tile_count
= 0u;
292 only_used_low_res_last_append_quads_
= true;
293 for (PictureLayerTilingSet::CoverageIterator
iter(tilings_
.get(),
295 scaled_visible_content_rect
,
296 ideal_contents_scale_
);
299 gfx::Rect geometry_rect
= iter
.geometry_rect();
300 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
301 gfx::Rect visible_geometry_rect
=
302 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
303 if (visible_geometry_rect
.IsEmpty())
306 append_quads_data
->visible_content_area
+=
307 visible_geometry_rect
.width() * visible_geometry_rect
.height();
309 bool has_draw_quad
= false;
310 if (*iter
&& iter
->IsReadyToDraw()) {
311 const TileDrawInfo
& draw_info
= iter
->draw_info();
312 switch (draw_info
.mode()) {
313 case TileDrawInfo::RESOURCE_MODE
: {
314 gfx::RectF texture_rect
= iter
.texture_rect();
316 // The raster_contents_scale_ is the best scale that the layer is
317 // trying to produce, even though it may not be ideal. Since that's
318 // the best the layer can promise in the future, consider those as
319 // complete. But if a tile is ideal scale, we don't want to consider
320 // it incomplete and trying to replace it with a tile at a worse
322 if (iter
->contents_scale() != raster_contents_scale_
&&
323 iter
->contents_scale() != ideal_contents_scale_
&&
324 geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
325 append_quads_data
->num_incomplete_tiles
++;
329 render_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
330 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
331 visible_geometry_rect
, draw_info
.resource_id(),
332 texture_rect
, draw_info
.resource_size(),
333 draw_info
.contents_swizzled(), nearest_neighbor_
);
334 has_draw_quad
= true;
337 case TileDrawInfo::PICTURE_PILE_MODE
: {
338 if (!layer_tree_impl()
339 ->GetRendererCapabilities()
340 .allow_rasterize_on_demand
) {
341 ++on_demand_missing_tile_count
;
345 gfx::RectF texture_rect
= iter
.texture_rect();
347 ResourceProvider
* resource_provider
=
348 layer_tree_impl()->resource_provider();
349 ResourceFormat format
=
350 resource_provider
->memory_efficient_texture_format();
351 PictureDrawQuad
* quad
=
352 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
353 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
354 visible_geometry_rect
, texture_rect
,
355 iter
->desired_texture_size(), nearest_neighbor_
, format
,
356 iter
->content_rect(), iter
->contents_scale(),
358 has_draw_quad
= true;
361 case TileDrawInfo::SOLID_COLOR_MODE
: {
362 SolidColorDrawQuad
* quad
=
363 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
364 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
365 draw_info
.solid_color(), false);
366 has_draw_quad
= true;
372 if (!has_draw_quad
) {
373 if (draw_checkerboard_for_missing_tiles()) {
374 CheckerboardDrawQuad
* quad
=
375 render_pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
376 SkColor color
= DebugColors::DefaultCheckerboardColor();
378 shared_quad_state
, geometry_rect
, visible_geometry_rect
, color
);
380 SkColor color
= SafeOpaqueBackgroundColor();
381 SolidColorDrawQuad
* quad
=
382 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
383 quad
->SetNew(shared_quad_state
,
385 visible_geometry_rect
,
390 if (geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
391 append_quads_data
->num_missing_tiles
++;
392 ++missing_tile_count
;
394 append_quads_data
->approximated_visible_content_area
+=
395 visible_geometry_rect
.width() * visible_geometry_rect
.height();
399 if (iter
.resolution() != HIGH_RESOLUTION
) {
400 append_quads_data
->approximated_visible_content_area
+=
401 visible_geometry_rect
.width() * visible_geometry_rect
.height();
404 // If we have a draw quad, but it's not low resolution, then
405 // mark that we've used something other than low res to draw.
406 if (iter
.resolution() != LOW_RESOLUTION
)
407 only_used_low_res_last_append_quads_
= false;
409 if (last_append_quads_tilings_
.empty() ||
410 last_append_quads_tilings_
.back() != iter
.CurrentTiling()) {
411 last_append_quads_tilings_
.push_back(iter
.CurrentTiling());
415 if (missing_tile_count
) {
416 TRACE_EVENT_INSTANT2("cc",
417 "PictureLayerImpl::AppendQuads checkerboard",
418 TRACE_EVENT_SCOPE_THREAD
,
419 "missing_tile_count",
421 "on_demand_missing_tile_count",
422 on_demand_missing_tile_count
);
425 // Aggressively remove any tilings that are not seen to save memory. Note
426 // that this is at the expense of doing cause more frequent re-painting. A
427 // better scheme would be to maintain a tighter visible_content_rect for the
429 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
432 bool PictureLayerImpl::UpdateTiles(const Occlusion
& occlusion_in_content_space
,
433 bool resourceless_software_draw
) {
434 DCHECK_EQ(1.f
, contents_scale_x());
435 DCHECK_EQ(1.f
, contents_scale_y());
437 if (!resourceless_software_draw
) {
438 visible_rect_for_tile_priority_
= visible_content_rect();
441 if (!CanHaveTilings()) {
442 ideal_page_scale_
= 0.f
;
443 ideal_device_scale_
= 0.f
;
444 ideal_contents_scale_
= 0.f
;
445 ideal_source_scale_
= 0.f
;
446 SanityCheckTilingState();
450 // Remove any non-ideal tilings that were not used last time we generated
451 // quads to save memory and processing time. Note that pending tree should
452 // only have one or two tilings (high and low res), so only clean up the
453 // active layer. This cleans it up here in case AppendQuads didn't run.
454 // If it did run, this would not remove any additional tilings.
455 if (GetTree() == ACTIVE_TREE
)
456 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
460 if (!raster_contents_scale_
|| ShouldAdjustRasterScale()) {
461 RecalculateRasterScales();
462 AddTilingsForRasterScale();
465 DCHECK(raster_page_scale_
);
466 DCHECK(raster_device_scale_
);
467 DCHECK(raster_source_scale_
);
468 DCHECK(raster_contents_scale_
);
469 DCHECK(low_res_raster_contents_scale_
);
471 was_screen_space_transform_animating_
=
472 draw_properties().screen_space_transform_is_animating
;
474 if (draw_transform_is_animating())
475 raster_source_
->SetShouldAttemptToUseDistanceFieldText();
476 return UpdateTilePriorities(occlusion_in_content_space
);
479 bool PictureLayerImpl::UpdateTilePriorities(
480 const Occlusion
& occlusion_in_content_space
) {
481 DCHECK_IMPLIES(raster_source_
->IsSolidColor(), tilings_
->num_tilings() == 0);
483 double current_frame_time_in_seconds
=
484 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time
-
485 base::TimeTicks()).InSecondsF();
486 UpdateViewportRectForTilePriorityInContentSpace();
488 // The tiling set can require tiles for activation any of the following
489 // conditions are true:
490 // - This layer produced a high-res or non-ideal-res tile last frame.
491 // - We're in requires high res to draw mode.
492 // - We're not in smoothness takes priority mode.
493 // To put different, the tiling set can't require tiles for activation if
494 // we're in smoothness mode and only used low-res or checkerboard to draw last
495 // frame and we don't need high res to draw.
497 // The reason for this is that we should be able to activate sooner and get a
498 // more up to date recording, so we don't run out of recording on the active
500 bool can_require_tiles_for_activation
=
501 !only_used_low_res_last_append_quads_
|| RequiresHighResToDraw() ||
502 !layer_tree_impl()->SmoothnessTakesPriority();
504 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
505 // they are the same space in picture layer, as contents scale is always 1.
506 bool updated
= tilings_
->UpdateTilePriorities(
507 viewport_rect_for_tile_priority_in_content_space_
, ideal_contents_scale_
,
508 current_frame_time_in_seconds
, occlusion_in_content_space
,
509 can_require_tiles_for_activation
);
513 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
514 // If visible_rect_for_tile_priority_ is empty or
515 // viewport_rect_for_tile_priority is set to be different from the device
516 // viewport, try to inverse project the viewport into layer space and use
517 // that. Otherwise just use visible_rect_for_tile_priority_
518 gfx::Rect visible_rect_in_content_space
= visible_rect_for_tile_priority_
;
519 gfx::Rect viewport_rect_for_tile_priority
=
520 layer_tree_impl()->ViewportRectForTilePriority();
521 if (visible_rect_in_content_space
.IsEmpty() ||
522 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority
) {
523 gfx::Transform
view_to_layer(gfx::Transform::kSkipInitialization
);
524 if (screen_space_transform().GetInverse(&view_to_layer
)) {
525 // Transform from view space to content space.
526 visible_rect_in_content_space
=
527 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
528 view_to_layer
, viewport_rect_for_tile_priority
));
531 viewport_rect_for_tile_priority_in_content_space_
=
532 visible_rect_in_content_space
;
535 PictureLayerImpl
* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
536 if (!twin_layer_
|| !twin_layer_
->IsOnActiveOrPendingTree())
541 PictureLayerImpl
* PictureLayerImpl::GetRecycledTwinLayer() const {
542 if (!twin_layer_
|| twin_layer_
->IsOnActiveOrPendingTree())
547 void PictureLayerImpl::UpdateRasterSource(
548 scoped_refptr
<RasterSource
> raster_source
,
549 Region
* new_invalidation
,
550 const PictureLayerTilingSet
* pending_set
) {
551 // The bounds and the pile size may differ if the pile wasn't updated (ie.
552 // PictureLayer::Update didn't happen). In that case the pile will be empty.
553 DCHECK_IMPLIES(!raster_source
->GetSize().IsEmpty(),
554 bounds() == raster_source
->GetSize())
555 << " bounds " << bounds().ToString() << " pile "
556 << raster_source
->GetSize().ToString();
558 // The |raster_source_| is initially null, so have to check for that for the
560 bool could_have_tilings
= raster_source_
.get() && CanHaveTilings();
561 raster_source_
.swap(raster_source
);
563 // The |new_invalidation| must be cleared before updating tilings since they
564 // access the invalidation through the PictureLayerTilingClient interface.
565 invalidation_
.Clear();
566 invalidation_
.Swap(new_invalidation
);
568 bool can_have_tilings
= CanHaveTilings();
571 can_have_tilings
== GetPendingOrActiveTwinLayer()->CanHaveTilings());
573 // Need to call UpdateTiles again if CanHaveTilings changed.
574 if (could_have_tilings
!= can_have_tilings
)
575 layer_tree_impl()->set_needs_update_draw_properties();
577 if (!can_have_tilings
) {
582 // We could do this after doing UpdateTiles, which would avoid doing this for
583 // tilings that are going to disappear on the pending tree (if scale changed).
584 // But that would also be more complicated, so we just do it here for now.
585 tilings_
->UpdateTilingsToCurrentRasterSource(
586 raster_source_
, pending_set
, invalidation_
, MinimumContentsScale(),
587 MaximumContentsScale());
590 void PictureLayerImpl::NotifyTileStateChanged(const Tile
* tile
) {
591 if (layer_tree_impl()->IsActiveTree()) {
592 gfx::RectF layer_damage_rect
=
593 gfx::ScaleRect(tile
->content_rect(), 1.f
/ tile
->contents_scale());
594 AddDamageRect(layer_damage_rect
);
598 void PictureLayerImpl::DidBeginTracing() {
599 raster_source_
->DidBeginTracing();
602 void PictureLayerImpl::ReleaseResources() {
603 // Recreate tilings with new settings, since some of those might change when
604 // we release resources.
609 void PictureLayerImpl::RecreateResources() {
610 tilings_
= CreatePictureLayerTilingSet();
612 // To avoid an edge case after lost context where the tree is up to date but
613 // the tilings have not been managed, request an update draw properties
614 // to force tilings to get managed.
615 layer_tree_impl()->set_needs_update_draw_properties();
618 skia::RefPtr
<SkPicture
> PictureLayerImpl::GetPicture() {
619 return raster_source_
->GetFlattenedPicture();
622 scoped_refptr
<Tile
> PictureLayerImpl::CreateTile(
623 float contents_scale
,
624 const gfx::Rect
& content_rect
) {
627 // We don't handle solid color masks, so we shouldn't bother analyzing those.
628 // Otherwise, always analyze to maximize memory savings.
630 flags
= Tile::USE_PICTURE_ANALYSIS
;
632 return layer_tree_impl()->tile_manager()->CreateTile(
633 raster_source_
.get(), content_rect
.size(), content_rect
, contents_scale
,
634 id(), layer_tree_impl()->source_frame_number(), flags
);
637 const Region
* PictureLayerImpl::GetPendingInvalidation() {
638 if (layer_tree_impl()->IsPendingTree())
639 return &invalidation_
;
640 if (layer_tree_impl()->IsRecycleTree())
642 DCHECK(layer_tree_impl()->IsActiveTree());
643 if (PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer())
644 return &twin_layer
->invalidation_
;
648 const PictureLayerTiling
* PictureLayerImpl::GetPendingOrActiveTwinTiling(
649 const PictureLayerTiling
* tiling
) const {
650 PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer();
653 return twin_layer
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
656 PictureLayerTiling
* PictureLayerImpl::GetRecycledTwinTiling(
657 const PictureLayerTiling
* tiling
) {
658 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
659 if (!recycled_twin
|| !recycled_twin
->tilings_
)
661 return recycled_twin
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
664 TilePriority::PriorityBin
PictureLayerImpl::GetMaxTilePriorityBin() const {
665 if (!HasValidTilePriorities())
666 return TilePriority::EVENTUALLY
;
667 return TilePriority::NOW
;
670 bool PictureLayerImpl::RequiresHighResToDraw() const {
671 return layer_tree_impl()->RequiresHighResToDraw();
674 gfx::Size
PictureLayerImpl::CalculateTileSize(
675 const gfx::Size
& content_bounds
) const {
676 int max_texture_size
=
677 layer_tree_impl()->resource_provider()->max_texture_size();
680 // Masks are not tiled, so if we can't cover the whole mask with one tile,
681 // we shouldn't have such a tiling at all.
682 DCHECK_LE(content_bounds
.width(), max_texture_size
);
683 DCHECK_LE(content_bounds
.height(), max_texture_size
);
684 return content_bounds
;
687 int default_tile_width
= 0;
688 int default_tile_height
= 0;
689 if (layer_tree_impl()->use_gpu_rasterization()) {
690 // For GPU rasterization, we pick an ideal tile size using the viewport
691 // so we don't need any settings. The current approach uses 4 tiles
692 // to cover the viewport vertically.
693 int viewport_width
= layer_tree_impl()->device_viewport_size().width();
694 int viewport_height
= layer_tree_impl()->device_viewport_size().height();
695 default_tile_width
= viewport_width
;
696 // Also, increase the height proportionally as the width decreases, and
697 // pad by our border texels to make the tiles exactly match the viewport.
699 if (content_bounds
.width() <= viewport_width
/ 2)
701 if (content_bounds
.width() <= viewport_width
/ 4)
703 default_tile_height
= RoundUp(viewport_height
, divisor
) / divisor
;
704 default_tile_height
+= 2 * PictureLayerTiling::kBorderTexels
;
705 default_tile_height
=
706 std::max(default_tile_height
, kMinHeightForGpuRasteredTile
);
708 // For CPU rasterization we use tile-size settings.
709 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
710 int max_untiled_content_width
= settings
.max_untiled_layer_size
.width();
711 int max_untiled_content_height
= settings
.max_untiled_layer_size
.height();
712 default_tile_width
= settings
.default_tile_size
.width();
713 default_tile_height
= settings
.default_tile_size
.height();
715 // If the content width is small, increase tile size vertically.
716 // If the content height is small, increase tile size horizontally.
717 // If both are less than the untiled-size, use a single tile.
718 if (content_bounds
.width() < default_tile_width
)
719 default_tile_height
= max_untiled_content_height
;
720 if (content_bounds
.height() < default_tile_height
)
721 default_tile_width
= max_untiled_content_width
;
722 if (content_bounds
.width() < max_untiled_content_width
&&
723 content_bounds
.height() < max_untiled_content_height
) {
724 default_tile_height
= max_untiled_content_height
;
725 default_tile_width
= max_untiled_content_width
;
729 int tile_width
= default_tile_width
;
730 int tile_height
= default_tile_height
;
732 // Clamp the tile width/height to the content width/height to save space.
733 if (content_bounds
.width() < default_tile_width
) {
734 tile_width
= std::min(tile_width
, content_bounds
.width());
735 tile_width
= RoundUp(tile_width
, kTileRoundUp
);
736 tile_width
= std::min(tile_width
, default_tile_width
);
738 if (content_bounds
.height() < default_tile_height
) {
739 tile_height
= std::min(tile_height
, content_bounds
.height());
740 tile_height
= RoundUp(tile_height
, kTileRoundUp
);
741 tile_height
= std::min(tile_height
, default_tile_height
);
744 // Under no circumstance should we be larger than the max texture size.
745 tile_width
= std::min(tile_width
, max_texture_size
);
746 tile_height
= std::min(tile_height
, max_texture_size
);
747 return gfx::Size(tile_width
, tile_height
);
750 void PictureLayerImpl::GetContentsResourceId(
751 ResourceProvider::ResourceId
* resource_id
,
752 gfx::Size
* resource_size
) const {
753 // The bounds and the pile size may differ if the pile wasn't updated (ie.
754 // PictureLayer::Update didn't happen). In that case the pile will be empty.
755 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
756 bounds() == raster_source_
->GetSize())
757 << " bounds " << bounds().ToString() << " pile "
758 << raster_source_
->GetSize().ToString();
759 gfx::Rect
content_rect(bounds());
760 PictureLayerTilingSet::CoverageIterator
iter(
761 tilings_
.get(), 1.f
, content_rect
, ideal_contents_scale_
);
763 // Mask resource not ready yet.
764 if (!iter
|| !*iter
) {
769 // Masks only supported if they fit on exactly one tile.
770 DCHECK(iter
.geometry_rect() == content_rect
)
771 << "iter rect " << iter
.geometry_rect().ToString() << " content rect "
772 << content_rect
.ToString();
774 const TileDrawInfo
& draw_info
= iter
->draw_info();
775 if (!draw_info
.IsReadyToDraw() ||
776 draw_info
.mode() != TileDrawInfo::RESOURCE_MODE
) {
781 *resource_id
= draw_info
.resource_id();
782 *resource_size
= draw_info
.resource_size();
785 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor
) {
786 if (nearest_neighbor_
== nearest_neighbor
)
789 nearest_neighbor_
= nearest_neighbor
;
790 NoteLayerPropertyChanged();
793 PictureLayerTiling
* PictureLayerImpl::AddTiling(float contents_scale
) {
794 DCHECK(CanHaveTilings());
795 DCHECK_GE(contents_scale
, MinimumContentsScale());
796 DCHECK_LE(contents_scale
, MaximumContentsScale());
797 DCHECK(raster_source_
->HasRecordings());
798 return tilings_
->AddTiling(contents_scale
, raster_source_
);
801 void PictureLayerImpl::RemoveAllTilings() {
802 tilings_
->RemoveAllTilings();
803 // If there are no tilings, then raster scales are no longer meaningful.
807 void PictureLayerImpl::AddTilingsForRasterScale() {
808 // Reset all resolution enums on tilings, we'll be setting new values in this
810 tilings_
->MarkAllTilingsNonIdeal();
812 PictureLayerTiling
* high_res
=
813 tilings_
->FindTilingWithScale(raster_contents_scale_
);
814 // We always need a high res tiling, so create one if it doesn't exist.
816 high_res
= AddTiling(raster_contents_scale_
);
818 // Try and find a low res tiling.
819 PictureLayerTiling
* low_res
= nullptr;
820 if (raster_contents_scale_
== low_res_raster_contents_scale_
)
823 low_res
= tilings_
->FindTilingWithScale(low_res_raster_contents_scale_
);
825 // Only create new low res tilings when the transform is static. This
826 // prevents wastefully creating a paired low res tiling for every new high res
827 // tiling during a pinch or a CSS animation.
828 bool can_have_low_res
= layer_tree_impl()->create_low_res_tiling();
829 bool needs_low_res
= !low_res
;
830 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
831 bool is_animating
= draw_properties().screen_space_transform_is_animating
;
832 if (can_have_low_res
&& needs_low_res
&& !is_pinching
&& !is_animating
)
833 low_res
= AddTiling(low_res_raster_contents_scale_
);
835 // Set low-res if we have one.
836 if (low_res
&& low_res
!= high_res
)
837 low_res
->set_resolution(LOW_RESOLUTION
);
839 // Make sure we always have one high-res (even if high == low).
840 high_res
->set_resolution(HIGH_RESOLUTION
);
842 if (layer_tree_impl()->IsPendingTree()) {
843 // On the pending tree, drop any tilings that are non-ideal since we don't
844 // need them to activate anyway.
845 tilings_
->RemoveNonIdealTilings();
848 SanityCheckTilingState();
851 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
852 if (was_screen_space_transform_animating_
!=
853 draw_properties().screen_space_transform_is_animating
)
856 if (draw_properties().screen_space_transform_is_animating
&&
857 raster_contents_scale_
!= ideal_contents_scale_
&&
858 ShouldAdjustRasterScaleDuringScaleAnimations())
861 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
862 if (is_pinching
&& raster_page_scale_
) {
863 // We change our raster scale when it is:
864 // - Higher than ideal (need a lower-res tiling available)
865 // - Too far from ideal (need a higher-res tiling available)
866 float ratio
= ideal_page_scale_
/ raster_page_scale_
;
867 if (raster_page_scale_
> ideal_page_scale_
||
868 ratio
> kMaxScaleRatioDuringPinch
)
873 // When not pinching, match the ideal page scale factor.
874 if (raster_page_scale_
!= ideal_page_scale_
)
878 // Always match the ideal device scale factor.
879 if (raster_device_scale_
!= ideal_device_scale_
)
882 // When the source scale changes we want to match it, but not when animating
883 // or when we've fixed the scale in place.
884 if (!draw_properties().screen_space_transform_is_animating
&&
885 !raster_source_scale_is_fixed_
&&
886 raster_source_scale_
!= ideal_source_scale_
)
889 if (raster_contents_scale_
> MaximumContentsScale())
891 if (raster_contents_scale_
< MinimumContentsScale())
897 void PictureLayerImpl::RecalculateRasterScales() {
898 float old_raster_contents_scale
= raster_contents_scale_
;
899 float old_raster_page_scale
= raster_page_scale_
;
900 float old_raster_source_scale
= raster_source_scale_
;
902 raster_device_scale_
= ideal_device_scale_
;
903 raster_page_scale_
= ideal_page_scale_
;
904 raster_source_scale_
= ideal_source_scale_
;
905 raster_contents_scale_
= ideal_contents_scale_
;
907 // If we're not animating, or leaving an animation, and the
908 // ideal_source_scale_ changes, then things are unpredictable, and we fix
909 // the raster_source_scale_ in place.
910 if (old_raster_source_scale
&&
911 !draw_properties().screen_space_transform_is_animating
&&
912 !was_screen_space_transform_animating_
&&
913 old_raster_source_scale
!= ideal_source_scale_
)
914 raster_source_scale_is_fixed_
= true;
916 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
917 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
918 // tree. This will allow CSS scale changes to get re-rastered at an
919 // appropriate rate. (crbug.com/413636)
920 if (raster_source_scale_is_fixed_
) {
921 raster_contents_scale_
/= raster_source_scale_
;
922 raster_source_scale_
= 1.f
;
925 // During pinch we completely ignore the current ideal scale, and just use
926 // a multiple of the previous scale.
927 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
928 if (is_pinching
&& old_raster_contents_scale
) {
929 // See ShouldAdjustRasterScale:
930 // - When zooming out, preemptively create new tiling at lower resolution.
931 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
932 bool zooming_out
= old_raster_page_scale
> ideal_page_scale_
;
933 float desired_contents_scale
= old_raster_contents_scale
;
935 while (desired_contents_scale
> ideal_contents_scale_
)
936 desired_contents_scale
/= kMaxScaleRatioDuringPinch
;
938 while (desired_contents_scale
< ideal_contents_scale_
)
939 desired_contents_scale
*= kMaxScaleRatioDuringPinch
;
941 raster_contents_scale_
= tilings_
->GetSnappedContentsScale(
942 desired_contents_scale
, kSnapToExistingTilingRatio
);
944 raster_contents_scale_
/ raster_device_scale_
/ raster_source_scale_
;
947 // If we're not re-rasterizing during animation, rasterize at the maximum
948 // scale that will occur during the animation, if the maximum scale is
949 // known. However we want to avoid excessive memory use. If the scale is
950 // smaller than what we would choose otherwise, then it's always better off
951 // for us memory-wise. But otherwise, we don't choose a scale at which this
952 // layer's rastered content would become larger than the viewport.
953 if (draw_properties().screen_space_transform_is_animating
&&
954 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
955 bool can_raster_at_maximum_scale
= false;
956 // TODO(ajuma): If we need to deal with scale-down animations starting right
957 // as a layer gets promoted, then we'd want to have the
958 // |starting_animation_contents_scale| passed in here as a separate draw
959 // property so we could try use that when the max is too large.
960 // See crbug.com/422341.
961 float maximum_scale
= draw_properties().maximum_animation_contents_scale
;
963 gfx::Size bounds_at_maximum_scale
= gfx::ToCeiledSize(
964 gfx::ScaleSize(raster_source_
->GetSize(), maximum_scale
));
965 int64 maximum_area
= static_cast<int64
>(bounds_at_maximum_scale
.width()) *
966 static_cast<int64
>(bounds_at_maximum_scale
.height());
967 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
968 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
969 static_cast<int64
>(viewport
.height());
970 if (maximum_area
<= viewport_area
)
971 can_raster_at_maximum_scale
= true;
973 // Use the computed scales for the raster scale directly, do not try to use
974 // the ideal scale here. The current ideal scale may be way too large in the
975 // case of an animation with scale, and will be constantly changing.
976 if (can_raster_at_maximum_scale
)
977 raster_contents_scale_
= maximum_scale
;
979 raster_contents_scale_
= 1.f
* ideal_page_scale_
* ideal_device_scale_
;
982 raster_contents_scale_
=
983 std::max(raster_contents_scale_
, MinimumContentsScale());
984 raster_contents_scale_
=
985 std::min(raster_contents_scale_
, MaximumContentsScale());
986 DCHECK_GE(raster_contents_scale_
, MinimumContentsScale());
987 DCHECK_LE(raster_contents_scale_
, MaximumContentsScale());
989 // If this layer would create zero or one tiles at this content scale,
990 // don't create a low res tiling.
991 gfx::Size raster_bounds
= gfx::ToCeiledSize(
992 gfx::ScaleSize(raster_source_
->GetSize(), raster_contents_scale_
));
993 gfx::Size tile_size
= CalculateTileSize(raster_bounds
);
994 bool tile_covers_bounds
= tile_size
.width() >= raster_bounds
.width() &&
995 tile_size
.height() >= raster_bounds
.height();
996 if (tile_size
.IsEmpty() || tile_covers_bounds
) {
997 low_res_raster_contents_scale_
= raster_contents_scale_
;
1001 float low_res_factor
=
1002 layer_tree_impl()->settings().low_res_contents_scale_factor
;
1003 low_res_raster_contents_scale_
=
1004 std::max(raster_contents_scale_
* low_res_factor
, MinimumContentsScale());
1005 DCHECK_LE(low_res_raster_contents_scale_
, raster_contents_scale_
);
1006 DCHECK_GE(low_res_raster_contents_scale_
, MinimumContentsScale());
1007 DCHECK_LE(low_res_raster_contents_scale_
, MaximumContentsScale());
1010 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
1011 const std::vector
<PictureLayerTiling
*>& used_tilings
) {
1012 DCHECK(layer_tree_impl()->IsActiveTree());
1013 if (tilings_
->num_tilings() == 0)
1016 float min_acceptable_high_res_scale
= std::min(
1017 raster_contents_scale_
, ideal_contents_scale_
);
1018 float max_acceptable_high_res_scale
= std::max(
1019 raster_contents_scale_
, ideal_contents_scale_
);
1021 PictureLayerImpl
* twin
= GetPendingOrActiveTwinLayer();
1022 if (twin
&& twin
->CanHaveTilings()) {
1023 min_acceptable_high_res_scale
= std::min(
1024 min_acceptable_high_res_scale
,
1025 std::min(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1026 max_acceptable_high_res_scale
= std::max(
1027 max_acceptable_high_res_scale
,
1028 std::max(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1031 PictureLayerTilingSet
* twin_set
= twin
? twin
->tilings_
.get() : nullptr;
1032 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
1033 PictureLayerTilingSet
* recycled_twin_set
=
1034 recycled_twin
? recycled_twin
->tilings_
.get() : nullptr;
1036 tilings_
->CleanUpTilings(min_acceptable_high_res_scale
,
1037 max_acceptable_high_res_scale
, used_tilings
,
1038 layer_tree_impl()->create_low_res_tiling(), twin_set
,
1041 if (recycled_twin_set
&& recycled_twin_set
->num_tilings() == 0)
1042 recycled_twin
->ResetRasterScale();
1044 DCHECK_GT(tilings_
->num_tilings(), 0u);
1045 SanityCheckTilingState();
1048 float PictureLayerImpl::MinimumContentsScale() const {
1049 float setting_min
= layer_tree_impl()->settings().minimum_contents_scale
;
1051 // If the contents scale is less than 1 / width (also for height),
1052 // then it will end up having less than one pixel of content in that
1053 // dimension. Bump the minimum contents scale up in this case to prevent
1054 // this from happening.
1055 int min_dimension
= std::min(raster_source_
->GetSize().width(),
1056 raster_source_
->GetSize().height());
1060 return std::max(1.f
/ min_dimension
, setting_min
);
1063 float PictureLayerImpl::MaximumContentsScale() const {
1064 // Masks can not have tilings that would become larger than the
1065 // max_texture_size since they use a single tile for the entire
1066 // tiling. Other layers can have tilings of any scale.
1068 return std::numeric_limits
<float>::max();
1070 int max_texture_size
=
1071 layer_tree_impl()->resource_provider()->max_texture_size();
1072 float max_scale_width
=
1073 static_cast<float>(max_texture_size
) / bounds().width();
1074 float max_scale_height
=
1075 static_cast<float>(max_texture_size
) / bounds().height();
1076 float max_scale
= std::min(max_scale_width
, max_scale_height
);
1077 // We require that multiplying the layer size by the contents scale and
1078 // ceiling produces a value <= |max_texture_size|. Because for large layer
1079 // sizes floating point ambiguity may crop up, making the result larger or
1080 // smaller than expected, we use a slightly smaller floating point value for
1081 // the scale, to help ensure that the resulting content bounds will never end
1082 // up larger than |max_texture_size|.
1083 return nextafterf(max_scale
, 0.f
);
1086 void PictureLayerImpl::ResetRasterScale() {
1087 raster_page_scale_
= 0.f
;
1088 raster_device_scale_
= 0.f
;
1089 raster_source_scale_
= 0.f
;
1090 raster_contents_scale_
= 0.f
;
1091 low_res_raster_contents_scale_
= 0.f
;
1092 raster_source_scale_is_fixed_
= false;
1095 bool PictureLayerImpl::CanHaveTilings() const {
1096 if (raster_source_
->IsSolidColor())
1098 if (!DrawsContent())
1100 if (!raster_source_
->HasRecordings())
1102 // If the |raster_source_| has a recording it should have non-empty bounds.
1103 DCHECK(!raster_source_
->GetSize().IsEmpty());
1104 if (MaximumContentsScale() < MinimumContentsScale())
1109 void PictureLayerImpl::SanityCheckTilingState() const {
1111 // Recycle tree doesn't have any restrictions.
1112 if (layer_tree_impl()->IsRecycleTree())
1115 if (!CanHaveTilings()) {
1116 DCHECK_EQ(0u, tilings_
->num_tilings());
1119 if (tilings_
->num_tilings() == 0)
1122 // We should only have one high res tiling.
1123 DCHECK_EQ(1, tilings_
->NumHighResTilings());
1127 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1128 return layer_tree_impl()->use_gpu_rasterization();
1131 float PictureLayerImpl::MaximumTilingContentsScale() const {
1132 float max_contents_scale
= tilings_
->GetMaximumContentsScale();
1133 return std::max(max_contents_scale
, MinimumContentsScale());
1136 scoped_ptr
<PictureLayerTilingSet
>
1137 PictureLayerImpl::CreatePictureLayerTilingSet() {
1138 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
1139 return PictureLayerTilingSet::Create(
1140 this, settings
.max_tiles_for_interest_area
,
1141 layer_tree_impl()->use_gpu_rasterization()
1143 : settings
.skewport_target_time_in_seconds
,
1144 settings
.skewport_extrapolation_limit_in_content_pixels
);
1147 void PictureLayerImpl::UpdateIdealScales() {
1148 DCHECK(CanHaveTilings());
1150 float min_contents_scale
= MinimumContentsScale();
1151 DCHECK_GT(min_contents_scale
, 0.f
);
1152 float min_page_scale
= layer_tree_impl()->min_page_scale_factor();
1153 DCHECK_GT(min_page_scale
, 0.f
);
1154 float min_device_scale
= 1.f
;
1155 float min_source_scale
=
1156 min_contents_scale
/ min_page_scale
/ min_device_scale
;
1158 float ideal_page_scale
= draw_properties().page_scale_factor
;
1159 float ideal_device_scale
= draw_properties().device_scale_factor
;
1160 float ideal_source_scale
= draw_properties().ideal_contents_scale
/
1161 ideal_page_scale
/ ideal_device_scale
;
1162 ideal_contents_scale_
=
1163 std::max(draw_properties().ideal_contents_scale
, min_contents_scale
);
1164 ideal_page_scale_
= draw_properties().page_scale_factor
;
1165 ideal_device_scale_
= draw_properties().device_scale_factor
;
1166 ideal_source_scale_
= std::max(ideal_source_scale
, min_source_scale
);
1169 void PictureLayerImpl::GetDebugBorderProperties(
1171 float* width
) const {
1172 *color
= DebugColors::TiledContentLayerBorderColor();
1173 *width
= DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1176 void PictureLayerImpl::GetAllTilesForTracing(
1177 std::set
<const Tile
*>* tiles
) const {
1180 tilings_
->GetAllTilesForTracing(tiles
);
1183 void PictureLayerImpl::AsValueInto(base::debug::TracedValue
* state
) const {
1184 LayerImpl::AsValueInto(state
);
1185 state
->SetDouble("ideal_contents_scale", ideal_contents_scale_
);
1186 state
->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1187 state
->BeginArray("tilings");
1188 tilings_
->AsValueInto(state
);
1191 MathUtil::AddToTracedValue("tile_priority_rect",
1192 viewport_rect_for_tile_priority_in_content_space_
,
1194 MathUtil::AddToTracedValue("visible_rect", visible_content_rect(), state
);
1196 state
->BeginArray("pictures");
1197 raster_source_
->AsValueInto(state
);
1200 state
->BeginArray("invalidation");
1201 invalidation_
.AsValueInto(state
);
1204 state
->BeginArray("coverage_tiles");
1205 for (PictureLayerTilingSet::CoverageIterator
iter(
1206 tilings_
.get(), 1.f
, gfx::Rect(raster_source_
->GetSize()),
1207 ideal_contents_scale_
);
1209 state
->BeginDictionary();
1211 MathUtil::AddToTracedValue("geometry_rect", iter
.geometry_rect(), state
);
1214 TracedValue::SetIDRef(*iter
, state
, "tile");
1216 state
->EndDictionary();
1221 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1222 return tilings_
->GPUMemoryUsageInBytes();
1225 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1226 benchmark
->RunOnLayer(this);
1229 WhichTree
PictureLayerImpl::GetTree() const {
1230 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
1233 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1234 return !layer_tree_impl()->IsRecycleTree();
1237 bool PictureLayerImpl::HasValidTilePriorities() const {
1238 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();