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

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, 2 months 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
« no previous file with comments | « content/common/gpu/client/gpu_channel_host.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 host->Connect(channel_handle, shutdown_event); 43 host->Connect(channel_handle, shutdown_event);
44 return host; 44 return host;
45 } 45 }
46 46
47 GpuChannelHost::GpuChannelHost( 47 GpuChannelHost::GpuChannelHost(
48 GpuChannelHostFactory* factory, 48 GpuChannelHostFactory* factory,
49 const gpu::GPUInfo& gpu_info, 49 const gpu::GPUInfo& gpu_info,
50 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager) 50 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager)
51 : factory_(factory), 51 : factory_(factory),
52 gpu_info_(gpu_info), 52 gpu_info_(gpu_info),
53 gpu_memory_buffer_manager_(gpu_memory_buffer_manager) { 53 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
54 next_signal_id_(0) {
54 next_transfer_buffer_id_.GetNext(); 55 next_transfer_buffer_id_.GetNext();
55 next_image_id_.GetNext(); 56 next_image_id_.GetNext();
56 next_route_id_.GetNext(); 57 next_route_id_.GetNext();
57 } 58 }
58 59
59 void GpuChannelHost::Connect(const IPC::ChannelHandle& channel_handle, 60 void GpuChannelHost::Connect(const IPC::ChannelHandle& channel_handle,
60 base::WaitableEvent* shutdown_event) { 61 base::WaitableEvent* shutdown_event) {
61 // Open a channel to the GPU process. We pass NULL as the main listener here 62 // 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. 63 // since we need to filter everything to route it to the right thread.
63 scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); 64 scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy();
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 313 }
313 314
314 int32 GpuChannelHost::ReserveImageId() { 315 int32 GpuChannelHost::ReserveImageId() {
315 return next_image_id_.GetNext(); 316 return next_image_id_.GetNext();
316 } 317 }
317 318
318 int32 GpuChannelHost::GenerateRouteID() { 319 int32 GpuChannelHost::GenerateRouteID() {
319 return next_route_id_.GetNext(); 320 return next_route_id_.GetNext();
320 } 321 }
321 322
323 namespace {
324 class SyncPointTracker : public base::RefCounted<SyncPointTracker> {
325 public:
326 SyncPointTracker(const base::Closure& destruction_callback,
327 scoped_refptr<MessageLoopProxy> caller_message_loop)
328 : destruction_callback_(destruction_callback),
329 caller_message_loop_(caller_message_loop) {}
330
331 void Noop() {}
332
333 private:
334 friend class base::RefCounted<SyncPointTracker>;
335 ~SyncPointTracker() {
336 caller_message_loop_->PostTask(FROM_HERE, destruction_callback_);
337 }
338
339 base::Closure destruction_callback_;
340 scoped_refptr<MessageLoopProxy> caller_message_loop_;
341 };
342 }
343
344 void GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToComplete(
345 const base::Closure& callback) {
346 AutoLock lock(signal_lock_);
347 uint32 signal_id = next_signal_id_++;
348 signal_tasks_.insert(std::make_pair(signal_id, callback));
349
350 factory_->GetMainLoop()->PostTask(
351 FROM_HERE,
352 base::Bind(
353 &GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToCompleteOnMain,
354 base::Unretained(this),
355 signal_id,
356 base::MessageLoopProxy::current()));
357 }
358
359 void GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToCompleteOnMain(
360 uint32 id,
361 scoped_refptr<base::MessageLoopProxy> caller_message_loop) {
362 scoped_refptr<SyncPointTracker> tracker = new SyncPointTracker(
363 base::Bind(&GpuChannelHost::WaitCompletedOnCallerThread,
364 base::Unretained(this),
365 id),
366 caller_message_loop);
367
368 AutoLock lock(context_lock_);
369 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); it++) {
370 uint32 sync_point = it->second->InsertSyncPoint();
371 it->second->SignalSyncPoint(sync_point,
372 base::Bind(&SyncPointTracker::Noop, tracker));
373 }
reveman 2014/10/22 16:20:08 Could we make all this much simpler by just having
374 }
375
376 void GpuChannelHost::WaitCompletedOnCallerThread(uint32 id) {
377 base::Closure callback;
378 {
379 AutoLock lock(signal_lock_);
380 SignalTaskMap::iterator it = signal_tasks_.find(id);
381 DCHECK(it != signal_tasks_.end());
382
383 callback = it->second;
384 signal_tasks_.erase(it);
385 }
386
387 callback.Run();
388 }
389
322 GpuChannelHost::~GpuChannelHost() { 390 GpuChannelHost::~GpuChannelHost() {
323 // channel_ must be destroyed on the main thread. 391 // channel_ must be destroyed on the main thread.
324 if (!factory_->IsMainThread()) 392 if (!factory_->IsMainThread())
325 factory_->GetMainLoop()->DeleteSoon(FROM_HERE, channel_.release()); 393 factory_->GetMainLoop()->DeleteSoon(FROM_HERE, channel_.release());
326 } 394 }
327 395
328 396
329 GpuChannelHost::MessageFilter::MessageFilter() 397 GpuChannelHost::MessageFilter::MessageFilter()
330 : lost_(false) { 398 : lost_(false) {
331 } 399 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 459
392 listeners_.clear(); 460 listeners_.clear();
393 } 461 }
394 462
395 bool GpuChannelHost::MessageFilter::IsLost() const { 463 bool GpuChannelHost::MessageFilter::IsLost() const {
396 AutoLock lock(lock_); 464 AutoLock lock(lock_);
397 return lost_; 465 return lost_;
398 } 466 }
399 467
400 } // namespace content 468 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/gpu_channel_host.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698