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 typedef std::pair
<GLenum
, GLenum
> ShaderPrecisionKey
;
141 typedef std::map
<ShaderPrecisionKey
,
142 cmds::GetShaderPrecisionFormat::Result
>
144 ShaderPrecisionMap shader_precisions
;
147 // The maxiumum result size from simple GL get commands.
148 static const size_t kMaxSizeOfSimpleResult
= 16 * sizeof(uint32
); // NOLINT.
150 // used for testing only. If more things are reseved add them here.
151 static const unsigned int kStartingOffset
= kMaxSizeOfSimpleResult
;
153 // Size in bytes to issue async flush for transfer buffer.
154 static const unsigned int kSizeToFlush
= 256 * 1024;
156 // The bucket used for results. Public for testing only.
157 static const uint32 kResultBucketId
= 1;
159 // Alignment of allocations.
160 static const unsigned int kAlignment
= 4;
162 // GL names for the buffers used to emulate client side buffers.
163 static const GLuint kClientSideArrayId
= 0xFEDCBA98u
;
164 static const GLuint kClientSideElementArrayId
= 0xFEDCBA99u
;
166 // Number of swap buffers allowed before waiting.
167 static const size_t kMaxSwapBuffers
= 2;
169 GLES2Implementation(GLES2CmdHelper
* helper
,
170 ShareGroup
* share_group
,
171 TransferBufferInterface
* transfer_buffer
,
172 bool bind_generates_resource
,
173 bool lose_context_when_out_of_memory
,
174 bool support_client_side_arrays
,
175 GpuControl
* gpu_control
);
177 ~GLES2Implementation() override
;
180 unsigned int starting_transfer_buffer_size
,
181 unsigned int min_transfer_buffer_size
,
182 unsigned int max_transfer_buffer_size
,
183 unsigned int mapped_memory_limit
);
185 // The GLES2CmdHelper being used by this GLES2Implementation. You can use
186 // this to issue cmds at a lower level for certain kinds of optimization.
187 GLES2CmdHelper
* helper() const;
189 // Gets client side generated errors.
190 GLenum
GetClientSideGLError();
192 // Include the auto-generated part of this class. We split this because
193 // it means we can easily edit the non-auto generated parts right here in
194 // this file instead of having to edit some template or the code generator.
195 #include "gpu/command_buffer/client/gles2_implementation_autogen.h"
197 void DisableVertexAttribArray(GLuint index
) override
;
198 void EnableVertexAttribArray(GLuint index
) override
;
199 void GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
* params
) override
;
200 void GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
* params
) override
;
201 void GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
* params
) override
;
202 void GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
* params
) override
;
204 // ContextSupport implementation.
205 void Swap() override
;
206 void PartialSwapBuffers(const gfx::Rect
& sub_buffer
) override
;
207 void ScheduleOverlayPlane(int plane_z_order
,
208 gfx::OverlayTransform plane_transform
,
209 unsigned overlay_texture_id
,
210 const gfx::Rect
& display_bounds
,
211 const gfx::RectF
& uv_rect
) override
;
212 GLuint
InsertFutureSyncPointCHROMIUM() override
;
213 void RetireSyncPointCHROMIUM(GLuint sync_point
) override
;
215 void GetProgramInfoCHROMIUMHelper(GLuint program
, std::vector
<int8
>* result
);
216 GLint
GetAttribLocationHelper(GLuint program
, const char* name
);
217 GLint
GetUniformLocationHelper(GLuint program
, const char* name
);
218 GLint
GetFragDataLocationHelper(GLuint program
, const char* name
);
219 bool GetActiveAttribHelper(
220 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
221 GLint
* size
, GLenum
* type
, char* name
);
222 bool GetActiveUniformHelper(
223 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
224 GLint
* size
, GLenum
* type
, char* name
);
225 void GetUniformBlocksCHROMIUMHelper(
226 GLuint program
, std::vector
<int8
>* result
);
227 void GetUniformsES3CHROMIUMHelper(
228 GLuint program
, std::vector
<int8
>* result
);
229 GLuint
GetUniformBlockIndexHelper(GLuint program
, const char* name
);
230 bool GetActiveUniformBlockNameHelper(
231 GLuint program
, GLuint index
, GLsizei bufsize
,
232 GLsizei
* length
, char* name
);
233 bool GetActiveUniformBlockivHelper(
234 GLuint program
, GLuint index
, GLenum pname
, GLint
* params
);
235 void GetTransformFeedbackVaryingsCHROMIUMHelper(
236 GLuint program
, std::vector
<int8
>* result
);
237 bool GetTransformFeedbackVaryingHelper(
238 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
239 GLint
* size
, GLenum
* type
, char* name
);
240 bool GetUniformIndicesHelper(
241 GLuint program
, GLsizei count
, const char* const* names
, GLuint
* indices
);
242 bool GetActiveUniformsivHelper(
243 GLuint program
, GLsizei count
, const GLuint
* indices
,
244 GLenum pname
, GLint
* params
);
245 bool GetSyncivHelper(
246 GLsync sync
, GLenum pname
, GLsizei bufsize
, GLsizei
* length
,
249 void FreeUnusedSharedMemory();
250 void FreeEverything();
252 // ContextSupport implementation.
253 void SignalSyncPoint(uint32 sync_point
,
254 const base::Closure
& callback
) override
;
255 void SignalQuery(uint32 query
, const base::Closure
& callback
) override
;
256 void SetSurfaceVisible(bool visible
) override
;
258 void SetErrorMessageCallback(
259 GLES2ImplementationErrorMessageCallback
* callback
) {
260 error_message_callback_
= callback
;
263 ShareGroup
* share_group() const {
264 return share_group_
.get();
267 const Capabilities
& capabilities() const {
268 return capabilities_
;
271 GpuControl
* gpu_control() {
275 ShareGroupContextData
* share_group_context_data() {
276 return &share_group_context_data_
;
280 friend class GLES2ImplementationTest
;
281 friend class VertexArrayObjectManager
;
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
)
299 // access mode. Currently only GL_WRITE_ONLY is valid
302 // Shared memory ID for buffer.
305 // Address of shared memory
308 // Offset of shared memory
309 unsigned int shm_offset
;
312 // Used to track mapped textures.
313 struct MappedTexture
: public MappedResource
{
318 unsigned int shm_offset
,
327 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
338 // These match the arguments to TexSubImage2D.
349 // Used to track mapped buffers.
350 struct MappedBuffer
: public MappedResource
{
355 unsigned int shm_offset
,
359 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
365 // These match the arguments to BufferSubData.
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
382 GLuint bound_texture_cube_map
;
384 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
386 GLuint bound_texture_external_oes
;
389 // Checks for single threaded access.
390 class SingleThreadChecker
{
392 explicit SingleThreadChecker(GLES2Implementation
* gles2_implementation
);
393 ~SingleThreadChecker();
396 GLES2Implementation
* gles2_implementation_
;
399 // Gets the value of the result.
400 template <typename T
>
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.
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() {
429 // Waits for all commands to execute.
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 DeleteProgramStub(GLsizei n
, const GLuint
* programs
);
514 void DeleteShaderStub(GLsizei n
, const GLuint
* shaders
);
515 void DeleteVertexArraysOESStub(GLsizei n
, const GLuint
* arrays
);
516 void DeleteValuebuffersCHROMIUMStub(GLsizei n
, const GLuint
* valuebuffers
);
517 void DeleteSamplersStub(GLsizei n
, const GLuint
* samplers
);
518 void DeleteTransformFeedbacksStub(
519 GLsizei n
, const GLuint
* transformfeedbacks
);
520 void DeleteSyncStub(GLsizei n
, const GLuint
* syncs
);
522 void BufferDataHelper(
523 GLenum target
, GLsizeiptr size
, const void* data
, GLenum usage
);
524 void BufferSubDataHelper(
525 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
);
526 void BufferSubDataHelperImpl(
527 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
,
528 ScopedTransferBufferPtr
* buffer
);
530 GLuint
CreateImageCHROMIUMHelper(ClientBuffer buffer
,
533 GLenum internalformat
);
534 void DestroyImageCHROMIUMHelper(GLuint image_id
);
535 GLuint
CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width
,
537 GLenum internalformat
,
540 // Helper for GetVertexAttrib
541 bool GetVertexAttribHelper(GLuint index
, GLenum pname
, uint32
* param
);
543 GLuint
GetMaxValueInBufferCHROMIUMHelper(
544 GLuint buffer_id
, GLsizei count
, GLenum type
, GLuint offset
);
546 void RestoreElementAndArrayBuffers(bool restore
);
547 void RestoreArrayBuffer(bool restrore
);
549 // The pixels pointer should already account for unpack skip
550 // images/rows/pixels.
551 void TexSubImage2DImpl(
552 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLsizei width
,
553 GLsizei height
, GLenum format
, GLenum type
, uint32 unpadded_row_size
,
554 const void* pixels
, uint32 pixels_padded_row_size
, GLboolean internal
,
555 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
556 void TexSubImage3DImpl(
557 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLint zoffset
,
558 GLsizei width
, GLsizei height
, GLsizei depth
, GLenum format
, GLenum type
,
559 uint32 unpadded_row_size
, const void* pixels
,
560 uint32 pixels_padded_row_size
, GLboolean internal
,
561 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
563 // Helpers for query functions.
564 bool GetHelper(GLenum pname
, GLint
* params
);
565 GLuint
GetBoundBufferHelper(GLenum target
);
566 bool GetBooleanvHelper(GLenum pname
, GLboolean
* params
);
567 bool GetBufferParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
568 bool GetFloatvHelper(GLenum pname
, GLfloat
* params
);
569 bool GetFramebufferAttachmentParameterivHelper(
570 GLenum target
, GLenum attachment
, GLenum pname
, GLint
* params
);
571 bool GetInteger64vHelper(GLenum pname
, GLint64
* params
);
572 bool GetIntegervHelper(GLenum pname
, GLint
* params
);
573 bool GetIntegeri_vHelper(GLenum pname
, GLuint index
, GLint
* data
);
574 bool GetInteger64i_vHelper(GLenum pname
, GLuint index
, GLint64
* data
);
575 bool GetInternalformativHelper(
576 GLenum target
, GLenum format
, GLenum pname
, GLsizei bufSize
,
578 bool GetProgramivHelper(GLuint program
, GLenum pname
, GLint
* params
);
579 bool GetSamplerParameterfvHelper(
580 GLuint sampler
, GLenum pname
, GLfloat
* params
);
581 bool GetSamplerParameterivHelper(
582 GLuint sampler
, GLenum pname
, GLint
* params
);
583 bool GetRenderbufferParameterivHelper(
584 GLenum target
, GLenum pname
, GLint
* params
);
585 bool GetShaderivHelper(GLuint shader
, GLenum pname
, GLint
* params
);
586 bool GetTexParameterfvHelper(GLenum target
, GLenum pname
, GLfloat
* params
);
587 bool GetTexParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
588 const GLubyte
* GetStringHelper(GLenum name
);
590 bool IsExtensionAvailable(const char* ext
);
592 // Caches certain capabilties state. Return true if cached.
593 bool SetCapabilityState(GLenum cap
, bool enabled
);
595 IdHandlerInterface
* GetIdHandler(int id_namespace
) const;
596 // IdAllocators for objects that can't be shared among contexts.
597 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
598 // Framebuffer and Vertex array objects.
599 IdAllocator
* GetIdAllocator(int id_namespace
) const;
603 void RunIfContextNotLost(const base::Closure
& callback
);
605 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
606 // If not, generate an approriate error, and return false.
607 bool ValidateOffset(const char* func
, GLintptr offset
);
609 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
610 // If not, generate an approriate error, and return false.
611 bool ValidateSize(const char* func
, GLsizeiptr offset
);
613 // Remove the transfer buffer from the buffer tracker. For buffers used
614 // asynchronously the memory is free:ed if the upload has completed. For
615 // other buffers, the memory is either free:ed immediately or free:ed pending
617 void RemoveTransferBuffer(BufferTracker::Buffer
* buffer
);
619 // Returns true if the async upload token has passed.
621 // NOTE: This will detect wrapped async tokens by checking if the most
622 // significant bit of async token to check is 1 but the last read is 0, i.e.
623 // the uint32 wrapped.
624 bool HasAsyncUploadTokenPassed(uint32 token
) const {
625 return async_upload_sync_
->HasAsyncUploadTokenPassed(token
);
628 // Get the next async upload token.
629 uint32
NextAsyncUploadToken();
631 // Ensure that the shared memory used for synchronizing async upload tokens
634 // Returns false on error, true on success.
635 bool EnsureAsyncUploadSync();
637 // Checks the last read asynchronously upload token and frees any unmanaged
638 // transfer buffer that has its async token passed.
639 void PollAsyncUploads();
641 // Free every async upload buffer. If some async upload buffer is still in use
642 // wait for them to finish before freeing.
643 void FreeAllAsyncUploadBuffers();
645 bool GetBoundPixelTransferBuffer(
646 GLenum target
, const char* function_name
, GLuint
* buffer_id
);
647 BufferTracker::Buffer
* GetBoundPixelUnpackTransferBufferIfValid(
649 const char* function_name
, GLuint offset
, GLsizei size
);
651 // Pack 2D arrays of char into a bucket.
652 // Helper function for ShaderSource(), TransformFeedbackVaryings(), etc.
653 bool PackStringsToBucket(GLsizei count
,
654 const char* const* str
,
656 const char* func_name
);
658 const std::string
& GetLogPrefix() const;
660 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
662 void FailGLError(GLenum error
);
664 void CheckGLError() { }
665 void FailGLError(GLenum
/* error */) { }
668 void RemoveMappedBufferRangeByTarget(GLenum target
);
669 void RemoveMappedBufferRangeById(GLuint buffer
);
670 void ClearMappedBufferRangeMap();
672 void DrawElementsImpl(GLenum mode
, GLsizei count
, GLenum type
,
673 const void* indices
, const char* func_name
);
676 GLES2CmdHelper
* helper_
;
677 TransferBufferInterface
* transfer_buffer_
;
678 std::string last_error_
;
679 DebugMarkerManager debug_marker_manager_
;
680 std::string this_in_hex_
;
682 std::queue
<int32
> swap_buffers_tokens_
;
683 std::queue
<int32
> rate_limit_tokens_
;
685 ExtensionStatus angle_pack_reverse_row_order_status_
;
686 ExtensionStatus chromium_framebuffer_multisample_
;
688 GLStaticState static_state_
;
689 ClientContextState state_
;
691 // pack alignment as last set by glPixelStorei
692 GLint pack_alignment_
;
694 // unpack alignment as last set by glPixelStorei
695 GLint unpack_alignment_
;
697 // unpack yflip as last set by glPixelstorei
700 // unpack row length as last set by glPixelStorei
701 GLint unpack_row_length_
;
703 // unpack image height as last set by glPixelStorei
704 GLint unpack_image_height_
;
706 // unpack skip rows as last set by glPixelStorei
707 GLint unpack_skip_rows_
;
709 // unpack skip pixels as last set by glPixelStorei
710 GLint unpack_skip_pixels_
;
712 // unpack skip images as last set by glPixelStorei
713 GLint unpack_skip_images_
;
715 // pack reverse row order as last set by glPixelstorei
716 bool pack_reverse_row_order_
;
718 scoped_ptr
<TextureUnit
[]> texture_units_
;
720 // 0 to gl_state_.max_combined_texture_image_units.
721 GLuint active_texture_unit_
;
723 GLuint bound_framebuffer_
;
724 GLuint bound_read_framebuffer_
;
725 GLuint bound_renderbuffer_
;
726 GLuint bound_valuebuffer_
;
728 // The program in use by glUseProgram
729 GLuint current_program_
;
731 GLuint bound_array_buffer_
;
732 GLuint bound_copy_read_buffer_
;
733 GLuint bound_copy_write_buffer_
;
734 GLuint bound_pixel_pack_buffer_
;
735 GLuint bound_pixel_unpack_buffer_
;
736 GLuint bound_transform_feedback_buffer_
;
737 GLuint bound_uniform_buffer_
;
739 // The currently bound pixel transfer buffers.
740 GLuint bound_pixel_pack_transfer_buffer_id_
;
741 GLuint bound_pixel_unpack_transfer_buffer_id_
;
743 // The current asynchronous pixel buffer upload token.
744 uint32 async_upload_token_
;
746 // The shared memory used for synchronizing asynchronous upload tokens.
747 AsyncUploadSync
* async_upload_sync_
;
748 int32 async_upload_sync_shm_id_
;
749 unsigned int async_upload_sync_shm_offset_
;
751 // Unmanaged pixel transfer buffer memory pending asynchronous upload token.
752 typedef std::list
<std::pair
<void*, uint32
> > DetachedAsyncUploadMemoryList
;
753 DetachedAsyncUploadMemoryList detached_async_upload_memory_
;
755 // Client side management for vertex array objects. Needed to correctly
756 // track client side arrays.
757 scoped_ptr
<VertexArrayObjectManager
> vertex_array_object_manager_
;
759 GLuint reserved_ids_
[2];
761 // Current GL error bits.
764 // Whether or not to print debugging info.
767 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
768 const bool lose_context_when_out_of_memory_
;
770 // Whether or not to support client side arrays.
771 const bool support_client_side_arrays_
;
773 // Used to check for single threaded access.
776 // Map of GLenum to Strings for glGetString. We need to cache these because
777 // the pointer passed back to the client has to remain valid for eternity.
778 typedef std::map
<uint32
, std::set
<std::string
> > GLStringMap
;
779 GLStringMap gl_strings_
;
781 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
782 // have an enum for this so handle it separately.
783 std::set
<std::string
> requestable_extensions_set_
;
785 typedef std::map
<const void*, MappedBuffer
> MappedBufferMap
;
786 MappedBufferMap mapped_buffers_
;
788 // TODO(zmo): Consolidate |mapped_buffers_| and |mapped_buffer_range_map_|.
789 typedef base::hash_map
<GLuint
, MappedBuffer
> MappedBufferRangeMap
;
790 MappedBufferRangeMap mapped_buffer_range_map_
;
792 typedef std::map
<const void*, MappedTexture
> MappedTextureMap
;
793 MappedTextureMap mapped_textures_
;
795 scoped_ptr
<MappedMemoryManager
> mapped_memory_
;
797 scoped_refptr
<ShareGroup
> share_group_
;
798 ShareGroupContextData share_group_context_data_
;
800 scoped_ptr
<QueryTracker
> query_tracker_
;
801 typedef std::map
<GLuint
, QueryTracker::Query
*> QueryMap
;
802 QueryMap current_queries_
;
803 scoped_ptr
<IdAllocator
> query_id_allocator_
;
805 scoped_ptr
<BufferTracker
> buffer_tracker_
;
807 GLES2ImplementationErrorMessageCallback
* error_message_callback_
;
809 int current_trace_stack_
;
811 GpuControl
* gpu_control_
;
813 Capabilities capabilities_
;
815 base::WeakPtrFactory
<GLES2Implementation
> weak_ptr_factory_
;
817 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation
);
820 inline bool GLES2Implementation::GetBufferParameterivHelper(
821 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
825 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
827 GLenum
/* attachment */,
829 GLint
* /* params */) {
833 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
834 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
838 inline bool GLES2Implementation::GetShaderivHelper(
839 GLuint
/* shader */, GLenum
/* pname */, GLint
* /* params */) {
843 inline bool GLES2Implementation::GetTexParameterfvHelper(
844 GLenum
/* target */, GLenum
/* pname */, GLfloat
* /* params */) {
848 inline bool GLES2Implementation::GetTexParameterivHelper(
849 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
856 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_