Chromium Code Reviews| 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 ChannelMessage; | |
|
piman
2015/09/01 03:55:27
nit: GpuChannelMessage? ChannelMessage is unspecif
David Yen
2015/09/01 19:08:02
Done.
| |
| 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_; } | 154 bool handle_messages_scheduled() const; |
| 148 uint64 messages_processed() const { return messages_processed_; } | |
| 149 | 155 |
| 150 // If |preemption_flag->IsSet()|, any stub on this channel | 156 // If |preemption_flag->IsSet()|, any stub on this channel |
| 151 // should stop issuing GL commands. Setting this to NULL stops deferral. | 157 // should stop issuing GL commands. Setting this to NULL stops deferral. |
| 152 void SetPreemptByFlag( | 158 void SetPreemptByFlag( |
| 153 scoped_refptr<gpu::PreemptionFlag> preemption_flag); | 159 scoped_refptr<gpu::PreemptionFlag> preemption_flag); |
| 154 | 160 |
| 155 void CacheShader(const std::string& key, const std::string& shader); | 161 void CacheShader(const std::string& key, const std::string& shader); |
| 156 | 162 |
| 157 virtual void AddFilter(IPC::MessageFilter* filter); | 163 virtual void AddFilter(IPC::MessageFilter* filter); |
| 158 virtual void RemoveFilter(IPC::MessageFilter* filter); | 164 virtual void RemoveFilter(IPC::MessageFilter* filter); |
| 159 | 165 |
| 160 uint64 GetMemoryUsage(); | 166 uint64 GetMemoryUsage(); |
| 161 | 167 |
| 162 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( | 168 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
| 163 const gfx::GpuMemoryBufferHandle& handle, | 169 const gfx::GpuMemoryBufferHandle& handle, |
| 164 const gfx::Size& size, | 170 const gfx::Size& size, |
| 165 gfx::BufferFormat format, | 171 gfx::BufferFormat format, |
| 166 uint32 internalformat); | 172 uint32 internalformat); |
| 167 | 173 |
| 168 bool allow_future_sync_points() const { return allow_future_sync_points_; } | 174 bool allow_future_sync_points() const { return allow_future_sync_points_; } |
| 169 | 175 |
| 170 void HandleUpdateValueState(unsigned int target, | 176 void HandleUpdateValueState(unsigned int target, |
| 171 const gpu::ValueState& state); | 177 const gpu::ValueState& state); |
| 172 | 178 |
| 173 // Visible for testing. | 179 // Visible for testing. |
| 174 const gpu::ValueStateMap* pending_valuebuffer_state() const { | 180 const gpu::ValueStateMap* pending_valuebuffer_state() const { |
| 175 return pending_valuebuffer_state_.get(); | 181 return pending_valuebuffer_state_.get(); |
| 176 } | 182 } |
| 177 | 183 |
| 184 uint32_t GetCurrentOrderNum() const { return current_order_num_; } | |
| 185 uint32_t GetProcessedOrderNum() const { return processed_order_num_; } | |
| 186 uint32_t GetUnprocessedOrderNum() const; | |
| 187 | |
| 178 protected: | 188 protected: |
| 179 // The message filter on the io thread. | 189 // The message filter on the io thread. |
| 180 scoped_refptr<GpuChannelMessageFilter> filter_; | 190 scoped_refptr<GpuChannelMessageFilter> filter_; |
| 181 | 191 |
| 182 // Map of routing id to command buffer stub. | 192 // Map of routing id to command buffer stub. |
| 183 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; | 193 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; |
| 184 | 194 |
| 185 private: | 195 private: |
| 186 friend class GpuChannelMessageFilter; | 196 friend class GpuChannelMessageFilter; |
| 197 friend class GpuChannelMessageQueue; | |
| 187 | 198 |
| 188 void OnDestroy(); | 199 void OnDestroy(); |
| 189 | 200 |
| 190 bool OnControlMessageReceived(const IPC::Message& msg); | 201 bool OnControlMessageReceived(const IPC::Message& msg); |
| 191 | 202 |
| 192 void HandleMessage(); | 203 void HandleMessage(); |
| 193 | 204 |
| 194 // Message handlers. | 205 // Message handlers. |
| 195 void OnCreateOffscreenCommandBuffer( | 206 void OnCreateOffscreenCommandBuffer( |
| 196 const gfx::Size& size, | 207 const gfx::Size& size, |
| 197 const GPUCreateCommandBufferConfig& init_params, | 208 const GPUCreateCommandBufferConfig& init_params, |
| 198 int32 route_id, | 209 int32 route_id, |
| 199 bool* succeeded); | 210 bool* succeeded); |
| 200 void OnDestroyCommandBuffer(int32 route_id); | 211 void OnDestroyCommandBuffer(int32 route_id); |
| 201 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); | 212 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); |
| 202 | 213 |
| 203 // Decrement the count of unhandled IPC messages and defer preemption. | 214 // Update processed order number and defer preemption. |
| 204 void MessageProcessed(); | 215 void MessageProcessed(uint32_t order_number); |
| 205 | 216 |
| 206 // The lifetime of objects of this class is managed by a GpuChannelManager. | 217 // The lifetime of objects of this class is managed by a GpuChannelManager. |
| 207 // The GpuChannelManager destroy all the GpuChannels that they own when they | 218 // The GpuChannelManager destroy all the GpuChannels that they own when they |
| 208 // are destroyed. So a raw pointer is safe. | 219 // are destroyed. So a raw pointer is safe. |
| 209 GpuChannelManager* gpu_channel_manager_; | 220 GpuChannelManager* gpu_channel_manager_; |
| 210 | 221 |
| 211 scoped_ptr<IPC::SyncChannel> channel_; | 222 scoped_ptr<IPC::SyncChannel> channel_; |
| 212 | 223 |
| 213 // Uniquely identifies the channel within this GPU process. | 224 // Uniquely identifies the channel within this GPU process. |
| 214 std::string channel_id_; | 225 std::string channel_id_; |
| 215 | 226 |
| 216 // Used to implement message routing functionality to CommandBuffer objects | 227 // Used to implement message routing functionality to CommandBuffer objects |
| 217 MessageRouter router_; | 228 MessageRouter router_; |
| 218 | 229 |
| 219 uint64 messages_processed_; | |
| 220 | |
| 221 // Whether the processing of IPCs on this channel is stalled and we should | 230 // Whether the processing of IPCs on this channel is stalled and we should |
| 222 // preempt other GpuChannels. | 231 // preempt other GpuChannels. |
| 223 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; | 232 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; |
| 224 | 233 |
| 225 // If non-NULL, all stubs on this channel should stop processing GL | 234 // If non-NULL, all stubs on this channel should stop processing GL |
| 226 // commands (via their GpuScheduler) when preempted_flag_->IsSet() | 235 // commands (via their GpuScheduler) when preempted_flag_->IsSet() |
| 227 scoped_refptr<gpu::PreemptionFlag> preempted_flag_; | 236 scoped_refptr<gpu::PreemptionFlag> preempted_flag_; |
| 228 | 237 |
| 229 std::deque<IPC::Message*> deferred_messages_; | 238 scoped_refptr<GpuChannelMessageQueue> message_queue_; |
| 230 | 239 |
| 231 // The id of the client who is on the other side of the channel. | 240 // The id of the client who is on the other side of the channel. |
| 232 int client_id_; | 241 int client_id_; |
| 233 | 242 |
| 234 // The tracing ID used for memory allocations associated with this client. | 243 // The tracing ID used for memory allocations associated with this client. |
| 235 uint64_t client_tracing_id_; | 244 uint64_t client_tracing_id_; |
| 236 | 245 |
| 237 // The task runners for the main thread and the io thread. | 246 // The task runners for the main thread and the io thread. |
| 238 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 247 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 239 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 248 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 240 | 249 |
| 241 // The share group that all contexts associated with a particular renderer | 250 // The share group that all contexts associated with a particular renderer |
| 242 // process use. | 251 // process use. |
| 243 scoped_refptr<gfx::GLShareGroup> share_group_; | 252 scoped_refptr<gfx::GLShareGroup> share_group_; |
| 244 | 253 |
| 245 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 254 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 246 | 255 |
| 247 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; | 256 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; |
| 248 | 257 |
| 249 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; | 258 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; |
| 250 | 259 |
| 251 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; | 260 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; |
| 252 | 261 |
| 253 gpu::gles2::DisallowedFeatures disallowed_features_; | 262 gpu::gles2::DisallowedFeatures disallowed_features_; |
| 254 GpuWatchdog* watchdog_; | 263 GpuWatchdog* watchdog_; |
| 255 bool software_; | 264 bool software_; |
| 256 bool handle_messages_scheduled_; | 265 ChannelMessage* currently_processing_message_; |
| 257 IPC::Message* currently_processing_message_; | 266 |
| 267 // Current IPC order number being processed. | |
| 268 uint32_t current_order_num_; | |
| 269 | |
| 270 // Last finished IPC order number. | |
| 271 uint32_t processed_order_num_; | |
| 258 | 272 |
| 259 size_t num_stubs_descheduled_; | 273 size_t num_stubs_descheduled_; |
| 260 | |
| 261 bool allow_future_sync_points_; | 274 bool allow_future_sync_points_; |
| 262 | 275 |
| 263 // Member variables should appear before the WeakPtrFactory, to ensure | 276 // Member variables should appear before the WeakPtrFactory, to ensure |
| 264 // that any WeakPtrs to Controller are invalidated before its members | 277 // that any WeakPtrs to Controller are invalidated before its members |
| 265 // variable's destructors are executed, rendering them invalid. | 278 // variable's destructors are executed, rendering them invalid. |
| 266 base::WeakPtrFactory<GpuChannel> weak_factory_; | 279 base::WeakPtrFactory<GpuChannel> weak_factory_; |
| 267 | 280 |
| 268 DISALLOW_COPY_AND_ASSIGN(GpuChannel); | 281 DISALLOW_COPY_AND_ASSIGN(GpuChannel); |
| 269 }; | 282 }; |
| 270 | 283 |
| 271 } // namespace content | 284 } // namespace content |
| 272 | 285 |
| 273 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 286 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
| OLD | NEW |