OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gpu/browser_gpu_memory_buffer_manager.h" | 5 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return request.result.Pass(); | 119 return request.result.Pass(); |
120 } | 120 } |
121 | 121 |
122 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( | 122 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
123 const gfx::Size& size, | 123 const gfx::Size& size, |
124 gfx::GpuMemoryBuffer::Format format, | 124 gfx::GpuMemoryBuffer::Format format, |
125 gfx::GpuMemoryBuffer::Usage usage, | 125 gfx::GpuMemoryBuffer::Usage usage, |
126 base::ProcessHandle child_process_handle, | 126 base::ProcessHandle child_process_handle, |
127 int child_client_id, | 127 int child_client_id, |
128 const AllocationCallback& callback) { | 128 const AllocationCallback& callback) { |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
130 | 130 |
131 gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); | 131 gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); |
132 | 132 |
133 BufferMap& buffers = clients_[child_client_id]; | 133 BufferMap& buffers = clients_[child_client_id]; |
134 DCHECK(buffers.find(new_id) == buffers.end()); | 134 DCHECK(buffers.find(new_id) == buffers.end()); |
135 | 135 |
136 // Fallback to shared memory buffer if |format| and |usage| are not supported | 136 // Fallback to shared memory buffer if |format| and |usage| are not supported |
137 // by factory. | 137 // by factory. |
138 if (!gpu_memory_buffer_factory_host_->IsGpuMemoryBufferConfigurationSupported( | 138 if (!gpu_memory_buffer_factory_host_->IsGpuMemoryBufferConfigurationSupported( |
139 format, usage)) { | 139 format, usage)) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 uint32 sync_point) { | 175 uint32 sync_point) { |
176 static_cast<GpuMemoryBufferImpl*>(buffer) | 176 static_cast<GpuMemoryBufferImpl*>(buffer) |
177 ->set_destruction_sync_point(sync_point); | 177 ->set_destruction_sync_point(sync_point); |
178 } | 178 } |
179 | 179 |
180 void BrowserGpuMemoryBufferManager::ChildProcessDeletedGpuMemoryBuffer( | 180 void BrowserGpuMemoryBufferManager::ChildProcessDeletedGpuMemoryBuffer( |
181 gfx::GpuMemoryBufferId id, | 181 gfx::GpuMemoryBufferId id, |
182 base::ProcessHandle child_process_handle, | 182 base::ProcessHandle child_process_handle, |
183 int child_client_id, | 183 int child_client_id, |
184 uint32 sync_point) { | 184 uint32 sync_point) { |
185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 185 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
186 DCHECK(clients_.find(child_client_id) != clients_.end()); | 186 DCHECK(clients_.find(child_client_id) != clients_.end()); |
187 | 187 |
188 BufferMap& buffers = clients_[child_client_id]; | 188 BufferMap& buffers = clients_[child_client_id]; |
189 | 189 |
190 BufferMap::iterator buffer_it = buffers.find(id); | 190 BufferMap::iterator buffer_it = buffers.find(id); |
191 if (buffer_it == buffers.end()) { | 191 if (buffer_it == buffers.end()) { |
192 LOG(ERROR) << "Invalid GpuMemoryBuffer ID for child process."; | 192 LOG(ERROR) << "Invalid GpuMemoryBuffer ID for child process."; |
193 return; | 193 return; |
194 } | 194 } |
195 | 195 |
(...skipping 11 matching lines...) Expand all Loading... |
207 child_client_id, | 207 child_client_id, |
208 sync_point); | 208 sync_point); |
209 } | 209 } |
210 | 210 |
211 buffers.erase(buffer_it); | 211 buffers.erase(buffer_it); |
212 } | 212 } |
213 | 213 |
214 void BrowserGpuMemoryBufferManager::ProcessRemoved( | 214 void BrowserGpuMemoryBufferManager::ProcessRemoved( |
215 base::ProcessHandle process_handle, | 215 base::ProcessHandle process_handle, |
216 int client_id) { | 216 int client_id) { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 217 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
218 | 218 |
219 ClientMap::iterator client_it = clients_.find(client_id); | 219 ClientMap::iterator client_it = clients_.find(client_id); |
220 if (client_it == clients_.end()) | 220 if (client_it == clients_.end()) |
221 return; | 221 return; |
222 | 222 |
223 for (auto &buffer_it : client_it->second) { | 223 for (auto &buffer_it : client_it->second) { |
224 // This might happen if buffer is currenlty in the process of being | 224 // This might happen if buffer is currenlty in the process of being |
225 // allocated. The buffer will in that case be cleaned up when allocation | 225 // allocated. The buffer will in that case be cleaned up when allocation |
226 // completes. | 226 // completes. |
227 if (buffer_it.second == gfx::EMPTY_BUFFER) | 227 if (buffer_it.second == gfx::EMPTY_BUFFER) |
(...skipping 18 matching lines...) Expand all Loading... |
246 gpu_memory_buffer_factory_host_->CreateGpuMemoryBuffer( | 246 gpu_memory_buffer_factory_host_->CreateGpuMemoryBuffer( |
247 g_next_gpu_memory_buffer_id.GetNext(), request->size, request->format, | 247 g_next_gpu_memory_buffer_id.GetNext(), request->size, request->format, |
248 request->usage, request->client_id, request->surface_id, | 248 request->usage, request->client_id, request->surface_id, |
249 base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedOnIO, | 249 base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedOnIO, |
250 base::Unretained(this), base::Unretained(request))); | 250 base::Unretained(this), base::Unretained(request))); |
251 } | 251 } |
252 | 252 |
253 void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedOnIO( | 253 void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedOnIO( |
254 AllocateGpuMemoryBufferRequest* request, | 254 AllocateGpuMemoryBufferRequest* request, |
255 const gfx::GpuMemoryBufferHandle& handle) { | 255 const gfx::GpuMemoryBufferHandle& handle) { |
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 256 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
257 | 257 |
258 // Early out if factory failed to allocate the buffer. | 258 // Early out if factory failed to allocate the buffer. |
259 if (handle.is_null()) { | 259 if (handle.is_null()) { |
260 request->event.Signal(); | 260 request->event.Signal(); |
261 return; | 261 return; |
262 } | 262 } |
263 | 263 |
264 DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER); | 264 DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER); |
265 request->result = GpuMemoryBufferImpl::CreateFromHandle( | 265 request->result = GpuMemoryBufferImpl::CreateFromHandle( |
266 handle, | 266 handle, |
(...skipping 12 matching lines...) Expand all Loading... |
279 uint32 sync_point) { | 279 uint32 sync_point) { |
280 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(id, | 280 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(id, |
281 client_id, | 281 client_id, |
282 sync_point); | 282 sync_point); |
283 } | 283 } |
284 | 284 |
285 void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess( | 285 void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess( |
286 int child_client_id, | 286 int child_client_id, |
287 const AllocationCallback& callback, | 287 const AllocationCallback& callback, |
288 const gfx::GpuMemoryBufferHandle& handle) { | 288 const gfx::GpuMemoryBufferHandle& handle) { |
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 289 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
290 | 290 |
291 ClientMap::iterator client_it = clients_.find(child_client_id); | 291 ClientMap::iterator client_it = clients_.find(child_client_id); |
292 | 292 |
293 // This can happen if the child process is removed while the buffer is being | 293 // This can happen if the child process is removed while the buffer is being |
294 // allocated. | 294 // allocated. |
295 if (client_it == clients_.end()) { | 295 if (client_it == clients_.end()) { |
296 if (!handle.is_null()) { | 296 if (!handle.is_null()) { |
297 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer( | 297 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer( |
298 handle.id, child_client_id, 0); | 298 handle.id, child_client_id, 0); |
299 } | 299 } |
(...skipping 17 matching lines...) Expand all Loading... |
317 DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER); | 317 DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER); |
318 | 318 |
319 // Store the type of this buffer so it can be cleaned up if the child | 319 // Store the type of this buffer so it can be cleaned up if the child |
320 // process is removed. | 320 // process is removed. |
321 buffer_it->second = handle.type; | 321 buffer_it->second = handle.type; |
322 | 322 |
323 callback.Run(handle); | 323 callback.Run(handle); |
324 } | 324 } |
325 | 325 |
326 } // namespace content | 326 } // namespace content |
OLD | NEW |