Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: cc/occlusion_tracker.h

Issue 11583005: cc: Make occlusion tracker always work in target space. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_OCCLUSION_TRACKER_H_ 5 #ifndef CC_OCCLUSION_TRACKER_H_
6 #define CC_OCCLUSION_TRACKER_H_ 6 #define CC_OCCLUSION_TRACKER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "cc/cc_export.h" 9 #include "cc/cc_export.h"
10 #include "cc/layer_iterator.h" 10 #include "cc/layer_iterator.h"
11 #include "cc/region.h" 11 #include "cc/region.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 13
14 namespace cc { 14 namespace cc {
15 class OverdrawMetrics; 15 class OverdrawMetrics;
16 class LayerImpl; 16 class LayerImpl;
17 class RenderSurfaceImpl; 17 class RenderSurfaceImpl;
18 class Layer; 18 class Layer;
19 class RenderSurface; 19 class RenderSurface;
20 20
21 // This class is used to track occlusion of layers while traversing them in a fr ont-to-back order. As each layer is visited, one of the 21 // This class is used to track occlusion of layers while traversing them in a fr ont-to-back order. As each layer is visited, one of the
22 // methods in this class is called to notify it about the current target surface . 22 // methods in this class is called to notify it about the current target surface .
23 // Then, occlusion in the content space of the current layer may be queried, via methods such as occluded() and unoccludedContentRect(). 23 // Then, occlusion in the content space of the current layer may be queried, via methods such as occluded() and unoccludedContentRect().
24 // If the current layer owns a RenderSurfaceImpl, then occlusion on that RenderS urfaceImpl may also be queried via surfaceOccluded() and surfaceUnoccludedConten tRect(). 24 // If the current layer owns a RenderSurfaceImpl, then occlusion on that RenderS urfaceImpl may also be queried via surfaceOccluded() and surfaceUnoccludedConten tRect().
25 // Finally, once finished with the layer, occlusion behind the layer should be m arked by calling markOccludedBehindLayer(). 25 // Finally, once finished with the layer, occlusion behind the layer should be m arked by calling markOccludedBehindLayer().
26 template<typename LayerType, typename RenderSurfaceType> 26 template<typename LayerType, typename RenderSurfaceType>
27 class CC_EXPORT OcclusionTrackerBase { 27 class CC_EXPORT OcclusionTrackerBase {
28 public: 28 public:
29 OcclusionTrackerBase(gfx::Rect rootTargetRect, bool recordMetricsForFrame); 29 OcclusionTrackerBase(gfx::Rect screenSpaceClipRect, bool recordMetricsForFra me);
30 ~OcclusionTrackerBase(); 30 ~OcclusionTrackerBase();
31 31
32 // Called at the beginning of each step in the LayerIterator's front-to-back traversal. 32 // Called at the beginning of each step in the LayerIterator's front-to-back traversal.
33 void enterLayer(const LayerIteratorPosition<LayerType>&); 33 void enterLayer(const LayerIteratorPosition<LayerType>&);
34 // Called at the end of each step in the LayerIterator's front-to-back trave rsal. 34 // Called at the end of each step in the LayerIterator's front-to-back trave rsal.
35 void leaveLayer(const LayerIteratorPosition<LayerType>&); 35 void leaveLayer(const LayerIteratorPosition<LayerType>&);
36 36
37 // Returns true if the given rect in content space for a layer is fully occl uded in either screen space or the layer's target surface. |renderTarget| is th e contributing layer's render target, and |drawTransform|, |transformsToTargetKn own| and |clippedRectInTarget| are relative to that. 37 // Returns true if the given rect in content space for a layer is fully occl uded in either screen space or the layer's target surface. |renderTarget| is th e contributing layer's render target, and |drawTransform|, |transformsToTargetKn own| and |clippedRectInTarget| are relative to that.
38 bool occluded(const LayerType* renderTarget, const gfx::Rect& contentRect, c onst gfx::Transform& drawTransform, bool implDrawTransformIsUnknown, const gfx:: Rect& clippedRectInTarget, bool* hasOcclusionFromOutsideTargetSurface = 0) const ; 38 bool occluded(const LayerType* renderTarget, const gfx::Rect& contentRect, c onst gfx::Transform& drawTransform, bool implDrawTransformIsUnknown, const gfx:: Rect& clippedRectInTarget, bool* hasOcclusionFromOutsideTargetSurface = 0) const ;
39 // Gives an unoccluded sub-rect of |contentRect| in the content space of a l ayer. Used when considering occlusion for a layer that paints/draws something. | renderTarget| is the contributing layer's render target, and |drawTransform|, |t ransformsToTargetKnown| and |clippedRectInTarget| are relative to that. 39 // Gives an unoccluded sub-rect of |contentRect| in the content space of a l ayer. Used when considering occlusion for a layer that paints/draws something. | renderTarget| is the contributing layer's render target, and |drawTransform|, |t ransformsToTargetKnown| and |clippedRectInTarget| are relative to that.
40 gfx::Rect unoccludedContentRect(const LayerType* renderTarget, const gfx::Re ct& contentRect, const gfx::Transform& drawTransform, bool implDrawTransformIsUn known, const gfx::Rect& clippedRectInTarget, bool* hasOcclusionFromOutsideTarget Surface = 0) const; 40 gfx::Rect unoccludedContentRect(const LayerType* renderTarget, const gfx::Re ct& contentRect, const gfx::Transform& drawTransform, bool implDrawTransformIsUn known, const gfx::Rect& clippedRectInTarget, bool* hasOcclusionFromOutsideTarget Surface = 0) const;
41 41
42 // Gives an unoccluded sub-rect of |contentRect| in the content space of the renderTarget owned by the layer. 42 // Gives an unoccluded sub-rect of |contentRect| in the content space of the renderTarget owned by the layer.
43 // Used when considering occlusion for a contributing surface that is render ing into another target. 43 // Used when considering occlusion for a contributing surface that is render ing into another target.
44 gfx::Rect unoccludedContributingSurfaceContentRect(const LayerType*, bool fo rReplica, const gfx::Rect& contentRect, bool* hasOcclusionFromOutsideTargetSurfa ce = 0) const; 44 gfx::Rect unoccludedContributingSurfaceContentRect(const LayerType*, bool fo rReplica, const gfx::Rect& contentRect, bool* hasOcclusionFromOutsideTargetSurfa ce = 0) const;
45 45
46 // Report operations for recording overdraw metrics. 46 // Report operations for recording overdraw metrics.
47 OverdrawMetrics& overdrawMetrics() const { return *m_overdrawMetrics.get(); } 47 OverdrawMetrics& overdrawMetrics() const { return *m_overdrawMetrics.get(); }
48 48
49 // Gives the region of the screen that is not occluded by something opaque. 49 // Gives the region of the screen that is not occluded by something opaque.
50 Region computeVisibleRegionInScreen() const { return SubtractRegions(m_rootT argetRect, m_stack.back().occlusionInScreen); } 50 Region computeVisibleRegionInScreen() const {
51 DCHECK(!m_stack.back().target->parent());
52 return SubtractRegions(m_screenSpaceClipRect, m_stack.back().occlusionFr omInsideTarget);
53 }
51 54
52 void setMinimumTrackingSize(const gfx::Size& size) { m_minimumTrackingSize = size; } 55 void setMinimumTrackingSize(const gfx::Size& size) { m_minimumTrackingSize = size; }
53 56
54 // The following is used for visualization purposes. 57 // The following is used for visualization purposes.
55 void setOccludingScreenSpaceRectsContainer(std::vector<gfx::Rect>* rects) { m_occludingScreenSpaceRects = rects; } 58 void setOccludingScreenSpaceRectsContainer(std::vector<gfx::Rect>* rects) { m_occludingScreenSpaceRects = rects; }
56 void setNonOccludingScreenSpaceRectsContainer(std::vector<gfx::Rect>* rects) { m_nonOccludingScreenSpaceRects = rects; } 59 void setNonOccludingScreenSpaceRectsContainer(std::vector<gfx::Rect>* rects) { m_nonOccludingScreenSpaceRects = rects; }
57 60
58 protected: 61 protected:
59 struct StackObject { 62 struct StackObject {
60 StackObject() : target(0) { } 63 StackObject() : target(0) { }
61 StackObject(const LayerType* target) : target(target) { } 64 StackObject(const LayerType* target) : target(target) { }
62 const LayerType* target; 65 const LayerType* target;
63 Region occlusionInScreen; 66 Region occlusionFromOutsideTarget;
64 Region occlusionInTarget; 67 Region occlusionFromInsideTarget;
65 }; 68 };
66 69
67 // The stack holds occluded regions for subtrees in the RenderSurfaceImpl-La yer tree, so that when we leave a subtree we may 70 // The stack holds occluded regions for subtrees in the RenderSurfaceImpl-La yer tree, so that when we leave a subtree we may
68 // apply a mask to it, but not to the parts outside the subtree. 71 // apply a mask to it, but not to the parts outside the subtree.
69 // - The first time we see a new subtree under a target, we add that target to the top of the stack. This can happen as a layer representing itself, or as a target surface. 72 // - The first time we see a new subtree under a target, we add that target to the top of the stack. This can happen as a layer representing itself, or as a target surface.
70 // - When we visit a target surface, we apply its mask to its subtree, which is at the top of the stack. 73 // - When we visit a target surface, we apply its mask to its subtree, which is at the top of the stack.
71 // - When we visit a layer representing itself, we add its occlusion to the current subtree, which is at the top of the stack. 74 // - When we visit a layer representing itself, we add its occlusion to the current subtree, which is at the top of the stack.
72 // - When we visit a layer representing a contributing surface, the current target will never be the top of the stack since we just came from the contributi ng surface. 75 // - When we visit a layer representing a contributing surface, the current target will never be the top of the stack since we just came from the contributi ng surface.
73 // We merge the occlusion at the top of the stack with the new current subtr ee. This new target is pushed onto the stack if not already there. 76 // We merge the occlusion at the top of the stack with the new current subtr ee. This new target is pushed onto the stack if not already there.
74 std::vector<StackObject> m_stack; 77 std::vector<StackObject> m_stack;
75 78
76 // Allow tests to override this. 79 // Allow tests to override this.
77 virtual gfx::Rect layerClipRectInTarget(const LayerType*) const; 80 virtual gfx::Rect layerClipRectInTarget(const LayerType*) const;
78 81
79 private: 82 private:
80 // Called when visiting a layer representing itself. If the target was not a lready current, then this indicates we have entered a new surface subtree. 83 // Called when visiting a layer representing itself. If the target was not a lready current, then this indicates we have entered a new surface subtree.
81 void enterRenderTarget(const LayerType* newTarget); 84 void enterRenderTarget(const LayerType* newTarget);
82 85
83 // Called when visiting a layer representing a target surface. This indicate s we have visited all the layers within the surface, and we may 86 // Called when visiting a layer representing a target surface. This indicate s we have visited all the layers within the surface, and we may
84 // perform any surface-wide operations. 87 // perform any surface-wide operations.
85 void finishedRenderTarget(const LayerType* finishedTarget); 88 void finishedRenderTarget(const LayerType* finishedTarget);
86 89
87 // Called when visiting a layer representing a contributing surface. This in dicates that we are leaving our current surface, and 90 // Called when visiting a layer representing a contributing surface. This in dicates that we are leaving our current surface, and
88 // entering the new one. We then perform any operations required for merging results from the child subtree into its parent. 91 // entering the new one. We then perform any operations required for merging results from the child subtree into its parent.
89 void leaveToRenderTarget(const LayerType* newTarget); 92 void leaveToRenderTarget(const LayerType* newTarget);
90 93
91 // Add the layer's occlusion to the tracked state. 94 // Add the layer's occlusion to the tracked state.
92 void markOccludedBehindLayer(const LayerType*); 95 void markOccludedBehindLayer(const LayerType*);
93 96
94 gfx::Rect m_rootTargetRect; 97 gfx::Rect m_screenSpaceClipRect;
95 scoped_ptr<OverdrawMetrics> m_overdrawMetrics; 98 scoped_ptr<OverdrawMetrics> m_overdrawMetrics;
96 gfx::Size m_minimumTrackingSize; 99 gfx::Size m_minimumTrackingSize;
97 100
98 // This is used for visualizing the occlusion tracking process. 101 // This is used for visualizing the occlusion tracking process.
99 std::vector<gfx::Rect>* m_occludingScreenSpaceRects; 102 std::vector<gfx::Rect>* m_occludingScreenSpaceRects;
100 std::vector<gfx::Rect>* m_nonOccludingScreenSpaceRects; 103 std::vector<gfx::Rect>* m_nonOccludingScreenSpaceRects;
101 104
102 DISALLOW_COPY_AND_ASSIGN(OcclusionTrackerBase); 105 DISALLOW_COPY_AND_ASSIGN(OcclusionTrackerBase);
103 }; 106 };
104 107
105 typedef OcclusionTrackerBase<Layer, RenderSurface> OcclusionTracker; 108 typedef OcclusionTrackerBase<Layer, RenderSurface> OcclusionTracker;
106 typedef OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl> OcclusionTrackerImpl; 109 typedef OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl> OcclusionTrackerImpl;
107 #if !defined(COMPILER_MSVC) 110 #if !defined(COMPILER_MSVC)
108 extern template class OcclusionTrackerBase<Layer, RenderSurface>; 111 extern template class OcclusionTrackerBase<Layer, RenderSurface>;
109 extern template class OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>; 112 extern template class OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>;
110 #endif 113 #endif
111 114
112 } // namespace cc 115 } // namespace cc
113 116
114 #endif // CC_OCCLUSION_TRACKER_H_ 117 #endif // CC_OCCLUSION_TRACKER_H_
OLDNEW
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/occlusion_tracker.cc » ('j') | cc/occlusion_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698