OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/test/test_simple_task_runner.h" | 6 #include "base/test/test_simple_task_runner.h" |
7 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 7 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
9 #include "media/renderers/mock_gpu_video_accelerator_factories.h" | 9 #include "media/renderers/mock_gpu_video_accelerator_factories.h" |
10 #include "media/video/gpu_memory_buffer_video_frame_pool.h" | 10 #include "media/video/gpu_memory_buffer_video_frame_pool.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 namespace { | 15 namespace { |
16 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { | 16 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { |
17 public: | 17 public: |
18 unsigned gen_textures = 0u; | 18 unsigned gen_textures = 0u; |
| 19 unsigned gen_images = 0u; |
19 void GenTextures(GLsizei n, GLuint* textures) override { | 20 void GenTextures(GLsizei n, GLuint* textures) override { |
20 DCHECK_EQ(1, n); | 21 DCHECK_EQ(1, n); |
21 *textures = ++gen_textures; | 22 *textures = ++gen_textures; |
22 } | 23 } |
23 | 24 |
| 25 GLuint CreateImageCHROMIUM(ClientBuffer buffer, |
| 26 GLsizei width, |
| 27 GLsizei height, |
| 28 GLenum inetrnalformat) override { |
| 29 return ++gen_images; |
| 30 } |
| 31 |
24 GLuint InsertSyncPointCHROMIUM() override { return ++sync_point; } | 32 GLuint InsertSyncPointCHROMIUM() override { return ++sync_point; } |
25 | 33 |
26 void GenMailboxCHROMIUM(GLbyte* mailbox) override { | 34 void GenMailboxCHROMIUM(GLbyte* mailbox) override { |
27 *reinterpret_cast<unsigned*>(mailbox) = ++this->mailbox; | 35 *reinterpret_cast<unsigned*>(mailbox) = ++this->mailbox; |
28 } | 36 } |
29 | 37 |
30 private: | 38 private: |
31 unsigned sync_point = 0u; | 39 unsigned sync_point = 0u; |
32 unsigned mailbox = 0u; | 40 unsigned mailbox = 0u; |
33 }; | 41 }; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 scoped_refptr<VideoFrame> frame; | 254 scoped_refptr<VideoFrame> frame; |
247 gpu_memory_buffer_pool_->MaybeCreateHardwareFrame( | 255 gpu_memory_buffer_pool_->MaybeCreateHardwareFrame( |
248 software_frame, base::Bind(MaybeCreateHardwareFrameCallback, &frame)); | 256 software_frame, base::Bind(MaybeCreateHardwareFrameCallback, &frame)); |
249 | 257 |
250 RunUntilIdle(); | 258 RunUntilIdle(); |
251 | 259 |
252 EXPECT_NE(software_frame.get(), frame.get()); | 260 EXPECT_NE(software_frame.get(), frame.get()); |
253 EXPECT_EQ(1u, gles2_->gen_textures); | 261 EXPECT_EQ(1u, gles2_->gen_textures); |
254 } | 262 } |
255 | 263 |
| 264 // AllocateGpuMemoryBuffer can return null (e.g: when the GPU process is down). |
| 265 // This test checks that in that case we don't crash and still create the |
| 266 // textures. |
| 267 // If we try to create another VideoFrame after the GPU process became active |
| 268 // again we should discard the previous created resources and create new ones. |
| 269 TEST_F(GpuMemoryBufferVideoFramePoolTest, AllocateGMBFail) { |
| 270 scoped_refptr<VideoFrame> software_frame = CreateTestYUVVideoFrame(10); |
| 271 scoped_refptr<MockGpuVideoAcceleratorFactories> mock_gpu_factories( |
| 272 new MockGpuVideoAcceleratorFactories); |
| 273 mock_gpu_factories->SetFailToAllocateGpuMemoryBuffer(true); |
| 274 scoped_ptr<GpuMemoryBufferVideoFramePool> gpu_memory_buffer_pool_ = |
| 275 make_scoped_ptr(new GpuMemoryBufferVideoFramePool( |
| 276 media_task_runner_, copy_task_runner_.get(), mock_gpu_factories)); |
| 277 |
| 278 EXPECT_CALL(*mock_gpu_factories.get(), GetGLES2Interface()) |
| 279 .WillRepeatedly(testing::Return(gles2_.get())); |
| 280 |
| 281 scoped_refptr<VideoFrame> frame; |
| 282 gpu_memory_buffer_pool_->MaybeCreateHardwareFrame( |
| 283 software_frame, base::Bind(MaybeCreateHardwareFrameCallback, &frame)); |
| 284 |
| 285 RunUntilIdle(); |
| 286 |
| 287 EXPECT_NE(software_frame.get(), frame.get()); |
| 288 EXPECT_EQ(3u, gles2_->gen_textures); |
| 289 EXPECT_EQ(0u, gles2_->gen_images); |
| 290 |
| 291 mock_gpu_factories->SetFailToAllocateGpuMemoryBuffer(false); |
| 292 gpu_memory_buffer_pool_->MaybeCreateHardwareFrame( |
| 293 software_frame, base::Bind(MaybeCreateHardwareFrameCallback, &frame)); |
| 294 |
| 295 RunUntilIdle(); |
| 296 EXPECT_NE(software_frame.get(), frame.get()); |
| 297 EXPECT_EQ(6u, gles2_->gen_textures); |
| 298 EXPECT_EQ(3u, gles2_->gen_images); |
| 299 } |
| 300 |
256 } // namespace media | 301 } // namespace media |
OLD | NEW |