| OLD | NEW |
| 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_COMMON_GPU_GPU_CHANNEL_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
| 6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <deque> | |
| 9 #include <string> | 8 #include <string> |
| 10 | 9 |
| 10 #include "base/atomicops.h" |
| 11 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
| 16 #include "base/timer/timer.h" |
| 16 #include "base/trace_event/memory_dump_provider.h" | 17 #include "base/trace_event/memory_dump_provider.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 19 #include "content/common/gpu/gpu_command_buffer_stub.h" | 20 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 20 #include "content/common/gpu/gpu_memory_manager.h" | 21 #include "content/common/gpu/gpu_memory_manager.h" |
| 21 #include "content/common/gpu/gpu_result_codes.h" | 22 #include "content/common/gpu/gpu_result_codes.h" |
| 22 #include "content/common/message_router.h" | 23 #include "content/common/message_router.h" |
| 23 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 24 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 24 #include "ipc/ipc_sync_channel.h" | 25 #include "ipc/ipc_sync_channel.h" |
| 25 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 } | 44 } |
| 44 | 45 |
| 45 namespace IPC { | 46 namespace IPC { |
| 46 class AttachmentBroker; | 47 class AttachmentBroker; |
| 47 class MessageFilter; | 48 class MessageFilter; |
| 48 } | 49 } |
| 49 | 50 |
| 50 namespace content { | 51 namespace content { |
| 51 class GpuChannelManager; | 52 class GpuChannelManager; |
| 52 class GpuChannelMessageFilter; | 53 class GpuChannelMessageFilter; |
| 54 class GpuChannelMessageQueue; |
| 53 class GpuJpegDecodeAccelerator; | 55 class GpuJpegDecodeAccelerator; |
| 54 class GpuWatchdog; | 56 class GpuWatchdog; |
| 55 | 57 |
| 58 struct GpuChannelMessage; |
| 59 |
| 56 // Encapsulates an IPC channel between the GPU process and one renderer | 60 // Encapsulates an IPC channel between the GPU process and one renderer |
| 57 // process. On the renderer side there's a corresponding GpuChannelHost. | 61 // process. On the renderer side there's a corresponding GpuChannelHost. |
| 58 class CONTENT_EXPORT GpuChannel | 62 class CONTENT_EXPORT GpuChannel |
| 59 : public IPC::Listener, | 63 : public IPC::Listener, |
| 60 public IPC::Sender, | 64 public IPC::Sender, |
| 61 public gpu::gles2::SubscriptionRefSet::Observer { | 65 public gpu::gles2::SubscriptionRefSet::Observer { |
| 62 public: | 66 public: |
| 63 // Takes ownership of the renderer process handle. | 67 // Takes ownership of the renderer process handle. |
| 64 GpuChannel(GpuChannelManager* gpu_channel_manager, | 68 GpuChannel(GpuChannelManager* gpu_channel_manager, |
| 65 GpuWatchdog* watchdog, | 69 GpuWatchdog* watchdog, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 88 virtual base::ProcessId GetClientPID() const; | 92 virtual base::ProcessId GetClientPID() const; |
| 89 | 93 |
| 90 int client_id() const { return client_id_; } | 94 int client_id() const { return client_id_; } |
| 91 | 95 |
| 92 uint64_t client_tracing_id() const { return client_tracing_id_; } | 96 uint64_t client_tracing_id() const { return client_tracing_id_; } |
| 93 | 97 |
| 94 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { | 98 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { |
| 95 return io_task_runner_; | 99 return io_task_runner_; |
| 96 } | 100 } |
| 97 | 101 |
| 102 // Process channel message from main thread. |
| 103 void ProcessMessage(uint32_t order_number, const IPC::Message& message); |
| 104 |
| 98 // IPC::Listener implementation: | 105 // IPC::Listener implementation: |
| 99 bool OnMessageReceived(const IPC::Message& msg) override; | 106 bool OnMessageReceived(const IPC::Message& msg) override; |
| 100 void OnChannelError() override; | 107 void OnChannelError() override; |
| 101 | 108 |
| 102 // IPC::Sender implementation: | 109 // IPC::Sender implementation: |
| 103 bool Send(IPC::Message* msg) override; | 110 bool Send(IPC::Message* msg) override; |
| 104 | 111 |
| 105 // Requeue the message that is currently being processed to the beginning of | 112 // Requeue the message that is currently being processed to the beginning of |
| 106 // the queue. Used when the processing of a message gets aborted because of | 113 // the queue. Used when the processing of a message gets aborted because of |
| 107 // unscheduling conditions. | 114 // unscheduling conditions. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 137 | 144 |
| 138 // Called to add a listener for a particular message routing ID. | 145 // Called to add a listener for a particular message routing ID. |
| 139 // Returns true if succeeded. | 146 // Returns true if succeeded. |
| 140 bool AddRoute(int32 route_id, IPC::Listener* listener); | 147 bool AddRoute(int32 route_id, IPC::Listener* listener); |
| 141 | 148 |
| 142 // Called to remove a listener for a particular message routing ID. | 149 // Called to remove a listener for a particular message routing ID. |
| 143 void RemoveRoute(int32 route_id); | 150 void RemoveRoute(int32 route_id); |
| 144 | 151 |
| 145 gpu::PreemptionFlag* GetPreemptionFlag(); | 152 gpu::PreemptionFlag* GetPreemptionFlag(); |
| 146 | 153 |
| 147 bool handle_messages_scheduled() const { return handle_messages_scheduled_; } | |
| 148 uint64 messages_processed() const { return messages_processed_; } | |
| 149 | |
| 150 // If |preemption_flag->IsSet()|, any stub on this channel | 154 // If |preemption_flag->IsSet()|, any stub on this channel |
| 151 // should stop issuing GL commands. Setting this to NULL stops deferral. | 155 // should stop issuing GL commands. Setting this to NULL stops deferral. |
| 152 void SetPreemptByFlag( | 156 void SetPreemptByFlag( |
| 153 scoped_refptr<gpu::PreemptionFlag> preemption_flag); | 157 scoped_refptr<gpu::PreemptionFlag> preemption_flag); |
| 154 | 158 |
| 155 void CacheShader(const std::string& key, const std::string& shader); | 159 void CacheShader(const std::string& key, const std::string& shader); |
| 156 | 160 |
| 157 virtual void AddFilter(IPC::MessageFilter* filter); | 161 virtual void AddFilter(IPC::MessageFilter* filter); |
| 158 virtual void RemoveFilter(IPC::MessageFilter* filter); | 162 virtual void RemoveFilter(IPC::MessageFilter* filter); |
| 159 | 163 |
| 160 uint64 GetMemoryUsage(); | 164 uint64 GetMemoryUsage(); |
| 161 | 165 |
| 162 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( | 166 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
| 163 const gfx::GpuMemoryBufferHandle& handle, | 167 const gfx::GpuMemoryBufferHandle& handle, |
| 164 const gfx::Size& size, | 168 const gfx::Size& size, |
| 165 gfx::BufferFormat format, | 169 gfx::BufferFormat format, |
| 166 uint32 internalformat); | 170 uint32 internalformat); |
| 167 | 171 |
| 168 bool allow_future_sync_points() const { return allow_future_sync_points_; } | 172 bool allow_future_sync_points() const { return allow_future_sync_points_; } |
| 169 | 173 |
| 170 void HandleUpdateValueState(unsigned int target, | 174 void HandleUpdateValueState(unsigned int target, |
| 171 const gpu::ValueState& state); | 175 const gpu::ValueState& state); |
| 172 | 176 |
| 173 // Visible for testing. | 177 // Visible for testing. |
| 174 const gpu::ValueStateMap* pending_valuebuffer_state() const { | 178 const gpu::ValueStateMap* pending_valuebuffer_state() const { |
| 175 return pending_valuebuffer_state_.get(); | 179 return pending_valuebuffer_state_.get(); |
| 176 } | 180 } |
| 177 | 181 |
| 182 uint32_t GetCurrentOrderNum() const { return current_order_num_; } |
| 183 uint32_t GetProcessedOrderNum() const { return processed_order_num_; } |
| 184 uint32_t GetUnprocessedOrderNum() const; |
| 185 |
| 178 protected: | 186 protected: |
| 179 // The message filter on the io thread. | 187 // The message filter on the io thread. |
| 180 scoped_refptr<GpuChannelMessageFilter> filter_; | 188 scoped_refptr<GpuChannelMessageFilter> filter_; |
| 181 | 189 |
| 182 // Map of routing id to command buffer stub. | 190 // Map of routing id to command buffer stub. |
| 183 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; | 191 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; |
| 184 | 192 |
| 185 private: | 193 private: |
| 186 friend class GpuChannelMessageFilter; | 194 friend class GpuChannelMessageFilter; |
| 195 friend class GpuChannelMessageQueue; |
| 187 | 196 |
| 188 void OnDestroy(); | 197 void OnDestroy(); |
| 189 | 198 |
| 190 bool OnControlMessageReceived(const IPC::Message& msg); | 199 bool OnControlMessageReceived(const IPC::Message& msg); |
| 191 | 200 |
| 192 void HandleMessage(); | 201 void HandleMessage(); |
| 193 | 202 |
| 194 // Message handlers. | 203 // Message handlers. |
| 195 void OnCreateOffscreenCommandBuffer( | 204 void OnCreateOffscreenCommandBuffer( |
| 196 const gfx::Size& size, | 205 const gfx::Size& size, |
| 197 const GPUCreateCommandBufferConfig& init_params, | 206 const GPUCreateCommandBufferConfig& init_params, |
| 198 int32 route_id, | 207 int32 route_id, |
| 199 bool* succeeded); | 208 bool* succeeded); |
| 200 void OnDestroyCommandBuffer(int32 route_id); | 209 void OnDestroyCommandBuffer(int32 route_id); |
| 201 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); | 210 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); |
| 202 | 211 |
| 203 // Decrement the count of unhandled IPC messages and defer preemption. | 212 // Update processed order number and defer preemption. |
| 204 void MessageProcessed(); | 213 void MessageProcessed(uint32_t order_number); |
| 205 | 214 |
| 206 // The lifetime of objects of this class is managed by a GpuChannelManager. | 215 // The lifetime of objects of this class is managed by a GpuChannelManager. |
| 207 // The GpuChannelManager destroy all the GpuChannels that they own when they | 216 // The GpuChannelManager destroy all the GpuChannels that they own when they |
| 208 // are destroyed. So a raw pointer is safe. | 217 // are destroyed. So a raw pointer is safe. |
| 209 GpuChannelManager* gpu_channel_manager_; | 218 GpuChannelManager* gpu_channel_manager_; |
| 210 | 219 |
| 211 scoped_ptr<IPC::SyncChannel> channel_; | 220 scoped_ptr<IPC::SyncChannel> channel_; |
| 212 | 221 |
| 213 // Uniquely identifies the channel within this GPU process. | 222 // Uniquely identifies the channel within this GPU process. |
| 214 std::string channel_id_; | 223 std::string channel_id_; |
| 215 | 224 |
| 216 // Used to implement message routing functionality to CommandBuffer objects | 225 // Used to implement message routing functionality to CommandBuffer objects |
| 217 MessageRouter router_; | 226 MessageRouter router_; |
| 218 | 227 |
| 219 uint64 messages_processed_; | |
| 220 | |
| 221 // Whether the processing of IPCs on this channel is stalled and we should | 228 // Whether the processing of IPCs on this channel is stalled and we should |
| 222 // preempt other GpuChannels. | 229 // preempt other GpuChannels. |
| 223 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; | 230 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; |
| 224 | 231 |
| 225 // If non-NULL, all stubs on this channel should stop processing GL | 232 // If non-NULL, all stubs on this channel should stop processing GL |
| 226 // commands (via their GpuScheduler) when preempted_flag_->IsSet() | 233 // commands (via their GpuScheduler) when preempted_flag_->IsSet() |
| 227 scoped_refptr<gpu::PreemptionFlag> preempted_flag_; | 234 scoped_refptr<gpu::PreemptionFlag> preempted_flag_; |
| 228 | 235 |
| 229 std::deque<IPC::Message*> deferred_messages_; | 236 scoped_refptr<GpuChannelMessageQueue> message_queue_; |
| 230 | 237 |
| 231 // The id of the client who is on the other side of the channel. | 238 // The id of the client who is on the other side of the channel. |
| 232 int client_id_; | 239 int client_id_; |
| 233 | 240 |
| 234 // The tracing ID used for memory allocations associated with this client. | 241 // The tracing ID used for memory allocations associated with this client. |
| 235 uint64_t client_tracing_id_; | 242 uint64_t client_tracing_id_; |
| 236 | 243 |
| 237 // The task runners for the main thread and the io thread. | 244 // The task runners for the main thread and the io thread. |
| 238 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 245 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 239 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 246 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 240 | 247 |
| 241 // The share group that all contexts associated with a particular renderer | 248 // The share group that all contexts associated with a particular renderer |
| 242 // process use. | 249 // process use. |
| 243 scoped_refptr<gfx::GLShareGroup> share_group_; | 250 scoped_refptr<gfx::GLShareGroup> share_group_; |
| 244 | 251 |
| 245 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 252 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 246 | 253 |
| 247 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; | 254 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; |
| 248 | 255 |
| 249 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; | 256 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; |
| 250 | 257 |
| 251 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; | 258 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; |
| 252 | 259 |
| 253 gpu::gles2::DisallowedFeatures disallowed_features_; | 260 gpu::gles2::DisallowedFeatures disallowed_features_; |
| 254 GpuWatchdog* watchdog_; | 261 GpuWatchdog* watchdog_; |
| 255 bool software_; | 262 bool software_; |
| 256 bool handle_messages_scheduled_; | 263 GpuChannelMessage* currently_processing_message_; |
| 257 IPC::Message* currently_processing_message_; | 264 |
| 265 // Current IPC order number being processed. |
| 266 uint32_t current_order_num_; |
| 267 |
| 268 // Last finished IPC order number. |
| 269 uint32_t processed_order_num_; |
| 258 | 270 |
| 259 size_t num_stubs_descheduled_; | 271 size_t num_stubs_descheduled_; |
| 260 | |
| 261 bool allow_future_sync_points_; | 272 bool allow_future_sync_points_; |
| 262 | 273 |
| 263 // Member variables should appear before the WeakPtrFactory, to ensure | 274 // Member variables should appear before the WeakPtrFactory, to ensure |
| 264 // that any WeakPtrs to Controller are invalidated before its members | 275 // that any WeakPtrs to Controller are invalidated before its members |
| 265 // variable's destructors are executed, rendering them invalid. | 276 // variable's destructors are executed, rendering them invalid. |
| 266 base::WeakPtrFactory<GpuChannel> weak_factory_; | 277 base::WeakPtrFactory<GpuChannel> weak_factory_; |
| 267 | 278 |
| 268 DISALLOW_COPY_AND_ASSIGN(GpuChannel); | 279 DISALLOW_COPY_AND_ASSIGN(GpuChannel); |
| 269 }; | 280 }; |
| 270 | 281 |
| 271 } // namespace content | 282 } // namespace content |
| 272 | 283 |
| 273 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 284 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
| OLD | NEW |