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_MANAGER_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ |
6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ | 6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
15 #include "base/id_map.h" | |
16 #include "base/macros.h" | 15 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
20 #include "build/build_config.h" | 19 #include "build/build_config.h" |
21 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
22 #include "content/common/content_param_traits.h" | 21 #include "content/common/content_param_traits.h" |
23 #include "content/common/gpu/gpu_memory_manager.h" | 22 #include "content/common/gpu/gpu_memory_manager.h" |
24 #include "gpu/command_buffer/common/constants.h" | 23 #include "ipc/ipc_listener.h" |
| 24 #include "ipc/ipc_sender.h" |
| 25 #include "ipc/message_router.h" |
25 #include "ui/gfx/gpu_memory_buffer.h" | 26 #include "ui/gfx/gpu_memory_buffer.h" |
26 #include "ui/gfx/native_widget_types.h" | 27 #include "ui/gfx/native_widget_types.h" |
27 #include "ui/gl/gl_surface.h" | 28 #include "ui/gl/gl_surface.h" |
28 #include "url/gurl.h" | |
29 | 29 |
30 namespace base { | 30 namespace base { |
31 class WaitableEvent; | 31 class WaitableEvent; |
32 } | 32 } |
33 | 33 |
34 namespace gfx { | 34 namespace gfx { |
35 class GLShareGroup; | 35 class GLShareGroup; |
36 } | 36 } |
37 | 37 |
38 namespace gpu { | 38 namespace gpu { |
39 class PreemptionFlag; | 39 class PreemptionFlag; |
40 class SyncPointClient; | 40 class SyncPointClient; |
41 class SyncPointManager; | 41 class SyncPointManager; |
42 struct SyncToken; | 42 struct SyncToken; |
43 union ValueState; | 43 union ValueState; |
44 namespace gles2 { | 44 namespace gles2 { |
45 class FramebufferCompletenessCache; | 45 class FramebufferCompletenessCache; |
46 class MailboxManager; | 46 class MailboxManager; |
47 class ProgramCache; | 47 class ProgramCache; |
48 class ShaderTranslatorCache; | 48 class ShaderTranslatorCache; |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 namespace IPC { | 52 namespace IPC { |
53 struct ChannelHandle; | 53 struct ChannelHandle; |
| 54 class SyncChannel; |
54 } | 55 } |
55 | 56 |
| 57 struct GPUCreateCommandBufferConfig; |
| 58 struct GpuMsg_EstablishChannel_Params; |
| 59 |
56 namespace content { | 60 namespace content { |
57 class GpuChannel; | 61 class GpuChannel; |
58 class GpuChannelManagerDelegate; | |
59 class GpuMemoryBufferFactory; | 62 class GpuMemoryBufferFactory; |
60 class GpuWatchdog; | 63 class GpuWatchdog; |
61 class ImageTransportHelper; | |
62 struct EstablishChannelParams; | |
63 #if defined(OS_MACOSX) | |
64 struct BufferPresentedParams; | |
65 #endif | |
66 | 64 |
67 // A GpuChannelManager is a thread responsible for issuing rendering commands | 65 // A GpuChannelManager is a thread responsible for issuing rendering commands |
68 // managing the lifetimes of GPU channels and forwarding IPC requests from the | 66 // managing the lifetimes of GPU channels and forwarding IPC requests from the |
69 // browser process to them based on the corresponding renderer ID. | 67 // browser process to them based on the corresponding renderer ID. |
70 class CONTENT_EXPORT GpuChannelManager { | 68 class CONTENT_EXPORT GpuChannelManager : public IPC::Listener, |
| 69 public IPC::Sender { |
71 public: | 70 public: |
72 GpuChannelManager(GpuChannelManagerDelegate* delegate, | 71 GpuChannelManager(IPC::SyncChannel* channel, |
73 GpuWatchdog* watchdog, | 72 GpuWatchdog* watchdog, |
74 base::SingleThreadTaskRunner* task_runner, | 73 base::SingleThreadTaskRunner* task_runner, |
75 base::SingleThreadTaskRunner* io_task_runner, | 74 base::SingleThreadTaskRunner* io_task_runner, |
76 base::WaitableEvent* shutdown_event, | 75 base::WaitableEvent* shutdown_event, |
77 gpu::SyncPointManager* sync_point_manager, | 76 gpu::SyncPointManager* sync_point_manager, |
78 GpuMemoryBufferFactory* gpu_memory_buffer_factory); | 77 GpuMemoryBufferFactory* gpu_memory_buffer_factory); |
79 virtual ~GpuChannelManager(); | 78 ~GpuChannelManager() override; |
80 | |
81 GpuChannelManagerDelegate* delegate() const { return delegate_; } | |
82 | |
83 void EstablishChannel(const EstablishChannelParams& params); | |
84 void CloseChannel(const IPC::ChannelHandle& channel_handle); | |
85 void PopulateShaderCache(const std::string& shader); | |
86 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
87 int client_id, | |
88 const gpu::SyncToken& sync_token); | |
89 void UpdateValueState(int client_id, | |
90 unsigned int target, | |
91 const gpu::ValueState& state); | |
92 #if defined(OS_ANDROID) | |
93 void WakeUpGpu(); | |
94 #endif | |
95 void DestroyAllChannels(); | |
96 | 79 |
97 // Remove the channel for a particular renderer. | 80 // Remove the channel for a particular renderer. |
98 void RemoveChannel(int client_id); | 81 void RemoveChannel(int client_id); |
99 | 82 |
| 83 // Listener overrides. |
| 84 bool OnMessageReceived(const IPC::Message& msg) override; |
| 85 |
| 86 // Sender overrides. |
| 87 bool Send(IPC::Message* msg) override; |
| 88 |
100 void LoseAllContexts(); | 89 void LoseAllContexts(); |
101 | 90 |
102 #if defined(OS_MACOSX) | 91 int GenerateRouteID(); |
103 void AddImageTransportSurface(int32_t routing_id, | 92 void AddRoute(int32_t routing_id, IPC::Listener* listener); |
104 ImageTransportHelper* image_transport_helper); | 93 void RemoveRoute(int32_t routing_id); |
105 void RemoveImageTransportSurface(int32_t routing_id); | |
106 void BufferPresented(const BufferPresentedParams& params); | |
107 #endif | |
108 | 94 |
109 gpu::gles2::ProgramCache* program_cache(); | 95 gpu::gles2::ProgramCache* program_cache(); |
110 gpu::gles2::ShaderTranslatorCache* shader_translator_cache(); | 96 gpu::gles2::ShaderTranslatorCache* shader_translator_cache(); |
111 gpu::gles2::FramebufferCompletenessCache* framebuffer_completeness_cache(); | 97 gpu::gles2::FramebufferCompletenessCache* framebuffer_completeness_cache(); |
112 | 98 |
113 GpuMemoryManager* gpu_memory_manager() { return &gpu_memory_manager_; } | 99 GpuMemoryManager* gpu_memory_manager() { return &gpu_memory_manager_; } |
114 | 100 |
115 GpuChannel* LookupChannel(int32_t client_id) const; | 101 GpuChannel* LookupChannel(int32_t client_id) const; |
116 | 102 |
117 gfx::GLSurface* GetDefaultOffscreenSurface(); | 103 gfx::GLSurface* GetDefaultOffscreenSurface(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 140 |
155 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 141 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
156 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 142 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
157 | 143 |
158 // These objects manage channels to individual renderer processes there is | 144 // These objects manage channels to individual renderer processes there is |
159 // one channel for each renderer process that has connected to this GPU | 145 // one channel for each renderer process that has connected to this GPU |
160 // process. | 146 // process. |
161 base::ScopedPtrHashMap<int32_t, scoped_ptr<GpuChannel>> gpu_channels_; | 147 base::ScopedPtrHashMap<int32_t, scoped_ptr<GpuChannel>> gpu_channels_; |
162 | 148 |
163 private: | 149 private: |
164 void InternalDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); | 150 // Message handlers. |
165 void InternalDestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, | 151 bool OnControlMessageReceived(const IPC::Message& msg); |
166 int client_id); | 152 void OnEstablishChannel(const GpuMsg_EstablishChannel_Params& params); |
| 153 void OnCloseChannel(const IPC::ChannelHandle& channel_handle); |
| 154 void OnVisibilityChanged(int32_t render_view_id, |
| 155 int32_t client_id, |
| 156 bool visible); |
| 157 void OnLoadedShader(const std::string& shader); |
| 158 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); |
| 159 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id); |
| 160 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 161 int client_id, |
| 162 const gpu::SyncToken& sync_token); |
| 163 |
| 164 void OnUpdateValueState(int client_id, |
| 165 unsigned int target, |
| 166 const gpu::ValueState& state); |
167 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
| 168 void OnWakeUpGpu(); |
168 void ScheduleWakeUpGpu(); | 169 void ScheduleWakeUpGpu(); |
169 void DoWakeUpGpu(); | 170 void DoWakeUpGpu(); |
170 #endif | 171 #endif |
| 172 void OnLoseAllContexts(); |
171 | 173 |
172 GpuChannelManagerDelegate* const delegate_; | 174 // Used to send and receive IPC messages from the browser process. |
173 #if defined(OS_MACOSX) | 175 IPC::SyncChannel* const channel_; |
174 IDMap<ImageTransportHelper> image_transport_map_; | 176 IPC::MessageRouter router_; |
175 #endif | |
176 | 177 |
177 GpuWatchdog* watchdog_; | 178 GpuWatchdog* watchdog_; |
178 | 179 |
179 base::WaitableEvent* shutdown_event_; | 180 base::WaitableEvent* shutdown_event_; |
180 | 181 |
181 scoped_refptr<gfx::GLShareGroup> share_group_; | 182 scoped_refptr<gfx::GLShareGroup> share_group_; |
182 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 183 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
183 scoped_refptr<gpu::PreemptionFlag> preemption_flag_; | 184 scoped_refptr<gpu::PreemptionFlag> preemption_flag_; |
184 GpuMemoryManager gpu_memory_manager_; | 185 GpuMemoryManager gpu_memory_manager_; |
185 // SyncPointManager guaranteed to outlive running MessageLoop. | 186 // SyncPointManager guaranteed to outlive running MessageLoop. |
(...skipping 16 matching lines...) Expand all Loading... |
202 // that any WeakPtrs to Controller are invalidated before its members | 203 // that any WeakPtrs to Controller are invalidated before its members |
203 // variable's destructors are executed, rendering them invalid. | 204 // variable's destructors are executed, rendering them invalid. |
204 base::WeakPtrFactory<GpuChannelManager> weak_factory_; | 205 base::WeakPtrFactory<GpuChannelManager> weak_factory_; |
205 | 206 |
206 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager); | 207 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager); |
207 }; | 208 }; |
208 | 209 |
209 } // namespace content | 210 } // namespace content |
210 | 211 |
211 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ | 212 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ |
OLD | NEW |