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

Side by Side Diff: services/ui/gpu/gpu_service.cc

Issue 2801943002: gpu: Some code cleanups. (Closed)
Patch Set: Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 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 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 "services/ui/gpu/gpu_service.h" 5 #include "services/ui/gpu/gpu_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/crash_logging.h" 8 #include "base/debug/crash_logging.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 225
226 void GpuService::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, 226 void GpuService::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
227 int client_id, 227 int client_id,
228 const gpu::SyncToken& sync_token) { 228 const gpu::SyncToken& sync_token) {
229 if (io_runner_->BelongsToCurrentThread()) { 229 if (io_runner_->BelongsToCurrentThread()) {
230 main_runner_->PostTask( 230 main_runner_->PostTask(
231 FROM_HERE, base::Bind(&GpuService::DestroyGpuMemoryBuffer, weak_ptr_, 231 FROM_HERE, base::Bind(&GpuService::DestroyGpuMemoryBuffer, weak_ptr_,
232 id, client_id, sync_token)); 232 id, client_id, sync_token));
233 return; 233 return;
234 } 234 }
235 if (gpu_channel_manager_) 235 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
piman 2017/04/06 20:51:14 This used to be necessary (in GpuChildThread) beca
sadrul 2017/04/07 02:16:12 We tear-down the mojo connection if the initializa
piman 2017/04/07 18:16:41 Ok. It does rely on the fact that gpu_service_.res
sadrul 2017/04/07 22:57:03 Sounds good. Moved Bind() to happen after the chec
236 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
237 } 236 }
238 237
239 void GpuService::GetVideoMemoryUsageStats( 238 void GpuService::GetVideoMemoryUsageStats(
240 const GetVideoMemoryUsageStatsCallback& callback) { 239 const GetVideoMemoryUsageStatsCallback& callback) {
241 if (io_runner_->BelongsToCurrentThread()) { 240 if (io_runner_->BelongsToCurrentThread()) {
242 auto wrap_callback = WrapCallback(io_runner_, callback); 241 auto wrap_callback = WrapCallback(io_runner_, callback);
243 main_runner_->PostTask( 242 main_runner_->PostTask(
244 FROM_HERE, base::Bind(&GpuService::GetVideoMemoryUsageStats, weak_ptr_, 243 FROM_HERE, base::Bind(&GpuService::GetVideoMemoryUsageStats, weak_ptr_,
245 wrap_callback)); 244 wrap_callback));
246 return; 245 return;
247 } 246 }
248 gpu::VideoMemoryUsageStats video_memory_usage_stats; 247 gpu::VideoMemoryUsageStats video_memory_usage_stats;
249 if (gpu_channel_manager_) { 248 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats(
250 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( 249 &video_memory_usage_stats);
251 &video_memory_usage_stats);
252 }
253 callback.Run(video_memory_usage_stats); 250 callback.Run(video_memory_usage_stats);
254 } 251 }
255 252
256 void GpuService::RequestCompleteGpuInfo( 253 void GpuService::RequestCompleteGpuInfo(
257 const RequestCompleteGpuInfoCallback& callback) { 254 const RequestCompleteGpuInfoCallback& callback) {
258 if (io_runner_->BelongsToCurrentThread()) { 255 if (io_runner_->BelongsToCurrentThread()) {
259 auto wrap_callback = WrapCallback(io_runner_, callback); 256 auto wrap_callback = WrapCallback(io_runner_, callback);
260 main_runner_->PostTask( 257 main_runner_->PostTask(
261 FROM_HERE, base::Bind(&GpuService::RequestCompleteGpuInfo, weak_ptr_, 258 FROM_HERE, base::Bind(&GpuService::RequestCompleteGpuInfo, weak_ptr_,
262 wrap_callback)); 259 wrap_callback));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 base::Bind(cb, base::Passed(std::move(handle)))); 374 base::Bind(cb, base::Passed(std::move(handle))));
378 }, 375 },
379 io_runner_, callback); 376 io_runner_, callback);
380 main_runner_->PostTask( 377 main_runner_->PostTask(
381 FROM_HERE, 378 FROM_HERE,
382 base::Bind(&GpuService::EstablishGpuChannel, weak_ptr_, client_id, 379 base::Bind(&GpuService::EstablishGpuChannel, weak_ptr_, client_id,
383 client_tracing_id, is_gpu_host, wrap_callback)); 380 client_tracing_id, is_gpu_host, wrap_callback));
384 return; 381 return;
385 } 382 }
386 383
387 if (!gpu_channel_manager_) {
388 callback.Run(mojo::ScopedMessagePipeHandle());
389 return;
390 }
391
392 gpu::GpuChannel* gpu_channel = gpu_channel_manager_->EstablishChannel( 384 gpu::GpuChannel* gpu_channel = gpu_channel_manager_->EstablishChannel(
393 client_id, client_tracing_id, is_gpu_host); 385 client_id, client_tracing_id, is_gpu_host);
394 386
395 mojo::MessagePipe pipe; 387 mojo::MessagePipe pipe;
396 gpu_channel->Init(base::MakeUnique<gpu::SyncChannelFilteredSender>( 388 gpu_channel->Init(base::MakeUnique<gpu::SyncChannelFilteredSender>(
397 pipe.handle0.release(), gpu_channel, io_runner_, shutdown_event_)); 389 pipe.handle0.release(), gpu_channel, io_runner_, shutdown_event_));
398 390
399 media_gpu_channel_manager_->AddChannel(client_id); 391 media_gpu_channel_manager_->AddChannel(client_id);
400 392
401 callback.Run(std::move(pipe.handle1)); 393 callback.Run(std::move(pipe.handle1));
402 } 394 }
403 395
404 void GpuService::CloseChannel(int32_t client_id) { 396 void GpuService::CloseChannel(int32_t client_id) {
405 if (io_runner_->BelongsToCurrentThread()) { 397 if (io_runner_->BelongsToCurrentThread()) {
406 main_runner_->PostTask( 398 main_runner_->PostTask(
407 FROM_HERE, base::Bind(&GpuService::CloseChannel, weak_ptr_, client_id)); 399 FROM_HERE, base::Bind(&GpuService::CloseChannel, weak_ptr_, client_id));
408 return; 400 return;
409 } 401 }
410 if (!gpu_channel_manager_)
411 return;
412 gpu_channel_manager_->RemoveChannel(client_id); 402 gpu_channel_manager_->RemoveChannel(client_id);
413 } 403 }
414 404
415 void GpuService::LoadedShader(const std::string& data) { 405 void GpuService::LoadedShader(const std::string& data) {
416 if (io_runner_->BelongsToCurrentThread()) { 406 if (io_runner_->BelongsToCurrentThread()) {
417 main_runner_->PostTask( 407 main_runner_->PostTask(
418 FROM_HERE, base::Bind(&GpuService::LoadedShader, weak_ptr_, data)); 408 FROM_HERE, base::Bind(&GpuService::LoadedShader, weak_ptr_, data));
419 return; 409 return;
420 } 410 }
421 if (!gpu_channel_manager_)
422 return;
423 gpu_channel_manager_->PopulateShaderCache(data); 411 gpu_channel_manager_->PopulateShaderCache(data);
424 } 412 }
425 413
426 void GpuService::DestroyingVideoSurface( 414 void GpuService::DestroyingVideoSurface(
427 int32_t surface_id, 415 int32_t surface_id,
428 const DestroyingVideoSurfaceCallback& callback) { 416 const DestroyingVideoSurfaceCallback& callback) {
429 DCHECK(io_runner_->BelongsToCurrentThread()); 417 DCHECK(io_runner_->BelongsToCurrentThread());
430 #if defined(OS_ANDROID) 418 #if defined(OS_ANDROID)
431 main_runner_->PostTaskAndReply( 419 main_runner_->PostTaskAndReply(
432 FROM_HERE, 420 FROM_HERE,
433 base::Bind( 421 base::Bind(
434 [](int32_t surface_id) { 422 [](int32_t surface_id) {
435 media::AVDACodecAllocator::Instance()->OnSurfaceDestroyed( 423 media::AVDACodecAllocator::Instance()->OnSurfaceDestroyed(
436 surface_id); 424 surface_id);
437 }, 425 },
438 surface_id), 426 surface_id),
439 callback); 427 callback);
440 #else 428 #else
441 NOTREACHED() << "DestroyingVideoSurface() not supported on this platform."; 429 NOTREACHED() << "DestroyingVideoSurface() not supported on this platform.";
442 #endif 430 #endif
443 } 431 }
444 432
445 void GpuService::WakeUpGpu() { 433 void GpuService::WakeUpGpu() {
446 if (io_runner_->BelongsToCurrentThread()) { 434 if (io_runner_->BelongsToCurrentThread()) {
447 main_runner_->PostTask(FROM_HERE, 435 main_runner_->PostTask(FROM_HERE,
448 base::Bind(&GpuService::WakeUpGpu, weak_ptr_)); 436 base::Bind(&GpuService::WakeUpGpu, weak_ptr_));
449 return; 437 return;
450 } 438 }
451 #if defined(OS_ANDROID) 439 #if defined(OS_ANDROID)
452 if (!gpu_channel_manager_)
453 return;
454 gpu_channel_manager_->WakeUpGpu(); 440 gpu_channel_manager_->WakeUpGpu();
455 #else 441 #else
456 NOTREACHED() << "WakeUpGpu() not supported on this platform."; 442 NOTREACHED() << "WakeUpGpu() not supported on this platform.";
457 #endif 443 #endif
458 } 444 }
459 445
460 void GpuService::GpuSwitched() { 446 void GpuService::GpuSwitched() {
461 DVLOG(1) << "GPU: GPU has switched"; 447 DVLOG(1) << "GPU: GPU has switched";
462 if (!in_host_process_) 448 if (!in_host_process_)
463 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); 449 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched();
464 } 450 }
465 451
466 void GpuService::DestroyAllChannels() { 452 void GpuService::DestroyAllChannels() {
467 if (io_runner_->BelongsToCurrentThread()) { 453 if (io_runner_->BelongsToCurrentThread()) {
468 main_runner_->PostTask( 454 main_runner_->PostTask(
469 FROM_HERE, base::Bind(&GpuService::DestroyAllChannels, weak_ptr_)); 455 FROM_HERE, base::Bind(&GpuService::DestroyAllChannels, weak_ptr_));
470 return; 456 return;
471 } 457 }
472 if (!gpu_channel_manager_)
473 return;
474 DVLOG(1) << "GPU: Removing all contexts"; 458 DVLOG(1) << "GPU: Removing all contexts";
475 gpu_channel_manager_->DestroyAllChannels(); 459 gpu_channel_manager_->DestroyAllChannels();
476 } 460 }
477 461
478 void GpuService::Crash() { 462 void GpuService::Crash() {
479 DCHECK(io_runner_->BelongsToCurrentThread()); 463 DCHECK(io_runner_->BelongsToCurrentThread());
480 DVLOG(1) << "GPU: Simulating GPU crash"; 464 DVLOG(1) << "GPU: Simulating GPU crash";
481 // Good bye, cruel world. 465 // Good bye, cruel world.
482 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; 466 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL;
483 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; 467 *it_s_the_end_of_the_world_as_we_know_it = 0xdead;
(...skipping 24 matching lines...) Expand all
508 492
509 void GpuService::Stop(const StopCallback& callback) { 493 void GpuService::Stop(const StopCallback& callback) {
510 DCHECK(io_runner_->BelongsToCurrentThread()); 494 DCHECK(io_runner_->BelongsToCurrentThread());
511 main_runner_->PostTaskAndReply(FROM_HERE, base::Bind([] { 495 main_runner_->PostTaskAndReply(FROM_HERE, base::Bind([] {
512 base::MessageLoop::current()->QuitWhenIdle(); 496 base::MessageLoop::current()->QuitWhenIdle();
513 }), 497 }),
514 callback); 498 callback);
515 } 499 }
516 500
517 } // namespace ui 501 } // namespace ui
OLDNEW
« content/browser/gpu/gpu_process_host.cc ('K') | « content/browser/gpu/gpu_process_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698