1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
cc / test / layer_tree_impl_test_base.cc [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/test/layer_tree_impl_test_base.h"
#include <stddef.h>
#include "cc/animation/animation.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/layers/append_quads_data.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/property_tree_test_utils.h"
#include "cc/trees/draw_property_utils.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
namespace cc {
LayerTreeImplTestBase::LayerTreeImplTestBase()
: LayerTreeImplTestBase(CommitToPendingTreeLayerListSettings()) {}
LayerTreeImplTestBase::LayerTreeImplTestBase(
std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink)
: LayerTreeImplTestBase(CommitToPendingTreeLayerListSettings(),
std::move(layer_tree_frame_sink)) {}
LayerTreeImplTestBase::LayerTreeImplTestBase(const LayerTreeSettings& settings)
: LayerTreeImplTestBase(settings, FakeLayerTreeFrameSink::Create3d()) {}
LayerTreeImplTestBase::LayerTreeImplTestBase(
const LayerTreeSettings& settings,
std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink)
: layer_tree_frame_sink_(std::move(layer_tree_frame_sink)),
animation_host_(AnimationHost::CreateForTesting(ThreadInstance::kMain)),
host_(FakeLayerTreeHost::Create(&client_,
&task_graph_runner_,
animation_host_.get(),
settings)),
render_pass_(viz::CompositorRenderPass::Create()),
layer_impl_id_(2) {
host_->CreateFakeLayerTreeHostImpl();
std::unique_ptr<LayerImpl> root =
LayerImpl::Create(host_impl()->active_tree(), 1);
root->SetBounds(gfx::Size(1, 1));
if (settings.use_layer_lists)
SetupRootProperties(root.get());
host_impl()->active_tree()->SetRootLayerForTesting(std::move(root));
host_impl()->SetVisible(true);
EXPECT_TRUE(host_impl()->InitializeFrameSink(layer_tree_frame_sink_.get()));
const int timeline_id = AnimationIdProvider::NextTimelineId();
timeline_ = AnimationTimeline::Create(timeline_id);
animation_host_->AddAnimationTimeline(timeline_);
// Create impl-side instance.
animation_host_->PushPropertiesTo(host_impl()->animation_host(),
*host_->property_trees());
timeline_impl_ = host_impl()->animation_host()->GetTimelineById(timeline_id);
}
LayerTreeImplTestBase::~LayerTreeImplTestBase() {
animation_host_->RemoveAnimationTimeline(timeline_);
timeline_ = nullptr;
host_impl()->ReleaseLayerTreeFrameSink();
}
LayerImpl* LayerTreeImplTestBase::EnsureRootLayerInPendingTree() {
LayerTreeImpl* pending_tree = host_impl()->pending_tree();
auto* root = pending_tree->root_layer();
if (root)
return root;
pending_tree->SetRootLayerForTesting(LayerImpl::Create(pending_tree, 1));
root = pending_tree->root_layer();
root->SetBounds(gfx::Size(1, 1));
if (host()->IsUsingLayerLists())
SetupRootProperties(root);
return root;
}
void LayerTreeImplTestBase::CalcDrawProps(const gfx::Size& viewport_size) {
host_impl()->active_tree()->SetDeviceViewportRect(gfx::Rect(viewport_size));
UpdateDrawProperties(host_impl()->active_tree());
}
void LayerTreeImplTestBase::AppendQuads(LayerImpl* layer_impl) {
AppendQuadsData data;
render_pass_->quad_list.clear();
render_pass_->shared_quad_state_list.clear();
layer_impl->AppendQuads(render_pass_.get(), &data);
}
void LayerTreeImplTestBase::AppendQuadsWithOcclusion(
LayerImpl* layer_impl,
const gfx::Rect& occluded) {
AppendQuadsData data;
render_pass_->quad_list.clear();
render_pass_->shared_quad_state_list.clear();
Occlusion occlusion(layer_impl->DrawTransform(),
SimpleEnclosedRegion(occluded), SimpleEnclosedRegion());
layer_impl->draw_properties().occlusion_in_content_space = occlusion;
if (layer_impl->WillDraw(DRAW_MODE_HARDWARE, resource_provider())) {
layer_impl->AppendQuads(render_pass_.get(), &data);
layer_impl->DidDraw(resource_provider());
}
}
void LayerTreeImplTestBase::AppendQuadsForPassWithOcclusion(
LayerImpl* layer_impl,
viz::CompositorRenderPass* given_render_pass,
const gfx::Rect& occluded) {
AppendQuadsData data;
given_render_pass->quad_list.clear();
given_render_pass->shared_quad_state_list.clear();
Occlusion occlusion(layer_impl->DrawTransform(),
SimpleEnclosedRegion(occluded), SimpleEnclosedRegion());
layer_impl->draw_properties().occlusion_in_content_space = occlusion;
layer_impl->WillDraw(DRAW_MODE_HARDWARE, resource_provider());
layer_impl->AppendQuads(given_render_pass, &data);
layer_impl->DidDraw(resource_provider());
}
void LayerTreeImplTestBase::AppendSurfaceQuadsWithOcclusion(
RenderSurfaceImpl* surface_impl,
const gfx::Rect& occluded) {
AppendQuadsData data;
render_pass_->quad_list.clear();
render_pass_->shared_quad_state_list.clear();
surface_impl->set_occlusion_in_content_space(
Occlusion(gfx::Transform(), SimpleEnclosedRegion(occluded),
SimpleEnclosedRegion()));
surface_impl->AppendQuads(DRAW_MODE_HARDWARE, render_pass_.get(), &data);
}
void LayerTreeImplTestBase::UpdateActiveTreeDrawProperties(
float device_scale_factor) {
SetDeviceScaleAndUpdateViewportRect(host_impl()->active_tree(),
device_scale_factor);
UpdateDrawProperties(host_impl()->active_tree(), &update_layer_impl_list_);
}
void LayerTreeImplTestBase::UpdatePendingTreeDrawProperties(
float device_scale_factor) {
SetDeviceScaleAndUpdateViewportRect(host_impl()->pending_tree(),
device_scale_factor);
UpdateDrawProperties(host_impl()->pending_tree(), &update_layer_impl_list_);
}
} // namespace cc