Home | History | Annotate | Download | only in gpu
      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 #include "webkit/common/gpu/webgraphicscontext3d_impl.h"
      6 
      7 #include "base/atomicops.h"
      8 #include "base/lazy_instance.h"
      9 #include "base/logging.h"
     10 #include "gpu/GLES2/gl2extchromium.h"
     11 #include "gpu/command_buffer/client/gles2_implementation.h"
     12 #include "gpu/command_buffer/client/gles2_lib.h"
     13 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
     14 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
     15 
     16 #include "third_party/khronos/GLES2/gl2.h"
     17 #ifndef GL_GLEXT_PROTOTYPES
     18 #define GL_GLEXT_PROTOTYPES 1
     19 #endif
     20 #include "third_party/khronos/GLES2/gl2ext.h"
     21 
     22 namespace webkit {
     23 namespace gpu {
     24 
     25 namespace {
     26 
     27 uint32_t GenFlushID() {
     28   static base::subtle::Atomic32 flush_id = 0;
     29 
     30   base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
     31       &flush_id, 1);
     32   return static_cast<uint32_t>(my_id);
     33 }
     34 
     35 } // namespace anonymous
     36 
     37 class WebGraphicsContext3DErrorMessageCallback
     38     : public ::gpu::gles2::GLES2ImplementationErrorMessageCallback {
     39  public:
     40   WebGraphicsContext3DErrorMessageCallback(
     41       WebGraphicsContext3DImpl* context)
     42       : graphics_context_(context) {
     43   }
     44 
     45   virtual void OnErrorMessage(const char* msg, int id) OVERRIDE;
     46 
     47  private:
     48   WebGraphicsContext3DImpl* graphics_context_;
     49 
     50   DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
     51 };
     52 
     53 void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
     54     const char* msg, int id) {
     55   graphics_context_->OnErrorMessage(msg, id);
     56 }
     57 
     58 // Helper macros to reduce the amount of code.
     59 
     60 #define DELEGATE_TO_GL(name, glname)                                    \
     61 void WebGraphicsContext3DImpl::name() {                                 \
     62   gl_->glname();                                                        \
     63 }
     64 
     65 #define DELEGATE_TO_GL_R(name, glname, rt)                              \
     66 rt WebGraphicsContext3DImpl::name() {                                   \
     67   return gl_->glname();                                                 \
     68 }
     69 
     70 #define DELEGATE_TO_GL_1(name, glname, t1)                              \
     71 void WebGraphicsContext3DImpl::name(t1 a1) {                            \
     72   gl_->glname(a1);                                                      \
     73 }
     74 
     75 #define DELEGATE_TO_GL_1R(name, glname, t1, rt)                         \
     76 rt WebGraphicsContext3DImpl::name(t1 a1) {                              \
     77   return gl_->glname(a1);                                               \
     78 }
     79 
     80 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt)                        \
     81 rt WebGraphicsContext3DImpl::name(t1 a1) {                              \
     82   return gl_->glname(a1) ? true : false;                                \
     83 }
     84 
     85 #define DELEGATE_TO_GL_2(name, glname, t1, t2)                          \
     86 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2) {                     \
     87   gl_->glname(a1, a2);                                                  \
     88 }
     89 
     90 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt)                     \
     91 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2) {                       \
     92   return gl_->glname(a1, a2);                                           \
     93 }
     94 
     95 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3)                      \
     96 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) {              \
     97   gl_->glname(a1, a2, a3);                                              \
     98 }
     99 
    100 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt)                 \
    101 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) {                \
    102   return gl_->glname(a1, a2, a3);                                       \
    103 }
    104 
    105 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4)                  \
    106 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) {       \
    107   gl_->glname(a1, a2, a3, a4);                                          \
    108 }
    109 
    110 #define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt)             \
    111 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) {         \
    112   return gl_->glname(a1, a2, a3, a4);                                   \
    113 }
    114 
    115 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5)              \
    116 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {\
    117                                                                         \
    118   gl_->glname(a1, a2, a3, a4, a5);                                      \
    119 }
    120 
    121 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6)          \
    122 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5,  \
    123                                     t6 a6) {                            \
    124   gl_->glname(a1, a2, a3, a4, a5, a6);                                  \
    125 }
    126 
    127 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7)      \
    128 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5,  \
    129                                     t6 a6, t7 a7) {                     \
    130   gl_->glname(a1, a2, a3, a4, a5, a6, a7);                              \
    131 }
    132 
    133 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8)  \
    134 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5,  \
    135                                     t6 a6, t7 a7, t8 a8) {              \
    136   gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8);                          \
    137 }
    138 
    139 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
    140 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5,  \
    141                                     t6 a6, t7 a7, t8 a8, t9 a9) {       \
    142   gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9);                      \
    143 }
    144 
    145 #define DELEGATE_TO_GL_9R(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
    146                           t9, rt)                                       \
    147 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5,    \
    148                                     t6 a6, t7 a7, t8 a8, t9 a9) {       \
    149   return gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9);               \
    150 }
    151 
    152 WebGraphicsContext3DImpl::WebGraphicsContext3DImpl()
    153     : initialized_(false),
    154       initialize_failed_(false),
    155       context_lost_callback_(0),
    156       context_lost_reason_(GL_NO_ERROR),
    157       error_message_callback_(0),
    158       gl_(NULL),
    159       flush_id_(0) {
    160 }
    161 
    162 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() {
    163 
    164 }
    165 
    166 void WebGraphicsContext3DImpl::synthesizeGLError(WGC3Denum error) {
    167   if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
    168       synthetic_errors_.end()) {
    169     synthetic_errors_.push_back(error);
    170   }
    171 }
    172 
    173 uint32_t WebGraphicsContext3DImpl::lastFlushID() {
    174   return flush_id_;
    175 }
    176 
    177 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int)
    178 
    179 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
    180 
    181 DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum,
    182                   WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*)
    183 
    184 DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM,
    185                  const void*)
    186 
    187 DELEGATE_TO_GL_9R(mapTexSubImage2DCHROMIUM, MapTexSubImage2DCHROMIUM, WGC3Denum,
    188                   WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
    189                   WGC3Denum, WGC3Denum, WGC3Denum, void*)
    190 
    191 DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM,
    192                  const void*)
    193 
    194 DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum,
    195                  WGC3Dsizei, const WGC3Denum*)
    196 
    197 blink::WebString WebGraphicsContext3DImpl::
    198     getRequestableExtensionsCHROMIUM() {
    199   return blink::WebString::fromUTF8(
    200       gl_->GetRequestableExtensionsCHROMIUM());
    201 }
    202 
    203 DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM,
    204                  const char*)
    205 
    206 void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM(
    207     WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
    208     WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
    209     WGC3Dbitfield mask, WGC3Denum filter) {
    210   gl_->BlitFramebufferCHROMIUM(
    211       srcX0, srcY0, srcX1, srcY1,
    212       dstX0, dstY0, dstX1, dstY1,
    213       mask, filter);
    214 }
    215 
    216 DELEGATE_TO_GL_5(renderbufferStorageMultisampleCHROMIUM,
    217                  RenderbufferStorageMultisampleCHROMIUM, WGC3Denum, WGC3Dsizei,
    218                  WGC3Denum, WGC3Dsizei, WGC3Dsizei)
    219 
    220 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
    221 
    222 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
    223 
    224 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
    225                  WGC3Duint, const WGC3Dchar*)
    226 
    227 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
    228 
    229 DELEGATE_TO_GL_2(bindFramebuffer, BindFramebuffer, WGC3Denum, WebGLId)
    230 
    231 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
    232 
    233 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
    234 
    235 DELEGATE_TO_GL_4(blendColor, BlendColor,
    236                  WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
    237 
    238 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
    239 
    240 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
    241                  WGC3Denum, WGC3Denum)
    242 
    243 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
    244 
    245 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
    246                  WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
    247 
    248 DELEGATE_TO_GL_4(bufferData, BufferData,
    249                  WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
    250 
    251 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
    252                  WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
    253 
    254 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
    255                   WGC3Denum, WGC3Denum)
    256 
    257 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
    258 
    259 DELEGATE_TO_GL_4(clearColor, ClearColor,
    260                  WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
    261 
    262 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
    263 
    264 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
    265 
    266 DELEGATE_TO_GL_4(colorMask, ColorMask,
    267                  WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
    268 
    269 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
    270 
    271 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
    272                  WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
    273                  WGC3Dsizei, WGC3Dsizei, const void*)
    274 
    275 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
    276                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
    277                  WGC3Denum, WGC3Dsizei, const void*)
    278 
    279 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
    280                  WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
    281                  WGC3Dsizei, WGC3Dsizei, WGC3Dint)
    282 
    283 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
    284                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
    285                  WGC3Dsizei, WGC3Dsizei)
    286 
    287 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
    288 
    289 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
    290 
    291 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
    292 
    293 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
    294 
    295 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
    296 
    297 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
    298 
    299 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
    300                  WGC3Duint)
    301 
    302 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
    303 
    304 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode,
    305                                                          WGC3Dsizei count,
    306                                                          WGC3Denum type,
    307                                                          WGC3Dintptr offset) {
    308   gl_->DrawElements(
    309       mode, count, type,
    310       reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
    311 }
    312 
    313 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
    314 
    315 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
    316                  WGC3Duint)
    317 
    318 void WebGraphicsContext3DImpl::finish() {
    319   flush_id_ = GenFlushID();
    320   gl_->Finish();
    321 }
    322 
    323 void WebGraphicsContext3DImpl::flush() {
    324   flush_id_ = GenFlushID();
    325   gl_->Flush();
    326 }
    327 
    328 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
    329                  WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
    330 
    331 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
    332                  WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
    333 
    334 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
    335 
    336 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
    337 
    338 bool WebGraphicsContext3DImpl::getActiveAttrib(
    339     WebGLId program, WGC3Duint index, ActiveInfo& info) {
    340   if (!program) {
    341     synthesizeGLError(GL_INVALID_VALUE);
    342     return false;
    343   }
    344   GLint max_name_length = -1;
    345   gl_->GetProgramiv(
    346       program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
    347   if (max_name_length < 0)
    348     return false;
    349   scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
    350   if (!name) {
    351     synthesizeGLError(GL_OUT_OF_MEMORY);
    352     return false;
    353   }
    354   GLsizei length = 0;
    355   GLint size = -1;
    356   GLenum type = 0;
    357   gl_->GetActiveAttrib(
    358       program, index, max_name_length, &length, &size, &type, name.get());
    359   if (size < 0) {
    360     return false;
    361   }
    362   info.name = blink::WebString::fromUTF8(name.get(), length);
    363   info.type = type;
    364   info.size = size;
    365   return true;
    366 }
    367 
    368 bool WebGraphicsContext3DImpl::getActiveUniform(
    369     WebGLId program, WGC3Duint index, ActiveInfo& info) {
    370   GLint max_name_length = -1;
    371   gl_->GetProgramiv(
    372       program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
    373   if (max_name_length < 0)
    374     return false;
    375   scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
    376   if (!name) {
    377     synthesizeGLError(GL_OUT_OF_MEMORY);
    378     return false;
    379   }
    380   GLsizei length = 0;
    381   GLint size = -1;
    382   GLenum type = 0;
    383   gl_->GetActiveUniform(
    384       program, index, max_name_length, &length, &size, &type, name.get());
    385   if (size < 0) {
    386     return false;
    387   }
    388   info.name = blink::WebString::fromUTF8(name.get(), length);
    389   info.type = type;
    390   info.size = size;
    391   return true;
    392 }
    393 
    394 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
    395                  WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
    396 
    397 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
    398                   WebGLId, const WGC3Dchar*, WGC3Dint)
    399 
    400 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
    401 
    402 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
    403                  WGC3Denum, WGC3Denum, WGC3Dint*)
    404 
    405 WGC3Denum WebGraphicsContext3DImpl::getError() {
    406   if (!synthetic_errors_.empty()) {
    407     std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
    408     WGC3Denum err = *iter;
    409     synthetic_errors_.erase(iter);
    410     return err;
    411   }
    412 
    413   return gl_->GetError();
    414 }
    415 
    416 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
    417 
    418 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
    419                  GetFramebufferAttachmentParameteriv,
    420                  WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
    421 
    422 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
    423 
    424 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
    425 
    426 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
    427     WebGLId program) {
    428   GLint logLength = 0;
    429   gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
    430   if (!logLength)
    431     return blink::WebString();
    432   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
    433   if (!log)
    434     return blink::WebString();
    435   GLsizei returnedLogLength = 0;
    436   gl_->GetProgramInfoLog(
    437       program, logLength, &returnedLogLength, log.get());
    438   DCHECK_EQ(logLength, returnedLogLength + 1);
    439   blink::WebString res =
    440       blink::WebString::fromUTF8(log.get(), returnedLogLength);
    441   return res;
    442 }
    443 
    444 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
    445                  WGC3Denum, WGC3Denum, WGC3Dint*)
    446 
    447 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
    448 
    449 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
    450     WebGLId shader) {
    451   GLint logLength = 0;
    452   gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
    453   if (!logLength)
    454     return blink::WebString();
    455   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
    456   if (!log)
    457     return blink::WebString();
    458   GLsizei returnedLogLength = 0;
    459   gl_->GetShaderInfoLog(
    460       shader, logLength, &returnedLogLength, log.get());
    461   DCHECK_EQ(logLength, returnedLogLength + 1);
    462   blink::WebString res =
    463       blink::WebString::fromUTF8(log.get(), returnedLogLength);
    464   return res;
    465 }
    466 
    467 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
    468                  WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
    469 
    470 blink::WebString WebGraphicsContext3DImpl::getShaderSource(
    471     WebGLId shader) {
    472   GLint logLength = 0;
    473   gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
    474   if (!logLength)
    475     return blink::WebString();
    476   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
    477   if (!log)
    478     return blink::WebString();
    479   GLsizei returnedLogLength = 0;
    480   gl_->GetShaderSource(
    481       shader, logLength, &returnedLogLength, log.get());
    482   if (!returnedLogLength)
    483     return blink::WebString();
    484   DCHECK_EQ(logLength, returnedLogLength + 1);
    485   blink::WebString res =
    486       blink::WebString::fromUTF8(log.get(), returnedLogLength);
    487   return res;
    488 }
    489 
    490 blink::WebString WebGraphicsContext3DImpl::
    491     getTranslatedShaderSourceANGLE(WebGLId shader) {
    492   GLint logLength = 0;
    493   gl_->GetShaderiv(
    494       shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
    495   if (!logLength)
    496     return blink::WebString();
    497   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
    498   if (!log)
    499     return blink::WebString();
    500   GLsizei returnedLogLength = 0;
    501   gl_->GetTranslatedShaderSourceANGLE(
    502       shader, logLength, &returnedLogLength, log.get());
    503   if (!returnedLogLength)
    504     return blink::WebString();
    505   DCHECK_EQ(logLength, returnedLogLength + 1);
    506   blink::WebString res =
    507       blink::WebString::fromUTF8(log.get(), returnedLogLength);
    508   return res;
    509 }
    510 
    511 blink::WebString WebGraphicsContext3DImpl::getString(
    512     WGC3Denum name) {
    513   return blink::WebString::fromUTF8(
    514       reinterpret_cast<const char*>(gl_->GetString(name)));
    515 }
    516 
    517 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
    518                  WGC3Denum, WGC3Denum, WGC3Dfloat*)
    519 
    520 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
    521                  WGC3Denum, WGC3Denum, WGC3Dint*)
    522 
    523 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
    524 
    525 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
    526 
    527 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
    528                   WebGLId, const WGC3Dchar*, WGC3Dint)
    529 
    530 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
    531                  WGC3Duint, WGC3Denum, WGC3Dfloat*)
    532 
    533 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
    534                  WGC3Duint, WGC3Denum, WGC3Dint*)
    535 
    536 WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
    537     WGC3Duint index, WGC3Denum pname) {
    538   GLvoid* value = NULL;
    539   // NOTE: If pname is ever a value that returns more then 1 element
    540   // this will corrupt memory.
    541   gl_->GetVertexAttribPointerv(index, pname, &value);
    542   return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
    543 }
    544 
    545 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
    546 
    547 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
    548 
    549 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
    550 
    551 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
    552 
    553 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
    554 
    555 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
    556 
    557 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
    558 
    559 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
    560 
    561 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
    562 
    563 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
    564 
    565 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
    566 
    567 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
    568 
    569 DELEGATE_TO_GL_7(readPixels, ReadPixels,
    570                  WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
    571                  WGC3Denum, void*)
    572 
    573 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
    574                  WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
    575 
    576 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
    577 
    578 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
    579 
    580 void WebGraphicsContext3DImpl::shaderSource(
    581     WebGLId shader, const WGC3Dchar* string) {
    582   GLint length = strlen(string);
    583   gl_->ShaderSource(shader, 1, &string, &length);
    584 }
    585 
    586 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
    587 
    588 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
    589                  WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
    590 
    591 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
    592 
    593 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
    594                  WGC3Denum, WGC3Duint)
    595 
    596 DELEGATE_TO_GL_3(stencilOp, StencilOp,
    597                  WGC3Denum, WGC3Denum, WGC3Denum)
    598 
    599 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
    600                  WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
    601 
    602 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
    603                  WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
    604                  WGC3Dint, WGC3Denum, WGC3Denum, const void*)
    605 
    606 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
    607                  WGC3Denum, WGC3Denum, WGC3Dfloat);
    608 
    609 static const unsigned int kTextureWrapR = 0x8072;
    610 
    611 void WebGraphicsContext3DImpl::texParameteri(
    612     WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
    613   // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
    614   // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
    615   // edge of cube maps, and, if it is, push it into the GLES2 service
    616   // side code.
    617   if (pname == kTextureWrapR) {
    618     return;
    619   }
    620   gl_->TexParameteri(target, pname, param);
    621 }
    622 
    623 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
    624                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
    625                  WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
    626 
    627 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
    628 
    629 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
    630                  const WGC3Dfloat*)
    631 
    632 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
    633 
    634 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
    635 
    636 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
    637 
    638 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
    639                  const WGC3Dfloat*)
    640 
    641 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
    642 
    643 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
    644 
    645 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
    646                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
    647 
    648 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
    649                  const WGC3Dfloat*)
    650 
    651 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
    652 
    653 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
    654 
    655 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
    656                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
    657 
    658 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
    659                  const WGC3Dfloat*)
    660 
    661 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
    662                  WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
    663 
    664 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
    665 
    666 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
    667                  WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
    668 
    669 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
    670                  WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
    671 
    672 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
    673                  WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
    674 
    675 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
    676 
    677 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
    678 
    679 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
    680 
    681 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
    682                  const WGC3Dfloat*)
    683 
    684 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
    685                  WGC3Dfloat, WGC3Dfloat)
    686 
    687 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
    688                  const WGC3Dfloat*)
    689 
    690 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
    691                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
    692 
    693 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
    694                  const WGC3Dfloat*)
    695 
    696 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
    697                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
    698 
    699 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
    700                  const WGC3Dfloat*)
    701 
    702 void WebGraphicsContext3DImpl::vertexAttribPointer(
    703     WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
    704     WGC3Dsizei stride, WGC3Dintptr offset) {
    705   gl_->VertexAttribPointer(
    706       index, size, type, normalized, stride,
    707       reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
    708 }
    709 
    710 DELEGATE_TO_GL_4(viewport, Viewport,
    711                  WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
    712 
    713 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
    714 
    715 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
    716 
    717 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
    718 
    719 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
    720 
    721 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
    722 
    723 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
    724 
    725 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
    726                  WebGLId*);
    727 
    728 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
    729 
    730 WebGLId WebGraphicsContext3DImpl::createBuffer() {
    731   GLuint o;
    732   gl_->GenBuffers(1, &o);
    733   return o;
    734 }
    735 
    736 WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
    737   GLuint o = 0;
    738   gl_->GenFramebuffers(1, &o);
    739   return o;
    740 }
    741 
    742 WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
    743   GLuint o;
    744   gl_->GenRenderbuffers(1, &o);
    745   return o;
    746 }
    747 
    748 WebGLId WebGraphicsContext3DImpl::createTexture() {
    749   GLuint o;
    750   gl_->GenTextures(1, &o);
    751   return o;
    752 }
    753 
    754 void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
    755   gl_->DeleteBuffers(1, &buffer);
    756 }
    757 
    758 void WebGraphicsContext3DImpl::deleteFramebuffer(
    759     WebGLId framebuffer) {
    760   gl_->DeleteFramebuffers(1, &framebuffer);
    761 }
    762 
    763 void WebGraphicsContext3DImpl::deleteRenderbuffer(
    764     WebGLId renderbuffer) {
    765   gl_->DeleteRenderbuffers(1, &renderbuffer);
    766 }
    767 
    768 void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
    769   gl_->DeleteTextures(1, &texture);
    770 }
    771 
    772 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
    773 
    774 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
    775 
    776 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
    777 
    778 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
    779 
    780 void WebGraphicsContext3DImpl::setErrorMessageCallback(
    781     WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
    782   error_message_callback_ = cb;
    783 }
    784 
    785 void WebGraphicsContext3DImpl::setContextLostCallback(
    786     WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
    787   context_lost_callback_ = cb;
    788 }
    789 
    790 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
    791                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
    792 
    793 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
    794                  WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
    795 
    796 WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
    797   GLuint o;
    798   gl_->GenQueriesEXT(1, &o);
    799   return o;
    800 }
    801 
    802 void WebGraphicsContext3DImpl::deleteQueryEXT(
    803     WebGLId query) {
    804   gl_->DeleteQueriesEXT(1, &query);
    805 }
    806 
    807 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
    808 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
    809 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
    810 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
    811 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
    812                  WebGLId, WGC3Denum, WGC3Duint*)
    813 
    814 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM,  WGC3Denum,
    815                  WebGLId, WebGLId, WGC3Dint, WGC3Denum, WGC3Denum);
    816 
    817 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
    818                  WebGLId, WGC3Dint, const WGC3Dchar*)
    819 
    820 void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
    821   flush_id_ = GenFlushID();
    822   gl_->ShallowFlushCHROMIUM();
    823 }
    824 
    825 void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
    826   flush_id_ = GenFlushID();
    827   gl_->ShallowFinishCHROMIUM();
    828 }
    829 
    830 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
    831 
    832 void WebGraphicsContext3DImpl::loseContextCHROMIUM(
    833     WGC3Denum current, WGC3Denum other) {
    834   gl_->LoseContextCHROMIUM(current, other);
    835   gl_->Flush();
    836 }
    837 
    838 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
    839 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
    840                  WGC3Denum, const WGC3Dbyte*)
    841 DELEGATE_TO_GL_3(produceTextureDirectCHROMIUM, ProduceTextureDirectCHROMIUM,
    842                  WebGLId, WGC3Denum, const WGC3Dbyte*)
    843 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
    844                  WGC3Denum, const WGC3Dbyte*)
    845 DELEGATE_TO_GL_2R(createAndConsumeTextureCHROMIUM,
    846                   CreateAndConsumeTextureCHROMIUM,
    847                   WGC3Denum, const WGC3Dbyte*, WebGLId)
    848 
    849 void WebGraphicsContext3DImpl::insertEventMarkerEXT(
    850     const WGC3Dchar* marker) {
    851   gl_->InsertEventMarkerEXT(0, marker);
    852 }
    853 
    854 void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
    855     const WGC3Dchar* marker) {
    856   gl_->PushGroupMarkerEXT(0, marker);
    857 }
    858 
    859 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
    860 
    861 WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
    862   GLuint array;
    863   gl_->GenVertexArraysOES(1, &array);
    864   return array;
    865 }
    866 
    867 void WebGraphicsContext3DImpl::deleteVertexArrayOES(
    868     WebGLId array) {
    869   gl_->DeleteVertexArraysOES(1, &array);
    870 }
    871 
    872 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
    873 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
    874 
    875 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
    876                  WGC3Denum, WGC3Dint)
    877 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
    878                  WGC3Denum, WGC3Dint)
    879 
    880 DELEGATE_TO_GL_2R(mapBufferCHROMIUM, MapBufferCHROMIUM, WGC3Denum, WGC3Denum,
    881                   void*)
    882 DELEGATE_TO_GL_1R(unmapBufferCHROMIUM, UnmapBufferCHROMIUM, WGC3Denum,
    883                   WGC3Dboolean)
    884 
    885 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, WGC3Denum,
    886                  WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
    887                  WGC3Denum, WGC3Denum, const void*)
    888 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
    889                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
    890                  WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
    891 
    892 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
    893                  WGC3Denum)
    894 
    895 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
    896 
    897 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
    898                  WGC3Dint, WGC3Dsizei, WGC3Dsizei)
    899 
    900 void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
    901     WGC3Denum mode,
    902     WGC3Dsizei count,
    903     WGC3Denum type,
    904     WGC3Dintptr offset,
    905     WGC3Dsizei primcount) {
    906   gl_->DrawElementsInstancedANGLE(
    907       mode, count, type,
    908       reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
    909 }
    910 
    911 DELEGATE_TO_GL_2(vertexAttribDivisorANGLE, VertexAttribDivisorANGLE, WGC3Duint,
    912                  WGC3Duint)
    913 
    914 DELEGATE_TO_GL_4R(createImageCHROMIUM,
    915                   CreateImageCHROMIUM,
    916                   WGC3Dsizei,
    917                   WGC3Dsizei,
    918                   WGC3Denum,
    919                   WGC3Denum,
    920                   WGC3Duint);
    921 
    922 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
    923 
    924 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM,
    925                  WGC3Duint, WGC3Denum, GLint*);
    926 
    927 DELEGATE_TO_GL_1R(mapImageCHROMIUM, MapImageCHROMIUM, WGC3Duint, void*);
    928 
    929 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
    930 
    931 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
    932                  FramebufferTexture2DMultisampleEXT,
    933                  WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
    934 
    935 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
    936                  RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
    937                  WGC3Denum, WGC3Dsizei, WGC3Dsizei)
    938 
    939 GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
    940   return skia_bindings::CreateCommandBufferSkiaGLBinding();
    941 }
    942 
    943 ::gpu::gles2::GLES2ImplementationErrorMessageCallback*
    944     WebGraphicsContext3DImpl::getErrorMessageCallback() {
    945   if (!client_error_message_callback_) {
    946     client_error_message_callback_.reset(
    947         new WebGraphicsContext3DErrorMessageCallback(this));
    948   }
    949   return client_error_message_callback_.get();
    950 }
    951 
    952 void WebGraphicsContext3DImpl::OnErrorMessage(
    953     const std::string& message, int id) {
    954   if (error_message_callback_) {
    955     blink::WebString str = blink::WebString::fromUTF8(message.c_str());
    956     error_message_callback_->onErrorMessage(str, id);
    957   }
    958 }
    959 
    960 // TODO(bajones): Look into removing these functions from the blink interface
    961 void WebGraphicsContext3DImpl::prepareTexture() {
    962   NOTREACHED();
    963 }
    964 
    965 void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
    966     int x, int y, int width, int height) {
    967   NOTREACHED();
    968 }
    969 
    970 void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
    971     bool visible) {
    972   NOTREACHED();
    973 }
    974 
    975 void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
    976     WebGLId texture, WebGLId parentTexture) {
    977   NOTIMPLEMENTED();
    978 }
    979 
    980 void WebGraphicsContext3DImpl::releaseShaderCompiler() {
    981 }
    982 
    983 // static
    984 void WebGraphicsContext3DImpl::ConvertAttributes(
    985     const blink::WebGraphicsContext3D::Attributes& attributes,
    986     ::gpu::gles2::ContextCreationAttribHelper* output_attribs) {
    987   output_attribs->alpha_size = attributes.alpha ? 8 : 0;
    988   output_attribs->depth_size = attributes.depth ? 24 : 0;
    989   output_attribs->stencil_size = attributes.stencil ? 8 : 0;
    990   output_attribs->samples = attributes.antialias ? 4 : 0;
    991   output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
    992   output_attribs->fail_if_major_perf_caveat =
    993       attributes.failIfMajorPerformanceCaveat;
    994   output_attribs->bind_generates_resource = false;
    995 }
    996 
    997 }  // namespace gpu
    998 }  // namespace webkit
    999