| 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" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 Context::Context(v8::Isolate* isolate, | 151 Context::Context(v8::Isolate* isolate, |
| 152 mojo::Handle handle, | 152 mojo::Handle handle, |
| 153 v8::Handle<v8::Function> context_lost_callback) { | 153 v8::Handle<v8::Function> context_lost_callback) { |
| 154 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 154 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| 155 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); | 155 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); |
| 156 context_lost_callback_.Reset(isolate, context_lost_callback); | 156 context_lost_callback_.Reset(isolate, context_lost_callback); |
| 157 context_ = MojoGLES2CreateContext( | 157 context_ = MojoGLES2CreateContext( |
| 158 handle.value(), | 158 handle.value(), |
| 159 &ContextLostThunk, | 159 &ContextLostThunk, |
| 160 NULL, | |
| 161 this); | 160 this); |
| 162 MojoGLES2MakeCurrent(context_); | 161 MojoGLES2MakeCurrent(context_); |
| 163 } | 162 } |
| 164 | 163 |
| 165 Context::~Context() { | 164 Context::~Context() { |
| 166 MojoGLES2DestroyContext(context_); | 165 MojoGLES2DestroyContext(context_); |
| 167 } | 166 } |
| 168 | 167 |
| 169 void Context::ContextLost() { | 168 void Context::ContextLost() { |
| 170 if (!runner_) | 169 if (!runner_) |
| 171 return; | 170 return; |
| 172 gin::Runner::Scope scope(runner_.get()); | 171 gin::Runner::Scope scope(runner_.get()); |
| 173 v8::Isolate* isolate = runner_->GetContextHolder()->isolate(); | 172 v8::Isolate* isolate = runner_->GetContextHolder()->isolate(); |
| 174 | 173 |
| 175 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( | 174 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( |
| 176 isolate, context_lost_callback_); | 175 isolate, context_lost_callback_); |
| 177 | 176 |
| 178 runner_->Call(callback, runner_->global(), 0, NULL); | 177 runner_->Call(callback, runner_->global(), 0, NULL); |
| 179 } | 178 } |
| 180 | 179 |
| 181 void Context::ContextLostThunk(void* closure) { | 180 void Context::ContextLostThunk(void* closure) { |
| 182 static_cast<Context*>(closure)->ContextLost(); | 181 static_cast<Context*>(closure)->ContextLost(); |
| 183 } | 182 } |
| 184 | 183 |
| 185 } // namespace gl | 184 } // namespace gl |
| 186 } // namespace js | 185 } // namespace js |
| 187 } // namespace mojo | 186 } // namespace mojo |
| OLD | NEW |