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
|
// Copyright 2013 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/output_surface.h"
#include "base/test/test_simple_task_runner.h"
#include "cc/output/managed_memory_policy.h"
#include "cc/output/output_surface_client.h"
#include "cc/output/software_output_device.h"
#include "cc/test/begin_frame_args_test.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_output_surface_client.h"
#include "cc/test/test_context_provider.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/frame_time.h"
namespace cc {
namespace {
class TestOutputSurface : public OutputSurface {
public:
explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider)
: OutputSurface(context_provider) {}
TestOutputSurface(scoped_refptr<ContextProvider> context_provider,
scoped_refptr<ContextProvider> worker_context_provider)
: OutputSurface(worker_context_provider) {}
explicit TestOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device)
: OutputSurface(software_device.Pass()) {}
TestOutputSurface(scoped_refptr<ContextProvider> context_provider,
scoped_ptr<SoftwareOutputDevice> software_device)
: OutputSurface(context_provider, software_device.Pass()) {}
void SwapBuffers(CompositorFrame* frame) override {
client_->DidSwapBuffers();
client_->DidSwapBuffersComplete();
}
void CommitVSyncParametersForTesting(base::TimeTicks timebase,
base::TimeDelta interval) {
CommitVSyncParameters(timebase, interval);
}
void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); }
void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); }
protected:
};
class TestSoftwareOutputDevice : public SoftwareOutputDevice {
public:
TestSoftwareOutputDevice();
~TestSoftwareOutputDevice() override;
// Overriden from cc:SoftwareOutputDevice
void DiscardBackbuffer() override;
void EnsureBackbuffer() override;
int discard_backbuffer_count() { return discard_backbuffer_count_; }
int ensure_backbuffer_count() { return ensure_backbuffer_count_; }
private:
int discard_backbuffer_count_;
int ensure_backbuffer_count_;
};
TestSoftwareOutputDevice::TestSoftwareOutputDevice()
: discard_backbuffer_count_(0), ensure_backbuffer_count_(0) {}
TestSoftwareOutputDevice::~TestSoftwareOutputDevice() {}
void TestSoftwareOutputDevice::DiscardBackbuffer() {
SoftwareOutputDevice::DiscardBackbuffer();
discard_backbuffer_count_++;
}
void TestSoftwareOutputDevice::EnsureBackbuffer() {
SoftwareOutputDevice::EnsureBackbuffer();
ensure_backbuffer_count_++;
}
TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) {
scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
TestOutputSurface output_surface(provider);
EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
EXPECT_TRUE(output_surface.HasClient());
// Verify DidLoseOutputSurface callback is hooked up correctly.
EXPECT_FALSE(client.did_lose_output_surface_called());
output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
output_surface.context_provider()->ContextGL()->Flush();
EXPECT_TRUE(client.did_lose_output_surface_called());
}
TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientSuccess) {
scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
scoped_refptr<TestContextProvider> worker_provider =
TestContextProvider::Create();
TestOutputSurface output_surface(provider, worker_provider);
EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
EXPECT_TRUE(output_surface.HasClient());
// Verify DidLoseOutputSurface callback is hooked up correctly.
EXPECT_FALSE(client.did_lose_output_surface_called());
output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
output_surface.context_provider()->ContextGL()->Flush();
EXPECT_TRUE(client.did_lose_output_surface_called());
}
TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) {
scoped_refptr<TestContextProvider> context_provider =
TestContextProvider::Create();
// Lose the context so BindToClient fails.
context_provider->UnboundTestContext3d()->set_context_lost(true);
TestOutputSurface output_surface(context_provider);
EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_FALSE(output_surface.BindToClient(&client));
EXPECT_FALSE(output_surface.HasClient());
}
TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientFailure) {
scoped_refptr<TestContextProvider> context_provider =
TestContextProvider::Create();
scoped_refptr<TestContextProvider> worker_context_provider =
TestContextProvider::Create();
// Lose the context so BindToClient fails.
worker_context_provider->UnboundTestContext3d()->set_context_lost(true);
TestOutputSurface output_surface(context_provider, worker_context_provider);
EXPECT_FALSE(output_surface.HasClient());
FakeOutputSurfaceClient client;
EXPECT_FALSE(output_surface.BindToClient(&client));
EXPECT_FALSE(output_surface.HasClient());
}
TEST(OutputSurfaceTest, MemoryAllocation) {
scoped_refptr<TestContextProvider> context_provider =
TestContextProvider::Create();
TestOutputSurface output_surface(context_provider);
FakeOutputSurfaceClient client;
EXPECT_TRUE(output_surface.BindToClient(&client));
ManagedMemoryPolicy policy(0);
policy.bytes_limit_when_visible = 1234;
policy.priority_cutoff_when_visible =
gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY;
context_provider->SetMemoryAllocation(policy);
EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY,
client.memory_policy().priority_cutoff_when_visible);
policy.priority_cutoff_when_visible =
gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
context_provider->SetMemoryAllocation(policy);
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
client.memory_policy().priority_cutoff_when_visible);
// 0 bytes limit should be ignored.
policy.bytes_limit_when_visible = 0;
context_provider->SetMemoryAllocation(policy);
EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
}
TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) {
TestSoftwareOutputDevice* software_output_device =
new TestSoftwareOutputDevice();
// TestOutputSurface now owns software_output_device and has responsibility to
// free it.
TestOutputSurface output_surface(make_scoped_ptr(software_output_device));
EXPECT_EQ(0, software_output_device->ensure_backbuffer_count());
EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
output_surface.EnsureBackbuffer();
EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
output_surface.DiscardBackbuffer();
EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
EXPECT_EQ(1, software_output_device->discard_backbuffer_count());
}
} // namespace
} // namespace cc
|