1 // Copyright 2014 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_TEST_MOCK_OCCLUSION_TRACKER_H_ 6 #define CC_TEST_MOCK_OCCLUSION_TRACKER_H_ 7 8 #include "cc/trees/occlusion_tracker.h" 9 10 namespace cc { 11 12 template <typename LayerType> 13 class MockOcclusionTracker : public OcclusionTracker<LayerType> { 14 // This class is used for testing only. It fakes just enough information to 15 // calculate unoccluded content rect and unoccluded contributing surface 16 // content rect. It calls the helper function of occlusion tracker to avoid 17 // DCHECKs since testing environment won't be set up properly to pass those. 18 public: 19 MockOcclusionTracker() 20 : OcclusionTracker<LayerType>(gfx::Rect(0, 0, 1000, 1000)) { 21 typename OcclusionTracker<LayerType>::StackObject stack_obj; 22 OcclusionTracker<LayerType>::stack_.push_back(stack_obj); 23 OcclusionTracker<LayerType>::stack_.push_back(stack_obj); 24 } 25 26 explicit MockOcclusionTracker(const gfx::Rect& screen_scissor_rect) 27 : OcclusionTracker<LayerType>(screen_scissor_rect) { 28 typename OcclusionTracker<LayerType>::StackObject stack_obj; 29 OcclusionTracker<LayerType>::stack_.push_back(stack_obj); 30 OcclusionTracker<LayerType>::stack_.push_back(stack_obj); 31 } 32 33 void set_occluded_target_rect(const gfx::Rect& occluded) { 34 OcclusionTracker<LayerType>::stack_.back().occlusion_from_inside_target = 35 occluded; 36 } 37 38 void set_occluded_target_rect_for_contributing_surface( 39 const gfx::Rect& occluded) { 40 OcclusionTracker< 41 LayerType>::stack_[OcclusionTracker<LayerType>::stack_.size() - 2] 42 .occlusion_from_inside_target = occluded; 43 } 44 45 private: 46 DISALLOW_COPY_AND_ASSIGN(MockOcclusionTracker); 47 }; 48 49 } // namespace cc 50 51 #endif // CC_TEST_MOCK_OCCLUSION_TRACKER_H_ 52