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
->set_gpu_raster_max_texture_size(gpu_raster_max_texture_size_
);
134 layer_impl
->UpdateRasterSource(raster_source_
, &invalidation_
,
136 DCHECK(invalidation_
.IsEmpty());
138 // After syncing a solid color layer, the active layer has no tilings.
139 DCHECK_IMPLIES(raster_source_
->IsSolidColor(),
140 layer_impl
->tilings_
->num_tilings() == 0);
142 layer_impl
->raster_page_scale_
= raster_page_scale_
;
143 layer_impl
->raster_device_scale_
= raster_device_scale_
;
144 layer_impl
->raster_source_scale_
= raster_source_scale_
;
145 layer_impl
->raster_contents_scale_
= raster_contents_scale_
;
146 layer_impl
->low_res_raster_contents_scale_
= low_res_raster_contents_scale_
;
148 layer_impl
->SanityCheckTilingState();
150 // We always need to push properties.
151 // See http://crbug.com/303943
152 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
153 needs_push_properties_
= true;
156 void PictureLayerImpl::AppendQuads(RenderPass
* render_pass
,
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
, draw_properties().occlusion_in_content_space
,
176 shared_quad_state
, visible_content_rect(),
177 raster_source_
->GetSolidColor(), append_quads_data
);
181 float max_contents_scale
= MaximumTilingContentsScale();
182 PopulateScaledSharedQuadState(shared_quad_state
, max_contents_scale
);
183 Occlusion scaled_occlusion
=
185 .occlusion_in_content_space
.GetOcclusionWithGivenDrawTransform(
186 shared_quad_state
->content_to_target_transform
);
188 if (current_draw_mode_
== DRAW_MODE_RESOURCELESS_SOFTWARE
) {
189 AppendDebugBorderQuad(
190 render_pass
, shared_quad_state
->content_bounds
, shared_quad_state
,
191 append_quads_data
, DebugColors::DirectPictureBorderColor(),
192 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
194 gfx::Rect geometry_rect
= shared_quad_state
->visible_content_rect
;
195 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
196 gfx::Rect visible_geometry_rect
=
197 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
198 if (visible_geometry_rect
.IsEmpty())
201 gfx::Rect quad_content_rect
= shared_quad_state
->visible_content_rect
;
202 gfx::Size texture_size
= quad_content_rect
.size();
203 gfx::RectF texture_rect
= gfx::RectF(texture_size
);
205 PictureDrawQuad
* quad
=
206 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
207 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
208 visible_geometry_rect
, texture_rect
, texture_size
,
209 nearest_neighbor_
, RGBA_8888
, quad_content_rect
,
210 max_contents_scale
, raster_source_
);
211 ValidateQuadResources(quad
);
215 AppendDebugBorderQuad(render_pass
, shared_quad_state
->content_bounds
,
216 shared_quad_state
, append_quads_data
);
218 if (ShowDebugBorders()) {
219 for (PictureLayerTilingSet::CoverageIterator
iter(
220 tilings_
.get(), max_contents_scale
,
221 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
225 if (*iter
&& iter
->IsReadyToDraw()) {
226 TileDrawInfo::Mode mode
= iter
->draw_info().mode();
227 if (mode
== TileDrawInfo::SOLID_COLOR_MODE
) {
228 color
= DebugColors::SolidColorTileBorderColor();
229 width
= DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
230 } else if (mode
== TileDrawInfo::OOM_MODE
) {
231 color
= DebugColors::OOMTileBorderColor();
232 width
= DebugColors::OOMTileBorderWidth(layer_tree_impl());
233 } else if (iter
.resolution() == HIGH_RESOLUTION
) {
234 color
= DebugColors::HighResTileBorderColor();
235 width
= DebugColors::HighResTileBorderWidth(layer_tree_impl());
236 } else if (iter
.resolution() == LOW_RESOLUTION
) {
237 color
= DebugColors::LowResTileBorderColor();
238 width
= DebugColors::LowResTileBorderWidth(layer_tree_impl());
239 } else if (iter
->contents_scale() > max_contents_scale
) {
240 color
= DebugColors::ExtraHighResTileBorderColor();
241 width
= DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
243 color
= DebugColors::ExtraLowResTileBorderColor();
244 width
= DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
247 color
= DebugColors::MissingTileBorderColor();
248 width
= DebugColors::MissingTileBorderWidth(layer_tree_impl());
251 DebugBorderDrawQuad
* debug_border_quad
=
252 render_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
253 gfx::Rect geometry_rect
= iter
.geometry_rect();
254 gfx::Rect visible_geometry_rect
= geometry_rect
;
255 debug_border_quad
->SetNew(shared_quad_state
,
257 visible_geometry_rect
,
263 // Keep track of the tilings that were used so that tilings that are
264 // unused can be considered for removal.
265 last_append_quads_tilings_
.clear();
267 // Ignore missing tiles outside of viewport for tile priority. This is
268 // normally the same as draw viewport but can be independently overridden by
269 // embedders like Android WebView with SetExternalDrawConstraints.
270 gfx::Rect scaled_viewport_for_tile_priority
= gfx::ScaleToEnclosingRect(
271 viewport_rect_for_tile_priority_in_content_space_
, max_contents_scale
);
273 size_t missing_tile_count
= 0u;
274 size_t on_demand_missing_tile_count
= 0u;
275 only_used_low_res_last_append_quads_
= true;
276 for (PictureLayerTilingSet::CoverageIterator
iter(
277 tilings_
.get(), max_contents_scale
,
278 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
280 gfx::Rect geometry_rect
= iter
.geometry_rect();
281 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
282 gfx::Rect visible_geometry_rect
=
283 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
284 if (visible_geometry_rect
.IsEmpty())
287 append_quads_data
->visible_content_area
+=
288 visible_geometry_rect
.width() * visible_geometry_rect
.height();
290 bool has_draw_quad
= false;
291 if (*iter
&& iter
->IsReadyToDraw()) {
292 const TileDrawInfo
& draw_info
= iter
->draw_info();
293 switch (draw_info
.mode()) {
294 case TileDrawInfo::RESOURCE_MODE
: {
295 gfx::RectF texture_rect
= iter
.texture_rect();
297 // The raster_contents_scale_ is the best scale that the layer is
298 // trying to produce, even though it may not be ideal. Since that's
299 // the best the layer can promise in the future, consider those as
300 // complete. But if a tile is ideal scale, we don't want to consider
301 // it incomplete and trying to replace it with a tile at a worse
303 if (iter
->contents_scale() != raster_contents_scale_
&&
304 iter
->contents_scale() != ideal_contents_scale_
&&
305 geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
306 append_quads_data
->num_incomplete_tiles
++;
310 render_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
311 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
312 visible_geometry_rect
, draw_info
.resource_id(),
313 texture_rect
, draw_info
.resource_size(),
314 draw_info
.contents_swizzled(), nearest_neighbor_
);
315 ValidateQuadResources(quad
);
316 has_draw_quad
= true;
319 case TileDrawInfo::SOLID_COLOR_MODE
: {
320 SolidColorDrawQuad
* quad
=
321 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
322 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
323 draw_info
.solid_color(), false);
324 ValidateQuadResources(quad
);
325 has_draw_quad
= true;
328 case TileDrawInfo::OOM_MODE
:
329 break; // Checkerboard.
333 if (!has_draw_quad
) {
334 if (draw_checkerboard_for_missing_tiles()) {
335 CheckerboardDrawQuad
* quad
=
336 render_pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
337 SkColor color
= DebugColors::DefaultCheckerboardColor();
338 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
339 color
, draw_properties().device_scale_factor
);
341 SkColor color
= SafeOpaqueBackgroundColor();
342 SolidColorDrawQuad
* quad
=
343 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
344 quad
->SetNew(shared_quad_state
,
346 visible_geometry_rect
,
349 ValidateQuadResources(quad
);
352 if (geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
353 append_quads_data
->num_missing_tiles
++;
354 ++missing_tile_count
;
356 append_quads_data
->approximated_visible_content_area
+=
357 visible_geometry_rect
.width() * visible_geometry_rect
.height();
358 append_quads_data
->checkerboarded_visible_content_area
+=
359 visible_geometry_rect
.width() * visible_geometry_rect
.height();
363 if (iter
.resolution() != HIGH_RESOLUTION
) {
364 append_quads_data
->approximated_visible_content_area
+=
365 visible_geometry_rect
.width() * visible_geometry_rect
.height();
368 // If we have a draw quad, but it's not low resolution, then
369 // mark that we've used something other than low res to draw.
370 if (iter
.resolution() != LOW_RESOLUTION
)
371 only_used_low_res_last_append_quads_
= false;
373 if (last_append_quads_tilings_
.empty() ||
374 last_append_quads_tilings_
.back() != iter
.CurrentTiling()) {
375 last_append_quads_tilings_
.push_back(iter
.CurrentTiling());
379 if (missing_tile_count
) {
380 TRACE_EVENT_INSTANT2("cc",
381 "PictureLayerImpl::AppendQuads checkerboard",
382 TRACE_EVENT_SCOPE_THREAD
,
383 "missing_tile_count",
385 "on_demand_missing_tile_count",
386 on_demand_missing_tile_count
);
389 // Aggressively remove any tilings that are not seen to save memory. Note
390 // that this is at the expense of doing cause more frequent re-painting. A
391 // better scheme would be to maintain a tighter visible_content_rect for the
393 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
396 bool PictureLayerImpl::UpdateTiles(bool resourceless_software_draw
) {
397 DCHECK_EQ(1.f
, contents_scale_x());
398 DCHECK_EQ(1.f
, contents_scale_y());
400 if (!resourceless_software_draw
) {
401 visible_rect_for_tile_priority_
= visible_content_rect();
404 if (!CanHaveTilings()) {
405 ideal_page_scale_
= 0.f
;
406 ideal_device_scale_
= 0.f
;
407 ideal_contents_scale_
= 0.f
;
408 ideal_source_scale_
= 0.f
;
409 SanityCheckTilingState();
413 // Remove any non-ideal tilings that were not used last time we generated
414 // quads to save memory and processing time. Note that pending tree should
415 // only have one or two tilings (high and low res), so only clean up the
416 // active layer. This cleans it up here in case AppendQuads didn't run.
417 // If it did run, this would not remove any additional tilings.
418 if (layer_tree_impl()->IsActiveTree())
419 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
423 if (!raster_contents_scale_
|| ShouldAdjustRasterScale()) {
424 RecalculateRasterScales();
425 AddTilingsForRasterScale();
428 DCHECK(raster_page_scale_
);
429 DCHECK(raster_device_scale_
);
430 DCHECK(raster_source_scale_
);
431 DCHECK(raster_contents_scale_
);
432 DCHECK(low_res_raster_contents_scale_
);
434 was_screen_space_transform_animating_
=
435 draw_properties().screen_space_transform_is_animating
;
437 if (draw_transform_is_animating())
438 raster_source_
->SetShouldAttemptToUseDistanceFieldText();
440 double current_frame_time_in_seconds
=
441 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time
-
442 base::TimeTicks()).InSecondsF();
443 UpdateViewportRectForTilePriorityInContentSpace();
445 // The tiling set can require tiles for activation any of the following
446 // conditions are true:
447 // - This layer produced a high-res or non-ideal-res tile last frame.
448 // - We're in requires high res to draw mode.
449 // - We're not in smoothness takes priority mode.
450 // To put different, the tiling set can't require tiles for activation if
451 // we're in smoothness mode and only used low-res or checkerboard to draw last
452 // frame and we don't need high res to draw.
454 // The reason for this is that we should be able to activate sooner and get a
455 // more up to date recording, so we don't run out of recording on the active
457 bool can_require_tiles_for_activation
=
458 !only_used_low_res_last_append_quads_
|| RequiresHighResToDraw() ||
459 !layer_tree_impl()->SmoothnessTakesPriority();
461 static const Occlusion kEmptyOcclusion
;
462 const Occlusion
& occlusion_in_content_space
=
463 layer_tree_impl()->settings().use_occlusion_for_tile_prioritization
464 ? draw_properties().occlusion_in_content_space
467 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
468 // they are the same space in picture layer, as contents scale is always 1.
469 bool updated
= tilings_
->UpdateTilePriorities(
470 viewport_rect_for_tile_priority_in_content_space_
, ideal_contents_scale_
,
471 current_frame_time_in_seconds
, occlusion_in_content_space
,
472 can_require_tiles_for_activation
);
476 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
477 // If visible_rect_for_tile_priority_ is empty or
478 // viewport_rect_for_tile_priority is set to be different from the device
479 // viewport, try to inverse project the viewport into layer space and use
480 // that. Otherwise just use visible_rect_for_tile_priority_
481 gfx::Rect visible_rect_in_content_space
= visible_rect_for_tile_priority_
;
482 gfx::Rect viewport_rect_for_tile_priority
=
483 layer_tree_impl()->ViewportRectForTilePriority();
484 if (visible_rect_in_content_space
.IsEmpty() ||
485 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority
) {
486 gfx::Transform
view_to_layer(gfx::Transform::kSkipInitialization
);
487 if (screen_space_transform().GetInverse(&view_to_layer
)) {
488 // Transform from view space to content space.
489 visible_rect_in_content_space
=
490 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
491 view_to_layer
, viewport_rect_for_tile_priority
));
494 viewport_rect_for_tile_priority_in_content_space_
=
495 visible_rect_in_content_space
;
498 PictureLayerImpl
* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
499 if (!twin_layer_
|| !twin_layer_
->IsOnActiveOrPendingTree())
504 PictureLayerImpl
* PictureLayerImpl::GetRecycledTwinLayer() const {
505 if (!twin_layer_
|| twin_layer_
->IsOnActiveOrPendingTree())
510 void PictureLayerImpl::UpdateRasterSource(
511 scoped_refptr
<RasterSource
> raster_source
,
512 Region
* new_invalidation
,
513 const PictureLayerTilingSet
* pending_set
) {
514 // The bounds and the pile size may differ if the pile wasn't updated (ie.
515 // PictureLayer::Update didn't happen). In that case the pile will be empty.
516 DCHECK_IMPLIES(!raster_source
->GetSize().IsEmpty(),
517 bounds() == raster_source
->GetSize())
518 << " bounds " << bounds().ToString() << " pile "
519 << raster_source
->GetSize().ToString();
521 // The |raster_source_| is initially null, so have to check for that for the
523 bool could_have_tilings
= raster_source_
.get() && CanHaveTilings();
524 raster_source_
.swap(raster_source
);
526 // The |new_invalidation| must be cleared before updating tilings since they
527 // access the invalidation through the PictureLayerTilingClient interface.
528 invalidation_
.Clear();
529 invalidation_
.Swap(new_invalidation
);
531 bool can_have_tilings
= CanHaveTilings();
534 can_have_tilings
== GetPendingOrActiveTwinLayer()->CanHaveTilings());
536 // Need to call UpdateTiles again if CanHaveTilings changed.
537 if (could_have_tilings
!= can_have_tilings
)
538 layer_tree_impl()->set_needs_update_draw_properties();
540 if (!can_have_tilings
) {
545 // We could do this after doing UpdateTiles, which would avoid doing this for
546 // tilings that are going to disappear on the pending tree (if scale changed).
547 // But that would also be more complicated, so we just do it here for now.
549 tilings_
->UpdateTilingsToCurrentRasterSourceForActivation(
550 raster_source_
, pending_set
, invalidation_
, MinimumContentsScale(),
551 MaximumContentsScale());
553 tilings_
->UpdateTilingsToCurrentRasterSourceForCommit(
554 raster_source_
, invalidation_
, MinimumContentsScale(),
555 MaximumContentsScale());
559 void PictureLayerImpl::UpdateCanUseLCDTextAfterCommit() {
560 // This function is only allowed to be called after commit, due to it not
561 // being smart about sharing tiles and because otherwise it would cause
562 // flashes by switching out tiles in place that may be currently on screen.
563 DCHECK(layer_tree_impl()->IsSyncTree());
565 // Don't allow the LCD text state to change once disabled.
566 if (!RasterSourceUsesLCDText())
568 if (can_use_lcd_text() == RasterSourceUsesLCDText())
571 // Raster sources are considered const, so in order to update the state
572 // a new one must be created and all tiles recreated.
573 scoped_refptr
<RasterSource
> new_raster_source
=
574 raster_source_
->CreateCloneWithoutLCDText();
575 raster_source_
.swap(new_raster_source
);
577 // Synthetically invalidate everything.
578 gfx::Rect
bounds_rect(bounds());
579 invalidation_
= Region(bounds_rect
);
580 tilings_
->UpdateRasterSourceDueToLCDChange(raster_source_
, invalidation_
);
581 SetUpdateRect(bounds_rect
);
583 DCHECK(!RasterSourceUsesLCDText());
586 bool PictureLayerImpl::RasterSourceUsesLCDText() const {
587 return raster_source_
? raster_source_
->CanUseLCDText()
588 : layer_tree_impl()->settings().can_use_lcd_text
;
591 void PictureLayerImpl::NotifyTileStateChanged(const Tile
* tile
) {
592 if (layer_tree_impl()->IsActiveTree()) {
593 gfx::RectF layer_damage_rect
=
594 gfx::ScaleRect(tile
->content_rect(), 1.f
/ tile
->contents_scale());
595 AddDamageRect(layer_damage_rect
);
599 void PictureLayerImpl::DidBeginTracing() {
600 raster_source_
->DidBeginTracing();
603 void PictureLayerImpl::ReleaseResources() {
604 // Recreate tilings with new settings, since some of those might change when
605 // we release resources.
610 void PictureLayerImpl::RecreateResources() {
611 tilings_
= CreatePictureLayerTilingSet();
613 // To avoid an edge case after lost context where the tree is up to date but
614 // the tilings have not been managed, request an update draw properties
615 // to force tilings to get managed.
616 layer_tree_impl()->set_needs_update_draw_properties();
619 skia::RefPtr
<SkPicture
> PictureLayerImpl::GetPicture() {
620 return raster_source_
->GetFlattenedPicture();
623 Region
PictureLayerImpl::GetInvalidationRegion() {
624 // |invalidation_| gives the invalidation contained in the source frame, but
625 // is not cleared after drawing from the layer. However, update_rect() is
626 // cleared once the invalidation is drawn, which is useful for debugging
627 // visualizations. This method intersects the two to give a more exact
628 // representation of what was invalidated that is cleared after drawing.
629 return IntersectRegions(invalidation_
, update_rect());
632 scoped_refptr
<Tile
> PictureLayerImpl::CreateTile(
633 float contents_scale
,
634 const gfx::Rect
& content_rect
) {
637 // We don't handle solid color masks, so we shouldn't bother analyzing those.
638 // Otherwise, always analyze to maximize memory savings.
640 flags
= Tile::USE_PICTURE_ANALYSIS
;
642 return layer_tree_impl()->tile_manager()->CreateTile(
643 raster_source_
.get(), content_rect
.size(), content_rect
, contents_scale
,
644 id(), layer_tree_impl()->source_frame_number(), flags
);
647 const Region
* PictureLayerImpl::GetPendingInvalidation() {
648 if (layer_tree_impl()->IsPendingTree())
649 return &invalidation_
;
650 if (layer_tree_impl()->IsRecycleTree())
652 DCHECK(layer_tree_impl()->IsActiveTree());
653 if (PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer())
654 return &twin_layer
->invalidation_
;
658 const PictureLayerTiling
* PictureLayerImpl::GetPendingOrActiveTwinTiling(
659 const PictureLayerTiling
* tiling
) const {
660 PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer();
663 return twin_layer
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
666 PictureLayerTiling
* PictureLayerImpl::GetRecycledTwinTiling(
667 const PictureLayerTiling
* tiling
) {
668 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
669 if (!recycled_twin
|| !recycled_twin
->tilings_
)
671 return recycled_twin
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
674 TilePriority::PriorityBin
PictureLayerImpl::GetMaxTilePriorityBin() const {
675 if (!HasValidTilePriorities())
676 return TilePriority::EVENTUALLY
;
677 return TilePriority::NOW
;
680 bool PictureLayerImpl::RequiresHighResToDraw() const {
681 return layer_tree_impl()->RequiresHighResToDraw();
684 gfx::Rect
PictureLayerImpl::GetEnclosingRectInTargetSpace() const {
685 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale());
688 gfx::Size
PictureLayerImpl::CalculateTileSize(
689 const gfx::Size
& content_bounds
) const {
690 int max_texture_size
=
691 layer_tree_impl()->resource_provider()->max_texture_size();
694 // Masks are not tiled, so if we can't cover the whole mask with one tile,
695 // we shouldn't have such a tiling at all.
696 DCHECK_LE(content_bounds
.width(), max_texture_size
);
697 DCHECK_LE(content_bounds
.height(), max_texture_size
);
698 return content_bounds
;
701 int default_tile_width
= 0;
702 int default_tile_height
= 0;
703 if (layer_tree_impl()->use_gpu_rasterization()) {
704 // For GPU rasterization, we pick an ideal tile size using the viewport
705 // so we don't need any settings. The current approach uses 4 tiles
706 // to cover the viewport vertically.
707 int viewport_width
= gpu_raster_max_texture_size_
.width();
708 int viewport_height
= gpu_raster_max_texture_size_
.height();
709 default_tile_width
= viewport_width
;
711 // Also, increase the height proportionally as the width decreases, and
712 // pad by our border texels to make the tiles exactly match the viewport.
714 if (content_bounds
.width() <= viewport_width
/ 2)
716 if (content_bounds
.width() <= viewport_width
/ 4)
718 default_tile_height
= RoundUp(viewport_height
, divisor
) / divisor
;
720 // Grow default sizes to account for overlapping border texels.
721 default_tile_width
+= 2 * PictureLayerTiling::kBorderTexels
;
722 default_tile_height
+= 2 * PictureLayerTiling::kBorderTexels
;
724 default_tile_height
=
725 std::max(default_tile_height
, kMinHeightForGpuRasteredTile
);
727 // For CPU rasterization we use tile-size settings.
728 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
729 int max_untiled_content_width
= settings
.max_untiled_layer_size
.width();
730 int max_untiled_content_height
= settings
.max_untiled_layer_size
.height();
731 default_tile_width
= settings
.default_tile_size
.width();
732 default_tile_height
= settings
.default_tile_size
.height();
734 // If the content width is small, increase tile size vertically.
735 // If the content height is small, increase tile size horizontally.
736 // If both are less than the untiled-size, use a single tile.
737 if (content_bounds
.width() < default_tile_width
)
738 default_tile_height
= max_untiled_content_height
;
739 if (content_bounds
.height() < default_tile_height
)
740 default_tile_width
= max_untiled_content_width
;
741 if (content_bounds
.width() < max_untiled_content_width
&&
742 content_bounds
.height() < max_untiled_content_height
) {
743 default_tile_height
= max_untiled_content_height
;
744 default_tile_width
= max_untiled_content_width
;
748 int tile_width
= default_tile_width
;
749 int tile_height
= default_tile_height
;
751 // Clamp the tile width/height to the content width/height to save space.
752 if (content_bounds
.width() < default_tile_width
) {
753 tile_width
= std::min(tile_width
, content_bounds
.width());
754 tile_width
= RoundUp(tile_width
, kTileRoundUp
);
755 tile_width
= std::min(tile_width
, default_tile_width
);
757 if (content_bounds
.height() < default_tile_height
) {
758 tile_height
= std::min(tile_height
, content_bounds
.height());
759 tile_height
= RoundUp(tile_height
, kTileRoundUp
);
760 tile_height
= std::min(tile_height
, default_tile_height
);
763 // Under no circumstance should we be larger than the max texture size.
764 tile_width
= std::min(tile_width
, max_texture_size
);
765 tile_height
= std::min(tile_height
, max_texture_size
);
766 return gfx::Size(tile_width
, tile_height
);
769 void PictureLayerImpl::GetContentsResourceId(
770 ResourceProvider::ResourceId
* resource_id
,
771 gfx::Size
* resource_size
) const {
772 // The bounds and the pile size may differ if the pile wasn't updated (ie.
773 // PictureLayer::Update didn't happen). In that case the pile will be empty.
774 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
775 bounds() == raster_source_
->GetSize())
776 << " bounds " << bounds().ToString() << " pile "
777 << raster_source_
->GetSize().ToString();
778 gfx::Rect
content_rect(bounds());
779 PictureLayerTilingSet::CoverageIterator
iter(
780 tilings_
.get(), 1.f
, content_rect
, ideal_contents_scale_
);
782 // Mask resource not ready yet.
783 if (!iter
|| !*iter
) {
788 // Masks only supported if they fit on exactly one tile.
789 DCHECK(iter
.geometry_rect() == content_rect
)
790 << "iter rect " << iter
.geometry_rect().ToString() << " content rect "
791 << content_rect
.ToString();
793 const TileDrawInfo
& draw_info
= iter
->draw_info();
794 if (!draw_info
.IsReadyToDraw() ||
795 draw_info
.mode() != TileDrawInfo::RESOURCE_MODE
) {
800 *resource_id
= draw_info
.resource_id();
801 *resource_size
= draw_info
.resource_size();
804 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor
) {
805 if (nearest_neighbor_
== nearest_neighbor
)
808 nearest_neighbor_
= nearest_neighbor
;
809 NoteLayerPropertyChanged();
812 PictureLayerTiling
* PictureLayerImpl::AddTiling(float contents_scale
) {
813 DCHECK(CanHaveTilings());
814 DCHECK_GE(contents_scale
, MinimumContentsScale());
815 DCHECK_LE(contents_scale
, MaximumContentsScale());
816 DCHECK(raster_source_
->HasRecordings());
817 return tilings_
->AddTiling(contents_scale
, raster_source_
);
820 void PictureLayerImpl::RemoveAllTilings() {
821 tilings_
->RemoveAllTilings();
822 // If there are no tilings, then raster scales are no longer meaningful.
826 void PictureLayerImpl::AddTilingsForRasterScale() {
827 // Reset all resolution enums on tilings, we'll be setting new values in this
829 tilings_
->MarkAllTilingsNonIdeal();
831 PictureLayerTiling
* high_res
=
832 tilings_
->FindTilingWithScale(raster_contents_scale_
);
833 // We always need a high res tiling, so create one if it doesn't exist.
835 high_res
= AddTiling(raster_contents_scale_
);
837 // Try and find a low res tiling.
838 PictureLayerTiling
* low_res
= nullptr;
839 if (raster_contents_scale_
== low_res_raster_contents_scale_
)
842 low_res
= tilings_
->FindTilingWithScale(low_res_raster_contents_scale_
);
844 // Only create new low res tilings when the transform is static. This
845 // prevents wastefully creating a paired low res tiling for every new high res
846 // tiling during a pinch or a CSS animation.
847 bool can_have_low_res
= layer_tree_impl()->create_low_res_tiling();
848 bool needs_low_res
= !low_res
;
849 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
850 bool is_animating
= draw_properties().screen_space_transform_is_animating
;
851 if (can_have_low_res
&& needs_low_res
&& !is_pinching
&& !is_animating
)
852 low_res
= AddTiling(low_res_raster_contents_scale_
);
854 // Set low-res if we have one.
855 if (low_res
&& low_res
!= high_res
)
856 low_res
->set_resolution(LOW_RESOLUTION
);
858 // Make sure we always have one high-res (even if high == low).
859 high_res
->set_resolution(HIGH_RESOLUTION
);
861 if (layer_tree_impl()->IsPendingTree()) {
862 // On the pending tree, drop any tilings that are non-ideal since we don't
863 // need them to activate anyway.
864 tilings_
->RemoveNonIdealTilings();
867 SanityCheckTilingState();
870 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
871 if (was_screen_space_transform_animating_
!=
872 draw_properties().screen_space_transform_is_animating
)
875 if (draw_properties().screen_space_transform_is_animating
&&
876 raster_contents_scale_
!= ideal_contents_scale_
&&
877 ShouldAdjustRasterScaleDuringScaleAnimations())
880 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
881 if (is_pinching
&& raster_page_scale_
) {
882 // We change our raster scale when it is:
883 // - Higher than ideal (need a lower-res tiling available)
884 // - Too far from ideal (need a higher-res tiling available)
885 float ratio
= ideal_page_scale_
/ raster_page_scale_
;
886 if (raster_page_scale_
> ideal_page_scale_
||
887 ratio
> kMaxScaleRatioDuringPinch
)
892 // When not pinching, match the ideal page scale factor.
893 if (raster_page_scale_
!= ideal_page_scale_
)
897 // Always match the ideal device scale factor.
898 if (raster_device_scale_
!= ideal_device_scale_
)
901 // When the source scale changes we want to match it, but not when animating
902 // or when we've fixed the scale in place.
903 if (!draw_properties().screen_space_transform_is_animating
&&
904 !raster_source_scale_is_fixed_
&&
905 raster_source_scale_
!= ideal_source_scale_
)
908 if (raster_contents_scale_
> MaximumContentsScale())
910 if (raster_contents_scale_
< MinimumContentsScale())
916 void PictureLayerImpl::RecalculateRasterScales() {
917 float old_raster_contents_scale
= raster_contents_scale_
;
918 float old_raster_page_scale
= raster_page_scale_
;
919 float old_raster_source_scale
= raster_source_scale_
;
921 raster_device_scale_
= ideal_device_scale_
;
922 raster_page_scale_
= ideal_page_scale_
;
923 raster_source_scale_
= ideal_source_scale_
;
924 raster_contents_scale_
= ideal_contents_scale_
;
926 // If we're not animating, or leaving an animation, and the
927 // ideal_source_scale_ changes, then things are unpredictable, and we fix
928 // the raster_source_scale_ in place.
929 if (old_raster_source_scale
&&
930 !draw_properties().screen_space_transform_is_animating
&&
931 !was_screen_space_transform_animating_
&&
932 old_raster_source_scale
!= ideal_source_scale_
)
933 raster_source_scale_is_fixed_
= true;
935 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
936 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
937 // tree. This will allow CSS scale changes to get re-rastered at an
938 // appropriate rate. (crbug.com/413636)
939 if (raster_source_scale_is_fixed_
) {
940 raster_contents_scale_
/= raster_source_scale_
;
941 raster_source_scale_
= 1.f
;
944 // During pinch we completely ignore the current ideal scale, and just use
945 // a multiple of the previous scale.
946 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
947 if (is_pinching
&& old_raster_contents_scale
) {
948 // See ShouldAdjustRasterScale:
949 // - When zooming out, preemptively create new tiling at lower resolution.
950 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
951 bool zooming_out
= old_raster_page_scale
> ideal_page_scale_
;
952 float desired_contents_scale
= old_raster_contents_scale
;
954 while (desired_contents_scale
> ideal_contents_scale_
)
955 desired_contents_scale
/= kMaxScaleRatioDuringPinch
;
957 while (desired_contents_scale
< ideal_contents_scale_
)
958 desired_contents_scale
*= kMaxScaleRatioDuringPinch
;
960 raster_contents_scale_
= tilings_
->GetSnappedContentsScale(
961 desired_contents_scale
, kSnapToExistingTilingRatio
);
963 raster_contents_scale_
/ raster_device_scale_
/ raster_source_scale_
;
966 // If we're not re-rasterizing during animation, rasterize at the maximum
967 // scale that will occur during the animation, if the maximum scale is
968 // known. However we want to avoid excessive memory use. If the scale is
969 // smaller than what we would choose otherwise, then it's always better off
970 // for us memory-wise. But otherwise, we don't choose a scale at which this
971 // layer's rastered content would become larger than the viewport.
972 if (draw_properties().screen_space_transform_is_animating
&&
973 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
974 bool can_raster_at_maximum_scale
= false;
975 // TODO(ajuma): If we need to deal with scale-down animations starting right
976 // as a layer gets promoted, then we'd want to have the
977 // |starting_animation_contents_scale| passed in here as a separate draw
978 // property so we could try use that when the max is too large.
979 // See crbug.com/422341.
980 float maximum_scale
= draw_properties().maximum_animation_contents_scale
;
982 gfx::Size bounds_at_maximum_scale
= gfx::ToCeiledSize(
983 gfx::ScaleSize(raster_source_
->GetSize(), maximum_scale
));
984 int64 maximum_area
= static_cast<int64
>(bounds_at_maximum_scale
.width()) *
985 static_cast<int64
>(bounds_at_maximum_scale
.height());
986 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
987 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
988 static_cast<int64
>(viewport
.height());
989 if (maximum_area
<= viewport_area
)
990 can_raster_at_maximum_scale
= true;
992 // Use the computed scales for the raster scale directly, do not try to use
993 // the ideal scale here. The current ideal scale may be way too large in the
994 // case of an animation with scale, and will be constantly changing.
995 if (can_raster_at_maximum_scale
)
996 raster_contents_scale_
= maximum_scale
;
998 raster_contents_scale_
= 1.f
* ideal_page_scale_
* ideal_device_scale_
;
1001 raster_contents_scale_
=
1002 std::max(raster_contents_scale_
, MinimumContentsScale());
1003 raster_contents_scale_
=
1004 std::min(raster_contents_scale_
, MaximumContentsScale());
1005 DCHECK_GE(raster_contents_scale_
, MinimumContentsScale());
1006 DCHECK_LE(raster_contents_scale_
, MaximumContentsScale());
1008 // If this layer would create zero or one tiles at this content scale,
1009 // don't create a low res tiling.
1010 gfx::Size raster_bounds
= gfx::ToCeiledSize(
1011 gfx::ScaleSize(raster_source_
->GetSize(), raster_contents_scale_
));
1012 gfx::Size tile_size
= CalculateTileSize(raster_bounds
);
1013 bool tile_covers_bounds
= tile_size
.width() >= raster_bounds
.width() &&
1014 tile_size
.height() >= raster_bounds
.height();
1015 if (tile_size
.IsEmpty() || tile_covers_bounds
) {
1016 low_res_raster_contents_scale_
= raster_contents_scale_
;
1020 float low_res_factor
=
1021 layer_tree_impl()->settings().low_res_contents_scale_factor
;
1022 low_res_raster_contents_scale_
=
1023 std::max(raster_contents_scale_
* low_res_factor
, MinimumContentsScale());
1024 DCHECK_LE(low_res_raster_contents_scale_
, raster_contents_scale_
);
1025 DCHECK_GE(low_res_raster_contents_scale_
, MinimumContentsScale());
1026 DCHECK_LE(low_res_raster_contents_scale_
, MaximumContentsScale());
1029 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
1030 const std::vector
<PictureLayerTiling
*>& used_tilings
) {
1031 DCHECK(layer_tree_impl()->IsActiveTree());
1032 if (tilings_
->num_tilings() == 0)
1035 float min_acceptable_high_res_scale
= std::min(
1036 raster_contents_scale_
, ideal_contents_scale_
);
1037 float max_acceptable_high_res_scale
= std::max(
1038 raster_contents_scale_
, ideal_contents_scale_
);
1040 PictureLayerImpl
* twin
= GetPendingOrActiveTwinLayer();
1041 if (twin
&& twin
->CanHaveTilings()) {
1042 min_acceptable_high_res_scale
= std::min(
1043 min_acceptable_high_res_scale
,
1044 std::min(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1045 max_acceptable_high_res_scale
= std::max(
1046 max_acceptable_high_res_scale
,
1047 std::max(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1050 PictureLayerTilingSet
* twin_set
= twin
? twin
->tilings_
.get() : nullptr;
1051 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
1052 PictureLayerTilingSet
* recycled_twin_set
=
1053 recycled_twin
? recycled_twin
->tilings_
.get() : nullptr;
1055 tilings_
->CleanUpTilings(min_acceptable_high_res_scale
,
1056 max_acceptable_high_res_scale
, used_tilings
,
1057 layer_tree_impl()->create_low_res_tiling(), twin_set
,
1060 if (recycled_twin_set
&& recycled_twin_set
->num_tilings() == 0)
1061 recycled_twin
->ResetRasterScale();
1063 DCHECK_GT(tilings_
->num_tilings(), 0u);
1064 SanityCheckTilingState();
1067 float PictureLayerImpl::MinimumContentsScale() const {
1068 float setting_min
= layer_tree_impl()->settings().minimum_contents_scale
;
1070 // If the contents scale is less than 1 / width (also for height),
1071 // then it will end up having less than one pixel of content in that
1072 // dimension. Bump the minimum contents scale up in this case to prevent
1073 // this from happening.
1074 int min_dimension
= std::min(raster_source_
->GetSize().width(),
1075 raster_source_
->GetSize().height());
1079 return std::max(1.f
/ min_dimension
, setting_min
);
1082 float PictureLayerImpl::MaximumContentsScale() const {
1083 // Masks can not have tilings that would become larger than the
1084 // max_texture_size since they use a single tile for the entire
1085 // tiling. Other layers can have tilings of any scale.
1087 return std::numeric_limits
<float>::max();
1089 int max_texture_size
=
1090 layer_tree_impl()->resource_provider()->max_texture_size();
1091 float max_scale_width
=
1092 static_cast<float>(max_texture_size
) / bounds().width();
1093 float max_scale_height
=
1094 static_cast<float>(max_texture_size
) / bounds().height();
1095 float max_scale
= std::min(max_scale_width
, max_scale_height
);
1096 // We require that multiplying the layer size by the contents scale and
1097 // ceiling produces a value <= |max_texture_size|. Because for large layer
1098 // sizes floating point ambiguity may crop up, making the result larger or
1099 // smaller than expected, we use a slightly smaller floating point value for
1100 // the scale, to help ensure that the resulting content bounds will never end
1101 // up larger than |max_texture_size|.
1102 return nextafterf(max_scale
, 0.f
);
1105 void PictureLayerImpl::ResetRasterScale() {
1106 raster_page_scale_
= 0.f
;
1107 raster_device_scale_
= 0.f
;
1108 raster_source_scale_
= 0.f
;
1109 raster_contents_scale_
= 0.f
;
1110 low_res_raster_contents_scale_
= 0.f
;
1111 raster_source_scale_is_fixed_
= false;
1114 bool PictureLayerImpl::CanHaveTilings() const {
1115 if (raster_source_
->IsSolidColor())
1117 if (!DrawsContent())
1119 if (!raster_source_
->HasRecordings())
1121 // If the |raster_source_| has a recording it should have non-empty bounds.
1122 DCHECK(!raster_source_
->GetSize().IsEmpty());
1123 if (MaximumContentsScale() < MinimumContentsScale())
1128 void PictureLayerImpl::SanityCheckTilingState() const {
1130 // Recycle tree doesn't have any restrictions.
1131 if (layer_tree_impl()->IsRecycleTree())
1134 if (!CanHaveTilings()) {
1135 DCHECK_EQ(0u, tilings_
->num_tilings());
1138 if (tilings_
->num_tilings() == 0)
1141 // We should only have one high res tiling.
1142 DCHECK_EQ(1, tilings_
->NumHighResTilings());
1146 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1147 return layer_tree_impl()->use_gpu_rasterization();
1150 float PictureLayerImpl::MaximumTilingContentsScale() const {
1151 float max_contents_scale
= tilings_
->GetMaximumContentsScale();
1152 return std::max(max_contents_scale
, MinimumContentsScale());
1155 scoped_ptr
<PictureLayerTilingSet
>
1156 PictureLayerImpl::CreatePictureLayerTilingSet() {
1157 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
1158 return PictureLayerTilingSet::Create(
1159 this, settings
.max_tiles_for_interest_area
,
1160 layer_tree_impl()->use_gpu_rasterization()
1161 ? settings
.gpu_rasterization_skewport_target_time_in_seconds
1162 : settings
.skewport_target_time_in_seconds
,
1163 settings
.skewport_extrapolation_limit_in_content_pixels
);
1166 void PictureLayerImpl::UpdateIdealScales() {
1167 DCHECK(CanHaveTilings());
1169 float min_contents_scale
= MinimumContentsScale();
1170 DCHECK_GT(min_contents_scale
, 0.f
);
1171 float min_page_scale
= layer_tree_impl()->min_page_scale_factor();
1172 DCHECK_GT(min_page_scale
, 0.f
);
1173 float min_device_scale
= 1.f
;
1174 float min_source_scale
=
1175 min_contents_scale
/ min_page_scale
/ min_device_scale
;
1177 float ideal_page_scale
= draw_properties().page_scale_factor
;
1178 float ideal_device_scale
= draw_properties().device_scale_factor
;
1179 float ideal_source_scale
= draw_properties().ideal_contents_scale
/
1180 ideal_page_scale
/ ideal_device_scale
;
1181 ideal_contents_scale_
=
1182 std::max(draw_properties().ideal_contents_scale
, min_contents_scale
);
1183 ideal_page_scale_
= draw_properties().page_scale_factor
;
1184 ideal_device_scale_
= draw_properties().device_scale_factor
;
1185 ideal_source_scale_
= std::max(ideal_source_scale
, min_source_scale
);
1188 void PictureLayerImpl::GetDebugBorderProperties(
1190 float* width
) const {
1191 *color
= DebugColors::TiledContentLayerBorderColor();
1192 *width
= DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1195 void PictureLayerImpl::GetAllTilesAndPrioritiesForTracing(
1196 std::map
<const Tile
*, TilePriority
>* tile_map
) const {
1199 tilings_
->GetAllTilesAndPrioritiesForTracing(tile_map
);
1202 void PictureLayerImpl::AsValueInto(
1203 base::trace_event::TracedValue
* state
) const {
1204 LayerImpl::AsValueInto(state
);
1205 state
->SetDouble("ideal_contents_scale", ideal_contents_scale_
);
1206 state
->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1207 state
->BeginArray("tilings");
1208 tilings_
->AsValueInto(state
);
1211 MathUtil::AddToTracedValue("tile_priority_rect",
1212 viewport_rect_for_tile_priority_in_content_space_
,
1214 MathUtil::AddToTracedValue("visible_rect", visible_content_rect(), state
);
1216 state
->BeginArray("pictures");
1217 raster_source_
->AsValueInto(state
);
1220 state
->BeginArray("invalidation");
1221 invalidation_
.AsValueInto(state
);
1224 state
->BeginArray("coverage_tiles");
1225 for (PictureLayerTilingSet::CoverageIterator
iter(
1226 tilings_
.get(), 1.f
, gfx::Rect(raster_source_
->GetSize()),
1227 ideal_contents_scale_
);
1229 state
->BeginDictionary();
1231 MathUtil::AddToTracedValue("geometry_rect", iter
.geometry_rect(), state
);
1234 TracedValue::SetIDRef(*iter
, state
, "tile");
1236 state
->EndDictionary();
1241 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1242 return tilings_
->GPUMemoryUsageInBytes();
1245 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1246 benchmark
->RunOnLayer(this);
1249 WhichTree
PictureLayerImpl::GetTree() const {
1250 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
1253 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1254 return !layer_tree_impl()->IsRecycleTree();
1257 bool PictureLayerImpl::HasValidTilePriorities() const {
1258 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();