cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / gpu / command_buffer / common / command_buffer.h
blob3078bca2ba3af97db63fbdd5ecb9da0180d94cbd
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 : num_entries(0),
24 get_offset(0),
25 put_offset(0),
26 token(-1),
27 error(error::kNoError),
28 context_lost_reason(error::kUnknown),
29 generation(0) {
32 // Size of the command buffer in command buffer entries.
33 int32 num_entries;
35 // The offset (in entries) from which the reader is reading.
36 int32 get_offset;
38 // The offset (in entries) at which the writer is writing.
39 int32 put_offset;
41 // The current token value. This is used by the writer to defer
42 // changes to shared memory objects until the reader has reached a certain
43 // point in the command buffer. The reader is responsible for updating the
44 // token value, for example in response to an asynchronous set token command
45 // embedded in the command buffer. The default token value is zero.
46 int32 token;
48 // Error status.
49 error::Error error;
51 // Lost context detail information.
52 error::ContextLostReason context_lost_reason;
54 // Generation index of this state. The generation index is incremented every
55 // time a new state is retrieved from the command processor, so that
56 // consistency can be kept even if IPC messages are processed out-of-order.
57 uint32 generation;
60 struct ConsoleMessage {
61 // An user supplied id.
62 int32 id;
63 // The message.
64 std::string message;
67 CommandBuffer() {
70 virtual ~CommandBuffer() {
73 // Initialize the command buffer with the given size.
74 virtual bool Initialize() = 0;
76 // Returns the current status.
77 virtual State GetState() = 0;
79 // Returns the last state without synchronizing with the service.
80 virtual State GetLastState() = 0;
82 // Returns the last token without synchronizing with the service. Note that
83 // while you could just call GetLastState().token, GetLastState needs to be
84 // fast as it is called for every command where GetLastToken is only called
85 // by code that needs to know the last token so it can be slower but more up
86 // to date than GetLastState.
87 virtual int32 GetLastToken() = 0;
89 // The writer calls this to update its put offset. This ensures the reader
90 // sees the latest added commands, and will eventually process them. On the
91 // service side, commands are processed up to the given put_offset before
92 // subsequent Flushes on the same GpuChannel.
93 virtual void Flush(int32 put_offset) = 0;
95 // The writer calls this to update its put offset. This function returns the
96 // reader's most recent get offset. Does not return until all pending commands
97 // have been executed.
98 virtual State FlushSync(int32 put_offset, int32 last_known_get) = 0;
100 // Sets the buffer commands are read from.
101 // Also resets the get and put offsets to 0.
102 virtual void SetGetBuffer(int32 transfer_buffer_id) = 0;
104 // Sets the current get offset. This can be called from any thread.
105 virtual void SetGetOffset(int32 get_offset) = 0;
107 // Create a transfer buffer of the given size. Returns its ID or -1 on
108 // error.
109 virtual Buffer CreateTransferBuffer(size_t size, int32* id) = 0;
111 // Destroy a transfer buffer. The ID must be positive.
112 virtual void DestroyTransferBuffer(int32 id) = 0;
114 // Get the transfer buffer associated with an ID. Returns a null buffer for
115 // ID 0.
116 virtual Buffer GetTransferBuffer(int32 id) = 0;
118 // Allows the reader to update the current token value.
119 virtual void SetToken(int32 token) = 0;
121 // Allows the reader to set the current parse error.
122 virtual void SetParseError(error::Error) = 0;
124 // Allows the reader to set the current context lost reason.
125 // NOTE: if calling this in conjunction with SetParseError,
126 // call this first.
127 virtual void SetContextLostReason(error::ContextLostReason) = 0;
129 // The NaCl Win64 build only really needs the struct definitions above; having
130 // GetLastError declared would mean we'd have to also define it, and pull more
131 // of gpu in to the NaCl Win64 build.
132 #if !defined(NACL_WIN64)
133 // TODO(apatrick): this is a temporary optimization while skia is calling
134 // RendererGLContext::MakeCurrent prior to every GL call. It saves returning 6
135 // ints redundantly when only the error is needed for the CommandBufferProxy
136 // implementation.
137 virtual error::Error GetLastError();
138 #endif
140 // Inserts a sync point, returning its ID. Sync point IDs are global and can
141 // be used for cross-context synchronization.
142 virtual uint32 InsertSyncPoint() = 0;
144 private:
145 DISALLOW_COPY_AND_ASSIGN(CommandBuffer);
148 } // namespace gpu
150 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_