| 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_COMMAND_BUFFER_STUB_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ |
| 6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ | 6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <functional> |
| 10 #include <queue> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 14 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 15 #include "content/common/gpu/gpu_memory_manager.h" | 17 #include "content/common/gpu/gpu_memory_manager.h" |
| 16 #include "content/common/gpu/gpu_memory_manager_client.h" | 18 #include "content/common/gpu/gpu_memory_manager_client.h" |
| 17 #include "gpu/command_buffer/common/constants.h" | 19 #include "gpu/command_buffer/common/constants.h" |
| 18 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 20 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 19 #include "gpu/command_buffer/service/command_buffer_service.h" | 21 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 20 #include "gpu/command_buffer/service/context_group.h" | 22 #include "gpu/command_buffer/service/context_group.h" |
| 23 #include "gpu/command_buffer/service/fence_sync_manager.h" |
| 21 #include "gpu/command_buffer/service/gpu_scheduler.h" | 24 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 22 #include "ipc/ipc_listener.h" | 25 #include "ipc/ipc_listener.h" |
| 23 #include "ipc/ipc_sender.h" | 26 #include "ipc/ipc_sender.h" |
| 24 #include "media/base/video_decoder_config.h" | 27 #include "media/base/video_decoder_config.h" |
| 25 #include "ui/events/latency_info.h" | 28 #include "ui/events/latency_info.h" |
| 26 #include "ui/gfx/geometry/size.h" | 29 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gfx/gpu_memory_buffer.h" | 30 #include "ui/gfx/gpu_memory_buffer.h" |
| 28 #include "ui/gfx/native_widget_types.h" | 31 #include "ui/gfx/native_widget_types.h" |
| 29 #include "ui/gfx/swap_result.h" | 32 #include "ui/gfx/swap_result.h" |
| 30 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // If the command buffer is pre-empted and cannot process commands. | 110 // If the command buffer is pre-empted and cannot process commands. |
| 108 bool IsPreempted() const { | 111 bool IsPreempted() const { |
| 109 return scheduler_.get() && scheduler_->IsPreempted(); | 112 return scheduler_.get() && scheduler_->IsPreempted(); |
| 110 } | 113 } |
| 111 | 114 |
| 112 // Whether there are commands in the buffer that haven't been processed. | 115 // Whether there are commands in the buffer that haven't been processed. |
| 113 bool HasUnprocessedCommands(); | 116 bool HasUnprocessedCommands(); |
| 114 | 117 |
| 115 gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); } | 118 gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); } |
| 116 gpu::GpuScheduler* scheduler() const { return scheduler_.get(); } | 119 gpu::GpuScheduler* scheduler() const { return scheduler_.get(); } |
| 120 gpu::FenceSyncManager* fence_sync_manager() const { |
| 121 return fence_sync_manager_.get(); |
| 122 } |
| 117 GpuChannel* channel() const { return channel_; } | 123 GpuChannel* channel() const { return channel_; } |
| 118 | 124 |
| 119 // Identifies the target surface. | 125 // Identifies the target surface. |
| 120 int32 surface_id() const { return surface_id_; } | 126 int32 surface_id() const { return surface_id_; } |
| 121 | 127 |
| 122 // Identifies the various GpuCommandBufferStubs in the GPU process belonging | 128 // Identifies the various GpuCommandBufferStubs in the GPU process belonging |
| 123 // to the same renderer process. | 129 // to the same renderer process. |
| 124 int32 route_id() const { return route_id_; } | 130 int32 route_id() const { return route_id_; } |
| 125 | 131 |
| 126 // Identifies the stream for this command buffer. | 132 // Identifies the stream for this command buffer. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 141 void RemoveDestructionObserver(DestructionObserver* observer); | 147 void RemoveDestructionObserver(DestructionObserver* observer); |
| 142 | 148 |
| 143 // Associates a sync point to this stub. When the stub is destroyed, it will | 149 // Associates a sync point to this stub. When the stub is destroyed, it will |
| 144 // retire all sync points that haven't been previously retired. | 150 // retire all sync points that haven't been previously retired. |
| 145 void AddSyncPoint(uint32 sync_point); | 151 void AddSyncPoint(uint32 sync_point); |
| 146 | 152 |
| 147 void SetPreemptByFlag(scoped_refptr<gpu::PreemptionFlag> flag); | 153 void SetPreemptByFlag(scoped_refptr<gpu::PreemptionFlag> flag); |
| 148 | 154 |
| 149 void SetLatencyInfoCallback(const LatencyInfoCallback& callback); | 155 void SetLatencyInfoCallback(const LatencyInfoCallback& callback); |
| 150 | 156 |
| 157 // Make sure fence sync is released by the time the order number is processed. |
| 158 void ValidateFenceSyncRelease(uint32_t max_order_number, uint32_t release); |
| 159 |
| 151 void MarkContextLost(); | 160 void MarkContextLost(); |
| 152 | 161 |
| 153 const gpu::gles2::FeatureInfo* GetFeatureInfo() const; | 162 const gpu::gles2::FeatureInfo* GetFeatureInfo() const; |
| 154 | 163 |
| 155 void SendSwapBuffersCompleted( | 164 void SendSwapBuffersCompleted( |
| 156 const std::vector<ui::LatencyInfo>& latency_info, | 165 const std::vector<ui::LatencyInfo>& latency_info, |
| 157 gfx::SwapResult result); | 166 gfx::SwapResult result); |
| 158 void SendUpdateVSyncParameters(base::TimeTicks timebase, | 167 void SendUpdateVSyncParameters(base::TimeTicks timebase, |
| 159 base::TimeDelta interval); | 168 base::TimeDelta interval); |
| 160 | 169 |
| 161 private: | 170 private: |
| 171 typedef std::pair<uint32_t, uint32_t> OrderFenceSync; |
| 172 typedef std::priority_queue<OrderFenceSync, |
| 173 std::vector<OrderFenceSync>, |
| 174 std::greater<OrderFenceSync>> OrderFenceQueue; |
| 175 |
| 162 GpuMemoryManager* GetMemoryManager() const; | 176 GpuMemoryManager* GetMemoryManager() const; |
| 163 | 177 |
| 164 void Destroy(); | 178 void Destroy(); |
| 165 | 179 |
| 166 bool MakeCurrent(); | 180 bool MakeCurrent(); |
| 167 | 181 |
| 168 // Cleans up and sends reply if OnInitialize failed. | 182 // Cleans up and sends reply if OnInitialize failed. |
| 169 void OnInitializeFailed(IPC::Message* reply_message); | 183 void OnInitializeFailed(IPC::Message* reply_message); |
| 170 | 184 |
| 171 // Message handlers: | 185 // Message handlers: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 217 |
| 204 void OnEnsureBackbuffer(); | 218 void OnEnsureBackbuffer(); |
| 205 | 219 |
| 206 void OnRetireSyncPoint(uint32 sync_point); | 220 void OnRetireSyncPoint(uint32 sync_point); |
| 207 bool OnWaitSyncPoint(uint32 sync_point); | 221 bool OnWaitSyncPoint(uint32 sync_point); |
| 208 void OnWaitSyncPointCompleted(uint32 sync_point); | 222 void OnWaitSyncPointCompleted(uint32 sync_point); |
| 209 void OnSignalSyncPoint(uint32 sync_point, uint32 id); | 223 void OnSignalSyncPoint(uint32 sync_point, uint32 id); |
| 210 void OnSignalSyncPointAck(uint32 id); | 224 void OnSignalSyncPointAck(uint32 id); |
| 211 void OnSignalQuery(uint32 query, uint32 id); | 225 void OnSignalQuery(uint32 query, uint32 id); |
| 212 | 226 |
| 227 void OnFenceSenceRelease(uint32_t release); |
| 228 bool OnWaitFenceSync(int channel_client_id, |
| 229 uint32_t route_id, |
| 230 uint32_t release); |
| 231 void OnWaitFenceSyncCompleted(int channel_client_id, |
| 232 uint32_t route_id, |
| 233 uint32_t release); |
| 234 void OnOrderNumberReached(uint32_t order_number); |
| 235 |
| 213 void OnSetClientHasMemoryAllocationChangedCallback(bool has_callback); | 236 void OnSetClientHasMemoryAllocationChangedCallback(bool has_callback); |
| 214 | 237 |
| 215 void OnCreateImage(int32 id, | 238 void OnCreateImage(int32 id, |
| 216 gfx::GpuMemoryBufferHandle handle, | 239 gfx::GpuMemoryBufferHandle handle, |
| 217 gfx::Size size, | 240 gfx::Size size, |
| 218 gfx::BufferFormat format, | 241 gfx::BufferFormat format, |
| 219 uint32 internalformat); | 242 uint32 internalformat); |
| 220 void OnDestroyImage(int32 id); | 243 void OnDestroyImage(int32 id); |
| 221 | 244 |
| 222 void OnCommandProcessed(); | 245 void OnCommandProcessed(); |
| 223 void OnParseError(); | 246 void OnParseError(); |
| 224 void OnCreateStreamTexture( | 247 void OnCreateStreamTexture( |
| 225 uint32 texture_id, int32 stream_id, bool* succeeded); | 248 uint32 texture_id, int32 stream_id, bool* succeeded); |
| 226 | 249 |
| 227 void ReportState(); | 250 void ReportState(); |
| 228 | 251 |
| 229 // Wrapper for GpuScheduler::PutChanged that sets the crash report URL. | 252 // Wrapper for GpuScheduler::PutChanged that sets the crash report URL. |
| 230 void PutChanged(); | 253 void PutChanged(); |
| 231 | 254 |
| 232 // Poll the command buffer to execute work. | 255 // Poll the command buffer to execute work. |
| 233 void PollWork(); | 256 void PollWork(); |
| 234 | 257 |
| 235 // Whether this command buffer needs to be polled again in the future. | 258 // Whether this command buffer needs to be polled again in the future. |
| 236 bool HasMoreWork(); | 259 bool HasMoreWork(); |
| 237 | 260 |
| 238 void ScheduleDelayedWork(int64 delay); | 261 void ScheduleDelayedWork(int64 delay); |
| 239 | 262 |
| 240 bool CheckContextLost(); | 263 bool CheckContextLost(); |
| 241 void CheckCompleteWaits(); | 264 void CheckCompleteWaits(); |
| 242 void PullTextureUpdates(uint32 sync_point); | 265 void PullTextureUpdates(int channel_id, uint32_t route_id, uint32 release); |
| 243 | 266 |
| 244 // The lifetime of objects of this class is managed by a GpuChannel. The | 267 // The lifetime of objects of this class is managed by a GpuChannel. The |
| 245 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they | 268 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they |
| 246 // are destroyed. So a raw pointer is safe. | 269 // are destroyed. So a raw pointer is safe. |
| 247 GpuChannel* channel_; | 270 GpuChannel* channel_; |
| 248 | 271 |
| 249 // Task runner for main thread. | 272 // Task runner for main thread. |
| 250 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 273 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 251 | 274 |
| 252 // The group of contexts that share namespaces with this context. | 275 // The group of contexts that share namespaces with this context. |
| 253 scoped_refptr<gpu::gles2::ContextGroup> context_group_; | 276 scoped_refptr<gpu::gles2::ContextGroup> context_group_; |
| 254 | 277 |
| 255 bool initialized_; | 278 bool initialized_; |
| 256 gfx::GLSurfaceHandle handle_; | 279 gfx::GLSurfaceHandle handle_; |
| 257 gfx::Size initial_size_; | 280 gfx::Size initial_size_; |
| 258 gpu::gles2::DisallowedFeatures disallowed_features_; | 281 gpu::gles2::DisallowedFeatures disallowed_features_; |
| 259 std::vector<int32> requested_attribs_; | 282 std::vector<int32> requested_attribs_; |
| 260 gfx::GpuPreference gpu_preference_; | 283 gfx::GpuPreference gpu_preference_; |
| 261 bool use_virtualized_gl_context_; | 284 bool use_virtualized_gl_context_; |
| 262 const int32 stream_id_; | 285 const int32 stream_id_; |
| 263 const int32 route_id_; | 286 const int32 route_id_; |
| 264 const int32 surface_id_; | 287 const int32 surface_id_; |
| 265 bool software_; | 288 bool software_; |
| 266 uint32 last_flush_count_; | 289 uint32 last_flush_count_; |
| 267 | 290 |
| 268 scoped_ptr<gpu::CommandBufferService> command_buffer_; | 291 scoped_ptr<gpu::CommandBufferService> command_buffer_; |
| 269 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; | 292 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; |
| 270 scoped_ptr<gpu::GpuScheduler> scheduler_; | 293 scoped_ptr<gpu::GpuScheduler> scheduler_; |
| 294 scoped_ptr<gpu::FenceSyncManager> fence_sync_manager_; |
| 271 scoped_refptr<gfx::GLSurface> surface_; | 295 scoped_refptr<gfx::GLSurface> surface_; |
| 272 | 296 |
| 273 scoped_ptr<GpuMemoryManagerClientState> memory_manager_client_state_; | 297 scoped_ptr<GpuMemoryManagerClientState> memory_manager_client_state_; |
| 274 // The last memory allocation received from the GpuMemoryManager (used to | 298 // The last memory allocation received from the GpuMemoryManager (used to |
| 275 // elide redundant work). | 299 // elide redundant work). |
| 276 bool last_memory_allocation_valid_; | 300 bool last_memory_allocation_valid_; |
| 277 gpu::MemoryAllocation last_memory_allocation_; | 301 gpu::MemoryAllocation last_memory_allocation_; |
| 278 | 302 |
| 279 GpuWatchdog* watchdog_; | 303 GpuWatchdog* watchdog_; |
| 280 | 304 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 292 | 316 |
| 293 LatencyInfoCallback latency_info_callback_; | 317 LatencyInfoCallback latency_info_callback_; |
| 294 | 318 |
| 295 GURL active_url_; | 319 GURL active_url_; |
| 296 size_t active_url_hash_; | 320 size_t active_url_hash_; |
| 297 | 321 |
| 298 size_t total_gpu_memory_; | 322 size_t total_gpu_memory_; |
| 299 scoped_ptr<WaitForCommandState> wait_for_token_; | 323 scoped_ptr<WaitForCommandState> wait_for_token_; |
| 300 scoped_ptr<WaitForCommandState> wait_for_get_offset_; | 324 scoped_ptr<WaitForCommandState> wait_for_get_offset_; |
| 301 | 325 |
| 326 // In situations where we are waiting on fence syncs that do not exist, we |
| 327 // validate the channel which the fence sync should have occurred by making |
| 328 // sure the order number of that channel does not pass the order number which |
| 329 // the wait command was issued. If that channel's order number reaches the |
| 330 // wait command's order, we should automatically release up to the expected |
| 331 // release count. Note that this also releases other lower release counts, |
| 332 // so a single misbehaved fence sync is enough to invalidate/signal all |
| 333 // previous fence syncs. |
| 334 OrderFenceQueue order_fence_queue_; |
| 335 |
| 302 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub); | 336 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub); |
| 303 }; | 337 }; |
| 304 | 338 |
| 305 } // namespace content | 339 } // namespace content |
| 306 | 340 |
| 307 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ | 341 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ |
| OLD | NEW |