summaryrefslogtreecommitdiffstats
path: root/cc/test/mock_occlusion_tracker.h
blob: 69e2e5a8b1063c27f2deec3e4c862f11305935d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TEST_MOCK_OCCLUSION_TRACKER_H_
#define CC_TEST_MOCK_OCCLUSION_TRACKER_H_

#include "cc/trees/occlusion_tracker.h"

namespace cc {

template <typename LayerType>
class MockOcclusionTracker : public OcclusionTracker<LayerType> {
  // This class is used for testing only. It fakes just enough information to
  // calculate unoccluded content rect and unoccluded contributing surface
  // content rect. It calls the helper function of occlusion tracker to avoid
  // DCHECKs since testing environment won't be set up properly to pass those.
 public:
  explicit MockOcclusionTracker(const gfx::Rect& screen_scissor_rect)
      : OcclusionTracker<LayerType>(screen_scissor_rect) {
    typename OcclusionTracker<LayerType>::StackObject stack_obj;
    OcclusionTracker<LayerType>::stack_.push_back(stack_obj);
    OcclusionTracker<LayerType>::stack_.push_back(stack_obj);
  }

  void set_occluded_target_rect(const gfx::Rect& occluded) {
    OcclusionTracker<LayerType>::stack_.back().occlusion_from_inside_target =
        occluded;
  }

  void set_occluded_target_rect_for_contributing_surface(
      const gfx::Rect& occluded) {
    OcclusionTracker<
        LayerType>::stack_[OcclusionTracker<LayerType>::stack_.size() - 2]
        .occlusion_from_inside_target = occluded;
  }
};

}  // namespace cc

#endif  // CC_TEST_MOCK_OCCLUSION_TRACKER_H_