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