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

Side by Side Diff: mojo/apps/js/main.js

Issue 129633005: Introduce a monotonic_clock module for Mojo.js. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
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 define([ 5 define([
6 'console', 6 'console',
7 'monotonic_clock',
7 'timer', 8 'timer',
8 'mojo/apps/js/bindings/connector', 9 'mojo/apps/js/bindings/connector',
9 'mojo/apps/js/bindings/core', 10 'mojo/apps/js/bindings/core',
10 'mojo/apps/js/bindings/gl', 11 'mojo/apps/js/bindings/gl',
11 'mojo/apps/js/bindings/threading', 12 'mojo/apps/js/bindings/threading',
12 'mojom/native_viewport', 13 'mojom/native_viewport',
13 'mojom/gles2', 14 'mojom/gles2',
14 'mojom/shell', 15 'mojom/shell',
15 ], function(console, 16 ], function(console,
17 monotonicClock,
16 timer, 18 timer,
17 connector, 19 connector,
18 core, 20 core,
19 gljs, 21 gljs,
20 threading, 22 threading,
21 nativeViewport, 23 nativeViewport,
22 gles2, 24 gles2,
23 shell) { 25 shell) {
24 26
25 const VERTEX_SHADER_SOURCE = [ 27 const VERTEX_SHADER_SOURCE = [
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 NativeViewportClientImpl.prototype.onCreated = function() { 308 NativeViewportClientImpl.prototype.onCreated = function() {
307 console.log('NativeViewportClientImpl.prototype.OnCreated'); 309 console.log('NativeViewportClientImpl.prototype.OnCreated');
308 }; 310 };
309 NativeViewportClientImpl.prototype.didOpen = function() { 311 NativeViewportClientImpl.prototype.didOpen = function() {
310 console.log('NativeViewportClientImpl.prototype.DidOpen'); 312 console.log('NativeViewportClientImpl.prototype.DidOpen');
311 }; 313 };
312 314
313 315
314 function GLES2ClientImpl(remote) { 316 function GLES2ClientImpl(remote) {
315 this.remote_ = remote; 317 this.remote_ = remote;
316 this.lastTime_ = Date.now(); 318 this.lastTime_ = monotonicClock.seconds();
317 this.angle_ = 45; 319 this.angle_ = 45;
318 } 320 }
319 GLES2ClientImpl.prototype = 321 GLES2ClientImpl.prototype =
320 Object.create(gles2.GLES2ClientStub.prototype); 322 Object.create(gles2.GLES2ClientStub.prototype);
321 323
322 GLES2ClientImpl.prototype.didCreateContext = function(encoded, 324 GLES2ClientImpl.prototype.didCreateContext = function(encoded,
323 width, 325 width,
324 height) { 326 height) {
325 this.width_ = width; 327 this.width_ = width;
326 this.height_ = height; 328 this.height_ = height;
(...skipping 20 matching lines...) Expand all
347 this.gl_.vertexAttribPointer(this.positionLocation_, 3, this.gl_.FLOAT, 349 this.gl_.vertexAttribPointer(this.positionLocation_, 3, this.gl_.FLOAT,
348 false, 12, 0); 350 false, 12, 0);
349 this.gl_.enableVertexAttribArray(this.positionLocation_); 351 this.gl_.enableVertexAttribArray(this.positionLocation_);
350 this.gl_.uniformMatrix4fv(this.mvpLocation_, false, this.mvpMatrix_.m); 352 this.gl_.uniformMatrix4fv(this.mvpLocation_, false, this.mvpMatrix_.m);
351 this.gl_.drawElements(this.gl_.TRIANGLES, this.numIndices_, 353 this.gl_.drawElements(this.gl_.TRIANGLES, this.numIndices_,
352 this.gl_.UNSIGNED_SHORT, 0); 354 this.gl_.UNSIGNED_SHORT, 0);
353 this.gl_.swapBuffers(); 355 this.gl_.swapBuffers();
354 }; 356 };
355 357
356 GLES2ClientImpl.prototype.handleTimer = function() { 358 GLES2ClientImpl.prototype.handleTimer = function() {
357 var now = Date.now(); 359 var now = monotonicClock.seconds();
358 var timeDelta = Date.now() - this.lastTime_; 360 var secondsDelta = now - this.lastTime_;
359 this.lastTime_ = now; 361 this.lastTime_ = now;
360 362
361 this.angle_ += this.getRotationForTimeDelgate(timeDelta); 363 this.angle_ += this.getRotationForTimeDelta(secondsDelta);
362 this.angle_ = this.angle_ % 360; 364 this.angle_ = this.angle_ % 360;
363 365
364 var aspect = this.width_ / this.height_; 366 var aspect = this.width_ / this.height_;
365 367
366 var perspective = new ESMatrix(); 368 var perspective = new ESMatrix();
367 perspective.loadIdentity(); 369 perspective.loadIdentity();
368 perspective.perspective(60, aspect, 1, 20); 370 perspective.perspective(60, aspect, 1, 20);
369 371
370 var modelView = new ESMatrix(); 372 var modelView = new ESMatrix();
371 modelView.loadIdentity(); 373 modelView.loadIdentity();
372 modelView.translate(0, 0, -2); 374 modelView.translate(0, 0, -2);
373 modelView.rotate(this.angle_, 1, 0, 1); 375 modelView.rotate(this.angle_, 1, 0, 1);
374 376
375 this.mvpMatrix_.multiply(modelView, perspective); 377 this.mvpMatrix_.multiply(modelView, perspective);
376 378
377 this.drawCube(); 379 this.drawCube();
378 }; 380 };
379 381
380 GLES2ClientImpl.prototype.getRotationForTimeDelgate = function(timeDelta) { 382 GLES2ClientImpl.prototype.getRotationForTimeDelta = function(secondsDelta) {
381 return timeDelta * .04; 383 return secondsDelta * 40;
382 }; 384 };
383 385
384 GLES2ClientImpl.prototype.contextLost = function() { 386 GLES2ClientImpl.prototype.contextLost = function() {
385 console.log('GLES2ClientImpl.prototype.contextLost'); 387 console.log('GLES2ClientImpl.prototype.contextLost');
386 }; 388 };
387 389
388 390
389 return function(handle) { 391 return function(handle) {
390 new connector.Connection(handle, SampleApp, shell.ShellProxy); 392 new connector.Connection(handle, SampleApp, shell.ShellProxy);
391 }; 393 };
392 }); 394 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698