Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / gpu / blink / webgraphicscontext3d_impl.cc
blob576b7b71ee3897fff4772f12c52c8ae8123e8cfc
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.
5 #include "gpu/blink/webgraphicscontext3d_impl.h"
7 #include "base/atomicops.h"
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
10 #include "gpu/GLES2/gl2extchromium.h"
11 #include "gpu/command_buffer/client/gles2_implementation.h"
12 #include "gpu/command_buffer/client/gles2_lib.h"
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
14 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
16 #include "third_party/khronos/GLES2/gl2.h"
17 #ifndef GL_GLEXT_PROTOTYPES
18 #define GL_GLEXT_PROTOTYPES 1
19 #endif
20 #include "third_party/khronos/GLES2/gl2ext.h"
22 using blink::WGC3Dbitfield;
23 using blink::WGC3Dboolean;
24 using blink::WGC3Dbyte;
25 using blink::WGC3Dchar;
26 using blink::WGC3Dclampf;
27 using blink::WGC3Denum;
28 using blink::WGC3Dfloat;
29 using blink::WGC3Dint;
30 using blink::WGC3Dintptr;
31 using blink::WGC3Dsizei;
32 using blink::WGC3Dsizeiptr;
33 using blink::WGC3Dint64;
34 using blink::WGC3Duint64;
35 using blink::WGC3Duint;
36 using blink::WebGLId;
37 using blink::WGC3Dsync;
39 namespace gpu_blink {
41 namespace {
43 uint32_t GenFlushID() {
44 static base::subtle::Atomic32 flush_id = 0;
46 base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
47 &flush_id, 1);
48 return static_cast<uint32_t>(my_id);
51 } // namespace anonymous
53 class WebGraphicsContext3DErrorMessageCallback
54 : public ::gpu::gles2::GLES2ImplementationErrorMessageCallback {
55 public:
56 WebGraphicsContext3DErrorMessageCallback(
57 WebGraphicsContext3DImpl* context)
58 : graphics_context_(context) {
61 void OnErrorMessage(const char* msg, int id) override;
63 private:
64 WebGraphicsContext3DImpl* graphics_context_;
66 DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
69 void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
70 const char* msg, int id) {
71 graphics_context_->OnErrorMessage(msg, id);
74 // Helper macros to reduce the amount of code.
76 #define DELEGATE_TO_GL(name, glname) \
77 void WebGraphicsContext3DImpl::name() { \
78 gl_->glname(); \
81 #define DELEGATE_TO_GL_R(name, glname, rt) \
82 rt WebGraphicsContext3DImpl::name() { \
83 return gl_->glname(); \
86 #define DELEGATE_TO_GL_1(name, glname, t1) \
87 void WebGraphicsContext3DImpl::name(t1 a1) { \
88 gl_->glname(a1); \
91 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
92 rt WebGraphicsContext3DImpl::name(t1 a1) { \
93 return gl_->glname(a1); \
96 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
97 rt WebGraphicsContext3DImpl::name(t1 a1) { \
98 return gl_->glname(a1) ? true : false; \
101 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
102 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
103 gl_->glname(a1, a2); \
106 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
107 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
108 return gl_->glname(a1, a2); \
111 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
112 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
113 gl_->glname(a1, a2, a3); \
116 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
117 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
118 return gl_->glname(a1, a2, a3); \
121 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
122 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
123 gl_->glname(a1, a2, a3, a4); \
126 #define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt) \
127 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
128 return gl_->glname(a1, a2, a3, a4); \
131 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
132 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {\
134 gl_->glname(a1, a2, a3, a4, a5); \
137 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
138 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
139 t6 a6) { \
140 gl_->glname(a1, a2, a3, a4, a5, a6); \
143 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
144 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
145 t6 a6, t7 a7) { \
146 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
149 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
150 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
151 t6 a6, t7 a7, t8 a8) { \
152 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
155 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
156 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
157 t6 a6, t7 a7, t8 a8, t9 a9) { \
158 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
161 #define DELEGATE_TO_GL_9R(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
162 t9, rt) \
163 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
164 t6 a6, t7 a7, t8 a8, t9 a9) { \
165 return gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
168 #define DELEGATE_TO_GL_10(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
169 t9, t10) \
170 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
171 t6 a6, t7 a7, t8 a8, t9 a9, \
172 t10 a10) { \
173 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
176 #define DELEGATE_TO_GL_11(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
177 t9, t10, t11) \
178 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
179 t6 a6, t7 a7, t8 a8, t9 a9, t10 a10,\
180 t11 a11) { \
181 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); \
184 #define DELEGATE_TO_GL_12(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
185 t9, t10, t11, t12) \
186 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
187 t6 a6, t7 a7, t8 a8, t9 a9, t10 a10,\
188 t11 a11, t12 a12) { \
189 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); \
192 WebGraphicsContext3DImpl::WebGraphicsContext3DImpl()
193 : initialized_(false),
194 initialize_failed_(false),
195 context_lost_callback_(0),
196 error_message_callback_(0),
197 gl_(NULL),
198 flush_id_(0) {
201 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() {
205 void WebGraphicsContext3DImpl::synthesizeGLError(WGC3Denum error) {
206 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
207 synthetic_errors_.end()) {
208 synthetic_errors_.push_back(error);
212 uint32_t WebGraphicsContext3DImpl::lastFlushID() {
213 return flush_id_;
216 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int)
218 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
220 DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum,
221 WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*)
223 DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM,
224 const void*)
226 DELEGATE_TO_GL_9R(mapTexSubImage2DCHROMIUM, MapTexSubImage2DCHROMIUM, WGC3Denum,
227 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
228 WGC3Denum, WGC3Denum, WGC3Denum, void*)
230 DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM,
231 const void*)
233 DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum,
234 WGC3Dsizei, const WGC3Denum*)
236 blink::WebString WebGraphicsContext3DImpl::
237 getRequestableExtensionsCHROMIUM() {
238 return blink::WebString::fromUTF8(
239 gl_->GetRequestableExtensionsCHROMIUM());
242 DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM,
243 const char*)
245 void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM(
246 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
247 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
248 WGC3Dbitfield mask, WGC3Denum filter) {
249 gl_->BlitFramebufferCHROMIUM(
250 srcX0, srcY0, srcX1, srcY1,
251 dstX0, dstY0, dstX1, dstY1,
252 mask, filter);
255 DELEGATE_TO_GL_5(renderbufferStorageMultisampleCHROMIUM,
256 RenderbufferStorageMultisampleCHROMIUM, WGC3Denum, WGC3Dsizei,
257 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
259 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
261 DELEGATE_TO_GL(applyScreenSpaceAntialiasingCHROMIUM,
262 ApplyScreenSpaceAntialiasingCHROMIUM);
264 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
266 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
267 WGC3Duint, const WGC3Dchar*)
269 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
271 DELEGATE_TO_GL_2(bindFramebuffer, BindFramebuffer, WGC3Denum, WebGLId)
273 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
275 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
277 DELEGATE_TO_GL_4(blendColor, BlendColor,
278 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
280 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
282 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
283 WGC3Denum, WGC3Denum)
285 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
287 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
288 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
290 DELEGATE_TO_GL_4(bufferData, BufferData,
291 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
293 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
294 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
296 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
297 WGC3Denum, WGC3Denum)
299 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
301 DELEGATE_TO_GL_4(clearColor, ClearColor,
302 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
304 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
306 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
308 DELEGATE_TO_GL_4(colorMask, ColorMask,
309 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
311 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
313 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
314 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
315 WGC3Dsizei, WGC3Dsizei, const void*)
317 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
318 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
319 WGC3Denum, WGC3Dsizei, const void*)
321 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
322 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
323 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
325 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
326 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
327 WGC3Dsizei, WGC3Dsizei)
329 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
331 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
333 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
335 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
337 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
339 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
341 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
342 WGC3Duint)
344 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
346 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode,
347 WGC3Dsizei count,
348 WGC3Denum type,
349 WGC3Dintptr offset) {
350 gl_->DrawElements(
351 mode, count, type,
352 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
355 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
357 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
358 WGC3Duint)
360 void WebGraphicsContext3DImpl::finish() {
361 flush_id_ = GenFlushID();
362 gl_->Finish();
365 void WebGraphicsContext3DImpl::flush() {
366 flush_id_ = GenFlushID();
367 gl_->Flush();
370 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
371 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
373 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
374 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
376 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
378 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
380 bool WebGraphicsContext3DImpl::getActiveAttrib(
381 WebGLId program, WGC3Duint index, ActiveInfo& info) {
382 if (!program) {
383 synthesizeGLError(GL_INVALID_VALUE);
384 return false;
386 GLint max_name_length = -1;
387 gl_->GetProgramiv(
388 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
389 if (max_name_length < 0)
390 return false;
391 if (max_name_length == 0) {
392 // No active attributes exist.
393 synthesizeGLError(GL_INVALID_VALUE);
394 return false;
396 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
397 GLsizei length = 0;
398 GLint size = -1;
399 GLenum type = 0;
400 gl_->GetActiveAttrib(
401 program, index, max_name_length, &length, &size, &type, name.get());
402 if (size < 0) {
403 return false;
405 info.name = blink::WebString::fromUTF8(name.get(), length);
406 info.type = type;
407 info.size = size;
408 return true;
411 bool WebGraphicsContext3DImpl::getActiveUniform(
412 WebGLId program, WGC3Duint index, ActiveInfo& info) {
413 GLint max_name_length = -1;
414 gl_->GetProgramiv(
415 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
416 if (max_name_length < 0)
417 return false;
418 if (max_name_length == 0) {
419 // No active uniforms exist.
420 synthesizeGLError(GL_INVALID_VALUE);
421 return false;
423 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
424 GLsizei length = 0;
425 GLint size = -1;
426 GLenum type = 0;
427 gl_->GetActiveUniform(
428 program, index, max_name_length, &length, &size, &type, name.get());
429 if (size < 0) {
430 return false;
432 info.name = blink::WebString::fromUTF8(name.get(), length);
433 info.type = type;
434 info.size = size;
435 return true;
438 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
439 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
441 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
442 WebGLId, const WGC3Dchar*, WGC3Dint)
444 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
446 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
447 WGC3Denum, WGC3Denum, WGC3Dint*)
449 WGC3Denum WebGraphicsContext3DImpl::getError() {
450 if (!synthetic_errors_.empty()) {
451 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
452 WGC3Denum err = *iter;
453 synthetic_errors_.erase(iter);
454 return err;
457 return gl_->GetError();
460 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
462 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
463 GetFramebufferAttachmentParameteriv,
464 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
466 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
468 DELEGATE_TO_GL_2(getInteger64v, GetInteger64v, WGC3Denum, WGC3Dint64*)
470 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
472 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
473 WebGLId program) {
474 GLint logLength = 0;
475 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
476 if (!logLength)
477 return blink::WebString();
478 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
479 if (!log)
480 return blink::WebString();
481 GLsizei returnedLogLength = 0;
482 gl_->GetProgramInfoLog(
483 program, logLength, &returnedLogLength, log.get());
484 DCHECK_EQ(logLength, returnedLogLength + 1);
485 blink::WebString res =
486 blink::WebString::fromUTF8(log.get(), returnedLogLength);
487 return res;
490 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
491 WGC3Denum, WGC3Denum, WGC3Dint*)
493 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
495 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
496 WebGLId shader) {
497 GLint logLength = 0;
498 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
499 if (!logLength)
500 return blink::WebString();
501 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
502 if (!log)
503 return blink::WebString();
504 GLsizei returnedLogLength = 0;
505 gl_->GetShaderInfoLog(
506 shader, logLength, &returnedLogLength, log.get());
507 DCHECK_EQ(logLength, returnedLogLength + 1);
508 blink::WebString res =
509 blink::WebString::fromUTF8(log.get(), returnedLogLength);
510 return res;
513 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
514 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
516 blink::WebString WebGraphicsContext3DImpl::getShaderSource(
517 WebGLId shader) {
518 GLint logLength = 0;
519 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
520 if (!logLength)
521 return blink::WebString();
522 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
523 if (!log)
524 return blink::WebString();
525 GLsizei returnedLogLength = 0;
526 gl_->GetShaderSource(
527 shader, logLength, &returnedLogLength, log.get());
528 if (!returnedLogLength)
529 return blink::WebString();
530 DCHECK_EQ(logLength, returnedLogLength + 1);
531 blink::WebString res =
532 blink::WebString::fromUTF8(log.get(), returnedLogLength);
533 return res;
536 blink::WebString WebGraphicsContext3DImpl::
537 getTranslatedShaderSourceANGLE(WebGLId shader) {
538 GLint logLength = 0;
539 gl_->GetShaderiv(
540 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
541 if (!logLength)
542 return blink::WebString();
543 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
544 if (!log)
545 return blink::WebString();
546 GLsizei returnedLogLength = 0;
547 gl_->GetTranslatedShaderSourceANGLE(
548 shader, logLength, &returnedLogLength, log.get());
549 if (!returnedLogLength)
550 return blink::WebString();
551 DCHECK_EQ(logLength, returnedLogLength + 1);
552 blink::WebString res =
553 blink::WebString::fromUTF8(log.get(), returnedLogLength);
554 return res;
557 blink::WebString WebGraphicsContext3DImpl::getString(
558 WGC3Denum name) {
559 return blink::WebString::fromUTF8(
560 reinterpret_cast<const char*>(gl_->GetString(name)));
563 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
564 WGC3Denum, WGC3Denum, WGC3Dfloat*)
566 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
567 WGC3Denum, WGC3Denum, WGC3Dint*)
569 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
571 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
573 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
574 WebGLId, const WGC3Dchar*, WGC3Dint)
576 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
577 WGC3Duint, WGC3Denum, WGC3Dfloat*)
579 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
580 WGC3Duint, WGC3Denum, WGC3Dint*)
582 WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
583 WGC3Duint index, WGC3Denum pname) {
584 GLvoid* value = NULL;
585 // NOTE: If pname is ever a value that returns more then 1 element
586 // this will corrupt memory.
587 gl_->GetVertexAttribPointerv(index, pname, &value);
588 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
591 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
593 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
595 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
597 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
599 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
601 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
603 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
605 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
607 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
609 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
611 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
613 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
615 DELEGATE_TO_GL_7(readPixels, ReadPixels,
616 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
617 WGC3Denum, void*)
619 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
620 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
622 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
624 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
626 void WebGraphicsContext3DImpl::shaderSource(
627 WebGLId shader, const WGC3Dchar* string) {
628 GLint length = strlen(string);
629 gl_->ShaderSource(shader, 1, &string, &length);
632 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
634 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
635 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
637 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
639 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
640 WGC3Denum, WGC3Duint)
642 DELEGATE_TO_GL_3(stencilOp, StencilOp,
643 WGC3Denum, WGC3Denum, WGC3Denum)
645 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
646 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
648 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
649 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
650 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
652 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
653 WGC3Denum, WGC3Denum, WGC3Dfloat);
655 DELEGATE_TO_GL_3(texParameteri, TexParameteri,
656 WGC3Denum, WGC3Denum, WGC3Dint);
658 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
659 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
660 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
662 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
664 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
665 const WGC3Dfloat*)
667 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
669 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
671 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
673 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
674 const WGC3Dfloat*)
676 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
678 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
680 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
681 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
683 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
684 const WGC3Dfloat*)
686 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
688 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
690 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
691 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
693 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
694 const WGC3Dfloat*)
696 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
697 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
699 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
701 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
702 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
704 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
705 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
707 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
708 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
710 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
712 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
714 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
716 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
717 const WGC3Dfloat*)
719 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
720 WGC3Dfloat, WGC3Dfloat)
722 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
723 const WGC3Dfloat*)
725 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
726 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
728 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
729 const WGC3Dfloat*)
731 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
732 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
734 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
735 const WGC3Dfloat*)
737 void WebGraphicsContext3DImpl::vertexAttribPointer(
738 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
739 WGC3Dsizei stride, WGC3Dintptr offset) {
740 gl_->VertexAttribPointer(
741 index, size, type, normalized, stride,
742 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
745 DELEGATE_TO_GL_4(viewport, Viewport,
746 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
748 WebGLId WebGraphicsContext3DImpl::createBuffer() {
749 GLuint o;
750 gl_->GenBuffers(1, &o);
751 return o;
754 WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
755 GLuint o = 0;
756 gl_->GenFramebuffers(1, &o);
757 return o;
760 WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
761 GLuint o;
762 gl_->GenRenderbuffers(1, &o);
763 return o;
766 WebGLId WebGraphicsContext3DImpl::createTexture() {
767 GLuint o;
768 gl_->GenTextures(1, &o);
769 return o;
772 void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
773 gl_->DeleteBuffers(1, &buffer);
776 void WebGraphicsContext3DImpl::deleteFramebuffer(
777 WebGLId framebuffer) {
778 gl_->DeleteFramebuffers(1, &framebuffer);
781 void WebGraphicsContext3DImpl::deleteRenderbuffer(
782 WebGLId renderbuffer) {
783 gl_->DeleteRenderbuffers(1, &renderbuffer);
786 void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
787 gl_->DeleteTextures(1, &texture);
790 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
792 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
794 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
796 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
798 void WebGraphicsContext3DImpl::setErrorMessageCallback(
799 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
800 error_message_callback_ = cb;
803 void WebGraphicsContext3DImpl::setContextLostCallback(
804 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
805 context_lost_callback_ = cb;
808 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
809 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
811 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
812 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
814 WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
815 GLuint o;
816 gl_->GenQueriesEXT(1, &o);
817 return o;
820 void WebGraphicsContext3DImpl::deleteQueryEXT(
821 WebGLId query) {
822 gl_->DeleteQueriesEXT(1, &query);
825 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
826 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
827 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
828 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
829 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
830 WebGLId, WGC3Denum, WGC3Duint*)
832 DELEGATE_TO_GL_2(queryCounterEXT, QueryCounterEXT, WebGLId, WGC3Denum)
833 DELEGATE_TO_GL_3(getQueryObjectui64vEXT,
834 GetQueryObjectui64vEXT,
835 WebGLId,
836 WGC3Denum,
837 WGC3Duint64*)
839 DELEGATE_TO_GL_8(copyTextureCHROMIUM,
840 CopyTextureCHROMIUM,
841 WGC3Denum,
842 WebGLId,
843 WebGLId,
844 WGC3Denum,
845 WGC3Denum,
846 WGC3Dboolean,
847 WGC3Dboolean,
848 WGC3Dboolean);
850 DELEGATE_TO_GL_12(copySubTextureCHROMIUM,
851 CopySubTextureCHROMIUM,
852 WGC3Denum,
853 WebGLId,
854 WebGLId,
855 WGC3Dint,
856 WGC3Dint,
857 WGC3Dint,
858 WGC3Dint,
859 WGC3Dsizei,
860 WGC3Dsizei,
861 WGC3Dboolean,
862 WGC3Dboolean,
863 WGC3Dboolean);
865 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
866 WebGLId, WGC3Dint, const WGC3Dchar*)
868 void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
869 flush_id_ = GenFlushID();
870 gl_->ShallowFlushCHROMIUM();
873 void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
874 flush_id_ = GenFlushID();
875 gl_->ShallowFinishCHROMIUM();
878 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
880 void WebGraphicsContext3DImpl::loseContextCHROMIUM(
881 WGC3Denum current, WGC3Denum other) {
882 gl_->LoseContextCHROMIUM(current, other);
883 gl_->Flush();
886 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
887 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
888 WGC3Denum, const WGC3Dbyte*)
889 DELEGATE_TO_GL_3(produceTextureDirectCHROMIUM, ProduceTextureDirectCHROMIUM,
890 WebGLId, WGC3Denum, const WGC3Dbyte*)
891 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
892 WGC3Denum, const WGC3Dbyte*)
893 DELEGATE_TO_GL_2R(createAndConsumeTextureCHROMIUM,
894 CreateAndConsumeTextureCHROMIUM,
895 WGC3Denum, const WGC3Dbyte*, WebGLId)
897 DELEGATE_TO_GL_2(genValuebuffersCHROMIUM,
898 GenValuebuffersCHROMIUM,
899 WGC3Dsizei,
900 WebGLId*);
902 WebGLId WebGraphicsContext3DImpl::createValuebufferCHROMIUM() {
903 GLuint o;
904 gl_->GenValuebuffersCHROMIUM(1, &o);
905 return o;
908 DELEGATE_TO_GL_2(deleteValuebuffersCHROMIUM,
909 DeleteValuebuffersCHROMIUM,
910 WGC3Dsizei,
911 WebGLId*);
913 void WebGraphicsContext3DImpl::deleteValuebufferCHROMIUM(WebGLId valuebuffer) {
914 gl_->DeleteValuebuffersCHROMIUM(1, &valuebuffer);
917 DELEGATE_TO_GL_1RB(isValuebufferCHROMIUM,
918 IsValuebufferCHROMIUM,
919 WebGLId,
920 WGC3Dboolean)
921 DELEGATE_TO_GL_2(bindValuebufferCHROMIUM,
922 BindValuebufferCHROMIUM,
923 WGC3Denum,
924 WebGLId)
925 DELEGATE_TO_GL_2(subscribeValueCHROMIUM,
926 SubscribeValueCHROMIUM,
927 WGC3Denum,
928 WGC3Denum);
929 DELEGATE_TO_GL_1(populateSubscribedValuesCHROMIUM,
930 PopulateSubscribedValuesCHROMIUM,
931 WGC3Denum);
932 DELEGATE_TO_GL_3(uniformValuebufferCHROMIUM,
933 UniformValuebufferCHROMIUM,
934 WGC3Dint,
935 WGC3Denum,
936 WGC3Denum);
937 DELEGATE_TO_GL_2(traceBeginCHROMIUM,
938 TraceBeginCHROMIUM,
939 const WGC3Dchar*,
940 const WGC3Dchar*);
941 DELEGATE_TO_GL(traceEndCHROMIUM, TraceEndCHROMIUM);
943 void WebGraphicsContext3DImpl::insertEventMarkerEXT(
944 const WGC3Dchar* marker) {
945 gl_->InsertEventMarkerEXT(0, marker);
948 void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
949 const WGC3Dchar* marker) {
950 gl_->PushGroupMarkerEXT(0, marker);
953 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
955 WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
956 GLuint array;
957 gl_->GenVertexArraysOES(1, &array);
958 return array;
961 void WebGraphicsContext3DImpl::deleteVertexArrayOES(
962 WebGLId array) {
963 gl_->DeleteVertexArraysOES(1, &array);
966 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
967 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
969 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
970 WGC3Denum, WGC3Dint)
971 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
972 WGC3Denum, WGC3Dint)
974 DELEGATE_TO_GL_2R(mapBufferCHROMIUM, MapBufferCHROMIUM, WGC3Denum, WGC3Denum,
975 void*)
976 DELEGATE_TO_GL_1R(unmapBufferCHROMIUM, UnmapBufferCHROMIUM, WGC3Denum,
977 WGC3Dboolean)
979 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
981 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
982 WGC3Dint, WGC3Dsizei, WGC3Dsizei)
984 void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
985 WGC3Denum mode,
986 WGC3Dsizei count,
987 WGC3Denum type,
988 WGC3Dintptr offset,
989 WGC3Dsizei primcount) {
990 gl_->DrawElementsInstancedANGLE(
991 mode, count, type,
992 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
995 DELEGATE_TO_GL_2(vertexAttribDivisorANGLE, VertexAttribDivisorANGLE, WGC3Duint,
996 WGC3Duint)
998 DELEGATE_TO_GL_4R(createGpuMemoryBufferImageCHROMIUM,
999 CreateGpuMemoryBufferImageCHROMIUM,
1000 WGC3Dsizei,
1001 WGC3Dsizei,
1002 WGC3Denum,
1003 WGC3Denum,
1004 WGC3Duint);
1006 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
1008 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
1009 FramebufferTexture2DMultisampleEXT,
1010 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1012 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1013 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1014 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1016 DELEGATE_TO_GL_1(beginTransformFeedback, BeginTransformFeedback, WGC3Denum)
1017 DELEGATE_TO_GL_3(bindBufferBase, BindBufferBase, WGC3Denum, WGC3Duint,
1018 WGC3Duint)
1019 DELEGATE_TO_GL_5(bindBufferRange, BindBufferRange, WGC3Denum, WGC3Duint,
1020 WGC3Duint, WGC3Dintptr, WGC3Dsizeiptr)
1021 DELEGATE_TO_GL_2(bindSampler, BindSampler, WGC3Duint, WebGLId)
1022 DELEGATE_TO_GL_2(bindTransformFeedback, BindTransformFeedback, WGC3Denum,
1023 WebGLId)
1024 DELEGATE_TO_GL_4(clearBufferfi, ClearBufferfi, WGC3Denum, WGC3Dint, WGC3Dfloat,
1025 WGC3Dint)
1026 DELEGATE_TO_GL_3(clearBufferfv, ClearBufferfv, WGC3Denum, WGC3Dint,
1027 const WGC3Dfloat *)
1028 DELEGATE_TO_GL_3(clearBufferiv, ClearBufferiv, WGC3Denum, WGC3Dint,
1029 const WGC3Dint *)
1030 DELEGATE_TO_GL_3(clearBufferuiv, ClearBufferuiv, WGC3Denum, WGC3Dint,
1031 const WGC3Duint *)
1032 WGC3Denum WebGraphicsContext3DImpl::clientWaitSync(WGC3Dsync sync,
1033 WGC3Dbitfield flags,
1034 WGC3Duint64 timeout) {
1035 return gl_->ClientWaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1037 DELEGATE_TO_GL_9(compressedTexImage3D, CompressedTexImage3D, WGC3Denum,
1038 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1039 WGC3Dint, WGC3Dsizei, const void *)
1040 DELEGATE_TO_GL_11(compressedTexSubImage3D, CompressedTexSubImage3D, WGC3Denum,
1041 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1042 WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Dsizei, const void *)
1043 DELEGATE_TO_GL_5(copyBufferSubData, CopyBufferSubData, WGC3Denum, WGC3Denum,
1044 WGC3Dintptr, WGC3Dintptr, WGC3Dsizeiptr)
1045 DELEGATE_TO_GL_9(copyTexSubImage3D, CopyTexSubImage3D, WGC3Denum, WGC3Dint,
1046 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1047 WGC3Dsizei)
1048 WebGLId WebGraphicsContext3DImpl::createSampler() {
1049 GLuint sampler;
1050 gl_->GenSamplers(1, &sampler);
1051 return sampler;
1053 WebGLId WebGraphicsContext3DImpl::createTransformFeedback() {
1054 GLuint tf;
1055 gl_->GenTransformFeedbacks(1, &tf);
1056 return tf;
1058 void WebGraphicsContext3DImpl::deleteSampler(WebGLId sampler) {
1059 gl_->DeleteSamplers(1, &sampler);
1061 void WebGraphicsContext3DImpl::deleteSync(WGC3Dsync sync) {
1062 gl_->DeleteSync(reinterpret_cast<GLsync>(sync));
1064 void WebGraphicsContext3DImpl::deleteTransformFeedback(WebGLId tf) {
1065 gl_->DeleteTransformFeedbacks(1, &tf);
1067 void WebGraphicsContext3DImpl::drawRangeElements(
1068 WGC3Denum mode, WGC3Duint start, WGC3Duint end, WGC3Dsizei count,
1069 WGC3Denum type, WGC3Dintptr offset) {
1070 gl_->DrawRangeElements(mode, start, end, count, type,
1071 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1073 DELEGATE_TO_GL(endTransformFeedback, EndTransformFeedback)
1074 WGC3Dsync WebGraphicsContext3DImpl::fenceSync(WGC3Denum condition,
1075 WGC3Dbitfield flags) {
1076 return reinterpret_cast<WGC3Dsync>(gl_->FenceSync(condition, flags));
1078 DELEGATE_TO_GL_5(framebufferTextureLayer, FramebufferTextureLayer, WGC3Denum,
1079 WGC3Denum, WGC3Duint, WGC3Dint, WGC3Dint)
1080 DELEGATE_TO_GL_5(getActiveUniformBlockName, GetActiveUniformBlockName,
1081 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dchar *)
1082 DELEGATE_TO_GL_4(getActiveUniformBlockiv, GetActiveUniformBlockiv, WGC3Duint,
1083 WGC3Duint, WGC3Denum, WGC3Dint *)
1084 DELEGATE_TO_GL_5(getActiveUniformsiv, GetActiveUniformsiv, WGC3Duint,
1085 WGC3Dsizei, const WGC3Duint *, WGC3Denum, WGC3Dint *)
1086 DELEGATE_TO_GL_2R(getFragDataLocation, GetFragDataLocation, WGC3Duint,
1087 const WGC3Dchar *, WGC3Dint)
1088 DELEGATE_TO_GL_5(getInternalformativ, GetInternalformativ, WGC3Denum, WGC3Denum,
1089 WGC3Denum, WGC3Dsizei, WGC3Dint *)
1090 DELEGATE_TO_GL_3(getSamplerParameterfv, GetSamplerParameterfv, WGC3Duint,
1091 WGC3Denum, WGC3Dfloat *)
1092 DELEGATE_TO_GL_3(getSamplerParameteriv, GetSamplerParameteriv, WGC3Duint,
1093 WGC3Denum, WGC3Dint *)
1094 DELEGATE_TO_GL_7(getTransformFeedbackVarying, GetTransformFeedbackVarying,
1095 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dsizei *,
1096 WGC3Denum *, WGC3Dchar *)
1097 DELEGATE_TO_GL_2R(getUniformBlockIndex, GetUniformBlockIndex, WGC3Duint,
1098 const WGC3Dchar *, WGC3Duint)
1099 DELEGATE_TO_GL_4(getUniformIndices, GetUniformIndices, WGC3Duint, WGC3Dsizei,
1100 const WGC3Dchar *const*, WGC3Duint *)
1101 DELEGATE_TO_GL_3(getUniformuiv, GetUniformuiv, WGC3Duint, WGC3Dint,
1102 WGC3Duint *)
1103 DELEGATE_TO_GL_3(getVertexAttribIiv, GetVertexAttribIiv, WGC3Duint,
1104 WGC3Denum, WGC3Dint *)
1105 DELEGATE_TO_GL_3(getVertexAttribIuiv, GetVertexAttribIuiv, WGC3Duint,
1106 WGC3Denum, WGC3Duint *)
1107 DELEGATE_TO_GL_3(invalidateFramebuffer, InvalidateFramebuffer, WGC3Denum,
1108 WGC3Dsizei, const WGC3Denum *)
1109 DELEGATE_TO_GL_7(invalidateSubFramebuffer, InvalidateSubFramebuffer, WGC3Denum,
1110 WGC3Dsizei, const WGC3Denum *, WGC3Dint, WGC3Dint, WGC3Dsizei,
1111 WGC3Dsizei)
1112 DELEGATE_TO_GL_1R(isSampler, IsSampler, WebGLId, WGC3Dboolean)
1113 WGC3Dboolean WebGraphicsContext3DImpl::isSync(WGC3Dsync sync) {
1114 return gl_->IsSync(reinterpret_cast<GLsync>(sync));
1116 DELEGATE_TO_GL_1R(isTransformFeedback, IsTransformFeedback, WGC3Duint,
1117 WGC3Dboolean)
1118 DELEGATE_TO_GL_4R(mapBufferRange, MapBufferRange, WGC3Denum, WGC3Dintptr,
1119 WGC3Dsizeiptr, WGC3Dbitfield, void*);
1120 DELEGATE_TO_GL(pauseTransformFeedback, PauseTransformFeedback)
1121 //DELEGATE_TO_GL_3(programParameteri, ProgramParameteri, WGC3Duint, WGC3Denum,
1122 // WGC3Dint)
1123 DELEGATE_TO_GL_1(readBuffer, ReadBuffer, WGC3Denum)
1124 DELEGATE_TO_GL(resumeTransformFeedback, ResumeTransformFeedback)
1125 DELEGATE_TO_GL_3(samplerParameterf, SamplerParameterf, WGC3Duint, WGC3Denum,
1126 WGC3Dfloat)
1127 DELEGATE_TO_GL_3(samplerParameterfv, SamplerParameterfv, WGC3Duint, WGC3Denum,
1128 const WGC3Dfloat *)
1129 DELEGATE_TO_GL_3(samplerParameteri, SamplerParameteri, WGC3Duint, WGC3Denum,
1130 WGC3Dint)
1131 DELEGATE_TO_GL_3(samplerParameteriv, SamplerParameteriv, WGC3Duint, WGC3Denum,
1132 const WGC3Dint *)
1133 DELEGATE_TO_GL_10(texImage3D, TexImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1134 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei, WGC3Dint, WGC3Denum,
1135 WGC3Denum, const void *)
1136 DELEGATE_TO_GL_6(texStorage3D, TexStorage3D, WGC3Denum, WGC3Dsizei, WGC3Denum,
1137 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei)
1138 DELEGATE_TO_GL_11(texSubImage3D, TexSubImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1139 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1140 WGC3Denum, WGC3Denum, const void *)
1141 DELEGATE_TO_GL_4(transformFeedbackVaryings, TransformFeedbackVaryings,
1142 WGC3Duint, WGC3Dsizei, const WGC3Dchar *const*, WGC3Denum)
1143 DELEGATE_TO_GL_2(uniform1ui, Uniform1ui, WGC3Dint, WGC3Duint)
1144 DELEGATE_TO_GL_3(uniform1uiv, Uniform1uiv, WGC3Dint, WGC3Dsizei,
1145 const WGC3Duint *)
1146 DELEGATE_TO_GL_3(uniform2ui, Uniform2ui, WGC3Dint, WGC3Duint, WGC3Duint)
1147 DELEGATE_TO_GL_3(uniform2uiv, Uniform2uiv, WGC3Dint, WGC3Dsizei,
1148 const WGC3Duint *)
1149 DELEGATE_TO_GL_4(uniform3ui, Uniform3ui, WGC3Dint, WGC3Duint, WGC3Duint,
1150 WGC3Duint)
1151 DELEGATE_TO_GL_3(uniform3uiv, Uniform3uiv, WGC3Dint, WGC3Dsizei,
1152 const WGC3Duint *)
1153 DELEGATE_TO_GL_5(uniform4ui, Uniform4ui, WGC3Dint, WGC3Duint, WGC3Duint,
1154 WGC3Duint, WGC3Duint)
1155 DELEGATE_TO_GL_3(uniform4uiv, Uniform4uiv, WGC3Dint, WGC3Dsizei,
1156 const WGC3Duint *)
1157 DELEGATE_TO_GL_3(uniformBlockBinding, UniformBlockBinding, WGC3Duint, WGC3Duint,
1158 WGC3Duint)
1159 DELEGATE_TO_GL_4(uniformMatrix2x3fv, UniformMatrix2x3fv, WGC3Dint, WGC3Dsizei,
1160 WGC3Dboolean, const WGC3Dfloat*)
1161 DELEGATE_TO_GL_4(uniformMatrix2x4fv, UniformMatrix2x4fv, WGC3Dint, WGC3Dsizei,
1162 WGC3Dboolean, const WGC3Dfloat*)
1163 DELEGATE_TO_GL_4(uniformMatrix3x2fv, UniformMatrix3x2fv, WGC3Dint, WGC3Dsizei,
1164 WGC3Dboolean, const WGC3Dfloat*)
1165 DELEGATE_TO_GL_4(uniformMatrix3x4fv, UniformMatrix3x4fv, WGC3Dint, WGC3Dsizei,
1166 WGC3Dboolean, const WGC3Dfloat*)
1167 DELEGATE_TO_GL_4(uniformMatrix4x2fv, UniformMatrix4x2fv, WGC3Dint, WGC3Dsizei,
1168 WGC3Dboolean, const WGC3Dfloat*)
1169 DELEGATE_TO_GL_4(uniformMatrix4x3fv, UniformMatrix4x3fv, WGC3Dint, WGC3Dsizei,
1170 WGC3Dboolean, const WGC3Dfloat*)
1171 DELEGATE_TO_GL_1R(unmapBuffer, UnmapBuffer, WGC3Denum, WGC3Dboolean);
1172 DELEGATE_TO_GL_5(vertexAttribI4i, VertexAttribI4i, WGC3Duint, WGC3Dint,
1173 WGC3Dint, WGC3Dint, WGC3Dint)
1174 DELEGATE_TO_GL_2(vertexAttribI4iv, VertexAttribI4iv, WGC3Duint,
1175 const WGC3Dint *)
1176 DELEGATE_TO_GL_5(vertexAttribI4ui, VertexAttribI4ui, WGC3Duint, WGC3Duint,
1177 WGC3Duint, WGC3Duint, WGC3Duint)
1178 DELEGATE_TO_GL_2(vertexAttribI4uiv, VertexAttribI4uiv, WGC3Duint,
1179 const WGC3Duint *)
1180 void WebGraphicsContext3DImpl::vertexAttribIPointer(
1181 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dsizei stride,
1182 WGC3Dintptr offset) {
1183 gl_->VertexAttribIPointer(
1184 index, size, type, stride,
1185 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1187 void WebGraphicsContext3DImpl::waitSync(WGC3Dsync sync,
1188 WGC3Dbitfield flags,
1189 WGC3Duint64 timeout) {
1190 gl_->WaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1193 bool WebGraphicsContext3DImpl::isContextLost() {
1194 return getGraphicsResetStatusARB() != GL_NO_ERROR;
1197 blink::WGC3Denum WebGraphicsContext3DImpl::getGraphicsResetStatusARB() {
1198 return gl_->GetGraphicsResetStatusKHR();
1201 GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
1202 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1205 ::gpu::gles2::GLES2ImplementationErrorMessageCallback*
1206 WebGraphicsContext3DImpl::getErrorMessageCallback() {
1207 if (!client_error_message_callback_) {
1208 client_error_message_callback_.reset(
1209 new WebGraphicsContext3DErrorMessageCallback(this));
1211 return client_error_message_callback_.get();
1214 void WebGraphicsContext3DImpl::OnErrorMessage(
1215 const std::string& message, int id) {
1216 if (error_message_callback_) {
1217 blink::WebString str = blink::WebString::fromUTF8(message.c_str());
1218 error_message_callback_->onErrorMessage(str, id);
1222 // TODO(bajones): Look into removing these functions from the blink interface
1223 void WebGraphicsContext3DImpl::prepareTexture() {
1224 NOTREACHED();
1227 void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
1228 int x, int y, int width, int height) {
1229 NOTREACHED();
1232 void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
1233 bool visible) {
1234 NOTREACHED();
1237 void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
1238 WebGLId texture, WebGLId parentTexture) {
1239 NOTIMPLEMENTED();
1242 void WebGraphicsContext3DImpl::releaseShaderCompiler() {
1245 // static
1246 void WebGraphicsContext3DImpl::ConvertAttributes(
1247 const blink::WebGraphicsContext3D::Attributes& attributes,
1248 ::gpu::gles2::ContextCreationAttribHelper* output_attribs) {
1249 output_attribs->alpha_size = attributes.alpha ? 8 : 0;
1250 output_attribs->depth_size = attributes.depth ? 24 : 0;
1251 output_attribs->stencil_size = attributes.stencil ? 8 : 0;
1252 output_attribs->samples = attributes.antialias ? 4 : 0;
1253 output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
1254 output_attribs->fail_if_major_perf_caveat =
1255 attributes.failIfMajorPerformanceCaveat;
1256 output_attribs->bind_generates_resource = false;
1257 output_attribs->webgl_version = attributes.webGLVersion;
1260 } // namespace gpu_blink