Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/apps/js/bindings/gl/context.h" | 5 #include "mojo/apps/js/bindings/gl/context.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 | 8 |
| 9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
| 10 #include "gin/object_template_builder.h" | 10 #include "gin/object_template_builder.h" |
| 11 #include "gin/per_isolate_data.h" | |
| 12 #include "mojo/public/gles2/gles2.h" | 11 #include "mojo/public/gles2/gles2.h" |
| 13 | 12 |
| 14 namespace mojo { | 13 namespace mojo { |
| 15 namespace js { | 14 namespace js { |
| 16 namespace gl { | 15 namespace gl { |
| 17 | 16 |
| 18 gin::WrapperInfo Context::kWrapperInfo = { gin::kEmbedderNativeGin }; | 17 gin::WrapperInfo Context::kWrapperInfo = { gin::kEmbedderNativeGin }; |
| 19 | 18 |
| 20 gin::Handle<Context> Context::Create(v8::Isolate* isolate, uint64_t encoded, | 19 gin::Handle<Context> Context::Create(v8::Isolate* isolate, uint64_t encoded, |
| 21 int width, int height) { | 20 int width, int height) { |
| 22 return gin::CreateHandle(isolate, new Context(encoded, width, height)); | 21 return gin::CreateHandle(isolate, new Context(encoded, width, height)); |
| 23 } | 22 } |
| 24 | 23 |
| 25 v8::Handle<v8::ObjectTemplate> Context::GetObjectTemplate( | 24 v8::Local<v8::ObjectTemplate> Context::GetObjectTemplate( |
| 26 v8::Isolate* isolate) { | 25 v8::Isolate* isolate) { |
| 27 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 26 return gin::ObjectTemplateBuilder(isolate) |
|
Aaron Boodman
2013/12/16 16:44:26
Ah, that looks nicer
| |
| 28 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(&kWrapperInfo); | 27 .SetValue("VERTEX_SHADER", GL_VERTEX_SHADER) |
| 29 if (templ.IsEmpty()) { | 28 .SetMethod("createShader", CreateShader) |
| 30 templ = gin::ObjectTemplateBuilder(isolate) | 29 .SetMethod("shaderSource", ShaderSource) |
| 31 .SetValue("VERTEX_SHADER", GL_VERTEX_SHADER) | 30 .SetMethod("compileShader", CompileShader) |
| 32 .SetMethod("createShader", CreateShader) | 31 .Build(); |
| 33 .SetMethod("shaderSource", ShaderSource) | |
| 34 .SetMethod("compileShader", CompileShader) | |
| 35 .Build(); | |
| 36 templ->SetInternalFieldCount(gin::kNumberOfInternalFields); | |
| 37 data->SetObjectTemplate(&kWrapperInfo, templ); | |
| 38 } | |
| 39 return templ; | |
| 40 } | 32 } |
| 41 | 33 |
| 42 gin::Handle<Shader> Context::CreateShader(const gin::Arguments& args, | 34 gin::Handle<Shader> Context::CreateShader(const gin::Arguments& args, |
| 43 GLenum type) { | 35 GLenum type) { |
| 44 gin::Handle<Shader> result; | 36 gin::Handle<Shader> result; |
| 45 GLuint glshader = glCreateShader(type); | 37 GLuint glshader = glCreateShader(type); |
| 46 if (glshader != 0u) { | 38 if (glshader != 0u) { |
| 47 result = Opaque::Create(args.isolate(), glshader); | 39 result = Opaque::Create(args.isolate(), glshader); |
| 48 } | 40 } |
| 49 return result; | 41 return result; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 71 Context::Context(uint64_t encoded, int width, int height) | 63 Context::Context(uint64_t encoded, int width, int height) |
| 72 : encoded_(encoded) { | 64 : encoded_(encoded) { |
| 73 // TODO(aa): When we want to support multiple contexts, we should add | 65 // TODO(aa): When we want to support multiple contexts, we should add |
| 74 // Context::MakeCurrent() for developers to switch between them. | 66 // Context::MakeCurrent() for developers to switch between them. |
| 75 MojoGLES2MakeCurrent(encoded_); | 67 MojoGLES2MakeCurrent(encoded_); |
| 76 } | 68 } |
| 77 | 69 |
| 78 } // namespace gl | 70 } // namespace gl |
| 79 } // namespace js | 71 } // namespace js |
| 80 } // namespace mojo | 72 } // namespace mojo |
| OLD | NEW |