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_
,
20 // Explicitly clear all debug settings.
21 SetDebugState(LayerTreeDebugState());
22 SetViewportSize(gfx::Size(100, 100));
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
));
29 FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(const LayerTreeSettings
& settings
,
31 SharedBitmapManager
* manager
)
32 : LayerTreeHostImpl(settings
,
35 &stats_instrumentation_
,
38 // Explicitly clear all debug settings.
39 SetDebugState(LayerTreeDebugState());
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
));
46 FakeLayerTreeHostImpl::~FakeLayerTreeHostImpl() {}
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
);
55 BeginFrameArgs
FakeLayerTreeHostImpl::CurrentBeginFrameArgs() const {
56 if (!current_begin_frame_args_
.IsValid())
57 return LayerTreeHostImpl::CurrentBeginFrameArgs();
58 return current_begin_frame_args_
;
61 void FakeLayerTreeHostImpl::SetCurrentBeginFrameArgs(
62 const BeginFrameArgs
& args
) {
63 current_begin_frame_args_
= args
;
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
]);
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);
78 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawPropertiesForActiveTree() {
79 UpdateNumChildrenAndDrawProperties(active_tree());
82 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawProperties(
83 LayerTreeImpl
* layerTree
) {
84 RecursiveUpdateNumChildren(layerTree
->root_layer());
85 layerTree
->UpdateDrawProperties();