| 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 GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
| 10 #include "gpu/command_buffer/common/command_buffer.h" | 12 #include "gpu/command_buffer/common/command_buffer.h" |
| 11 #include "gpu/command_buffer/common/command_buffer_shared.h" | 13 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 14 #include "ui/gfx/gpu_memory_buffer.h" |
| 12 | 15 |
| 13 namespace gpu { | 16 namespace gpu { |
| 17 class GpuMemoryBufferFactory; |
| 18 class TransferBufferManagerInterface; |
| 14 | 19 |
| 15 class TransferBufferManagerInterface; | 20 namespace gles2 { |
| 21 class ImageManager; |
| 22 } |
| 16 | 23 |
| 17 // An object that implements a shared memory command buffer and a synchronous | 24 // An object that implements a shared memory command buffer and a synchronous |
| 18 // API to manage the put and get pointers. | 25 // API to manage the put and get pointers. |
| 19 class GPU_EXPORT CommandBufferService : public CommandBuffer { | 26 class GPU_EXPORT CommandBufferService : public CommandBuffer { |
| 20 public: | 27 public: |
| 21 typedef base::Callback<bool(int32)> GetBufferChangedCallback; | 28 typedef base::Callback<bool(int32)> GetBufferChangedCallback; |
| 22 explicit CommandBufferService( | 29 CommandBufferService( |
| 23 TransferBufferManagerInterface* transfer_buffer_manager); | 30 TransferBufferManagerInterface* transfer_buffer_manager, |
| 31 gles2::ImageManager* image_manager, |
| 32 GpuMemoryBufferFactory* gpu_memory_buffer_factory); |
| 24 virtual ~CommandBufferService(); | 33 virtual ~CommandBufferService(); |
| 25 | 34 |
| 26 // CommandBuffer implementation: | 35 // CommandBuffer implementation: |
| 27 virtual bool Initialize() OVERRIDE; | 36 virtual bool Initialize() OVERRIDE; |
| 28 virtual State GetState() OVERRIDE; | 37 virtual State GetState() OVERRIDE; |
| 29 virtual State GetLastState() OVERRIDE; | 38 virtual State GetLastState() OVERRIDE; |
| 30 virtual int32 GetLastToken() OVERRIDE; | 39 virtual int32 GetLastToken() OVERRIDE; |
| 31 virtual void Flush(int32 put_offset) OVERRIDE; | 40 virtual void Flush(int32 put_offset) OVERRIDE; |
| 32 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; | 41 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; |
| 33 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; | 42 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; |
| 34 virtual void SetGetOffset(int32 get_offset) OVERRIDE; | 43 virtual void SetGetOffset(int32 get_offset) OVERRIDE; |
| 35 virtual Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; | 44 virtual Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; |
| 36 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; | 45 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; |
| 37 virtual Buffer GetTransferBuffer(int32 id) OVERRIDE; | 46 virtual Buffer GetTransferBuffer(int32 id) OVERRIDE; |
| 38 virtual void SetToken(int32 token) OVERRIDE; | 47 virtual void SetToken(int32 token) OVERRIDE; |
| 39 virtual void SetParseError(error::Error error) OVERRIDE; | 48 virtual void SetParseError(error::Error error) OVERRIDE; |
| 40 virtual void SetContextLostReason(error::ContextLostReason) OVERRIDE; | 49 virtual void SetContextLostReason(error::ContextLostReason) OVERRIDE; |
| 41 virtual uint32 InsertSyncPoint() OVERRIDE; | 50 virtual uint32 InsertSyncPoint() OVERRIDE; |
| 51 virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer( |
| 52 size_t width, |
| 53 size_t height, |
| 54 unsigned internalformat, |
| 55 int32* id) OVERRIDE; |
| 56 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; |
| 57 virtual gfx::GLImage* GetImage(int32 id) OVERRIDE; |
| 42 | 58 |
| 43 // Sets a callback that is called whenever the put offset is changed. When | 59 // Sets a callback that is called whenever the put offset is changed. When |
| 44 // called with sync==true, the callback must not return until some progress | 60 // called with sync==true, the callback must not return until some progress |
| 45 // has been made (unless the command buffer is empty), i.e. the get offset | 61 // has been made (unless the command buffer is empty), i.e. the get offset |
| 46 // must have changed. It need not process the entire command buffer though. | 62 // must have changed. It need not process the entire command buffer though. |
| 47 // This allows concurrency between the writer and the reader while giving the | 63 // This allows concurrency between the writer and the reader while giving the |
| 48 // writer a means of waiting for the reader to make some progress before | 64 // writer a means of waiting for the reader to make some progress before |
| 49 // attempting to write more to the command buffer. Takes ownership of | 65 // attempting to write more to the command buffer. Takes ownership of |
| 50 // callback. | 66 // callback. |
| 51 virtual void SetPutOffsetChangeCallback(const base::Closure& callback); | 67 virtual void SetPutOffsetChangeCallback(const base::Closure& callback); |
| 52 // Sets a callback that is called whenever the get buffer is changed. | 68 // Sets a callback that is called whenever the get buffer is changed. |
| 53 virtual void SetGetBufferChangeCallback( | 69 virtual void SetGetBufferChangeCallback( |
| 54 const GetBufferChangedCallback& callback); | 70 const GetBufferChangedCallback& callback); |
| 55 virtual void SetParseErrorCallback(const base::Closure& callback); | 71 virtual void SetParseErrorCallback(const base::Closure& callback); |
| 56 | 72 |
| 57 // Setup the shared memory that shared state should be copied into. | 73 // Setup the shared memory that shared state should be copied into. |
| 58 bool SetSharedStateBuffer(scoped_ptr<base::SharedMemory> shared_state_shm); | 74 bool SetSharedStateBuffer(scoped_ptr<base::SharedMemory> shared_state_shm); |
| 59 | 75 |
| 60 // Copy the current state into the shared state transfer buffer. | 76 // Copy the current state into the shared state transfer buffer. |
| 61 void UpdateState(); | 77 void UpdateState(); |
| 62 | 78 |
| 63 // Register an existing shared memory object and get an ID that can be used | 79 // Register an existing shared memory object and get an ID that can be used |
| 64 // to identify it in the command buffer. Callee dups the handle until | 80 // to identify it in the command buffer. Callee dups the handle until |
| 65 // DestroyTransferBuffer is called. | 81 // DestroyTransferBuffer is called. |
| 66 bool RegisterTransferBuffer(int32 id, | 82 bool RegisterTransferBuffer(int32 id, |
| 67 base::SharedMemory* shared_memory, | 83 base::SharedMemory* shared_memory, |
| 68 size_t size); | 84 size_t size); |
| 69 | 85 |
| 86 // Register an existing gpu memory buffer and get an ID that can be used |
| 87 // to identify it in the command buffer. |
| 88 bool RegisterGpuMemoryBuffer(int32 id, |
| 89 gfx::GpuMemoryBufferHandle buffer, |
| 90 size_t width, |
| 91 size_t height, |
| 92 unsigned internalformat); |
| 93 |
| 70 private: | 94 private: |
| 71 int32 ring_buffer_id_; | 95 int32 ring_buffer_id_; |
| 72 Buffer ring_buffer_; | 96 Buffer ring_buffer_; |
| 73 scoped_ptr<base::SharedMemory> shared_state_shm_; | 97 scoped_ptr<base::SharedMemory> shared_state_shm_; |
| 74 CommandBufferSharedState* shared_state_; | 98 CommandBufferSharedState* shared_state_; |
| 75 int32 num_entries_; | 99 int32 num_entries_; |
| 76 int32 get_offset_; | 100 int32 get_offset_; |
| 77 int32 put_offset_; | 101 int32 put_offset_; |
| 78 base::Closure put_offset_change_callback_; | 102 base::Closure put_offset_change_callback_; |
| 79 GetBufferChangedCallback get_buffer_change_callback_; | 103 GetBufferChangedCallback get_buffer_change_callback_; |
| 80 base::Closure parse_error_callback_; | 104 base::Closure parse_error_callback_; |
| 81 TransferBufferManagerInterface* transfer_buffer_manager_; | 105 TransferBufferManagerInterface* transfer_buffer_manager_; |
| 82 int32 token_; | 106 int32 token_; |
| 83 uint32 generation_; | 107 uint32 generation_; |
| 84 error::Error error_; | 108 error::Error error_; |
| 85 error::ContextLostReason context_lost_reason_; | 109 error::ContextLostReason context_lost_reason_; |
| 110 GpuMemoryBufferFactory* gpu_memory_buffer_factory_; |
| 111 gles2::ImageManager* image_manager_; |
| 112 typedef std::map<int32, gfx::GpuMemoryBuffer*> GpuMemoryBufferMap; |
| 113 GpuMemoryBufferMap gpu_memory_buffers_; |
| 86 | 114 |
| 87 DISALLOW_COPY_AND_ASSIGN(CommandBufferService); | 115 DISALLOW_COPY_AND_ASSIGN(CommandBufferService); |
| 88 }; | 116 }; |
| 89 | 117 |
| 90 } // namespace gpu | 118 } // namespace gpu |
| 91 | 119 |
| 92 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 120 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
| OLD | NEW |