OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_TREES_OCCLUSION_TRACKER_H_ | |
6 #define CC_TREES_OCCLUSION_TRACKER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "cc/base/cc_export.h" | |
12 #include "cc/base/simple_enclosed_region.h" | |
13 #include "cc/layers/layer_iterator.h" | |
14 #include "cc/trees/occlusion.h" | |
15 #include "ui/gfx/geometry/rect.h" | |
16 | |
17 namespace cc { | |
18 class LayerImpl; | |
19 class Region; | |
20 class RenderSurfaceImpl; | |
21 class Layer; | |
22 class RenderSurface; | |
23 | |
24 // This class is used to track occlusion of layers while traversing them in a | |
25 // front-to-back order. As each layer is visited, one of the methods in this | |
26 // class is called to notify it about the current target surface. Then, | |
27 // occlusion in the content space of the current layer may be queried, via | |
28 // Occlusion from GetCurrentOcclusionForLayer(). If the current layer owns a | |
29 // RenderSurfaceImpl, then occlusion on that RenderSurfaceImpl may also be | |
30 // queried via surfaceOccluded() and surfaceUnoccludedContentRect(). Finally, | |
31 // once finished with the layer, occlusion behind the layer should be marked by | |
32 // calling MarkOccludedBehindLayer(). | |
33 template <typename LayerType> | |
34 class CC_EXPORT OcclusionTracker { | |
35 public: | |
36 explicit OcclusionTracker(const gfx::Rect& screen_space_clip_rect); | |
37 ~OcclusionTracker(); | |
38 | |
39 // Return an occlusion that retains the current state of the tracker | |
40 // and can be used outside of a layer walk to check occlusion. | |
41 Occlusion GetCurrentOcclusionForLayer( | |
42 const gfx::Transform& draw_transform) const; | |
43 Occlusion GetCurrentOcclusionForContributingSurface( | |
44 const gfx::Transform& draw_transform) const; | |
45 | |
46 // Called at the beginning of each step in the LayerIterator's front-to-back | |
47 // traversal. | |
48 void EnterLayer(const LayerIteratorPosition<LayerType>& layer_iterator); | |
49 // Called at the end of each step in the LayerIterator's front-to-back | |
50 // traversal. | |
51 void LeaveLayer(const LayerIteratorPosition<LayerType>& layer_iterator); | |
52 | |
53 // Gives the region of the screen that is not occluded by something opaque. | |
54 Region ComputeVisibleRegionInScreen() const; | |
55 | |
56 void set_minimum_tracking_size(const gfx::Size& size) { | |
57 minimum_tracking_size_ = size; | |
58 } | |
59 | |
60 protected: | |
61 struct StackObject { | |
62 StackObject() : target(0) {} | |
63 explicit StackObject(const LayerType* target) : target(target) {} | |
64 const LayerType* target; | |
65 SimpleEnclosedRegion occlusion_from_outside_target; | |
66 SimpleEnclosedRegion occlusion_from_inside_target; | |
67 }; | |
68 | |
69 // The stack holds occluded regions for subtrees in the | |
70 // RenderSurfaceImpl-Layer tree, so that when we leave a subtree we may apply | |
71 // a mask to it, but not to the parts outside the subtree. | |
72 // - The first time we see a new subtree under a target, we add that target to | |
73 // the top of the stack. This can happen as a layer representing itself, or as | |
74 // a target surface. | |
75 // - When we visit a target surface, we apply its mask to its subtree, which | |
76 // is at the top of the stack. | |
77 // - When we visit a layer representing itself, we add its occlusion to the | |
78 // current subtree, which is at the top of the stack. | |
79 // - When we visit a layer representing a contributing surface, the current | |
80 // target will never be the top of the stack since we just came from the | |
81 // contributing surface. | |
82 // We merge the occlusion at the top of the stack with the new current | |
83 // subtree. This new target is pushed onto the stack if not already there. | |
84 std::vector<StackObject> stack_; | |
85 | |
86 private: | |
87 // Called when visiting a layer representing itself. If the target was not | |
88 // already current, then this indicates we have entered a new surface subtree. | |
89 void EnterRenderTarget(const LayerType* new_target); | |
90 | |
91 // Called when visiting a layer representing a target surface. This indicates | |
92 // we have visited all the layers within the surface, and we may perform any | |
93 // surface-wide operations. | |
94 void FinishedRenderTarget(const LayerType* finished_target); | |
95 | |
96 // Called when visiting a layer representing a contributing surface. This | |
97 // indicates that we are leaving our current surface, and entering the new | |
98 // one. We then perform any operations required for merging results from the | |
99 // child subtree into its parent. | |
100 void LeaveToRenderTarget(const LayerType* new_target); | |
101 | |
102 // Add the layer's occlusion to the tracked state. | |
103 void MarkOccludedBehindLayer(const LayerType* layer); | |
104 | |
105 gfx::Rect screen_space_clip_rect_; | |
106 gfx::Size minimum_tracking_size_; | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(OcclusionTracker); | |
109 }; | |
110 | |
111 #if !defined(COMPILER_MSVC) | |
112 extern template class OcclusionTracker<Layer>; | |
113 extern template class OcclusionTracker<LayerImpl>; | |
114 #endif | |
115 | |
116 } // namespace cc | |
117 | |
118 #endif // CC_TREES_OCCLUSION_TRACKER_H_ | |
OLD | NEW |