| 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/trees/occlusion_tracker.h" | 5 #include "cc/trees/occlusion_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 &clipped); | 486 &clipped); |
| 487 // TODO(danakj): Store the quad in the debug info instead of the bounding | 487 // TODO(danakj): Store the quad in the debug info instead of the bounding |
| 488 // box. | 488 // box. |
| 489 gfx::Rect screen_space_rect = | 489 gfx::Rect screen_space_rect = |
| 490 gfx::ToEnclosedRect(screen_space_quad.BoundingBox()); | 490 gfx::ToEnclosedRect(screen_space_quad.BoundingBox()); |
| 491 non_occluding_screen_space_rects_->push_back(screen_space_rect); | 491 non_occluding_screen_space_rects_->push_back(screen_space_rect); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 | 494 |
| 495 template <typename LayerType> | 495 template <typename LayerType> |
| 496 gfx::Rect OcclusionTracker<LayerType>::UnoccludedContentRect( | |
| 497 const gfx::Rect& content_rect, | |
| 498 const gfx::Transform& draw_transform) const { | |
| 499 DCHECK(!stack_.empty()); | |
| 500 if (content_rect.IsEmpty()) | |
| 501 return content_rect; | |
| 502 | |
| 503 const StackObject& back = stack_.back(); | |
| 504 if (back.occlusion_from_inside_target.IsEmpty() && | |
| 505 back.occlusion_from_outside_target.IsEmpty()) { | |
| 506 return content_rect; | |
| 507 } | |
| 508 | |
| 509 gfx::Transform inverse_draw_transform(gfx::Transform::kSkipInitialization); | |
| 510 bool ok = draw_transform.GetInverse(&inverse_draw_transform); | |
| 511 DCHECK(ok); | |
| 512 | |
| 513 // Take the ToEnclosingRect at each step, as we want to contain any unoccluded | |
| 514 // partial pixels in the resulting Rect. | |
| 515 gfx::Rect unoccluded_rect_in_target_surface = | |
| 516 MathUtil::MapEnclosingClippedRect(draw_transform, content_rect); | |
| 517 DCHECK_LE(back.occlusion_from_inside_target.GetRegionComplexity(), 1u); | |
| 518 DCHECK_LE(back.occlusion_from_outside_target.GetRegionComplexity(), 1u); | |
| 519 // These subtract operations are more lossy than if we did both operations at | |
| 520 // once. | |
| 521 unoccluded_rect_in_target_surface.Subtract( | |
| 522 back.occlusion_from_inside_target.bounds()); | |
| 523 unoccluded_rect_in_target_surface.Subtract( | |
| 524 back.occlusion_from_outside_target.bounds()); | |
| 525 | |
| 526 if (unoccluded_rect_in_target_surface.IsEmpty()) | |
| 527 return gfx::Rect(); | |
| 528 | |
| 529 gfx::Rect unoccluded_rect = MathUtil::ProjectEnclosingClippedRect( | |
| 530 inverse_draw_transform, unoccluded_rect_in_target_surface); | |
| 531 unoccluded_rect.Intersect(content_rect); | |
| 532 | |
| 533 return unoccluded_rect; | |
| 534 } | |
| 535 | |
| 536 template <typename LayerType> | |
| 537 gfx::Rect OcclusionTracker<LayerType>::UnoccludedContributingSurfaceContentRect( | 496 gfx::Rect OcclusionTracker<LayerType>::UnoccludedContributingSurfaceContentRect( |
| 538 const gfx::Rect& content_rect, | 497 const gfx::Rect& content_rect, |
| 539 const gfx::Transform& draw_transform) const { | 498 const gfx::Transform& draw_transform) const { |
| 540 if (content_rect.IsEmpty()) | 499 if (content_rect.IsEmpty()) |
| 541 return content_rect; | 500 return content_rect; |
| 542 | 501 |
| 543 // A contributing surface doesn't get occluded by things inside its own | 502 // A contributing surface doesn't get occluded by things inside its own |
| 544 // surface, so only things outside the surface can occlude it. That occlusion | 503 // surface, so only things outside the surface can occlude it. That occlusion |
| 545 // is found just below the top of the stack (if it exists). | 504 // is found just below the top of the stack (if it exists). |
| 546 bool has_occlusion = stack_.size() > 1; | 505 bool has_occlusion = stack_.size() > 1; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 for (size_t i = 0; i < occluded.GetRegionComplexity(); ++i) | 548 for (size_t i = 0; i < occluded.GetRegionComplexity(); ++i) |
| 590 visible_region.Subtract(occluded.GetRect(i)); | 549 visible_region.Subtract(occluded.GetRect(i)); |
| 591 return visible_region; | 550 return visible_region; |
| 592 } | 551 } |
| 593 | 552 |
| 594 // Instantiate (and export) templates here for the linker. | 553 // Instantiate (and export) templates here for the linker. |
| 595 template class OcclusionTracker<Layer>; | 554 template class OcclusionTracker<Layer>; |
| 596 template class OcclusionTracker<LayerImpl>; | 555 template class OcclusionTracker<LayerImpl>; |
| 597 | 556 |
| 598 } // namespace cc | 557 } // namespace cc |
| OLD | NEW |