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/debug/debug_colors.h"
16 #include "cc/debug/micro_benchmark_impl.h"
17 #include "cc/debug/traced_value.h"
18 #include "cc/layers/append_quads_data.h"
19 #include "cc/layers/solid_color_layer_impl.h"
20 #include "cc/output/begin_frame_args.h"
21 #include "cc/quads/checkerboard_draw_quad.h"
22 #include "cc/quads/debug_border_draw_quad.h"
23 #include "cc/quads/picture_draw_quad.h"
24 #include "cc/quads/solid_color_draw_quad.h"
25 #include "cc/quads/tile_draw_quad.h"
26 #include "cc/tiles/tile_manager.h"
27 #include "cc/tiles/tiling_set_raster_queue_all.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "cc/trees/occlusion.h"
30 #include "ui/gfx/geometry/quad_f.h"
31 #include "ui/gfx/geometry/rect_conversions.h"
32 #include "ui/gfx/geometry/size_conversions.h"
35 // This must be > 1 as we multiply or divide by this to find a new raster
36 // scale during pinch.
37 const float kMaxScaleRatioDuringPinch
= 2.0f
;
39 // When creating a new tiling during pinch, snap to an existing
40 // tiling's scale if the desired scale is within this ratio.
41 const float kSnapToExistingTilingRatio
= 1.2f
;
43 // Even for really wide viewports, at some point GPU raster should use
44 // less than 4 tiles to fill the viewport. This is set to 256 as a
45 // sane minimum for now, but we might want to tune this for low-end.
46 const int kMinHeightForGpuRasteredTile
= 256;
48 // When making odd-sized tiles, round them up to increase the chances
49 // of using the same tile size.
50 const int kTileRoundUp
= 64;
56 PictureLayerImpl::PictureLayerImpl(
57 LayerTreeImpl
* tree_impl
,
60 scoped_refptr
<SyncedScrollOffset
> scroll_offset
)
61 : LayerImpl(tree_impl
, id
, scroll_offset
),
63 tilings_(CreatePictureLayerTilingSet()),
64 ideal_page_scale_(0.f
),
65 ideal_device_scale_(0.f
),
66 ideal_source_scale_(0.f
),
67 ideal_contents_scale_(0.f
),
68 raster_page_scale_(0.f
),
69 raster_device_scale_(0.f
),
70 raster_source_scale_(0.f
),
71 raster_contents_scale_(0.f
),
72 low_res_raster_contents_scale_(0.f
),
73 raster_source_scale_is_fixed_(false),
74 was_screen_space_transform_animating_(false),
75 only_used_low_res_last_append_quads_(false),
77 nearest_neighbor_(false) {
78 layer_tree_impl()->RegisterPictureLayerImpl(this);
81 PictureLayerImpl::~PictureLayerImpl() {
83 twin_layer_
->twin_layer_
= nullptr;
84 layer_tree_impl()->UnregisterPictureLayerImpl(this);
87 const char* PictureLayerImpl::LayerTypeAsString() const {
88 return "cc::PictureLayerImpl";
91 scoped_ptr
<LayerImpl
> PictureLayerImpl::CreateLayerImpl(
92 LayerTreeImpl
* tree_impl
) {
93 return PictureLayerImpl::Create(tree_impl
, id(), is_mask_
,
94 synced_scroll_offset());
97 void PictureLayerImpl::PushPropertiesTo(LayerImpl
* base_layer
) {
98 PictureLayerImpl
* layer_impl
= static_cast<PictureLayerImpl
*>(base_layer
);
99 DCHECK_EQ(layer_impl
->is_mask_
, is_mask_
);
101 LayerImpl::PushPropertiesTo(base_layer
);
103 // Twin relationships should never change once established.
104 DCHECK_IMPLIES(twin_layer_
, twin_layer_
== layer_impl
);
105 DCHECK_IMPLIES(twin_layer_
, layer_impl
->twin_layer_
== this);
106 // The twin relationship does not need to exist before the first
107 // PushPropertiesTo from pending to active layer since before that the active
108 // layer can not have a pile or tilings, it has only been created and inserted
109 // into the tree at that point.
110 twin_layer_
= layer_impl
;
111 layer_impl
->twin_layer_
= this;
113 layer_impl
->SetNearestNeighbor(nearest_neighbor_
);
115 // Solid color layers have no tilings.
116 DCHECK_IMPLIES(raster_source_
->IsSolidColor(), tilings_
->num_tilings() == 0);
117 // The pending tree should only have a high res (and possibly low res) tiling.
118 DCHECK_LE(tilings_
->num_tilings(),
119 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
121 layer_impl
->set_gpu_raster_max_texture_size(gpu_raster_max_texture_size_
);
122 layer_impl
->UpdateRasterSource(raster_source_
, &invalidation_
,
124 DCHECK(invalidation_
.IsEmpty());
126 // After syncing a solid color layer, the active layer has no tilings.
127 DCHECK_IMPLIES(raster_source_
->IsSolidColor(),
128 layer_impl
->tilings_
->num_tilings() == 0);
130 layer_impl
->raster_page_scale_
= raster_page_scale_
;
131 layer_impl
->raster_device_scale_
= raster_device_scale_
;
132 layer_impl
->raster_source_scale_
= raster_source_scale_
;
133 layer_impl
->raster_contents_scale_
= raster_contents_scale_
;
134 layer_impl
->low_res_raster_contents_scale_
= low_res_raster_contents_scale_
;
136 layer_impl
->SanityCheckTilingState();
138 // We always need to push properties.
139 // See http://crbug.com/303943
140 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
141 needs_push_properties_
= true;
144 void PictureLayerImpl::AppendQuads(RenderPass
* render_pass
,
145 AppendQuadsData
* append_quads_data
) {
146 // The bounds and the pile size may differ if the pile wasn't updated (ie.
147 // PictureLayer::Update didn't happen). In that case the pile will be empty.
148 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
149 bounds() == raster_source_
->GetSize())
150 << " bounds " << bounds().ToString() << " pile "
151 << raster_source_
->GetSize().ToString();
153 SharedQuadState
* shared_quad_state
=
154 render_pass
->CreateAndAppendSharedQuadState();
156 if (raster_source_
->IsSolidColor()) {
157 PopulateSharedQuadState(shared_quad_state
);
159 AppendDebugBorderQuad(
160 render_pass
, bounds(), shared_quad_state
, append_quads_data
);
162 SolidColorLayerImpl::AppendSolidQuads(
163 render_pass
, draw_properties().occlusion_in_content_space
,
164 shared_quad_state
, visible_content_rect(),
165 raster_source_
->GetSolidColor(), append_quads_data
);
169 float max_contents_scale
= MaximumTilingContentsScale();
170 PopulateScaledSharedQuadState(shared_quad_state
, max_contents_scale
);
171 Occlusion scaled_occlusion
=
173 .occlusion_in_content_space
.GetOcclusionWithGivenDrawTransform(
174 shared_quad_state
->content_to_target_transform
);
176 if (current_draw_mode_
== DRAW_MODE_RESOURCELESS_SOFTWARE
) {
177 AppendDebugBorderQuad(
178 render_pass
, shared_quad_state
->content_bounds
, shared_quad_state
,
179 append_quads_data
, DebugColors::DirectPictureBorderColor(),
180 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
182 gfx::Rect geometry_rect
= shared_quad_state
->visible_content_rect
;
183 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
184 gfx::Rect visible_geometry_rect
=
185 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
186 if (visible_geometry_rect
.IsEmpty())
189 gfx::Rect quad_content_rect
= shared_quad_state
->visible_content_rect
;
190 gfx::Size texture_size
= quad_content_rect
.size();
191 gfx::RectF texture_rect
= gfx::RectF(texture_size
);
193 PictureDrawQuad
* quad
=
194 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
195 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
196 visible_geometry_rect
, texture_rect
, texture_size
,
197 nearest_neighbor_
, RGBA_8888
, quad_content_rect
,
198 max_contents_scale
, raster_source_
);
199 ValidateQuadResources(quad
);
203 AppendDebugBorderQuad(render_pass
, shared_quad_state
->content_bounds
,
204 shared_quad_state
, append_quads_data
);
206 if (ShowDebugBorders()) {
207 for (PictureLayerTilingSet::CoverageIterator
iter(
208 tilings_
.get(), max_contents_scale
,
209 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
213 if (*iter
&& iter
->draw_info().IsReadyToDraw()) {
214 TileDrawInfo::Mode mode
= iter
->draw_info().mode();
215 if (mode
== TileDrawInfo::SOLID_COLOR_MODE
) {
216 color
= DebugColors::SolidColorTileBorderColor();
217 width
= DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
218 } else if (mode
== TileDrawInfo::OOM_MODE
) {
219 color
= DebugColors::OOMTileBorderColor();
220 width
= DebugColors::OOMTileBorderWidth(layer_tree_impl());
221 } else if (iter
.resolution() == HIGH_RESOLUTION
) {
222 color
= DebugColors::HighResTileBorderColor();
223 width
= DebugColors::HighResTileBorderWidth(layer_tree_impl());
224 } else if (iter
.resolution() == LOW_RESOLUTION
) {
225 color
= DebugColors::LowResTileBorderColor();
226 width
= DebugColors::LowResTileBorderWidth(layer_tree_impl());
227 } else if (iter
->contents_scale() > max_contents_scale
) {
228 color
= DebugColors::ExtraHighResTileBorderColor();
229 width
= DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
231 color
= DebugColors::ExtraLowResTileBorderColor();
232 width
= DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
235 color
= DebugColors::MissingTileBorderColor();
236 width
= DebugColors::MissingTileBorderWidth(layer_tree_impl());
239 DebugBorderDrawQuad
* debug_border_quad
=
240 render_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
241 gfx::Rect geometry_rect
= iter
.geometry_rect();
242 gfx::Rect visible_geometry_rect
= geometry_rect
;
243 debug_border_quad
->SetNew(shared_quad_state
,
245 visible_geometry_rect
,
251 // Keep track of the tilings that were used so that tilings that are
252 // unused can be considered for removal.
253 last_append_quads_tilings_
.clear();
255 // Ignore missing tiles outside of viewport for tile priority. This is
256 // normally the same as draw viewport but can be independently overridden by
257 // embedders like Android WebView with SetExternalDrawConstraints.
258 gfx::Rect scaled_viewport_for_tile_priority
= gfx::ScaleToEnclosingRect(
259 viewport_rect_for_tile_priority_in_content_space_
, max_contents_scale
);
261 size_t missing_tile_count
= 0u;
262 size_t on_demand_missing_tile_count
= 0u;
263 only_used_low_res_last_append_quads_
= true;
264 for (PictureLayerTilingSet::CoverageIterator
iter(
265 tilings_
.get(), max_contents_scale
,
266 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
268 gfx::Rect geometry_rect
= iter
.geometry_rect();
269 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
270 gfx::Rect visible_geometry_rect
=
271 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
272 if (visible_geometry_rect
.IsEmpty())
275 append_quads_data
->visible_content_area
+=
276 visible_geometry_rect
.width() * visible_geometry_rect
.height();
278 bool has_draw_quad
= false;
279 if (*iter
&& iter
->draw_info().IsReadyToDraw()) {
280 const TileDrawInfo
& draw_info
= iter
->draw_info();
281 switch (draw_info
.mode()) {
282 case TileDrawInfo::RESOURCE_MODE
: {
283 gfx::RectF texture_rect
= iter
.texture_rect();
285 // The raster_contents_scale_ is the best scale that the layer is
286 // trying to produce, even though it may not be ideal. Since that's
287 // the best the layer can promise in the future, consider those as
288 // complete. But if a tile is ideal scale, we don't want to consider
289 // it incomplete and trying to replace it with a tile at a worse
291 if (iter
->contents_scale() != raster_contents_scale_
&&
292 iter
->contents_scale() != ideal_contents_scale_
&&
293 geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
294 append_quads_data
->num_incomplete_tiles
++;
298 render_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
299 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
300 visible_geometry_rect
, draw_info
.resource_id(),
301 texture_rect
, draw_info
.resource_size(),
302 draw_info
.contents_swizzled(), nearest_neighbor_
);
303 ValidateQuadResources(quad
);
304 has_draw_quad
= true;
307 case TileDrawInfo::SOLID_COLOR_MODE
: {
308 SolidColorDrawQuad
* quad
=
309 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
310 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
311 draw_info
.solid_color(), false);
312 ValidateQuadResources(quad
);
313 has_draw_quad
= true;
316 case TileDrawInfo::OOM_MODE
:
317 break; // Checkerboard.
321 if (!has_draw_quad
) {
322 if (draw_checkerboard_for_missing_tiles()) {
323 CheckerboardDrawQuad
* quad
=
324 render_pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
325 SkColor color
= DebugColors::DefaultCheckerboardColor();
326 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
327 color
, draw_properties().device_scale_factor
);
329 SkColor color
= SafeOpaqueBackgroundColor();
330 SolidColorDrawQuad
* quad
=
331 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
332 quad
->SetNew(shared_quad_state
,
334 visible_geometry_rect
,
337 ValidateQuadResources(quad
);
340 if (geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
341 append_quads_data
->num_missing_tiles
++;
342 ++missing_tile_count
;
344 append_quads_data
->approximated_visible_content_area
+=
345 visible_geometry_rect
.width() * visible_geometry_rect
.height();
346 append_quads_data
->checkerboarded_visible_content_area
+=
347 visible_geometry_rect
.width() * visible_geometry_rect
.height();
351 if (iter
.resolution() != HIGH_RESOLUTION
) {
352 append_quads_data
->approximated_visible_content_area
+=
353 visible_geometry_rect
.width() * visible_geometry_rect
.height();
356 // If we have a draw quad, but it's not low resolution, then
357 // mark that we've used something other than low res to draw.
358 if (iter
.resolution() != LOW_RESOLUTION
)
359 only_used_low_res_last_append_quads_
= false;
361 if (last_append_quads_tilings_
.empty() ||
362 last_append_quads_tilings_
.back() != iter
.CurrentTiling()) {
363 last_append_quads_tilings_
.push_back(iter
.CurrentTiling());
367 if (missing_tile_count
) {
368 TRACE_EVENT_INSTANT2("cc",
369 "PictureLayerImpl::AppendQuads checkerboard",
370 TRACE_EVENT_SCOPE_THREAD
,
371 "missing_tile_count",
373 "on_demand_missing_tile_count",
374 on_demand_missing_tile_count
);
377 // Aggressively remove any tilings that are not seen to save memory. Note
378 // that this is at the expense of doing cause more frequent re-painting. A
379 // better scheme would be to maintain a tighter visible_content_rect for the
381 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
384 bool PictureLayerImpl::UpdateTiles(bool resourceless_software_draw
) {
385 DCHECK_EQ(1.f
, contents_scale_x());
386 DCHECK_EQ(1.f
, contents_scale_y());
388 if (!resourceless_software_draw
) {
389 visible_rect_for_tile_priority_
= visible_content_rect();
392 if (!CanHaveTilings()) {
393 ideal_page_scale_
= 0.f
;
394 ideal_device_scale_
= 0.f
;
395 ideal_contents_scale_
= 0.f
;
396 ideal_source_scale_
= 0.f
;
397 SanityCheckTilingState();
401 // Remove any non-ideal tilings that were not used last time we generated
402 // quads to save memory and processing time. Note that pending tree should
403 // only have one or two tilings (high and low res), so only clean up the
404 // active layer. This cleans it up here in case AppendQuads didn't run.
405 // If it did run, this would not remove any additional tilings.
406 if (layer_tree_impl()->IsActiveTree())
407 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
411 if (!raster_contents_scale_
|| ShouldAdjustRasterScale()) {
412 RecalculateRasterScales();
413 AddTilingsForRasterScale();
416 DCHECK(raster_page_scale_
);
417 DCHECK(raster_device_scale_
);
418 DCHECK(raster_source_scale_
);
419 DCHECK(raster_contents_scale_
);
420 DCHECK(low_res_raster_contents_scale_
);
422 was_screen_space_transform_animating_
=
423 draw_properties().screen_space_transform_is_animating
;
425 if (draw_transform_is_animating())
426 raster_source_
->SetShouldAttemptToUseDistanceFieldText();
428 double current_frame_time_in_seconds
=
429 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time
-
430 base::TimeTicks()).InSecondsF();
431 UpdateViewportRectForTilePriorityInContentSpace();
433 // The tiling set can require tiles for activation any of the following
434 // conditions are true:
435 // - This layer produced a high-res or non-ideal-res tile last frame.
436 // - We're in requires high res to draw mode.
437 // - We're not in smoothness takes priority mode.
438 // To put different, the tiling set can't require tiles for activation if
439 // we're in smoothness mode and only used low-res or checkerboard to draw last
440 // frame and we don't need high res to draw.
442 // The reason for this is that we should be able to activate sooner and get a
443 // more up to date recording, so we don't run out of recording on the active
445 bool can_require_tiles_for_activation
=
446 !only_used_low_res_last_append_quads_
|| RequiresHighResToDraw() ||
447 !layer_tree_impl()->SmoothnessTakesPriority();
449 static const Occlusion kEmptyOcclusion
;
450 const Occlusion
& occlusion_in_content_space
=
451 layer_tree_impl()->settings().use_occlusion_for_tile_prioritization
452 ? draw_properties().occlusion_in_content_space
455 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
456 // they are the same space in picture layer, as contents scale is always 1.
457 bool updated
= tilings_
->UpdateTilePriorities(
458 viewport_rect_for_tile_priority_in_content_space_
, ideal_contents_scale_
,
459 current_frame_time_in_seconds
, occlusion_in_content_space
,
460 can_require_tiles_for_activation
);
464 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
465 // If visible_rect_for_tile_priority_ is empty or
466 // viewport_rect_for_tile_priority is set to be different from the device
467 // viewport, try to inverse project the viewport into layer space and use
468 // that. Otherwise just use visible_rect_for_tile_priority_
469 gfx::Rect visible_rect_in_content_space
= visible_rect_for_tile_priority_
;
470 gfx::Rect viewport_rect_for_tile_priority
=
471 layer_tree_impl()->ViewportRectForTilePriority();
472 if (visible_rect_in_content_space
.IsEmpty() ||
473 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority
) {
474 gfx::Transform
view_to_layer(gfx::Transform::kSkipInitialization
);
475 if (screen_space_transform().GetInverse(&view_to_layer
)) {
476 // Transform from view space to content space.
477 visible_rect_in_content_space
=
478 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
479 view_to_layer
, viewport_rect_for_tile_priority
));
482 viewport_rect_for_tile_priority_in_content_space_
=
483 visible_rect_in_content_space
;
486 PictureLayerImpl
* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
487 if (!twin_layer_
|| !twin_layer_
->IsOnActiveOrPendingTree())
492 void PictureLayerImpl::UpdateRasterSource(
493 scoped_refptr
<RasterSource
> raster_source
,
494 Region
* new_invalidation
,
495 const PictureLayerTilingSet
* pending_set
) {
496 // The bounds and the pile size may differ if the pile wasn't updated (ie.
497 // PictureLayer::Update didn't happen). In that case the pile will be empty.
498 DCHECK_IMPLIES(!raster_source
->GetSize().IsEmpty(),
499 bounds() == raster_source
->GetSize())
500 << " bounds " << bounds().ToString() << " pile "
501 << raster_source
->GetSize().ToString();
503 // The |raster_source_| is initially null, so have to check for that for the
505 bool could_have_tilings
= raster_source_
.get() && CanHaveTilings();
506 raster_source_
.swap(raster_source
);
508 // The |new_invalidation| must be cleared before updating tilings since they
509 // access the invalidation through the PictureLayerTilingClient interface.
510 invalidation_
.Clear();
511 invalidation_
.Swap(new_invalidation
);
513 bool can_have_tilings
= CanHaveTilings();
516 can_have_tilings
== GetPendingOrActiveTwinLayer()->CanHaveTilings());
518 // Need to call UpdateTiles again if CanHaveTilings changed.
519 if (could_have_tilings
!= can_have_tilings
)
520 layer_tree_impl()->set_needs_update_draw_properties();
522 if (!can_have_tilings
) {
527 // We could do this after doing UpdateTiles, which would avoid doing this for
528 // tilings that are going to disappear on the pending tree (if scale changed).
529 // But that would also be more complicated, so we just do it here for now.
531 tilings_
->UpdateTilingsToCurrentRasterSourceForActivation(
532 raster_source_
, pending_set
, invalidation_
, MinimumContentsScale(),
533 MaximumContentsScale());
535 tilings_
->UpdateTilingsToCurrentRasterSourceForCommit(
536 raster_source_
, invalidation_
, MinimumContentsScale(),
537 MaximumContentsScale());
541 void PictureLayerImpl::UpdateCanUseLCDTextAfterCommit() {
542 // This function is only allowed to be called after commit, due to it not
543 // being smart about sharing tiles and because otherwise it would cause
544 // flashes by switching out tiles in place that may be currently on screen.
545 DCHECK(layer_tree_impl()->IsSyncTree());
547 // Don't allow the LCD text state to change once disabled.
548 if (!RasterSourceUsesLCDText())
550 if (can_use_lcd_text() == RasterSourceUsesLCDText())
553 // Raster sources are considered const, so in order to update the state
554 // a new one must be created and all tiles recreated.
555 scoped_refptr
<RasterSource
> new_raster_source
=
556 raster_source_
->CreateCloneWithoutLCDText();
557 raster_source_
.swap(new_raster_source
);
559 // Synthetically invalidate everything.
560 gfx::Rect
bounds_rect(bounds());
561 invalidation_
= Region(bounds_rect
);
562 tilings_
->UpdateRasterSourceDueToLCDChange(raster_source_
, invalidation_
);
563 SetUpdateRect(bounds_rect
);
565 DCHECK(!RasterSourceUsesLCDText());
568 bool PictureLayerImpl::RasterSourceUsesLCDText() const {
569 return raster_source_
? raster_source_
->CanUseLCDText()
570 : layer_tree_impl()->settings().can_use_lcd_text
;
573 void PictureLayerImpl::NotifyTileStateChanged(const Tile
* tile
) {
574 if (layer_tree_impl()->IsActiveTree()) {
575 gfx::RectF layer_damage_rect
=
576 gfx::ScaleRect(tile
->content_rect(), 1.f
/ tile
->contents_scale());
577 AddDamageRect(layer_damage_rect
);
579 if (tile
->draw_info().NeedsRaster()) {
580 PictureLayerTiling
* tiling
=
581 tilings_
->FindTilingWithScale(tile
->contents_scale());
583 tiling
->set_all_tiles_done(false);
587 void PictureLayerImpl::DidBeginTracing() {
588 raster_source_
->DidBeginTracing();
591 void PictureLayerImpl::ReleaseResources() {
592 // Recreate tilings with new settings, since some of those might change when
593 // we release resources.
598 void PictureLayerImpl::RecreateResources() {
599 tilings_
= CreatePictureLayerTilingSet();
601 // To avoid an edge case after lost context where the tree is up to date but
602 // the tilings have not been managed, request an update draw properties
603 // to force tilings to get managed.
604 layer_tree_impl()->set_needs_update_draw_properties();
607 skia::RefPtr
<SkPicture
> PictureLayerImpl::GetPicture() {
608 return raster_source_
->GetFlattenedPicture();
611 Region
PictureLayerImpl::GetInvalidationRegion() {
612 // |invalidation_| gives the invalidation contained in the source frame, but
613 // is not cleared after drawing from the layer. However, update_rect() is
614 // cleared once the invalidation is drawn, which is useful for debugging
615 // visualizations. This method intersects the two to give a more exact
616 // representation of what was invalidated that is cleared after drawing.
617 return IntersectRegions(invalidation_
, update_rect());
620 ScopedTilePtr
PictureLayerImpl::CreateTile(float contents_scale
,
621 const gfx::Rect
& content_rect
) {
624 // We don't handle solid color masks, so we shouldn't bother analyzing those.
625 // Otherwise, always analyze to maximize memory savings.
627 flags
= Tile::USE_PICTURE_ANALYSIS
;
629 return layer_tree_impl()->tile_manager()->CreateTile(
630 content_rect
.size(), content_rect
, contents_scale
, id(),
631 layer_tree_impl()->source_frame_number(), flags
);
634 const Region
* PictureLayerImpl::GetPendingInvalidation() {
635 if (layer_tree_impl()->IsPendingTree())
636 return &invalidation_
;
637 if (layer_tree_impl()->IsRecycleTree())
639 DCHECK(layer_tree_impl()->IsActiveTree());
640 if (PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer())
641 return &twin_layer
->invalidation_
;
645 const PictureLayerTiling
* PictureLayerImpl::GetPendingOrActiveTwinTiling(
646 const PictureLayerTiling
* tiling
) const {
647 PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer();
650 return twin_layer
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
653 TilePriority::PriorityBin
PictureLayerImpl::GetMaxTilePriorityBin() const {
654 if (!HasValidTilePriorities())
655 return TilePriority::EVENTUALLY
;
656 return TilePriority::NOW
;
659 bool PictureLayerImpl::RequiresHighResToDraw() const {
660 return layer_tree_impl()->RequiresHighResToDraw();
663 gfx::Rect
PictureLayerImpl::GetEnclosingRectInTargetSpace() const {
664 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale());
667 gfx::Size
PictureLayerImpl::CalculateTileSize(
668 const gfx::Size
& content_bounds
) const {
669 int max_texture_size
=
670 layer_tree_impl()->resource_provider()->max_texture_size();
673 // Masks are not tiled, so if we can't cover the whole mask with one tile,
674 // we shouldn't have such a tiling at all.
675 DCHECK_LE(content_bounds
.width(), max_texture_size
);
676 DCHECK_LE(content_bounds
.height(), max_texture_size
);
677 return content_bounds
;
680 int default_tile_width
= 0;
681 int default_tile_height
= 0;
682 if (layer_tree_impl()->use_gpu_rasterization()) {
683 // For GPU rasterization, we pick an ideal tile size using the viewport
684 // so we don't need any settings. The current approach uses 4 tiles
685 // to cover the viewport vertically.
686 int viewport_width
= gpu_raster_max_texture_size_
.width();
687 int viewport_height
= gpu_raster_max_texture_size_
.height();
688 default_tile_width
= viewport_width
;
690 // Also, increase the height proportionally as the width decreases, and
691 // pad by our border texels to make the tiles exactly match the viewport.
693 if (content_bounds
.width() <= viewport_width
/ 2)
695 if (content_bounds
.width() <= viewport_width
/ 4)
697 default_tile_height
= MathUtil::RoundUp(viewport_height
, divisor
) / divisor
;
699 // Grow default sizes to account for overlapping border texels.
700 default_tile_width
+= 2 * PictureLayerTiling::kBorderTexels
;
701 default_tile_height
+= 2 * PictureLayerTiling::kBorderTexels
;
703 default_tile_height
=
704 std::max(default_tile_height
, kMinHeightForGpuRasteredTile
);
706 // For CPU rasterization we use tile-size settings.
707 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
708 int max_untiled_content_width
= settings
.max_untiled_layer_size
.width();
709 int max_untiled_content_height
= settings
.max_untiled_layer_size
.height();
710 default_tile_width
= settings
.default_tile_size
.width();
711 default_tile_height
= settings
.default_tile_size
.height();
713 // If the content width is small, increase tile size vertically.
714 // If the content height is small, increase tile size horizontally.
715 // If both are less than the untiled-size, use a single tile.
716 if (content_bounds
.width() < default_tile_width
)
717 default_tile_height
= max_untiled_content_height
;
718 if (content_bounds
.height() < default_tile_height
)
719 default_tile_width
= max_untiled_content_width
;
720 if (content_bounds
.width() < max_untiled_content_width
&&
721 content_bounds
.height() < max_untiled_content_height
) {
722 default_tile_height
= max_untiled_content_height
;
723 default_tile_width
= max_untiled_content_width
;
727 int tile_width
= default_tile_width
;
728 int tile_height
= default_tile_height
;
730 // Clamp the tile width/height to the content width/height to save space.
731 if (content_bounds
.width() < default_tile_width
) {
732 tile_width
= std::min(tile_width
, content_bounds
.width());
733 tile_width
= MathUtil::RoundUp(tile_width
, kTileRoundUp
);
734 tile_width
= std::min(tile_width
, default_tile_width
);
736 if (content_bounds
.height() < default_tile_height
) {
737 tile_height
= std::min(tile_height
, content_bounds
.height());
738 tile_height
= MathUtil::RoundUp(tile_height
, kTileRoundUp
);
739 tile_height
= std::min(tile_height
, default_tile_height
);
742 // Under no circumstance should we be larger than the max texture size.
743 tile_width
= std::min(tile_width
, max_texture_size
);
744 tile_height
= std::min(tile_height
, max_texture_size
);
745 return gfx::Size(tile_width
, tile_height
);
748 void PictureLayerImpl::GetContentsResourceId(ResourceId
* resource_id
,
749 gfx::Size
* resource_size
) const {
750 // The bounds and the pile size may differ if the pile wasn't updated (ie.
751 // PictureLayer::Update didn't happen). In that case the pile will be empty.
752 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
753 bounds() == raster_source_
->GetSize())
754 << " bounds " << bounds().ToString() << " pile "
755 << raster_source_
->GetSize().ToString();
756 gfx::Rect
content_rect(bounds());
757 PictureLayerTilingSet::CoverageIterator
iter(
758 tilings_
.get(), 1.f
, content_rect
, ideal_contents_scale_
);
760 // Mask resource not ready yet.
761 if (!iter
|| !*iter
) {
766 // Masks only supported if they fit on exactly one tile.
767 DCHECK(iter
.geometry_rect() == content_rect
)
768 << "iter rect " << iter
.geometry_rect().ToString() << " content rect "
769 << content_rect
.ToString();
771 const TileDrawInfo
& draw_info
= iter
->draw_info();
772 if (!draw_info
.IsReadyToDraw() ||
773 draw_info
.mode() != TileDrawInfo::RESOURCE_MODE
) {
778 *resource_id
= draw_info
.resource_id();
779 *resource_size
= draw_info
.resource_size();
782 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor
) {
783 if (nearest_neighbor_
== nearest_neighbor
)
786 nearest_neighbor_
= nearest_neighbor
;
787 NoteLayerPropertyChanged();
790 PictureLayerTiling
* PictureLayerImpl::AddTiling(float contents_scale
) {
791 DCHECK(CanHaveTilings());
792 DCHECK_GE(contents_scale
, MinimumContentsScale());
793 DCHECK_LE(contents_scale
, MaximumContentsScale());
794 DCHECK(raster_source_
->HasRecordings());
795 return tilings_
->AddTiling(contents_scale
, raster_source_
);
798 void PictureLayerImpl::RemoveAllTilings() {
799 tilings_
->RemoveAllTilings();
800 // If there are no tilings, then raster scales are no longer meaningful.
804 void PictureLayerImpl::AddTilingsForRasterScale() {
805 // Reset all resolution enums on tilings, we'll be setting new values in this
807 tilings_
->MarkAllTilingsNonIdeal();
809 PictureLayerTiling
* high_res
=
810 tilings_
->FindTilingWithScale(raster_contents_scale_
);
811 // We always need a high res tiling, so create one if it doesn't exist.
813 high_res
= AddTiling(raster_contents_scale_
);
815 // Try and find a low res tiling.
816 PictureLayerTiling
* low_res
= nullptr;
817 if (raster_contents_scale_
== low_res_raster_contents_scale_
)
820 low_res
= tilings_
->FindTilingWithScale(low_res_raster_contents_scale_
);
822 // Only create new low res tilings when the transform is static. This
823 // prevents wastefully creating a paired low res tiling for every new high res
824 // tiling during a pinch or a CSS animation.
825 bool can_have_low_res
= layer_tree_impl()->create_low_res_tiling();
826 bool needs_low_res
= !low_res
;
827 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
828 bool is_animating
= draw_properties().screen_space_transform_is_animating
;
829 if (can_have_low_res
&& needs_low_res
&& !is_pinching
&& !is_animating
)
830 low_res
= AddTiling(low_res_raster_contents_scale_
);
832 // Set low-res if we have one.
833 if (low_res
&& low_res
!= high_res
)
834 low_res
->set_resolution(LOW_RESOLUTION
);
836 // Make sure we always have one high-res (even if high == low).
837 high_res
->set_resolution(HIGH_RESOLUTION
);
839 if (layer_tree_impl()->IsPendingTree()) {
840 // On the pending tree, drop any tilings that are non-ideal since we don't
841 // need them to activate anyway.
842 tilings_
->RemoveNonIdealTilings();
845 SanityCheckTilingState();
848 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
849 if (was_screen_space_transform_animating_
!=
850 draw_properties().screen_space_transform_is_animating
)
853 if (draw_properties().screen_space_transform_is_animating
&&
854 raster_contents_scale_
!= ideal_contents_scale_
&&
855 ShouldAdjustRasterScaleDuringScaleAnimations())
858 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
859 if (is_pinching
&& raster_page_scale_
) {
860 // We change our raster scale when it is:
861 // - Higher than ideal (need a lower-res tiling available)
862 // - Too far from ideal (need a higher-res tiling available)
863 float ratio
= ideal_page_scale_
/ raster_page_scale_
;
864 if (raster_page_scale_
> ideal_page_scale_
||
865 ratio
> kMaxScaleRatioDuringPinch
)
870 // When not pinching, match the ideal page scale factor.
871 if (raster_page_scale_
!= ideal_page_scale_
)
875 // Always match the ideal device scale factor.
876 if (raster_device_scale_
!= ideal_device_scale_
)
879 // When the source scale changes we want to match it, but not when animating
880 // or when we've fixed the scale in place.
881 if (!draw_properties().screen_space_transform_is_animating
&&
882 !raster_source_scale_is_fixed_
&&
883 raster_source_scale_
!= ideal_source_scale_
)
886 if (raster_contents_scale_
> MaximumContentsScale())
888 if (raster_contents_scale_
< MinimumContentsScale())
894 void PictureLayerImpl::RecalculateRasterScales() {
895 float old_raster_contents_scale
= raster_contents_scale_
;
896 float old_raster_page_scale
= raster_page_scale_
;
897 float old_raster_source_scale
= raster_source_scale_
;
899 raster_device_scale_
= ideal_device_scale_
;
900 raster_page_scale_
= ideal_page_scale_
;
901 raster_source_scale_
= ideal_source_scale_
;
902 raster_contents_scale_
= ideal_contents_scale_
;
904 // If we're not animating, or leaving an animation, and the
905 // ideal_source_scale_ changes, then things are unpredictable, and we fix
906 // the raster_source_scale_ in place.
907 if (old_raster_source_scale
&&
908 !draw_properties().screen_space_transform_is_animating
&&
909 !was_screen_space_transform_animating_
&&
910 old_raster_source_scale
!= ideal_source_scale_
)
911 raster_source_scale_is_fixed_
= true;
913 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
914 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
915 // tree. This will allow CSS scale changes to get re-rastered at an
916 // appropriate rate. (crbug.com/413636)
917 if (raster_source_scale_is_fixed_
) {
918 raster_contents_scale_
/= raster_source_scale_
;
919 raster_source_scale_
= 1.f
;
922 // During pinch we completely ignore the current ideal scale, and just use
923 // a multiple of the previous scale.
924 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
925 if (is_pinching
&& old_raster_contents_scale
) {
926 // See ShouldAdjustRasterScale:
927 // - When zooming out, preemptively create new tiling at lower resolution.
928 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
929 bool zooming_out
= old_raster_page_scale
> ideal_page_scale_
;
930 float desired_contents_scale
= old_raster_contents_scale
;
932 while (desired_contents_scale
> ideal_contents_scale_
)
933 desired_contents_scale
/= kMaxScaleRatioDuringPinch
;
935 while (desired_contents_scale
< ideal_contents_scale_
)
936 desired_contents_scale
*= kMaxScaleRatioDuringPinch
;
938 raster_contents_scale_
= tilings_
->GetSnappedContentsScale(
939 desired_contents_scale
, kSnapToExistingTilingRatio
);
941 raster_contents_scale_
/ raster_device_scale_
/ raster_source_scale_
;
944 // If we're not re-rasterizing during animation, rasterize at the maximum
945 // scale that will occur during the animation, if the maximum scale is
946 // known. However we want to avoid excessive memory use. If the scale is
947 // smaller than what we would choose otherwise, then it's always better off
948 // for us memory-wise. But otherwise, we don't choose a scale at which this
949 // layer's rastered content would become larger than the viewport.
950 if (draw_properties().screen_space_transform_is_animating
&&
951 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
952 bool can_raster_at_maximum_scale
= false;
953 bool should_raster_at_starting_scale
= false;
954 float maximum_scale
= draw_properties().maximum_animation_contents_scale
;
955 float starting_scale
= draw_properties().starting_animation_contents_scale
;
957 gfx::Size bounds_at_maximum_scale
= gfx::ToCeiledSize(
958 gfx::ScaleSize(raster_source_
->GetSize(), maximum_scale
));
959 int64 maximum_area
= static_cast<int64
>(bounds_at_maximum_scale
.width()) *
960 static_cast<int64
>(bounds_at_maximum_scale
.height());
961 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
962 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
963 static_cast<int64
>(viewport
.height());
964 if (maximum_area
<= viewport_area
)
965 can_raster_at_maximum_scale
= true;
967 if (starting_scale
&& starting_scale
> maximum_scale
) {
968 gfx::Size bounds_at_starting_scale
= gfx::ToCeiledSize(
969 gfx::ScaleSize(raster_source_
->GetSize(), starting_scale
));
970 int64 start_area
= static_cast<int64
>(bounds_at_starting_scale
.width()) *
971 static_cast<int64
>(bounds_at_starting_scale
.height());
972 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
973 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
974 static_cast<int64
>(viewport
.height());
975 if (start_area
<= viewport_area
)
976 should_raster_at_starting_scale
= true;
978 // Use the computed scales for the raster scale directly, do not try to use
979 // the ideal scale here. The current ideal scale may be way too large in the
980 // case of an animation with scale, and will be constantly changing.
981 if (should_raster_at_starting_scale
)
982 raster_contents_scale_
= starting_scale
;
983 else if (can_raster_at_maximum_scale
)
984 raster_contents_scale_
= maximum_scale
;
986 raster_contents_scale_
= 1.f
* ideal_page_scale_
* ideal_device_scale_
;
989 raster_contents_scale_
=
990 std::max(raster_contents_scale_
, MinimumContentsScale());
991 raster_contents_scale_
=
992 std::min(raster_contents_scale_
, MaximumContentsScale());
993 DCHECK_GE(raster_contents_scale_
, MinimumContentsScale());
994 DCHECK_LE(raster_contents_scale_
, MaximumContentsScale());
996 // If this layer would create zero or one tiles at this content scale,
997 // don't create a low res tiling.
998 gfx::Size raster_bounds
= gfx::ToCeiledSize(
999 gfx::ScaleSize(raster_source_
->GetSize(), raster_contents_scale_
));
1000 gfx::Size tile_size
= CalculateTileSize(raster_bounds
);
1001 bool tile_covers_bounds
= tile_size
.width() >= raster_bounds
.width() &&
1002 tile_size
.height() >= raster_bounds
.height();
1003 if (tile_size
.IsEmpty() || tile_covers_bounds
) {
1004 low_res_raster_contents_scale_
= raster_contents_scale_
;
1008 float low_res_factor
=
1009 layer_tree_impl()->settings().low_res_contents_scale_factor
;
1010 low_res_raster_contents_scale_
=
1011 std::max(raster_contents_scale_
* low_res_factor
, MinimumContentsScale());
1012 DCHECK_LE(low_res_raster_contents_scale_
, raster_contents_scale_
);
1013 DCHECK_GE(low_res_raster_contents_scale_
, MinimumContentsScale());
1014 DCHECK_LE(low_res_raster_contents_scale_
, MaximumContentsScale());
1017 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
1018 const std::vector
<PictureLayerTiling
*>& used_tilings
) {
1019 DCHECK(layer_tree_impl()->IsActiveTree());
1020 if (tilings_
->num_tilings() == 0)
1023 float min_acceptable_high_res_scale
= std::min(
1024 raster_contents_scale_
, ideal_contents_scale_
);
1025 float max_acceptable_high_res_scale
= std::max(
1026 raster_contents_scale_
, ideal_contents_scale_
);
1028 PictureLayerImpl
* twin
= GetPendingOrActiveTwinLayer();
1029 if (twin
&& twin
->CanHaveTilings()) {
1030 min_acceptable_high_res_scale
= std::min(
1031 min_acceptable_high_res_scale
,
1032 std::min(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1033 max_acceptable_high_res_scale
= std::max(
1034 max_acceptable_high_res_scale
,
1035 std::max(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1038 PictureLayerTilingSet
* twin_set
= twin
? twin
->tilings_
.get() : nullptr;
1039 tilings_
->CleanUpTilings(
1040 min_acceptable_high_res_scale
, max_acceptable_high_res_scale
,
1041 used_tilings
, layer_tree_impl()->create_low_res_tiling(), twin_set
);
1042 DCHECK_GT(tilings_
->num_tilings(), 0u);
1043 SanityCheckTilingState();
1046 float PictureLayerImpl::MinimumContentsScale() const {
1047 float setting_min
= layer_tree_impl()->settings().minimum_contents_scale
;
1049 // If the contents scale is less than 1 / width (also for height),
1050 // then it will end up having less than one pixel of content in that
1051 // dimension. Bump the minimum contents scale up in this case to prevent
1052 // this from happening.
1053 int min_dimension
= std::min(raster_source_
->GetSize().width(),
1054 raster_source_
->GetSize().height());
1058 return std::max(1.f
/ min_dimension
, setting_min
);
1061 float PictureLayerImpl::MaximumContentsScale() const {
1062 // Masks can not have tilings that would become larger than the
1063 // max_texture_size since they use a single tile for the entire
1064 // tiling. Other layers can have tilings of any scale.
1066 return std::numeric_limits
<float>::max();
1068 int max_texture_size
=
1069 layer_tree_impl()->resource_provider()->max_texture_size();
1070 float max_scale_width
=
1071 static_cast<float>(max_texture_size
) / bounds().width();
1072 float max_scale_height
=
1073 static_cast<float>(max_texture_size
) / bounds().height();
1074 float max_scale
= std::min(max_scale_width
, max_scale_height
);
1075 // We require that multiplying the layer size by the contents scale and
1076 // ceiling produces a value <= |max_texture_size|. Because for large layer
1077 // sizes floating point ambiguity may crop up, making the result larger or
1078 // smaller than expected, we use a slightly smaller floating point value for
1079 // the scale, to help ensure that the resulting content bounds will never end
1080 // up larger than |max_texture_size|.
1081 return nextafterf(max_scale
, 0.f
);
1084 void PictureLayerImpl::ResetRasterScale() {
1085 raster_page_scale_
= 0.f
;
1086 raster_device_scale_
= 0.f
;
1087 raster_source_scale_
= 0.f
;
1088 raster_contents_scale_
= 0.f
;
1089 low_res_raster_contents_scale_
= 0.f
;
1090 raster_source_scale_is_fixed_
= false;
1093 bool PictureLayerImpl::CanHaveTilings() const {
1094 if (raster_source_
->IsSolidColor())
1096 if (!DrawsContent())
1098 if (!raster_source_
->HasRecordings())
1100 // If the |raster_source_| has a recording it should have non-empty bounds.
1101 DCHECK(!raster_source_
->GetSize().IsEmpty());
1102 if (MaximumContentsScale() < MinimumContentsScale())
1107 void PictureLayerImpl::SanityCheckTilingState() const {
1109 if (!CanHaveTilings()) {
1110 DCHECK_EQ(0u, tilings_
->num_tilings());
1113 if (tilings_
->num_tilings() == 0)
1116 // We should only have one high res tiling.
1117 DCHECK_EQ(1, tilings_
->NumHighResTilings());
1121 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1122 return layer_tree_impl()->use_gpu_rasterization();
1125 float PictureLayerImpl::MaximumTilingContentsScale() const {
1126 float max_contents_scale
= tilings_
->GetMaximumContentsScale();
1127 return std::max(max_contents_scale
, MinimumContentsScale());
1130 scoped_ptr
<PictureLayerTilingSet
>
1131 PictureLayerImpl::CreatePictureLayerTilingSet() {
1132 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
1133 return PictureLayerTilingSet::Create(
1134 GetTree(), this, settings
.tiling_interest_area_viewport_multiplier
,
1135 layer_tree_impl()->use_gpu_rasterization()
1136 ? settings
.gpu_rasterization_skewport_target_time_in_seconds
1137 : settings
.skewport_target_time_in_seconds
,
1138 settings
.skewport_extrapolation_limit_in_content_pixels
);
1141 void PictureLayerImpl::UpdateIdealScales() {
1142 DCHECK(CanHaveTilings());
1144 float min_contents_scale
= MinimumContentsScale();
1145 DCHECK_GT(min_contents_scale
, 0.f
);
1146 float min_page_scale
= layer_tree_impl()->min_page_scale_factor();
1147 DCHECK_GT(min_page_scale
, 0.f
);
1148 float min_device_scale
= 1.f
;
1149 float min_source_scale
=
1150 min_contents_scale
/ min_page_scale
/ min_device_scale
;
1152 float ideal_page_scale
= draw_properties().page_scale_factor
;
1153 float ideal_device_scale
= draw_properties().device_scale_factor
;
1154 float ideal_source_scale
= draw_properties().ideal_contents_scale
/
1155 ideal_page_scale
/ ideal_device_scale
;
1156 ideal_contents_scale_
=
1157 std::max(draw_properties().ideal_contents_scale
, min_contents_scale
);
1158 ideal_page_scale_
= draw_properties().page_scale_factor
;
1159 ideal_device_scale_
= draw_properties().device_scale_factor
;
1160 ideal_source_scale_
= std::max(ideal_source_scale
, min_source_scale
);
1163 void PictureLayerImpl::GetDebugBorderProperties(
1165 float* width
) const {
1166 *color
= DebugColors::TiledContentLayerBorderColor();
1167 *width
= DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1170 void PictureLayerImpl::GetAllPrioritizedTilesForTracing(
1171 std::vector
<PrioritizedTile
>* prioritized_tiles
) const {
1174 tilings_
->GetAllPrioritizedTilesForTracing(prioritized_tiles
);
1177 void PictureLayerImpl::AsValueInto(
1178 base::trace_event::TracedValue
* state
) const {
1179 LayerImpl::AsValueInto(state
);
1180 state
->SetDouble("ideal_contents_scale", ideal_contents_scale_
);
1181 state
->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1182 state
->BeginArray("tilings");
1183 tilings_
->AsValueInto(state
);
1186 MathUtil::AddToTracedValue("tile_priority_rect",
1187 viewport_rect_for_tile_priority_in_content_space_
,
1189 MathUtil::AddToTracedValue("visible_rect", visible_content_rect(), state
);
1191 state
->BeginArray("pictures");
1192 raster_source_
->AsValueInto(state
);
1195 state
->BeginArray("invalidation");
1196 invalidation_
.AsValueInto(state
);
1199 state
->BeginArray("coverage_tiles");
1200 for (PictureLayerTilingSet::CoverageIterator
iter(
1201 tilings_
.get(), 1.f
, gfx::Rect(raster_source_
->GetSize()),
1202 ideal_contents_scale_
);
1204 state
->BeginDictionary();
1206 MathUtil::AddToTracedValue("geometry_rect", iter
.geometry_rect(), state
);
1209 TracedValue::SetIDRef(*iter
, state
, "tile");
1211 state
->EndDictionary();
1216 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1217 return tilings_
->GPUMemoryUsageInBytes();
1220 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1221 benchmark
->RunOnLayer(this);
1224 WhichTree
PictureLayerImpl::GetTree() const {
1225 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
1228 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1229 return !layer_tree_impl()->IsRecycleTree();
1232 bool PictureLayerImpl::HasValidTilePriorities() const {
1233 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();