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
;
212 uint64_t ShareGroupTracingGUID() const override
;
214 void GetProgramInfoCHROMIUMHelper(GLuint program
, std::vector
<int8
>* result
);
215 GLint
GetAttribLocationHelper(GLuint program
, const char* name
);
216 GLint
GetUniformLocationHelper(GLuint program
, const char* name
);
217 GLint
GetFragDataLocationHelper(GLuint program
, const char* name
);
218 bool GetActiveAttribHelper(
219 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
220 GLint
* size
, GLenum
* type
, char* name
);
221 bool GetActiveUniformHelper(
222 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
223 GLint
* size
, GLenum
* type
, char* name
);
224 void GetUniformBlocksCHROMIUMHelper(
225 GLuint program
, std::vector
<int8
>* result
);
226 void GetUniformsES3CHROMIUMHelper(
227 GLuint program
, std::vector
<int8
>* result
);
228 GLuint
GetUniformBlockIndexHelper(GLuint program
, const char* name
);
229 bool GetActiveUniformBlockNameHelper(
230 GLuint program
, GLuint index
, GLsizei bufsize
,
231 GLsizei
* length
, char* name
);
232 bool GetActiveUniformBlockivHelper(
233 GLuint program
, GLuint index
, GLenum pname
, GLint
* params
);
234 void GetTransformFeedbackVaryingsCHROMIUMHelper(
235 GLuint program
, std::vector
<int8
>* result
);
236 bool GetTransformFeedbackVaryingHelper(
237 GLuint program
, GLuint index
, GLsizei bufsize
, GLsizei
* length
,
238 GLint
* size
, GLenum
* type
, char* name
);
239 bool GetUniformIndicesHelper(
240 GLuint program
, GLsizei count
, const char* const* names
, GLuint
* indices
);
241 bool GetActiveUniformsivHelper(
242 GLuint program
, GLsizei count
, const GLuint
* indices
,
243 GLenum pname
, GLint
* params
);
244 bool GetSyncivHelper(
245 GLsync sync
, GLenum pname
, GLsizei bufsize
, GLsizei
* length
,
247 bool GetQueryObjectValueHelper(
248 const char* function_name
, GLuint id
, GLenum pname
, GLuint64
* params
);
250 void FreeUnusedSharedMemory();
251 void FreeEverything();
253 // ContextSupport implementation.
254 void SignalSyncPoint(uint32 sync_point
,
255 const base::Closure
& callback
) override
;
256 void SignalQuery(uint32 query
, const base::Closure
& callback
) override
;
257 void SetSurfaceVisible(bool visible
) override
;
258 void SetAggressivelyFreeResources(bool aggressively_free_resources
) override
;
260 // base::trace_event::MemoryDumpProvider implementation.
261 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs
& args
,
262 base::trace_event::ProcessMemoryDump
* pmd
) override
;
264 void SetErrorMessageCallback(
265 GLES2ImplementationErrorMessageCallback
* callback
) {
266 error_message_callback_
= callback
;
269 ShareGroup
* share_group() const {
270 return share_group_
.get();
273 const Capabilities
& capabilities() const {
274 return capabilities_
;
277 GpuControl
* gpu_control() {
281 ShareGroupContextData
* share_group_context_data() {
282 return &share_group_context_data_
;
286 friend class GLES2ImplementationTest
;
287 friend class VertexArrayObjectManager
;
288 friend class QueryTracker
;
290 // Used to track whether an extension is available
291 enum ExtensionStatus
{
292 kAvailableExtensionStatus
,
293 kUnavailableExtensionStatus
,
294 kUnknownExtensionStatus
297 // Base class for mapped resources.
298 struct MappedResource
{
299 MappedResource(GLenum _access
, int _shm_id
, void* mem
, unsigned int offset
)
306 // access mode. Currently only GL_WRITE_ONLY is valid
309 // Shared memory ID for buffer.
312 // Address of shared memory
315 // Offset of shared memory
316 unsigned int shm_offset
;
319 // Used to track mapped textures.
320 struct MappedTexture
: public MappedResource
{
325 unsigned int shm_offset
,
334 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
345 // These match the arguments to TexSubImage2D.
356 // Used to track mapped buffers.
357 struct MappedBuffer
: public MappedResource
{
362 unsigned int shm_offset
,
366 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
372 // These match the arguments to BufferSubData.
380 : bound_texture_2d(0),
381 bound_texture_cube_map(0),
382 bound_texture_external_oes(0) {}
384 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
385 GLuint bound_texture_2d
;
387 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
389 GLuint bound_texture_cube_map
;
391 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
393 GLuint bound_texture_external_oes
;
396 // Checks for single threaded access.
397 class SingleThreadChecker
{
399 explicit SingleThreadChecker(GLES2Implementation
* gles2_implementation
);
400 ~SingleThreadChecker();
403 GLES2Implementation
* gles2_implementation_
;
406 // Gets the value of the result.
407 template <typename T
>
409 return static_cast<T
>(GetResultBuffer());
412 void* GetResultBuffer();
413 int32
GetResultShmId();
414 uint32
GetResultShmOffset();
416 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
417 bool IsAnglePackReverseRowOrderAvailable();
418 bool IsChromiumFramebufferMultisampleAvailable();
420 bool IsExtensionAvailableHelper(
421 const char* extension
, ExtensionStatus
* status
);
423 // Gets the GLError through our wrapper.
426 // Sets our wrapper for the GLError.
427 void SetGLError(GLenum error
, const char* function_name
, const char* msg
);
428 void SetGLErrorInvalidEnum(
429 const char* function_name
, GLenum value
, const char* label
);
431 // Returns the last error and clears it. Useful for debugging.
432 const std::string
& GetLastError() {
436 // Waits for all commands to execute.
439 // TODO(gman): These bucket functions really seem like they belong in
440 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
441 // a transfer buffer to function which is currently managed by this class.
443 // Gets the contents of a bucket.
444 bool GetBucketContents(uint32 bucket_id
, std::vector
<int8
>* data
);
446 // Sets the contents of a bucket.
447 void SetBucketContents(uint32 bucket_id
, const void* data
, size_t size
);
449 // Sets the contents of a bucket as a string.
450 void SetBucketAsCString(uint32 bucket_id
, const char* str
);
452 // Gets the contents of a bucket as a string. Returns false if there is no
453 // string available which is a separate case from the empty string.
454 bool GetBucketAsString(uint32 bucket_id
, std::string
* str
);
456 // Sets the contents of a bucket as a string.
457 void SetBucketAsString(uint32 bucket_id
, const std::string
& str
);
459 // Returns true if id is reserved.
460 bool IsBufferReservedId(GLuint id
);
461 bool IsFramebufferReservedId(GLuint id
) { return false; }
462 bool IsRenderbufferReservedId(GLuint id
) { return false; }
463 bool IsTextureReservedId(GLuint id
) { return false; }
464 bool IsVertexArrayReservedId(GLuint id
) { return false; }
465 bool IsProgramReservedId(GLuint id
) { return false; }
466 bool IsValuebufferReservedId(GLuint id
) { return false; }
467 bool IsSamplerReservedId(GLuint id
) { return false; }
468 bool IsTransformFeedbackReservedId(GLuint id
) { return false; }
470 void BindBufferHelper(GLenum target
, GLuint buffer
);
471 void BindBufferBaseHelper(GLenum target
, GLuint index
, GLuint buffer
);
472 void BindBufferRangeHelper(GLenum target
, GLuint index
, GLuint buffer
,
473 GLintptr offset
, GLsizeiptr size
);
474 void BindFramebufferHelper(GLenum target
, GLuint framebuffer
);
475 void BindRenderbufferHelper(GLenum target
, GLuint renderbuffer
);
476 void BindSamplerHelper(GLuint unit
, GLuint sampler
);
477 void BindTextureHelper(GLenum target
, GLuint texture
);
478 void BindTransformFeedbackHelper(GLenum target
, GLuint transformfeedback
);
479 void BindVertexArrayOESHelper(GLuint array
);
480 void BindValuebufferCHROMIUMHelper(GLenum target
, GLuint valuebuffer
);
481 void UseProgramHelper(GLuint program
);
483 void BindBufferStub(GLenum target
, GLuint buffer
);
484 void BindBufferBaseStub(GLenum target
, GLuint index
, GLuint buffer
);
485 void BindBufferRangeStub(GLenum target
, GLuint index
, GLuint buffer
,
486 GLintptr offset
, GLsizeiptr size
);
487 void BindFramebufferStub(GLenum target
, GLuint framebuffer
);
488 void BindRenderbufferStub(GLenum target
, GLuint renderbuffer
);
489 void BindTextureStub(GLenum target
, GLuint texture
);
490 void BindValuebufferCHROMIUMStub(GLenum target
, GLuint valuebuffer
);
492 void GenBuffersHelper(GLsizei n
, const GLuint
* buffers
);
493 void GenFramebuffersHelper(GLsizei n
, const GLuint
* framebuffers
);
494 void GenRenderbuffersHelper(GLsizei n
, const GLuint
* renderbuffers
);
495 void GenTexturesHelper(GLsizei n
, const GLuint
* textures
);
496 void GenVertexArraysOESHelper(GLsizei n
, const GLuint
* arrays
);
497 void GenQueriesEXTHelper(GLsizei n
, const GLuint
* queries
);
498 void GenValuebuffersCHROMIUMHelper(GLsizei n
, const GLuint
* valuebuffers
);
499 void GenSamplersHelper(GLsizei n
, const GLuint
* samplers
);
500 void GenTransformFeedbacksHelper(GLsizei n
, const GLuint
* transformfeedbacks
);
502 void DeleteBuffersHelper(GLsizei n
, const GLuint
* buffers
);
503 void DeleteFramebuffersHelper(GLsizei n
, const GLuint
* framebuffers
);
504 void DeleteRenderbuffersHelper(GLsizei n
, const GLuint
* renderbuffers
);
505 void DeleteTexturesHelper(GLsizei n
, const GLuint
* textures
);
506 bool DeleteProgramHelper(GLuint program
);
507 bool DeleteShaderHelper(GLuint shader
);
508 void DeleteQueriesEXTHelper(GLsizei n
, const GLuint
* queries
);
509 void DeleteVertexArraysOESHelper(GLsizei n
, const GLuint
* arrays
);
510 void DeleteValuebuffersCHROMIUMHelper(GLsizei n
, const GLuint
* valuebuffers
);
511 void DeleteSamplersHelper(GLsizei n
, const GLuint
* samplers
);
512 void DeleteTransformFeedbacksHelper(
513 GLsizei n
, const GLuint
* transformfeedbacks
);
514 void DeleteSyncHelper(GLsync sync
);
516 void DeleteBuffersStub(GLsizei n
, const GLuint
* buffers
);
517 void DeleteFramebuffersStub(GLsizei n
, const GLuint
* framebuffers
);
518 void DeleteRenderbuffersStub(GLsizei n
, const GLuint
* renderbuffers
);
519 void DeleteTexturesStub(GLsizei n
, const GLuint
* textures
);
520 void DeletePathsCHROMIUMStub(GLuint first_client_id
, GLsizei range
);
521 void DeleteProgramStub(GLsizei n
, const GLuint
* programs
);
522 void DeleteShaderStub(GLsizei n
, const GLuint
* shaders
);
523 void DeleteVertexArraysOESStub(GLsizei n
, const GLuint
* arrays
);
524 void DeleteValuebuffersCHROMIUMStub(GLsizei n
, const GLuint
* valuebuffers
);
525 void DeleteSamplersStub(GLsizei n
, const GLuint
* samplers
);
526 void DeleteTransformFeedbacksStub(
527 GLsizei n
, const GLuint
* transformfeedbacks
);
528 void DeleteSyncStub(GLsizei n
, const GLuint
* syncs
);
530 void BufferDataHelper(
531 GLenum target
, GLsizeiptr size
, const void* data
, GLenum usage
);
532 void BufferSubDataHelper(
533 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
);
534 void BufferSubDataHelperImpl(
535 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
,
536 ScopedTransferBufferPtr
* buffer
);
538 GLuint
CreateImageCHROMIUMHelper(ClientBuffer buffer
,
541 GLenum internalformat
);
542 void DestroyImageCHROMIUMHelper(GLuint image_id
);
543 GLuint
CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width
,
545 GLenum internalformat
,
548 // Helper for GetVertexAttrib
549 bool GetVertexAttribHelper(GLuint index
, GLenum pname
, uint32
* param
);
551 GLuint
GetMaxValueInBufferCHROMIUMHelper(
552 GLuint buffer_id
, GLsizei count
, GLenum type
, GLuint offset
);
554 void WaitAllAsyncTexImage2DCHROMIUMHelper();
556 void RestoreElementAndArrayBuffers(bool restore
);
557 void RestoreArrayBuffer(bool restrore
);
559 // The pixels pointer should already account for unpack skip
560 // images/rows/pixels.
561 void TexSubImage2DImpl(
562 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLsizei width
,
563 GLsizei height
, GLenum format
, GLenum type
, uint32 unpadded_row_size
,
564 const void* pixels
, uint32 pixels_padded_row_size
, GLboolean internal
,
565 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
566 void TexSubImage3DImpl(
567 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLint zoffset
,
568 GLsizei width
, GLsizei height
, GLsizei depth
, GLenum format
, GLenum type
,
569 uint32 unpadded_row_size
, const void* pixels
,
570 uint32 pixels_padded_row_size
, GLboolean internal
,
571 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
573 // Helpers for query functions.
574 bool GetHelper(GLenum pname
, GLint
* params
);
575 GLuint
GetBoundBufferHelper(GLenum target
);
576 bool GetBooleanvHelper(GLenum pname
, GLboolean
* params
);
577 bool GetBufferParameteri64vHelper(
578 GLenum target
, GLenum pname
, GLint64
* params
);
579 bool GetBufferParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
580 bool GetFloatvHelper(GLenum pname
, GLfloat
* params
);
581 bool GetFramebufferAttachmentParameterivHelper(
582 GLenum target
, GLenum attachment
, GLenum pname
, GLint
* params
);
583 bool GetInteger64vHelper(GLenum pname
, GLint64
* params
);
584 bool GetIntegervHelper(GLenum pname
, GLint
* params
);
585 bool GetIntegeri_vHelper(GLenum pname
, GLuint index
, GLint
* data
);
586 bool GetInteger64i_vHelper(GLenum pname
, GLuint index
, GLint64
* data
);
587 bool GetInternalformativHelper(
588 GLenum target
, GLenum format
, GLenum pname
, GLsizei bufSize
,
590 bool GetProgramivHelper(GLuint program
, GLenum pname
, GLint
* params
);
591 bool GetSamplerParameterfvHelper(
592 GLuint sampler
, GLenum pname
, GLfloat
* params
);
593 bool GetSamplerParameterivHelper(
594 GLuint sampler
, GLenum pname
, GLint
* params
);
595 bool GetRenderbufferParameterivHelper(
596 GLenum target
, GLenum pname
, GLint
* params
);
597 bool GetShaderivHelper(GLuint shader
, GLenum pname
, GLint
* params
);
598 bool GetTexParameterfvHelper(GLenum target
, GLenum pname
, GLfloat
* params
);
599 bool GetTexParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
600 const GLubyte
* GetStringHelper(GLenum name
);
602 bool IsExtensionAvailable(const char* ext
);
604 // Caches certain capabilties state. Return true if cached.
605 bool SetCapabilityState(GLenum cap
, bool enabled
);
607 IdHandlerInterface
* GetIdHandler(int id_namespace
) const;
608 RangeIdHandlerInterface
* GetRangeIdHandler(int id_namespace
) const;
609 // IdAllocators for objects that can't be shared among contexts.
610 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
611 // Framebuffer and Vertex array objects.
612 IdAllocator
* GetIdAllocator(int id_namespace
) const;
617 void RunIfContextNotLost(const base::Closure
& callback
);
619 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
620 // If not, generate an approriate error, and return false.
621 bool ValidateOffset(const char* func
, GLintptr offset
);
623 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
624 // If not, generate an approriate error, and return false.
625 bool ValidateSize(const char* func
, GLsizeiptr offset
);
627 // Remove the transfer buffer from the buffer tracker. For buffers used
628 // asynchronously the memory is free:ed if the upload has completed. For
629 // other buffers, the memory is either free:ed immediately or free:ed pending
631 void RemoveTransferBuffer(BufferTracker::Buffer
* buffer
);
633 bool GetBoundPixelTransferBuffer(
634 GLenum target
, const char* function_name
, GLuint
* buffer_id
);
635 BufferTracker::Buffer
* GetBoundPixelUnpackTransferBufferIfValid(
637 const char* function_name
, GLuint offset
, GLsizei size
);
639 // Pack 2D arrays of char into a bucket.
640 // Helper function for ShaderSource(), TransformFeedbackVaryings(), etc.
641 bool PackStringsToBucket(GLsizei count
,
642 const char* const* str
,
644 const char* func_name
);
646 const std::string
& GetLogPrefix() const;
648 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
650 void FailGLError(GLenum error
);
652 void CheckGLError() { }
653 void FailGLError(GLenum
/* error */) { }
656 void RemoveMappedBufferRangeByTarget(GLenum target
);
657 void RemoveMappedBufferRangeById(GLuint buffer
);
658 void ClearMappedBufferRangeMap();
660 void DrawElementsImpl(GLenum mode
, GLsizei count
, GLenum type
,
661 const void* indices
, const char* func_name
);
664 GLES2CmdHelper
* helper_
;
665 TransferBufferInterface
* transfer_buffer_
;
666 std::string last_error_
;
667 DebugMarkerManager debug_marker_manager_
;
668 std::string this_in_hex_
;
670 std::queue
<int32
> swap_buffers_tokens_
;
671 std::queue
<int32
> rate_limit_tokens_
;
673 ExtensionStatus angle_pack_reverse_row_order_status_
;
674 ExtensionStatus chromium_framebuffer_multisample_
;
676 GLStaticState static_state_
;
677 ClientContextState state_
;
679 // pack alignment as last set by glPixelStorei
680 GLint pack_alignment_
;
682 // unpack alignment as last set by glPixelStorei
683 GLint unpack_alignment_
;
685 // unpack row length as last set by glPixelStorei
686 GLint unpack_row_length_
;
688 // unpack image height as last set by glPixelStorei
689 GLint unpack_image_height_
;
691 // unpack skip rows as last set by glPixelStorei
692 GLint unpack_skip_rows_
;
694 // unpack skip pixels as last set by glPixelStorei
695 GLint unpack_skip_pixels_
;
697 // unpack skip images as last set by glPixelStorei
698 GLint unpack_skip_images_
;
700 // pack reverse row order as last set by glPixelstorei
701 bool pack_reverse_row_order_
;
703 scoped_ptr
<TextureUnit
[]> texture_units_
;
705 // 0 to gl_state_.max_combined_texture_image_units.
706 GLuint active_texture_unit_
;
708 GLuint bound_framebuffer_
;
709 GLuint bound_read_framebuffer_
;
710 GLuint bound_renderbuffer_
;
711 GLuint bound_valuebuffer_
;
713 // The program in use by glUseProgram
714 GLuint current_program_
;
716 GLuint bound_array_buffer_
;
717 GLuint bound_copy_read_buffer_
;
718 GLuint bound_copy_write_buffer_
;
719 GLuint bound_pixel_pack_buffer_
;
720 GLuint bound_pixel_unpack_buffer_
;
721 GLuint bound_transform_feedback_buffer_
;
722 GLuint bound_uniform_buffer_
;
724 // The currently bound pixel transfer buffers.
725 GLuint bound_pixel_pack_transfer_buffer_id_
;
726 GLuint bound_pixel_unpack_transfer_buffer_id_
;
728 // Client side management for vertex array objects. Needed to correctly
729 // track client side arrays.
730 scoped_ptr
<VertexArrayObjectManager
> vertex_array_object_manager_
;
732 GLuint reserved_ids_
[2];
734 // Current GL error bits.
737 // Whether or not to print debugging info.
740 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
741 const bool lose_context_when_out_of_memory_
;
743 // Whether or not to support client side arrays.
744 const bool support_client_side_arrays_
;
746 // Used to check for single threaded access.
749 // Map of GLenum to Strings for glGetString. We need to cache these because
750 // the pointer passed back to the client has to remain valid for eternity.
751 typedef std::map
<uint32
, std::set
<std::string
> > GLStringMap
;
752 GLStringMap gl_strings_
;
754 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
755 // have an enum for this so handle it separately.
756 std::set
<std::string
> requestable_extensions_set_
;
758 typedef std::map
<const void*, MappedBuffer
> MappedBufferMap
;
759 MappedBufferMap mapped_buffers_
;
761 // TODO(zmo): Consolidate |mapped_buffers_| and |mapped_buffer_range_map_|.
762 typedef base::hash_map
<GLuint
, MappedBuffer
> MappedBufferRangeMap
;
763 MappedBufferRangeMap mapped_buffer_range_map_
;
765 typedef std::map
<const void*, MappedTexture
> MappedTextureMap
;
766 MappedTextureMap mapped_textures_
;
768 scoped_ptr
<MappedMemoryManager
> mapped_memory_
;
770 scoped_refptr
<ShareGroup
> share_group_
;
771 ShareGroupContextData share_group_context_data_
;
773 scoped_ptr
<QueryTracker
> query_tracker_
;
774 scoped_ptr
<IdAllocator
> query_id_allocator_
;
776 scoped_ptr
<BufferTracker
> buffer_tracker_
;
778 GLES2ImplementationErrorMessageCallback
* error_message_callback_
;
780 int current_trace_stack_
;
782 GpuControl
* gpu_control_
;
784 Capabilities capabilities_
;
786 // Flag to indicate whether the implementation can retain resources, or
787 // whether it should aggressively free them.
788 bool aggressively_free_resources_
;
790 base::WeakPtrFactory
<GLES2Implementation
> weak_ptr_factory_
;
792 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation
);
795 inline bool GLES2Implementation::GetBufferParameteri64vHelper(
796 GLenum
/* target */, GLenum
/* pname */, GLint64
* /* params */) {
800 inline bool GLES2Implementation::GetBufferParameterivHelper(
801 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
805 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
807 GLenum
/* attachment */,
809 GLint
* /* params */) {
813 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
814 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
818 inline bool GLES2Implementation::GetShaderivHelper(
819 GLuint
/* shader */, GLenum
/* pname */, GLint
* /* params */) {
823 inline bool GLES2Implementation::GetTexParameterfvHelper(
824 GLenum
/* target */, GLenum
/* pname */, GLfloat
* /* params */) {
828 inline bool GLES2Implementation::GetTexParameterivHelper(
829 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
836 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_