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