| 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" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.share_group_id = MSG_ROUTING_NONE; | 218 init_params.share_group_id = MSG_ROUTING_NONE; |
| 218 init_params.stream_id = 0; | 219 init_params.stream_id = 0; |
| 219 init_params.stream_priority = GpuStreamPriority::NORMAL; | 220 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 220 init_params.attribs = gles2::ContextCreationAttribHelper(); | 221 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 221 init_params.active_url = GURL(); | 222 init_params.active_url = GURL(); |
| 223 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 222 bool result = false; | 224 bool result = false; |
| 223 gpu::Capabilities capabilities; | 225 gpu::Capabilities capabilities; |
| 224 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 226 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 225 init_params, kRouteId, GetSharedHandle(), &result, | 227 init_params, kRouteId, GetSharedHandle(), &result, |
| 226 &capabilities)); | 228 &capabilities)); |
| 227 EXPECT_TRUE(result); | 229 EXPECT_TRUE(result); |
| 228 | 230 |
| 229 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 231 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
| 230 ASSERT_TRUE(stub); | 232 ASSERT_TRUE(stub); |
| 231 } | 233 } |
| 232 | 234 |
| 233 TEST_F(GpuChannelTest, CreateViewCommandBufferDisallowed) { | 235 TEST_F(GpuChannelTest, CreateViewCommandBufferDisallowed) { |
| 234 int32_t kClientId = 1; | 236 int32_t kClientId = 1; |
| 235 bool allow_view_command_buffers = false; | 237 bool allow_view_command_buffers = false; |
| 236 GpuChannel* channel = | 238 GpuChannel* channel = |
| 237 CreateChannel(kClientId, allow_view_command_buffers, false); | 239 CreateChannel(kClientId, allow_view_command_buffers, false); |
| 238 ASSERT_TRUE(channel); | 240 ASSERT_TRUE(channel); |
| 239 | 241 |
| 240 SurfaceHandle surface_handle = kFakeSurfaceHandle; | 242 SurfaceHandle surface_handle = kFakeSurfaceHandle; |
| 241 DCHECK_NE(surface_handle, kNullSurfaceHandle); | 243 DCHECK_NE(surface_handle, kNullSurfaceHandle); |
| 242 | 244 |
| 243 int32_t kRouteId = 1; | 245 int32_t kRouteId = 1; |
| 244 GPUCreateCommandBufferConfig init_params; | 246 GPUCreateCommandBufferConfig init_params; |
| 245 init_params.surface_handle = surface_handle; | 247 init_params.surface_handle = surface_handle; |
| 248 init_params.size = gfx::Size(); |
| 246 init_params.share_group_id = MSG_ROUTING_NONE; | 249 init_params.share_group_id = MSG_ROUTING_NONE; |
| 247 init_params.stream_id = 0; | 250 init_params.stream_id = 0; |
| 248 init_params.stream_priority = GpuStreamPriority::NORMAL; | 251 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 249 init_params.attribs = gles2::ContextCreationAttribHelper(); | 252 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 250 init_params.active_url = GURL(); | 253 init_params.active_url = GURL(); |
| 254 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 251 bool result = false; | 255 bool result = false; |
| 252 gpu::Capabilities capabilities; | 256 gpu::Capabilities capabilities; |
| 253 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 257 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 254 init_params, kRouteId, GetSharedHandle(), &result, | 258 init_params, kRouteId, GetSharedHandle(), &result, |
| 255 &capabilities)); | 259 &capabilities)); |
| 256 EXPECT_FALSE(result); | 260 EXPECT_FALSE(result); |
| 257 | 261 |
| 258 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 262 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
| 259 EXPECT_FALSE(stub); | 263 EXPECT_FALSE(stub); |
| 260 } | 264 } |
| 261 | 265 |
| 262 TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) { | 266 TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) { |
| 263 int32_t kClientId = 1; | 267 int32_t kClientId = 1; |
| 264 GpuChannel* channel = CreateChannel(kClientId, true, false); | 268 GpuChannel* channel = CreateChannel(kClientId, true, false); |
| 265 ASSERT_TRUE(channel); | 269 ASSERT_TRUE(channel); |
| 266 | 270 |
| 267 int32_t kRouteId = 1; | 271 int32_t kRouteId = 1; |
| 268 GPUCreateCommandBufferConfig init_params; | 272 GPUCreateCommandBufferConfig init_params; |
| 269 init_params.surface_handle = kNullSurfaceHandle; | 273 init_params.surface_handle = kNullSurfaceHandle; |
| 274 init_params.size = gfx::Size(1, 1); |
| 270 init_params.share_group_id = MSG_ROUTING_NONE; | 275 init_params.share_group_id = MSG_ROUTING_NONE; |
| 271 init_params.stream_id = 0; | 276 init_params.stream_id = 0; |
| 272 init_params.stream_priority = GpuStreamPriority::NORMAL; | 277 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 273 init_params.attribs = gles2::ContextCreationAttribHelper(); | 278 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 274 init_params.active_url = GURL(); | 279 init_params.active_url = GURL(); |
| 280 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 275 bool result = false; | 281 bool result = false; |
| 276 gpu::Capabilities capabilities; | 282 gpu::Capabilities capabilities; |
| 277 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 283 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 278 init_params, kRouteId, GetSharedHandle(), &result, | 284 init_params, kRouteId, GetSharedHandle(), &result, |
| 279 &capabilities)); | 285 &capabilities)); |
| 280 EXPECT_TRUE(result); | 286 EXPECT_TRUE(result); |
| 281 | 287 |
| 282 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 288 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
| 283 EXPECT_TRUE(stub); | 289 EXPECT_TRUE(stub); |
| 284 } | 290 } |
| 285 | 291 |
| 286 TEST_F(GpuChannelTest, IncompatibleStreamIds) { | 292 TEST_F(GpuChannelTest, IncompatibleStreamIds) { |
| 287 int32_t kClientId = 1; | 293 int32_t kClientId = 1; |
| 288 GpuChannel* channel = CreateChannel(kClientId, true, false); | 294 GpuChannel* channel = CreateChannel(kClientId, true, false); |
| 289 ASSERT_TRUE(channel); | 295 ASSERT_TRUE(channel); |
| 290 | 296 |
| 291 // Create first context. | 297 // Create first context. |
| 292 int32_t kRouteId1 = 1; | 298 int32_t kRouteId1 = 1; |
| 293 int32_t kStreamId1 = 1; | 299 int32_t kStreamId1 = 1; |
| 294 GPUCreateCommandBufferConfig init_params; | 300 GPUCreateCommandBufferConfig init_params; |
| 295 init_params.surface_handle = kNullSurfaceHandle; | 301 init_params.surface_handle = kNullSurfaceHandle; |
| 302 init_params.size = gfx::Size(1, 1); |
| 296 init_params.share_group_id = MSG_ROUTING_NONE; | 303 init_params.share_group_id = MSG_ROUTING_NONE; |
| 297 init_params.stream_id = kStreamId1; | 304 init_params.stream_id = kStreamId1; |
| 298 init_params.stream_priority = GpuStreamPriority::NORMAL; | 305 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 299 init_params.attribs = gles2::ContextCreationAttribHelper(); | 306 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 300 init_params.active_url = GURL(); | 307 init_params.active_url = GURL(); |
| 308 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 301 bool result = false; | 309 bool result = false; |
| 302 gpu::Capabilities capabilities; | 310 gpu::Capabilities capabilities; |
| 303 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 311 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 304 init_params, kRouteId1, GetSharedHandle(), &result, | 312 init_params, kRouteId1, GetSharedHandle(), &result, |
| 305 &capabilities)); | 313 &capabilities)); |
| 306 EXPECT_TRUE(result); | 314 EXPECT_TRUE(result); |
| 307 | 315 |
| 308 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); | 316 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); |
| 309 EXPECT_TRUE(stub); | 317 EXPECT_TRUE(stub); |
| 310 | 318 |
| 311 // Create second context in same share group but different stream. | 319 // Create second context in same share group but different stream. |
| 312 int32_t kRouteId2 = 2; | 320 int32_t kRouteId2 = 2; |
| 313 int32_t kStreamId2 = 2; | 321 int32_t kStreamId2 = 2; |
| 314 | 322 |
| 315 init_params.share_group_id = kRouteId1; | 323 init_params.share_group_id = kRouteId1; |
| 316 init_params.stream_id = kStreamId2; | 324 init_params.stream_id = kStreamId2; |
| 317 init_params.stream_priority = GpuStreamPriority::NORMAL; | 325 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 318 init_params.attribs = gles2::ContextCreationAttribHelper(); | 326 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 319 init_params.active_url = GURL(); | 327 init_params.active_url = GURL(); |
| 328 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 320 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 329 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 321 init_params, kRouteId2, GetSharedHandle(), &result, | 330 init_params, kRouteId2, GetSharedHandle(), &result, |
| 322 &capabilities)); | 331 &capabilities)); |
| 323 EXPECT_FALSE(result); | 332 EXPECT_FALSE(result); |
| 324 | 333 |
| 325 stub = channel->LookupCommandBuffer(kRouteId2); | 334 stub = channel->LookupCommandBuffer(kRouteId2); |
| 326 EXPECT_FALSE(stub); | 335 EXPECT_FALSE(stub); |
| 327 } | 336 } |
| 328 | 337 |
| 329 TEST_F(GpuChannelTest, StreamLifetime) { | 338 TEST_F(GpuChannelTest, StreamLifetime) { |
| 330 int32_t kClientId = 1; | 339 int32_t kClientId = 1; |
| 331 GpuChannel* channel = CreateChannel(kClientId, true, false); | 340 GpuChannel* channel = CreateChannel(kClientId, true, false); |
| 332 ASSERT_TRUE(channel); | 341 ASSERT_TRUE(channel); |
| 333 | 342 |
| 334 // Create first context. | 343 // Create first context. |
| 335 int32_t kRouteId1 = 1; | 344 int32_t kRouteId1 = 1; |
| 336 int32_t kStreamId1 = 1; | 345 int32_t kStreamId1 = 1; |
| 337 GpuStreamPriority kStreamPriority1 = GpuStreamPriority::NORMAL; | 346 GpuStreamPriority kStreamPriority1 = GpuStreamPriority::NORMAL; |
| 338 GPUCreateCommandBufferConfig init_params; | 347 GPUCreateCommandBufferConfig init_params; |
| 339 init_params.surface_handle = kNullSurfaceHandle; | 348 init_params.surface_handle = kNullSurfaceHandle; |
| 349 init_params.size = gfx::Size(1, 1); |
| 340 init_params.share_group_id = MSG_ROUTING_NONE; | 350 init_params.share_group_id = MSG_ROUTING_NONE; |
| 341 init_params.stream_id = kStreamId1; | 351 init_params.stream_id = kStreamId1; |
| 342 init_params.stream_priority = kStreamPriority1; | 352 init_params.stream_priority = kStreamPriority1; |
| 343 init_params.attribs = gles2::ContextCreationAttribHelper(); | 353 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 344 init_params.active_url = GURL(); | 354 init_params.active_url = GURL(); |
| 355 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 345 bool result = false; | 356 bool result = false; |
| 346 gpu::Capabilities capabilities; | 357 gpu::Capabilities capabilities; |
| 347 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 358 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 348 init_params, kRouteId1, GetSharedHandle(), &result, | 359 init_params, kRouteId1, GetSharedHandle(), &result, |
| 349 &capabilities)); | 360 &capabilities)); |
| 350 EXPECT_TRUE(result); | 361 EXPECT_TRUE(result); |
| 351 | 362 |
| 352 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); | 363 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); |
| 353 EXPECT_TRUE(stub); | 364 EXPECT_TRUE(stub); |
| 354 | 365 |
| 355 HandleMessage(channel, new GpuChannelMsg_DestroyCommandBuffer(kRouteId1)); | 366 HandleMessage(channel, new GpuChannelMsg_DestroyCommandBuffer(kRouteId1)); |
| 356 stub = channel->LookupCommandBuffer(kRouteId1); | 367 stub = channel->LookupCommandBuffer(kRouteId1); |
| 357 EXPECT_FALSE(stub); | 368 EXPECT_FALSE(stub); |
| 358 | 369 |
| 359 // Create second context in same share group but different stream. | 370 // Create second context in same share group but different stream. |
| 360 int32_t kRouteId2 = 2; | 371 int32_t kRouteId2 = 2; |
| 361 int32_t kStreamId2 = 2; | 372 int32_t kStreamId2 = 2; |
| 362 GpuStreamPriority kStreamPriority2 = GpuStreamPriority::LOW; | 373 GpuStreamPriority kStreamPriority2 = GpuStreamPriority::LOW; |
| 363 | 374 |
| 364 init_params.share_group_id = MSG_ROUTING_NONE; | 375 init_params.share_group_id = MSG_ROUTING_NONE; |
| 365 init_params.stream_id = kStreamId2; | 376 init_params.stream_id = kStreamId2; |
| 366 init_params.stream_priority = kStreamPriority2; | 377 init_params.stream_priority = kStreamPriority2; |
| 367 init_params.attribs = gles2::ContextCreationAttribHelper(); | 378 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 368 init_params.active_url = GURL(); | 379 init_params.active_url = GURL(); |
| 380 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 369 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 381 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 370 init_params, kRouteId2, GetSharedHandle(), &result, | 382 init_params, kRouteId2, GetSharedHandle(), &result, |
| 371 &capabilities)); | 383 &capabilities)); |
| 372 EXPECT_TRUE(result); | 384 EXPECT_TRUE(result); |
| 373 | 385 |
| 374 stub = channel->LookupCommandBuffer(kRouteId2); | 386 stub = channel->LookupCommandBuffer(kRouteId2); |
| 375 EXPECT_TRUE(stub); | 387 EXPECT_TRUE(stub); |
| 376 } | 388 } |
| 377 | 389 |
| 378 TEST_F(GpuChannelTest, RealTimeStreamsDisallowed) { | 390 TEST_F(GpuChannelTest, RealTimeStreamsDisallowed) { |
| 379 int32_t kClientId = 1; | 391 int32_t kClientId = 1; |
| 380 bool allow_real_time_streams = false; | 392 bool allow_real_time_streams = false; |
| 381 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); | 393 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); |
| 382 ASSERT_TRUE(channel); | 394 ASSERT_TRUE(channel); |
| 383 | 395 |
| 384 // Create first context. | 396 // Create first context. |
| 385 int32_t kRouteId = 1; | 397 int32_t kRouteId = 1; |
| 386 int32_t kStreamId = 1; | 398 int32_t kStreamId = 1; |
| 387 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; | 399 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; |
| 388 GPUCreateCommandBufferConfig init_params; | 400 GPUCreateCommandBufferConfig init_params; |
| 389 init_params.surface_handle = kNullSurfaceHandle; | 401 init_params.surface_handle = kNullSurfaceHandle; |
| 402 init_params.size = gfx::Size(1, 1); |
| 390 init_params.share_group_id = MSG_ROUTING_NONE; | 403 init_params.share_group_id = MSG_ROUTING_NONE; |
| 391 init_params.stream_id = kStreamId; | 404 init_params.stream_id = kStreamId; |
| 392 init_params.stream_priority = kStreamPriority; | 405 init_params.stream_priority = kStreamPriority; |
| 393 init_params.attribs = gles2::ContextCreationAttribHelper(); | 406 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 394 init_params.active_url = GURL(); | 407 init_params.active_url = GURL(); |
| 408 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 395 bool result = false; | 409 bool result = false; |
| 396 gpu::Capabilities capabilities; | 410 gpu::Capabilities capabilities; |
| 397 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 411 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 398 init_params, kRouteId, GetSharedHandle(), &result, | 412 init_params, kRouteId, GetSharedHandle(), &result, |
| 399 &capabilities)); | 413 &capabilities)); |
| 400 EXPECT_FALSE(result); | 414 EXPECT_FALSE(result); |
| 401 | 415 |
| 402 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 416 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
| 403 EXPECT_FALSE(stub); | 417 EXPECT_FALSE(stub); |
| 404 } | 418 } |
| 405 | 419 |
| 406 TEST_F(GpuChannelTest, RealTimeStreamsAllowed) { | 420 TEST_F(GpuChannelTest, RealTimeStreamsAllowed) { |
| 407 int32_t kClientId = 1; | 421 int32_t kClientId = 1; |
| 408 bool allow_real_time_streams = true; | 422 bool allow_real_time_streams = true; |
| 409 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); | 423 GpuChannel* channel = CreateChannel(kClientId, true, allow_real_time_streams); |
| 410 ASSERT_TRUE(channel); | 424 ASSERT_TRUE(channel); |
| 411 | 425 |
| 412 // Create first context. | 426 // Create first context. |
| 413 int32_t kRouteId = 1; | 427 int32_t kRouteId = 1; |
| 414 int32_t kStreamId = 1; | 428 int32_t kStreamId = 1; |
| 415 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; | 429 GpuStreamPriority kStreamPriority = GpuStreamPriority::REAL_TIME; |
| 416 GPUCreateCommandBufferConfig init_params; | 430 GPUCreateCommandBufferConfig init_params; |
| 417 init_params.surface_handle = kNullSurfaceHandle; | 431 init_params.surface_handle = kNullSurfaceHandle; |
| 432 init_params.size = gfx::Size(1, 1); |
| 418 init_params.share_group_id = MSG_ROUTING_NONE; | 433 init_params.share_group_id = MSG_ROUTING_NONE; |
| 419 init_params.stream_id = kStreamId; | 434 init_params.stream_id = kStreamId; |
| 420 init_params.stream_priority = kStreamPriority; | 435 init_params.stream_priority = kStreamPriority; |
| 421 init_params.attribs = gles2::ContextCreationAttribHelper(); | 436 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 422 init_params.active_url = GURL(); | 437 init_params.active_url = GURL(); |
| 438 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 423 bool result = false; | 439 bool result = false; |
| 424 gpu::Capabilities capabilities; | 440 gpu::Capabilities capabilities; |
| 425 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 441 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 426 init_params, kRouteId, GetSharedHandle(), &result, | 442 init_params, kRouteId, GetSharedHandle(), &result, |
| 427 &capabilities)); | 443 &capabilities)); |
| 428 EXPECT_TRUE(result); | 444 EXPECT_TRUE(result); |
| 429 | 445 |
| 430 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 446 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
| 431 EXPECT_TRUE(stub); | 447 EXPECT_TRUE(stub); |
| 432 } | 448 } |
| 433 | 449 |
| 434 TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { | 450 TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { |
| 435 int32_t kClientId = 1; | 451 int32_t kClientId = 1; |
| 436 GpuChannel* channel = CreateChannel(kClientId, false, false); | 452 GpuChannel* channel = CreateChannel(kClientId, false, false); |
| 437 ASSERT_TRUE(channel); | 453 ASSERT_TRUE(channel); |
| 438 | 454 |
| 439 // Create first context, we will share this one. | 455 // Create first context, we will share this one. |
| 440 int32_t kSharedRouteId = 1; | 456 int32_t kSharedRouteId = 1; |
| 441 { | 457 { |
| 442 SCOPED_TRACE("kSharedRouteId"); | 458 SCOPED_TRACE("kSharedRouteId"); |
| 443 GPUCreateCommandBufferConfig init_params; | 459 GPUCreateCommandBufferConfig init_params; |
| 444 init_params.surface_handle = kNullSurfaceHandle; | 460 init_params.surface_handle = kNullSurfaceHandle; |
| 461 init_params.size = gfx::Size(1, 1); |
| 445 init_params.share_group_id = MSG_ROUTING_NONE; | 462 init_params.share_group_id = MSG_ROUTING_NONE; |
| 446 init_params.stream_id = 0; | 463 init_params.stream_id = 0; |
| 447 init_params.stream_priority = GpuStreamPriority::NORMAL; | 464 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 448 init_params.attribs = gles2::ContextCreationAttribHelper(); | 465 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 449 init_params.active_url = GURL(); | 466 init_params.active_url = GURL(); |
| 467 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 450 bool result = false; | 468 bool result = false; |
| 451 gpu::Capabilities capabilities; | 469 gpu::Capabilities capabilities; |
| 452 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 470 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 453 init_params, kSharedRouteId, GetSharedHandle(), | 471 init_params, kSharedRouteId, GetSharedHandle(), |
| 454 &result, &capabilities)); | 472 &result, &capabilities)); |
| 455 EXPECT_TRUE(result); | 473 EXPECT_TRUE(result); |
| 456 } | 474 } |
| 457 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); | 475 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); |
| 458 | 476 |
| 459 // This context shares with the first one, this should be possible. | 477 // This context shares with the first one, this should be possible. |
| 460 int32_t kFriendlyRouteId = 2; | 478 int32_t kFriendlyRouteId = 2; |
| 461 { | 479 { |
| 462 SCOPED_TRACE("kFriendlyRouteId"); | 480 SCOPED_TRACE("kFriendlyRouteId"); |
| 463 GPUCreateCommandBufferConfig init_params; | 481 GPUCreateCommandBufferConfig init_params; |
| 464 init_params.surface_handle = kNullSurfaceHandle; | 482 init_params.surface_handle = kNullSurfaceHandle; |
| 483 init_params.size = gfx::Size(1, 1); |
| 465 init_params.share_group_id = kSharedRouteId; | 484 init_params.share_group_id = kSharedRouteId; |
| 466 init_params.stream_id = 0; | 485 init_params.stream_id = 0; |
| 467 init_params.stream_priority = GpuStreamPriority::NORMAL; | 486 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 468 init_params.attribs = gles2::ContextCreationAttribHelper(); | 487 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 469 init_params.active_url = GURL(); | 488 init_params.active_url = GURL(); |
| 489 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 470 bool result = false; | 490 bool result = false; |
| 471 gpu::Capabilities capabilities; | 491 gpu::Capabilities capabilities; |
| 472 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 492 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 473 init_params, kFriendlyRouteId, GetSharedHandle(), | 493 init_params, kFriendlyRouteId, GetSharedHandle(), |
| 474 &result, &capabilities)); | 494 &result, &capabilities)); |
| 475 EXPECT_TRUE(result); | 495 EXPECT_TRUE(result); |
| 476 } | 496 } |
| 477 EXPECT_TRUE(channel->LookupCommandBuffer(kFriendlyRouteId)); | 497 EXPECT_TRUE(channel->LookupCommandBuffer(kFriendlyRouteId)); |
| 478 | 498 |
| 479 // The shared context is lost. | 499 // The shared context is lost. |
| 480 channel->LookupCommandBuffer(kSharedRouteId)->MarkContextLost(); | 500 channel->LookupCommandBuffer(kSharedRouteId)->MarkContextLost(); |
| 481 | 501 |
| 482 // 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 |
| 483 // should fail. | 503 // should fail. |
| 484 int32_t kAnotherRouteId = 3; | 504 int32_t kAnotherRouteId = 3; |
| 485 { | 505 { |
| 486 SCOPED_TRACE("kAnotherRouteId"); | 506 SCOPED_TRACE("kAnotherRouteId"); |
| 487 GPUCreateCommandBufferConfig init_params; | 507 GPUCreateCommandBufferConfig init_params; |
| 488 init_params.surface_handle = kNullSurfaceHandle; | 508 init_params.surface_handle = kNullSurfaceHandle; |
| 509 init_params.size = gfx::Size(1, 1); |
| 489 init_params.share_group_id = kSharedRouteId; | 510 init_params.share_group_id = kSharedRouteId; |
| 490 init_params.stream_id = 0; | 511 init_params.stream_id = 0; |
| 491 init_params.stream_priority = GpuStreamPriority::NORMAL; | 512 init_params.stream_priority = GpuStreamPriority::NORMAL; |
| 492 init_params.attribs = gles2::ContextCreationAttribHelper(); | 513 init_params.attribs = gles2::ContextCreationAttribHelper(); |
| 493 init_params.active_url = GURL(); | 514 init_params.active_url = GURL(); |
| 515 init_params.gpu_preference = gl::PreferIntegratedGpu; |
| 494 bool result = false; | 516 bool result = false; |
| 495 gpu::Capabilities capabilities; | 517 gpu::Capabilities capabilities; |
| 496 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 518 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 497 init_params, kAnotherRouteId, GetSharedHandle(), | 519 init_params, kAnotherRouteId, GetSharedHandle(), |
| 498 &result, &capabilities)); | 520 &result, &capabilities)); |
| 499 EXPECT_FALSE(result); | 521 EXPECT_FALSE(result); |
| 500 } | 522 } |
| 501 EXPECT_FALSE(channel->LookupCommandBuffer(kAnotherRouteId)); | 523 EXPECT_FALSE(channel->LookupCommandBuffer(kAnotherRouteId)); |
| 502 | 524 |
| 503 // 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 |
| 504 // 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). |
| 505 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); | 527 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); |
| 506 | 528 |
| 507 // Destroy the command buffers we initialized before destoying GL. | 529 // Destroy the command buffers we initialized before destoying GL. |
| 508 HandleMessage(channel, | 530 HandleMessage(channel, |
| 509 new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); | 531 new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); |
| 510 HandleMessage(channel, | 532 HandleMessage(channel, |
| 511 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); | 533 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); |
| 512 } | 534 } |
| 513 | 535 |
| 514 } // namespace gpu | 536 } // namespace gpu |
| OLD | NEW |