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

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
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 void GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToComplete(
324 const base::Closure& callback) {
325 uint32 signal_id = next_signal_id_++;
326 signal_tasks_.insert(std::make_pair(signal_id, callback));
327
328 factory_->GetMainLoop()->PostTask(
329 FROM_HERE,
330 base::Bind(
331 &GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToCompleteOnMain,
332 base::Unretained(this),
333 signal_id));
334 }
335
336 void GpuChannelHost::WaitForPendingGpuMemoryBufferUsageToCompleteOnMain(
337 uint32 id) {
338 AutoLock lock(context_lock_);
339
340 size_t num_proxies = proxies_.size();
341 signal_counters_.insert(std::make_pair(id, num_proxies));
reveman 2014/10/21 20:27:58 Instead of signal_counters_ and signal_tasks_ maps
alexst (slow to review) 2014/10/22 14:47:08 That's a good idea, it deals with proxy removal cl
reveman 2014/10/22 16:20:08 hm, does it matter when you can guaranteed that it
342
343 if (!num_proxies) {
344 OnSignalSyncPoint(id);
345 return;
346 }
347
348 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); it++) {
349 uint32 sync_point = it->second->InsertSyncPoint();
350 it->second->SignalSyncPoint(
351 sync_point,
352 base::Bind(
353 &GpuChannelHost::OnSignalSyncPoint, base::Unretained(this), id));
354 }
355 }
356
357 void GpuChannelHost::OnSignalSyncPoint(uint32 id) {
358 SignalCounterMap::iterator it = signal_counters_.find(id);
359 DCHECK(it != signal_counters_.end());
360 it->second--;
361
362 if (it->second <= 0) {
363 factory_->GetIOLoopProxy()->PostTask(
364 FROM_HERE,
365 base::Bind(&GpuChannelHost::ProcessSignalCounterOnIO,
366 base::Unretained(this),
367 id));
368 }
369 }
370
371 void GpuChannelHost::ProcessSignalCounterOnIO(uint32 id) {
372 SignalTaskMap::iterator it = signal_tasks_.find(id);
373 DCHECK(it != signal_tasks_.end());
374
375 base::Closure callback = it->second;
376 signal_tasks_.erase(it);
377 callback.Run();
378 }
379
322 GpuChannelHost::~GpuChannelHost() { 380 GpuChannelHost::~GpuChannelHost() {
323 // channel_ must be destroyed on the main thread. 381 // channel_ must be destroyed on the main thread.
324 if (!factory_->IsMainThread()) 382 if (!factory_->IsMainThread())
325 factory_->GetMainLoop()->DeleteSoon(FROM_HERE, channel_.release()); 383 factory_->GetMainLoop()->DeleteSoon(FROM_HERE, channel_.release());
326 } 384 }
327 385
328 386
329 GpuChannelHost::MessageFilter::MessageFilter() 387 GpuChannelHost::MessageFilter::MessageFilter()
330 : lost_(false) { 388 : lost_(false) {
331 } 389 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 449
392 listeners_.clear(); 450 listeners_.clear();
393 } 451 }
394 452
395 bool GpuChannelHost::MessageFilter::IsLost() const { 453 bool GpuChannelHost::MessageFilter::IsLost() const {
396 AutoLock lock(lock_); 454 AutoLock lock(lock_);
397 return lost_; 455 return lost_;
398 } 456 }
399 457
400 } // namespace content 458 } // namespace content
OLDNEW
« content/common/gpu/client/gpu_channel_host.h ('K') | « content/common/gpu/client/gpu_channel_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698