Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / gpu / blink / webgraphicscontext3d_impl.cc
blob30fa260bb1623dcf2b89744fe66370df6b3c79ee
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_2(attachShader, AttachShader, WebGLId, WebGLId)
263 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
264 WGC3Duint, const WGC3Dchar*)
266 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
268 DELEGATE_TO_GL_2(bindFramebuffer, BindFramebuffer, WGC3Denum, WebGLId)
270 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
272 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
274 DELEGATE_TO_GL_4(blendColor, BlendColor,
275 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
277 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
279 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
280 WGC3Denum, WGC3Denum)
282 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
284 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
285 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
287 DELEGATE_TO_GL_4(bufferData, BufferData,
288 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
290 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
291 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
293 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
294 WGC3Denum, WGC3Denum)
296 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
298 DELEGATE_TO_GL_4(clearColor, ClearColor,
299 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
301 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
303 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
305 DELEGATE_TO_GL_4(colorMask, ColorMask,
306 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
308 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
310 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
311 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
312 WGC3Dsizei, WGC3Dsizei, const void*)
314 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
315 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
316 WGC3Denum, WGC3Dsizei, const void*)
318 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
319 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
320 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
322 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
323 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
324 WGC3Dsizei, WGC3Dsizei)
326 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
328 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
330 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
332 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
334 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
336 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
338 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
339 WGC3Duint)
341 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
343 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode,
344 WGC3Dsizei count,
345 WGC3Denum type,
346 WGC3Dintptr offset) {
347 gl_->DrawElements(
348 mode, count, type,
349 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
352 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
354 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
355 WGC3Duint)
357 void WebGraphicsContext3DImpl::finish() {
358 flush_id_ = GenFlushID();
359 gl_->Finish();
362 void WebGraphicsContext3DImpl::flush() {
363 flush_id_ = GenFlushID();
364 gl_->Flush();
367 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
368 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
370 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
371 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
373 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
375 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
377 bool WebGraphicsContext3DImpl::getActiveAttrib(
378 WebGLId program, WGC3Duint index, ActiveInfo& info) {
379 if (!program) {
380 synthesizeGLError(GL_INVALID_VALUE);
381 return false;
383 GLint max_name_length = -1;
384 gl_->GetProgramiv(
385 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
386 if (max_name_length < 0)
387 return false;
388 if (max_name_length == 0) {
389 // No active attributes exist.
390 synthesizeGLError(GL_INVALID_VALUE);
391 return false;
393 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
394 GLsizei length = 0;
395 GLint size = -1;
396 GLenum type = 0;
397 gl_->GetActiveAttrib(
398 program, index, max_name_length, &length, &size, &type, name.get());
399 if (size < 0) {
400 return false;
402 info.name = blink::WebString::fromUTF8(name.get(), length);
403 info.type = type;
404 info.size = size;
405 return true;
408 bool WebGraphicsContext3DImpl::getActiveUniform(
409 WebGLId program, WGC3Duint index, ActiveInfo& info) {
410 GLint max_name_length = -1;
411 gl_->GetProgramiv(
412 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
413 if (max_name_length < 0)
414 return false;
415 if (max_name_length == 0) {
416 // No active uniforms exist.
417 synthesizeGLError(GL_INVALID_VALUE);
418 return false;
420 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
421 GLsizei length = 0;
422 GLint size = -1;
423 GLenum type = 0;
424 gl_->GetActiveUniform(
425 program, index, max_name_length, &length, &size, &type, name.get());
426 if (size < 0) {
427 return false;
429 info.name = blink::WebString::fromUTF8(name.get(), length);
430 info.type = type;
431 info.size = size;
432 return true;
435 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
436 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
438 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
439 WebGLId, const WGC3Dchar*, WGC3Dint)
441 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
443 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
444 WGC3Denum, WGC3Denum, WGC3Dint*)
446 WGC3Denum WebGraphicsContext3DImpl::getError() {
447 if (!synthetic_errors_.empty()) {
448 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
449 WGC3Denum err = *iter;
450 synthetic_errors_.erase(iter);
451 return err;
454 return gl_->GetError();
457 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
459 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
460 GetFramebufferAttachmentParameteriv,
461 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
463 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
465 DELEGATE_TO_GL_2(getInteger64v, GetInteger64v, WGC3Denum, WGC3Dint64*)
467 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
469 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
470 WebGLId program) {
471 GLint logLength = 0;
472 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
473 if (!logLength)
474 return blink::WebString();
475 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
476 if (!log)
477 return blink::WebString();
478 GLsizei returnedLogLength = 0;
479 gl_->GetProgramInfoLog(
480 program, logLength, &returnedLogLength, log.get());
481 DCHECK_EQ(logLength, returnedLogLength + 1);
482 blink::WebString res =
483 blink::WebString::fromUTF8(log.get(), returnedLogLength);
484 return res;
487 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
488 WGC3Denum, WGC3Denum, WGC3Dint*)
490 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
492 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
493 WebGLId shader) {
494 GLint logLength = 0;
495 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
496 if (!logLength)
497 return blink::WebString();
498 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
499 if (!log)
500 return blink::WebString();
501 GLsizei returnedLogLength = 0;
502 gl_->GetShaderInfoLog(
503 shader, logLength, &returnedLogLength, log.get());
504 DCHECK_EQ(logLength, returnedLogLength + 1);
505 blink::WebString res =
506 blink::WebString::fromUTF8(log.get(), returnedLogLength);
507 return res;
510 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
511 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
513 blink::WebString WebGraphicsContext3DImpl::getShaderSource(
514 WebGLId shader) {
515 GLint logLength = 0;
516 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
517 if (!logLength)
518 return blink::WebString();
519 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
520 if (!log)
521 return blink::WebString();
522 GLsizei returnedLogLength = 0;
523 gl_->GetShaderSource(
524 shader, logLength, &returnedLogLength, log.get());
525 if (!returnedLogLength)
526 return blink::WebString();
527 DCHECK_EQ(logLength, returnedLogLength + 1);
528 blink::WebString res =
529 blink::WebString::fromUTF8(log.get(), returnedLogLength);
530 return res;
533 blink::WebString WebGraphicsContext3DImpl::
534 getTranslatedShaderSourceANGLE(WebGLId shader) {
535 GLint logLength = 0;
536 gl_->GetShaderiv(
537 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
538 if (!logLength)
539 return blink::WebString();
540 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
541 if (!log)
542 return blink::WebString();
543 GLsizei returnedLogLength = 0;
544 gl_->GetTranslatedShaderSourceANGLE(
545 shader, logLength, &returnedLogLength, log.get());
546 if (!returnedLogLength)
547 return blink::WebString();
548 DCHECK_EQ(logLength, returnedLogLength + 1);
549 blink::WebString res =
550 blink::WebString::fromUTF8(log.get(), returnedLogLength);
551 return res;
554 blink::WebString WebGraphicsContext3DImpl::getString(
555 WGC3Denum name) {
556 return blink::WebString::fromUTF8(
557 reinterpret_cast<const char*>(gl_->GetString(name)));
560 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
561 WGC3Denum, WGC3Denum, WGC3Dfloat*)
563 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
564 WGC3Denum, WGC3Denum, WGC3Dint*)
566 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
568 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
570 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
571 WebGLId, const WGC3Dchar*, WGC3Dint)
573 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
574 WGC3Duint, WGC3Denum, WGC3Dfloat*)
576 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
577 WGC3Duint, WGC3Denum, WGC3Dint*)
579 WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
580 WGC3Duint index, WGC3Denum pname) {
581 GLvoid* value = NULL;
582 // NOTE: If pname is ever a value that returns more then 1 element
583 // this will corrupt memory.
584 gl_->GetVertexAttribPointerv(index, pname, &value);
585 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
588 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
590 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
592 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
594 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
596 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
598 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
600 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
602 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
604 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
606 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
608 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
610 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
612 DELEGATE_TO_GL_7(readPixels, ReadPixels,
613 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
614 WGC3Denum, void*)
616 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
617 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
619 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
621 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
623 void WebGraphicsContext3DImpl::shaderSource(
624 WebGLId shader, const WGC3Dchar* string) {
625 GLint length = strlen(string);
626 gl_->ShaderSource(shader, 1, &string, &length);
629 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
631 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
632 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
634 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
636 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
637 WGC3Denum, WGC3Duint)
639 DELEGATE_TO_GL_3(stencilOp, StencilOp,
640 WGC3Denum, WGC3Denum, WGC3Denum)
642 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
643 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
645 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
646 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
647 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
649 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
650 WGC3Denum, WGC3Denum, WGC3Dfloat);
652 DELEGATE_TO_GL_3(texParameteri, TexParameteri,
653 WGC3Denum, WGC3Denum, WGC3Dint);
655 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
656 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
657 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
659 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
661 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
662 const WGC3Dfloat*)
664 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
666 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
668 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
670 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
671 const WGC3Dfloat*)
673 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
675 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
677 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
678 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
680 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
681 const WGC3Dfloat*)
683 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
685 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
687 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
688 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
690 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
691 const WGC3Dfloat*)
693 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
694 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
696 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
698 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
699 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
701 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
702 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
704 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
705 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
707 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
709 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
711 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
713 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
714 const WGC3Dfloat*)
716 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
717 WGC3Dfloat, WGC3Dfloat)
719 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
720 const WGC3Dfloat*)
722 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
723 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
725 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
726 const WGC3Dfloat*)
728 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
729 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
731 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
732 const WGC3Dfloat*)
734 void WebGraphicsContext3DImpl::vertexAttribPointer(
735 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
736 WGC3Dsizei stride, WGC3Dintptr offset) {
737 gl_->VertexAttribPointer(
738 index, size, type, normalized, stride,
739 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
742 DELEGATE_TO_GL_4(viewport, Viewport,
743 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
745 WebGLId WebGraphicsContext3DImpl::createBuffer() {
746 GLuint o;
747 gl_->GenBuffers(1, &o);
748 return o;
751 WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
752 GLuint o = 0;
753 gl_->GenFramebuffers(1, &o);
754 return o;
757 WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
758 GLuint o;
759 gl_->GenRenderbuffers(1, &o);
760 return o;
763 WebGLId WebGraphicsContext3DImpl::createTexture() {
764 GLuint o;
765 gl_->GenTextures(1, &o);
766 return o;
769 void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
770 gl_->DeleteBuffers(1, &buffer);
773 void WebGraphicsContext3DImpl::deleteFramebuffer(
774 WebGLId framebuffer) {
775 gl_->DeleteFramebuffers(1, &framebuffer);
778 void WebGraphicsContext3DImpl::deleteRenderbuffer(
779 WebGLId renderbuffer) {
780 gl_->DeleteRenderbuffers(1, &renderbuffer);
783 void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
784 gl_->DeleteTextures(1, &texture);
787 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
789 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
791 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
793 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
795 void WebGraphicsContext3DImpl::setErrorMessageCallback(
796 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
797 error_message_callback_ = cb;
800 void WebGraphicsContext3DImpl::setContextLostCallback(
801 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
802 context_lost_callback_ = cb;
805 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
806 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
808 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
809 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
811 WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
812 GLuint o;
813 gl_->GenQueriesEXT(1, &o);
814 return o;
817 void WebGraphicsContext3DImpl::deleteQueryEXT(
818 WebGLId query) {
819 gl_->DeleteQueriesEXT(1, &query);
822 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
823 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
824 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
825 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
826 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
827 WebGLId, WGC3Denum, WGC3Duint*)
829 DELEGATE_TO_GL_8(copyTextureCHROMIUM,
830 CopyTextureCHROMIUM,
831 WGC3Denum,
832 WebGLId,
833 WebGLId,
834 WGC3Denum,
835 WGC3Denum,
836 WGC3Dboolean,
837 WGC3Dboolean,
838 WGC3Dboolean);
840 DELEGATE_TO_GL_12(copySubTextureCHROMIUM,
841 CopySubTextureCHROMIUM,
842 WGC3Denum,
843 WebGLId,
844 WebGLId,
845 WGC3Dint,
846 WGC3Dint,
847 WGC3Dint,
848 WGC3Dint,
849 WGC3Dsizei,
850 WGC3Dsizei,
851 WGC3Dboolean,
852 WGC3Dboolean,
853 WGC3Dboolean);
855 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
856 WebGLId, WGC3Dint, const WGC3Dchar*)
858 void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
859 flush_id_ = GenFlushID();
860 gl_->ShallowFlushCHROMIUM();
863 void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
864 flush_id_ = GenFlushID();
865 gl_->ShallowFinishCHROMIUM();
868 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
870 void WebGraphicsContext3DImpl::loseContextCHROMIUM(
871 WGC3Denum current, WGC3Denum other) {
872 gl_->LoseContextCHROMIUM(current, other);
873 gl_->Flush();
876 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
877 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
878 WGC3Denum, const WGC3Dbyte*)
879 DELEGATE_TO_GL_3(produceTextureDirectCHROMIUM, ProduceTextureDirectCHROMIUM,
880 WebGLId, WGC3Denum, const WGC3Dbyte*)
881 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
882 WGC3Denum, const WGC3Dbyte*)
883 DELEGATE_TO_GL_2R(createAndConsumeTextureCHROMIUM,
884 CreateAndConsumeTextureCHROMIUM,
885 WGC3Denum, const WGC3Dbyte*, WebGLId)
887 DELEGATE_TO_GL_2(genValuebuffersCHROMIUM,
888 GenValuebuffersCHROMIUM,
889 WGC3Dsizei,
890 WebGLId*);
892 WebGLId WebGraphicsContext3DImpl::createValuebufferCHROMIUM() {
893 GLuint o;
894 gl_->GenValuebuffersCHROMIUM(1, &o);
895 return o;
898 DELEGATE_TO_GL_2(deleteValuebuffersCHROMIUM,
899 DeleteValuebuffersCHROMIUM,
900 WGC3Dsizei,
901 WebGLId*);
903 void WebGraphicsContext3DImpl::deleteValuebufferCHROMIUM(WebGLId valuebuffer) {
904 gl_->DeleteValuebuffersCHROMIUM(1, &valuebuffer);
907 DELEGATE_TO_GL_1RB(isValuebufferCHROMIUM,
908 IsValuebufferCHROMIUM,
909 WebGLId,
910 WGC3Dboolean)
911 DELEGATE_TO_GL_2(bindValuebufferCHROMIUM,
912 BindValuebufferCHROMIUM,
913 WGC3Denum,
914 WebGLId)
915 DELEGATE_TO_GL_2(subscribeValueCHROMIUM,
916 SubscribeValueCHROMIUM,
917 WGC3Denum,
918 WGC3Denum);
919 DELEGATE_TO_GL_1(populateSubscribedValuesCHROMIUM,
920 PopulateSubscribedValuesCHROMIUM,
921 WGC3Denum);
922 DELEGATE_TO_GL_3(uniformValuebufferCHROMIUM,
923 UniformValuebufferCHROMIUM,
924 WGC3Dint,
925 WGC3Denum,
926 WGC3Denum);
927 DELEGATE_TO_GL_2(traceBeginCHROMIUM,
928 TraceBeginCHROMIUM,
929 const WGC3Dchar*,
930 const WGC3Dchar*);
931 DELEGATE_TO_GL(traceEndCHROMIUM, TraceEndCHROMIUM);
933 void WebGraphicsContext3DImpl::insertEventMarkerEXT(
934 const WGC3Dchar* marker) {
935 gl_->InsertEventMarkerEXT(0, marker);
938 void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
939 const WGC3Dchar* marker) {
940 gl_->PushGroupMarkerEXT(0, marker);
943 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
945 WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
946 GLuint array;
947 gl_->GenVertexArraysOES(1, &array);
948 return array;
951 void WebGraphicsContext3DImpl::deleteVertexArrayOES(
952 WebGLId array) {
953 gl_->DeleteVertexArraysOES(1, &array);
956 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
957 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
959 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
960 WGC3Denum, WGC3Dint)
961 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
962 WGC3Denum, WGC3Dint)
964 DELEGATE_TO_GL_2R(mapBufferCHROMIUM, MapBufferCHROMIUM, WGC3Denum, WGC3Denum,
965 void*)
966 DELEGATE_TO_GL_1R(unmapBufferCHROMIUM, UnmapBufferCHROMIUM, WGC3Denum,
967 WGC3Dboolean)
969 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, WGC3Denum,
970 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
971 WGC3Denum, WGC3Denum, const void*)
972 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
973 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
974 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
976 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
977 WGC3Denum)
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