Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / common / command_buffer.h
blobb69936320eca53013c0110d77743644c97c14834
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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
6 #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
8 #include "gpu/command_buffer/common/buffer.h"
9 #include "gpu/command_buffer/common/constants.h"
10 #include "gpu/gpu_export.h"
12 namespace base {
13 class SharedMemory;
16 namespace gpu {
18 // Common interface for CommandBuffer implementations.
19 class GPU_EXPORT CommandBuffer {
20 public:
21 struct State {
22 State()
23 : get_offset(0),
24 token(-1),
25 error(error::kNoError),
26 context_lost_reason(error::kUnknown),
27 generation(0) {
30 // The offset (in entries) from which the reader is reading.
31 int32 get_offset;
33 // 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 // 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 // embedded in the command buffer. The default token value is zero.
38 int32 token;
40 // Error status.
41 error::Error error;
43 // Lost context detail information.
44 error::ContextLostReason context_lost_reason;
46 // Generation index of this state. The generation index is incremented every
47 // 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.
49 uint32 generation;
52 struct ConsoleMessage {
53 // An user supplied id.
54 int32 id;
55 // The message.
56 std::string message;
59 CommandBuffer() {
62 virtual ~CommandBuffer() {
65 // Check if a value is between a start and end value, inclusive, allowing
66 // for wrapping if start > end.
67 static bool InRange(int32 start, int32 end, int32 value) {
68 if (start <= end)
69 return start <= value && value <= end;
70 else
71 return start <= value || value <= end;
74 // Initialize the command buffer with the given size.
75 virtual bool Initialize() = 0;
77 // Returns the last state without synchronizing with the service.
78 virtual State GetLastState() = 0;
80 // Returns the last token without synchronizing with the service. Note that
81 // while you could just call GetLastState().token, GetLastState needs to be
82 // fast as it is called for every command where GetLastToken is only called
83 // by code that needs to know the last token so it can be slower but more up
84 // to date than GetLastState.
85 virtual int32 GetLastToken() = 0;
87 // The writer calls this to update its put offset. This ensures the reader
88 // sees the latest added commands, and will eventually process them. On the
89 // service side, commands are processed up to the given put_offset before
90 // subsequent Flushes on the same GpuChannel.
91 virtual void Flush(int32 put_offset) = 0;
93 // As Flush, ensures that on the service side, commands up to put_offset
94 // are processed but before subsequent commands on the same GpuChannel but
95 // flushing to the service may be deferred.
96 virtual void OrderingBarrier(int32 put_offset) = 0;
98 // The writer calls this to wait until the current token is within a
99 // specific range, inclusive. Can return early if an error is generated.
100 virtual void WaitForTokenInRange(int32 start, int32 end) = 0;
102 // The writer calls this to wait until the current get offset is within a
103 // specific range, inclusive. Can return early if an error is generated.
104 virtual void WaitForGetOffsetInRange(int32 start, int32 end) = 0;
106 // Sets the buffer commands are read from.
107 // Also resets the get and put offsets to 0.
108 virtual void SetGetBuffer(int32 transfer_buffer_id) = 0;
110 // Create a transfer buffer of the given size. Returns its ID or -1 on
111 // error.
112 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
113 int32* id) = 0;
115 // Destroy a transfer buffer. The ID must be positive.
116 virtual void DestroyTransferBuffer(int32 id) = 0;
118 // The NaCl Win64 build only really needs the struct definitions above; having
119 // GetLastError declared would mean we'd have to also define it, and pull more
120 // of gpu in to the NaCl Win64 build.
121 #if !defined(NACL_WIN64)
122 // TODO(apatrick): this is a temporary optimization while skia is calling
123 // RendererGLContext::MakeCurrent prior to every GL call. It saves returning 6
124 // ints redundantly when only the error is needed for the CommandBufferProxy
125 // implementation.
126 virtual error::Error GetLastError();
127 #endif
129 private:
130 DISALLOW_COPY_AND_ASSIGN(CommandBuffer);
133 } // namespace gpu
135 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_