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 "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
7 #include "third_party/khronos/GLES2/gl2.h"
8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1
11 #include "third_party/khronos/GLES2/gl2ext.h"
16 #include "base/atomicops.h"
17 #include "base/bind.h"
18 #include "base/command_line.h"
19 #include "base/debug/trace_event.h"
20 #include "base/lazy_instance.h"
21 #include "base/logging.h"
22 #include "base/message_loop/message_loop.h"
23 #include "base/metrics/field_trial.h"
24 #include "base/metrics/histogram.h"
25 #include "base/synchronization/lock.h"
26 #include "content/common/gpu/client/gpu_channel_host.h"
27 #include "content/public/common/content_constants.h"
28 #include "content/public/common/content_switches.h"
29 #include "gpu/GLES2/gl2extchromium.h"
30 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
31 #include "gpu/command_buffer/client/gles2_implementation.h"
32 #include "gpu/command_buffer/client/gles2_lib.h"
33 #include "gpu/command_buffer/client/gles2_trace_implementation.h"
34 #include "gpu/command_buffer/client/transfer_buffer.h"
35 #include "gpu/command_buffer/common/constants.h"
36 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
37 #include "gpu/command_buffer/common/mailbox.h"
38 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
39 #include "third_party/skia/include/core/SkTypes.h"
45 static base::LazyInstance<base::Lock>::Leaky
46 g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER;
48 typedef std::multimap<GpuChannelHost*, WebGraphicsContext3DCommandBufferImpl*>
50 static base::LazyInstance<ContextMap> g_all_shared_contexts =
51 LAZY_INSTANCE_INITIALIZER;
53 uint32_t GenFlushID() {
54 static base::subtle::Atomic32 flush_id = 0;
56 base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
58 return static_cast<uint32_t>(my_id);
61 // Singleton used to initialize and terminate the gles2 library.
62 class GLES2Initializer {
73 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
76 ////////////////////////////////////////////////////////////////////////////////
78 base::LazyInstance<GLES2Initializer> g_gles2_initializer =
79 LAZY_INSTANCE_INITIALIZER;
81 ////////////////////////////////////////////////////////////////////////////////
83 } // namespace anonymous
85 // Helper macros to reduce the amount of code.
87 #define DELEGATE_TO_GL(name, glname) \
88 void WebGraphicsContext3DCommandBufferImpl::name() { \
92 #define DELEGATE_TO_GL_R(name, glname, rt) \
93 rt WebGraphicsContext3DCommandBufferImpl::name() { \
94 return gl_->glname(); \
97 #define DELEGATE_TO_GL_1(name, glname, t1) \
98 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
102 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
103 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
104 return gl_->glname(a1); \
107 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
108 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
109 return gl_->glname(a1) ? true : false; \
112 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
113 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
114 gl_->glname(a1, a2); \
117 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
118 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
119 return gl_->glname(a1, a2); \
122 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
123 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
124 gl_->glname(a1, a2, a3); \
127 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
128 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
129 return gl_->glname(a1, a2, a3); \
132 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
133 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
135 gl_->glname(a1, a2, a3, a4); \
138 #define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt) \
139 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
141 return gl_->glname(a1, a2, a3, a4); \
144 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
145 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
147 gl_->glname(a1, a2, a3, a4, a5); \
150 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
151 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
152 t4 a4, t5 a5, t6 a6) { \
153 gl_->glname(a1, a2, a3, a4, a5, a6); \
156 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
157 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
158 t4 a4, t5 a5, t6 a6, \
160 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
163 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
164 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
165 t4 a4, t5 a5, t6 a6, \
167 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
170 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
171 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
172 t4 a4, t5 a5, t6 a6, \
173 t7 a7, t8 a8, t9 a9) { \
174 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
177 class WebGraphicsContext3DErrorMessageCallback
178 : public gpu::gles2::GLES2Implementation::ErrorMessageCallback {
180 WebGraphicsContext3DErrorMessageCallback(
181 WebGraphicsContext3DCommandBufferImpl* context)
182 : graphics_context_(context) {
185 virtual void OnErrorMessage(const char* msg, int id) OVERRIDE;
188 WebGraphicsContext3DCommandBufferImpl* graphics_context_;
190 DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
193 void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
194 const char* msg, int id) {
195 graphics_context_->OnErrorMessage(msg, id);
198 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits::SharedMemoryLimits()
199 : command_buffer_size(kDefaultCommandBufferSize),
200 start_transfer_buffer_size(kDefaultStartTransferBufferSize),
201 min_transfer_buffer_size(kDefaultMinTransferBufferSize),
202 max_transfer_buffer_size(kDefaultMaxTransferBufferSize),
203 mapped_memory_reclaim_limit(gpu::gles2::GLES2Implementation::kNoLimit) {}
205 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
207 const GURL& active_url,
208 GpuChannelHost* host,
209 const Attributes& attributes,
210 bool bind_generates_resources,
211 const SharedMemoryLimits& limits)
212 : initialize_failed_(false),
215 surface_id_(surface_id),
216 active_url_(active_url),
217 context_lost_callback_(0),
218 context_lost_reason_(GL_NO_ERROR),
219 error_message_callback_(0),
220 attributes_(attributes),
221 gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu
222 : gfx::PreferIntegratedGpu),
223 weak_ptr_factory_(this),
226 bind_generates_resources_(bind_generates_resources),
231 WebGraphicsContext3DCommandBufferImpl::
232 ~WebGraphicsContext3DCommandBufferImpl() {
234 real_gl_->SetErrorMessageCallback(NULL);
240 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
244 if (initialize_failed_)
247 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL");
249 if (!CreateContext(surface_id_ != 0)) {
251 initialize_failed_ = true;
255 // TODO(twiz): This code is too fragile in that it assumes that only WebGL
256 // contexts will request noExtensions.
257 if (gl_ && attributes_.noExtensions)
258 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
260 command_buffer_->SetChannelErrorCallback(
261 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost,
262 weak_ptr_factory_.GetWeakPtr()));
264 command_buffer_->SetOnConsoleMessageCallback(
265 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage,
266 weak_ptr_factory_.GetWeakPtr()));
268 client_error_message_callback_.reset(
269 new WebGraphicsContext3DErrorMessageCallback(this));
270 real_gl_->SetErrorMessageCallback(client_error_message_callback_.get());
272 // Set attributes_ from created offscreen context.
274 static const int pcount = 4;
275 static const GLenum pnames[pcount] = {
281 GLint pvalues[pcount] = { 0, 0, 0, 0 };
283 gl_->GetMultipleIntegervCHROMIUM(pnames, pcount,
284 pvalues, sizeof(pvalues));
286 attributes_.alpha = pvalues[0] > 0;
287 attributes_.depth = pvalues[1] > 0;
288 attributes_.stencil = pvalues[2] > 0;
289 attributes_.antialias = pvalues[3] > 0;
297 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(
301 // We need to lock g_all_shared_contexts to ensure that the context we picked
302 // for our share group isn't deleted.
303 // (There's also a lock in our destructor.)
304 base::AutoLock lock(g_all_shared_contexts_lock.Get());
305 CommandBufferProxyImpl* share_group = NULL;
306 if (attributes_.shareResources) {
307 ContextMap& all_contexts = g_all_shared_contexts.Get();
308 ContextMap::const_iterator it = all_contexts.find(host_.get());
309 if (it != all_contexts.end())
310 share_group = it->second->command_buffer_.get();
313 std::vector<int32> attribs;
314 attribs.push_back(ALPHA_SIZE);
315 attribs.push_back(attributes_.alpha ? 8 : 0);
316 attribs.push_back(DEPTH_SIZE);
317 attribs.push_back(attributes_.depth ? 24 : 0);
318 attribs.push_back(STENCIL_SIZE);
319 attribs.push_back(attributes_.stencil ? 8 : 0);
320 attribs.push_back(SAMPLES);
321 attribs.push_back(attributes_.antialias ? 4 : 0);
322 attribs.push_back(SAMPLE_BUFFERS);
323 attribs.push_back(attributes_.antialias ? 1 : 0);
324 attribs.push_back(FAIL_IF_MAJOR_PERF_CAVEAT);
325 attribs.push_back(attributes_.failIfMajorPerformanceCaveat ? 1 : 0);
326 attribs.push_back(NONE);
328 // Create a proxy to a command buffer in the GPU process.
330 command_buffer_.reset(host_->CreateViewCommandBuffer(
337 command_buffer_.reset(host_->CreateOffscreenCommandBuffer(
345 if (!command_buffer_)
348 // Initialize the command buffer.
349 return command_buffer_->Initialize();
352 bool WebGraphicsContext3DCommandBufferImpl::CreateContext(
354 // Ensure the gles2 library is initialized first in a thread safe way.
355 g_gles2_initializer.Get();
357 if (!command_buffer_ &&
358 !InitializeCommandBuffer(onscreen)) {
362 // Create the GLES2 helper, which writes the command buffer protocol.
363 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get()));
364 if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size))
367 if (attributes_.noAutomaticFlushes)
368 gles2_helper_->SetAutomaticFlushes(false);
370 // Create a transfer buffer used to copy resources between the renderer
371 // process and the GPU process.
372 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get()));
375 scoped_ptr<base::AutoLock> lock;
376 scoped_refptr<gpu::gles2::ShareGroup> share_group;
377 if (attributes_.shareResources) {
378 // Make sure two clients don't try to create a new ShareGroup
380 lock.reset(new base::AutoLock(g_all_shared_contexts_lock.Get()));
381 ContextMap& all_contexts = g_all_shared_contexts.Get();
382 ContextMap::const_iterator it = all_contexts.find(host_.get());
383 if (it != all_contexts.end()) {
384 share_group = it->second->GetImplementation()->share_group();
389 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
390 bool free_command_buffer_when_invisible =
391 command_line.HasSwitch(switches::kEnablePruneGpuCommandBuffers);
393 // Create the object exposing the OpenGL API.
394 real_gl_.reset(new gpu::gles2::GLES2Implementation(
397 transfer_buffer_.get(),
398 bind_generates_resources_,
399 free_command_buffer_when_invisible,
400 command_buffer_.get()));
401 gl_ = real_gl_.get();
403 if (attributes_.shareResources) {
404 // Don't add ourselves to the list before others can get to our ShareGroup.
405 g_all_shared_contexts.Get().insert(std::make_pair(host_.get(), this));
409 if (!real_gl_->Initialize(
410 mem_limits_.start_transfer_buffer_size,
411 mem_limits_.min_transfer_buffer_size,
412 mem_limits_.max_transfer_buffer_size,
413 mem_limits_.mapped_memory_reclaim_limit)) {
417 if (CommandLine::ForCurrentProcess()->HasSwitch(
418 switches::kEnableGpuClientTracing)) {
419 trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(gl_));
420 gl_ = trace_gl_.get();
426 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
427 if (!MaybeInitializeGL())
429 gles2::SetGLContext(gl_);
430 if (command_buffer_->GetLastError() != gpu::error::kNoError)
436 uint32_t WebGraphicsContext3DCommandBufferImpl::lastFlushID() {
440 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int)
442 void WebGraphicsContext3DCommandBufferImpl::Destroy() {
444 base::AutoLock lock(g_all_shared_contexts_lock.Get());
445 ContextMap& all_contexts = g_all_shared_contexts.Get();
446 ContextMap::iterator it = std::find(
447 all_contexts.begin(),
449 std::pair<GpuChannelHost* const,
450 WebGraphicsContext3DCommandBufferImpl*>(host_.get(), this));
451 if (it != all_contexts.end())
452 all_contexts.erase(it);
456 // First flush the context to ensure that any pending frees of resources
457 // are completed. Otherwise, if this context is part of a share group,
458 // those resources might leak. Also, any remaining side effects of commands
459 // issued on this context might not be visible to other contexts in the
467 transfer_buffer_.reset();
468 gles2_helper_.reset();
471 if (command_buffer_) {
473 host_->DestroyCommandBuffer(command_buffer_.release());
474 command_buffer_.reset();
481 WebGraphicsContext3DCommandBufferImpl::GetContextSupport() {
482 return real_gl_.get();
485 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
489 void WebGraphicsContext3DCommandBufferImpl::postSubBufferCHROMIUM(
490 int x, int y, int width, int height) {
494 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
496 void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
498 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
499 synthetic_errors_.end()) {
500 synthetic_errors_.push_back(error);
504 DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum,
505 WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*)
507 DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM,
510 void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM(
520 return gl_->MapTexSubImage2DCHROMIUM(
521 target, level, xoffset, yoffset, width, height, format, type, access);
524 DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM,
527 void WebGraphicsContext3DCommandBufferImpl::setVisibilityCHROMIUM(
532 DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum,
533 WGC3Dsizei, const WGC3Denum*)
535 void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM(
536 WebGLId texture, WebGLId parentTexture) {
540 blink::WebString WebGraphicsContext3DCommandBufferImpl::
541 getRequestableExtensionsCHROMIUM() {
542 return blink::WebString::fromUTF8(
543 gl_->GetRequestableExtensionsCHROMIUM());
546 DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM,
549 void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM(
550 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
551 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
552 WGC3Dbitfield mask, WGC3Denum filter) {
553 gl_->BlitFramebufferCHROMIUM(
554 srcX0, srcY0, srcX1, srcY1,
555 dstX0, dstY0, dstX1, dstY1,
559 DELEGATE_TO_GL_5(renderbufferStorageMultisampleCHROMIUM,
560 RenderbufferStorageMultisampleCHROMIUM, WGC3Denum, WGC3Dsizei,
561 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
563 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
565 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
567 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
568 WGC3Duint, const WGC3Dchar*)
570 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
572 DELEGATE_TO_GL_2(bindFramebuffer, BindFramebuffer, WGC3Denum, WebGLId)
574 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
576 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
578 DELEGATE_TO_GL_4(blendColor, BlendColor,
579 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
581 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
583 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
584 WGC3Denum, WGC3Denum)
586 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
588 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
589 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
591 DELEGATE_TO_GL_4(bufferData, BufferData,
592 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
594 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
595 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
597 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
598 WGC3Denum, WGC3Denum)
600 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
602 DELEGATE_TO_GL_4(clearColor, ClearColor,
603 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
605 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
607 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
609 DELEGATE_TO_GL_4(colorMask, ColorMask,
610 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
612 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
614 DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D,
615 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
616 WGC3Dsizei, WGC3Dsizei, const void*)
618 DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D,
619 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
620 WGC3Denum, WGC3Dsizei, const void*)
622 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
623 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
624 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
626 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
627 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
628 WGC3Dsizei, WGC3Dsizei)
630 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
632 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
634 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
636 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
638 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
640 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
642 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
645 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
647 void WebGraphicsContext3DCommandBufferImpl::drawElements(WGC3Denum mode,
650 WGC3Dintptr offset) {
653 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
656 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
658 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
661 void WebGraphicsContext3DCommandBufferImpl::finish() {
662 flush_id_ = GenFlushID();
666 void WebGraphicsContext3DCommandBufferImpl::flush() {
667 flush_id_ = GenFlushID();
671 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
672 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
674 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
675 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
677 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
679 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
681 bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib(
682 WebGLId program, WGC3Duint index, ActiveInfo& info) {
684 synthesizeGLError(GL_INVALID_VALUE);
687 GLint max_name_length = -1;
689 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
690 if (max_name_length < 0)
692 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
694 synthesizeGLError(GL_OUT_OF_MEMORY);
700 gl_->GetActiveAttrib(
701 program, index, max_name_length, &length, &size, &type, name.get());
705 info.name = blink::WebString::fromUTF8(name.get(), length);
711 bool WebGraphicsContext3DCommandBufferImpl::getActiveUniform(
712 WebGLId program, WGC3Duint index, ActiveInfo& info) {
713 GLint max_name_length = -1;
715 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
716 if (max_name_length < 0)
718 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
720 synthesizeGLError(GL_OUT_OF_MEMORY);
726 gl_->GetActiveUniform(
727 program, index, max_name_length, &length, &size, &type, name.get());
731 info.name = blink::WebString::fromUTF8(name.get(), length);
737 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
738 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
740 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
741 WebGLId, const WGC3Dchar*, WGC3Dint)
743 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
745 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
746 WGC3Denum, WGC3Denum, WGC3Dint*)
748 blink::WebGraphicsContext3D::Attributes
749 WebGraphicsContext3DCommandBufferImpl::getContextAttributes() {
753 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() {
754 if (!synthetic_errors_.empty()) {
755 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
756 WGC3Denum err = *iter;
757 synthetic_errors_.erase(iter);
761 return gl_->GetError();
764 bool WebGraphicsContext3DCommandBufferImpl::isContextLost() {
765 return initialize_failed_ ||
766 (command_buffer_ && IsCommandBufferContextLost()) ||
767 context_lost_reason_ != GL_NO_ERROR;
770 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
772 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
773 GetFramebufferAttachmentParameteriv,
774 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
776 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
778 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
780 blink::WebString WebGraphicsContext3DCommandBufferImpl::getProgramInfoLog(
783 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
785 return blink::WebString();
786 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
788 return blink::WebString();
789 GLsizei returnedLogLength = 0;
790 gl_->GetProgramInfoLog(
791 program, logLength, &returnedLogLength, log.get());
792 DCHECK_EQ(logLength, returnedLogLength + 1);
793 blink::WebString res =
794 blink::WebString::fromUTF8(log.get(), returnedLogLength);
798 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
799 WGC3Denum, WGC3Denum, WGC3Dint*)
801 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
803 blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog(
806 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
808 return blink::WebString();
809 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
811 return blink::WebString();
812 GLsizei returnedLogLength = 0;
813 gl_->GetShaderInfoLog(
814 shader, logLength, &returnedLogLength, log.get());
815 DCHECK_EQ(logLength, returnedLogLength + 1);
816 blink::WebString res =
817 blink::WebString::fromUTF8(log.get(), returnedLogLength);
821 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
822 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
824 blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource(
827 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
829 return blink::WebString();
830 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
832 return blink::WebString();
833 GLsizei returnedLogLength = 0;
834 gl_->GetShaderSource(
835 shader, logLength, &returnedLogLength, log.get());
836 if (!returnedLogLength)
837 return blink::WebString();
838 DCHECK_EQ(logLength, returnedLogLength + 1);
839 blink::WebString res =
840 blink::WebString::fromUTF8(log.get(), returnedLogLength);
844 blink::WebString WebGraphicsContext3DCommandBufferImpl::
845 getTranslatedShaderSourceANGLE(WebGLId shader) {
848 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
850 return blink::WebString();
851 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
853 return blink::WebString();
854 GLsizei returnedLogLength = 0;
855 gl_->GetTranslatedShaderSourceANGLE(
856 shader, logLength, &returnedLogLength, log.get());
857 if (!returnedLogLength)
858 return blink::WebString();
859 DCHECK_EQ(logLength, returnedLogLength + 1);
860 blink::WebString res =
861 blink::WebString::fromUTF8(log.get(), returnedLogLength);
865 blink::WebString WebGraphicsContext3DCommandBufferImpl::getString(
867 return blink::WebString::fromUTF8(
868 reinterpret_cast<const char*>(gl_->GetString(name)));
871 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
872 WGC3Denum, WGC3Denum, WGC3Dfloat*)
874 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
875 WGC3Denum, WGC3Denum, WGC3Dint*)
877 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
879 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
881 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
882 WebGLId, const WGC3Dchar*, WGC3Dint)
884 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
885 WGC3Duint, WGC3Denum, WGC3Dfloat*)
887 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
888 WGC3Duint, WGC3Denum, WGC3Dint*)
890 WGC3Dsizeiptr WebGraphicsContext3DCommandBufferImpl::getVertexAttribOffset(
891 WGC3Duint index, WGC3Denum pname) {
892 GLvoid* value = NULL;
893 // NOTE: If pname is ever a value that returns more then 1 element
894 // this will corrupt memory.
895 gl_->GetVertexAttribPointerv(index, pname, &value);
896 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
899 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
901 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
903 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
905 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
907 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
909 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
911 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
913 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
915 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
917 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
919 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
921 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
923 DELEGATE_TO_GL_7(readPixels, ReadPixels,
924 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
927 void WebGraphicsContext3DCommandBufferImpl::releaseShaderCompiler() {
930 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
931 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
933 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
935 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
937 void WebGraphicsContext3DCommandBufferImpl::shaderSource(
938 WebGLId shader, const WGC3Dchar* string) {
939 GLint length = strlen(string);
940 gl_->ShaderSource(shader, 1, &string, &length);
943 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
945 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
946 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
948 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
950 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
951 WGC3Denum, WGC3Duint)
953 DELEGATE_TO_GL_3(stencilOp, StencilOp,
954 WGC3Denum, WGC3Denum, WGC3Denum)
956 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
957 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
959 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
960 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
961 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
963 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
964 WGC3Denum, WGC3Denum, WGC3Dfloat);
966 static const unsigned int kTextureWrapR = 0x8072;
968 void WebGraphicsContext3DCommandBufferImpl::texParameteri(
969 WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
970 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
971 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
972 // edge of cube maps, and, if it is, push it into the GLES2 service
974 if (pname == kTextureWrapR) {
977 gl_->TexParameteri(target, pname, param);
980 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
981 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
982 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
984 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
986 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
989 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
991 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
993 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
995 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
998 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
1000 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
1002 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
1003 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
1005 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
1008 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
1010 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
1012 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
1013 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
1015 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
1018 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
1019 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
1021 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
1023 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
1024 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
1026 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
1027 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
1029 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
1030 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
1032 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
1034 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
1036 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
1038 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
1041 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
1042 WGC3Dfloat, WGC3Dfloat)
1044 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
1047 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
1048 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
1050 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
1053 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
1054 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
1056 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
1059 void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer(
1060 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
1061 WGC3Dsizei stride, WGC3Dintptr offset) {
1062 gl_->VertexAttribPointer(
1063 index, size, type, normalized, stride,
1064 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1067 DELEGATE_TO_GL_4(viewport, Viewport,
1068 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
1070 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
1072 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
1074 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
1076 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
1078 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
1080 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
1082 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
1085 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
1087 WebGLId WebGraphicsContext3DCommandBufferImpl::createBuffer() {
1089 gl_->GenBuffers(1, &o);
1093 WebGLId WebGraphicsContext3DCommandBufferImpl::createFramebuffer() {
1095 gl_->GenFramebuffers(1, &o);
1099 WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() {
1101 gl_->GenRenderbuffers(1, &o);
1105 WebGLId WebGraphicsContext3DCommandBufferImpl::createTexture() {
1107 gl_->GenTextures(1, &o);
1111 void WebGraphicsContext3DCommandBufferImpl::deleteBuffer(WebGLId buffer) {
1112 gl_->DeleteBuffers(1, &buffer);
1115 void WebGraphicsContext3DCommandBufferImpl::deleteFramebuffer(
1116 WebGLId framebuffer) {
1117 gl_->DeleteFramebuffers(1, &framebuffer);
1120 void WebGraphicsContext3DCommandBufferImpl::deleteRenderbuffer(
1121 WebGLId renderbuffer) {
1122 gl_->DeleteRenderbuffers(1, &renderbuffer);
1125 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) {
1126 gl_->DeleteTextures(1, &texture);
1129 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
1131 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
1133 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
1135 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
1137 void WebGraphicsContext3DCommandBufferImpl::setErrorMessageCallback(
1138 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
1139 error_message_callback_ = cb;
1142 void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback(
1143 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
1144 context_lost_callback_ = cb;
1147 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() {
1148 if (IsCommandBufferContextLost() &&
1149 context_lost_reason_ == GL_NO_ERROR) {
1150 return GL_UNKNOWN_CONTEXT_RESET_ARB;
1153 return context_lost_reason_;
1156 bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() {
1157 // If the channel shut down unexpectedly, let that supersede the
1158 // command buffer's state.
1159 if (host_.get() && host_->IsLost())
1161 gpu::CommandBuffer::State state = command_buffer_->GetLastState();
1162 return state.error == gpu::error::kLostContext;
1166 WebGraphicsContext3DCommandBufferImpl*
1167 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
1168 GpuChannelHost* host,
1169 const WebGraphicsContext3D::Attributes& attributes,
1170 const GURL& active_url,
1171 const SharedMemoryLimits& limits) {
1174 return new WebGraphicsContext3DCommandBufferImpl(0,
1182 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
1183 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
1185 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
1186 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
1188 WebGLId WebGraphicsContext3DCommandBufferImpl::createQueryEXT() {
1190 gl_->GenQueriesEXT(1, &o);
1194 void WebGraphicsContext3DCommandBufferImpl::deleteQueryEXT(
1196 gl_->DeleteQueriesEXT(1, &query);
1199 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
1200 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
1201 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
1202 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
1203 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
1204 WebGLId, WGC3Denum, WGC3Duint*)
1206 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum,
1207 WebGLId, WebGLId, WGC3Dint, WGC3Denum, WGC3Denum);
1209 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1210 WebGLId, WGC3Dint, const WGC3Dchar*)
1212 void WebGraphicsContext3DCommandBufferImpl::shallowFlushCHROMIUM() {
1213 flush_id_ = GenFlushID();
1214 gl_->ShallowFlushCHROMIUM();
1217 void WebGraphicsContext3DCommandBufferImpl::shallowFinishCHROMIUM() {
1218 flush_id_ = GenFlushID();
1219 gl_->ShallowFinishCHROMIUM();
1222 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
1224 void WebGraphicsContext3DCommandBufferImpl::loseContextCHROMIUM(
1225 WGC3Denum current, WGC3Denum other) {
1226 gl_->LoseContextCHROMIUM(current, other);
1230 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1231 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1232 WGC3Denum, const WGC3Dbyte*)
1233 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1234 WGC3Denum, const WGC3Dbyte*)
1236 void WebGraphicsContext3DCommandBufferImpl::insertEventMarkerEXT(
1237 const WGC3Dchar* marker) {
1238 gl_->InsertEventMarkerEXT(0, marker);
1241 void WebGraphicsContext3DCommandBufferImpl::pushGroupMarkerEXT(
1242 const WGC3Dchar* marker) {
1243 gl_->PushGroupMarkerEXT(0, marker);
1246 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
1248 WebGLId WebGraphicsContext3DCommandBufferImpl::createVertexArrayOES() {
1250 gl_->GenVertexArraysOES(1, &array);
1254 void WebGraphicsContext3DCommandBufferImpl::deleteVertexArrayOES(
1256 gl_->DeleteVertexArraysOES(1, &array);
1259 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
1260 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
1262 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
1263 WGC3Denum, WGC3Dint)
1264 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
1265 WGC3Denum, WGC3Dint)
1267 DELEGATE_TO_GL_2R(mapBufferCHROMIUM, MapBufferCHROMIUM, WGC3Denum, WGC3Denum,
1269 DELEGATE_TO_GL_1R(unmapBufferCHROMIUM, UnmapBufferCHROMIUM, WGC3Denum,
1272 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, WGC3Denum,
1273 WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
1274 WGC3Denum, WGC3Denum, const void*)
1275 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1276 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
1277 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
1279 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1282 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
1284 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
1285 WGC3Dint, WGC3Dsizei, WGC3Dsizei)
1287 void WebGraphicsContext3DCommandBufferImpl::drawElementsInstancedANGLE(
1292 WGC3Dsizei primcount) {
1293 gl_->DrawElementsInstancedANGLE(
1295 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
1298 DELEGATE_TO_GL_2(vertexAttribDivisorANGLE, VertexAttribDivisorANGLE, WGC3Duint,
1301 DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM,
1302 WGC3Dsizei, WGC3Dsizei, WGC3Denum,
1305 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint);
1307 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM,
1308 WGC3Duint, WGC3Denum, GLint*);
1310 DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM,
1311 WGC3Duint, WGC3Denum, void*);
1313 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
1315 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
1316 FramebufferTexture2DMultisampleEXT,
1317 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1319 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1320 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1321 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1323 GrGLInterface* WebGraphicsContext3DCommandBufferImpl::createGrGLInterface() {
1324 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1329 WGC3Denum convertReason(gpu::error::ContextLostReason reason) {
1331 case gpu::error::kGuilty:
1332 return GL_GUILTY_CONTEXT_RESET_ARB;
1333 case gpu::error::kInnocent:
1334 return GL_INNOCENT_CONTEXT_RESET_ARB;
1335 case gpu::error::kUnknown:
1336 return GL_UNKNOWN_CONTEXT_RESET_ARB;
1340 return GL_UNKNOWN_CONTEXT_RESET_ARB;
1343 } // anonymous namespace
1345 void WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost() {
1346 context_lost_reason_ = convertReason(
1347 command_buffer_->GetLastState().context_lost_reason);
1348 if (context_lost_callback_) {
1349 context_lost_callback_->onContextLost();
1352 DCHECK(host_.get());
1354 base::AutoLock lock(g_all_shared_contexts_lock.Get());
1355 g_all_shared_contexts.Get().erase(host_.get());
1359 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage(
1360 const std::string& message, int id) {
1361 if (error_message_callback_) {
1362 blink::WebString str = blink::WebString::fromUTF8(message.c_str());
1363 error_message_callback_->onErrorMessage(str, id);
1367 } // namespace content