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