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_
18 #include "base/compiler_specific.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_cmd_helper.h"
25 #include "gpu/command_buffer/client/gles2_impl_export.h"
26 #include "gpu/command_buffer/client/gles2_interface.h"
27 #include "gpu/command_buffer/client/mapped_memory.h"
28 #include "gpu/command_buffer/client/query_tracker.h"
29 #include "gpu/command_buffer/client/ref_counted.h"
30 #include "gpu/command_buffer/client/ring_buffer.h"
31 #include "gpu/command_buffer/client/share_group.h"
32 #include "gpu/command_buffer/common/capabilities.h"
33 #include "gpu/command_buffer/common/debug_marker_manager.h"
34 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
35 #include "gpu/command_buffer/common/id_allocator.h"
37 #if !defined(NDEBUG) && !defined(__native_client__) && !defined(GLES2_CONFORMANCE_TESTS) // NOLINT
38 #if defined(GLES2_INLINE_OPTIMIZATION)
39 // TODO(gman): Replace with macros that work with inline optmization.
40 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
41 #define GPU_CLIENT_LOG(args)
42 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
43 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
45 #include "base/logging.h"
46 #define GPU_CLIENT_SINGLE_THREAD_CHECK() SingleThreadChecker checker(this);
47 #define GPU_CLIENT_LOG(args) DLOG_IF(INFO, debug_) << args;
48 #define GPU_CLIENT_LOG_CODE_BLOCK(code) code
49 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code) code
50 #define GPU_CLIENT_DEBUG
53 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
54 #define GPU_CLIENT_LOG(args)
55 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
56 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
59 #if defined(GPU_CLIENT_DEBUG)
60 // Set to 1 to have the client fail when a GL error is generated.
61 // This helps find bugs in the renderer since the debugger stops on the error.
63 # define GL_CLIENT_FAIL_GL_ERRORS
67 // Check that destination pointers point to initialized memory.
68 // When the context is lost, calling GL function has no effect so if destination
69 // pointers point to initialized memory it can often lead to crash bugs. eg.
72 // glGetShaderSource(shader, max_size, &len, buffer);
73 // std::string src(buffer, buffer + len); // len can be uninitialized here!!!
75 // Because this check is not official GL this check happens only on Chrome code,
78 // If it was up to us we'd just always write to the destination but the OpenGL
79 // spec defines the behavior of OpenGL functions, not us. :-(
80 #if defined(__native_client__) || defined(GLES2_CONFORMANCE_TESTS)
81 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v)
82 #define GPU_CLIENT_DCHECK(v)
83 #elif defined(GPU_DCHECK)
84 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v)
85 #define GPU_CLIENT_DCHECK(v) GPU_DCHECK(v)
87 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
88 #define GPU_CLIENT_DCHECK(v) DCHECK(v)
90 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
91 #define GPU_CLIENT_DCHECK(v) ASSERT(v)
94 #define GPU_CLIENT_VALIDATE_DESTINATION_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 #define GPU_CLIENT_VALIDATE_DESTINATION_OPTIONAL_INITALIZATION(type, ptr) \
99 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(!ptr || \
100 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
102 struct GLUniformDefinitionCHROMIUM;
107 class ScopedTransferBufferPtr;
108 class TransferBufferInterface;
113 class VertexArrayObjectManager;
115 class GLES2ImplementationErrorMessageCallback {
117 virtual ~GLES2ImplementationErrorMessageCallback() { }
118 virtual void OnErrorMessage(const char* msg, int id) = 0;
121 // This class emulates GLES2 over command buffers. It can be used by a client
122 // program so that the program does not need deal with shared memory and command
123 // buffer management. See gl2_lib.h. Note that there is a performance gain to
124 // be had by changing your code to use command buffers directly by using the
125 // GLES2CmdHelper but that entails changing your code to use and deal with
126 // shared memory and synchronization issues.
127 class GLES2_IMPL_EXPORT GLES2Implementation
128 : NON_EXPORTED_BASE(public GLES2Interface),
129 NON_EXPORTED_BASE(public ContextSupport) {
131 enum MappedMemoryLimit {
132 kNoLimit = MappedMemoryManager::kNoLimit,
135 // Stores GL state that never changes.
136 struct GLES2_IMPL_EXPORT GLStaticState {
140 struct GLES2_IMPL_EXPORT IntState {
142 GLint max_combined_texture_image_units;
143 GLint max_cube_map_texture_size;
144 GLint max_fragment_uniform_vectors;
145 GLint max_renderbuffer_size;
146 GLint max_texture_image_units;
147 GLint max_texture_size;
148 GLint max_varying_vectors;
149 GLint max_vertex_attribs;
150 GLint max_vertex_texture_image_units;
151 GLint max_vertex_uniform_vectors;
152 GLint num_compressed_texture_formats;
153 GLint num_shader_binary_formats;
154 GLint bind_generates_resource_chromium;
158 typedef std::pair<GLenum, GLenum> ShaderPrecisionKey;
159 typedef std::map<ShaderPrecisionKey,
160 cmds::GetShaderPrecisionFormat::Result>
162 ShaderPrecisionMap shader_precisions;
165 // The maxiumum result size from simple GL get commands.
166 static const size_t kMaxSizeOfSimpleResult = 16 * sizeof(uint32); // NOLINT.
168 // used for testing only. If more things are reseved add them here.
169 static const unsigned int kStartingOffset = kMaxSizeOfSimpleResult;
171 // Size in bytes to issue async flush for transfer buffer.
172 static const unsigned int kSizeToFlush = 256 * 1024;
174 // The bucket used for results. Public for testing only.
175 static const uint32 kResultBucketId = 1;
177 // Alignment of allocations.
178 static const unsigned int kAlignment = 4;
180 // GL names for the buffers used to emulate client side buffers.
181 static const GLuint kClientSideArrayId = 0xFEDCBA98u;
182 static const GLuint kClientSideElementArrayId = 0xFEDCBA99u;
184 // Number of swap buffers allowed before waiting.
185 static const size_t kMaxSwapBuffers = 2;
187 GLES2Implementation(GLES2CmdHelper* helper,
188 ShareGroup* share_group,
189 TransferBufferInterface* transfer_buffer,
190 bool bind_generates_resource,
191 bool lose_context_when_out_of_memory,
192 bool support_client_side_arrays,
193 GpuControl* gpu_control);
195 ~GLES2Implementation() override;
198 unsigned int starting_transfer_buffer_size,
199 unsigned int min_transfer_buffer_size,
200 unsigned int max_transfer_buffer_size,
201 unsigned int mapped_memory_limit);
203 // The GLES2CmdHelper being used by this GLES2Implementation. You can use
204 // this to issue cmds at a lower level for certain kinds of optimization.
205 GLES2CmdHelper* helper() const;
207 // Gets client side generated errors.
208 GLenum GetClientSideGLError();
210 // Include the auto-generated part of this class. We split this because
211 // it means we can easily edit the non-auto generated parts right here in
212 // this file instead of having to edit some template or the code generator.
213 #include "gpu/command_buffer/client/gles2_implementation_autogen.h"
215 void DisableVertexAttribArray(GLuint index) override;
216 void EnableVertexAttribArray(GLuint index) override;
217 void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) override;
218 void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) override;
220 // ContextSupport implementation.
221 void Swap() override;
222 void PartialSwapBuffers(const gfx::Rect& sub_buffer) override;
223 void ScheduleOverlayPlane(int plane_z_order,
224 gfx::OverlayTransform plane_transform,
225 unsigned overlay_texture_id,
226 const gfx::Rect& display_bounds,
227 const gfx::RectF& uv_rect) override;
228 GLuint InsertFutureSyncPointCHROMIUM() override;
229 void RetireSyncPointCHROMIUM(GLuint sync_point) override;
231 void GetProgramInfoCHROMIUMHelper(GLuint program, std::vector<int8>* result);
232 GLint GetAttribLocationHelper(GLuint program, const char* name);
233 GLint GetUniformLocationHelper(GLuint program, const char* name);
234 bool GetActiveAttribHelper(
235 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
236 GLint* size, GLenum* type, char* name);
237 bool GetActiveUniformHelper(
238 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
239 GLint* size, GLenum* type, char* name);
241 void FreeUnusedSharedMemory();
242 void FreeEverything();
244 // ContextSupport implementation.
245 void SignalSyncPoint(uint32 sync_point,
246 const base::Closure& callback) override;
247 void SignalQuery(uint32 query, const base::Closure& callback) override;
248 void SetSurfaceVisible(bool visible) override;
250 void SetErrorMessageCallback(
251 GLES2ImplementationErrorMessageCallback* callback) {
252 error_message_callback_ = callback;
255 ShareGroup* share_group() const {
256 return share_group_.get();
259 const Capabilities& capabilities() const {
260 return capabilities_;
263 GpuControl* gpu_control() {
267 ShareGroupContextData* share_group_context_data() {
268 return &share_group_context_data_;
272 friend class GLES2ImplementationTest;
273 friend class VertexArrayObjectManager;
275 // Used to track whether an extension is available
276 enum ExtensionStatus {
277 kAvailableExtensionStatus,
278 kUnavailableExtensionStatus,
279 kUnknownExtensionStatus
282 // Base class for mapped resources.
283 struct MappedResource {
284 MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset)
291 // access mode. Currently only GL_WRITE_ONLY is valid
294 // Shared memory ID for buffer.
297 // Address of shared memory
300 // Offset of shared memory
301 unsigned int shm_offset;
304 // Used to track mapped textures.
305 struct MappedTexture : public MappedResource {
310 unsigned int shm_offset,
319 : MappedResource(access, shm_id, shm_mem, shm_offset),
330 // These match the arguments to TexSubImage2D.
341 // Used to track mapped buffers.
342 struct MappedBuffer : public MappedResource {
347 unsigned int shm_offset,
351 : MappedResource(access, shm_id, shm_mem, shm_offset),
357 // These match the arguments to BufferSubData.
365 : bound_texture_2d(0),
366 bound_texture_cube_map(0),
367 bound_texture_external_oes(0) {}
369 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
370 GLuint bound_texture_2d;
372 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
374 GLuint bound_texture_cube_map;
376 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
378 GLuint bound_texture_external_oes;
381 // Checks for single threaded access.
382 class SingleThreadChecker {
384 explicit SingleThreadChecker(GLES2Implementation* gles2_implementation);
385 ~SingleThreadChecker();
388 GLES2Implementation* gles2_implementation_;
391 // Gets the value of the result.
392 template <typename T>
394 return static_cast<T>(GetResultBuffer());
397 void* GetResultBuffer();
398 int32 GetResultShmId();
399 uint32 GetResultShmOffset();
401 bool QueryAndCacheStaticState();
403 // Helpers used to batch synchronous GetIntergerv calls with other
404 // synchronous calls.
405 struct GetMultipleIntegervState {
406 GetMultipleIntegervState(const GLenum* pnames, GLuint pnames_count,
407 GLint* results, GLsizeiptr results_size)
409 pnames_count(pnames_count),
411 results_size(results_size)
414 const GLenum* pnames;
418 GLsizeiptr results_size;
421 int transfer_buffer_size_needed;
423 void* results_buffer;
425 bool GetMultipleIntegervSetup(
426 GetMultipleIntegervState* state);
427 void GetMultipleIntegervRequest(
428 GetMultipleIntegervState* state);
429 void GetMultipleIntegervOnCompleted(
430 GetMultipleIntegervState* state);
432 // Helpers used to batch synchronous GetShaderPrecision calls with other
433 // synchronous calls.
434 struct GetAllShaderPrecisionFormatsState {
435 GetAllShaderPrecisionFormatsState(
436 const GLenum (*precision_params)[2],
437 int precision_params_count)
438 : precision_params(precision_params),
439 precision_params_count(precision_params_count)
441 const GLenum (*precision_params)[2];
442 int precision_params_count;
443 int transfer_buffer_size_needed;
444 void* results_buffer;
446 void GetAllShaderPrecisionFormatsSetup(
447 GetAllShaderPrecisionFormatsState* state);
448 void GetAllShaderPrecisionFormatsRequest(
449 GetAllShaderPrecisionFormatsState* state);
450 void GetAllShaderPrecisionFormatsOnCompleted(
451 GetAllShaderPrecisionFormatsState* state);
453 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
454 bool IsAnglePackReverseRowOrderAvailable();
455 bool IsChromiumFramebufferMultisampleAvailable();
457 bool IsExtensionAvailableHelper(
458 const char* extension, ExtensionStatus* status);
460 // Gets the GLError through our wrapper.
463 // Sets our wrapper for the GLError.
464 void SetGLError(GLenum error, const char* function_name, const char* msg);
465 void SetGLErrorInvalidEnum(
466 const char* function_name, GLenum value, const char* label);
468 // Returns the last error and clears it. Useful for debugging.
469 const std::string& GetLastError() {
473 // Waits for all commands to execute.
476 // TODO(gman): These bucket functions really seem like they belong in
477 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
478 // a transfer buffer to function which is currently managed by this class.
480 // Gets the contents of a bucket.
481 bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data);
483 // Sets the contents of a bucket.
484 void SetBucketContents(uint32 bucket_id, const void* data, size_t size);
486 // Sets the contents of a bucket as a string.
487 void SetBucketAsCString(uint32 bucket_id, const char* str);
489 // Gets the contents of a bucket as a string. Returns false if there is no
490 // string available which is a separate case from the empty string.
491 bool GetBucketAsString(uint32 bucket_id, std::string* str);
493 // Sets the contents of a bucket as a string.
494 void SetBucketAsString(uint32 bucket_id, const std::string& str);
496 // Returns true if id is reserved.
497 bool IsBufferReservedId(GLuint id);
498 bool IsFramebufferReservedId(GLuint id) { return false; }
499 bool IsRenderbufferReservedId(GLuint id) { return false; }
500 bool IsTextureReservedId(GLuint id) { return false; }
501 bool IsVertexArrayReservedId(GLuint id) { return false; }
502 bool IsProgramReservedId(GLuint id) { return false; }
503 bool IsValuebufferReservedId(GLuint id) { return false; }
505 bool BindBufferHelper(GLenum target, GLuint texture);
506 bool BindFramebufferHelper(GLenum target, GLuint texture);
507 bool BindRenderbufferHelper(GLenum target, GLuint texture);
508 bool BindTextureHelper(GLenum target, GLuint texture);
509 bool BindVertexArrayOESHelper(GLuint array);
510 bool BindValuebufferCHROMIUMHelper(GLenum target, GLuint valuebuffer);
511 bool UseProgramHelper(GLuint program);
513 void GenBuffersHelper(GLsizei n, const GLuint* buffers);
514 void GenFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
515 void GenRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
516 void GenTexturesHelper(GLsizei n, const GLuint* textures);
517 void GenVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
518 void GenQueriesEXTHelper(GLsizei n, const GLuint* queries);
519 void GenValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
521 void DeleteBuffersHelper(GLsizei n, const GLuint* buffers);
522 void DeleteFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
523 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
524 void DeleteTexturesHelper(GLsizei n, const GLuint* textures);
525 bool DeleteProgramHelper(GLuint program);
526 bool DeleteShaderHelper(GLuint shader);
527 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* queries);
528 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
529 void DeleteValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
531 void DeleteBuffersStub(GLsizei n, const GLuint* buffers);
532 void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers);
533 void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers);
534 void DeleteTexturesStub(GLsizei n, const GLuint* textures);
535 void DeleteProgramStub(GLsizei n, const GLuint* programs);
536 void DeleteShaderStub(GLsizei n, const GLuint* shaders);
537 void DeleteVertexArraysOESStub(GLsizei n, const GLuint* arrays);
538 void DeleteValuebuffersCHROMIUMStub(GLsizei n, const GLuint* valuebuffers);
540 void BufferDataHelper(
541 GLenum target, GLsizeiptr size, const void* data, GLenum usage);
542 void BufferSubDataHelper(
543 GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
544 void BufferSubDataHelperImpl(
545 GLenum target, GLintptr offset, GLsizeiptr size, const void* data,
546 ScopedTransferBufferPtr* buffer);
548 GLuint CreateImageCHROMIUMHelper(ClientBuffer buffer,
551 GLenum internalformat);
552 void DestroyImageCHROMIUMHelper(GLuint image_id);
553 GLuint CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width,
555 GLenum internalformat,
558 // Helper for GetVertexAttrib
559 bool GetVertexAttribHelper(GLuint index, GLenum pname, uint32* param);
561 GLuint GetMaxValueInBufferCHROMIUMHelper(
562 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset);
564 void RestoreElementAndArrayBuffers(bool restore);
565 void RestoreArrayBuffer(bool restrore);
567 // The pixels pointer should already account for unpack skip rows and skip
569 void TexSubImage2DImpl(
570 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
571 GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size,
572 const void* pixels, uint32 pixels_padded_row_size, GLboolean internal,
573 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
575 // Helpers for query functions.
576 bool GetHelper(GLenum pname, GLint* params);
577 bool GetBooleanvHelper(GLenum pname, GLboolean* params);
578 bool GetBufferParameterivHelper(GLenum target, GLenum pname, GLint* params);
579 bool GetFloatvHelper(GLenum pname, GLfloat* params);
580 bool GetFramebufferAttachmentParameterivHelper(
581 GLenum target, GLenum attachment, GLenum pname, GLint* params);
582 bool GetIntegervHelper(GLenum pname, GLint* params);
583 bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params);
584 bool GetRenderbufferParameterivHelper(
585 GLenum target, GLenum pname, GLint* params);
586 bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params);
587 bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params);
588 bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params);
589 const GLubyte* GetStringHelper(GLenum name);
591 bool IsExtensionAvailable(const char* ext);
593 // Caches certain capabilties state. Return true if cached.
594 bool SetCapabilityState(GLenum cap, bool enabled);
596 IdHandlerInterface* GetIdHandler(int id_namespace) const;
597 // IdAllocators for objects that can't be shared among contexts.
598 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
599 // Framebuffer and Vertex array objects.
600 IdAllocator* GetIdAllocator(int id_namespace) const;
604 void RunIfContextNotLost(const base::Closure& callback);
606 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
607 // If not, generate an approriate error, and return false.
608 bool ValidateOffset(const char* func, GLintptr offset);
610 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
611 // If not, generate an approriate error, and return false.
612 bool ValidateSize(const char* func, GLsizeiptr offset);
614 // Remove the transfer buffer from the buffer tracker. For buffers used
615 // asynchronously the memory is free:ed if the upload has completed. For
616 // other buffers, the memory is either free:ed immediately or free:ed pending
618 void RemoveTransferBuffer(BufferTracker::Buffer* buffer);
620 // Returns true if the async upload token has passed.
622 // NOTE: This will detect wrapped async tokens by checking if the most
623 // significant bit of async token to check is 1 but the last read is 0, i.e.
624 // the uint32 wrapped.
625 bool HasAsyncUploadTokenPassed(uint32 token) const {
626 return async_upload_sync_->HasAsyncUploadTokenPassed(token);
629 // Get the next async upload token.
630 uint32 NextAsyncUploadToken();
632 // Ensure that the shared memory used for synchronizing async upload tokens
635 // Returns false on error, true on success.
636 bool EnsureAsyncUploadSync();
638 // Checks the last read asynchronously upload token and frees any unmanaged
639 // transfer buffer that has its async token passed.
640 void PollAsyncUploads();
642 // Free every async upload buffer. If some async upload buffer is still in use
643 // wait for them to finish before freeing.
644 void FreeAllAsyncUploadBuffers();
646 bool GetBoundPixelTransferBuffer(
647 GLenum target, const char* function_name, GLuint* buffer_id);
648 BufferTracker::Buffer* GetBoundPixelUnpackTransferBufferIfValid(
650 const char* function_name, GLuint offset, GLsizei size);
652 const std::string& GetLogPrefix() const;
654 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
656 void FailGLError(GLenum error);
658 void CheckGLError() { }
659 void FailGLError(GLenum /* error */) { }
663 GLES2CmdHelper* helper_;
664 TransferBufferInterface* transfer_buffer_;
665 std::string last_error_;
666 DebugMarkerManager debug_marker_manager_;
667 std::string this_in_hex_;
669 std::queue<int32> swap_buffers_tokens_;
670 std::queue<int32> rate_limit_tokens_;
672 ExtensionStatus angle_pack_reverse_row_order_status_;
673 ExtensionStatus chromium_framebuffer_multisample_;
675 GLStaticState static_state_;
676 ClientContextState state_;
678 // pack alignment as last set by glPixelStorei
679 GLint pack_alignment_;
681 // unpack alignment as last set by glPixelStorei
682 GLint unpack_alignment_;
684 // unpack yflip as last set by glPixelstorei
687 // unpack row length as last set by glPixelStorei
688 GLint unpack_row_length_;
690 // unpack skip rows as last set by glPixelStorei
691 GLint unpack_skip_rows_;
693 // unpack skip pixels as last set by glPixelStorei
694 GLint unpack_skip_pixels_;
696 // pack reverse row order as last set by glPixelstorei
697 bool pack_reverse_row_order_;
699 scoped_ptr<TextureUnit[]> texture_units_;
701 // 0 to gl_state_.max_combined_texture_image_units.
702 GLuint active_texture_unit_;
704 GLuint bound_framebuffer_;
705 GLuint bound_read_framebuffer_;
706 GLuint bound_renderbuffer_;
707 GLuint bound_valuebuffer_;
709 // The program in use by glUseProgram
710 GLuint current_program_;
712 // The currently bound array buffer.
713 GLuint bound_array_buffer_id_;
715 // The currently bound pixel transfer buffers.
716 GLuint bound_pixel_pack_transfer_buffer_id_;
717 GLuint bound_pixel_unpack_transfer_buffer_id_;
719 // The current asynchronous pixel buffer upload token.
720 uint32 async_upload_token_;
722 // The shared memory used for synchronizing asynchronous upload tokens.
723 AsyncUploadSync* async_upload_sync_;
724 int32 async_upload_sync_shm_id_;
725 unsigned int async_upload_sync_shm_offset_;
727 // Unmanaged pixel transfer buffer memory pending asynchronous upload token.
728 typedef std::list<std::pair<void*, uint32> > DetachedAsyncUploadMemoryList;
729 DetachedAsyncUploadMemoryList detached_async_upload_memory_;
731 // Client side management for vertex array objects. Needed to correctly
732 // track client side arrays.
733 scoped_ptr<VertexArrayObjectManager> vertex_array_object_manager_;
735 GLuint reserved_ids_[2];
737 // Current GL error bits.
740 // Whether or not to print debugging info.
743 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
744 bool lose_context_when_out_of_memory_;
746 // Whether or not to support client side arrays.
747 bool support_client_side_arrays_;
749 // Used to check for single threaded access.
752 // Map of GLenum to Strings for glGetString. We need to cache these because
753 // the pointer passed back to the client has to remain valid for eternity.
754 typedef std::map<uint32, std::set<std::string> > GLStringMap;
755 GLStringMap gl_strings_;
757 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
758 // have an enum for this so handle it separately.
759 std::set<std::string> requestable_extensions_set_;
761 typedef std::map<const void*, MappedBuffer> MappedBufferMap;
762 MappedBufferMap mapped_buffers_;
764 typedef std::map<const void*, MappedTexture> MappedTextureMap;
765 MappedTextureMap mapped_textures_;
767 scoped_ptr<MappedMemoryManager> mapped_memory_;
769 scoped_refptr<ShareGroup> share_group_;
770 ShareGroupContextData share_group_context_data_;
772 scoped_ptr<QueryTracker> query_tracker_;
773 typedef std::map<GLuint, QueryTracker::Query*> QueryMap;
774 QueryMap current_queries_;
775 scoped_ptr<IdAllocator> query_id_allocator_;
777 scoped_ptr<BufferTracker> buffer_tracker_;
779 GLES2ImplementationErrorMessageCallback* error_message_callback_;
781 scoped_ptr<std::string> current_trace_name_;
783 GpuControl* gpu_control_;
785 Capabilities capabilities_;
787 base::WeakPtrFactory<GLES2Implementation> weak_ptr_factory_;
789 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation);
792 inline bool GLES2Implementation::GetBufferParameterivHelper(
793 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
797 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
799 GLenum /* attachment */,
801 GLint* /* params */) {
805 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
806 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
810 inline bool GLES2Implementation::GetShaderivHelper(
811 GLuint /* shader */, GLenum /* pname */, GLint* /* params */) {
815 inline bool GLES2Implementation::GetTexParameterfvHelper(
816 GLenum /* target */, GLenum /* pname */, GLfloat* /* params */) {
820 inline bool GLES2Implementation::GetTexParameterivHelper(
821 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
828 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_