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