Home | History | Annotate | Download | only in test
      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_TEST_LAYER_TEST_COMMON_H_
      6 #define CC_TEST_LAYER_TEST_COMMON_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "cc/test/fake_layer_tree_host.h"
     11 #include "cc/test/mock_quad_culler.h"
     12 #include "cc/trees/layer_tree_host_impl.h"
     13 
     14 #define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test)                 \
     15   do {                                                                \
     16     EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
     17     code_to_test;                                                     \
     18     Mock::VerifyAndClearExpectations(layer_tree_host_.get());         \
     19   } while (false)
     20 
     21 #define EXPECT_SET_NEEDS_UPDATE(expect, code_to_test)                       \
     22   do {                                                                      \
     23     EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times((expect)); \
     24     code_to_test;                                                           \
     25     Mock::VerifyAndClearExpectations(layer_tree_host_.get());               \
     26   } while (false)
     27 
     28 namespace gfx { class Rect; }
     29 
     30 namespace cc {
     31 class LayerImpl;
     32 class OutputSurface;
     33 class QuadList;
     34 class RenderSurfaceImpl;
     35 class ResourceProvider;
     36 
     37 class LayerTestCommon {
     38  public:
     39   static const char* quad_string;
     40 
     41   static void VerifyQuadsExactlyCoverRect(const QuadList& quads,
     42                                           const gfx::Rect& rect);
     43 
     44   static void VerifyQuadsCoverRectWithOcclusion(
     45       const QuadList& quads,
     46       const gfx::Rect& rect,
     47       const gfx::Rect& occluded,
     48       size_t* partially_occluded_count);
     49 
     50   class LayerImplTest {
     51    public:
     52     LayerImplTest();
     53     ~LayerImplTest();
     54 
     55     template <typename T>
     56     T* AddChildToRoot() {
     57       scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2);
     58       T* ptr = layer.get();
     59       root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
     60       return ptr;
     61     }
     62 
     63     template <typename T, typename A>
     64     T* AddChildToRoot(const A& a) {
     65       scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2, a);
     66       T* ptr = layer.get();
     67       root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
     68       return ptr;
     69     }
     70 
     71     template <typename T, typename A, typename B, typename C, typename D>
     72     T* AddChildToRoot(const A& a, const B& b, const C& c, const D& d) {
     73       scoped_ptr<T> layer =
     74           T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d);
     75       T* ptr = layer.get();
     76       root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
     77       return ptr;
     78     }
     79 
     80     template <typename T,
     81               typename A,
     82               typename B,
     83               typename C,
     84               typename D,
     85               typename E>
     86     T* AddChildToRoot(const A& a,
     87                       const B& b,
     88                       const C& c,
     89                       const D& d,
     90                       const E& e) {
     91       scoped_ptr<T> layer =
     92           T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d, e);
     93       T* ptr = layer.get();
     94       root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
     95       return ptr;
     96     }
     97 
     98     void CalcDrawProps(const gfx::Size& viewport_size);
     99     void AppendQuadsWithOcclusion(LayerImpl* layer_impl,
    100                                   const gfx::Rect& occluded);
    101     void AppendQuadsForPassWithOcclusion(LayerImpl* layer_impl,
    102                                          const RenderPass::Id& id,
    103                                          const gfx::Rect& occluded);
    104     void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
    105                                          const gfx::Rect& occluded);
    106 
    107     OutputSurface* output_surface() const {
    108       return host_->host_impl()->output_surface();
    109     }
    110     ResourceProvider* resource_provider() const {
    111       return host_->host_impl()->resource_provider();
    112     }
    113     LayerImpl* root_layer() const { return root_layer_impl_.get(); }
    114     FakeLayerTreeHostImpl* host_impl() const { return host_->host_impl(); }
    115     Proxy* proxy() const { return host_->host_impl()->proxy(); }
    116     const QuadList& quad_list() const { return quad_culler_->quad_list(); }
    117 
    118    private:
    119     scoped_ptr<FakeLayerTreeHost> host_;
    120     scoped_ptr<LayerImpl> root_layer_impl_;
    121     scoped_ptr<RenderPass> render_pass_;
    122     MockOcclusionTracker<LayerImpl> occlusion_tracker_;
    123     scoped_ptr<MockQuadCuller> quad_culler_;
    124   };
    125 };
    126 
    127 }  // namespace cc
    128 
    129 #endif  // CC_TEST_LAYER_TEST_COMMON_H_
    130