Home | History | Annotate | Download | only in client
      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.
      4 
      5 #ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
      6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
      7 
      8 #include <GLES2/gl2.h>
      9 
     10 #include <map>
     11 #include <queue>
     12 #include <set>
     13 #include <string>
     14 #include <vector>
     15 
     16 #include "base/compiler_specific.h"
     17 #include "base/memory/scoped_ptr.h"
     18 #include "base/memory/weak_ptr.h"
     19 #include "gles2_impl_export.h"
     20 #include "gpu/command_buffer/client/buffer_tracker.h"
     21 #include "gpu/command_buffer/client/client_context_state.h"
     22 #include "gpu/command_buffer/client/context_support.h"
     23 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
     24 #include "gpu/command_buffer/client/gles2_interface.h"
     25 #include "gpu/command_buffer/client/gpu_memory_buffer_tracker.h"
     26 #include "gpu/command_buffer/client/mapped_memory.h"
     27 #include "gpu/command_buffer/client/query_tracker.h"
     28 #include "gpu/command_buffer/client/ref_counted.h"
     29 #include "gpu/command_buffer/client/ring_buffer.h"
     30 #include "gpu/command_buffer/client/share_group.h"
     31 #include "gpu/command_buffer/common/capabilities.h"
     32 #include "gpu/command_buffer/common/debug_marker_manager.h"
     33 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
     34 
     35 #if !defined(NDEBUG) && !defined(__native_client__) && !defined(GLES2_CONFORMANCE_TESTS)  // NOLINT
     36   #if defined(GLES2_INLINE_OPTIMIZATION)
     37     // TODO(gman): Replace with macros that work with inline optmization.
     38     #define GPU_CLIENT_SINGLE_THREAD_CHECK()
     39     #define GPU_CLIENT_LOG(args)
     40     #define GPU_CLIENT_LOG_CODE_BLOCK(code)
     41     #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
     42   #else
     43     #include "base/logging.h"
     44     #define GPU_CLIENT_SINGLE_THREAD_CHECK() SingleThreadChecker checker(this);
     45     #define GPU_CLIENT_LOG(args)  DLOG_IF(INFO, debug_) << args;
     46     #define GPU_CLIENT_LOG_CODE_BLOCK(code) code
     47     #define GPU_CLIENT_DCHECK_CODE_BLOCK(code) code
     48     #define GPU_CLIENT_DEBUG
     49   #endif
     50 #else
     51   #define GPU_CLIENT_SINGLE_THREAD_CHECK()
     52   #define GPU_CLIENT_LOG(args)
     53   #define GPU_CLIENT_LOG_CODE_BLOCK(code)
     54   #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
     55 #endif
     56 
     57 #if defined(GPU_CLIENT_DEBUG)
     58   // Set to 1 to have the client fail when a GL error is generated.
     59   // This helps find bugs in the renderer since the debugger stops on the error.
     60 #  if 0
     61 #    define GL_CLIENT_FAIL_GL_ERRORS
     62 #  endif
     63 #endif
     64 
     65 // Check that destination pointers point to initialized memory.
     66 // When the context is lost, calling GL function has no effect so if destination
     67 // pointers point to initialized memory it can often lead to crash bugs. eg.
     68 //
     69 // GLsizei len;
     70 // glGetShaderSource(shader, max_size, &len, buffer);
     71 // std::string src(buffer, buffer + len);  // len can be uninitialized here!!!
     72 //
     73 // Because this check is not official GL this check happens only on Chrome code,
     74 // not Pepper.
     75 //
     76 // If it was up to us we'd just always write to the destination but the OpenGL
     77 // spec defines the behavior of OpenGL functions, not us. :-(
     78 #if defined(__native_client__) || defined(GLES2_CONFORMANCE_TESTS)
     79   #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v)
     80   #define GPU_CLIENT_DCHECK(v)
     81 #elif defined(GPU_DCHECK)
     82   #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v)
     83   #define GPU_CLIENT_DCHECK(v) GPU_DCHECK(v)
     84 #elif defined(DCHECK)
     85   #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
     86   #define GPU_CLIENT_DCHECK(v) DCHECK(v)
     87 #else
     88   #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
     89   #define GPU_CLIENT_DCHECK(v) ASSERT(v)
     90 #endif
     91 
     92 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \
     93     GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \
     94         (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
     95 
     96 #define GPU_CLIENT_VALIDATE_DESTINATION_OPTIONAL_INITALIZATION(type, ptr) \
     97     GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(!ptr || \
     98         (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
     99 
    100 struct GLUniformDefinitionCHROMIUM;
    101 
    102 namespace gpu {
    103 
    104 class GpuControl;
    105 class ScopedTransferBufferPtr;
    106 class TransferBufferInterface;
    107 
    108 namespace gles2 {
    109 
    110 class ImageFactory;
    111 class VertexArrayObjectManager;
    112 
    113 // This class emulates GLES2 over command buffers. It can be used by a client
    114 // program so that the program does not need deal with shared memory and command
    115 // buffer management. See gl2_lib.h.  Note that there is a performance gain to
    116 // be had by changing your code to use command buffers directly by using the
    117 // GLES2CmdHelper but that entails changing your code to use and deal with
    118 // shared memory and synchronization issues.
    119 class GLES2_IMPL_EXPORT GLES2Implementation
    120     : NON_EXPORTED_BASE(public GLES2Interface),
    121       NON_EXPORTED_BASE(public ContextSupport) {
    122  public:
    123   enum MappedMemoryLimit {
    124     kNoLimit = MappedMemoryManager::kNoLimit,
    125   };
    126   class ErrorMessageCallback {
    127    public:
    128     virtual ~ErrorMessageCallback() { }
    129     virtual void OnErrorMessage(const char* msg, int id) = 0;
    130   };
    131 
    132   // Stores GL state that never changes.
    133   struct GLES2_IMPL_EXPORT GLStaticState {
    134     GLStaticState();
    135     ~GLStaticState();
    136 
    137     struct GLES2_IMPL_EXPORT IntState {
    138       IntState();
    139       GLint max_combined_texture_image_units;
    140       GLint max_cube_map_texture_size;
    141       GLint max_fragment_uniform_vectors;
    142       GLint max_renderbuffer_size;
    143       GLint max_texture_image_units;
    144       GLint max_texture_size;
    145       GLint max_varying_vectors;
    146       GLint max_vertex_attribs;
    147       GLint max_vertex_texture_image_units;
    148       GLint max_vertex_uniform_vectors;
    149       GLint num_compressed_texture_formats;
    150       GLint num_shader_binary_formats;
    151     };
    152     IntState int_state;
    153 
    154     typedef std::pair<GLenum,GLenum> ShaderPrecisionKey;
    155     typedef std::map<ShaderPrecisionKey,
    156                      cmds::GetShaderPrecisionFormat::Result>
    157         ShaderPrecisionMap;
    158     ShaderPrecisionMap shader_precisions;
    159   };
    160 
    161   // The maxiumum result size from simple GL get commands.
    162   static const size_t kMaxSizeOfSimpleResult = 16 * sizeof(uint32);  // NOLINT.
    163 
    164   // used for testing only. If more things are reseved add them here.
    165   static const unsigned int kStartingOffset = kMaxSizeOfSimpleResult;
    166 
    167   // Size in bytes to issue async flush for transfer buffer.
    168   static const unsigned int kSizeToFlush = 256 * 1024;
    169 
    170   // The bucket used for results. Public for testing only.
    171   static const uint32 kResultBucketId = 1;
    172 
    173   // Alignment of allocations.
    174   static const unsigned int kAlignment = 4;
    175 
    176   // GL names for the buffers used to emulate client side buffers.
    177   static const GLuint kClientSideArrayId = 0xFEDCBA98u;
    178   static const GLuint kClientSideElementArrayId = 0xFEDCBA99u;
    179 
    180   // Number of swap buffers allowed before waiting.
    181   static const size_t kMaxSwapBuffers = 2;
    182 
    183   GLES2Implementation(
    184       GLES2CmdHelper* helper,
    185       ShareGroup* share_group,
    186       TransferBufferInterface* transfer_buffer,
    187       bool bind_generates_resource,
    188       bool free_everything_when_invisible,
    189       GpuControl* gpu_control);
    190 
    191   virtual ~GLES2Implementation();
    192 
    193   bool Initialize(
    194       unsigned int starting_transfer_buffer_size,
    195       unsigned int min_transfer_buffer_size,
    196       unsigned int max_transfer_buffer_size,
    197       unsigned int mapped_memory_limit);
    198 
    199   // The GLES2CmdHelper being used by this GLES2Implementation. You can use
    200   // this to issue cmds at a lower level for certain kinds of optimization.
    201   GLES2CmdHelper* helper() const;
    202 
    203   // Gets client side generated errors.
    204   GLenum GetClientSideGLError();
    205 
    206   // Include the auto-generated part of this class. We split this because
    207   // it means we can easily edit the non-auto generated parts right here in
    208   // this file instead of having to edit some template or the code generator.
    209   #include "gpu/command_buffer/client/gles2_implementation_autogen.h"
    210 
    211   virtual void DisableVertexAttribArray(GLuint index) OVERRIDE;
    212   virtual void EnableVertexAttribArray(GLuint index) OVERRIDE;
    213   virtual void GetVertexAttribfv(
    214       GLuint index, GLenum pname, GLfloat* params) OVERRIDE;
    215   virtual void GetVertexAttribiv(
    216       GLuint index, GLenum pname, GLint* params) OVERRIDE;
    217 
    218   // ContextSupport implementation.
    219   virtual void Swap() OVERRIDE;
    220   virtual void PartialSwapBuffers(gfx::Rect sub_buffer) OVERRIDE;
    221   virtual void SetSwapBuffersCompleteCallback(
    222       const base::Closure& swap_buffers_complete_callback)
    223           OVERRIDE;
    224 
    225   void GetProgramInfoCHROMIUMHelper(GLuint program, std::vector<int8>* result);
    226   GLint GetAttribLocationHelper(GLuint program, const char* name);
    227   GLint GetUniformLocationHelper(GLuint program, const char* name);
    228   bool GetActiveAttribHelper(
    229       GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
    230       GLint* size, GLenum* type, char* name);
    231   bool GetActiveUniformHelper(
    232       GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
    233       GLint* size, GLenum* type, char* name);
    234 
    235   void FreeUnusedSharedMemory();
    236   void FreeEverything();
    237 
    238   // ContextSupport implementation.
    239   virtual void SignalSyncPoint(uint32 sync_point,
    240                                const base::Closure& callback) OVERRIDE;
    241   virtual void SignalQuery(uint32 query,
    242                            const base::Closure& callback) OVERRIDE;
    243   virtual void SetSurfaceVisible(bool visible) OVERRIDE;
    244   virtual void SendManagedMemoryStats(const ManagedMemoryStats& stats)
    245       OVERRIDE;
    246 
    247   void SetErrorMessageCallback(ErrorMessageCallback* callback) {
    248     error_message_callback_ = callback;
    249   }
    250 
    251   ShareGroup* share_group() const {
    252     return share_group_.get();
    253   }
    254 
    255   const Capabilities& capabilities() const {
    256     return capabilities_;
    257   }
    258 
    259   GpuControl* gpu_control() {
    260     return gpu_control_;
    261   }
    262 
    263  private:
    264   friend class GLES2ImplementationTest;
    265   friend class VertexArrayObjectManager;
    266 
    267   // Used to track whether an extension is available
    268   enum ExtensionStatus {
    269       kAvailableExtensionStatus,
    270       kUnavailableExtensionStatus,
    271       kUnknownExtensionStatus
    272   };
    273 
    274   // Base class for mapped resources.
    275   struct MappedResource {
    276     MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset)
    277         : access(_access),
    278           shm_id(_shm_id),
    279           shm_memory(mem),
    280           shm_offset(offset) {
    281     }
    282 
    283     // access mode. Currently only GL_WRITE_ONLY is valid
    284     GLenum access;
    285 
    286     // Shared memory ID for buffer.
    287     int shm_id;
    288 
    289     // Address of shared memory
    290     void* shm_memory;
    291 
    292     // Offset of shared memory
    293     unsigned int shm_offset;
    294   };
    295 
    296   // Used to track mapped textures.
    297   struct MappedTexture : public MappedResource {
    298     MappedTexture(
    299         GLenum access,
    300         int shm_id,
    301         void* shm_mem,
    302         unsigned int shm_offset,
    303         GLenum _target,
    304         GLint _level,
    305         GLint _xoffset,
    306         GLint _yoffset,
    307         GLsizei _width,
    308         GLsizei _height,
    309         GLenum _format,
    310         GLenum _type)
    311         : MappedResource(access, shm_id, shm_mem, shm_offset),
    312           target(_target),
    313           level(_level),
    314           xoffset(_xoffset),
    315           yoffset(_yoffset),
    316           width(_width),
    317           height(_height),
    318           format(_format),
    319           type(_type) {
    320     }
    321 
    322     // These match the arguments to TexSubImage2D.
    323     GLenum target;
    324     GLint level;
    325     GLint xoffset;
    326     GLint yoffset;
    327     GLsizei width;
    328     GLsizei height;
    329     GLenum format;
    330     GLenum type;
    331   };
    332 
    333   // Used to track mapped buffers.
    334   struct MappedBuffer : public MappedResource {
    335     MappedBuffer(
    336         GLenum access,
    337         int shm_id,
    338         void* shm_mem,
    339         unsigned int shm_offset,
    340         GLenum _target,
    341         GLintptr _offset,
    342         GLsizeiptr _size)
    343         : MappedResource(access, shm_id, shm_mem, shm_offset),
    344           target(_target),
    345           offset(_offset),
    346           size(_size) {
    347     }
    348 
    349     // These match the arguments to BufferSubData.
    350     GLenum target;
    351     GLintptr offset;
    352     GLsizeiptr size;
    353   };
    354 
    355   struct TextureUnit {
    356     TextureUnit()
    357         : bound_texture_2d(0),
    358           bound_texture_cube_map(0),
    359           bound_texture_external_oes(0) {}
    360 
    361     // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
    362     GLuint bound_texture_2d;
    363 
    364     // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
    365     // glBindTexture
    366     GLuint bound_texture_cube_map;
    367 
    368     // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
    369     // glBindTexture
    370     GLuint bound_texture_external_oes;
    371   };
    372 
    373   // Checks for single threaded access.
    374   class SingleThreadChecker {
    375    public:
    376     SingleThreadChecker(GLES2Implementation* gles2_implementation);
    377     ~SingleThreadChecker();
    378 
    379    private:
    380     GLES2Implementation* gles2_implementation_;
    381   };
    382 
    383   // Gets the value of the result.
    384   template <typename T>
    385   T GetResultAs() {
    386     return static_cast<T>(GetResultBuffer());
    387   }
    388 
    389   void* GetResultBuffer();
    390   int32 GetResultShmId();
    391   uint32 GetResultShmOffset();
    392 
    393   bool QueryAndCacheStaticState();
    394 
    395   // Helpers used to batch synchronous GetIntergerv calls with other
    396   // synchronous calls.
    397   struct GetMultipleIntegervState {
    398     GetMultipleIntegervState(const GLenum* pnames, GLuint pnames_count,
    399                              GLint* results, GLsizeiptr results_size)
    400        : pnames(pnames),
    401          pnames_count(pnames_count),
    402          results(results),
    403          results_size(results_size)
    404     { }
    405     // inputs
    406     const GLenum* pnames;
    407     GLuint pnames_count;
    408     // outputs
    409     GLint* results;
    410     GLsizeiptr results_size;
    411     // transfer buffer
    412     int num_results;
    413     int transfer_buffer_size_needed;
    414     void* buffer;
    415     void* results_buffer;
    416   };
    417   bool GetMultipleIntegervSetup(
    418       GetMultipleIntegervState* state);
    419   void GetMultipleIntegervRequest(
    420       GetMultipleIntegervState* state);
    421   void GetMultipleIntegervOnCompleted(
    422       GetMultipleIntegervState* state);
    423 
    424   // Helpers used to batch synchronous GetShaderPrecision calls with other
    425   // synchronous calls.
    426   struct GetAllShaderPrecisionFormatsState {
    427     GetAllShaderPrecisionFormatsState(
    428         const GLenum (*precision_params)[2],
    429         int precision_params_count)
    430         : precision_params(precision_params),
    431           precision_params_count(precision_params_count)
    432     { }
    433     const GLenum (*precision_params)[2];
    434     int precision_params_count;
    435     int transfer_buffer_size_needed;
    436     void* results_buffer;
    437   };
    438   void GetAllShaderPrecisionFormatsSetup(
    439       GetAllShaderPrecisionFormatsState* state);
    440   void GetAllShaderPrecisionFormatsRequest(
    441       GetAllShaderPrecisionFormatsState* state);
    442   void GetAllShaderPrecisionFormatsOnCompleted(
    443       GetAllShaderPrecisionFormatsState* state);
    444 
    445   // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
    446   bool IsAnglePackReverseRowOrderAvailable();
    447   bool IsChromiumFramebufferMultisampleAvailable();
    448 
    449   bool IsExtensionAvailableHelper(
    450       const char* extension, ExtensionStatus* status);
    451 
    452   // Gets the GLError through our wrapper.
    453   GLenum GetGLError();
    454 
    455   // Sets our wrapper for the GLError.
    456   void SetGLError(GLenum error, const char* function_name, const char* msg);
    457   void SetGLErrorInvalidEnum(
    458       const char* function_name, GLenum value, const char* label);
    459 
    460   // Returns the last error and clears it. Useful for debugging.
    461   const std::string& GetLastError() {
    462     return last_error_;
    463   }
    464 
    465   // Waits for all commands to execute.
    466   void WaitForCmd();
    467 
    468   // TODO(gman): These bucket functions really seem like they belong in
    469   // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
    470   // a transfer buffer to function which is currently managed by this class.
    471 
    472   // Gets the contents of a bucket.
    473   bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data);
    474 
    475   // Sets the contents of a bucket.
    476   void SetBucketContents(uint32 bucket_id, const void* data, size_t size);
    477 
    478   // Sets the contents of a bucket as a string.
    479   void SetBucketAsCString(uint32 bucket_id, const char* str);
    480 
    481   // Gets the contents of a bucket as a string. Returns false if there is no
    482   // string available which is a separate case from the empty string.
    483   bool GetBucketAsString(uint32 bucket_id, std::string* str);
    484 
    485   // Sets the contents of a bucket as a string.
    486   void SetBucketAsString(uint32 bucket_id, const std::string& str);
    487 
    488   // Returns true if id is reserved.
    489   bool IsBufferReservedId(GLuint id);
    490   bool IsFramebufferReservedId(GLuint id) { return false;  }
    491   bool IsRenderbufferReservedId(GLuint id) { return false; }
    492   bool IsTextureReservedId(GLuint id) { return false; }
    493   bool IsVertexArrayReservedId(GLuint id) { return false; }
    494 
    495   bool BindBufferHelper(GLenum target, GLuint texture);
    496   bool BindFramebufferHelper(GLenum target, GLuint texture);
    497   bool BindRenderbufferHelper(GLenum target, GLuint texture);
    498   bool BindTextureHelper(GLenum target, GLuint texture);
    499   bool BindVertexArrayHelper(GLuint array);
    500 
    501   void GenBuffersHelper(GLsizei n, const GLuint* buffers);
    502   void GenFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
    503   void GenRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
    504   void GenTexturesHelper(GLsizei n, const GLuint* textures);
    505   void GenVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
    506   void GenQueriesEXTHelper(GLsizei n, const GLuint* queries);
    507 
    508   void DeleteBuffersHelper(GLsizei n, const GLuint* buffers);
    509   void DeleteFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
    510   void DeleteRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
    511   void DeleteTexturesHelper(GLsizei n, const GLuint* textures);
    512   bool DeleteProgramHelper(GLuint program);
    513   bool DeleteShaderHelper(GLuint shader);
    514   void DeleteQueriesEXTHelper(GLsizei n, const GLuint* queries);
    515   void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
    516 
    517   void DeleteBuffersStub(GLsizei n, const GLuint* buffers);
    518   void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers);
    519   void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers);
    520   void DeleteTexturesStub(GLsizei n, const GLuint* textures);
    521   void DeleteProgramStub(GLsizei n, const GLuint* programs);
    522   void DeleteShaderStub(GLsizei n, const GLuint* shaders);
    523   // TODO(gman): Remove this as queries are not shared.
    524   void DeleteQueriesStub(GLsizei n, const GLuint* queries);
    525   void DeleteVertexArraysOESStub(GLsizei n, const GLuint* arrays);
    526 
    527   void BufferDataHelper(
    528       GLenum target, GLsizeiptr size, const void* data, GLenum usage);
    529   void BufferSubDataHelper(
    530       GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
    531   void BufferSubDataHelperImpl(
    532       GLenum target, GLintptr offset, GLsizeiptr size, const void* data,
    533       ScopedTransferBufferPtr* buffer);
    534 
    535   GLuint CreateImageCHROMIUMHelper(
    536       GLsizei width, GLsizei height, GLenum internalformat);
    537   void DestroyImageCHROMIUMHelper(GLuint image_id);
    538   void* MapImageCHROMIUMHelper(GLuint image_id, GLenum access);
    539   void UnmapImageCHROMIUMHelper(GLuint image_id);
    540   void GetImageParameterivCHROMIUMHelper(
    541       GLuint image_id, GLenum pname, GLint* params);
    542 
    543   // Helper for GetVertexAttrib
    544   bool GetVertexAttribHelper(GLuint index, GLenum pname, uint32* param);
    545 
    546   GLuint GetMaxValueInBufferCHROMIUMHelper(
    547       GLuint buffer_id, GLsizei count, GLenum type, GLuint offset);
    548 
    549   void RestoreElementAndArrayBuffers(bool restore);
    550   void RestoreArrayBuffer(bool restrore);
    551 
    552   // The pixels pointer should already account for unpack skip rows and skip
    553   // pixels.
    554   void TexSubImage2DImpl(
    555       GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
    556       GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size,
    557       const void* pixels, uint32 pixels_padded_row_size, GLboolean internal,
    558       ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
    559 
    560   // Helpers for query functions.
    561   bool GetHelper(GLenum pname, GLint* params);
    562   bool GetBooleanvHelper(GLenum pname, GLboolean* params);
    563   bool GetBufferParameterivHelper(GLenum target, GLenum pname, GLint* params);
    564   bool GetFloatvHelper(GLenum pname, GLfloat* params);
    565   bool GetFramebufferAttachmentParameterivHelper(
    566       GLenum target, GLenum attachment, GLenum pname, GLint* params);
    567   bool GetIntegervHelper(GLenum pname, GLint* params);
    568   bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params);
    569   bool GetRenderbufferParameterivHelper(
    570       GLenum target, GLenum pname, GLint* params);
    571   bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params);
    572   bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params);
    573   bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params);
    574   const GLubyte* GetStringHelper(GLenum name);
    575 
    576   bool IsExtensionAvailable(const char* ext);
    577 
    578   // Caches certain capabilties state. Return true if cached.
    579   bool SetCapabilityState(GLenum cap, bool enabled);
    580 
    581   IdHandlerInterface* GetIdHandler(int id_namespace) const;
    582 
    583   void FinishHelper();
    584 
    585   // Asserts that the context is lost.
    586   // NOTE: This is an expensive call and should only be called
    587   // for error checking.
    588   bool MustBeContextLost();
    589 
    590   void RunIfContextNotLost(const base::Closure& callback);
    591 
    592   void OnSwapBuffersComplete();
    593 
    594   bool GetBoundPixelTransferBuffer(
    595       GLenum target, const char* function_name, GLuint* buffer_id);
    596   BufferTracker::Buffer* GetBoundPixelUnpackTransferBufferIfValid(
    597       GLuint buffer_id,
    598       const char* function_name, GLuint offset, GLsizei size);
    599 
    600   const std::string& GetLogPrefix() const;
    601 
    602 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
    603   void CheckGLError();
    604   void FailGLError(GLenum error);
    605 #else
    606   void CheckGLError() { }
    607   void FailGLError(GLenum /* error */) { }
    608 #endif
    609 
    610   GLES2Util util_;
    611   GLES2CmdHelper* helper_;
    612   TransferBufferInterface* transfer_buffer_;
    613   std::string last_error_;
    614   DebugMarkerManager debug_marker_manager_;
    615   std::string this_in_hex_;
    616 
    617   std::queue<int32> swap_buffers_tokens_;
    618   std::queue<int32> rate_limit_tokens_;
    619 
    620   ExtensionStatus angle_pack_reverse_row_order_status_;
    621   ExtensionStatus chromium_framebuffer_multisample_;
    622 
    623   GLStaticState static_state_;
    624   ClientContextState state_;
    625 
    626   // pack alignment as last set by glPixelStorei
    627   GLint pack_alignment_;
    628 
    629   // unpack alignment as last set by glPixelStorei
    630   GLint unpack_alignment_;
    631 
    632   // unpack yflip as last set by glPixelstorei
    633   bool unpack_flip_y_;
    634 
    635   // unpack row length as last set by glPixelStorei
    636   GLint unpack_row_length_;
    637 
    638   // unpack skip rows as last set by glPixelStorei
    639   GLint unpack_skip_rows_;
    640 
    641   // unpack skip pixels as last set by glPixelStorei
    642   GLint unpack_skip_pixels_;
    643 
    644   // pack reverse row order as last set by glPixelstorei
    645   bool pack_reverse_row_order_;
    646 
    647   scoped_ptr<TextureUnit[]> texture_units_;
    648 
    649   // 0 to gl_state_.max_combined_texture_image_units.
    650   GLuint active_texture_unit_;
    651 
    652   GLuint bound_framebuffer_;
    653   GLuint bound_read_framebuffer_;
    654   GLuint bound_renderbuffer_;
    655 
    656   // The program in use by glUseProgram
    657   GLuint current_program_;
    658 
    659   // The currently bound array buffer.
    660   GLuint bound_array_buffer_id_;
    661 
    662   // The currently bound pixel transfer buffers.
    663   GLuint bound_pixel_pack_transfer_buffer_id_;
    664   GLuint bound_pixel_unpack_transfer_buffer_id_;
    665 
    666   // Client side management for vertex array objects. Needed to correctly
    667   // track client side arrays.
    668   scoped_ptr<VertexArrayObjectManager> vertex_array_object_manager_;
    669 
    670   GLuint reserved_ids_[2];
    671 
    672   // Current GL error bits.
    673   uint32 error_bits_;
    674 
    675   // Whether or not to print debugging info.
    676   bool debug_;
    677 
    678   // Used to check for single threaded access.
    679   int use_count_;
    680 
    681   // Map of GLenum to Strings for glGetString.  We need to cache these because
    682   // the pointer passed back to the client has to remain valid for eternity.
    683   typedef std::map<uint32, std::set<std::string> > GLStringMap;
    684   GLStringMap gl_strings_;
    685 
    686   // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
    687   // have an enum for this so handle it separately.
    688   std::set<std::string> requestable_extensions_set_;
    689 
    690   typedef std::map<const void*, MappedBuffer> MappedBufferMap;
    691   MappedBufferMap mapped_buffers_;
    692 
    693   typedef std::map<const void*, MappedTexture> MappedTextureMap;
    694   MappedTextureMap mapped_textures_;
    695 
    696   scoped_ptr<MappedMemoryManager> mapped_memory_;
    697 
    698   scoped_refptr<ShareGroup> share_group_;
    699 
    700   scoped_ptr<QueryTracker> query_tracker_;
    701   QueryTracker::Query* current_query_;
    702 
    703   scoped_ptr<BufferTracker> buffer_tracker_;
    704 
    705   scoped_ptr<GpuMemoryBufferTracker> gpu_memory_buffer_tracker_;
    706 
    707   ErrorMessageCallback* error_message_callback_;
    708 
    709   scoped_ptr<std::string> current_trace_name_;
    710 
    711   GpuControl* gpu_control_;
    712 
    713   bool surface_visible_;
    714   bool free_everything_when_invisible_;
    715 
    716   Capabilities capabilities_;
    717 
    718   bool use_echo_for_swap_ack_;
    719   base::Closure swap_buffers_complete_callback_;
    720 
    721   base::WeakPtrFactory<GLES2Implementation> weak_ptr_factory_;
    722 
    723   DISALLOW_COPY_AND_ASSIGN(GLES2Implementation);
    724 };
    725 
    726 inline bool GLES2Implementation::GetBufferParameterivHelper(
    727     GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
    728   return false;
    729 }
    730 
    731 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
    732     GLenum /* target */,
    733     GLenum /* attachment */,
    734     GLenum /* pname */,
    735     GLint* /* params */) {
    736   return false;
    737 }
    738 
    739 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
    740     GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
    741   return false;
    742 }
    743 
    744 inline bool GLES2Implementation::GetShaderivHelper(
    745     GLuint /* shader */, GLenum /* pname */, GLint* /* params */) {
    746   return false;
    747 }
    748 
    749 inline bool GLES2Implementation::GetTexParameterfvHelper(
    750     GLenum /* target */, GLenum /* pname */, GLfloat* /* params */) {
    751   return false;
    752 }
    753 
    754 inline bool GLES2Implementation::GetTexParameterivHelper(
    755     GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
    756   return false;
    757 }
    758 
    759 }  // namespace gles2
    760 }  // namespace gpu
    761 
    762 #endif  // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
    763