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.
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"
12 FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(Proxy* proxy,
13 SharedBitmapManager* manager)
14 : LayerTreeHostImpl(LayerTreeSettings(),
17 &stats_instrumentation_,
21 // Explicitly clear all debug settings.
22 SetDebugState(LayerTreeDebugState());
23 SetViewportSize(gfx::Size(100, 100));
25 // Avoid using Now() as the frame time in unit tests.
26 base::TimeTicks time_ticks = base::TimeTicks::FromInternalValue(1);
27 SetCurrentBeginFrameArgs(CreateBeginFrameArgsForTesting(time_ticks));
30 FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(const LayerTreeSettings& settings,
32 SharedBitmapManager* manager)
33 : LayerTreeHostImpl(settings,
36 &stats_instrumentation_,
40 // Explicitly clear all debug settings.
41 SetDebugState(LayerTreeDebugState());
43 // Avoid using Now() as the frame time in unit tests.
44 base::TimeTicks time_ticks = base::TimeTicks::FromInternalValue(1);
45 SetCurrentBeginFrameArgs(CreateBeginFrameArgsForTesting(time_ticks));
48 FakeLayerTreeHostImpl::~FakeLayerTreeHostImpl() {}
50 void FakeLayerTreeHostImpl::CreatePendingTree() {
51 LayerTreeHostImpl::CreatePendingTree();
52 float arbitrary_large_page_scale = 100000.f;
53 pending_tree()->SetPageScaleFactorAndLimits(
54 1.f, 1.f / arbitrary_large_page_scale, arbitrary_large_page_scale);
57 BeginFrameArgs FakeLayerTreeHostImpl::CurrentBeginFrameArgs() const {
58 if (!current_begin_frame_args_.IsValid())
59 return LayerTreeHostImpl::CurrentBeginFrameArgs();
60 return current_begin_frame_args_;
63 void FakeLayerTreeHostImpl::SetCurrentBeginFrameArgs(
64 const BeginFrameArgs& args) {
65 current_begin_frame_args_ = args;
68 int FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(LayerImpl* layer) {
69 int num_children_that_draw_content = 0;
70 for (size_t i = 0; i < layer->children().size(); ++i) {
71 num_children_that_draw_content +=
72 RecursiveUpdateNumChildren(layer->children()[i]);
74 if (layer->DrawsContent() && layer->HasDelegatedContent())
75 num_children_that_draw_content += 1000;
76 layer->SetNumDescendantsThatDrawContent(num_children_that_draw_content);
77 return num_children_that_draw_content + (layer->DrawsContent() ? 1 : 0);
80 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawPropertiesForActiveTree() {
81 UpdateNumChildrenAndDrawProperties(active_tree());
84 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawProperties(
85 LayerTreeImpl* layerTree) {
86 RecursiveUpdateNumChildren(layerTree->root_layer());
87 layerTree->UpdateDrawProperties();