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 TaskGraphRunner
* task_graph_runner
)
15 : LayerTreeHostImpl(LayerTreeSettings(),
18 &stats_instrumentation_
,
23 // Explicitly clear all debug settings.
24 SetDebugState(LayerTreeDebugState());
25 SetViewportSize(gfx::Size(100, 100));
27 // Start an impl frame so tests have a valid frame_time to work with.
28 base::TimeTicks time_ticks
= base::TimeTicks::FromInternalValue(1);
30 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
33 FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(const LayerTreeSettings
& settings
,
35 SharedBitmapManager
* manager
,
36 TaskGraphRunner
* task_graph_runner
)
37 : LayerTreeHostImpl(settings
,
40 &stats_instrumentation_
,
45 // Explicitly clear all debug settings.
46 SetDebugState(LayerTreeDebugState());
48 // Start an impl frame so tests have a valid frame_time to work with.
49 base::TimeTicks time_ticks
= base::TimeTicks::FromInternalValue(1);
51 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
54 FakeLayerTreeHostImpl::~FakeLayerTreeHostImpl() {}
56 void FakeLayerTreeHostImpl::CreatePendingTree() {
57 LayerTreeHostImpl::CreatePendingTree();
58 float arbitrary_large_page_scale
= 100000.f
;
59 pending_tree()->PushPageScaleFromMainThread(
60 1.f
, 1.f
/ arbitrary_large_page_scale
, arbitrary_large_page_scale
);
63 BeginFrameArgs
FakeLayerTreeHostImpl::CurrentBeginFrameArgs() const {
64 return current_begin_frame_tracker_
.DangerousMethodCurrentOrLast();
67 void FakeLayerTreeHostImpl::AdvanceToNextFrame(base::TimeDelta advance_by
) {
68 BeginFrameArgs next_begin_frame_args
= current_begin_frame_tracker_
.Current();
69 next_begin_frame_args
.frame_time
+= advance_by
;
71 WillBeginImplFrame(next_begin_frame_args
);
74 int FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(LayerImpl
* layer
) {
75 int num_children_that_draw_content
= 0;
76 for (size_t i
= 0; i
< layer
->children().size(); ++i
) {
77 num_children_that_draw_content
+=
78 RecursiveUpdateNumChildren(layer
->children()[i
]);
80 if (layer
->DrawsContent() && layer
->HasDelegatedContent())
81 num_children_that_draw_content
+= 1000;
82 layer
->SetNumDescendantsThatDrawContent(num_children_that_draw_content
);
83 return num_children_that_draw_content
+ (layer
->DrawsContent() ? 1 : 0);
86 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawPropertiesForActiveTree() {
87 UpdateNumChildrenAndDrawProperties(active_tree());
90 void FakeLayerTreeHostImpl::UpdateNumChildrenAndDrawProperties(
91 LayerTreeImpl
* layerTree
) {
92 RecursiveUpdateNumChildren(layerTree
->root_layer());
93 bool update_lcd_text
= false;
94 layerTree
->BuildPropertyTreesForTesting();
95 layerTree
->UpdateDrawProperties(update_lcd_text
);