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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/output/compositor_frame.h"
#include "cc/output/copy_output_result.h"
#include "cc/output/delegated_frame_data.h"
#include "cc/quads/render_pass.h"
#include "cc/resources/shared_bitmap_manager.h"
#include "cc/surfaces/display.h"
#include "cc/surfaces/display_client.h"
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_factory.h"
#include "cc/surfaces/surface_factory_client.h"
#include "cc/surfaces/surface_id_allocator.h"
#include "cc/surfaces/surface_manager.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
class EmptySurfaceFactoryClient : public SurfaceFactoryClient {
public:
void ReturnResources(const ReturnedResourceArray& resources) override {}
};
class DisplayTest : public testing::Test {
public:
DisplayTest() : factory_(&manager_, &empty_client_) {}
void SetUp() override {
output_surface_ = FakeOutputSurface::CreateSoftware(
make_scoped_ptr(new SoftwareOutputDevice));
shared_bitmap_manager_.reset(new TestSharedBitmapManager);
output_surface_ptr_ = output_surface_.get();
}
protected:
void SubmitFrame(RenderPassList* pass_list, SurfaceId surface_id) {
scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
pass_list->swap(frame_data->render_pass_list);
scoped_ptr<CompositorFrame> frame(new CompositorFrame);
frame->delegated_frame_data = frame_data.Pass();
factory_.SubmitFrame(surface_id, frame.Pass(),
SurfaceFactory::DrawCallback());
}
SurfaceManager manager_;
EmptySurfaceFactoryClient empty_client_;
SurfaceFactory factory_;
scoped_ptr<FakeOutputSurface> output_surface_;
FakeOutputSurface* output_surface_ptr_;
scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
};
class TestDisplayClient : public DisplayClient {
public:
TestDisplayClient() : damaged(false), swapped(false) {}
~TestDisplayClient() override {}
void DisplayDamaged() override { damaged = true; }
void DidSwapBuffers() override { swapped = true; }
void DidSwapBuffersComplete() override {}
void CommitVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) override {}
void OutputSurfaceLost() override {}
void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override {}
bool damaged;
bool swapped;
};
void CopyCallback(bool* called, scoped_ptr<CopyOutputResult> result) {
*called = true;
}
// Check that frame is damaged and swapped only under correct conditions.
TEST_F(DisplayTest, DisplayDamaged) {
TestDisplayClient client;
RendererSettings settings;
settings.partial_swap_enabled = true;
Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr,
settings);
display.Initialize(output_surface_.Pass());
SurfaceId surface_id(7u);
EXPECT_FALSE(client.damaged);
display.SetSurfaceId(surface_id, 1.f);
EXPECT_TRUE(client.damaged);
client.damaged = false;
display.Resize(gfx::Size(100, 100));
EXPECT_TRUE(client.damaged);
factory_.Create(surface_id);
// First draw from surface should have full damage.
RenderPassList pass_list;
scoped_ptr<RenderPass> pass = RenderPass::Create();
pass->output_rect = gfx::Rect(0, 0, 100, 100);
pass->damage_rect = gfx::Rect(10, 10, 1, 1);
pass->id = RenderPassId(1, 1);
pass_list.push_back(pass.Pass());
client.damaged = false;
SubmitFrame(&pass_list, surface_id);
EXPECT_TRUE(client.damaged);
EXPECT_FALSE(client.swapped);
EXPECT_EQ(0u, output_surface_ptr_->num_sent_frames());
display.Draw();
EXPECT_TRUE(client.swapped);
EXPECT_EQ(1u, output_surface_ptr_->num_sent_frames());
SoftwareFrameData* software_data =
output_surface_ptr_->last_sent_frame().software_frame_data.get();
ASSERT_NE(nullptr, software_data);
EXPECT_EQ(gfx::Size(100, 100).ToString(), software_data->size.ToString());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
software_data->damage_rect.ToString());
{
// Only damaged portion should be swapped.
pass = RenderPass::Create();
pass->output_rect = gfx::Rect(0, 0, 100, 100);
pass->damage_rect = gfx::Rect(10, 10, 1, 1);
pass->id = RenderPassId(1, 1);
pass_list.push_back(pass.Pass());
client.damaged = false;
SubmitFrame(&pass_list, surface_id);
EXPECT_TRUE(client.damaged);
client.swapped = false;
display.Draw();
EXPECT_TRUE(client.swapped);
EXPECT_EQ(2u, output_surface_ptr_->num_sent_frames());
software_data =
output_surface_ptr_->last_sent_frame().software_frame_data.get();
ASSERT_NE(nullptr, software_data);
EXPECT_EQ(gfx::Size(100, 100).ToString(), software_data->size.ToString());
EXPECT_EQ(gfx::Rect(10, 10, 1, 1).ToString(),
software_data->damage_rect.ToString());
}
{
// Pass has no damage so shouldn't be swapped.
pass = RenderPass::Create();
pass->output_rect = gfx::Rect(0, 0, 100, 100);
pass->damage_rect = gfx::Rect(10, 10, 0, 0);
pass->id = RenderPassId(1, 1);
pass_list.push_back(pass.Pass());
client.damaged = false;
SubmitFrame(&pass_list, surface_id);
EXPECT_TRUE(client.damaged);
client.swapped = false;
display.Draw();
EXPECT_TRUE(client.swapped);
EXPECT_EQ(2u, output_surface_ptr_->num_sent_frames());
}
{
// Pass is wrong size so shouldn't be swapped.
pass = RenderPass::Create();
pass->output_rect = gfx::Rect(0, 0, 99, 99);
pass->damage_rect = gfx::Rect(10, 10, 10, 10);
pass->id = RenderPassId(1, 1);
pass_list.push_back(pass.Pass());
client.damaged = false;
SubmitFrame(&pass_list, surface_id);
EXPECT_TRUE(client.damaged);
client.swapped = false;
display.Draw();
EXPECT_TRUE(client.swapped);
EXPECT_EQ(2u, output_surface_ptr_->num_sent_frames());
}
{
// Pass has copy output request so should be swapped.
pass = RenderPass::Create();
pass->output_rect = gfx::Rect(0, 0, 100, 100);
pass->damage_rect = gfx::Rect(10, 10, 0, 0);
bool copy_called = false;
pass->copy_requests.push_back(CopyOutputRequest::CreateRequest(
base::Bind(&CopyCallback, ©_called)));
pass->id = RenderPassId(1, 1);
pass_list.push_back(pass.Pass());
client.damaged = false;
SubmitFrame(&pass_list, surface_id);
EXPECT_TRUE(client.damaged);
client.swapped = false;
display.Draw();
EXPECT_TRUE(client.swapped);
EXPECT_EQ(3u, output_surface_ptr_->num_sent_frames());
EXPECT_TRUE(copy_called);
}
// Pass has latency info so should be swapped.
{
pass = RenderPass::Create();
pass->output_rect = gfx::Rect(0, 0, 100, 100);
pass->damage_rect = gfx::Rect(10, 10, 0, 0);
pass->id = RenderPassId(1, 1);
pass_list.push_back(pass.Pass());
client.damaged = false;
scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
pass_list.swap(frame_data->render_pass_list);
scoped_ptr<CompositorFrame> frame(new CompositorFrame);
frame->delegated_frame_data = frame_data.Pass();
frame->metadata.latency_info.push_back(ui::LatencyInfo());
factory_.SubmitFrame(surface_id, frame.Pass(),
SurfaceFactory::DrawCallback());
EXPECT_TRUE(client.damaged);
client.swapped = false;
display.Draw();
EXPECT_TRUE(client.swapped);
EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames());
}
factory_.Destroy(surface_id);
}
} // namespace
} // namespace cc
|