| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> | |
| 10 #include <queue> | 9 #include <queue> |
| 11 | 10 |
| 12 #include "base/callback_old.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/linked_ptr.h" | |
| 14 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 15 #include "content/browser/browser_child_process_host.h" | 13 #include "content/browser/browser_child_process_host.h" |
| 16 #include "content/common/gpu/gpu_info.h" | 14 #include "content/common/gpu/gpu_info.h" |
| 15 #include "content/browser/gpu/gpu_message_hub.h" |
| 17 #include "content/common/gpu/gpu_process_launch_causes.h" | 16 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 19 | 18 |
| 20 struct GPUCreateCommandBufferConfig; | 19 struct GPUCreateCommandBufferConfig; |
| 21 | 20 |
| 22 namespace IPC { | 21 namespace IPC { |
| 23 class Message; | 22 class Message; |
| 24 } | 23 } |
| 25 | 24 |
| 26 class GpuProcessHost : public BrowserChildProcessHost, | 25 class GpuProcessHost : public BrowserChildProcessHost, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 // null if the process no longer exists. | 45 // null if the process no longer exists. |
| 47 static GpuProcessHost* FromID(int host_id); | 46 static GpuProcessHost* FromID(int host_id); |
| 48 int host_id() const { return host_id_; } | 47 int host_id() const { return host_id_; } |
| 49 | 48 |
| 50 virtual bool Send(IPC::Message* msg); | 49 virtual bool Send(IPC::Message* msg); |
| 51 | 50 |
| 52 // ChildProcessHost implementation. | 51 // ChildProcessHost implementation. |
| 53 virtual bool OnMessageReceived(const IPC::Message& message); | 52 virtual bool OnMessageReceived(const IPC::Message& message); |
| 54 virtual void OnChannelConnected(int32 peer_pid); | 53 virtual void OnChannelConnected(int32 peer_pid); |
| 55 | 54 |
| 56 typedef Callback3<const IPC::ChannelHandle&, | 55 GpuMessageHub* GetMessageHub() { return message_hub_.get(); } |
| 57 base::ProcessHandle, | |
| 58 const GPUInfo&>::Type | |
| 59 EstablishChannelCallback; | |
| 60 | |
| 61 // Tells the GPU process to create a new channel for communication with a | |
| 62 // renderer. Once the GPU process responds asynchronously with the IPC handle | |
| 63 // and GPUInfo, we call the callback. | |
| 64 void EstablishGpuChannel( | |
| 65 int renderer_id, EstablishChannelCallback* callback); | |
| 66 | |
| 67 typedef Callback0::Type SynchronizeCallback; | |
| 68 | |
| 69 // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes | |
| 70 // in. | |
| 71 void Synchronize(SynchronizeCallback* callback); | |
| 72 | |
| 73 typedef Callback1<int32>::Type CreateCommandBufferCallback; | |
| 74 | |
| 75 // Tells the GPU process to create a new command buffer that draws into the | |
| 76 // window associated with the given renderer. | |
| 77 void CreateViewCommandBuffer( | |
| 78 gfx::PluginWindowHandle compositing_surface, | |
| 79 int32 render_view_id, | |
| 80 int32 renderer_id, | |
| 81 const GPUCreateCommandBufferConfig& init_params, | |
| 82 CreateCommandBufferCallback* callback); | |
| 83 | 56 |
| 84 private: | 57 private: |
| 85 GpuProcessHost(int host_id); | 58 GpuProcessHost(int host_id); |
| 86 virtual ~GpuProcessHost(); | 59 virtual ~GpuProcessHost(); |
| 87 | 60 |
| 88 bool Init(); | 61 bool Init(); |
| 89 | 62 |
| 90 // Post an IPC message to the UI shim's message handler on the UI thread. | |
| 91 void RouteOnUIThread(const IPC::Message& message); | |
| 92 | |
| 93 virtual bool CanShutdown(); | 63 virtual bool CanShutdown(); |
| 94 virtual void OnProcessLaunched(); | 64 virtual void OnProcessLaunched(); |
| 95 virtual void OnChildDied(); | 65 virtual void OnChildDied(); |
| 96 virtual void OnProcessCrashed(int exit_code); | 66 virtual void OnProcessCrashed(int exit_code); |
| 97 | 67 |
| 98 // Message handlers. | |
| 99 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle); | |
| 100 void OnSynchronizeReply(); | |
| 101 void OnCommandBufferCreated(const int32 route_id); | |
| 102 void OnDestroyCommandBuffer( | |
| 103 gfx::PluginWindowHandle window, int32 renderer_id, int32 render_view_id); | |
| 104 void OnGraphicsInfoCollected(const GPUInfo& gpu_info); | |
| 105 | |
| 106 bool LaunchGpuProcess(); | 68 bool LaunchGpuProcess(); |
| 107 | 69 |
| 108 void SendOutstandingReplies(); | 70 void SendOutstandingReplies(); |
| 109 void EstablishChannelError( | |
| 110 EstablishChannelCallback* callback, | |
| 111 const IPC::ChannelHandle& channel_handle, | |
| 112 base::ProcessHandle renderer_process_for_gpu, | |
| 113 const GPUInfo& gpu_info); | |
| 114 void CreateCommandBufferError(CreateCommandBufferCallback* callback, | |
| 115 int32 route_id); | |
| 116 void SynchronizeError(SynchronizeCallback* callback); | |
| 117 | 71 |
| 118 // The serial number of the GpuProcessHost / GpuProcessHostUIShim pair. | 72 // The serial number of the GpuProcessHost / GpuProcessHostUIShim pair. |
| 119 int host_id_; | 73 int host_id_; |
| 120 | 74 |
| 121 // These are the channel requests that we have already sent to | |
| 122 // the GPU process, but haven't heard back about yet. | |
| 123 std::queue<linked_ptr<EstablishChannelCallback> > channel_requests_; | |
| 124 | |
| 125 // The pending synchronization requests we need to reply to. | |
| 126 std::queue<linked_ptr<SynchronizeCallback> > synchronize_requests_; | |
| 127 | |
| 128 // The pending create command buffer requests we need to reply to. | |
| 129 std::queue<linked_ptr<CreateCommandBufferCallback> > | |
| 130 create_command_buffer_requests_; | |
| 131 | |
| 132 #if defined(OS_LINUX) | |
| 133 typedef std::pair<int32 /* renderer_id */, | |
| 134 int32 /* render_view_id */> ViewID; | |
| 135 | |
| 136 // Encapsulates surfaces that we lock when creating view command buffers. | |
| 137 // We release this lock once the command buffer (or associated GPU process) | |
| 138 // is destroyed. This prevents the browser from destroying the surface | |
| 139 // while the GPU process is drawing to it. | |
| 140 | |
| 141 // Multimap is used to simulate reference counting, see comment in | |
| 142 // GpuProcessHostUIShim::CreateViewCommandBuffer. | |
| 143 class SurfaceRef; | |
| 144 typedef std::multimap<ViewID, linked_ptr<SurfaceRef> > SurfaceRefMap; | |
| 145 SurfaceRefMap surface_refs_; | |
| 146 #endif | |
| 147 | |
| 148 // Qeueud messages to send when the process launches. | 75 // Qeueud messages to send when the process launches. |
| 149 std::queue<IPC::Message*> queued_messages_; | 76 std::queue<IPC::Message*> queued_messages_; |
| 150 | 77 |
| 151 // The handle for the GPU process or null if it is not known to be launched. | 78 // The handle for the GPU process or null if it is not known to be launched. |
| 152 base::ProcessHandle gpu_process_; | 79 base::ProcessHandle gpu_process_; |
| 153 | 80 |
| 81 // This member handles incoming messages from the GPU process that |
| 82 // are either going to the UI thread or are replies to the renderer. |
| 83 scoped_ptr<GpuMessageHub> message_hub_; |
| 84 |
| 154 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); | 85 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); |
| 155 }; | 86 }; |
| 156 | 87 |
| 157 #endif // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ | 88 #endif // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ |
| OLD | NEW |