| 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/test/gl_surface_test_support.h" | 16 #include "ui/gl/test/gl_surface_test_support.h" |
| 17 | 17 |
| 18 namespace gpu { | 18 namespace gpu { |
| 19 | 19 |
| 20 class GpuChannelTest : public GpuChannelTestCommon { | 20 class GpuChannelTest : public GpuChannelTestCommon { |
| 21 public: | 21 public: |
| 22 GpuChannelTest() : GpuChannelTestCommon() {} | 22 GpuChannelTest() : GpuChannelTestCommon() {} |
| 23 ~GpuChannelTest() override {} | 23 ~GpuChannelTest() override {} |
| 24 | 24 |
| 25 void SetUp() override { |
| 26 // We need GL bindings to actually initialize command buffers. |
| 27 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); |
| 28 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
| 29 } |
| 30 |
| 25 GpuChannel* CreateChannel(int32_t client_id, | 31 GpuChannel* CreateChannel(int32_t client_id, |
| 26 bool allow_view_command_buffers, | 32 bool allow_view_command_buffers, |
| 27 bool allow_real_time_streams) { | 33 bool allow_real_time_streams) { |
| 28 DCHECK(channel_manager()); | 34 DCHECK(channel_manager()); |
| 29 uint64_t kClientTracingId = 1; | 35 uint64_t kClientTracingId = 1; |
| 30 channel_manager()->EstablishChannel( | 36 channel_manager()->EstablishChannel( |
| 31 client_id, kClientTracingId, false /* preempts */, | 37 client_id, kClientTracingId, false /* preempts */, |
| 32 allow_view_command_buffers, allow_real_time_streams); | 38 allow_view_command_buffers, allow_real_time_streams); |
| 33 return channel_manager()->LookupChannel(client_id); | 39 return channel_manager()->LookupChannel(client_id); |
| 34 } | 40 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 63 }; | 69 }; |
| 64 | 70 |
| 65 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
| 66 const SurfaceHandle kFakeSurfaceHandle = | 72 const SurfaceHandle kFakeSurfaceHandle = |
| 67 reinterpret_cast<SurfaceHandle>(1); | 73 reinterpret_cast<SurfaceHandle>(1); |
| 68 #else | 74 #else |
| 69 const SurfaceHandle kFakeSurfaceHandle = 1; | 75 const SurfaceHandle kFakeSurfaceHandle = 1; |
| 70 #endif | 76 #endif |
| 71 | 77 |
| 72 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { | 78 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { |
| 73 // We need GL bindings to actually initialize command buffers. | |
| 74 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); | |
| 75 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | |
| 76 | |
| 77 int32_t kClientId = 1; | 79 int32_t kClientId = 1; |
| 78 bool allow_view_command_buffers = true; | 80 bool allow_view_command_buffers = true; |
| 79 GpuChannel* channel = | 81 GpuChannel* channel = |
| 80 CreateChannel(kClientId, allow_view_command_buffers, false); | 82 CreateChannel(kClientId, allow_view_command_buffers, false); |
| 81 ASSERT_TRUE(channel); | 83 ASSERT_TRUE(channel); |
| 82 | 84 |
| 83 SurfaceHandle surface_handle = kFakeSurfaceHandle; | 85 SurfaceHandle surface_handle = kFakeSurfaceHandle; |
| 84 DCHECK_NE(surface_handle, kNullSurfaceHandle); | 86 DCHECK_NE(surface_handle, kNullSurfaceHandle); |
| 85 | 87 |
| 86 int32_t kRouteId = 1; | 88 int32_t kRouteId = 1; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( | 296 HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( |
| 295 kNullSurfaceHandle, gfx::Size(1, 1), | 297 kNullSurfaceHandle, gfx::Size(1, 1), |
| 296 init_params, kRouteId, &succeeded)); | 298 init_params, kRouteId, &succeeded)); |
| 297 EXPECT_TRUE(succeeded); | 299 EXPECT_TRUE(succeeded); |
| 298 | 300 |
| 299 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); | 301 GpuCommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); |
| 300 EXPECT_TRUE(stub); | 302 EXPECT_TRUE(stub); |
| 301 } | 303 } |
| 302 | 304 |
| 303 TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { | 305 TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { |
| 304 // We need GL bindings to actually initialize command buffers. | |
| 305 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); | |
| 306 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | |
| 307 | |
| 308 // This GLInterface is a stub for the gl driver. | 306 // This GLInterface is a stub for the gl driver. |
| 309 std::unique_ptr<gfx::MockGLInterface> gl_interface( | 307 std::unique_ptr<gfx::MockGLInterface> gl_interface( |
| 310 new testing::NiceMock<gfx::MockGLInterface>); | 308 new testing::NiceMock<gfx::MockGLInterface>); |
| 311 // std::unique_ptr<gfx::MockGLInterface> gl_interface(new | 309 // std::unique_ptr<gfx::MockGLInterface> gl_interface(new |
| 312 // gfx::MockGLInterface); | 310 // gfx::MockGLInterface); |
| 313 gfx::MockGLInterface::SetGLInterface(gl_interface.get()); | 311 gfx::MockGLInterface::SetGLInterface(gl_interface.get()); |
| 314 | 312 |
| 315 using testing::AnyNumber; | 313 using testing::AnyNumber; |
| 316 using testing::NotNull; | 314 using testing::NotNull; |
| 317 using testing::Return; | 315 using testing::Return; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); | 475 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); |
| 478 | 476 |
| 479 // Destroy the command buffer we initialized before destoying GL. | 477 // Destroy the command buffer we initialized before destoying GL. |
| 480 HandleMessage(channel, | 478 HandleMessage(channel, |
| 481 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); | 479 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); |
| 482 gfx::MockGLInterface::SetGLInterface(nullptr); | 480 gfx::MockGLInterface::SetGLInterface(nullptr); |
| 483 gfx::ClearGLBindings(); | 481 gfx::ClearGLBindings(); |
| 484 } | 482 } |
| 485 | 483 |
| 486 } // namespace gpu | 484 } // namespace gpu |
| OLD | NEW |