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

Side by Side Diff: content/browser/gpu/gpu_process_host.h

Issue 9150017: Add a Content API around BrowserChildProcessHost, similar to what was done with ChildProcessHost.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix?! Created 8 years, 11 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 | Annotate | Revision Log
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 #ifndef CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ 5 #ifndef CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_
6 #define CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ 6 #define CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/process.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
15 #include "content/browser/browser_child_process_host.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/common/gpu/gpu_process_launch_causes.h" 17 #include "content/common/gpu/gpu_process_launch_causes.h"
18 #include "content/public/browser/browser_child_process_host_delegate.h"
18 #include "content/public/common/gpu_info.h" 19 #include "content/public/common/gpu_info.h"
20 #include "ipc/ipc_message.h"
19 #include "ui/gfx/native_widget_types.h" 21 #include "ui/gfx/native_widget_types.h"
20 22
23 class GpuMainThread;
21 struct GPUCreateCommandBufferConfig; 24 struct GPUCreateCommandBufferConfig;
22 25
23 namespace IPC { 26 class BrowserChildProcessHost;
24 class Message;
25 }
26 27
27 class GpuMainThread; 28 class GpuProcessHost : public content::BrowserChildProcessHostDelegate,
28 29 public IPC::Message::Sender,
29 class GpuProcessHost : public BrowserChildProcessHost,
30 public base::NonThreadSafe { 30 public base::NonThreadSafe {
31 public: 31 public:
32 static bool gpu_enabled() { return gpu_enabled_; } 32 static bool gpu_enabled() { return gpu_enabled_; }
33 33
34 // Creates a new GpuProcessHost or gets one for a particular 34 // Creates a new GpuProcessHost or gets one for a particular
35 // renderer process, resulting in the launching of a GPU process if required. 35 // renderer process, resulting in the launching of a GPU process if required.
36 // Returns null on failure. It is not safe to store the pointer once control 36 // Returns null on failure. It is not safe to store the pointer once control
37 // has returned to the message loop as it can be destroyed. Instead store the 37 // has returned to the message loop as it can be destroyed. Instead store the
38 // associated GPU host ID. A renderer ID of zero means the browser process. 38 // associated GPU host ID. A renderer ID of zero means the browser process.
39 // This could return NULL if GPU access is not allowed (blacklisted). 39 // This could return NULL if GPU access is not allowed (blacklisted).
40 static GpuProcessHost* GetForRenderer(int client_id, 40 static GpuProcessHost* GetForRenderer(int client_id,
41 content::CauseForGpuLaunch cause); 41 content::CauseForGpuLaunch cause);
42 42
43 // Helper function to send the given message to the GPU process on the IO 43 // Helper function to send the given message to the GPU process on the IO
44 // thread. Calls GetForRenderer and if a host is returned, sends it. 44 // thread. Calls GetForRenderer and if a host is returned, sends it.
45 // Can be called from any thread. 45 // Can be called from any thread.
46 CONTENT_EXPORT static void SendOnIO(int client_id, 46 CONTENT_EXPORT static void SendOnIO(int client_id,
47 content::CauseForGpuLaunch cause, 47 content::CauseForGpuLaunch cause,
48 IPC::Message* message); 48 IPC::Message* message);
49 49
50 // Get the GPU process host for the GPU process with the given ID. Returns 50 // Get the GPU process host for the GPU process with the given ID. Returns
51 // null if the process no longer exists. 51 // null if the process no longer exists.
52 static GpuProcessHost* FromID(int host_id); 52 static GpuProcessHost* FromID(int host_id);
53 int host_id() const { return host_id_; } 53 int host_id() const { return host_id_; }
54 54
55 // IPC::Message::Sender implementation:
55 virtual bool Send(IPC::Message* msg) OVERRIDE; 56 virtual bool Send(IPC::Message* msg) OVERRIDE;
56 57
57 // ChildProcessHost implementation.
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
59 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
60
61 typedef base::Callback<void(const IPC::ChannelHandle&, 58 typedef base::Callback<void(const IPC::ChannelHandle&,
62 base::ProcessHandle, 59 base::ProcessHandle,
63 const content::GPUInfo&)> 60 const content::GPUInfo&)>
64 EstablishChannelCallback; 61 EstablishChannelCallback;
65 62
66 // Tells the GPU process to create a new channel for communication with a 63 // Tells the GPU process to create a new channel for communication with a
67 // renderer. Once the GPU process responds asynchronously with the IPC handle 64 // renderer. Once the GPU process responds asynchronously with the IPC handle
68 // and GPUInfo, we call the callback. 65 // and GPUInfo, we call the callback.
69 void EstablishGpuChannel( 66 void EstablishGpuChannel(
70 int client_id, const EstablishChannelCallback& callback); 67 int client_id, const EstablishChannelCallback& callback);
71 68
72 typedef base::Callback<void(int32)> CreateCommandBufferCallback; 69 typedef base::Callback<void(int32)> CreateCommandBufferCallback;
73 70
74 // Tells the GPU process to create a new command buffer that draws into the 71 // Tells the GPU process to create a new command buffer that draws into the
75 // window associated with the given renderer. 72 // window associated with the given renderer.
76 void CreateViewCommandBuffer( 73 void CreateViewCommandBuffer(
77 gfx::PluginWindowHandle compositing_surface, 74 gfx::PluginWindowHandle compositing_surface,
78 int surface_id, 75 int surface_id,
79 int client_id, 76 int client_id,
80 const GPUCreateCommandBufferConfig& init_params, 77 const GPUCreateCommandBufferConfig& init_params,
81 const CreateCommandBufferCallback& callback); 78 const CreateCommandBufferCallback& callback);
82 79
83 // Whether this GPU process is set up to use software rendering. 80 // Whether this GPU process is set up to use software rendering.
84 bool software_rendering(); 81 bool software_rendering();
85 82
86 void ForceShutdown(); 83 void ForceShutdown();
87 84
88 private: 85 private:
86 static bool HostIsValid(GpuProcessHost* host);
87
89 GpuProcessHost(int host_id); 88 GpuProcessHost(int host_id);
90 virtual ~GpuProcessHost(); 89 virtual ~GpuProcessHost();
91 90
92 bool Init(); 91 bool Init();
93 92
94 // Post an IPC message to the UI shim's message handler on the UI thread. 93 // Post an IPC message to the UI shim's message handler on the UI thread.
95 void RouteOnUIThread(const IPC::Message& message); 94 void RouteOnUIThread(const IPC::Message& message);
96 95
96 // BrowserChildProcessHostDelegate implementation.
97 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
98 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
97 virtual void OnProcessLaunched() OVERRIDE; 99 virtual void OnProcessLaunched() OVERRIDE;
98 virtual void OnProcessCrashed(int exit_code) OVERRIDE; 100 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
99 101
100 // Message handlers. 102 // Message handlers.
101 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle); 103 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle);
102 void OnCommandBufferCreated(const int32 route_id); 104 void OnCommandBufferCreated(const int32 route_id);
103 void OnDestroyCommandBuffer(int32 surface_id); 105 void OnDestroyCommandBuffer(int32 surface_id);
104 106
105 bool LaunchGpuProcess(const std::string& channel_id); 107 bool LaunchGpuProcess(const std::string& channel_id);
106 108
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 150
149 bool software_rendering_; 151 bool software_rendering_;
150 152
151 scoped_ptr<GpuMainThread> in_process_gpu_thread_; 153 scoped_ptr<GpuMainThread> in_process_gpu_thread_;
152 154
153 // Master switch for enabling/disabling GPU acceleration for the current 155 // Master switch for enabling/disabling GPU acceleration for the current
154 // browser session. It does not change the acceleration settings for 156 // browser session. It does not change the acceleration settings for
155 // existing tabs, just the future ones. 157 // existing tabs, just the future ones.
156 CONTENT_EXPORT static bool gpu_enabled_; 158 CONTENT_EXPORT static bool gpu_enabled_;
157 159
160 scoped_ptr<BrowserChildProcessHost> process_;
161
158 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); 162 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost);
159 }; 163 };
160 164
161 #endif // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ 165 #endif // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « content/browser/debugger/worker_devtools_manager.cc ('k') | content/browser/gpu/gpu_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698