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