| 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_stub_api.h" |
| 16 #include "ui/gl/gl_surface_stub.h" | 16 #include "ui/gl/gl_surface_stub.h" |
| 17 #include "ui/gl/init/gl_factory.h" | 17 #include "ui/gl/init/gl_factory.h" |
| 18 #include "ui/gl/test/gl_surface_test_support.h" | 18 #include "ui/gl/test/gl_surface_test_support.h" |
| 19 | 19 |
| 20 namespace gpu { | 20 namespace gpu { |
| 21 | 21 |
| 22 static constexpr int kFakeTextureIds[] = {1, 2}; | |
| 23 | |
| 24 class GpuChannelTest : public GpuChannelTestCommon { | 22 class GpuChannelTest : public GpuChannelTestCommon { |
| 25 public: | 23 public: |
| 26 GpuChannelTest() : GpuChannelTestCommon() {} | 24 GpuChannelTest() : GpuChannelTestCommon() {} |
| 27 ~GpuChannelTest() override {} | 25 ~GpuChannelTest() override {} |
| 28 | 26 |
| 29 void SetUp() override { | 27 void SetUp() override { |
| 30 // We need GL bindings to actually initialize command buffers. | 28 // We need GL bindings to actually initialize command buffers. |
| 31 gl::SetGLGetProcAddressProc(gl::MockGLInterface::GetGLProcAddress); | |
| 32 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 29 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
| 33 | 30 gl::SetStubGLApi(&api_); |
| 34 // This GLInterface is a stub for the gl driver. | |
| 35 gl_interface_.reset(new testing::NiceMock<gl::MockGLInterface>); | |
| 36 gl::MockGLInterface::SetGLInterface(gl_interface_.get()); | |
| 37 | |
| 38 using testing::AnyNumber; | |
| 39 using testing::NotNull; | |
| 40 using testing::Return; | |
| 41 using testing::SetArgPointee; | |
| 42 using testing::SetArrayArgument; | |
| 43 // We need it to return non-null strings in order for things to not crash. | |
| 44 EXPECT_CALL(*gl_interface_, GetString(GL_RENDERER)) | |
| 45 .Times(AnyNumber()) | |
| 46 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(""))); | |
| 47 EXPECT_CALL(*gl_interface_, GetString(GL_VERSION)) | |
| 48 .Times(AnyNumber()) | |
| 49 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>("2.0"))); | |
| 50 EXPECT_CALL(*gl_interface_, GetString(GL_EXTENSIONS)) | |
| 51 .Times(AnyNumber()) | |
| 52 .WillRepeatedly(Return( | |
| 53 reinterpret_cast<const GLubyte*>("GL_EXT_framebuffer_object "))); | |
| 54 // And we need some values to be large enough to initialize ContextGroup. | |
| 55 EXPECT_CALL(*gl_interface_, | |
| 56 GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, NotNull())) | |
| 57 .Times(AnyNumber()) | |
| 58 .WillRepeatedly(SetArgPointee<1>(512)); | |
| 59 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, NotNull())) | |
| 60 .Times(AnyNumber()) | |
| 61 .WillRepeatedly(SetArgPointee<1>(8)); | |
| 62 EXPECT_CALL(*gl_interface_, | |
| 63 GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, NotNull())) | |
| 64 .Times(AnyNumber()) | |
| 65 .WillRepeatedly(SetArgPointee<1>(8)); | |
| 66 EXPECT_CALL(*gl_interface_, | |
| 67 GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, NotNull())) | |
| 68 .Times(AnyNumber()) | |
| 69 .WillRepeatedly(SetArgPointee<1>(8)); | |
| 70 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_MAX_TEXTURE_SIZE, NotNull())) | |
| 71 .Times(AnyNumber()) | |
| 72 .WillRepeatedly(SetArgPointee<1>(2048)); | |
| 73 EXPECT_CALL(*gl_interface_, | |
| 74 GetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, NotNull())) | |
| 75 .Times(AnyNumber()) | |
| 76 .WillRepeatedly(SetArgPointee<1>(2048)); | |
| 77 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_MAX_VARYING_FLOATS, NotNull())) | |
| 78 .Times(AnyNumber()) | |
| 79 .WillRepeatedly(SetArgPointee<1>(8 * 4)); | |
| 80 EXPECT_CALL(*gl_interface_, | |
| 81 GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, NotNull())) | |
| 82 .Times(AnyNumber()) | |
| 83 .WillRepeatedly(SetArgPointee<1>(128 * 4)); | |
| 84 EXPECT_CALL(*gl_interface_, | |
| 85 GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, NotNull())) | |
| 86 .Times(AnyNumber()) | |
| 87 .WillRepeatedly(SetArgPointee<1>(16 * 4)); | |
| 88 EXPECT_CALL(*gl_interface_, | |
| 89 GetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, NotNull())) | |
| 90 .Times(AnyNumber()) | |
| 91 .WillRepeatedly(SetArgPointee<1>(32)); | |
| 92 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, NotNull())) | |
| 93 .Times(AnyNumber()) | |
| 94 .WillRepeatedly(SetArgPointee<1>(1024 << 8)); | |
| 95 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_ALPHA_BITS, NotNull())) | |
| 96 .Times(AnyNumber()) | |
| 97 .WillRepeatedly(SetArgPointee<1>(8)); | |
| 98 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_DEPTH_BITS, NotNull())) | |
| 99 .Times(AnyNumber()) | |
| 100 .WillRepeatedly(SetArgPointee<1>(24)); | |
| 101 EXPECT_CALL(*gl_interface_, GetIntegerv(GL_STENCIL_BITS, NotNull())) | |
| 102 .Times(AnyNumber()) | |
| 103 .WillRepeatedly(SetArgPointee<1>(8)); | |
| 104 // Allow generating non-0 resources so code does not DCHECK. | |
| 105 EXPECT_CALL(*gl_interface_, GenFramebuffersEXT(1, NotNull())) | |
| 106 .Times(AnyNumber()) | |
| 107 .WillRepeatedly(SetArgPointee<1>(1)); | |
| 108 EXPECT_CALL(*gl_interface_, GenTextures(1, NotNull())) | |
| 109 .Times(AnyNumber()) | |
| 110 .WillRepeatedly( | |
| 111 SetArrayArgument<1>(kFakeTextureIds, kFakeTextureIds + 1)); | |
| 112 EXPECT_CALL(*gl_interface_, GenTextures(2, NotNull())) | |
| 113 .Times(AnyNumber()) | |
| 114 .WillRepeatedly( | |
| 115 SetArrayArgument<1>(kFakeTextureIds, kFakeTextureIds + 2)); | |
| 116 // And errors should be squashed. | |
| 117 EXPECT_CALL(*gl_interface_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) | |
| 118 .Times(AnyNumber()) | |
| 119 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE)); | |
| 120 | 31 |
| 121 GpuChannelTestCommon::SetUp(); | 32 GpuChannelTestCommon::SetUp(); |
| 122 } | 33 } |
| 123 | 34 |
| 124 void TearDown() override { | 35 void TearDown() override { |
| 125 GpuChannelTestCommon::TearDown(); | 36 GpuChannelTestCommon::TearDown(); |
| 126 | 37 |
| 127 gl::MockGLInterface::SetGLInterface(nullptr); | |
| 128 gl::init::ClearGLBindings(); | 38 gl::init::ClearGLBindings(); |
| 129 gl_interface_ = nullptr; | |
| 130 } | 39 } |
| 131 | 40 |
| 132 GpuChannel* CreateChannel(int32_t client_id, | 41 GpuChannel* CreateChannel(int32_t client_id, |
| 133 bool allow_view_command_buffers, | 42 bool allow_view_command_buffers, |
| 134 bool allow_real_time_streams) { | 43 bool allow_real_time_streams) { |
| 135 DCHECK(channel_manager()); | 44 DCHECK(channel_manager()); |
| 136 uint64_t kClientTracingId = 1; | 45 uint64_t kClientTracingId = 1; |
| 137 channel_manager()->EstablishChannel( | 46 channel_manager()->EstablishChannel( |
| 138 client_id, kClientTracingId, false /* preempts */, | 47 client_id, kClientTracingId, false /* preempts */, |
| 139 allow_view_command_buffers, allow_real_time_streams); | 48 allow_view_command_buffers, allow_real_time_streams); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 base::SharedMemory shared_memory; | 82 base::SharedMemory shared_memory; |
| 174 shared_memory.CreateAnonymous(10); | 83 shared_memory.CreateAnonymous(10); |
| 175 base::SharedMemoryHandle shmem_handle; | 84 base::SharedMemoryHandle shmem_handle; |
| 176 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 85 shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
| 177 &shmem_handle); | 86 &shmem_handle); |
| 178 return shmem_handle; | 87 return shmem_handle; |
| 179 } | 88 } |
| 180 | 89 |
| 181 private: | 90 private: |
| 182 base::TestMessageLoop message_loop_; | 91 base::TestMessageLoop message_loop_; |
| 183 std::unique_ptr<gl::MockGLInterface> gl_interface_; | 92 gl::GLStubApi api_; |
| 184 }; | 93 }; |
| 185 | 94 |
| 186 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
| 187 const SurfaceHandle kFakeSurfaceHandle = reinterpret_cast<SurfaceHandle>(1); | 96 const SurfaceHandle kFakeSurfaceHandle = reinterpret_cast<SurfaceHandle>(1); |
| 188 #else | 97 #else |
| 189 const SurfaceHandle kFakeSurfaceHandle = 1; | 98 const SurfaceHandle kFakeSurfaceHandle = 1; |
| 190 #endif | 99 #endif |
| 191 | 100 |
| 192 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { | 101 TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { |
| 193 int32_t kClientId = 1; | 102 int32_t kClientId = 1; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); | 402 EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); |
| 494 | 403 |
| 495 // Destroy the command buffers we initialized before destoying GL. | 404 // Destroy the command buffers we initialized before destoying GL. |
| 496 HandleMessage(channel, | 405 HandleMessage(channel, |
| 497 new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); | 406 new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); |
| 498 HandleMessage(channel, | 407 HandleMessage(channel, |
| 499 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); | 408 new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); |
| 500 } | 409 } |
| 501 | 410 |
| 502 } // namespace gpu | 411 } // namespace gpu |
| OLD | NEW |