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"
18 // Common interface for CommandBuffer implementations.
19 class GPU_EXPORT CommandBuffer
{
27 error(error::kNoError
),
28 context_lost_reason(error::kUnknown
),
32 // Size of the command buffer in command buffer entries.
35 // The offset (in entries) from which the reader is reading.
38 // The offset (in entries) at which the writer is writing.
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.
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.
60 struct ConsoleMessage
{
61 // An user supplied id.
70 virtual ~CommandBuffer() {
73 // Check if a value is between a start and end value, inclusive, allowing
74 // for wrapping if start > end.
75 static bool InRange(int32 start
, int32 end
, int32 value
) {
77 return start
<= value
&& value
<= end
;
79 return start
<= value
|| value
<= end
;
82 // Initialize the command buffer with the given size.
83 virtual bool Initialize() = 0;
85 // Returns the last state without synchronizing with the service.
86 virtual State
GetLastState() = 0;
88 // Returns the last token without synchronizing with the service. Note that
89 // while you could just call GetLastState().token, GetLastState needs to be
90 // fast as it is called for every command where GetLastToken is only called
91 // by code that needs to know the last token so it can be slower but more up
92 // to date than GetLastState.
93 virtual int32
GetLastToken() = 0;
95 // The writer calls this to update its put offset. This ensures the reader
96 // sees the latest added commands, and will eventually process them. On the
97 // service side, commands are processed up to the given put_offset before
98 // subsequent Flushes on the same GpuChannel.
99 virtual void Flush(int32 put_offset
) = 0;
101 // The writer calls this to wait until the current token is within a
102 // specific range, inclusive. Can return early if an error is generated.
103 virtual void WaitForTokenInRange(int32 start
, int32 end
) = 0;
105 // The writer calls this to wait until the current get offset is within a
106 // specific range, inclusive. Can return early if an error is generated.
107 virtual void WaitForGetOffsetInRange(int32 start
, int32 end
) = 0;
109 // Sets the buffer commands are read from.
110 // Also resets the get and put offsets to 0.
111 virtual void SetGetBuffer(int32 transfer_buffer_id
) = 0;
113 // Create a transfer buffer of the given size. Returns its ID or -1 on
115 virtual scoped_refptr
<gpu::Buffer
> CreateTransferBuffer(size_t size
,
118 // Destroy a transfer buffer. The ID must be positive.
119 virtual void DestroyTransferBuffer(int32 id
) = 0;
121 // The NaCl Win64 build only really needs the struct definitions above; having
122 // GetLastError declared would mean we'd have to also define it, and pull more
123 // of gpu in to the NaCl Win64 build.
124 #if !defined(NACL_WIN64)
125 // TODO(apatrick): this is a temporary optimization while skia is calling
126 // RendererGLContext::MakeCurrent prior to every GL call. It saves returning 6
127 // ints redundantly when only the error is needed for the CommandBufferProxy
129 virtual error::Error
GetLastError();
133 DISALLOW_COPY_AND_ASSIGN(CommandBuffer
);
138 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_