| 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 "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 7 #include "content/browser/renderer_host/media/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 #include <utility> |
| 12 | 13 |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "cc/test/test_context_provider.h" | 20 #include "cc/test/test_context_provider.h" |
| 20 #include "cc/test/test_web_graphics_context_3d.h" | 21 #include "cc/test/test_web_graphics_context_3d.h" |
| 21 #include "content/browser/compositor/buffer_queue.h" | 22 #include "content/browser/compositor/buffer_queue.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void(int, int, const gfx::Rect&, const gfx::Rect&)); | 125 void(int, int, const gfx::Rect&, const gfx::Rect&)); |
| 125 }; | 126 }; |
| 126 #endif | 127 #endif |
| 127 | 128 |
| 128 // This is a generic Buffer tracker | 129 // This is a generic Buffer tracker |
| 129 class Buffer { | 130 class Buffer { |
| 130 public: | 131 public: |
| 131 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, | 132 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, |
| 132 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, | 133 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, |
| 133 int id) | 134 int id) |
| 134 : id_(id), pool_(pool), buffer_handle_(buffer_handle.Pass()) {} | 135 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} |
| 135 ~Buffer() { pool_->RelinquishProducerReservation(id()); } | 136 ~Buffer() { pool_->RelinquishProducerReservation(id()); } |
| 136 int id() const { return id_; } | 137 int id() const { return id_; } |
| 137 size_t mapped_size() { return buffer_handle_->mapped_size(); } | 138 size_t mapped_size() { return buffer_handle_->mapped_size(); } |
| 138 void* data() { return buffer_handle_->data(0); } | 139 void* data() { return buffer_handle_->data(0); } |
| 139 | 140 |
| 140 private: | 141 private: |
| 141 const int id_; | 142 const int id_; |
| 142 const scoped_refptr<VideoCaptureBufferPool> pool_; | 143 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 143 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; | 144 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; |
| 144 }; | 145 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 const int buffer_id = pool_->ReserveForProducer( | 177 const int buffer_id = pool_->ReserveForProducer( |
| 177 format_and_storage.pixel_format, format_and_storage.pixel_storage, | 178 format_and_storage.pixel_format, format_and_storage.pixel_storage, |
| 178 dimensions, &buffer_id_to_drop); | 179 dimensions, &buffer_id_to_drop); |
| 179 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 180 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 180 return scoped_ptr<Buffer>(); | 181 return scoped_ptr<Buffer>(); |
| 181 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); | 182 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); |
| 182 | 183 |
| 183 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle = | 184 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle = |
| 184 pool_->GetBufferHandle(buffer_id); | 185 pool_->GetBufferHandle(buffer_id); |
| 185 return scoped_ptr<Buffer>( | 186 return scoped_ptr<Buffer>( |
| 186 new Buffer(pool_, buffer_handle.Pass(), buffer_id)); | 187 new Buffer(pool_, std::move(buffer_handle), buffer_id)); |
| 187 } | 188 } |
| 188 | 189 |
| 189 base::MessageLoop loop_; | 190 base::MessageLoop loop_; |
| 190 int expected_dropped_id_; | 191 int expected_dropped_id_; |
| 191 scoped_refptr<VideoCaptureBufferPool> pool_; | 192 scoped_refptr<VideoCaptureBufferPool> pool_; |
| 192 | 193 |
| 193 private: | 194 private: |
| 194 #if !defined(OS_ANDROID) | 195 #if !defined(OS_ANDROID) |
| 195 scoped_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 196 scoped_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 196 scoped_ptr<MockBufferQueue> output_surface_; | 197 scoped_ptr<MockBufferQueue> output_surface_; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (buffer4->data() != nullptr) | 369 if (buffer4->data() != nullptr) |
| 369 memset(buffer4->data(), 0x77, buffer4->mapped_size()); | 370 memset(buffer4->data(), 0x77, buffer4->mapped_size()); |
| 370 buffer4.reset(); | 371 buffer4.reset(); |
| 371 } | 372 } |
| 372 | 373 |
| 373 INSTANTIATE_TEST_CASE_P(, | 374 INSTANTIATE_TEST_CASE_P(, |
| 374 VideoCaptureBufferPoolTest, | 375 VideoCaptureBufferPoolTest, |
| 375 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 376 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 376 | 377 |
| 377 } // namespace content | 378 } // namespace content |
| OLD | NEW |