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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "mojo/apps/js/bindings/gl/context.h"
6
7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h>
9
10 #include "gin/arguments.h"
11 #include "gin/object_template_builder.h"
12 #include "gin/per_isolate_data.h"
13 #include "mojo/public/gles2/gles2.h"
14
15 namespace mojo {
16 namespace js {
17 namespace gl {
18
19 gin::WrapperInfo Context::kWrapperInfo = { gin::kEmbedderNativeGin };
20
21 gin::Handle<Context> Context::Create(v8::Isolate* isolate, uint64_t encoded,
22 int width, int height) {
23 return CreateHandle(isolate, new Context(encoded, width, height));
24 }
25
26 v8::Handle<v8::ObjectTemplate> Context::GetObjectTemplate(
27 v8::Isolate* isolate) {
28 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
29 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(&kWrapperInfo);
30 if (templ.IsEmpty()) {
31 templ = gin::ObjectTemplateBuilder(isolate)
32 .SetValue("VERTEX_SHADER", GL_VERTEX_SHADER)
33 .SetMethod("createShader", CreateShader)
34 .SetMethod("shaderSource", ShaderSource)
35 .SetMethod("compileShader", CompileShader)
36 .Build();
37 templ->SetInternalFieldCount(gin::kNumberOfInternalFields);
38 data->SetObjectTemplate(&kWrapperInfo, templ);
39 }
40 return templ;
41 }
42
43 gin::Handle<Shader> Context::CreateShader(const gin::Arguments& args,
44 GLenum type) {
45 gin::Handle<Shader> result;
46 GLuint glshader = glCreateShader(type);
47 if (glshader != 0u) {
48 result = Opaque::Create(args.isolate(), glshader);
49 }
50 return result;
51 }
52
53 void Context::ShaderSource(gin::Handle<Shader> shader,
54 const std::string& source) {
55 const char* source_chars = source.c_str();
56 glShaderSource(shader->value(), 1, &source_chars, NULL);
57 }
58
59 void Context::CompileShader(const gin::Arguments& args,
60 gin::Handle<Shader> shader) {
61 glCompileShader(shader->value());
62 GLint compiled = 0;
63 glGetShaderiv(shader->value(), GL_COMPILE_STATUS, &compiled);
64 if (!compiled) {
65 // Or should |shader| do it when it is destroyed?
66 glDeleteShader(shader->value());
67 args.ThrowTypeError("Could not compile shader");
68 return;
69 }
70 }
71
72 Context::Context(uint64_t encoded, int width, int height)
73 : encoded_(encoded) {
74 MojoGLES2MakeCurrent(encoded_);
75 }
76
77 } // namespace gl
78 } // namespace js
79 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698