OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/test/test_message_loop.h" | 8 #include "base/test/test_message_loop.h" |
9 #include "gpu/ipc/common/gpu_messages.h" | 9 #include "gpu/ipc/common/gpu_messages.h" |
10 #include "gpu/ipc/service/gpu_channel.h" | 10 #include "gpu/ipc/service/gpu_channel.h" |
11 #include "gpu/ipc/service/gpu_channel_manager.h" | 11 #include "gpu/ipc/service/gpu_channel_manager.h" |
12 #include "gpu/ipc/service/gpu_channel_test_common.h" | 12 #include "gpu/ipc/service/gpu_channel_test_common.h" |
13 #include "ipc/ipc_test_sink.h" | 13 #include "ipc/ipc_test_sink.h" |
14 #include "ui/gl/gl_context_stub_with_extensions.h" | 14 #include "ui/gl/gl_context_stub_with_extensions.h" |
15 #include "ui/gl/gl_mock.h" | 15 #include "ui/gl/gl_mock.h" |
16 #include "ui/gl/gl_surface_stub.h" | 16 #include "ui/gl/gl_surface_stub.h" |
17 #include "ui/gl/test/gl_surface_test_support.h" | 17 #include "ui/gl/test/gl_surface_test_support.h" |
18 | 18 |
19 namespace gpu { | 19 namespace gpu { |
20 | 20 |
21 static constexpr int kFakeTextureIds[] = {1, 2}; | 21 static constexpr int kFakeTextureIds[] = {1, 2}; |
22 | 22 |
23 class GpuChannelTest : public GpuChannelTestCommon { | 23 class GpuChannelTest : public GpuChannelTestCommon { |
24 public: | 24 public: |
25 GpuChannelTest() : GpuChannelTestCommon() {} | 25 GpuChannelTest() : GpuChannelTestCommon() {} |
26 ~GpuChannelTest() override {} | 26 ~GpuChannelTest() override {} |
27 | 27 |
28 void SetUp() override { | 28 void SetUp() override { |
29 // We need GL bindings to actually initialize command buffers. | 29 // We need GL bindings to actually initialize command buffers. |
30 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); | 30 gl::SetGLGetProcAddressProc(gl::MockGLInterface::GetGLProcAddress); |
31 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 31 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
32 | 32 |
33 // This GLInterface is a stub for the gl driver. | 33 // This GLInterface is a stub for the gl driver. |
34 gl_interface_.reset(new testing::NiceMock<gfx::MockGLInterface>); | 34 gl_interface_.reset(new testing::NiceMock<gl::MockGLInterface>); |
35 gfx::MockGLInterface::SetGLInterface(gl_interface_.get()); | 35 gl::MockGLInterface::SetGLInterface(gl_interface_.get()); |
36 | 36 |
37 using testing::AnyNumber; | 37 using testing::AnyNumber; |
38 using testing::NotNull; | 38 using testing::NotNull; |
39 using testing::Return; | 39 using testing::Return; |
40 using testing::SetArgPointee; | 40 using testing::SetArgPointee; |
41 using testing::SetArrayArgument; | 41 using testing::SetArrayArgument; |
42 // We need it to return non-null strings in order for things to not crash. | 42 // We need it to return non-null strings in order for things to not crash. |
43 EXPECT_CALL(*gl_interface_, GetString(GL_RENDERER)) | 43 EXPECT_CALL(*gl_interface_, GetString(GL_RENDERER)) |
44 .Times(AnyNumber()) | 44 .Times(AnyNumber()) |
45 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(""))); | 45 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(""))); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 .WillRepeatedly( | 113 .WillRepeatedly( |
114 SetArrayArgument<1>(kFakeTextureIds, kFakeTextureIds + 2)); | 114 SetArrayArgument<1>(kFakeTextureIds, kFakeTextureIds + 2)); |
115 // And errors should be squashed. | 115 // And errors should be squashed. |
116 EXPECT_CALL(*gl_interface_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) | 116 EXPECT_CALL(*gl_interface_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) |
117 .Times(AnyNumber()) | 117 .Times(AnyNumber()) |
118 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE)); | 118 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE)); |
119 | 119 |
120 // Dynamic bindings must be set up for the GLES2DecoderImpl, which requires | 120 // Dynamic bindings must be set up for the GLES2DecoderImpl, which requires |
121 // a GLContext. Use a GLContextStub which does nothing but call through to | 121 // a GLContext. Use a GLContextStub which does nothing but call through to |
122 // our |gl_interface| above. | 122 // our |gl_interface| above. |
123 stub_context_ = new gfx::GLContextStub; | 123 stub_context_ = new gl::GLContextStub; |
124 stub_surface_ = new gfx::GLSurfaceStub; | 124 stub_surface_ = new gl::GLSurfaceStub; |
125 stub_context_->MakeCurrent(stub_surface_.get()); | 125 stub_context_->MakeCurrent(stub_surface_.get()); |
126 gfx::GLSurfaceTestSupport::InitializeDynamicMockBindings( | 126 gl::GLSurfaceTestSupport::InitializeDynamicMockBindings( |
127 stub_context_.get()); | 127 stub_context_.get()); |
128 | 128 |
129 GpuChannelTestCommon::SetUp(); | 129 GpuChannelTestCommon::SetUp(); |
130 } | 130 } |
131 | 131 |
132 void TearDown() override { | 132 void TearDown() override { |
133 GpuChannelTestCommon::TearDown(); | 133 GpuChannelTestCommon::TearDown(); |
134 | 134 |
135 stub_context_ = nullptr; | 135 stub_context_ = nullptr; |
136 stub_surface_ = nullptr; | 136 stub_surface_ = nullptr; |
137 gfx::MockGLInterface::SetGLInterface(nullptr); | 137 gl::MockGLInterface::SetGLInterface(nullptr); |
138 gfx::ClearGLBindings(); | 138 gl::ClearGLBindings(); |
139 gl_interface_ = nullptr; | 139 gl_interface_ = nullptr; |
140 } | 140 } |
141 | 141 |
142 GpuChannel* CreateChannel(int32_t client_id, | 142 GpuChannel* CreateChannel(int32_t client_id, |
143 bool allow_view_command_buffers, | 143 bool allow_view_command_buffers, |
144 bool allow_real_time_streams) { | 144 bool allow_real_time_streams) { |
145 DCHECK(channel_manager()); | 145 DCHECK(channel_manager()); |
146 uint64_t kClientTracingId = 1; | 146 uint64_t kClientTracingId = 1; |
147 channel_manager()->EstablishChannel( | 147 channel_manager()->EstablishChannel( |
148 client_id, kClientTracingId, false /* preempts */, | 148 client_id, kClientTracingId, false /* preempts */, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 base::SharedMemory shared_memory; | 183 base::SharedMemory shared_memory; |
184 shared_memory.CreateAnonymous(10); | 184 shared_memory.CreateAnonymous(10); |
185 base::SharedMemoryHandle shmem_handle; | 185 base::SharedMemoryHandle shmem_handle; |
186 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 186 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
187 &shmem_handle); | 187 &shmem_handle); |
188 return shmem_handle; | 188 return shmem_handle; |
189 } | 189 } |
190 | 190 |
191 private: | 191 private: |
192 base::TestMessageLoop message_loop_; | 192 base::TestMessageLoop message_loop_; |
193 std::unique_ptr<gfx::MockGLInterface> gl_interface_; | 193 std::unique_ptr<gl::MockGLInterface> gl_interface_; |
194 scoped_refptr<gfx::GLContextStub> stub_context_; | 194 scoped_refptr<gl::GLContextStub> stub_context_; |
195 scoped_refptr<gfx::GLSurfaceStub> stub_surface_; | 195 scoped_refptr<gl::GLSurfaceStub> stub_surface_; |
196 }; | 196 }; |
197 | 197 |
198 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
199 const SurfaceHandle kFakeSurfaceHandle = reinterpret_cast<SurfaceHandle>(1); | 199 const SurfaceHandle kFakeSurfaceHandle = reinterpret_cast<SurfaceHandle>(1); |
200 #else | 200 #else |
201 const SurfaceHandle kFakeSurfaceHandle = 1; | 201 const SurfaceHandle kFakeSurfaceHandle = 1; |
202 #endif | 202 #endif |
203 | 203 |
204 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { | 204 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { |
205 int32_t kClientId = 1; | 205 int32_t kClientId = 1; |
206 bool allow_view_command_buffers = true; | 206 bool allow_view_command_buffers = true; |
207 GpuChannel* channel = | 207 GpuChannel* channel = |
208 CreateChannel(kClientId, allow_view_command_buffers, false); | 208 CreateChannel(kClientId, allow_view_command_buffers, false); |
209 ASSERT_TRUE(channel); | 209 ASSERT_TRUE(channel); |
210 | 210 |
211 SurfaceHandle surface_handle = kFakeSurfaceHandle; | 211 SurfaceHandle surface_handle = kFakeSurfaceHandle; |
212 DCHECK_NE(surface_handle, kNullSurfaceHandle); | 212 DCHECK_NE(surface_handle, kNullSurfaceHandle); |
213 | 213 |
214 int32_t kRouteId = 1; | 214 int32_t kRouteId = 1; |
215 GPUCreateCommandBufferConfig init_params; | 215 GPUCreateCommandBufferConfig init_params; |
216 init_params.surface_handle = surface_handle; | 216 init_params.surface_handle = surface_handle; |
217 init_params.size = gfx::Size(); | 217 init_params.size = gfx::Size(); |
218 init_params.share_group_id = MSG_ROUTING_NONE; | 218 init_params.share_group_id = MSG_ROUTING_NONE; |
219 init_params.stream_id = 0; | 219 init_params.stream_id = 0; |
220 init_params.stream_priority = GpuStreamPriority::NORMAL; | 220 init_params.stream_priority = GpuStreamPriority::NORMAL; |
221 init_params.attribs = gles2::ContextCreationAttribHelper(); | 221 init_params.attribs = gles2::ContextCreationAttribHelper(); |
222 init_params.active_url = GURL(); | 222 init_params.active_url = GURL(); |
223 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 223 init_params.gpu_preference = gl::PreferIntegratedGpu; |
224 bool result = false; | 224 bool result = false; |
225 gpu::Capabilities capabilities; | 225 gpu::Capabilities capabilities; |
226 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 226 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
227 init_params, kRouteId, GetSharedHandle(), &result, | 227 init_params, kRouteId, GetSharedHandle(), &result, |
228 &capabilities)); | 228 &capabilities)); |
229 EXPECT_TRUE(result); | 229 EXPECT_TRUE(result); |
230 | 230 |
231 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 231 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
232 ASSERT_TRUE(stub); | 232 ASSERT_TRUE(stub); |
233 } | 233 } |
(...skipping 10 matching lines...) Expand all Loading... |
244 | 244 |
245 int32_t kRouteId = 1; | 245 int32_t kRouteId = 1; |
246 GPUCreateCommandBufferConfig init_params; | 246 GPUCreateCommandBufferConfig init_params; |
247 init_params.surface_handle = surface_handle; | 247 init_params.surface_handle = surface_handle; |
248 init_params.size = gfx::Size(); | 248 init_params.size = gfx::Size(); |
249 init_params.share_group_id = MSG_ROUTING_NONE; | 249 init_params.share_group_id = MSG_ROUTING_NONE; |
250 init_params.stream_id = 0; | 250 init_params.stream_id = 0; |
251 init_params.stream_priority = GpuStreamPriority::NORMAL; | 251 init_params.stream_priority = GpuStreamPriority::NORMAL; |
252 init_params.attribs = gles2::ContextCreationAttribHelper(); | 252 init_params.attribs = gles2::ContextCreationAttribHelper(); |
253 init_params.active_url = GURL(); | 253 init_params.active_url = GURL(); |
254 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 254 init_params.gpu_preference = gl::PreferIntegratedGpu; |
255 bool result = false; | 255 bool result = false; |
256 gpu::Capabilities capabilities; | 256 gpu::Capabilities capabilities; |
257 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 257 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
258 init_params, kRouteId, GetSharedHandle(), &result, | 258 init_params, kRouteId, GetSharedHandle(), &result, |
259 &capabilities)); | 259 &capabilities)); |
260 EXPECT_FALSE(result); | 260 EXPECT_FALSE(result); |
261 | 261 |
262 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 262 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
263 EXPECT_FALSE(stub); | 263 EXPECT_FALSE(stub); |
264 } | 264 } |
265 | 265 |
266 TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) { | 266 TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) { |
267 int32_t kClientId = 1; | 267 int32_t kClientId = 1; |
268 GpuChannel* channel = CreateChannel(kClientId, true, false); | 268 GpuChannel* channel = CreateChannel(kClientId, true, false); |
269 ASSERT_TRUE(channel); | 269 ASSERT_TRUE(channel); |
270 | 270 |
271 int32_t kRouteId = 1; | 271 int32_t kRouteId = 1; |
272 GPUCreateCommandBufferConfig init_params; | 272 GPUCreateCommandBufferConfig init_params; |
273 init_params.surface_handle = kNullSurfaceHandle; | 273 init_params.surface_handle = kNullSurfaceHandle; |
274 init_params.size = gfx::Size(1, 1); | 274 init_params.size = gfx::Size(1, 1); |
275 init_params.share_group_id = MSG_ROUTING_NONE; | 275 init_params.share_group_id = MSG_ROUTING_NONE; |
276 init_params.stream_id = 0; | 276 init_params.stream_id = 0; |
277 init_params.stream_priority = GpuStreamPriority::NORMAL; | 277 init_params.stream_priority = GpuStreamPriority::NORMAL; |
278 init_params.attribs = gles2::ContextCreationAttribHelper(); | 278 init_params.attribs = gles2::ContextCreationAttribHelper(); |
279 init_params.active_url = GURL(); | 279 init_params.active_url = GURL(); |
280 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 280 init_params.gpu_preference = gl::PreferIntegratedGpu; |
281 bool result = false; | 281 bool result = false; |
282 gpu::Capabilities capabilities; | 282 gpu::Capabilities capabilities; |
283 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 283 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
284 init_params, kRouteId, GetSharedHandle(), &result, | 284 init_params, kRouteId, GetSharedHandle(), &result, |
285 &capabilities)); | 285 &capabilities)); |
286 EXPECT_TRUE(result); | 286 EXPECT_TRUE(result); |
287 | 287 |
288 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 288 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
289 EXPECT_TRUE(stub); | 289 EXPECT_TRUE(stub); |
290 } | 290 } |
291 | 291 |
292 TEST_F(GpuChannelTest, IncompatibleStreamIds) { | 292 TEST_F(GpuChannelTest, IncompatibleStreamIds) { |
293 int32_t kClientId = 1; | 293 int32_t kClientId = 1; |
294 GpuChannel* channel = CreateChannel(kClientId, true, false); | 294 GpuChannel* channel = CreateChannel(kClientId, true, false); |
295 ASSERT_TRUE(channel); | 295 ASSERT_TRUE(channel); |
296 | 296 |
297 // Create first context. | 297 // Create first context. |
298 int32_t kRouteId1 = 1; | 298 int32_t kRouteId1 = 1; |
299 int32_t kStreamId1 = 1; | 299 int32_t kStreamId1 = 1; |
300 GPUCreateCommandBufferConfig init_params; | 300 GPUCreateCommandBufferConfig init_params; |
301 init_params.surface_handle = kNullSurfaceHandle; | 301 init_params.surface_handle = kNullSurfaceHandle; |
302 init_params.size = gfx::Size(1, 1); | 302 init_params.size = gfx::Size(1, 1); |
303 init_params.share_group_id = MSG_ROUTING_NONE; | 303 init_params.share_group_id = MSG_ROUTING_NONE; |
304 init_params.stream_id = kStreamId1; | 304 init_params.stream_id = kStreamId1; |
305 init_params.stream_priority = GpuStreamPriority::NORMAL; | 305 init_params.stream_priority = GpuStreamPriority::NORMAL; |
306 init_params.attribs = gles2::ContextCreationAttribHelper(); | 306 init_params.attribs = gles2::ContextCreationAttribHelper(); |
307 init_params.active_url = GURL(); | 307 init_params.active_url = GURL(); |
308 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 308 init_params.gpu_preference = gl::PreferIntegratedGpu; |
309 bool result = false; | 309 bool result = false; |
310 gpu::Capabilities capabilities; | 310 gpu::Capabilities capabilities; |
311 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 311 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
312 init_params, kRouteId1, GetSharedHandle(), &result, | 312 init_params, kRouteId1, GetSharedHandle(), &result, |
313 &capabilities)); | 313 &capabilities)); |
314 EXPECT_TRUE(result); | 314 EXPECT_TRUE(result); |
315 | 315 |
316 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); | 316 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); |
317 EXPECT_TRUE(stub); | 317 EXPECT_TRUE(stub); |
318 | 318 |
319 // Create second context in same share group but different stream. | 319 // Create second context in same share group but different stream. |
320 int32_t kRouteId2 = 2; | 320 int32_t kRouteId2 = 2; |
321 int32_t kStreamId2 = 2; | 321 int32_t kStreamId2 = 2; |
322 | 322 |
323 init_params.share_group_id = kRouteId1; | 323 init_params.share_group_id = kRouteId1; |
324 init_params.stream_id = kStreamId2; | 324 init_params.stream_id = kStreamId2; |
325 init_params.stream_priority = GpuStreamPriority::NORMAL; | 325 init_params.stream_priority = GpuStreamPriority::NORMAL; |
326 init_params.attribs = gles2::ContextCreationAttribHelper(); | 326 init_params.attribs = gles2::ContextCreationAttribHelper(); |
327 init_params.active_url = GURL(); | 327 init_params.active_url = GURL(); |
328 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 328 init_params.gpu_preference = gl::PreferIntegratedGpu; |
329 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 329 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
330 init_params, kRouteId2, GetSharedHandle(), &result, | 330 init_params, kRouteId2, GetSharedHandle(), &result, |
331 &capabilities)); | 331 &capabilities)); |
332 EXPECT_FALSE(result); | 332 EXPECT_FALSE(result); |
333 | 333 |
334 stub = channel->LookupCommandBuffer(kRouteId2); | 334 stub = channel->LookupCommandBuffer(kRouteId2); |
335 EXPECT_FALSE(stub); | 335 EXPECT_FALSE(stub); |
336 } | 336 } |
337 | 337 |
338 TEST_F(GpuChannelTest, StreamLifetime) { | 338 TEST_F(GpuChannelTest, StreamLifetime) { |
339 int32_t kClientId = 1; | 339 int32_t kClientId = 1; |
340 GpuChannel* channel = CreateChannel(kClientId, true, false); | 340 GpuChannel* channel = CreateChannel(kClientId, true, false); |
341 ASSERT_TRUE(channel); | 341 ASSERT_TRUE(channel); |
342 | 342 |
343 // Create first context. | 343 // Create first context. |
344 int32_t kRouteId1 = 1; | 344 int32_t kRouteId1 = 1; |
345 int32_t kStreamId1 = 1; | 345 int32_t kStreamId1 = 1; |
346 GpuStreamPriority kStreamPriority1 = GpuStreamPriority::NORMAL; | 346 GpuStreamPriority kStreamPriority1 = GpuStreamPriority::NORMAL; |
347 GPUCreateCommandBufferConfig init_params; | 347 GPUCreateCommandBufferConfig init_params; |
348 init_params.surface_handle = kNullSurfaceHandle; | 348 init_params.surface_handle = kNullSurfaceHandle; |
349 init_params.size = gfx::Size(1, 1); | 349 init_params.size = gfx::Size(1, 1); |
350 init_params.share_group_id = MSG_ROUTING_NONE; | 350 init_params.share_group_id = MSG_ROUTING_NONE; |
351 init_params.stream_id = kStreamId1; | 351 init_params.stream_id = kStreamId1; |
352 init_params.stream_priority = kStreamPriority1; | 352 init_params.stream_priority = kStreamPriority1; |
353 init_params.attribs = gles2::ContextCreationAttribHelper(); | 353 init_params.attribs = gles2::ContextCreationAttribHelper(); |
354 init_params.active_url = GURL(); | 354 init_params.active_url = GURL(); |
355 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 355 init_params.gpu_preference = gl::PreferIntegratedGpu; |
356 bool result = false; | 356 bool result = false; |
357 gpu::Capabilities capabilities; | 357 gpu::Capabilities capabilities; |
358 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 358 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
359 init_params, kRouteId1, GetSharedHandle(), &result, | 359 init_params, kRouteId1, GetSharedHandle(), &result, |
360 &capabilities)); | 360 &capabilities)); |
361 EXPECT_TRUE(result); | 361 EXPECT_TRUE(result); |
362 | 362 |
363 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); | 363 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); |
364 EXPECT_TRUE(stub); | 364 EXPECT_TRUE(stub); |
365 | 365 |
366 HandleMessage(channel, new GpuChannelMsg_DestroyCommandBuffer(kRouteId1)); | 366 HandleMessage(channel, new GpuChannelMsg_DestroyCommandBuffer(kRouteId1)); |
367 stub = channel->LookupCommandBuffer(kRouteId1); | 367 stub = channel->LookupCommandBuffer(kRouteId1); |
368 EXPECT_FALSE(stub); | 368 EXPECT_FALSE(stub); |
369 | 369 |
370 // Create second context in same share group but different stream. | 370 // Create second context in same share group but different stream. |
371 int32_t kRouteId2 = 2; | 371 int32_t kRouteId2 = 2; |
372 int32_t kStreamId2 = 2; | 372 int32_t kStreamId2 = 2; |
373 GpuStreamPriority kStreamPriority2 = GpuStreamPriority::LOW; | 373 GpuStreamPriority kStreamPriority2 = GpuStreamPriority::LOW; |
374 | 374 |
375 init_params.share_group_id = MSG_ROUTING_NONE; | 375 init_params.share_group_id = MSG_ROUTING_NONE; |
376 init_params.stream_id = kStreamId2; | 376 init_params.stream_id = kStreamId2; |
377 init_params.stream_priority = kStreamPriority2; | 377 init_params.stream_priority = kStreamPriority2; |
378 init_params.attribs = gles2::ContextCreationAttribHelper(); | 378 init_params.attribs = gles2::ContextCreationAttribHelper(); |
379 init_params.active_url = GURL(); | 379 init_params.active_url = GURL(); |
380 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 380 init_params.gpu_preference = gl::PreferIntegratedGpu; |
381 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 381 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
382 init_params, kRouteId2, GetSharedHandle(), &result, | 382 init_params, kRouteId2, GetSharedHandle(), &result, |
383 &capabilities)); | 383 &capabilities)); |
384 EXPECT_TRUE(result); | 384 EXPECT_TRUE(result); |
385 | 385 |
386 stub = channel->LookupCommandBuffer(kRouteId2); | 386 stub = channel->LookupCommandBuffer(kRouteId2); |
387 EXPECT_TRUE(stub); | 387 EXPECT_TRUE(stub); |
388 } | 388 } |
389 | 389 |
390 TEST_F(GpuChannelTest, RealTimeStreamsDisallowed) { | 390 TEST_F(GpuChannelTest, RealTimeStreamsDisallowed) { |
391 int32_t kClientId = 1; | 391 int32_t kClientId = 1; |
392 bool allow_real_time_streams = false; | 392 bool allow_real_time_streams = false; |
393 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); | 393 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); |
394 ASSERT_TRUE(channel); | 394 ASSERT_TRUE(channel); |
395 | 395 |
396 // Create first context. | 396 // Create first context. |
397 int32_t kRouteId = 1; | 397 int32_t kRouteId = 1; |
398 int32_t kStreamId = 1; | 398 int32_t kStreamId = 1; |
399 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; | 399 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; |
400 GPUCreateCommandBufferConfig init_params; | 400 GPUCreateCommandBufferConfig init_params; |
401 init_params.surface_handle = kNullSurfaceHandle; | 401 init_params.surface_handle = kNullSurfaceHandle; |
402 init_params.size = gfx::Size(1, 1); | 402 init_params.size = gfx::Size(1, 1); |
403 init_params.share_group_id = MSG_ROUTING_NONE; | 403 init_params.share_group_id = MSG_ROUTING_NONE; |
404 init_params.stream_id = kStreamId; | 404 init_params.stream_id = kStreamId; |
405 init_params.stream_priority = kStreamPriority; | 405 init_params.stream_priority = kStreamPriority; |
406 init_params.attribs = gles2::ContextCreationAttribHelper(); | 406 init_params.attribs = gles2::ContextCreationAttribHelper(); |
407 init_params.active_url = GURL(); | 407 init_params.active_url = GURL(); |
408 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 408 init_params.gpu_preference = gl::PreferIntegratedGpu; |
409 bool result = false; | 409 bool result = false; |
410 gpu::Capabilities capabilities; | 410 gpu::Capabilities capabilities; |
411 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 411 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
412 init_params, kRouteId, GetSharedHandle(), &result, | 412 init_params, kRouteId, GetSharedHandle(), &result, |
413 &capabilities)); | 413 &capabilities)); |
414 EXPECT_FALSE(result); | 414 EXPECT_FALSE(result); |
415 | 415 |
416 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 416 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
417 EXPECT_FALSE(stub); | 417 EXPECT_FALSE(stub); |
418 } | 418 } |
419 | 419 |
420 TEST_F(GpuChannelTest, RealTimeStreamsAllowed) { | 420 TEST_F(GpuChannelTest, RealTimeStreamsAllowed) { |
421 int32_t kClientId = 1; | 421 int32_t kClientId = 1; |
422 bool allow_real_time_streams = true; | 422 bool allow_real_time_streams = true; |
423 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); | 423 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); |
424 ASSERT_TRUE(channel); | 424 ASSERT_TRUE(channel); |
425 | 425 |
426 // Create first context. | 426 // Create first context. |
427 int32_t kRouteId = 1; | 427 int32_t kRouteId = 1; |
428 int32_t kStreamId = 1; | 428 int32_t kStreamId = 1; |
429 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; | 429 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; |
430 GPUCreateCommandBufferConfig init_params; | 430 GPUCreateCommandBufferConfig init_params; |
431 init_params.surface_handle = kNullSurfaceHandle; | 431 init_params.surface_handle = kNullSurfaceHandle; |
432 init_params.size = gfx::Size(1, 1); | 432 init_params.size = gfx::Size(1, 1); |
433 init_params.share_group_id = MSG_ROUTING_NONE; | 433 init_params.share_group_id = MSG_ROUTING_NONE; |
434 init_params.stream_id = kStreamId; | 434 init_params.stream_id = kStreamId; |
435 init_params.stream_priority = kStreamPriority; | 435 init_params.stream_priority = kStreamPriority; |
436 init_params.attribs = gles2::ContextCreationAttribHelper(); | 436 init_params.attribs = gles2::ContextCreationAttribHelper(); |
437 init_params.active_url = GURL(); | 437 init_params.active_url = GURL(); |
438 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 438 init_params.gpu_preference = gl::PreferIntegratedGpu; |
439 bool result = false; | 439 bool result = false; |
440 gpu::Capabilities capabilities; | 440 gpu::Capabilities capabilities; |
441 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 441 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
442 init_params, kRouteId, GetSharedHandle(), &result, | 442 init_params, kRouteId, GetSharedHandle(), &result, |
443 &capabilities)); | 443 &capabilities)); |
444 EXPECT_TRUE(result); | 444 EXPECT_TRUE(result); |
445 | 445 |
446 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 446 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
447 EXPECT_TRUE(stub); | 447 EXPECT_TRUE(stub); |
448 } | 448 } |
449 | 449 |
450 TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { | 450 TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { |
451 int32_t kClientId = 1; | 451 int32_t kClientId = 1; |
452 GpuChannel* channel = CreateChannel(kClientId, false, false); | 452 GpuChannel* channel = CreateChannel(kClientId, false, false); |
453 ASSERT_TRUE(channel); | 453 ASSERT_TRUE(channel); |
454 | 454 |
455 // Create first context, we will share this one. | 455 // Create first context, we will share this one. |
456 int32_t kSharedRouteId = 1; | 456 int32_t kSharedRouteId = 1; |
457 { | 457 { |
458 SCOPED_TRACE("kSharedRouteId"); | 458 SCOPED_TRACE("kSharedRouteId"); |
459 GPUCreateCommandBufferConfig init_params; | 459 GPUCreateCommandBufferConfig init_params; |
460 init_params.surface_handle = kNullSurfaceHandle; | 460 init_params.surface_handle = kNullSurfaceHandle; |
461 init_params.size = gfx::Size(1, 1); | 461 init_params.size = gfx::Size(1, 1); |
462 init_params.share_group_id = MSG_ROUTING_NONE; | 462 init_params.share_group_id = MSG_ROUTING_NONE; |
463 init_params.stream_id = 0; | 463 init_params.stream_id = 0; |
464 init_params.stream_priority = GpuStreamPriority::NORMAL; | 464 init_params.stream_priority = GpuStreamPriority::NORMAL; |
465 init_params.attribs = gles2::ContextCreationAttribHelper(); | 465 init_params.attribs = gles2::ContextCreationAttribHelper(); |
466 init_params.active_url = GURL(); | 466 init_params.active_url = GURL(); |
467 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 467 init_params.gpu_preference = gl::PreferIntegratedGpu; |
468 bool result = false; | 468 bool result = false; |
469 gpu::Capabilities capabilities; | 469 gpu::Capabilities capabilities; |
470 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 470 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
471 init_params, kSharedRouteId, GetSharedHandle(), | 471 init_params, kSharedRouteId, GetSharedHandle(), |
472 &result, &capabilities)); | 472 &result, &capabilities)); |
473 EXPECT_TRUE(result); | 473 EXPECT_TRUE(result); |
474 } | 474 } |
475 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); | 475 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); |
476 | 476 |
477 // This context shares with the first one, this should be possible. | 477 // This context shares with the first one, this should be possible. |
478 int32_t kFriendlyRouteId = 2; | 478 int32_t kFriendlyRouteId = 2; |
479 { | 479 { |
480 SCOPED_TRACE("kFriendlyRouteId"); | 480 SCOPED_TRACE("kFriendlyRouteId"); |
481 GPUCreateCommandBufferConfig init_params; | 481 GPUCreateCommandBufferConfig init_params; |
482 init_params.surface_handle = kNullSurfaceHandle; | 482 init_params.surface_handle = kNullSurfaceHandle; |
483 init_params.size = gfx::Size(1, 1); | 483 init_params.size = gfx::Size(1, 1); |
484 init_params.share_group_id = kSharedRouteId; | 484 init_params.share_group_id = kSharedRouteId; |
485 init_params.stream_id = 0; | 485 init_params.stream_id = 0; |
486 init_params.stream_priority = GpuStreamPriority::NORMAL; | 486 init_params.stream_priority = GpuStreamPriority::NORMAL; |
487 init_params.attribs = gles2::ContextCreationAttribHelper(); | 487 init_params.attribs = gles2::ContextCreationAttribHelper(); |
488 init_params.active_url = GURL(); | 488 init_params.active_url = GURL(); |
489 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 489 init_params.gpu_preference = gl::PreferIntegratedGpu; |
490 bool result = false; | 490 bool result = false; |
491 gpu::Capabilities capabilities; | 491 gpu::Capabilities capabilities; |
492 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 492 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
493 init_params, kFriendlyRouteId, GetSharedHandle(), | 493 init_params, kFriendlyRouteId, GetSharedHandle(), |
494 &result, &capabilities)); | 494 &result, &capabilities)); |
495 EXPECT_TRUE(result); | 495 EXPECT_TRUE(result); |
496 } | 496 } |
497 EXPECT_TRUE(channel->LookupCommandBuffer(kFriendlyRouteId)); | 497 EXPECT_TRUE(channel->LookupCommandBuffer(kFriendlyRouteId)); |
498 | 498 |
499 // The shared context is lost. | 499 // The shared context is lost. |
500 channel->LookupCommandBuffer(kSharedRouteId)->MarkContextLost(); | 500 channel->LookupCommandBuffer(kSharedRouteId)->MarkContextLost(); |
501 | 501 |
502 // Meanwhile another context is being made pointing to the shared one. This | 502 // Meanwhile another context is being made pointing to the shared one. This |
503 // should fail. | 503 // should fail. |
504 int32_t kAnotherRouteId = 3; | 504 int32_t kAnotherRouteId = 3; |
505 { | 505 { |
506 SCOPED_TRACE("kAnotherRouteId"); | 506 SCOPED_TRACE("kAnotherRouteId"); |
507 GPUCreateCommandBufferConfig init_params; | 507 GPUCreateCommandBufferConfig init_params; |
508 init_params.surface_handle = kNullSurfaceHandle; | 508 init_params.surface_handle = kNullSurfaceHandle; |
509 init_params.size = gfx::Size(1, 1); | 509 init_params.size = gfx::Size(1, 1); |
510 init_params.share_group_id = kSharedRouteId; | 510 init_params.share_group_id = kSharedRouteId; |
511 init_params.stream_id = 0; | 511 init_params.stream_id = 0; |
512 init_params.stream_priority = GpuStreamPriority::NORMAL; | 512 init_params.stream_priority = GpuStreamPriority::NORMAL; |
513 init_params.attribs = gles2::ContextCreationAttribHelper(); | 513 init_params.attribs = gles2::ContextCreationAttribHelper(); |
514 init_params.active_url = GURL(); | 514 init_params.active_url = GURL(); |
515 init_params.gpu_preference = gfx::PreferIntegratedGpu; | 515 init_params.gpu_preference = gl::PreferIntegratedGpu; |
516 bool result = false; | 516 bool result = false; |
517 gpu::Capabilities capabilities; | 517 gpu::Capabilities capabilities; |
518 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 518 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
519 init_params, kAnotherRouteId, GetSharedHandle(), | 519 init_params, kAnotherRouteId, GetSharedHandle(), |
520 &result, &capabilities)); | 520 &result, &capabilities)); |
521 EXPECT_FALSE(result); | 521 EXPECT_FALSE(result); |
522 } | 522 } |
523 EXPECT_FALSE(channel->LookupCommandBuffer(kAnotherRouteId)); | 523 EXPECT_FALSE(channel->LookupCommandBuffer(kAnotherRouteId)); |
524 | 524 |
525 // The lost context is still around though (to verify the failure happened due | 525 // The lost context is still around though (to verify the failure happened due |
526 // to the shared context being lost, not due to it being deleted). | 526 // to the shared context being lost, not due to it being deleted). |
527 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); | 527 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); |
528 | 528 |
529 // Destroy the command buffers we initialized before destoying GL. | 529 // Destroy the command buffers we initialized before destoying GL. |
530 HandleMessage(channel, | 530 HandleMessage(channel, |
531 new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); | 531 new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); |
532 HandleMessage(channel, | 532 HandleMessage(channel, |
533 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); | 533 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); |
534 } | 534 } |
535 | 535 |
536 } // namespace gpu | 536 } // namespace gpu |
OLD | NEW |