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