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/debug/overdraw_metrics.h" | 10 #include "cc/debug/overdraw_metrics.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/quad_f.h" | 15 #include "ui/gfx/quad_f.h" |
16 #include "ui/gfx/rect_conversions.h" | 16 #include "ui/gfx/rect_conversions.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 template <typename LayerType, typename RenderSurfaceType> | 20 template <typename LayerType, typename RenderSurfaceType> |
21 OcclusionTrackerBase<LayerType, RenderSurfaceType>::OcclusionTrackerBase( | 21 OcclusionTrackerBase<LayerType, RenderSurfaceType>::OcclusionTrackerBase( |
22 gfx::Rect screen_space_clip_rect, bool record_metrics_for_frame) | 22 gfx::Rect screen_space_clip_rect, bool record_metrics_for_frame) |
23 : screen_space_clip_rect_(screen_space_clip_rect), | 23 : screen_space_clip_rect_(screen_space_clip_rect), |
24 overdraw_metrics_(OverdrawMetrics::Create(record_metrics_for_frame)), | 24 overdraw_metrics_(OverdrawMetrics::Create(record_metrics_for_frame)), |
25 prevent_occlusion_(false), | |
26 occluding_screen_space_rects_(NULL), | 25 occluding_screen_space_rects_(NULL), |
27 non_occluding_screen_space_rects_(NULL) {} | 26 non_occluding_screen_space_rects_(NULL) {} |
28 | 27 |
29 template <typename LayerType, typename RenderSurfaceType> | 28 template <typename LayerType, typename RenderSurfaceType> |
30 OcclusionTrackerBase<LayerType, RenderSurfaceType>::~OcclusionTrackerBase() {} | 29 OcclusionTrackerBase<LayerType, RenderSurfaceType>::~OcclusionTrackerBase() {} |
31 | 30 |
32 template <typename LayerType, typename RenderSurfaceType> | 31 template <typename LayerType, typename RenderSurfaceType> |
33 void OcclusionTrackerBase<LayerType, RenderSurfaceType>::EnterLayer( | 32 void OcclusionTrackerBase<LayerType, RenderSurfaceType>::EnterLayer( |
34 const LayerIteratorPosition<LayerType>& layer_iterator, | 33 const LayerIteratorPosition<LayerType>& layer_iterator) { |
35 bool prevent_occlusion) { | |
36 LayerType* render_target = layer_iterator.target_render_surface_layer; | 34 LayerType* render_target = layer_iterator.target_render_surface_layer; |
37 | 35 |
38 if (layer_iterator.represents_itself) | 36 if (layer_iterator.represents_itself) |
39 EnterRenderTarget(render_target); | 37 EnterRenderTarget(render_target); |
40 else if (layer_iterator.represents_target_render_surface) | 38 else if (layer_iterator.represents_target_render_surface) |
41 FinishedRenderTarget(render_target); | 39 FinishedRenderTarget(render_target); |
42 | |
43 prevent_occlusion_ = prevent_occlusion; | |
44 } | 40 } |
45 | 41 |
46 template <typename LayerType, typename RenderSurfaceType> | 42 template <typename LayerType, typename RenderSurfaceType> |
47 void OcclusionTrackerBase<LayerType, RenderSurfaceType>::LeaveLayer( | 43 void OcclusionTrackerBase<LayerType, RenderSurfaceType>::LeaveLayer( |
48 const LayerIteratorPosition<LayerType>& layer_iterator) { | 44 const LayerIteratorPosition<LayerType>& layer_iterator) { |
49 LayerType* render_target = layer_iterator.target_render_surface_layer; | 45 LayerType* render_target = layer_iterator.target_render_surface_layer; |
50 | 46 |
51 if (layer_iterator.represents_itself) | 47 if (layer_iterator.represents_itself) |
52 MarkOccludedBehindLayer(layer_iterator.current_layer); | 48 MarkOccludedBehindLayer(layer_iterator.current_layer); |
53 // TODO(danakj): This should be done when entering the contributing surface, | 49 // TODO(danakj): This should be done when entering the contributing surface, |
54 // but in a way that the surface's own occlusion won't occlude itself. | 50 // but in a way that the surface's own occlusion won't occlude itself. |
55 else if (layer_iterator.represents_contributing_render_surface) | 51 else if (layer_iterator.represents_contributing_render_surface) |
56 LeaveToRenderTarget(render_target); | 52 LeaveToRenderTarget(render_target); |
57 | |
58 prevent_occlusion_ = false; | |
59 } | 53 } |
60 | 54 |
61 template <typename RenderSurfaceType> | 55 template <typename RenderSurfaceType> |
62 static gfx::Rect ScreenSpaceClipRectInTargetSurface( | 56 static gfx::Rect ScreenSpaceClipRectInTargetSurface( |
63 const RenderSurfaceType* target_surface, gfx::Rect screen_space_clip_rect) { | 57 const RenderSurfaceType* target_surface, gfx::Rect screen_space_clip_rect) { |
64 gfx::Transform inverse_screen_space_transform( | 58 gfx::Transform inverse_screen_space_transform( |
65 gfx::Transform::kSkipInitialization); | 59 gfx::Transform::kSkipInitialization); |
66 if (!target_surface->screen_space_transform().GetInverse( | 60 if (!target_surface->screen_space_transform().GetInverse( |
67 &inverse_screen_space_transform)) | 61 &inverse_screen_space_transform)) |
68 return target_surface->content_rect(); | 62 return target_surface->content_rect(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 non_occluding_screen_space_rects_->push_back(screen_space_rect); | 490 non_occluding_screen_space_rects_->push_back(screen_space_rect); |
497 } | 491 } |
498 } | 492 } |
499 | 493 |
500 template <typename LayerType, typename RenderSurfaceType> | 494 template <typename LayerType, typename RenderSurfaceType> |
501 bool OcclusionTrackerBase<LayerType, RenderSurfaceType>::Occluded( | 495 bool OcclusionTrackerBase<LayerType, RenderSurfaceType>::Occluded( |
502 const LayerType* render_target, | 496 const LayerType* render_target, |
503 gfx::Rect content_rect, | 497 gfx::Rect content_rect, |
504 const gfx::Transform& draw_transform, | 498 const gfx::Transform& draw_transform, |
505 bool impl_draw_transform_is_unknown) const { | 499 bool impl_draw_transform_is_unknown) const { |
506 if (prevent_occlusion_) | |
507 return false; | |
508 | |
509 DCHECK(!stack_.empty()); | 500 DCHECK(!stack_.empty()); |
510 if (stack_.empty()) | 501 if (stack_.empty()) |
511 return false; | 502 return false; |
512 if (content_rect.IsEmpty()) | 503 if (content_rect.IsEmpty()) |
513 return true; | 504 return true; |
514 if (impl_draw_transform_is_unknown) | 505 if (impl_draw_transform_is_unknown) |
515 return false; | 506 return false; |
516 | 507 |
517 // For tests with no render target. | 508 // For tests with no render target. |
518 if (!render_target) | 509 if (!render_target) |
(...skipping 29 matching lines...) Expand all Loading... |
548 return unoccluded_rect_in_target_surface.IsEmpty(); | 539 return unoccluded_rect_in_target_surface.IsEmpty(); |
549 } | 540 } |
550 | 541 |
551 template <typename LayerType, typename RenderSurfaceType> | 542 template <typename LayerType, typename RenderSurfaceType> |
552 gfx::Rect OcclusionTrackerBase<LayerType, RenderSurfaceType>:: | 543 gfx::Rect OcclusionTrackerBase<LayerType, RenderSurfaceType>:: |
553 UnoccludedContentRect( | 544 UnoccludedContentRect( |
554 const LayerType* render_target, | 545 const LayerType* render_target, |
555 gfx::Rect content_rect, | 546 gfx::Rect content_rect, |
556 const gfx::Transform& draw_transform, | 547 const gfx::Transform& draw_transform, |
557 bool impl_draw_transform_is_unknown) const { | 548 bool impl_draw_transform_is_unknown) const { |
558 if (prevent_occlusion_) | |
559 return content_rect; | |
560 | |
561 DCHECK(!stack_.empty()); | 549 DCHECK(!stack_.empty()); |
562 if (stack_.empty()) | 550 if (stack_.empty()) |
563 return content_rect; | 551 return content_rect; |
564 if (content_rect.IsEmpty()) | 552 if (content_rect.IsEmpty()) |
565 return content_rect; | 553 return content_rect; |
566 if (impl_draw_transform_is_unknown) | 554 if (impl_draw_transform_is_unknown) |
567 return content_rect; | 555 return content_rect; |
568 | 556 |
569 // For tests with no render target. | 557 // For tests with no render target. |
570 if (!render_target) | 558 if (!render_target) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 // The layer is a contributing render_target so it should have a surface. | 600 // The layer is a contributing render_target so it should have a surface. |
613 DCHECK(layer->render_surface()); | 601 DCHECK(layer->render_surface()); |
614 // The layer is a contributing render_target so its target should be itself. | 602 // The layer is a contributing render_target so its target should be itself. |
615 DCHECK_EQ(layer->render_target(), layer); | 603 DCHECK_EQ(layer->render_target(), layer); |
616 // The layer should not be the root, else what is is contributing to? | 604 // The layer should not be the root, else what is is contributing to? |
617 DCHECK(layer->parent()); | 605 DCHECK(layer->parent()); |
618 // This should be called while the layer is still considered the current | 606 // This should be called while the layer is still considered the current |
619 // target in the occlusion tracker. | 607 // target in the occlusion tracker. |
620 DCHECK_EQ(layer, stack_.back().target); | 608 DCHECK_EQ(layer, stack_.back().target); |
621 | 609 |
622 if (prevent_occlusion_) | |
623 return content_rect; | |
624 | |
625 if (content_rect.IsEmpty()) | 610 if (content_rect.IsEmpty()) |
626 return content_rect; | 611 return content_rect; |
627 | 612 |
628 const RenderSurfaceType* surface = layer->render_surface(); | 613 const RenderSurfaceType* surface = layer->render_surface(); |
629 const LayerType* contributing_surface_render_target = | 614 const LayerType* contributing_surface_render_target = |
630 layer->parent()->render_target(); | 615 layer->parent()->render_target(); |
631 | 616 |
632 if (!SurfaceTransformsToTargetKnown(surface)) | 617 if (!SurfaceTransformsToTargetKnown(surface)) |
633 return content_rect; | 618 return content_rect; |
634 | 619 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 unoccluded_rect.Intersect(content_rect); | 660 unoccluded_rect.Intersect(content_rect); |
676 | 661 |
677 return unoccluded_rect; | 662 return unoccluded_rect; |
678 } | 663 } |
679 | 664 |
680 // Instantiate (and export) templates here for the linker. | 665 // Instantiate (and export) templates here for the linker. |
681 template class OcclusionTrackerBase<Layer, RenderSurface>; | 666 template class OcclusionTrackerBase<Layer, RenderSurface>; |
682 template class OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>; | 667 template class OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>; |
683 | 668 |
684 } // namespace cc | 669 } // namespace cc |
OLD | NEW |