| 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" |
| 11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
| 12 #include "cc/layers/layer_impl.h" | 12 #include "cc/layers/layer_impl.h" |
| 13 #include "cc/layers/render_surface.h" | 13 #include "cc/layers/render_surface.h" |
| 14 #include "cc/layers/render_surface_impl.h" | 14 #include "cc/layers/render_surface_impl.h" |
| 15 #include "ui/gfx/geometry/quad_f.h" | 15 #include "ui/gfx/geometry/quad_f.h" |
| 16 #include "ui/gfx/geometry/rect_conversions.h" | 16 #include "ui/gfx/geometry/rect_conversions.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 template <typename LayerType> | 20 template <typename LayerType> |
| 21 OcclusionTracker<LayerType>::OcclusionTracker( | 21 OcclusionTracker<LayerType>::OcclusionTracker( |
| 22 const gfx::Rect& screen_space_clip_rect) | 22 const gfx::Rect& screen_space_clip_rect) |
| 23 : screen_space_clip_rect_(screen_space_clip_rect), | 23 : screen_space_clip_rect_(screen_space_clip_rect) { |
| 24 occluding_screen_space_rects_(NULL), | 24 } |
| 25 non_occluding_screen_space_rects_(NULL) {} | |
| 26 | 25 |
| 27 template <typename LayerType> | 26 template <typename LayerType> |
| 28 OcclusionTracker<LayerType>::~OcclusionTracker() {} | 27 OcclusionTracker<LayerType>::~OcclusionTracker() { |
| 28 } |
| 29 | 29 |
| 30 template <typename LayerType> | 30 template <typename LayerType> |
| 31 Occlusion OcclusionTracker<LayerType>::GetCurrentOcclusionForLayer( | 31 Occlusion OcclusionTracker<LayerType>::GetCurrentOcclusionForLayer( |
| 32 const gfx::Transform& draw_transform) const { | 32 const gfx::Transform& draw_transform) const { |
| 33 DCHECK(!stack_.empty()); | 33 DCHECK(!stack_.empty()); |
| 34 const StackObject& back = stack_.back(); | 34 const StackObject& back = stack_.back(); |
| 35 return Occlusion(draw_transform, | 35 return Occlusion(draw_transform, |
| 36 back.occlusion_from_outside_target, | 36 back.occlusion_from_outside_target, |
| 37 back.occlusion_from_inside_target); | 37 back.occlusion_from_inside_target); |
| 38 } | 38 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 for (size_t i = 0; i < opaque_contents.GetRegionComplexity(); ++i) { | 459 for (size_t i = 0; i < opaque_contents.GetRegionComplexity(); ++i) { |
| 460 gfx::Rect transformed_rect = | 460 gfx::Rect transformed_rect = |
| 461 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform( | 461 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform( |
| 462 layer->draw_transform(), opaque_contents.GetRect(i)); | 462 layer->draw_transform(), opaque_contents.GetRect(i)); |
| 463 transformed_rect.Intersect(clip_rect_in_target); | 463 transformed_rect.Intersect(clip_rect_in_target); |
| 464 if (transformed_rect.width() < minimum_tracking_size_.width() && | 464 if (transformed_rect.width() < minimum_tracking_size_.width() && |
| 465 transformed_rect.height() < minimum_tracking_size_.height()) | 465 transformed_rect.height() < minimum_tracking_size_.height()) |
| 466 continue; | 466 continue; |
| 467 stack_.back().occlusion_from_inside_target.Union(transformed_rect); | 467 stack_.back().occlusion_from_inside_target.Union(transformed_rect); |
| 468 | |
| 469 if (!occluding_screen_space_rects_) | |
| 470 continue; | |
| 471 | |
| 472 // Save the occluding area in screen space for debug visualization. | |
| 473 bool clipped; | |
| 474 gfx::QuadF screen_space_quad = MathUtil::MapQuad( | |
| 475 layer->render_target()->render_surface()->screen_space_transform(), | |
| 476 gfx::QuadF(transformed_rect), &clipped); | |
| 477 // TODO(danakj): Store the quad in the debug info instead of the bounding | |
| 478 // box. | |
| 479 gfx::Rect screen_space_rect = | |
| 480 gfx::ToEnclosedRect(screen_space_quad.BoundingBox()); | |
| 481 occluding_screen_space_rects_->push_back(screen_space_rect); | |
| 482 } | |
| 483 | |
| 484 if (!non_occluding_screen_space_rects_) | |
| 485 return; | |
| 486 | |
| 487 Region non_opaque_contents(gfx::Rect(layer->content_bounds())); | |
| 488 non_opaque_contents.Subtract(opaque_contents); | |
| 489 | |
| 490 for (Region::Iterator non_opaque_content_rects(non_opaque_contents); | |
| 491 non_opaque_content_rects.has_rect(); | |
| 492 non_opaque_content_rects.next()) { | |
| 493 gfx::Rect transformed_rect = | |
| 494 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform( | |
| 495 layer->draw_transform(), non_opaque_content_rects.rect()); | |
| 496 transformed_rect.Intersect(clip_rect_in_target); | |
| 497 if (transformed_rect.IsEmpty()) | |
| 498 continue; | |
| 499 | |
| 500 bool clipped; | |
| 501 gfx::QuadF screen_space_quad = MathUtil::MapQuad( | |
| 502 layer->render_target()->render_surface()->screen_space_transform(), | |
| 503 gfx::QuadF(transformed_rect), | |
| 504 &clipped); | |
| 505 // TODO(danakj): Store the quad in the debug info instead of the bounding | |
| 506 // box. | |
| 507 gfx::Rect screen_space_rect = | |
| 508 gfx::ToEnclosedRect(screen_space_quad.BoundingBox()); | |
| 509 non_occluding_screen_space_rects_->push_back(screen_space_rect); | |
| 510 } | 468 } |
| 511 } | 469 } |
| 512 | 470 |
| 513 template <typename LayerType> | 471 template <typename LayerType> |
| 514 Region OcclusionTracker<LayerType>::ComputeVisibleRegionInScreen() const { | 472 Region OcclusionTracker<LayerType>::ComputeVisibleRegionInScreen() const { |
| 515 DCHECK(!stack_.back().target->parent()); | 473 DCHECK(!stack_.back().target->parent()); |
| 516 const SimpleEnclosedRegion& occluded = | 474 const SimpleEnclosedRegion& occluded = |
| 517 stack_.back().occlusion_from_inside_target; | 475 stack_.back().occlusion_from_inside_target; |
| 518 Region visible_region(screen_space_clip_rect_); | 476 Region visible_region(screen_space_clip_rect_); |
| 519 for (size_t i = 0; i < occluded.GetRegionComplexity(); ++i) | 477 for (size_t i = 0; i < occluded.GetRegionComplexity(); ++i) |
| 520 visible_region.Subtract(occluded.GetRect(i)); | 478 visible_region.Subtract(occluded.GetRect(i)); |
| 521 return visible_region; | 479 return visible_region; |
| 522 } | 480 } |
| 523 | 481 |
| 524 // Instantiate (and export) templates here for the linker. | 482 // Instantiate (and export) templates here for the linker. |
| 525 template class OcclusionTracker<Layer>; | 483 template class OcclusionTracker<Layer>; |
| 526 template class OcclusionTracker<LayerImpl>; | 484 template class OcclusionTracker<LayerImpl>; |
| 527 | 485 |
| 528 } // namespace cc | 486 } // namespace cc |
| OLD | NEW |