OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ |
| 6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <deque> |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/containers/scoped_ptr_hash_map.h" |
| 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" |
| 19 #include "build/build_config.h" |
| 20 #include "content/common/content_export.h" |
| 21 #include "content/common/gpu/gpu_memory_manager.h" |
| 22 #include "gpu/command_buffer/common/constants.h" |
| 23 #include "ui/gfx/gpu_memory_buffer.h" |
| 24 #include "ui/gfx/native_widget_types.h" |
| 25 #include "ui/gl/gl_surface.h" |
| 26 #include "url/gurl.h" |
| 27 |
| 28 #if defined(OS_MACOSX) |
| 29 #include "base/callback.h" |
| 30 #include "base/containers/hash_tables.h" |
| 31 #endif |
| 32 |
| 33 namespace base { |
| 34 class WaitableEvent; |
| 35 } |
| 36 |
| 37 namespace gfx { |
| 38 class GLShareGroup; |
| 39 } |
| 40 |
| 41 namespace gpu { |
| 42 struct GpuPreferences; |
| 43 class PreemptionFlag; |
| 44 class SyncPointClient; |
| 45 class SyncPointManager; |
| 46 struct SyncToken; |
| 47 union ValueState; |
| 48 namespace gles2 { |
| 49 class FramebufferCompletenessCache; |
| 50 class MailboxManager; |
| 51 class ProgramCache; |
| 52 class ShaderTranslatorCache; |
| 53 } |
| 54 } |
| 55 |
| 56 namespace IPC { |
| 57 struct ChannelHandle; |
| 58 } |
| 59 |
| 60 namespace content { |
| 61 class GpuChannel; |
| 62 class GpuChannelManagerDelegate; |
| 63 class GpuMemoryBufferFactory; |
| 64 class GpuWatchdog; |
| 65 |
| 66 // A GpuChannelManager is a thread responsible for issuing rendering commands |
| 67 // managing the lifetimes of GPU channels and forwarding IPC requests from the |
| 68 // browser process to them based on the corresponding renderer ID. |
| 69 class CONTENT_EXPORT GpuChannelManager { |
| 70 public: |
| 71 #if defined(OS_MACOSX) |
| 72 typedef base::Callback< |
| 73 void(int32_t, const base::TimeTicks&, const base::TimeDelta&)> |
| 74 BufferPresentedCallback; |
| 75 #endif |
| 76 GpuChannelManager(const gpu::GpuPreferences& gpu_preferences, |
| 77 GpuChannelManagerDelegate* delegate, |
| 78 GpuWatchdog* watchdog, |
| 79 base::SingleThreadTaskRunner* task_runner, |
| 80 base::SingleThreadTaskRunner* io_task_runner, |
| 81 base::WaitableEvent* shutdown_event, |
| 82 gpu::SyncPointManager* sync_point_manager, |
| 83 GpuMemoryBufferFactory* gpu_memory_buffer_factory); |
| 84 virtual ~GpuChannelManager(); |
| 85 |
| 86 GpuChannelManagerDelegate* delegate() const { return delegate_; } |
| 87 |
| 88 IPC::ChannelHandle EstablishChannel(int client_id, |
| 89 uint64_t client_tracing_id, |
| 90 bool preempts, |
| 91 bool allow_view_command_buffers, |
| 92 bool allow_real_time_streams); |
| 93 |
| 94 void PopulateShaderCache(const std::string& shader); |
| 95 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 96 int client_id, |
| 97 const gpu::SyncToken& sync_token); |
| 98 void UpdateValueState(int client_id, |
| 99 unsigned int target, |
| 100 const gpu::ValueState& state); |
| 101 #if defined(OS_ANDROID) |
| 102 void WakeUpGpu(); |
| 103 #endif |
| 104 void DestroyAllChannels(); |
| 105 |
| 106 // Remove the channel for a particular renderer. |
| 107 void RemoveChannel(int client_id); |
| 108 |
| 109 void LoseAllContexts(); |
| 110 |
| 111 #if defined(OS_MACOSX) |
| 112 void AddBufferPresentedCallback(int32_t routing_id, |
| 113 const BufferPresentedCallback& callback); |
| 114 void RemoveBufferPresentedCallback(int32_t routing_id); |
| 115 void BufferPresented(int32_t surface_id, |
| 116 const base::TimeTicks& vsync_timebase, |
| 117 const base::TimeDelta& vsync_interval); |
| 118 #endif |
| 119 |
| 120 const gpu::GpuPreferences& gpu_preferences() const { |
| 121 return gpu_preferences_; |
| 122 } |
| 123 gpu::gles2::ProgramCache* program_cache(); |
| 124 gpu::gles2::ShaderTranslatorCache* shader_translator_cache(); |
| 125 gpu::gles2::FramebufferCompletenessCache* framebuffer_completeness_cache(); |
| 126 |
| 127 GpuMemoryManager* gpu_memory_manager() { return &gpu_memory_manager_; } |
| 128 |
| 129 GpuChannel* LookupChannel(int32_t client_id) const; |
| 130 |
| 131 gfx::GLSurface* GetDefaultOffscreenSurface(); |
| 132 |
| 133 GpuMemoryBufferFactory* gpu_memory_buffer_factory() { |
| 134 return gpu_memory_buffer_factory_; |
| 135 } |
| 136 |
| 137 // Returns the maximum order number for unprocessed IPC messages across all |
| 138 // channels. |
| 139 uint32_t GetUnprocessedOrderNum() const; |
| 140 |
| 141 // Returns the maximum order number for processed IPC messages across all |
| 142 // channels. |
| 143 uint32_t GetProcessedOrderNum() const; |
| 144 |
| 145 #if defined(OS_ANDROID) |
| 146 void DidAccessGpu(); |
| 147 #endif |
| 148 |
| 149 protected: |
| 150 virtual scoped_ptr<GpuChannel> CreateGpuChannel( |
| 151 int client_id, |
| 152 uint64_t client_tracing_id, |
| 153 bool preempts, |
| 154 bool allow_view_command_buffers, |
| 155 bool allow_real_time_streams); |
| 156 |
| 157 gpu::SyncPointManager* sync_point_manager() const { |
| 158 return sync_point_manager_; |
| 159 } |
| 160 |
| 161 gfx::GLShareGroup* share_group() const { return share_group_.get(); } |
| 162 gpu::gles2::MailboxManager* mailbox_manager() const { |
| 163 return mailbox_manager_.get(); |
| 164 } |
| 165 gpu::PreemptionFlag* preemption_flag() const { |
| 166 return preemption_flag_.get(); |
| 167 } |
| 168 |
| 169 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 170 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 171 |
| 172 // These objects manage channels to individual renderer processes there is |
| 173 // one channel for each renderer process that has connected to this GPU |
| 174 // process. |
| 175 base::ScopedPtrHashMap<int32_t, scoped_ptr<GpuChannel>> gpu_channels_; |
| 176 |
| 177 private: |
| 178 void InternalDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); |
| 179 void InternalDestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, |
| 180 int client_id); |
| 181 #if defined(OS_ANDROID) |
| 182 void ScheduleWakeUpGpu(); |
| 183 void DoWakeUpGpu(); |
| 184 #endif |
| 185 |
| 186 const gpu::GpuPreferences& gpu_preferences_; |
| 187 |
| 188 GpuChannelManagerDelegate* const delegate_; |
| 189 #if defined(OS_MACOSX) |
| 190 base::hash_map<int32_t, BufferPresentedCallback> |
| 191 buffer_presented_callback_map_; |
| 192 #endif |
| 193 |
| 194 GpuWatchdog* watchdog_; |
| 195 |
| 196 base::WaitableEvent* shutdown_event_; |
| 197 |
| 198 scoped_refptr<gfx::GLShareGroup> share_group_; |
| 199 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 200 scoped_refptr<gpu::PreemptionFlag> preemption_flag_; |
| 201 GpuMemoryManager gpu_memory_manager_; |
| 202 // SyncPointManager guaranteed to outlive running MessageLoop. |
| 203 gpu::SyncPointManager* sync_point_manager_; |
| 204 scoped_ptr<gpu::SyncPointClient> sync_point_client_waiter_; |
| 205 scoped_ptr<gpu::gles2::ProgramCache> program_cache_; |
| 206 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; |
| 207 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> |
| 208 framebuffer_completeness_cache_; |
| 209 scoped_refptr<gfx::GLSurface> default_offscreen_surface_; |
| 210 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_; |
| 211 #if defined(OS_ANDROID) |
| 212 // Last time we know the GPU was powered on. Global for tracking across all |
| 213 // transport surfaces. |
| 214 base::TimeTicks last_gpu_access_time_; |
| 215 base::TimeTicks begin_wake_up_time_; |
| 216 #endif |
| 217 |
| 218 // Member variables should appear before the WeakPtrFactory, to ensure |
| 219 // that any WeakPtrs to Controller are invalidated before its members |
| 220 // variable's destructors are executed, rendering them invalid. |
| 221 base::WeakPtrFactory<GpuChannelManager> weak_factory_; |
| 222 |
| 223 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager); |
| 224 }; |
| 225 |
| 226 } // namespace content |
| 227 |
| 228 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_ |
OLD | NEW |