Slow Reports - Embed Metadata in Traces
[chromium-blink-merge.git] / gpu / blink / webgraphicscontext3d_impl.cc
blob123ba79aa121db8c476c7eb502ac9ab25df4d186
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 WebGraphicsContext3DImpl::WebGraphicsContext3DImpl()
185 : initialized_(false),
186 initialize_failed_(false),
187 context_lost_callback_(0),
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_2(getInteger64v, GetInteger64v, WGC3Denum, WGC3Dint64*)
459 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
461 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
462 WebGLId program) {
463 GLint logLength = 0;
464 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
465 if (!logLength)
466 return blink::WebString();
467 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
468 if (!log)
469 return blink::WebString();
470 GLsizei returnedLogLength = 0;
471 gl_->GetProgramInfoLog(
472 program, logLength, &returnedLogLength, log.get());
473 DCHECK_EQ(logLength, returnedLogLength + 1);
474 blink::WebString res =
475 blink::WebString::fromUTF8(log.get(), returnedLogLength);
476 return res;
479 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
480 WGC3Denum, WGC3Denum, WGC3Dint*)
482 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
484 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
485 WebGLId shader) {
486 GLint logLength = 0;
487 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
488 if (!logLength)
489 return blink::WebString();
490 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
491 if (!log)
492 return blink::WebString();
493 GLsizei returnedLogLength = 0;
494 gl_->GetShaderInfoLog(
495 shader, logLength, &returnedLogLength, log.get());
496 DCHECK_EQ(logLength, returnedLogLength + 1);
497 blink::WebString res =
498 blink::WebString::fromUTF8(log.get(), returnedLogLength);
499 return res;
502 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
503 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
505 blink::WebString WebGraphicsContext3DImpl::getShaderSource(
506 WebGLId shader) {
507 GLint logLength = 0;
508 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
509 if (!logLength)
510 return blink::WebString();
511 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
512 if (!log)
513 return blink::WebString();
514 GLsizei returnedLogLength = 0;
515 gl_->GetShaderSource(
516 shader, logLength, &returnedLogLength, log.get());
517 if (!returnedLogLength)
518 return blink::WebString();
519 DCHECK_EQ(logLength, returnedLogLength + 1);
520 blink::WebString res =
521 blink::WebString::fromUTF8(log.get(), returnedLogLength);
522 return res;
525 blink::WebString WebGraphicsContext3DImpl::
526 getTranslatedShaderSourceANGLE(WebGLId shader) {
527 GLint logLength = 0;
528 gl_->GetShaderiv(
529 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
530 if (!logLength)
531 return blink::WebString();
532 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
533 if (!log)
534 return blink::WebString();
535 GLsizei returnedLogLength = 0;
536 gl_->GetTranslatedShaderSourceANGLE(
537 shader, logLength, &returnedLogLength, log.get());
538 if (!returnedLogLength)
539 return blink::WebString();
540 DCHECK_EQ(logLength, returnedLogLength + 1);
541 blink::WebString res =
542 blink::WebString::fromUTF8(log.get(), returnedLogLength);
543 return res;
546 blink::WebString WebGraphicsContext3DImpl::getString(
547 WGC3Denum name) {
548 return blink::WebString::fromUTF8(
549 reinterpret_cast<const char*>(gl_->GetString(name)));
552 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
553 WGC3Denum, WGC3Denum, WGC3Dfloat*)
555 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
556 WGC3Denum, WGC3Denum, WGC3Dint*)
558 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
560 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
562 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
563 WebGLId, const WGC3Dchar*, WGC3Dint)
565 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
566 WGC3Duint, WGC3Denum, WGC3Dfloat*)
568 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
569 WGC3Duint, WGC3Denum, WGC3Dint*)
571 WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
572 WGC3Duint index, WGC3Denum pname) {
573 GLvoid* value = NULL;
574 // NOTE: If pname is ever a value that returns more then 1 element
575 // this will corrupt memory.
576 gl_->GetVertexAttribPointerv(index, pname, &value);
577 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
580 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
582 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
584 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
586 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
588 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
590 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
592 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
594 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
596 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
598 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
600 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
602 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
604 DELEGATE_TO_GL_7(readPixels, ReadPixels,
605 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
606 WGC3Denum, void*)
608 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
609 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
611 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
613 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
615 void WebGraphicsContext3DImpl::shaderSource(
616 WebGLId shader, const WGC3Dchar* string) {
617 GLint length = strlen(string);
618 gl_->ShaderSource(shader, 1, &string, &length);
621 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
623 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
624 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
626 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
628 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
629 WGC3Denum, WGC3Duint)
631 DELEGATE_TO_GL_3(stencilOp, StencilOp,
632 WGC3Denum, WGC3Denum, WGC3Denum)
634 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
635 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
637 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
638 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
639 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
641 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
642 WGC3Denum, WGC3Denum, WGC3Dfloat);
644 DELEGATE_TO_GL_3(texParameteri, TexParameteri,
645 WGC3Denum, WGC3Denum, WGC3Dint);
647 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
648 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
649 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
651 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
653 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
654 const WGC3Dfloat*)
656 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
658 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
660 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
662 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
663 const WGC3Dfloat*)
665 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
667 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
669 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
670 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
672 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
673 const WGC3Dfloat*)
675 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
677 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
679 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
680 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
682 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
683 const WGC3Dfloat*)
685 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
686 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
688 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
690 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
691 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
693 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
694 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
696 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
697 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
699 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
701 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
703 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
705 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
706 const WGC3Dfloat*)
708 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
709 WGC3Dfloat, WGC3Dfloat)
711 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
712 const WGC3Dfloat*)
714 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
715 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
717 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
718 const WGC3Dfloat*)
720 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
721 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
723 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
724 const WGC3Dfloat*)
726 void WebGraphicsContext3DImpl::vertexAttribPointer(
727 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
728 WGC3Dsizei stride, WGC3Dintptr offset) {
729 gl_->VertexAttribPointer(
730 index, size, type, normalized, stride,
731 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
734 DELEGATE_TO_GL_4(viewport, Viewport,
735 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
737 WebGLId WebGraphicsContext3DImpl::createBuffer() {
738 GLuint o;
739 gl_->GenBuffers(1, &o);
740 return o;
743 WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
744 GLuint o = 0;
745 gl_->GenFramebuffers(1, &o);
746 return o;
749 WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
750 GLuint o;
751 gl_->GenRenderbuffers(1, &o);
752 return o;
755 WebGLId WebGraphicsContext3DImpl::createTexture() {
756 GLuint o;
757 gl_->GenTextures(1, &o);
758 return o;
761 void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
762 gl_->DeleteBuffers(1, &buffer);
765 void WebGraphicsContext3DImpl::deleteFramebuffer(
766 WebGLId framebuffer) {
767 gl_->DeleteFramebuffers(1, &framebuffer);
770 void WebGraphicsContext3DImpl::deleteRenderbuffer(
771 WebGLId renderbuffer) {
772 gl_->DeleteRenderbuffers(1, &renderbuffer);
775 void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
776 gl_->DeleteTextures(1, &texture);
779 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
781 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
783 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
785 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
787 void WebGraphicsContext3DImpl::setErrorMessageCallback(
788 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
789 error_message_callback_ = cb;
792 void WebGraphicsContext3DImpl::setContextLostCallback(
793 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
794 context_lost_callback_ = cb;
797 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
798 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
800 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
801 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
803 WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
804 GLuint o;
805 gl_->GenQueriesEXT(1, &o);
806 return o;
809 void WebGraphicsContext3DImpl::deleteQueryEXT(
810 WebGLId query) {
811 gl_->DeleteQueriesEXT(1, &query);
814 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
815 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
816 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
817 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
818 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
819 WebGLId, WGC3Denum, WGC3Duint*)
821 DELEGATE_TO_GL_5(copyTextureCHROMIUM,
822 CopyTextureCHROMIUM,
823 WGC3Denum,
824 WebGLId,
825 WebGLId,
826 WGC3Denum,
827 WGC3Denum);
829 DELEGATE_TO_GL_9(copySubTextureCHROMIUM,
830 CopySubTextureCHROMIUM,
831 WGC3Denum,
832 WebGLId,
833 WebGLId,
834 WGC3Dint,
835 WGC3Dint,
836 WGC3Dint,
837 WGC3Dint,
838 WGC3Dsizei,
839 WGC3Dsizei);
841 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
842 WebGLId, WGC3Dint, const WGC3Dchar*)
844 void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
845 flush_id_ = GenFlushID();
846 gl_->ShallowFlushCHROMIUM();
849 void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
850 flush_id_ = GenFlushID();
851 gl_->ShallowFinishCHROMIUM();
854 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
856 void WebGraphicsContext3DImpl::loseContextCHROMIUM(
857 WGC3Denum current, WGC3Denum other) {
858 gl_->LoseContextCHROMIUM(current, other);
859 gl_->Flush();
862 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
863 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
864 WGC3Denum, const WGC3Dbyte*)
865 DELEGATE_TO_GL_3(produceTextureDirectCHROMIUM, ProduceTextureDirectCHROMIUM,
866 WebGLId, WGC3Denum, const WGC3Dbyte*)
867 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
868 WGC3Denum, const WGC3Dbyte*)
869 DELEGATE_TO_GL_2R(createAndConsumeTextureCHROMIUM,
870 CreateAndConsumeTextureCHROMIUM,
871 WGC3Denum, const WGC3Dbyte*, WebGLId)
873 DELEGATE_TO_GL_2(genValuebuffersCHROMIUM,
874 GenValuebuffersCHROMIUM,
875 WGC3Dsizei,
876 WebGLId*);
878 WebGLId WebGraphicsContext3DImpl::createValuebufferCHROMIUM() {
879 GLuint o;
880 gl_->GenValuebuffersCHROMIUM(1, &o);
881 return o;
884 DELEGATE_TO_GL_2(deleteValuebuffersCHROMIUM,
885 DeleteValuebuffersCHROMIUM,
886 WGC3Dsizei,
887 WebGLId*);
889 void WebGraphicsContext3DImpl::deleteValuebufferCHROMIUM(WebGLId valuebuffer) {
890 gl_->DeleteValuebuffersCHROMIUM(1, &valuebuffer);
893 DELEGATE_TO_GL_1RB(isValuebufferCHROMIUM,
894 IsValuebufferCHROMIUM,
895 WebGLId,
896 WGC3Dboolean)
897 DELEGATE_TO_GL_2(bindValuebufferCHROMIUM,
898 BindValuebufferCHROMIUM,
899 WGC3Denum,
900 WebGLId)
901 DELEGATE_TO_GL_2(subscribeValueCHROMIUM,
902 SubscribeValueCHROMIUM,
903 WGC3Denum,
904 WGC3Denum);
905 DELEGATE_TO_GL_1(populateSubscribedValuesCHROMIUM,
906 PopulateSubscribedValuesCHROMIUM,
907 WGC3Denum);
908 DELEGATE_TO_GL_3(uniformValuebufferCHROMIUM,
909 UniformValuebufferCHROMIUM,
910 WGC3Dint,
911 WGC3Denum,
912 WGC3Denum);
913 DELEGATE_TO_GL_2(traceBeginCHROMIUM,
914 TraceBeginCHROMIUM,
915 const WGC3Dchar*,
916 const WGC3Dchar*);
917 DELEGATE_TO_GL(traceEndCHROMIUM, TraceEndCHROMIUM);
919 void WebGraphicsContext3DImpl::insertEventMarkerEXT(
920 const WGC3Dchar* marker) {
921 gl_->InsertEventMarkerEXT(0, marker);
924 void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
925 const WGC3Dchar* marker) {
926 gl_->PushGroupMarkerEXT(0, marker);
929 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
931 WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
932 GLuint array;
933 gl_->GenVertexArraysOES(1, &array);
934 return array;
937 void WebGraphicsContext3DImpl::deleteVertexArrayOES(
938 WebGLId array) {
939 gl_->DeleteVertexArraysOES(1, &array);
942 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
943 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
945 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
946 WGC3Denum, WGC3Dint)
947 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
948 WGC3Denum, WGC3Dint)
950 DELEGATE_TO_GL_2R(mapBufferCHROMIUM, MapBufferCHROMIUM, WGC3Denum, WGC3Denum,
951 void*)
952 DELEGATE_TO_GL_1R(unmapBufferCHROMIUM, UnmapBufferCHROMIUM, WGC3Denum,
953 WGC3Dboolean)
955 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, WGC3Denum,
956 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
957 WGC3Denum, WGC3Denum, const void*)
958 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
959 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
960 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
962 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
963 WGC3Denum)
965 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
967 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
968 WGC3Dint, WGC3Dsizei, WGC3Dsizei)
970 void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
971 WGC3Denum mode,
972 WGC3Dsizei count,
973 WGC3Denum type,
974 WGC3Dintptr offset,
975 WGC3Dsizei primcount) {
976 gl_->DrawElementsInstancedANGLE(
977 mode, count, type,
978 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
981 DELEGATE_TO_GL_2(vertexAttribDivisorANGLE, VertexAttribDivisorANGLE, WGC3Duint,
982 WGC3Duint)
984 DELEGATE_TO_GL_4R(createGpuMemoryBufferImageCHROMIUM,
985 CreateGpuMemoryBufferImageCHROMIUM,
986 WGC3Dsizei,
987 WGC3Dsizei,
988 WGC3Denum,
989 WGC3Denum,
990 WGC3Duint);
992 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
994 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
995 FramebufferTexture2DMultisampleEXT,
996 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
998 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
999 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1000 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1002 DELEGATE_TO_GL_1(beginTransformFeedback, BeginTransformFeedback, WGC3Denum)
1003 DELEGATE_TO_GL_3(bindBufferBase, BindBufferBase, WGC3Denum, WGC3Duint,
1004 WGC3Duint)
1005 DELEGATE_TO_GL_5(bindBufferRange, BindBufferRange, WGC3Denum, WGC3Duint,
1006 WGC3Duint, WGC3Dintptr, WGC3Dsizeiptr)
1007 DELEGATE_TO_GL_2(bindSampler, BindSampler, WGC3Duint, WebGLId)
1008 DELEGATE_TO_GL_2(bindTransformFeedback, BindTransformFeedback, WGC3Denum,
1009 WebGLId)
1010 DELEGATE_TO_GL_4(clearBufferfi, ClearBufferfi, WGC3Denum, WGC3Dint, WGC3Dfloat,
1011 WGC3Dint)
1012 DELEGATE_TO_GL_3(clearBufferfv, ClearBufferfv, WGC3Denum, WGC3Dint,
1013 const WGC3Dfloat *)
1014 DELEGATE_TO_GL_3(clearBufferiv, ClearBufferiv, WGC3Denum, WGC3Dint,
1015 const WGC3Dint *)
1016 DELEGATE_TO_GL_3(clearBufferuiv, ClearBufferuiv, WGC3Denum, WGC3Dint,
1017 const WGC3Duint *)
1018 WGC3Denum WebGraphicsContext3DImpl::clientWaitSync(WGC3Dsync sync,
1019 WGC3Dbitfield flags,
1020 WGC3Duint64 timeout) {
1021 return gl_->ClientWaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1023 DELEGATE_TO_GL_9(compressedTexImage3D, CompressedTexImage3D, WGC3Denum,
1024 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1025 WGC3Dint, WGC3Dsizei, const void *)
1026 DELEGATE_TO_GL_11(compressedTexSubImage3D, CompressedTexSubImage3D, WGC3Denum,
1027 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1028 WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Dsizei, const void *)
1029 DELEGATE_TO_GL_5(copyBufferSubData, CopyBufferSubData, WGC3Denum, WGC3Denum,
1030 WGC3Dintptr, WGC3Dintptr, WGC3Dsizeiptr)
1031 DELEGATE_TO_GL_9(copyTexSubImage3D, CopyTexSubImage3D, WGC3Denum, WGC3Dint,
1032 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1033 WGC3Dsizei)
1034 WebGLId WebGraphicsContext3DImpl::createSampler() {
1035 GLuint sampler;
1036 gl_->GenSamplers(1, &sampler);
1037 return sampler;
1039 WebGLId WebGraphicsContext3DImpl::createTransformFeedback() {
1040 GLuint tf;
1041 gl_->GenTransformFeedbacks(1, &tf);
1042 return tf;
1044 void WebGraphicsContext3DImpl::deleteSampler(WebGLId sampler) {
1045 gl_->DeleteSamplers(1, &sampler);
1047 void WebGraphicsContext3DImpl::deleteSync(WGC3Dsync sync) {
1048 gl_->DeleteSync(reinterpret_cast<GLsync>(sync));
1050 void WebGraphicsContext3DImpl::deleteTransformFeedback(WebGLId tf) {
1051 gl_->DeleteTransformFeedbacks(1, &tf);
1053 void WebGraphicsContext3DImpl::drawRangeElements(
1054 WGC3Denum mode, WGC3Duint start, WGC3Duint end, WGC3Dsizei count,
1055 WGC3Denum type, WGC3Dintptr offset) {
1056 gl_->DrawRangeElements(mode, start, end, count, type,
1057 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1059 DELEGATE_TO_GL(endTransformFeedback, EndTransformFeedback)
1060 WGC3Dsync WebGraphicsContext3DImpl::fenceSync(WGC3Denum condition,
1061 WGC3Dbitfield flags) {
1062 return reinterpret_cast<WGC3Dsync>(gl_->FenceSync(condition, flags));
1064 DELEGATE_TO_GL_5(framebufferTextureLayer, FramebufferTextureLayer, WGC3Denum,
1065 WGC3Denum, WGC3Duint, WGC3Dint, WGC3Dint)
1066 DELEGATE_TO_GL_5(getActiveUniformBlockName, GetActiveUniformBlockName,
1067 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dchar *)
1068 DELEGATE_TO_GL_4(getActiveUniformBlockiv, GetActiveUniformBlockiv, WGC3Duint,
1069 WGC3Duint, WGC3Denum, WGC3Dint *)
1070 DELEGATE_TO_GL_5(getActiveUniformsiv, GetActiveUniformsiv, WGC3Duint,
1071 WGC3Dsizei, const WGC3Duint *, WGC3Denum, WGC3Dint *)
1072 DELEGATE_TO_GL_2R(getFragDataLocation, GetFragDataLocation, WGC3Duint,
1073 const WGC3Dchar *, WGC3Dint)
1074 DELEGATE_TO_GL_5(getInternalformativ, GetInternalformativ, WGC3Denum, WGC3Denum,
1075 WGC3Denum, WGC3Dsizei, WGC3Dint *)
1076 DELEGATE_TO_GL_3(getSamplerParameterfv, GetSamplerParameterfv, WGC3Duint,
1077 WGC3Denum, WGC3Dfloat *)
1078 DELEGATE_TO_GL_3(getSamplerParameteriv, GetSamplerParameteriv, WGC3Duint,
1079 WGC3Denum, WGC3Dint *)
1080 DELEGATE_TO_GL_7(getTransformFeedbackVarying, GetTransformFeedbackVarying,
1081 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dsizei *,
1082 WGC3Denum *, WGC3Dchar *)
1083 DELEGATE_TO_GL_2R(getUniformBlockIndex, GetUniformBlockIndex, WGC3Duint,
1084 const WGC3Dchar *, WGC3Duint)
1085 DELEGATE_TO_GL_4(getUniformIndices, GetUniformIndices, WGC3Duint, WGC3Dsizei,
1086 const WGC3Dchar *const*, WGC3Duint *)
1087 //DELEGATE_TO_GL_3(getUniformuiv, GetUniformuiv, WGC3Duint, WGC3Dint,
1088 // WGC3Duint *)
1089 //DELEGATE_TO_GL_3(getVertexAttribIiv, GetVertexAttribIiv, WGC3Duint,
1090 // WGC3Denum, WGC3Dint *)
1091 //DELEGATE_TO_GL_3(getVertexAttribIuiv, GetVertexAttribIuiv, WGC3Duint,
1092 // WGC3Denum, WGC3Duint *)
1093 DELEGATE_TO_GL_3(invalidateFramebuffer, InvalidateFramebuffer, WGC3Denum,
1094 WGC3Dsizei, const WGC3Denum *)
1095 DELEGATE_TO_GL_7(invalidateSubFramebuffer, InvalidateSubFramebuffer, WGC3Denum,
1096 WGC3Dsizei, const WGC3Denum *, WGC3Dint, WGC3Dint, WGC3Dsizei,
1097 WGC3Dsizei)
1098 DELEGATE_TO_GL_1R(isSampler, IsSampler, WebGLId, WGC3Dboolean)
1099 WGC3Dboolean WebGraphicsContext3DImpl::isSync(WGC3Dsync sync) {
1100 return gl_->IsSync(reinterpret_cast<GLsync>(sync));
1102 DELEGATE_TO_GL_1R(isTransformFeedback, IsTransformFeedback, WGC3Duint,
1103 WGC3Dboolean)
1104 DELEGATE_TO_GL(pauseTransformFeedback, PauseTransformFeedback)
1105 //DELEGATE_TO_GL_3(programParameteri, ProgramParameteri, WGC3Duint, WGC3Denum,
1106 // WGC3Dint)
1107 DELEGATE_TO_GL_1(readBuffer, ReadBuffer, WGC3Denum)
1108 DELEGATE_TO_GL(resumeTransformFeedback, ResumeTransformFeedback)
1109 DELEGATE_TO_GL_3(samplerParameterf, SamplerParameterf, WGC3Duint, WGC3Denum,
1110 WGC3Dfloat)
1111 DELEGATE_TO_GL_3(samplerParameterfv, SamplerParameterfv, WGC3Duint, WGC3Denum,
1112 const WGC3Dfloat *)
1113 DELEGATE_TO_GL_3(samplerParameteri, SamplerParameteri, WGC3Duint, WGC3Denum,
1114 WGC3Dint)
1115 DELEGATE_TO_GL_3(samplerParameteriv, SamplerParameteriv, WGC3Duint, WGC3Denum,
1116 const WGC3Dint *)
1117 DELEGATE_TO_GL_10(texImage3D, TexImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1118 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei, WGC3Dint, WGC3Denum,
1119 WGC3Denum, const void *)
1120 DELEGATE_TO_GL_6(texStorage3D, TexStorage3D, WGC3Denum, WGC3Dsizei, WGC3Denum,
1121 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei)
1122 DELEGATE_TO_GL_11(texSubImage3D, TexSubImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1123 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1124 WGC3Denum, WGC3Denum, const void *)
1125 DELEGATE_TO_GL_4(transformFeedbackVaryings, TransformFeedbackVaryings,
1126 WGC3Duint, WGC3Dsizei, const WGC3Dchar *const*, WGC3Denum)
1127 DELEGATE_TO_GL_2(uniform1ui, Uniform1ui, WGC3Dint, WGC3Duint)
1128 DELEGATE_TO_GL_3(uniform1uiv, Uniform1uiv, WGC3Dint, WGC3Dsizei,
1129 const WGC3Duint *)
1130 DELEGATE_TO_GL_3(uniform2ui, Uniform2ui, WGC3Dint, WGC3Duint, WGC3Duint)
1131 DELEGATE_TO_GL_3(uniform2uiv, Uniform2uiv, WGC3Dint, WGC3Dsizei,
1132 const WGC3Duint *)
1133 DELEGATE_TO_GL_4(uniform3ui, Uniform3ui, WGC3Dint, WGC3Duint, WGC3Duint,
1134 WGC3Duint)
1135 DELEGATE_TO_GL_3(uniform3uiv, Uniform3uiv, WGC3Dint, WGC3Dsizei,
1136 const WGC3Duint *)
1137 DELEGATE_TO_GL_5(uniform4ui, Uniform4ui, WGC3Dint, WGC3Duint, WGC3Duint,
1138 WGC3Duint, WGC3Duint)
1139 DELEGATE_TO_GL_3(uniform4uiv, Uniform4uiv, WGC3Dint, WGC3Dsizei,
1140 const WGC3Duint *)
1141 DELEGATE_TO_GL_3(uniformBlockBinding, UniformBlockBinding, WGC3Duint, WGC3Duint,
1142 WGC3Duint)
1143 DELEGATE_TO_GL_4(uniformMatrix2x3fv, UniformMatrix2x3fv, WGC3Dint, WGC3Dsizei,
1144 WGC3Dboolean, const WGC3Dfloat*)
1145 DELEGATE_TO_GL_4(uniformMatrix2x4fv, UniformMatrix2x4fv, WGC3Dint, WGC3Dsizei,
1146 WGC3Dboolean, const WGC3Dfloat*)
1147 DELEGATE_TO_GL_4(uniformMatrix3x2fv, UniformMatrix3x2fv, WGC3Dint, WGC3Dsizei,
1148 WGC3Dboolean, const WGC3Dfloat*)
1149 DELEGATE_TO_GL_4(uniformMatrix3x4fv, UniformMatrix3x4fv, WGC3Dint, WGC3Dsizei,
1150 WGC3Dboolean, const WGC3Dfloat*)
1151 DELEGATE_TO_GL_4(uniformMatrix4x2fv, UniformMatrix4x2fv, WGC3Dint, WGC3Dsizei,
1152 WGC3Dboolean, const WGC3Dfloat*)
1153 DELEGATE_TO_GL_4(uniformMatrix4x3fv, UniformMatrix4x3fv, WGC3Dint, WGC3Dsizei,
1154 WGC3Dboolean, const WGC3Dfloat*)
1155 DELEGATE_TO_GL_5(vertexAttribI4i, VertexAttribI4i, WGC3Duint, WGC3Dint,
1156 WGC3Dint, WGC3Dint, WGC3Dint)
1157 DELEGATE_TO_GL_2(vertexAttribI4iv, VertexAttribI4iv, WGC3Duint,
1158 const WGC3Dint *)
1159 DELEGATE_TO_GL_5(vertexAttribI4ui, VertexAttribI4ui, WGC3Duint, WGC3Duint,
1160 WGC3Duint, WGC3Duint, WGC3Duint)
1161 DELEGATE_TO_GL_2(vertexAttribI4uiv, VertexAttribI4uiv, WGC3Duint,
1162 const WGC3Duint *)
1163 void WebGraphicsContext3DImpl::vertexAttribIPointer(
1164 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dsizei stride,
1165 WGC3Dintptr offset) {
1166 gl_->VertexAttribIPointer(
1167 index, size, type, stride,
1168 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1170 void WebGraphicsContext3DImpl::waitSync(WGC3Dsync sync,
1171 WGC3Dbitfield flags,
1172 WGC3Duint64 timeout) {
1173 gl_->WaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1176 bool WebGraphicsContext3DImpl::isContextLost() {
1177 return getGraphicsResetStatusARB() != GL_NO_ERROR;
1180 blink::WGC3Denum WebGraphicsContext3DImpl::getGraphicsResetStatusARB() {
1181 return gl_->GetGraphicsResetStatusKHR();
1184 GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
1185 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1188 ::gpu::gles2::GLES2ImplementationErrorMessageCallback*
1189 WebGraphicsContext3DImpl::getErrorMessageCallback() {
1190 if (!client_error_message_callback_) {
1191 client_error_message_callback_.reset(
1192 new WebGraphicsContext3DErrorMessageCallback(this));
1194 return client_error_message_callback_.get();
1197 void WebGraphicsContext3DImpl::OnErrorMessage(
1198 const std::string& message, int id) {
1199 if (error_message_callback_) {
1200 blink::WebString str = blink::WebString::fromUTF8(message.c_str());
1201 error_message_callback_->onErrorMessage(str, id);
1205 // TODO(bajones): Look into removing these functions from the blink interface
1206 void WebGraphicsContext3DImpl::prepareTexture() {
1207 NOTREACHED();
1210 void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
1211 int x, int y, int width, int height) {
1212 NOTREACHED();
1215 void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
1216 bool visible) {
1217 NOTREACHED();
1220 void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
1221 WebGLId texture, WebGLId parentTexture) {
1222 NOTIMPLEMENTED();
1225 void WebGraphicsContext3DImpl::releaseShaderCompiler() {
1228 // static
1229 void WebGraphicsContext3DImpl::ConvertAttributes(
1230 const blink::WebGraphicsContext3D::Attributes& attributes,
1231 ::gpu::gles2::ContextCreationAttribHelper* output_attribs) {
1232 output_attribs->alpha_size = attributes.alpha ? 8 : 0;
1233 output_attribs->depth_size = attributes.depth ? 24 : 0;
1234 output_attribs->stencil_size = attributes.stencil ? 8 : 0;
1235 output_attribs->samples = attributes.antialias ? 4 : 0;
1236 output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
1237 output_attribs->fail_if_major_perf_caveat =
1238 attributes.failIfMajorPerformanceCaveat;
1239 output_attribs->bind_generates_resource = false;
1240 output_attribs->webgl_version = attributes.webGLVersion;
1243 } // namespace gpu_blink