webgraphicscontext3d_in_process_command_buffer_impl.cc revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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 "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
26#include "ui/gfx/size.h"
27#include "ui/gl/gl_implementation.h"
28
29using gpu::gles2::GLES2Implementation;
30using gpu::GLInProcessContext;
31
32namespace webkit {
33namespace gpu {
34
35namespace {
36
37const int32 kCommandBufferSize = 1024 * 1024;
38// TODO(kbr): make the transfer buffer size configurable via context
39// creation attributes.
40const size_t kStartTransferBufferSize = 4 * 1024 * 1024;
41const size_t kMinTransferBufferSize = 1 * 256 * 1024;
42const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
43
44uint32_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.
53class 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
67static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
68    LAZY_INSTANCE_INITIALIZER;
69
70}  // namespace anonymous
71
72// static
73scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
74WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
75    const blink::WebGraphicsContext3D::Attributes& attributes,
76    bool lose_context_when_out_of_memory,
77    gfx::AcceleratedWidget window) {
78  DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
79  bool is_offscreen = false;
80  return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
81      scoped_ptr< ::gpu::GLInProcessContext>(),
82      attributes,
83      lose_context_when_out_of_memory,
84      is_offscreen,
85      window));
86}
87
88// static
89scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
90WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
91    const blink::WebGraphicsContext3D::Attributes& attributes,
92    bool lose_context_when_out_of_memory) {
93  bool is_offscreen = true;
94  return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
95      scoped_ptr< ::gpu::GLInProcessContext>(),
96      attributes,
97      lose_context_when_out_of_memory,
98      is_offscreen,
99      gfx::kNullAcceleratedWidget));
100}
101
102scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
103WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
104    scoped_ptr< ::gpu::GLInProcessContext> context,
105    const blink::WebGraphicsContext3D::Attributes& attributes) {
106  bool lose_context_when_out_of_memory = false;  // Not used.
107  bool is_offscreen = true;                      // Not used.
108  return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
109      context.Pass(),
110      attributes,
111      lose_context_when_out_of_memory,
112      is_offscreen,
113      gfx::kNullAcceleratedWidget /* window. Not used. */));
114}
115
116WebGraphicsContext3DInProcessCommandBufferImpl::
117    WebGraphicsContext3DInProcessCommandBufferImpl(
118        scoped_ptr< ::gpu::GLInProcessContext> context,
119        const blink::WebGraphicsContext3D::Attributes& attributes,
120        bool lose_context_when_out_of_memory,
121        bool is_offscreen,
122        gfx::AcceleratedWidget window)
123    : is_offscreen_(is_offscreen),
124      window_(window),
125      initialized_(false),
126      initialize_failed_(false),
127      context_(context.Pass()),
128      gl_(NULL),
129      context_lost_callback_(NULL),
130      context_lost_reason_(GL_NO_ERROR),
131      attributes_(attributes),
132      lose_context_when_out_of_memory_(lose_context_when_out_of_memory),
133      flush_id_(0) {}
134
135WebGraphicsContext3DInProcessCommandBufferImpl::
136    ~WebGraphicsContext3DInProcessCommandBufferImpl() {
137}
138
139// static
140void WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
141    const blink::WebGraphicsContext3D::Attributes& attributes,
142    ::gpu::GLInProcessContextAttribs* output_attribs) {
143  output_attribs->alpha_size = attributes.alpha ? 8 : 0;
144  output_attribs->depth_size = attributes.depth ? 24 : 0;
145  output_attribs->stencil_size = attributes.stencil ? 8 : 0;
146  output_attribs->samples = attributes.antialias ? 4 : 0;
147  output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
148  output_attribs->fail_if_major_perf_caveat =
149      attributes.failIfMajorPerformanceCaveat ? 1 : 0;
150}
151
152bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
153  if (initialized_)
154    return true;
155
156  if (initialize_failed_)
157    return false;
158
159  // Ensure the gles2 library is initialized first in a thread safe way.
160  g_gles2_initializer.Get();
161
162  if (!context_) {
163    // TODO(kbr): More work will be needed in this implementation to
164    // properly support GPU switching. Like in the out-of-process
165    // command buffer implementation, all previously created contexts
166    // will need to be lost either when the first context requesting the
167    // discrete GPU is created, or the last one is destroyed.
168    gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
169
170    ::gpu::GLInProcessContextAttribs attrib_struct;
171    ConvertAttributes(attributes_, &attrib_struct);
172    attrib_struct.lose_context_when_out_of_memory =
173        lose_context_when_out_of_memory_;
174
175    context_.reset(GLInProcessContext::CreateContext(
176        is_offscreen_,
177        window_,
178        gfx::Size(1, 1),
179        attributes_.shareResources,
180        attrib_struct,
181        gpu_preference));
182  }
183
184  if (context_) {
185    base::Closure context_lost_callback = base::Bind(
186        &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost,
187        base::Unretained(this));
188    context_->SetContextLostCallback(context_lost_callback);
189  } else {
190    initialize_failed_ = true;
191    return false;
192  }
193
194  gl_ = context_->GetImplementation();
195
196  if (gl_ && attributes_.noExtensions)
197    gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
198
199  // Set attributes_ from created offscreen context.
200  {
201    GLint alpha_bits = 0;
202    getIntegerv(GL_ALPHA_BITS, &alpha_bits);
203    attributes_.alpha = alpha_bits > 0;
204    GLint depth_bits = 0;
205    getIntegerv(GL_DEPTH_BITS, &depth_bits);
206    attributes_.depth = depth_bits > 0;
207    GLint stencil_bits = 0;
208    getIntegerv(GL_STENCIL_BITS, &stencil_bits);
209    attributes_.stencil = stencil_bits > 0;
210    GLint sample_buffers = 0;
211    getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers);
212    attributes_.antialias = sample_buffers > 0;
213  }
214
215  initialized_ = true;
216  return true;
217}
218
219bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() {
220  if (!MaybeInitializeGL())
221    return false;
222  ::gles2::SetGLContext(gl_);
223  return context_ && !isContextLost();
224}
225
226uint32_t WebGraphicsContext3DInProcessCommandBufferImpl::lastFlushID() {
227  return flush_id_;
228}
229
230void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() {
231  // NOTE: Comment in the line below to check for code that is not calling
232  // eglMakeCurrent where appropriate. The issue is code using
233  // WebGraphicsContext3D does not need to call makeContextCurrent. Code using
234  // direct OpenGL bindings needs to call the appropriate form of
235  // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong
236  // context. Uncommenting the line below clears the current context so that
237  // any code not calling eglMakeCurrent in the appropriate place should crash.
238  // This is not a perfect test but generally code that used the direct OpenGL
239  // bindings should not be mixed with code that uses WebGraphicsContext3D.
240  //
241  // GLInProcessContext::MakeCurrent(NULL);
242}
243
244// Helper macros to reduce the amount of code.
245
246#define DELEGATE_TO_GL(name, glname)                                    \
247void WebGraphicsContext3DInProcessCommandBufferImpl::name() {           \
248  ClearContext();                                                       \
249  gl_->glname();                                                        \
250}
251
252#define DELEGATE_TO_GL_R(name, glname, rt)                              \
253rt WebGraphicsContext3DInProcessCommandBufferImpl::name() {             \
254  ClearContext();                                                       \
255  return gl_->glname();                                                 \
256}
257
258#define DELEGATE_TO_GL_1(name, glname, t1)                              \
259void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) {      \
260  ClearContext();                                                       \
261  gl_->glname(a1);                                                      \
262}
263
264#define DELEGATE_TO_GL_1R(name, glname, t1, rt)                         \
265rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) {        \
266  ClearContext();                                                       \
267  return gl_->glname(a1);                                               \
268}
269
270#define DELEGATE_TO_GL_1RB(name, glname, t1, rt)                        \
271rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) {        \
272  ClearContext();                                                       \
273  return gl_->glname(a1) ? true : false;                                \
274}
275
276#define DELEGATE_TO_GL_2(name, glname, t1, t2)                          \
277void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
278    t1 a1, t2 a2) {                                                     \
279  ClearContext();                                                       \
280  gl_->glname(a1, a2);                                                  \
281}
282
283#define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt)                     \
284rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1, t2 a2) { \
285  ClearContext();                                                       \
286  return gl_->glname(a1, a2);                                           \
287}
288
289#define DELEGATE_TO_GL_3(name, glname, t1, t2, t3)                      \
290void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
291    t1 a1, t2 a2, t3 a3) {                                              \
292  ClearContext();                                                       \
293  gl_->glname(a1, a2, a3);                                              \
294}
295
296#define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt)                 \
297rt WebGraphicsContext3DInProcessCommandBufferImpl::name(                \
298    t1 a1, t2 a2, t3 a3) {                                              \
299  ClearContext();                                                       \
300  return gl_->glname(a1, a2, a3);                                       \
301}
302
303#define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4)                  \
304void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
305    t1 a1, t2 a2, t3 a3, t4 a4) {                                       \
306  ClearContext();                                                       \
307  gl_->glname(a1, a2, a3, a4);                                          \
308}
309
310#define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5)              \
311void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
312    t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {                                \
313  ClearContext();                                                       \
314  gl_->glname(a1, a2, a3, a4, a5);                                      \
315}
316
317#define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6)          \
318void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
319    t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) {                         \
320  ClearContext();                                                       \
321  gl_->glname(a1, a2, a3, a4, a5, a6);                                  \
322}
323
324#define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7)      \
325void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
326    t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) {                  \
327  ClearContext();                                                       \
328  gl_->glname(a1, a2, a3, a4, a5, a6, a7);                              \
329}
330
331#define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8)  \
332void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
333    t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) {           \
334  ClearContext();                                                       \
335  gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8);                          \
336}
337
338#define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
339void WebGraphicsContext3DInProcessCommandBufferImpl::name(              \
340    t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) {    \
341  ClearContext();                                                       \
342  gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9);                      \
343}
344
345void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() {
346  NOTREACHED();
347}
348
349void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM(
350    int x, int y, int width, int height) {
351  NOTREACHED();
352}
353
354DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
355
356void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError(
357    WGC3Denum error) {
358  if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
359      synthetic_errors_.end()) {
360    synthetic_errors_.push_back(error);
361  }
362}
363
364void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM(
365    WGC3Denum target,
366    WGC3Dintptr offset,
367    WGC3Dsizeiptr size,
368    WGC3Denum access) {
369  ClearContext();
370  return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access);
371}
372
373void WebGraphicsContext3DInProcessCommandBufferImpl::unmapBufferSubDataCHROMIUM(
374    const void* mem) {
375  ClearContext();
376  return gl_->UnmapBufferSubDataCHROMIUM(mem);
377}
378
379void* WebGraphicsContext3DInProcessCommandBufferImpl::mapTexSubImage2DCHROMIUM(
380    WGC3Denum target,
381    WGC3Dint level,
382    WGC3Dint xoffset,
383    WGC3Dint yoffset,
384    WGC3Dsizei width,
385    WGC3Dsizei height,
386    WGC3Denum format,
387    WGC3Denum type,
388    WGC3Denum access) {
389  ClearContext();
390  return gl_->MapTexSubImage2DCHROMIUM(
391      target, level, xoffset, yoffset, width, height, format, type, access);
392}
393
394void WebGraphicsContext3DInProcessCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
395    const void* mem) {
396  ClearContext();
397  gl_->UnmapTexSubImage2DCHROMIUM(mem);
398}
399
400void WebGraphicsContext3DInProcessCommandBufferImpl::setVisibilityCHROMIUM(
401    bool visible) {
402}
403
404void WebGraphicsContext3DInProcessCommandBufferImpl::discardFramebufferEXT(
405    WGC3Denum target, WGC3Dsizei numAttachments, const WGC3Denum* attachments) {
406  gl_->DiscardFramebufferEXT(target, numAttachments, attachments);
407}
408
409void WebGraphicsContext3DInProcessCommandBufferImpl::
410    copyTextureToParentTextureCHROMIUM(WebGLId texture, WebGLId parentTexture) {
411  NOTIMPLEMENTED();
412}
413
414blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
415    getRequestableExtensionsCHROMIUM() {
416  // TODO(gmam): See if we can comment this in.
417  // ClearContext();
418  return blink::WebString::fromUTF8(
419      gl_->GetRequestableExtensionsCHROMIUM());
420}
421
422void WebGraphicsContext3DInProcessCommandBufferImpl::requestExtensionCHROMIUM(
423    const char* extension) {
424  // TODO(gmam): See if we can comment this in.
425  // ClearContext();
426  gl_->RequestExtensionCHROMIUM(extension);
427}
428
429void WebGraphicsContext3DInProcessCommandBufferImpl::blitFramebufferCHROMIUM(
430    WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
431    WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
432    WGC3Dbitfield mask, WGC3Denum filter) {
433  ClearContext();
434  gl_->BlitFramebufferCHROMIUM(
435      srcX0, srcY0, srcX1, srcY1,
436      dstX0, dstY0, dstX1, dstY1,
437      mask, filter);
438}
439
440void WebGraphicsContext3DInProcessCommandBufferImpl::
441    renderbufferStorageMultisampleCHROMIUM(
442        WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
443        WGC3Dsizei width, WGC3Dsizei height) {
444  ClearContext();
445  gl_->RenderbufferStorageMultisampleCHROMIUM(
446      target, samples, internalformat, width, height);
447}
448
449DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
450
451DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
452
453DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
454                 WGC3Duint, const WGC3Dchar*)
455
456DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
457
458void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer(
459    WGC3Denum target,
460    WebGLId framebuffer) {
461  ClearContext();
462  gl_->BindFramebuffer(target, framebuffer);
463}
464
465DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
466
467DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
468
469DELEGATE_TO_GL_4(blendColor, BlendColor,
470                 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
471
472DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
473
474DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
475                 WGC3Denum, WGC3Denum)
476
477DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
478
479DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
480                 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
481
482DELEGATE_TO_GL_4(bufferData, BufferData,
483                 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
484
485DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
486                 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
487
488DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
489                  WGC3Denum, WGC3Denum)
490
491DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
492
493DELEGATE_TO_GL_4(clearColor, ClearColor,
494                 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
495
496DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
497
498DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
499
500DELEGATE_TO_GL_4(colorMask, ColorMask,
501                 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
502
503DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
504
505DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
506                 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
507                 WGC3Dsizei, WGC3Dsizei, const void*)
508
509DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
510                 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
511                 WGC3Denum, WGC3Dsizei, const void*)
512
513DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
514                 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
515                 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
516
517DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
518                 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
519                 WGC3Dsizei, WGC3Dsizei)
520
521DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
522
523DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
524
525DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
526
527DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
528
529DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
530
531DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
532
533DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
534                 WGC3Duint)
535
536DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
537
538void WebGraphicsContext3DInProcessCommandBufferImpl::drawElements(
539    WGC3Denum mode,
540    WGC3Dsizei count,
541    WGC3Denum type,
542    WGC3Dintptr offset) {
543  ClearContext();
544  gl_->DrawElements(
545      mode, count, type,
546      reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
547}
548
549DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
550
551DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
552                 WGC3Duint)
553
554void WebGraphicsContext3DInProcessCommandBufferImpl::finish() {
555  flush_id_ = GenFlushID();
556  gl_->Finish();
557}
558
559void WebGraphicsContext3DInProcessCommandBufferImpl::flush() {
560  flush_id_ = GenFlushID();
561  gl_->Flush();
562}
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 = blink::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 = blink::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
643blink::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
674blink::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 blink::WebString();
681  scoped_ptr<GLchar[]> log(new GLchar[logLength]);
682  if (!log)
683    return blink::WebString();
684  GLsizei returnedLogLength = 0;
685  gl_->GetProgramInfoLog(
686      program, logLength, &returnedLogLength, log.get());
687  DCHECK_EQ(logLength, returnedLogLength + 1);
688  blink::WebString res =
689      blink::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
698blink::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 blink::WebString();
705  scoped_ptr<GLchar[]> log(new GLchar[logLength]);
706  if (!log)
707    return blink::WebString();
708  GLsizei returnedLogLength = 0;
709  gl_->GetShaderInfoLog(
710      shader, logLength, &returnedLogLength, log.get());
711  DCHECK_EQ(logLength, returnedLogLength + 1);
712  blink::WebString res =
713      blink::WebString::fromUTF8(log.get(), returnedLogLength);
714  return res;
715}
716
717DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
718                 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
719
720blink::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 blink::WebString();
727  scoped_ptr<GLchar[]> log(new GLchar[logLength]);
728  if (!log)
729    return blink::WebString();
730  GLsizei returnedLogLength = 0;
731  gl_->GetShaderSource(
732      shader, logLength, &returnedLogLength, log.get());
733  if (!returnedLogLength)
734    return blink::WebString();
735  DCHECK_EQ(logLength, returnedLogLength + 1);
736  blink::WebString res =
737      blink::WebString::fromUTF8(log.get(), returnedLogLength);
738  return res;
739}
740
741blink::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 blink::WebString();
749  scoped_ptr<GLchar[]> log(new GLchar[logLength]);
750  if (!log)
751    return blink::WebString();
752  GLsizei returnedLogLength = 0;
753  gl_->GetTranslatedShaderSourceANGLE(
754      shader, logLength, &returnedLogLength, log.get());
755  if (!returnedLogLength)
756    return blink::WebString();
757  DCHECK_EQ(logLength, returnedLogLength + 1);
758  blink::WebString res =
759      blink::WebString::fromUTF8(log.get(), returnedLogLength);
760  return res;
761}
762
763blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::getString(
764    WGC3Denum name) {
765  ClearContext();
766  return blink::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
974DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
975
976DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
977
978DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
979
980DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
981
982DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
983
984DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
985
986DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
987                 WebGLId*);
988
989DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
990
991WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createBuffer() {
992  ClearContext();
993  GLuint o;
994  gl_->GenBuffers(1, &o);
995  return o;
996}
997
998WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createFramebuffer() {
999  ClearContext();
1000  GLuint o = 0;
1001  gl_->GenFramebuffers(1, &o);
1002  return o;
1003}
1004
1005WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createRenderbuffer() {
1006  ClearContext();
1007  GLuint o;
1008  gl_->GenRenderbuffers(1, &o);
1009  return o;
1010}
1011
1012WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() {
1013  ClearContext();
1014  GLuint o;
1015  gl_->GenTextures(1, &o);
1016  return o;
1017}
1018
1019void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer(
1020    WebGLId buffer) {
1021  ClearContext();
1022  gl_->DeleteBuffers(1, &buffer);
1023}
1024
1025void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer(
1026    WebGLId framebuffer) {
1027  ClearContext();
1028  gl_->DeleteFramebuffers(1, &framebuffer);
1029}
1030
1031void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer(
1032    WebGLId renderbuffer) {
1033  ClearContext();
1034  gl_->DeleteRenderbuffers(1, &renderbuffer);
1035}
1036
1037void WebGraphicsContext3DInProcessCommandBufferImpl::deleteTexture(
1038    WebGLId texture) {
1039  ClearContext();
1040  gl_->DeleteTextures(1, &texture);
1041}
1042
1043DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId);
1044
1045DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId);
1046
1047DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId);
1048
1049DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId);
1050
1051void WebGraphicsContext3DInProcessCommandBufferImpl::setContextLostCallback(
1052    WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
1053  context_lost_callback_ = cb;
1054}
1055
1056WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::
1057    getGraphicsResetStatusARB() {
1058  return context_lost_reason_;
1059}
1060
1061DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
1062                 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
1063
1064DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
1065                 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
1066
1067WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createQueryEXT() {
1068  GLuint o;
1069  gl_->GenQueriesEXT(1, &o);
1070  return o;
1071}
1072
1073void WebGraphicsContext3DInProcessCommandBufferImpl::
1074    deleteQueryEXT(WebGLId query) {
1075  gl_->DeleteQueriesEXT(1, &query);
1076}
1077
1078DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
1079DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
1080DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
1081DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
1082DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
1083                 WebGLId, WGC3Denum, WGC3Duint*)
1084
1085DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum, WGC3Duint,
1086                 WGC3Duint, WGC3Dint, WGC3Denum, WGC3Denum)
1087
1088void WebGraphicsContext3DInProcessCommandBufferImpl::insertEventMarkerEXT(
1089    const WGC3Dchar* marker) {
1090  gl_->InsertEventMarkerEXT(0, marker);
1091}
1092
1093void WebGraphicsContext3DInProcessCommandBufferImpl::pushGroupMarkerEXT(
1094    const WGC3Dchar* marker) {
1095  gl_->PushGroupMarkerEXT(0, marker);
1096}
1097
1098DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
1099
1100DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
1101                 WGC3Denum, WGC3Dint)
1102DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
1103                 WGC3Denum, WGC3Dint)
1104
1105void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferCHROMIUM(
1106    WGC3Denum target, WGC3Denum access) {
1107  ClearContext();
1108  return gl_->MapBufferCHROMIUM(target, access);
1109}
1110
1111WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl::
1112    unmapBufferCHROMIUM(WGC3Denum target) {
1113  ClearContext();
1114  return gl_->UnmapBufferCHROMIUM(target);
1115}
1116
1117GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl::
1118    createGrGLInterface() {
1119  makeContextCurrent();
1120  return skia_bindings::CreateCommandBufferSkiaGLBinding();
1121}
1122
1123::gpu::gles2::GLES2Interface*
1124WebGraphicsContext3DInProcessCommandBufferImpl::GetGLInterface() {
1125  return gl_;
1126}
1127
1128::gpu::ContextSupport*
1129WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() {
1130  return gl_;
1131}
1132
1133void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
1134  // TODO(kbr): improve the precision here.
1135  context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
1136  if (context_lost_callback_) {
1137    context_lost_callback_->onContextLost();
1138  }
1139}
1140
1141DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM,
1142                  WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Duint);
1143
1144DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
1145
1146DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM,
1147                 WGC3Duint, WGC3Denum, GLint*);
1148
1149DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM,
1150                  WGC3Duint, WGC3Denum, void*);
1151
1152DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
1153
1154DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
1155                 FramebufferTexture2DMultisampleEXT,
1156                 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1157
1158DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1159                 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1160                 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1161
1162DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1163                 WebGLId, WGC3Dint, const WGC3Dchar*)
1164
1165void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFlushCHROMIUM() {
1166  flush_id_ = GenFlushID();
1167  gl_->ShallowFlushCHROMIUM();
1168}
1169
1170void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFinishCHROMIUM() {
1171  flush_id_ = GenFlushID();
1172  gl_->ShallowFinishCHROMIUM();
1173}
1174
1175DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1176DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1177                 WGC3Denum, const WGC3Dbyte*)
1178DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1179                 WGC3Denum, const WGC3Dbyte*)
1180
1181DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT,
1182                 WGC3Dsizei, const WGC3Denum*)
1183
1184DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned)
1185
1186void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM(
1187    WGC3Denum current, WGC3Denum other) {
1188  gl_->LoseContextCHROMIUM(current, other);
1189  gl_->ShallowFlushCHROMIUM();
1190}
1191
1192DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM,
1193    WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
1194    WGC3Denum, WGC3Denum, const void*)
1195
1196DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1197    WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1198    WGC3Denum, WGC3Denum, const void*)
1199
1200DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1201    WGC3Denum)
1202
1203}  // namespace gpu
1204}  // namespace webkit
1205