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

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: rebase, fix various issues Created 6 years, 10 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
« no previous file with comments | « mojo/apps/js/bindings/gl/context.cc ('k') | mojo/examples/aura_demo/aura_demo.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 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 var rect = new nativeViewport.Rect;
301 rect.position = new nativeViewport.Point;
302 rect.size = new nativeViewport.Size;
303 rect.size.width = 800;
304 rect.size.height = 600;
305 this.remote_.create(rect);
306 this.remote_.show();
301 this.remote_.createGLES2Context(pipe.handle1); 307 this.remote_.createGLES2Context(pipe.handle1);
302 } 308 }
303 NativeViewportClientImpl.prototype = 309 NativeViewportClientImpl.prototype =
304 Object.create(nativeViewport.NativeViewportClientStub.prototype); 310 Object.create(nativeViewport.NativeViewportClientStub.prototype);
305 311
306 NativeViewportClientImpl.prototype.onCreated = function() { 312 NativeViewportClientImpl.prototype.onCreated = function() {
307 console.log('NativeViewportClientImpl.prototype.OnCreated'); 313 console.log('NativeViewportClientImpl.prototype.OnCreated');
308 }; 314 };
309 NativeViewportClientImpl.prototype.didOpen = function() {
310 console.log('NativeViewportClientImpl.prototype.DidOpen');
311 };
312 315
316 NativeViewportClientImpl.prototype.onBoundsChanged = function(bounds) {
317 console.log('NativeViewportClientImpl.prototype.OnBoundsChanged');
318 this.gles2_.setDimensions(bounds.size);
319 }
313 320
314 function GLES2ClientImpl(remotePipe) { 321 function GLES2ClientImpl(remotePipe) {
315 this.gl_ = new gljs.Context(remotePipe, this.didCreateContext.bind(this)); 322 this.gl_ = new gljs.Context(remotePipe, this.didCreateContext.bind(this));
316 this.lastTime_ = monotonicClock.seconds(); 323 this.lastTime_ = monotonicClock.seconds();
317 this.angle_ = 45; 324 this.angle_ = 45;
318 } 325 }
319 326
320 GLES2ClientImpl.prototype.didCreateContext = function(width, height) { 327 GLES2ClientImpl.prototype.didCreateContext = function() {
321 this.width_ = width;
322 this.height_ = height;
323 this.program_ = loadProgram(this.gl_); 328 this.program_ = loadProgram(this.gl_);
324 this.positionLocation_ = 329 this.positionLocation_ =
325 this.gl_.getAttribLocation(this.program_, 'a_position'); 330 this.gl_.getAttribLocation(this.program_, 'a_position');
326 this.mvpLocation_ = 331 this.mvpLocation_ =
327 this.gl_.getUniformLocation(this.program_, 'u_mvpMatrix'); 332 this.gl_.getUniformLocation(this.program_, 'u_mvpMatrix');
328 this.numIndices_ = generateCube(this.gl_); 333 this.numIndices_ = generateCube(this.gl_);
329 this.mvpMatrix_ = new ESMatrix(); 334 this.mvpMatrix_ = new ESMatrix();
330 this.mvpMatrix_.loadIdentity(); 335 this.mvpMatrix_.loadIdentity();
331 336
332 this.gl_.clearColor(0, 0, 0, 0); 337 this.gl_.clearColor(0, 0, 0, 0);
333 this.timer_ = timer.createRepeating(16, this.handleTimer.bind(this)); 338 this.timer_ = timer.createRepeating(16, this.handleTimer.bind(this));
334 }; 339 };
335 340
341 GLES2ClientImpl.prototype.setDimensions = function(size) {
342 this.width_ = size.width;
343 this.height_ = size.height;
344 }
345
336 GLES2ClientImpl.prototype.drawCube = function() { 346 GLES2ClientImpl.prototype.drawCube = function() {
347 if (!this.width_ || !this.height_)
348 return;
337 this.gl_.viewport(0, 0, this.width_, this.height_); 349 this.gl_.viewport(0, 0, this.width_, this.height_);
338 this.gl_.clear(this.gl_.COLOR_BUFFER_BIT); 350 this.gl_.clear(this.gl_.COLOR_BUFFER_BIT);
339 this.gl_.useProgram(this.program_); 351 this.gl_.useProgram(this.program_);
340 this.gl_.bindBuffer(this.gl_.ARRAY_BUFFER, vboVertices); 352 this.gl_.bindBuffer(this.gl_.ARRAY_BUFFER, vboVertices);
341 this.gl_.bindBuffer(this.gl_.ELEMENT_ARRAY_BUFFER, vboIndices); 353 this.gl_.bindBuffer(this.gl_.ELEMENT_ARRAY_BUFFER, vboIndices);
342 this.gl_.vertexAttribPointer(this.positionLocation_, 3, this.gl_.FLOAT, 354 this.gl_.vertexAttribPointer(this.positionLocation_, 3, this.gl_.FLOAT,
343 false, 12, 0); 355 false, 12, 0);
344 this.gl_.enableVertexAttribArray(this.positionLocation_); 356 this.gl_.enableVertexAttribArray(this.positionLocation_);
345 this.gl_.uniformMatrix4fv(this.mvpLocation_, false, this.mvpMatrix_.m); 357 this.gl_.uniformMatrix4fv(this.mvpLocation_, false, this.mvpMatrix_.m);
346 this.gl_.drawElements(this.gl_.TRIANGLES, this.numIndices_, 358 this.gl_.drawElements(this.gl_.TRIANGLES, this.numIndices_,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 390
379 GLES2ClientImpl.prototype.contextLost = function() { 391 GLES2ClientImpl.prototype.contextLost = function() {
380 console.log('GLES2ClientImpl.prototype.contextLost'); 392 console.log('GLES2ClientImpl.prototype.contextLost');
381 }; 393 };
382 394
383 395
384 return function(handle) { 396 return function(handle) {
385 new connector.Connection(handle, SampleApp, shell.ShellProxy); 397 new connector.Connection(handle, SampleApp, shell.ShellProxy);
386 }; 398 };
387 }); 399 });
OLDNEW
« no previous file with comments | « mojo/apps/js/bindings/gl/context.cc ('k') | mojo/examples/aura_demo/aura_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698