Fix crash on app list start page keyboard navigation with <4 apps.
[chromium-blink-merge.git] / gpu / command_buffer / client / gles2_implementation.h
blob4e8ae5f998be65e400cffc28d4d2745c95156f56
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_
8 #include <GLES2/gl2.h>
10 #include <list>
11 #include <map>
12 #include <queue>
13 #include <set>
14 #include <string>
15 #include <utility>
16 #include <vector>
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)
44 #else
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
51 #endif
52 #else
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)
57 #endif
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.
62 # if 0
63 # define GL_CLIENT_FAIL_GL_ERRORS
64 # endif
65 #endif
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.
71 // GLsizei len;
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,
76 // not Pepper.
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)
86 #elif defined(DCHECK)
87 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
88 #define GPU_CLIENT_DCHECK(v) DCHECK(v)
89 #else
90 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
91 #define GPU_CLIENT_DCHECK(v) ASSERT(v)
92 #endif
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;
104 namespace gpu {
106 class GpuControl;
107 class ScopedTransferBufferPtr;
108 class TransferBufferInterface;
110 namespace gles2 {
112 class ImageFactory;
113 class VertexArrayObjectManager;
115 class GLES2ImplementationErrorMessageCallback {
116 public:
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) {
130 public:
131 enum MappedMemoryLimit {
132 kNoLimit = MappedMemoryManager::kNoLimit,
135 // Stores GL state that never changes.
136 struct GLES2_IMPL_EXPORT GLStaticState {
137 GLStaticState();
138 ~GLStaticState();
140 typedef std::pair<GLenum, GLenum> ShaderPrecisionKey;
141 typedef std::map<ShaderPrecisionKey,
142 cmds::GetShaderPrecisionFormat::Result>
143 ShaderPrecisionMap;
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;
179 bool Initialize(
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);
244 void FreeUnusedSharedMemory();
245 void FreeEverything();
247 // ContextSupport implementation.
248 void SignalSyncPoint(uint32 sync_point,
249 const base::Closure& callback) override;
250 void SignalQuery(uint32 query, const base::Closure& callback) override;
251 void SetSurfaceVisible(bool visible) override;
253 void SetErrorMessageCallback(
254 GLES2ImplementationErrorMessageCallback* callback) {
255 error_message_callback_ = callback;
258 ShareGroup* share_group() const {
259 return share_group_.get();
262 const Capabilities& capabilities() const {
263 return capabilities_;
266 GpuControl* gpu_control() {
267 return gpu_control_;
270 ShareGroupContextData* share_group_context_data() {
271 return &share_group_context_data_;
274 private:
275 friend class GLES2ImplementationTest;
276 friend class VertexArrayObjectManager;
278 // Used to track whether an extension is available
279 enum ExtensionStatus {
280 kAvailableExtensionStatus,
281 kUnavailableExtensionStatus,
282 kUnknownExtensionStatus
285 // Base class for mapped resources.
286 struct MappedResource {
287 MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset)
288 : access(_access),
289 shm_id(_shm_id),
290 shm_memory(mem),
291 shm_offset(offset) {
294 // access mode. Currently only GL_WRITE_ONLY is valid
295 GLenum access;
297 // Shared memory ID for buffer.
298 int shm_id;
300 // Address of shared memory
301 void* shm_memory;
303 // Offset of shared memory
304 unsigned int shm_offset;
307 // Used to track mapped textures.
308 struct MappedTexture : public MappedResource {
309 MappedTexture(
310 GLenum access,
311 int shm_id,
312 void* shm_mem,
313 unsigned int shm_offset,
314 GLenum _target,
315 GLint _level,
316 GLint _xoffset,
317 GLint _yoffset,
318 GLsizei _width,
319 GLsizei _height,
320 GLenum _format,
321 GLenum _type)
322 : MappedResource(access, shm_id, shm_mem, shm_offset),
323 target(_target),
324 level(_level),
325 xoffset(_xoffset),
326 yoffset(_yoffset),
327 width(_width),
328 height(_height),
329 format(_format),
330 type(_type) {
333 // These match the arguments to TexSubImage2D.
334 GLenum target;
335 GLint level;
336 GLint xoffset;
337 GLint yoffset;
338 GLsizei width;
339 GLsizei height;
340 GLenum format;
341 GLenum type;
344 // Used to track mapped buffers.
345 struct MappedBuffer : public MappedResource {
346 MappedBuffer(
347 GLenum access,
348 int shm_id,
349 void* shm_mem,
350 unsigned int shm_offset,
351 GLenum _target,
352 GLintptr _offset,
353 GLsizeiptr _size)
354 : MappedResource(access, shm_id, shm_mem, shm_offset),
355 target(_target),
356 offset(_offset),
357 size(_size) {
360 // These match the arguments to BufferSubData.
361 GLenum target;
362 GLintptr offset;
363 GLsizeiptr size;
366 struct TextureUnit {
367 TextureUnit()
368 : bound_texture_2d(0),
369 bound_texture_cube_map(0),
370 bound_texture_external_oes(0) {}
372 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
373 GLuint bound_texture_2d;
375 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
376 // glBindTexture
377 GLuint bound_texture_cube_map;
379 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
380 // glBindTexture
381 GLuint bound_texture_external_oes;
384 // Checks for single threaded access.
385 class SingleThreadChecker {
386 public:
387 explicit SingleThreadChecker(GLES2Implementation* gles2_implementation);
388 ~SingleThreadChecker();
390 private:
391 GLES2Implementation* gles2_implementation_;
394 // Gets the value of the result.
395 template <typename T>
396 T GetResultAs() {
397 return static_cast<T>(GetResultBuffer());
400 void* GetResultBuffer();
401 int32 GetResultShmId();
402 uint32 GetResultShmOffset();
404 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
405 bool IsAnglePackReverseRowOrderAvailable();
406 bool IsChromiumFramebufferMultisampleAvailable();
408 bool IsExtensionAvailableHelper(
409 const char* extension, ExtensionStatus* status);
411 // Gets the GLError through our wrapper.
412 GLenum GetGLError();
414 // Sets our wrapper for the GLError.
415 void SetGLError(GLenum error, const char* function_name, const char* msg);
416 void SetGLErrorInvalidEnum(
417 const char* function_name, GLenum value, const char* label);
419 // Returns the last error and clears it. Useful for debugging.
420 const std::string& GetLastError() {
421 return last_error_;
424 // Waits for all commands to execute.
425 void WaitForCmd();
427 // TODO(gman): These bucket functions really seem like they belong in
428 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
429 // a transfer buffer to function which is currently managed by this class.
431 // Gets the contents of a bucket.
432 bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data);
434 // Sets the contents of a bucket.
435 void SetBucketContents(uint32 bucket_id, const void* data, size_t size);
437 // Sets the contents of a bucket as a string.
438 void SetBucketAsCString(uint32 bucket_id, const char* str);
440 // Gets the contents of a bucket as a string. Returns false if there is no
441 // string available which is a separate case from the empty string.
442 bool GetBucketAsString(uint32 bucket_id, std::string* str);
444 // Sets the contents of a bucket as a string.
445 void SetBucketAsString(uint32 bucket_id, const std::string& str);
447 // Returns true if id is reserved.
448 bool IsBufferReservedId(GLuint id);
449 bool IsFramebufferReservedId(GLuint id) { return false; }
450 bool IsRenderbufferReservedId(GLuint id) { return false; }
451 bool IsTextureReservedId(GLuint id) { return false; }
452 bool IsVertexArrayReservedId(GLuint id) { return false; }
453 bool IsProgramReservedId(GLuint id) { return false; }
454 bool IsValuebufferReservedId(GLuint id) { return false; }
455 bool IsSamplerReservedId(GLuint id) { return false; }
456 bool IsTransformFeedbackReservedId(GLuint id) { return false; }
458 void BindBufferHelper(GLenum target, GLuint buffer);
459 void BindBufferBaseHelper(GLenum target, GLuint index, GLuint buffer);
460 void BindBufferRangeHelper(GLenum target, GLuint index, GLuint buffer,
461 GLintptr offset, GLsizeiptr size);
462 void BindFramebufferHelper(GLenum target, GLuint framebuffer);
463 void BindRenderbufferHelper(GLenum target, GLuint renderbuffer);
464 void BindSamplerHelper(GLuint unit, GLuint sampler);
465 void BindTextureHelper(GLenum target, GLuint texture);
466 void BindTransformFeedbackHelper(GLenum target, GLuint transformfeedback);
467 void BindVertexArrayOESHelper(GLuint array);
468 void BindValuebufferCHROMIUMHelper(GLenum target, GLuint valuebuffer);
469 void UseProgramHelper(GLuint program);
471 void BindBufferStub(GLenum target, GLuint buffer);
472 void BindBufferBaseStub(GLenum target, GLuint index, GLuint buffer);
473 void BindBufferRangeStub(GLenum target, GLuint index, GLuint buffer,
474 GLintptr offset, GLsizeiptr size);
475 void BindFramebufferStub(GLenum target, GLuint framebuffer);
476 void BindRenderbufferStub(GLenum target, GLuint renderbuffer);
477 void BindTextureStub(GLenum target, GLuint texture);
478 void BindValuebufferCHROMIUMStub(GLenum target, GLuint valuebuffer);
480 void GenBuffersHelper(GLsizei n, const GLuint* buffers);
481 void GenFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
482 void GenRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
483 void GenTexturesHelper(GLsizei n, const GLuint* textures);
484 void GenVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
485 void GenQueriesEXTHelper(GLsizei n, const GLuint* queries);
486 void GenValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
487 void GenSamplersHelper(GLsizei n, const GLuint* samplers);
488 void GenTransformFeedbacksHelper(GLsizei n, const GLuint* transformfeedbacks);
490 void DeleteBuffersHelper(GLsizei n, const GLuint* buffers);
491 void DeleteFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
492 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
493 void DeleteTexturesHelper(GLsizei n, const GLuint* textures);
494 bool DeleteProgramHelper(GLuint program);
495 bool DeleteShaderHelper(GLuint shader);
496 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* queries);
497 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
498 void DeleteValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
499 void DeleteSamplersHelper(GLsizei n, const GLuint* samplers);
500 void DeleteTransformFeedbacksHelper(
501 GLsizei n, const GLuint* transformfeedbacks);
502 void DeleteSyncHelper(GLsync sync);
504 void DeleteBuffersStub(GLsizei n, const GLuint* buffers);
505 void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers);
506 void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers);
507 void DeleteTexturesStub(GLsizei n, const GLuint* textures);
508 void DeleteProgramStub(GLsizei n, const GLuint* programs);
509 void DeleteShaderStub(GLsizei n, const GLuint* shaders);
510 void DeleteVertexArraysOESStub(GLsizei n, const GLuint* arrays);
511 void DeleteValuebuffersCHROMIUMStub(GLsizei n, const GLuint* valuebuffers);
512 void DeleteSamplersStub(GLsizei n, const GLuint* samplers);
513 void DeleteTransformFeedbacksStub(
514 GLsizei n, const GLuint* transformfeedbacks);
515 void DeleteSyncStub(GLsizei n, const GLuint* syncs);
517 void BufferDataHelper(
518 GLenum target, GLsizeiptr size, const void* data, GLenum usage);
519 void BufferSubDataHelper(
520 GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
521 void BufferSubDataHelperImpl(
522 GLenum target, GLintptr offset, GLsizeiptr size, const void* data,
523 ScopedTransferBufferPtr* buffer);
525 GLuint CreateImageCHROMIUMHelper(ClientBuffer buffer,
526 GLsizei width,
527 GLsizei height,
528 GLenum internalformat);
529 void DestroyImageCHROMIUMHelper(GLuint image_id);
530 GLuint CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width,
531 GLsizei height,
532 GLenum internalformat,
533 GLenum usage);
535 // Helper for GetVertexAttrib
536 bool GetVertexAttribHelper(GLuint index, GLenum pname, uint32* param);
538 GLuint GetMaxValueInBufferCHROMIUMHelper(
539 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset);
541 void RestoreElementAndArrayBuffers(bool restore);
542 void RestoreArrayBuffer(bool restrore);
544 // The pixels pointer should already account for unpack skip
545 // images/rows/pixels.
546 void TexSubImage2DImpl(
547 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
548 GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size,
549 const void* pixels, uint32 pixels_padded_row_size, GLboolean internal,
550 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
551 void TexSubImage3DImpl(
552 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
553 GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
554 uint32 unpadded_row_size, const void* pixels,
555 uint32 pixels_padded_row_size, GLboolean internal,
556 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
558 // Helpers for query functions.
559 bool GetHelper(GLenum pname, GLint* params);
560 bool GetBooleanvHelper(GLenum pname, GLboolean* params);
561 bool GetBufferParameterivHelper(GLenum target, GLenum pname, GLint* params);
562 bool GetFloatvHelper(GLenum pname, GLfloat* params);
563 bool GetFramebufferAttachmentParameterivHelper(
564 GLenum target, GLenum attachment, GLenum pname, GLint* params);
565 bool GetIntegervHelper(GLenum pname, GLint* params);
566 bool GetInternalformativHelper(
567 GLenum target, GLenum format, GLenum pname, GLsizei bufSize,
568 GLint* params);
569 bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params);
570 bool GetSamplerParameterfvHelper(
571 GLuint sampler, GLenum pname, GLfloat* params);
572 bool GetSamplerParameterivHelper(
573 GLuint sampler, GLenum pname, GLint* params);
574 bool GetRenderbufferParameterivHelper(
575 GLenum target, GLenum pname, GLint* params);
576 bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params);
577 bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params);
578 bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params);
579 const GLubyte* GetStringHelper(GLenum name);
581 bool IsExtensionAvailable(const char* ext);
583 // Caches certain capabilties state. Return true if cached.
584 bool SetCapabilityState(GLenum cap, bool enabled);
586 IdHandlerInterface* GetIdHandler(int id_namespace) const;
587 // IdAllocators for objects that can't be shared among contexts.
588 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
589 // Framebuffer and Vertex array objects.
590 IdAllocator* GetIdAllocator(int id_namespace) const;
592 void FinishHelper();
594 void RunIfContextNotLost(const base::Closure& callback);
596 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
597 // If not, generate an approriate error, and return false.
598 bool ValidateOffset(const char* func, GLintptr offset);
600 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
601 // If not, generate an approriate error, and return false.
602 bool ValidateSize(const char* func, GLsizeiptr offset);
604 // Remove the transfer buffer from the buffer tracker. For buffers used
605 // asynchronously the memory is free:ed if the upload has completed. For
606 // other buffers, the memory is either free:ed immediately or free:ed pending
607 // a token.
608 void RemoveTransferBuffer(BufferTracker::Buffer* buffer);
610 // Returns true if the async upload token has passed.
612 // NOTE: This will detect wrapped async tokens by checking if the most
613 // significant bit of async token to check is 1 but the last read is 0, i.e.
614 // the uint32 wrapped.
615 bool HasAsyncUploadTokenPassed(uint32 token) const {
616 return async_upload_sync_->HasAsyncUploadTokenPassed(token);
619 // Get the next async upload token.
620 uint32 NextAsyncUploadToken();
622 // Ensure that the shared memory used for synchronizing async upload tokens
623 // has been mapped.
625 // Returns false on error, true on success.
626 bool EnsureAsyncUploadSync();
628 // Checks the last read asynchronously upload token and frees any unmanaged
629 // transfer buffer that has its async token passed.
630 void PollAsyncUploads();
632 // Free every async upload buffer. If some async upload buffer is still in use
633 // wait for them to finish before freeing.
634 void FreeAllAsyncUploadBuffers();
636 bool GetBoundPixelTransferBuffer(
637 GLenum target, const char* function_name, GLuint* buffer_id);
638 BufferTracker::Buffer* GetBoundPixelUnpackTransferBufferIfValid(
639 GLuint buffer_id,
640 const char* function_name, GLuint offset, GLsizei size);
642 // Pack 2D arrays of char into a bucket.
643 // Helper function for ShaderSource(), TransformFeedbackVaryings(), etc.
644 bool PackStringsToBucket(GLsizei count,
645 const char* const* str,
646 const GLint* length,
647 const char* func_name);
649 const std::string& GetLogPrefix() const;
651 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
652 void CheckGLError();
653 void FailGLError(GLenum error);
654 #else
655 void CheckGLError() { }
656 void FailGLError(GLenum /* error */) { }
657 #endif
659 GLES2Util util_;
660 GLES2CmdHelper* helper_;
661 TransferBufferInterface* transfer_buffer_;
662 std::string last_error_;
663 DebugMarkerManager debug_marker_manager_;
664 std::string this_in_hex_;
666 std::queue<int32> swap_buffers_tokens_;
667 std::queue<int32> rate_limit_tokens_;
669 ExtensionStatus angle_pack_reverse_row_order_status_;
670 ExtensionStatus chromium_framebuffer_multisample_;
672 GLStaticState static_state_;
673 ClientContextState state_;
675 // pack alignment as last set by glPixelStorei
676 GLint pack_alignment_;
678 // unpack alignment as last set by glPixelStorei
679 GLint unpack_alignment_;
681 // unpack yflip as last set by glPixelstorei
682 bool unpack_flip_y_;
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 // The currently bound array buffer.
716 GLuint bound_array_buffer_id_;
718 // The currently bound pixel transfer buffers.
719 GLuint bound_pixel_pack_transfer_buffer_id_;
720 GLuint bound_pixel_unpack_transfer_buffer_id_;
722 // The current asynchronous pixel buffer upload token.
723 uint32 async_upload_token_;
725 // The shared memory used for synchronizing asynchronous upload tokens.
726 AsyncUploadSync* async_upload_sync_;
727 int32 async_upload_sync_shm_id_;
728 unsigned int async_upload_sync_shm_offset_;
730 // Unmanaged pixel transfer buffer memory pending asynchronous upload token.
731 typedef std::list<std::pair<void*, uint32> > DetachedAsyncUploadMemoryList;
732 DetachedAsyncUploadMemoryList detached_async_upload_memory_;
734 // Client side management for vertex array objects. Needed to correctly
735 // track client side arrays.
736 scoped_ptr<VertexArrayObjectManager> vertex_array_object_manager_;
738 GLuint reserved_ids_[2];
740 // Current GL error bits.
741 uint32 error_bits_;
743 // Whether or not to print debugging info.
744 bool debug_;
746 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
747 const bool lose_context_when_out_of_memory_;
749 // Whether or not to support client side arrays.
750 const bool support_client_side_arrays_;
752 // Used to check for single threaded access.
753 int use_count_;
755 // Map of GLenum to Strings for glGetString. We need to cache these because
756 // the pointer passed back to the client has to remain valid for eternity.
757 typedef std::map<uint32, std::set<std::string> > GLStringMap;
758 GLStringMap gl_strings_;
760 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
761 // have an enum for this so handle it separately.
762 std::set<std::string> requestable_extensions_set_;
764 typedef std::map<const void*, MappedBuffer> MappedBufferMap;
765 MappedBufferMap mapped_buffers_;
767 typedef std::map<const void*, MappedTexture> MappedTextureMap;
768 MappedTextureMap mapped_textures_;
770 scoped_ptr<MappedMemoryManager> mapped_memory_;
772 scoped_refptr<ShareGroup> share_group_;
773 ShareGroupContextData share_group_context_data_;
775 scoped_ptr<QueryTracker> query_tracker_;
776 typedef std::map<GLuint, QueryTracker::Query*> QueryMap;
777 QueryMap current_queries_;
778 scoped_ptr<IdAllocator> query_id_allocator_;
780 scoped_ptr<BufferTracker> buffer_tracker_;
782 GLES2ImplementationErrorMessageCallback* error_message_callback_;
784 int current_trace_stack_;
786 GpuControl* gpu_control_;
788 Capabilities capabilities_;
790 base::WeakPtrFactory<GLES2Implementation> weak_ptr_factory_;
792 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation);
795 inline bool GLES2Implementation::GetBufferParameterivHelper(
796 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
797 return false;
800 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
801 GLenum /* target */,
802 GLenum /* attachment */,
803 GLenum /* pname */,
804 GLint* /* params */) {
805 return false;
808 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
809 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
810 return false;
813 inline bool GLES2Implementation::GetShaderivHelper(
814 GLuint /* shader */, GLenum /* pname */, GLint* /* params */) {
815 return false;
818 inline bool GLES2Implementation::GetTexParameterfvHelper(
819 GLenum /* target */, GLenum /* pname */, GLfloat* /* params */) {
820 return false;
823 inline bool GLES2Implementation::GetTexParameterivHelper(
824 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
825 return false;
828 } // namespace gles2
829 } // namespace gpu
831 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_