Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / gpu / blink / webgraphicscontext3d_impl.cc
blob5d6e76d941a9d2facd7271a8505df0a1951e6d30
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::WGC3Duint64;
34 using blink::WGC3Duint;
35 using blink::WebGLId;
36 using blink::WGC3Dsync;
38 namespace gpu_blink {
40 namespace {
42 uint32_t GenFlushID() {
43 static base::subtle::Atomic32 flush_id = 0;
45 base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
46 &flush_id, 1);
47 return static_cast<uint32_t>(my_id);
50 } // namespace anonymous
52 class WebGraphicsContext3DErrorMessageCallback
53 : public ::gpu::gles2::GLES2ImplementationErrorMessageCallback {
54 public:
55 WebGraphicsContext3DErrorMessageCallback(
56 WebGraphicsContext3DImpl* context)
57 : graphics_context_(context) {
60 void OnErrorMessage(const char* msg, int id) override;
62 private:
63 WebGraphicsContext3DImpl* graphics_context_;
65 DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
68 void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
69 const char* msg, int id) {
70 graphics_context_->OnErrorMessage(msg, id);
73 // Helper macros to reduce the amount of code.
75 #define DELEGATE_TO_GL(name, glname) \
76 void WebGraphicsContext3DImpl::name() { \
77 gl_->glname(); \
80 #define DELEGATE_TO_GL_R(name, glname, rt) \
81 rt WebGraphicsContext3DImpl::name() { \
82 return gl_->glname(); \
85 #define DELEGATE_TO_GL_1(name, glname, t1) \
86 void WebGraphicsContext3DImpl::name(t1 a1) { \
87 gl_->glname(a1); \
90 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
91 rt WebGraphicsContext3DImpl::name(t1 a1) { \
92 return gl_->glname(a1); \
95 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
96 rt WebGraphicsContext3DImpl::name(t1 a1) { \
97 return gl_->glname(a1) ? true : false; \
100 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
101 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
102 gl_->glname(a1, a2); \
105 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
106 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
107 return gl_->glname(a1, a2); \
110 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
111 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
112 gl_->glname(a1, a2, a3); \
115 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
116 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
117 return gl_->glname(a1, a2, a3); \
120 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
121 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
122 gl_->glname(a1, a2, a3, a4); \
125 #define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt) \
126 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
127 return gl_->glname(a1, a2, a3, a4); \
130 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
131 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {\
133 gl_->glname(a1, a2, a3, a4, a5); \
136 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
137 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
138 t6 a6) { \
139 gl_->glname(a1, a2, a3, a4, a5, a6); \
142 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
143 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
144 t6 a6, t7 a7) { \
145 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
148 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
149 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
150 t6 a6, t7 a7, t8 a8) { \
151 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
154 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
155 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
156 t6 a6, t7 a7, t8 a8, t9 a9) { \
157 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
160 #define DELEGATE_TO_GL_9R(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
161 t9, rt) \
162 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
163 t6 a6, t7 a7, t8 a8, t9 a9) { \
164 return gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
167 #define DELEGATE_TO_GL_10(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
168 t9, t10) \
169 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
170 t6 a6, t7 a7, t8 a8, t9 a9, \
171 t10 a10) { \
172 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
175 #define DELEGATE_TO_GL_11(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
176 t9, t10, t11) \
177 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
178 t6 a6, t7 a7, t8 a8, t9 a9, t10 a10,\
179 t11 a11) { \
180 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); \
183 WebGraphicsContext3DImpl::WebGraphicsContext3DImpl()
184 : initialized_(false),
185 initialize_failed_(false),
186 context_lost_callback_(0),
187 context_lost_reason_(GL_NO_ERROR),
188 error_message_callback_(0),
189 gl_(NULL),
190 flush_id_(0) {
193 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() {
197 void WebGraphicsContext3DImpl::synthesizeGLError(WGC3Denum error) {
198 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
199 synthetic_errors_.end()) {
200 synthetic_errors_.push_back(error);
204 uint32_t WebGraphicsContext3DImpl::lastFlushID() {
205 return flush_id_;
208 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int)
210 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
212 DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum,
213 WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*)
215 DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM,
216 const void*)
218 DELEGATE_TO_GL_9R(mapTexSubImage2DCHROMIUM, MapTexSubImage2DCHROMIUM, WGC3Denum,
219 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
220 WGC3Denum, WGC3Denum, WGC3Denum, void*)
222 DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM,
223 const void*)
225 DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum,
226 WGC3Dsizei, const WGC3Denum*)
228 blink::WebString WebGraphicsContext3DImpl::
229 getRequestableExtensionsCHROMIUM() {
230 return blink::WebString::fromUTF8(
231 gl_->GetRequestableExtensionsCHROMIUM());
234 DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM,
235 const char*)
237 void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM(
238 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
239 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
240 WGC3Dbitfield mask, WGC3Denum filter) {
241 gl_->BlitFramebufferCHROMIUM(
242 srcX0, srcY0, srcX1, srcY1,
243 dstX0, dstY0, dstX1, dstY1,
244 mask, filter);
247 DELEGATE_TO_GL_5(renderbufferStorageMultisampleCHROMIUM,
248 RenderbufferStorageMultisampleCHROMIUM, WGC3Denum, WGC3Dsizei,
249 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
251 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
253 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
255 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
256 WGC3Duint, const WGC3Dchar*)
258 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
260 DELEGATE_TO_GL_2(bindFramebuffer, BindFramebuffer, WGC3Denum, WebGLId)
262 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
264 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
266 DELEGATE_TO_GL_4(blendColor, BlendColor,
267 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
269 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
271 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
272 WGC3Denum, WGC3Denum)
274 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
276 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
277 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
279 DELEGATE_TO_GL_4(bufferData, BufferData,
280 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
282 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
283 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
285 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
286 WGC3Denum, WGC3Denum)
288 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
290 DELEGATE_TO_GL_4(clearColor, ClearColor,
291 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
293 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
295 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
297 DELEGATE_TO_GL_4(colorMask, ColorMask,
298 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
300 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
302 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
303 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
304 WGC3Dsizei, WGC3Dsizei, const void*)
306 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
307 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
308 WGC3Denum, WGC3Dsizei, const void*)
310 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
311 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
312 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
314 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
315 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
316 WGC3Dsizei, WGC3Dsizei)
318 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
320 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
322 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
324 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
326 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
328 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
330 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
331 WGC3Duint)
333 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
335 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode,
336 WGC3Dsizei count,
337 WGC3Denum type,
338 WGC3Dintptr offset) {
339 gl_->DrawElements(
340 mode, count, type,
341 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
344 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
346 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
347 WGC3Duint)
349 void WebGraphicsContext3DImpl::finish() {
350 flush_id_ = GenFlushID();
351 gl_->Finish();
354 void WebGraphicsContext3DImpl::flush() {
355 flush_id_ = GenFlushID();
356 gl_->Flush();
359 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
360 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
362 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
363 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
365 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
367 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
369 bool WebGraphicsContext3DImpl::getActiveAttrib(
370 WebGLId program, WGC3Duint index, ActiveInfo& info) {
371 if (!program) {
372 synthesizeGLError(GL_INVALID_VALUE);
373 return false;
375 GLint max_name_length = -1;
376 gl_->GetProgramiv(
377 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
378 if (max_name_length < 0)
379 return false;
380 if (max_name_length == 0) {
381 // No active attributes exist.
382 synthesizeGLError(GL_INVALID_VALUE);
383 return false;
385 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
386 GLsizei length = 0;
387 GLint size = -1;
388 GLenum type = 0;
389 gl_->GetActiveAttrib(
390 program, index, max_name_length, &length, &size, &type, name.get());
391 if (size < 0) {
392 return false;
394 info.name = blink::WebString::fromUTF8(name.get(), length);
395 info.type = type;
396 info.size = size;
397 return true;
400 bool WebGraphicsContext3DImpl::getActiveUniform(
401 WebGLId program, WGC3Duint index, ActiveInfo& info) {
402 GLint max_name_length = -1;
403 gl_->GetProgramiv(
404 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
405 if (max_name_length < 0)
406 return false;
407 if (max_name_length == 0) {
408 // No active uniforms exist.
409 synthesizeGLError(GL_INVALID_VALUE);
410 return false;
412 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
413 GLsizei length = 0;
414 GLint size = -1;
415 GLenum type = 0;
416 gl_->GetActiveUniform(
417 program, index, max_name_length, &length, &size, &type, name.get());
418 if (size < 0) {
419 return false;
421 info.name = blink::WebString::fromUTF8(name.get(), length);
422 info.type = type;
423 info.size = size;
424 return true;
427 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
428 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
430 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
431 WebGLId, const WGC3Dchar*, WGC3Dint)
433 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
435 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
436 WGC3Denum, WGC3Denum, WGC3Dint*)
438 WGC3Denum WebGraphicsContext3DImpl::getError() {
439 if (!synthetic_errors_.empty()) {
440 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
441 WGC3Denum err = *iter;
442 synthetic_errors_.erase(iter);
443 return err;
446 return gl_->GetError();
449 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
451 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
452 GetFramebufferAttachmentParameteriv,
453 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
455 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
457 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
459 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
460 WebGLId program) {
461 GLint logLength = 0;
462 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
463 if (!logLength)
464 return blink::WebString();
465 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
466 if (!log)
467 return blink::WebString();
468 GLsizei returnedLogLength = 0;
469 gl_->GetProgramInfoLog(
470 program, logLength, &returnedLogLength, log.get());
471 DCHECK_EQ(logLength, returnedLogLength + 1);
472 blink::WebString res =
473 blink::WebString::fromUTF8(log.get(), returnedLogLength);
474 return res;
477 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
478 WGC3Denum, WGC3Denum, WGC3Dint*)
480 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
482 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
483 WebGLId shader) {
484 GLint logLength = 0;
485 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
486 if (!logLength)
487 return blink::WebString();
488 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
489 if (!log)
490 return blink::WebString();
491 GLsizei returnedLogLength = 0;
492 gl_->GetShaderInfoLog(
493 shader, logLength, &returnedLogLength, log.get());
494 DCHECK_EQ(logLength, returnedLogLength + 1);
495 blink::WebString res =
496 blink::WebString::fromUTF8(log.get(), returnedLogLength);
497 return res;
500 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
501 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
503 blink::WebString WebGraphicsContext3DImpl::getShaderSource(
504 WebGLId shader) {
505 GLint logLength = 0;
506 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
507 if (!logLength)
508 return blink::WebString();
509 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
510 if (!log)
511 return blink::WebString();
512 GLsizei returnedLogLength = 0;
513 gl_->GetShaderSource(
514 shader, logLength, &returnedLogLength, log.get());
515 if (!returnedLogLength)
516 return blink::WebString();
517 DCHECK_EQ(logLength, returnedLogLength + 1);
518 blink::WebString res =
519 blink::WebString::fromUTF8(log.get(), returnedLogLength);
520 return res;
523 blink::WebString WebGraphicsContext3DImpl::
524 getTranslatedShaderSourceANGLE(WebGLId shader) {
525 GLint logLength = 0;
526 gl_->GetShaderiv(
527 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
528 if (!logLength)
529 return blink::WebString();
530 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
531 if (!log)
532 return blink::WebString();
533 GLsizei returnedLogLength = 0;
534 gl_->GetTranslatedShaderSourceANGLE(
535 shader, logLength, &returnedLogLength, log.get());
536 if (!returnedLogLength)
537 return blink::WebString();
538 DCHECK_EQ(logLength, returnedLogLength + 1);
539 blink::WebString res =
540 blink::WebString::fromUTF8(log.get(), returnedLogLength);
541 return res;
544 blink::WebString WebGraphicsContext3DImpl::getString(
545 WGC3Denum name) {
546 return blink::WebString::fromUTF8(
547 reinterpret_cast<const char*>(gl_->GetString(name)));
550 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
551 WGC3Denum, WGC3Denum, WGC3Dfloat*)
553 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
554 WGC3Denum, WGC3Denum, WGC3Dint*)
556 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
558 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
560 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
561 WebGLId, const WGC3Dchar*, WGC3Dint)
563 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
564 WGC3Duint, WGC3Denum, WGC3Dfloat*)
566 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
567 WGC3Duint, WGC3Denum, WGC3Dint*)
569 WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
570 WGC3Duint index, WGC3Denum pname) {
571 GLvoid* value = NULL;
572 // NOTE: If pname is ever a value that returns more then 1 element
573 // this will corrupt memory.
574 gl_->GetVertexAttribPointerv(index, pname, &value);
575 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
578 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
580 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
582 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
584 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
586 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
588 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
590 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
592 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
594 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
596 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
598 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
600 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
602 DELEGATE_TO_GL_7(readPixels, ReadPixels,
603 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
604 WGC3Denum, void*)
606 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
607 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
609 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
611 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
613 void WebGraphicsContext3DImpl::shaderSource(
614 WebGLId shader, const WGC3Dchar* string) {
615 GLint length = strlen(string);
616 gl_->ShaderSource(shader, 1, &string, &length);
619 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
621 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
622 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
624 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
626 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
627 WGC3Denum, WGC3Duint)
629 DELEGATE_TO_GL_3(stencilOp, StencilOp,
630 WGC3Denum, WGC3Denum, WGC3Denum)
632 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
633 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
635 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
636 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
637 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
639 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
640 WGC3Denum, WGC3Denum, WGC3Dfloat);
642 static const unsigned int kTextureWrapR = 0x8072;
644 void WebGraphicsContext3DImpl::texParameteri(
645 WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
646 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
647 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
648 // edge of cube maps, and, if it is, push it into the GLES2 service
649 // side code.
650 if (pname == kTextureWrapR) {
651 return;
653 gl_->TexParameteri(target, pname, param);
656 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
657 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
658 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
660 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
662 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
663 const WGC3Dfloat*)
665 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
667 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
669 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
671 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
672 const WGC3Dfloat*)
674 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
676 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
678 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
679 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
681 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
682 const WGC3Dfloat*)
684 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
686 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
688 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
689 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
691 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
692 const WGC3Dfloat*)
694 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
695 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
697 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
699 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
700 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
702 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
703 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
705 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
706 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
708 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
710 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
712 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
714 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
715 const WGC3Dfloat*)
717 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
718 WGC3Dfloat, WGC3Dfloat)
720 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
721 const WGC3Dfloat*)
723 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
724 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
726 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
727 const WGC3Dfloat*)
729 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
730 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
732 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
733 const WGC3Dfloat*)
735 void WebGraphicsContext3DImpl::vertexAttribPointer(
736 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
737 WGC3Dsizei stride, WGC3Dintptr offset) {
738 gl_->VertexAttribPointer(
739 index, size, type, normalized, stride,
740 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
743 DELEGATE_TO_GL_4(viewport, Viewport,
744 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
746 WebGLId WebGraphicsContext3DImpl::createBuffer() {
747 GLuint o;
748 gl_->GenBuffers(1, &o);
749 return o;
752 WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
753 GLuint o = 0;
754 gl_->GenFramebuffers(1, &o);
755 return o;
758 WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
759 GLuint o;
760 gl_->GenRenderbuffers(1, &o);
761 return o;
764 WebGLId WebGraphicsContext3DImpl::createTexture() {
765 GLuint o;
766 gl_->GenTextures(1, &o);
767 return o;
770 void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
771 gl_->DeleteBuffers(1, &buffer);
774 void WebGraphicsContext3DImpl::deleteFramebuffer(
775 WebGLId framebuffer) {
776 gl_->DeleteFramebuffers(1, &framebuffer);
779 void WebGraphicsContext3DImpl::deleteRenderbuffer(
780 WebGLId renderbuffer) {
781 gl_->DeleteRenderbuffers(1, &renderbuffer);
784 void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
785 gl_->DeleteTextures(1, &texture);
788 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
790 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
792 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
794 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
796 void WebGraphicsContext3DImpl::setErrorMessageCallback(
797 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
798 error_message_callback_ = cb;
801 void WebGraphicsContext3DImpl::setContextLostCallback(
802 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
803 context_lost_callback_ = cb;
806 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
807 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
809 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
810 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
812 WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
813 GLuint o;
814 gl_->GenQueriesEXT(1, &o);
815 return o;
818 void WebGraphicsContext3DImpl::deleteQueryEXT(
819 WebGLId query) {
820 gl_->DeleteQueriesEXT(1, &query);
823 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
824 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
825 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
826 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
827 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
828 WebGLId, WGC3Denum, WGC3Duint*)
830 DELEGATE_TO_GL_5(copyTextureCHROMIUM,
831 CopyTextureCHROMIUM,
832 WGC3Denum,
833 WebGLId,
834 WebGLId,
835 WGC3Denum,
836 WGC3Denum);
838 DELEGATE_TO_GL_5(copySubTextureCHROMIUM,
839 CopySubTextureCHROMIUM,
840 WGC3Denum,
841 WebGLId,
842 WebGLId,
843 WGC3Dint,
844 WGC3Dint);
846 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
847 WebGLId, WGC3Dint, const WGC3Dchar*)
849 void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
850 flush_id_ = GenFlushID();
851 gl_->ShallowFlushCHROMIUM();
854 void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
855 flush_id_ = GenFlushID();
856 gl_->ShallowFinishCHROMIUM();
859 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
861 void WebGraphicsContext3DImpl::loseContextCHROMIUM(
862 WGC3Denum current, WGC3Denum other) {
863 gl_->LoseContextCHROMIUM(current, other);
864 gl_->Flush();
867 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
868 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
869 WGC3Denum, const WGC3Dbyte*)
870 DELEGATE_TO_GL_3(produceTextureDirectCHROMIUM, ProduceTextureDirectCHROMIUM,
871 WebGLId, WGC3Denum, const WGC3Dbyte*)
872 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
873 WGC3Denum, const WGC3Dbyte*)
874 DELEGATE_TO_GL_2R(createAndConsumeTextureCHROMIUM,
875 CreateAndConsumeTextureCHROMIUM,
876 WGC3Denum, const WGC3Dbyte*, WebGLId)
878 DELEGATE_TO_GL_2(genValuebuffersCHROMIUM,
879 GenValuebuffersCHROMIUM,
880 WGC3Dsizei,
881 WebGLId*);
883 WebGLId WebGraphicsContext3DImpl::createValuebufferCHROMIUM() {
884 GLuint o;
885 gl_->GenValuebuffersCHROMIUM(1, &o);
886 return o;
889 DELEGATE_TO_GL_2(deleteValuebuffersCHROMIUM,
890 DeleteValuebuffersCHROMIUM,
891 WGC3Dsizei,
892 WebGLId*);
894 void WebGraphicsContext3DImpl::deleteValuebufferCHROMIUM(WebGLId valuebuffer) {
895 gl_->DeleteValuebuffersCHROMIUM(1, &valuebuffer);
898 DELEGATE_TO_GL_1RB(isValuebufferCHROMIUM,
899 IsValuebufferCHROMIUM,
900 WebGLId,
901 WGC3Dboolean)
902 DELEGATE_TO_GL_2(bindValuebufferCHROMIUM,
903 BindValuebufferCHROMIUM,
904 WGC3Denum,
905 WebGLId)
906 DELEGATE_TO_GL_2(subscribeValueCHROMIUM,
907 SubscribeValueCHROMIUM,
908 WGC3Denum,
909 WGC3Denum);
910 DELEGATE_TO_GL_1(populateSubscribedValuesCHROMIUM,
911 PopulateSubscribedValuesCHROMIUM,
912 WGC3Denum);
913 DELEGATE_TO_GL_3(uniformValuebufferCHROMIUM,
914 UniformValuebufferCHROMIUM,
915 WGC3Dint,
916 WGC3Denum,
917 WGC3Denum);
918 DELEGATE_TO_GL_2(traceBeginCHROMIUM,
919 TraceBeginCHROMIUM,
920 const WGC3Dchar*,
921 const WGC3Dchar*);
922 DELEGATE_TO_GL(traceEndCHROMIUM, TraceEndCHROMIUM);
924 void WebGraphicsContext3DImpl::insertEventMarkerEXT(
925 const WGC3Dchar* marker) {
926 gl_->InsertEventMarkerEXT(0, marker);
929 void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
930 const WGC3Dchar* marker) {
931 gl_->PushGroupMarkerEXT(0, marker);
934 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
936 WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
937 GLuint array;
938 gl_->GenVertexArraysOES(1, &array);
939 return array;
942 void WebGraphicsContext3DImpl::deleteVertexArrayOES(
943 WebGLId array) {
944 gl_->DeleteVertexArraysOES(1, &array);
947 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
948 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
950 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
951 WGC3Denum, WGC3Dint)
952 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
953 WGC3Denum, WGC3Dint)
955 DELEGATE_TO_GL_2R(mapBufferCHROMIUM, MapBufferCHROMIUM, WGC3Denum, WGC3Denum,
956 void*)
957 DELEGATE_TO_GL_1R(unmapBufferCHROMIUM, UnmapBufferCHROMIUM, WGC3Denum,
958 WGC3Dboolean)
960 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, WGC3Denum,
961 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
962 WGC3Denum, WGC3Denum, const void*)
963 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
964 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
965 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
967 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
968 WGC3Denum)
970 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
972 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
973 WGC3Dint, WGC3Dsizei, WGC3Dsizei)
975 void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
976 WGC3Denum mode,
977 WGC3Dsizei count,
978 WGC3Denum type,
979 WGC3Dintptr offset,
980 WGC3Dsizei primcount) {
981 gl_->DrawElementsInstancedANGLE(
982 mode, count, type,
983 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
986 DELEGATE_TO_GL_2(vertexAttribDivisorANGLE, VertexAttribDivisorANGLE, WGC3Duint,
987 WGC3Duint)
989 DELEGATE_TO_GL_4R(createGpuMemoryBufferImageCHROMIUM,
990 CreateGpuMemoryBufferImageCHROMIUM,
991 WGC3Dsizei,
992 WGC3Dsizei,
993 WGC3Denum,
994 WGC3Denum,
995 WGC3Duint);
997 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
999 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
1000 FramebufferTexture2DMultisampleEXT,
1001 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1003 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1004 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1005 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1007 DELEGATE_TO_GL_1(beginTransformFeedback, BeginTransformFeedback, WGC3Denum)
1008 DELEGATE_TO_GL_3(bindBufferBase, BindBufferBase, WGC3Denum, WGC3Duint,
1009 WGC3Duint)
1010 DELEGATE_TO_GL_5(bindBufferRange, BindBufferRange, WGC3Denum, WGC3Duint,
1011 WGC3Duint, WGC3Dintptr, WGC3Dsizeiptr)
1012 DELEGATE_TO_GL_2(bindSampler, BindSampler, WGC3Duint, WebGLId)
1013 DELEGATE_TO_GL_2(bindTransformFeedback, BindTransformFeedback, WGC3Denum,
1014 WebGLId)
1015 DELEGATE_TO_GL_4(clearBufferfi, ClearBufferfi, WGC3Denum, WGC3Dint, WGC3Dfloat,
1016 WGC3Dint)
1017 DELEGATE_TO_GL_3(clearBufferfv, ClearBufferfv, WGC3Denum, WGC3Dint,
1018 const WGC3Dfloat *)
1019 DELEGATE_TO_GL_3(clearBufferiv, ClearBufferiv, WGC3Denum, WGC3Dint,
1020 const WGC3Dint *)
1021 DELEGATE_TO_GL_3(clearBufferuiv, ClearBufferuiv, WGC3Denum, WGC3Dint,
1022 const WGC3Duint *)
1023 WGC3Denum WebGraphicsContext3DImpl::clientWaitSync(WGC3Dsync sync,
1024 WGC3Dbitfield flags,
1025 WGC3Duint64 timeout) {
1026 return gl_->ClientWaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1028 //DELEGATE_TO_GL_9(compressedTexImage3D, CompressedTexImage3D, WGC3Denum,
1029 // WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1030 // WGC3Dint, WGC3Dsizei, const void *)
1031 //DELEGATE_TO_GL_11(compressedTexSubImage3D, CompressedTexSubImage3D, WGC3Denum,
1032 // WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1033 // WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Dsizei, const void *)
1034 DELEGATE_TO_GL_5(copyBufferSubData, CopyBufferSubData, WGC3Denum, WGC3Denum,
1035 WGC3Dintptr, WGC3Dintptr, WGC3Dsizeiptr)
1036 DELEGATE_TO_GL_9(copyTexSubImage3D, CopyTexSubImage3D, WGC3Denum, WGC3Dint,
1037 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1038 WGC3Dsizei)
1039 WebGLId WebGraphicsContext3DImpl::createSampler() {
1040 GLuint sampler;
1041 gl_->GenSamplers(1, &sampler);
1042 return sampler;
1044 WebGLId WebGraphicsContext3DImpl::createTransformFeedback() {
1045 GLuint tf;
1046 gl_->GenTransformFeedbacks(1, &tf);
1047 return tf;
1049 void WebGraphicsContext3DImpl::deleteSampler(WebGLId sampler) {
1050 gl_->DeleteSamplers(1, &sampler);
1052 void WebGraphicsContext3DImpl::deleteSync(WGC3Dsync sync) {
1053 gl_->DeleteSync(reinterpret_cast<GLsync>(sync));
1055 void WebGraphicsContext3DImpl::deleteTransformFeedback(WebGLId tf) {
1056 gl_->DeleteTransformFeedbacks(1, &tf);
1058 void WebGraphicsContext3DImpl::drawRangeElements(
1059 WGC3Denum mode, WGC3Duint start, WGC3Duint end, WGC3Dsizei count,
1060 WGC3Denum type, WGC3Dintptr offset) {
1061 gl_->DrawRangeElements(mode, start, end, count, type,
1062 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1064 DELEGATE_TO_GL(endTransformFeedback, EndTransformFeedback)
1065 WGC3Dsync WebGraphicsContext3DImpl::fenceSync(WGC3Denum condition,
1066 WGC3Dbitfield flags) {
1067 return reinterpret_cast<WGC3Dsync>(gl_->FenceSync(condition, flags));
1069 DELEGATE_TO_GL_5(framebufferTextureLayer, FramebufferTextureLayer, WGC3Denum,
1070 WGC3Denum, WGC3Duint, WGC3Dint, WGC3Dint)
1071 DELEGATE_TO_GL_5(getActiveUniformBlockName, GetActiveUniformBlockName,
1072 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dchar *)
1073 DELEGATE_TO_GL_4(getActiveUniformBlockiv, GetActiveUniformBlockiv, WGC3Duint,
1074 WGC3Duint, WGC3Denum, WGC3Dint *)
1075 DELEGATE_TO_GL_5(getActiveUniformsiv, GetActiveUniformsiv, WGC3Duint,
1076 WGC3Dsizei, const WGC3Duint *, WGC3Denum, WGC3Dint *)
1077 DELEGATE_TO_GL_2R(getFragDataLocation, GetFragDataLocation, WGC3Duint,
1078 const WGC3Dchar *, WGC3Dint)
1079 DELEGATE_TO_GL_5(getInternalformativ, GetInternalformativ, WGC3Denum, WGC3Denum,
1080 WGC3Denum, WGC3Dsizei, WGC3Dint *)
1081 DELEGATE_TO_GL_3(getSamplerParameterfv, GetSamplerParameterfv, WGC3Duint,
1082 WGC3Denum, WGC3Dfloat *)
1083 DELEGATE_TO_GL_3(getSamplerParameteriv, GetSamplerParameteriv, WGC3Duint,
1084 WGC3Denum, WGC3Dint *)
1085 DELEGATE_TO_GL_7(getTransformFeedbackVarying, GetTransformFeedbackVarying,
1086 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dsizei *,
1087 WGC3Denum *, WGC3Dchar *)
1088 DELEGATE_TO_GL_2R(getUniformBlockIndex, GetUniformBlockIndex, WGC3Duint,
1089 const WGC3Dchar *, WGC3Duint)
1090 DELEGATE_TO_GL_4(getUniformIndices, GetUniformIndices, WGC3Duint, WGC3Dsizei,
1091 const WGC3Dchar *const*, WGC3Duint *)
1092 //DELEGATE_TO_GL_3(getUniformuiv, GetUniformuiv, WGC3Duint, WGC3Dint,
1093 // WGC3Duint *)
1094 //DELEGATE_TO_GL_3(getVertexAttribIiv, GetVertexAttribIiv, WGC3Duint,
1095 // WGC3Denum, WGC3Dint *)
1096 //DELEGATE_TO_GL_3(getVertexAttribIuiv, GetVertexAttribIuiv, WGC3Duint,
1097 // WGC3Denum, WGC3Duint *)
1098 DELEGATE_TO_GL_3(invalidateFramebuffer, InvalidateFramebuffer, WGC3Denum,
1099 WGC3Dsizei, const WGC3Denum *)
1100 DELEGATE_TO_GL_7(invalidateSubFramebuffer, InvalidateSubFramebuffer, WGC3Denum,
1101 WGC3Dsizei, const WGC3Denum *, WGC3Dint, WGC3Dint, WGC3Dsizei,
1102 WGC3Dsizei)
1103 DELEGATE_TO_GL_1R(isSampler, IsSampler, WebGLId, WGC3Dboolean)
1104 WGC3Dboolean WebGraphicsContext3DImpl::isSync(WGC3Dsync sync) {
1105 return gl_->IsSync(reinterpret_cast<GLsync>(sync));
1107 DELEGATE_TO_GL_1R(isTransformFeedback, IsTransformFeedback, WGC3Duint,
1108 WGC3Dboolean)
1109 DELEGATE_TO_GL(pauseTransformFeedback, PauseTransformFeedback)
1110 //DELEGATE_TO_GL_3(programParameteri, ProgramParameteri, WGC3Duint, WGC3Denum,
1111 // WGC3Dint)
1112 DELEGATE_TO_GL_1(readBuffer, ReadBuffer, WGC3Denum)
1113 DELEGATE_TO_GL(resumeTransformFeedback, ResumeTransformFeedback)
1114 DELEGATE_TO_GL_3(samplerParameterf, SamplerParameterf, WGC3Duint, WGC3Denum,
1115 WGC3Dfloat)
1116 DELEGATE_TO_GL_3(samplerParameterfv, SamplerParameterfv, WGC3Duint, WGC3Denum,
1117 const WGC3Dfloat *)
1118 DELEGATE_TO_GL_3(samplerParameteri, SamplerParameteri, WGC3Duint, WGC3Denum,
1119 WGC3Dint)
1120 DELEGATE_TO_GL_3(samplerParameteriv, SamplerParameteriv, WGC3Duint, WGC3Denum,
1121 const WGC3Dint *)
1122 DELEGATE_TO_GL_10(texImage3D, TexImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1123 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei, WGC3Dint, WGC3Denum,
1124 WGC3Denum, const void *)
1125 DELEGATE_TO_GL_6(texStorage3D, TexStorage3D, WGC3Denum, WGC3Dsizei, WGC3Denum,
1126 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei)
1127 DELEGATE_TO_GL_11(texSubImage3D, TexSubImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1128 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1129 WGC3Denum, WGC3Denum, const void *)
1130 DELEGATE_TO_GL_4(transformFeedbackVaryings, TransformFeedbackVaryings,
1131 WGC3Duint, WGC3Dsizei, const WGC3Dchar *const*, WGC3Denum)
1132 DELEGATE_TO_GL_2(uniform1ui, Uniform1ui, WGC3Dint, WGC3Duint)
1133 DELEGATE_TO_GL_3(uniform1uiv, Uniform1uiv, WGC3Dint, WGC3Dsizei,
1134 const WGC3Duint *)
1135 DELEGATE_TO_GL_3(uniform2ui, Uniform2ui, WGC3Dint, WGC3Duint, WGC3Duint)
1136 DELEGATE_TO_GL_3(uniform2uiv, Uniform2uiv, WGC3Dint, WGC3Dsizei,
1137 const WGC3Duint *)
1138 DELEGATE_TO_GL_4(uniform3ui, Uniform3ui, WGC3Dint, WGC3Duint, WGC3Duint,
1139 WGC3Duint)
1140 DELEGATE_TO_GL_3(uniform3uiv, Uniform3uiv, WGC3Dint, WGC3Dsizei,
1141 const WGC3Duint *)
1142 DELEGATE_TO_GL_5(uniform4ui, Uniform4ui, WGC3Dint, WGC3Duint, WGC3Duint,
1143 WGC3Duint, WGC3Duint)
1144 DELEGATE_TO_GL_3(uniform4uiv, Uniform4uiv, WGC3Dint, WGC3Dsizei,
1145 const WGC3Duint *)
1146 DELEGATE_TO_GL_3(uniformBlockBinding, UniformBlockBinding, WGC3Duint, WGC3Duint,
1147 WGC3Duint)
1148 DELEGATE_TO_GL_4(uniformMatrix2x3fv, UniformMatrix2x3fv, WGC3Dint, WGC3Dsizei,
1149 WGC3Dboolean, const WGC3Dfloat*)
1150 DELEGATE_TO_GL_4(uniformMatrix2x4fv, UniformMatrix2x4fv, WGC3Dint, WGC3Dsizei,
1151 WGC3Dboolean, const WGC3Dfloat*)
1152 DELEGATE_TO_GL_4(uniformMatrix3x2fv, UniformMatrix3x2fv, WGC3Dint, WGC3Dsizei,
1153 WGC3Dboolean, const WGC3Dfloat*)
1154 DELEGATE_TO_GL_4(uniformMatrix3x4fv, UniformMatrix3x4fv, WGC3Dint, WGC3Dsizei,
1155 WGC3Dboolean, const WGC3Dfloat*)
1156 DELEGATE_TO_GL_4(uniformMatrix4x2fv, UniformMatrix4x2fv, WGC3Dint, WGC3Dsizei,
1157 WGC3Dboolean, const WGC3Dfloat*)
1158 DELEGATE_TO_GL_4(uniformMatrix4x3fv, UniformMatrix4x3fv, WGC3Dint, WGC3Dsizei,
1159 WGC3Dboolean, const WGC3Dfloat*)
1160 DELEGATE_TO_GL_5(vertexAttribI4i, VertexAttribI4i, WGC3Duint, WGC3Dint,
1161 WGC3Dint, WGC3Dint, WGC3Dint)
1162 DELEGATE_TO_GL_2(vertexAttribI4iv, VertexAttribI4iv, WGC3Duint,
1163 const WGC3Dint *)
1164 DELEGATE_TO_GL_5(vertexAttribI4ui, VertexAttribI4ui, WGC3Duint, WGC3Duint,
1165 WGC3Duint, WGC3Duint, WGC3Duint)
1166 DELEGATE_TO_GL_2(vertexAttribI4uiv, VertexAttribI4uiv, WGC3Duint,
1167 const WGC3Duint *)
1168 void WebGraphicsContext3DImpl::vertexAttribIPointer(
1169 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dsizei stride,
1170 WGC3Dintptr offset) {
1171 gl_->VertexAttribIPointer(
1172 index, size, type, stride,
1173 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1175 void WebGraphicsContext3DImpl::waitSync(WGC3Dsync sync,
1176 WGC3Dbitfield flags,
1177 WGC3Duint64 timeout) {
1178 gl_->WaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1181 GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
1182 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1185 ::gpu::gles2::GLES2ImplementationErrorMessageCallback*
1186 WebGraphicsContext3DImpl::getErrorMessageCallback() {
1187 if (!client_error_message_callback_) {
1188 client_error_message_callback_.reset(
1189 new WebGraphicsContext3DErrorMessageCallback(this));
1191 return client_error_message_callback_.get();
1194 void WebGraphicsContext3DImpl::OnErrorMessage(
1195 const std::string& message, int id) {
1196 if (error_message_callback_) {
1197 blink::WebString str = blink::WebString::fromUTF8(message.c_str());
1198 error_message_callback_->onErrorMessage(str, id);
1202 // TODO(bajones): Look into removing these functions from the blink interface
1203 void WebGraphicsContext3DImpl::prepareTexture() {
1204 NOTREACHED();
1207 void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
1208 int x, int y, int width, int height) {
1209 NOTREACHED();
1212 void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
1213 bool visible) {
1214 NOTREACHED();
1217 void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
1218 WebGLId texture, WebGLId parentTexture) {
1219 NOTIMPLEMENTED();
1222 void WebGraphicsContext3DImpl::releaseShaderCompiler() {
1225 // static
1226 void WebGraphicsContext3DImpl::ConvertAttributes(
1227 const blink::WebGraphicsContext3D::Attributes& attributes,
1228 ::gpu::gles2::ContextCreationAttribHelper* output_attribs) {
1229 output_attribs->alpha_size = attributes.alpha ? 8 : 0;
1230 output_attribs->depth_size = attributes.depth ? 24 : 0;
1231 output_attribs->stencil_size = attributes.stencil ? 8 : 0;
1232 output_attribs->samples = attributes.antialias ? 4 : 0;
1233 output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
1234 output_attribs->fail_if_major_perf_caveat =
1235 attributes.failIfMajorPerformanceCaveat;
1236 output_attribs->bind_generates_resource = false;
1237 output_attribs->es3_context_required =
1238 (attributes.webGL && attributes.webGLVersion == 2);
1241 } // namespace gpu_blink