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_COMMAND_BUFFER_STUB_H_ |
| 6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include <deque> |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
| 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" |
| 18 #include "base/time/time.h" |
| 19 #include "content/common/content_export.h" |
| 20 #include "content/common/gpu/gpu_memory_manager.h" |
| 21 #include "gpu/command_buffer/common/command_buffer_id.h" |
| 22 #include "gpu/command_buffer/common/constants.h" |
| 23 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 24 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 25 #include "gpu/command_buffer/service/command_executor.h" |
| 26 #include "gpu/command_buffer/service/context_group.h" |
| 27 #include "gpu/ipc/common/surface_handle.h" |
| 28 #include "ipc/ipc_listener.h" |
| 29 #include "ipc/ipc_sender.h" |
| 30 #include "ui/events/latency_info.h" |
| 31 #include "ui/gfx/geometry/size.h" |
| 32 #include "ui/gfx/gpu_memory_buffer.h" |
| 33 #include "ui/gfx/swap_result.h" |
| 34 #include "ui/gl/gl_surface.h" |
| 35 #include "ui/gl/gpu_preference.h" |
| 36 #include "url/gurl.h" |
| 37 |
| 38 namespace gpu { |
| 39 struct Mailbox; |
| 40 struct SyncToken; |
| 41 class SyncPointClient; |
| 42 class SyncPointManager; |
| 43 class ValueStateMap; |
| 44 namespace gles2 { |
| 45 class MailboxManager; |
| 46 class SubscriptionRefSet; |
| 47 } |
| 48 } |
| 49 |
| 50 struct GpuCommandBufferMsg_CreateImage_Params; |
| 51 |
| 52 namespace content { |
| 53 |
| 54 class GpuChannel; |
| 55 class GpuWatchdog; |
| 56 struct WaitForCommandState; |
| 57 |
| 58 class GpuCommandBufferStub |
| 59 : public IPC::Listener, |
| 60 public IPC::Sender, |
| 61 public base::SupportsWeakPtr<GpuCommandBufferStub> { |
| 62 public: |
| 63 class DestructionObserver { |
| 64 public: |
| 65 // Called in Destroy(), before the context/surface are released. |
| 66 virtual void OnWillDestroyStub() = 0; |
| 67 |
| 68 protected: |
| 69 virtual ~DestructionObserver() {} |
| 70 }; |
| 71 |
| 72 typedef base::Callback<void(const std::vector<ui::LatencyInfo>&)> |
| 73 LatencyInfoCallback; |
| 74 |
| 75 GpuCommandBufferStub( |
| 76 GpuChannel* channel, |
| 77 gpu::SyncPointManager* sync_point_manager, |
| 78 base::SingleThreadTaskRunner* task_runner, |
| 79 GpuCommandBufferStub* share_group, |
| 80 gpu::SurfaceHandle surface_handle, |
| 81 gpu::gles2::MailboxManager* mailbox_manager, |
| 82 gpu::PreemptionFlag* preempt_by_flag, |
| 83 gpu::gles2::SubscriptionRefSet* subscription_ref_set, |
| 84 gpu::ValueStateMap* pending_valuebuffer_state, |
| 85 const gfx::Size& size, |
| 86 const gpu::gles2::DisallowedFeatures& disallowed_features, |
| 87 const std::vector<int32_t>& attribs, |
| 88 gfx::GpuPreference gpu_preference, |
| 89 int32_t stream_id, |
| 90 int32_t route_id, |
| 91 GpuWatchdog* watchdog, |
| 92 const GURL& active_url); |
| 93 |
| 94 ~GpuCommandBufferStub() override; |
| 95 |
| 96 // IPC::Listener implementation: |
| 97 bool OnMessageReceived(const IPC::Message& message) override; |
| 98 |
| 99 // IPC::Sender implementation: |
| 100 bool Send(IPC::Message* msg) override; |
| 101 |
| 102 gpu::gles2::MemoryTracker* GetMemoryTracker() const; |
| 103 |
| 104 // Whether this command buffer can currently handle IPC messages. |
| 105 bool IsScheduled(); |
| 106 |
| 107 // Whether there are commands in the buffer that haven't been processed. |
| 108 bool HasUnprocessedCommands(); |
| 109 |
| 110 gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); } |
| 111 gpu::CommandExecutor* scheduler() const { return executor_.get(); } |
| 112 GpuChannel* channel() const { return channel_; } |
| 113 |
| 114 // Unique command buffer ID for this command buffer stub. |
| 115 gpu::CommandBufferId command_buffer_id() const { return command_buffer_id_; } |
| 116 |
| 117 // Identifies the various GpuCommandBufferStubs in the GPU process belonging |
| 118 // to the same renderer process. |
| 119 int32_t route_id() const { return route_id_; } |
| 120 |
| 121 // Identifies the stream for this command buffer. |
| 122 int32_t stream_id() const { return stream_id_; } |
| 123 |
| 124 gfx::GpuPreference gpu_preference() { return gpu_preference_; } |
| 125 |
| 126 int32_t GetRequestedAttribute(int attr) const; |
| 127 |
| 128 // Sends a message to the console. |
| 129 void SendConsoleMessage(int32_t id, const std::string& message); |
| 130 |
| 131 void SendCachedShader(const std::string& key, const std::string& shader); |
| 132 |
| 133 gfx::GLSurface* surface() const { return surface_.get(); } |
| 134 |
| 135 void AddDestructionObserver(DestructionObserver* observer); |
| 136 void RemoveDestructionObserver(DestructionObserver* observer); |
| 137 |
| 138 void SetLatencyInfoCallback(const LatencyInfoCallback& callback); |
| 139 |
| 140 void MarkContextLost(); |
| 141 |
| 142 const gpu::gles2::FeatureInfo* GetFeatureInfo() const; |
| 143 |
| 144 void SendSwapBuffersCompleted( |
| 145 const std::vector<ui::LatencyInfo>& latency_info, |
| 146 gfx::SwapResult result); |
| 147 void SendUpdateVSyncParameters(base::TimeTicks timebase, |
| 148 base::TimeDelta interval); |
| 149 |
| 150 private: |
| 151 GpuMemoryManager* GetMemoryManager() const; |
| 152 |
| 153 void Destroy(); |
| 154 |
| 155 bool MakeCurrent(); |
| 156 |
| 157 // Cleans up and sends reply if OnInitialize failed. |
| 158 void OnInitializeFailed(IPC::Message* reply_message); |
| 159 |
| 160 scoped_refptr<gfx::GLSurface> CreateSurface(); |
| 161 |
| 162 // Message handlers: |
| 163 void OnInitialize(base::SharedMemoryHandle shared_state_shm, |
| 164 IPC::Message* reply_message); |
| 165 void OnSetGetBuffer(int32_t shm_id, IPC::Message* reply_message); |
| 166 void OnProduceFrontBuffer(const gpu::Mailbox& mailbox); |
| 167 void OnGetState(IPC::Message* reply_message); |
| 168 void OnWaitForTokenInRange(int32_t start, |
| 169 int32_t end, |
| 170 IPC::Message* reply_message); |
| 171 void OnWaitForGetOffsetInRange(int32_t start, |
| 172 int32_t end, |
| 173 IPC::Message* reply_message); |
| 174 void OnAsyncFlush(int32_t put_offset, |
| 175 uint32_t flush_count, |
| 176 const std::vector<ui::LatencyInfo>& latency_info); |
| 177 void OnRegisterTransferBuffer(int32_t id, |
| 178 base::SharedMemoryHandle transfer_buffer, |
| 179 uint32_t size); |
| 180 void OnDestroyTransferBuffer(int32_t id); |
| 181 void OnGetTransferBuffer(int32_t id, IPC::Message* reply_message); |
| 182 |
| 183 void OnEnsureBackbuffer(); |
| 184 |
| 185 void OnSignalSyncToken(const gpu::SyncToken& sync_token, uint32_t id); |
| 186 void OnSignalAck(uint32_t id); |
| 187 void OnSignalQuery(uint32_t query, uint32_t id); |
| 188 |
| 189 void OnFenceSyncRelease(uint64_t release); |
| 190 bool OnWaitFenceSync(gpu::CommandBufferNamespace namespace_id, |
| 191 gpu::CommandBufferId command_buffer_id, |
| 192 uint64_t release); |
| 193 void OnWaitFenceSyncCompleted(gpu::CommandBufferNamespace namespace_id, |
| 194 gpu::CommandBufferId command_buffer_id, |
| 195 uint64_t release); |
| 196 |
| 197 void OnCreateImage(const GpuCommandBufferMsg_CreateImage_Params& params); |
| 198 void OnDestroyImage(int32_t id); |
| 199 void OnCreateStreamTexture(uint32_t texture_id, |
| 200 int32_t stream_id, |
| 201 bool* succeeded); |
| 202 |
| 203 void OnCommandProcessed(); |
| 204 void OnParseError(); |
| 205 void OnSchedulingChanged(bool scheduled); |
| 206 |
| 207 void ReportState(); |
| 208 |
| 209 // Wrapper for CommandExecutor::PutChanged that sets the crash report URL. |
| 210 void PutChanged(); |
| 211 |
| 212 // Poll the command buffer to execute work. |
| 213 void PollWork(); |
| 214 void PerformWork(); |
| 215 |
| 216 // Schedule processing of delayed work. This updates the time at which |
| 217 // delayed work should be processed. |process_delayed_work_time_| is |
| 218 // updated to current time + delay. Call this after processing some amount |
| 219 // of delayed work. |
| 220 void ScheduleDelayedWork(base::TimeDelta delay); |
| 221 |
| 222 bool CheckContextLost(); |
| 223 void CheckCompleteWaits(); |
| 224 void PullTextureUpdates(gpu::CommandBufferNamespace namespace_id, |
| 225 gpu::CommandBufferId command_buffer_id, |
| 226 uint32_t release); |
| 227 |
| 228 // The lifetime of objects of this class is managed by a GpuChannel. The |
| 229 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they |
| 230 // are destroyed. So a raw pointer is safe. |
| 231 GpuChannel* const channel_; |
| 232 |
| 233 // Outlives the stub. |
| 234 gpu::SyncPointManager* const sync_point_manager_; |
| 235 |
| 236 // Task runner for main thread. |
| 237 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 238 |
| 239 // The group of contexts that share namespaces with this context. |
| 240 scoped_refptr<gpu::gles2::ContextGroup> context_group_; |
| 241 |
| 242 bool initialized_; |
| 243 const gpu::SurfaceHandle surface_handle_; |
| 244 gfx::Size initial_size_; |
| 245 gpu::gles2::DisallowedFeatures disallowed_features_; |
| 246 std::vector<int32_t> requested_attribs_; |
| 247 gfx::GpuPreference gpu_preference_; |
| 248 bool use_virtualized_gl_context_; |
| 249 const gpu::CommandBufferId command_buffer_id_; |
| 250 const int32_t stream_id_; |
| 251 const int32_t route_id_; |
| 252 uint32_t last_flush_count_; |
| 253 |
| 254 scoped_ptr<gpu::CommandBufferService> command_buffer_; |
| 255 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; |
| 256 scoped_ptr<gpu::CommandExecutor> executor_; |
| 257 scoped_ptr<gpu::SyncPointClient> sync_point_client_; |
| 258 scoped_refptr<gfx::GLSurface> surface_; |
| 259 gfx::GLSurface::Format surface_format_; |
| 260 |
| 261 GpuWatchdog* watchdog_; |
| 262 |
| 263 base::ObserverList<DestructionObserver> destruction_observers_; |
| 264 |
| 265 bool waiting_for_sync_point_; |
| 266 |
| 267 base::TimeTicks process_delayed_work_time_; |
| 268 uint32_t previous_processed_num_; |
| 269 base::TimeTicks last_idle_time_; |
| 270 |
| 271 scoped_refptr<gpu::PreemptionFlag> preemption_flag_; |
| 272 |
| 273 LatencyInfoCallback latency_info_callback_; |
| 274 |
| 275 GURL active_url_; |
| 276 size_t active_url_hash_; |
| 277 |
| 278 scoped_ptr<WaitForCommandState> wait_for_token_; |
| 279 scoped_ptr<WaitForCommandState> wait_for_get_offset_; |
| 280 |
| 281 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub); |
| 282 }; |
| 283 |
| 284 } // namespace content |
| 285 |
| 286 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ |
OLD | NEW |