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/tiles/tile_manager.h"
28 #include "cc/tiles/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::PictureLayerImpl(
58 LayerTreeImpl
* tree_impl
,
61 scoped_refptr
<SyncedScrollOffset
> scroll_offset
)
62 : LayerImpl(tree_impl
, id
, scroll_offset
),
64 tilings_(CreatePictureLayerTilingSet()),
65 ideal_page_scale_(0.f
),
66 ideal_device_scale_(0.f
),
67 ideal_source_scale_(0.f
),
68 ideal_contents_scale_(0.f
),
69 raster_page_scale_(0.f
),
70 raster_device_scale_(0.f
),
71 raster_source_scale_(0.f
),
72 raster_contents_scale_(0.f
),
73 low_res_raster_contents_scale_(0.f
),
74 raster_source_scale_is_fixed_(false),
75 was_screen_space_transform_animating_(false),
76 only_used_low_res_last_append_quads_(false),
78 nearest_neighbor_(false) {
79 layer_tree_impl()->RegisterPictureLayerImpl(this);
82 PictureLayerImpl::~PictureLayerImpl() {
84 twin_layer_
->twin_layer_
= nullptr;
85 layer_tree_impl()->UnregisterPictureLayerImpl(this);
88 const char* PictureLayerImpl::LayerTypeAsString() const {
89 return "cc::PictureLayerImpl";
92 scoped_ptr
<LayerImpl
> PictureLayerImpl::CreateLayerImpl(
93 LayerTreeImpl
* tree_impl
) {
94 return PictureLayerImpl::Create(tree_impl
, id(), is_mask_
,
95 synced_scroll_offset());
98 void PictureLayerImpl::PushPropertiesTo(LayerImpl
* base_layer
) {
99 PictureLayerImpl
* layer_impl
= static_cast<PictureLayerImpl
*>(base_layer
);
100 DCHECK_EQ(layer_impl
->is_mask_
, is_mask_
);
102 LayerImpl::PushPropertiesTo(base_layer
);
104 // Twin relationships should never change once established.
105 DCHECK_IMPLIES(twin_layer_
, twin_layer_
== layer_impl
);
106 DCHECK_IMPLIES(twin_layer_
, layer_impl
->twin_layer_
== this);
107 // The twin relationship does not need to exist before the first
108 // PushPropertiesTo from pending to active layer since before that the active
109 // layer can not have a pile or tilings, it has only been created and inserted
110 // into the tree at that point.
111 twin_layer_
= layer_impl
;
112 layer_impl
->twin_layer_
= this;
114 layer_impl
->SetNearestNeighbor(nearest_neighbor_
);
116 // Solid color layers have no tilings.
117 DCHECK_IMPLIES(raster_source_
->IsSolidColor(), tilings_
->num_tilings() == 0);
118 // The pending tree should only have a high res (and possibly low res) tiling.
119 DCHECK_LE(tilings_
->num_tilings(),
120 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
122 layer_impl
->set_gpu_raster_max_texture_size(gpu_raster_max_texture_size_
);
123 layer_impl
->UpdateRasterSource(raster_source_
, &invalidation_
,
125 DCHECK(invalidation_
.IsEmpty());
127 // After syncing a solid color layer, the active layer has no tilings.
128 DCHECK_IMPLIES(raster_source_
->IsSolidColor(),
129 layer_impl
->tilings_
->num_tilings() == 0);
131 layer_impl
->raster_page_scale_
= raster_page_scale_
;
132 layer_impl
->raster_device_scale_
= raster_device_scale_
;
133 layer_impl
->raster_source_scale_
= raster_source_scale_
;
134 layer_impl
->raster_contents_scale_
= raster_contents_scale_
;
135 layer_impl
->low_res_raster_contents_scale_
= low_res_raster_contents_scale_
;
137 layer_impl
->SanityCheckTilingState();
139 // We always need to push properties.
140 // See http://crbug.com/303943
141 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
142 needs_push_properties_
= true;
145 void PictureLayerImpl::AppendQuads(RenderPass
* render_pass
,
146 AppendQuadsData
* append_quads_data
) {
147 // The bounds and the pile size may differ if the pile wasn't updated (ie.
148 // PictureLayer::Update didn't happen). In that case the pile will be empty.
149 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
150 bounds() == raster_source_
->GetSize())
151 << " bounds " << bounds().ToString() << " pile "
152 << raster_source_
->GetSize().ToString();
154 SharedQuadState
* shared_quad_state
=
155 render_pass
->CreateAndAppendSharedQuadState();
157 if (raster_source_
->IsSolidColor()) {
158 PopulateSharedQuadState(shared_quad_state
);
160 AppendDebugBorderQuad(
161 render_pass
, bounds(), shared_quad_state
, append_quads_data
);
163 SolidColorLayerImpl::AppendSolidQuads(
164 render_pass
, draw_properties().occlusion_in_content_space
,
165 shared_quad_state
, visible_content_rect(),
166 raster_source_
->GetSolidColor(), append_quads_data
);
170 float max_contents_scale
= MaximumTilingContentsScale();
171 PopulateScaledSharedQuadState(shared_quad_state
, max_contents_scale
);
172 Occlusion scaled_occlusion
=
174 .occlusion_in_content_space
.GetOcclusionWithGivenDrawTransform(
175 shared_quad_state
->content_to_target_transform
);
177 if (current_draw_mode_
== DRAW_MODE_RESOURCELESS_SOFTWARE
) {
178 AppendDebugBorderQuad(
179 render_pass
, shared_quad_state
->content_bounds
, shared_quad_state
,
180 append_quads_data
, DebugColors::DirectPictureBorderColor(),
181 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
183 gfx::Rect geometry_rect
= shared_quad_state
->visible_content_rect
;
184 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
185 gfx::Rect visible_geometry_rect
=
186 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
187 if (visible_geometry_rect
.IsEmpty())
190 gfx::Rect quad_content_rect
= shared_quad_state
->visible_content_rect
;
191 gfx::Size texture_size
= quad_content_rect
.size();
192 gfx::RectF texture_rect
= gfx::RectF(texture_size
);
194 PictureDrawQuad
* quad
=
195 render_pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
196 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
197 visible_geometry_rect
, texture_rect
, texture_size
,
198 nearest_neighbor_
, RGBA_8888
, quad_content_rect
,
199 max_contents_scale
, raster_source_
);
200 ValidateQuadResources(quad
);
204 AppendDebugBorderQuad(render_pass
, shared_quad_state
->content_bounds
,
205 shared_quad_state
, append_quads_data
);
207 if (ShowDebugBorders()) {
208 for (PictureLayerTilingSet::CoverageIterator
iter(
209 tilings_
.get(), max_contents_scale
,
210 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
214 if (*iter
&& iter
->draw_info().IsReadyToDraw()) {
215 TileDrawInfo::Mode mode
= iter
->draw_info().mode();
216 if (mode
== TileDrawInfo::SOLID_COLOR_MODE
) {
217 color
= DebugColors::SolidColorTileBorderColor();
218 width
= DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
219 } else if (mode
== TileDrawInfo::OOM_MODE
) {
220 color
= DebugColors::OOMTileBorderColor();
221 width
= DebugColors::OOMTileBorderWidth(layer_tree_impl());
222 } else if (iter
.resolution() == HIGH_RESOLUTION
) {
223 color
= DebugColors::HighResTileBorderColor();
224 width
= DebugColors::HighResTileBorderWidth(layer_tree_impl());
225 } else if (iter
.resolution() == LOW_RESOLUTION
) {
226 color
= DebugColors::LowResTileBorderColor();
227 width
= DebugColors::LowResTileBorderWidth(layer_tree_impl());
228 } else if (iter
->contents_scale() > max_contents_scale
) {
229 color
= DebugColors::ExtraHighResTileBorderColor();
230 width
= DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
232 color
= DebugColors::ExtraLowResTileBorderColor();
233 width
= DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
236 color
= DebugColors::MissingTileBorderColor();
237 width
= DebugColors::MissingTileBorderWidth(layer_tree_impl());
240 DebugBorderDrawQuad
* debug_border_quad
=
241 render_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
242 gfx::Rect geometry_rect
= iter
.geometry_rect();
243 gfx::Rect visible_geometry_rect
= geometry_rect
;
244 debug_border_quad
->SetNew(shared_quad_state
,
246 visible_geometry_rect
,
252 // Keep track of the tilings that were used so that tilings that are
253 // unused can be considered for removal.
254 last_append_quads_tilings_
.clear();
256 // Ignore missing tiles outside of viewport for tile priority. This is
257 // normally the same as draw viewport but can be independently overridden by
258 // embedders like Android WebView with SetExternalDrawConstraints.
259 gfx::Rect scaled_viewport_for_tile_priority
= gfx::ScaleToEnclosingRect(
260 viewport_rect_for_tile_priority_in_content_space_
, max_contents_scale
);
262 size_t missing_tile_count
= 0u;
263 size_t on_demand_missing_tile_count
= 0u;
264 only_used_low_res_last_append_quads_
= true;
265 for (PictureLayerTilingSet::CoverageIterator
iter(
266 tilings_
.get(), max_contents_scale
,
267 shared_quad_state
->visible_content_rect
, ideal_contents_scale_
);
269 gfx::Rect geometry_rect
= iter
.geometry_rect();
270 gfx::Rect opaque_rect
= contents_opaque() ? geometry_rect
: gfx::Rect();
271 gfx::Rect visible_geometry_rect
=
272 scaled_occlusion
.GetUnoccludedContentRect(geometry_rect
);
273 if (visible_geometry_rect
.IsEmpty())
276 append_quads_data
->visible_content_area
+=
277 visible_geometry_rect
.width() * visible_geometry_rect
.height();
279 bool has_draw_quad
= false;
280 if (*iter
&& iter
->draw_info().IsReadyToDraw()) {
281 const TileDrawInfo
& draw_info
= iter
->draw_info();
282 switch (draw_info
.mode()) {
283 case TileDrawInfo::RESOURCE_MODE
: {
284 gfx::RectF texture_rect
= iter
.texture_rect();
286 // The raster_contents_scale_ is the best scale that the layer is
287 // trying to produce, even though it may not be ideal. Since that's
288 // the best the layer can promise in the future, consider those as
289 // complete. But if a tile is ideal scale, we don't want to consider
290 // it incomplete and trying to replace it with a tile at a worse
292 if (iter
->contents_scale() != raster_contents_scale_
&&
293 iter
->contents_scale() != ideal_contents_scale_
&&
294 geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
295 append_quads_data
->num_incomplete_tiles
++;
299 render_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
300 quad
->SetNew(shared_quad_state
, geometry_rect
, opaque_rect
,
301 visible_geometry_rect
, draw_info
.resource_id(),
302 texture_rect
, draw_info
.resource_size(),
303 draw_info
.contents_swizzled(), nearest_neighbor_
);
304 ValidateQuadResources(quad
);
305 has_draw_quad
= true;
308 case TileDrawInfo::SOLID_COLOR_MODE
: {
309 SolidColorDrawQuad
* quad
=
310 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
311 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
312 draw_info
.solid_color(), false);
313 ValidateQuadResources(quad
);
314 has_draw_quad
= true;
317 case TileDrawInfo::OOM_MODE
:
318 break; // Checkerboard.
322 if (!has_draw_quad
) {
323 if (draw_checkerboard_for_missing_tiles()) {
324 CheckerboardDrawQuad
* quad
=
325 render_pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
326 SkColor color
= DebugColors::DefaultCheckerboardColor();
327 quad
->SetNew(shared_quad_state
, geometry_rect
, visible_geometry_rect
,
328 color
, draw_properties().device_scale_factor
);
330 SkColor color
= SafeOpaqueBackgroundColor();
331 SolidColorDrawQuad
* quad
=
332 render_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
333 quad
->SetNew(shared_quad_state
,
335 visible_geometry_rect
,
338 ValidateQuadResources(quad
);
341 if (geometry_rect
.Intersects(scaled_viewport_for_tile_priority
)) {
342 append_quads_data
->num_missing_tiles
++;
343 ++missing_tile_count
;
345 append_quads_data
->approximated_visible_content_area
+=
346 visible_geometry_rect
.width() * visible_geometry_rect
.height();
347 append_quads_data
->checkerboarded_visible_content_area
+=
348 visible_geometry_rect
.width() * visible_geometry_rect
.height();
352 if (iter
.resolution() != HIGH_RESOLUTION
) {
353 append_quads_data
->approximated_visible_content_area
+=
354 visible_geometry_rect
.width() * visible_geometry_rect
.height();
357 // If we have a draw quad, but it's not low resolution, then
358 // mark that we've used something other than low res to draw.
359 if (iter
.resolution() != LOW_RESOLUTION
)
360 only_used_low_res_last_append_quads_
= false;
362 if (last_append_quads_tilings_
.empty() ||
363 last_append_quads_tilings_
.back() != iter
.CurrentTiling()) {
364 last_append_quads_tilings_
.push_back(iter
.CurrentTiling());
368 if (missing_tile_count
) {
369 TRACE_EVENT_INSTANT2("cc",
370 "PictureLayerImpl::AppendQuads checkerboard",
371 TRACE_EVENT_SCOPE_THREAD
,
372 "missing_tile_count",
374 "on_demand_missing_tile_count",
375 on_demand_missing_tile_count
);
378 // Aggressively remove any tilings that are not seen to save memory. Note
379 // that this is at the expense of doing cause more frequent re-painting. A
380 // better scheme would be to maintain a tighter visible_content_rect for the
382 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
385 bool PictureLayerImpl::UpdateTiles(bool resourceless_software_draw
) {
386 DCHECK_EQ(1.f
, contents_scale_x());
387 DCHECK_EQ(1.f
, contents_scale_y());
389 if (!resourceless_software_draw
) {
390 visible_rect_for_tile_priority_
= visible_content_rect();
393 if (!CanHaveTilings()) {
394 ideal_page_scale_
= 0.f
;
395 ideal_device_scale_
= 0.f
;
396 ideal_contents_scale_
= 0.f
;
397 ideal_source_scale_
= 0.f
;
398 SanityCheckTilingState();
402 // Remove any non-ideal tilings that were not used last time we generated
403 // quads to save memory and processing time. Note that pending tree should
404 // only have one or two tilings (high and low res), so only clean up the
405 // active layer. This cleans it up here in case AppendQuads didn't run.
406 // If it did run, this would not remove any additional tilings.
407 if (layer_tree_impl()->IsActiveTree())
408 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_
);
412 if (!raster_contents_scale_
|| ShouldAdjustRasterScale()) {
413 RecalculateRasterScales();
414 AddTilingsForRasterScale();
417 DCHECK(raster_page_scale_
);
418 DCHECK(raster_device_scale_
);
419 DCHECK(raster_source_scale_
);
420 DCHECK(raster_contents_scale_
);
421 DCHECK(low_res_raster_contents_scale_
);
423 was_screen_space_transform_animating_
=
424 draw_properties().screen_space_transform_is_animating
;
426 if (draw_transform_is_animating())
427 raster_source_
->SetShouldAttemptToUseDistanceFieldText();
429 double current_frame_time_in_seconds
=
430 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time
-
431 base::TimeTicks()).InSecondsF();
432 UpdateViewportRectForTilePriorityInContentSpace();
434 // The tiling set can require tiles for activation any of the following
435 // conditions are true:
436 // - This layer produced a high-res or non-ideal-res tile last frame.
437 // - We're in requires high res to draw mode.
438 // - We're not in smoothness takes priority mode.
439 // To put different, the tiling set can't require tiles for activation if
440 // we're in smoothness mode and only used low-res or checkerboard to draw last
441 // frame and we don't need high res to draw.
443 // The reason for this is that we should be able to activate sooner and get a
444 // more up to date recording, so we don't run out of recording on the active
446 bool can_require_tiles_for_activation
=
447 !only_used_low_res_last_append_quads_
|| RequiresHighResToDraw() ||
448 !layer_tree_impl()->SmoothnessTakesPriority();
450 static const Occlusion kEmptyOcclusion
;
451 const Occlusion
& occlusion_in_content_space
=
452 layer_tree_impl()->settings().use_occlusion_for_tile_prioritization
453 ? draw_properties().occlusion_in_content_space
456 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
457 // they are the same space in picture layer, as contents scale is always 1.
458 bool updated
= tilings_
->UpdateTilePriorities(
459 viewport_rect_for_tile_priority_in_content_space_
, ideal_contents_scale_
,
460 current_frame_time_in_seconds
, occlusion_in_content_space
,
461 can_require_tiles_for_activation
);
465 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
466 // If visible_rect_for_tile_priority_ is empty or
467 // viewport_rect_for_tile_priority is set to be different from the device
468 // viewport, try to inverse project the viewport into layer space and use
469 // that. Otherwise just use visible_rect_for_tile_priority_
470 gfx::Rect visible_rect_in_content_space
= visible_rect_for_tile_priority_
;
471 gfx::Rect viewport_rect_for_tile_priority
=
472 layer_tree_impl()->ViewportRectForTilePriority();
473 if (visible_rect_in_content_space
.IsEmpty() ||
474 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority
) {
475 gfx::Transform
view_to_layer(gfx::Transform::kSkipInitialization
);
476 if (screen_space_transform().GetInverse(&view_to_layer
)) {
477 // Transform from view space to content space.
478 visible_rect_in_content_space
=
479 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
480 view_to_layer
, viewport_rect_for_tile_priority
));
483 viewport_rect_for_tile_priority_in_content_space_
=
484 visible_rect_in_content_space
;
487 PictureLayerImpl
* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
488 if (!twin_layer_
|| !twin_layer_
->IsOnActiveOrPendingTree())
493 void PictureLayerImpl::UpdateRasterSource(
494 scoped_refptr
<RasterSource
> raster_source
,
495 Region
* new_invalidation
,
496 const PictureLayerTilingSet
* pending_set
) {
497 // The bounds and the pile size may differ if the pile wasn't updated (ie.
498 // PictureLayer::Update didn't happen). In that case the pile will be empty.
499 DCHECK_IMPLIES(!raster_source
->GetSize().IsEmpty(),
500 bounds() == raster_source
->GetSize())
501 << " bounds " << bounds().ToString() << " pile "
502 << raster_source
->GetSize().ToString();
504 // The |raster_source_| is initially null, so have to check for that for the
506 bool could_have_tilings
= raster_source_
.get() && CanHaveTilings();
507 raster_source_
.swap(raster_source
);
509 // The |new_invalidation| must be cleared before updating tilings since they
510 // access the invalidation through the PictureLayerTilingClient interface.
511 invalidation_
.Clear();
512 invalidation_
.Swap(new_invalidation
);
514 bool can_have_tilings
= CanHaveTilings();
517 can_have_tilings
== GetPendingOrActiveTwinLayer()->CanHaveTilings());
519 // Need to call UpdateTiles again if CanHaveTilings changed.
520 if (could_have_tilings
!= can_have_tilings
)
521 layer_tree_impl()->set_needs_update_draw_properties();
523 if (!can_have_tilings
) {
528 // We could do this after doing UpdateTiles, which would avoid doing this for
529 // tilings that are going to disappear on the pending tree (if scale changed).
530 // But that would also be more complicated, so we just do it here for now.
532 tilings_
->UpdateTilingsToCurrentRasterSourceForActivation(
533 raster_source_
, pending_set
, invalidation_
, MinimumContentsScale(),
534 MaximumContentsScale());
536 tilings_
->UpdateTilingsToCurrentRasterSourceForCommit(
537 raster_source_
, invalidation_
, MinimumContentsScale(),
538 MaximumContentsScale());
542 void PictureLayerImpl::UpdateCanUseLCDTextAfterCommit() {
543 // This function is only allowed to be called after commit, due to it not
544 // being smart about sharing tiles and because otherwise it would cause
545 // flashes by switching out tiles in place that may be currently on screen.
546 DCHECK(layer_tree_impl()->IsSyncTree());
548 // Don't allow the LCD text state to change once disabled.
549 if (!RasterSourceUsesLCDText())
551 if (can_use_lcd_text() == RasterSourceUsesLCDText())
554 // Raster sources are considered const, so in order to update the state
555 // a new one must be created and all tiles recreated.
556 scoped_refptr
<RasterSource
> new_raster_source
=
557 raster_source_
->CreateCloneWithoutLCDText();
558 raster_source_
.swap(new_raster_source
);
560 // Synthetically invalidate everything.
561 gfx::Rect
bounds_rect(bounds());
562 invalidation_
= Region(bounds_rect
);
563 tilings_
->UpdateRasterSourceDueToLCDChange(raster_source_
, invalidation_
);
564 SetUpdateRect(bounds_rect
);
566 DCHECK(!RasterSourceUsesLCDText());
569 bool PictureLayerImpl::RasterSourceUsesLCDText() const {
570 return raster_source_
? raster_source_
->CanUseLCDText()
571 : layer_tree_impl()->settings().can_use_lcd_text
;
574 void PictureLayerImpl::NotifyTileStateChanged(const Tile
* tile
) {
575 if (layer_tree_impl()->IsActiveTree()) {
576 gfx::RectF layer_damage_rect
=
577 gfx::ScaleRect(tile
->content_rect(), 1.f
/ tile
->contents_scale());
578 AddDamageRect(layer_damage_rect
);
582 void PictureLayerImpl::DidBeginTracing() {
583 raster_source_
->DidBeginTracing();
586 void PictureLayerImpl::ReleaseResources() {
587 // Recreate tilings with new settings, since some of those might change when
588 // we release resources.
593 void PictureLayerImpl::RecreateResources() {
594 tilings_
= CreatePictureLayerTilingSet();
596 // To avoid an edge case after lost context where the tree is up to date but
597 // the tilings have not been managed, request an update draw properties
598 // to force tilings to get managed.
599 layer_tree_impl()->set_needs_update_draw_properties();
602 skia::RefPtr
<SkPicture
> PictureLayerImpl::GetPicture() {
603 return raster_source_
->GetFlattenedPicture();
606 Region
PictureLayerImpl::GetInvalidationRegion() {
607 // |invalidation_| gives the invalidation contained in the source frame, but
608 // is not cleared after drawing from the layer. However, update_rect() is
609 // cleared once the invalidation is drawn, which is useful for debugging
610 // visualizations. This method intersects the two to give a more exact
611 // representation of what was invalidated that is cleared after drawing.
612 return IntersectRegions(invalidation_
, update_rect());
615 ScopedTilePtr
PictureLayerImpl::CreateTile(float contents_scale
,
616 const gfx::Rect
& content_rect
) {
619 // We don't handle solid color masks, so we shouldn't bother analyzing those.
620 // Otherwise, always analyze to maximize memory savings.
622 flags
= Tile::USE_PICTURE_ANALYSIS
;
624 return layer_tree_impl()->tile_manager()->CreateTile(
625 content_rect
.size(), content_rect
, contents_scale
, id(),
626 layer_tree_impl()->source_frame_number(), flags
);
629 const Region
* PictureLayerImpl::GetPendingInvalidation() {
630 if (layer_tree_impl()->IsPendingTree())
631 return &invalidation_
;
632 if (layer_tree_impl()->IsRecycleTree())
634 DCHECK(layer_tree_impl()->IsActiveTree());
635 if (PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer())
636 return &twin_layer
->invalidation_
;
640 const PictureLayerTiling
* PictureLayerImpl::GetPendingOrActiveTwinTiling(
641 const PictureLayerTiling
* tiling
) const {
642 PictureLayerImpl
* twin_layer
= GetPendingOrActiveTwinLayer();
645 return twin_layer
->tilings_
->FindTilingWithScale(tiling
->contents_scale());
648 TilePriority::PriorityBin
PictureLayerImpl::GetMaxTilePriorityBin() const {
649 if (!HasValidTilePriorities())
650 return TilePriority::EVENTUALLY
;
651 return TilePriority::NOW
;
654 bool PictureLayerImpl::RequiresHighResToDraw() const {
655 return layer_tree_impl()->RequiresHighResToDraw();
658 gfx::Rect
PictureLayerImpl::GetEnclosingRectInTargetSpace() const {
659 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale());
662 gfx::Size
PictureLayerImpl::CalculateTileSize(
663 const gfx::Size
& content_bounds
) const {
664 int max_texture_size
=
665 layer_tree_impl()->resource_provider()->max_texture_size();
668 // Masks are not tiled, so if we can't cover the whole mask with one tile,
669 // we shouldn't have such a tiling at all.
670 DCHECK_LE(content_bounds
.width(), max_texture_size
);
671 DCHECK_LE(content_bounds
.height(), max_texture_size
);
672 return content_bounds
;
675 int default_tile_width
= 0;
676 int default_tile_height
= 0;
677 if (layer_tree_impl()->use_gpu_rasterization()) {
678 // For GPU rasterization, we pick an ideal tile size using the viewport
679 // so we don't need any settings. The current approach uses 4 tiles
680 // to cover the viewport vertically.
681 int viewport_width
= gpu_raster_max_texture_size_
.width();
682 int viewport_height
= gpu_raster_max_texture_size_
.height();
683 default_tile_width
= viewport_width
;
685 // Also, increase the height proportionally as the width decreases, and
686 // pad by our border texels to make the tiles exactly match the viewport.
688 if (content_bounds
.width() <= viewport_width
/ 2)
690 if (content_bounds
.width() <= viewport_width
/ 4)
692 default_tile_height
= RoundUp(viewport_height
, divisor
) / divisor
;
694 // Grow default sizes to account for overlapping border texels.
695 default_tile_width
+= 2 * PictureLayerTiling::kBorderTexels
;
696 default_tile_height
+= 2 * PictureLayerTiling::kBorderTexels
;
698 default_tile_height
=
699 std::max(default_tile_height
, kMinHeightForGpuRasteredTile
);
701 // For CPU rasterization we use tile-size settings.
702 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
703 int max_untiled_content_width
= settings
.max_untiled_layer_size
.width();
704 int max_untiled_content_height
= settings
.max_untiled_layer_size
.height();
705 default_tile_width
= settings
.default_tile_size
.width();
706 default_tile_height
= settings
.default_tile_size
.height();
708 // If the content width is small, increase tile size vertically.
709 // If the content height is small, increase tile size horizontally.
710 // If both are less than the untiled-size, use a single tile.
711 if (content_bounds
.width() < default_tile_width
)
712 default_tile_height
= max_untiled_content_height
;
713 if (content_bounds
.height() < default_tile_height
)
714 default_tile_width
= max_untiled_content_width
;
715 if (content_bounds
.width() < max_untiled_content_width
&&
716 content_bounds
.height() < max_untiled_content_height
) {
717 default_tile_height
= max_untiled_content_height
;
718 default_tile_width
= max_untiled_content_width
;
722 int tile_width
= default_tile_width
;
723 int tile_height
= default_tile_height
;
725 // Clamp the tile width/height to the content width/height to save space.
726 if (content_bounds
.width() < default_tile_width
) {
727 tile_width
= std::min(tile_width
, content_bounds
.width());
728 tile_width
= RoundUp(tile_width
, kTileRoundUp
);
729 tile_width
= std::min(tile_width
, default_tile_width
);
731 if (content_bounds
.height() < default_tile_height
) {
732 tile_height
= std::min(tile_height
, content_bounds
.height());
733 tile_height
= RoundUp(tile_height
, kTileRoundUp
);
734 tile_height
= std::min(tile_height
, default_tile_height
);
737 // Under no circumstance should we be larger than the max texture size.
738 tile_width
= std::min(tile_width
, max_texture_size
);
739 tile_height
= std::min(tile_height
, max_texture_size
);
740 return gfx::Size(tile_width
, tile_height
);
743 void PictureLayerImpl::GetContentsResourceId(ResourceId
* resource_id
,
744 gfx::Size
* resource_size
) const {
745 // The bounds and the pile size may differ if the pile wasn't updated (ie.
746 // PictureLayer::Update didn't happen). In that case the pile will be empty.
747 DCHECK_IMPLIES(!raster_source_
->GetSize().IsEmpty(),
748 bounds() == raster_source_
->GetSize())
749 << " bounds " << bounds().ToString() << " pile "
750 << raster_source_
->GetSize().ToString();
751 gfx::Rect
content_rect(bounds());
752 PictureLayerTilingSet::CoverageIterator
iter(
753 tilings_
.get(), 1.f
, content_rect
, ideal_contents_scale_
);
755 // Mask resource not ready yet.
756 if (!iter
|| !*iter
) {
761 // Masks only supported if they fit on exactly one tile.
762 DCHECK(iter
.geometry_rect() == content_rect
)
763 << "iter rect " << iter
.geometry_rect().ToString() << " content rect "
764 << content_rect
.ToString();
766 const TileDrawInfo
& draw_info
= iter
->draw_info();
767 if (!draw_info
.IsReadyToDraw() ||
768 draw_info
.mode() != TileDrawInfo::RESOURCE_MODE
) {
773 *resource_id
= draw_info
.resource_id();
774 *resource_size
= draw_info
.resource_size();
777 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor
) {
778 if (nearest_neighbor_
== nearest_neighbor
)
781 nearest_neighbor_
= nearest_neighbor
;
782 NoteLayerPropertyChanged();
785 PictureLayerTiling
* PictureLayerImpl::AddTiling(float contents_scale
) {
786 DCHECK(CanHaveTilings());
787 DCHECK_GE(contents_scale
, MinimumContentsScale());
788 DCHECK_LE(contents_scale
, MaximumContentsScale());
789 DCHECK(raster_source_
->HasRecordings());
790 return tilings_
->AddTiling(contents_scale
, raster_source_
);
793 void PictureLayerImpl::RemoveAllTilings() {
794 tilings_
->RemoveAllTilings();
795 // If there are no tilings, then raster scales are no longer meaningful.
799 void PictureLayerImpl::AddTilingsForRasterScale() {
800 // Reset all resolution enums on tilings, we'll be setting new values in this
802 tilings_
->MarkAllTilingsNonIdeal();
804 PictureLayerTiling
* high_res
=
805 tilings_
->FindTilingWithScale(raster_contents_scale_
);
806 // We always need a high res tiling, so create one if it doesn't exist.
808 high_res
= AddTiling(raster_contents_scale_
);
810 // Try and find a low res tiling.
811 PictureLayerTiling
* low_res
= nullptr;
812 if (raster_contents_scale_
== low_res_raster_contents_scale_
)
815 low_res
= tilings_
->FindTilingWithScale(low_res_raster_contents_scale_
);
817 // Only create new low res tilings when the transform is static. This
818 // prevents wastefully creating a paired low res tiling for every new high res
819 // tiling during a pinch or a CSS animation.
820 bool can_have_low_res
= layer_tree_impl()->create_low_res_tiling();
821 bool needs_low_res
= !low_res
;
822 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
823 bool is_animating
= draw_properties().screen_space_transform_is_animating
;
824 if (can_have_low_res
&& needs_low_res
&& !is_pinching
&& !is_animating
)
825 low_res
= AddTiling(low_res_raster_contents_scale_
);
827 // Set low-res if we have one.
828 if (low_res
&& low_res
!= high_res
)
829 low_res
->set_resolution(LOW_RESOLUTION
);
831 // Make sure we always have one high-res (even if high == low).
832 high_res
->set_resolution(HIGH_RESOLUTION
);
834 if (layer_tree_impl()->IsPendingTree()) {
835 // On the pending tree, drop any tilings that are non-ideal since we don't
836 // need them to activate anyway.
837 tilings_
->RemoveNonIdealTilings();
840 SanityCheckTilingState();
843 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
844 if (was_screen_space_transform_animating_
!=
845 draw_properties().screen_space_transform_is_animating
)
848 if (draw_properties().screen_space_transform_is_animating
&&
849 raster_contents_scale_
!= ideal_contents_scale_
&&
850 ShouldAdjustRasterScaleDuringScaleAnimations())
853 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
854 if (is_pinching
&& raster_page_scale_
) {
855 // We change our raster scale when it is:
856 // - Higher than ideal (need a lower-res tiling available)
857 // - Too far from ideal (need a higher-res tiling available)
858 float ratio
= ideal_page_scale_
/ raster_page_scale_
;
859 if (raster_page_scale_
> ideal_page_scale_
||
860 ratio
> kMaxScaleRatioDuringPinch
)
865 // When not pinching, match the ideal page scale factor.
866 if (raster_page_scale_
!= ideal_page_scale_
)
870 // Always match the ideal device scale factor.
871 if (raster_device_scale_
!= ideal_device_scale_
)
874 // When the source scale changes we want to match it, but not when animating
875 // or when we've fixed the scale in place.
876 if (!draw_properties().screen_space_transform_is_animating
&&
877 !raster_source_scale_is_fixed_
&&
878 raster_source_scale_
!= ideal_source_scale_
)
881 if (raster_contents_scale_
> MaximumContentsScale())
883 if (raster_contents_scale_
< MinimumContentsScale())
889 void PictureLayerImpl::RecalculateRasterScales() {
890 float old_raster_contents_scale
= raster_contents_scale_
;
891 float old_raster_page_scale
= raster_page_scale_
;
892 float old_raster_source_scale
= raster_source_scale_
;
894 raster_device_scale_
= ideal_device_scale_
;
895 raster_page_scale_
= ideal_page_scale_
;
896 raster_source_scale_
= ideal_source_scale_
;
897 raster_contents_scale_
= ideal_contents_scale_
;
899 // If we're not animating, or leaving an animation, and the
900 // ideal_source_scale_ changes, then things are unpredictable, and we fix
901 // the raster_source_scale_ in place.
902 if (old_raster_source_scale
&&
903 !draw_properties().screen_space_transform_is_animating
&&
904 !was_screen_space_transform_animating_
&&
905 old_raster_source_scale
!= ideal_source_scale_
)
906 raster_source_scale_is_fixed_
= true;
908 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
909 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
910 // tree. This will allow CSS scale changes to get re-rastered at an
911 // appropriate rate. (crbug.com/413636)
912 if (raster_source_scale_is_fixed_
) {
913 raster_contents_scale_
/= raster_source_scale_
;
914 raster_source_scale_
= 1.f
;
917 // During pinch we completely ignore the current ideal scale, and just use
918 // a multiple of the previous scale.
919 bool is_pinching
= layer_tree_impl()->PinchGestureActive();
920 if (is_pinching
&& old_raster_contents_scale
) {
921 // See ShouldAdjustRasterScale:
922 // - When zooming out, preemptively create new tiling at lower resolution.
923 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
924 bool zooming_out
= old_raster_page_scale
> ideal_page_scale_
;
925 float desired_contents_scale
= old_raster_contents_scale
;
927 while (desired_contents_scale
> ideal_contents_scale_
)
928 desired_contents_scale
/= kMaxScaleRatioDuringPinch
;
930 while (desired_contents_scale
< ideal_contents_scale_
)
931 desired_contents_scale
*= kMaxScaleRatioDuringPinch
;
933 raster_contents_scale_
= tilings_
->GetSnappedContentsScale(
934 desired_contents_scale
, kSnapToExistingTilingRatio
);
936 raster_contents_scale_
/ raster_device_scale_
/ raster_source_scale_
;
939 // If we're not re-rasterizing during animation, rasterize at the maximum
940 // scale that will occur during the animation, if the maximum scale is
941 // known. However we want to avoid excessive memory use. If the scale is
942 // smaller than what we would choose otherwise, then it's always better off
943 // for us memory-wise. But otherwise, we don't choose a scale at which this
944 // layer's rastered content would become larger than the viewport.
945 if (draw_properties().screen_space_transform_is_animating
&&
946 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
947 bool can_raster_at_maximum_scale
= false;
948 bool should_raster_at_starting_scale
= false;
949 float maximum_scale
= draw_properties().maximum_animation_contents_scale
;
950 float starting_scale
= draw_properties().starting_animation_contents_scale
;
952 gfx::Size bounds_at_maximum_scale
= gfx::ToCeiledSize(
953 gfx::ScaleSize(raster_source_
->GetSize(), maximum_scale
));
954 int64 maximum_area
= static_cast<int64
>(bounds_at_maximum_scale
.width()) *
955 static_cast<int64
>(bounds_at_maximum_scale
.height());
956 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
957 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
958 static_cast<int64
>(viewport
.height());
959 if (maximum_area
<= viewport_area
)
960 can_raster_at_maximum_scale
= true;
962 if (starting_scale
&& starting_scale
> maximum_scale
) {
963 gfx::Size bounds_at_starting_scale
= gfx::ToCeiledSize(
964 gfx::ScaleSize(raster_source_
->GetSize(), starting_scale
));
965 int64 start_area
= static_cast<int64
>(bounds_at_starting_scale
.width()) *
966 static_cast<int64
>(bounds_at_starting_scale
.height());
967 gfx::Size viewport
= layer_tree_impl()->device_viewport_size();
968 int64 viewport_area
= static_cast<int64
>(viewport
.width()) *
969 static_cast<int64
>(viewport
.height());
970 if (start_area
<= viewport_area
)
971 should_raster_at_starting_scale
= true;
973 // Use the computed scales for the raster scale directly, do not try to use
974 // the ideal scale here. The current ideal scale may be way too large in the
975 // case of an animation with scale, and will be constantly changing.
976 if (should_raster_at_starting_scale
)
977 raster_contents_scale_
= starting_scale
;
978 else if (can_raster_at_maximum_scale
)
979 raster_contents_scale_
= maximum_scale
;
981 raster_contents_scale_
= 1.f
* ideal_page_scale_
* ideal_device_scale_
;
984 raster_contents_scale_
=
985 std::max(raster_contents_scale_
, MinimumContentsScale());
986 raster_contents_scale_
=
987 std::min(raster_contents_scale_
, MaximumContentsScale());
988 DCHECK_GE(raster_contents_scale_
, MinimumContentsScale());
989 DCHECK_LE(raster_contents_scale_
, MaximumContentsScale());
991 // If this layer would create zero or one tiles at this content scale,
992 // don't create a low res tiling.
993 gfx::Size raster_bounds
= gfx::ToCeiledSize(
994 gfx::ScaleSize(raster_source_
->GetSize(), raster_contents_scale_
));
995 gfx::Size tile_size
= CalculateTileSize(raster_bounds
);
996 bool tile_covers_bounds
= tile_size
.width() >= raster_bounds
.width() &&
997 tile_size
.height() >= raster_bounds
.height();
998 if (tile_size
.IsEmpty() || tile_covers_bounds
) {
999 low_res_raster_contents_scale_
= raster_contents_scale_
;
1003 float low_res_factor
=
1004 layer_tree_impl()->settings().low_res_contents_scale_factor
;
1005 low_res_raster_contents_scale_
=
1006 std::max(raster_contents_scale_
* low_res_factor
, MinimumContentsScale());
1007 DCHECK_LE(low_res_raster_contents_scale_
, raster_contents_scale_
);
1008 DCHECK_GE(low_res_raster_contents_scale_
, MinimumContentsScale());
1009 DCHECK_LE(low_res_raster_contents_scale_
, MaximumContentsScale());
1012 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
1013 const std::vector
<PictureLayerTiling
*>& used_tilings
) {
1014 DCHECK(layer_tree_impl()->IsActiveTree());
1015 if (tilings_
->num_tilings() == 0)
1018 float min_acceptable_high_res_scale
= std::min(
1019 raster_contents_scale_
, ideal_contents_scale_
);
1020 float max_acceptable_high_res_scale
= std::max(
1021 raster_contents_scale_
, ideal_contents_scale_
);
1023 PictureLayerImpl
* twin
= GetPendingOrActiveTwinLayer();
1024 if (twin
&& twin
->CanHaveTilings()) {
1025 min_acceptable_high_res_scale
= std::min(
1026 min_acceptable_high_res_scale
,
1027 std::min(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1028 max_acceptable_high_res_scale
= std::max(
1029 max_acceptable_high_res_scale
,
1030 std::max(twin
->raster_contents_scale_
, twin
->ideal_contents_scale_
));
1033 PictureLayerTilingSet
* twin_set
= twin
? twin
->tilings_
.get() : nullptr;
1034 tilings_
->CleanUpTilings(
1035 min_acceptable_high_res_scale
, max_acceptable_high_res_scale
,
1036 used_tilings
, layer_tree_impl()->create_low_res_tiling(), twin_set
);
1037 DCHECK_GT(tilings_
->num_tilings(), 0u);
1038 SanityCheckTilingState();
1041 float PictureLayerImpl::MinimumContentsScale() const {
1042 float setting_min
= layer_tree_impl()->settings().minimum_contents_scale
;
1044 // If the contents scale is less than 1 / width (also for height),
1045 // then it will end up having less than one pixel of content in that
1046 // dimension. Bump the minimum contents scale up in this case to prevent
1047 // this from happening.
1048 int min_dimension
= std::min(raster_source_
->GetSize().width(),
1049 raster_source_
->GetSize().height());
1053 return std::max(1.f
/ min_dimension
, setting_min
);
1056 float PictureLayerImpl::MaximumContentsScale() const {
1057 // Masks can not have tilings that would become larger than the
1058 // max_texture_size since they use a single tile for the entire
1059 // tiling. Other layers can have tilings of any scale.
1061 return std::numeric_limits
<float>::max();
1063 int max_texture_size
=
1064 layer_tree_impl()->resource_provider()->max_texture_size();
1065 float max_scale_width
=
1066 static_cast<float>(max_texture_size
) / bounds().width();
1067 float max_scale_height
=
1068 static_cast<float>(max_texture_size
) / bounds().height();
1069 float max_scale
= std::min(max_scale_width
, max_scale_height
);
1070 // We require that multiplying the layer size by the contents scale and
1071 // ceiling produces a value <= |max_texture_size|. Because for large layer
1072 // sizes floating point ambiguity may crop up, making the result larger or
1073 // smaller than expected, we use a slightly smaller floating point value for
1074 // the scale, to help ensure that the resulting content bounds will never end
1075 // up larger than |max_texture_size|.
1076 return nextafterf(max_scale
, 0.f
);
1079 void PictureLayerImpl::ResetRasterScale() {
1080 raster_page_scale_
= 0.f
;
1081 raster_device_scale_
= 0.f
;
1082 raster_source_scale_
= 0.f
;
1083 raster_contents_scale_
= 0.f
;
1084 low_res_raster_contents_scale_
= 0.f
;
1085 raster_source_scale_is_fixed_
= false;
1088 bool PictureLayerImpl::CanHaveTilings() const {
1089 if (raster_source_
->IsSolidColor())
1091 if (!DrawsContent())
1093 if (!raster_source_
->HasRecordings())
1095 // If the |raster_source_| has a recording it should have non-empty bounds.
1096 DCHECK(!raster_source_
->GetSize().IsEmpty());
1097 if (MaximumContentsScale() < MinimumContentsScale())
1102 void PictureLayerImpl::SanityCheckTilingState() const {
1104 if (!CanHaveTilings()) {
1105 DCHECK_EQ(0u, tilings_
->num_tilings());
1108 if (tilings_
->num_tilings() == 0)
1111 // We should only have one high res tiling.
1112 DCHECK_EQ(1, tilings_
->NumHighResTilings());
1116 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1117 return layer_tree_impl()->use_gpu_rasterization();
1120 float PictureLayerImpl::MaximumTilingContentsScale() const {
1121 float max_contents_scale
= tilings_
->GetMaximumContentsScale();
1122 return std::max(max_contents_scale
, MinimumContentsScale());
1125 scoped_ptr
<PictureLayerTilingSet
>
1126 PictureLayerImpl::CreatePictureLayerTilingSet() {
1127 const LayerTreeSettings
& settings
= layer_tree_impl()->settings();
1128 return PictureLayerTilingSet::Create(
1129 GetTree(), this, settings
.tiling_interest_area_viewport_multiplier
,
1130 layer_tree_impl()->use_gpu_rasterization()
1131 ? settings
.gpu_rasterization_skewport_target_time_in_seconds
1132 : settings
.skewport_target_time_in_seconds
,
1133 settings
.skewport_extrapolation_limit_in_content_pixels
);
1136 void PictureLayerImpl::UpdateIdealScales() {
1137 DCHECK(CanHaveTilings());
1139 float min_contents_scale
= MinimumContentsScale();
1140 DCHECK_GT(min_contents_scale
, 0.f
);
1141 float min_page_scale
= layer_tree_impl()->min_page_scale_factor();
1142 DCHECK_GT(min_page_scale
, 0.f
);
1143 float min_device_scale
= 1.f
;
1144 float min_source_scale
=
1145 min_contents_scale
/ min_page_scale
/ min_device_scale
;
1147 float ideal_page_scale
= draw_properties().page_scale_factor
;
1148 float ideal_device_scale
= draw_properties().device_scale_factor
;
1149 float ideal_source_scale
= draw_properties().ideal_contents_scale
/
1150 ideal_page_scale
/ ideal_device_scale
;
1151 ideal_contents_scale_
=
1152 std::max(draw_properties().ideal_contents_scale
, min_contents_scale
);
1153 ideal_page_scale_
= draw_properties().page_scale_factor
;
1154 ideal_device_scale_
= draw_properties().device_scale_factor
;
1155 ideal_source_scale_
= std::max(ideal_source_scale
, min_source_scale
);
1158 void PictureLayerImpl::GetDebugBorderProperties(
1160 float* width
) const {
1161 *color
= DebugColors::TiledContentLayerBorderColor();
1162 *width
= DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1165 void PictureLayerImpl::GetAllPrioritizedTilesForTracing(
1166 std::vector
<PrioritizedTile
>* prioritized_tiles
) const {
1169 tilings_
->GetAllPrioritizedTilesForTracing(prioritized_tiles
);
1172 void PictureLayerImpl::AsValueInto(
1173 base::trace_event::TracedValue
* state
) const {
1174 LayerImpl::AsValueInto(state
);
1175 state
->SetDouble("ideal_contents_scale", ideal_contents_scale_
);
1176 state
->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1177 state
->BeginArray("tilings");
1178 tilings_
->AsValueInto(state
);
1181 MathUtil::AddToTracedValue("tile_priority_rect",
1182 viewport_rect_for_tile_priority_in_content_space_
,
1184 MathUtil::AddToTracedValue("visible_rect", visible_content_rect(), state
);
1186 state
->BeginArray("pictures");
1187 raster_source_
->AsValueInto(state
);
1190 state
->BeginArray("invalidation");
1191 invalidation_
.AsValueInto(state
);
1194 state
->BeginArray("coverage_tiles");
1195 for (PictureLayerTilingSet::CoverageIterator
iter(
1196 tilings_
.get(), 1.f
, gfx::Rect(raster_source_
->GetSize()),
1197 ideal_contents_scale_
);
1199 state
->BeginDictionary();
1201 MathUtil::AddToTracedValue("geometry_rect", iter
.geometry_rect(), state
);
1204 TracedValue::SetIDRef(*iter
, state
, "tile");
1206 state
->EndDictionary();
1211 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1212 return tilings_
->GPUMemoryUsageInBytes();
1215 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1216 benchmark
->RunOnLayer(this);
1219 WhichTree
PictureLayerImpl::GetTree() const {
1220 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
1223 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1224 return !layer_tree_impl()->IsRecycleTree();
1227 bool PictureLayerImpl::HasValidTilePriorities() const {
1228 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();