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_COMMON_COMMAND_BUFFER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ |
6 #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ | 6 #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ |
7 | 7 |
8 #include "base/shared_memory.h" | |
9 #include "base/task.h" | 8 #include "base/task.h" |
| 9 #include "gpu/command_buffer/common/buffer.h" |
10 | 10 |
11 namespace gpu { | 11 namespace gpu { |
12 | 12 |
13 // Common interface for CommandBuffer implementations. | 13 // Common interface for CommandBuffer implementations. |
14 class CommandBuffer { | 14 class CommandBuffer { |
15 public: | 15 public: |
16 CommandBuffer() { | 16 CommandBuffer() { |
17 } | 17 } |
18 | 18 |
19 virtual ~CommandBuffer() { | 19 virtual ~CommandBuffer() { |
20 } | 20 } |
21 | 21 |
22 // Initialize the command buffer with the given size (number of command | 22 // Initialize the command buffer with the given size (number of command |
23 // entries). | 23 // entries). |
24 virtual base::SharedMemory* Initialize(int32 size) = 0; | 24 virtual bool Initialize(int32 size) = 0; |
25 | 25 |
26 // Gets the shared memory ring buffer object for the command buffer. | 26 // Gets the ring buffer for the command buffer. |
27 virtual base::SharedMemory* GetRingBuffer() = 0; | 27 virtual Buffer GetRingBuffer() = 0; |
28 | 28 |
29 virtual int32 GetSize() = 0; | 29 virtual int32 GetSize() = 0; |
30 | 30 |
31 // The writer calls this to update its put offset. This function returns the | 31 // The writer calls this to update its put offset. This function returns the |
32 // reader's most recent get offset. Does not return until after the put offset | 32 // reader's most recent get offset. Does not return until after the put offset |
33 // change callback has been invoked. Returns -1 if the put offset is invalid. | 33 // change callback has been invoked. Returns -1 if the put offset is invalid. |
34 virtual int32 SyncOffsets(int32 put_offset) = 0; | 34 virtual int32 SyncOffsets(int32 put_offset) = 0; |
35 | 35 |
36 // Returns the current get offset. This can be called from any thread. | 36 // Returns the current get offset. This can be called from any thread. |
37 virtual int32 GetGetOffset() = 0; | 37 virtual int32 GetGetOffset() = 0; |
38 | 38 |
39 // Sets the current get offset. This can be called from any thread. | 39 // Sets the current get offset. This can be called from any thread. |
40 virtual void SetGetOffset(int32 get_offset) = 0; | 40 virtual void SetGetOffset(int32 get_offset) = 0; |
41 | 41 |
42 // Returns the current put offset. This can be called from any thread. | 42 // Returns the current put offset. This can be called from any thread. |
43 virtual int32 GetPutOffset() = 0; | 43 virtual int32 GetPutOffset() = 0; |
44 | 44 |
45 // Sets a callback that should be posted on another thread whenever the put | 45 // Sets a callback that should be posted on another thread whenever the put |
46 // offset is changed. The callback must not return until some progress has | 46 // offset is changed. The callback must not return until some progress has |
47 // been made (unless the command buffer is empty), i.e. the | 47 // been made (unless the command buffer is empty), i.e. the |
48 // get offset must have changed. It need not process the entire command | 48 // get offset must have changed. It need not process the entire command |
49 // buffer though. This allows concurrency between the writer and the reader | 49 // buffer though. This allows concurrency between the writer and the reader |
50 // while giving the writer a means of waiting for the reader to make some | 50 // while giving the writer a means of waiting for the reader to make some |
51 // progress before attempting to write more to the command buffer. Avoiding | 51 // progress before attempting to write more to the command buffer. Avoiding |
52 // the use of a synchronization primitive like a condition variable to | 52 // the use of a synchronization primitive like a condition variable to |
53 // synchronize reader and writer reduces the risk of deadlock. | 53 // synchronize reader and writer reduces the risk of deadlock. |
54 // Takes ownership of callback. The callback is invoked on the plugin thread. | 54 // Takes ownership of callback. The callback is invoked on the plugin thread. |
55 virtual void SetPutOffsetChangeCallback(Callback0::Type* callback) = 0; | 55 virtual void SetPutOffsetChangeCallback(Callback0::Type* callback) = 0; |
56 | 56 |
57 // Create a shared memory transfer buffer and return a handle that uniquely | 57 // Create a transfer buffer and return a handle that uniquely |
58 // identifies it or -1 on error. | 58 // identifies it or -1 on error. |
59 virtual int32 CreateTransferBuffer(size_t size) = 0; | 59 virtual int32 CreateTransferBuffer(size_t size) = 0; |
60 | 60 |
61 // Destroy a shared memory transfer buffer and recycle the handle. | 61 // Destroy a transfer buffer and recycle the handle. |
62 virtual void DestroyTransferBuffer(int32 id) = 0; | 62 virtual void DestroyTransferBuffer(int32 id) = 0; |
63 | 63 |
64 // Get the shared memory associated with a handle. | 64 // Get the transfer buffer associated with a handle. |
65 virtual base::SharedMemory* GetTransferBuffer(int32 handle) = 0; | 65 virtual Buffer GetTransferBuffer(int32 handle) = 0; |
66 | 66 |
67 // Get the current token value. This is used for by the writer to defer | 67 // Get the current token value. This is used for by the writer to defer |
68 // changes to shared memory objects until the reader has reached a certain | 68 // changes to shared memory objects until the reader has reached a certain |
69 // point in the command buffer. The reader is responsible for updating the | 69 // point in the command buffer. The reader is responsible for updating the |
70 // token value, for example in response to an asynchronous set token command | 70 // token value, for example in response to an asynchronous set token command |
71 // embedded in the command buffer. The default token value is zero. | 71 // embedded in the command buffer. The default token value is zero. |
72 virtual int32 GetToken() = 0; | 72 virtual int32 GetToken() = 0; |
73 | 73 |
74 // Allows the reader to update the current token value. | 74 // Allows the reader to update the current token value. |
75 virtual void SetToken(int32 token) = 0; | 75 virtual void SetToken(int32 token) = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
88 // command buffer cannot recover and ceases to process commands. | 88 // command buffer cannot recover and ceases to process commands. |
89 virtual void RaiseErrorStatus() = 0; | 89 virtual void RaiseErrorStatus() = 0; |
90 | 90 |
91 private: | 91 private: |
92 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); | 92 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); |
93 }; | 93 }; |
94 | 94 |
95 } // namespace gpu | 95 } // namespace gpu |
96 | 96 |
97 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ | 97 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ |
OLD | NEW |