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

Side by Side Diff: services/ui/public/cpp/gpu/gpu.cc

Issue 2968053002: mus-gpu: Fix handling channel establish requests. (Closed)
Patch Set: . Created 3 years, 5 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 | « no previous file | services/ui/public/cpp/tests/gpu_unittest.cc » ('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 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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 gpu::kNullSurfaceHandle, GURL("chrome://gpu/MusContextFactory"), 88 gpu::kNullSurfaceHandle, GURL("chrome://gpu/MusContextFactory"),
89 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), attributes, 89 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), attributes,
90 shared_context_provider, ui::command_buffer_metrics::MUS_CLIENT_CONTEXT)); 90 shared_context_provider, ui::command_buffer_metrics::MUS_CLIENT_CONTEXT));
91 } 91 }
92 92
93 void Gpu::EstablishGpuChannel( 93 void Gpu::EstablishGpuChannel(
94 const gpu::GpuChannelEstablishedCallback& callback) { 94 const gpu::GpuChannelEstablishedCallback& callback) {
95 DCHECK(IsMainThread()); 95 DCHECK(IsMainThread());
96 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); 96 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel();
97 if (channel) { 97 if (channel) {
98 main_task_runner_->PostTask(FROM_HERE, 98 callback.Run(std::move(channel));
99 base::Bind(callback, std::move(channel)));
100 return; 99 return;
101 } 100 }
102 establish_callbacks_.push_back(callback); 101 establish_callbacks_.push_back(callback);
103 if (gpu_) 102 if (gpu_)
104 return; 103 return;
105 104
106 gpu_ = factory_.Run(); 105 gpu_ = factory_.Run();
107 gpu_->EstablishGpuChannel( 106 gpu_->EstablishGpuChannel(
108 base::Bind(&Gpu::OnEstablishedGpuChannel, base::Unretained(this))); 107 base::Bind(&Gpu::OnEstablishedGpuChannel, base::Unretained(this)));
109 } 108 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DCHECK(gpu_.get()); 146 DCHECK(gpu_.get());
148 DCHECK(!gpu_channel_); 147 DCHECK(!gpu_channel_);
149 148
150 if (client_id && channel_handle.is_valid()) { 149 if (client_id && channel_handle.is_valid()) {
151 gpu_channel_ = gpu::GpuChannelHost::Create( 150 gpu_channel_ = gpu::GpuChannelHost::Create(
152 this, client_id, gpu_info, IPC::ChannelHandle(channel_handle.release()), 151 this, client_id, gpu_info, IPC::ChannelHandle(channel_handle.release()),
153 &shutdown_event_, gpu_memory_buffer_manager_.get()); 152 &shutdown_event_, gpu_memory_buffer_manager_.get());
154 } 153 }
155 154
156 gpu_.reset(); 155 gpu_.reset();
157 for (const auto& i : establish_callbacks_) 156 auto callbacks = std::move(establish_callbacks_);
158 i.Run(gpu_channel_);
159 establish_callbacks_.clear(); 157 establish_callbacks_.clear();
158 for (const auto& callback : callbacks)
159 callback.Run(gpu_channel_);
160 } 160 }
161 161
162 bool Gpu::IsMainThread() { 162 bool Gpu::IsMainThread() {
163 return main_task_runner_->BelongsToCurrentThread(); 163 return main_task_runner_->BelongsToCurrentThread();
164 } 164 }
165 165
166 scoped_refptr<base::SingleThreadTaskRunner> Gpu::GetIOThreadTaskRunner() { 166 scoped_refptr<base::SingleThreadTaskRunner> Gpu::GetIOThreadTaskRunner() {
167 return io_task_runner_; 167 return io_task_runner_;
168 } 168 }
169 169
170 std::unique_ptr<base::SharedMemory> Gpu::AllocateSharedMemory(size_t size) { 170 std::unique_ptr<base::SharedMemory> Gpu::AllocateSharedMemory(size_t size) {
171 mojo::ScopedSharedBufferHandle handle = 171 mojo::ScopedSharedBufferHandle handle =
172 mojo::SharedBufferHandle::Create(size); 172 mojo::SharedBufferHandle::Create(size);
173 if (!handle.is_valid()) 173 if (!handle.is_valid())
174 return nullptr; 174 return nullptr;
175 175
176 base::SharedMemoryHandle platform_handle; 176 base::SharedMemoryHandle platform_handle;
177 size_t shared_memory_size; 177 size_t shared_memory_size;
178 bool readonly; 178 bool readonly;
179 MojoResult result = mojo::UnwrapSharedMemoryHandle( 179 MojoResult result = mojo::UnwrapSharedMemoryHandle(
180 std::move(handle), &platform_handle, &shared_memory_size, &readonly); 180 std::move(handle), &platform_handle, &shared_memory_size, &readonly);
181 if (result != MOJO_RESULT_OK) 181 if (result != MOJO_RESULT_OK)
182 return nullptr; 182 return nullptr;
183 DCHECK_EQ(shared_memory_size, size); 183 DCHECK_EQ(shared_memory_size, size);
184 184
185 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); 185 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
186 } 186 }
187 187
188 } // namespace ui 188 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | services/ui/public/cpp/tests/gpu_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698