| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 &DidCreateContextThunk, | 159 &DidCreateContextThunk, |
| 160 &ContextLostThunk, | 160 &ContextLostThunk, |
| 161 NULL, | 161 NULL, |
| 162 this); | 162 this); |
| 163 } | 163 } |
| 164 | 164 |
| 165 Context::~Context() { | 165 Context::~Context() { |
| 166 MojoGLES2DestroyContext(context_); | 166 MojoGLES2DestroyContext(context_); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void Context::DidCreateContext(uint32_t width, uint32_t height) { | 169 void Context::DidCreateContext() { |
| 170 // TODO(aa): When we want to support multiple contexts, we should add | 170 // TODO(aa): When we want to support multiple contexts, we should add |
| 171 // Context::MakeCurrent() for developers to switch between them. | 171 // Context::MakeCurrent() for developers to switch between them. |
| 172 MojoGLES2MakeCurrent(context_); | 172 MojoGLES2MakeCurrent(context_); |
| 173 if (!runner_) | 173 if (!runner_) |
| 174 return; | 174 return; |
| 175 gin::Runner::Scope scope(runner_.get()); | 175 gin::Runner::Scope scope(runner_.get()); |
| 176 v8::Isolate* isolate = runner_->isolate(); | 176 v8::Isolate* isolate = runner_->isolate(); |
| 177 | 177 |
| 178 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( | 178 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( |
| 179 isolate, did_create_callback_); | 179 isolate, did_create_callback_); |
| 180 | 180 |
| 181 v8::Handle<v8::Value> args[] = { | 181 runner_->Call(callback, runner_->global(), 0, NULL); |
| 182 gin::ConvertToV8(isolate, width), | |
| 183 gin::ConvertToV8(isolate, height), | |
| 184 }; | |
| 185 runner_->Call(callback, runner_->global(), 2, args); | |
| 186 } | 182 } |
| 187 | 183 |
| 188 void Context::DidCreateContextThunk( | 184 void Context::DidCreateContextThunk(void* closure) { |
| 189 void* closure, | 185 static_cast<Context*>(closure)->DidCreateContext(); |
| 190 uint32_t width, | |
| 191 uint32_t height) { | |
| 192 static_cast<Context*>(closure)->DidCreateContext(width, height); | |
| 193 } | 186 } |
| 194 | 187 |
| 195 void Context::ContextLost() { | 188 void Context::ContextLost() { |
| 196 } | 189 } |
| 197 | 190 |
| 198 void Context::ContextLostThunk(void* closure) { | 191 void Context::ContextLostThunk(void* closure) { |
| 199 static_cast<Context*>(closure)->ContextLost(); | 192 static_cast<Context*>(closure)->ContextLost(); |
| 200 } | 193 } |
| 201 | 194 |
| 202 } // namespace gl | 195 } // namespace gl |
| 203 } // namespace js | 196 } // namespace js |
| 204 } // namespace mojo | 197 } // namespace mojo |
| OLD | NEW |