| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_GPU_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_GPU_PROCESS_HOST_H_ |
| 6 #define CHROME_BROWSER_GPU_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_GPU_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "chrome/browser/browser_child_process_host.h" | 14 #include "chrome/browser/browser_child_process_host.h" |
| 15 #include "chrome/common/gpu_feature_flags.h" | 15 #include "chrome/common/gpu_feature_flags.h" |
| 16 #include "gfx/native_widget_types.h" | 16 #include "gfx/native_widget_types.h" |
| 17 | 17 |
| 18 class GpuBlacklist; | 18 class GpuBlacklist; |
| 19 struct GPUCreateCommandBufferConfig; |
| 19 class GPUInfo; | 20 class GPUInfo; |
| 20 class RenderMessageFilter; | 21 class RenderMessageFilter; |
| 21 | 22 |
| 22 namespace IPC { | 23 namespace IPC { |
| 23 struct ChannelHandle; | 24 struct ChannelHandle; |
| 24 class Message; | 25 class Message; |
| 25 } | 26 } |
| 26 | 27 |
| 27 class GpuProcessHost : public BrowserChildProcessHost, | 28 class GpuProcessHost : public BrowserChildProcessHost, |
| 28 public base::NonThreadSafe { | 29 public base::NonThreadSafe { |
| 29 public: | 30 public: |
| 30 // Getter for the singleton. This will return NULL on failure. | 31 // Getter for the singleton. This will return NULL on failure. |
| 31 static GpuProcessHost* Get(); | 32 static GpuProcessHost* Get(); |
| 32 | 33 |
| 33 virtual bool Send(IPC::Message* msg); | 34 virtual bool Send(IPC::Message* msg); |
| 34 | 35 |
| 35 // IPC::Channel::Listener implementation. | 36 // IPC::Channel::Listener implementation. |
| 36 virtual bool OnMessageReceived(const IPC::Message& message); | 37 virtual bool OnMessageReceived(const IPC::Message& message); |
| 37 | 38 |
| 38 // Tells the GPU process to create a new channel for communication with a | 39 // Tells the GPU process to create a new channel for communication with a |
| 39 // renderer. Will asynchronously send message to object with given routing id | 40 // renderer. Will asynchronously send message to object with given routing id |
| 40 // on completion. | 41 // on completion. |
| 41 void EstablishGpuChannel(int renderer_id, RenderMessageFilter* filter); | 42 void EstablishGpuChannel(int renderer_id, RenderMessageFilter* filter); |
| 42 | 43 |
| 43 // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes | 44 // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes |
| 44 // in. | 45 // in. |
| 45 void Synchronize(IPC::Message* reply, RenderMessageFilter* filter); | 46 void Synchronize(IPC::Message* reply, RenderMessageFilter* filter); |
| 46 | 47 |
| 48 // Tells the GPU process to create a new command buffer that draws into the |
| 49 // window associated with the given renderer. |
| 50 void CreateViewCommandBuffer( |
| 51 int32 render_view_id, |
| 52 int32 renderer_id, |
| 53 const GPUCreateCommandBufferConfig& init_params, |
| 54 IPC::Message* reply, |
| 55 RenderMessageFilter* filter); |
| 56 |
| 57 // We need to hop threads when creating the command buffer. |
| 58 // Let these tasks access our internals. |
| 59 friend class CVCBThreadHopping; |
| 60 |
| 47 private: | 61 private: |
| 48 // Used to queue pending channel requests. | 62 // Used to queue pending channel requests. |
| 49 struct ChannelRequest { | 63 struct ChannelRequest { |
| 50 explicit ChannelRequest(RenderMessageFilter* filter); | 64 explicit ChannelRequest(RenderMessageFilter* filter); |
| 51 ~ChannelRequest(); | 65 ~ChannelRequest(); |
| 52 | 66 |
| 53 // Used to send the reply message back to the renderer. | 67 // Used to send the reply message back to the renderer. |
| 54 scoped_refptr<RenderMessageFilter> filter; | 68 scoped_refptr<RenderMessageFilter> filter; |
| 55 }; | 69 }; |
| 56 | 70 |
| 57 // Used to queue pending synchronization requests. | 71 struct DelayedReply { |
| 58 struct SynchronizationRequest { | 72 DelayedReply(IPC::Message* reply, RenderMessageFilter* filter); |
| 59 SynchronizationRequest(IPC::Message* reply, RenderMessageFilter* filter); | 73 ~DelayedReply(); |
| 60 ~SynchronizationRequest(); | |
| 61 | 74 |
| 62 // The delayed reply message which needs to be sent to the | 75 // The delayed reply message which needs to be sent to the |
| 63 // renderer. | 76 // renderer. |
| 64 IPC::Message* reply; | 77 IPC::Message* reply; |
| 65 | 78 |
| 66 // Used to send the reply message back to the renderer. | 79 // Used to send the reply message back to the renderer. |
| 67 scoped_refptr<RenderMessageFilter> filter; | 80 scoped_refptr<RenderMessageFilter> filter; |
| 68 }; | 81 }; |
| 69 | 82 |
| 70 GpuProcessHost(); | 83 GpuProcessHost(); |
| 71 virtual ~GpuProcessHost(); | 84 virtual ~GpuProcessHost(); |
| 72 | 85 |
| 73 bool EnsureInitialized(); | 86 bool EnsureInitialized(); |
| 74 bool Init(); | 87 bool Init(); |
| 75 | 88 |
| 76 bool OnControlMessageReceived(const IPC::Message& message); | 89 bool OnControlMessageReceived(const IPC::Message& message); |
| 77 | 90 |
| 78 // Message handlers. | 91 // Message handlers. |
| 79 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle, | 92 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle, |
| 80 const GPUInfo& gpu_info); | 93 const GPUInfo& gpu_info); |
| 81 void OnSynchronizeReply(); | 94 void OnSynchronizeReply(); |
| 95 void OnCommandBufferCreated(const int32 route_id); |
| 82 | 96 |
| 83 // Sends the response for establish channel request to the renderer. | 97 // Sends the response for establish channel request to the renderer. |
| 84 void SendEstablishChannelReply(const IPC::ChannelHandle& channel, | 98 void SendEstablishChannelReply(const IPC::ChannelHandle& channel, |
| 85 const GPUInfo& gpu_info, | 99 const GPUInfo& gpu_info, |
| 86 RenderMessageFilter* filter); | 100 RenderMessageFilter* filter); |
| 87 // Sends the response for synchronization request to the renderer. | |
| 88 void SendSynchronizationReply(IPC::Message* reply, | |
| 89 RenderMessageFilter* filter); | |
| 90 | 101 |
| 91 // Sends outstanding replies to renderer processes. This is only called | 102 // Sends outstanding replies to renderer processes. This is only called |
| 92 // in error situations like the GPU process crashing -- but is necessary | 103 // in error situations like the GPU process crashing -- but is necessary |
| 93 // to prevent the renderer process from hanging. | 104 // to prevent the renderer process from hanging. |
| 94 void SendOutstandingReplies(); | 105 void SendOutstandingReplies(); |
| 95 | 106 |
| 96 virtual bool CanShutdown(); | 107 virtual bool CanShutdown(); |
| 97 virtual void OnChildDied(); | 108 virtual void OnChildDied(); |
| 98 virtual void OnProcessCrashed(int exit_code); | 109 virtual void OnProcessCrashed(int exit_code); |
| 99 | 110 |
| 100 bool CanLaunchGpuProcess() const; | 111 bool CanLaunchGpuProcess() const; |
| 101 bool LaunchGpuProcess(); | 112 bool LaunchGpuProcess(); |
| 102 | 113 |
| 103 bool LoadGpuBlacklist(); | 114 bool LoadGpuBlacklist(); |
| 104 | 115 |
| 105 bool initialized_; | 116 bool initialized_; |
| 106 bool initialized_successfully_; | 117 bool initialized_successfully_; |
| 107 | 118 |
| 108 bool gpu_feature_flags_set_; | 119 bool gpu_feature_flags_set_; |
| 109 scoped_ptr<GpuBlacklist> gpu_blacklist_; | 120 scoped_ptr<GpuBlacklist> gpu_blacklist_; |
| 110 GpuFeatureFlags gpu_feature_flags_; | 121 GpuFeatureFlags gpu_feature_flags_; |
| 111 | 122 |
| 112 // These are the channel requests that we have already sent to | 123 // These are the channel requests that we have already sent to |
| 113 // the GPU process, but haven't heard back about yet. | 124 // the GPU process, but haven't heard back about yet. |
| 114 std::queue<ChannelRequest> sent_requests_; | 125 std::queue<ChannelRequest> sent_requests_; |
| 115 | 126 |
| 116 // The pending synchronization requests we need to reply to. | 127 // The pending synchronization requests we need to reply to. |
| 117 std::queue<SynchronizationRequest> queued_synchronization_replies_; | 128 std::queue<DelayedReply> queued_synchronization_replies_; |
| 129 |
| 130 // The pending create command buffer requests we need to reply to. |
| 131 std::queue<DelayedReply> create_command_buffer_replies_; |
| 118 | 132 |
| 119 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); | 133 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); |
| 120 }; | 134 }; |
| 121 | 135 |
| 136 |
| 122 #endif // CHROME_BROWSER_GPU_PROCESS_HOST_H_ | 137 #endif // CHROME_BROWSER_GPU_PROCESS_HOST_H_ |
| OLD | NEW |