Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / gpu / blink / webgraphicscontext3d_impl.cc
blob8fe23ee54933ca82336732698457a16aa95e2d34
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_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
971 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
972 WGC3Dint, WGC3Dsizei, WGC3Dsizei)
974 void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
975 WGC3Denum mode,
976 WGC3Dsizei count,
977 WGC3Denum type,
978 WGC3Dintptr offset,
979 WGC3Dsizei primcount) {
980 gl_->DrawElementsInstancedANGLE(
981 mode, count, type,
982 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
985 DELEGATE_TO_GL_2(vertexAttribDivisorANGLE, VertexAttribDivisorANGLE, WGC3Duint,
986 WGC3Duint)
988 DELEGATE_TO_GL_4R(createGpuMemoryBufferImageCHROMIUM,
989 CreateGpuMemoryBufferImageCHROMIUM,
990 WGC3Dsizei,
991 WGC3Dsizei,
992 WGC3Denum,
993 WGC3Denum,
994 WGC3Duint);
996 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
998 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
999 FramebufferTexture2DMultisampleEXT,
1000 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1002 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1003 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1004 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1006 DELEGATE_TO_GL_1(beginTransformFeedback, BeginTransformFeedback, WGC3Denum)
1007 DELEGATE_TO_GL_3(bindBufferBase, BindBufferBase, WGC3Denum, WGC3Duint,
1008 WGC3Duint)
1009 DELEGATE_TO_GL_5(bindBufferRange, BindBufferRange, WGC3Denum, WGC3Duint,
1010 WGC3Duint, WGC3Dintptr, WGC3Dsizeiptr)
1011 DELEGATE_TO_GL_2(bindSampler, BindSampler, WGC3Duint, WebGLId)
1012 DELEGATE_TO_GL_2(bindTransformFeedback, BindTransformFeedback, WGC3Denum,
1013 WebGLId)
1014 DELEGATE_TO_GL_4(clearBufferfi, ClearBufferfi, WGC3Denum, WGC3Dint, WGC3Dfloat,
1015 WGC3Dint)
1016 DELEGATE_TO_GL_3(clearBufferfv, ClearBufferfv, WGC3Denum, WGC3Dint,
1017 const WGC3Dfloat *)
1018 DELEGATE_TO_GL_3(clearBufferiv, ClearBufferiv, WGC3Denum, WGC3Dint,
1019 const WGC3Dint *)
1020 DELEGATE_TO_GL_3(clearBufferuiv, ClearBufferuiv, WGC3Denum, WGC3Dint,
1021 const WGC3Duint *)
1022 WGC3Denum WebGraphicsContext3DImpl::clientWaitSync(WGC3Dsync sync,
1023 WGC3Dbitfield flags,
1024 WGC3Duint64 timeout) {
1025 return gl_->ClientWaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1027 DELEGATE_TO_GL_9(compressedTexImage3D, CompressedTexImage3D, WGC3Denum,
1028 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1029 WGC3Dint, WGC3Dsizei, const void *)
1030 DELEGATE_TO_GL_11(compressedTexSubImage3D, CompressedTexSubImage3D, WGC3Denum,
1031 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1032 WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Dsizei, const void *)
1033 DELEGATE_TO_GL_5(copyBufferSubData, CopyBufferSubData, WGC3Denum, WGC3Denum,
1034 WGC3Dintptr, WGC3Dintptr, WGC3Dsizeiptr)
1035 DELEGATE_TO_GL_9(copyTexSubImage3D, CopyTexSubImage3D, WGC3Denum, WGC3Dint,
1036 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1037 WGC3Dsizei)
1038 WebGLId WebGraphicsContext3DImpl::createSampler() {
1039 GLuint sampler;
1040 gl_->GenSamplers(1, &sampler);
1041 return sampler;
1043 WebGLId WebGraphicsContext3DImpl::createTransformFeedback() {
1044 GLuint tf;
1045 gl_->GenTransformFeedbacks(1, &tf);
1046 return tf;
1048 void WebGraphicsContext3DImpl::deleteSampler(WebGLId sampler) {
1049 gl_->DeleteSamplers(1, &sampler);
1051 void WebGraphicsContext3DImpl::deleteSync(WGC3Dsync sync) {
1052 gl_->DeleteSync(reinterpret_cast<GLsync>(sync));
1054 void WebGraphicsContext3DImpl::deleteTransformFeedback(WebGLId tf) {
1055 gl_->DeleteTransformFeedbacks(1, &tf);
1057 void WebGraphicsContext3DImpl::drawRangeElements(
1058 WGC3Denum mode, WGC3Duint start, WGC3Duint end, WGC3Dsizei count,
1059 WGC3Denum type, WGC3Dintptr offset) {
1060 gl_->DrawRangeElements(mode, start, end, count, type,
1061 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1063 DELEGATE_TO_GL(endTransformFeedback, EndTransformFeedback)
1064 WGC3Dsync WebGraphicsContext3DImpl::fenceSync(WGC3Denum condition,
1065 WGC3Dbitfield flags) {
1066 return reinterpret_cast<WGC3Dsync>(gl_->FenceSync(condition, flags));
1068 DELEGATE_TO_GL_5(framebufferTextureLayer, FramebufferTextureLayer, WGC3Denum,
1069 WGC3Denum, WGC3Duint, WGC3Dint, WGC3Dint)
1070 DELEGATE_TO_GL_5(getActiveUniformBlockName, GetActiveUniformBlockName,
1071 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dchar *)
1072 DELEGATE_TO_GL_4(getActiveUniformBlockiv, GetActiveUniformBlockiv, WGC3Duint,
1073 WGC3Duint, WGC3Denum, WGC3Dint *)
1074 DELEGATE_TO_GL_5(getActiveUniformsiv, GetActiveUniformsiv, WGC3Duint,
1075 WGC3Dsizei, const WGC3Duint *, WGC3Denum, WGC3Dint *)
1076 DELEGATE_TO_GL_2R(getFragDataLocation, GetFragDataLocation, WGC3Duint,
1077 const WGC3Dchar *, WGC3Dint)
1078 DELEGATE_TO_GL_5(getInternalformativ, GetInternalformativ, WGC3Denum, WGC3Denum,
1079 WGC3Denum, WGC3Dsizei, WGC3Dint *)
1080 DELEGATE_TO_GL_3(getSamplerParameterfv, GetSamplerParameterfv, WGC3Duint,
1081 WGC3Denum, WGC3Dfloat *)
1082 DELEGATE_TO_GL_3(getSamplerParameteriv, GetSamplerParameteriv, WGC3Duint,
1083 WGC3Denum, WGC3Dint *)
1084 DELEGATE_TO_GL_7(getTransformFeedbackVarying, GetTransformFeedbackVarying,
1085 WGC3Duint, WGC3Duint, WGC3Dsizei, WGC3Dsizei *, WGC3Dsizei *,
1086 WGC3Denum *, WGC3Dchar *)
1087 DELEGATE_TO_GL_2R(getUniformBlockIndex, GetUniformBlockIndex, WGC3Duint,
1088 const WGC3Dchar *, WGC3Duint)
1089 DELEGATE_TO_GL_4(getUniformIndices, GetUniformIndices, WGC3Duint, WGC3Dsizei,
1090 const WGC3Dchar *const*, WGC3Duint *)
1091 DELEGATE_TO_GL_3(getUniformuiv, GetUniformuiv, WGC3Duint, WGC3Dint,
1092 WGC3Duint *)
1093 DELEGATE_TO_GL_3(getVertexAttribIiv, GetVertexAttribIiv, WGC3Duint,
1094 WGC3Denum, WGC3Dint *)
1095 DELEGATE_TO_GL_3(getVertexAttribIuiv, GetVertexAttribIuiv, WGC3Duint,
1096 WGC3Denum, WGC3Duint *)
1097 DELEGATE_TO_GL_3(invalidateFramebuffer, InvalidateFramebuffer, WGC3Denum,
1098 WGC3Dsizei, const WGC3Denum *)
1099 DELEGATE_TO_GL_7(invalidateSubFramebuffer, InvalidateSubFramebuffer, WGC3Denum,
1100 WGC3Dsizei, const WGC3Denum *, WGC3Dint, WGC3Dint, WGC3Dsizei,
1101 WGC3Dsizei)
1102 DELEGATE_TO_GL_1R(isSampler, IsSampler, WebGLId, WGC3Dboolean)
1103 WGC3Dboolean WebGraphicsContext3DImpl::isSync(WGC3Dsync sync) {
1104 return gl_->IsSync(reinterpret_cast<GLsync>(sync));
1106 DELEGATE_TO_GL_1R(isTransformFeedback, IsTransformFeedback, WGC3Duint,
1107 WGC3Dboolean)
1108 DELEGATE_TO_GL_4R(mapBufferRange, MapBufferRange, WGC3Denum, WGC3Dintptr,
1109 WGC3Dsizeiptr, WGC3Dbitfield, void*);
1110 DELEGATE_TO_GL(pauseTransformFeedback, PauseTransformFeedback)
1111 //DELEGATE_TO_GL_3(programParameteri, ProgramParameteri, WGC3Duint, WGC3Denum,
1112 // WGC3Dint)
1113 DELEGATE_TO_GL_1(readBuffer, ReadBuffer, WGC3Denum)
1114 DELEGATE_TO_GL(resumeTransformFeedback, ResumeTransformFeedback)
1115 DELEGATE_TO_GL_3(samplerParameterf, SamplerParameterf, WGC3Duint, WGC3Denum,
1116 WGC3Dfloat)
1117 DELEGATE_TO_GL_3(samplerParameterfv, SamplerParameterfv, WGC3Duint, WGC3Denum,
1118 const WGC3Dfloat *)
1119 DELEGATE_TO_GL_3(samplerParameteri, SamplerParameteri, WGC3Duint, WGC3Denum,
1120 WGC3Dint)
1121 DELEGATE_TO_GL_3(samplerParameteriv, SamplerParameteriv, WGC3Duint, WGC3Denum,
1122 const WGC3Dint *)
1123 DELEGATE_TO_GL_10(texImage3D, TexImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1124 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei, WGC3Dint, WGC3Denum,
1125 WGC3Denum, const void *)
1126 DELEGATE_TO_GL_6(texStorage3D, TexStorage3D, WGC3Denum, WGC3Dsizei, WGC3Denum,
1127 WGC3Dsizei, WGC3Dsizei, WGC3Dsizei)
1128 DELEGATE_TO_GL_11(texSubImage3D, TexSubImage3D, WGC3Denum, WGC3Dint, WGC3Dint,
1129 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Dsizei,
1130 WGC3Denum, WGC3Denum, const void *)
1131 DELEGATE_TO_GL_4(transformFeedbackVaryings, TransformFeedbackVaryings,
1132 WGC3Duint, WGC3Dsizei, const WGC3Dchar *const*, WGC3Denum)
1133 DELEGATE_TO_GL_2(uniform1ui, Uniform1ui, WGC3Dint, WGC3Duint)
1134 DELEGATE_TO_GL_3(uniform1uiv, Uniform1uiv, WGC3Dint, WGC3Dsizei,
1135 const WGC3Duint *)
1136 DELEGATE_TO_GL_3(uniform2ui, Uniform2ui, WGC3Dint, WGC3Duint, WGC3Duint)
1137 DELEGATE_TO_GL_3(uniform2uiv, Uniform2uiv, WGC3Dint, WGC3Dsizei,
1138 const WGC3Duint *)
1139 DELEGATE_TO_GL_4(uniform3ui, Uniform3ui, WGC3Dint, WGC3Duint, WGC3Duint,
1140 WGC3Duint)
1141 DELEGATE_TO_GL_3(uniform3uiv, Uniform3uiv, WGC3Dint, WGC3Dsizei,
1142 const WGC3Duint *)
1143 DELEGATE_TO_GL_5(uniform4ui, Uniform4ui, WGC3Dint, WGC3Duint, WGC3Duint,
1144 WGC3Duint, WGC3Duint)
1145 DELEGATE_TO_GL_3(uniform4uiv, Uniform4uiv, WGC3Dint, WGC3Dsizei,
1146 const WGC3Duint *)
1147 DELEGATE_TO_GL_3(uniformBlockBinding, UniformBlockBinding, WGC3Duint, WGC3Duint,
1148 WGC3Duint)
1149 DELEGATE_TO_GL_4(uniformMatrix2x3fv, UniformMatrix2x3fv, WGC3Dint, WGC3Dsizei,
1150 WGC3Dboolean, const WGC3Dfloat*)
1151 DELEGATE_TO_GL_4(uniformMatrix2x4fv, UniformMatrix2x4fv, WGC3Dint, WGC3Dsizei,
1152 WGC3Dboolean, const WGC3Dfloat*)
1153 DELEGATE_TO_GL_4(uniformMatrix3x2fv, UniformMatrix3x2fv, WGC3Dint, WGC3Dsizei,
1154 WGC3Dboolean, const WGC3Dfloat*)
1155 DELEGATE_TO_GL_4(uniformMatrix3x4fv, UniformMatrix3x4fv, WGC3Dint, WGC3Dsizei,
1156 WGC3Dboolean, const WGC3Dfloat*)
1157 DELEGATE_TO_GL_4(uniformMatrix4x2fv, UniformMatrix4x2fv, WGC3Dint, WGC3Dsizei,
1158 WGC3Dboolean, const WGC3Dfloat*)
1159 DELEGATE_TO_GL_4(uniformMatrix4x3fv, UniformMatrix4x3fv, WGC3Dint, WGC3Dsizei,
1160 WGC3Dboolean, const WGC3Dfloat*)
1161 DELEGATE_TO_GL_1R(unmapBuffer, UnmapBuffer, WGC3Denum, WGC3Dboolean);
1162 DELEGATE_TO_GL_5(vertexAttribI4i, VertexAttribI4i, WGC3Duint, WGC3Dint,
1163 WGC3Dint, WGC3Dint, WGC3Dint)
1164 DELEGATE_TO_GL_2(vertexAttribI4iv, VertexAttribI4iv, WGC3Duint,
1165 const WGC3Dint *)
1166 DELEGATE_TO_GL_5(vertexAttribI4ui, VertexAttribI4ui, WGC3Duint, WGC3Duint,
1167 WGC3Duint, WGC3Duint, WGC3Duint)
1168 DELEGATE_TO_GL_2(vertexAttribI4uiv, VertexAttribI4uiv, WGC3Duint,
1169 const WGC3Duint *)
1170 void WebGraphicsContext3DImpl::vertexAttribIPointer(
1171 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dsizei stride,
1172 WGC3Dintptr offset) {
1173 gl_->VertexAttribIPointer(
1174 index, size, type, stride,
1175 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1177 void WebGraphicsContext3DImpl::waitSync(WGC3Dsync sync,
1178 WGC3Dbitfield flags,
1179 WGC3Duint64 timeout) {
1180 gl_->WaitSync(reinterpret_cast<GLsync>(sync), flags, timeout);
1183 bool WebGraphicsContext3DImpl::isContextLost() {
1184 return getGraphicsResetStatusARB() != GL_NO_ERROR;
1187 blink::WGC3Denum WebGraphicsContext3DImpl::getGraphicsResetStatusARB() {
1188 return gl_->GetGraphicsResetStatusKHR();
1191 GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
1192 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1195 ::gpu::gles2::GLES2ImplementationErrorMessageCallback*
1196 WebGraphicsContext3DImpl::getErrorMessageCallback() {
1197 if (!client_error_message_callback_) {
1198 client_error_message_callback_.reset(
1199 new WebGraphicsContext3DErrorMessageCallback(this));
1201 return client_error_message_callback_.get();
1204 void WebGraphicsContext3DImpl::OnErrorMessage(
1205 const std::string& message, int id) {
1206 if (error_message_callback_) {
1207 blink::WebString str = blink::WebString::fromUTF8(message.c_str());
1208 error_message_callback_->onErrorMessage(str, id);
1212 // TODO(bajones): Look into removing these functions from the blink interface
1213 void WebGraphicsContext3DImpl::prepareTexture() {
1214 NOTREACHED();
1217 void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
1218 int x, int y, int width, int height) {
1219 NOTREACHED();
1222 void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
1223 bool visible) {
1224 NOTREACHED();
1227 void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
1228 WebGLId texture, WebGLId parentTexture) {
1229 NOTIMPLEMENTED();
1232 void WebGraphicsContext3DImpl::releaseShaderCompiler() {
1235 // static
1236 void WebGraphicsContext3DImpl::ConvertAttributes(
1237 const blink::WebGraphicsContext3D::Attributes& attributes,
1238 ::gpu::gles2::ContextCreationAttribHelper* output_attribs) {
1239 output_attribs->alpha_size = attributes.alpha ? 8 : 0;
1240 output_attribs->depth_size = attributes.depth ? 24 : 0;
1241 output_attribs->stencil_size = attributes.stencil ? 8 : 0;
1242 output_attribs->samples = attributes.antialias ? 4 : 0;
1243 output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
1244 output_attribs->fail_if_major_perf_caveat =
1245 attributes.failIfMajorPerformanceCaveat;
1246 output_attribs->bind_generates_resource = false;
1247 output_attribs->webgl_version = attributes.webGLVersion;
1250 } // namespace gpu_blink