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 CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_
      6 #define CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/callback.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/memory/weak_ptr.h"
     14 #include "content/common/content_export.h"
     15 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
     16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
     17 #include "third_party/WebKit/public/platform/WebString.h"
     18 #include "ui/gfx/native_widget_types.h"
     19 #include "ui/gl/gpu_preference.h"
     20 #include "url/gurl.h"
     21 
     22 namespace gpu {
     23 
     24 class ContextSupport;
     25 class TransferBuffer;
     26 
     27 namespace gles2 {
     28 class GLES2CmdHelper;
     29 class GLES2Implementation;
     30 class GLES2Interface;
     31 }
     32 }
     33 
     34 using blink::WebGLId;
     35 
     36 using blink::WGC3Dbyte;
     37 using blink::WGC3Dchar;
     38 using blink::WGC3Denum;
     39 using blink::WGC3Dboolean;
     40 using blink::WGC3Dbitfield;
     41 using blink::WGC3Dint;
     42 using blink::WGC3Dsizei;
     43 using blink::WGC3Duint;
     44 using blink::WGC3Dfloat;
     45 using blink::WGC3Dclampf;
     46 using blink::WGC3Dintptr;
     47 using blink::WGC3Dsizeiptr;
     48 
     49 namespace content {
     50 class GpuChannelHost;
     51 
     52 const size_t kDefaultCommandBufferSize = 1024 * 1024;
     53 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024;
     54 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024;
     55 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024;
     56 
     57 class WebGraphicsContext3DErrorMessageCallback;
     58 
     59 class WebGraphicsContext3DCommandBufferImpl
     60     : public blink::WebGraphicsContext3D {
     61  public:
     62   enum MappedMemoryReclaimLimit {
     63     kNoLimit = 0,
     64   };
     65 
     66   struct CONTENT_EXPORT SharedMemoryLimits {
     67     SharedMemoryLimits();
     68 
     69     size_t command_buffer_size;
     70     size_t start_transfer_buffer_size;
     71     size_t min_transfer_buffer_size;
     72     size_t max_transfer_buffer_size;
     73     size_t mapped_memory_reclaim_limit;
     74   };
     75 
     76   WebGraphicsContext3DCommandBufferImpl(
     77       int surface_id,
     78       const GURL& active_url,
     79       GpuChannelHost* host,
     80       const Attributes& attributes,
     81       bool bind_generates_resources,
     82       const SharedMemoryLimits& limits);
     83 
     84   virtual ~WebGraphicsContext3DCommandBufferImpl();
     85 
     86   // The following 3 IDs let one uniquely identify this context.
     87   // Gets the GPU process ID for this context.
     88   int GetGPUProcessID();
     89 
     90   CommandBufferProxyImpl* GetCommandBufferProxy() {
     91     return command_buffer_.get();
     92   }
     93 
     94   CONTENT_EXPORT gpu::ContextSupport* GetContextSupport();
     95 
     96   gpu::gles2::GLES2Implementation* GetImplementation() {
     97     return real_gl_.get();
     98   }
     99 
    100   // Return true if GPU process reported context lost or there was a
    101   // problem communicating with the GPU process.
    102   bool IsCommandBufferContextLost();
    103 
    104   // Create & initialize a WebGraphicsContext3DCommandBufferImpl.  Return NULL
    105   // on any failure.
    106   static CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl*
    107       CreateOffscreenContext(
    108           GpuChannelHost* host,
    109           const WebGraphicsContext3D::Attributes& attributes,
    110           const GURL& active_url,
    111           const SharedMemoryLimits& limits);
    112 
    113   size_t GetMappedMemoryLimit() {
    114     return mem_limits_.mapped_memory_reclaim_limit;
    115   }
    116 
    117   //----------------------------------------------------------------------
    118   // WebGraphicsContext3D methods
    119 
    120   // Must be called after initialize() and before any of the following methods.
    121   // Permanently binds to the first calling thread. Returns false if the
    122   // graphics context fails to create. Do not call from more than one thread.
    123   virtual bool makeContextCurrent();
    124 
    125   virtual uint32_t lastFlushID();
    126 
    127   virtual unsigned int insertSyncPoint();
    128   virtual void waitSyncPoint(unsigned int sync_point);
    129 
    130   virtual void loseContextCHROMIUM(WGC3Denum current, WGC3Denum other);
    131 
    132   virtual void reshapeWithScaleFactor(
    133       int width, int height, float scale_factor);
    134 
    135   virtual void prepareTexture();
    136   virtual void postSubBufferCHROMIUM(int x, int y, int width, int height);
    137 
    138   virtual void activeTexture(WGC3Denum texture);
    139   virtual void attachShader(WebGLId program, WebGLId shader);
    140   virtual void bindAttribLocation(WebGLId program, WGC3Duint index,
    141                                   const WGC3Dchar* name);
    142   virtual void bindBuffer(WGC3Denum target, WebGLId buffer);
    143   virtual void bindFramebuffer(WGC3Denum target, WebGLId framebuffer);
    144   virtual void bindRenderbuffer(WGC3Denum target, WebGLId renderbuffer);
    145   virtual void bindTexture(WGC3Denum target, WebGLId texture);
    146   virtual void blendColor(WGC3Dclampf red, WGC3Dclampf green,
    147                           WGC3Dclampf blue, WGC3Dclampf alpha);
    148   virtual void blendEquation(WGC3Denum mode);
    149   virtual void blendEquationSeparate(WGC3Denum modeRGB,
    150                                      WGC3Denum modeAlpha);
    151   virtual void blendFunc(WGC3Denum sfactor, WGC3Denum dfactor);
    152   virtual void blendFuncSeparate(WGC3Denum srcRGB,
    153                                  WGC3Denum dstRGB,
    154                                  WGC3Denum srcAlpha,
    155                                  WGC3Denum dstAlpha);
    156 
    157   virtual void bufferData(WGC3Denum target, WGC3Dsizeiptr size,
    158                           const void* data, WGC3Denum usage);
    159   virtual void bufferSubData(WGC3Denum target, WGC3Dintptr offset,
    160                              WGC3Dsizeiptr size, const void* data);
    161 
    162   virtual WGC3Denum checkFramebufferStatus(WGC3Denum target);
    163   virtual void clear(WGC3Dbitfield mask);
    164   virtual void clearColor(WGC3Dclampf red, WGC3Dclampf green,
    165                           WGC3Dclampf blue, WGC3Dclampf alpha);
    166   virtual void clearDepth(WGC3Dclampf depth);
    167   virtual void clearStencil(WGC3Dint s);
    168   virtual void colorMask(WGC3Dboolean red, WGC3Dboolean green,
    169                          WGC3Dboolean blue, WGC3Dboolean alpha);
    170   virtual void compileShader(WebGLId shader);
    171 
    172   virtual void compressedTexImage2D(WGC3Denum target,
    173                                     WGC3Dint level,
    174                                     WGC3Denum internalformat,
    175                                     WGC3Dsizei width,
    176                                     WGC3Dsizei height,
    177                                     WGC3Dint border,
    178                                     WGC3Dsizei imageSize,
    179                                     const void* data);
    180   virtual void compressedTexSubImage2D(WGC3Denum target,
    181                                        WGC3Dint level,
    182                                        WGC3Dint xoffset,
    183                                        WGC3Dint yoffset,
    184                                        WGC3Dsizei width,
    185                                        WGC3Dsizei height,
    186                                        WGC3Denum format,
    187                                        WGC3Dsizei imageSize,
    188                                        const void* data);
    189   virtual void copyTexImage2D(WGC3Denum target,
    190                               WGC3Dint level,
    191                               WGC3Denum internalformat,
    192                               WGC3Dint x,
    193                               WGC3Dint y,
    194                               WGC3Dsizei width,
    195                               WGC3Dsizei height,
    196                               WGC3Dint border);
    197   virtual void copyTexSubImage2D(WGC3Denum target,
    198                                  WGC3Dint level,
    199                                  WGC3Dint xoffset,
    200                                  WGC3Dint yoffset,
    201                                  WGC3Dint x,
    202                                  WGC3Dint y,
    203                                  WGC3Dsizei width,
    204                                  WGC3Dsizei height);
    205   virtual void cullFace(WGC3Denum mode);
    206   virtual void depthFunc(WGC3Denum func);
    207   virtual void depthMask(WGC3Dboolean flag);
    208   virtual void depthRange(WGC3Dclampf zNear, WGC3Dclampf zFar);
    209   virtual void detachShader(WebGLId program, WebGLId shader);
    210   virtual void disable(WGC3Denum cap);
    211   virtual void disableVertexAttribArray(WGC3Duint index);
    212   virtual void drawArrays(WGC3Denum mode, WGC3Dint first, WGC3Dsizei count);
    213   virtual void drawElements(WGC3Denum mode,
    214                             WGC3Dsizei count,
    215                             WGC3Denum type,
    216                             WGC3Dintptr offset);
    217 
    218   virtual void enable(WGC3Denum cap);
    219   virtual void enableVertexAttribArray(WGC3Duint index);
    220   virtual void finish();
    221   virtual void flush();
    222   virtual void framebufferRenderbuffer(WGC3Denum target,
    223                                        WGC3Denum attachment,
    224                                        WGC3Denum renderbuffertarget,
    225                                        WebGLId renderbuffer);
    226   virtual void framebufferTexture2D(WGC3Denum target,
    227                                     WGC3Denum attachment,
    228                                     WGC3Denum textarget,
    229                                     WebGLId texture,
    230                                     WGC3Dint level);
    231   virtual void framebufferTexture2DMultisampleEXT(WGC3Denum target,
    232                                     WGC3Denum attachment,
    233                                     WGC3Denum textarget,
    234                                     WebGLId texture,
    235                                     WGC3Dint level,
    236                                     WGC3Dsizei samples);
    237   virtual void frontFace(WGC3Denum mode);
    238   virtual void generateMipmap(WGC3Denum target);
    239 
    240   virtual bool getActiveAttrib(WebGLId program,
    241                                WGC3Duint index,
    242                                ActiveInfo&);
    243   virtual bool getActiveUniform(WebGLId program,
    244                                 WGC3Duint index,
    245                                 ActiveInfo&);
    246 
    247   virtual void getAttachedShaders(WebGLId program,
    248                                   WGC3Dsizei maxCount,
    249                                   WGC3Dsizei* count,
    250                                   WebGLId* shaders);
    251 
    252   virtual WGC3Dint  getAttribLocation(WebGLId program, const WGC3Dchar* name);
    253 
    254   virtual void getBooleanv(WGC3Denum pname, WGC3Dboolean* value);
    255 
    256   virtual void getBufferParameteriv(WGC3Denum target,
    257                                     WGC3Denum pname,
    258                                     WGC3Dint* value);
    259 
    260   virtual Attributes getContextAttributes();
    261 
    262   virtual WGC3Denum getError();
    263 
    264   virtual bool isContextLost();
    265 
    266   virtual void getFloatv(WGC3Denum pname, WGC3Dfloat* value);
    267 
    268   virtual void getFramebufferAttachmentParameteriv(WGC3Denum target,
    269                                                    WGC3Denum attachment,
    270                                                    WGC3Denum pname,
    271                                                    WGC3Dint* value);
    272 
    273   virtual void getIntegerv(WGC3Denum pname, WGC3Dint* value);
    274 
    275   virtual void getProgramiv(WebGLId program, WGC3Denum pname, WGC3Dint* value);
    276 
    277   virtual blink::WebString getProgramInfoLog(WebGLId program);
    278 
    279   virtual void getRenderbufferParameteriv(WGC3Denum target,
    280                                           WGC3Denum pname,
    281                                           WGC3Dint* value);
    282 
    283   virtual void getShaderiv(WebGLId shader, WGC3Denum pname, WGC3Dint* value);
    284 
    285   virtual blink::WebString getShaderInfoLog(WebGLId shader);
    286 
    287   virtual void getShaderPrecisionFormat(WGC3Denum shadertype,
    288                                         WGC3Denum precisiontype,
    289                                         WGC3Dint* range,
    290                                         WGC3Dint* precision);
    291 
    292   virtual blink::WebString getShaderSource(WebGLId shader);
    293   virtual blink::WebString getString(WGC3Denum name);
    294 
    295   virtual void getTexParameterfv(WGC3Denum target,
    296                                  WGC3Denum pname,
    297                                  WGC3Dfloat* value);
    298   virtual void getTexParameteriv(WGC3Denum target,
    299                                  WGC3Denum pname,
    300                                  WGC3Dint* value);
    301 
    302   virtual void getUniformfv(WebGLId program,
    303                             WGC3Dint location,
    304                             WGC3Dfloat* value);
    305   virtual void getUniformiv(WebGLId program,
    306                             WGC3Dint location,
    307                             WGC3Dint* value);
    308 
    309   virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name);
    310 
    311   virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname,
    312                                  WGC3Dfloat* value);
    313   virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname,
    314                                  WGC3Dint* value);
    315 
    316   virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname);
    317 
    318   virtual void hint(WGC3Denum target, WGC3Denum mode);
    319   virtual WGC3Dboolean isBuffer(WebGLId buffer);
    320   virtual WGC3Dboolean isEnabled(WGC3Denum cap);
    321   virtual WGC3Dboolean isFramebuffer(WebGLId framebuffer);
    322   virtual WGC3Dboolean isProgram(WebGLId program);
    323   virtual WGC3Dboolean isRenderbuffer(WebGLId renderbuffer);
    324   virtual WGC3Dboolean isShader(WebGLId shader);
    325   virtual WGC3Dboolean isTexture(WebGLId texture);
    326   virtual void lineWidth(WGC3Dfloat);
    327   virtual void linkProgram(WebGLId program);
    328   virtual void pixelStorei(WGC3Denum pname, WGC3Dint param);
    329   virtual void polygonOffset(WGC3Dfloat factor, WGC3Dfloat units);
    330 
    331   virtual void readPixels(WGC3Dint x,
    332                           WGC3Dint y,
    333                           WGC3Dsizei width,
    334                           WGC3Dsizei height,
    335                           WGC3Denum format,
    336                           WGC3Denum type,
    337                           void* pixels);
    338 
    339   virtual void releaseShaderCompiler();
    340   virtual void renderbufferStorage(WGC3Denum target,
    341                                    WGC3Denum internalformat,
    342                                    WGC3Dsizei width,
    343                                    WGC3Dsizei height);
    344   virtual void sampleCoverage(WGC3Dfloat value, WGC3Dboolean invert);
    345   virtual void scissor(WGC3Dint x, WGC3Dint y,
    346                        WGC3Dsizei width, WGC3Dsizei height);
    347   virtual void shaderSource(WebGLId shader, const WGC3Dchar* string);
    348   virtual void stencilFunc(WGC3Denum func, WGC3Dint ref, WGC3Duint mask);
    349   virtual void stencilFuncSeparate(WGC3Denum face,
    350                                    WGC3Denum func,
    351                                    WGC3Dint ref,
    352                                    WGC3Duint mask);
    353   virtual void stencilMask(WGC3Duint mask);
    354   virtual void stencilMaskSeparate(WGC3Denum face, WGC3Duint mask);
    355   virtual void stencilOp(WGC3Denum fail,
    356                          WGC3Denum zfail,
    357                          WGC3Denum zpass);
    358   virtual void stencilOpSeparate(WGC3Denum face,
    359                                  WGC3Denum fail,
    360                                  WGC3Denum zfail,
    361                                  WGC3Denum zpass);
    362 
    363   virtual void texImage2D(WGC3Denum target,
    364                           WGC3Dint level,
    365                           WGC3Denum internalformat,
    366                           WGC3Dsizei width,
    367                           WGC3Dsizei height,
    368                           WGC3Dint border,
    369                           WGC3Denum format,
    370                           WGC3Denum type,
    371                           const void* pixels);
    372 
    373   virtual void texParameterf(WGC3Denum target,
    374                              WGC3Denum pname,
    375                              WGC3Dfloat param);
    376   virtual void texParameteri(WGC3Denum target,
    377                              WGC3Denum pname,
    378                              WGC3Dint param);
    379 
    380   virtual void texSubImage2D(WGC3Denum target,
    381                              WGC3Dint level,
    382                              WGC3Dint xoffset,
    383                              WGC3Dint yoffset,
    384                              WGC3Dsizei width,
    385                              WGC3Dsizei height,
    386                              WGC3Denum format,
    387                              WGC3Denum type,
    388                              const void* pixels);
    389 
    390   virtual void uniform1f(WGC3Dint location, WGC3Dfloat x);
    391   virtual void uniform1fv(WGC3Dint location,
    392                           WGC3Dsizei count, const WGC3Dfloat* v);
    393   virtual void uniform1i(WGC3Dint location, WGC3Dint x);
    394   virtual void uniform1iv(WGC3Dint location,
    395                           WGC3Dsizei count, const WGC3Dint* v);
    396   virtual void uniform2f(WGC3Dint location, WGC3Dfloat x, WGC3Dfloat y);
    397   virtual void uniform2fv(WGC3Dint location,
    398                           WGC3Dsizei count, const WGC3Dfloat* v);
    399   virtual void uniform2i(WGC3Dint location, WGC3Dint x, WGC3Dint y);
    400   virtual void uniform2iv(WGC3Dint location,
    401                           WGC3Dsizei count, const WGC3Dint* v);
    402   virtual void uniform3f(WGC3Dint location,
    403                          WGC3Dfloat x, WGC3Dfloat y, WGC3Dfloat z);
    404   virtual void uniform3fv(WGC3Dint location,
    405                           WGC3Dsizei count, const WGC3Dfloat* v);
    406   virtual void uniform3i(WGC3Dint location,
    407                          WGC3Dint x, WGC3Dint y, WGC3Dint z);
    408   virtual void uniform3iv(WGC3Dint location,
    409                           WGC3Dsizei count, const WGC3Dint* v);
    410   virtual void uniform4f(WGC3Dint location,
    411                          WGC3Dfloat x, WGC3Dfloat y,
    412                          WGC3Dfloat z, WGC3Dfloat w);
    413   virtual void uniform4fv(WGC3Dint location,
    414                           WGC3Dsizei count, const WGC3Dfloat* v);
    415   virtual void uniform4i(WGC3Dint location,
    416                          WGC3Dint x, WGC3Dint y, WGC3Dint z, WGC3Dint w);
    417   virtual void uniform4iv(WGC3Dint location,
    418                           WGC3Dsizei count, const WGC3Dint* v);
    419   virtual void uniformMatrix2fv(WGC3Dint location,
    420                                 WGC3Dsizei count,
    421                                 WGC3Dboolean transpose,
    422                                 const WGC3Dfloat* value);
    423   virtual void uniformMatrix3fv(WGC3Dint location,
    424                                 WGC3Dsizei count,
    425                                 WGC3Dboolean transpose,
    426                                 const WGC3Dfloat* value);
    427   virtual void uniformMatrix4fv(WGC3Dint location,
    428                                 WGC3Dsizei count,
    429                                 WGC3Dboolean transpose,
    430                                 const WGC3Dfloat* value);
    431 
    432   virtual void useProgram(WebGLId program);
    433   virtual void validateProgram(WebGLId program);
    434 
    435   virtual void vertexAttrib1f(WGC3Duint index, WGC3Dfloat x);
    436   virtual void vertexAttrib1fv(WGC3Duint index, const WGC3Dfloat* values);
    437   virtual void vertexAttrib2f(WGC3Duint index, WGC3Dfloat x, WGC3Dfloat y);
    438   virtual void vertexAttrib2fv(WGC3Duint index, const WGC3Dfloat* values);
    439   virtual void vertexAttrib3f(WGC3Duint index,
    440                               WGC3Dfloat x, WGC3Dfloat y, WGC3Dfloat z);
    441   virtual void vertexAttrib3fv(WGC3Duint index, const WGC3Dfloat* values);
    442   virtual void vertexAttrib4f(WGC3Duint index,
    443                               WGC3Dfloat x, WGC3Dfloat y,
    444                               WGC3Dfloat z, WGC3Dfloat w);
    445   virtual void vertexAttrib4fv(WGC3Duint index, const WGC3Dfloat* values);
    446   virtual void vertexAttribPointer(WGC3Duint index,
    447                                    WGC3Dint size,
    448                                    WGC3Denum type,
    449                                    WGC3Dboolean normalized,
    450                                    WGC3Dsizei stride,
    451                                    WGC3Dintptr offset);
    452 
    453   virtual void viewport(WGC3Dint x, WGC3Dint y,
    454                         WGC3Dsizei width, WGC3Dsizei height);
    455 
    456   // Support for buffer creation and deletion
    457   virtual void genBuffers(WGC3Dsizei count, WebGLId* ids);
    458   virtual void genFramebuffers(WGC3Dsizei count, WebGLId* ids);
    459   virtual void genRenderbuffers(WGC3Dsizei count, WebGLId* ids);
    460   virtual void genTextures(WGC3Dsizei count, WebGLId* ids);
    461 
    462   virtual void deleteBuffers(WGC3Dsizei count, WebGLId* ids);
    463   virtual void deleteFramebuffers(WGC3Dsizei count, WebGLId* ids);
    464   virtual void deleteRenderbuffers(WGC3Dsizei count, WebGLId* ids);
    465   virtual void deleteTextures(WGC3Dsizei count, WebGLId* ids);
    466 
    467   virtual WebGLId createBuffer();
    468   virtual WebGLId createFramebuffer();
    469   virtual WebGLId createRenderbuffer();
    470   virtual WebGLId createTexture();
    471 
    472   virtual void deleteBuffer(WebGLId);
    473   virtual void deleteFramebuffer(WebGLId);
    474   virtual void deleteRenderbuffer(WebGLId);
    475   virtual void deleteTexture(WebGLId);
    476 
    477   virtual WebGLId createProgram();
    478   virtual WebGLId createShader(WGC3Denum);
    479 
    480   virtual void deleteProgram(WebGLId);
    481   virtual void deleteShader(WebGLId);
    482 
    483   virtual void synthesizeGLError(WGC3Denum);
    484 
    485   virtual void* mapBufferSubDataCHROMIUM(
    486       WGC3Denum target, WGC3Dintptr offset,
    487       WGC3Dsizeiptr size, WGC3Denum access);
    488   virtual void unmapBufferSubDataCHROMIUM(const void*);
    489   virtual void* mapTexSubImage2DCHROMIUM(
    490       WGC3Denum target,
    491       WGC3Dint level,
    492       WGC3Dint xoffset,
    493       WGC3Dint yoffset,
    494       WGC3Dsizei width,
    495       WGC3Dsizei height,
    496       WGC3Denum format,
    497       WGC3Denum type,
    498       WGC3Denum access);
    499   virtual void unmapTexSubImage2DCHROMIUM(const void*);
    500 
    501   virtual void setVisibilityCHROMIUM(bool visible);
    502 
    503   virtual void discardFramebufferEXT(WGC3Denum target,
    504                                      WGC3Dsizei numAttachments,
    505                                      const WGC3Denum* attachments);
    506   virtual void copyTextureToParentTextureCHROMIUM(
    507       WebGLId texture, WebGLId parentTexture);
    508 
    509   virtual void rateLimitOffscreenContextCHROMIUM();
    510 
    511   virtual blink::WebString getRequestableExtensionsCHROMIUM();
    512   virtual void requestExtensionCHROMIUM(const char*);
    513 
    514   virtual void blitFramebufferCHROMIUM(
    515       WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
    516       WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
    517       WGC3Dbitfield mask, WGC3Denum filter);
    518   virtual void renderbufferStorageMultisampleCHROMIUM(
    519       WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
    520       WGC3Dsizei width, WGC3Dsizei height);
    521 
    522   virtual blink::WebString getTranslatedShaderSourceANGLE(WebGLId shader);
    523 
    524   virtual void setContextLostCallback(
    525       WebGraphicsContext3D::WebGraphicsContextLostCallback* callback);
    526 
    527   virtual WGC3Denum getGraphicsResetStatusARB();
    528 
    529   virtual void setErrorMessageCallback(
    530       WebGraphicsContext3D::WebGraphicsErrorMessageCallback* callback);
    531 
    532   virtual void texImageIOSurface2DCHROMIUM(
    533       WGC3Denum target, WGC3Dint width, WGC3Dint height,
    534       WGC3Duint ioSurfaceId, WGC3Duint plane);
    535 
    536   virtual void texStorage2DEXT(
    537       WGC3Denum target, WGC3Dint levels, WGC3Duint internalformat,
    538       WGC3Dint width, WGC3Dint height);
    539 
    540   virtual WebGLId createQueryEXT();
    541   virtual void deleteQueryEXT(WebGLId query);
    542   virtual WGC3Dboolean isQueryEXT(WGC3Duint query);
    543   virtual void beginQueryEXT(WGC3Denum target, WebGLId query);
    544   virtual void endQueryEXT(WGC3Denum target);
    545   virtual void getQueryivEXT(
    546       WGC3Denum target, WGC3Denum pname, WGC3Dint* params);
    547   virtual void getQueryObjectuivEXT(
    548       WebGLId query, WGC3Denum pname, WGC3Duint* params);
    549 
    550   virtual void copyTextureCHROMIUM(WGC3Denum target, WebGLId source_id,
    551                                    WebGLId dest_id, WGC3Dint level,
    552                                    WGC3Denum internal_format,
    553                                    WGC3Denum dest_type);
    554 
    555   virtual void bindUniformLocationCHROMIUM(WebGLId program, WGC3Dint location,
    556                                            const WGC3Dchar* uniform);
    557 
    558   virtual void shallowFlushCHROMIUM();
    559   virtual void shallowFinishCHROMIUM();
    560 
    561   virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox);
    562   virtual void produceTextureCHROMIUM(WGC3Denum target,
    563                                       const WGC3Dbyte* mailbox);
    564   virtual void consumeTextureCHROMIUM(WGC3Denum target,
    565                                       const WGC3Dbyte* mailbox);
    566 
    567   virtual void insertEventMarkerEXT(const WGC3Dchar* marker);
    568   virtual void pushGroupMarkerEXT(const WGC3Dchar* marker);
    569   virtual void popGroupMarkerEXT();
    570 
    571   // GL_OES_vertex_array_object
    572   virtual WebGLId createVertexArrayOES();
    573   virtual void deleteVertexArrayOES(WebGLId array);
    574   virtual WGC3Dboolean isVertexArrayOES(WebGLId array);
    575   virtual void bindVertexArrayOES(WebGLId array);
    576 
    577   virtual void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint image_id);
    578   virtual void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint image_id);
    579 
    580   virtual WebGLId createStreamTextureCHROMIUM(WebGLId texture);
    581   virtual void destroyStreamTextureCHROMIUM(WebGLId texture);
    582 
    583   virtual void* mapBufferCHROMIUM(WGC3Denum target, WGC3Denum access);
    584   virtual WGC3Dboolean unmapBufferCHROMIUM(WGC3Denum target);
    585 
    586   // Async pixel transfer functions.
    587   virtual void asyncTexImage2DCHROMIUM(
    588       WGC3Denum target,
    589       WGC3Dint level,
    590       WGC3Denum internalformat,
    591       WGC3Dsizei width,
    592       WGC3Dsizei height,
    593       WGC3Dint border,
    594       WGC3Denum format,
    595       WGC3Denum type,
    596       const void* pixels);
    597   virtual void asyncTexSubImage2DCHROMIUM(
    598       WGC3Denum target,
    599       WGC3Dint level,
    600       WGC3Dint xoffset,
    601       WGC3Dint yoffset,
    602       WGC3Dsizei width,
    603       WGC3Dsizei height,
    604       WGC3Denum format,
    605       WGC3Denum type,
    606       const void* pixels);
    607   virtual void waitAsyncTexImage2DCHROMIUM(WGC3Denum target);
    608 
    609   // GL_EXT_draw_buffers
    610   virtual void drawBuffersEXT(
    611       WGC3Dsizei n,
    612       const WGC3Denum* bufs);
    613 
    614   // GL_ANGLE_instanced_arrays
    615   virtual void drawArraysInstancedANGLE(WGC3Denum mode, WGC3Dint first,
    616       WGC3Dsizei count, WGC3Dsizei primcount);
    617   virtual void drawElementsInstancedANGLE(WGC3Denum mode, WGC3Dsizei count,
    618       WGC3Denum type, WGC3Dintptr offset, WGC3Dsizei primcount);
    619   virtual void vertexAttribDivisorANGLE(WGC3Duint index, WGC3Duint divisor);
    620 
    621   // GL_CHROMIUM_map_image
    622   virtual WGC3Duint createImageCHROMIUM(
    623       WGC3Dsizei width, WGC3Dsizei height, WGC3Denum internalformat);
    624   virtual void destroyImageCHROMIUM(WGC3Duint image_id);
    625   virtual void getImageParameterivCHROMIUM(
    626       WGC3Duint image_id, WGC3Denum pname, WGC3Dint* params);
    627   virtual void* mapImageCHROMIUM(WGC3Duint image_id, WGC3Denum access);
    628   virtual void unmapImageCHROMIUM(WGC3Duint image_id);
    629 
    630   virtual GrGLInterface* createGrGLInterface();
    631 
    632  private:
    633   // These are the same error codes as used by EGL.
    634   enum Error {
    635     SUCCESS               = 0x3000,
    636     BAD_ATTRIBUTE         = 0x3004,
    637     CONTEXT_LOST          = 0x300E
    638   };
    639   // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
    640   // the 16-bit range are the same as used by EGL. Those outside the 16-bit
    641   // range are unique to Chromium. Attributes are matched using a closest fit
    642   // algorithm.
    643   // Changes to this enum should also be copied to
    644   // gpu/command_buffer/common/gles2_cmd_utils.cc and to
    645   // gpu/command_buffer/client/gl_in_process_context.cc
    646   enum Attribute {
    647     ALPHA_SIZE                = 0x3021,
    648     BLUE_SIZE                 = 0x3022,
    649     GREEN_SIZE                = 0x3023,
    650     RED_SIZE                  = 0x3024,
    651     DEPTH_SIZE                = 0x3025,
    652     STENCIL_SIZE              = 0x3026,
    653     SAMPLES                   = 0x3031,
    654     SAMPLE_BUFFERS            = 0x3032,
    655     HEIGHT                    = 0x3056,
    656     WIDTH                     = 0x3057,
    657     NONE                      = 0x3038,  // Attrib list = terminator
    658     SHARE_RESOURCES           = 0x10000,
    659     BIND_GENERATES_RESOURCES  = 0x10001,
    660     FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002
    661   };
    662   friend class WebGraphicsContext3DErrorMessageCallback;
    663 
    664   // Initialize the underlying GL context. May be called multiple times; second
    665   // and subsequent calls are ignored. Must be called from the thread that is
    666   // going to use this object to issue GL commands (which might not be the main
    667   // thread).
    668   bool MaybeInitializeGL();
    669 
    670   bool InitializeCommandBuffer(bool onscreen);
    671 
    672   void Destroy();
    673 
    674   // Create a CommandBufferProxy that renders directly to a view. The view and
    675   // the associated window must not be destroyed until the returned
    676   // CommandBufferProxy has been destroyed, otherwise the GPU process might
    677   // attempt to render to an invalid window handle.
    678   //
    679   // NOTE: on Mac OS X, this entry point is only used to set up the
    680   // accelerated compositor's output. On this platform, we actually pass
    681   // a gfx::PluginWindowHandle in place of the gfx::NativeViewId,
    682   // because the facility to allocate a fake PluginWindowHandle is
    683   // already in place. We could add more entry points and messages to
    684   // allocate both fake PluginWindowHandles and NativeViewIds and map
    685   // from fake NativeViewIds to PluginWindowHandles, but this seems like
    686   // unnecessary complexity at the moment.
    687   bool CreateContext(bool onscreen);
    688 
    689   virtual void OnGpuChannelLost();
    690   virtual void OnErrorMessage(const std::string& message, int id);
    691 
    692   bool initialize_failed_;
    693 
    694   bool visible_;
    695 
    696   // State needed by MaybeInitializeGL.
    697   scoped_refptr<GpuChannelHost> host_;
    698   int32 surface_id_;
    699   GURL active_url_;
    700 
    701   WebGraphicsContext3D::WebGraphicsContextLostCallback* context_lost_callback_;
    702   WGC3Denum context_lost_reason_;
    703 
    704   WebGraphicsContext3D::WebGraphicsErrorMessageCallback*
    705       error_message_callback_;
    706   scoped_ptr<WebGraphicsContext3DErrorMessageCallback>
    707       client_error_message_callback_;
    708 
    709   blink::WebGraphicsContext3D::Attributes attributes_;
    710   gfx::GpuPreference gpu_preference_;
    711 
    712   // Errors raised by synthesizeGLError().
    713   std::vector<WGC3Denum> synthetic_errors_;
    714 
    715   base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_;
    716 
    717   bool initialized_;
    718   scoped_ptr<CommandBufferProxyImpl> command_buffer_;
    719   scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_;
    720   scoped_ptr<gpu::TransferBuffer> transfer_buffer_;
    721   gpu::gles2::GLES2Interface* gl_;
    722   scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_;
    723   scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_;
    724   Error last_error_;
    725   bool bind_generates_resources_;
    726   SharedMemoryLimits mem_limits_;
    727 
    728   uint32_t flush_id_;
    729 };
    730 
    731 }  // namespace content
    732 
    733 #endif  // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_
    734