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 #include "cc/test/begin_frame_args_test.h" 6 #include "cc/test/fake_layer_tree_host_impl.h" 7 #include "cc/test/test_shared_bitmap_manager.h" 8 #include "cc/trees/layer_tree_impl.h" 9 10 namespace cc { 11 12 FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(Proxy* proxy, 13 SharedBitmapManager* manager) 14 : LayerTreeHostImpl(LayerTreeSettings(), 15 &client_, 16 proxy, 17 &stats_instrumentation_, 18 manager, 19 0) { 20 // Explicitly clear all debug settings. 21 SetDebugState(LayerTreeDebugState()); 22 SetViewportSize(gfx::Size(100, 100)); 23 24 // Avoid using Now() as the frame time in unit tests. 25 base::TimeTicks time_ticks = base::TimeTicks::FromInternalValue(1); 26 SetCurrentBeginFrameArgs(CreateBeginFrameArgsForTesting(time_ticks)); 27 } 28 29 FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(const LayerTreeSettings& settings, 30 Proxy* proxy, 31 SharedBitmapManager* manager) 32 : LayerTreeHostImpl(settings, 33 &client_, 34 proxy, 35 &stats_instrumentation_, 36 manager, 37 0) { 38 // Explicitly clear all debug settings. 39 SetDebugState(LayerTreeDebugState()); 40 41 // Avoid using Now() as the frame time in unit tests. 42 base::TimeTicks time_ticks = base::TimeTicks::FromInternalValue(1); 43 SetCurrentBeginFrameArgs(CreateBeginFrameArgsForTesting(time_ticks)); 44 } 45 46 FakeLayerTreeHostImpl::~FakeLayerTreeHostImpl() {} 47 48 void FakeLayerTreeHostImpl::CreatePendingTree() { 49 LayerTreeHostImpl::CreatePendingTree(); 50 float arbitrary_large_page_scale = 100000.f; 51 pending_tree()->SetPageScaleFactorAndLimits( 52 1.f, 1.f / arbitrary_large_page_scale, arbitrary_large_page_scale); 53 } 54 55 BeginFrameArgs FakeLayerTreeHostImpl::CurrentBeginFrameArgs() const { 56 if (!current_begin_frame_args_.IsValid()) 57 return LayerTreeHostImpl::CurrentBeginFrameArgs(); 58 return current_begin_frame_args_; 59 } 60 61 void FakeLayerTreeHostImpl::SetCurrentBeginFrameArgs( 62 const BeginFrameArgs& args) { 63 current_begin_frame_args_ = args; 64 } 65 66 int FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(LayerImpl* layer) { 67 int num_children_that_draw_content = 0; 68 for (size_t i = 0; i < layer->children().size(); ++i) { 69 num_children_that_draw_content += 70 RecursiveUpdateNumChildren(layer->children()[i]); 71 } 72 if (layer->DrawsContent() && layer->HasDelegatedContent()) 73 num_children_that_draw_content += 1000; 74 layer->SetNumDescendantsThatDrawContent(num_children_that_draw_content); 75 return num_children_that_draw_content + (layer->DrawsContent() ? 1 : 0); 76 } 77 78 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawPropertiesForActiveTree() { 79 UpdateNumChildrenAndDrawProperties(active_tree()); 80 } 81 82 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawProperties( 83 LayerTreeImpl* layerTree) { 84 RecursiveUpdateNumChildren(layerTree->root_layer()); 85 layerTree->UpdateDrawProperties(); 86 } 87 88 } // namespace cc 89