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_surface.h"
28
29 using gpu::gles2::GLES2Implementation;
30 using gpu::GLInProcessContext;
31
32 namespace webkit {
33 namespace gpu {
34
35 namespace {
36
37 const int32 kCommandBufferSize = 1024 * 1024;
38 // TODO(kbr): make the transfer buffer size configurable via context
39 // creation attributes.
40 const size_t kStartTransferBufferSize = 4 * 1024 * 1024;
41 const size_t kMinTransferBufferSize = 1 * 256 * 1024;
42 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
43
GenFlushID()44 uint32_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.
53 class GLES2Initializer {
54 public:
GLES2Initializer()55 GLES2Initializer() {
56 ::gles2::Initialize();
57 }
58
~GLES2Initializer()59 ~GLES2Initializer() {
60 ::gles2::Terminate();
61 }
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
65 };
66
67 static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
68 LAZY_INSTANCE_INITIALIZER;
69
70 } // namespace anonymous
71
72 // static
73 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
CreateViewContext(const blink::WebGraphicsContext3D::Attributes & attributes,gfx::AcceleratedWidget window)74 WebGraphicsContext3DInProcessCommandBufferImpl::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
86 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
CreateOffscreenContext(const blink::WebGraphicsContext3D::Attributes & attributes)87 WebGraphicsContext3DInProcessCommandBufferImpl::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
97 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
WrapContext(scoped_ptr<::gpu::GLInProcessContext> context,const blink::WebGraphicsContext3D::Attributes & attributes)98 WebGraphicsContext3DInProcessCommandBufferImpl::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
110 WebGraphicsContext3DInProcessCommandBufferImpl::
WebGraphicsContext3DInProcessCommandBufferImpl(scoped_ptr<::gpu::GLInProcessContext> context,const blink::WebGraphicsContext3D::Attributes & attributes,bool is_offscreen,gfx::AcceleratedWidget window)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
128 WebGraphicsContext3DInProcessCommandBufferImpl::
~WebGraphicsContext3DInProcessCommandBufferImpl()129 ~WebGraphicsContext3DInProcessCommandBufferImpl() {
130 }
131
132 // static
ConvertAttributes(const blink::WebGraphicsContext3D::Attributes & attributes,::gpu::GLInProcessContextAttribs * output_attribs)133 void 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
MaybeInitializeGL()145 bool 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
makeContextCurrent()210 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() {
211 if (!MaybeInitializeGL())
212 return false;
213 ::gles2::SetGLContext(gl_);
214 return context_ && !isContextLost();
215 }
216
lastFlushID()217 uint32_t WebGraphicsContext3DInProcessCommandBufferImpl::lastFlushID() {
218 return flush_id_;
219 }
220
ClearContext()221 void 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) \
238 void WebGraphicsContext3DInProcessCommandBufferImpl::name() { \
239 ClearContext(); \
240 gl_->glname(); \
241 }
242
243 #define DELEGATE_TO_GL_R(name, glname, rt) \
244 rt WebGraphicsContext3DInProcessCommandBufferImpl::name() { \
245 ClearContext(); \
246 return gl_->glname(); \
247 }
248
249 #define DELEGATE_TO_GL_1(name, glname, t1) \
250 void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \
251 ClearContext(); \
252 gl_->glname(a1); \
253 }
254
255 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
256 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \
257 ClearContext(); \
258 return gl_->glname(a1); \
259 }
260
261 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
262 rt 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) \
268 void 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) \
275 rt 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) \
281 void 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) \
288 rt 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) \
295 void 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) \
302 void 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) \
309 void 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) \
316 void 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) \
323 void 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) \
330 void 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
prepareTexture()336 void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() {
337 NOTREACHED();
338 }
339
postSubBufferCHROMIUM(int x,int y,int width,int height)340 void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM(
341 int x, int y, int width, int height) {
342 NOTREACHED();
343 }
344
DELEGATE_TO_GL_3(reshapeWithScaleFactor,ResizeCHROMIUM,int,int,float)345 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
346
347 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError(
348 WGC3Denum error) {
349 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
350 synthetic_errors_.end()) {
351 synthetic_errors_.push_back(error);
352 }
353 }
354
mapBufferSubDataCHROMIUM(WGC3Denum target,WGC3Dintptr offset,WGC3Dsizeiptr size,WGC3Denum access)355 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM(
356 WGC3Denum target,
357 WGC3Dintptr offset,
358 WGC3Dsizeiptr size,
359 WGC3Denum access) {
360 ClearContext();
361 return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access);
362 }
363
unmapBufferSubDataCHROMIUM(const void * mem)364 void WebGraphicsContext3DInProcessCommandBufferImpl::unmapBufferSubDataCHROMIUM(
365 const void* mem) {
366 ClearContext();
367 return gl_->UnmapBufferSubDataCHROMIUM(mem);
368 }
369
mapTexSubImage2DCHROMIUM(WGC3Denum target,WGC3Dint level,WGC3Dint xoffset,WGC3Dint yoffset,WGC3Dsizei width,WGC3Dsizei height,WGC3Denum format,WGC3Denum type,WGC3Denum access)370 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapTexSubImage2DCHROMIUM(
371 WGC3Denum target,
372 WGC3Dint level,
373 WGC3Dint xoffset,
374 WGC3Dint yoffset,
375 WGC3Dsizei width,
376 WGC3Dsizei height,
377 WGC3Denum format,
378 WGC3Denum type,
379 WGC3Denum access) {
380 ClearContext();
381 return gl_->MapTexSubImage2DCHROMIUM(
382 target, level, xoffset, yoffset, width, height, format, type, access);
383 }
384
unmapTexSubImage2DCHROMIUM(const void * mem)385 void WebGraphicsContext3DInProcessCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
386 const void* mem) {
387 ClearContext();
388 gl_->UnmapTexSubImage2DCHROMIUM(mem);
389 }
390
setVisibilityCHROMIUM(bool visible)391 void WebGraphicsContext3DInProcessCommandBufferImpl::setVisibilityCHROMIUM(
392 bool visible) {
393 }
394
discardFramebufferEXT(WGC3Denum target,WGC3Dsizei numAttachments,const WGC3Denum * attachments)395 void WebGraphicsContext3DInProcessCommandBufferImpl::discardFramebufferEXT(
396 WGC3Denum target, WGC3Dsizei numAttachments, const WGC3Denum* attachments) {
397 gl_->DiscardFramebufferEXT(target, numAttachments, attachments);
398 }
399
400 void WebGraphicsContext3DInProcessCommandBufferImpl::
copyTextureToParentTextureCHROMIUM(WebGLId texture,WebGLId parentTexture)401 copyTextureToParentTextureCHROMIUM(WebGLId texture, WebGLId parentTexture) {
402 NOTIMPLEMENTED();
403 }
404
405 void WebGraphicsContext3DInProcessCommandBufferImpl::
rateLimitOffscreenContextCHROMIUM()406 rateLimitOffscreenContextCHROMIUM() {
407 // TODO(gmam): See if we can comment this in.
408 // ClearContext();
409 gl_->RateLimitOffscreenContextCHROMIUM();
410 }
411
412 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
getRequestableExtensionsCHROMIUM()413 getRequestableExtensionsCHROMIUM() {
414 // TODO(gmam): See if we can comment this in.
415 // ClearContext();
416 return blink::WebString::fromUTF8(
417 gl_->GetRequestableExtensionsCHROMIUM());
418 }
419
requestExtensionCHROMIUM(const char * extension)420 void WebGraphicsContext3DInProcessCommandBufferImpl::requestExtensionCHROMIUM(
421 const char* extension) {
422 // TODO(gmam): See if we can comment this in.
423 // ClearContext();
424 gl_->RequestExtensionCHROMIUM(extension);
425 }
426
blitFramebufferCHROMIUM(WGC3Dint srcX0,WGC3Dint srcY0,WGC3Dint srcX1,WGC3Dint srcY1,WGC3Dint dstX0,WGC3Dint dstY0,WGC3Dint dstX1,WGC3Dint dstY1,WGC3Dbitfield mask,WGC3Denum filter)427 void WebGraphicsContext3DInProcessCommandBufferImpl::blitFramebufferCHROMIUM(
428 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
429 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
430 WGC3Dbitfield mask, WGC3Denum filter) {
431 ClearContext();
432 gl_->BlitFramebufferCHROMIUM(
433 srcX0, srcY0, srcX1, srcY1,
434 dstX0, dstY0, dstX1, dstY1,
435 mask, filter);
436 }
437
438 void WebGraphicsContext3DInProcessCommandBufferImpl::
renderbufferStorageMultisampleCHROMIUM(WGC3Denum target,WGC3Dsizei samples,WGC3Denum internalformat,WGC3Dsizei width,WGC3Dsizei height)439 renderbufferStorageMultisampleCHROMIUM(
440 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
441 WGC3Dsizei width, WGC3Dsizei height) {
442 ClearContext();
443 gl_->RenderbufferStorageMultisampleCHROMIUM(
444 target, samples, internalformat, width, height);
445 }
446
DELEGATE_TO_GL_1(activeTexture,ActiveTexture,WGC3Denum)447 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
448
449 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
450
451 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
452 WGC3Duint, const WGC3Dchar*)
453
454 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
455
456 void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer(
457 WGC3Denum target,
458 WebGLId framebuffer) {
459 ClearContext();
460 gl_->BindFramebuffer(target, framebuffer);
461 }
462
DELEGATE_TO_GL_2(bindRenderbuffer,BindRenderbuffer,WGC3Denum,WebGLId)463 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
464
465 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
466
467 DELEGATE_TO_GL_4(blendColor, BlendColor,
468 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
469
470 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
471
472 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
473 WGC3Denum, WGC3Denum)
474
475 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
476
477 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
478 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
479
480 DELEGATE_TO_GL_4(bufferData, BufferData,
481 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
482
483 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
484 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
485
486 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
487 WGC3Denum, WGC3Denum)
488
489 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
490
491 DELEGATE_TO_GL_4(clearColor, ClearColor,
492 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
493
494 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
495
496 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
497
498 DELEGATE_TO_GL_4(colorMask, ColorMask,
499 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
500
501 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
502
503 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
504 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
505 WGC3Dsizei, WGC3Dsizei, const void*)
506
507 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
508 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
509 WGC3Denum, WGC3Dsizei, const void*)
510
511 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
512 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
513 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
514
515 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
516 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
517 WGC3Dsizei, WGC3Dsizei)
518
519 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
520
521 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
522
523 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
524
525 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
526
527 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
528
529 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
530
531 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
532 WGC3Duint)
533
534 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
535
536 void WebGraphicsContext3DInProcessCommandBufferImpl::drawElements(
537 WGC3Denum mode,
538 WGC3Dsizei count,
539 WGC3Denum type,
540 WGC3Dintptr offset) {
541 ClearContext();
542 gl_->DrawElements(
543 mode, count, type,
544 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
545 }
546
DELEGATE_TO_GL_1(enable,Enable,WGC3Denum)547 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
548
549 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
550 WGC3Duint)
551
552 void WebGraphicsContext3DInProcessCommandBufferImpl::finish() {
553 flush_id_ = GenFlushID();
554 gl_->Finish();
555 }
556
flush()557 void WebGraphicsContext3DInProcessCommandBufferImpl::flush() {
558 flush_id_ = GenFlushID();
559 gl_->Flush();
560 }
561
DELEGATE_TO_GL_4(framebufferRenderbuffer,FramebufferRenderbuffer,WGC3Denum,WGC3Denum,WGC3Denum,WebGLId)562 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
563 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
564
565 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
566 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
567
568 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
569
570 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
571
572 bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveAttrib(
573 WebGLId program, WGC3Duint index, ActiveInfo& info) {
574 ClearContext();
575 if (!program) {
576 synthesizeGLError(GL_INVALID_VALUE);
577 return false;
578 }
579 GLint max_name_length = -1;
580 gl_->GetProgramiv(
581 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
582 if (max_name_length < 0)
583 return false;
584 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
585 if (!name) {
586 synthesizeGLError(GL_OUT_OF_MEMORY);
587 return false;
588 }
589 GLsizei length = 0;
590 GLint size = -1;
591 GLenum type = 0;
592 gl_->GetActiveAttrib(
593 program, index, max_name_length, &length, &size, &type, name.get());
594 if (size < 0) {
595 return false;
596 }
597 info.name = blink::WebString::fromUTF8(name.get(), length);
598 info.type = type;
599 info.size = size;
600 return true;
601 }
602
getActiveUniform(WebGLId program,WGC3Duint index,ActiveInfo & info)603 bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveUniform(
604 WebGLId program, WGC3Duint index, ActiveInfo& info) {
605 ClearContext();
606 GLint max_name_length = -1;
607 gl_->GetProgramiv(
608 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
609 if (max_name_length < 0)
610 return false;
611 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
612 if (!name) {
613 synthesizeGLError(GL_OUT_OF_MEMORY);
614 return false;
615 }
616 GLsizei length = 0;
617 GLint size = -1;
618 GLenum type = 0;
619 gl_->GetActiveUniform(
620 program, index, max_name_length, &length, &size, &type, name.get());
621 if (size < 0) {
622 return false;
623 }
624 info.name = blink::WebString::fromUTF8(name.get(), length);
625 info.type = type;
626 info.size = size;
627 return true;
628 }
629
DELEGATE_TO_GL_4(getAttachedShaders,GetAttachedShaders,WebGLId,WGC3Dsizei,WGC3Dsizei *,WebGLId *)630 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
631 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
632
633 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
634 WebGLId, const WGC3Dchar*, WGC3Dint)
635
636 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
637
638 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
639 WGC3Denum, WGC3Denum, WGC3Dint*)
640
641 blink::WebGraphicsContext3D::Attributes
642 WebGraphicsContext3DInProcessCommandBufferImpl::getContextAttributes() {
643 return attributes_;
644 }
645
getError()646 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::getError() {
647 ClearContext();
648 if (!synthetic_errors_.empty()) {
649 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
650 WGC3Denum err = *iter;
651 synthetic_errors_.erase(iter);
652 return err;
653 }
654
655 return gl_->GetError();
656 }
657
isContextLost()658 bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() {
659 return context_lost_reason_ != GL_NO_ERROR;
660 }
661
DELEGATE_TO_GL_2(getFloatv,GetFloatv,WGC3Denum,WGC3Dfloat *)662 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
663
664 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
665 GetFramebufferAttachmentParameteriv,
666 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
667
668 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
669
670 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
671
672 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
673 getProgramInfoLog(WebGLId program) {
674 ClearContext();
675 GLint logLength = 0;
676 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
677 if (!logLength)
678 return blink::WebString();
679 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
680 if (!log)
681 return blink::WebString();
682 GLsizei returnedLogLength = 0;
683 gl_->GetProgramInfoLog(
684 program, logLength, &returnedLogLength, log.get());
685 DCHECK_EQ(logLength, returnedLogLength + 1);
686 blink::WebString res =
687 blink::WebString::fromUTF8(log.get(), returnedLogLength);
688 return res;
689 }
690
DELEGATE_TO_GL_3(getRenderbufferParameteriv,GetRenderbufferParameteriv,WGC3Denum,WGC3Denum,WGC3Dint *)691 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
692 WGC3Denum, WGC3Denum, WGC3Dint*)
693
694 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
695
696 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
697 getShaderInfoLog(WebGLId shader) {
698 ClearContext();
699 GLint logLength = 0;
700 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
701 if (!logLength)
702 return blink::WebString();
703 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
704 if (!log)
705 return blink::WebString();
706 GLsizei returnedLogLength = 0;
707 gl_->GetShaderInfoLog(
708 shader, logLength, &returnedLogLength, log.get());
709 DCHECK_EQ(logLength, returnedLogLength + 1);
710 blink::WebString res =
711 blink::WebString::fromUTF8(log.get(), returnedLogLength);
712 return res;
713 }
714
DELEGATE_TO_GL_4(getShaderPrecisionFormat,GetShaderPrecisionFormat,WGC3Denum,WGC3Denum,WGC3Dint *,WGC3Dint *)715 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
716 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
717
718 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
719 getShaderSource(WebGLId shader) {
720 ClearContext();
721 GLint logLength = 0;
722 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
723 if (!logLength)
724 return blink::WebString();
725 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
726 if (!log)
727 return blink::WebString();
728 GLsizei returnedLogLength = 0;
729 gl_->GetShaderSource(
730 shader, logLength, &returnedLogLength, log.get());
731 if (!returnedLogLength)
732 return blink::WebString();
733 DCHECK_EQ(logLength, returnedLogLength + 1);
734 blink::WebString res =
735 blink::WebString::fromUTF8(log.get(), returnedLogLength);
736 return res;
737 }
738
739 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
getTranslatedShaderSourceANGLE(WebGLId shader)740 getTranslatedShaderSourceANGLE(WebGLId shader) {
741 ClearContext();
742 GLint logLength = 0;
743 gl_->GetShaderiv(
744 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
745 if (!logLength)
746 return blink::WebString();
747 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
748 if (!log)
749 return blink::WebString();
750 GLsizei returnedLogLength = 0;
751 gl_->GetTranslatedShaderSourceANGLE(
752 shader, logLength, &returnedLogLength, log.get());
753 if (!returnedLogLength)
754 return blink::WebString();
755 DCHECK_EQ(logLength, returnedLogLength + 1);
756 blink::WebString res =
757 blink::WebString::fromUTF8(log.get(), returnedLogLength);
758 return res;
759 }
760
getString(WGC3Denum name)761 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::getString(
762 WGC3Denum name) {
763 ClearContext();
764 return blink::WebString::fromUTF8(
765 reinterpret_cast<const char*>(gl_->GetString(name)));
766 }
767
DELEGATE_TO_GL_3(getTexParameterfv,GetTexParameterfv,WGC3Denum,WGC3Denum,WGC3Dfloat *)768 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
769 WGC3Denum, WGC3Denum, WGC3Dfloat*)
770
771 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
772 WGC3Denum, WGC3Denum, WGC3Dint*)
773
774 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
775
776 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
777
778 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
779 WebGLId, const WGC3Dchar*, WGC3Dint)
780
781 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
782 WGC3Duint, WGC3Denum, WGC3Dfloat*)
783
784 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
785 WGC3Duint, WGC3Denum, WGC3Dint*)
786
787 WGC3Dsizeiptr WebGraphicsContext3DInProcessCommandBufferImpl::
788 getVertexAttribOffset(WGC3Duint index, WGC3Denum pname) {
789 ClearContext();
790 GLvoid* value = NULL;
791 // NOTE: If pname is ever a value that returns more then 1 element
792 // this will corrupt memory.
793 gl_->GetVertexAttribPointerv(index, pname, &value);
794 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
795 }
796
DELEGATE_TO_GL_2(hint,Hint,WGC3Denum,WGC3Denum)797 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
798
799 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
800
801 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
802
803 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
804
805 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
806
807 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
808
809 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
810
811 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
812
813 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
814
815 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
816
817 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
818
819 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
820
821 DELEGATE_TO_GL_7(readPixels, ReadPixels,
822 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
823 WGC3Denum, void*)
824
825 void WebGraphicsContext3DInProcessCommandBufferImpl::releaseShaderCompiler() {
826 ClearContext();
827 }
828
DELEGATE_TO_GL_4(renderbufferStorage,RenderbufferStorage,WGC3Denum,WGC3Denum,WGC3Dsizei,WGC3Dsizei)829 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
830 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
831
832 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
833
834 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
835
836 void WebGraphicsContext3DInProcessCommandBufferImpl::shaderSource(
837 WebGLId shader, const WGC3Dchar* string) {
838 ClearContext();
839 GLint length = strlen(string);
840 gl_->ShaderSource(shader, 1, &string, &length);
841 }
842
843 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
844
845 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
846 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
847
848 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
849
850 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
851 WGC3Denum, WGC3Duint)
852
853 DELEGATE_TO_GL_3(stencilOp, StencilOp,
854 WGC3Denum, WGC3Denum, WGC3Denum)
855
856 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
857 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
858
859 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
860 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
861 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
862
863 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
864 WGC3Denum, WGC3Denum, WGC3Dfloat);
865
866 static const unsigned int kTextureWrapR = 0x8072;
867
texParameteri(WGC3Denum target,WGC3Denum pname,WGC3Dint param)868 void WebGraphicsContext3DInProcessCommandBufferImpl::texParameteri(
869 WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
870 ClearContext();
871 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
872 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
873 // edge of cube maps, and, if it is, push it into the GLES2 service
874 // side code.
875 if (pname == kTextureWrapR) {
876 return;
877 }
878 gl_->TexParameteri(target, pname, param);
879 }
880
DELEGATE_TO_GL_9(texSubImage2D,TexSubImage2D,WGC3Denum,WGC3Dint,WGC3Dint,WGC3Dint,WGC3Dsizei,WGC3Dsizei,WGC3Denum,WGC3Denum,const void *)881 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
882 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
883 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
884
885 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
886
887 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
888 const WGC3Dfloat*)
889
890 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
891
892 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
893
894 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
895
896 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
897 const WGC3Dfloat*)
898
899 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
900
901 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
902
903 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
904 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
905
906 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
907 const WGC3Dfloat*)
908
909 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
910
911 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
912
913 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
914 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
915
916 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
917 const WGC3Dfloat*)
918
919 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
920 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
921
922 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
923
924 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
925 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
926
927 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
928 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
929
930 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
931 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
932
933 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
934
935 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
936
937 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
938
939 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
940 const WGC3Dfloat*)
941
942 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
943 WGC3Dfloat, WGC3Dfloat)
944
945 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
946 const WGC3Dfloat*)
947
948 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
949 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
950
951 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
952 const WGC3Dfloat*)
953
954 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
955 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
956
957 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
958 const WGC3Dfloat*)
959
960 void WebGraphicsContext3DInProcessCommandBufferImpl::vertexAttribPointer(
961 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
962 WGC3Dsizei stride, WGC3Dintptr offset) {
963 ClearContext();
964 gl_->VertexAttribPointer(
965 index, size, type, normalized, stride,
966 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
967 }
968
969 DELEGATE_TO_GL_4(viewport, Viewport,
970 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
971
972 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
973
974 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
975
976 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
977
978 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
979
980 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
981
982 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
983
984 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
985 WebGLId*);
986
987 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
988
createBuffer()989 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createBuffer() {
990 ClearContext();
991 GLuint o;
992 gl_->GenBuffers(1, &o);
993 return o;
994 }
995
createFramebuffer()996 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createFramebuffer() {
997 ClearContext();
998 GLuint o = 0;
999 gl_->GenFramebuffers(1, &o);
1000 return o;
1001 }
1002
createRenderbuffer()1003 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createRenderbuffer() {
1004 ClearContext();
1005 GLuint o;
1006 gl_->GenRenderbuffers(1, &o);
1007 return o;
1008 }
1009
createTexture()1010 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() {
1011 ClearContext();
1012 GLuint o;
1013 gl_->GenTextures(1, &o);
1014 return o;
1015 }
1016
deleteBuffer(WebGLId buffer)1017 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer(
1018 WebGLId buffer) {
1019 ClearContext();
1020 gl_->DeleteBuffers(1, &buffer);
1021 }
1022
deleteFramebuffer(WebGLId framebuffer)1023 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer(
1024 WebGLId framebuffer) {
1025 ClearContext();
1026 gl_->DeleteFramebuffers(1, &framebuffer);
1027 }
1028
deleteRenderbuffer(WebGLId renderbuffer)1029 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer(
1030 WebGLId renderbuffer) {
1031 ClearContext();
1032 gl_->DeleteRenderbuffers(1, &renderbuffer);
1033 }
1034
deleteTexture(WebGLId texture)1035 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteTexture(
1036 WebGLId texture) {
1037 ClearContext();
1038 gl_->DeleteTextures(1, &texture);
1039 }
1040
1041 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId);
1042
1043 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId);
1044
1045 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId);
1046
1047 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId);
1048
setContextLostCallback(WebGraphicsContext3D::WebGraphicsContextLostCallback * cb)1049 void WebGraphicsContext3DInProcessCommandBufferImpl::setContextLostCallback(
1050 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
1051 context_lost_callback_ = cb;
1052 }
1053
1054 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::
getGraphicsResetStatusARB()1055 getGraphicsResetStatusARB() {
1056 return context_lost_reason_;
1057 }
1058
DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM,TexImageIOSurface2DCHROMIUM,WGC3Denum,WGC3Dint,WGC3Dint,WGC3Duint,WGC3Duint)1059 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
1060 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
1061
1062 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
1063 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
1064
1065 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createQueryEXT() {
1066 GLuint o;
1067 gl_->GenQueriesEXT(1, &o);
1068 return o;
1069 }
1070
1071 void WebGraphicsContext3DInProcessCommandBufferImpl::
deleteQueryEXT(WebGLId query)1072 deleteQueryEXT(WebGLId query) {
1073 gl_->DeleteQueriesEXT(1, &query);
1074 }
1075
DELEGATE_TO_GL_1R(isQueryEXT,IsQueryEXT,WebGLId,WGC3Dboolean)1076 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
1077 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
1078 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
1079 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
1080 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
1081 WebGLId, WGC3Denum, WGC3Duint*)
1082
1083 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum, WGC3Duint,
1084 WGC3Duint, WGC3Dint, WGC3Denum, WGC3Denum)
1085
1086 void WebGraphicsContext3DInProcessCommandBufferImpl::insertEventMarkerEXT(
1087 const WGC3Dchar* marker) {
1088 gl_->InsertEventMarkerEXT(0, marker);
1089 }
1090
pushGroupMarkerEXT(const WGC3Dchar * marker)1091 void WebGraphicsContext3DInProcessCommandBufferImpl::pushGroupMarkerEXT(
1092 const WGC3Dchar* marker) {
1093 gl_->PushGroupMarkerEXT(0, marker);
1094 }
1095
1096 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
1097
DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM,BindTexImage2DCHROMIUM,WGC3Denum,WGC3Dint)1098 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
1099 WGC3Denum, WGC3Dint)
1100 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
1101 WGC3Denum, WGC3Dint)
1102
1103 DELEGATE_TO_GL_1R(createStreamTextureCHROMIUM, CreateStreamTextureCHROMIUM,
1104 WebGLId, WebGLId)
1105 DELEGATE_TO_GL_1(destroyStreamTextureCHROMIUM, DestroyStreamTextureCHROMIUM,
1106 WebGLId)
1107
1108 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferCHROMIUM(
1109 WGC3Denum target, WGC3Denum access) {
1110 ClearContext();
1111 return gl_->MapBufferCHROMIUM(target, access);
1112 }
1113
1114 WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl::
unmapBufferCHROMIUM(WGC3Denum target)1115 unmapBufferCHROMIUM(WGC3Denum target) {
1116 ClearContext();
1117 return gl_->UnmapBufferCHROMIUM(target);
1118 }
1119
1120 GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl::
createGrGLInterface()1121 createGrGLInterface() {
1122 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1123 }
1124
1125 ::gpu::gles2::GLES2Interface*
GetGLInterface()1126 WebGraphicsContext3DInProcessCommandBufferImpl::GetGLInterface() {
1127 return gl_;
1128 }
1129
1130 ::gpu::ContextSupport*
GetContextSupport()1131 WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() {
1132 return gl_;
1133 }
1134
OnContextLost()1135 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
1136 // TODO(kbr): improve the precision here.
1137 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
1138 if (context_lost_callback_) {
1139 context_lost_callback_->onContextLost();
1140 }
1141 }
1142
1143 DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM,
1144 WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Duint);
1145
1146 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
1147
1148 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM,
1149 WGC3Duint, WGC3Denum, GLint*);
1150
1151 DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM,
1152 WGC3Duint, WGC3Denum, void*);
1153
1154 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
1155
DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM,BindUniformLocationCHROMIUM,WebGLId,WGC3Dint,const WGC3Dchar *)1156 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1157 WebGLId, WGC3Dint, const WGC3Dchar*)
1158
1159 void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFlushCHROMIUM() {
1160 flush_id_ = GenFlushID();
1161 gl_->ShallowFlushCHROMIUM();
1162 }
1163
shallowFinishCHROMIUM()1164 void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFinishCHROMIUM() {
1165 flush_id_ = GenFlushID();
1166 gl_->ShallowFinishCHROMIUM();
1167 }
1168
DELEGATE_TO_GL_1(genMailboxCHROMIUM,GenMailboxCHROMIUM,WGC3Dbyte *)1169 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1170 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1171 WGC3Denum, const WGC3Dbyte*)
1172 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1173 WGC3Denum, const WGC3Dbyte*)
1174
1175 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT,
1176 WGC3Dsizei, const WGC3Denum*)
1177
1178 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned)
1179
1180 void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM(
1181 WGC3Denum current, WGC3Denum other) {
1182 gl_->LoseContextCHROMIUM(current, other);
1183 gl_->ShallowFlushCHROMIUM();
1184 }
1185
1186 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM,
1187 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
1188 WGC3Denum, WGC3Denum, const void*)
1189
1190 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1191 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1192 WGC3Denum, WGC3Denum, const void*)
1193
1194 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1195 WGC3Denum)
1196
1197 } // namespace gpu
1198 } // namespace webkit
1199