15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef MOJO_APPS_JS_BINDINGS_GL_CONTEXT_H_ 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MOJO_APPS_JS_BINDINGS_GL_CONTEXT_H_ 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <GLES2/gl2.h> 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/weak_ptr.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gin/handle.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gin/public/wrapper_info.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gin/runner.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gin/wrappable.h" 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "mojo/bindings/js/handle.h" 164ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch#include "mojo/public/c/gles2/gles2.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "v8/include/v8.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace gin { 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Arguments; 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ArrayBufferView; 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace mojo { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace js { 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace gl { 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Context implements WebGLRenderingContext. 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Context : public gin::Wrappable<Context> { 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static gin::WrapperInfo kWrapperInfo; 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(piman): draw animation frame callback. 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static gin::Handle<Context> Create( 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) v8::Isolate* isolate, 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mojo::Handle handle, 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) v8::Handle<v8::Function> context_lost_callback); 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void BufferData(GLenum target, const gin::ArrayBufferView& buffer, 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GLenum usage); 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void CompileShader(const gin::Arguments& args, GLuint shader); 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static GLuint CreateBuffer(); 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void DrawElements(GLenum mode, GLsizei count, GLenum type, 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint64_t indices); 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static GLint GetAttribLocation(GLuint program, const std::string& name); 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static std::string GetProgramInfoLog(GLuint program); 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static std::string GetShaderInfoLog(GLuint shader); 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static GLint GetUniformLocation(GLuint program, const std::string& name); 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void ShaderSource(GLuint shader, const std::string& source); 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void UniformMatrix4fv(GLint location, GLboolean transpose, 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gin::ArrayBufferView& buffer); 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void VertexAttribPointer(GLuint index, GLint size, GLenum type, 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GLboolean normalized, GLsizei stride, 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint64_t offset); 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) v8::Isolate* isolate) OVERRIDE; 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) explicit Context(v8::Isolate* isolate, 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mojo::Handle handle, 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) v8::Handle<v8::Function> context_lost_callback); 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~Context(); 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ContextLost(); 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static void ContextLostThunk(void* closure); 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::WeakPtr<gin::Runner> runner_; 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) v8::Persistent<v8::Function> context_lost_callback_; 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MojoGLES2Context context_; 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace gl 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace js 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace mojo 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif // MOJO_APPS_JS_BINDINGS_GL_CONTEXT_H_ 78