- add sources.
[platform/framework/web/crosswalk.git] / src / webkit / common / gpu / webgraphicscontext3d_in_process_command_buffer_impl.cc
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_in_process_command_buffer_impl.h"
6
7 #include <GLES2/gl2.h>
8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1
10 #endif
11 #include <GLES2/gl2ext.h>
12 #include <GLES2/gl2extchromium.h>
13
14 #include <string>
15
16 #include "base/atomicops.h"
17 #include "base/bind.h"
18 #include "base/bind_helpers.h"
19 #include "base/callback.h"
20 #include "base/lazy_instance.h"
21 #include "base/logging.h"
22 #include "gpu/command_buffer/client/gl_in_process_context.h"
23 #include "gpu/command_buffer/client/gles2_implementation.h"
24 #include "gpu/command_buffer/client/gles2_lib.h"
25 #include "ui/gfx/size.h"
26 #include "ui/gl/gl_surface.h"
27 #include "webkit/common/gpu/gl_bindings_skia_cmd_buffer.h"
28
29 using gpu::gles2::GLES2Implementation;
30 using gpu::GLInProcessContext;
31
32 namespace webkit {
33 namespace gpu {
34
35 namespace {
36
37 const int32 kCommandBufferSize = 1024 * 1024;
38 // TODO(kbr): make the transfer buffer size configurable via context
39 // creation attributes.
40 const size_t kStartTransferBufferSize = 4 * 1024 * 1024;
41 const size_t kMinTransferBufferSize = 1 * 256 * 1024;
42 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
43
44 uint32_t GenFlushID() {
45   static base::subtle::Atomic32 flush_id = 0;
46
47   base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
48       &flush_id, 1);
49   return static_cast<uint32_t>(my_id);
50 }
51
52 // Singleton used to initialize and terminate the gles2 library.
53 class GLES2Initializer {
54  public:
55   GLES2Initializer() {
56     ::gles2::Initialize();
57   }
58
59   ~GLES2Initializer() {
60     ::gles2::Terminate();
61   }
62
63  private:
64   DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
65 };
66
67 static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
68     LAZY_INSTANCE_INITIALIZER;
69
70 }  // namespace anonymous
71
72 // static
73 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
74 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
75     const WebKit::WebGraphicsContext3D::Attributes& attributes,
76     gfx::AcceleratedWidget window) {
77   scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context;
78   if (gfx::GLSurface::InitializeOneOff()) {
79     context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl(
80       scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window));
81   }
82   return context.Pass();
83 }
84
85 // static
86 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
87 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
88     const WebKit::WebGraphicsContext3D::Attributes& attributes) {
89   return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
90                              scoped_ptr< ::gpu::GLInProcessContext>(),
91                              attributes,
92                              true,
93                              gfx::kNullAcceleratedWidget))
94       .Pass();
95 }
96
97 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
98 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
99     scoped_ptr< ::gpu::GLInProcessContext> context,
100     const WebKit::WebGraphicsContext3D::Attributes& attributes) {
101   return make_scoped_ptr(
102       new WebGraphicsContext3DInProcessCommandBufferImpl(
103           context.Pass(),
104           attributes,
105           true /* is_offscreen. Not used. */,
106           gfx::kNullAcceleratedWidget /* window. Not used. */))
107       .Pass();
108 }
109
110 WebGraphicsContext3DInProcessCommandBufferImpl::
111     WebGraphicsContext3DInProcessCommandBufferImpl(
112         scoped_ptr< ::gpu::GLInProcessContext> context,
113         const WebKit::WebGraphicsContext3D::Attributes& attributes,
114         bool is_offscreen,
115         gfx::AcceleratedWidget window)
116     : is_offscreen_(is_offscreen),
117       window_(window),
118       initialized_(false),
119       initialize_failed_(false),
120       context_(context.Pass()),
121       gl_(NULL),
122       context_lost_callback_(NULL),
123       context_lost_reason_(GL_NO_ERROR),
124       attributes_(attributes),
125       flush_id_(0) {
126 }
127
128 WebGraphicsContext3DInProcessCommandBufferImpl::
129     ~WebGraphicsContext3DInProcessCommandBufferImpl() {
130 }
131
132 // static
133 void WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
134     const WebKit::WebGraphicsContext3D::Attributes& attributes,
135     ::gpu::GLInProcessContextAttribs* output_attribs) {
136   output_attribs->alpha_size = attributes.alpha ? 8 : 0;
137   output_attribs->depth_size = attributes.depth ? 24 : 0;
138   output_attribs->stencil_size = attributes.stencil ? 8 : 0;
139   output_attribs->samples = attributes.antialias ? 4 : 0;
140   output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
141 }
142
143 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
144   if (initialized_)
145     return true;
146
147   if (initialize_failed_)
148     return false;
149
150   // Ensure the gles2 library is initialized first in a thread safe way.
151   g_gles2_initializer.Get();
152
153   if (!context_) {
154     // TODO(kbr): More work will be needed in this implementation to
155     // properly support GPU switching. Like in the out-of-process
156     // command buffer implementation, all previously created contexts
157     // will need to be lost either when the first context requesting the
158     // discrete GPU is created, or the last one is destroyed.
159     gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
160
161     ::gpu::GLInProcessContextAttribs attrib_struct;
162     ConvertAttributes(attributes_, &attrib_struct),
163
164     context_.reset(GLInProcessContext::CreateContext(
165         is_offscreen_,
166         window_,
167         gfx::Size(1, 1),
168         attributes_.shareResources,
169         attrib_struct,
170         gpu_preference));
171   }
172
173   if (context_) {
174     base::Closure context_lost_callback = base::Bind(
175         &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost,
176         base::Unretained(this));
177     context_->SetContextLostCallback(context_lost_callback);
178   } else {
179     initialize_failed_ = true;
180     return false;
181   }
182
183   gl_ = context_->GetImplementation();
184
185   if (gl_ && attributes_.noExtensions)
186     gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
187
188   // Set attributes_ from created offscreen context.
189   {
190     GLint alpha_bits = 0;
191     getIntegerv(GL_ALPHA_BITS, &alpha_bits);
192     attributes_.alpha = alpha_bits > 0;
193     GLint depth_bits = 0;
194     getIntegerv(GL_DEPTH_BITS, &depth_bits);
195     attributes_.depth = depth_bits > 0;
196     GLint stencil_bits = 0;
197     getIntegerv(GL_STENCIL_BITS, &stencil_bits);
198     attributes_.stencil = stencil_bits > 0;
199     GLint sample_buffers = 0;
200     getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers);
201     attributes_.antialias = sample_buffers > 0;
202   }
203
204   initialized_ = true;
205   return true;
206 }
207
208 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() {
209   if (!MaybeInitializeGL())
210     return false;
211   ::gles2::SetGLContext(gl_);
212   return context_ && !isContextLost();
213 }
214
215 uint32_t WebGraphicsContext3DInProcessCommandBufferImpl::lastFlushID() {
216   return flush_id_;
217 }
218
219 void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() {
220   // NOTE: Comment in the line below to check for code that is not calling
221   // eglMakeCurrent where appropriate. The issue is code using
222   // WebGraphicsContext3D does not need to call makeContextCurrent. Code using
223   // direct OpenGL bindings needs to call the appropriate form of
224   // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong
225   // context. Uncommenting the line below clears the current context so that
226   // any code not calling eglMakeCurrent in the appropriate place should crash.
227   // This is not a perfect test but generally code that used the direct OpenGL
228   // bindings should not be mixed with code that uses WebGraphicsContext3D.
229   //
230   // GLInProcessContext::MakeCurrent(NULL);
231 }
232
233 // Helper macros to reduce the amount of code.
234
235 #define DELEGATE_TO_GL(name, glname)                                    \
236 void WebGraphicsContext3DInProcessCommandBufferImpl::name() {           \
237   ClearContext();                                                       \
238   gl_->glname();                                                        \
239 }
240
241 #define DELEGATE_TO_GL_R(name, glname, rt)                              \
242 rt WebGraphicsContext3DInProcessCommandBufferImpl::name() {             \
243   ClearContext();                                                       \
244   return gl_->glname();                                                 \
245 }
246
247 #define DELEGATE_TO_GL_1(name, glname, t1)                              \
248 void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) {      \
249   ClearContext();                                                       \
250   gl_->glname(a1);                                                      \
251 }
252
253 #define DELEGATE_TO_GL_1R(name, glname, t1, rt)                         \
254 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) {        \
255   ClearContext();                                                       \
256   return gl_->glname(a1);                                               \
257 }
258
259 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt)                        \
260 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) {        \
261   ClearContext();                                                       \
262   return gl_->glname(a1) ? true : false;                                \
263 }
264
265 #define DELEGATE_TO_GL_2(name, glname, t1, t2)                          \
266 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
267     t1 a1, t2 a2) {                                                     \
268   ClearContext();                                                       \
269   gl_->glname(a1, a2);                                                  \
270 }
271
272 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt)                     \
273 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1, t2 a2) { \
274   ClearContext();                                                       \
275   return gl_->glname(a1, a2);                                           \
276 }
277
278 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3)                      \
279 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
280     t1 a1, t2 a2, t3 a3) {                                              \
281   ClearContext();                                                       \
282   gl_->glname(a1, a2, a3);                                              \
283 }
284
285 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt)                 \
286 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(                \
287     t1 a1, t2 a2, t3 a3) {                                              \
288   ClearContext();                                                       \
289   return gl_->glname(a1, a2, a3);                                       \
290 }
291
292 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4)                  \
293 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
294     t1 a1, t2 a2, t3 a3, t4 a4) {                                       \
295   ClearContext();                                                       \
296   gl_->glname(a1, a2, a3, a4);                                          \
297 }
298
299 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5)              \
300 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
301     t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {                                \
302   ClearContext();                                                       \
303   gl_->glname(a1, a2, a3, a4, a5);                                      \
304 }
305
306 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6)          \
307 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
308     t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) {                         \
309   ClearContext();                                                       \
310   gl_->glname(a1, a2, a3, a4, a5, a6);                                  \
311 }
312
313 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7)      \
314 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
315     t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) {                  \
316   ClearContext();                                                       \
317   gl_->glname(a1, a2, a3, a4, a5, a6, a7);                              \
318 }
319
320 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8)  \
321 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
322     t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) {           \
323   ClearContext();                                                       \
324   gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8);                          \
325 }
326
327 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
328 void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
329     t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) {    \
330   ClearContext();                                                       \
331   gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9);                      \
332 }
333
334 void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() {
335   if (!isContextLost()) {
336     gl_->SwapBuffers();
337     gl_->ShallowFlushCHROMIUM();
338   }
339 }
340
341 void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM(
342     int x, int y, int width, int height) {
343   gl_->PostSubBufferCHROMIUM(x, y, width, height);
344 }
345
346 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
347
348 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError(
349     WGC3Denum error) {
350   if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
351       synthetic_errors_.end()) {
352     synthetic_errors_.push_back(error);
353   }
354 }
355
356 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM(
357     WGC3Denum target,
358     WGC3Dintptr offset,
359     WGC3Dsizeiptr size,
360     WGC3Denum access) {
361   ClearContext();
362   return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access);
363 }
364
365 void WebGraphicsContext3DInProcessCommandBufferImpl::unmapBufferSubDataCHROMIUM(
366     const void* mem) {
367   ClearContext();
368   return gl_->UnmapBufferSubDataCHROMIUM(mem);
369 }
370
371 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapTexSubImage2DCHROMIUM(
372     WGC3Denum target,
373     WGC3Dint level,
374     WGC3Dint xoffset,
375     WGC3Dint yoffset,
376     WGC3Dsizei width,
377     WGC3Dsizei height,
378     WGC3Denum format,
379     WGC3Denum type,
380     WGC3Denum access) {
381   ClearContext();
382   return gl_->MapTexSubImage2DCHROMIUM(
383       target, level, xoffset, yoffset, width, height, format, type, access);
384 }
385
386 void WebGraphicsContext3DInProcessCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
387     const void* mem) {
388   ClearContext();
389   gl_->UnmapTexSubImage2DCHROMIUM(mem);
390 }
391
392 void WebGraphicsContext3DInProcessCommandBufferImpl::setVisibilityCHROMIUM(
393     bool visible) {
394 }
395
396 void WebGraphicsContext3DInProcessCommandBufferImpl::discardFramebufferEXT(
397     WGC3Denum target, WGC3Dsizei numAttachments, const WGC3Denum* attachments) {
398   gl_->DiscardFramebufferEXT(target, numAttachments, attachments);
399 }
400
401 void WebGraphicsContext3DInProcessCommandBufferImpl::
402     discardBackbufferCHROMIUM() {
403 }
404
405 void WebGraphicsContext3DInProcessCommandBufferImpl::
406     ensureBackbufferCHROMIUM() {
407 }
408
409 void WebGraphicsContext3DInProcessCommandBufferImpl::
410     copyTextureToParentTextureCHROMIUM(WebGLId texture, WebGLId parentTexture) {
411   NOTIMPLEMENTED();
412 }
413
414 void WebGraphicsContext3DInProcessCommandBufferImpl::
415     rateLimitOffscreenContextCHROMIUM() {
416   // TODO(gmam): See if we can comment this in.
417   // ClearContext();
418   gl_->RateLimitOffscreenContextCHROMIUM();
419 }
420
421 WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
422     getRequestableExtensionsCHROMIUM() {
423   // TODO(gmam): See if we can comment this in.
424   // ClearContext();
425   return WebKit::WebString::fromUTF8(
426       gl_->GetRequestableExtensionsCHROMIUM());
427 }
428
429 void WebGraphicsContext3DInProcessCommandBufferImpl::requestExtensionCHROMIUM(
430     const char* extension) {
431   // TODO(gmam): See if we can comment this in.
432   // ClearContext();
433   gl_->RequestExtensionCHROMIUM(extension);
434 }
435
436 void WebGraphicsContext3DInProcessCommandBufferImpl::blitFramebufferCHROMIUM(
437     WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
438     WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
439     WGC3Dbitfield mask, WGC3Denum filter) {
440   ClearContext();
441   gl_->BlitFramebufferEXT(
442       srcX0, srcY0, srcX1, srcY1,
443       dstX0, dstY0, dstX1, dstY1,
444       mask, filter);
445 }
446
447 void WebGraphicsContext3DInProcessCommandBufferImpl::
448     renderbufferStorageMultisampleCHROMIUM(
449         WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
450         WGC3Dsizei width, WGC3Dsizei height) {
451   ClearContext();
452   gl_->RenderbufferStorageMultisampleEXT(
453       target, samples, internalformat, width, height);
454 }
455
456 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
457
458 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
459
460 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
461                  WGC3Duint, const WGC3Dchar*)
462
463 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
464
465 void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer(
466     WGC3Denum target,
467     WebGLId framebuffer) {
468   ClearContext();
469   gl_->BindFramebuffer(target, framebuffer);
470 }
471
472 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
473
474 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
475
476 DELEGATE_TO_GL_4(blendColor, BlendColor,
477                  WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
478
479 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
480
481 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
482                  WGC3Denum, WGC3Denum)
483
484 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
485
486 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
487                  WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
488
489 DELEGATE_TO_GL_4(bufferData, BufferData,
490                  WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
491
492 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
493                  WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
494
495 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
496                   WGC3Denum, WGC3Denum)
497
498 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
499
500 DELEGATE_TO_GL_4(clearColor, ClearColor,
501                  WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
502
503 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
504
505 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
506
507 DELEGATE_TO_GL_4(colorMask, ColorMask,
508                  WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
509
510 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
511
512 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
513                  WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
514                  WGC3Dsizei, WGC3Dsizei, const void*)
515
516 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
517                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
518                  WGC3Denum, WGC3Dsizei, const void*)
519
520 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
521                  WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
522                  WGC3Dsizei, WGC3Dsizei, WGC3Dint)
523
524 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
525                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
526                  WGC3Dsizei, WGC3Dsizei)
527
528 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
529
530 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
531
532 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
533
534 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
535
536 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
537
538 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
539
540 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
541                  WGC3Duint)
542
543 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
544
545 void WebGraphicsContext3DInProcessCommandBufferImpl::drawElements(
546     WGC3Denum mode,
547     WGC3Dsizei count,
548     WGC3Denum type,
549     WGC3Dintptr offset) {
550   ClearContext();
551   gl_->DrawElements(
552       mode, count, type,
553       reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
554 }
555
556 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
557
558 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
559                  WGC3Duint)
560
561 void WebGraphicsContext3DInProcessCommandBufferImpl::finish() {
562   flush_id_ = GenFlushID();
563   gl_->Finish();
564 }
565
566 void WebGraphicsContext3DInProcessCommandBufferImpl::flush() {
567   flush_id_ = GenFlushID();
568   gl_->Flush();
569 }
570
571 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
572                  WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
573
574 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
575                  WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
576
577 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
578
579 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
580
581 bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveAttrib(
582     WebGLId program, WGC3Duint index, ActiveInfo& info) {
583   ClearContext();
584   if (!program) {
585     synthesizeGLError(GL_INVALID_VALUE);
586     return false;
587   }
588   GLint max_name_length = -1;
589   gl_->GetProgramiv(
590       program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
591   if (max_name_length < 0)
592     return false;
593   scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
594   if (!name) {
595     synthesizeGLError(GL_OUT_OF_MEMORY);
596     return false;
597   }
598   GLsizei length = 0;
599   GLint size = -1;
600   GLenum type = 0;
601   gl_->GetActiveAttrib(
602       program, index, max_name_length, &length, &size, &type, name.get());
603   if (size < 0) {
604     return false;
605   }
606   info.name = WebKit::WebString::fromUTF8(name.get(), length);
607   info.type = type;
608   info.size = size;
609   return true;
610 }
611
612 bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveUniform(
613     WebGLId program, WGC3Duint index, ActiveInfo& info) {
614   ClearContext();
615   GLint max_name_length = -1;
616   gl_->GetProgramiv(
617       program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
618   if (max_name_length < 0)
619     return false;
620   scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
621   if (!name) {
622     synthesizeGLError(GL_OUT_OF_MEMORY);
623     return false;
624   }
625   GLsizei length = 0;
626   GLint size = -1;
627   GLenum type = 0;
628   gl_->GetActiveUniform(
629       program, index, max_name_length, &length, &size, &type, name.get());
630   if (size < 0) {
631     return false;
632   }
633   info.name = WebKit::WebString::fromUTF8(name.get(), length);
634   info.type = type;
635   info.size = size;
636   return true;
637 }
638
639 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
640                  WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
641
642 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
643                   WebGLId, const WGC3Dchar*, WGC3Dint)
644
645 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
646
647 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
648                  WGC3Denum, WGC3Denum, WGC3Dint*)
649
650 WebKit::WebGraphicsContext3D::Attributes
651 WebGraphicsContext3DInProcessCommandBufferImpl::getContextAttributes() {
652   return attributes_;
653 }
654
655 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::getError() {
656   ClearContext();
657   if (!synthetic_errors_.empty()) {
658     std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
659     WGC3Denum err = *iter;
660     synthetic_errors_.erase(iter);
661     return err;
662   }
663
664   return gl_->GetError();
665 }
666
667 bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() {
668   return context_lost_reason_ != GL_NO_ERROR;
669 }
670
671 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
672
673 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
674                  GetFramebufferAttachmentParameteriv,
675                  WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
676
677 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
678
679 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
680
681 WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
682     getProgramInfoLog(WebGLId program) {
683   ClearContext();
684   GLint logLength = 0;
685   gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
686   if (!logLength)
687     return WebKit::WebString();
688   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
689   if (!log)
690     return WebKit::WebString();
691   GLsizei returnedLogLength = 0;
692   gl_->GetProgramInfoLog(
693       program, logLength, &returnedLogLength, log.get());
694   DCHECK_EQ(logLength, returnedLogLength + 1);
695   WebKit::WebString res =
696       WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
697   return res;
698 }
699
700 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
701                  WGC3Denum, WGC3Denum, WGC3Dint*)
702
703 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
704
705 WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
706     getShaderInfoLog(WebGLId shader) {
707   ClearContext();
708   GLint logLength = 0;
709   gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
710   if (!logLength)
711     return WebKit::WebString();
712   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
713   if (!log)
714     return WebKit::WebString();
715   GLsizei returnedLogLength = 0;
716   gl_->GetShaderInfoLog(
717       shader, logLength, &returnedLogLength, log.get());
718   DCHECK_EQ(logLength, returnedLogLength + 1);
719   WebKit::WebString res =
720       WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
721   return res;
722 }
723
724 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
725                  WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
726
727 WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
728     getShaderSource(WebGLId shader) {
729   ClearContext();
730   GLint logLength = 0;
731   gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
732   if (!logLength)
733     return WebKit::WebString();
734   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
735   if (!log)
736     return WebKit::WebString();
737   GLsizei returnedLogLength = 0;
738   gl_->GetShaderSource(
739       shader, logLength, &returnedLogLength, log.get());
740   if (!returnedLogLength)
741     return WebKit::WebString();
742   DCHECK_EQ(logLength, returnedLogLength + 1);
743   WebKit::WebString res =
744       WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
745   return res;
746 }
747
748 WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
749     getTranslatedShaderSourceANGLE(WebGLId shader) {
750   ClearContext();
751   GLint logLength = 0;
752   gl_->GetShaderiv(
753       shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
754   if (!logLength)
755     return WebKit::WebString();
756   scoped_ptr<GLchar[]> log(new GLchar[logLength]);
757   if (!log)
758     return WebKit::WebString();
759   GLsizei returnedLogLength = 0;
760   gl_->GetTranslatedShaderSourceANGLE(
761       shader, logLength, &returnedLogLength, log.get());
762   if (!returnedLogLength)
763     return WebKit::WebString();
764   DCHECK_EQ(logLength, returnedLogLength + 1);
765   WebKit::WebString res =
766       WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
767   return res;
768 }
769
770 WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::getString(
771     WGC3Denum name) {
772   ClearContext();
773   return WebKit::WebString::fromUTF8(
774       reinterpret_cast<const char*>(gl_->GetString(name)));
775 }
776
777 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
778                  WGC3Denum, WGC3Denum, WGC3Dfloat*)
779
780 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
781                  WGC3Denum, WGC3Denum, WGC3Dint*)
782
783 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
784
785 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
786
787 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
788                   WebGLId, const WGC3Dchar*, WGC3Dint)
789
790 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
791                  WGC3Duint, WGC3Denum, WGC3Dfloat*)
792
793 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
794                  WGC3Duint, WGC3Denum, WGC3Dint*)
795
796 WGC3Dsizeiptr WebGraphicsContext3DInProcessCommandBufferImpl::
797     getVertexAttribOffset(WGC3Duint index, WGC3Denum pname) {
798   ClearContext();
799   GLvoid* value = NULL;
800   // NOTE: If pname is ever a value that returns more then 1 element
801   // this will corrupt memory.
802   gl_->GetVertexAttribPointerv(index, pname, &value);
803   return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
804 }
805
806 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
807
808 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
809
810 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
811
812 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
813
814 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
815
816 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
817
818 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
819
820 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
821
822 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
823
824 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
825
826 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
827
828 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
829
830 DELEGATE_TO_GL_7(readPixels, ReadPixels,
831                  WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
832                  WGC3Denum, void*)
833
834 void WebGraphicsContext3DInProcessCommandBufferImpl::releaseShaderCompiler() {
835   ClearContext();
836 }
837
838 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
839                  WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
840
841 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
842
843 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
844
845 void WebGraphicsContext3DInProcessCommandBufferImpl::shaderSource(
846     WebGLId shader, const WGC3Dchar* string) {
847   ClearContext();
848   GLint length = strlen(string);
849   gl_->ShaderSource(shader, 1, &string, &length);
850 }
851
852 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
853
854 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
855                  WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
856
857 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
858
859 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
860                  WGC3Denum, WGC3Duint)
861
862 DELEGATE_TO_GL_3(stencilOp, StencilOp,
863                  WGC3Denum, WGC3Denum, WGC3Denum)
864
865 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
866                  WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
867
868 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
869                  WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
870                  WGC3Dint, WGC3Denum, WGC3Denum, const void*)
871
872 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
873                  WGC3Denum, WGC3Denum, WGC3Dfloat);
874
875 static const unsigned int kTextureWrapR = 0x8072;
876
877 void WebGraphicsContext3DInProcessCommandBufferImpl::texParameteri(
878     WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
879   ClearContext();
880   // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
881   // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
882   // edge of cube maps, and, if it is, push it into the GLES2 service
883   // side code.
884   if (pname == kTextureWrapR) {
885     return;
886   }
887   gl_->TexParameteri(target, pname, param);
888 }
889
890 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
891                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
892                  WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
893
894 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
895
896 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
897                  const WGC3Dfloat*)
898
899 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
900
901 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
902
903 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
904
905 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
906                  const WGC3Dfloat*)
907
908 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
909
910 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
911
912 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
913                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
914
915 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
916                  const WGC3Dfloat*)
917
918 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
919
920 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
921
922 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
923                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
924
925 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
926                  const WGC3Dfloat*)
927
928 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
929                  WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
930
931 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
932
933 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
934                  WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
935
936 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
937                  WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
938
939 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
940                  WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
941
942 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
943
944 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
945
946 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
947
948 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
949                  const WGC3Dfloat*)
950
951 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
952                  WGC3Dfloat, WGC3Dfloat)
953
954 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
955                  const WGC3Dfloat*)
956
957 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
958                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
959
960 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
961                  const WGC3Dfloat*)
962
963 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
964                  WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
965
966 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
967                  const WGC3Dfloat*)
968
969 void WebGraphicsContext3DInProcessCommandBufferImpl::vertexAttribPointer(
970     WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
971     WGC3Dsizei stride, WGC3Dintptr offset) {
972   ClearContext();
973   gl_->VertexAttribPointer(
974       index, size, type, normalized, stride,
975       reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
976 }
977
978 DELEGATE_TO_GL_4(viewport, Viewport,
979                  WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
980
981 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
982
983 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
984
985 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
986
987 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
988
989 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
990
991 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
992
993 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
994                  WebGLId*);
995
996 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
997
998 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createBuffer() {
999   ClearContext();
1000   GLuint o;
1001   gl_->GenBuffers(1, &o);
1002   return o;
1003 }
1004
1005 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createFramebuffer() {
1006   ClearContext();
1007   GLuint o = 0;
1008   gl_->GenFramebuffers(1, &o);
1009   return o;
1010 }
1011
1012 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createRenderbuffer() {
1013   ClearContext();
1014   GLuint o;
1015   gl_->GenRenderbuffers(1, &o);
1016   return o;
1017 }
1018
1019 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() {
1020   ClearContext();
1021   GLuint o;
1022   gl_->GenTextures(1, &o);
1023   return o;
1024 }
1025
1026 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer(
1027     WebGLId buffer) {
1028   ClearContext();
1029   gl_->DeleteBuffers(1, &buffer);
1030 }
1031
1032 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer(
1033     WebGLId framebuffer) {
1034   ClearContext();
1035   gl_->DeleteFramebuffers(1, &framebuffer);
1036 }
1037
1038 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer(
1039     WebGLId renderbuffer) {
1040   ClearContext();
1041   gl_->DeleteRenderbuffers(1, &renderbuffer);
1042 }
1043
1044 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteTexture(
1045     WebGLId texture) {
1046   ClearContext();
1047   gl_->DeleteTextures(1, &texture);
1048 }
1049
1050 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId);
1051
1052 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId);
1053
1054 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId);
1055
1056 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId);
1057
1058 void WebGraphicsContext3DInProcessCommandBufferImpl::OnSwapBuffersComplete() {
1059 }
1060
1061 void WebGraphicsContext3DInProcessCommandBufferImpl::setContextLostCallback(
1062     WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
1063   context_lost_callback_ = cb;
1064 }
1065
1066 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::
1067     getGraphicsResetStatusARB() {
1068   return context_lost_reason_;
1069 }
1070
1071 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
1072                  WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
1073
1074 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
1075                  WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
1076
1077 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createQueryEXT() {
1078   GLuint o;
1079   gl_->GenQueriesEXT(1, &o);
1080   return o;
1081 }
1082
1083 void WebGraphicsContext3DInProcessCommandBufferImpl::
1084     deleteQueryEXT(WebGLId query) {
1085   gl_->DeleteQueriesEXT(1, &query);
1086 }
1087
1088 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
1089 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
1090 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
1091 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
1092 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
1093                  WebGLId, WGC3Denum, WGC3Duint*)
1094
1095 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum, WGC3Duint,
1096                  WGC3Duint, WGC3Dint, WGC3Denum, WGC3Denum)
1097
1098 void WebGraphicsContext3DInProcessCommandBufferImpl::insertEventMarkerEXT(
1099     const WGC3Dchar* marker) {
1100   gl_->InsertEventMarkerEXT(0, marker);
1101 }
1102
1103 void WebGraphicsContext3DInProcessCommandBufferImpl::pushGroupMarkerEXT(
1104     const WGC3Dchar* marker) {
1105   gl_->PushGroupMarkerEXT(0, marker);
1106 }
1107
1108 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
1109
1110 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
1111                  WGC3Denum, WGC3Dint)
1112 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
1113                  WGC3Denum, WGC3Dint)
1114
1115 DELEGATE_TO_GL_1R(createStreamTextureCHROMIUM, CreateStreamTextureCHROMIUM,
1116                   WebGLId, WebGLId)
1117 DELEGATE_TO_GL_1(destroyStreamTextureCHROMIUM, DestroyStreamTextureCHROMIUM,
1118                  WebGLId)
1119
1120 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferCHROMIUM(
1121     WGC3Denum target, WGC3Denum access) {
1122   ClearContext();
1123   return gl_->MapBufferCHROMIUM(target, access);
1124 }
1125
1126 WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl::
1127     unmapBufferCHROMIUM(WGC3Denum target) {
1128   ClearContext();
1129   return gl_->UnmapBufferCHROMIUM(target);
1130 }
1131
1132 GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl::
1133     createGrGLInterface() {
1134   return CreateCommandBufferSkiaGLBinding();
1135 }
1136
1137 ::gpu::ContextSupport*
1138 WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() {
1139   return gl_;
1140 }
1141
1142 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
1143   // TODO(kbr): improve the precision here.
1144   context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
1145   if (context_lost_callback_) {
1146     context_lost_callback_->onContextLost();
1147   }
1148 }
1149
1150 DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM,
1151                   WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Duint);
1152
1153 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
1154
1155 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM,
1156                  WGC3Duint, WGC3Denum, GLint*);
1157
1158 DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM,
1159                   WGC3Duint, WGC3Denum, void*);
1160
1161 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
1162
1163 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1164                  WebGLId, WGC3Dint, const WGC3Dchar*)
1165
1166 void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFlushCHROMIUM() {
1167   flush_id_ = GenFlushID();
1168   gl_->ShallowFlushCHROMIUM();
1169 }
1170
1171 void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFinishCHROMIUM() {
1172   flush_id_ = GenFlushID();
1173   gl_->ShallowFinishCHROMIUM();
1174 }
1175
1176 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1177 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1178                  WGC3Denum, const WGC3Dbyte*)
1179 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1180                  WGC3Denum, const WGC3Dbyte*)
1181
1182 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT,
1183                  WGC3Dsizei, const WGC3Denum*)
1184
1185 unsigned WebGraphicsContext3DInProcessCommandBufferImpl::insertSyncPoint() {
1186   shallowFlushCHROMIUM();
1187   return 0;
1188 }
1189
1190 void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM(
1191     WGC3Denum current, WGC3Denum other) {
1192   gl_->LoseContextCHROMIUM(current, other);
1193   gl_->ShallowFlushCHROMIUM();
1194 }
1195
1196 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM,
1197     WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
1198     WGC3Denum, WGC3Denum, const void*)
1199
1200 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1201     WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1202     WGC3Denum, WGC3Denum, const void*)
1203
1204 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1205     WGC3Denum)
1206
1207 }  // namespace gpu
1208 }  // namespace webkit