Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / cc / trees / occlusion_tracker.h
blob9a9294c779d2f4683049f77304d9ad6a2714f5ec
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.
5 #ifndef CC_TREES_OCCLUSION_TRACKER_H_
6 #define CC_TREES_OCCLUSION_TRACKER_H_
8 #include <vector>
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"
17 namespace cc {
18 class LayerImpl;
19 class Region;
20 class RenderSurfaceImpl;
22 // This class is used to track occlusion of layers while traversing them in a
23 // front-to-back order. As each layer is visited, one of the methods in this
24 // class is called to notify it about the current target surface. Then,
25 // occlusion in the content space of the current layer may be queried, via
26 // Occlusion from GetCurrentOcclusionForLayer(). If the current layer owns a
27 // RenderSurfaceImpl, then occlusion on that RenderSurfaceImpl may also be
28 // queried via surfaceOccluded() and surfaceUnoccludedContentRect(). Finally,
29 // once finished with the layer, occlusion behind the layer should be marked by
30 // calling MarkOccludedBehindLayer().
31 class CC_EXPORT OcclusionTracker {
32 public:
33 explicit OcclusionTracker(const gfx::Rect& screen_space_clip_rect);
34 ~OcclusionTracker();
36 // Return an occlusion that retains the current state of the tracker
37 // and can be used outside of a layer walk to check occlusion.
38 Occlusion GetCurrentOcclusionForLayer(
39 const gfx::Transform& draw_transform) const;
40 Occlusion GetCurrentOcclusionForContributingSurface(
41 const gfx::Transform& draw_transform) const;
43 // Called at the beginning of each step in the LayerIterator's front-to-back
44 // traversal.
45 void EnterLayer(const LayerIteratorPosition& layer_iterator);
46 // Called at the end of each step in the LayerIterator's front-to-back
47 // traversal.
48 void LeaveLayer(const LayerIteratorPosition& layer_iterator);
50 // Gives the region of the screen that is not occluded by something opaque.
51 Region ComputeVisibleRegionInScreen() const;
53 void set_minimum_tracking_size(const gfx::Size& size) {
54 minimum_tracking_size_ = size;
57 protected:
58 struct StackObject {
59 StackObject() : target(0) {}
60 explicit StackObject(const LayerImpl* target) : target(target) {}
61 const LayerImpl* target;
62 SimpleEnclosedRegion occlusion_from_outside_target;
63 SimpleEnclosedRegion occlusion_from_inside_target;
66 // The stack holds occluded regions for subtrees in the
67 // RenderSurfaceImpl-Layer tree, so that when we leave a subtree we may apply
68 // 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
70 // the top of the stack. This can happen as a layer representing itself, or as
71 // a target surface.
72 // - When we visit a target surface, we apply its mask to its subtree, which
73 // is at the top of the stack.
74 // - When we visit a layer representing itself, we add its occlusion to the
75 // current subtree, which is at the top of the stack.
76 // - When we visit a layer representing a contributing surface, the current
77 // target will never be the top of the stack since we just came from the
78 // contributing surface.
79 // We merge the occlusion at the top of the stack with the new current
80 // subtree. This new target is pushed onto the stack if not already there.
81 std::vector<StackObject> stack_;
83 private:
84 // Called when visiting a layer representing itself. If the target was not
85 // already current, then this indicates we have entered a new surface subtree.
86 void EnterRenderTarget(const LayerImpl* new_target);
88 // Called when visiting a layer representing a target surface. This indicates
89 // we have visited all the layers within the surface, and we may perform any
90 // surface-wide operations.
91 void FinishedRenderTarget(const LayerImpl* finished_target);
93 // Called when visiting a layer representing a contributing surface. This
94 // indicates that we are leaving our current surface, and entering the new
95 // one. We then perform any operations required for merging results from the
96 // child subtree into its parent.
97 void LeaveToRenderTarget(const LayerImpl* new_target);
99 // Add the layer's occlusion to the tracked state.
100 void MarkOccludedBehindLayer(const LayerImpl* layer);
102 gfx::Rect screen_space_clip_rect_;
103 gfx::Size minimum_tracking_size_;
105 DISALLOW_COPY_AND_ASSIGN(OcclusionTracker);
108 } // namespace cc
110 #endif // CC_TREES_OCCLUSION_TRACKER_H_