Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Unified Diff: mojo/apps/js/bindings/gl/context.cc

Issue 111083005: Beginning of JS Mojo API to GL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/apps/js/bindings/gl/context.cc
diff --git a/mojo/apps/js/bindings/gl/context.cc b/mojo/apps/js/bindings/gl/context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc9ed73e45803583c77d654b9c9e27c94bacee56
--- /dev/null
+++ b/mojo/apps/js/bindings/gl/context.cc
@@ -0,0 +1,82 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/apps/js/bindings/gl/context.h"
+
+#include <GLES2/gl2.h>
+
+#include "gin/arguments.h"
+#include "gin/object_template_builder.h"
+#include "gin/per_isolate_data.h"
+#include "mojo/public/gles2/gles2.h"
+
+namespace mojo {
+namespace js {
+namespace gl {
+
+gin::WrapperInfo Context::kWrapperInfo = { gin::kEmbedderNativeGin };
+
+gin::Handle<Context> Context::Create(v8::Isolate* isolate, uint64_t encoded,
+ int width, int height) {
+ return CreateHandle(isolate, new Context(encoded, width, height));
+}
+
+v8::Handle<v8::ObjectTemplate> Context::GetObjectTemplate(
+ v8::Isolate* isolate) {
+ gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
+ v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(&kWrapperInfo);
+ if (templ.IsEmpty()) {
+ templ = gin::ObjectTemplateBuilder(isolate)
+ .SetValue("VERTEX_SHADER", GL_VERTEX_SHADER)
+ .SetMethod("createShader", CreateShader)
+ .SetMethod("shaderSource", ShaderSource)
+ .SetMethod("compileShader", CompileShader)
+ .Build();
+ templ->SetInternalFieldCount(gin::kNumberOfInternalFields);
+ data->SetObjectTemplate(&kWrapperInfo, templ);
+ }
+ return templ;
+}
+
+gin::Handle<Shader> Context::CreateShader(const gin::Arguments& args,
+ GLenum type) {
+ gin::Handle<Shader> result;
+ GLuint glshader = glCreateShader(type);
+ if (glshader != 0u) {
+ result = Opaque::Create(args.isolate(), glshader);
+ }
+ return result;
+}
+
+void Context::ShaderSource(gin::Handle<Shader> shader,
+ const std::string& source) {
+ const char* source_chars = source.c_str();
+ glShaderSource(shader->value(), 1, &source_chars, NULL);
+}
+
+void Context::CompileShader(const gin::Arguments& args,
+ gin::Handle<Shader> shader) {
+ glCompileShader(shader->value());
+ GLint compiled = 0;
+ glGetShaderiv(shader->value(), GL_COMPILE_STATUS, &compiled);
+ if (!compiled) {
+ // Or should |shader| do it when it is destroyed?
+ glDeleteShader(shader->value());
+ args.ThrowTypeError("Could not compile shader");
+ return;
+ }
+}
+
+Context::Context(uint64_t encoded, int width, int height)
+ : encoded_(encoded) {
+ // TODO(aa): Does this need to be called at the start of every public method?
abarth-chromium 2013/12/11 06:24:22 Probably not. We only support on GL context right
Aaron Boodman 2013/12/11 07:17:06 But if we had multiple contexts, we would need to
+ // If so, perhaps we should have the JS API be something like:
+ // context.with(function() {
+ // });
+ MojoGLES2MakeCurrent(encoded_);
+}
+
+} // namespace gl
+} // namespace js
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698