| OLD | NEW |
| 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/public/cpp/gpu/gpu.h" | 5 #include "services/ui/public/cpp/gpu/gpu.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" | 10 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 io_thread_.reset(new base::Thread("GPUIOThread")); | 39 io_thread_.reset(new base::Thread("GPUIOThread")); |
| 40 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 40 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 41 thread_options.priority = base::ThreadPriority::NORMAL; | 41 thread_options.priority = base::ThreadPriority::NORMAL; |
| 42 CHECK(io_thread_->StartWithOptions(thread_options)); | 42 CHECK(io_thread_->StartWithOptions(thread_options)); |
| 43 io_task_runner_ = io_thread_->task_runner(); | 43 io_task_runner_ = io_thread_->task_runner(); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 Gpu::~Gpu() { | 47 Gpu::~Gpu() { |
| 48 DCHECK(IsMainThread()); | 48 DCHECK(IsMainThread()); |
| 49 DCHECK(!in_shutdown_); |
| 50 |
| 51 in_shutdown_ = true; |
| 49 for (const auto& callback : establish_callbacks_) | 52 for (const auto& callback : establish_callbacks_) |
| 50 callback.Run(nullptr); | 53 callback.Run(nullptr); |
| 51 shutdown_event_.Signal(); | 54 shutdown_event_.Signal(); |
| 52 if (gpu_channel_) | 55 if (gpu_channel_) |
| 53 gpu_channel_->DestroyChannel(); | 56 gpu_channel_->DestroyChannel(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 // static | 59 // static |
| 57 std::unique_ptr<Gpu> Gpu::Create( | 60 std::unique_ptr<Gpu> Gpu::Create( |
| 58 service_manager::Connector* connector, | 61 service_manager::Connector* connector, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 83 std::move(gpu_channel), gpu::GPU_STREAM_DEFAULT, | 86 std::move(gpu_channel), gpu::GPU_STREAM_DEFAULT, |
| 84 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, | 87 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, |
| 85 GURL("chrome://gpu/MusContextFactory"), automatic_flushes, | 88 GURL("chrome://gpu/MusContextFactory"), automatic_flushes, |
| 86 support_locking, gpu::SharedMemoryLimits(), attributes, | 89 support_locking, gpu::SharedMemoryLimits(), attributes, |
| 87 shared_context_provider, ui::command_buffer_metrics::MUS_CLIENT_CONTEXT)); | 90 shared_context_provider, ui::command_buffer_metrics::MUS_CLIENT_CONTEXT)); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void Gpu::EstablishGpuChannel( | 93 void Gpu::EstablishGpuChannel( |
| 91 const gpu::GpuChannelEstablishedCallback& callback) { | 94 const gpu::GpuChannelEstablishedCallback& callback) { |
| 92 DCHECK(IsMainThread()); | 95 DCHECK(IsMainThread()); |
| 96 |
| 97 if (in_shutdown_) |
| 98 return; |
| 99 |
| 93 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); | 100 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); |
| 94 if (channel) { | 101 if (channel) { |
| 95 main_task_runner_->PostTask(FROM_HERE, | 102 main_task_runner_->PostTask(FROM_HERE, |
| 96 base::Bind(callback, std::move(channel))); | 103 base::Bind(callback, std::move(channel))); |
| 97 return; | 104 return; |
| 98 } | 105 } |
| 99 establish_callbacks_.push_back(callback); | 106 establish_callbacks_.push_back(callback); |
| 100 if (gpu_) | 107 if (gpu_) |
| 101 return; | 108 return; |
| 102 | 109 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 190 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 184 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 191 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
| 185 if (result != MOJO_RESULT_OK) | 192 if (result != MOJO_RESULT_OK) |
| 186 return nullptr; | 193 return nullptr; |
| 187 DCHECK_EQ(shared_memory_size, size); | 194 DCHECK_EQ(shared_memory_size, size); |
| 188 | 195 |
| 189 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 196 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
| 190 } | 197 } |
| 191 | 198 |
| 192 } // namespace ui | 199 } // namespace ui |
| OLD | NEW |