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_
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 "base/trace_event/memory_dump_provider.h"
22 #include "gpu/command_buffer/client/buffer_tracker.h"
23 #include "gpu/command_buffer/client/client_context_state.h"
24 #include "gpu/command_buffer/client/context_support.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/ref_counted.h"
29 #include "gpu/command_buffer/client/share_group.h"
30 #include "gpu/command_buffer/common/capabilities.h"
31 #include "gpu/command_buffer/common/debug_marker_manager.h"
32 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
34 #if !defined(NDEBUG) && !defined(__native_client__) && !defined(GLES2_CONFORMANCE_TESTS) // NOLINT
35 #if defined(GLES2_INLINE_OPTIMIZATION)
36 // TODO(gman): Replace with macros that work with inline optmization.
37 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
38 #define GPU_CLIENT_LOG(args)
39 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
40 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
42 #include "base/logging.h"
43 #define GPU_CLIENT_SINGLE_THREAD_CHECK() SingleThreadChecker checker(this);
44 #define GPU_CLIENT_LOG(args) DLOG_IF(INFO, debug_) << args;
45 #define GPU_CLIENT_LOG_CODE_BLOCK(code) code
46 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code) code
47 #define GPU_CLIENT_DEBUG
50 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
51 #define GPU_CLIENT_LOG(args)
52 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
53 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
56 #if defined(GPU_CLIENT_DEBUG)
57 // Set to 1 to have the client fail when a GL error is generated.
58 // This helps find bugs in the renderer since the debugger stops on the error.
60 # define GL_CLIENT_FAIL_GL_ERRORS
64 // Check that destination pointers point to initialized memory.
65 // When the context is lost, calling GL function has no effect so if destination
66 // pointers point to initialized memory it can often lead to crash bugs. eg.
69 // glGetShaderSource(shader, max_size, &len, buffer);
70 // std::string src(buffer, buffer + len); // len can be uninitialized here!!!
72 // Because this check is not official GL this check happens only on Chrome code,
75 // If it was up to us we'd just always write to the destination but the OpenGL
76 // spec defines the behavior of OpenGL functions, not us. :-(
77 #if defined(__native_client__) || defined(GLES2_CONFORMANCE_TESTS)
78 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v)
79 #define GPU_CLIENT_DCHECK(v)
80 #elif defined(GPU_DCHECK)
81 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v)
82 #define GPU_CLIENT_DCHECK(v) GPU_DCHECK(v)
84 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
85 #define GPU_CLIENT_DCHECK(v) DCHECK(v)
87 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
88 #define GPU_CLIENT_DCHECK(v) ASSERT(v)
91 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \
92 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \
93 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
95 #define GPU_CLIENT_VALIDATE_DESTINATION_OPTIONAL_INITALIZATION(type, ptr) \
96 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(!ptr || \
97 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
103 class ScopedTransferBufferPtr
;
104 class TransferBufferInterface
;
108 class GLES2CmdHelper
;
109 class VertexArrayObjectManager
;
112 class GLES2ImplementationErrorMessageCallback
{
114 virtual ~GLES2ImplementationErrorMessageCallback() { }
115 virtual void OnErrorMessage(const char* msg
, int id
) = 0;
118 // This class emulates GLES2 over command buffers. It can be used by a client
119 // program so that the program does not need deal with shared memory and command
120 // buffer management. See gl2_lib.h. Note that there is a performance gain to
121 // be had by changing your code to use command buffers directly by using the
122 // GLES2CmdHelper but that entails changing your code to use and deal with
123 // shared memory and synchronization issues.
124 class GLES2_IMPL_EXPORT GLES2Implementation
125 : NON_EXPORTED_BASE(public GLES2Interface
),
126 NON_EXPORTED_BASE(public ContextSupport
),
127 NON_EXPORTED_BASE(public base::trace_event::MemoryDumpProvider
) {
129 enum MappedMemoryLimit
{
130 kNoLimit
= MappedMemoryManager::kNoLimit
,
133 // Stores GL state that never changes.
134 struct GLES2_IMPL_EXPORT GLStaticState
{
138 typedef std::pair
<GLenum
, GLenum
> ShaderPrecisionKey
;
139 typedef std::map
<ShaderPrecisionKey
,
140 cmds::GetShaderPrecisionFormat::Result
>
142 ShaderPrecisionMap shader_precisions
;
145 // The maxiumum result size from simple GL get commands.
146 static const size_t kMaxSizeOfSimpleResult
= 16 * sizeof(uint32
); // NOLINT.
148 // used for testing only. If more things are reseved add them here.
149 static const unsigned int kStartingOffset
= kMaxSizeOfSimpleResult
;
151 // Size in bytes to issue async flush for transfer buffer.
152 static const unsigned int kSizeToFlush
= 256 * 1024;
154 // The bucket used for results. Public for testing only.
155 static const uint32 kResultBucketId
= 1;
157 // Alignment of allocations.
158 static const unsigned int kAlignment
= 4;
160 // GL names for the buffers used to emulate client side buffers.
161 static const GLuint kClientSideArrayId
= 0xFEDCBA98u
;
162 static const GLuint kClientSideElementArrayId
= 0xFEDCBA99u
;
164 // Number of swap buffers allowed before waiting.
165 static const size_t kMaxSwapBuffers
= 2;
167 GLES2Implementation(GLES2CmdHelper
* helper
,
168 ShareGroup
* share_group
,
169 TransferBufferInterface
* transfer_buffer
,
170 bool bind_generates_resource
,
171 bool lose_context_when_out_of_memory
,
172 bool support_client_side_arrays
,
173 GpuControl
* gpu_control
);
175 ~GLES2Implementation() override
;
178 unsigned int starting_transfer_buffer_size
,
179 unsigned int min_transfer_buffer_size
,
180 unsigned int max_transfer_buffer_size
,
181 unsigned int mapped_memory_limit
);
183 // The GLES2CmdHelper being used by this GLES2Implementation. You can use
184 // this to issue cmds at a lower level for certain kinds of optimization.
185 GLES2CmdHelper
* helper() const;
187 // Gets client side generated errors.
188 GLenum
GetClientSideGLError();
190 // Include the auto-generated part of this class. We split this because
191 // it means we can easily edit the non-auto generated parts right here in
192 // this file instead of having to edit some template or the code generator.
193 #include "gpu/command_buffer/client/gles2_implementation_autogen.h"
195 void DisableVertexAttribArray(GLuint index
) override
;
196 void EnableVertexAttribArray(GLuint index
) override
;
197 void GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
* params
) override
;
198 void GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
* params
) override
;
199 void GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
* params
) override
;
200 void GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
* params
) override
;
202 // ContextSupport implementation.
203 void Swap() override
;
204 void PartialSwapBuffers(const gfx::Rect
& sub_buffer
) override
;
205 void ScheduleOverlayPlane(int plane_z_order
,
206 gfx::OverlayTransform plane_transform
,
207 unsigned overlay_texture_id
,
208 const gfx::Rect
& display_bounds
,
209 const gfx::RectF
& uv_rect
) override
;
210 GLuint
InsertFutureSyncPointCHROMIUM() override
;
211 void RetireSyncPointCHROMIUM(GLuint sync_point
) override
;
213 void GetProgramInfoCHROMIUMHelper(GLuint program
, std::vector
<int8
>* result
);
214 GLint
GetAttribLocationHelper(GLuint program
, const char* name
);
215 GLint
GetUniformLocationHelper(GLuint program
, const char* name
);
216 GLint
GetFragDataLocationHelper(GLuint program
, const char* name
);
217 bool GetActiveAttribHelper(
218 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
219 GLint
* size
, GLenum
* type
, char* name
);
220 bool GetActiveUniformHelper(
221 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
222 GLint
* size
, GLenum
* type
, char* name
);
223 void GetUniformBlocksCHROMIUMHelper(
224 GLuint program
, std::vector
<int8
>* result
);
225 void GetUniformsES3CHROMIUMHelper(
226 GLuint program
, std::vector
<int8
>* result
);
227 GLuint
GetUniformBlockIndexHelper(GLuint program
, const char* name
);
228 bool GetActiveUniformBlockNameHelper(
229 GLuint program
, GLuint index
, GLsizei bufsize
,
230 GLsizei
* length
, char* name
);
231 bool GetActiveUniformBlockivHelper(
232 GLuint program
, GLuint index
, GLenum pname
, GLint
* params
);
233 void GetTransformFeedbackVaryingsCHROMIUMHelper(
234 GLuint program
, std::vector
<int8
>* result
);
235 bool GetTransformFeedbackVaryingHelper(
236 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
237 GLint
* size
, GLenum
* type
, char* name
);
238 bool GetUniformIndicesHelper(
239 GLuint program
, GLsizei count
, const char* const* names
, GLuint
* indices
);
240 bool GetActiveUniformsivHelper(
241 GLuint program
, GLsizei count
, const GLuint
* indices
,
242 GLenum pname
, GLint
* params
);
243 bool GetSyncivHelper(
244 GLsync sync
, GLenum pname
, GLsizei bufsize
, GLsizei
* length
,
246 bool GetQueryObjectValueHelper(
247 const char* function_name
, GLuint id
, GLenum pname
, GLuint64
* params
);
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
;
257 void SetAggressivelyFreeResources(bool aggressively_free_resources
) override
;
259 // base::trace_event::MemoryDumpProvider implementation.
260 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs
& args
,
261 base::trace_event::ProcessMemoryDump
* pmd
) override
;
263 void SetErrorMessageCallback(
264 GLES2ImplementationErrorMessageCallback
* callback
) {
265 error_message_callback_
= callback
;
268 ShareGroup
* share_group() const {
269 return share_group_
.get();
272 const Capabilities
& capabilities() const {
273 return capabilities_
;
276 GpuControl
* gpu_control() {
280 ShareGroupContextData
* share_group_context_data() {
281 return &share_group_context_data_
;
285 friend class GLES2ImplementationTest
;
286 friend class VertexArrayObjectManager
;
287 friend class QueryTracker
;
289 // Used to track whether an extension is available
290 enum ExtensionStatus
{
291 kAvailableExtensionStatus
,
292 kUnavailableExtensionStatus
,
293 kUnknownExtensionStatus
296 // Base class for mapped resources.
297 struct MappedResource
{
298 MappedResource(GLenum _access
, int _shm_id
, void* mem
, unsigned int offset
)
305 // access mode. Currently only GL_WRITE_ONLY is valid
308 // Shared memory ID for buffer.
311 // Address of shared memory
314 // Offset of shared memory
315 unsigned int shm_offset
;
318 // Used to track mapped textures.
319 struct MappedTexture
: public MappedResource
{
324 unsigned int shm_offset
,
333 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
344 // These match the arguments to TexSubImage2D.
355 // Used to track mapped buffers.
356 struct MappedBuffer
: public MappedResource
{
361 unsigned int shm_offset
,
365 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
371 // These match the arguments to BufferSubData.
379 : bound_texture_2d(0),
380 bound_texture_cube_map(0),
381 bound_texture_external_oes(0) {}
383 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
384 GLuint bound_texture_2d
;
386 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
388 GLuint bound_texture_cube_map
;
390 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
392 GLuint bound_texture_external_oes
;
395 // Checks for single threaded access.
396 class SingleThreadChecker
{
398 explicit SingleThreadChecker(GLES2Implementation
* gles2_implementation
);
399 ~SingleThreadChecker();
402 GLES2Implementation
* gles2_implementation_
;
405 // Gets the value of the result.
406 template <typename T
>
408 return static_cast<T
>(GetResultBuffer());
411 void* GetResultBuffer();
412 int32
GetResultShmId();
413 uint32
GetResultShmOffset();
415 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
416 bool IsAnglePackReverseRowOrderAvailable();
417 bool IsChromiumFramebufferMultisampleAvailable();
419 bool IsExtensionAvailableHelper(
420 const char* extension
, ExtensionStatus
* status
);
422 // Gets the GLError through our wrapper.
425 // Sets our wrapper for the GLError.
426 void SetGLError(GLenum error
, const char* function_name
, const char* msg
);
427 void SetGLErrorInvalidEnum(
428 const char* function_name
, GLenum value
, const char* label
);
430 // Returns the last error and clears it. Useful for debugging.
431 const std::string
& GetLastError() {
435 // Waits for all commands to execute.
438 // TODO(gman): These bucket functions really seem like they belong in
439 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
440 // a transfer buffer to function which is currently managed by this class.
442 // Gets the contents of a bucket.
443 bool GetBucketContents(uint32 bucket_id
, std::vector
<int8
>* data
);
445 // Sets the contents of a bucket.
446 void SetBucketContents(uint32 bucket_id
, const void* data
, size_t size
);
448 // Sets the contents of a bucket as a string.
449 void SetBucketAsCString(uint32 bucket_id
, const char* str
);
451 // Gets the contents of a bucket as a string. Returns false if there is no
452 // string available which is a separate case from the empty string.
453 bool GetBucketAsString(uint32 bucket_id
, std::string
* str
);
455 // Sets the contents of a bucket as a string.
456 void SetBucketAsString(uint32 bucket_id
, const std::string
& str
);
458 // Returns true if id is reserved.
459 bool IsBufferReservedId(GLuint id
);
460 bool IsFramebufferReservedId(GLuint id
) { return false; }
461 bool IsRenderbufferReservedId(GLuint id
) { return false; }
462 bool IsTextureReservedId(GLuint id
) { return false; }
463 bool IsVertexArrayReservedId(GLuint id
) { return false; }
464 bool IsProgramReservedId(GLuint id
) { return false; }
465 bool IsValuebufferReservedId(GLuint id
) { return false; }
466 bool IsSamplerReservedId(GLuint id
) { return false; }
467 bool IsTransformFeedbackReservedId(GLuint id
) { return false; }
469 void BindBufferHelper(GLenum target
, GLuint buffer
);
470 void BindBufferBaseHelper(GLenum target
, GLuint index
, GLuint buffer
);
471 void BindBufferRangeHelper(GLenum target
, GLuint index
, GLuint buffer
,
472 GLintptr offset
, GLsizeiptr size
);
473 void BindFramebufferHelper(GLenum target
, GLuint framebuffer
);
474 void BindRenderbufferHelper(GLenum target
, GLuint renderbuffer
);
475 void BindSamplerHelper(GLuint unit
, GLuint sampler
);
476 void BindTextureHelper(GLenum target
, GLuint texture
);
477 void BindTransformFeedbackHelper(GLenum target
, GLuint transformfeedback
);
478 void BindVertexArrayOESHelper(GLuint array
);
479 void BindValuebufferCHROMIUMHelper(GLenum target
, GLuint valuebuffer
);
480 void UseProgramHelper(GLuint program
);
482 void BindBufferStub(GLenum target
, GLuint buffer
);
483 void BindBufferBaseStub(GLenum target
, GLuint index
, GLuint buffer
);
484 void BindBufferRangeStub(GLenum target
, GLuint index
, GLuint buffer
,
485 GLintptr offset
, GLsizeiptr size
);
486 void BindFramebufferStub(GLenum target
, GLuint framebuffer
);
487 void BindRenderbufferStub(GLenum target
, GLuint renderbuffer
);
488 void BindTextureStub(GLenum target
, GLuint texture
);
489 void BindValuebufferCHROMIUMStub(GLenum target
, GLuint valuebuffer
);
491 void GenBuffersHelper(GLsizei n
, const GLuint
* buffers
);
492 void GenFramebuffersHelper(GLsizei n
, const GLuint
* framebuffers
);
493 void GenRenderbuffersHelper(GLsizei n
, const GLuint
* renderbuffers
);
494 void GenTexturesHelper(GLsizei n
, const GLuint
* textures
);
495 void GenVertexArraysOESHelper(GLsizei n
, const GLuint
* arrays
);
496 void GenQueriesEXTHelper(GLsizei n
, const GLuint
* queries
);
497 void GenValuebuffersCHROMIUMHelper(GLsizei n
, const GLuint
* valuebuffers
);
498 void GenSamplersHelper(GLsizei n
, const GLuint
* samplers
);
499 void GenTransformFeedbacksHelper(GLsizei n
, const GLuint
* transformfeedbacks
);
501 void DeleteBuffersHelper(GLsizei n
, const GLuint
* buffers
);
502 void DeleteFramebuffersHelper(GLsizei n
, const GLuint
* framebuffers
);
503 void DeleteRenderbuffersHelper(GLsizei n
, const GLuint
* renderbuffers
);
504 void DeleteTexturesHelper(GLsizei n
, const GLuint
* textures
);
505 bool DeleteProgramHelper(GLuint program
);
506 bool DeleteShaderHelper(GLuint shader
);
507 void DeleteQueriesEXTHelper(GLsizei n
, const GLuint
* queries
);
508 void DeleteVertexArraysOESHelper(GLsizei n
, const GLuint
* arrays
);
509 void DeleteValuebuffersCHROMIUMHelper(GLsizei n
, const GLuint
* valuebuffers
);
510 void DeleteSamplersHelper(GLsizei n
, const GLuint
* samplers
);
511 void DeleteTransformFeedbacksHelper(
512 GLsizei n
, const GLuint
* transformfeedbacks
);
513 void DeleteSyncHelper(GLsync sync
);
515 void DeleteBuffersStub(GLsizei n
, const GLuint
* buffers
);
516 void DeleteFramebuffersStub(GLsizei n
, const GLuint
* framebuffers
);
517 void DeleteRenderbuffersStub(GLsizei n
, const GLuint
* renderbuffers
);
518 void DeleteTexturesStub(GLsizei n
, const GLuint
* textures
);
519 void DeletePathsCHROMIUMStub(GLuint first_client_id
, GLsizei range
);
520 void DeleteProgramStub(GLsizei n
, const GLuint
* programs
);
521 void DeleteShaderStub(GLsizei n
, const GLuint
* shaders
);
522 void DeleteVertexArraysOESStub(GLsizei n
, const GLuint
* arrays
);
523 void DeleteValuebuffersCHROMIUMStub(GLsizei n
, const GLuint
* valuebuffers
);
524 void DeleteSamplersStub(GLsizei n
, const GLuint
* samplers
);
525 void DeleteTransformFeedbacksStub(
526 GLsizei n
, const GLuint
* transformfeedbacks
);
527 void DeleteSyncStub(GLsizei n
, const GLuint
* syncs
);
529 void BufferDataHelper(
530 GLenum target
, GLsizeiptr size
, const void* data
, GLenum usage
);
531 void BufferSubDataHelper(
532 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
);
533 void BufferSubDataHelperImpl(
534 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
,
535 ScopedTransferBufferPtr
* buffer
);
537 GLuint
CreateImageCHROMIUMHelper(ClientBuffer buffer
,
540 GLenum internalformat
);
541 void DestroyImageCHROMIUMHelper(GLuint image_id
);
542 GLuint
CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width
,
544 GLenum internalformat
,
547 // Helper for GetVertexAttrib
548 bool GetVertexAttribHelper(GLuint index
, GLenum pname
, uint32
* param
);
550 GLuint
GetMaxValueInBufferCHROMIUMHelper(
551 GLuint buffer_id
, GLsizei count
, GLenum type
, GLuint offset
);
553 void WaitAllAsyncTexImage2DCHROMIUMHelper();
555 void RestoreElementAndArrayBuffers(bool restore
);
556 void RestoreArrayBuffer(bool restrore
);
558 // The pixels pointer should already account for unpack skip
559 // images/rows/pixels.
560 void TexSubImage2DImpl(
561 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLsizei width
,
562 GLsizei height
, GLenum format
, GLenum type
, uint32 unpadded_row_size
,
563 const void* pixels
, uint32 pixels_padded_row_size
, GLboolean internal
,
564 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
565 void TexSubImage3DImpl(
566 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLint zoffset
,
567 GLsizei width
, GLsizei height
, GLsizei depth
, GLenum format
, GLenum type
,
568 uint32 unpadded_row_size
, const void* pixels
,
569 uint32 pixels_padded_row_size
, GLboolean internal
,
570 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
572 // Helpers for query functions.
573 bool GetHelper(GLenum pname
, GLint
* params
);
574 GLuint
GetBoundBufferHelper(GLenum target
);
575 bool GetBooleanvHelper(GLenum pname
, GLboolean
* params
);
576 bool GetBufferParameteri64vHelper(
577 GLenum target
, GLenum pname
, GLint64
* 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 GetInteger64vHelper(GLenum pname
, GLint64
* params
);
583 bool GetIntegervHelper(GLenum pname
, GLint
* params
);
584 bool GetIntegeri_vHelper(GLenum pname
, GLuint index
, GLint
* data
);
585 bool GetInteger64i_vHelper(GLenum pname
, GLuint index
, GLint64
* data
);
586 bool GetInternalformativHelper(
587 GLenum target
, GLenum format
, GLenum pname
, GLsizei bufSize
,
589 bool GetProgramivHelper(GLuint program
, GLenum pname
, GLint
* params
);
590 bool GetSamplerParameterfvHelper(
591 GLuint sampler
, GLenum pname
, GLfloat
* params
);
592 bool GetSamplerParameterivHelper(
593 GLuint sampler
, GLenum pname
, GLint
* params
);
594 bool GetRenderbufferParameterivHelper(
595 GLenum target
, GLenum pname
, GLint
* params
);
596 bool GetShaderivHelper(GLuint shader
, GLenum pname
, GLint
* params
);
597 bool GetTexParameterfvHelper(GLenum target
, GLenum pname
, GLfloat
* params
);
598 bool GetTexParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
599 const GLubyte
* GetStringHelper(GLenum name
);
601 bool IsExtensionAvailable(const char* ext
);
603 // Caches certain capabilties state. Return true if cached.
604 bool SetCapabilityState(GLenum cap
, bool enabled
);
606 IdHandlerInterface
* GetIdHandler(int id_namespace
) const;
607 RangeIdHandlerInterface
* GetRangeIdHandler(int id_namespace
) const;
608 // IdAllocators for objects that can't be shared among contexts.
609 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
610 // Framebuffer and Vertex array objects.
611 IdAllocator
* GetIdAllocator(int id_namespace
) const;
616 void RunIfContextNotLost(const base::Closure
& callback
);
618 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
619 // If not, generate an approriate error, and return false.
620 bool ValidateOffset(const char* func
, GLintptr offset
);
622 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
623 // If not, generate an approriate error, and return false.
624 bool ValidateSize(const char* func
, GLsizeiptr offset
);
626 // Remove the transfer buffer from the buffer tracker. For buffers used
627 // asynchronously the memory is free:ed if the upload has completed. For
628 // other buffers, the memory is either free:ed immediately or free:ed pending
630 void RemoveTransferBuffer(BufferTracker::Buffer
* buffer
);
632 bool GetBoundPixelTransferBuffer(
633 GLenum target
, const char* function_name
, GLuint
* buffer_id
);
634 BufferTracker::Buffer
* GetBoundPixelUnpackTransferBufferIfValid(
636 const char* function_name
, GLuint offset
, GLsizei size
);
638 // Pack 2D arrays of char into a bucket.
639 // Helper function for ShaderSource(), TransformFeedbackVaryings(), etc.
640 bool PackStringsToBucket(GLsizei count
,
641 const char* const* str
,
643 const char* func_name
);
645 const std::string
& GetLogPrefix() const;
647 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
649 void FailGLError(GLenum error
);
651 void CheckGLError() { }
652 void FailGLError(GLenum
/* error */) { }
655 void RemoveMappedBufferRangeByTarget(GLenum target
);
656 void RemoveMappedBufferRangeById(GLuint buffer
);
657 void ClearMappedBufferRangeMap();
659 void DrawElementsImpl(GLenum mode
, GLsizei count
, GLenum type
,
660 const void* indices
, const char* func_name
);
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 row length as last set by glPixelStorei
685 GLint unpack_row_length_
;
687 // unpack image height as last set by glPixelStorei
688 GLint unpack_image_height_
;
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 // unpack skip images as last set by glPixelStorei
697 GLint unpack_skip_images_
;
699 // pack reverse row order as last set by glPixelstorei
700 bool pack_reverse_row_order_
;
702 scoped_ptr
<TextureUnit
[]> texture_units_
;
704 // 0 to gl_state_.max_combined_texture_image_units.
705 GLuint active_texture_unit_
;
707 GLuint bound_framebuffer_
;
708 GLuint bound_read_framebuffer_
;
709 GLuint bound_renderbuffer_
;
710 GLuint bound_valuebuffer_
;
712 // The program in use by glUseProgram
713 GLuint current_program_
;
715 GLuint bound_array_buffer_
;
716 GLuint bound_copy_read_buffer_
;
717 GLuint bound_copy_write_buffer_
;
718 GLuint bound_pixel_pack_buffer_
;
719 GLuint bound_pixel_unpack_buffer_
;
720 GLuint bound_transform_feedback_buffer_
;
721 GLuint bound_uniform_buffer_
;
723 // The currently bound pixel transfer buffers.
724 GLuint bound_pixel_pack_transfer_buffer_id_
;
725 GLuint bound_pixel_unpack_transfer_buffer_id_
;
727 // Client side management for vertex array objects. Needed to correctly
728 // track client side arrays.
729 scoped_ptr
<VertexArrayObjectManager
> vertex_array_object_manager_
;
731 GLuint reserved_ids_
[2];
733 // Current GL error bits.
736 // Whether or not to print debugging info.
739 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
740 const bool lose_context_when_out_of_memory_
;
742 // Whether or not to support client side arrays.
743 const bool support_client_side_arrays_
;
745 // Used to check for single threaded access.
748 // Map of GLenum to Strings for glGetString. We need to cache these because
749 // the pointer passed back to the client has to remain valid for eternity.
750 typedef std::map
<uint32
, std::set
<std::string
> > GLStringMap
;
751 GLStringMap gl_strings_
;
753 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
754 // have an enum for this so handle it separately.
755 std::set
<std::string
> requestable_extensions_set_
;
757 typedef std::map
<const void*, MappedBuffer
> MappedBufferMap
;
758 MappedBufferMap mapped_buffers_
;
760 // TODO(zmo): Consolidate |mapped_buffers_| and |mapped_buffer_range_map_|.
761 typedef base::hash_map
<GLuint
, MappedBuffer
> MappedBufferRangeMap
;
762 MappedBufferRangeMap mapped_buffer_range_map_
;
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 scoped_ptr
<IdAllocator
> query_id_allocator_
;
775 scoped_ptr
<BufferTracker
> buffer_tracker_
;
777 GLES2ImplementationErrorMessageCallback
* error_message_callback_
;
779 int current_trace_stack_
;
781 GpuControl
* gpu_control_
;
783 Capabilities capabilities_
;
785 // Flag to indicate whether the implementation can retain resources, or
786 // whether it should aggressively free them.
787 bool aggressively_free_resources_
;
789 base::WeakPtrFactory
<GLES2Implementation
> weak_ptr_factory_
;
791 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation
);
794 inline bool GLES2Implementation::GetBufferParameteri64vHelper(
795 GLenum
/* target */, GLenum
/* pname */, GLint64
* /* params */) {
799 inline bool GLES2Implementation::GetBufferParameterivHelper(
800 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
804 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
806 GLenum
/* attachment */,
808 GLint
* /* params */) {
812 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
813 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
817 inline bool GLES2Implementation::GetShaderivHelper(
818 GLuint
/* shader */, GLenum
/* pname */, GLint
* /* params */) {
822 inline bool GLES2Implementation::GetTexParameterfvHelper(
823 GLenum
/* target */, GLenum
/* pname */, GLfloat
* /* params */) {
827 inline bool GLES2Implementation::GetTexParameterivHelper(
828 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
835 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_