| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // Unit test for VideoCaptureBufferPool. | 5 // Unit test for VideoCaptureBufferPool. |
| 6 | 6 |
| 7 #include "media/capture/video/video_capture_buffer_pool.h" | 7 #include "media/capture/video/video_capture_buffer_pool.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "cc/test/test_context_provider.h" | 23 #include "cc/test/test_context_provider.h" |
| 24 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
| 25 #include "components/display_compositor/buffer_queue.h" | 25 #include "components/display_compositor/buffer_queue.h" |
| 26 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | |
| 27 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto
ry_impl.h" | 26 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto
ry_impl.h" |
| 28 #include "content/browser/renderer_host/media/video_capture_controller.h" | 27 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 29 #include "media/base/video_frame.h" | 28 #include "media/base/video_frame.h" |
| 30 #include "media/capture/video/video_capture_buffer_pool_impl.h" | 29 #include "media/capture/video/video_capture_buffer_pool_impl.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 32 |
| 34 namespace content { | 33 namespace content { |
| 35 | 34 |
| 36 struct PixelFormatAndStorage { | 35 struct PixelFormatAndStorage { |
| 37 media::VideoPixelFormat pixel_format; | 36 media::VideoPixelFormat pixel_format; |
| 38 media::VideoPixelStorage pixel_storage; | 37 media::VideoPixelStorage pixel_storage; |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = { | 40 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = { |
| 42 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU}, | 41 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU}, |
| 43 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU}, | 42 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU}, |
| 44 #if !defined(OS_ANDROID) | |
| 45 {media::PIXEL_FORMAT_I420, | |
| 46 media::PIXEL_STORAGE_GPUMEMORYBUFFER}, | |
| 47 #endif | |
| 48 }; | 43 }; |
| 49 | 44 |
| 50 static const int kTestBufferPoolSize = 3; | 45 static const int kTestBufferPoolSize = 3; |
| 51 | 46 |
| 52 // Note that this test does not exercise the class VideoCaptureBufferPool | 47 // Note that this test does not exercise the class VideoCaptureBufferPool |
| 53 // in isolation. The "unit under test" is an instance of VideoCaptureBufferPool | 48 // in isolation. The "unit under test" is an instance of VideoCaptureBufferPool |
| 54 // with some context that is specific to renderer_host/media, and therefore | 49 // with some context that is specific to renderer_host/media, and therefore |
| 55 // this test must live here and not in media/capture/video. | 50 // this test must live here and not in media/capture/video. |
| 56 class VideoCaptureBufferPoolTest | 51 class VideoCaptureBufferPoolTest |
| 57 : public testing::TestWithParam<PixelFormatAndStorage> { | 52 : public testing::TestWithParam<PixelFormatAndStorage> { |
| 58 protected: | 53 protected: |
| 59 // A GpuMemoryBuffer Mock to provide a trivial RGBA buffer as Map() backing. | |
| 60 // We need to allocate on ctor and deallocate on dtor so that consecutive | |
| 61 // Map()-Unmap() cycles yield the same underlying data pointer. | |
| 62 class MockGpuMemoryBuffer : public gfx::GpuMemoryBuffer { | |
| 63 public: | |
| 64 explicit MockGpuMemoryBuffer(const gfx::Size& size) | |
| 65 : size_(size), | |
| 66 data_(new uint8_t[size_.GetArea() * 4]), | |
| 67 mapped_(false) {} | |
| 68 ~MockGpuMemoryBuffer() override { delete[] data_; } | |
| 69 | |
| 70 bool Map() override { | |
| 71 EXPECT_FALSE(mapped_); | |
| 72 mapped_ = true; | |
| 73 return true; | |
| 74 } | |
| 75 void* memory(size_t plane) override { | |
| 76 EXPECT_TRUE(mapped_); | |
| 77 EXPECT_EQ(0u, plane); | |
| 78 return static_cast<void*>(data_); | |
| 79 } | |
| 80 void Unmap() override { | |
| 81 EXPECT_TRUE(mapped_); | |
| 82 mapped_ = false; | |
| 83 } | |
| 84 gfx::Size GetSize() const override { return size_; } | |
| 85 gfx::BufferFormat GetFormat() const override { | |
| 86 return gfx::BufferFormat::BGRA_8888; | |
| 87 } | |
| 88 int stride(size_t plane) const override { | |
| 89 EXPECT_EQ(0u, plane); | |
| 90 return size_.width() * 4; | |
| 91 } | |
| 92 gfx::GpuMemoryBufferId GetId() const override { | |
| 93 return gfx::GpuMemoryBufferId(0); | |
| 94 } | |
| 95 gfx::GpuMemoryBufferHandle GetHandle() const override { | |
| 96 return gfx::GpuMemoryBufferHandle(); | |
| 97 } | |
| 98 ClientBuffer AsClientBuffer() override { return nullptr; } | |
| 99 | |
| 100 private: | |
| 101 const gfx::Size size_; | |
| 102 uint8_t* const data_; | |
| 103 bool mapped_; | |
| 104 }; | |
| 105 | |
| 106 #if !defined(OS_ANDROID) | |
| 107 // The next two classes are needed to replicate the GpuMemoryBuffer allocation | |
| 108 // on Browser side. | |
| 109 class StubBrowserGpuMemoryBufferManager | |
| 110 : public BrowserGpuMemoryBufferManager { | |
| 111 public: | |
| 112 StubBrowserGpuMemoryBufferManager() : BrowserGpuMemoryBufferManager(1, 1) {} | |
| 113 | |
| 114 std::unique_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer( | |
| 115 const gfx::Size& size, | |
| 116 gfx::BufferFormat format, | |
| 117 gfx::BufferUsage usage, | |
| 118 gpu::SurfaceHandle surface_handle) override { | |
| 119 return base::MakeUnique<MockGpuMemoryBuffer>(size); | |
| 120 } | |
| 121 }; | |
| 122 #endif | |
| 123 | |
| 124 // This is a generic Buffer tracker | 54 // This is a generic Buffer tracker |
| 125 class Buffer { | 55 class Buffer { |
| 126 public: | 56 public: |
| 127 Buffer(const scoped_refptr<media::VideoCaptureBufferPool> pool, | 57 Buffer(const scoped_refptr<media::VideoCaptureBufferPool> pool, |
| 128 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle, | 58 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle, |
| 129 int id) | 59 int id) |
| 130 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} | 60 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} |
| 131 ~Buffer() { pool_->RelinquishProducerReservation(id()); } | 61 ~Buffer() { pool_->RelinquishProducerReservation(id()); } |
| 132 int id() const { return id_; } | 62 int id() const { return id_; } |
| 133 size_t mapped_size() { return buffer_handle_->mapped_size(); } | 63 size_t mapped_size() { return buffer_handle_->mapped_size(); } |
| 134 void* data() { return buffer_handle_->data(0); } | 64 void* data() { return buffer_handle_->data(0); } |
| 135 | 65 |
| 136 private: | 66 private: |
| 137 const int id_; | 67 const int id_; |
| 138 const scoped_refptr<media::VideoCaptureBufferPool> pool_; | 68 const scoped_refptr<media::VideoCaptureBufferPool> pool_; |
| 139 const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_; | 69 const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_; |
| 140 }; | 70 }; |
| 141 | 71 |
| 142 VideoCaptureBufferPoolTest() | 72 VideoCaptureBufferPoolTest() |
| 143 : expected_dropped_id_(0), | 73 : expected_dropped_id_(0), |
| 144 pool_(new media::VideoCaptureBufferPoolImpl( | 74 pool_(new media::VideoCaptureBufferPoolImpl( |
| 145 base::MakeUnique<VideoCaptureBufferTrackerFactoryImpl>(), | 75 base::MakeUnique<VideoCaptureBufferTrackerFactoryImpl>(), |
| 146 kTestBufferPoolSize)) {} | 76 kTestBufferPoolSize)) {} |
| 147 | 77 |
| 148 #if !defined(OS_ANDROID) | |
| 149 void SetUp() override { | |
| 150 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); | |
| 151 } | |
| 152 #endif | |
| 153 | |
| 154 void ExpectDroppedId(int expected_dropped_id) { | 78 void ExpectDroppedId(int expected_dropped_id) { |
| 155 expected_dropped_id_ = expected_dropped_id; | 79 expected_dropped_id_ = expected_dropped_id; |
| 156 } | 80 } |
| 157 | 81 |
| 158 std::unique_ptr<Buffer> ReserveBuffer( | 82 std::unique_ptr<Buffer> ReserveBuffer( |
| 159 const gfx::Size& dimensions, | 83 const gfx::Size& dimensions, |
| 160 PixelFormatAndStorage format_and_storage) { | 84 PixelFormatAndStorage format_and_storage) { |
| 161 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, | 85 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, |
| 162 // initialize it to something different than the expected value. | 86 // initialize it to something different than the expected value. |
| 163 int buffer_id_to_drop = ~expected_dropped_id_; | 87 int buffer_id_to_drop = ~expected_dropped_id_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 188 return std::unique_ptr<Buffer>(); | 112 return std::unique_ptr<Buffer>(); |
| 189 return std::unique_ptr<Buffer>( | 113 return std::unique_ptr<Buffer>( |
| 190 new Buffer(pool_, pool_->GetBufferHandle(buffer_id), buffer_id)); | 114 new Buffer(pool_, pool_->GetBufferHandle(buffer_id), buffer_id)); |
| 191 } | 115 } |
| 192 | 116 |
| 193 base::MessageLoop loop_; | 117 base::MessageLoop loop_; |
| 194 int expected_dropped_id_; | 118 int expected_dropped_id_; |
| 195 scoped_refptr<media::VideoCaptureBufferPool> pool_; | 119 scoped_refptr<media::VideoCaptureBufferPool> pool_; |
| 196 | 120 |
| 197 private: | 121 private: |
| 198 #if !defined(OS_ANDROID) | |
| 199 std::unique_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; | |
| 200 #endif | |
| 201 | |
| 202 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); | 122 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); |
| 203 }; | 123 }; |
| 204 | 124 |
| 205 TEST_P(VideoCaptureBufferPoolTest, BufferPool) { | 125 TEST_P(VideoCaptureBufferPoolTest, BufferPool) { |
| 206 const gfx::Size size_lo = gfx::Size(10, 10); | 126 const gfx::Size size_lo = gfx::Size(10, 10); |
| 207 const gfx::Size size_hi = gfx::Size(21, 33); | 127 const gfx::Size size_hi = gfx::Size(21, 33); |
| 208 const media::VideoCaptureFormat format_lo( | 128 const media::VideoCaptureFormat format_lo( |
| 209 size_lo, 0.0, GetParam().pixel_format, GetParam().pixel_storage); | 129 size_lo, 0.0, GetParam().pixel_format, GetParam().pixel_storage); |
| 210 const media::VideoCaptureFormat format_hi( | 130 const media::VideoCaptureFormat format_hi( |
| 211 size_hi, 0.0, GetParam().pixel_format, GetParam().pixel_storage); | 131 size_hi, 0.0, GetParam().pixel_format, GetParam().pixel_storage); |
| 212 | 132 |
| 213 // Reallocation won't happen for the first part of the test. | 133 // Reallocation won't happen for the first part of the test. |
| 214 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); | 134 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 215 | 135 |
| 216 // The buffer pool should have zero utilization before any buffers have been | 136 // The buffer pool should have zero utilization before any buffers have been |
| 217 // reserved. | 137 // reserved. |
| 218 ASSERT_EQ(0.0, pool_->GetBufferPoolUtilization()); | 138 ASSERT_EQ(0.0, pool_->GetBufferPoolUtilization()); |
| 219 | 139 |
| 220 std::unique_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam()); | 140 std::unique_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam()); |
| 221 ASSERT_NE(nullptr, buffer1.get()); | 141 ASSERT_NE(nullptr, buffer1.get()); |
| 222 ASSERT_EQ(1.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 142 ASSERT_EQ(1.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 223 std::unique_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam()); | 143 std::unique_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam()); |
| 224 ASSERT_NE(nullptr, buffer2.get()); | 144 ASSERT_NE(nullptr, buffer2.get()); |
| 225 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 145 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 226 std::unique_ptr<Buffer> buffer3 = ReserveBuffer(size_lo, GetParam()); | 146 std::unique_ptr<Buffer> buffer3 = ReserveBuffer(size_lo, GetParam()); |
| 227 ASSERT_NE(nullptr, buffer3.get()); | 147 ASSERT_NE(nullptr, buffer3.get()); |
| 228 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 148 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 229 | 149 |
| 230 // GMB backed frames have their platform and format specific allocations. | 150 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->mapped_size()); |
| 231 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) { | 151 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); |
| 232 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->mapped_size()); | 152 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->mapped_size()); |
| 233 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); | |
| 234 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->mapped_size()); | |
| 235 } | |
| 236 | 153 |
| 237 ASSERT_NE(nullptr, buffer1->data()); | 154 ASSERT_NE(nullptr, buffer1->data()); |
| 238 ASSERT_NE(nullptr, buffer2->data()); | 155 ASSERT_NE(nullptr, buffer2->data()); |
| 239 ASSERT_NE(nullptr, buffer3->data()); | 156 ASSERT_NE(nullptr, buffer3->data()); |
| 240 | 157 |
| 241 // Touch the memory. | 158 // Touch the memory. |
| 242 if (buffer1->data() != nullptr) | 159 if (buffer1->data() != nullptr) |
| 243 memset(buffer1->data(), 0x11, buffer1->mapped_size()); | 160 memset(buffer1->data(), 0x11, buffer1->mapped_size()); |
| 244 if (buffer2->data() != nullptr) | 161 if (buffer2->data() != nullptr) |
| 245 memset(buffer2->data(), 0x44, buffer2->mapped_size()); | 162 memset(buffer2->data(), 0x44, buffer2->mapped_size()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 245 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; |
| 329 ASSERT_EQ(1.0, pool_->GetBufferPoolUtilization()); | 246 ASSERT_EQ(1.0, pool_->GetBufferPoolUtilization()); |
| 330 | 247 |
| 331 // Now try reallocation with different resolutions. We expect reallocation | 248 // Now try reallocation with different resolutions. We expect reallocation |
| 332 // to occur only when the old buffer is too small. | 249 // to occur only when the old buffer is too small. |
| 333 buffer2.reset(); | 250 buffer2.reset(); |
| 334 ExpectDroppedId(buffer_id2); | 251 ExpectDroppedId(buffer_id2); |
| 335 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 252 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 336 buffer2 = ReserveBuffer(size_hi, GetParam()); | 253 buffer2 = ReserveBuffer(size_hi, GetParam()); |
| 337 ASSERT_NE(nullptr, buffer2.get()); | 254 ASSERT_NE(nullptr, buffer2.get()); |
| 338 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) | 255 ASSERT_LE(format_hi.ImageAllocationSize(), buffer2->mapped_size()); |
| 339 ASSERT_LE(format_hi.ImageAllocationSize(), buffer2->mapped_size()); | |
| 340 ASSERT_EQ(3, buffer2->id()); | 256 ASSERT_EQ(3, buffer2->id()); |
| 341 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 257 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 342 void* const memory_pointer_hi = buffer2->data(); | 258 void* const memory_pointer_hi = buffer2->data(); |
| 343 buffer2.reset(); // Frees it. | 259 buffer2.reset(); // Frees it. |
| 344 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); | 260 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 345 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 261 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 346 buffer2 = ReserveBuffer(size_lo, GetParam()); | 262 buffer2 = ReserveBuffer(size_lo, GetParam()); |
| 347 void* const memory_pointer_lo = buffer2->data(); | 263 void* const memory_pointer_lo = buffer2->data(); |
| 348 ASSERT_EQ(memory_pointer_hi, memory_pointer_lo) | 264 ASSERT_EQ(memory_pointer_hi, memory_pointer_lo) |
| 349 << "Decrease in resolution should not reallocate buffer"; | 265 << "Decrease in resolution should not reallocate buffer"; |
| 350 ASSERT_NE(nullptr, buffer2.get()); | 266 ASSERT_NE(nullptr, buffer2.get()); |
| 351 ASSERT_EQ(3, buffer2->id()); | 267 ASSERT_EQ(3, buffer2->id()); |
| 352 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) | 268 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); |
| 353 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); | |
| 354 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 269 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 355 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 270 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; |
| 356 ASSERT_EQ(1.0, pool_->GetBufferPoolUtilization()); | 271 ASSERT_EQ(1.0, pool_->GetBufferPoolUtilization()); |
| 357 | 272 |
| 358 // Tear down the pool_, writing into the buffers. The buffer should preserve | 273 // Tear down the pool_, writing into the buffers. The buffer should preserve |
| 359 // the lifetime of the underlying memory. | 274 // the lifetime of the underlying memory. |
| 360 buffer3.reset(); | 275 buffer3.reset(); |
| 361 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 276 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 362 pool_ = NULL; | 277 pool_ = NULL; |
| 363 | 278 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // match. | 355 // match. |
| 441 PixelFormatAndStorage altered_format_or_storage = GetParam(); | 356 PixelFormatAndStorage altered_format_or_storage = GetParam(); |
| 442 altered_format_or_storage.pixel_format = | 357 altered_format_or_storage.pixel_format = |
| 443 (altered_format_or_storage.pixel_format == media::PIXEL_FORMAT_I420 | 358 (altered_format_or_storage.pixel_format == media::PIXEL_FORMAT_I420 |
| 444 ? media::PIXEL_FORMAT_ARGB | 359 ? media::PIXEL_FORMAT_ARGB |
| 445 : media::PIXEL_FORMAT_I420); | 360 : media::PIXEL_FORMAT_I420); |
| 446 resurrected = | 361 resurrected = |
| 447 ResurrectLastBuffer(gfx::Size(10, 10), altered_format_or_storage); | 362 ResurrectLastBuffer(gfx::Size(10, 10), altered_format_or_storage); |
| 448 ASSERT_EQ(nullptr, resurrected.get()); | 363 ASSERT_EQ(nullptr, resurrected.get()); |
| 449 | 364 |
| 450 // Expect that the buffer cannot be resurrected if the pixel storage does not | |
| 451 // match. | |
| 452 altered_format_or_storage = GetParam(); | |
| 453 altered_format_or_storage.pixel_storage = | |
| 454 (altered_format_or_storage.pixel_storage == media::PIXEL_STORAGE_CPU) | |
| 455 ? media::PIXEL_STORAGE_GPUMEMORYBUFFER | |
| 456 : media::PIXEL_STORAGE_CPU; | |
| 457 resurrected = | |
| 458 ResurrectLastBuffer(gfx::Size(10, 10), altered_format_or_storage); | |
| 459 ASSERT_EQ(nullptr, resurrected.get()); | |
| 460 | |
| 461 // Finally, check that the buffer CAN be resurrected if all properties match. | 365 // Finally, check that the buffer CAN be resurrected if all properties match. |
| 462 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 366 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 463 ASSERT_NE(nullptr, resurrected.get()); | 367 ASSERT_NE(nullptr, resurrected.get()); |
| 464 ASSERT_EQ(original_mapped_size, resurrected->mapped_size()); | 368 ASSERT_EQ(original_mapped_size, resurrected->mapped_size()); |
| 465 uint8_t* resurrected_memory = reinterpret_cast<uint8_t*>(resurrected->data()); | 369 uint8_t* resurrected_memory = reinterpret_cast<uint8_t*>(resurrected->data()); |
| 466 for (size_t i = 0; i < original_mapped_size; ++i) | 370 for (size_t i = 0; i < original_mapped_size; ++i) |
| 467 EXPECT_EQ(0xcd, resurrected_memory[i]) << "Mismatch at byte offset: " << i; | 371 EXPECT_EQ(0xcd, resurrected_memory[i]) << "Mismatch at byte offset: " << i; |
| 468 } | 372 } |
| 469 | 373 |
| 470 // Tests that the buffers are managed by the pool such that the last-released | 374 // Tests that the buffers are managed by the pool such that the last-released |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 ASSERT_NE(nullptr, held_buffers.back().get()); | 407 ASSERT_NE(nullptr, held_buffers.back().get()); |
| 504 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 408 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 505 ASSERT_EQ(nullptr, resurrected.get()); | 409 ASSERT_EQ(nullptr, resurrected.get()); |
| 506 } | 410 } |
| 507 | 411 |
| 508 INSTANTIATE_TEST_CASE_P(, | 412 INSTANTIATE_TEST_CASE_P(, |
| 509 VideoCaptureBufferPoolTest, | 413 VideoCaptureBufferPoolTest, |
| 510 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 414 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 511 | 415 |
| 512 } // namespace content | 416 } // namespace content |
| OLD | NEW |