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
;
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
,
247 void FreeUnusedSharedMemory();
248 void FreeEverything();
250 // ContextSupport implementation.
251 void SignalSyncPoint(uint32 sync_point
,
252 const base::Closure
& callback
) override
;
253 void SignalQuery(uint32 query
, const base::Closure
& callback
) override
;
254 void SetSurfaceVisible(bool visible
) override
;
256 void SetErrorMessageCallback(
257 GLES2ImplementationErrorMessageCallback
* callback
) {
258 error_message_callback_
= callback
;
261 ShareGroup
* share_group() const {
262 return share_group_
.get();
265 const Capabilities
& capabilities() const {
266 return capabilities_
;
269 GpuControl
* gpu_control() {
273 ShareGroupContextData
* share_group_context_data() {
274 return &share_group_context_data_
;
278 friend class GLES2ImplementationTest
;
279 friend class VertexArrayObjectManager
;
281 // Used to track whether an extension is available
282 enum ExtensionStatus
{
283 kAvailableExtensionStatus
,
284 kUnavailableExtensionStatus
,
285 kUnknownExtensionStatus
288 // Base class for mapped resources.
289 struct MappedResource
{
290 MappedResource(GLenum _access
, int _shm_id
, void* mem
, unsigned int offset
)
297 // access mode. Currently only GL_WRITE_ONLY is valid
300 // Shared memory ID for buffer.
303 // Address of shared memory
306 // Offset of shared memory
307 unsigned int shm_offset
;
310 // Used to track mapped textures.
311 struct MappedTexture
: public MappedResource
{
316 unsigned int shm_offset
,
325 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
336 // These match the arguments to TexSubImage2D.
347 // Used to track mapped buffers.
348 struct MappedBuffer
: public MappedResource
{
353 unsigned int shm_offset
,
357 : MappedResource(access
, shm_id
, shm_mem
, shm_offset
),
363 // These match the arguments to BufferSubData.
371 : bound_texture_2d(0),
372 bound_texture_cube_map(0),
373 bound_texture_external_oes(0) {}
375 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
376 GLuint bound_texture_2d
;
378 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
380 GLuint bound_texture_cube_map
;
382 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
384 GLuint bound_texture_external_oes
;
387 // Checks for single threaded access.
388 class SingleThreadChecker
{
390 explicit SingleThreadChecker(GLES2Implementation
* gles2_implementation
);
391 ~SingleThreadChecker();
394 GLES2Implementation
* gles2_implementation_
;
397 // Gets the value of the result.
398 template <typename T
>
400 return static_cast<T
>(GetResultBuffer());
403 void* GetResultBuffer();
404 int32
GetResultShmId();
405 uint32
GetResultShmOffset();
407 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
408 bool IsAnglePackReverseRowOrderAvailable();
409 bool IsChromiumFramebufferMultisampleAvailable();
411 bool IsExtensionAvailableHelper(
412 const char* extension
, ExtensionStatus
* status
);
414 // Gets the GLError through our wrapper.
417 // Sets our wrapper for the GLError.
418 void SetGLError(GLenum error
, const char* function_name
, const char* msg
);
419 void SetGLErrorInvalidEnum(
420 const char* function_name
, GLenum value
, const char* label
);
422 // Returns the last error and clears it. Useful for debugging.
423 const std::string
& GetLastError() {
427 // Waits for all commands to execute.
430 // TODO(gman): These bucket functions really seem like they belong in
431 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
432 // a transfer buffer to function which is currently managed by this class.
434 // Gets the contents of a bucket.
435 bool GetBucketContents(uint32 bucket_id
, std::vector
<int8
>* data
);
437 // Sets the contents of a bucket.
438 void SetBucketContents(uint32 bucket_id
, const void* data
, size_t size
);
440 // Sets the contents of a bucket as a string.
441 void SetBucketAsCString(uint32 bucket_id
, const char* str
);
443 // Gets the contents of a bucket as a string. Returns false if there is no
444 // string available which is a separate case from the empty string.
445 bool GetBucketAsString(uint32 bucket_id
, std::string
* str
);
447 // Sets the contents of a bucket as a string.
448 void SetBucketAsString(uint32 bucket_id
, const std::string
& str
);
450 // Returns true if id is reserved.
451 bool IsBufferReservedId(GLuint id
);
452 bool IsFramebufferReservedId(GLuint id
) { return false; }
453 bool IsRenderbufferReservedId(GLuint id
) { return false; }
454 bool IsTextureReservedId(GLuint id
) { return false; }
455 bool IsVertexArrayReservedId(GLuint id
) { return false; }
456 bool IsProgramReservedId(GLuint id
) { return false; }
457 bool IsValuebufferReservedId(GLuint id
) { return false; }
458 bool IsSamplerReservedId(GLuint id
) { return false; }
459 bool IsTransformFeedbackReservedId(GLuint id
) { return false; }
461 void BindBufferHelper(GLenum target
, GLuint buffer
);
462 void BindBufferBaseHelper(GLenum target
, GLuint index
, GLuint buffer
);
463 void BindBufferRangeHelper(GLenum target
, GLuint index
, GLuint buffer
,
464 GLintptr offset
, GLsizeiptr size
);
465 void BindFramebufferHelper(GLenum target
, GLuint framebuffer
);
466 void BindRenderbufferHelper(GLenum target
, GLuint renderbuffer
);
467 void BindSamplerHelper(GLuint unit
, GLuint sampler
);
468 void BindTextureHelper(GLenum target
, GLuint texture
);
469 void BindTransformFeedbackHelper(GLenum target
, GLuint transformfeedback
);
470 void BindVertexArrayOESHelper(GLuint array
);
471 void BindValuebufferCHROMIUMHelper(GLenum target
, GLuint valuebuffer
);
472 void UseProgramHelper(GLuint program
);
474 void BindBufferStub(GLenum target
, GLuint buffer
);
475 void BindBufferBaseStub(GLenum target
, GLuint index
, GLuint buffer
);
476 void BindBufferRangeStub(GLenum target
, GLuint index
, GLuint buffer
,
477 GLintptr offset
, GLsizeiptr size
);
478 void BindFramebufferStub(GLenum target
, GLuint framebuffer
);
479 void BindRenderbufferStub(GLenum target
, GLuint renderbuffer
);
480 void BindTextureStub(GLenum target
, GLuint texture
);
481 void BindValuebufferCHROMIUMStub(GLenum target
, GLuint valuebuffer
);
483 void GenBuffersHelper(GLsizei n
, const GLuint
* buffers
);
484 void GenFramebuffersHelper(GLsizei n
, const GLuint
* framebuffers
);
485 void GenRenderbuffersHelper(GLsizei n
, const GLuint
* renderbuffers
);
486 void GenTexturesHelper(GLsizei n
, const GLuint
* textures
);
487 void GenVertexArraysOESHelper(GLsizei n
, const GLuint
* arrays
);
488 void GenQueriesEXTHelper(GLsizei n
, const GLuint
* queries
);
489 void GenValuebuffersCHROMIUMHelper(GLsizei n
, const GLuint
* valuebuffers
);
490 void GenSamplersHelper(GLsizei n
, const GLuint
* samplers
);
491 void GenTransformFeedbacksHelper(GLsizei n
, const GLuint
* transformfeedbacks
);
493 void DeleteBuffersHelper(GLsizei n
, const GLuint
* buffers
);
494 void DeleteFramebuffersHelper(GLsizei n
, const GLuint
* framebuffers
);
495 void DeleteRenderbuffersHelper(GLsizei n
, const GLuint
* renderbuffers
);
496 void DeleteTexturesHelper(GLsizei n
, const GLuint
* textures
);
497 bool DeleteProgramHelper(GLuint program
);
498 bool DeleteShaderHelper(GLuint shader
);
499 void DeleteQueriesEXTHelper(GLsizei n
, const GLuint
* queries
);
500 void DeleteVertexArraysOESHelper(GLsizei n
, const GLuint
* arrays
);
501 void DeleteValuebuffersCHROMIUMHelper(GLsizei n
, const GLuint
* valuebuffers
);
502 void DeleteSamplersHelper(GLsizei n
, const GLuint
* samplers
);
503 void DeleteTransformFeedbacksHelper(
504 GLsizei n
, const GLuint
* transformfeedbacks
);
505 void DeleteSyncHelper(GLsync sync
);
507 void DeleteBuffersStub(GLsizei n
, const GLuint
* buffers
);
508 void DeleteFramebuffersStub(GLsizei n
, const GLuint
* framebuffers
);
509 void DeleteRenderbuffersStub(GLsizei n
, const GLuint
* renderbuffers
);
510 void DeleteTexturesStub(GLsizei n
, const GLuint
* textures
);
511 void DeleteProgramStub(GLsizei n
, const GLuint
* programs
);
512 void DeleteShaderStub(GLsizei n
, const GLuint
* shaders
);
513 void DeleteVertexArraysOESStub(GLsizei n
, const GLuint
* arrays
);
514 void DeleteValuebuffersCHROMIUMStub(GLsizei n
, const GLuint
* valuebuffers
);
515 void DeleteSamplersStub(GLsizei n
, const GLuint
* samplers
);
516 void DeleteTransformFeedbacksStub(
517 GLsizei n
, const GLuint
* transformfeedbacks
);
518 void DeleteSyncStub(GLsizei n
, const GLuint
* syncs
);
520 void BufferDataHelper(
521 GLenum target
, GLsizeiptr size
, const void* data
, GLenum usage
);
522 void BufferSubDataHelper(
523 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
);
524 void BufferSubDataHelperImpl(
525 GLenum target
, GLintptr offset
, GLsizeiptr size
, const void* data
,
526 ScopedTransferBufferPtr
* buffer
);
528 GLuint
CreateImageCHROMIUMHelper(ClientBuffer buffer
,
531 GLenum internalformat
);
532 void DestroyImageCHROMIUMHelper(GLuint image_id
);
533 GLuint
CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width
,
535 GLenum internalformat
,
538 // Helper for GetVertexAttrib
539 bool GetVertexAttribHelper(GLuint index
, GLenum pname
, uint32
* param
);
541 GLuint
GetMaxValueInBufferCHROMIUMHelper(
542 GLuint buffer_id
, GLsizei count
, GLenum type
, GLuint offset
);
544 void RestoreElementAndArrayBuffers(bool restore
);
545 void RestoreArrayBuffer(bool restrore
);
547 // The pixels pointer should already account for unpack skip
548 // images/rows/pixels.
549 void TexSubImage2DImpl(
550 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLsizei width
,
551 GLsizei height
, GLenum format
, GLenum type
, uint32 unpadded_row_size
,
552 const void* pixels
, uint32 pixels_padded_row_size
, GLboolean internal
,
553 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
554 void TexSubImage3DImpl(
555 GLenum target
, GLint level
, GLint xoffset
, GLint yoffset
, GLint zoffset
,
556 GLsizei width
, GLsizei height
, GLsizei depth
, GLenum format
, GLenum type
,
557 uint32 unpadded_row_size
, const void* pixels
,
558 uint32 pixels_padded_row_size
, GLboolean internal
,
559 ScopedTransferBufferPtr
* buffer
, uint32 buffer_padded_row_size
);
561 // Helpers for query functions.
562 bool GetHelper(GLenum pname
, GLint
* params
);
563 bool GetBooleanvHelper(GLenum pname
, GLboolean
* params
);
564 bool GetBufferParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
565 bool GetFloatvHelper(GLenum pname
, GLfloat
* params
);
566 bool GetFramebufferAttachmentParameterivHelper(
567 GLenum target
, GLenum attachment
, GLenum pname
, GLint
* params
);
568 bool GetIntegervHelper(GLenum pname
, GLint
* params
);
569 bool GetInternalformativHelper(
570 GLenum target
, GLenum format
, GLenum pname
, GLsizei bufSize
,
572 bool GetProgramivHelper(GLuint program
, GLenum pname
, GLint
* params
);
573 bool GetSamplerParameterfvHelper(
574 GLuint sampler
, GLenum pname
, GLfloat
* params
);
575 bool GetSamplerParameterivHelper(
576 GLuint sampler
, GLenum pname
, GLint
* params
);
577 bool GetRenderbufferParameterivHelper(
578 GLenum target
, GLenum pname
, GLint
* params
);
579 bool GetShaderivHelper(GLuint shader
, GLenum pname
, GLint
* params
);
580 bool GetTexParameterfvHelper(GLenum target
, GLenum pname
, GLfloat
* params
);
581 bool GetTexParameterivHelper(GLenum target
, GLenum pname
, GLint
* params
);
582 const GLubyte
* GetStringHelper(GLenum name
);
584 bool IsExtensionAvailable(const char* ext
);
586 // Caches certain capabilties state. Return true if cached.
587 bool SetCapabilityState(GLenum cap
, bool enabled
);
589 IdHandlerInterface
* GetIdHandler(int id_namespace
) const;
590 // IdAllocators for objects that can't be shared among contexts.
591 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
592 // Framebuffer and Vertex array objects.
593 IdAllocator
* GetIdAllocator(int id_namespace
) const;
597 void RunIfContextNotLost(const base::Closure
& callback
);
599 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
600 // If not, generate an approriate error, and return false.
601 bool ValidateOffset(const char* func
, GLintptr offset
);
603 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
604 // If not, generate an approriate error, and return false.
605 bool ValidateSize(const char* func
, GLsizeiptr offset
);
607 // Remove the transfer buffer from the buffer tracker. For buffers used
608 // asynchronously the memory is free:ed if the upload has completed. For
609 // other buffers, the memory is either free:ed immediately or free:ed pending
611 void RemoveTransferBuffer(BufferTracker::Buffer
* buffer
);
613 // Returns true if the async upload token has passed.
615 // NOTE: This will detect wrapped async tokens by checking if the most
616 // significant bit of async token to check is 1 but the last read is 0, i.e.
617 // the uint32 wrapped.
618 bool HasAsyncUploadTokenPassed(uint32 token
) const {
619 return async_upload_sync_
->HasAsyncUploadTokenPassed(token
);
622 // Get the next async upload token.
623 uint32
NextAsyncUploadToken();
625 // Ensure that the shared memory used for synchronizing async upload tokens
628 // Returns false on error, true on success.
629 bool EnsureAsyncUploadSync();
631 // Checks the last read asynchronously upload token and frees any unmanaged
632 // transfer buffer that has its async token passed.
633 void PollAsyncUploads();
635 // Free every async upload buffer. If some async upload buffer is still in use
636 // wait for them to finish before freeing.
637 void FreeAllAsyncUploadBuffers();
639 bool GetBoundPixelTransferBuffer(
640 GLenum target
, const char* function_name
, GLuint
* buffer_id
);
641 BufferTracker::Buffer
* GetBoundPixelUnpackTransferBufferIfValid(
643 const char* function_name
, GLuint offset
, GLsizei size
);
645 // Pack 2D arrays of char into a bucket.
646 // Helper function for ShaderSource(), TransformFeedbackVaryings(), etc.
647 bool PackStringsToBucket(GLsizei count
,
648 const char* const* str
,
650 const char* func_name
);
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 image height as last set by glPixelStorei
691 GLint unpack_image_height_
;
693 // unpack skip rows as last set by glPixelStorei
694 GLint unpack_skip_rows_
;
696 // unpack skip pixels as last set by glPixelStorei
697 GLint unpack_skip_pixels_
;
699 // unpack skip images as last set by glPixelStorei
700 GLint unpack_skip_images_
;
702 // pack reverse row order as last set by glPixelstorei
703 bool pack_reverse_row_order_
;
705 scoped_ptr
<TextureUnit
[]> texture_units_
;
707 // 0 to gl_state_.max_combined_texture_image_units.
708 GLuint active_texture_unit_
;
710 GLuint bound_framebuffer_
;
711 GLuint bound_read_framebuffer_
;
712 GLuint bound_renderbuffer_
;
713 GLuint bound_valuebuffer_
;
715 // The program in use by glUseProgram
716 GLuint current_program_
;
718 // The currently bound array buffer.
719 GLuint bound_array_buffer_id_
;
721 // The currently bound pixel transfer buffers.
722 GLuint bound_pixel_pack_transfer_buffer_id_
;
723 GLuint bound_pixel_unpack_transfer_buffer_id_
;
725 // The current asynchronous pixel buffer upload token.
726 uint32 async_upload_token_
;
728 // The shared memory used for synchronizing asynchronous upload tokens.
729 AsyncUploadSync
* async_upload_sync_
;
730 int32 async_upload_sync_shm_id_
;
731 unsigned int async_upload_sync_shm_offset_
;
733 // Unmanaged pixel transfer buffer memory pending asynchronous upload token.
734 typedef std::list
<std::pair
<void*, uint32
> > DetachedAsyncUploadMemoryList
;
735 DetachedAsyncUploadMemoryList detached_async_upload_memory_
;
737 // Client side management for vertex array objects. Needed to correctly
738 // track client side arrays.
739 scoped_ptr
<VertexArrayObjectManager
> vertex_array_object_manager_
;
741 GLuint reserved_ids_
[2];
743 // Current GL error bits.
746 // Whether or not to print debugging info.
749 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
750 const bool lose_context_when_out_of_memory_
;
752 // Whether or not to support client side arrays.
753 const bool support_client_side_arrays_
;
755 // Used to check for single threaded access.
758 // Map of GLenum to Strings for glGetString. We need to cache these because
759 // the pointer passed back to the client has to remain valid for eternity.
760 typedef std::map
<uint32
, std::set
<std::string
> > GLStringMap
;
761 GLStringMap gl_strings_
;
763 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
764 // have an enum for this so handle it separately.
765 std::set
<std::string
> requestable_extensions_set_
;
767 typedef std::map
<const void*, MappedBuffer
> MappedBufferMap
;
768 MappedBufferMap mapped_buffers_
;
770 typedef std::map
<const void*, MappedTexture
> MappedTextureMap
;
771 MappedTextureMap mapped_textures_
;
773 scoped_ptr
<MappedMemoryManager
> mapped_memory_
;
775 scoped_refptr
<ShareGroup
> share_group_
;
776 ShareGroupContextData share_group_context_data_
;
778 scoped_ptr
<QueryTracker
> query_tracker_
;
779 typedef std::map
<GLuint
, QueryTracker::Query
*> QueryMap
;
780 QueryMap current_queries_
;
781 scoped_ptr
<IdAllocator
> query_id_allocator_
;
783 scoped_ptr
<BufferTracker
> buffer_tracker_
;
785 GLES2ImplementationErrorMessageCallback
* error_message_callback_
;
787 int current_trace_stack_
;
789 GpuControl
* gpu_control_
;
791 Capabilities capabilities_
;
793 base::WeakPtrFactory
<GLES2Implementation
> weak_ptr_factory_
;
795 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation
);
798 inline bool GLES2Implementation::GetBufferParameterivHelper(
799 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
803 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
805 GLenum
/* attachment */,
807 GLint
* /* params */) {
811 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
812 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
816 inline bool GLES2Implementation::GetShaderivHelper(
817 GLuint
/* shader */, GLenum
/* pname */, GLint
* /* params */) {
821 inline bool GLES2Implementation::GetTexParameterfvHelper(
822 GLenum
/* target */, GLenum
/* pname */, GLfloat
* /* params */) {
826 inline bool GLES2Implementation::GetTexParameterivHelper(
827 GLenum
/* target */, GLenum
/* pname */, GLint
* /* params */) {
834 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_