1 // Copyright 2013 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 #ifndef MOJO_APPS_JS_BINDINGS_GL_CONTEXT_H_
6 #define MOJO_APPS_JS_BINDINGS_GL_CONTEXT_H_
10 #include "base/memory/weak_ptr.h"
11 #include "gin/handle.h"
12 #include "gin/public/wrapper_info.h"
13 #include "gin/runner.h"
14 #include "gin/wrappable.h"
15 #include "mojo/apps/js/bindings/handle.h"
16 #include "mojo/public/gles2/gles2.h"
17 #include "v8/include/v8.h"
21 class ArrayBufferView;
28 // Context implements WebGLRenderingContext.
29 class Context : public gin::Wrappable<Context> {
31 static gin::WrapperInfo kWrapperInfo;
33 // TODO(piman): draw animation frame callback.
34 static gin::Handle<Context> Create(
37 v8::Handle<v8::Function> context_lost_callback);
39 static void BufferData(GLenum target, const gin::ArrayBufferView& buffer,
41 static void CompileShader(const gin::Arguments& args, GLuint shader);
42 static GLuint CreateBuffer();
43 static void DrawElements(GLenum mode, GLsizei count, GLenum type,
45 static GLint GetAttribLocation(GLuint program, const std::string& name);
46 static std::string GetProgramInfoLog(GLuint program);
47 static std::string GetShaderInfoLog(GLuint shader);
48 static GLint GetUniformLocation(GLuint program, const std::string& name);
49 static void ShaderSource(GLuint shader, const std::string& source);
50 static void UniformMatrix4fv(GLint location, GLboolean transpose,
51 const gin::ArrayBufferView& buffer);
52 static void VertexAttribPointer(GLuint index, GLint size, GLenum type,
53 GLboolean normalized, GLsizei stride,
57 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
58 v8::Isolate* isolate) OVERRIDE;
60 explicit Context(v8::Isolate* isolate,
62 v8::Handle<v8::Function> context_lost_callback);
66 static void ContextLostThunk(void* closure);
68 base::WeakPtr<gin::Runner> runner_;
69 v8::Persistent<v8::Function> context_lost_callback_;
70 MojoGLES2Context context_;
77 #endif // MOJO_APPS_JS_BINDINGS_GL_CONTEXT_H_