OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // it incomplete and trying to replace it with a tile at a worse | 335 // it incomplete and trying to replace it with a tile at a worse |
336 // scale. | 336 // scale. |
337 if (iter->contents_scale() != raster_contents_scale_ && | 337 if (iter->contents_scale() != raster_contents_scale_ && |
338 iter->contents_scale() != ideal_contents_scale_ && | 338 iter->contents_scale() != ideal_contents_scale_ && |
339 geometry_rect.Intersects(scaled_viewport_for_tile_priority)) { | 339 geometry_rect.Intersects(scaled_viewport_for_tile_priority)) { |
340 append_quads_data->num_incomplete_tiles++; | 340 append_quads_data->num_incomplete_tiles++; |
341 } | 341 } |
342 | 342 |
343 TileDrawQuad* quad = | 343 TileDrawQuad* quad = |
344 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); | 344 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); |
345 quad->SetNew(shared_quad_state, | 345 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, |
346 geometry_rect, | 346 visible_geometry_rect, draw_info.resource_id(), |
347 opaque_rect, | 347 texture_rect, draw_info.resource_size(), |
348 visible_geometry_rect, | 348 draw_info.contents_swizzled(), nearest_neighbor_); |
349 draw_info.get_resource_id(), | |
350 texture_rect, | |
351 iter.texture_size(), | |
352 draw_info.contents_swizzled(), | |
353 nearest_neighbor_); | |
354 has_draw_quad = true; | 349 has_draw_quad = true; |
355 break; | 350 break; |
356 } | 351 } |
357 case TileDrawInfo::PICTURE_PILE_MODE: { | 352 case TileDrawInfo::PICTURE_PILE_MODE: { |
358 if (!layer_tree_impl() | 353 if (!layer_tree_impl() |
359 ->GetRendererCapabilities() | 354 ->GetRendererCapabilities() |
360 .allow_rasterize_on_demand) { | 355 .allow_rasterize_on_demand) { |
361 ++on_demand_missing_tile_count; | 356 ++on_demand_missing_tile_count; |
362 break; | 357 break; |
363 } | 358 } |
364 | 359 |
365 gfx::RectF texture_rect = iter.texture_rect(); | 360 gfx::RectF texture_rect = iter.texture_rect(); |
366 | 361 |
367 ResourceProvider* resource_provider = | 362 ResourceProvider* resource_provider = |
368 layer_tree_impl()->resource_provider(); | 363 layer_tree_impl()->resource_provider(); |
369 ResourceFormat format = | 364 ResourceFormat format = |
370 resource_provider->memory_efficient_texture_format(); | 365 resource_provider->memory_efficient_texture_format(); |
371 PictureDrawQuad* quad = | 366 PictureDrawQuad* quad = |
372 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>(); | 367 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>(); |
373 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, | 368 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, |
374 visible_geometry_rect, texture_rect, iter.texture_size(), | 369 visible_geometry_rect, texture_rect, |
375 nearest_neighbor_, format, iter->content_rect(), | 370 iter->desired_texture_size(), nearest_neighbor_, format, |
376 iter->contents_scale(), raster_source_); | 371 iter->content_rect(), iter->contents_scale(), |
| 372 raster_source_); |
377 has_draw_quad = true; | 373 has_draw_quad = true; |
378 break; | 374 break; |
379 } | 375 } |
380 case TileDrawInfo::SOLID_COLOR_MODE: { | 376 case TileDrawInfo::SOLID_COLOR_MODE: { |
381 SolidColorDrawQuad* quad = | 377 SolidColorDrawQuad* quad = |
382 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 378 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
383 quad->SetNew(shared_quad_state, | 379 quad->SetNew(shared_quad_state, geometry_rect, visible_geometry_rect, |
384 geometry_rect, | 380 draw_info.solid_color(), false); |
385 visible_geometry_rect, | |
386 draw_info.get_solid_color(), | |
387 false); | |
388 has_draw_quad = true; | 381 has_draw_quad = true; |
389 break; | 382 break; |
390 } | 383 } |
391 } | 384 } |
392 } | 385 } |
393 | 386 |
394 if (!has_draw_quad) { | 387 if (!has_draw_quad) { |
395 if (draw_checkerboard_for_missing_tiles()) { | 388 if (draw_checkerboard_for_missing_tiles()) { |
396 CheckerboardDrawQuad* quad = | 389 CheckerboardDrawQuad* quad = |
397 render_pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | 390 render_pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 on_demand_missing_tile_count); | 435 on_demand_missing_tile_count); |
443 } | 436 } |
444 | 437 |
445 // Aggressively remove any tilings that are not seen to save memory. Note | 438 // Aggressively remove any tilings that are not seen to save memory. Note |
446 // that this is at the expense of doing cause more frequent re-painting. A | 439 // that this is at the expense of doing cause more frequent re-painting. A |
447 // better scheme would be to maintain a tighter visible_content_rect for the | 440 // better scheme would be to maintain a tighter visible_content_rect for the |
448 // finer tilings. | 441 // finer tilings. |
449 CleanUpTilingsOnActiveLayer(seen_tilings); | 442 CleanUpTilingsOnActiveLayer(seen_tilings); |
450 } | 443 } |
451 | 444 |
452 void PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, | 445 bool PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, |
453 bool resourceless_software_draw) { | 446 bool resourceless_software_draw) { |
454 DCHECK_EQ(1.f, contents_scale_x()); | 447 DCHECK_EQ(1.f, contents_scale_x()); |
455 DCHECK_EQ(1.f, contents_scale_y()); | 448 DCHECK_EQ(1.f, contents_scale_y()); |
456 | 449 |
457 if (!resourceless_software_draw) { | 450 if (!resourceless_software_draw) { |
458 visible_rect_for_tile_priority_ = visible_content_rect(); | 451 visible_rect_for_tile_priority_ = visible_content_rect(); |
459 } | 452 } |
460 | 453 |
461 if (!CanHaveTilings()) { | 454 if (!CanHaveTilings()) { |
462 ideal_page_scale_ = 0.f; | 455 ideal_page_scale_ = 0.f; |
463 ideal_device_scale_ = 0.f; | 456 ideal_device_scale_ = 0.f; |
464 ideal_contents_scale_ = 0.f; | 457 ideal_contents_scale_ = 0.f; |
465 ideal_source_scale_ = 0.f; | 458 ideal_source_scale_ = 0.f; |
466 SanityCheckTilingState(); | 459 SanityCheckTilingState(); |
467 return; | 460 return false; |
468 } | 461 } |
469 | 462 |
470 UpdateIdealScales(); | 463 UpdateIdealScales(); |
471 | 464 |
472 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { | 465 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { |
473 RecalculateRasterScales(); | 466 RecalculateRasterScales(); |
474 AddTilingsForRasterScale(); | 467 AddTilingsForRasterScale(); |
475 } | 468 } |
476 | 469 |
477 DCHECK(raster_page_scale_); | 470 DCHECK(raster_page_scale_); |
478 DCHECK(raster_device_scale_); | 471 DCHECK(raster_device_scale_); |
479 DCHECK(raster_source_scale_); | 472 DCHECK(raster_source_scale_); |
480 DCHECK(raster_contents_scale_); | 473 DCHECK(raster_contents_scale_); |
481 DCHECK(low_res_raster_contents_scale_); | 474 DCHECK(low_res_raster_contents_scale_); |
482 | 475 |
483 was_screen_space_transform_animating_ = | 476 was_screen_space_transform_animating_ = |
484 draw_properties().screen_space_transform_is_animating; | 477 draw_properties().screen_space_transform_is_animating; |
485 | 478 |
486 if (draw_transform_is_animating()) | 479 if (draw_transform_is_animating()) |
487 raster_source_->SetShouldAttemptToUseDistanceFieldText(); | 480 raster_source_->SetShouldAttemptToUseDistanceFieldText(); |
488 | 481 |
489 should_update_tile_priorities_ = true; | 482 should_update_tile_priorities_ = true; |
490 | 483 |
491 UpdateTilePriorities(occlusion_in_content_space); | 484 return UpdateTilePriorities(occlusion_in_content_space); |
492 } | 485 } |
493 | 486 |
494 void PictureLayerImpl::UpdateTilePriorities( | 487 bool PictureLayerImpl::UpdateTilePriorities( |
495 const Occlusion& occlusion_in_content_space) { | 488 const Occlusion& occlusion_in_content_space) { |
496 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); | 489 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); |
497 | 490 |
498 double current_frame_time_in_seconds = | 491 double current_frame_time_in_seconds = |
499 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - | 492 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - |
500 base::TimeTicks()).InSecondsF(); | 493 base::TimeTicks()).InSecondsF(); |
501 gfx::Rect viewport_rect_in_layer_space = | 494 gfx::Rect viewport_rect_in_layer_space = |
502 GetViewportForTilePriorityInContentSpace(); | 495 GetViewportForTilePriorityInContentSpace(); |
503 | 496 |
504 // The tiling set can require tiles for activation any of the following | 497 // The tiling set can require tiles for activation any of the following |
(...skipping 11 matching lines...) Expand all Loading... |
516 bool can_require_tiles_for_activation = | 509 bool can_require_tiles_for_activation = |
517 !only_used_low_res_last_append_quads_ || RequiresHighResToDraw() || | 510 !only_used_low_res_last_append_quads_ || RequiresHighResToDraw() || |
518 !layer_tree_impl()->SmoothnessTakesPriority(); | 511 !layer_tree_impl()->SmoothnessTakesPriority(); |
519 | 512 |
520 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since | 513 // Pass |occlusion_in_content_space| for |occlusion_in_layer_space| since |
521 // they are the same space in picture layer, as contents scale is always 1. | 514 // they are the same space in picture layer, as contents scale is always 1. |
522 bool updated = tilings_->UpdateTilePriorities( | 515 bool updated = tilings_->UpdateTilePriorities( |
523 viewport_rect_in_layer_space, ideal_contents_scale_, | 516 viewport_rect_in_layer_space, ideal_contents_scale_, |
524 current_frame_time_in_seconds, occlusion_in_content_space, | 517 current_frame_time_in_seconds, occlusion_in_content_space, |
525 can_require_tiles_for_activation); | 518 can_require_tiles_for_activation); |
526 | 519 return updated; |
527 // TODO(vmpstr): See if this can be removed in favour of calling it from LTHI | |
528 if (updated) | |
529 layer_tree_impl()->DidModifyTilePriorities(); | |
530 } | 520 } |
531 | 521 |
532 gfx::Rect PictureLayerImpl::GetViewportForTilePriorityInContentSpace() const { | 522 gfx::Rect PictureLayerImpl::GetViewportForTilePriorityInContentSpace() const { |
533 // If visible_rect_for_tile_priority_ is empty or | 523 // If visible_rect_for_tile_priority_ is empty or |
534 // viewport_rect_for_tile_priority is set to be different from the device | 524 // viewport_rect_for_tile_priority is set to be different from the device |
535 // viewport, try to inverse project the viewport into layer space and use | 525 // viewport, try to inverse project the viewport into layer space and use |
536 // that. Otherwise just use visible_rect_for_tile_priority_ | 526 // that. Otherwise just use visible_rect_for_tile_priority_ |
537 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; | 527 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; |
538 gfx::Rect viewport_rect_for_tile_priority = | 528 gfx::Rect viewport_rect_for_tile_priority = |
539 layer_tree_impl()->ViewportRectForTilePriority(); | 529 layer_tree_impl()->ViewportRectForTilePriority(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 594 } |
605 | 595 |
606 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 596 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
607 if (layer_tree_impl()->IsActiveTree()) { | 597 if (layer_tree_impl()->IsActiveTree()) { |
608 gfx::RectF layer_damage_rect = | 598 gfx::RectF layer_damage_rect = |
609 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 599 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
610 AddDamageRect(layer_damage_rect); | 600 AddDamageRect(layer_damage_rect); |
611 } | 601 } |
612 } | 602 } |
613 | 603 |
614 void PictureLayerImpl::DidBecomeActive() { | |
615 LayerImpl::DidBecomeActive(); | |
616 // TODO(vmpstr): See if this can be removed in favour of calling it from LTHI | |
617 layer_tree_impl()->DidModifyTilePriorities(); | |
618 } | |
619 | |
620 void PictureLayerImpl::DidBeginTracing() { | 604 void PictureLayerImpl::DidBeginTracing() { |
621 raster_source_->DidBeginTracing(); | 605 raster_source_->DidBeginTracing(); |
622 } | 606 } |
623 | 607 |
624 void PictureLayerImpl::ReleaseResources() { | 608 void PictureLayerImpl::ReleaseResources() { |
625 // Recreate tilings with new settings, since some of those might change when | 609 // Recreate tilings with new settings, since some of those might change when |
626 // we release resources. If tilings_ is null, then leave it as null. | 610 // we release resources. If tilings_ is null, then leave it as null. |
627 if (tilings_) | 611 if (tilings_) |
628 tilings_ = CreatePictureLayerTilingSet(); | 612 tilings_ = CreatePictureLayerTilingSet(); |
629 ResetRasterScale(); | 613 ResetRasterScale(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 << "iter rect " << iter.geometry_rect().ToString() << " content rect " | 774 << "iter rect " << iter.geometry_rect().ToString() << " content rect " |
791 << content_rect.ToString(); | 775 << content_rect.ToString(); |
792 | 776 |
793 const TileDrawInfo& draw_info = iter->draw_info(); | 777 const TileDrawInfo& draw_info = iter->draw_info(); |
794 if (!draw_info.IsReadyToDraw() || | 778 if (!draw_info.IsReadyToDraw() || |
795 draw_info.mode() != TileDrawInfo::RESOURCE_MODE) { | 779 draw_info.mode() != TileDrawInfo::RESOURCE_MODE) { |
796 *resource_id = 0; | 780 *resource_id = 0; |
797 return; | 781 return; |
798 } | 782 } |
799 | 783 |
800 *resource_id = draw_info.get_resource_id(); | 784 *resource_id = draw_info.resource_id(); |
801 *resource_size = iter.texture_size(); | 785 *resource_size = draw_info.resource_size(); |
802 } | 786 } |
803 | 787 |
804 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { | 788 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { |
805 if (nearest_neighbor_ == nearest_neighbor) | 789 if (nearest_neighbor_ == nearest_neighbor) |
806 return; | 790 return; |
807 | 791 |
808 nearest_neighbor_ = nearest_neighbor; | 792 nearest_neighbor_ = nearest_neighbor; |
809 NoteLayerPropertyChanged(); | 793 NoteLayerPropertyChanged(); |
810 } | 794 } |
811 | 795 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 | 1309 |
1326 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | 1310 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { |
1327 if (!layer_tree_impl()->IsActiveTree()) | 1311 if (!layer_tree_impl()->IsActiveTree()) |
1328 return true; | 1312 return true; |
1329 | 1313 |
1330 return AllTilesRequiredAreReadyToDraw( | 1314 return AllTilesRequiredAreReadyToDraw( |
1331 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | 1315 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); |
1332 } | 1316 } |
1333 | 1317 |
1334 } // namespace cc | 1318 } // namespace cc |
OLD | NEW |