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