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

Side by Side Diff: content/browser/gpu/browser_gpu_channel_host_factory.cc

Issue 1823763003: Move more files to gpu/ipc/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Android Build Created 4 years, 9 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/browser/gpu/browser_gpu_channel_host_factory.h" 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
(...skipping 18 matching lines...) Expand all
29 #include "ipc/ipc_channel_handle.h" 29 #include "ipc/ipc_channel_handle.h"
30 #include "ipc/message_filter.h" 30 #include "ipc/message_filter.h"
31 31
32 namespace content { 32 namespace content {
33 33
34 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; 34 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL;
35 35
36 class BrowserGpuChannelHostFactory::EstablishRequest 36 class BrowserGpuChannelHostFactory::EstablishRequest
37 : public base::RefCountedThreadSafe<EstablishRequest> { 37 : public base::RefCountedThreadSafe<EstablishRequest> {
38 public: 38 public:
39 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, 39 static scoped_refptr<EstablishRequest> Create(gpu::CauseForGpuLaunch cause,
40 int gpu_client_id, 40 int gpu_client_id,
41 uint64_t gpu_client_tracing_id, 41 uint64_t gpu_client_tracing_id,
42 int gpu_host_id); 42 int gpu_host_id);
43 void Wait(); 43 void Wait();
44 void Cancel(); 44 void Cancel();
45 45
46 int gpu_host_id() { return gpu_host_id_; } 46 int gpu_host_id() { return gpu_host_id_; }
47 IPC::ChannelHandle& channel_handle() { return channel_handle_; } 47 IPC::ChannelHandle& channel_handle() { return channel_handle_; }
48 gpu::GPUInfo gpu_info() { return gpu_info_; } 48 gpu::GPUInfo gpu_info() { return gpu_info_; }
49 49
50 private: 50 private:
51 friend class base::RefCountedThreadSafe<EstablishRequest>; 51 friend class base::RefCountedThreadSafe<EstablishRequest>;
52 explicit EstablishRequest(CauseForGpuLaunch cause, 52 explicit EstablishRequest(gpu::CauseForGpuLaunch cause,
53 int gpu_client_id, 53 int gpu_client_id,
54 uint64_t gpu_client_tracing_id, 54 uint64_t gpu_client_tracing_id,
55 int gpu_host_id); 55 int gpu_host_id);
56 ~EstablishRequest() {} 56 ~EstablishRequest() {}
57 void EstablishOnIO(); 57 void EstablishOnIO();
58 void OnEstablishedOnIO(const IPC::ChannelHandle& channel_handle, 58 void OnEstablishedOnIO(const IPC::ChannelHandle& channel_handle,
59 const gpu::GPUInfo& gpu_info); 59 const gpu::GPUInfo& gpu_info);
60 void FinishOnIO(); 60 void FinishOnIO();
61 void FinishOnMain(); 61 void FinishOnMain();
62 62
63 base::WaitableEvent event_; 63 base::WaitableEvent event_;
64 CauseForGpuLaunch cause_for_gpu_launch_; 64 gpu::CauseForGpuLaunch cause_for_gpu_launch_;
65 const int gpu_client_id_; 65 const int gpu_client_id_;
66 const uint64_t gpu_client_tracing_id_; 66 const uint64_t gpu_client_tracing_id_;
67 int gpu_host_id_; 67 int gpu_host_id_;
68 bool reused_gpu_process_; 68 bool reused_gpu_process_;
69 IPC::ChannelHandle channel_handle_; 69 IPC::ChannelHandle channel_handle_;
70 gpu::GPUInfo gpu_info_; 70 gpu::GPUInfo gpu_info_;
71 bool finished_; 71 bool finished_;
72 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 72 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
73 }; 73 };
74 74
75 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest> 75 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest>
76 BrowserGpuChannelHostFactory::EstablishRequest::Create( 76 BrowserGpuChannelHostFactory::EstablishRequest::Create(
77 CauseForGpuLaunch cause, 77 gpu::CauseForGpuLaunch cause,
78 int gpu_client_id, 78 int gpu_client_id,
79 uint64_t gpu_client_tracing_id, 79 uint64_t gpu_client_tracing_id,
80 int gpu_host_id) { 80 int gpu_host_id) {
81 scoped_refptr<EstablishRequest> establish_request = new EstablishRequest( 81 scoped_refptr<EstablishRequest> establish_request = new EstablishRequest(
82 cause, gpu_client_id, gpu_client_tracing_id, gpu_host_id); 82 cause, gpu_client_id, gpu_client_tracing_id, gpu_host_id);
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
84 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 84 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
85 // PostTask outside the constructor to ensure at least one reference exists. 85 // PostTask outside the constructor to ensure at least one reference exists.
86 task_runner->PostTask( 86 task_runner->PostTask(
87 FROM_HERE, 87 FROM_HERE,
88 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO, 88 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO,
89 establish_request)); 89 establish_request));
90 return establish_request; 90 return establish_request;
91 } 91 }
92 92
93 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest( 93 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest(
94 CauseForGpuLaunch cause, 94 gpu::CauseForGpuLaunch cause,
95 int gpu_client_id, 95 int gpu_client_id,
96 uint64_t gpu_client_tracing_id, 96 uint64_t gpu_client_tracing_id,
97 int gpu_host_id) 97 int gpu_host_id)
98 : event_(false, false), 98 : event_(false, false),
99 cause_for_gpu_launch_(cause), 99 cause_for_gpu_launch_(cause),
100 gpu_client_id_(gpu_client_id), 100 gpu_client_id_(gpu_client_id),
101 gpu_client_tracing_id_(gpu_client_tracing_id), 101 gpu_client_tracing_id_(gpu_client_tracing_id),
102 gpu_host_id_(gpu_host_id), 102 gpu_host_id_(gpu_host_id),
103 reused_gpu_process_(false), 103 reused_gpu_process_(false),
104 finished_(false), 104 finished_(false),
105 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) { 105 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
106 }
107 106
108 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() { 107 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() {
109 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 108 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
110 tracked_objects::ScopedTracker tracking_profile( 109 tracked_objects::ScopedTracker tracking_profile(
111 FROM_HERE_WITH_EXPLICIT_FUNCTION( 110 FROM_HERE_WITH_EXPLICIT_FUNCTION(
112 "477117 " 111 "477117 "
113 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO")); 112 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO"));
114 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); 113 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
115 if (!host) { 114 if (!host) {
116 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, 115 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 204 }
206 205
207 bool BrowserGpuChannelHostFactory::CanUseForTesting() { 206 bool BrowserGpuChannelHostFactory::CanUseForTesting() {
208 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL); 207 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL);
209 } 208 }
210 209
211 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) { 210 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) {
212 DCHECK(!instance_); 211 DCHECK(!instance_);
213 instance_ = new BrowserGpuChannelHostFactory(); 212 instance_ = new BrowserGpuChannelHostFactory();
214 if (establish_gpu_channel) { 213 if (establish_gpu_channel) {
215 instance_->EstablishGpuChannel(CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP, 214 instance_->EstablishGpuChannel(gpu::CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP,
216 base::Closure()); 215 base::Closure());
217 } 216 }
218 } 217 }
219 218
220 void BrowserGpuChannelHostFactory::Terminate() { 219 void BrowserGpuChannelHostFactory::Terminate() {
221 DCHECK(instance_); 220 DCHECK(instance_);
222 delete instance_; 221 delete instance_;
223 instance_ = NULL; 222 instance_ = NULL;
224 } 223 }
225 224
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (!shm->CreateAnonymous(size)) 273 if (!shm->CreateAnonymous(size))
275 return scoped_ptr<base::SharedMemory>(); 274 return scoped_ptr<base::SharedMemory>();
276 return shm; 275 return shm;
277 } 276 }
278 277
279 // Blocking the UI thread to open a GPU channel is not supported on Android. 278 // Blocking the UI thread to open a GPU channel is not supported on Android.
280 // (Opening the initial channel to a child process involves handling a reply 279 // (Opening the initial channel to a child process involves handling a reply
281 // task on the UI thread first, so we cannot block here.) 280 // task on the UI thread first, so we cannot block here.)
282 #if !defined(OS_ANDROID) 281 #if !defined(OS_ANDROID)
283 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( 282 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync(
284 CauseForGpuLaunch cause_for_gpu_launch) { 283 gpu::CauseForGpuLaunch cause_for_gpu_launch) {
285 EstablishGpuChannel(cause_for_gpu_launch, base::Closure()); 284 EstablishGpuChannel(cause_for_gpu_launch, base::Closure());
286 285
287 if (pending_request_.get()) 286 if (pending_request_.get())
288 pending_request_->Wait(); 287 pending_request_->Wait();
289 288
290 return gpu_channel_.get(); 289 return gpu_channel_.get();
291 } 290 }
292 #endif 291 #endif
293 292
294 void BrowserGpuChannelHostFactory::EstablishGpuChannel( 293 void BrowserGpuChannelHostFactory::EstablishGpuChannel(
295 CauseForGpuLaunch cause_for_gpu_launch, 294 gpu::CauseForGpuLaunch cause_for_gpu_launch,
296 const base::Closure& callback) { 295 const base::Closure& callback) {
297 if (gpu_channel_.get() && gpu_channel_->IsLost()) { 296 if (gpu_channel_.get() && gpu_channel_->IsLost()) {
298 DCHECK(!pending_request_.get()); 297 DCHECK(!pending_request_.get());
299 // Recreate the channel if it has been lost. 298 // Recreate the channel if it has been lost.
300 gpu_channel_->DestroyChannel(); 299 gpu_channel_->DestroyChannel();
301 gpu_channel_ = NULL; 300 gpu_channel_ = NULL;
302 } 301 }
303 302
304 if (!gpu_channel_.get() && !pending_request_.get()) { 303 if (!gpu_channel_.get() && !pending_request_.get()) {
305 // We should only get here if the context was lost. 304 // We should only get here if the context was lost.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 367 }
369 368
370 // static 369 // static
371 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( 370 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO(
372 int gpu_client_id, 371 int gpu_client_id,
373 const base::FilePath& cache_dir) { 372 const base::FilePath& cache_dir) {
374 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir); 373 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir);
375 } 374 }
376 375
377 } // namespace content 376 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698