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 AppendQuadsData
* append_quads_data
) {
157 // The bounds and the pile size may differ if the pile wasn't updated (ie.
158 // PictureLayer::Update didn't happen). In that case the pile will be empty.
159 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
160 bounds() == raster_source_
->GetSize())
161 << " bounds " << bounds().ToString() << " pile "
162 << raster_source_
->GetSize().ToString();
164 SharedQuadState
* shared_quad_state
=
165 render_pass
->CreateAndAppendSharedQuadState();
167 if (raster_source_
->IsSolidColor()) {
168 PopulateSharedQuadState(shared_quad_state
);
170 AppendDebugBorderQuad(
171 render_pass
, bounds(), shared_quad_state
, append_quads_data
);
173 SolidColorLayerImpl::AppendSolidQuads(
174 render_pass
, draw_properties().occlusion_in_content_space
,
175 shared_quad_state
, visible_content_rect(),
176 raster_source_
->GetSolidColor(), append_quads_data
);
180 float max_contents_scale
= MaximumTilingContentsScale();
181 PopulateScaledSharedQuadState(shared_quad_state
, max_contents_scale
);
182 Occlusion scaled_occlusion
=
184 .occlusion_in_content_space
.GetOcclusionWithGivenDrawTransform(
185 shared_quad_state
->content_to_target_transform
);
187 if (current_draw_mode_
== DRAW_MODE_RESOURCELESS_SOFTWARE
) {
188 AppendDebugBorderQuad(
189 render_pass
, shared_quad_state
->content_bounds
, shared_quad_state
,
190 append_quads_data
, DebugColors::DirectPictureBorderColor(),
191 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
193 gfx::Rect geometry_rect
= shared_quad_state
->visible_content_rect
;
194 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
195 gfx::Rect visible_geometry_rect
=
196 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
197 if (visible_geometry_rect
.IsEmpty())
200 gfx::Rect quad_content_rect
= shared_quad_state
->visible_content_rect
;
201 gfx::Size texture_size
= quad_content_rect
.size();
202 gfx::RectF texture_rect
= gfx::RectF(texture_size
);
204 PictureDrawQuad
* quad
=
205 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
206 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
207 visible_geometry_rect
, texture_rect
, texture_size
,
208 nearest_neighbor_
, RGBA_8888
, quad_content_rect
,
209 max_contents_scale
, raster_source_
);
213 AppendDebugBorderQuad(render_pass
, shared_quad_state
->content_bounds
,
214 shared_quad_state
, append_quads_data
);
216 if (ShowDebugBorders()) {
217 for (PictureLayerTilingSet::CoverageIterator
iter(
218 tilings_
.get(), max_contents_scale
,
219 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
223 if (*iter
&& iter
->IsReadyToDraw()) {
224 TileDrawInfo::Mode mode
= iter
->draw_info().mode();
225 if (mode
== TileDrawInfo::SOLID_COLOR_MODE
) {
226 color
= DebugColors::SolidColorTileBorderColor();
227 width
= DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
228 } else if (mode
== TileDrawInfo::OOM_MODE
) {
229 color
= DebugColors::OOMTileBorderColor();
230 width
= DebugColors::OOMTileBorderWidth(layer_tree_impl());
231 } else if (iter
.resolution() == HIGH_RESOLUTION
) {
232 color
= DebugColors::HighResTileBorderColor();
233 width
= DebugColors::HighResTileBorderWidth(layer_tree_impl());
234 } else if (iter
.resolution() == LOW_RESOLUTION
) {
235 color
= DebugColors::LowResTileBorderColor();
236 width
= DebugColors::LowResTileBorderWidth(layer_tree_impl());
237 } else if (iter
->contents_scale() > max_contents_scale
) {
238 color
= DebugColors::ExtraHighResTileBorderColor();
239 width
= DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
241 color
= DebugColors::ExtraLowResTileBorderColor();
242 width
= DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
245 color
= DebugColors::MissingTileBorderColor();
246 width
= DebugColors::MissingTileBorderWidth(layer_tree_impl());
249 DebugBorderDrawQuad
* debug_border_quad
=
250 render_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
251 gfx::Rect geometry_rect
= iter
.geometry_rect();
252 gfx::Rect visible_geometry_rect
= geometry_rect
;
253 debug_border_quad
->SetNew(shared_quad_state
,
255 visible_geometry_rect
,
261 // Keep track of the tilings that were used so that tilings that are
262 // unused can be considered for removal.
263 last_append_quads_tilings_
.clear();
265 // Ignore missing tiles outside of viewport for tile priority. This is
266 // normally the same as draw viewport but can be independently overridden by
267 // embedders like Android WebView with SetExternalDrawConstraints.
268 gfx::Rect scaled_viewport_for_tile_priority
= gfx::ScaleToEnclosingRect(
269 viewport_rect_for_tile_priority_in_content_space_
, max_contents_scale
);
271 size_t missing_tile_count
= 0u;
272 size_t on_demand_missing_tile_count
= 0u;
273 only_used_low_res_last_append_quads_
= true;
274 for (PictureLayerTilingSet::CoverageIterator
iter(
275 tilings_
.get(), max_contents_scale
,
276 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
278 gfx::Rect geometry_rect
= iter
.geometry_rect();
279 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
280 gfx::Rect visible_geometry_rect
=
281 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
282 if (visible_geometry_rect
.IsEmpty())
285 append_quads_data
->visible_content_area
+=
286 visible_geometry_rect
.width() * visible_geometry_rect
.height();
288 bool has_draw_quad
= false;
289 if (*iter
&& iter
->IsReadyToDraw()) {
290 const TileDrawInfo
& draw_info
= iter
->draw_info();
291 switch (draw_info
.mode()) {
292 case TileDrawInfo::RESOURCE_MODE
: {
293 gfx::RectF texture_rect
= iter
.texture_rect();
295 // The raster_contents_scale_ is the best scale that the layer is
296 // trying to produce, even though it may not be ideal. Since that's
297 // the best the layer can promise in the future, consider those as
298 // complete. But if a tile is ideal scale, we don't want to consider
299 // it incomplete and trying to replace it with a tile at a worse
301 if (iter
->contents_scale() != raster_contents_scale_
&&
302 iter
->contents_scale() != ideal_contents_scale_
&&
303 geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
304 append_quads_data
->num_incomplete_tiles
++;
308 render_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
309 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
310 visible_geometry_rect
, draw_info
.resource_id(),
311 texture_rect
, draw_info
.resource_size(),
312 draw_info
.contents_swizzled(), nearest_neighbor_
);
313 has_draw_quad
= true;
316 case TileDrawInfo::SOLID_COLOR_MODE
: {
317 SolidColorDrawQuad
* quad
=
318 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
319 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
320 draw_info
.solid_color(), false);
321 has_draw_quad
= true;
324 case TileDrawInfo::OOM_MODE
:
325 break; // Checkerboard.
329 if (!has_draw_quad
) {
330 if (draw_checkerboard_for_missing_tiles()) {
331 CheckerboardDrawQuad
* quad
=
332 render_pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
333 SkColor color
= DebugColors::DefaultCheckerboardColor();
335 shared_quad_state
, geometry_rect
, visible_geometry_rect
, color
);
337 SkColor color
= SafeOpaqueBackgroundColor();
338 SolidColorDrawQuad
* quad
=
339 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
340 quad
->SetNew(shared_quad_state
,
342 visible_geometry_rect
,
347 if (geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
348 append_quads_data
->num_missing_tiles
++;
349 ++missing_tile_count
;
351 append_quads_data
->approximated_visible_content_area
+=
352 visible_geometry_rect
.width() * visible_geometry_rect
.height();
356 if (iter
.resolution() != HIGH_RESOLUTION
) {
357 append_quads_data
->approximated_visible_content_area
+=
358 visible_geometry_rect
.width() * visible_geometry_rect
.height();
361 // If we have a draw quad, but it's not low resolution, then
362 // mark that we've used something other than low res to draw.
363 if (iter
.resolution() != LOW_RESOLUTION
)
364 only_used_low_res_last_append_quads_
= false;
366 if (last_append_quads_tilings_
.empty() ||
367 last_append_quads_tilings_
.back() != iter
.CurrentTiling()) {
368 last_append_quads_tilings_
.push_back(iter
.CurrentTiling());
372 if (missing_tile_count
) {
373 TRACE_EVENT_INSTANT2("cc",
374 "PictureLayerImpl::AppendQuads checkerboard",
375 TRACE_EVENT_SCOPE_THREAD
,
376 "missing_tile_count",
378 "on_demand_missing_tile_count",
379 on_demand_missing_tile_count
);
382 // Aggressively remove any tilings that are not seen to save memory. Note
383 // that this is at the expense of doing cause more frequent re-painting. A
384 // better scheme would be to maintain a tighter visible_content_rect for the
386 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
389 bool PictureLayerImpl::UpdateTiles(bool resourceless_software_draw
) {
390 DCHECK_EQ(1.f
, contents_scale_x());
391 DCHECK_EQ(1.f
, contents_scale_y());
393 if (!resourceless_software_draw
) {
394 visible_rect_for_tile_priority_
= visible_content_rect();
397 if (!CanHaveTilings()) {
398 ideal_page_scale_
= 0.f
;
399 ideal_device_scale_
= 0.f
;
400 ideal_contents_scale_
= 0.f
;
401 ideal_source_scale_
= 0.f
;
402 SanityCheckTilingState();
406 // Remove any non-ideal tilings that were not used last time we generated
407 // quads to save memory and processing time. Note that pending tree should
408 // only have one or two tilings (high and low res), so only clean up the
409 // active layer. This cleans it up here in case AppendQuads didn't run.
410 // If it did run, this would not remove any additional tilings.
411 if (layer_tree_impl()->IsActiveTree())
412 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
416 if (!raster_contents_scale_
|| ShouldAdjustRasterScale()) {
417 RecalculateRasterScales();
418 AddTilingsForRasterScale();
421 DCHECK(raster_page_scale_
);
422 DCHECK(raster_device_scale_
);
423 DCHECK(raster_source_scale_
);
424 DCHECK(raster_contents_scale_
);
425 DCHECK(low_res_raster_contents_scale_
);
427 was_screen_space_transform_animating_
=
428 draw_properties().screen_space_transform_is_animating
;
430 if (draw_transform_is_animating())
431 raster_source_
->SetShouldAttemptToUseDistanceFieldText();
433 double current_frame_time_in_seconds
=
434 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time
-
435 base::TimeTicks()).InSecondsF();
436 UpdateViewportRectForTilePriorityInContentSpace();
438 // The tiling set can require tiles for activation any of the following
439 // conditions are true:
440 // - This layer produced a high-res or non-ideal-res tile last frame.
441 // - We're in requires high res to draw mode.
442 // - We're not in smoothness takes priority mode.
443 // To put different, the tiling set can't require tiles for activation if
444 // we're in smoothness mode and only used low-res or checkerboard to draw last
445 // frame and we don't need high res to draw.
447 // The reason for this is that we should be able to activate sooner and get a
448 // more up to date recording, so we don't run out of recording on the active
450 bool can_require_tiles_for_activation
=
451 !only_used_low_res_last_append_quads_
|| RequiresHighResToDraw() ||
452 !layer_tree_impl()->SmoothnessTakesPriority();
454 static const Occlusion kEmptyOcclusion
;
455 const Occlusion
& occlusion_in_content_space
=
456 layer_tree_impl()->settings().use_occlusion_for_tile_prioritization
457 ? draw_properties().occlusion_in_content_space
460 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
461 // they are the same space in picture layer, as contents scale is always 1.
462 bool updated
= tilings_
->UpdateTilePriorities(
463 viewport_rect_for_tile_priority_in_content_space_
, ideal_contents_scale_
,
464 current_frame_time_in_seconds
, occlusion_in_content_space
,
465 can_require_tiles_for_activation
);
469 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
470 // If visible_rect_for_tile_priority_ is empty or
471 // viewport_rect_for_tile_priority is set to be different from the device
472 // viewport, try to inverse project the viewport into layer space and use
473 // that. Otherwise just use visible_rect_for_tile_priority_
474 gfx::Rect visible_rect_in_content_space
= visible_rect_for_tile_priority_
;
475 gfx::Rect viewport_rect_for_tile_priority
=
476 layer_tree_impl()->ViewportRectForTilePriority();
477 if (visible_rect_in_content_space
.IsEmpty() ||
478 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority
) {
479 gfx::Transform
view_to_layer(gfx::Transform::kSkipInitialization
);
480 if (screen_space_transform().GetInverse(&view_to_layer
)) {
481 // Transform from view space to content space.
482 visible_rect_in_content_space
=
483 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
484 view_to_layer
, viewport_rect_for_tile_priority
));
487 viewport_rect_for_tile_priority_in_content_space_
=
488 visible_rect_in_content_space
;
491 PictureLayerImpl
* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
492 if (!twin_layer_
|| !twin_layer_
->IsOnActiveOrPendingTree())
497 PictureLayerImpl
* PictureLayerImpl::GetRecycledTwinLayer() const {
498 if (!twin_layer_
|| twin_layer_
->IsOnActiveOrPendingTree())
503 void PictureLayerImpl::UpdateRasterSource(
504 scoped_refptr
<RasterSource
> raster_source
,
505 Region
* new_invalidation
,
506 const PictureLayerTilingSet
* pending_set
) {
507 // The bounds and the pile size may differ if the pile wasn't updated (ie.
508 // PictureLayer::Update didn't happen). In that case the pile will be empty.
509 DCHECK_IMPLIES(!raster_source
->GetSize().IsEmpty(),
510 bounds() == raster_source
->GetSize())
511 << " bounds " << bounds().ToString() << " pile "
512 << raster_source
->GetSize().ToString();
514 // The |raster_source_| is initially null, so have to check for that for the
516 bool could_have_tilings
= raster_source_
.get() && CanHaveTilings();
517 raster_source_
.swap(raster_source
);
519 // The |new_invalidation| must be cleared before updating tilings since they
520 // access the invalidation through the PictureLayerTilingClient interface.
521 invalidation_
.Clear();
522 invalidation_
.Swap(new_invalidation
);
524 bool can_have_tilings
= CanHaveTilings();
527 can_have_tilings
== GetPendingOrActiveTwinLayer()->CanHaveTilings());
529 // Need to call UpdateTiles again if CanHaveTilings changed.
530 if (could_have_tilings
!= can_have_tilings
)
531 layer_tree_impl()->set_needs_update_draw_properties();
533 if (!can_have_tilings
) {
538 // We could do this after doing UpdateTiles, which would avoid doing this for
539 // tilings that are going to disappear on the pending tree (if scale changed).
540 // But that would also be more complicated, so we just do it here for now.
541 tilings_
->UpdateTilingsToCurrentRasterSource(
542 raster_source_
, pending_set
, invalidation_
, MinimumContentsScale(),
543 MaximumContentsScale());
546 void PictureLayerImpl::UpdateCanUseLCDTextAfterCommit() {
547 // This function is only allowed to be called after commit, due to it not
548 // being smart about sharing tiles and because otherwise it would cause
549 // flashes by switching out tiles in place that may be currently on screen.
550 DCHECK(layer_tree_impl()->IsSyncTree());
552 // Don't allow the LCD text state to change once disabled.
553 if (!RasterSourceUsesLCDText())
555 if (can_use_lcd_text() == RasterSourceUsesLCDText())
558 // Raster sources are considered const, so in order to update the state
559 // a new one must be created and all tiles recreated.
560 scoped_refptr
<RasterSource
> new_raster_source
=
561 raster_source_
->CreateCloneWithoutLCDText();
562 // Synthetically invalidate everything.
563 gfx::Rect
bounds_rect(bounds());
564 Region
invalidation(bounds_rect
);
565 UpdateRasterSource(new_raster_source
, &invalidation
, nullptr);
566 SetUpdateRect(bounds_rect
);
568 DCHECK(!RasterSourceUsesLCDText());
571 bool PictureLayerImpl::RasterSourceUsesLCDText() const {
572 return raster_source_
? raster_source_
->CanUseLCDText()
573 : layer_tree_impl()->settings().can_use_lcd_text
;
576 void PictureLayerImpl::NotifyTileStateChanged(const Tile
* tile
) {
577 if (layer_tree_impl()->IsActiveTree()) {
578 gfx::RectF layer_damage_rect
=
579 gfx::ScaleRect(tile
->content_rect(), 1.f
/ tile
->contents_scale());
580 AddDamageRect(layer_damage_rect
);
584 void PictureLayerImpl::DidBeginTracing() {
585 raster_source_
->DidBeginTracing();
588 void PictureLayerImpl::ReleaseResources() {
589 // Recreate tilings with new settings, since some of those might change when
590 // we release resources.
595 void PictureLayerImpl::RecreateResources() {
596 tilings_
= CreatePictureLayerTilingSet();
598 // To avoid an edge case after lost context where the tree is up to date but
599 // the tilings have not been managed, request an update draw properties
600 // to force tilings to get managed.
601 layer_tree_impl()->set_needs_update_draw_properties();
604 skia::RefPtr
<SkPicture
> PictureLayerImpl::GetPicture() {
605 return raster_source_
->GetFlattenedPicture();
608 scoped_refptr
<Tile
> PictureLayerImpl::CreateTile(
609 float contents_scale
,
610 const gfx::Rect
& content_rect
) {
613 // We don't handle solid color masks, so we shouldn't bother analyzing those.
614 // Otherwise, always analyze to maximize memory savings.
616 flags
= Tile::USE_PICTURE_ANALYSIS
;
618 return layer_tree_impl()->tile_manager()->CreateTile(
619 raster_source_
.get(), content_rect
.size(), content_rect
, contents_scale
,
620 id(), layer_tree_impl()->source_frame_number(), flags
);
623 const Region
* PictureLayerImpl::GetPendingInvalidation() {
624 if (layer_tree_impl()->IsPendingTree())
625 return &invalidation_
;
626 if (layer_tree_impl()->IsRecycleTree())
628 DCHECK(layer_tree_impl()->IsActiveTree());
629 if (PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer())
630 return &twin_layer
->invalidation_
;
634 const PictureLayerTiling
* PictureLayerImpl::GetPendingOrActiveTwinTiling(
635 const PictureLayerTiling
* tiling
) const {
636 PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer();
639 return twin_layer
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
642 PictureLayerTiling
* PictureLayerImpl::GetRecycledTwinTiling(
643 const PictureLayerTiling
* tiling
) {
644 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
645 if (!recycled_twin
|| !recycled_twin
->tilings_
)
647 return recycled_twin
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
650 TilePriority::PriorityBin
PictureLayerImpl::GetMaxTilePriorityBin() const {
651 if (!HasValidTilePriorities())
652 return TilePriority::EVENTUALLY
;
653 return TilePriority::NOW
;
656 bool PictureLayerImpl::RequiresHighResToDraw() const {
657 return layer_tree_impl()->RequiresHighResToDraw();
660 gfx::Size
PictureLayerImpl::CalculateTileSize(
661 const gfx::Size
& content_bounds
) const {
662 int max_texture_size
=
663 layer_tree_impl()->resource_provider()->max_texture_size();
666 // Masks are not tiled, so if we can't cover the whole mask with one tile,
667 // we shouldn't have such a tiling at all.
668 DCHECK_LE(content_bounds
.width(), max_texture_size
);
669 DCHECK_LE(content_bounds
.height(), max_texture_size
);
670 return content_bounds
;
673 int default_tile_width
= 0;
674 int default_tile_height
= 0;
675 if (layer_tree_impl()->use_gpu_rasterization()) {
676 // For GPU rasterization, we pick an ideal tile size using the viewport
677 // so we don't need any settings. The current approach uses 4 tiles
678 // to cover the viewport vertically.
679 int viewport_width
= layer_tree_impl()->device_viewport_size().width();
680 int viewport_height
= layer_tree_impl()->device_viewport_size().height();
681 default_tile_width
= viewport_width
;
682 // Also, increase the height proportionally as the width decreases, and
683 // pad by our border texels to make the tiles exactly match the viewport.
685 if (content_bounds
.width() <= viewport_width
/ 2)
687 if (content_bounds
.width() <= viewport_width
/ 4)
689 default_tile_height
= RoundUp(viewport_height
, divisor
) / divisor
;
690 default_tile_height
+= 2 * PictureLayerTiling::kBorderTexels
;
691 default_tile_height
=
692 std::max(default_tile_height
, kMinHeightForGpuRasteredTile
);
694 // For CPU rasterization we use tile-size settings.
695 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
696 int max_untiled_content_width
= settings
.max_untiled_layer_size
.width();
697 int max_untiled_content_height
= settings
.max_untiled_layer_size
.height();
698 default_tile_width
= settings
.default_tile_size
.width();
699 default_tile_height
= settings
.default_tile_size
.height();
701 // If the content width is small, increase tile size vertically.
702 // If the content height is small, increase tile size horizontally.
703 // If both are less than the untiled-size, use a single tile.
704 if (content_bounds
.width() < default_tile_width
)
705 default_tile_height
= max_untiled_content_height
;
706 if (content_bounds
.height() < default_tile_height
)
707 default_tile_width
= max_untiled_content_width
;
708 if (content_bounds
.width() < max_untiled_content_width
&&
709 content_bounds
.height() < max_untiled_content_height
) {
710 default_tile_height
= max_untiled_content_height
;
711 default_tile_width
= max_untiled_content_width
;
715 int tile_width
= default_tile_width
;
716 int tile_height
= default_tile_height
;
718 // Clamp the tile width/height to the content width/height to save space.
719 if (content_bounds
.width() < default_tile_width
) {
720 tile_width
= std::min(tile_width
, content_bounds
.width());
721 tile_width
= RoundUp(tile_width
, kTileRoundUp
);
722 tile_width
= std::min(tile_width
, default_tile_width
);
724 if (content_bounds
.height() < default_tile_height
) {
725 tile_height
= std::min(tile_height
, content_bounds
.height());
726 tile_height
= RoundUp(tile_height
, kTileRoundUp
);
727 tile_height
= std::min(tile_height
, default_tile_height
);
730 // Under no circumstance should we be larger than the max texture size.
731 tile_width
= std::min(tile_width
, max_texture_size
);
732 tile_height
= std::min(tile_height
, max_texture_size
);
733 return gfx::Size(tile_width
, tile_height
);
736 void PictureLayerImpl::GetContentsResourceId(
737 ResourceProvider::ResourceId
* resource_id
,
738 gfx::Size
* resource_size
) const {
739 // The bounds and the pile size may differ if the pile wasn't updated (ie.
740 // PictureLayer::Update didn't happen). In that case the pile will be empty.
741 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
742 bounds() == raster_source_
->GetSize())
743 << " bounds " << bounds().ToString() << " pile "
744 << raster_source_
->GetSize().ToString();
745 gfx::Rect
content_rect(bounds());
746 PictureLayerTilingSet::CoverageIterator
iter(
747 tilings_
.get(), 1.f
, content_rect
, ideal_contents_scale_
);
749 // Mask resource not ready yet.
750 if (!iter
|| !*iter
) {
755 // Masks only supported if they fit on exactly one tile.
756 DCHECK(iter
.geometry_rect() == content_rect
)
757 << "iter rect " << iter
.geometry_rect().ToString() << " content rect "
758 << content_rect
.ToString();
760 const TileDrawInfo
& draw_info
= iter
->draw_info();
761 if (!draw_info
.IsReadyToDraw() ||
762 draw_info
.mode() != TileDrawInfo::RESOURCE_MODE
) {
767 *resource_id
= draw_info
.resource_id();
768 *resource_size
= draw_info
.resource_size();
771 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor
) {
772 if (nearest_neighbor_
== nearest_neighbor
)
775 nearest_neighbor_
= nearest_neighbor
;
776 NoteLayerPropertyChanged();
779 PictureLayerTiling
* PictureLayerImpl::AddTiling(float contents_scale
) {
780 DCHECK(CanHaveTilings());
781 DCHECK_GE(contents_scale
, MinimumContentsScale());
782 DCHECK_LE(contents_scale
, MaximumContentsScale());
783 DCHECK(raster_source_
->HasRecordings());
784 return tilings_
->AddTiling(contents_scale
, raster_source_
);
787 void PictureLayerImpl::RemoveAllTilings() {
788 tilings_
->RemoveAllTilings();
789 // If there are no tilings, then raster scales are no longer meaningful.
793 void PictureLayerImpl::AddTilingsForRasterScale() {
794 // Reset all resolution enums on tilings, we'll be setting new values in this
796 tilings_
->MarkAllTilingsNonIdeal();
798 PictureLayerTiling
* high_res
=
799 tilings_
->FindTilingWithScale(raster_contents_scale_
);
800 // We always need a high res tiling, so create one if it doesn't exist.
802 high_res
= AddTiling(raster_contents_scale_
);
804 // Try and find a low res tiling.
805 PictureLayerTiling
* low_res
= nullptr;
806 if (raster_contents_scale_
== low_res_raster_contents_scale_
)
809 low_res
= tilings_
->FindTilingWithScale(low_res_raster_contents_scale_
);
811 // Only create new low res tilings when the transform is static. This
812 // prevents wastefully creating a paired low res tiling for every new high res
813 // tiling during a pinch or a CSS animation.
814 bool can_have_low_res
= layer_tree_impl()->create_low_res_tiling();
815 bool needs_low_res
= !low_res
;
816 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
817 bool is_animating
= draw_properties().screen_space_transform_is_animating
;
818 if (can_have_low_res
&& needs_low_res
&& !is_pinching
&& !is_animating
)
819 low_res
= AddTiling(low_res_raster_contents_scale_
);
821 // Set low-res if we have one.
822 if (low_res
&& low_res
!= high_res
)
823 low_res
->set_resolution(LOW_RESOLUTION
);
825 // Make sure we always have one high-res (even if high == low).
826 high_res
->set_resolution(HIGH_RESOLUTION
);
828 if (layer_tree_impl()->IsPendingTree()) {
829 // On the pending tree, drop any tilings that are non-ideal since we don't
830 // need them to activate anyway.
831 tilings_
->RemoveNonIdealTilings();
834 SanityCheckTilingState();
837 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
838 if (was_screen_space_transform_animating_
!=
839 draw_properties().screen_space_transform_is_animating
)
842 if (draw_properties().screen_space_transform_is_animating
&&
843 raster_contents_scale_
!= ideal_contents_scale_
&&
844 ShouldAdjustRasterScaleDuringScaleAnimations())
847 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
848 if (is_pinching
&& raster_page_scale_
) {
849 // We change our raster scale when it is:
850 // - Higher than ideal (need a lower-res tiling available)
851 // - Too far from ideal (need a higher-res tiling available)
852 float ratio
= ideal_page_scale_
/ raster_page_scale_
;
853 if (raster_page_scale_
> ideal_page_scale_
||
854 ratio
> kMaxScaleRatioDuringPinch
)
859 // When not pinching, match the ideal page scale factor.
860 if (raster_page_scale_
!= ideal_page_scale_
)
864 // Always match the ideal device scale factor.
865 if (raster_device_scale_
!= ideal_device_scale_
)
868 // When the source scale changes we want to match it, but not when animating
869 // or when we've fixed the scale in place.
870 if (!draw_properties().screen_space_transform_is_animating
&&
871 !raster_source_scale_is_fixed_
&&
872 raster_source_scale_
!= ideal_source_scale_
)
875 if (raster_contents_scale_
> MaximumContentsScale())
877 if (raster_contents_scale_
< MinimumContentsScale())
883 void PictureLayerImpl::RecalculateRasterScales() {
884 float old_raster_contents_scale
= raster_contents_scale_
;
885 float old_raster_page_scale
= raster_page_scale_
;
886 float old_raster_source_scale
= raster_source_scale_
;
888 raster_device_scale_
= ideal_device_scale_
;
889 raster_page_scale_
= ideal_page_scale_
;
890 raster_source_scale_
= ideal_source_scale_
;
891 raster_contents_scale_
= ideal_contents_scale_
;
893 // If we're not animating, or leaving an animation, and the
894 // ideal_source_scale_ changes, then things are unpredictable, and we fix
895 // the raster_source_scale_ in place.
896 if (old_raster_source_scale
&&
897 !draw_properties().screen_space_transform_is_animating
&&
898 !was_screen_space_transform_animating_
&&
899 old_raster_source_scale
!= ideal_source_scale_
)
900 raster_source_scale_is_fixed_
= true;
902 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
903 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
904 // tree. This will allow CSS scale changes to get re-rastered at an
905 // appropriate rate. (crbug.com/413636)
906 if (raster_source_scale_is_fixed_
) {
907 raster_contents_scale_
/= raster_source_scale_
;
908 raster_source_scale_
= 1.f
;
911 // During pinch we completely ignore the current ideal scale, and just use
912 // a multiple of the previous scale.
913 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
914 if (is_pinching
&& old_raster_contents_scale
) {
915 // See ShouldAdjustRasterScale:
916 // - When zooming out, preemptively create new tiling at lower resolution.
917 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
918 bool zooming_out
= old_raster_page_scale
> ideal_page_scale_
;
919 float desired_contents_scale
= old_raster_contents_scale
;
921 while (desired_contents_scale
> ideal_contents_scale_
)
922 desired_contents_scale
/= kMaxScaleRatioDuringPinch
;
924 while (desired_contents_scale
< ideal_contents_scale_
)
925 desired_contents_scale
*= kMaxScaleRatioDuringPinch
;
927 raster_contents_scale_
= tilings_
->GetSnappedContentsScale(
928 desired_contents_scale
, kSnapToExistingTilingRatio
);
930 raster_contents_scale_
/ raster_device_scale_
/ raster_source_scale_
;
933 // If we're not re-rasterizing during animation, rasterize at the maximum
934 // scale that will occur during the animation, if the maximum scale is
935 // known. However we want to avoid excessive memory use. If the scale is
936 // smaller than what we would choose otherwise, then it's always better off
937 // for us memory-wise. But otherwise, we don't choose a scale at which this
938 // layer's rastered content would become larger than the viewport.
939 if (draw_properties().screen_space_transform_is_animating
&&
940 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
941 bool can_raster_at_maximum_scale
= false;
942 // TODO(ajuma): If we need to deal with scale-down animations starting right
943 // as a layer gets promoted, then we'd want to have the
944 // |starting_animation_contents_scale| passed in here as a separate draw
945 // property so we could try use that when the max is too large.
946 // See crbug.com/422341.
947 float maximum_scale
= draw_properties().maximum_animation_contents_scale
;
949 gfx::Size bounds_at_maximum_scale
= gfx::ToCeiledSize(
950 gfx::ScaleSize(raster_source_
->GetSize(), maximum_scale
));
951 int64 maximum_area
= static_cast<int64
>(bounds_at_maximum_scale
.width()) *
952 static_cast<int64
>(bounds_at_maximum_scale
.height());
953 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
954 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
955 static_cast<int64
>(viewport
.height());
956 if (maximum_area
<= viewport_area
)
957 can_raster_at_maximum_scale
= true;
959 // Use the computed scales for the raster scale directly, do not try to use
960 // the ideal scale here. The current ideal scale may be way too large in the
961 // case of an animation with scale, and will be constantly changing.
962 if (can_raster_at_maximum_scale
)
963 raster_contents_scale_
= maximum_scale
;
965 raster_contents_scale_
= 1.f
* ideal_page_scale_
* ideal_device_scale_
;
968 raster_contents_scale_
=
969 std::max(raster_contents_scale_
, MinimumContentsScale());
970 raster_contents_scale_
=
971 std::min(raster_contents_scale_
, MaximumContentsScale());
972 DCHECK_GE(raster_contents_scale_
, MinimumContentsScale());
973 DCHECK_LE(raster_contents_scale_
, MaximumContentsScale());
975 // If this layer would create zero or one tiles at this content scale,
976 // don't create a low res tiling.
977 gfx::Size raster_bounds
= gfx::ToCeiledSize(
978 gfx::ScaleSize(raster_source_
->GetSize(), raster_contents_scale_
));
979 gfx::Size tile_size
= CalculateTileSize(raster_bounds
);
980 bool tile_covers_bounds
= tile_size
.width() >= raster_bounds
.width() &&
981 tile_size
.height() >= raster_bounds
.height();
982 if (tile_size
.IsEmpty() || tile_covers_bounds
) {
983 low_res_raster_contents_scale_
= raster_contents_scale_
;
987 float low_res_factor
=
988 layer_tree_impl()->settings().low_res_contents_scale_factor
;
989 low_res_raster_contents_scale_
=
990 std::max(raster_contents_scale_
* low_res_factor
, MinimumContentsScale());
991 DCHECK_LE(low_res_raster_contents_scale_
, raster_contents_scale_
);
992 DCHECK_GE(low_res_raster_contents_scale_
, MinimumContentsScale());
993 DCHECK_LE(low_res_raster_contents_scale_
, MaximumContentsScale());
996 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
997 const std::vector
<PictureLayerTiling
*>& used_tilings
) {
998 DCHECK(layer_tree_impl()->IsActiveTree());
999 if (tilings_
->num_tilings() == 0)
1002 float min_acceptable_high_res_scale
= std::min(
1003 raster_contents_scale_
, ideal_contents_scale_
);
1004 float max_acceptable_high_res_scale
= std::max(
1005 raster_contents_scale_
, ideal_contents_scale_
);
1007 PictureLayerImpl
* twin
= GetPendingOrActiveTwinLayer();
1008 if (twin
&& twin
->CanHaveTilings()) {
1009 min_acceptable_high_res_scale
= std::min(
1010 min_acceptable_high_res_scale
,
1011 std::min(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1012 max_acceptable_high_res_scale
= std::max(
1013 max_acceptable_high_res_scale
,
1014 std::max(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1017 PictureLayerTilingSet
* twin_set
= twin
? twin
->tilings_
.get() : nullptr;
1018 PictureLayerImpl
* recycled_twin
= GetRecycledTwinLayer();
1019 PictureLayerTilingSet
* recycled_twin_set
=
1020 recycled_twin
? recycled_twin
->tilings_
.get() : nullptr;
1022 tilings_
->CleanUpTilings(min_acceptable_high_res_scale
,
1023 max_acceptable_high_res_scale
, used_tilings
,
1024 layer_tree_impl()->create_low_res_tiling(), twin_set
,
1027 if (recycled_twin_set
&& recycled_twin_set
->num_tilings() == 0)
1028 recycled_twin
->ResetRasterScale();
1030 DCHECK_GT(tilings_
->num_tilings(), 0u);
1031 SanityCheckTilingState();
1034 float PictureLayerImpl::MinimumContentsScale() const {
1035 float setting_min
= layer_tree_impl()->settings().minimum_contents_scale
;
1037 // If the contents scale is less than 1 / width (also for height),
1038 // then it will end up having less than one pixel of content in that
1039 // dimension. Bump the minimum contents scale up in this case to prevent
1040 // this from happening.
1041 int min_dimension
= std::min(raster_source_
->GetSize().width(),
1042 raster_source_
->GetSize().height());
1046 return std::max(1.f
/ min_dimension
, setting_min
);
1049 float PictureLayerImpl::MaximumContentsScale() const {
1050 // Masks can not have tilings that would become larger than the
1051 // max_texture_size since they use a single tile for the entire
1052 // tiling. Other layers can have tilings of any scale.
1054 return std::numeric_limits
<float>::max();
1056 int max_texture_size
=
1057 layer_tree_impl()->resource_provider()->max_texture_size();
1058 float max_scale_width
=
1059 static_cast<float>(max_texture_size
) / bounds().width();
1060 float max_scale_height
=
1061 static_cast<float>(max_texture_size
) / bounds().height();
1062 float max_scale
= std::min(max_scale_width
, max_scale_height
);
1063 // We require that multiplying the layer size by the contents scale and
1064 // ceiling produces a value <= |max_texture_size|. Because for large layer
1065 // sizes floating point ambiguity may crop up, making the result larger or
1066 // smaller than expected, we use a slightly smaller floating point value for
1067 // the scale, to help ensure that the resulting content bounds will never end
1068 // up larger than |max_texture_size|.
1069 return nextafterf(max_scale
, 0.f
);
1072 void PictureLayerImpl::ResetRasterScale() {
1073 raster_page_scale_
= 0.f
;
1074 raster_device_scale_
= 0.f
;
1075 raster_source_scale_
= 0.f
;
1076 raster_contents_scale_
= 0.f
;
1077 low_res_raster_contents_scale_
= 0.f
;
1078 raster_source_scale_is_fixed_
= false;
1081 bool PictureLayerImpl::CanHaveTilings() const {
1082 if (raster_source_
->IsSolidColor())
1084 if (!DrawsContent())
1086 if (!raster_source_
->HasRecordings())
1088 // If the |raster_source_| has a recording it should have non-empty bounds.
1089 DCHECK(!raster_source_
->GetSize().IsEmpty());
1090 if (MaximumContentsScale() < MinimumContentsScale())
1095 void PictureLayerImpl::SanityCheckTilingState() const {
1097 // Recycle tree doesn't have any restrictions.
1098 if (layer_tree_impl()->IsRecycleTree())
1101 if (!CanHaveTilings()) {
1102 DCHECK_EQ(0u, tilings_
->num_tilings());
1105 if (tilings_
->num_tilings() == 0)
1108 // We should only have one high res tiling.
1109 DCHECK_EQ(1, tilings_
->NumHighResTilings());
1113 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1114 return layer_tree_impl()->use_gpu_rasterization();
1117 float PictureLayerImpl::MaximumTilingContentsScale() const {
1118 float max_contents_scale
= tilings_
->GetMaximumContentsScale();
1119 return std::max(max_contents_scale
, MinimumContentsScale());
1122 scoped_ptr
<PictureLayerTilingSet
>
1123 PictureLayerImpl::CreatePictureLayerTilingSet() {
1124 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
1125 return PictureLayerTilingSet::Create(
1126 this, settings
.max_tiles_for_interest_area
,
1127 layer_tree_impl()->use_gpu_rasterization()
1128 ? settings
.gpu_rasterization_skewport_target_time_in_seconds
1129 : settings
.skewport_target_time_in_seconds
,
1130 settings
.skewport_extrapolation_limit_in_content_pixels
);
1133 void PictureLayerImpl::UpdateIdealScales() {
1134 DCHECK(CanHaveTilings());
1136 float min_contents_scale
= MinimumContentsScale();
1137 DCHECK_GT(min_contents_scale
, 0.f
);
1138 float min_page_scale
= layer_tree_impl()->min_page_scale_factor();
1139 DCHECK_GT(min_page_scale
, 0.f
);
1140 float min_device_scale
= 1.f
;
1141 float min_source_scale
=
1142 min_contents_scale
/ min_page_scale
/ min_device_scale
;
1144 float ideal_page_scale
= draw_properties().page_scale_factor
;
1145 float ideal_device_scale
= draw_properties().device_scale_factor
;
1146 float ideal_source_scale
= draw_properties().ideal_contents_scale
/
1147 ideal_page_scale
/ ideal_device_scale
;
1148 ideal_contents_scale_
=
1149 std::max(draw_properties().ideal_contents_scale
, min_contents_scale
);
1150 ideal_page_scale_
= draw_properties().page_scale_factor
;
1151 ideal_device_scale_
= draw_properties().device_scale_factor
;
1152 ideal_source_scale_
= std::max(ideal_source_scale
, min_source_scale
);
1155 void PictureLayerImpl::GetDebugBorderProperties(
1157 float* width
) const {
1158 *color
= DebugColors::TiledContentLayerBorderColor();
1159 *width
= DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1162 void PictureLayerImpl::GetAllTilesForTracing(
1163 std::set
<const Tile
*>* tiles
) const {
1166 tilings_
->GetAllTilesForTracing(tiles
);
1169 void PictureLayerImpl::AsValueInto(
1170 base::trace_event::TracedValue
* state
) const {
1171 LayerImpl::AsValueInto(state
);
1172 state
->SetDouble("ideal_contents_scale", ideal_contents_scale_
);
1173 state
->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1174 state
->BeginArray("tilings");
1175 tilings_
->AsValueInto(state
);
1178 MathUtil::AddToTracedValue("tile_priority_rect",
1179 viewport_rect_for_tile_priority_in_content_space_
,
1181 MathUtil::AddToTracedValue("visible_rect", visible_content_rect(), state
);
1183 state
->BeginArray("pictures");
1184 raster_source_
->AsValueInto(state
);
1187 state
->BeginArray("invalidation");
1188 invalidation_
.AsValueInto(state
);
1191 state
->BeginArray("coverage_tiles");
1192 for (PictureLayerTilingSet::CoverageIterator
iter(
1193 tilings_
.get(), 1.f
, gfx::Rect(raster_source_
->GetSize()),
1194 ideal_contents_scale_
);
1196 state
->BeginDictionary();
1198 MathUtil::AddToTracedValue("geometry_rect", iter
.geometry_rect(), state
);
1201 TracedValue::SetIDRef(*iter
, state
, "tile");
1203 state
->EndDictionary();
1208 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1209 return tilings_
->GPUMemoryUsageInBytes();
1212 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1213 benchmark
->RunOnLayer(this);
1216 WhichTree
PictureLayerImpl::GetTree() const {
1217 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
1220 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1221 return !layer_tree_impl()->IsRecycleTree();
1224 bool PictureLayerImpl::HasValidTilePriorities() const {
1225 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();