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 3 // found in the LICENSE file. 4 5 define([ 6 "console", 7 "mojo/apps/js/bindings/connector", 8 "mojo/apps/js/bindings/core", 9 "mojo/apps/js/bindings/gl", 10 "mojo/apps/js/bindings/threading", 11 "mojom/native_viewport", 12 "mojom/gles2", 13 ], function(console, 14 connector, 15 core, 16 gljs, 17 threading, 18 nativeViewport, 19 gles2) { 20 21 const VERTEX_SHADER_SOURCE = 22 "uniform mat4 u_mvpMatrix; \n" + 23 "attribute vec4 a_position; \n" + 24 "void main() \n" + 25 "{ \n" + 26 " gl_Position = u_mvpMatrix * a_position; \n" + 27 "} \n"; 28 29 function NativeViewportClientImpl() { 30 } 31 32 // TODO(aa): It is a bummer to need this stub object in JavaScript. We should 33 // have a 'client' object that contains both the sending and receiving bits of 34 // the client side of the interface. Since JS is loosely typed, we do not need 35 // a separate base class to inherit from to receive callbacks. 36 NativeViewportClientImpl.prototype = 37 Object.create(nativeViewport.NativeViewportClientStub.prototype); 38 39 NativeViewportClientImpl.prototype.didOpen = function() { 40 console.log("NativeViewportClientImpl.prototype.DidOpen"); 41 }; 42 43 44 function GLES2ClientImpl() { 45 } 46 47 GLES2ClientImpl.prototype = 48 Object.create(gles2.GLES2ClientStub.prototype); 49 50 GLES2ClientImpl.prototype.didCreateContext = function(encoded, 51 width, 52 height) { 53 console.log("GLES2ClientImpl.prototype.didCreateContext"); 54 var gl = new gljs.Context(encoded, width, height); 55 56 var shader = gl.createShader(gl.VERTEX_SHADER); 57 console.log("shader is: ", String(shader)); 58 gl.shaderSource(shader, VERTEX_SHADER_SOURCE); 59 gl.compileShader(shader); 60 console.log("all done"); 61 }; 62 63 GLES2ClientImpl.prototype.contextLost = function() { 64 console.log("GLES2ClientImpl.prototype.contextLost"); 65 }; 66 67 return function(handle) { 68 var nativeViewportConnection = new connector.Connection( 69 handle, 70 NativeViewportClientImpl, 71 nativeViewport.NativeViewportProxy); 72 73 var gles2Handles = core.createMessagePipe(); 74 var gles2Connection = new connector.Connection( 75 gles2Handles.handle0, GLES2ClientImpl, gles2.GLES2Proxy); 76 77 nativeViewportConnection.remote.open(); 78 nativeViewportConnection.remote.createGLES2Context(gles2Handles.handle1); 79 }; 80 }); 81