1 // Copyright 2013 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_FAKE_LAYER_TREE_HOST_H_ 6 #define CC_TEST_FAKE_LAYER_TREE_HOST_H_ 7 8 #include "cc/test/fake_impl_proxy.h" 9 #include "cc/test/fake_layer_tree_host_client.h" 10 #include "cc/test/fake_layer_tree_host_impl.h" 11 #include "cc/trees/layer_tree_host.h" 12 #include "cc/trees/layer_tree_impl.h" 13 #include "cc/trees/tree_synchronizer.h" 14 15 namespace cc { 16 17 class FakeLayerTreeHost : protected LayerTreeHost { 18 public: 19 static scoped_ptr<FakeLayerTreeHost> Create() { 20 static FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); 21 static LayerTreeSettings settings; 22 return make_scoped_ptr(new FakeLayerTreeHost(&client, settings)); 23 } 24 25 static scoped_ptr<FakeLayerTreeHost> Create( 26 const LayerTreeSettings& settings) { 27 static FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); 28 return make_scoped_ptr(new FakeLayerTreeHost(&client, settings)); 29 } 30 31 virtual ~FakeLayerTreeHost() {} 32 33 virtual void SetNeedsCommit() OVERRIDE {} 34 virtual void SetNeedsFullTreeSync() OVERRIDE {} 35 36 using LayerTreeHost::SetRootLayer; 37 using LayerTreeHost::root_layer; 38 39 LayerImpl* CommitAndCreateLayerImplTree() { 40 scoped_ptr<LayerImpl> old_root_layer_impl = 41 active_tree()->DetachLayerTree(); 42 43 scoped_ptr<LayerImpl> layer_impl = 44 TreeSynchronizer::SynchronizeTrees( 45 root_layer(), 46 old_root_layer_impl.Pass(), 47 active_tree()); 48 TreeSynchronizer::PushProperties(root_layer(), layer_impl.get()); 49 50 active_tree()->SetRootLayer(layer_impl.Pass()); 51 return active_tree()->root_layer(); 52 } 53 54 FakeLayerTreeHostImpl* host_impl() { return &host_impl_; } 55 LayerTreeImpl* active_tree() { return host_impl_.active_tree(); } 56 57 private: 58 FakeLayerTreeHost(LayerTreeHostClient* client, 59 const LayerTreeSettings& settings) 60 : LayerTreeHost(client, settings), 61 host_impl_(settings, &proxy_) {} 62 63 FakeImplProxy proxy_; 64 FakeLayerTreeHostImpl host_impl_; 65 }; 66 67 } // namespace cc 68 69 #endif // CC_TEST_FAKE_LAYER_TREE_HOST_H_ 70