| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "gpu/command_buffer/common/buffer.h" | 12 #include "gpu/command_buffer/common/buffer.h" |
| 13 #include "gpu/command_buffer/common/constants.h" | 13 #include "gpu/command_buffer/common/constants.h" |
| 14 #include "gpu/gpu_export.h" | 14 #include "gpu/gpu_export.h" |
| 15 | 15 |
| 16 namespace gpu { | 16 namespace gpu { |
| 17 | 17 |
| 18 // Common interface for CommandBuffer implementations. | 18 // Common interface for CommandBuffer implementations. |
| 19 class GPU_EXPORT CommandBuffer { | 19 class GPU_EXPORT CommandBuffer { |
| 20 public: | 20 public: |
| 21 struct State { | 21 struct State { |
| 22 State() | 22 State() |
| 23 : get_offset(0), | 23 : get_offset(0), |
| 24 token(-1), | 24 token(-1), |
| 25 release_count(0), |
| 25 error(error::kNoError), | 26 error(error::kNoError), |
| 26 context_lost_reason(error::kUnknown), | 27 context_lost_reason(error::kUnknown), |
| 27 generation(0) { | 28 generation(0) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 // The offset (in entries) from which the reader is reading. | 31 // The offset (in entries) from which the reader is reading. |
| 31 int32_t get_offset; | 32 int32_t get_offset; |
| 32 | 33 |
| 33 // The current token value. This is used by the writer to defer | 34 // The current token value. This is used by the writer to defer |
| 34 // changes to shared memory objects until the reader has reached a certain | 35 // changes to shared memory objects until the reader has reached a certain |
| 35 // point in the command buffer. The reader is responsible for updating the | 36 // point in the command buffer. The reader is responsible for updating the |
| 36 // token value, for example in response to an asynchronous set token command | 37 // token value, for example in response to an asynchronous set token command |
| 37 // embedded in the command buffer. The default token value is zero. | 38 // embedded in the command buffer. The default token value is zero. |
| 38 int32_t token; | 39 int32_t token; |
| 39 | 40 |
| 41 // The fence sync release count. Incremented by InsertFenceSync commands. |
| 42 // Used by the client to monitor sync token progress. |
| 43 uint64_t release_count; |
| 44 |
| 40 // Error status. | 45 // Error status. |
| 41 error::Error error; | 46 error::Error error; |
| 42 | 47 |
| 43 // Lost context detail information. | 48 // Lost context detail information. |
| 44 error::ContextLostReason context_lost_reason; | 49 error::ContextLostReason context_lost_reason; |
| 45 | 50 |
| 46 // Generation index of this state. The generation index is incremented every | 51 // Generation index of this state. The generation index is incremented every |
| 47 // time a new state is retrieved from the command processor, so that | 52 // time a new state is retrieved from the command processor, so that |
| 48 // consistency can be kept even if IPC messages are processed out-of-order. | 53 // consistency can be kept even if IPC messages are processed out-of-order. |
| 49 uint32_t generation; | 54 uint32_t generation; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 67 static bool InRange(int32_t start, int32_t end, int32_t value) { | 72 static bool InRange(int32_t start, int32_t end, int32_t value) { |
| 68 if (start <= end) | 73 if (start <= end) |
| 69 return start <= value && value <= end; | 74 return start <= value && value <= end; |
| 70 else | 75 else |
| 71 return start <= value || value <= end; | 76 return start <= value || value <= end; |
| 72 } | 77 } |
| 73 | 78 |
| 74 // Returns the last state without synchronizing with the service. | 79 // Returns the last state without synchronizing with the service. |
| 75 virtual State GetLastState() = 0; | 80 virtual State GetLastState() = 0; |
| 76 | 81 |
| 77 // Returns the last token without synchronizing with the service. Note that | |
| 78 // while you could just call GetLastState().token, GetLastState needs to be | |
| 79 // fast as it is called for every command where GetLastToken is only called | |
| 80 // by code that needs to know the last token so it can be slower but more up | |
| 81 // to date than GetLastState. | |
| 82 virtual int32_t GetLastToken() = 0; | |
| 83 | |
| 84 // The writer calls this to update its put offset. This ensures the reader | 82 // The writer calls this to update its put offset. This ensures the reader |
| 85 // sees the latest added commands, and will eventually process them. On the | 83 // sees the latest added commands, and will eventually process them. On the |
| 86 // service side, commands are processed up to the given put_offset before | 84 // service side, commands are processed up to the given put_offset before |
| 87 // subsequent Flushes on the same GpuChannel. | 85 // subsequent Flushes on the same GpuChannel. |
| 88 virtual void Flush(int32_t put_offset) = 0; | 86 virtual void Flush(int32_t put_offset) = 0; |
| 89 | 87 |
| 90 // As Flush, ensures that on the service side, commands up to put_offset | 88 // As Flush, ensures that on the service side, commands up to put_offset |
| 91 // are processed but before subsequent commands on the same GpuChannel but | 89 // are processed but before subsequent commands on the same GpuChannel but |
| 92 // flushing to the service may be deferred. | 90 // flushing to the service may be deferred. |
| 93 virtual void OrderingBarrier(int32_t put_offset) = 0; | 91 virtual void OrderingBarrier(int32_t put_offset) = 0; |
| 94 | 92 |
| 95 // The writer calls this to wait until the current token is within a | 93 // The writer calls this to wait until the current token is within a |
| 96 // specific range, inclusive. Can return early if an error is generated. | 94 // specific range, inclusive. Can return early if an error is generated. |
| 97 virtual void WaitForTokenInRange(int32_t start, int32_t end) = 0; | 95 virtual State WaitForTokenInRange(int32_t start, int32_t end) = 0; |
| 98 | 96 |
| 99 // The writer calls this to wait until the current get offset is within a | 97 // The writer calls this to wait until the current get offset is within a |
| 100 // specific range, inclusive. Can return early if an error is generated. | 98 // specific range, inclusive. Can return early if an error is generated. |
| 101 virtual void WaitForGetOffsetInRange(int32_t start, int32_t end) = 0; | 99 virtual State WaitForGetOffsetInRange(int32_t start, int32_t end) = 0; |
| 102 | 100 |
| 103 // Sets the buffer commands are read from. | 101 // Sets the buffer commands are read from. |
| 104 // Also resets the get and put offsets to 0. | 102 // Also resets the get and put offsets to 0. |
| 105 virtual void SetGetBuffer(int32_t transfer_buffer_id) = 0; | 103 virtual void SetGetBuffer(int32_t transfer_buffer_id) = 0; |
| 106 | 104 |
| 107 // Create a transfer buffer of the given size. Returns its ID or -1 on | 105 // Create a transfer buffer of the given size. Returns its ID or -1 on |
| 108 // error. | 106 // error. |
| 109 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, | 107 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, |
| 110 int32_t* id) = 0; | 108 int32_t* id) = 0; |
| 111 | 109 |
| 112 // Destroy a transfer buffer. The ID must be positive. | 110 // Destroy a transfer buffer. The ID must be positive. |
| 113 virtual void DestroyTransferBuffer(int32_t id) = 0; | 111 virtual void DestroyTransferBuffer(int32_t id) = 0; |
| 114 | 112 |
| 115 // The NaCl Win64 build only really needs the struct definitions above; having | |
| 116 // GetLastError declared would mean we'd have to also define it, and pull more | |
| 117 // of gpu in to the NaCl Win64 build. | |
| 118 #if !defined(NACL_WIN64) | |
| 119 // TODO(apatrick): this is a temporary optimization while skia is calling | |
| 120 // RendererGLContext::MakeCurrent prior to every GL call. It saves returning 6 | |
| 121 // ints redundantly when only the error is needed for the CommandBufferProxy | |
| 122 // implementation. | |
| 123 virtual error::Error GetLastError(); | |
| 124 #endif | |
| 125 | |
| 126 private: | 113 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); | 114 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); |
| 128 }; | 115 }; |
| 129 | 116 |
| 130 } // namespace gpu | 117 } // namespace gpu |
| 131 | 118 |
| 132 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ | 119 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ |
| OLD | NEW |