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

Side by Side Diff: mojo/apps/js/bindings/codec.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 | « no previous file | mojo/apps/js/bindings/gl/context.h » ('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(function() { 5 define(function() {
6 6
7 // Memory ------------------------------------------------------------------- 7 // Memory -------------------------------------------------------------------
8 8
9 function store8(memory, pointer, val) { 9 function store8(memory, pointer, val) {
10 memory[pointer] = val; 10 memory[pointer] = val;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Decoder ------------------------------------------------------------------ 88 // Decoder ------------------------------------------------------------------
89 89
90 function Decoder(memory, handles, base) { 90 function Decoder(memory, handles, base) {
91 this.memory = memory; 91 this.memory = memory;
92 this.handles = handles; 92 this.handles = handles;
93 this.base = base; 93 this.base = base;
94 this.next = base; 94 this.next = base;
95 this.viewU32 = new Uint32Array( 95 this.viewU32 = new Uint32Array(
96 this.memory.buffer, 0, 96 this.memory.buffer, 0,
97 Math.floor(this.memory.length / Uint32Array.BYTES_PER_ELEMENT)); 97 Math.floor(this.memory.length / Uint32Array.BYTES_PER_ELEMENT));
98 this.viewFloat = new Float32Array(
99 this.memory.buffer, 0,
100 Math.floor(this.memory.length / Float32Array.BYTES_PER_ELEMENT));
98 } 101 }
99 102
100 Decoder.prototype.skip = function(offset) { 103 Decoder.prototype.skip = function(offset) {
101 this.next += offset; 104 this.next += offset;
102 }; 105 };
103 106
104 Decoder.prototype.read8 = function() { 107 Decoder.prototype.read8 = function() {
105 var result = load8(this.memory, this.next); 108 var result = load8(this.memory, this.next);
106 this.next += 1; 109 this.next += 1;
107 return result; 110 return result;
108 }; 111 };
109 112
110 Decoder.prototype.read32 = function() { 113 Decoder.prototype.read32 = function() {
111 var result = this.viewU32[this.next / this.viewU32.BYTES_PER_ELEMENT]; 114 var result = this.viewU32[this.next / this.viewU32.BYTES_PER_ELEMENT];
112 this.next += this.viewU32.BYTES_PER_ELEMENT; 115 this.next += this.viewU32.BYTES_PER_ELEMENT;
113 return result; 116 return result;
114 }; 117 };
115 118
116 Decoder.prototype.read64 = function() { 119 Decoder.prototype.read64 = function() {
117 var low = this.read32(); 120 var low = this.read32();
118 var high = this.read32(); 121 var high = this.read32();
119 return low + high * 0x100000000; 122 return low + high * 0x100000000;
120 }; 123 };
121 124
125 Decoder.prototype.decodeFloat = function() {
126 var result = this.viewFloat[this.next / this.viewFloat.BYTES_PER_ELEMENT];
127 this.next += this.viewFloat.BYTES_PER_ELEMENT;
128 return result;
129 };
130
122 Decoder.prototype.decodePointer = function() { 131 Decoder.prototype.decodePointer = function() {
123 // TODO(abarth): To correctly decode a pointer, we need to know the real 132 // TODO(abarth): To correctly decode a pointer, we need to know the real
124 // base address of the array buffer. 133 // base address of the array buffer.
125 var offsetPointer = this.next; 134 var offsetPointer = this.next;
126 var offset = this.read64(); 135 var offset = this.read64();
127 if (!offset) 136 if (!offset)
128 return 0; 137 return 0;
129 return offsetPointer + offset; 138 return offsetPointer + offset;
130 }; 139 };
131 140
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Encoder.prototype.write32 = function(val) { 205 Encoder.prototype.write32 = function(val) {
197 store32(this.buffer.memory, this.next, val); 206 store32(this.buffer.memory, this.next, val);
198 this.next += 4; 207 this.next += 4;
199 }; 208 };
200 209
201 Encoder.prototype.write64 = function(val) { 210 Encoder.prototype.write64 = function(val) {
202 store64(this.buffer.memory, this.next, val); 211 store64(this.buffer.memory, this.next, val);
203 this.next += 8; 212 this.next += 8;
204 }; 213 };
205 214
215 Encoder.prototype.encodeFloat = function(val) {
216 var floatBuffer = new Float32Array(1);
217 floatBuffer[0] = val;
218 var buffer = new Uint8Array(floatBuffer.buffer, 0);
219 for (var i = 0; i < buffer.length; ++i)
220 this.buffer.memory[this.next++] = buffer[i];
221 };
222
206 Encoder.prototype.encodePointer = function(pointer) { 223 Encoder.prototype.encodePointer = function(pointer) {
207 if (!pointer) 224 if (!pointer)
208 return this.write64(0); 225 return this.write64(0);
209 // TODO(abarth): To correctly encode a pointer, we need to know the real 226 // TODO(abarth): To correctly encode a pointer, we need to know the real
210 // base address of the array buffer. 227 // base address of the array buffer.
211 var offset = pointer - this.next; 228 var offset = pointer - this.next;
212 this.write64(offset); 229 this.write64(offset);
213 }; 230 };
214 231
215 Encoder.prototype.createAndEncodeEncoder = function(size) { 232 Encoder.prototype.createAndEncodeEncoder = function(size) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 exports.kMessageHeaderSize = kMessageHeaderSize; 450 exports.kMessageHeaderSize = kMessageHeaderSize;
434 exports.Uint8 = Uint8; 451 exports.Uint8 = Uint8;
435 exports.Uint16 = Uint16; 452 exports.Uint16 = Uint16;
436 exports.Uint32 = Uint32; 453 exports.Uint32 = Uint32;
437 exports.Uint64 = Uint64; 454 exports.Uint64 = Uint64;
438 exports.PointerTo = PointerTo; 455 exports.PointerTo = PointerTo;
439 exports.ArrayOf = ArrayOf; 456 exports.ArrayOf = ArrayOf;
440 exports.Handle = Handle; 457 exports.Handle = Handle;
441 return exports; 458 return exports;
442 }); 459 });
OLDNEW
« no previous file with comments | « no previous file | mojo/apps/js/bindings/gl/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698