Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / client / gles2_implementation.h
blobce2591de766aeaded24e07b5ea390cbebda41d4e
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_CLIENT_GLES2_IMPLEMENTATION_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
8 #include <list>
9 #include <map>
10 #include <queue>
11 #include <set>
12 #include <string>
13 #include <utility>
14 #include <vector>
16 #include "base/basictypes.h"
17 #include "base/compiler_specific.h"
18 #include "base/macros.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/weak_ptr.h"
21 #include "gpu/command_buffer/client/buffer_tracker.h"
22 #include "gpu/command_buffer/client/client_context_state.h"
23 #include "gpu/command_buffer/client/context_support.h"
24 #include "gpu/command_buffer/client/gles2_impl_export.h"
25 #include "gpu/command_buffer/client/gles2_interface.h"
26 #include "gpu/command_buffer/client/mapped_memory.h"
27 #include "gpu/command_buffer/client/ref_counted.h"
28 #include "gpu/command_buffer/client/share_group.h"
29 #include "gpu/command_buffer/common/capabilities.h"
30 #include "gpu/command_buffer/common/debug_marker_manager.h"
31 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
33 #if !defined(NDEBUG) && !defined(__native_client__) && !defined(GLES2_CONFORMANCE_TESTS) // NOLINT
34 #if defined(GLES2_INLINE_OPTIMIZATION)
35 // TODO(gman): Replace with macros that work with inline optmization.
36 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
37 #define GPU_CLIENT_LOG(args)
38 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
39 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
40 #else
41 #include "base/logging.h"
42 #define GPU_CLIENT_SINGLE_THREAD_CHECK() SingleThreadChecker checker(this);
43 #define GPU_CLIENT_LOG(args) DLOG_IF(INFO, debug_) << args;
44 #define GPU_CLIENT_LOG_CODE_BLOCK(code) code
45 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code) code
46 #define GPU_CLIENT_DEBUG
47 #endif
48 #else
49 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
50 #define GPU_CLIENT_LOG(args)
51 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
52 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
53 #endif
55 #if defined(GPU_CLIENT_DEBUG)
56 // Set to 1 to have the client fail when a GL error is generated.
57 // This helps find bugs in the renderer since the debugger stops on the error.
58 # if 0
59 # define GL_CLIENT_FAIL_GL_ERRORS
60 # endif
61 #endif
63 // Check that destination pointers point to initialized memory.
64 // When the context is lost, calling GL function has no effect so if destination
65 // pointers point to initialized memory it can often lead to crash bugs. eg.
67 // GLsizei len;
68 // glGetShaderSource(shader, max_size, &len, buffer);
69 // std::string src(buffer, buffer + len); // len can be uninitialized here!!!
71 // Because this check is not official GL this check happens only on Chrome code,
72 // not Pepper.
74 // If it was up to us we'd just always write to the destination but the OpenGL
75 // spec defines the behavior of OpenGL functions, not us. :-(
76 #if defined(__native_client__) || defined(GLES2_CONFORMANCE_TESTS)
77 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v)
78 #define GPU_CLIENT_DCHECK(v)
79 #elif defined(GPU_DCHECK)
80 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v)
81 #define GPU_CLIENT_DCHECK(v) GPU_DCHECK(v)
82 #elif defined(DCHECK)
83 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
84 #define GPU_CLIENT_DCHECK(v) DCHECK(v)
85 #else
86 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
87 #define GPU_CLIENT_DCHECK(v) ASSERT(v)
88 #endif
90 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \
91 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \
92 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
94 #define GPU_CLIENT_VALIDATE_DESTINATION_OPTIONAL_INITALIZATION(type, ptr) \
95 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(!ptr || \
96 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
98 namespace gpu {
100 class GpuControl;
101 class IdAllocator;
102 class ScopedTransferBufferPtr;
103 class TransferBufferInterface;
105 namespace gles2 {
107 class GLES2CmdHelper;
108 class VertexArrayObjectManager;
109 class QueryTracker;
111 class GLES2ImplementationErrorMessageCallback {
112 public:
113 virtual ~GLES2ImplementationErrorMessageCallback() { }
114 virtual void OnErrorMessage(const char* msg, int id) = 0;
117 // This class emulates GLES2 over command buffers. It can be used by a client
118 // program so that the program does not need deal with shared memory and command
119 // buffer management. See gl2_lib.h. Note that there is a performance gain to
120 // be had by changing your code to use command buffers directly by using the
121 // GLES2CmdHelper but that entails changing your code to use and deal with
122 // shared memory and synchronization issues.
123 class GLES2_IMPL_EXPORT GLES2Implementation
124 : NON_EXPORTED_BASE(public GLES2Interface),
125 NON_EXPORTED_BASE(public ContextSupport) {
126 public:
127 enum MappedMemoryLimit {
128 kNoLimit = MappedMemoryManager::kNoLimit,
131 // Stores GL state that never changes.
132 struct GLES2_IMPL_EXPORT GLStaticState {
133 GLStaticState();
134 ~GLStaticState();
136 typedef std::pair<GLenum, GLenum> ShaderPrecisionKey;
137 typedef std::map<ShaderPrecisionKey,
138 cmds::GetShaderPrecisionFormat::Result>
139 ShaderPrecisionMap;
140 ShaderPrecisionMap shader_precisions;
143 // The maxiumum result size from simple GL get commands.
144 static const size_t kMaxSizeOfSimpleResult = 16 * sizeof(uint32); // NOLINT.
146 // used for testing only. If more things are reseved add them here.
147 static const unsigned int kStartingOffset = kMaxSizeOfSimpleResult;
149 // Size in bytes to issue async flush for transfer buffer.
150 static const unsigned int kSizeToFlush = 256 * 1024;
152 // The bucket used for results. Public for testing only.
153 static const uint32 kResultBucketId = 1;
155 // Alignment of allocations.
156 static const unsigned int kAlignment = 4;
158 // GL names for the buffers used to emulate client side buffers.
159 static const GLuint kClientSideArrayId = 0xFEDCBA98u;
160 static const GLuint kClientSideElementArrayId = 0xFEDCBA99u;
162 // Number of swap buffers allowed before waiting.
163 static const size_t kMaxSwapBuffers = 2;
165 GLES2Implementation(GLES2CmdHelper* helper,
166 ShareGroup* share_group,
167 TransferBufferInterface* transfer_buffer,
168 bool bind_generates_resource,
169 bool lose_context_when_out_of_memory,
170 bool support_client_side_arrays,
171 GpuControl* gpu_control);
173 ~GLES2Implementation() override;
175 bool Initialize(
176 unsigned int starting_transfer_buffer_size,
177 unsigned int min_transfer_buffer_size,
178 unsigned int max_transfer_buffer_size,
179 unsigned int mapped_memory_limit);
181 // The GLES2CmdHelper being used by this GLES2Implementation. You can use
182 // this to issue cmds at a lower level for certain kinds of optimization.
183 GLES2CmdHelper* helper() const;
185 // Gets client side generated errors.
186 GLenum GetClientSideGLError();
188 // Include the auto-generated part of this class. We split this because
189 // it means we can easily edit the non-auto generated parts right here in
190 // this file instead of having to edit some template or the code generator.
191 #include "gpu/command_buffer/client/gles2_implementation_autogen.h"
193 void DisableVertexAttribArray(GLuint index) override;
194 void EnableVertexAttribArray(GLuint index) override;
195 void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) override;
196 void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) override;
197 void GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params) override;
198 void GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params) override;
200 // ContextSupport implementation.
201 void Swap() override;
202 void PartialSwapBuffers(const gfx::Rect& sub_buffer) override;
203 void ScheduleOverlayPlane(int plane_z_order,
204 gfx::OverlayTransform plane_transform,
205 unsigned overlay_texture_id,
206 const gfx::Rect& display_bounds,
207 const gfx::RectF& uv_rect) override;
208 GLuint InsertFutureSyncPointCHROMIUM() override;
209 void RetireSyncPointCHROMIUM(GLuint sync_point) override;
211 void GetProgramInfoCHROMIUMHelper(GLuint program, std::vector<int8>* result);
212 GLint GetAttribLocationHelper(GLuint program, const char* name);
213 GLint GetUniformLocationHelper(GLuint program, const char* name);
214 GLint GetFragDataLocationHelper(GLuint program, const char* name);
215 bool GetActiveAttribHelper(
216 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
217 GLint* size, GLenum* type, char* name);
218 bool GetActiveUniformHelper(
219 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
220 GLint* size, GLenum* type, char* name);
221 void GetUniformBlocksCHROMIUMHelper(
222 GLuint program, std::vector<int8>* result);
223 void GetUniformsES3CHROMIUMHelper(
224 GLuint program, std::vector<int8>* result);
225 GLuint GetUniformBlockIndexHelper(GLuint program, const char* name);
226 bool GetActiveUniformBlockNameHelper(
227 GLuint program, GLuint index, GLsizei bufsize,
228 GLsizei* length, char* name);
229 bool GetActiveUniformBlockivHelper(
230 GLuint program, GLuint index, GLenum pname, GLint* params);
231 void GetTransformFeedbackVaryingsCHROMIUMHelper(
232 GLuint program, std::vector<int8>* result);
233 bool GetTransformFeedbackVaryingHelper(
234 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
235 GLint* size, GLenum* type, char* name);
236 bool GetUniformIndicesHelper(
237 GLuint program, GLsizei count, const char* const* names, GLuint* indices);
238 bool GetActiveUniformsivHelper(
239 GLuint program, GLsizei count, const GLuint* indices,
240 GLenum pname, GLint* params);
241 bool GetSyncivHelper(
242 GLsync sync, GLenum pname, GLsizei bufsize, GLsizei* length,
243 GLint* values);
244 bool GetQueryObjectValueHelper(
245 const char* function_name, GLuint id, GLenum pname, GLuint64* params);
247 void FreeUnusedSharedMemory();
248 void FreeEverything();
250 // ContextSupport implementation.
251 void SignalSyncPoint(uint32 sync_point,
252 const base::Closure& callback) override;
253 void SignalQuery(uint32 query, const base::Closure& callback) override;
254 void SetSurfaceVisible(bool visible) override;
255 void SetAggressivelyFreeResources(bool aggressively_free_resources) override;
257 void SetErrorMessageCallback(
258 GLES2ImplementationErrorMessageCallback* callback) {
259 error_message_callback_ = callback;
262 ShareGroup* share_group() const {
263 return share_group_.get();
266 const Capabilities& capabilities() const {
267 return capabilities_;
270 GpuControl* gpu_control() {
271 return gpu_control_;
274 ShareGroupContextData* share_group_context_data() {
275 return &share_group_context_data_;
278 private:
279 friend class GLES2ImplementationTest;
280 friend class VertexArrayObjectManager;
281 friend class QueryTracker;
283 // Used to track whether an extension is available
284 enum ExtensionStatus {
285 kAvailableExtensionStatus,
286 kUnavailableExtensionStatus,
287 kUnknownExtensionStatus
290 // Base class for mapped resources.
291 struct MappedResource {
292 MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset)
293 : access(_access),
294 shm_id(_shm_id),
295 shm_memory(mem),
296 shm_offset(offset) {
299 // access mode. Currently only GL_WRITE_ONLY is valid
300 GLenum access;
302 // Shared memory ID for buffer.
303 int shm_id;
305 // Address of shared memory
306 void* shm_memory;
308 // Offset of shared memory
309 unsigned int shm_offset;
312 // Used to track mapped textures.
313 struct MappedTexture : public MappedResource {
314 MappedTexture(
315 GLenum access,
316 int shm_id,
317 void* shm_mem,
318 unsigned int shm_offset,
319 GLenum _target,
320 GLint _level,
321 GLint _xoffset,
322 GLint _yoffset,
323 GLsizei _width,
324 GLsizei _height,
325 GLenum _format,
326 GLenum _type)
327 : MappedResource(access, shm_id, shm_mem, shm_offset),
328 target(_target),
329 level(_level),
330 xoffset(_xoffset),
331 yoffset(_yoffset),
332 width(_width),
333 height(_height),
334 format(_format),
335 type(_type) {
338 // These match the arguments to TexSubImage2D.
339 GLenum target;
340 GLint level;
341 GLint xoffset;
342 GLint yoffset;
343 GLsizei width;
344 GLsizei height;
345 GLenum format;
346 GLenum type;
349 // Used to track mapped buffers.
350 struct MappedBuffer : public MappedResource {
351 MappedBuffer(
352 GLenum access,
353 int shm_id,
354 void* shm_mem,
355 unsigned int shm_offset,
356 GLenum _target,
357 GLintptr _offset,
358 GLsizeiptr _size)
359 : MappedResource(access, shm_id, shm_mem, shm_offset),
360 target(_target),
361 offset(_offset),
362 size(_size) {
365 // These match the arguments to BufferSubData.
366 GLenum target;
367 GLintptr offset;
368 GLsizeiptr size;
371 struct TextureUnit {
372 TextureUnit()
373 : bound_texture_2d(0),
374 bound_texture_cube_map(0),
375 bound_texture_external_oes(0) {}
377 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
378 GLuint bound_texture_2d;
380 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
381 // glBindTexture
382 GLuint bound_texture_cube_map;
384 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
385 // glBindTexture
386 GLuint bound_texture_external_oes;
389 // Checks for single threaded access.
390 class SingleThreadChecker {
391 public:
392 explicit SingleThreadChecker(GLES2Implementation* gles2_implementation);
393 ~SingleThreadChecker();
395 private:
396 GLES2Implementation* gles2_implementation_;
399 // Gets the value of the result.
400 template <typename T>
401 T GetResultAs() {
402 return static_cast<T>(GetResultBuffer());
405 void* GetResultBuffer();
406 int32 GetResultShmId();
407 uint32 GetResultShmOffset();
409 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
410 bool IsAnglePackReverseRowOrderAvailable();
411 bool IsChromiumFramebufferMultisampleAvailable();
413 bool IsExtensionAvailableHelper(
414 const char* extension, ExtensionStatus* status);
416 // Gets the GLError through our wrapper.
417 GLenum GetGLError();
419 // Sets our wrapper for the GLError.
420 void SetGLError(GLenum error, const char* function_name, const char* msg);
421 void SetGLErrorInvalidEnum(
422 const char* function_name, GLenum value, const char* label);
424 // Returns the last error and clears it. Useful for debugging.
425 const std::string& GetLastError() {
426 return last_error_;
429 // Waits for all commands to execute.
430 void WaitForCmd();
432 // TODO(gman): These bucket functions really seem like they belong in
433 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
434 // a transfer buffer to function which is currently managed by this class.
436 // Gets the contents of a bucket.
437 bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data);
439 // Sets the contents of a bucket.
440 void SetBucketContents(uint32 bucket_id, const void* data, size_t size);
442 // Sets the contents of a bucket as a string.
443 void SetBucketAsCString(uint32 bucket_id, const char* str);
445 // Gets the contents of a bucket as a string. Returns false if there is no
446 // string available which is a separate case from the empty string.
447 bool GetBucketAsString(uint32 bucket_id, std::string* str);
449 // Sets the contents of a bucket as a string.
450 void SetBucketAsString(uint32 bucket_id, const std::string& str);
452 // Returns true if id is reserved.
453 bool IsBufferReservedId(GLuint id);
454 bool IsFramebufferReservedId(GLuint id) { return false; }
455 bool IsRenderbufferReservedId(GLuint id) { return false; }
456 bool IsTextureReservedId(GLuint id) { return false; }
457 bool IsVertexArrayReservedId(GLuint id) { return false; }
458 bool IsProgramReservedId(GLuint id) { return false; }
459 bool IsValuebufferReservedId(GLuint id) { return false; }
460 bool IsSamplerReservedId(GLuint id) { return false; }
461 bool IsTransformFeedbackReservedId(GLuint id) { return false; }
463 void BindBufferHelper(GLenum target, GLuint buffer);
464 void BindBufferBaseHelper(GLenum target, GLuint index, GLuint buffer);
465 void BindBufferRangeHelper(GLenum target, GLuint index, GLuint buffer,
466 GLintptr offset, GLsizeiptr size);
467 void BindFramebufferHelper(GLenum target, GLuint framebuffer);
468 void BindRenderbufferHelper(GLenum target, GLuint renderbuffer);
469 void BindSamplerHelper(GLuint unit, GLuint sampler);
470 void BindTextureHelper(GLenum target, GLuint texture);
471 void BindTransformFeedbackHelper(GLenum target, GLuint transformfeedback);
472 void BindVertexArrayOESHelper(GLuint array);
473 void BindValuebufferCHROMIUMHelper(GLenum target, GLuint valuebuffer);
474 void UseProgramHelper(GLuint program);
476 void BindBufferStub(GLenum target, GLuint buffer);
477 void BindBufferBaseStub(GLenum target, GLuint index, GLuint buffer);
478 void BindBufferRangeStub(GLenum target, GLuint index, GLuint buffer,
479 GLintptr offset, GLsizeiptr size);
480 void BindFramebufferStub(GLenum target, GLuint framebuffer);
481 void BindRenderbufferStub(GLenum target, GLuint renderbuffer);
482 void BindTextureStub(GLenum target, GLuint texture);
483 void BindValuebufferCHROMIUMStub(GLenum target, GLuint valuebuffer);
485 void GenBuffersHelper(GLsizei n, const GLuint* buffers);
486 void GenFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
487 void GenRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
488 void GenTexturesHelper(GLsizei n, const GLuint* textures);
489 void GenVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
490 void GenQueriesEXTHelper(GLsizei n, const GLuint* queries);
491 void GenValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
492 void GenSamplersHelper(GLsizei n, const GLuint* samplers);
493 void GenTransformFeedbacksHelper(GLsizei n, const GLuint* transformfeedbacks);
495 void DeleteBuffersHelper(GLsizei n, const GLuint* buffers);
496 void DeleteFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
497 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
498 void DeleteTexturesHelper(GLsizei n, const GLuint* textures);
499 bool DeleteProgramHelper(GLuint program);
500 bool DeleteShaderHelper(GLuint shader);
501 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* queries);
502 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
503 void DeleteValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
504 void DeleteSamplersHelper(GLsizei n, const GLuint* samplers);
505 void DeleteTransformFeedbacksHelper(
506 GLsizei n, const GLuint* transformfeedbacks);
507 void DeleteSyncHelper(GLsync sync);
509 void DeleteBuffersStub(GLsizei n, const GLuint* buffers);
510 void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers);
511 void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers);
512 void DeleteTexturesStub(GLsizei n, const GLuint* textures);
513 void DeletePathsCHROMIUMStub(GLuint first_client_id, GLsizei range);
514 void DeleteProgramStub(GLsizei n, const GLuint* programs);
515 void DeleteShaderStub(GLsizei n, const GLuint* shaders);
516 void DeleteVertexArraysOESStub(GLsizei n, const GLuint* arrays);
517 void DeleteValuebuffersCHROMIUMStub(GLsizei n, const GLuint* valuebuffers);
518 void DeleteSamplersStub(GLsizei n, const GLuint* samplers);
519 void DeleteTransformFeedbacksStub(
520 GLsizei n, const GLuint* transformfeedbacks);
521 void DeleteSyncStub(GLsizei n, const GLuint* syncs);
523 void BufferDataHelper(
524 GLenum target, GLsizeiptr size, const void* data, GLenum usage);
525 void BufferSubDataHelper(
526 GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
527 void BufferSubDataHelperImpl(
528 GLenum target, GLintptr offset, GLsizeiptr size, const void* data,
529 ScopedTransferBufferPtr* buffer);
531 GLuint CreateImageCHROMIUMHelper(ClientBuffer buffer,
532 GLsizei width,
533 GLsizei height,
534 GLenum internalformat);
535 void DestroyImageCHROMIUMHelper(GLuint image_id);
536 GLuint CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width,
537 GLsizei height,
538 GLenum internalformat,
539 GLenum usage);
541 // Helper for GetVertexAttrib
542 bool GetVertexAttribHelper(GLuint index, GLenum pname, uint32* param);
544 GLuint GetMaxValueInBufferCHROMIUMHelper(
545 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset);
547 void WaitAllAsyncTexImage2DCHROMIUMHelper();
549 void RestoreElementAndArrayBuffers(bool restore);
550 void RestoreArrayBuffer(bool restrore);
552 // The pixels pointer should already account for unpack skip
553 // images/rows/pixels.
554 void TexSubImage2DImpl(
555 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
556 GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size,
557 const void* pixels, uint32 pixels_padded_row_size, GLboolean internal,
558 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
559 void TexSubImage3DImpl(
560 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
561 GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
562 uint32 unpadded_row_size, const void* pixels,
563 uint32 pixels_padded_row_size, GLboolean internal,
564 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
566 // Helpers for query functions.
567 bool GetHelper(GLenum pname, GLint* params);
568 GLuint GetBoundBufferHelper(GLenum target);
569 bool GetBooleanvHelper(GLenum pname, GLboolean* params);
570 bool GetBufferParameteri64vHelper(
571 GLenum target, GLenum pname, GLint64* params);
572 bool GetBufferParameterivHelper(GLenum target, GLenum pname, GLint* params);
573 bool GetFloatvHelper(GLenum pname, GLfloat* params);
574 bool GetFramebufferAttachmentParameterivHelper(
575 GLenum target, GLenum attachment, GLenum pname, GLint* params);
576 bool GetInteger64vHelper(GLenum pname, GLint64* params);
577 bool GetIntegervHelper(GLenum pname, GLint* params);
578 bool GetIntegeri_vHelper(GLenum pname, GLuint index, GLint* data);
579 bool GetInteger64i_vHelper(GLenum pname, GLuint index, GLint64* data);
580 bool GetInternalformativHelper(
581 GLenum target, GLenum format, GLenum pname, GLsizei bufSize,
582 GLint* params);
583 bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params);
584 bool GetSamplerParameterfvHelper(
585 GLuint sampler, GLenum pname, GLfloat* params);
586 bool GetSamplerParameterivHelper(
587 GLuint sampler, GLenum pname, GLint* params);
588 bool GetRenderbufferParameterivHelper(
589 GLenum target, GLenum pname, GLint* params);
590 bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params);
591 bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params);
592 bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params);
593 const GLubyte* GetStringHelper(GLenum name);
595 bool IsExtensionAvailable(const char* ext);
597 // Caches certain capabilties state. Return true if cached.
598 bool SetCapabilityState(GLenum cap, bool enabled);
600 IdHandlerInterface* GetIdHandler(int id_namespace) const;
601 RangeIdHandlerInterface* GetRangeIdHandler(int id_namespace) const;
602 // IdAllocators for objects that can't be shared among contexts.
603 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
604 // Framebuffer and Vertex array objects.
605 IdAllocator* GetIdAllocator(int id_namespace) const;
607 void FinishHelper();
608 void FlushHelper();
610 void RunIfContextNotLost(const base::Closure& callback);
612 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
613 // If not, generate an approriate error, and return false.
614 bool ValidateOffset(const char* func, GLintptr offset);
616 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
617 // If not, generate an approriate error, and return false.
618 bool ValidateSize(const char* func, GLsizeiptr offset);
620 // Remove the transfer buffer from the buffer tracker. For buffers used
621 // asynchronously the memory is free:ed if the upload has completed. For
622 // other buffers, the memory is either free:ed immediately or free:ed pending
623 // a token.
624 void RemoveTransferBuffer(BufferTracker::Buffer* buffer);
626 // Returns true if the async upload token has passed.
628 // NOTE: This will detect wrapped async tokens by checking if the most
629 // significant bit of async token to check is 1 but the last read is 0, i.e.
630 // the uint32 wrapped.
631 bool HasAsyncUploadTokenPassed(uint32 token) const {
632 return async_upload_sync_->HasAsyncUploadTokenPassed(token);
635 // Get the next async upload token.
636 uint32 NextAsyncUploadToken();
638 // Ensure that the shared memory used for synchronizing async upload tokens
639 // has been mapped.
641 // Returns false on error, true on success.
642 bool EnsureAsyncUploadSync();
644 // Checks the last read asynchronously upload token and frees any unmanaged
645 // transfer buffer that has its async token passed.
646 void PollAsyncUploads();
648 // Free every async upload buffer. If some async upload buffer is still in use
649 // wait for them to finish before freeing.
650 void FreeAllAsyncUploadBuffers();
652 bool GetBoundPixelTransferBuffer(
653 GLenum target, const char* function_name, GLuint* buffer_id);
654 BufferTracker::Buffer* GetBoundPixelUnpackTransferBufferIfValid(
655 GLuint buffer_id,
656 const char* function_name, GLuint offset, GLsizei size);
658 // Pack 2D arrays of char into a bucket.
659 // Helper function for ShaderSource(), TransformFeedbackVaryings(), etc.
660 bool PackStringsToBucket(GLsizei count,
661 const char* const* str,
662 const GLint* length,
663 const char* func_name);
665 const std::string& GetLogPrefix() const;
667 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
668 void CheckGLError();
669 void FailGLError(GLenum error);
670 #else
671 void CheckGLError() { }
672 void FailGLError(GLenum /* error */) { }
673 #endif
675 void RemoveMappedBufferRangeByTarget(GLenum target);
676 void RemoveMappedBufferRangeById(GLuint buffer);
677 void ClearMappedBufferRangeMap();
679 void DrawElementsImpl(GLenum mode, GLsizei count, GLenum type,
680 const void* indices, const char* func_name);
682 GLES2Util util_;
683 GLES2CmdHelper* helper_;
684 TransferBufferInterface* transfer_buffer_;
685 std::string last_error_;
686 DebugMarkerManager debug_marker_manager_;
687 std::string this_in_hex_;
689 std::queue<int32> swap_buffers_tokens_;
690 std::queue<int32> rate_limit_tokens_;
692 ExtensionStatus angle_pack_reverse_row_order_status_;
693 ExtensionStatus chromium_framebuffer_multisample_;
695 GLStaticState static_state_;
696 ClientContextState state_;
698 // pack alignment as last set by glPixelStorei
699 GLint pack_alignment_;
701 // unpack alignment as last set by glPixelStorei
702 GLint unpack_alignment_;
704 // unpack row length as last set by glPixelStorei
705 GLint unpack_row_length_;
707 // unpack image height as last set by glPixelStorei
708 GLint unpack_image_height_;
710 // unpack skip rows as last set by glPixelStorei
711 GLint unpack_skip_rows_;
713 // unpack skip pixels as last set by glPixelStorei
714 GLint unpack_skip_pixels_;
716 // unpack skip images as last set by glPixelStorei
717 GLint unpack_skip_images_;
719 // pack reverse row order as last set by glPixelstorei
720 bool pack_reverse_row_order_;
722 scoped_ptr<TextureUnit[]> texture_units_;
724 // 0 to gl_state_.max_combined_texture_image_units.
725 GLuint active_texture_unit_;
727 GLuint bound_framebuffer_;
728 GLuint bound_read_framebuffer_;
729 GLuint bound_renderbuffer_;
730 GLuint bound_valuebuffer_;
732 // The program in use by glUseProgram
733 GLuint current_program_;
735 GLuint bound_array_buffer_;
736 GLuint bound_copy_read_buffer_;
737 GLuint bound_copy_write_buffer_;
738 GLuint bound_pixel_pack_buffer_;
739 GLuint bound_pixel_unpack_buffer_;
740 GLuint bound_transform_feedback_buffer_;
741 GLuint bound_uniform_buffer_;
743 // The currently bound pixel transfer buffers.
744 GLuint bound_pixel_pack_transfer_buffer_id_;
745 GLuint bound_pixel_unpack_transfer_buffer_id_;
747 // The current asynchronous pixel buffer upload token.
748 uint32 async_upload_token_;
750 // The shared memory used for synchronizing asynchronous upload tokens.
751 AsyncUploadSync* async_upload_sync_;
752 int32 async_upload_sync_shm_id_;
753 unsigned int async_upload_sync_shm_offset_;
755 // Unmanaged pixel transfer buffer memory pending asynchronous upload token.
756 typedef std::list<std::pair<void*, uint32> > DetachedAsyncUploadMemoryList;
757 DetachedAsyncUploadMemoryList detached_async_upload_memory_;
759 // Client side management for vertex array objects. Needed to correctly
760 // track client side arrays.
761 scoped_ptr<VertexArrayObjectManager> vertex_array_object_manager_;
763 GLuint reserved_ids_[2];
765 // Current GL error bits.
766 uint32 error_bits_;
768 // Whether or not to print debugging info.
769 bool debug_;
771 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
772 const bool lose_context_when_out_of_memory_;
774 // Whether or not to support client side arrays.
775 const bool support_client_side_arrays_;
777 // Used to check for single threaded access.
778 int use_count_;
780 // Map of GLenum to Strings for glGetString. We need to cache these because
781 // the pointer passed back to the client has to remain valid for eternity.
782 typedef std::map<uint32, std::set<std::string> > GLStringMap;
783 GLStringMap gl_strings_;
785 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
786 // have an enum for this so handle it separately.
787 std::set<std::string> requestable_extensions_set_;
789 typedef std::map<const void*, MappedBuffer> MappedBufferMap;
790 MappedBufferMap mapped_buffers_;
792 // TODO(zmo): Consolidate |mapped_buffers_| and |mapped_buffer_range_map_|.
793 typedef base::hash_map<GLuint, MappedBuffer> MappedBufferRangeMap;
794 MappedBufferRangeMap mapped_buffer_range_map_;
796 typedef std::map<const void*, MappedTexture> MappedTextureMap;
797 MappedTextureMap mapped_textures_;
799 scoped_ptr<MappedMemoryManager> mapped_memory_;
801 scoped_refptr<ShareGroup> share_group_;
802 ShareGroupContextData share_group_context_data_;
804 scoped_ptr<QueryTracker> query_tracker_;
805 scoped_ptr<IdAllocator> query_id_allocator_;
807 scoped_ptr<BufferTracker> buffer_tracker_;
809 GLES2ImplementationErrorMessageCallback* error_message_callback_;
811 int current_trace_stack_;
813 GpuControl* gpu_control_;
815 Capabilities capabilities_;
817 // Flag to indicate whether the implementation can retain resources, or
818 // whether it should aggressively free them.
819 bool aggressively_free_resources_;
821 base::WeakPtrFactory<GLES2Implementation> weak_ptr_factory_;
823 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation);
826 inline bool GLES2Implementation::GetBufferParameteri64vHelper(
827 GLenum /* target */, GLenum /* pname */, GLint64* /* params */) {
828 return false;
831 inline bool GLES2Implementation::GetBufferParameterivHelper(
832 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
833 return false;
836 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
837 GLenum /* target */,
838 GLenum /* attachment */,
839 GLenum /* pname */,
840 GLint* /* params */) {
841 return false;
844 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
845 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
846 return false;
849 inline bool GLES2Implementation::GetShaderivHelper(
850 GLuint /* shader */, GLenum /* pname */, GLint* /* params */) {
851 return false;
854 inline bool GLES2Implementation::GetTexParameterfvHelper(
855 GLenum /* target */, GLenum /* pname */, GLfloat* /* params */) {
856 return false;
859 inline bool GLES2Implementation::GetTexParameterivHelper(
860 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
861 return false;
864 } // namespace gles2
865 } // namespace gpu
867 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_