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_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 "../common/buffer.h" | 8 #include "../common/buffer.h" |
9 #include "../common/constants.h" | 9 #include "../common/constants.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 class SharedMemory; | 12 class SharedMemory; |
13 } | 13 } |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 | 16 |
17 // Common interface for CommandBuffer implementations. | 17 // Common interface for CommandBuffer implementations. |
18 class CommandBuffer { | 18 class CommandBuffer { |
19 public: | 19 public: |
20 enum { | 20 enum { |
21 kMaxCommandBufferSize = 4 * 1024 * 1024 | 21 kMaxCommandBufferSize = 4 * 1024 * 1024 |
22 }; | 22 }; |
23 | 23 |
24 struct State { | 24 struct State { |
25 State() | 25 State() |
26 : num_entries(0), | 26 : num_entries(0), |
27 get_offset(0), | 27 get_offset(0), |
28 put_offset(0), | 28 put_offset(0), |
29 token(-1), | 29 token(-1), |
30 error(error::kNoError) { | 30 error(error::kNoError), |
| 31 generation(0) { |
31 } | 32 } |
32 | 33 |
33 // Size of the command buffer in command buffer entries. | 34 // Size of the command buffer in command buffer entries. |
34 int32 num_entries; | 35 int32 num_entries; |
35 | 36 |
36 // The offset (in entries) from which the reader is reading. | 37 // The offset (in entries) from which the reader is reading. |
37 int32 get_offset; | 38 int32 get_offset; |
38 | 39 |
39 // The offset (in entries) at which the writer is writing. | 40 // The offset (in entries) at which the writer is writing. |
40 int32 put_offset; | 41 int32 put_offset; |
41 | 42 |
42 // The current token value. This is used by the writer to defer | 43 // The current token value. This is used by the writer to defer |
43 // changes to shared memory objects until the reader has reached a certain | 44 // changes to shared memory objects until the reader has reached a certain |
44 // point in the command buffer. The reader is responsible for updating the | 45 // point in the command buffer. The reader is responsible for updating the |
45 // token value, for example in response to an asynchronous set token command | 46 // token value, for example in response to an asynchronous set token command |
46 // embedded in the command buffer. The default token value is zero. | 47 // embedded in the command buffer. The default token value is zero. |
47 int32 token; | 48 int32 token; |
48 | 49 |
49 // Error status. | 50 // Error status. |
50 error::Error error; | 51 error::Error error; |
| 52 |
| 53 // Generation index of this state. The generation index is incremented every |
| 54 // time a new state is retrieved from the command processor, so that |
| 55 // consistency can be kept even if IPC messages are processed out-of-order. |
| 56 uint32 generation; |
51 }; | 57 }; |
52 | 58 |
53 CommandBuffer() { | 59 CommandBuffer() { |
54 } | 60 } |
55 | 61 |
56 virtual ~CommandBuffer() { | 62 virtual ~CommandBuffer() { |
57 } | 63 } |
58 | 64 |
59 // Initialize the command buffer with the given size. | 65 // Initialize the command buffer with the given size. |
60 virtual bool Initialize(int32 size) = 0; | 66 virtual bool Initialize(int32 size) = 0; |
61 | 67 |
62 // Initialize the command buffer using the given preallocated buffer. | 68 // Initialize the command buffer using the given preallocated buffer. |
63 virtual bool Initialize(base::SharedMemory* buffer, int32 size) = 0; | 69 virtual bool Initialize(base::SharedMemory* buffer, int32 size) = 0; |
64 | 70 |
65 // Gets the ring buffer for the command buffer. | 71 // Gets the ring buffer for the command buffer. |
66 virtual Buffer GetRingBuffer() = 0; | 72 virtual Buffer GetRingBuffer() = 0; |
67 | 73 |
68 // Returns the current status. | 74 // Returns the current status. |
69 virtual State GetState() = 0; | 75 virtual State GetState() = 0; |
70 | 76 |
71 // The writer calls this to update its put offset. This ensures the reader | 77 // The writer calls this to update its put offset. This ensures the reader |
72 // sees the latest added commands, and will eventually process them. | 78 // sees the latest added commands, and will eventually process them. |
73 virtual void Flush(int32 put_offset) = 0; | 79 virtual void Flush(int32 put_offset) = 0; |
74 | 80 |
75 // The writer calls this to update its put offset. This function returns the | 81 // The writer calls this to update its put offset. This function returns the |
76 // reader's most recent get offset. Does not return until after the put offset | 82 // reader's most recent get offset. Does not return until after the put offset |
77 // change callback has been invoked. Returns -1 if the put offset is invalid. | 83 // change callback has been invoked. Returns -1 if the put offset is invalid. |
78 // As opposed to Flush(), this function guarantees that the reader has | 84 // If last_known_get is different from the reader's current get pointer, this |
79 // processed some commands before returning (assuming the command buffer isn't | 85 // function will return immediately, otherwise it guarantees that the reader |
80 // empty and there is no error). | 86 // has processed some commands before returning (assuming the command buffer |
81 virtual State FlushSync(int32 put_offset) = 0; | 87 // isn't empty and there is no error). |
| 88 virtual State FlushSync(int32 put_offset, int32 last_known_get) = 0; |
82 | 89 |
83 // Sets the current get offset. This can be called from any thread. | 90 // Sets the current get offset. This can be called from any thread. |
84 virtual void SetGetOffset(int32 get_offset) = 0; | 91 virtual void SetGetOffset(int32 get_offset) = 0; |
85 | 92 |
86 // Create a transfer buffer and return a handle that uniquely | 93 // Create a transfer buffer and return a handle that uniquely |
87 // identifies it or -1 on error. id_request lets the caller request a | 94 // identifies it or -1 on error. id_request lets the caller request a |
88 // specific id for the transfer buffer, or -1 if the caller does not care. | 95 // specific id for the transfer buffer, or -1 if the caller does not care. |
89 // If the requested id can not be fulfilled, a different id will be returned. | 96 // If the requested id can not be fulfilled, a different id will be returned. |
90 // id_request must be either -1 or between 0 and 100. | 97 // id_request must be either -1 or between 0 and 100. |
91 virtual int32 CreateTransferBuffer(size_t size, int32 id_request) = 0; | 98 virtual int32 CreateTransferBuffer(size_t size, int32 id_request) = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
112 // Allows the reader to set the current parse error. | 119 // Allows the reader to set the current parse error. |
113 virtual void SetParseError(error::Error) = 0; | 120 virtual void SetParseError(error::Error) = 0; |
114 | 121 |
115 private: | 122 private: |
116 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); | 123 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); |
117 }; | 124 }; |
118 | 125 |
119 } // namespace gpu | 126 } // namespace gpu |
120 | 127 |
121 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ | 128 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ |
OLD | NEW |