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 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 5 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | |
10 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
11 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 10 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
13 #include "ui/gfx/buffer_format_util.h" | 12 #include "ui/gfx/buffer_format_util.h" |
14 | 13 |
15 namespace content { | 14 namespace content { |
16 | 15 |
17 const int VideoCaptureBufferPool::kInvalidId = -1; | 16 const int VideoCaptureBufferPool::kInvalidId = -1; |
18 | 17 |
19 // A simple holder of a memory-backed buffer and accessors to it. | 18 // A simple holder of a memory-backed buffer and accessors to it. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const base::SharedMemoryHandle handle_; | 57 const base::SharedMemoryHandle handle_; |
59 #endif | 58 #endif |
60 }; | 59 }; |
61 | 60 |
62 // A holder of a GpuMemoryBuffer-backed buffer. Holds weak references to | 61 // A holder of a GpuMemoryBuffer-backed buffer. Holds weak references to |
63 // GpuMemoryBuffer-backed buffers and provides accessors to their data. | 62 // GpuMemoryBuffer-backed buffers and provides accessors to their data. |
64 class GpuMemoryBufferBufferHandle final | 63 class GpuMemoryBufferBufferHandle final |
65 : public VideoCaptureBufferPool::BufferHandle { | 64 : public VideoCaptureBufferPool::BufferHandle { |
66 public: | 65 public: |
67 GpuMemoryBufferBufferHandle(const gfx::Size& dimensions, | 66 GpuMemoryBufferBufferHandle(const gfx::Size& dimensions, |
68 ScopedVector<gfx::GpuMemoryBuffer>* gmbs) | 67 std::vector< |
| 68 scoped_ptr<gfx::GpuMemoryBuffer>>* gmbs) |
69 : dimensions_(dimensions), gmbs_(gmbs) { | 69 : dimensions_(dimensions), gmbs_(gmbs) { |
70 DCHECK(gmbs); | 70 DCHECK(gmbs); |
71 } | 71 } |
72 ~GpuMemoryBufferBufferHandle() override {} | 72 ~GpuMemoryBufferBufferHandle() override {} |
73 | 73 |
74 gfx::Size dimensions() const override { return dimensions_; } | 74 gfx::Size dimensions() const override { return dimensions_; } |
75 size_t mapped_size() const override { return dimensions_.GetArea(); } | 75 size_t mapped_size() const override { return dimensions_.GetArea(); } |
76 void* data(int plane) override { | 76 void* data(int plane) override { |
77 DCHECK_GE(plane, 0); | 77 DCHECK_GE(plane, 0); |
78 DCHECK_LT(plane, static_cast<int>(gmbs_->size())); | 78 DCHECK_LT(plane, static_cast<int>(gmbs_->size())); |
79 DCHECK((*gmbs_)[plane]); | 79 DCHECK((*gmbs_)[plane]); |
80 return (*gmbs_)[plane]->memory(0); | 80 return (*gmbs_)[plane]->memory(0); |
81 } | 81 } |
82 ClientBuffer AsClientBuffer(int plane) override { | 82 ClientBuffer AsClientBuffer(int plane) override { |
83 DCHECK_GE(plane, 0); | 83 DCHECK_GE(plane, 0); |
84 DCHECK_LT(plane, static_cast<int>(gmbs_->size())); | 84 DCHECK_LT(plane, static_cast<int>(gmbs_->size())); |
85 return (*gmbs_)[plane]->AsClientBuffer(); | 85 return (*gmbs_)[plane]->AsClientBuffer(); |
86 } | 86 } |
87 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 87 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
88 base::FileDescriptor AsPlatformFile() override { | 88 base::FileDescriptor AsPlatformFile() override { |
89 NOTREACHED(); | 89 NOTREACHED(); |
90 return base::FileDescriptor(); | 90 return base::FileDescriptor(); |
91 } | 91 } |
92 #endif | 92 #endif |
93 | 93 |
94 private: | 94 private: |
95 const gfx::Size dimensions_; | 95 const gfx::Size dimensions_; |
96 ScopedVector<gfx::GpuMemoryBuffer>* const gmbs_; | 96 std::vector<scoped_ptr<gfx::GpuMemoryBuffer>>* const gmbs_; |
97 }; | 97 }; |
98 | 98 |
99 // Tracker specifics for SharedMemory. | 99 // Tracker specifics for SharedMemory. |
100 class VideoCaptureBufferPool::SharedMemTracker final : public Tracker { | 100 class VideoCaptureBufferPool::SharedMemTracker final : public Tracker { |
101 public: | 101 public: |
102 SharedMemTracker(); | 102 SharedMemTracker(); |
103 bool Init(media::VideoPixelFormat format, | 103 bool Init(media::VideoPixelFormat format, |
104 media::VideoPixelStorage storage_type, | 104 media::VideoPixelStorage storage_type, |
105 const gfx::Size& dimensions, | 105 const gfx::Size& dimensions, |
106 base::Lock* lock) override; | 106 base::Lock* lock) override; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 NOTREACHED(); | 148 NOTREACHED(); |
149 return false; | 149 return false; |
150 } | 150 } |
151 bool ShareToProcess2(int plane, | 151 bool ShareToProcess2(int plane, |
152 base::ProcessHandle process_handle, | 152 base::ProcessHandle process_handle, |
153 gfx::GpuMemoryBufferHandle* new_handle) override; | 153 gfx::GpuMemoryBufferHandle* new_handle) override; |
154 | 154 |
155 private: | 155 private: |
156 gfx::Size dimensions_; | 156 gfx::Size dimensions_; |
157 // Owned references to GpuMemoryBuffers. | 157 // Owned references to GpuMemoryBuffers. |
158 ScopedVector<gfx::GpuMemoryBuffer> gpu_memory_buffers_; | 158 std::vector<scoped_ptr<gfx::GpuMemoryBuffer>> gpu_memory_buffers_; |
159 }; | 159 }; |
160 | 160 |
161 VideoCaptureBufferPool::SharedMemTracker::SharedMemTracker() : Tracker() {} | 161 VideoCaptureBufferPool::SharedMemTracker::SharedMemTracker() : Tracker() {} |
162 | 162 |
163 bool VideoCaptureBufferPool::SharedMemTracker::Init( | 163 bool VideoCaptureBufferPool::SharedMemTracker::Init( |
164 media::VideoPixelFormat format, | 164 media::VideoPixelFormat format, |
165 media::VideoPixelStorage storage_type, | 165 media::VideoPixelStorage storage_type, |
166 const gfx::Size& dimensions, | 166 const gfx::Size& dimensions, |
167 base::Lock* lock) { | 167 base::Lock* lock) { |
168 DVLOG(2) << "allocating ShMem of " << dimensions.ToString(); | 168 DVLOG(2) << "allocating ShMem of " << dimensions.ToString(); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 return buffer_id; | 455 return buffer_id; |
456 } | 456 } |
457 | 457 |
458 VideoCaptureBufferPool::Tracker* VideoCaptureBufferPool::GetTracker( | 458 VideoCaptureBufferPool::Tracker* VideoCaptureBufferPool::GetTracker( |
459 int buffer_id) { | 459 int buffer_id) { |
460 TrackerMap::const_iterator it = trackers_.find(buffer_id); | 460 TrackerMap::const_iterator it = trackers_.find(buffer_id); |
461 return (it == trackers_.end()) ? NULL : it->second; | 461 return (it == trackers_.end()) ? NULL : it->second; |
462 } | 462 } |
463 | 463 |
464 } // namespace content | 464 } // namespace content |
OLD | NEW |