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

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

Issue 131153007: Send size to NativeViewportClient::OnCreated instead of GLES2Client::DidCreateContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix TODO 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 'monotonic_clock',
8 'timer', 8 'timer',
9 'mojo/apps/js/bindings/connector', 9 'mojo/apps/js/bindings/connector',
10 'mojo/apps/js/bindings/core', 10 'mojo/apps/js/bindings/core',
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // have a 'client' object that contains both the sending and receiving bits of 288 // have a 'client' object that contains both the sending and receiving bits of
289 // the client side of the interface. Since JS is loosely typed, we do not need 289 // the client side of the interface. Since JS is loosely typed, we do not need
290 // a separate base class to inherit from to receive callbacks. 290 // a separate base class to inherit from to receive callbacks.
291 SampleApp.prototype = Object.create(shell.ShellClientStub.prototype); 291 SampleApp.prototype = Object.create(shell.ShellClientStub.prototype);
292 292
293 293
294 function NativeViewportClientImpl(remote) { 294 function NativeViewportClientImpl(remote) {
295 this.remote_ = remote; 295 this.remote_ = remote;
296 296
297 var pipe = core.createMessagePipe(); 297 var pipe = core.createMessagePipe();
298 new GLES2ClientImpl(pipe.handle0); 298 this.gles2_ = new GLES2ClientImpl(pipe.handle0);
299 299
300 this.remote_.open(); 300 this.remote_.open();
301 this.remote_.createGLES2Context(pipe.handle1); 301 this.remote_.createGLES2Context(pipe.handle1);
302 } 302 }
303 NativeViewportClientImpl.prototype = 303 NativeViewportClientImpl.prototype =
304 Object.create(nativeViewport.NativeViewportClientStub.prototype); 304 Object.create(nativeViewport.NativeViewportClientStub.prototype);
305 305
306 NativeViewportClientImpl.prototype.onCreated = function() { 306 NativeViewportClientImpl.prototype.onCreated = function(width, height) {
307 this.gles2_.setDimensions(width, height);
307 console.log('NativeViewportClientImpl.prototype.OnCreated'); 308 console.log('NativeViewportClientImpl.prototype.OnCreated');
308 }; 309 };
309 NativeViewportClientImpl.prototype.didOpen = function() { 310 NativeViewportClientImpl.prototype.didOpen = function() {
310 console.log('NativeViewportClientImpl.prototype.DidOpen'); 311 console.log('NativeViewportClientImpl.prototype.DidOpen');
311 }; 312 };
312 313
313 314
314 function GLES2ClientImpl(remotePipe) { 315 function GLES2ClientImpl(remotePipe) {
315 this.gl_ = new gljs.Context(remotePipe, this.didCreateContext.bind(this)); 316 this.gl_ = new gljs.Context(remotePipe, this.didCreateContext.bind(this));
316 this.lastTime_ = monotonicClock.seconds(); 317 this.lastTime_ = monotonicClock.seconds();
317 this.angle_ = 45; 318 this.angle_ = 45;
318 } 319 }
319 320
320 GLES2ClientImpl.prototype.didCreateContext = function(width, height) { 321 GLES2ClientImpl.prototype.didCreateContext = function() {
321 this.width_ = width;
322 this.height_ = height;
323 this.program_ = loadProgram(this.gl_); 322 this.program_ = loadProgram(this.gl_);
324 this.positionLocation_ = 323 this.positionLocation_ =
325 this.gl_.getAttribLocation(this.program_, 'a_position'); 324 this.gl_.getAttribLocation(this.program_, 'a_position');
326 this.mvpLocation_ = 325 this.mvpLocation_ =
327 this.gl_.getUniformLocation(this.program_, 'u_mvpMatrix'); 326 this.gl_.getUniformLocation(this.program_, 'u_mvpMatrix');
328 this.numIndices_ = generateCube(this.gl_); 327 this.numIndices_ = generateCube(this.gl_);
329 this.mvpMatrix_ = new ESMatrix(); 328 this.mvpMatrix_ = new ESMatrix();
330 this.mvpMatrix_.loadIdentity(); 329 this.mvpMatrix_.loadIdentity();
331 330
332 this.gl_.clearColor(0, 0, 0, 0); 331 this.gl_.clearColor(0, 0, 0, 0);
333 this.timer_ = timer.createRepeating(16, this.handleTimer.bind(this)); 332 this.timer_ = timer.createRepeating(16, this.handleTimer.bind(this));
334 }; 333 };
335 334
335 GLES2ClientImpl.prototype.setDimensions = function(width, height) {
336 this.width_ = width;
337 this.height_ = height;
338 }
339
336 GLES2ClientImpl.prototype.drawCube = function() { 340 GLES2ClientImpl.prototype.drawCube = function() {
341 if (!this.width_ || !this.height_)
342 return;
337 this.gl_.viewport(0, 0, this.width_, this.height_); 343 this.gl_.viewport(0, 0, this.width_, this.height_);
338 this.gl_.clear(this.gl_.COLOR_BUFFER_BIT); 344 this.gl_.clear(this.gl_.COLOR_BUFFER_BIT);
339 this.gl_.useProgram(this.program_); 345 this.gl_.useProgram(this.program_);
340 this.gl_.bindBuffer(this.gl_.ARRAY_BUFFER, vboVertices); 346 this.gl_.bindBuffer(this.gl_.ARRAY_BUFFER, vboVertices);
341 this.gl_.bindBuffer(this.gl_.ELEMENT_ARRAY_BUFFER, vboIndices); 347 this.gl_.bindBuffer(this.gl_.ELEMENT_ARRAY_BUFFER, vboIndices);
342 this.gl_.vertexAttribPointer(this.positionLocation_, 3, this.gl_.FLOAT, 348 this.gl_.vertexAttribPointer(this.positionLocation_, 3, this.gl_.FLOAT,
343 false, 12, 0); 349 false, 12, 0);
344 this.gl_.enableVertexAttribArray(this.positionLocation_); 350 this.gl_.enableVertexAttribArray(this.positionLocation_);
345 this.gl_.uniformMatrix4fv(this.mvpLocation_, false, this.mvpMatrix_.m); 351 this.gl_.uniformMatrix4fv(this.mvpLocation_, false, this.mvpMatrix_.m);
346 this.gl_.drawElements(this.gl_.TRIANGLES, this.numIndices_, 352 this.gl_.drawElements(this.gl_.TRIANGLES, this.numIndices_,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 384
379 GLES2ClientImpl.prototype.contextLost = function() { 385 GLES2ClientImpl.prototype.contextLost = function() {
380 console.log('GLES2ClientImpl.prototype.contextLost'); 386 console.log('GLES2ClientImpl.prototype.contextLost');
381 }; 387 };
382 388
383 389
384 return function(handle) { 390 return function(handle) {
385 new connector.Connection(handle, SampleApp, shell.ShellProxy); 391 new connector.Connection(handle, SampleApp, shell.ShellProxy);
386 }; 392 };
387 }); 393 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698