Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: content/common/gpu/client/gpu_channel_host.cc

Issue 654223006: Cleanup GpuMemoryBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/gpu/client/gpu_channel_host.h" 5 #include "content/common/gpu/client/gpu_channel_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/barrier_closure.h"
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/posix/eintr_wrapper.h" 14 #include "base/posix/eintr_wrapper.h"
14 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
15 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 16 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
16 #include "content/common/gpu/gpu_messages.h" 17 #include "content/common/gpu/gpu_messages.h"
17 #include "ipc/ipc_sync_message_filter.h" 18 #include "ipc/ipc_sync_message_filter.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
(...skipping 24 matching lines...) Expand all
43 host->Connect(channel_handle, shutdown_event); 44 host->Connect(channel_handle, shutdown_event);
44 return host; 45 return host;
45 } 46 }
46 47
47 GpuChannelHost::GpuChannelHost( 48 GpuChannelHost::GpuChannelHost(
48 GpuChannelHostFactory* factory, 49 GpuChannelHostFactory* factory,
49 const gpu::GPUInfo& gpu_info, 50 const gpu::GPUInfo& gpu_info,
50 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager) 51 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager)
51 : factory_(factory), 52 : factory_(factory),
52 gpu_info_(gpu_info), 53 gpu_info_(gpu_info),
53 gpu_memory_buffer_manager_(gpu_memory_buffer_manager) { 54 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
55 next_signal_id_(0) {
54 next_transfer_buffer_id_.GetNext(); 56 next_transfer_buffer_id_.GetNext();
55 next_image_id_.GetNext(); 57 next_image_id_.GetNext();
56 next_route_id_.GetNext(); 58 next_route_id_.GetNext();
57 } 59 }
58 60
59 void GpuChannelHost::Connect(const IPC::ChannelHandle& channel_handle, 61 void GpuChannelHost::Connect(const IPC::ChannelHandle& channel_handle,
60 base::WaitableEvent* shutdown_event) { 62 base::WaitableEvent* shutdown_event) {
61 // Open a channel to the GPU process. We pass NULL as the main listener here 63 // Open a channel to the GPU process. We pass NULL as the main listener here
62 // since we need to filter everything to route it to the right thread. 64 // since we need to filter everything to route it to the right thread.
63 scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); 65 scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy();
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 314 }
313 315
314 int32 GpuChannelHost::ReserveImageId() { 316 int32 GpuChannelHost::ReserveImageId() {
315 return next_image_id_.GetNext(); 317 return next_image_id_.GetNext();
316 } 318 }
317 319
318 int32 GpuChannelHost::GenerateRouteID() { 320 int32 GpuChannelHost::GenerateRouteID() {
319 return next_route_id_.GetNext(); 321 return next_route_id_.GetNext();
320 } 322 }
321 323
324 void GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToComplete(
325 const base::Closure& callback) {
326 AutoLock lock(signal_lock_);
327 uint32 signal_id = next_signal_id_++;
328 signal_tasks_.insert(std::make_pair(signal_id, callback));
329
330 base::Closure proxy_barrier_closure = base::BarrierClosure(
331 proxies_.size(),
332 base::Bind(&GpuChannelHost::GpuMemoryBufferWaitCompleted,
333 base::Unretained(this),
reveman 2014/10/22 22:42:47 is this safe?
334 signal_id,
335 base::MessageLoopProxy::current()));
336 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); it++) {
337 it->second->WaitForPendingGpuMemoryBufferUsageToComplete(
338 proxy_barrier_closure);
339 }
340 }
341
342 void GpuChannelHost::GpuMemoryBufferWaitCompleted(
reveman 2014/10/22 22:42:47 GpuMemoryBufferUsageCompleted
343 uint32 id,
344 scoped_refptr<base::MessageLoopProxy> caller_message_loop) {
345 caller_message_loop->PostTask(
346 FROM_HERE,
347 base::Bind(&GpuChannelHost::GpuMemoryBufferWaitCompletedOnCallerThread,
348 base::Unretained(this),
reveman 2014/10/22 22:42:47 is this safe? what if the GpuChannelHost is delete
349 id));
350 }
351
352 void GpuChannelHost::GpuMemoryBufferWaitCompletedOnCallerThread(uint32 id) {
353 base::Closure callback;
354 {
355 AutoLock lock(signal_lock_);
356 SignalTaskMap::iterator it = signal_tasks_.find(id);
357 DCHECK(it != signal_tasks_.end());
358
359 callback = it->second;
360 signal_tasks_.erase(it);
361 }
362
363 callback.Run();
364 }
365
322 GpuChannelHost::~GpuChannelHost() { 366 GpuChannelHost::~GpuChannelHost() {
323 // channel_ must be destroyed on the main thread. 367 // channel_ must be destroyed on the main thread.
324 if (!factory_->IsMainThread()) 368 if (!factory_->IsMainThread())
325 factory_->GetMainLoop()->DeleteSoon(FROM_HERE, channel_.release()); 369 factory_->GetMainLoop()->DeleteSoon(FROM_HERE, channel_.release());
326 } 370 }
327 371
328 372
329 GpuChannelHost::MessageFilter::MessageFilter() 373 GpuChannelHost::MessageFilter::MessageFilter()
330 : lost_(false) { 374 : lost_(false) {
331 } 375 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 435
392 listeners_.clear(); 436 listeners_.clear();
393 } 437 }
394 438
395 bool GpuChannelHost::MessageFilter::IsLost() const { 439 bool GpuChannelHost::MessageFilter::IsLost() const {
396 AutoLock lock(lock_); 440 AutoLock lock(lock_);
397 return lost_; 441 return lost_;
398 } 442 }
399 443
400 } // namespace content 444 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698