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

Side by Side Diff: services/js/modules/gl/context.cc

Issue 788863003: Restore the JS Spinning Cube demo (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Changes per review feedback Created 6 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
« no previous file with comments | « services/js/modules/gl/context.h ('k') | services/js/modules/gl/module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/js/modules/gl/context.h" 5 #include "services/js/modules/gl/context.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h>
8 9
10 #include "base/bind.h"
9 #include "gin/arguments.h" 11 #include "gin/arguments.h"
10 #include "gin/array_buffer.h" 12 #include "gin/array_buffer.h"
11 #include "gin/object_template_builder.h" 13 #include "gin/object_template_builder.h"
12 #include "gin/per_context_data.h" 14 #include "gin/per_context_data.h"
15 #include "gpu/command_buffer/client/gles2_interface.h"
13 #include "mojo/public/c/gles2/gles2.h" 16 #include "mojo/public/c/gles2/gles2.h"
14 #include "mojo/public/cpp/environment/environment.h" 17 #include "mojo/public/cpp/environment/environment.h"
15 18
16 namespace gin { 19 namespace gin {
17 template<> 20 template<>
18 struct Converter<GLboolean> { 21 struct Converter<GLboolean> {
19 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, 22 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
20 GLboolean* out) { 23 GLboolean* out) {
21 bool bool_val = false; 24 bool bool_val = false;
22 if (!Converter<bool>::FromV8(isolate, val, &bool_val)) 25 if (!Converter<bool>::FromV8(isolate, val, &bool_val))
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 .SetMethod("createProgram", glCreateProgram) 136 .SetMethod("createProgram", glCreateProgram)
134 .SetMethod("createShader", glCreateShader) 137 .SetMethod("createShader", glCreateShader)
135 .SetMethod("deleteShader", glDeleteShader) 138 .SetMethod("deleteShader", glDeleteShader)
136 .SetMethod("drawElements", DrawElements) 139 .SetMethod("drawElements", DrawElements)
137 .SetMethod("enableVertexAttribArray", glEnableVertexAttribArray) 140 .SetMethod("enableVertexAttribArray", glEnableVertexAttribArray)
138 .SetMethod("getAttribLocation", GetAttribLocation) 141 .SetMethod("getAttribLocation", GetAttribLocation)
139 .SetMethod("getProgramInfoLog", GetProgramInfoLog) 142 .SetMethod("getProgramInfoLog", GetProgramInfoLog)
140 .SetMethod("getShaderInfoLog", GetShaderInfoLog) 143 .SetMethod("getShaderInfoLog", GetShaderInfoLog)
141 .SetMethod("getUniformLocation", GetUniformLocation) 144 .SetMethod("getUniformLocation", GetUniformLocation)
142 .SetMethod("linkProgram", glLinkProgram) 145 .SetMethod("linkProgram", glLinkProgram)
146 .SetMethod("resize", base::Bind(&Context::Resize, base::Unretained(this)))
143 .SetMethod("shaderSource", ShaderSource) 147 .SetMethod("shaderSource", ShaderSource)
144 .SetMethod("swapBuffers", MojoGLES2SwapBuffers) 148 .SetMethod("swapBuffers", MojoGLES2SwapBuffers)
145 .SetMethod("uniformMatrix4fv", UniformMatrix4fv) 149 .SetMethod("uniformMatrix4fv", UniformMatrix4fv)
146 .SetMethod("useProgram", glUseProgram) 150 .SetMethod("useProgram", glUseProgram)
147 .SetMethod("vertexAttribPointer", VertexAttribPointer) 151 .SetMethod("vertexAttribPointer", VertexAttribPointer)
148 .SetMethod("viewport", glViewport); 152 .SetMethod("viewport", glViewport);
149 } 153 }
150 154
151 Context::Context(v8::Isolate* isolate, 155 Context::Context(v8::Isolate* isolate,
152 mojo::Handle handle, 156 mojo::Handle handle,
153 v8::Handle<v8::Function> context_lost_callback) { 157 v8::Handle<v8::Function> context_lost_callback) {
154 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); 158 v8::Handle<v8::Context> context = isolate->GetCurrentContext();
155 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); 159 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
156 context_lost_callback_.Reset(isolate, context_lost_callback); 160 context_lost_callback_.Reset(isolate, context_lost_callback);
157 context_ = MojoGLES2CreateContext(handle.value(), 161 context_ = MojoGLES2CreateContext(handle.value(),
158 &ContextLostThunk, 162 &ContextLostThunk,
159 this, 163 this,
160 mojo::Environment::GetDefaultAsyncWaiter()); 164 mojo::Environment::GetDefaultAsyncWaiter());
161 MojoGLES2MakeCurrent(context_); 165 MojoGLES2MakeCurrent(context_);
162 } 166 }
163 167
164 Context::~Context() { 168 Context::~Context() {
165 MojoGLES2DestroyContext(context_); 169 MojoGLES2DestroyContext(context_);
166 } 170 }
167 171
172 void Context::Resize(GLuint width, GLuint height, GLfloat scale_factor) {
173 static_cast<gpu::gles2::GLES2Interface*>(
174 MojoGLES2GetGLES2Interface(context_))->ResizeCHROMIUM(width,
175 height,
176 scale_factor);
177 }
178
168 void Context::ContextLost() { 179 void Context::ContextLost() {
169 if (!runner_) 180 if (!runner_)
170 return; 181 return;
171 gin::Runner::Scope scope(runner_.get()); 182 gin::Runner::Scope scope(runner_.get());
172 v8::Isolate* isolate = runner_->GetContextHolder()->isolate(); 183 v8::Isolate* isolate = runner_->GetContextHolder()->isolate();
173 184
174 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( 185 v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New(
175 isolate, context_lost_callback_); 186 isolate, context_lost_callback_);
176 187
177 runner_->Call(callback, runner_->global(), 0, NULL); 188 runner_->Call(callback, runner_->global(), 0, NULL);
178 } 189 }
179 190
180 void Context::ContextLostThunk(void* closure) { 191 void Context::ContextLostThunk(void* closure) {
181 static_cast<Context*>(closure)->ContextLost(); 192 static_cast<Context*>(closure)->ContextLost();
182 } 193 }
183 194
184 } // namespace gl 195 } // namespace gl
185 } // namespace js 196 } // namespace js
OLDNEW
« no previous file with comments | « services/js/modules/gl/context.h ('k') | services/js/modules/gl/module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698