| 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/array_buffer.h" | 10 #include "gin/array_buffer.h" |
| 11 #include "gin/object_template_builder.h" | 11 #include "gin/object_template_builder.h" |
| 12 #include "gin/per_context_data.h" | 12 #include "gin/per_context_data.h" |
| 13 #include "mojo/public/c/gles2/gles2.h" | 13 #include "mojo/public/c/gles2/gles2.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" |
| 14 | 15 |
| 15 namespace gin { | 16 namespace gin { |
| 16 template<> | 17 template<> |
| 17 struct Converter<GLboolean> { | 18 struct Converter<GLboolean> { |
| 18 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 19 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
| 19 GLboolean* out) { | 20 GLboolean* out) { |
| 20 bool bool_val = false; | 21 bool bool_val = false; |
| 21 if (!Converter<bool>::FromV8(isolate, val, &bool_val)) | 22 if (!Converter<bool>::FromV8(isolate, val, &bool_val)) |
| 22 return false; | 23 return false; |
| 23 *out = static_cast<GLboolean>(bool_val); | 24 *out = static_cast<GLboolean>(bool_val); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 .SetMethod("vertexAttribPointer", VertexAttribPointer) | 148 .SetMethod("vertexAttribPointer", VertexAttribPointer) |
| 148 .SetMethod("viewport", glViewport); | 149 .SetMethod("viewport", glViewport); |
| 149 } | 150 } |
| 150 | 151 |
| 151 Context::Context(v8::Isolate* isolate, | 152 Context::Context(v8::Isolate* isolate, |
| 152 mojo::Handle handle, | 153 mojo::Handle handle, |
| 153 v8::Handle<v8::Function> context_lost_callback) { | 154 v8::Handle<v8::Function> context_lost_callback) { |
| 154 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 155 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| 155 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); | 156 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); |
| 156 context_lost_callback_.Reset(isolate, context_lost_callback); | 157 context_lost_callback_.Reset(isolate, context_lost_callback); |
| 157 context_ = MojoGLES2CreateContext( | 158 context_ = MojoGLES2CreateContext(handle.value(), |
| 158 handle.value(), | 159 &ContextLostThunk, |
| 159 &ContextLostThunk, | 160 this, |
| 160 this); | 161 Environment::GetDefaultAsyncWaiter()); |
| 161 MojoGLES2MakeCurrent(context_); | 162 MojoGLES2MakeCurrent(context_); |
| 162 } | 163 } |
| 163 | 164 |
| 164 Context::~Context() { | 165 Context::~Context() { |
| 165 MojoGLES2DestroyContext(context_); | 166 MojoGLES2DestroyContext(context_); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void Context::ContextLost() { | 169 void Context::ContextLost() { |
| 169 if (!runner_) | 170 if (!runner_) |
| 170 return; | 171 return; |
| 171 gin::Runner::Scope scope(runner_.get()); | 172 gin::Runner::Scope scope(runner_.get()); |
| 172 v8::Isolate* isolate = runner_->GetContextHolder()->isolate(); | 173 v8::Isolate* isolate = runner_->GetContextHolder()->isolate(); |
| 173 | 174 |
| 174 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( | 175 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( |
| 175 isolate, context_lost_callback_); | 176 isolate, context_lost_callback_); |
| 176 | 177 |
| 177 runner_->Call(callback, runner_->global(), 0, NULL); | 178 runner_->Call(callback, runner_->global(), 0, NULL); |
| 178 } | 179 } |
| 179 | 180 |
| 180 void Context::ContextLostThunk(void* closure) { | 181 void Context::ContextLostThunk(void* closure) { |
| 181 static_cast<Context*>(closure)->ContextLost(); | 182 static_cast<Context*>(closure)->ContextLost(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace gl | 185 } // namespace gl |
| 185 } // namespace js | 186 } // namespace js |
| 186 } // namespace mojo | 187 } // namespace mojo |
| OLD | NEW |