webgraphicscontext3d_in_process_command_buffer_impl.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Use of this source code is governed by a BSD-style license that can be 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// found in the LICENSE file. 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <GLES2/gl2.h> 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef GL_GLEXT_PROTOTYPES 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define GL_GLEXT_PROTOTYPES 1 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <GLES2/gl2ext.h> 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <GLES2/gl2extchromium.h> 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string> 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "base/atomicops.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "base/bind.h" 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "base/bind_helpers.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "base/callback.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "base/lazy_instance.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "base/logging.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "gpu/command_buffer/client/gl_in_process_context.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "gpu/command_buffer/client/gles2_implementation.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "gpu/command_buffer/client/gles2_lib.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ui/gfx/size.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ui/gl/gl_surface.h" 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "webkit/common/gpu/gl_bindings_skia_cmd_buffer.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruusing gpu::gles2::GLES2Implementation; 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruusing gpu::GLInProcessContext; 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querunamespace webkit { 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querunamespace gpu { 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querunamespace { 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst int32 kCommandBufferSize = 1024 * 1024; 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// TODO(kbr): make the transfer buffer size configurable via context 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// creation attributes. 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst size_t kStartTransferBufferSize = 4 * 1024 * 1024; 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst size_t kMinTransferBufferSize = 1 * 256 * 1024; 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst size_t kMaxTransferBufferSize = 16 * 1024 * 1024; 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid OnSignalSyncPoint( 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback* callback) { 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru callback->onSyncPointReached(); 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruuint32_t GenFlushID() { 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static base::subtle::Atomic32 flush_id = 0; 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement( 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru &flush_id, 1); 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return static_cast<uint32_t>(my_id); 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Singleton used to initialize and terminate the gles2 library. 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass GLES2Initializer { 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public: 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GLES2Initializer() { 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ::gles2::Initialize(); 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ~GLES2Initializer() { 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ::gles2::Terminate(); 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru private: 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic base::LazyInstance<GLES2Initializer> g_gles2_initializer = 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LAZY_INSTANCE_INITIALIZER; 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} // namespace anonymous 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// static 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruscoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruWebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const WebKit::WebGraphicsContext3D::Attributes& attributes, 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gfx::AcceleratedWidget window) { 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context; 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (gfx::GLSurface::InitializeOneOff()) { 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl( 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window)); 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return context.Pass(); 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// static 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruscoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruWebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const WebKit::WebGraphicsContext3D::Attributes& attributes) { 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scoped_ptr< ::gpu::GLInProcessContext>(), 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes, 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru true, 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gfx::kNullAcceleratedWidget)) 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru .Pass(); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruscoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruWebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scoped_ptr< ::gpu::GLInProcessContext> context, 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const WebKit::WebGraphicsContext3D::Attributes& attributes) { 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return make_scoped_ptr( 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru new WebGraphicsContext3DInProcessCommandBufferImpl( 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context.Pass(), 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes, 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru true /* is_offscreen. Not used. */, 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gfx::kNullAcceleratedWidget /* window. Not used. */)) 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru .Pass(); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruWebGraphicsContext3DInProcessCommandBufferImpl:: 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WebGraphicsContext3DInProcessCommandBufferImpl( 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru scoped_ptr< ::gpu::GLInProcessContext> context, 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const WebKit::WebGraphicsContext3D::Attributes& attributes, 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bool is_offscreen, 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gfx::AcceleratedWidget window) 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru : is_offscreen_(is_offscreen), 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru window_(window), 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru initialized_(false), 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru initialize_failed_(false), 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context_(context.Pass()), 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_(NULL), 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context_lost_callback_(NULL), 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context_lost_reason_(GL_NO_ERROR), 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes_(attributes), 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cached_width_(0), 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cached_height_(0), 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru flush_id_(0) { 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruWebGraphicsContext3DInProcessCommandBufferImpl:: 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ~WebGraphicsContext3DInProcessCommandBufferImpl() { 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// static 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const WebKit::WebGraphicsContext3D::Attributes& attributes, 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ::gpu::GLInProcessContextAttribs* output_attribs) { 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru output_attribs->alpha_size = attributes.alpha ? 8 : 0; 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru output_attribs->depth_size = attributes.depth ? 24 : 0; 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru output_attribs->stencil_size = attributes.stencil ? 8 : 0; 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru output_attribs->samples = attributes.antialias ? 4 : 0; 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru output_attribs->sample_buffers = attributes.antialias ? 1 : 0; 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querubool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (initialized_) 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return true; 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (initialize_failed_) 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return false; 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Ensure the gles2 library is initialized first in a thread safe way. 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru g_gles2_initializer.Get(); 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!context_) { 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // TODO(kbr): More work will be needed in this implementation to 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // properly support GPU switching. Like in the out-of-process 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // command buffer implementation, all previously created contexts 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // will need to be lost either when the first context requesting the 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // discrete GPU is created, or the last one is destroyed. 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ::gpu::GLInProcessContextAttribs attrib_struct; 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ConvertAttributes(attributes_, &attrib_struct), 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context_.reset(GLInProcessContext::CreateContext( 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru is_offscreen_, 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru window_, 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gfx::Size(1, 1), 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes_.shareResources, 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attrib_struct, 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gpu_preference)); 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (context_) { 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base::Closure context_lost_callback = base::Bind( 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru base::Unretained(this)); 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru context_->SetContextLostCallback(context_lost_callback); 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru initialize_failed_ = true; 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return false; 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_ = context_->GetImplementation(); 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (gl_ && attributes_.noExtensions) 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Set attributes_ from created offscreen context. 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GLint alpha_bits = 0; 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getIntegerv(GL_ALPHA_BITS, &alpha_bits); 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes_.alpha = alpha_bits > 0; 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GLint depth_bits = 0; 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getIntegerv(GL_DEPTH_BITS, &depth_bits); 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes_.depth = depth_bits > 0; 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GLint stencil_bits = 0; 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getIntegerv(GL_STENCIL_BITS, &stencil_bits); 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes_.stencil = stencil_bits > 0; 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GLint sample_buffers = 0; 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers); 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru attributes_.antialias = sample_buffers > 0; 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru initialized_ = true; 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return true; 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querubool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!MaybeInitializeGL()) 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return false; 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ::gles2::SetGLContext(gl_); 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return context_ && !isContextLost(); 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruuint32_t WebGraphicsContext3DInProcessCommandBufferImpl::lastFlushID() { 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return flush_id_; 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() { 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // NOTE: Comment in the line below to check for code that is not calling 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // eglMakeCurrent where appropriate. The issue is code using 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // WebGraphicsContext3D does not need to call makeContextCurrent. Code using 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // direct OpenGL bindings needs to call the appropriate form of 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // context. Uncommenting the line below clears the current context so that 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // any code not calling eglMakeCurrent in the appropriate place should crash. 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // This is not a perfect test but generally code that used the direct OpenGL 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // bindings should not be mixed with code that uses WebGraphicsContext3D. 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // GLInProcessContext::MakeCurrent(NULL); 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint WebGraphicsContext3DInProcessCommandBufferImpl::width() { 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return cached_width_; 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint WebGraphicsContext3DInProcessCommandBufferImpl::height() { 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return cached_height_; 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() { 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!isContextLost()) { 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_->SwapBuffers(); 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_->ShallowFlushCHROMIUM(); 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM( 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int x, int y, int width, int height) { 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_->PostSubBufferCHROMIUM(x, y, width, height); 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::reshape( 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int width, int height) { 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reshapeWithScaleFactor(width, height, 1.0f); 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::reshapeWithScaleFactor( 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int width, int height, float scale_factor) { 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cached_width_ = width; 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cached_height_ = height; 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // TODO(gmam): See if we can comment this in. 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // ClearContext(); 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru gl_->ResizeCHROMIUM(width, height, scale_factor); 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError( 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum error) { 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru synthetic_errors_.end()) { 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru synthetic_errors_.push_back(error); 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM( 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum target, 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dintptr offset, 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dsizeiptr size, 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum access) { 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ClearContext(); 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access); 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid WebGraphicsContext3DInProcessCommandBufferImpl::unmapBufferSubDataCHROMIUM( 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const void* mem) { 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ClearContext(); 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return gl_->UnmapBufferSubDataCHROMIUM(mem); 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid* WebGraphicsContext3DInProcessCommandBufferImpl::mapTexSubImage2DCHROMIUM( 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum target, 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dint level, 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dint xoffset, 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dint yoffset, 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dsizei width, 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Dsizei height, 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum format, 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum type, 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru WGC3Denum access) { 309 ClearContext(); 310 return gl_->MapTexSubImage2DCHROMIUM( 311 target, level, xoffset, yoffset, width, height, format, type, access); 312} 313 314void WebGraphicsContext3DInProcessCommandBufferImpl::unmapTexSubImage2DCHROMIUM( 315 const void* mem) { 316 ClearContext(); 317 gl_->UnmapTexSubImage2DCHROMIUM(mem); 318} 319 320void WebGraphicsContext3DInProcessCommandBufferImpl::setVisibilityCHROMIUM( 321 bool visible) { 322} 323 324void WebGraphicsContext3DInProcessCommandBufferImpl:: 325 setMemoryAllocationChangedCallbackCHROMIUM( 326 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) { 327} 328 329void WebGraphicsContext3DInProcessCommandBufferImpl::discardFramebufferEXT( 330 WGC3Denum target, WGC3Dsizei numAttachments, const WGC3Denum* attachments) { 331 gl_->DiscardFramebufferEXT(target, numAttachments, attachments); 332} 333 334void WebGraphicsContext3DInProcessCommandBufferImpl:: 335 discardBackbufferCHROMIUM() { 336} 337 338void WebGraphicsContext3DInProcessCommandBufferImpl:: 339 ensureBackbufferCHROMIUM() { 340} 341 342void WebGraphicsContext3DInProcessCommandBufferImpl:: 343 copyTextureToParentTextureCHROMIUM(WebGLId texture, WebGLId parentTexture) { 344 NOTIMPLEMENTED(); 345} 346 347void WebGraphicsContext3DInProcessCommandBufferImpl:: 348 rateLimitOffscreenContextCHROMIUM() { 349 // TODO(gmam): See if we can comment this in. 350 // ClearContext(); 351 gl_->RateLimitOffscreenContextCHROMIUM(); 352} 353 354WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl:: 355 getRequestableExtensionsCHROMIUM() { 356 // TODO(gmam): See if we can comment this in. 357 // ClearContext(); 358 return WebKit::WebString::fromUTF8( 359 gl_->GetRequestableExtensionsCHROMIUM()); 360} 361 362void WebGraphicsContext3DInProcessCommandBufferImpl::requestExtensionCHROMIUM( 363 const char* extension) { 364 // TODO(gmam): See if we can comment this in. 365 // ClearContext(); 366 gl_->RequestExtensionCHROMIUM(extension); 367} 368 369void WebGraphicsContext3DInProcessCommandBufferImpl::blitFramebufferCHROMIUM( 370 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, 371 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, 372 WGC3Dbitfield mask, WGC3Denum filter) { 373 ClearContext(); 374 gl_->BlitFramebufferEXT( 375 srcX0, srcY0, srcX1, srcY1, 376 dstX0, dstY0, dstX1, dstY1, 377 mask, filter); 378} 379 380void WebGraphicsContext3DInProcessCommandBufferImpl:: 381 renderbufferStorageMultisampleCHROMIUM( 382 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, 383 WGC3Dsizei width, WGC3Dsizei height) { 384 ClearContext(); 385 gl_->RenderbufferStorageMultisampleEXT( 386 target, samples, internalformat, width, height); 387} 388 389// Helper macros to reduce the amount of code. 390 391#define DELEGATE_TO_GL(name, glname) \ 392void WebGraphicsContext3DInProcessCommandBufferImpl::name() { \ 393 ClearContext(); \ 394 gl_->glname(); \ 395} 396 397#define DELEGATE_TO_GL_1(name, glname, t1) \ 398void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ 399 ClearContext(); \ 400 gl_->glname(a1); \ 401} 402 403#define DELEGATE_TO_GL_1R(name, glname, t1, rt) \ 404rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ 405 ClearContext(); \ 406 return gl_->glname(a1); \ 407} 408 409#define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \ 410rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ 411 ClearContext(); \ 412 return gl_->glname(a1) ? true : false; \ 413} 414 415#define DELEGATE_TO_GL_2(name, glname, t1, t2) \ 416void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 417 t1 a1, t2 a2) { \ 418 ClearContext(); \ 419 gl_->glname(a1, a2); \ 420} 421 422#define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \ 423rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1, t2 a2) { \ 424 ClearContext(); \ 425 return gl_->glname(a1, a2); \ 426} 427 428#define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \ 429void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 430 t1 a1, t2 a2, t3 a3) { \ 431 ClearContext(); \ 432 gl_->glname(a1, a2, a3); \ 433} 434 435#define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \ 436rt WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 437 t1 a1, t2 a2, t3 a3) { \ 438 ClearContext(); \ 439 return gl_->glname(a1, a2, a3); \ 440} 441 442#define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \ 443void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 444 t1 a1, t2 a2, t3 a3, t4 a4) { \ 445 ClearContext(); \ 446 gl_->glname(a1, a2, a3, a4); \ 447} 448 449#define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \ 450void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 451 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \ 452 ClearContext(); \ 453 gl_->glname(a1, a2, a3, a4, a5); \ 454} 455 456#define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \ 457void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 458 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) { \ 459 ClearContext(); \ 460 gl_->glname(a1, a2, a3, a4, a5, a6); \ 461} 462 463#define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \ 464void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 465 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) { \ 466 ClearContext(); \ 467 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \ 468} 469 470#define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \ 471void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 472 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) { \ 473 ClearContext(); \ 474 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \ 475} 476 477#define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ 478void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ 479 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) { \ 480 ClearContext(); \ 481 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ 482} 483 484DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum) 485 486DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId) 487 488DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId, 489 WGC3Duint, const WGC3Dchar*) 490 491DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId) 492 493void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer( 494 WGC3Denum target, 495 WebGLId framebuffer) { 496 ClearContext(); 497 gl_->BindFramebuffer(target, framebuffer); 498} 499 500DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId) 501 502DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId) 503 504DELEGATE_TO_GL_4(blendColor, BlendColor, 505 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf) 506 507DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum) 508 509DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate, 510 WGC3Denum, WGC3Denum) 511 512DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum) 513 514DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate, 515 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum) 516 517DELEGATE_TO_GL_4(bufferData, BufferData, 518 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum) 519 520DELEGATE_TO_GL_4(bufferSubData, BufferSubData, 521 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*) 522 523DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus, 524 WGC3Denum, WGC3Denum) 525 526DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield) 527 528DELEGATE_TO_GL_4(clearColor, ClearColor, 529 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf) 530 531DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf) 532 533DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint) 534 535DELEGATE_TO_GL_4(colorMask, ColorMask, 536 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean) 537 538DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId) 539 540DELEGATE_TO_GL_8(compressedTexImage2D, CompressedTexImage2D, 541 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint, 542 WGC3Dsizei, WGC3Dsizei, const void*) 543 544DELEGATE_TO_GL_9(compressedTexSubImage2D, CompressedTexSubImage2D, 545 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, 546 WGC3Denum, WGC3Dsizei, const void*) 547 548DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D, 549 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint, 550 WGC3Dsizei, WGC3Dsizei, WGC3Dint) 551 552DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D, 553 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, 554 WGC3Dsizei, WGC3Dsizei) 555 556DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum) 557 558DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum) 559 560DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean) 561 562DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf) 563 564DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId) 565 566DELEGATE_TO_GL_1(disable, Disable, WGC3Denum) 567 568DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray, 569 WGC3Duint) 570 571DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei) 572 573void WebGraphicsContext3DInProcessCommandBufferImpl::drawElements( 574 WGC3Denum mode, 575 WGC3Dsizei count, 576 WGC3Denum type, 577 WGC3Dintptr offset) { 578 ClearContext(); 579 gl_->DrawElements( 580 mode, count, type, 581 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 582} 583 584DELEGATE_TO_GL_1(enable, Enable, WGC3Denum) 585 586DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray, 587 WGC3Duint) 588 589void WebGraphicsContext3DInProcessCommandBufferImpl::finish() { 590 flush_id_ = GenFlushID(); 591 gl_->Finish(); 592} 593 594void WebGraphicsContext3DInProcessCommandBufferImpl::flush() { 595 flush_id_ = GenFlushID(); 596 gl_->Flush(); 597} 598 599DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer, 600 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId) 601 602DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D, 603 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint) 604 605DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum) 606 607DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum) 608 609bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveAttrib( 610 WebGLId program, WGC3Duint index, ActiveInfo& info) { 611 ClearContext(); 612 if (!program) { 613 synthesizeGLError(GL_INVALID_VALUE); 614 return false; 615 } 616 GLint max_name_length = -1; 617 gl_->GetProgramiv( 618 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); 619 if (max_name_length < 0) 620 return false; 621 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); 622 if (!name) { 623 synthesizeGLError(GL_OUT_OF_MEMORY); 624 return false; 625 } 626 GLsizei length = 0; 627 GLint size = -1; 628 GLenum type = 0; 629 gl_->GetActiveAttrib( 630 program, index, max_name_length, &length, &size, &type, name.get()); 631 if (size < 0) { 632 return false; 633 } 634 info.name = WebKit::WebString::fromUTF8(name.get(), length); 635 info.type = type; 636 info.size = size; 637 return true; 638} 639 640bool WebGraphicsContext3DInProcessCommandBufferImpl::getActiveUniform( 641 WebGLId program, WGC3Duint index, ActiveInfo& info) { 642 ClearContext(); 643 GLint max_name_length = -1; 644 gl_->GetProgramiv( 645 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); 646 if (max_name_length < 0) 647 return false; 648 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); 649 if (!name) { 650 synthesizeGLError(GL_OUT_OF_MEMORY); 651 return false; 652 } 653 GLsizei length = 0; 654 GLint size = -1; 655 GLenum type = 0; 656 gl_->GetActiveUniform( 657 program, index, max_name_length, &length, &size, &type, name.get()); 658 if (size < 0) { 659 return false; 660 } 661 info.name = WebKit::WebString::fromUTF8(name.get(), length); 662 info.type = type; 663 info.size = size; 664 return true; 665} 666 667DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders, 668 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*) 669 670DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation, 671 WebGLId, const WGC3Dchar*, WGC3Dint) 672 673DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*) 674 675DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv, 676 WGC3Denum, WGC3Denum, WGC3Dint*) 677 678WebKit::WebGraphicsContext3D::Attributes 679WebGraphicsContext3DInProcessCommandBufferImpl::getContextAttributes() { 680 return attributes_; 681} 682 683WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::getError() { 684 ClearContext(); 685 if (!synthetic_errors_.empty()) { 686 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin(); 687 WGC3Denum err = *iter; 688 synthetic_errors_.erase(iter); 689 return err; 690 } 691 692 return gl_->GetError(); 693} 694 695bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() { 696 return context_lost_reason_ != GL_NO_ERROR; 697} 698 699DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*) 700 701DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv, 702 GetFramebufferAttachmentParameteriv, 703 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*) 704 705DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*) 706 707DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*) 708 709WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl:: 710 getProgramInfoLog(WebGLId program) { 711 ClearContext(); 712 GLint logLength = 0; 713 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 714 if (!logLength) 715 return WebKit::WebString(); 716 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 717 if (!log) 718 return WebKit::WebString(); 719 GLsizei returnedLogLength = 0; 720 gl_->GetProgramInfoLog( 721 program, logLength, &returnedLogLength, log.get()); 722 DCHECK_EQ(logLength, returnedLogLength + 1); 723 WebKit::WebString res = 724 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); 725 return res; 726} 727 728DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv, 729 WGC3Denum, WGC3Denum, WGC3Dint*) 730 731DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*) 732 733WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl:: 734 getShaderInfoLog(WebGLId shader) { 735 ClearContext(); 736 GLint logLength = 0; 737 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); 738 if (!logLength) 739 return WebKit::WebString(); 740 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 741 if (!log) 742 return WebKit::WebString(); 743 GLsizei returnedLogLength = 0; 744 gl_->GetShaderInfoLog( 745 shader, logLength, &returnedLogLength, log.get()); 746 DCHECK_EQ(logLength, returnedLogLength + 1); 747 WebKit::WebString res = 748 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); 749 return res; 750} 751 752DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat, 753 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*) 754 755WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl:: 756 getShaderSource(WebGLId shader) { 757 ClearContext(); 758 GLint logLength = 0; 759 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); 760 if (!logLength) 761 return WebKit::WebString(); 762 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 763 if (!log) 764 return WebKit::WebString(); 765 GLsizei returnedLogLength = 0; 766 gl_->GetShaderSource( 767 shader, logLength, &returnedLogLength, log.get()); 768 if (!returnedLogLength) 769 return WebKit::WebString(); 770 DCHECK_EQ(logLength, returnedLogLength + 1); 771 WebKit::WebString res = 772 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); 773 return res; 774} 775 776WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl:: 777 getTranslatedShaderSourceANGLE(WebGLId shader) { 778 ClearContext(); 779 GLint logLength = 0; 780 gl_->GetShaderiv( 781 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength); 782 if (!logLength) 783 return WebKit::WebString(); 784 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 785 if (!log) 786 return WebKit::WebString(); 787 GLsizei returnedLogLength = 0; 788 gl_->GetTranslatedShaderSourceANGLE( 789 shader, logLength, &returnedLogLength, log.get()); 790 if (!returnedLogLength) 791 return WebKit::WebString(); 792 DCHECK_EQ(logLength, returnedLogLength + 1); 793 WebKit::WebString res = 794 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); 795 return res; 796} 797 798WebKit::WebString WebGraphicsContext3DInProcessCommandBufferImpl::getString( 799 WGC3Denum name) { 800 ClearContext(); 801 return WebKit::WebString::fromUTF8( 802 reinterpret_cast<const char*>(gl_->GetString(name))); 803} 804 805DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv, 806 WGC3Denum, WGC3Denum, WGC3Dfloat*) 807 808DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv, 809 WGC3Denum, WGC3Denum, WGC3Dint*) 810 811DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*) 812 813DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*) 814 815DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation, 816 WebGLId, const WGC3Dchar*, WGC3Dint) 817 818DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv, 819 WGC3Duint, WGC3Denum, WGC3Dfloat*) 820 821DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv, 822 WGC3Duint, WGC3Denum, WGC3Dint*) 823 824WGC3Dsizeiptr WebGraphicsContext3DInProcessCommandBufferImpl:: 825 getVertexAttribOffset(WGC3Duint index, WGC3Denum pname) { 826 ClearContext(); 827 GLvoid* value = NULL; 828 // NOTE: If pname is ever a value that returns more then 1 element 829 // this will corrupt memory. 830 gl_->GetVertexAttribPointerv(index, pname, &value); 831 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value)); 832} 833 834DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum) 835 836DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean) 837 838DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean) 839 840DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean) 841 842DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean) 843 844DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean) 845 846DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean) 847 848DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean) 849 850DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat) 851 852DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId) 853 854DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint) 855 856DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat) 857 858DELEGATE_TO_GL_7(readPixels, ReadPixels, 859 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum, 860 WGC3Denum, void*) 861 862void WebGraphicsContext3DInProcessCommandBufferImpl::releaseShaderCompiler() { 863 ClearContext(); 864} 865 866DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage, 867 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei) 868 869DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean) 870 871DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) 872 873void WebGraphicsContext3DInProcessCommandBufferImpl::shaderSource( 874 WebGLId shader, const WGC3Dchar* string) { 875 ClearContext(); 876 GLint length = strlen(string); 877 gl_->ShaderSource(shader, 1, &string, &length); 878} 879 880DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint) 881 882DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate, 883 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint) 884 885DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint) 886 887DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate, 888 WGC3Denum, WGC3Duint) 889 890DELEGATE_TO_GL_3(stencilOp, StencilOp, 891 WGC3Denum, WGC3Denum, WGC3Denum) 892 893DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate, 894 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum) 895 896DELEGATE_TO_GL_9(texImage2D, TexImage2D, 897 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, 898 WGC3Dint, WGC3Denum, WGC3Denum, const void*) 899 900DELEGATE_TO_GL_3(texParameterf, TexParameterf, 901 WGC3Denum, WGC3Denum, WGC3Dfloat); 902 903static const unsigned int kTextureWrapR = 0x8072; 904 905void WebGraphicsContext3DInProcessCommandBufferImpl::texParameteri( 906 WGC3Denum target, WGC3Denum pname, WGC3Dint param) { 907 ClearContext(); 908 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in 909 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the 910 // edge of cube maps, and, if it is, push it into the GLES2 service 911 // side code. 912 if (pname == kTextureWrapR) { 913 return; 914 } 915 gl_->TexParameteri(target, pname, param); 916} 917 918DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D, 919 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, 920 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*) 921 922DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat) 923 924DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei, 925 const WGC3Dfloat*) 926 927DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint) 928 929DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*) 930 931DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat) 932 933DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei, 934 const WGC3Dfloat*) 935 936DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint) 937 938DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*) 939 940DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint, 941 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) 942 943DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei, 944 const WGC3Dfloat*) 945 946DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint) 947 948DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*) 949 950DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint, 951 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) 952 953DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei, 954 const WGC3Dfloat*) 955 956DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint, 957 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint) 958 959DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*) 960 961DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv, 962 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*) 963 964DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv, 965 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*) 966 967DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv, 968 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*) 969 970DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId) 971 972DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId) 973 974DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat) 975 976DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint, 977 const WGC3Dfloat*) 978 979DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint, 980 WGC3Dfloat, WGC3Dfloat) 981 982DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint, 983 const WGC3Dfloat*) 984 985DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint, 986 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) 987 988DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint, 989 const WGC3Dfloat*) 990 991DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint, 992 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) 993 994DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint, 995 const WGC3Dfloat*) 996 997void WebGraphicsContext3DInProcessCommandBufferImpl::vertexAttribPointer( 998 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized, 999 WGC3Dsizei stride, WGC3Dintptr offset) { 1000 ClearContext(); 1001 gl_->VertexAttribPointer( 1002 index, size, type, normalized, stride, 1003 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 1004} 1005 1006DELEGATE_TO_GL_4(viewport, Viewport, 1007 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) 1008 1009WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createBuffer() { 1010 ClearContext(); 1011 GLuint o; 1012 gl_->GenBuffers(1, &o); 1013 return o; 1014} 1015 1016WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createFramebuffer() { 1017 ClearContext(); 1018 GLuint o = 0; 1019 gl_->GenFramebuffers(1, &o); 1020 return o; 1021} 1022 1023WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createProgram() { 1024 ClearContext(); 1025 return gl_->CreateProgram(); 1026} 1027 1028WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createRenderbuffer() { 1029 ClearContext(); 1030 GLuint o; 1031 gl_->GenRenderbuffers(1, &o); 1032 return o; 1033} 1034 1035DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId); 1036 1037WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() { 1038 ClearContext(); 1039 GLuint o; 1040 gl_->GenTextures(1, &o); 1041 return o; 1042} 1043 1044void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer( 1045 WebGLId buffer) { 1046 ClearContext(); 1047 gl_->DeleteBuffers(1, &buffer); 1048} 1049 1050void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( 1051 WebGLId framebuffer) { 1052 ClearContext(); 1053 gl_->DeleteFramebuffers(1, &framebuffer); 1054} 1055 1056void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( 1057 WebGLId program) { 1058 ClearContext(); 1059 gl_->DeleteProgram(program); 1060} 1061 1062void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer( 1063 WebGLId renderbuffer) { 1064 ClearContext(); 1065 gl_->DeleteRenderbuffers(1, &renderbuffer); 1066} 1067 1068void WebGraphicsContext3DInProcessCommandBufferImpl::deleteShader( 1069 WebGLId shader) { 1070 ClearContext(); 1071 gl_->DeleteShader(shader); 1072} 1073 1074void WebGraphicsContext3DInProcessCommandBufferImpl::deleteTexture( 1075 WebGLId texture) { 1076 ClearContext(); 1077 gl_->DeleteTextures(1, &texture); 1078} 1079 1080void WebGraphicsContext3DInProcessCommandBufferImpl::OnSwapBuffersComplete() { 1081} 1082 1083void WebGraphicsContext3DInProcessCommandBufferImpl::setContextLostCallback( 1084 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { 1085 context_lost_callback_ = cb; 1086} 1087 1088WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl:: 1089 getGraphicsResetStatusARB() { 1090 return context_lost_reason_; 1091} 1092 1093DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, 1094 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) 1095 1096DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT, 1097 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) 1098 1099WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createQueryEXT() { 1100 GLuint o; 1101 gl_->GenQueriesEXT(1, &o); 1102 return o; 1103} 1104 1105void WebGraphicsContext3DInProcessCommandBufferImpl:: 1106 deleteQueryEXT(WebGLId query) { 1107 gl_->DeleteQueriesEXT(1, &query); 1108} 1109 1110DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean) 1111DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId) 1112DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum) 1113DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*) 1114DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT, 1115 WebGLId, WGC3Denum, WGC3Duint*) 1116 1117DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum, WGC3Duint, 1118 WGC3Duint, WGC3Dint, WGC3Denum, WGC3Denum) 1119 1120void WebGraphicsContext3DInProcessCommandBufferImpl::insertEventMarkerEXT( 1121 const WGC3Dchar* marker) { 1122 gl_->InsertEventMarkerEXT(0, marker); 1123} 1124 1125void WebGraphicsContext3DInProcessCommandBufferImpl::pushGroupMarkerEXT( 1126 const WGC3Dchar* marker) { 1127 gl_->PushGroupMarkerEXT(0, marker); 1128} 1129 1130DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT); 1131 1132DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM, 1133 WGC3Denum, WGC3Dint) 1134DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM, 1135 WGC3Denum, WGC3Dint) 1136 1137DELEGATE_TO_GL_1R(createStreamTextureCHROMIUM, CreateStreamTextureCHROMIUM, 1138 WebGLId, WebGLId) 1139DELEGATE_TO_GL_1(destroyStreamTextureCHROMIUM, DestroyStreamTextureCHROMIUM, 1140 WebGLId) 1141 1142void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferCHROMIUM( 1143 WGC3Denum target, WGC3Denum access) { 1144 ClearContext(); 1145 return gl_->MapBufferCHROMIUM(target, access); 1146} 1147 1148WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl:: 1149 unmapBufferCHROMIUM(WGC3Denum target) { 1150 ClearContext(); 1151 return gl_->UnmapBufferCHROMIUM(target); 1152} 1153 1154GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl:: 1155 onCreateGrGLInterface() { 1156 return CreateCommandBufferSkiaGLBinding(); 1157} 1158 1159void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { 1160 // TODO(kbr): improve the precision here. 1161 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; 1162 if (context_lost_callback_) { 1163 context_lost_callback_->onContextLost(); 1164 } 1165} 1166 1167DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM, 1168 WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Duint); 1169 1170DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint); 1171 1172DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM, 1173 WGC3Duint, WGC3Denum, GLint*); 1174 1175DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM, 1176 WGC3Duint, WGC3Denum, void*); 1177 1178DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint); 1179 1180DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, 1181 WebGLId, WGC3Dint, const WGC3Dchar*) 1182 1183void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFlushCHROMIUM() { 1184 flush_id_ = GenFlushID(); 1185 gl_->ShallowFlushCHROMIUM(); 1186} 1187 1188void WebGraphicsContext3DInProcessCommandBufferImpl::shallowFinishCHROMIUM() { 1189 flush_id_ = GenFlushID(); 1190 gl_->ShallowFinishCHROMIUM(); 1191} 1192 1193DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) 1194DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, 1195 WGC3Denum, const WGC3Dbyte*) 1196DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, 1197 WGC3Denum, const WGC3Dbyte*) 1198 1199DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, 1200 WGC3Dsizei, const WGC3Denum*) 1201 1202unsigned WebGraphicsContext3DInProcessCommandBufferImpl::insertSyncPoint() { 1203 shallowFlushCHROMIUM(); 1204 return 0; 1205} 1206 1207void WebGraphicsContext3DInProcessCommandBufferImpl::signalSyncPoint( 1208 unsigned sync_point, 1209 WebGraphicsSyncPointCallback* callback) { 1210 // Take ownership of the callback. 1211 context_->SignalSyncPoint( 1212 sync_point, base::Bind(&OnSignalSyncPoint, base::Owned(callback))); 1213} 1214 1215void WebGraphicsContext3DInProcessCommandBufferImpl::signalQuery( 1216 unsigned query, 1217 WebGraphicsSyncPointCallback* callback) { 1218 // Take ownership of the callback. 1219 context_->SignalQuery(query, 1220 base::Bind(&OnSignalSyncPoint, base::Owned(callback))); 1221} 1222 1223void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM( 1224 WGC3Denum current, WGC3Denum other) { 1225 gl_->LoseContextCHROMIUM(current, other); 1226 gl_->ShallowFlushCHROMIUM(); 1227} 1228 1229DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, 1230 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint, 1231 WGC3Denum, WGC3Denum, const void*) 1232 1233DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, 1234 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, 1235 WGC3Denum, WGC3Denum, const void*) 1236 1237DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, 1238 WGC3Denum) 1239 1240} // namespace gpu 1241} // namespace webkit 1242