| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "gpu/command_buffer/common/command_buffer.h" | 16 #include "gpu/command_buffer/common/command_buffer.h" |
| 17 | 17 |
| 18 namespace gpu { | 18 namespace gpu { |
| 19 | 19 |
| 20 // An object that implements a shared memory command buffer and a synchronous | 20 // An object that implements a shared memory command buffer and a synchronous |
| 21 // API to manage the put and get pointers. | 21 // API to manage the put and get pointers. |
| 22 class CommandBufferService : public CommandBuffer { | 22 class CommandBufferService : public CommandBuffer { |
| 23 public: | 23 public: |
| 24 typedef base::Callback<bool(int32)> GetBufferChangedCallback; |
| 24 CommandBufferService(); | 25 CommandBufferService(); |
| 25 virtual ~CommandBufferService(); | 26 virtual ~CommandBufferService(); |
| 26 | 27 |
| 27 // CommandBuffer implementation: | 28 // CommandBuffer implementation: |
| 28 virtual bool Initialize(int32 size) OVERRIDE; | 29 virtual bool Initialize() OVERRIDE; |
| 29 virtual bool Initialize(base::SharedMemory* buffer, int32 size) OVERRIDE; | |
| 30 virtual Buffer GetRingBuffer() OVERRIDE; | |
| 31 virtual State GetState() OVERRIDE; | 30 virtual State GetState() OVERRIDE; |
| 32 virtual State GetLastState() OVERRIDE; | 31 virtual State GetLastState() OVERRIDE; |
| 33 virtual void Flush(int32 put_offset) OVERRIDE; | 32 virtual void Flush(int32 put_offset) OVERRIDE; |
| 34 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; | 33 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; |
| 34 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; |
| 35 virtual void SetGetOffset(int32 get_offset) OVERRIDE; | 35 virtual void SetGetOffset(int32 get_offset) OVERRIDE; |
| 36 virtual int32 CreateTransferBuffer(size_t size, int32 id_request) OVERRIDE; | 36 virtual int32 CreateTransferBuffer(size_t size, int32 id_request) OVERRIDE; |
| 37 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | 37 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
| 38 size_t size, | 38 size_t size, |
| 39 int32 id_request) OVERRIDE; | 39 int32 id_request) OVERRIDE; |
| 40 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; | 40 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; |
| 41 virtual Buffer GetTransferBuffer(int32 handle) OVERRIDE; | 41 virtual Buffer GetTransferBuffer(int32 handle) OVERRIDE; |
| 42 virtual void SetToken(int32 token) OVERRIDE; | 42 virtual void SetToken(int32 token) OVERRIDE; |
| 43 virtual void SetParseError(error::Error error) OVERRIDE; | 43 virtual void SetParseError(error::Error error) OVERRIDE; |
| 44 virtual void SetContextLostReason(error::ContextLostReason) OVERRIDE; | 44 virtual void SetContextLostReason(error::ContextLostReason) OVERRIDE; |
| 45 | 45 |
| 46 // Sets a callback that is called whenever the put offset is changed. When | 46 // Sets a callback that is called whenever the put offset is changed. When |
| 47 // called with sync==true, the callback must not return until some progress | 47 // called with sync==true, the callback must not return until some progress |
| 48 // has been made (unless the command buffer is empty), i.e. the get offset | 48 // has been made (unless the command buffer is empty), i.e. the get offset |
| 49 // must have changed. It need not process the entire command buffer though. | 49 // must have changed. It need not process the entire command buffer though. |
| 50 // This allows concurrency between the writer and the reader while giving the | 50 // This allows concurrency between the writer and the reader while giving the |
| 51 // writer a means of waiting for the reader to make some progress before | 51 // writer a means of waiting for the reader to make some progress before |
| 52 // attempting to write more to the command buffer. Takes ownership of | 52 // attempting to write more to the command buffer. Takes ownership of |
| 53 // callback. | 53 // callback. |
| 54 virtual void SetPutOffsetChangeCallback(const base::Closure& callback); | 54 virtual void SetPutOffsetChangeCallback(const base::Closure& callback); |
| 55 // Sets a callback that is called whenever the get buffer is changed. |
| 56 virtual void SetGetBufferChangeCallback( |
| 57 const GetBufferChangedCallback& callback); |
| 55 virtual void SetParseErrorCallback(const base::Closure& callback); | 58 virtual void SetParseErrorCallback(const base::Closure& callback); |
| 56 | 59 |
| 57 private: | 60 private: |
| 61 int32 ring_buffer_id_; |
| 58 Buffer ring_buffer_; | 62 Buffer ring_buffer_; |
| 59 int32 num_entries_; | 63 int32 num_entries_; |
| 60 int32 get_offset_; | 64 int32 get_offset_; |
| 61 int32 put_offset_; | 65 int32 put_offset_; |
| 62 base::Closure put_offset_change_callback_; | 66 base::Closure put_offset_change_callback_; |
| 67 GetBufferChangedCallback get_buffer_change_callback_; |
| 63 base::Closure parse_error_callback_; | 68 base::Closure parse_error_callback_; |
| 64 std::vector<Buffer> registered_objects_; | 69 std::vector<Buffer> registered_objects_; |
| 65 std::set<int32> unused_registered_object_elements_; | 70 std::set<int32> unused_registered_object_elements_; |
| 66 int32 token_; | 71 int32 token_; |
| 67 uint32 generation_; | 72 uint32 generation_; |
| 68 error::Error error_; | 73 error::Error error_; |
| 69 error::ContextLostReason context_lost_reason_; | 74 error::ContextLostReason context_lost_reason_; |
| 70 }; | 75 }; |
| 71 | 76 |
| 72 } // namespace gpu | 77 } // namespace gpu |
| 73 | 78 |
| 74 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 79 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
| OLD | NEW |