| 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 #ifndef CC_TREES_OCCLUSION_TRACKER_H_ | 5 #ifndef CC_TREES_OCCLUSION_TRACKER_H_ |
| 6 #define CC_TREES_OCCLUSION_TRACKER_H_ | 6 #define CC_TREES_OCCLUSION_TRACKER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/base/region.h" | 12 #include "cc/base/region.h" |
| 13 #include "cc/layers/layer_iterator.h" | 13 #include "cc/layers/layer_iterator.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 class OverdrawMetrics; | |
| 18 class LayerImpl; | 17 class LayerImpl; |
| 19 class RenderSurfaceImpl; | 18 class RenderSurfaceImpl; |
| 20 class Layer; | 19 class Layer; |
| 21 class RenderSurface; | 20 class RenderSurface; |
| 22 | 21 |
| 23 // This class is used to track occlusion of layers while traversing them in a | 22 // This class is used to track occlusion of layers while traversing them in a |
| 24 // front-to-back order. As each layer is visited, one of the methods in this | 23 // front-to-back order. As each layer is visited, one of the methods in this |
| 25 // class is called to notify it about the current target surface. Then, | 24 // class is called to notify it about the current target surface. Then, |
| 26 // occlusion in the content space of the current layer may be queried, via | 25 // occlusion in the content space of the current layer may be queried, via |
| 27 // methods such as Occluded() and UnoccludedContentRect(). If the current layer | 26 // methods such as Occluded() and UnoccludedContentRect(). If the current layer |
| 28 // owns a RenderSurfaceImpl, then occlusion on that RenderSurfaceImpl may also | 27 // owns a RenderSurfaceImpl, then occlusion on that RenderSurfaceImpl may also |
| 29 // be queried via surfaceOccluded() and surfaceUnoccludedContentRect(). Finally, | 28 // be queried via surfaceOccluded() and surfaceUnoccludedContentRect(). Finally, |
| 30 // once finished with the layer, occlusion behind the layer should be marked by | 29 // once finished with the layer, occlusion behind the layer should be marked by |
| 31 // calling MarkOccludedBehindLayer(). | 30 // calling MarkOccludedBehindLayer(). |
| 32 template <typename LayerType> | 31 template <typename LayerType> |
| 33 class CC_EXPORT OcclusionTracker { | 32 class CC_EXPORT OcclusionTracker { |
| 34 public: | 33 public: |
| 35 OcclusionTracker(const gfx::Rect& screen_space_clip_rect, | 34 explicit OcclusionTracker(const gfx::Rect& screen_space_clip_rect); |
| 36 bool record_metrics_for_frame); | |
| 37 ~OcclusionTracker(); | 35 ~OcclusionTracker(); |
| 38 | 36 |
| 39 // Called at the beginning of each step in the LayerIterator's front-to-back | 37 // Called at the beginning of each step in the LayerIterator's front-to-back |
| 40 // traversal. | 38 // traversal. |
| 41 void EnterLayer(const LayerIteratorPosition<LayerType>& layer_iterator); | 39 void EnterLayer(const LayerIteratorPosition<LayerType>& layer_iterator); |
| 42 // Called at the end of each step in the LayerIterator's front-to-back | 40 // Called at the end of each step in the LayerIterator's front-to-back |
| 43 // traversal. | 41 // traversal. |
| 44 void LeaveLayer(const LayerIteratorPosition<LayerType>& layer_iterator); | 42 void LeaveLayer(const LayerIteratorPosition<LayerType>& layer_iterator); |
| 45 | 43 |
| 46 // Returns true if the given rect in content space for a layer is fully | 44 // Returns true if the given rect in content space for a layer is fully |
| (...skipping 13 matching lines...) Expand all Loading... |
| 60 const gfx::Transform& draw_transform) const; | 58 const gfx::Transform& draw_transform) const; |
| 61 | 59 |
| 62 // Gives an unoccluded sub-rect of |content_rect| in the content space of the | 60 // Gives an unoccluded sub-rect of |content_rect| in the content space of the |
| 63 // render_target owned by the layer. Used when considering occlusion for a | 61 // render_target owned by the layer. Used when considering occlusion for a |
| 64 // contributing surface that is rendering into another target. | 62 // contributing surface that is rendering into another target. |
| 65 gfx::Rect UnoccludedContributingSurfaceContentRect( | 63 gfx::Rect UnoccludedContributingSurfaceContentRect( |
| 66 const LayerType* layer, | 64 const LayerType* layer, |
| 67 bool for_replica, | 65 bool for_replica, |
| 68 const gfx::Rect& content_rect) const; | 66 const gfx::Rect& content_rect) const; |
| 69 | 67 |
| 70 // Report operations for recording overdraw metrics. | |
| 71 OverdrawMetrics* overdraw_metrics() const { | |
| 72 return overdraw_metrics_.get(); | |
| 73 } | |
| 74 | |
| 75 // Gives the region of the screen that is not occluded by something opaque. | 68 // Gives the region of the screen that is not occluded by something opaque. |
| 76 Region ComputeVisibleRegionInScreen() const { | 69 Region ComputeVisibleRegionInScreen() const { |
| 77 DCHECK(!stack_.back().target->parent()); | 70 DCHECK(!stack_.back().target->parent()); |
| 78 return SubtractRegions(screen_space_clip_rect_, | 71 return SubtractRegions(screen_space_clip_rect_, |
| 79 stack_.back().occlusion_from_inside_target); | 72 stack_.back().occlusion_from_inside_target); |
| 80 } | 73 } |
| 81 | 74 |
| 82 void set_minimum_tracking_size(const gfx::Size& size) { | 75 void set_minimum_tracking_size(const gfx::Size& size) { |
| 83 minimum_tracking_size_ = size; | 76 minimum_tracking_size_ = size; |
| 84 } | 77 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // Called when visiting a layer representing a contributing surface. This | 125 // Called when visiting a layer representing a contributing surface. This |
| 133 // indicates that we are leaving our current surface, and entering the new | 126 // indicates that we are leaving our current surface, and entering the new |
| 134 // one. We then perform any operations required for merging results from the | 127 // one. We then perform any operations required for merging results from the |
| 135 // child subtree into its parent. | 128 // child subtree into its parent. |
| 136 void LeaveToRenderTarget(const LayerType* new_target); | 129 void LeaveToRenderTarget(const LayerType* new_target); |
| 137 | 130 |
| 138 // Add the layer's occlusion to the tracked state. | 131 // Add the layer's occlusion to the tracked state. |
| 139 void MarkOccludedBehindLayer(const LayerType* layer); | 132 void MarkOccludedBehindLayer(const LayerType* layer); |
| 140 | 133 |
| 141 gfx::Rect screen_space_clip_rect_; | 134 gfx::Rect screen_space_clip_rect_; |
| 142 scoped_ptr<class OverdrawMetrics> overdraw_metrics_; | |
| 143 gfx::Size minimum_tracking_size_; | 135 gfx::Size minimum_tracking_size_; |
| 144 | 136 |
| 145 // This is used for visualizing the occlusion tracking process. | 137 // This is used for visualizing the occlusion tracking process. |
| 146 std::vector<gfx::Rect>* occluding_screen_space_rects_; | 138 std::vector<gfx::Rect>* occluding_screen_space_rects_; |
| 147 std::vector<gfx::Rect>* non_occluding_screen_space_rects_; | 139 std::vector<gfx::Rect>* non_occluding_screen_space_rects_; |
| 148 | 140 |
| 149 DISALLOW_COPY_AND_ASSIGN(OcclusionTracker); | 141 DISALLOW_COPY_AND_ASSIGN(OcclusionTracker); |
| 150 }; | 142 }; |
| 151 | 143 |
| 152 #if !defined(COMPILER_MSVC) | 144 #if !defined(COMPILER_MSVC) |
| 153 extern template class OcclusionTracker<Layer>; | 145 extern template class OcclusionTracker<Layer>; |
| 154 extern template class OcclusionTracker<LayerImpl>; | 146 extern template class OcclusionTracker<LayerImpl>; |
| 155 #endif | 147 #endif |
| 156 | 148 |
| 157 } // namespace cc | 149 } // namespace cc |
| 158 | 150 |
| 159 #endif // CC_TREES_OCCLUSION_TRACKER_H_ | 151 #endif // CC_TREES_OCCLUSION_TRACKER_H_ |
| OLD | NEW |