Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: content/common/gpu/gpu_channel_unittest.cc

Issue 1845563005: Refactor content/common/gpu into gpu/ipc/service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop ref to deleted content_tests_gypi_values.content_unittests_ozone_sources Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 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.
4
5 #include <stdint.h>
6
7 #include "base/test/test_simple_task_runner.h"
8 #include "content/common/gpu/gpu_channel.h"
9 #include "content/common/gpu/gpu_channel_manager.h"
10 #include "content/common/gpu/gpu_channel_test_common.h"
11 #include "gpu/ipc/common/gpu_messages.h"
12 #include "ipc/ipc_test_sink.h"
13
14 namespace content {
15
16 class GpuChannelTest : public GpuChannelTestCommon {
17 public:
18 GpuChannelTest() : GpuChannelTestCommon() {}
19 ~GpuChannelTest() override {}
20
21 GpuChannel* CreateChannel(int32_t client_id,
22 bool allow_view_command_buffers,
23 bool allow_real_time_streams) {
24 DCHECK(channel_manager());
25 uint64_t kClientTracingId = 1;
26 channel_manager()->EstablishChannel(
27 client_id, kClientTracingId, false /* preempts */,
28 allow_view_command_buffers, allow_real_time_streams);
29 return channel_manager()->LookupChannel(client_id);
30 }
31
32 void HandleMessage(GpuChannel* channel, IPC::Message* msg) {
33 TestGpuChannel* test_channel = static_cast<TestGpuChannel*>(channel);
34 test_channel->HandleMessageForTesting(*msg);
35
36 if (msg->is_sync()) {
37 const IPC::Message* reply_msg = test_channel->sink()->GetMessageAt(0);
38 ASSERT_TRUE(reply_msg);
39
40 EXPECT_TRUE(IPC::SyncMessage::IsMessageReplyTo(
41 *reply_msg, IPC::SyncMessage::GetMessageId(*msg)));
42
43 IPC::MessageReplyDeserializer* deserializer =
44 static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer();
45 ASSERT_TRUE(deserializer);
46 deserializer->SerializeOutputParameters(*reply_msg);
47
48 delete deserializer;
49
50 test_channel->sink()->ClearMessages();
51 }
52
53 delete msg;
54 }
55 };
56
57 #if defined(OS_WIN)
58 const gpu::SurfaceHandle kFakeSurfaceHandle =
59 reinterpret_cast<gpu::SurfaceHandle>(1);
60 #else
61 const gpu::SurfaceHandle kFakeSurfaceHandle = 1;
62 #endif
63
64 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) {
65 int32_t kClientId = 1;
66 bool allow_view_command_buffers = true;
67 GpuChannel* channel =
68 CreateChannel(kClientId, allow_view_command_buffers, false);
69 ASSERT_TRUE(channel);
70
71 gpu::SurfaceHandle surface_handle = kFakeSurfaceHandle;
72 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle);
73
74 int32_t kRouteId = 1;
75 GPUCreateCommandBufferConfig init_params;
76 init_params.share_group_id = MSG_ROUTING_NONE;
77 init_params.stream_id = 0;
78 init_params.stream_priority = gpu::GpuStreamPriority::NORMAL;
79 init_params.attribs = std::vector<int>();
80 init_params.active_url = GURL();
81 init_params.gpu_preference = gfx::PreferIntegratedGpu;
82 bool succeeded = false;
83 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
84 surface_handle, gfx::Size(), init_params, kRouteId,
85 &succeeded));
86 EXPECT_TRUE(succeeded);
87
88 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId);
89 ASSERT_TRUE(stub);
90 }
91
92 TEST_F(GpuChannelTest, CreateViewCommandBufferDisallowed) {
93 int32_t kClientId = 1;
94 bool allow_view_command_buffers = false;
95 GpuChannel* channel =
96 CreateChannel(kClientId, allow_view_command_buffers, false);
97 ASSERT_TRUE(channel);
98
99 gpu::SurfaceHandle surface_handle = kFakeSurfaceHandle;
100 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle);
101
102 int32_t kRouteId = 1;
103 GPUCreateCommandBufferConfig init_params;
104 init_params.share_group_id = MSG_ROUTING_NONE;
105 init_params.stream_id = 0;
106 init_params.stream_priority = gpu::GpuStreamPriority::NORMAL;
107 init_params.attribs = std::vector<int>();
108 init_params.active_url = GURL();
109 init_params.gpu_preference = gfx::PreferIntegratedGpu;
110 bool succeeded = false;
111 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
112 surface_handle, gfx::Size(), init_params, kRouteId,
113 &succeeded));
114 EXPECT_FALSE(succeeded);
115
116 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId);
117 EXPECT_FALSE(stub);
118 }
119
120 TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) {
121 int32_t kClientId = 1;
122 GpuChannel* channel = CreateChannel(kClientId, true, false);
123 ASSERT_TRUE(channel);
124
125 int32_t kRouteId = 1;
126 GPUCreateCommandBufferConfig init_params;
127 init_params.share_group_id = MSG_ROUTING_NONE;
128 init_params.stream_id = 0;
129 init_params.stream_priority = gpu::GpuStreamPriority::NORMAL;
130 init_params.attribs = std::vector<int>();
131 init_params.active_url = GURL();
132 init_params.gpu_preference = gfx::PreferIntegratedGpu;
133 bool succeeded = false;
134 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
135 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
136 init_params, kRouteId, &succeeded));
137 EXPECT_TRUE(succeeded);
138
139 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId);
140 EXPECT_TRUE(stub);
141 }
142
143 TEST_F(GpuChannelTest, IncompatibleStreamIds) {
144 int32_t kClientId = 1;
145 GpuChannel* channel = CreateChannel(kClientId, true, false);
146 ASSERT_TRUE(channel);
147
148 // Create first context.
149 int32_t kRouteId1 = 1;
150 int32_t kStreamId1 = 1;
151 GPUCreateCommandBufferConfig init_params;
152 init_params.share_group_id = MSG_ROUTING_NONE;
153 init_params.stream_id = kStreamId1;
154 init_params.stream_priority = gpu::GpuStreamPriority::NORMAL;
155 init_params.attribs = std::vector<int>();
156 init_params.active_url = GURL();
157 init_params.gpu_preference = gfx::PreferIntegratedGpu;
158 bool succeeded = false;
159 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
160 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
161 init_params, kRouteId1, &succeeded));
162 EXPECT_TRUE(succeeded);
163
164 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1);
165 EXPECT_TRUE(stub);
166
167 // Create second context in same share group but different stream.
168 int32_t kRouteId2 = 2;
169 int32_t kStreamId2 = 2;
170
171 init_params.share_group_id = kRouteId1;
172 init_params.stream_id = kStreamId2;
173 init_params.stream_priority = gpu::GpuStreamPriority::NORMAL;
174 init_params.attribs = std::vector<int>();
175 init_params.active_url = GURL();
176 init_params.gpu_preference = gfx::PreferIntegratedGpu;
177 succeeded = false;
178 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
179 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
180 init_params, kRouteId2, &succeeded));
181 EXPECT_FALSE(succeeded);
182
183 stub = channel->LookupCommandBuffer(kRouteId2);
184 EXPECT_FALSE(stub);
185 }
186
187 TEST_F(GpuChannelTest, StreamLifetime) {
188 int32_t kClientId = 1;
189 GpuChannel* channel = CreateChannel(kClientId, true, false);
190 ASSERT_TRUE(channel);
191
192 // Create first context.
193 int32_t kRouteId1 = 1;
194 int32_t kStreamId1 = 1;
195 gpu::GpuStreamPriority kStreamPriority1 = gpu::GpuStreamPriority::NORMAL;
196 GPUCreateCommandBufferConfig init_params;
197 init_params.share_group_id = MSG_ROUTING_NONE;
198 init_params.stream_id = kStreamId1;
199 init_params.stream_priority = kStreamPriority1;
200 init_params.attribs = std::vector<int>();
201 init_params.active_url = GURL();
202 init_params.gpu_preference = gfx::PreferIntegratedGpu;
203 bool succeeded = false;
204 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
205 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
206 init_params, kRouteId1, &succeeded));
207 EXPECT_TRUE(succeeded);
208
209 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1);
210 EXPECT_TRUE(stub);
211
212 HandleMessage(channel, new GpuChannelMsg_DestroyCommandBuffer(kRouteId1));
213 stub = channel->LookupCommandBuffer(kRouteId1);
214 EXPECT_FALSE(stub);
215
216 // Create second context in same share group but different stream.
217 int32_t kRouteId2 = 2;
218 int32_t kStreamId2 = 2;
219 gpu::GpuStreamPriority kStreamPriority2 = gpu::GpuStreamPriority::LOW;
220
221 init_params.share_group_id = MSG_ROUTING_NONE;
222 init_params.stream_id = kStreamId2;
223 init_params.stream_priority = kStreamPriority2;
224 init_params.attribs = std::vector<int>();
225 init_params.active_url = GURL();
226 init_params.gpu_preference = gfx::PreferIntegratedGpu;
227 succeeded = false;
228 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
229 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
230 init_params, kRouteId2, &succeeded));
231 EXPECT_TRUE(succeeded);
232
233 stub = channel->LookupCommandBuffer(kRouteId2);
234 EXPECT_TRUE(stub);
235 }
236
237 TEST_F(GpuChannelTest, RealTimeStreamsDisallowed) {
238 int32_t kClientId = 1;
239 bool allow_real_time_streams = false;
240 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams);
241 ASSERT_TRUE(channel);
242
243 // Create first context.
244 int32_t kRouteId = 1;
245 int32_t kStreamId = 1;
246 gpu::GpuStreamPriority kStreamPriority = gpu::GpuStreamPriority::REAL_TIME;
247 GPUCreateCommandBufferConfig init_params;
248 init_params.share_group_id = MSG_ROUTING_NONE;
249 init_params.stream_id = kStreamId;
250 init_params.stream_priority = kStreamPriority;
251 init_params.attribs = std::vector<int>();
252 init_params.active_url = GURL();
253 init_params.gpu_preference = gfx::PreferIntegratedGpu;
254 bool succeeded = false;
255 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
256 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
257 init_params, kRouteId, &succeeded));
258 EXPECT_FALSE(succeeded);
259
260 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId);
261 EXPECT_FALSE(stub);
262 }
263
264 TEST_F(GpuChannelTest, RealTimeStreamsAllowed) {
265 int32_t kClientId = 1;
266 bool allow_real_time_streams = true;
267 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams);
268 ASSERT_TRUE(channel);
269
270 // Create first context.
271 int32_t kRouteId = 1;
272 int32_t kStreamId = 1;
273 gpu::GpuStreamPriority kStreamPriority = gpu::GpuStreamPriority::REAL_TIME;
274 GPUCreateCommandBufferConfig init_params;
275 init_params.share_group_id = MSG_ROUTING_NONE;
276 init_params.stream_id = kStreamId;
277 init_params.stream_priority = kStreamPriority;
278 init_params.attribs = std::vector<int>();
279 init_params.active_url = GURL();
280 init_params.gpu_preference = gfx::PreferIntegratedGpu;
281 bool succeeded = false;
282 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer(
283 gpu::kNullSurfaceHandle, gfx::Size(1, 1),
284 init_params, kRouteId, &succeeded));
285 EXPECT_TRUE(succeeded);
286
287 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId);
288 EXPECT_TRUE(stub);
289 }
290
291 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_channel_test_common.cc ('k') | content/common/gpu/gpu_command_buffer_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698