Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / gpu / command_buffer / common / gles2_cmd_format.h
blob252aafd06cf800695b969d1518bb344dcdacfe05
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 // This file defines the GLES2 command buffer commands.
7 #ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_
8 #define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_
11 #include <KHR/khrplatform.h>
13 #include <string.h>
15 #include "gpu/command_buffer/common/bitfield_helpers.h"
16 #include "gpu/command_buffer/common/cmd_buffer_common.h"
17 #include "gpu/command_buffer/common/gles2_cmd_ids.h"
18 #include "gpu/command_buffer/common/types.h"
20 // GL types are forward declared to avoid including the GL headers. The problem
21 // is determining which GL headers to include from code that is common to the
22 // client and service sides (GLES2 or one of several GL implementations).
23 typedef unsigned int GLenum;
24 typedef unsigned int GLbitfield;
25 typedef unsigned int GLuint;
26 typedef int GLint;
27 typedef int GLsizei;
28 typedef unsigned char GLboolean;
29 typedef signed char GLbyte;
30 typedef short GLshort;
31 typedef unsigned char GLubyte;
32 typedef unsigned short GLushort;
33 typedef unsigned long GLulong;
34 typedef float GLfloat;
35 typedef float GLclampf;
36 typedef double GLdouble;
37 typedef double GLclampd;
38 typedef void GLvoid;
39 typedef khronos_intptr_t GLintptr;
40 typedef khronos_ssize_t GLsizeiptr;
42 namespace gpu {
43 namespace gles2 {
45 #pragma pack(push, 1)
47 namespace id_namespaces {
49 // These are used when contexts share resources.
50 enum IdNamespaces {
51 kBuffers,
52 kFramebuffers,
53 kProgramsAndShaders,
54 kRenderbuffers,
55 kTextures,
56 kQueries,
57 kVertexArrays,
58 kNumIdNamespaces
61 // These numbers must not change
62 COMPILE_ASSERT(kBuffers == 0, kBuffers_is_not_0);
63 COMPILE_ASSERT(kFramebuffers == 1, kFramebuffers_is_not_1);
64 COMPILE_ASSERT(kProgramsAndShaders == 2, kProgramsAndShaders_is_not_2);
65 COMPILE_ASSERT(kRenderbuffers == 3, kRenderbuffers_is_not_3);
66 COMPILE_ASSERT(kTextures == 4, kTextures_is_not_4);
68 } // namespace id_namespaces
70 // Used for some glGetXXX commands that return a result through a pointer. We
71 // need to know if the command succeeded or not and the size of the result. If
72 // the command failed its result size will 0.
73 template <typename T>
74 struct SizedResult {
75 typedef T Type;
77 T* GetData() {
78 return static_cast<T*>(static_cast<void*>(&data));
81 // Returns the total size in bytes of the SizedResult for a given number of
82 // results including the size field.
83 static size_t ComputeSize(size_t num_results) {
84 return sizeof(T) * num_results + sizeof(uint32); // NOLINT
87 // Returns the total size in bytes of the SizedResult for a given size of
88 // results.
89 static size_t ComputeSizeFromBytes(size_t size_of_result_in_bytes) {
90 return size_of_result_in_bytes + sizeof(uint32); // NOLINT
93 // Returns the maximum number of results for a given buffer size.
94 static uint32 ComputeMaxResults(size_t size_of_buffer) {
95 return (size_of_buffer >= sizeof(uint32)) ?
96 ((size_of_buffer - sizeof(uint32)) / sizeof(T)) : 0; // NOLINT
99 // Set the size for a given number of results.
100 void SetNumResults(size_t num_results) {
101 size = sizeof(T) * num_results; // NOLINT
104 // Get the number of elements in the result
105 int32 GetNumResults() const {
106 return size / sizeof(T); // NOLINT
109 // Copy the result.
110 void CopyResult(void* dst) const {
111 memcpy(dst, &data, size);
114 uint32 size; // in bytes.
115 int32 data; // this is just here to get an offset.
118 COMPILE_ASSERT(sizeof(SizedResult<int8>) == 8, SizedResult_size_not_8);
119 COMPILE_ASSERT(offsetof(SizedResult<int8>, size) == 0,
120 OffsetOf_SizedResult_size_not_0);
121 COMPILE_ASSERT(offsetof(SizedResult<int8>, data) == 4,
122 OffsetOf_SizedResult_data_not_4);
124 // The data for one attrib or uniform from GetProgramInfoCHROMIUM.
125 struct ProgramInput {
126 uint32 type; // The type (GL_VEC3, GL_MAT3, GL_SAMPLER_2D, etc.
127 int32 size; // The size (how big the array is for uniforms)
128 uint32 location_offset; // offset from ProgramInfoHeader to 'size' locations
129 // for uniforms, 1 for attribs.
130 uint32 name_offset; // offset from ProgrmaInfoHeader to start of name.
131 uint32 name_length; // length of the name.
134 // The format of the bucket filled out by GetProgramInfoCHROMIUM
135 struct ProgramInfoHeader {
136 uint32 link_status;
137 uint32 num_attribs;
138 uint32 num_uniforms;
139 // ProgramInput inputs[num_attribs + num_uniforms];
142 // The format of QuerySync used by EXT_occlusion_query_boolean
143 struct QuerySync {
144 void Reset() {
145 process_count = 0;
146 result = 0;
149 uint32 process_count;
150 uint64 result;
153 COMPILE_ASSERT(sizeof(ProgramInput) == 20, ProgramInput_size_not_20);
154 COMPILE_ASSERT(offsetof(ProgramInput, type) == 0,
155 OffsetOf_ProgramInput_type_not_0);
156 COMPILE_ASSERT(offsetof(ProgramInput, size) == 4,
157 OffsetOf_ProgramInput_size_not_4);
158 COMPILE_ASSERT(offsetof(ProgramInput, location_offset) == 8,
159 OffsetOf_ProgramInput_location_offset_not_8);
160 COMPILE_ASSERT(offsetof(ProgramInput, name_offset) == 12,
161 OffsetOf_ProgramInput_name_offset_not_12);
162 COMPILE_ASSERT(offsetof(ProgramInput, name_length) == 16,
163 OffsetOf_ProgramInput_name_length_not_16);
165 COMPILE_ASSERT(sizeof(ProgramInfoHeader) == 12, ProgramInfoHeader_size_not_12);
166 COMPILE_ASSERT(offsetof(ProgramInfoHeader, link_status) == 0,
167 OffsetOf_ProgramInfoHeader_link_status_not_0);
168 COMPILE_ASSERT(offsetof(ProgramInfoHeader, num_attribs) == 4,
169 OffsetOf_ProgramInfoHeader_num_attribs_not_4);
170 COMPILE_ASSERT(offsetof(ProgramInfoHeader, num_uniforms) == 8,
171 OffsetOf_ProgramInfoHeader_num_uniforms_not_8);
173 namespace cmds {
175 #include "../common/gles2_cmd_format_autogen.h"
177 // These are hand written commands.
178 // TODO(gman): Attempt to make these auto-generated.
180 struct GetAttribLocation {
181 typedef GetAttribLocation ValueType;
182 static const CommandId kCmdId = kGetAttribLocation;
183 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
184 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
186 typedef GLint Result;
188 static uint32 ComputeSize() {
189 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
192 void SetHeader() {
193 header.SetCmd<ValueType>();
196 void Init(
197 GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
198 uint32 _location_shm_id, uint32 _location_shm_offset,
199 uint32 _data_size) {
200 SetHeader();
201 program = _program;
202 name_shm_id = _name_shm_id;
203 name_shm_offset = _name_shm_offset;
204 location_shm_id = _location_shm_id;
205 location_shm_offset = _location_shm_offset;
206 data_size = _data_size;
209 void* Set(
210 void* cmd, GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
211 uint32 _location_shm_id, uint32 _location_shm_offset,
212 uint32 _data_size) {
213 static_cast<ValueType*>(
214 cmd)->Init(
215 _program, _name_shm_id, _name_shm_offset, _location_shm_id,
216 _location_shm_offset, _data_size);
217 return NextCmdAddress<ValueType>(cmd);
220 CommandHeader header;
221 uint32 program;
222 uint32 name_shm_id;
223 uint32 name_shm_offset;
224 uint32 location_shm_id;
225 uint32 location_shm_offset;
226 uint32 data_size;
229 COMPILE_ASSERT(sizeof(GetAttribLocation) == 28,
230 Sizeof_GetAttribLocation_is_not_28);
231 COMPILE_ASSERT(offsetof(GetAttribLocation, header) == 0,
232 OffsetOf_GetAttribLocation_header_not_0);
233 COMPILE_ASSERT(offsetof(GetAttribLocation, program) == 4,
234 OffsetOf_GetAttribLocation_program_not_4);
235 COMPILE_ASSERT(offsetof(GetAttribLocation, name_shm_id) == 8,
236 OffsetOf_GetAttribLocation_name_shm_id_not_8);
237 COMPILE_ASSERT(offsetof(GetAttribLocation, name_shm_offset) == 12,
238 OffsetOf_GetAttribLocation_name_shm_offset_not_12);
239 COMPILE_ASSERT(offsetof(GetAttribLocation, location_shm_id) == 16,
240 OffsetOf_GetAttribLocation_location_shm_id_not_16);
241 COMPILE_ASSERT(offsetof(GetAttribLocation, location_shm_offset) == 20,
242 OffsetOf_GetAttribLocation_location_shm_offset_not_20);
243 COMPILE_ASSERT(offsetof(GetAttribLocation, data_size) == 24,
244 OffsetOf_GetAttribLocation_data_size_not_24);
247 struct GetAttribLocationBucket {
248 typedef GetAttribLocationBucket ValueType;
249 static const CommandId kCmdId = kGetAttribLocationBucket;
250 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
251 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
253 typedef GLint Result;
255 static uint32 ComputeSize() {
256 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
259 void SetHeader() {
260 header.SetCmd<ValueType>();
263 void Init(
264 GLuint _program, uint32 _name_bucket_id,
265 uint32 _location_shm_id, uint32 _location_shm_offset) {
266 SetHeader();
267 program = _program;
268 name_bucket_id = _name_bucket_id;
269 location_shm_id = _location_shm_id;
270 location_shm_offset = _location_shm_offset;
273 void* Set(
274 void* cmd, GLuint _program, uint32 _name_bucket_id,
275 uint32 _location_shm_id, uint32 _location_shm_offset) {
276 static_cast<ValueType*>(
277 cmd)->Init(
278 _program, _name_bucket_id, _location_shm_id,
279 _location_shm_offset);
280 return NextCmdAddress<ValueType>(cmd);
283 CommandHeader header;
284 uint32 program;
285 uint32 name_bucket_id;
286 uint32 location_shm_id;
287 uint32 location_shm_offset;
290 COMPILE_ASSERT(sizeof(GetAttribLocationBucket) == 20,
291 Sizeof_GetAttribLocationBucket_is_not_24);
292 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, header) == 0,
293 OffsetOf_GetAttribLocationBucket_header_not_0);
294 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, program) == 4,
295 OffsetOf_GetAttribLocationBucket_program_not_4);
296 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, name_bucket_id) == 8,
297 OffsetOf_GetAttribLocationBucket_name_bucket_id_not_8);
298 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, location_shm_id) == 12,
299 OffsetOf_GetAttribLocationBucket_location_shm_id_not_12);
300 COMPILE_ASSERT(offsetof(GetAttribLocationBucket, location_shm_offset) == 16,
301 OffsetOf_GetAttribLocationBucket_location_shm_offset_not_16);
303 struct GetUniformLocation {
304 typedef GetUniformLocation ValueType;
305 static const CommandId kCmdId = kGetUniformLocation;
306 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
307 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
309 typedef GLint Result;
311 static uint32 ComputeSize() {
312 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
315 void SetHeader() {
316 header.SetCmd<ValueType>();
319 void Init(
320 GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
321 uint32 _location_shm_id, uint32 _location_shm_offset,
322 uint32 _data_size) {
323 SetHeader();
324 program = _program;
325 name_shm_id = _name_shm_id;
326 name_shm_offset = _name_shm_offset;
327 location_shm_id = _location_shm_id;
328 location_shm_offset = _location_shm_offset;
329 data_size = _data_size;
332 void* Set(
333 void* cmd, GLuint _program, uint32 _name_shm_id, uint32 _name_shm_offset,
334 uint32 _location_shm_id, uint32 _location_shm_offset,
335 uint32 _data_size) {
336 static_cast<ValueType*>(
337 cmd)->Init(
338 _program, _name_shm_id, _name_shm_offset, _location_shm_id,
339 _location_shm_offset, _data_size);
340 return NextCmdAddress<ValueType>(cmd);
343 CommandHeader header;
344 uint32 program;
345 uint32 name_shm_id;
346 uint32 name_shm_offset;
347 uint32 location_shm_id;
348 uint32 location_shm_offset;
349 uint32 data_size;
352 COMPILE_ASSERT(sizeof(GetUniformLocation) == 28,
353 Sizeof_GetUniformLocation_is_not_28);
354 COMPILE_ASSERT(offsetof(GetUniformLocation, header) == 0,
355 OffsetOf_GetUniformLocation_header_not_0);
356 COMPILE_ASSERT(offsetof(GetUniformLocation, program) == 4,
357 OffsetOf_GetUniformLocation_program_not_4);
358 COMPILE_ASSERT(offsetof(GetUniformLocation, name_shm_id) == 8,
359 OffsetOf_GetUniformLocation_name_shm_id_not_8);
360 COMPILE_ASSERT(offsetof(GetUniformLocation, name_shm_offset) == 12,
361 OffsetOf_GetUniformLocation_name_shm_offset_not_12);
362 COMPILE_ASSERT(offsetof(GetUniformLocation, location_shm_id) == 16,
363 OffsetOf_GetUniformLocation_location_shm_id_not_16);
364 COMPILE_ASSERT(offsetof(GetUniformLocation, location_shm_offset) == 20,
365 OffsetOf_GetUniformLocation_location_shm_offset_not_20);
366 COMPILE_ASSERT(offsetof(GetUniformLocation, data_size) == 24,
367 OffsetOf_GetUniformLocation_data_size_not_24);
369 struct GetUniformLocationBucket {
370 typedef GetUniformLocationBucket ValueType;
371 static const CommandId kCmdId = kGetUniformLocationBucket;
372 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
373 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
375 typedef GLint Result;
377 static uint32 ComputeSize() {
378 return static_cast<uint32>(sizeof(ValueType)); // NOLINT
381 void SetHeader() {
382 header.SetCmd<ValueType>();
385 void Init(
386 GLuint _program, uint32 _name_bucket_id,
387 uint32 _location_shm_id, uint32 _location_shm_offset) {
388 SetHeader();
389 program = _program;
390 name_bucket_id = _name_bucket_id;
391 location_shm_id = _location_shm_id;
392 location_shm_offset = _location_shm_offset;
395 void* Set(
396 void* cmd, GLuint _program, uint32 _name_bucket_id,
397 uint32 _location_shm_id, uint32 _location_shm_offset) {
398 static_cast<ValueType*>(
399 cmd)->Init(
400 _program, _name_bucket_id, _location_shm_id,
401 _location_shm_offset);
402 return NextCmdAddress<ValueType>(cmd);
405 CommandHeader header;
406 uint32 program;
407 uint32 name_bucket_id;
408 uint32 location_shm_id;
409 uint32 location_shm_offset;
412 COMPILE_ASSERT(sizeof(GetUniformLocationBucket) == 20,
413 Sizeof_GetUniformLocationBucket_is_not_24);
414 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, header) == 0,
415 OffsetOf_GetUniformLocationBucket_header_not_0);
416 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, program) == 4,
417 OffsetOf_GetUniformLocationBucket_program_not_4);
418 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, name_bucket_id) == 8,
419 OffsetOf_GetUniformLocationBucket_name_bucket_id_not_8);
420 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, location_shm_id) == 12,
421 OffsetOf_GetUniformLocationBucket_location_shm_id_not_12);
422 COMPILE_ASSERT(offsetof(GetUniformLocationBucket, location_shm_offset) == 16,
423 OffsetOf_GetUniformLocationBucket_location_shm_offset_not_16);
425 struct GenMailboxCHROMIUM {
426 typedef GenMailboxCHROMIUM ValueType;
427 static const CommandId kCmdId = kGenMailboxCHROMIUM;
428 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
429 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
430 CommandHeader header;
433 struct InsertSyncPointCHROMIUM {
434 typedef InsertSyncPointCHROMIUM ValueType;
435 static const CommandId kCmdId = kInsertSyncPointCHROMIUM;
436 static const cmd::ArgFlags kArgFlags = cmd::kFixed;
437 static const uint8 cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
438 CommandHeader header;
441 #pragma pack(pop)
443 } // namespace cmd
444 } // namespace gles2
445 } // namespace gpu
447 #endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_H_