OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/media/gpu_memory_buffer_tracker.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | |
9 #include "content/browser/renderer_host/media/gpu_memory_buffer_handle.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 #include "media/base/video_frame.h" | |
12 | |
13 namespace content { | |
14 | |
15 GpuMemoryBufferTracker::GpuMemoryBufferTracker() | |
16 : VideoCaptureBufferTracker() {} | |
17 | |
18 GpuMemoryBufferTracker::~GpuMemoryBufferTracker() { | |
19 for (const auto& gmb : gpu_memory_buffers_) | |
20 gmb->Unmap(); | |
21 } | |
22 | |
23 bool GpuMemoryBufferTracker::Init(const gfx::Size& dimensions, | |
24 media::VideoPixelFormat format, | |
25 media::VideoPixelStorage storage_type, | |
26 base::Lock* lock) { | |
27 DVLOG(2) << "allocating GMB for " << dimensions.ToString(); | |
28 // BrowserGpuMemoryBufferManager::current() may not be accessed on IO | |
29 // Thread. | |
30 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
31 DCHECK(BrowserGpuMemoryBufferManager::current()); | |
32 // This class is only expected to be called with I420 buffer requests at | |
33 // this point. | |
34 DCHECK_EQ(format, media::PIXEL_FORMAT_I420); | |
35 set_dimensions(dimensions); | |
36 set_max_pixel_count(dimensions.GetArea()); | |
37 set_pixel_format(format); | |
38 set_storage_type(storage_type); | |
39 // |dimensions| can be 0x0 for trackers that do not require memory backing. | |
40 if (dimensions.GetArea() == 0u) | |
41 return true; | |
42 | |
43 base::AutoUnlock auto_unlock(*lock); | |
44 const size_t num_planes = media::VideoFrame::NumPlanes(pixel_format()); | |
45 for (size_t i = 0; i < num_planes; ++i) { | |
46 const gfx::Size& size = | |
47 media::VideoFrame::PlaneSize(pixel_format(), i, dimensions); | |
48 gpu_memory_buffers_.push_back( | |
49 BrowserGpuMemoryBufferManager::current()->AllocateGpuMemoryBuffer( | |
50 size, gfx::BufferFormat::R_8, | |
51 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
52 gpu::kNullSurfaceHandle)); | |
53 | |
54 DLOG_IF(ERROR, !gpu_memory_buffers_[i]) << "Allocating GpuMemoryBuffer"; | |
55 if (!gpu_memory_buffers_[i] || !gpu_memory_buffers_[i]->Map()) | |
56 return false; | |
57 } | |
58 return true; | |
59 } | |
60 | |
61 std::unique_ptr<VideoCaptureBufferHandle> | |
62 GpuMemoryBufferTracker::GetBufferHandle() { | |
63 DCHECK_EQ(gpu_memory_buffers_.size(), | |
64 media::VideoFrame::NumPlanes(pixel_format())); | |
65 return base::MakeUnique<GpuMemoryBufferBufferHandle>(this); | |
66 } | |
67 | |
68 bool GpuMemoryBufferTracker::ShareToProcess( | |
69 base::ProcessHandle process_handle, | |
70 base::SharedMemoryHandle* new_handle) { | |
71 NOTREACHED(); | |
72 return false; | |
73 } | |
74 | |
75 bool GpuMemoryBufferTracker::ShareToProcess2( | |
76 int plane, | |
77 base::ProcessHandle process_handle, | |
78 gfx::GpuMemoryBufferHandle* new_handle) { | |
79 DCHECK_LE(plane, static_cast<int>(gpu_memory_buffers_.size())); | |
80 | |
81 const auto& current_gmb_handle = gpu_memory_buffers_[plane]->GetHandle(); | |
82 switch (current_gmb_handle.type) { | |
83 case gfx::EMPTY_BUFFER: | |
84 NOTREACHED(); | |
85 return false; | |
86 case gfx::SHARED_MEMORY_BUFFER: { | |
87 DCHECK(base::SharedMemory::IsHandleValid(current_gmb_handle.handle)); | |
88 base::SharedMemory shared_memory( | |
89 base::SharedMemory::DuplicateHandle(current_gmb_handle.handle), | |
90 false); | |
91 shared_memory.ShareToProcess(process_handle, &new_handle->handle); | |
92 DCHECK(base::SharedMemory::IsHandleValid(new_handle->handle)); | |
93 new_handle->type = gfx::SHARED_MEMORY_BUFFER; | |
94 return true; | |
95 } | |
96 case gfx::IO_SURFACE_BUFFER: | |
97 case gfx::SURFACE_TEXTURE_BUFFER: | |
mcasas
2016/09/20 00:51:07
https://codereview.chromium.org/2353453002/ is rem
chfremer
2016/09/20 18:43:09
Thanks for the heads up.
It seems I am unable to r
| |
98 case gfx::OZONE_NATIVE_PIXMAP: | |
99 *new_handle = current_gmb_handle; | |
100 return true; | |
101 } | |
102 NOTREACHED(); | |
103 return true; | |
104 } | |
105 | |
106 } // namespace content | |
OLD | NEW |