Add a function to create a bookmark app from a WebApplicationInfo.
[chromium-blink-merge.git] / webkit / common / gpu / webgraphicscontext3d_in_process_command_buffer_impl.cc
blob3c6d608e316e4a58a10475229a2258ae19277b7b
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 "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
7 #include <GLES2/gl2.h>
8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1
10 #endif
11 #include <GLES2/gl2ext.h>
12 #include <GLES2/gl2extchromium.h>
14 #include <string>
16 #include "base/atomicops.h"
17 #include "base/bind.h"
18 #include "base/bind_helpers.h"
19 #include "base/callback.h"
20 #include "base/lazy_instance.h"
21 #include "base/logging.h"
22 #include "gpu/command_buffer/client/gl_in_process_context.h"
23 #include "gpu/command_buffer/client/gles2_implementation.h"
24 #include "gpu/command_buffer/client/gles2_lib.h"
25 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
26 #include "ui/gfx/size.h"
27 #include "ui/gl/gl_implementation.h"
29 using gpu::gles2::GLES2Implementation;
30 using gpu::GLInProcessContext;
32 namespace webkit {
33 namespace gpu {
35 namespace {
37 const int32 kCommandBufferSize = 1024 * 1024;
38 // TODO(kbr): make the transfer buffer size configurable via context
39 // creation attributes.
40 const size_t kStartTransferBufferSize = 4 * 1024 * 1024;
41 const size_t kMinTransferBufferSize = 1 * 256 * 1024;
42 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
44 uint32_t GenFlushID() {
45 static base::subtle::Atomic32 flush_id = 0;
47 base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
48 &flush_id, 1);
49 return static_cast<uint32_t>(my_id);
52 // Singleton used to initialize and terminate the gles2 library.
53 class GLES2Initializer {
54 public:
55 GLES2Initializer() {
56 ::gles2::Initialize();
59 ~GLES2Initializer() {
60 ::gles2::Terminate();
63 private:
64 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
67 static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
68 LAZY_INSTANCE_INITIALIZER;
70 } // namespace anonymous
72 // static
73 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
74 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
75 const blink::WebGraphicsContext3D::Attributes& attributes,
76 gfx::AcceleratedWidget window) {
77 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
78 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
79 scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window));
82 // static
83 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
84 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
85 const blink::WebGraphicsContext3D::Attributes& attributes) {
86 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
87 scoped_ptr< ::gpu::GLInProcessContext>(),
88 attributes,
89 true,
90 gfx::kNullAcceleratedWidget));
93 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
94 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
95 scoped_ptr< ::gpu::GLInProcessContext> context,
96 const blink::WebGraphicsContext3D::Attributes& attributes) {
97 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
98 context.Pass(),
99 attributes,
100 true /* is_offscreen. Not used. */,
101 gfx::kNullAcceleratedWidget /* window. Not used. */));
104 WebGraphicsContext3DInProcessCommandBufferImpl::
105 WebGraphicsContext3DInProcessCommandBufferImpl(
106 scoped_ptr< ::gpu::GLInProcessContext> context,
107 const blink::WebGraphicsContext3D::Attributes& attributes,
108 bool is_offscreen,
109 gfx::AcceleratedWidget window)
110 : is_offscreen_(is_offscreen),
111 window_(window),
112 initialized_(false),
113 initialize_failed_(false),
114 context_(context.Pass()),
115 gl_(NULL),
116 context_lost_callback_(NULL),
117 context_lost_reason_(GL_NO_ERROR),
118 attributes_(attributes),
119 flush_id_(0) {
122 WebGraphicsContext3DInProcessCommandBufferImpl::
123 ~WebGraphicsContext3DInProcessCommandBufferImpl() {
126 // static
127 void WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
128 const blink::WebGraphicsContext3D::Attributes& attributes,
129 ::gpu::GLInProcessContextAttribs* output_attribs) {
130 output_attribs->alpha_size = attributes.alpha ? 8 : 0;
131 output_attribs->depth_size = attributes.depth ? 24 : 0;
132 output_attribs->stencil_size = attributes.stencil ? 8 : 0;
133 output_attribs->samples = attributes.antialias ? 4 : 0;
134 output_attribs->sample_buffers = attributes.antialias ? 1 : 0;
135 output_attribs->fail_if_major_perf_caveat =
136 attributes.failIfMajorPerformanceCaveat ? 1 : 0;
139 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
140 if (initialized_)
141 return true;
143 if (initialize_failed_)
144 return false;
146 // Ensure the gles2 library is initialized first in a thread safe way.
147 g_gles2_initializer.Get();
149 if (!context_) {
150 // TODO(kbr): More work will be needed in this implementation to
151 // properly support GPU switching. Like in the out-of-process
152 // command buffer implementation, all previously created contexts
153 // will need to be lost either when the first context requesting the
154 // discrete GPU is created, or the last one is destroyed.
155 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
157 ::gpu::GLInProcessContextAttribs attrib_struct;
158 ConvertAttributes(attributes_, &attrib_struct),
160 context_.reset(GLInProcessContext::CreateContext(
161 is_offscreen_,
162 window_,
163 gfx::Size(1, 1),
164 attributes_.shareResources,
165 attrib_struct,
166 gpu_preference));
169 if (context_) {
170 base::Closure context_lost_callback = base::Bind(
171 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost,
172 base::Unretained(this));
173 context_->SetContextLostCallback(context_lost_callback);
174 } else {
175 initialize_failed_ = true;
176 return false;
179 gl_ = context_->GetImplementation();
181 if (gl_ && attributes_.noExtensions)
182 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
184 // Set attributes_ from created offscreen context.
186 GLint alpha_bits = 0;
187 getIntegerv(GL_ALPHA_BITS, &alpha_bits);
188 attributes_.alpha = alpha_bits > 0;
189 GLint depth_bits = 0;
190 getIntegerv(GL_DEPTH_BITS, &depth_bits);
191 attributes_.depth = depth_bits > 0;
192 GLint stencil_bits = 0;
193 getIntegerv(GL_STENCIL_BITS, &stencil_bits);
194 attributes_.stencil = stencil_bits > 0;
195 GLint sample_buffers = 0;
196 getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers);
197 attributes_.antialias = sample_buffers > 0;
200 initialized_ = true;
201 return true;
204 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() {
205 if (!MaybeInitializeGL())
206 return false;
207 ::gles2::SetGLContext(gl_);
208 return context_ && !isContextLost();
211 uint32_t WebGraphicsContext3DInProcessCommandBufferImpl::lastFlushID() {
212 return flush_id_;
215 void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() {
216 // NOTE: Comment in the line below to check for code that is not calling
217 // eglMakeCurrent where appropriate. The issue is code using
218 // WebGraphicsContext3D does not need to call makeContextCurrent. Code using
219 // direct OpenGL bindings needs to call the appropriate form of
220 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong
221 // context. Uncommenting the line below clears the current context so that
222 // any code not calling eglMakeCurrent in the appropriate place should crash.
223 // This is not a perfect test but generally code that used the direct OpenGL
224 // bindings should not be mixed with code that uses WebGraphicsContext3D.
226 // GLInProcessContext::MakeCurrent(NULL);
229 // Helper macros to reduce the amount of code.
231 #define DELEGATE_TO_GL(name, glname) \
232 void WebGraphicsContext3DInProcessCommandBufferImpl::name() { \
233 ClearContext(); \
234 gl_->glname(); \
237 #define DELEGATE_TO_GL_R(name, glname, rt) \
238 rt WebGraphicsContext3DInProcessCommandBufferImpl::name() { \
239 ClearContext(); \
240 return gl_->glname(); \
243 #define DELEGATE_TO_GL_1(name, glname, t1) \
244 void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \
245 ClearContext(); \
246 gl_->glname(a1); \
249 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
250 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \
251 ClearContext(); \
252 return gl_->glname(a1); \
255 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
256 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \
257 ClearContext(); \
258 return gl_->glname(a1) ? true : false; \
261 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
262 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
263 t1 a1, t2 a2) { \
264 ClearContext(); \
265 gl_->glname(a1, a2); \
268 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
269 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1, t2 a2) { \
270 ClearContext(); \
271 return gl_->glname(a1, a2); \
274 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
275 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
276 t1 a1, t2 a2, t3 a3) { \
277 ClearContext(); \
278 gl_->glname(a1, a2, a3); \
281 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
282 rt WebGraphicsContext3DInProcessCommandBufferImpl::name( \
283 t1 a1, t2 a2, t3 a3) { \
284 ClearContext(); \
285 return gl_->glname(a1, a2, a3); \
288 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
289 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
290 t1 a1, t2 a2, t3 a3, t4 a4) { \
291 ClearContext(); \
292 gl_->glname(a1, a2, a3, a4); \
295 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
296 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
297 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \
298 ClearContext(); \
299 gl_->glname(a1, a2, a3, a4, a5); \
302 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
303 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
304 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) { \
305 ClearContext(); \
306 gl_->glname(a1, a2, a3, a4, a5, a6); \
309 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
310 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
311 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) { \
312 ClearContext(); \
313 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
316 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
317 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
318 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) { \
319 ClearContext(); \
320 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
323 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
324 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \
325 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) { \
326 ClearContext(); \
327 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
330 void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() {
331 NOTREACHED();
334 void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM(
335 int x, int y, int width, int height) {
336 NOTREACHED();
339 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
341 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError(
342 WGC3Denum error) {
343 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
344 synthetic_errors_.end()) {
345 synthetic_errors_.push_back(error);
349 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM(
350 WGC3Denum target,
351 WGC3Dintptr offset,
352 WGC3Dsizeiptr size,
353 WGC3Denum access) {
354 ClearContext();
355 return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access);
358 void WebGraphicsContext3DInProcessCommandBufferImpl::unmapBufferSubDataCHROMIUM(
359 const void* mem) {
360 ClearContext();
361 return gl_->UnmapBufferSubDataCHROMIUM(mem);
364 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapTexSubImage2DCHROMIUM(
365 WGC3Denum target,
366 WGC3Dint level,
367 WGC3Dint xoffset,
368 WGC3Dint yoffset,
369 WGC3Dsizei width,
370 WGC3Dsizei height,
371 WGC3Denum format,
372 WGC3Denum type,
373 WGC3Denum access) {
374 ClearContext();
375 return gl_->MapTexSubImage2DCHROMIUM(
376 target, level, xoffset, yoffset, width, height, format, type, access);
379 void WebGraphicsContext3DInProcessCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
380 const void* mem) {
381 ClearContext();
382 gl_->UnmapTexSubImage2DCHROMIUM(mem);
385 void WebGraphicsContext3DInProcessCommandBufferImpl::setVisibilityCHROMIUM(
386 bool visible) {
389 void WebGraphicsContext3DInProcessCommandBufferImpl::discardFramebufferEXT(
390 WGC3Denum target, WGC3Dsizei numAttachments, const WGC3Denum* attachments) {
391 gl_->DiscardFramebufferEXT(target, numAttachments, attachments);
394 void WebGraphicsContext3DInProcessCommandBufferImpl::
395 copyTextureToParentTextureCHROMIUM(WebGLId texture, WebGLId parentTexture) {
396 NOTIMPLEMENTED();
399 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
400 getRequestableExtensionsCHROMIUM() {
401 // TODO(gmam): See if we can comment this in.
402 // ClearContext();
403 return blink::WebString::fromUTF8(
404 gl_->GetRequestableExtensionsCHROMIUM());
407 void WebGraphicsContext3DInProcessCommandBufferImpl::requestExtensionCHROMIUM(
408 const char* extension) {
409 // TODO(gmam): See if we can comment this in.
410 // ClearContext();
411 gl_->RequestExtensionCHROMIUM(extension);
414 void WebGraphicsContext3DInProcessCommandBufferImpl::blitFramebufferCHROMIUM(
415 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
416 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
417 WGC3Dbitfield mask, WGC3Denum filter) {
418 ClearContext();
419 gl_->BlitFramebufferCHROMIUM(
420 srcX0, srcY0, srcX1, srcY1,
421 dstX0, dstY0, dstX1, dstY1,
422 mask, filter);
425 void WebGraphicsContext3DInProcessCommandBufferImpl::
426 renderbufferStorageMultisampleCHROMIUM(
427 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
428 WGC3Dsizei width, WGC3Dsizei height) {
429 ClearContext();
430 gl_->RenderbufferStorageMultisampleCHROMIUM(
431 target, samples, internalformat, width, height);
434 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
436 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
438 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
439 WGC3Duint, const WGC3Dchar*)
441 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
443 void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer(
444 WGC3Denum target,
445 WebGLId framebuffer) {
446 ClearContext();
447 gl_->BindFramebuffer(target, framebuffer);
450 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
452 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
454 DELEGATE_TO_GL_4(blendColor, BlendColor,
455 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
457 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
459 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
460 WGC3Denum, WGC3Denum)
462 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
464 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
465 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
467 DELEGATE_TO_GL_4(bufferData, BufferData,
468 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
470 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
471 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
473 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
474 WGC3Denum, WGC3Denum)
476 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
478 DELEGATE_TO_GL_4(clearColor, ClearColor,
479 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
481 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
483 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
485 DELEGATE_TO_GL_4(colorMask, ColorMask,
486 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
488 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
490 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
491 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
492 WGC3Dsizei, WGC3Dsizei, const void*)
494 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
495 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
496 WGC3Denum, WGC3Dsizei, const void*)
498 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
499 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
500 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
502 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
503 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
504 WGC3Dsizei, WGC3Dsizei)
506 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
508 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
510 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
512 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
514 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
516 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
518 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
519 WGC3Duint)
521 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
523 void WebGraphicsContext3DInProcessCommandBufferImpl::drawElements(
524 WGC3Denum mode,
525 WGC3Dsizei count,
526 WGC3Denum type,
527 WGC3Dintptr offset) {
528 ClearContext();
529 gl_->DrawElements(
530 mode, count, type,
531 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
534 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
536 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
537 WGC3Duint)
539 void WebGraphicsContext3DInProcessCommandBufferImpl::finish() {
540 flush_id_ = GenFlushID();
541 gl_->Finish();
544 void WebGraphicsContext3DInProcessCommandBufferImpl::flush() {
545 flush_id_ = GenFlushID();
546 gl_->Flush();
549 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
550 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
552 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
553 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
555 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
557 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
559 bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveAttrib(
560 WebGLId program, WGC3Duint index, ActiveInfo& info) {
561 ClearContext();
562 if (!program) {
563 synthesizeGLError(GL_INVALID_VALUE);
564 return false;
566 GLint max_name_length = -1;
567 gl_->GetProgramiv(
568 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
569 if (max_name_length < 0)
570 return false;
571 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
572 if (!name) {
573 synthesizeGLError(GL_OUT_OF_MEMORY);
574 return false;
576 GLsizei length = 0;
577 GLint size = -1;
578 GLenum type = 0;
579 gl_->GetActiveAttrib(
580 program, index, max_name_length, &length, &size, &type, name.get());
581 if (size < 0) {
582 return false;
584 info.name = blink::WebString::fromUTF8(name.get(), length);
585 info.type = type;
586 info.size = size;
587 return true;
590 bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveUniform(
591 WebGLId program, WGC3Duint index, ActiveInfo& info) {
592 ClearContext();
593 GLint max_name_length = -1;
594 gl_->GetProgramiv(
595 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
596 if (max_name_length < 0)
597 return false;
598 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
599 if (!name) {
600 synthesizeGLError(GL_OUT_OF_MEMORY);
601 return false;
603 GLsizei length = 0;
604 GLint size = -1;
605 GLenum type = 0;
606 gl_->GetActiveUniform(
607 program, index, max_name_length, &length, &size, &type, name.get());
608 if (size < 0) {
609 return false;
611 info.name = blink::WebString::fromUTF8(name.get(), length);
612 info.type = type;
613 info.size = size;
614 return true;
617 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
618 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
620 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
621 WebGLId, const WGC3Dchar*, WGC3Dint)
623 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
625 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
626 WGC3Denum, WGC3Denum, WGC3Dint*)
628 blink::WebGraphicsContext3D::Attributes
629 WebGraphicsContext3DInProcessCommandBufferImpl::getContextAttributes() {
630 return attributes_;
633 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::getError() {
634 ClearContext();
635 if (!synthetic_errors_.empty()) {
636 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
637 WGC3Denum err = *iter;
638 synthetic_errors_.erase(iter);
639 return err;
642 return gl_->GetError();
645 bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() {
646 return context_lost_reason_ != GL_NO_ERROR;
649 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
651 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
652 GetFramebufferAttachmentParameteriv,
653 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
655 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
657 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
659 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
660 getProgramInfoLog(WebGLId program) {
661 ClearContext();
662 GLint logLength = 0;
663 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
664 if (!logLength)
665 return blink::WebString();
666 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
667 if (!log)
668 return blink::WebString();
669 GLsizei returnedLogLength = 0;
670 gl_->GetProgramInfoLog(
671 program, logLength, &returnedLogLength, log.get());
672 DCHECK_EQ(logLength, returnedLogLength + 1);
673 blink::WebString res =
674 blink::WebString::fromUTF8(log.get(), returnedLogLength);
675 return res;
678 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
679 WGC3Denum, WGC3Denum, WGC3Dint*)
681 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
683 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
684 getShaderInfoLog(WebGLId shader) {
685 ClearContext();
686 GLint logLength = 0;
687 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
688 if (!logLength)
689 return blink::WebString();
690 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
691 if (!log)
692 return blink::WebString();
693 GLsizei returnedLogLength = 0;
694 gl_->GetShaderInfoLog(
695 shader, logLength, &returnedLogLength, log.get());
696 DCHECK_EQ(logLength, returnedLogLength + 1);
697 blink::WebString res =
698 blink::WebString::fromUTF8(log.get(), returnedLogLength);
699 return res;
702 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
703 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
705 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
706 getShaderSource(WebGLId shader) {
707 ClearContext();
708 GLint logLength = 0;
709 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
710 if (!logLength)
711 return blink::WebString();
712 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
713 if (!log)
714 return blink::WebString();
715 GLsizei returnedLogLength = 0;
716 gl_->GetShaderSource(
717 shader, logLength, &returnedLogLength, log.get());
718 if (!returnedLogLength)
719 return blink::WebString();
720 DCHECK_EQ(logLength, returnedLogLength + 1);
721 blink::WebString res =
722 blink::WebString::fromUTF8(log.get(), returnedLogLength);
723 return res;
726 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::
727 getTranslatedShaderSourceANGLE(WebGLId shader) {
728 ClearContext();
729 GLint logLength = 0;
730 gl_->GetShaderiv(
731 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
732 if (!logLength)
733 return blink::WebString();
734 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
735 if (!log)
736 return blink::WebString();
737 GLsizei returnedLogLength = 0;
738 gl_->GetTranslatedShaderSourceANGLE(
739 shader, logLength, &returnedLogLength, log.get());
740 if (!returnedLogLength)
741 return blink::WebString();
742 DCHECK_EQ(logLength, returnedLogLength + 1);
743 blink::WebString res =
744 blink::WebString::fromUTF8(log.get(), returnedLogLength);
745 return res;
748 blink::WebString WebGraphicsContext3DInProcessCommandBufferImpl::getString(
749 WGC3Denum name) {
750 ClearContext();
751 return blink::WebString::fromUTF8(
752 reinterpret_cast<const char*>(gl_->GetString(name)));
755 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
756 WGC3Denum, WGC3Denum, WGC3Dfloat*)
758 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
759 WGC3Denum, WGC3Denum, WGC3Dint*)
761 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
763 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
765 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
766 WebGLId, const WGC3Dchar*, WGC3Dint)
768 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
769 WGC3Duint, WGC3Denum, WGC3Dfloat*)
771 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
772 WGC3Duint, WGC3Denum, WGC3Dint*)
774 WGC3Dsizeiptr WebGraphicsContext3DInProcessCommandBufferImpl::
775 getVertexAttribOffset(WGC3Duint index, WGC3Denum pname) {
776 ClearContext();
777 GLvoid* value = NULL;
778 // NOTE: If pname is ever a value that returns more then 1 element
779 // this will corrupt memory.
780 gl_->GetVertexAttribPointerv(index, pname, &value);
781 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
784 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
786 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
788 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
790 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
792 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
794 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
796 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
798 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
800 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
802 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
804 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
806 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
808 DELEGATE_TO_GL_7(readPixels, ReadPixels,
809 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
810 WGC3Denum, void*)
812 void WebGraphicsContext3DInProcessCommandBufferImpl::releaseShaderCompiler() {
813 ClearContext();
816 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
817 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
819 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
821 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
823 void WebGraphicsContext3DInProcessCommandBufferImpl::shaderSource(
824 WebGLId shader, const WGC3Dchar* string) {
825 ClearContext();
826 GLint length = strlen(string);
827 gl_->ShaderSource(shader, 1, &string, &length);
830 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
832 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
833 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
835 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
837 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
838 WGC3Denum, WGC3Duint)
840 DELEGATE_TO_GL_3(stencilOp, StencilOp,
841 WGC3Denum, WGC3Denum, WGC3Denum)
843 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
844 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
846 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
847 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
848 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
850 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
851 WGC3Denum, WGC3Denum, WGC3Dfloat);
853 static const unsigned int kTextureWrapR = 0x8072;
855 void WebGraphicsContext3DInProcessCommandBufferImpl::texParameteri(
856 WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
857 ClearContext();
858 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
859 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
860 // edge of cube maps, and, if it is, push it into the GLES2 service
861 // side code.
862 if (pname == kTextureWrapR) {
863 return;
865 gl_->TexParameteri(target, pname, param);
868 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
869 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
870 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
872 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
874 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
875 const WGC3Dfloat*)
877 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
879 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
881 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
883 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
884 const WGC3Dfloat*)
886 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
888 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
890 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
891 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
893 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
894 const WGC3Dfloat*)
896 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
898 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
900 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
901 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
903 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
904 const WGC3Dfloat*)
906 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
907 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
909 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
911 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
912 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
914 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
915 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
917 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
918 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
920 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
922 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
924 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
926 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
927 const WGC3Dfloat*)
929 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
930 WGC3Dfloat, WGC3Dfloat)
932 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
933 const WGC3Dfloat*)
935 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
936 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
938 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
939 const WGC3Dfloat*)
941 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
942 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
944 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
945 const WGC3Dfloat*)
947 void WebGraphicsContext3DInProcessCommandBufferImpl::vertexAttribPointer(
948 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
949 WGC3Dsizei stride, WGC3Dintptr offset) {
950 ClearContext();
951 gl_->VertexAttribPointer(
952 index, size, type, normalized, stride,
953 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
956 DELEGATE_TO_GL_4(viewport, Viewport,
957 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
959 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
961 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
963 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
965 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
967 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
969 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
971 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
972 WebGLId*);
974 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
976 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createBuffer() {
977 ClearContext();
978 GLuint o;
979 gl_->GenBuffers(1, &o);
980 return o;
983 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createFramebuffer() {
984 ClearContext();
985 GLuint o = 0;
986 gl_->GenFramebuffers(1, &o);
987 return o;
990 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createRenderbuffer() {
991 ClearContext();
992 GLuint o;
993 gl_->GenRenderbuffers(1, &o);
994 return o;
997 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() {
998 ClearContext();
999 GLuint o;
1000 gl_->GenTextures(1, &o);
1001 return o;
1004 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer(
1005 WebGLId buffer) {
1006 ClearContext();
1007 gl_->DeleteBuffers(1, &buffer);
1010 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer(
1011 WebGLId framebuffer) {
1012 ClearContext();
1013 gl_->DeleteFramebuffers(1, &framebuffer);
1016 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer(
1017 WebGLId renderbuffer) {
1018 ClearContext();
1019 gl_->DeleteRenderbuffers(1, &renderbuffer);
1022 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteTexture(
1023 WebGLId texture) {
1024 ClearContext();
1025 gl_->DeleteTextures(1, &texture);
1028 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId);
1030 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId);
1032 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId);
1034 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId);
1036 void WebGraphicsContext3DInProcessCommandBufferImpl::setContextLostCallback(
1037 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
1038 context_lost_callback_ = cb;
1041 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::
1042 getGraphicsResetStatusARB() {
1043 return context_lost_reason_;
1046 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
1047 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
1049 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
1050 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
1052 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createQueryEXT() {
1053 GLuint o;
1054 gl_->GenQueriesEXT(1, &o);
1055 return o;
1058 void WebGraphicsContext3DInProcessCommandBufferImpl::
1059 deleteQueryEXT(WebGLId query) {
1060 gl_->DeleteQueriesEXT(1, &query);
1063 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
1064 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
1065 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
1066 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
1067 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
1068 WebGLId, WGC3Denum, WGC3Duint*)
1070 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum, WGC3Duint,
1071 WGC3Duint, WGC3Dint, WGC3Denum, WGC3Denum)
1073 void WebGraphicsContext3DInProcessCommandBufferImpl::insertEventMarkerEXT(
1074 const WGC3Dchar* marker) {
1075 gl_->InsertEventMarkerEXT(0, marker);
1078 void WebGraphicsContext3DInProcessCommandBufferImpl::pushGroupMarkerEXT(
1079 const WGC3Dchar* marker) {
1080 gl_->PushGroupMarkerEXT(0, marker);
1083 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
1085 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
1086 WGC3Denum, WGC3Dint)
1087 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
1088 WGC3Denum, WGC3Dint)
1090 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferCHROMIUM(
1091 WGC3Denum target, WGC3Denum access) {
1092 ClearContext();
1093 return gl_->MapBufferCHROMIUM(target, access);
1096 WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl::
1097 unmapBufferCHROMIUM(WGC3Denum target) {
1098 ClearContext();
1099 return gl_->UnmapBufferCHROMIUM(target);
1102 GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl::
1103 createGrGLInterface() {
1104 makeContextCurrent();
1105 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1108 ::gpu::gles2::GLES2Interface*
1109 WebGraphicsContext3DInProcessCommandBufferImpl::GetGLInterface() {
1110 return gl_;
1113 ::gpu::ContextSupport*
1114 WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() {
1115 return gl_;
1118 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
1119 // TODO(kbr): improve the precision here.
1120 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
1121 if (context_lost_callback_) {
1122 context_lost_callback_->onContextLost();
1126 DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM,
1127 WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Duint);
1129 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
1131 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM,
1132 WGC3Duint, WGC3Denum, GLint*);
1134 DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM,
1135 WGC3Duint, WGC3Denum, void*);
1137 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
1139 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
1140 FramebufferTexture2DMultisampleEXT,
1141 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1143 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1144 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1145 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1147 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1148 WebGLId, WGC3Dint, const WGC3Dchar*)
1150 void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFlushCHROMIUM() {
1151 flush_id_ = GenFlushID();
1152 gl_->ShallowFlushCHROMIUM();
1155 void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFinishCHROMIUM() {
1156 flush_id_ = GenFlushID();
1157 gl_->ShallowFinishCHROMIUM();
1160 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1161 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1162 WGC3Denum, const WGC3Dbyte*)
1163 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1164 WGC3Denum, const WGC3Dbyte*)
1166 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT,
1167 WGC3Dsizei, const WGC3Denum*)
1169 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned)
1171 void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM(
1172 WGC3Denum current, WGC3Denum other) {
1173 gl_->LoseContextCHROMIUM(current, other);
1174 gl_->ShallowFlushCHROMIUM();
1177 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM,
1178 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
1179 WGC3Denum, WGC3Denum, const void*)
1181 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1182 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1183 WGC3Denum, WGC3Denum, const void*)
1185 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1186 WGC3Denum)
1188 } // namespace gpu
1189 } // namespace webkit