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/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "gpu/command_buffer/common/buffer.h" | 9 #include "gpu/command_buffer/common/buffer.h" |
| 10 #include "gpu/command_buffer/common/constants.h" |
10 | 11 |
11 namespace gpu { | 12 namespace gpu { |
12 | 13 |
13 // Common interface for CommandBuffer implementations. | 14 // Common interface for CommandBuffer implementations. |
14 class CommandBuffer { | 15 class CommandBuffer { |
15 public: | 16 public: |
| 17 struct State { |
| 18 State() |
| 19 : size(0), |
| 20 get_offset(0), |
| 21 put_offset(0), |
| 22 token(-1), |
| 23 error(parse_error::kParseNoError) { |
| 24 } |
| 25 |
| 26 // Size of the command buffer in command buffer entries. |
| 27 int32 size; |
| 28 |
| 29 // The offset (in entries) from which the reader is reading. |
| 30 int32 get_offset; |
| 31 |
| 32 // The offset (in entries) at which the writer is writing. |
| 33 int32 put_offset; |
| 34 |
| 35 // The current token value. This is used by the writer to defer |
| 36 // changes to shared memory objects until the reader has reached a certain |
| 37 // point in the command buffer. The reader is responsible for updating the |
| 38 // token value, for example in response to an asynchronous set token command |
| 39 // embedded in the command buffer. The default token value is zero. |
| 40 int32 token; |
| 41 |
| 42 // Error status. |
| 43 parse_error::ParseError error; |
| 44 }; |
| 45 |
16 CommandBuffer() { | 46 CommandBuffer() { |
17 } | 47 } |
18 | 48 |
19 virtual ~CommandBuffer() { | 49 virtual ~CommandBuffer() { |
20 } | 50 } |
21 | 51 |
22 // Initialize the command buffer with the given size (number of command | 52 // Initialize the command buffer with the given size (number of command |
23 // entries). | 53 // entries). |
24 virtual bool Initialize(int32 size) = 0; | 54 virtual bool Initialize(int32 size) = 0; |
25 | 55 |
26 // Gets the ring buffer for the command buffer. | 56 // Gets the ring buffer for the command buffer. |
27 virtual Buffer GetRingBuffer() = 0; | 57 virtual Buffer GetRingBuffer() = 0; |
28 | 58 |
29 virtual int32 GetSize() = 0; | 59 // Returns the current status. |
| 60 virtual State GetState() = 0; |
30 | 61 |
31 // The writer calls this to update its put offset. This function returns the | 62 // 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 | 63 // 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. | 64 // change callback has been invoked. Returns -1 if the put offset is invalid. |
34 virtual int32 SyncOffsets(int32 put_offset) = 0; | 65 virtual State Flush(int32 put_offset) = 0; |
35 | |
36 // Returns the current get offset. This can be called from any thread. | |
37 virtual int32 GetGetOffset() = 0; | |
38 | 66 |
39 // Sets the current get offset. This can be called from any thread. | 67 // Sets the current get offset. This can be called from any thread. |
40 virtual void SetGetOffset(int32 get_offset) = 0; | 68 virtual void SetGetOffset(int32 get_offset) = 0; |
41 | 69 |
42 // Returns the current put offset. This can be called from any thread. | |
43 virtual int32 GetPutOffset() = 0; | |
44 | |
45 // Create a transfer buffer and return a handle that uniquely | 70 // Create a transfer buffer and return a handle that uniquely |
46 // identifies it or -1 on error. | 71 // identifies it or -1 on error. |
47 virtual int32 CreateTransferBuffer(size_t size) = 0; | 72 virtual int32 CreateTransferBuffer(size_t size) = 0; |
48 | 73 |
49 // Destroy a transfer buffer and recycle the handle. | 74 // Destroy a transfer buffer and recycle the handle. |
50 virtual void DestroyTransferBuffer(int32 id) = 0; | 75 virtual void DestroyTransferBuffer(int32 id) = 0; |
51 | 76 |
52 // Get the transfer buffer associated with a handle. | 77 // Get the transfer buffer associated with a handle. |
53 virtual Buffer GetTransferBuffer(int32 handle) = 0; | 78 virtual Buffer GetTransferBuffer(int32 handle) = 0; |
54 | 79 |
55 // Get the current token value. This is used for by the writer to defer | |
56 // changes to shared memory objects until the reader has reached a certain | |
57 // point in the command buffer. The reader is responsible for updating the | |
58 // token value, for example in response to an asynchronous set token command | |
59 // embedded in the command buffer. The default token value is zero. | |
60 virtual int32 GetToken() = 0; | |
61 | |
62 // Allows the reader to update the current token value. | 80 // Allows the reader to update the current token value. |
63 virtual void SetToken(int32 token) = 0; | 81 virtual void SetToken(int32 token) = 0; |
64 | 82 |
65 // Get the current parse error and reset it to zero. Zero means no error. Non- | |
66 // zero means error. The default error status is zero. | |
67 virtual int32 ResetParseError() = 0; | |
68 | |
69 // Allows the reader to set the current parse error. | 83 // Allows the reader to set the current parse error. |
70 virtual void SetParseError(int32 parse_error) = 0; | 84 virtual void SetParseError(parse_error::ParseError) = 0; |
71 | |
72 // Returns whether the command buffer is in the error state. | |
73 virtual bool GetErrorStatus() = 0; | |
74 | |
75 // Allows the reader to set the error status. Once in an error state, the | |
76 // command buffer cannot recover and ceases to process commands. | |
77 virtual void RaiseErrorStatus() = 0; | |
78 | 85 |
79 private: | 86 private: |
80 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); | 87 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); |
81 }; | 88 }; |
82 | 89 |
83 } // namespace gpu | 90 } // namespace gpu |
84 | 91 |
85 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ | 92 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ |
OLD | NEW |