OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/linked_ptr.h" | 12 #include "base/linked_ptr.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/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 CommandBufferService(); | 24 CommandBufferService(); |
25 virtual ~CommandBufferService(); | 25 virtual ~CommandBufferService(); |
26 | 26 |
27 // CommandBuffer implementation: | 27 // CommandBuffer implementation: |
28 virtual bool Initialize(int32 size); | 28 virtual bool Initialize(int32 size); |
| 29 virtual bool Initialize(base::SharedMemory* buffer, int32 size); |
29 virtual Buffer GetRingBuffer(); | 30 virtual Buffer GetRingBuffer(); |
30 virtual State GetState(); | 31 virtual State GetState(); |
31 virtual void Flush(int32 put_offset); | 32 virtual void Flush(int32 put_offset); |
32 virtual State FlushSync(int32 put_offset); | 33 virtual State FlushSync(int32 put_offset); |
33 virtual void SetGetOffset(int32 get_offset); | 34 virtual void SetGetOffset(int32 get_offset); |
34 virtual int32 CreateTransferBuffer(size_t size); | 35 virtual int32 CreateTransferBuffer(size_t size); |
35 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | 36 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
36 size_t size); | 37 size_t size); |
37 virtual void DestroyTransferBuffer(int32 id); | 38 virtual void DestroyTransferBuffer(int32 id); |
38 virtual Buffer GetTransferBuffer(int32 handle); | 39 virtual Buffer GetTransferBuffer(int32 handle); |
39 virtual void SetToken(int32 token); | 40 virtual void SetToken(int32 token); |
40 virtual void SetParseError(error::Error error); | 41 virtual void SetParseError(error::Error error); |
41 | 42 |
42 // Sets a callback that should be posted on another thread whenever the put | 43 // Sets a callback that should be posted on another thread whenever the put |
43 // offset is changed. The callback must not return until some progress has | 44 // offset is changed. The callback must not return until some progress has |
44 // been made (unless the command buffer is empty), i.e. the | 45 // been made (unless the command buffer is empty), i.e. the |
45 // get offset must have changed. It need not process the entire command | 46 // get offset must have changed. It need not process the entire command |
46 // buffer though. This allows concurrency between the writer and the reader | 47 // buffer though. This allows concurrency between the writer and the reader |
47 // while giving the writer a means of waiting for the reader to make some | 48 // while giving the writer a means of waiting for the reader to make some |
48 // progress before attempting to write more to the command buffer. Avoiding | 49 // progress before attempting to write more to the command buffer. Avoiding |
49 // the use of a synchronization primitive like a condition variable to | 50 // the use of a synchronization primitive like a condition variable to |
50 // synchronize reader and writer reduces the risk of deadlock. | 51 // synchronize reader and writer reduces the risk of deadlock. |
51 // Takes ownership of callback. The callback is invoked on the plugin thread. | 52 // Takes ownership of callback. The callback is invoked on the plugin thread. |
52 virtual void SetPutOffsetChangeCallback(Callback0::Type* callback); | 53 virtual void SetPutOffsetChangeCallback(Callback0::Type* callback); |
53 | 54 |
54 private: | 55 private: |
55 scoped_ptr< base::SharedMemory> ring_buffer_; | 56 Buffer ring_buffer_; |
56 int32 num_entries_; | 57 int32 num_entries_; |
57 int32 get_offset_; | 58 int32 get_offset_; |
58 int32 put_offset_; | 59 int32 put_offset_; |
59 scoped_ptr<Callback0::Type> put_offset_change_callback_; | 60 scoped_ptr<Callback0::Type> put_offset_change_callback_; |
60 std::vector<Buffer> registered_objects_; | 61 std::vector<Buffer> registered_objects_; |
61 std::set<int32> unused_registered_object_elements_; | 62 std::set<int32> unused_registered_object_elements_; |
62 int32 token_; | 63 int32 token_; |
63 error::Error error_; | 64 error::Error error_; |
64 }; | 65 }; |
65 | 66 |
66 } // namespace gpu | 67 } // namespace gpu |
67 | 68 |
68 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 69 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
OLD | NEW |