Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / layers / picture_layer_impl.cc
blob0b292ebc3a9c64a4fabfda4889927002a119ff77
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"
7 #include <algorithm>
8 #include <cmath>
9 #include <limits>
10 #include <set>
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/debug_border_draw_quad.h"
22 #include "cc/quads/picture_draw_quad.h"
23 #include "cc/quads/solid_color_draw_quad.h"
24 #include "cc/quads/tile_draw_quad.h"
25 #include "cc/tiles/tile_manager.h"
26 #include "cc/tiles/tiling_set_raster_queue_all.h"
27 #include "cc/trees/layer_tree_impl.h"
28 #include "cc/trees/occlusion.h"
29 #include "ui/gfx/geometry/quad_f.h"
30 #include "ui/gfx/geometry/rect_conversions.h"
31 #include "ui/gfx/geometry/size_conversions.h"
33 namespace {
34 // This must be > 1 as we multiply or divide by this to find a new raster
35 // scale during pinch.
36 const float kMaxScaleRatioDuringPinch = 2.0f;
38 // When creating a new tiling during pinch, snap to an existing
39 // tiling's scale if the desired scale is within this ratio.
40 const float kSnapToExistingTilingRatio = 1.2f;
42 // Even for really wide viewports, at some point GPU raster should use
43 // less than 4 tiles to fill the viewport. This is set to 256 as a
44 // sane minimum for now, but we might want to tune this for low-end.
45 const int kMinHeightForGpuRasteredTile = 256;
47 // When making odd-sized tiles, round them up to increase the chances
48 // of using the same tile size.
49 const int kTileRoundUp = 64;
51 } // namespace
53 namespace cc {
55 PictureLayerImpl::PictureLayerImpl(
56 LayerTreeImpl* tree_impl,
57 int id,
58 bool is_mask,
59 scoped_refptr<SyncedScrollOffset> scroll_offset)
60 : LayerImpl(tree_impl, id, scroll_offset),
61 twin_layer_(nullptr),
62 tilings_(CreatePictureLayerTilingSet()),
63 ideal_page_scale_(0.f),
64 ideal_device_scale_(0.f),
65 ideal_source_scale_(0.f),
66 ideal_contents_scale_(0.f),
67 raster_page_scale_(0.f),
68 raster_device_scale_(0.f),
69 raster_source_scale_(0.f),
70 raster_contents_scale_(0.f),
71 low_res_raster_contents_scale_(0.f),
72 raster_source_scale_is_fixed_(false),
73 was_screen_space_transform_animating_(false),
74 only_used_low_res_last_append_quads_(false),
75 is_mask_(is_mask),
76 nearest_neighbor_(false) {
77 layer_tree_impl()->RegisterPictureLayerImpl(this);
80 PictureLayerImpl::~PictureLayerImpl() {
81 if (twin_layer_)
82 twin_layer_->twin_layer_ = nullptr;
83 layer_tree_impl()->UnregisterPictureLayerImpl(this);
86 const char* PictureLayerImpl::LayerTypeAsString() const {
87 return "cc::PictureLayerImpl";
90 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
91 LayerTreeImpl* tree_impl) {
92 return PictureLayerImpl::Create(tree_impl, id(), is_mask_,
93 synced_scroll_offset());
96 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
97 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
98 DCHECK_EQ(layer_impl->is_mask_, is_mask_);
100 LayerImpl::PushPropertiesTo(base_layer);
102 // Twin relationships should never change once established.
103 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl);
104 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this);
105 // The twin relationship does not need to exist before the first
106 // PushPropertiesTo from pending to active layer since before that the active
107 // layer can not have a pile or tilings, it has only been created and inserted
108 // into the tree at that point.
109 twin_layer_ = layer_impl;
110 layer_impl->twin_layer_ = this;
112 layer_impl->SetNearestNeighbor(nearest_neighbor_);
114 // Solid color layers have no tilings.
115 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0);
116 // The pending tree should only have a high res (and possibly low res) tiling.
117 DCHECK_LE(tilings_->num_tilings(),
118 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u);
120 layer_impl->set_gpu_raster_max_texture_size(gpu_raster_max_texture_size_);
121 layer_impl->UpdateRasterSource(raster_source_, &invalidation_,
122 tilings_.get());
123 DCHECK(invalidation_.IsEmpty());
125 // After syncing a solid color layer, the active layer has no tilings.
126 DCHECK_IMPLIES(raster_source_->IsSolidColor(),
127 layer_impl->tilings_->num_tilings() == 0);
129 layer_impl->raster_page_scale_ = raster_page_scale_;
130 layer_impl->raster_device_scale_ = raster_device_scale_;
131 layer_impl->raster_source_scale_ = raster_source_scale_;
132 layer_impl->raster_contents_scale_ = raster_contents_scale_;
133 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_;
135 layer_impl->SanityCheckTilingState();
137 // We always need to push properties.
138 // See http://crbug.com/303943
139 // TODO(danakj): Stop always pushing properties since we don't swap tilings.
140 needs_push_properties_ = true;
143 void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
144 AppendQuadsData* append_quads_data) {
145 // The bounds and the pile size may differ if the pile wasn't updated (ie.
146 // PictureLayer::Update didn't happen). In that case the pile will be empty.
147 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(),
148 bounds() == raster_source_->GetSize())
149 << " bounds " << bounds().ToString() << " pile "
150 << raster_source_->GetSize().ToString();
152 SharedQuadState* shared_quad_state =
153 render_pass->CreateAndAppendSharedQuadState();
155 if (raster_source_->IsSolidColor()) {
156 PopulateSharedQuadState(shared_quad_state);
158 AppendDebugBorderQuad(
159 render_pass, bounds(), shared_quad_state, append_quads_data);
161 SolidColorLayerImpl::AppendSolidQuads(
162 render_pass, draw_properties().occlusion_in_content_space,
163 shared_quad_state, visible_layer_rect(),
164 raster_source_->GetSolidColor(), append_quads_data);
165 return;
168 float max_contents_scale = MaximumTilingContentsScale();
169 PopulateScaledSharedQuadState(shared_quad_state, max_contents_scale);
170 Occlusion scaled_occlusion =
171 draw_properties()
172 .occlusion_in_content_space.GetOcclusionWithGivenDrawTransform(
173 shared_quad_state->quad_to_target_transform);
175 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) {
176 AppendDebugBorderQuad(
177 render_pass, shared_quad_state->quad_layer_bounds, shared_quad_state,
178 append_quads_data, DebugColors::DirectPictureBorderColor(),
179 DebugColors::DirectPictureBorderWidth(layer_tree_impl()));
181 gfx::Rect geometry_rect = shared_quad_state->visible_quad_layer_rect;
182 gfx::Rect opaque_rect = contents_opaque() ? geometry_rect : gfx::Rect();
183 gfx::Rect visible_geometry_rect =
184 scaled_occlusion.GetUnoccludedContentRect(geometry_rect);
185 if (visible_geometry_rect.IsEmpty())
186 return;
188 gfx::Rect quad_content_rect = shared_quad_state->visible_quad_layer_rect;
189 gfx::Size texture_size = quad_content_rect.size();
190 gfx::RectF texture_rect = gfx::RectF(texture_size);
192 PictureDrawQuad* quad =
193 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
194 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect,
195 visible_geometry_rect, texture_rect, texture_size,
196 nearest_neighbor_, RGBA_8888, quad_content_rect,
197 max_contents_scale, raster_source_);
198 ValidateQuadResources(quad);
199 return;
202 AppendDebugBorderQuad(render_pass, shared_quad_state->quad_layer_bounds,
203 shared_quad_state, append_quads_data);
205 if (ShowDebugBorders()) {
206 for (PictureLayerTilingSet::CoverageIterator iter(
207 tilings_.get(), max_contents_scale,
208 shared_quad_state->visible_quad_layer_rect, ideal_contents_scale_);
209 iter; ++iter) {
210 SkColor color;
211 float width;
212 if (*iter && iter->draw_info().IsReadyToDraw()) {
213 TileDrawInfo::Mode mode = iter->draw_info().mode();
214 if (mode == TileDrawInfo::SOLID_COLOR_MODE) {
215 color = DebugColors::SolidColorTileBorderColor();
216 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
217 } else if (mode == TileDrawInfo::OOM_MODE) {
218 color = DebugColors::OOMTileBorderColor();
219 width = DebugColors::OOMTileBorderWidth(layer_tree_impl());
220 } else if (iter.resolution() == HIGH_RESOLUTION) {
221 color = DebugColors::HighResTileBorderColor();
222 width = DebugColors::HighResTileBorderWidth(layer_tree_impl());
223 } else if (iter.resolution() == LOW_RESOLUTION) {
224 color = DebugColors::LowResTileBorderColor();
225 width = DebugColors::LowResTileBorderWidth(layer_tree_impl());
226 } else if (iter->contents_scale() > max_contents_scale) {
227 color = DebugColors::ExtraHighResTileBorderColor();
228 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
229 } else {
230 color = DebugColors::ExtraLowResTileBorderColor();
231 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
233 } else {
234 color = DebugColors::MissingTileBorderColor();
235 width = DebugColors::MissingTileBorderWidth(layer_tree_impl());
238 DebugBorderDrawQuad* debug_border_quad =
239 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
240 gfx::Rect geometry_rect = iter.geometry_rect();
241 gfx::Rect visible_geometry_rect = geometry_rect;
242 debug_border_quad->SetNew(shared_quad_state,
243 geometry_rect,
244 visible_geometry_rect,
245 color,
246 width);
250 // Keep track of the tilings that were used so that tilings that are
251 // unused can be considered for removal.
252 last_append_quads_tilings_.clear();
254 // Ignore missing tiles outside of viewport for tile priority. This is
255 // normally the same as draw viewport but can be independently overridden by
256 // embedders like Android WebView with SetExternalDrawConstraints.
257 gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect(
258 viewport_rect_for_tile_priority_in_content_space_, max_contents_scale);
260 size_t missing_tile_count = 0u;
261 size_t on_demand_missing_tile_count = 0u;
262 only_used_low_res_last_append_quads_ = true;
263 for (PictureLayerTilingSet::CoverageIterator iter(
264 tilings_.get(), max_contents_scale,
265 shared_quad_state->visible_quad_layer_rect, ideal_contents_scale_);
266 iter; ++iter) {
267 gfx::Rect geometry_rect = iter.geometry_rect();
268 gfx::Rect opaque_rect = contents_opaque() ? geometry_rect : gfx::Rect();
269 gfx::Rect visible_geometry_rect =
270 scaled_occlusion.GetUnoccludedContentRect(geometry_rect);
271 if (visible_geometry_rect.IsEmpty())
272 continue;
274 append_quads_data->visible_layer_area +=
275 visible_geometry_rect.width() * visible_geometry_rect.height();
277 bool has_draw_quad = false;
278 if (*iter && iter->draw_info().IsReadyToDraw()) {
279 const TileDrawInfo& draw_info = iter->draw_info();
280 switch (draw_info.mode()) {
281 case TileDrawInfo::RESOURCE_MODE: {
282 gfx::RectF texture_rect = iter.texture_rect();
284 // The raster_contents_scale_ is the best scale that the layer is
285 // trying to produce, even though it may not be ideal. Since that's
286 // the best the layer can promise in the future, consider those as
287 // complete. But if a tile is ideal scale, we don't want to consider
288 // it incomplete and trying to replace it with a tile at a worse
289 // scale.
290 if (iter->contents_scale() != raster_contents_scale_ &&
291 iter->contents_scale() != ideal_contents_scale_ &&
292 geometry_rect.Intersects(scaled_viewport_for_tile_priority)) {
293 append_quads_data->num_incomplete_tiles++;
296 TileDrawQuad* quad =
297 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
298 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect,
299 visible_geometry_rect, draw_info.resource_id(),
300 texture_rect, draw_info.resource_size(),
301 draw_info.contents_swizzled(), nearest_neighbor_);
302 ValidateQuadResources(quad);
303 iter->draw_info().set_was_ever_used_to_draw();
304 has_draw_quad = true;
305 break;
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 iter->draw_info().set_was_ever_used_to_draw();
314 has_draw_quad = true;
315 break;
317 case TileDrawInfo::OOM_MODE:
318 break; // Checkerboard.
322 if (!has_draw_quad) {
323 // Checkerboard.
324 SkColor color = SafeOpaqueBackgroundColor();
325 if (ShowDebugBorders()) {
326 // Fill the whole tile with the missing tile color.
327 color = DebugColors::OOMTileBorderColor();
329 SolidColorDrawQuad* quad =
330 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
331 quad->SetNew(shared_quad_state, geometry_rect, visible_geometry_rect,
332 color, false);
333 ValidateQuadResources(quad);
335 if (geometry_rect.Intersects(scaled_viewport_for_tile_priority)) {
336 append_quads_data->num_missing_tiles++;
337 ++missing_tile_count;
339 append_quads_data->approximated_visible_content_area +=
340 visible_geometry_rect.width() * visible_geometry_rect.height();
341 append_quads_data->checkerboarded_visible_content_area +=
342 visible_geometry_rect.width() * visible_geometry_rect.height();
343 continue;
346 if (iter.resolution() != HIGH_RESOLUTION) {
347 append_quads_data->approximated_visible_content_area +=
348 visible_geometry_rect.width() * visible_geometry_rect.height();
351 // If we have a draw quad, but it's not low resolution, then
352 // mark that we've used something other than low res to draw.
353 if (iter.resolution() != LOW_RESOLUTION)
354 only_used_low_res_last_append_quads_ = false;
356 if (last_append_quads_tilings_.empty() ||
357 last_append_quads_tilings_.back() != iter.CurrentTiling()) {
358 last_append_quads_tilings_.push_back(iter.CurrentTiling());
362 if (missing_tile_count) {
363 TRACE_EVENT_INSTANT2("cc",
364 "PictureLayerImpl::AppendQuads checkerboard",
365 TRACE_EVENT_SCOPE_THREAD,
366 "missing_tile_count",
367 missing_tile_count,
368 "on_demand_missing_tile_count",
369 on_demand_missing_tile_count);
372 // Aggressively remove any tilings that are not seen to save memory. Note
373 // that this is at the expense of doing cause more frequent re-painting. A
374 // better scheme would be to maintain a tighter visible_layer_rect for the
375 // finer tilings.
376 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_);
379 bool PictureLayerImpl::UpdateTiles(bool resourceless_software_draw) {
380 if (!resourceless_software_draw) {
381 visible_rect_for_tile_priority_ = visible_layer_rect();
384 if (!CanHaveTilings()) {
385 ideal_page_scale_ = 0.f;
386 ideal_device_scale_ = 0.f;
387 ideal_contents_scale_ = 0.f;
388 ideal_source_scale_ = 0.f;
389 SanityCheckTilingState();
390 return false;
393 // Remove any non-ideal tilings that were not used last time we generated
394 // quads to save memory and processing time. Note that pending tree should
395 // only have one or two tilings (high and low res), so only clean up the
396 // active layer. This cleans it up here in case AppendQuads didn't run.
397 // If it did run, this would not remove any additional tilings.
398 if (layer_tree_impl()->IsActiveTree())
399 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_);
401 UpdateIdealScales();
403 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) {
404 RecalculateRasterScales();
405 AddTilingsForRasterScale();
408 if (layer_tree_impl()->IsActiveTree())
409 AddLowResolutionTilingIfNeeded();
411 DCHECK(raster_page_scale_);
412 DCHECK(raster_device_scale_);
413 DCHECK(raster_source_scale_);
414 DCHECK(raster_contents_scale_);
415 DCHECK(low_res_raster_contents_scale_);
417 was_screen_space_transform_animating_ =
418 draw_properties().screen_space_transform_is_animating;
420 if (screen_space_transform_is_animating())
421 raster_source_->SetShouldAttemptToUseDistanceFieldText();
423 double current_frame_time_in_seconds =
424 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time -
425 base::TimeTicks()).InSecondsF();
426 UpdateViewportRectForTilePriorityInContentSpace();
428 // The tiling set can require tiles for activation any of the following
429 // conditions are true:
430 // - This layer produced a high-res or non-ideal-res tile last frame.
431 // - We're in requires high res to draw mode.
432 // - We're not in smoothness takes priority mode.
433 // To put different, the tiling set can't require tiles for activation if
434 // we're in smoothness mode and only used low-res or checkerboard to draw last
435 // frame and we don't need high res to draw.
437 // The reason for this is that we should be able to activate sooner and get a
438 // more up to date recording, so we don't run out of recording on the active
439 // tree.
440 bool can_require_tiles_for_activation =
441 !only_used_low_res_last_append_quads_ || RequiresHighResToDraw() ||
442 !layer_tree_impl()->SmoothnessTakesPriority();
444 static const Occlusion kEmptyOcclusion;
445 const Occlusion& occlusion_in_content_space =
446 layer_tree_impl()->settings().use_occlusion_for_tile_prioritization
447 ? draw_properties().occlusion_in_content_space
448 : kEmptyOcclusion;
450 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since
451 // they are the same space in picture layer, as contents scale is always 1.
452 bool updated = tilings_->UpdateTilePriorities(
453 viewport_rect_for_tile_priority_in_content_space_, ideal_contents_scale_,
454 current_frame_time_in_seconds, occlusion_in_content_space,
455 can_require_tiles_for_activation);
456 return updated;
459 void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {
460 // If visible_rect_for_tile_priority_ is empty or
461 // viewport_rect_for_tile_priority is set to be different from the device
462 // viewport, try to inverse project the viewport into layer space and use
463 // that. Otherwise just use visible_rect_for_tile_priority_
464 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_;
465 gfx::Rect viewport_rect_for_tile_priority =
466 layer_tree_impl()->ViewportRectForTilePriority();
467 if (visible_rect_in_content_space.IsEmpty() ||
468 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority) {
469 gfx::Transform view_to_layer(gfx::Transform::kSkipInitialization);
470 if (screen_space_transform().GetInverse(&view_to_layer)) {
471 // Transform from view space to content space.
472 visible_rect_in_content_space =
473 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
474 view_to_layer, viewport_rect_for_tile_priority));
476 // We have to allow for a viewport that is outside of the layer bounds in
477 // order to compute tile priorities correctly for offscreen content that
478 // is going to make it on screen. However, we also have to limit the
479 // viewport since it can be very large due to screen_space_transforms. As
480 // a heuristic, we clip to bounds padded by skewport_extrapolation_limit *
481 // maximum tiling scale, since this should allow sufficient room for
482 // skewport calculations.
483 gfx::Rect padded_bounds(bounds());
484 int padding_amount = layer_tree_impl()
485 ->settings()
486 .skewport_extrapolation_limit_in_content_pixels *
487 MaximumTilingContentsScale();
488 padded_bounds.Inset(-padding_amount, -padding_amount);
489 visible_rect_in_content_space.Intersect(padded_bounds);
492 viewport_rect_for_tile_priority_in_content_space_ =
493 visible_rect_in_content_space;
496 PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
497 if (!twin_layer_ || !twin_layer_->IsOnActiveOrPendingTree())
498 return nullptr;
499 return twin_layer_;
502 void PictureLayerImpl::UpdateRasterSource(
503 scoped_refptr<RasterSource> raster_source,
504 Region* new_invalidation,
505 const PictureLayerTilingSet* pending_set) {
506 // The bounds and the pile size may differ if the pile wasn't updated (ie.
507 // PictureLayer::Update didn't happen). In that case the pile will be empty.
508 DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(),
509 bounds() == raster_source->GetSize())
510 << " bounds " << bounds().ToString() << " pile "
511 << raster_source->GetSize().ToString();
513 // The |raster_source_| is initially null, so have to check for that for the
514 // first frame.
515 bool could_have_tilings = raster_source_.get() && CanHaveTilings();
516 raster_source_.swap(raster_source);
518 // The |new_invalidation| must be cleared before updating tilings since they
519 // access the invalidation through the PictureLayerTilingClient interface.
520 invalidation_.Clear();
521 invalidation_.Swap(new_invalidation);
523 bool can_have_tilings = CanHaveTilings();
524 DCHECK_IMPLIES(
525 pending_set,
526 can_have_tilings == GetPendingOrActiveTwinLayer()->CanHaveTilings());
528 // Need to call UpdateTiles again if CanHaveTilings changed.
529 if (could_have_tilings != can_have_tilings)
530 layer_tree_impl()->set_needs_update_draw_properties();
532 if (!can_have_tilings) {
533 RemoveAllTilings();
534 return;
537 // We could do this after doing UpdateTiles, which would avoid doing this for
538 // tilings that are going to disappear on the pending tree (if scale changed).
539 // But that would also be more complicated, so we just do it here for now.
540 if (pending_set) {
541 tilings_->UpdateTilingsToCurrentRasterSourceForActivation(
542 raster_source_, pending_set, invalidation_, MinimumContentsScale(),
543 MaximumContentsScale());
544 } else {
545 tilings_->UpdateTilingsToCurrentRasterSourceForCommit(
546 raster_source_, invalidation_, MinimumContentsScale(),
547 MaximumContentsScale());
551 void PictureLayerImpl::UpdateCanUseLCDTextAfterCommit() {
552 // This function is only allowed to be called after commit, due to it not
553 // being smart about sharing tiles and because otherwise it would cause
554 // flashes by switching out tiles in place that may be currently on screen.
555 DCHECK(layer_tree_impl()->IsSyncTree());
557 // Don't allow the LCD text state to change once disabled.
558 if (!RasterSourceUsesLCDText())
559 return;
560 if (can_use_lcd_text() == RasterSourceUsesLCDText())
561 return;
563 // Raster sources are considered const, so in order to update the state
564 // a new one must be created and all tiles recreated.
565 scoped_refptr<RasterSource> new_raster_source =
566 raster_source_->CreateCloneWithoutLCDText();
567 raster_source_.swap(new_raster_source);
569 // Synthetically invalidate everything.
570 gfx::Rect bounds_rect(bounds());
571 invalidation_ = Region(bounds_rect);
572 tilings_->UpdateRasterSourceDueToLCDChange(raster_source_, invalidation_);
573 SetUpdateRect(bounds_rect);
575 DCHECK(!RasterSourceUsesLCDText());
578 bool PictureLayerImpl::RasterSourceUsesLCDText() const {
579 return raster_source_ ? raster_source_->CanUseLCDText()
580 : layer_tree_impl()->settings().can_use_lcd_text;
583 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) {
584 if (layer_tree_impl()->IsActiveTree()) {
585 gfx::RectF layer_damage_rect =
586 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale());
587 AddDamageRect(layer_damage_rect);
589 if (tile->draw_info().NeedsRaster()) {
590 PictureLayerTiling* tiling =
591 tilings_->FindTilingWithScale(tile->contents_scale());
592 if (tiling)
593 tiling->set_all_tiles_done(false);
597 void PictureLayerImpl::DidBeginTracing() {
598 raster_source_->DidBeginTracing();
601 void PictureLayerImpl::ReleaseResources() {
602 // Recreate tilings with new settings, since some of those might change when
603 // we release resources.
604 tilings_ = nullptr;
605 ResetRasterScale();
608 void PictureLayerImpl::RecreateResources() {
609 tilings_ = CreatePictureLayerTilingSet();
611 // To avoid an edge case after lost context where the tree is up to date but
612 // the tilings have not been managed, request an update draw properties
613 // to force tilings to get managed.
614 layer_tree_impl()->set_needs_update_draw_properties();
617 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() {
618 return raster_source_->GetFlattenedPicture();
621 Region PictureLayerImpl::GetInvalidationRegion() {
622 // |invalidation_| gives the invalidation contained in the source frame, but
623 // is not cleared after drawing from the layer. However, update_rect() is
624 // cleared once the invalidation is drawn, which is useful for debugging
625 // visualizations. This method intersects the two to give a more exact
626 // representation of what was invalidated that is cleared after drawing.
627 return IntersectRegions(invalidation_, update_rect());
630 ScopedTilePtr PictureLayerImpl::CreateTile(float contents_scale,
631 const gfx::Rect& content_rect) {
632 int flags = 0;
634 // We don't handle solid color masks, so we shouldn't bother analyzing those.
635 // Otherwise, always analyze to maximize memory savings.
636 if (!is_mask_)
637 flags = Tile::USE_PICTURE_ANALYSIS;
639 return layer_tree_impl()->tile_manager()->CreateTile(
640 content_rect.size(), content_rect, contents_scale, id(),
641 layer_tree_impl()->source_frame_number(), flags);
644 const Region* PictureLayerImpl::GetPendingInvalidation() {
645 if (layer_tree_impl()->IsPendingTree())
646 return &invalidation_;
647 if (layer_tree_impl()->IsRecycleTree())
648 return nullptr;
649 DCHECK(layer_tree_impl()->IsActiveTree());
650 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer())
651 return &twin_layer->invalidation_;
652 return nullptr;
655 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling(
656 const PictureLayerTiling* tiling) const {
657 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
658 if (!twin_layer)
659 return nullptr;
660 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale());
663 bool PictureLayerImpl::RequiresHighResToDraw() const {
664 return layer_tree_impl()->RequiresHighResToDraw();
667 gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const {
668 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale());
671 gfx::Size PictureLayerImpl::CalculateTileSize(
672 const gfx::Size& content_bounds) const {
673 int max_texture_size =
674 layer_tree_impl()->resource_provider()->max_texture_size();
676 if (is_mask_) {
677 // Masks are not tiled, so if we can't cover the whole mask with one tile,
678 // we shouldn't have such a tiling at all.
679 DCHECK_LE(content_bounds.width(), max_texture_size);
680 DCHECK_LE(content_bounds.height(), max_texture_size);
681 return content_bounds;
684 int default_tile_width = 0;
685 int default_tile_height = 0;
686 if (layer_tree_impl()->use_gpu_rasterization()) {
687 // For GPU rasterization, we pick an ideal tile size using the viewport
688 // so we don't need any settings. The current approach uses 4 tiles
689 // to cover the viewport vertically.
690 int viewport_width = gpu_raster_max_texture_size_.width();
691 int viewport_height = gpu_raster_max_texture_size_.height();
692 default_tile_width = viewport_width;
694 // Also, increase the height proportionally as the width decreases, and
695 // pad by our border texels to make the tiles exactly match the viewport.
696 int divisor = 4;
697 if (content_bounds.width() <= viewport_width / 2)
698 divisor = 2;
699 if (content_bounds.width() <= viewport_width / 4)
700 divisor = 1;
701 default_tile_height =
702 MathUtil::UncheckedRoundUp(viewport_height, divisor) / divisor;
704 // Grow default sizes to account for overlapping border texels.
705 default_tile_width += 2 * PictureLayerTiling::kBorderTexels;
706 default_tile_height += 2 * PictureLayerTiling::kBorderTexels;
708 default_tile_height =
709 std::max(default_tile_height, kMinHeightForGpuRasteredTile);
710 } else {
711 // For CPU rasterization we use tile-size settings.
712 const LayerTreeSettings& settings = layer_tree_impl()->settings();
713 int max_untiled_content_width = settings.max_untiled_layer_size.width();
714 int max_untiled_content_height = settings.max_untiled_layer_size.height();
715 default_tile_width = settings.default_tile_size.width();
716 default_tile_height = settings.default_tile_size.height();
718 // If the content width is small, increase tile size vertically.
719 // If the content height is small, increase tile size horizontally.
720 // If both are less than the untiled-size, use a single tile.
721 if (content_bounds.width() < default_tile_width)
722 default_tile_height = max_untiled_content_height;
723 if (content_bounds.height() < default_tile_height)
724 default_tile_width = max_untiled_content_width;
725 if (content_bounds.width() < max_untiled_content_width &&
726 content_bounds.height() < max_untiled_content_height) {
727 default_tile_height = max_untiled_content_height;
728 default_tile_width = max_untiled_content_width;
732 int tile_width = default_tile_width;
733 int tile_height = default_tile_height;
735 // Clamp the tile width/height to the content width/height to save space.
736 if (content_bounds.width() < default_tile_width) {
737 tile_width = std::min(tile_width, content_bounds.width());
738 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileRoundUp);
739 tile_width = std::min(tile_width, default_tile_width);
741 if (content_bounds.height() < default_tile_height) {
742 tile_height = std::min(tile_height, content_bounds.height());
743 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileRoundUp);
744 tile_height = std::min(tile_height, default_tile_height);
747 // Under no circumstance should we be larger than the max texture size.
748 tile_width = std::min(tile_width, max_texture_size);
749 tile_height = std::min(tile_height, max_texture_size);
750 return gfx::Size(tile_width, tile_height);
753 void PictureLayerImpl::GetContentsResourceId(ResourceId* resource_id,
754 gfx::Size* resource_size) const {
755 // The bounds and the pile size may differ if the pile wasn't updated (ie.
756 // PictureLayer::Update didn't happen). In that case the pile will be empty.
757 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(),
758 bounds() == raster_source_->GetSize())
759 << " bounds " << bounds().ToString() << " pile "
760 << raster_source_->GetSize().ToString();
761 gfx::Rect content_rect(bounds());
762 PictureLayerTilingSet::CoverageIterator iter(
763 tilings_.get(), 1.f, content_rect, ideal_contents_scale_);
765 // Mask resource not ready yet.
766 if (!iter || !*iter) {
767 *resource_id = 0;
768 return;
771 // Masks only supported if they fit on exactly one tile.
772 DCHECK(iter.geometry_rect() == content_rect)
773 << "iter rect " << iter.geometry_rect().ToString() << " content rect "
774 << content_rect.ToString();
776 const TileDrawInfo& draw_info = iter->draw_info();
777 if (!draw_info.IsReadyToDraw() ||
778 draw_info.mode() != TileDrawInfo::RESOURCE_MODE) {
779 *resource_id = 0;
780 return;
783 *resource_id = draw_info.resource_id();
784 *resource_size = draw_info.resource_size();
787 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) {
788 if (nearest_neighbor_ == nearest_neighbor)
789 return;
791 nearest_neighbor_ = nearest_neighbor;
792 NoteLayerPropertyChanged();
795 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
796 DCHECK(CanHaveTilings());
797 DCHECK_GE(contents_scale, MinimumContentsScale());
798 DCHECK_LE(contents_scale, MaximumContentsScale());
799 DCHECK(raster_source_->HasRecordings());
800 return tilings_->AddTiling(contents_scale, raster_source_);
803 void PictureLayerImpl::RemoveAllTilings() {
804 tilings_->RemoveAllTilings();
805 // If there are no tilings, then raster scales are no longer meaningful.
806 ResetRasterScale();
809 void PictureLayerImpl::AddTilingsForRasterScale() {
810 // Reset all resolution enums on tilings, we'll be setting new values in this
811 // function.
812 tilings_->MarkAllTilingsNonIdeal();
814 PictureLayerTiling* high_res =
815 tilings_->FindTilingWithScale(raster_contents_scale_);
816 if (!high_res) {
817 // We always need a high res tiling, so create one if it doesn't exist.
818 high_res = AddTiling(raster_contents_scale_);
819 } else if (high_res->may_contain_low_resolution_tiles()) {
820 // If the tiling we find here was LOW_RESOLUTION previously, it may not be
821 // fully rastered, so destroy the old tiles.
822 high_res->Reset();
823 // Reset the flag now that we'll make it high res, it will have fully
824 // rastered content.
825 high_res->reset_may_contain_low_resolution_tiles();
827 high_res->set_resolution(HIGH_RESOLUTION);
829 if (layer_tree_impl()->IsPendingTree()) {
830 // On the pending tree, drop any tilings that are non-ideal since we don't
831 // need them to activate anyway.
832 tilings_->RemoveNonIdealTilings();
835 SanityCheckTilingState();
838 bool PictureLayerImpl::ShouldAdjustRasterScale() const {
839 if (was_screen_space_transform_animating_ !=
840 draw_properties().screen_space_transform_is_animating)
841 return true;
843 if (draw_properties().screen_space_transform_is_animating &&
844 raster_contents_scale_ != ideal_contents_scale_ &&
845 ShouldAdjustRasterScaleDuringScaleAnimations())
846 return true;
848 bool is_pinching = layer_tree_impl()->PinchGestureActive();
849 if (is_pinching && raster_page_scale_) {
850 // We change our raster scale when it is:
851 // - Higher than ideal (need a lower-res tiling available)
852 // - Too far from ideal (need a higher-res tiling available)
853 float ratio = ideal_page_scale_ / raster_page_scale_;
854 if (raster_page_scale_ > ideal_page_scale_ ||
855 ratio > kMaxScaleRatioDuringPinch)
856 return true;
859 if (!is_pinching) {
860 // When not pinching, match the ideal page scale factor.
861 if (raster_page_scale_ != ideal_page_scale_)
862 return true;
865 // Always match the ideal device scale factor.
866 if (raster_device_scale_ != ideal_device_scale_)
867 return true;
869 // When the source scale changes we want to match it, but not when animating
870 // or when we've fixed the scale in place.
871 if (!draw_properties().screen_space_transform_is_animating &&
872 !raster_source_scale_is_fixed_ &&
873 raster_source_scale_ != ideal_source_scale_)
874 return true;
876 if (raster_contents_scale_ > MaximumContentsScale())
877 return true;
878 if (raster_contents_scale_ < MinimumContentsScale())
879 return true;
881 return false;
884 void PictureLayerImpl::AddLowResolutionTilingIfNeeded() {
885 DCHECK(layer_tree_impl()->IsActiveTree());
887 if (!layer_tree_impl()->create_low_res_tiling())
888 return;
890 // We should have a high resolution tiling at raster_contents_scale, so if the
891 // low res one is the same then we shouldn't try to override this tiling by
892 // marking it as a low res.
893 if (raster_contents_scale_ == low_res_raster_contents_scale_)
894 return;
896 PictureLayerTiling* low_res =
897 tilings_->FindTilingWithScale(low_res_raster_contents_scale_);
898 DCHECK_IMPLIES(low_res, low_res->resolution() != HIGH_RESOLUTION);
900 // Only create new low res tilings when the transform is static. This
901 // prevents wastefully creating a paired low res tiling for every new high
902 // res tiling during a pinch or a CSS animation.
903 bool is_pinching = layer_tree_impl()->PinchGestureActive();
904 bool is_animating = draw_properties().screen_space_transform_is_animating;
905 if (!is_pinching && !is_animating) {
906 if (!low_res)
907 low_res = AddTiling(low_res_raster_contents_scale_);
908 low_res->set_resolution(LOW_RESOLUTION);
912 void PictureLayerImpl::RecalculateRasterScales() {
913 float old_raster_contents_scale = raster_contents_scale_;
914 float old_raster_page_scale = raster_page_scale_;
915 float old_raster_source_scale = raster_source_scale_;
917 raster_device_scale_ = ideal_device_scale_;
918 raster_page_scale_ = ideal_page_scale_;
919 raster_source_scale_ = ideal_source_scale_;
920 raster_contents_scale_ = ideal_contents_scale_;
922 // If we're not animating, or leaving an animation, and the
923 // ideal_source_scale_ changes, then things are unpredictable, and we fix
924 // the raster_source_scale_ in place.
925 if (old_raster_source_scale &&
926 !draw_properties().screen_space_transform_is_animating &&
927 !was_screen_space_transform_animating_ &&
928 old_raster_source_scale != ideal_source_scale_)
929 raster_source_scale_is_fixed_ = true;
931 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
932 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
933 // tree. This will allow CSS scale changes to get re-rastered at an
934 // appropriate rate. (crbug.com/413636)
935 if (raster_source_scale_is_fixed_) {
936 raster_contents_scale_ /= raster_source_scale_;
937 raster_source_scale_ = 1.f;
940 // During pinch we completely ignore the current ideal scale, and just use
941 // a multiple of the previous scale.
942 bool is_pinching = layer_tree_impl()->PinchGestureActive();
943 if (is_pinching && old_raster_contents_scale) {
944 // See ShouldAdjustRasterScale:
945 // - When zooming out, preemptively create new tiling at lower resolution.
946 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
947 bool zooming_out = old_raster_page_scale > ideal_page_scale_;
948 float desired_contents_scale = old_raster_contents_scale;
949 if (zooming_out) {
950 while (desired_contents_scale > ideal_contents_scale_)
951 desired_contents_scale /= kMaxScaleRatioDuringPinch;
952 } else {
953 while (desired_contents_scale < ideal_contents_scale_)
954 desired_contents_scale *= kMaxScaleRatioDuringPinch;
956 raster_contents_scale_ = tilings_->GetSnappedContentsScale(
957 desired_contents_scale, kSnapToExistingTilingRatio);
958 raster_page_scale_ =
959 raster_contents_scale_ / raster_device_scale_ / raster_source_scale_;
962 // If we're not re-rasterizing during animation, rasterize at the maximum
963 // scale that will occur during the animation, if the maximum scale is
964 // known. However we want to avoid excessive memory use. If the scale is
965 // smaller than what we would choose otherwise, then it's always better off
966 // for us memory-wise. But otherwise, we don't choose a scale at which this
967 // layer's rastered content would become larger than the viewport.
968 if (draw_properties().screen_space_transform_is_animating &&
969 !ShouldAdjustRasterScaleDuringScaleAnimations()) {
970 bool can_raster_at_maximum_scale = false;
971 bool should_raster_at_starting_scale = false;
972 float maximum_scale = draw_properties().maximum_animation_contents_scale;
973 float starting_scale = draw_properties().starting_animation_contents_scale;
974 if (maximum_scale) {
975 gfx::Size bounds_at_maximum_scale = gfx::ToCeiledSize(
976 gfx::ScaleSize(raster_source_->GetSize(), maximum_scale));
977 int64 maximum_area = static_cast<int64>(bounds_at_maximum_scale.width()) *
978 static_cast<int64>(bounds_at_maximum_scale.height());
979 gfx::Size viewport = layer_tree_impl()->device_viewport_size();
980 int64 viewport_area = static_cast<int64>(viewport.width()) *
981 static_cast<int64>(viewport.height());
982 if (maximum_area <= viewport_area)
983 can_raster_at_maximum_scale = true;
985 if (starting_scale && starting_scale > maximum_scale) {
986 gfx::Size bounds_at_starting_scale = gfx::ToCeiledSize(
987 gfx::ScaleSize(raster_source_->GetSize(), starting_scale));
988 int64 start_area = static_cast<int64>(bounds_at_starting_scale.width()) *
989 static_cast<int64>(bounds_at_starting_scale.height());
990 gfx::Size viewport = layer_tree_impl()->device_viewport_size();
991 int64 viewport_area = static_cast<int64>(viewport.width()) *
992 static_cast<int64>(viewport.height());
993 if (start_area <= viewport_area)
994 should_raster_at_starting_scale = true;
996 // Use the computed scales for the raster scale directly, do not try to use
997 // the ideal scale here. The current ideal scale may be way too large in the
998 // case of an animation with scale, and will be constantly changing.
999 if (should_raster_at_starting_scale)
1000 raster_contents_scale_ = starting_scale;
1001 else if (can_raster_at_maximum_scale)
1002 raster_contents_scale_ = maximum_scale;
1003 else
1004 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_;
1007 raster_contents_scale_ =
1008 std::max(raster_contents_scale_, MinimumContentsScale());
1009 raster_contents_scale_ =
1010 std::min(raster_contents_scale_, MaximumContentsScale());
1011 DCHECK_GE(raster_contents_scale_, MinimumContentsScale());
1012 DCHECK_LE(raster_contents_scale_, MaximumContentsScale());
1014 // If this layer would create zero or one tiles at this content scale,
1015 // don't create a low res tiling.
1016 gfx::Size raster_bounds = gfx::ToCeiledSize(
1017 gfx::ScaleSize(raster_source_->GetSize(), raster_contents_scale_));
1018 gfx::Size tile_size = CalculateTileSize(raster_bounds);
1019 bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() &&
1020 tile_size.height() >= raster_bounds.height();
1021 if (tile_size.IsEmpty() || tile_covers_bounds) {
1022 low_res_raster_contents_scale_ = raster_contents_scale_;
1023 return;
1026 float low_res_factor =
1027 layer_tree_impl()->settings().low_res_contents_scale_factor;
1028 low_res_raster_contents_scale_ =
1029 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale());
1030 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_);
1031 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale());
1032 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale());
1035 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
1036 const std::vector<PictureLayerTiling*>& used_tilings) {
1037 DCHECK(layer_tree_impl()->IsActiveTree());
1038 if (tilings_->num_tilings() == 0)
1039 return;
1041 float min_acceptable_high_res_scale = std::min(
1042 raster_contents_scale_, ideal_contents_scale_);
1043 float max_acceptable_high_res_scale = std::max(
1044 raster_contents_scale_, ideal_contents_scale_);
1046 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer();
1047 if (twin && twin->CanHaveTilings()) {
1048 min_acceptable_high_res_scale = std::min(
1049 min_acceptable_high_res_scale,
1050 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1051 max_acceptable_high_res_scale = std::max(
1052 max_acceptable_high_res_scale,
1053 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1056 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr;
1057 tilings_->CleanUpTilings(min_acceptable_high_res_scale,
1058 max_acceptable_high_res_scale, used_tilings,
1059 twin_set);
1060 DCHECK_GT(tilings_->num_tilings(), 0u);
1061 SanityCheckTilingState();
1064 float PictureLayerImpl::MinimumContentsScale() const {
1065 float setting_min = layer_tree_impl()->settings().minimum_contents_scale;
1067 // If the contents scale is less than 1 / width (also for height),
1068 // then it will end up having less than one pixel of content in that
1069 // dimension. Bump the minimum contents scale up in this case to prevent
1070 // this from happening.
1071 int min_dimension = std::min(raster_source_->GetSize().width(),
1072 raster_source_->GetSize().height());
1073 if (!min_dimension)
1074 return setting_min;
1076 return std::max(1.f / min_dimension, setting_min);
1079 float PictureLayerImpl::MaximumContentsScale() const {
1080 // Masks can not have tilings that would become larger than the
1081 // max_texture_size since they use a single tile for the entire
1082 // tiling. Other layers can have tilings of any scale.
1083 if (!is_mask_)
1084 return std::numeric_limits<float>::max();
1086 int max_texture_size =
1087 layer_tree_impl()->resource_provider()->max_texture_size();
1088 float max_scale_width =
1089 static_cast<float>(max_texture_size) / bounds().width();
1090 float max_scale_height =
1091 static_cast<float>(max_texture_size) / bounds().height();
1092 float max_scale = std::min(max_scale_width, max_scale_height);
1093 // We require that multiplying the layer size by the contents scale and
1094 // ceiling produces a value <= |max_texture_size|. Because for large layer
1095 // sizes floating point ambiguity may crop up, making the result larger or
1096 // smaller than expected, we use a slightly smaller floating point value for
1097 // the scale, to help ensure that the resulting content bounds will never end
1098 // up larger than |max_texture_size|.
1099 return nextafterf(max_scale, 0.f);
1102 void PictureLayerImpl::ResetRasterScale() {
1103 raster_page_scale_ = 0.f;
1104 raster_device_scale_ = 0.f;
1105 raster_source_scale_ = 0.f;
1106 raster_contents_scale_ = 0.f;
1107 low_res_raster_contents_scale_ = 0.f;
1108 raster_source_scale_is_fixed_ = false;
1111 bool PictureLayerImpl::CanHaveTilings() const {
1112 if (raster_source_->IsSolidColor())
1113 return false;
1114 if (!DrawsContent())
1115 return false;
1116 if (!raster_source_->HasRecordings())
1117 return false;
1118 // If the |raster_source_| has a recording it should have non-empty bounds.
1119 DCHECK(!raster_source_->GetSize().IsEmpty());
1120 if (MaximumContentsScale() < MinimumContentsScale())
1121 return false;
1122 return true;
1125 void PictureLayerImpl::SanityCheckTilingState() const {
1126 #if DCHECK_IS_ON()
1127 if (!CanHaveTilings()) {
1128 DCHECK_EQ(0u, tilings_->num_tilings());
1129 return;
1131 if (tilings_->num_tilings() == 0)
1132 return;
1134 // We should only have one high res tiling.
1135 DCHECK_EQ(1, tilings_->NumHighResTilings());
1136 #endif
1139 bool PictureLayerImpl::ShouldAdjustRasterScaleDuringScaleAnimations() const {
1140 return layer_tree_impl()->use_gpu_rasterization();
1143 float PictureLayerImpl::MaximumTilingContentsScale() const {
1144 float max_contents_scale = tilings_->GetMaximumContentsScale();
1145 return std::max(max_contents_scale, MinimumContentsScale());
1148 scoped_ptr<PictureLayerTilingSet>
1149 PictureLayerImpl::CreatePictureLayerTilingSet() {
1150 const LayerTreeSettings& settings = layer_tree_impl()->settings();
1151 return PictureLayerTilingSet::Create(
1152 GetTree(), this, settings.tiling_interest_area_padding,
1153 layer_tree_impl()->use_gpu_rasterization()
1154 ? settings.gpu_rasterization_skewport_target_time_in_seconds
1155 : settings.skewport_target_time_in_seconds,
1156 settings.skewport_extrapolation_limit_in_content_pixels);
1159 void PictureLayerImpl::UpdateIdealScales() {
1160 DCHECK(CanHaveTilings());
1162 float min_contents_scale = MinimumContentsScale();
1163 DCHECK_GT(min_contents_scale, 0.f);
1165 ideal_page_scale_ = IsAffectedByPageScale()
1166 ? layer_tree_impl()->current_page_scale_factor()
1167 : 1.f;
1168 ideal_device_scale_ = layer_tree_impl()->device_scale_factor();
1169 ideal_contents_scale_ = std::max(GetIdealContentsScale(), min_contents_scale);
1170 ideal_source_scale_ =
1171 ideal_contents_scale_ / ideal_page_scale_ / ideal_device_scale_;
1174 void PictureLayerImpl::GetDebugBorderProperties(
1175 SkColor* color,
1176 float* width) const {
1177 *color = DebugColors::TiledContentLayerBorderColor();
1178 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1181 void PictureLayerImpl::GetAllPrioritizedTilesForTracing(
1182 std::vector<PrioritizedTile>* prioritized_tiles) const {
1183 if (!tilings_)
1184 return;
1185 tilings_->GetAllPrioritizedTilesForTracing(prioritized_tiles);
1188 void PictureLayerImpl::AsValueInto(
1189 base::trace_event::TracedValue* state) const {
1190 LayerImpl::AsValueInto(state);
1191 state->SetDouble("ideal_contents_scale", ideal_contents_scale_);
1192 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale());
1193 state->BeginArray("tilings");
1194 tilings_->AsValueInto(state);
1195 state->EndArray();
1197 MathUtil::AddToTracedValue("tile_priority_rect",
1198 viewport_rect_for_tile_priority_in_content_space_,
1199 state);
1200 MathUtil::AddToTracedValue("visible_rect", visible_layer_rect(), state);
1202 state->BeginArray("pictures");
1203 raster_source_->AsValueInto(state);
1204 state->EndArray();
1206 state->BeginArray("invalidation");
1207 invalidation_.AsValueInto(state);
1208 state->EndArray();
1210 state->BeginArray("coverage_tiles");
1211 for (PictureLayerTilingSet::CoverageIterator iter(
1212 tilings_.get(), 1.f, gfx::Rect(raster_source_->GetSize()),
1213 ideal_contents_scale_);
1214 iter; ++iter) {
1215 state->BeginDictionary();
1217 MathUtil::AddToTracedValue("geometry_rect", iter.geometry_rect(), state);
1219 if (*iter)
1220 TracedValue::SetIDRef(*iter, state, "tile");
1222 state->EndDictionary();
1224 state->EndArray();
1227 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1228 return tilings_->GPUMemoryUsageInBytes();
1231 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1232 benchmark->RunOnLayer(this);
1235 WhichTree PictureLayerImpl::GetTree() const {
1236 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
1239 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1240 return !layer_tree_impl()->IsRecycleTree();
1243 bool PictureLayerImpl::HasValidTilePriorities() const {
1244 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember();
1247 } // namespace cc