Changeset 51049 in webkit
- Timestamp:
- Nov 16, 2009 1:30:15 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 53 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r51041 r51049 1 2009-11-16 Kenneth Russell <kbr@google.com> 2 3 Reviewed by Oliver Hunt. 4 5 Update API of WebGLArray and friends 6 https://bugs.webkit.org/show_bug.cgi?id=31175 7 8 * fast/canvas/webgl/array-unit-tests-expected.txt: 9 * fast/canvas/webgl/array-unit-tests.html: 10 1 11 2009-11-16 Alexey Proskuryakov <ap@apple.com> 2 12 -
trunk/LayoutTests/fast/canvas/webgl/array-unit-tests-expected.txt
r50725 r51049 4 4 5 5 PASS test WebGLByteArray SetAndGetPos10ToNeg10 6 PASS test WebGLByteArray SetAndGetMethodsPos10ToNeg10 6 7 PASS test WebGLByteArray ConstructWithArrayOfSignedValues 8 PASS test WebGLByteArray ConstructWithWebGLArrayOfSignedValues 9 PASS test WebGLByteArray OffsetsAndSizes 10 PASS test WebGLByteArray SetFromWebGLArray 11 PASS negativeTest WebGLByteArray SetFromWebGLArray 12 PASS test WebGLByteArray SetFromArray 13 PASS test WebGLByteArray Slice 14 PASS negativeTest WebGLByteArray Slice 7 15 PASS test WebGLByteArray BoundaryConditions(-128, -128, 127, 127) 8 16 PASS test WebGLFloatArray SetAndGetPos10ToNeg10 17 PASS test WebGLFloatArray SetAndGetMethodsPos10ToNeg10 9 18 PASS test WebGLFloatArray ConstructWithArrayOfSignedValues 19 PASS test WebGLFloatArray ConstructWithWebGLArrayOfSignedValues 20 PASS test WebGLFloatArray OffsetsAndSizes 21 PASS test WebGLFloatArray SetFromWebGLArray 22 PASS negativeTest WebGLFloatArray SetFromWebGLArray 23 PASS test WebGLFloatArray SetFromArray 24 PASS test WebGLFloatArray Slice 25 PASS negativeTest WebGLFloatArray Slice 10 26 PASS test WebGLFloatArray BoundaryConditions(-500, -500, 500, 500) 11 27 PASS test WebGLIntArray SetAndGetPos10ToNeg10 28 PASS test WebGLIntArray SetAndGetMethodsPos10ToNeg10 12 29 PASS test WebGLIntArray ConstructWithArrayOfSignedValues 30 PASS test WebGLIntArray ConstructWithWebGLArrayOfSignedValues 31 PASS test WebGLIntArray OffsetsAndSizes 32 PASS test WebGLIntArray SetFromWebGLArray 33 PASS negativeTest WebGLIntArray SetFromWebGLArray 34 PASS test WebGLIntArray SetFromArray 35 PASS test WebGLIntArray Slice 36 PASS negativeTest WebGLIntArray Slice 13 37 PASS test WebGLIntArray BoundaryConditions(-2147483648, -2147483648, 2147483647, 2147483647) 14 38 PASS test WebGLShortArray SetAndGetPos10ToNeg10 39 PASS test WebGLShortArray SetAndGetMethodsPos10ToNeg10 15 40 PASS test WebGLShortArray ConstructWithArrayOfSignedValues 41 PASS test WebGLShortArray ConstructWithWebGLArrayOfSignedValues 42 PASS test WebGLShortArray OffsetsAndSizes 43 PASS test WebGLShortArray SetFromWebGLArray 44 PASS negativeTest WebGLShortArray SetFromWebGLArray 45 PASS test WebGLShortArray SetFromArray 46 PASS test WebGLShortArray Slice 47 PASS negativeTest WebGLShortArray Slice 16 48 PASS test WebGLShortArray BoundaryConditions(-32768, -32768, 32767, 32767) 17 49 PASS test WebGLUnsignedByteArray SetAndGet10To1 50 PASS test WebGLUnsignedByteArray SetAndGetMethods10To1 18 51 PASS test WebGLUnsignedByteArray ConstructWithArrayOfUnsignedValues 52 PASS test WebGLUnsignedByteArray ConstructWithWebGLArrayOfUnsignedValues 53 PASS test WebGLUnsignedByteArray OffsetsAndSizes 54 PASS test WebGLUnsignedByteArray SetFromWebGLArray 55 PASS negativeTest WebGLUnsignedByteArray SetFromWebGLArray 56 PASS test WebGLUnsignedByteArray SetFromArray 57 PASS test WebGLUnsignedByteArray Slice 58 PASS negativeTest WebGLUnsignedByteArray Slice 19 59 PASS test WebGLUnsignedByteArray BoundaryConditions(0, 0, 255, 255) 20 60 PASS test WebGLUnsignedIntArray SetAndGet10To1 61 PASS test WebGLUnsignedIntArray SetAndGetMethods10To1 21 62 PASS test WebGLUnsignedIntArray ConstructWithArrayOfUnsignedValues 63 PASS test WebGLUnsignedIntArray ConstructWithWebGLArrayOfUnsignedValues 64 PASS test WebGLUnsignedIntArray OffsetsAndSizes 65 PASS test WebGLUnsignedIntArray SetFromWebGLArray 66 PASS negativeTest WebGLUnsignedIntArray SetFromWebGLArray 67 PASS test WebGLUnsignedIntArray SetFromArray 68 PASS test WebGLUnsignedIntArray Slice 69 PASS negativeTest WebGLUnsignedIntArray Slice 22 70 PASS test WebGLUnsignedIntArray BoundaryConditions(0, 0, 4294967295, 4294967295) 23 71 PASS test WebGLUnsignedShortArray SetAndGet10To1 72 PASS test WebGLUnsignedShortArray SetAndGetMethods10To1 24 73 PASS test WebGLUnsignedShortArray ConstructWithArrayOfUnsignedValues 74 PASS test WebGLUnsignedShortArray ConstructWithWebGLArrayOfUnsignedValues 75 PASS test WebGLUnsignedShortArray OffsetsAndSizes 76 PASS test WebGLUnsignedShortArray SetFromWebGLArray 77 PASS negativeTest WebGLUnsignedShortArray SetFromWebGLArray 78 PASS test WebGLUnsignedShortArray SetFromArray 79 PASS test WebGLUnsignedShortArray Slice 80 PASS negativeTest WebGLUnsignedShortArray Slice 25 81 PASS test WebGLUnsignedShortArray BoundaryConditions(0, 0, 65535, 65535) 26 82 Test passed. -
trunk/LayoutTests/fast/canvas/webgl/array-unit-tests.html
r50725 r51049 28 28 29 29 function fail(str) { 30 var exc = 'FAILED: ' + currentlyRunning + ': ' + str; 31 testFailed(str); 30 allPassed = false; 31 var exc; 32 if (str) 33 exc = currentlyRunning + ': ' + str; 34 else 35 exc = str; 36 testFailed(exc); 32 37 } 33 38 34 39 function assertEq(prefix, expected, val) { 35 40 if (expected != val) { 36 fail(prefix + ': expected ' + expected + ', got ' + val); 41 var str = prefix + ': expected ' + expected + ', got ' + val; 42 throw str; 43 } 44 } 45 46 function assert(prefix, expected) { 47 if (!expected) { 48 var str = prefix + ': expected value / true'; 49 throw str; 37 50 } 38 51 } … … 66 79 } 67 80 81 function testSetAndGetMethods10To1(type, name) { 82 running('test ' + name + ' SetAndGetMethods10To1'); 83 try { 84 var array = new type(10); 85 for (var i = 0; i < 10; i++) { 86 array.set(i, 10 - i); 87 } 88 for (var i = 0; i < 10; i++) { 89 assertEq('Element ' + i, 10 - i, array.get(i)); 90 } 91 pass(); 92 } catch (e) { 93 fail(e); 94 } 95 } 96 68 97 function testConstructWithArrayOfUnsignedValues(type, name) { 69 98 running('test ' + name + ' ConstructWithArrayOfUnsignedValues'); … … 80 109 } 81 110 111 function testConstructWithWebGLArrayOfUnsignedValues(type, name) { 112 running('test ' + name + ' ConstructWithWebGLArrayOfUnsignedValues'); 113 try { 114 var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); 115 var array = new type(tmp); 116 assertEq('Array length', 10, array.length); 117 for (var i = 0; i < 10; i++) { 118 assertEq('Element ' + i, 10 - i, array[i]); 119 } 120 pass(); 121 } catch (e) { 122 fail(e); 123 } 124 } 125 82 126 // 83 127 // Tests for signed array variants … … 100 144 } 101 145 146 function testSetAndGetMethodsPos10ToNeg10(type, name) { 147 running('test ' + name + ' SetAndGetMethodsPos10ToNeg10'); 148 try { 149 var array = new type(21); 150 for (var i = 0; i < 21; i++) { 151 array.set(i, 10 - i); 152 } 153 for (var i = 0; i < 21; i++) { 154 assertEq('Element ' + i, 10 - i, array.get(i)); 155 } 156 pass(); 157 } catch (e) { 158 fail(e); 159 } 160 } 161 102 162 function testConstructWithArrayOfSignedValues(type, name) { 103 163 running('test ' + name + ' ConstructWithArrayOfSignedValues'); … … 114 174 } 115 175 176 function testConstructWithWebGLArrayOfSignedValues(type, name) { 177 running('test ' + name + ' ConstructWithWebGLArrayOfSignedValues'); 178 try { 179 var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]); 180 var array = new type(tmp); 181 assertEq('Array length', 21, array.length); 182 for (var i = 0; i < 21; i++) { 183 assertEq('Element ' + i, 10 - i, array[i]); 184 } 185 pass(); 186 } catch (e) { 187 fail(e); 188 } 189 } 190 116 191 // 117 192 // Test cases for both signed and unsigned types 118 193 // 194 195 function testOffsetsAndSizes(type, name, elementSizeInBytes) { 196 running('test ' + name + ' OffsetsAndSizes'); 197 try { 198 var len = 10; 199 var array = new type(len); 200 assert('array.buffer', array.buffer); 201 assertEq('array.byteOffset', array.byteOffset, 0); 202 assertEq('array.length', array.length, len); 203 assertEq('array.byteLength', array.byteLength, len * elementSizeInBytes); 204 array = new type(array.buffer, elementSizeInBytes, len - 1); 205 assert('array.buffer', array.buffer); 206 assertEq('array.byteOffset', array.byteOffset, elementSizeInBytes); 207 assertEq('array.length', array.length, len - 1); 208 assertEq('array.byteLength', array.byteLength, (len - 1) * elementSizeInBytes); 209 pass(); 210 } catch (e) { 211 fail(e); 212 } 213 } 214 215 function testSetFromWebGLArray(type, name) { 216 running('test ' + name + ' SetFromWebGLArray'); 217 try { 218 var array = new type(10); 219 var array2 = new type(5); 220 for (var i = 0; i < 10; i++) { 221 assertEq('Element ' + i, 0, array[i]); 222 } 223 for (var i = 0; i < array2.length; i++) { 224 array2[i] = i; 225 } 226 array.set(array2); 227 for (var i = 0; i < array2.length; i++) { 228 assertEq('Element ' + i, i, array[i]); 229 } 230 array.set(array2, 5); 231 for (var i = 0; i < array2.length; i++) { 232 assertEq('Element ' + i, i, array[5 + i]); 233 } 234 pass(); 235 } catch (e) { 236 fail(e); 237 } 238 } 239 240 function negativeTestSetFromWebGLArray(type, name) { 241 running('negativeTest ' + name + ' SetFromWebGLArray'); 242 try { 243 var array = new type(5); 244 var array2 = new type(6); 245 for (var i = 0; i < 5; i++) { 246 assertEq('Element ' + i, 0, array[i]); 247 } 248 for (var i = 0; i < array2.length; i++) { 249 array2[i] = i; 250 } 251 try { 252 array.set(array2); 253 fail('Expected exception from array.set(array2)'); 254 return; 255 } catch (e) { 256 } 257 try { 258 array2.set(array, 2); 259 fail('Expected exception from array2.set(array, 2)'); 260 return; 261 } catch (e) { 262 } 263 pass(); 264 } catch (e) { 265 fail(e); 266 } 267 } 268 269 function testSetFromArray(type, name) { 270 running('test ' + name + ' SetFromArray'); 271 try { 272 var array = new type(10); 273 var array2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; 274 for (var i = 0; i < 10; i++) { 275 assertEq('Element ' + i, 0, array[i]); 276 } 277 array.set(array2, 0); 278 for (var i = 0; i < array2.length; i++) { 279 assertEq('Element ' + i, 10 - i, array[i]); 280 } 281 pass(); 282 } catch (e) { 283 fail(e); 284 } 285 } 286 287 function testSlice(type, name) { 288 running('test ' + name + ' Slice'); 289 try { 290 var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); 291 var slice = array.slice(0, 5); 292 assertEq('slice.length', 5, slice.length); 293 for (var i = 0; i < 5; i++) { 294 assertEq('Element ' + i, i, slice[i]); 295 } 296 slice = array.slice(4, 6); 297 assertEq('slice.length', 6, slice.length); 298 for (var i = 0; i < 6; i++) { 299 assertEq('Element ' + i, 4 + i, slice[i]); 300 } 301 pass(); 302 } catch (e) { 303 fail(e); 304 } 305 } 306 307 function negativeTestSlice(type, name) { 308 running('negativeTest ' + name + ' Slice'); 309 try { 310 var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); 311 slice = array.slice(5, 6); 312 if (slice) { 313 fail(); 314 return; 315 } 316 slice = array.slice(10, 0); 317 if (slice) { 318 fail(); 319 return; 320 } 321 pass(); 322 } catch (e) { 323 pass(); 324 } 325 } 119 326 120 327 function testBoundaryConditions(type, name, lowValue, expectedLowValue, highValue, expectedHighValue) { … … 147 354 [ {name: "WebGLByteArray", 148 355 unsigned: false, 356 elementSizeInBytes: 1, 149 357 low: -128, 150 358 expectedLow: -128, … … 153 361 {name: "WebGLFloatArray", 154 362 unsigned: false, 363 elementSizeInBytes: 4, 155 364 low: -500, 156 365 expectedLow: -500, … … 159 368 {name: "WebGLIntArray", 160 369 unsigned: false, 370 elementSizeInBytes: 4, 161 371 low: -2147483648, 162 372 expectedLow: -2147483648, … … 165 375 {name: "WebGLShortArray", 166 376 unsigned: false, 377 elementSizeInBytes: 2, 167 378 low: -32768, 168 379 expectedLow: -32768, … … 171 382 {name: "WebGLUnsignedByteArray", 172 383 unsigned: true, 384 elementSizeInBytes: 1, 173 385 low: 0, 174 386 expectedLow: 0, … … 177 389 {name: "WebGLUnsignedIntArray", 178 390 unsigned: true, 391 elementSizeInBytes: 4, 179 392 low: 0, 180 393 expectedLow: 0, … … 183 396 {name: "WebGLUnsignedShortArray", 184 397 unsigned: true, 398 elementSizeInBytes: 2, 185 399 low: 0, 186 400 expectedLow: 0, … … 199 413 if (testCase.unsigned) { 200 414 testSetAndGet10To1(type, name); 415 testSetAndGetMethods10To1(type, name); 201 416 testConstructWithArrayOfUnsignedValues(type, name); 417 testConstructWithWebGLArrayOfUnsignedValues(type, name); 202 418 } else { 203 419 testSetAndGetPos10ToNeg10(type, name); 420 testSetAndGetMethodsPos10ToNeg10(type, name); 204 421 testConstructWithArrayOfSignedValues(type, name); 205 } 422 testConstructWithWebGLArrayOfSignedValues(type, name); 423 } 424 testOffsetsAndSizes(type, name, testCase.elementSizeInBytes); 425 testSetFromWebGLArray(type, name); 426 negativeTestSetFromWebGLArray(type, name); 427 testSetFromArray(type, name); 428 testSlice(type, name); 429 negativeTestSlice(type, name); 206 430 testBoundaryConditions(type, 207 431 name, -
trunk/WebCore/ChangeLog
r51048 r51049 1 2009-11-16 Kenneth Russell <kbr@google.com> 2 3 Reviewed by Oliver Hunt. 4 5 Update API of WebGLArray and friends 6 https://bugs.webkit.org/show_bug.cgi?id=31175 7 8 * bindings/js/JSWebGLArrayCustom.cpp: 9 (WebCore::toJS): 10 * bindings/js/JSWebGLArrayHelper.h: Added. 11 (WebCore::setWebGLArrayFromArray): 12 * bindings/js/JSWebGLByteArrayCustom.cpp: 13 (WebCore::JSWebGLByteArray::set): 14 * bindings/js/JSWebGLFloatArrayCustom.cpp: 15 (WebCore::JSWebGLFloatArray::set): 16 * bindings/js/JSWebGLIntArrayCustom.cpp: 17 (WebCore::JSWebGLIntArray::set): 18 * bindings/js/JSWebGLShortArrayCustom.cpp: 19 (WebCore::JSWebGLShortArray::set): 20 * bindings/js/JSWebGLUnsignedByteArrayCustom.cpp: 21 (WebCore::JSWebGLUnsignedByteArray::set): 22 * bindings/js/JSWebGLUnsignedIntArrayCustom.cpp: 23 (WebCore::JSWebGLUnsignedIntArray::set): 24 * bindings/js/JSWebGLUnsignedShortArrayCustom.cpp: 25 (WebCore::JSWebGLUnsignedShortArray::set): 26 * bindings/scripts/CodeGeneratorV8.pm: 27 * bindings/v8/V8DOMWrapper.cpp: 28 (WebCore::V8DOMWrapper::convertToV8Object): 29 * bindings/v8/custom/V8CustomBinding.h: 30 * bindings/v8/custom/V8WebGLArrayBufferCustom.cpp: 31 (WebCore::CALLBACK_FUNC_DECL): 32 * bindings/v8/custom/V8WebGLArrayCustom.h: 33 (WebCore::constructWebGLArray): 34 (WebCore::getWebGLArrayElement): 35 (WebCore::setWebGLArrayFromArray): 36 (WebCore::setWebGLArray): 37 * bindings/v8/custom/V8WebGLByteArrayCustom.cpp: 38 (WebCore::CALLBACK_FUNC_DECL): 39 * bindings/v8/custom/V8WebGLFloatArrayCustom.cpp: 40 (WebCore::CALLBACK_FUNC_DECL): 41 * bindings/v8/custom/V8WebGLIntArrayCustom.cpp: 42 (WebCore::CALLBACK_FUNC_DECL): 43 * bindings/v8/custom/V8WebGLShortArrayCustom.cpp: 44 (WebCore::CALLBACK_FUNC_DECL): 45 * bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp: 46 (WebCore::CALLBACK_FUNC_DECL): 47 * bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp: 48 (WebCore::CALLBACK_FUNC_DECL): 49 * bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp: 50 (WebCore::CALLBACK_FUNC_DECL): 51 * html/canvas/WebGLArray.cpp: 52 (WebCore::WebGLArray::WebGLArray): 53 (WebCore::WebGLArray::~WebGLArray): 54 (WebCore::WebGLArray::setImpl): 55 * html/canvas/WebGLArray.h: 56 (WebCore::WebGLArray::isByteArray): 57 (WebCore::WebGLArray::isUnsignedByteArray): 58 (WebCore::WebGLArray::isShortArray): 59 (WebCore::WebGLArray::isUnsignedShortArray): 60 (WebCore::WebGLArray::isIntArray): 61 (WebCore::WebGLArray::isUnsignedIntArray): 62 (WebCore::WebGLArray::isFloatArray): 63 (WebCore::WebGLArray::buffer): 64 (WebCore::WebGLArray::baseAddress): 65 (WebCore::WebGLArray::byteOffset): 66 * html/canvas/WebGLArray.idl: 67 * html/canvas/WebGLArrayBuffer.cpp: 68 (WebCore::WebGLArrayBuffer::create): 69 (WebCore::WebGLArrayBuffer::WebGLArrayBuffer): 70 (WebCore::WebGLArrayBuffer::data): 71 (WebCore::WebGLArrayBuffer::byteLength): 72 (WebCore::WebGLArrayBuffer::~WebGLArrayBuffer): 73 * html/canvas/WebGLArrayBuffer.h: 74 * html/canvas/WebGLByteArray.cpp: 75 (WebCore::WebGLByteArray::create): 76 (WebCore::WebGLByteArray::byteLength): 77 (WebCore::WebGLByteArray::slice): 78 (WebCore::WebGLByteArray::set): 79 * html/canvas/WebGLByteArray.h: 80 (WebCore::WebGLByteArray::isByteArray): 81 (WebCore::WebGLByteArray::data): 82 (WebCore::WebGLByteArray::set): 83 (WebCore::WebGLByteArray::get): 84 (WebCore::WebGLByteArray::item): 85 * html/canvas/WebGLByteArray.idl: 86 * html/canvas/WebGLFloatArray.cpp: 87 (WebCore::WebGLFloatArray::create): 88 (WebCore::WebGLFloatArray::WebGLFloatArray): 89 (WebCore::WebGLFloatArray::length): 90 (WebCore::WebGLFloatArray::byteLength): 91 (WebCore::WebGLFloatArray::slice): 92 (WebCore::WebGLFloatArray::set): 93 * html/canvas/WebGLFloatArray.h: 94 (WebCore::WebGLFloatArray::isFloatArray): 95 (WebCore::WebGLFloatArray::data): 96 (WebCore::WebGLFloatArray::set): 97 (WebCore::WebGLFloatArray::get): 98 (WebCore::WebGLFloatArray::item): 99 * html/canvas/WebGLFloatArray.idl: 100 * html/canvas/WebGLIntArray.cpp: 101 (WebCore::WebGLIntArray::create): 102 (WebCore::WebGLIntArray::WebGLIntArray): 103 (WebCore::WebGLIntArray::length): 104 (WebCore::WebGLIntArray::byteLength): 105 (WebCore::WebGLIntArray::slice): 106 (WebCore::WebGLIntArray::set): 107 * html/canvas/WebGLIntArray.h: 108 (WebCore::WebGLIntArray::isIntArray): 109 (WebCore::WebGLIntArray::data): 110 (WebCore::WebGLIntArray::set): 111 (WebCore::WebGLIntArray::get): 112 (WebCore::WebGLIntArray::item): 113 * html/canvas/WebGLIntArray.idl: 114 * html/canvas/WebGLShortArray.cpp: 115 (WebCore::WebGLShortArray::create): 116 (WebCore::WebGLShortArray::WebGLShortArray): 117 (WebCore::WebGLShortArray::length): 118 (WebCore::WebGLShortArray::byteLength): 119 (WebCore::WebGLShortArray::slice): 120 (WebCore::WebGLShortArray::set): 121 * html/canvas/WebGLShortArray.h: 122 (WebCore::WebGLShortArray::isShortArray): 123 (WebCore::WebGLShortArray::data): 124 (WebCore::WebGLShortArray::set): 125 (WebCore::WebGLShortArray::get): 126 (WebCore::WebGLShortArray::item): 127 * html/canvas/WebGLShortArray.idl: 128 * html/canvas/WebGLUnsignedByteArray.cpp: 129 (WebCore::WebGLUnsignedByteArray::create): 130 (WebCore::WebGLUnsignedByteArray::WebGLUnsignedByteArray): 131 (WebCore::WebGLUnsignedByteArray::length): 132 (WebCore::WebGLUnsignedByteArray::byteLength): 133 (WebCore::WebGLUnsignedByteArray::slice): 134 (WebCore::WebGLUnsignedByteArray::set): 135 * html/canvas/WebGLUnsignedByteArray.h: 136 (WebCore::WebGLUnsignedByteArray::isUnsignedByteArray): 137 (WebCore::WebGLUnsignedByteArray::data): 138 (WebCore::WebGLUnsignedByteArray::set): 139 (WebCore::WebGLUnsignedByteArray::get): 140 (WebCore::WebGLUnsignedByteArray::item): 141 * html/canvas/WebGLUnsignedByteArray.idl: 142 * html/canvas/WebGLUnsignedIntArray.cpp: 143 (WebCore::WebGLUnsignedIntArray::create): 144 (WebCore::WebGLUnsignedIntArray::WebGLUnsignedIntArray): 145 (WebCore::WebGLUnsignedIntArray::length): 146 (WebCore::WebGLUnsignedIntArray::byteLength): 147 (WebCore::WebGLUnsignedIntArray::slice): 148 (WebCore::WebGLUnsignedIntArray::set): 149 * html/canvas/WebGLUnsignedIntArray.h: 150 (WebCore::WebGLUnsignedIntArray::isUnsignedIntArray): 151 (WebCore::WebGLUnsignedIntArray::data): 152 (WebCore::WebGLUnsignedIntArray::set): 153 (WebCore::WebGLUnsignedIntArray::get): 154 (WebCore::WebGLUnsignedIntArray::item): 155 * html/canvas/WebGLUnsignedIntArray.idl: 156 * html/canvas/WebGLUnsignedShortArray.cpp: 157 (WebCore::WebGLUnsignedShortArray::create): 158 (WebCore::WebGLUnsignedShortArray::WebGLUnsignedShortArray): 159 (WebCore::WebGLUnsignedShortArray::length): 160 (WebCore::WebGLUnsignedShortArray::byteLength): 161 (WebCore::WebGLUnsignedShortArray::slice): 162 (WebCore::WebGLUnsignedShortArray::set): 163 * html/canvas/WebGLUnsignedShortArray.h: 164 (WebCore::WebGLUnsignedShortArray::isUnsignedShortArray): 165 (WebCore::WebGLUnsignedShortArray::data): 166 (WebCore::WebGLUnsignedShortArray::set): 167 (WebCore::WebGLUnsignedShortArray::get): 168 (WebCore::WebGLUnsignedShortArray::item): 169 * html/canvas/WebGLUnsignedShortArray.idl: 170 * platform/graphics/mac/GraphicsContext3DMac.cpp: 171 (WebCore::GraphicsContext3D::bufferData): 172 (WebCore::GraphicsContext3D::bufferSubData): 173 1 174 2009-11-16 Alexey Proskuryakov <ap@apple.com> 2 175 -
trunk/WebCore/bindings/js/JSWebGLArrayCustom.cpp
r50725 r51049 46 46 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, WebGLArray* object) 47 47 { 48 if (object->isFloatArray()) 49 return getDOMObjectWrapper<JSWebGLFloatArray>(exec, globalObject, static_cast<WebGLFloatArray*>(object)); 50 if (object->isUnsignedByteArray()) 51 return getDOMObjectWrapper<JSWebGLUnsignedByteArray>(exec, globalObject, static_cast<WebGLUnsignedByteArray*>(object)); 52 if (object->isByteArray()) 53 return getDOMObjectWrapper<JSWebGLByteArray>(exec, globalObject, static_cast<WebGLByteArray*>(object)); 54 if (object->isIntArray()) 55 return getDOMObjectWrapper<JSWebGLIntArray>(exec, globalObject, static_cast<WebGLIntArray*>(object)); 56 if (object->isUnsignedIntArray()) 57 return getDOMObjectWrapper<JSWebGLUnsignedIntArray>(exec, globalObject, static_cast<WebGLUnsignedIntArray*>(object)); 58 if (object->isShortArray()) 59 return getDOMObjectWrapper<JSWebGLShortArray>(exec, globalObject, static_cast<WebGLShortArray*>(object)); 60 if (object->isUnsignedShortArray()) 61 return getDOMObjectWrapper<JSWebGLUnsignedShortArray>(exec, globalObject, static_cast<WebGLUnsignedShortArray*>(object)); 48 if (object) { 49 if (object->isFloatArray()) 50 return getDOMObjectWrapper<JSWebGLFloatArray>(exec, globalObject, static_cast<WebGLFloatArray*>(object)); 51 if (object->isUnsignedByteArray()) 52 return getDOMObjectWrapper<JSWebGLUnsignedByteArray>(exec, globalObject, static_cast<WebGLUnsignedByteArray*>(object)); 53 if (object->isByteArray()) 54 return getDOMObjectWrapper<JSWebGLByteArray>(exec, globalObject, static_cast<WebGLByteArray*>(object)); 55 if (object->isIntArray()) 56 return getDOMObjectWrapper<JSWebGLIntArray>(exec, globalObject, static_cast<WebGLIntArray*>(object)); 57 if (object->isUnsignedIntArray()) 58 return getDOMObjectWrapper<JSWebGLUnsignedIntArray>(exec, globalObject, static_cast<WebGLUnsignedIntArray*>(object)); 59 if (object->isShortArray()) 60 return getDOMObjectWrapper<JSWebGLShortArray>(exec, globalObject, static_cast<WebGLShortArray*>(object)); 61 if (object->isUnsignedShortArray()) 62 return getDOMObjectWrapper<JSWebGLUnsignedShortArray>(exec, globalObject, static_cast<WebGLUnsignedShortArray*>(object)); 63 } 62 64 return jsUndefined(); 63 65 } -
trunk/WebCore/bindings/js/JSWebGLByteArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLByteArray.h" 31 32 32 33 #include "WebGLByteArray.h" 34 35 #include <runtime/Error.h> 33 36 34 37 using namespace JSC; … … 46 49 } 47 50 51 JSC::JSValue JSWebGLByteArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 52 { 53 if (args.size() < 1 || args.size() > 2) 54 return throwError(exec, SyntaxError); 55 56 if (args.size() == 2 && args.at(0).isInt32()) { 57 // void set(in unsigned long index, in long value); 58 unsigned index = args.at(0).toUInt32(exec); 59 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 60 return jsUndefined(); 61 } 62 63 WebGLByteArray* array = toWebGLByteArray(args.at(0)); 64 if (array) { 65 // void set(in WebGLByteArray array, [Optional] in unsigned long offset); 66 unsigned offset = 0; 67 if (args.size() == 2) 68 offset = args.at(1).toInt32(exec); 69 ExceptionCode ec = 0; 70 impl()->set(array, offset, ec); 71 setDOMException(exec, ec); 72 return jsUndefined(); 73 } 74 75 return setWebGLArrayFromArray(exec, impl(), args); 76 } 77 48 78 } // namespace WebCore 49 79 -
trunk/WebCore/bindings/js/JSWebGLFloatArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLFloatArray.h" 31 32 … … 46 47 } 47 48 49 JSC::JSValue JSWebGLFloatArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 50 { 51 if (args.size() > 2) 52 return throwError(exec, SyntaxError); 53 54 if (args.size() == 2 && args.at(0).isInt32()) { 55 // void set(in unsigned long index, in long value); 56 unsigned index = args.at(0).toUInt32(exec); 57 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 58 return jsUndefined(); 59 } 60 61 WebGLFloatArray* array = toWebGLFloatArray(args.at(0)); 62 if (array) { 63 // void set(in WebGLFloatArray array, [Optional] in unsigned long offset); 64 unsigned offset = 0; 65 if (args.size() == 2) 66 offset = args.at(1).toInt32(exec); 67 ExceptionCode ec = 0; 68 impl()->set(array, offset, ec); 69 setDOMException(exec, ec); 70 return jsUndefined(); 71 } 72 73 return setWebGLArrayFromArray(exec, impl(), args); 74 } 75 48 76 } // namespace WebCore 49 77 -
trunk/WebCore/bindings/js/JSWebGLIntArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLIntArray.h" 31 32 … … 46 47 } 47 48 49 JSC::JSValue JSWebGLIntArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 50 { 51 if (args.size() > 2) 52 return throwError(exec, SyntaxError); 53 54 if (args.size() == 2 && args.at(0).isInt32()) { 55 // void set(in unsigned long index, in long value); 56 unsigned index = args.at(0).toUInt32(exec); 57 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 58 return jsUndefined(); 59 } 60 61 WebGLIntArray* array = toWebGLIntArray(args.at(0)); 62 if (array) { 63 // void set(in WebGLIntArray array, [Optional] in unsigned long offset); 64 unsigned offset = 0; 65 if (args.size() == 2) 66 offset = args.at(1).toInt32(exec); 67 ExceptionCode ec = 0; 68 impl()->set(array, offset, ec); 69 setDOMException(exec, ec); 70 return jsUndefined(); 71 } 72 73 return setWebGLArrayFromArray(exec, impl(), args); 74 } 75 48 76 } // namespace WebCore 49 77 -
trunk/WebCore/bindings/js/JSWebGLShortArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLShortArray.h" 31 32 … … 46 47 } 47 48 49 JSC::JSValue JSWebGLShortArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 50 { 51 if (args.size() > 2) 52 return throwError(exec, SyntaxError); 53 54 if (args.size() == 2 && args.at(0).isInt32()) { 55 // void set(in unsigned long index, in long value); 56 unsigned index = args.at(0).toUInt32(exec); 57 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 58 return jsUndefined(); 59 } 60 61 WebGLShortArray* shortArray = toWebGLShortArray(args.at(0)); 62 if (shortArray) { 63 // void set(in WebGLShortArray array, [Optional] in unsigned long offset); 64 unsigned offset = 0; 65 if (args.size() == 2) 66 offset = args.at(1).toInt32(exec); 67 ExceptionCode ec = 0; 68 impl()->set(shortArray, offset, ec); 69 setDOMException(exec, ec); 70 return jsUndefined(); 71 } 72 73 return setWebGLArrayFromArray(exec, impl(), args); 74 } 75 48 76 } // namespace WebCore 49 77 -
trunk/WebCore/bindings/js/JSWebGLUnsignedByteArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLUnsignedByteArray.h" 31 32 … … 46 47 } 47 48 49 JSC::JSValue JSWebGLUnsignedByteArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 50 { 51 if (args.size() > 2) 52 return throwError(exec, SyntaxError); 53 54 if (args.size() == 2 && args.at(0).isInt32()) { 55 // void set(in unsigned long index, in long value); 56 unsigned index = args.at(0).toUInt32(exec); 57 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 58 return jsUndefined(); 59 } 60 61 WebGLUnsignedByteArray* array = toWebGLUnsignedByteArray(args.at(0)); 62 if (array) { 63 // void set(in WebGLUnsignedByteArray array, [Optional] in unsigned long offset); 64 unsigned offset = 0; 65 if (args.size() == 2) 66 offset = args.at(1).toInt32(exec); 67 ExceptionCode ec = 0; 68 impl()->set(array, offset, ec); 69 setDOMException(exec, ec); 70 return jsUndefined(); 71 } 72 73 return setWebGLArrayFromArray(exec, impl(), args); 74 } 75 48 76 } // namespace WebCore 49 77 -
trunk/WebCore/bindings/js/JSWebGLUnsignedIntArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLUnsignedIntArray.h" 31 32 … … 46 47 } 47 48 49 JSC::JSValue JSWebGLUnsignedIntArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 50 { 51 if (args.size() > 2) 52 return throwError(exec, SyntaxError); 53 54 if (args.size() == 2 && args.at(0).isInt32()) { 55 // void set(in unsigned long index, in long value); 56 unsigned index = args.at(0).toUInt32(exec); 57 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 58 return jsUndefined(); 59 } 60 61 WebGLUnsignedIntArray* array = toWebGLUnsignedIntArray(args.at(0)); 62 if (array) { 63 // void set(in WebGLUnsignedIntArray array, [Optional] in unsigned long offset); 64 unsigned offset = 0; 65 if (args.size() == 2) 66 offset = args.at(1).toInt32(exec); 67 ExceptionCode ec = 0; 68 impl()->set(array, offset, ec); 69 setDOMException(exec, ec); 70 return jsUndefined(); 71 } 72 73 return setWebGLArrayFromArray(exec, impl(), args); 74 } 75 48 76 } // namespace WebCore 49 77 -
trunk/WebCore/bindings/js/JSWebGLUnsignedShortArrayCustom.cpp
r50725 r51049 28 28 #if ENABLE(3D_CANVAS) 29 29 30 #include "JSWebGLArrayHelper.h" 30 31 #include "JSWebGLUnsignedShortArray.h" 31 32 … … 46 47 } 47 48 49 JSC::JSValue JSWebGLUnsignedShortArray::set(JSC::ExecState* exec, JSC::ArgList const& args) 50 { 51 if (args.size() > 2) 52 return throwError(exec, SyntaxError); 53 54 if (args.size() == 2 && args.at(0).isInt32()) { 55 // void set(in unsigned long index, in long value); 56 unsigned index = args.at(0).toUInt32(exec); 57 impl()->set(index, static_cast<signed char>(args.at(1).toInt32(exec))); 58 return jsUndefined(); 59 } 60 61 WebGLUnsignedShortArray* array = toWebGLUnsignedShortArray(args.at(0)); 62 if (array) { 63 // void set(in WebGLUnsignedShortArray array, [Optional] in unsigned long offset); 64 unsigned offset = 0; 65 if (args.size() == 2) 66 offset = args.at(1).toInt32(exec); 67 ExceptionCode ec = 0; 68 impl()->set(array, offset, ec); 69 setDOMException(exec, ec); 70 return jsUndefined(); 71 } 72 73 return setWebGLArrayFromArray(exec, impl(), args); 74 } 75 48 76 } // namespace WebCore 49 77 -
trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm
r50972 r51049 1747 1747 my $type = shift; 1748 1748 return 1 if $type eq "Attr"; 1749 return 1 if $type eq "WebGLActiveInfo";1750 return 1 if $type eq "WebGLArray";1751 return 1 if $type eq "WebGLArrayBuffer";1752 1749 return 1 if $type eq "CanvasBooleanArray"; 1753 return 1 if $type eq "WebGLByteArray";1754 return 1 if $type eq "WebGLBuffer";1755 return 1 if $type eq "WebGLFloatArray";1756 return 1 if $type eq "WebGLFramebuffer";1757 1750 return 1 if $type eq "CanvasGradient"; 1758 return 1 if $type eq "WebGLIntArray";1759 1751 return 1 if $type eq "CanvasObject"; 1760 return 1 if $type eq "WebGLProgram";1761 return 1 if $type eq "WebGLRenderbuffer";1762 return 1 if $type eq "WebGLShader";1763 return 1 if $type eq "WebGLShortArray";1764 return 1 if $type eq "WebGLTexture";1765 return 1 if $type eq "WebGLUnsignedByteArray";1766 return 1 if $type eq "WebGLUnsignedIntArray";1767 return 1 if $type eq "WebGLUnsignedShortArray";1768 1752 return 1 if $type eq "ClientRect"; 1769 1753 return 1 if $type eq "ClientRectList"; … … 1813 1797 return 1 if $type eq "TimeRanges"; 1814 1798 return 1 if $type eq "TreeWalker"; 1799 return 1 if $type eq "WebGLActiveInfo"; 1800 return 1 if $type eq "WebGLArray"; 1801 return 1 if $type eq "WebGLArrayBuffer"; 1802 return 1 if $type eq "WebGLByteArray"; 1803 return 1 if $type eq "WebGLBuffer"; 1804 return 1 if $type eq "WebGLFloatArray"; 1805 return 1 if $type eq "WebGLFramebuffer"; 1806 return 1 if $type eq "WebGLIntArray"; 1807 return 1 if $type eq "WebGLProgram"; 1808 return 1 if $type eq "WebGLRenderbuffer"; 1809 return 1 if $type eq "WebGLShader"; 1810 return 1 if $type eq "WebGLShortArray"; 1811 return 1 if $type eq "WebGLTexture"; 1812 return 1 if $type eq "WebGLUnsignedByteArray"; 1813 return 1 if $type eq "WebGLUnsignedIntArray"; 1814 return 1 if $type eq "WebGLUnsignedShortArray"; 1815 1815 return 1 if $type eq "WebKitCSSMatrix"; 1816 1816 return 1 if $type eq "WebKitPoint"; -
trunk/WebCore/bindings/v8/V8DOMWrapper.cpp
r51004 r51049 32 32 #include "V8DOMWrapper.h" 33 33 34 #include "WebGLArray.h"35 34 #include "CSSMutableStyleDeclaration.h" 36 35 #include "ChromiumBridge.h" … … 52 51 #include "V8IsolatedWorld.h" 53 52 #include "V8Proxy.h" 53 #include "WebGLArray.h" 54 54 #include "WorkerContextExecutionProxy.h" 55 55 … … 721 721 v8::Persistent<v8::Object> result = isActiveDomObject ? getActiveDOMObjectMap().get(impl) : getDOMObjectMap().get(impl); 722 722 if (result.IsEmpty()) { 723 #if ENABLE(3D_CANVAS) 724 if (type == V8ClassIndex::WEBGLARRAY && impl) { 725 // Determine which subclass we are wrapping. 726 WebGLArray* array = reinterpret_cast<WebGLArray*>(impl); 727 if (array->isByteArray()) 728 type = V8ClassIndex::WEBGLBYTEARRAY; 729 else if (array->isFloatArray()) 730 type = V8ClassIndex::WEBGLFLOATARRAY; 731 else if (array->isIntArray()) 732 type = V8ClassIndex::WEBGLINTARRAY; 733 else if (array->isShortArray()) 734 type = V8ClassIndex::WEBGLSHORTARRAY; 735 else if (array->isUnsignedByteArray()) 736 type = V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY; 737 else if (array->isUnsignedIntArray()) 738 type = V8ClassIndex::WEBGLUNSIGNEDINTARRAY; 739 else if (array->isUnsignedShortArray()) 740 type = V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY; 741 } 742 #endif 743 723 744 v8::Local<v8::Object> v8Object = instantiateV8Object(type, type, impl); 724 745 if (!v8Object.IsEmpty()) { -
trunk/WebCore/bindings/v8/custom/V8CustomBinding.h
r50933 r51049 532 532 DECLARE_NAMED_PROPERTY_GETTER(HTMLCollection); 533 533 534 DECLARE_INDEXED_PROPERTY_GETTER(CanvasPixelArray); 535 DECLARE_INDEXED_PROPERTY_SETTER(CanvasPixelArray); 536 534 537 #if ENABLE(3D_CANVAS) 538 DECLARE_CALLBACK(WebGLByteArrayGet); 539 DECLARE_CALLBACK(WebGLByteArraySet); 535 540 DECLARE_INDEXED_PROPERTY_GETTER(WebGLByteArray); 536 541 DECLARE_INDEXED_PROPERTY_SETTER(WebGLByteArray); 537 542 543 DECLARE_CALLBACK(WebGLFloatArrayGet); 544 DECLARE_CALLBACK(WebGLFloatArraySet); 538 545 DECLARE_INDEXED_PROPERTY_GETTER(WebGLFloatArray); 539 546 DECLARE_INDEXED_PROPERTY_SETTER(WebGLFloatArray); 540 547 548 DECLARE_CALLBACK(WebGLIntArrayGet); 549 DECLARE_CALLBACK(WebGLIntArraySet); 541 550 DECLARE_INDEXED_PROPERTY_GETTER(WebGLIntArray); 542 551 DECLARE_INDEXED_PROPERTY_SETTER(WebGLIntArray); 543 #endif 544 545 DECLARE_INDEXED_PROPERTY_GETTER(CanvasPixelArray); 546 DECLARE_INDEXED_PROPERTY_SETTER(CanvasPixelArray); 547 548 #if ENABLE(3D_CANVAS) 552 553 DECLARE_CALLBACK(WebGLShortArrayGet); 554 DECLARE_CALLBACK(WebGLShortArraySet); 549 555 DECLARE_INDEXED_PROPERTY_GETTER(WebGLShortArray); 550 556 DECLARE_INDEXED_PROPERTY_SETTER(WebGLShortArray); 551 557 558 DECLARE_CALLBACK(WebGLUnsignedByteArrayGet); 559 DECLARE_CALLBACK(WebGLUnsignedByteArraySet); 552 560 DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedByteArray); 553 561 DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedByteArray); 554 562 563 DECLARE_CALLBACK(WebGLUnsignedIntArrayGet); 564 DECLARE_CALLBACK(WebGLUnsignedIntArraySet); 555 565 DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedIntArray); 556 566 DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedIntArray); 557 567 568 DECLARE_CALLBACK(WebGLUnsignedShortArrayGet); 569 DECLARE_CALLBACK(WebGLUnsignedShortArraySet); 558 570 DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedShortArray); 559 571 DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedShortArray); -
trunk/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp
r50730 r51049 44 44 CALLBACK_FUNC_DECL(WebGLArrayBufferConstructor) 45 45 { 46 INC_STATS("DOM.WebGLArrayBuffer.Con tructor");46 INC_STATS("DOM.WebGLArrayBuffer.Constructor"); 47 47 48 48 if (!args.IsConstructCall()) … … 50 50 51 51 int argLen = args.Length(); 52 if (argLen == 0) { 53 // This happens when we return a previously constructed 54 // WebGLArrayBuffer, e.g. from the call to WebGLArray.buffer. 55 // The V8DOMWrapper will set the internal pointer in the 56 // created object. Unfortunately it doesn't look like it's 57 // possible to distinguish between this case and that where 58 // the user calls "new WebGLArrayBuffer()" from JavaScript. 59 return args.Holder(); 60 } 61 52 62 // Supported constructors: 53 63 // WebGLArrayBuffer(n) where n is an integer: -
trunk/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h
r50730 r51049 42 42 namespace WebCore { 43 43 44 // Template function used by the WebGLArray*Constructor callbacks. 45 template<class ArrayClass> 46 v8::Handle<v8::Value> constructCanvasArray(const v8::Arguments& args, 47 int classIndex) 48 { 49 if (!args.IsConstructCall()) 50 return throwError("DOM object constructor cannot be called as a function."); 51 52 int argLen = args.Length(); 53 // Supported constructors: 54 // Canvas<T>Array(n) where n is an integer: 55 // -- create an empty array of n elements 56 // Canvas<T>Array(arr) where arr is an array: 57 // -- create a Canvas<T>Array containing the contents of "arr" 58 // Canvas<T>Array(buf, offset, length) 59 // -- create a Canvas<T>Array pointing to the WebGLArrayBuffer 60 // "buf", starting at the specified offset, for the given 61 // length 62 63 if (argLen == 0) 64 return throwError("No arguments specified to constructor"); 65 66 // See whether the first argument is a WebGLArrayBuffer. 67 if (V8WebGLArrayBuffer::HasInstance(args[0])) { 68 if (argLen > 3) 69 return throwError("Wrong number of arguments to new Canvas<T>Array(WebGLArrayBuffer, int, int)"); 70 71 WebGLArrayBuffer* buf = 44 // Template function used by the WebGLArray*Constructor callbacks. 45 template<class ArrayClass> 46 v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, 47 int classIndex) 48 { 49 if (!args.IsConstructCall()) 50 return throwError("DOM object constructor cannot be called as a function."); 51 52 int argLen = args.Length(); 53 if (argLen == 0) { 54 // This happens when we return a previously constructed 55 // WebGLArray, e.g. from the call to WebGL<T>Array.slice(). 56 // The V8DOMWrapper will set the internal pointer in the 57 // created object. Unfortunately it doesn't look like it's 58 // possible to distinguish between this case and that where 59 // the user calls "new WebGL<T>Array()" from JavaScript. 60 return args.Holder(); 61 } 62 63 // Supported constructors: 64 // WebGL<T>Array(n) where n is an integer: 65 // -- create an empty array of n elements 66 // WebGL<T>Array(arr) where arr is an array: 67 // -- create a WebGL<T>Array containing the contents of "arr" 68 // WebGL<T>Array(buf, offset, length) 69 // -- create a WebGL<T>Array pointing to the WebGLArrayBuffer 70 // "buf", starting at the specified offset, for the given 71 // length 72 73 // See whether the first argument is a WebGLArrayBuffer. 74 if (V8WebGLArrayBuffer::HasInstance(args[0])) { 75 if (argLen > 3) 76 return throwError("Wrong number of arguments to new WebGL<T>Array(WebGLArrayBuffer, int, int)"); 77 78 WebGLArrayBuffer* buf = 72 79 V8DOMWrapper::convertToNativeObject<WebGLArrayBuffer>(V8ClassIndex::WEBGLARRAYBUFFER, 73 args[0]->ToObject()); 74 if (buf == NULL) 75 return throwError("Could not convert argument 0 to a WebGLArrayBuffer"); 76 bool ok; 77 int offset = 0; 78 if (argLen > 1) { 79 offset = toInt32(args[1], ok); 80 if (!ok) 81 return throwError("Could not convert argument 1 to an integer"); 82 } 83 int length = buf->byteLength() - offset; 84 if (argLen > 2) { 85 length = toInt32(args[2], ok); 86 if (!ok) 87 return throwError("Could not convert argument 2 to an integer"); 88 } 89 if (length < 0) 90 return throwError("Length / offset out of range"); 91 92 RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); 93 if (array == NULL) 94 return throwError("Invalid arguments to new Canvas<T>Array(WebGLArrayBuffer, int, int)"); 95 // Transform the holder into a wrapper object for the array. 96 V8DOMWrapper::setDOMWrapper(args.Holder(), classIndex, array.get()); 97 V8DOMWrapper::setIndexedPropertiesToExternalArray(args.Holder(), 98 classIndex, 99 array.get()->baseAddress(), 100 array.get()->length()); 101 return toV8(array.release(), args.Holder()); 102 } 103 104 int len = 0; 105 v8::Handle<v8::Array> srcArray; 106 if (argLen != 1) 107 return throwError("Wrong number of arguments to new Canvas<T>Array(int / array)"); 108 109 if (args[0]->IsInt32()) { 110 len = toInt32(args[0]); 111 } else if (args[0]->IsArray()) { 112 srcArray = v8::Local<v8::Array>::Cast(args[0]); 113 if (srcArray.IsEmpty()) 114 return throwError("Could not convert argument 0 to an array"); 115 len = srcArray->Length(); 116 } else 117 return throwError("Could not convert argument 0 to either an int32 or an array"); 118 119 RefPtr<ArrayClass> array = ArrayClass::create(len); 120 if (!srcArray.IsEmpty()) { 121 // Need to copy the incoming array into the newly created WebGLArray. 122 for (int i = 0; i < len; i++) { 123 v8::Local<v8::Value> val = srcArray->Get(v8::Integer::New(i)); 124 if (!val->IsNumber()) { 125 char buf[256]; 126 sprintf(buf, "Could not convert array element %d to a number", i); 127 return throwError(buf); 128 } 129 array->set(i, val->NumberValue()); 130 } 131 } 132 80 args[0]->ToObject()); 81 if (buf == NULL) 82 return throwError("Could not convert argument 0 to a WebGLArrayBuffer"); 83 bool ok; 84 int offset = 0; 85 if (argLen > 1) { 86 offset = toInt32(args[1], ok); 87 if (!ok) 88 return throwError("Could not convert argument 1 to an integer"); 89 } 90 int length = buf->byteLength() - offset; 91 if (argLen > 2) { 92 length = toInt32(args[2], ok); 93 if (!ok) 94 return throwError("Could not convert argument 2 to an integer"); 95 } 96 if (length < 0) 97 return throwError("Length / offset out of range"); 98 99 RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); 100 if (array == NULL) 101 return throwError("Invalid arguments to new WebGL<T>Array(WebGLArrayBuffer, int, int)"); 133 102 // Transform the holder into a wrapper object for the array. 134 103 V8DOMWrapper::setDOMWrapper(args.Holder(), classIndex, array.get()); … … 140 109 } 141 110 111 int len = 0; 112 v8::Handle<v8::Object> srcArray; 113 if (argLen != 1) 114 return throwError("Wrong number of arguments to new WebGL<T>Array(int / array)"); 115 116 if (args[0]->IsInt32()) { 117 len = toInt32(args[0]); 118 } else if (args[0]->IsObject()) { 119 srcArray = args[0]->ToObject(); 120 if (srcArray.IsEmpty()) 121 return throwError("Could not convert argument 0 to an object"); 122 len = toInt32(srcArray->Get(v8::String::New("length"))); 123 } else 124 return throwError("Could not convert argument 0 to either an int32 or an object"); 125 126 RefPtr<ArrayClass> array = ArrayClass::create(len); 127 if (!srcArray.IsEmpty()) { 128 // Need to copy the incoming array into the newly created WebGLArray. 129 for (int i = 0; i < len; i++) { 130 v8::Local<v8::Value> val = srcArray->Get(v8::Integer::New(i)); 131 array->set(i, val->NumberValue()); 132 } 133 } 134 135 // Transform the holder into a wrapper object for the array. 136 V8DOMWrapper::setDOMWrapper(args.Holder(), classIndex, array.get()); 137 V8DOMWrapper::setIndexedPropertiesToExternalArray(args.Holder(), 138 classIndex, 139 array.get()->baseAddress(), 140 array.get()->length()); 141 return toV8(array.release(), args.Holder()); 142 } 143 144 template <class T, typename ElementType> 145 v8::Handle<v8::Value> getWebGLArrayElement(const v8::Arguments& args, 146 V8ClassIndex::V8WrapperType wrapperType) 147 { 148 if (args.Length() != 1) { 149 V8Proxy::setDOMException(SYNTAX_ERR); 150 return notHandledByInterceptor(); 151 } 152 bool ok; 153 uint32_t index = toInt32(args[0], ok); 154 if (!ok) { 155 V8Proxy::setDOMException(SYNTAX_ERR); 156 return notHandledByInterceptor(); 157 } 158 T* array = V8DOMWrapper::convertToNativeObject<T>(wrapperType, args.Holder()); 159 if (index >= array->length()) 160 return v8::Undefined(); 161 ElementType result; 162 if (!array->get(index, result)) 163 return v8::Undefined(); 164 return v8::Number::New(result); 165 } 166 167 template <class T> 168 v8::Handle<v8::Value> setWebGLArrayFromArray(T* webGLArray, const v8::Arguments& args) 169 { 170 if (args[0]->IsObject()) { 171 // void set(in sequence<long> array, [Optional] in unsigned long offset); 172 v8::Local<v8::Object> array = args[0]->ToObject(); 173 uint32_t offset = 0; 174 if (args.Length() == 2) 175 offset = toInt32(args[1]); 176 uint32_t length = toInt32(array->Get(v8::String::New("length"))); 177 for (uint32_t i = 0; i < length; i++) { 178 webGLArray->set(offset + i, array->Get(v8::Integer::New(i))->NumberValue()); 179 } 180 } 181 182 return v8::Undefined(); 183 } 184 185 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> 186 v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args, 187 V8ClassIndex::V8WrapperType wrapperType) 188 { 189 if (args.Length() < 1 || args.Length() > 2) { 190 V8Proxy::setDOMException(SYNTAX_ERR); 191 return notHandledByInterceptor(); 192 } 193 194 CPlusPlusArrayType* array = V8DOMWrapper::convertToNativeObject<CPlusPlusArrayType>(wrapperType, args.Holder()); 195 196 if (args.Length() == 2 && args[0]->IsInt32()) { 197 // void set(in unsigned long index, in long value); 198 uint32_t index = toInt32(args[0]); 199 array->set(index, args[1]->NumberValue()); 200 return v8::Undefined(); 201 } 202 203 if (JavaScriptWrapperArrayType::HasInstance(args[0])) { 204 // void set(in WebGL<T>Array array, [Optional] in unsigned long offset); 205 CPlusPlusArrayType* src = V8DOMWrapper::convertToNativeObject<CPlusPlusArrayType>(wrapperType, args[0]->ToObject()); 206 uint32_t offset = 0; 207 if (args.Length() == 2) 208 offset = toInt32(args[1]); 209 ExceptionCode ec = 0; 210 array->set(src, offset, ec); 211 V8Proxy::setDOMException(ec); 212 return v8::Undefined(); 213 } 214 215 return setWebGLArrayFromArray(array, args); 216 } 217 142 218 } 143 219 -
trunk/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp
r50730 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLByteArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLByteArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLBYTEARRAY));51 return constructWebGLArray<WebGLByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLBYTEARRAY)); 51 52 } 52 53 … … 79 80 } 80 81 82 CALLBACK_FUNC_DECL(WebGLByteArrayGet) 83 { 84 INC_STATS("DOM.WebGLByteArray.get()"); 85 return getWebGLArrayElement<WebGLByteArray, signed char>(args, V8ClassIndex::WEBGLBYTEARRAY); 86 } 87 88 CALLBACK_FUNC_DECL(WebGLByteArraySet) 89 { 90 INC_STATS("DOM.WebGLByteArray.set()"); 91 return setWebGLArray<WebGLByteArray, V8WebGLByteArray>(args, V8ClassIndex::WEBGLBYTEARRAY); 92 } 93 81 94 } // namespace WebCore 82 95 -
trunk/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp
r50730 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLFloatArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLFloatArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLFloatArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLFLOATARRAY));51 return constructWebGLArray<WebGLFloatArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLFLOATARRAY)); 51 52 } 52 53 … … 76 77 } 77 78 79 CALLBACK_FUNC_DECL(WebGLFloatArrayGet) 80 { 81 INC_STATS("DOM.WebGLFloatArray.get()"); 82 return getWebGLArrayElement<WebGLFloatArray, float>(args, V8ClassIndex::WEBGLFLOATARRAY); 83 } 84 85 CALLBACK_FUNC_DECL(WebGLFloatArraySet) 86 { 87 INC_STATS("DOM.WebGLFloatArray.set()"); 88 return setWebGLArray<WebGLFloatArray, V8WebGLFloatArray>(args, V8ClassIndex::WEBGLFLOATARRAY); 89 } 90 78 91 } // namespace WebCore 79 92 -
trunk/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp
r50734 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLIntArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLIntArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLINTARRAY));51 return constructWebGLArray<WebGLIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLINTARRAY)); 51 52 } 52 53 … … 79 80 } 80 81 82 CALLBACK_FUNC_DECL(WebGLIntArrayGet) 83 { 84 INC_STATS("DOM.WebGLIntArray.get()"); 85 return getWebGLArrayElement<WebGLIntArray, int>(args, V8ClassIndex::WEBGLINTARRAY); 86 } 87 88 CALLBACK_FUNC_DECL(WebGLIntArraySet) 89 { 90 INC_STATS("DOM.WebGLIntArray.set()"); 91 return setWebGLArray<WebGLIntArray, V8WebGLIntArray>(args, V8ClassIndex::WEBGLINTARRAY); 92 } 93 81 94 } // namespace WebCore 82 95 -
trunk/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp
r50730 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLShortArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLShortArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLSHORTARRAY));51 return constructWebGLArray<WebGLShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLSHORTARRAY)); 51 52 } 52 53 … … 79 80 } 80 81 82 CALLBACK_FUNC_DECL(WebGLShortArrayGet) 83 { 84 INC_STATS("DOM.WebGLShortArray.get()"); 85 return getWebGLArrayElement<WebGLShortArray, short>(args, V8ClassIndex::WEBGLSHORTARRAY); 86 } 87 88 CALLBACK_FUNC_DECL(WebGLShortArraySet) 89 { 90 INC_STATS("DOM.WebGLShortArray.set()"); 91 return setWebGLArray<WebGLShortArray, V8WebGLShortArray>(args, V8ClassIndex::WEBGLSHORTARRAY); 92 } 93 81 94 } // namespace WebCore 82 95 -
trunk/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp
r50730 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLUnsignedByteArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLUnsignedByteArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLUnsignedByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY));51 return constructWebGLArray<WebGLUnsignedByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY)); 51 52 } 52 53 … … 79 80 } 80 81 82 CALLBACK_FUNC_DECL(WebGLUnsignedByteArrayGet) 83 { 84 INC_STATS("DOM.WebGLUnsignedByteArray.get()"); 85 return getWebGLArrayElement<WebGLUnsignedByteArray, unsigned char>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY); 86 } 87 88 CALLBACK_FUNC_DECL(WebGLUnsignedByteArraySet) 89 { 90 INC_STATS("DOM.WebGLUnsignedByteArray.set()"); 91 return setWebGLArray<WebGLUnsignedByteArray, V8WebGLUnsignedByteArray>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY); 92 } 93 81 94 } // namespace WebCore 82 95 -
trunk/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp
r50730 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLUnsignedIntArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLUnsignedIntArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLUnsignedIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDINTARRAY));51 return constructWebGLArray<WebGLUnsignedIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDINTARRAY)); 51 52 } 52 53 … … 79 80 } 80 81 82 CALLBACK_FUNC_DECL(WebGLUnsignedIntArrayGet) 83 { 84 INC_STATS("DOM.WebGLUnsignedIntArray.get()"); 85 return getWebGLArrayElement<WebGLUnsignedIntArray, unsigned int>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY); 86 } 87 88 CALLBACK_FUNC_DECL(WebGLUnsignedIntArraySet) 89 { 90 INC_STATS("DOM.WebGLUnsignedIntArray.set()"); 91 return setWebGLArray<WebGLUnsignedIntArray, V8WebGLUnsignedIntArray>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY); 92 } 93 81 94 } // namespace WebCore 82 95 -
trunk/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp
r50730 r51049 39 39 #include "V8WebGLArrayBuffer.h" 40 40 #include "V8WebGLArrayCustom.h" 41 #include "V8WebGLUnsignedShortArray.h" 41 42 #include "V8CustomBinding.h" 42 43 #include "V8Proxy.h" … … 48 49 INC_STATS("DOM.WebGLUnsignedShortArray.Contructor"); 49 50 50 return construct CanvasArray<WebGLUnsignedShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY));51 return constructWebGLArray<WebGLUnsignedShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY)); 51 52 } 52 53 … … 79 80 } 80 81 82 CALLBACK_FUNC_DECL(WebGLUnsignedShortArrayGet) 83 { 84 INC_STATS("DOM.WebGLUnsignedShortArray.get()"); 85 return getWebGLArrayElement<WebGLUnsignedShortArray, unsigned short>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY); 86 } 87 88 CALLBACK_FUNC_DECL(WebGLUnsignedShortArraySet) 89 { 90 INC_STATS("DOM.WebGLUnsignedShortArray.set()"); 91 return setWebGLArray<WebGLUnsignedShortArray, V8WebGLUnsignedShortArray>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY); 92 } 93 81 94 } // namespace WebCore 82 95 -
trunk/WebCore/html/canvas/WebGLArray.cpp
r50725 r51049 32 32 33 33 namespace WebCore { 34 WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, 35 unsigned offset) 36 : m_offset(offset) 34 35 WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, 36 unsigned byteOffset) 37 : m_byteOffset(byteOffset) 37 38 , m_buffer(buffer) 38 { 39 m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_offset) : 0; 39 { 40 m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_byteOffset) : 0; 41 } 42 43 WebGLArray::~WebGLArray() 44 { 45 } 46 47 void WebGLArray::setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec) 48 { 49 if (byteOffset + array->byteLength() > byteLength()) { 50 ec = INDEX_SIZE_ERR; 51 return; 40 52 } 41 53 42 WebGLArray::~WebGLArray()43 {44 54 char* base = static_cast<char*>(baseAddress()); 55 memcpy(base + byteOffset, array->baseAddress(), array->byteLength()); 56 } 45 57 46 unsigned WebGLArray::alignedSizeInBytes() const {47 // Assume we only need to round up to 4-byte boundaries for alignment.48 return ((sizeInBytes() + 3) / 4) * 4;49 }50 58 } 51 59 -
trunk/WebCore/html/canvas/WebGLArray.h
r50725 r51049 27 27 #define WebGLArray_h 28 28 29 #include "ExceptionCode.h" 29 30 #include <wtf/PassRefPtr.h> 30 31 #include <wtf/RefCounted.h> … … 33 34 34 35 namespace WebCore { 35 class WebGLArray : public RefCounted<WebGLArray> {36 public:37 virtual bool isByteArray() const { return false; }38 virtual bool isUnsignedByteArray() const { return false; }39 virtual bool isShortArray() const { return false; }40 virtual bool isUnsignedShortArray() const { return false; }41 virtual bool isIntArray() const { return false; }42 virtual bool isUnsignedIntArray() const { return false; }43 virtual bool isFloatArray() const { return false; }44 45 PassRefPtr<WebGLArrayBuffer> buffer() {46 return m_buffer;47 }48 36 49 void* baseAddress() { 50 return m_baseAddress; 51 } 37 class WebGLArray : public RefCounted<WebGLArray> { 38 public: 39 virtual bool isByteArray() const { return false; } 40 virtual bool isUnsignedByteArray() const { return false; } 41 virtual bool isShortArray() const { return false; } 42 virtual bool isUnsignedShortArray() const { return false; } 43 virtual bool isIntArray() const { return false; } 44 virtual bool isUnsignedIntArray() const { return false; } 45 virtual bool isFloatArray() const { return false; } 52 46 53 unsigned offset() const{54 return m_offset;55 47 PassRefPtr<WebGLArrayBuffer> buffer() { 48 return m_buffer; 49 } 56 50 57 virtual unsigned length() const = 0; 58 virtual unsigned sizeInBytes() const = 0; 59 virtual unsigned alignedSizeInBytes() const; 60 virtual ~WebGLArray(); 51 void* baseAddress() { 52 return m_baseAddress; 53 } 61 54 62 protected: 63 WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned offset); 55 unsigned byteOffset() const { 56 return m_byteOffset; 57 } 64 58 65 // This is the address of the WebGLArrayBuffer's storage, plus the offset. 66 void* m_baseAddress; 67 unsigned m_offset; 68 69 private: 70 RefPtr<WebGLArrayBuffer> m_buffer; 71 }; 72 59 virtual unsigned length() const = 0; 60 virtual unsigned byteLength() const = 0; 61 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length) = 0; 62 63 virtual ~WebGLArray(); 64 65 protected: 66 WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset); 67 68 void setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec); 69 70 // This is the address of the WebGLArrayBuffer's storage, plus the byte offset. 71 void* m_baseAddress; 72 73 unsigned m_byteOffset; 74 75 private: 76 RefPtr<WebGLArrayBuffer> m_buffer; 77 }; 78 73 79 } // namespace WebCore 74 80 -
trunk/WebCore/html/canvas/WebGLArray.idl
r50725 r51049 26 26 module html { 27 27 interface [Conditional=3D_CANVAS, CustomToJS] WebGLArray { 28 readonly attribute long length; 29 int sizeInBytes(); 30 int alignedSizeInBytes(); 28 readonly attribute WebGLArrayBuffer buffer; 29 readonly attribute unsigned long byteOffset; 30 readonly attribute unsigned long byteLength; 31 readonly attribute unsigned long length; 32 33 WebGLArray slice(in unsigned long offset, in unsigned long length); 31 34 }; 32 35 } -
trunk/WebCore/html/canvas/WebGLArrayBuffer.cpp
r50725 r51049 31 31 32 32 namespace WebCore { 33 34 PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(unsigned sizeInBytes)35 {36 return adoptRef(new WebGLArrayBuffer(sizeInBytes));37 }38 39 WebGLArrayBuffer::WebGLArrayBuffer(unsigned sizeInBytes) {40 m_sizeInBytes = sizeInBytes;41 m_data = WTF::fastZeroedMalloc(sizeInBytes);42 }43 44 void* WebGLArrayBuffer::data() {45 return m_data;46 }47 33 48 unsigned WebGLArrayBuffer::byteLength() const { 49 return m_sizeInBytes; 50 } 34 PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(unsigned sizeInBytes) 35 { 36 return adoptRef(new WebGLArrayBuffer(sizeInBytes)); 37 } 51 38 52 WebGLArrayBuffer::~WebGLArrayBuffer() { 53 WTF::fastFree(m_data); 54 } 39 WebGLArrayBuffer::WebGLArrayBuffer(unsigned sizeInBytes) { 40 m_sizeInBytes = sizeInBytes; 41 m_data = WTF::fastZeroedMalloc(sizeInBytes); 42 } 43 44 void* WebGLArrayBuffer::data() { 45 return m_data; 46 } 47 48 unsigned WebGLArrayBuffer::byteLength() const { 49 return m_sizeInBytes; 50 } 51 52 WebGLArrayBuffer::~WebGLArrayBuffer() { 53 WTF::fastFree(m_data); 54 } 55 55 56 } 56 57 -
trunk/WebCore/html/canvas/WebGLArrayBuffer.h
r50725 r51049 31 31 32 32 namespace WebCore { 33 34 class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> {35 public:36 static PassRefPtr<WebGLArrayBuffer> create(unsigned sizeInBytes);37 33 38 void* data(); 39 unsigned byteLength() const; 34 class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> { 35 public: 36 static PassRefPtr<WebGLArrayBuffer> create(unsigned sizeInBytes); 40 37 41 ~WebGLArrayBuffer(); 38 void* data(); 39 unsigned byteLength() const; 42 40 43 private: 44 WebGLArrayBuffer(unsigned sizeInBytes); 45 unsigned m_sizeInBytes; 46 void* m_data; 47 }; 48 41 ~WebGLArrayBuffer(); 42 43 private: 44 WebGLArrayBuffer(unsigned sizeInBytes); 45 unsigned m_sizeInBytes; 46 void* m_data; 47 }; 48 49 49 } // namespace WebCore 50 50 -
trunk/WebCore/html/canvas/WebGLByteArray.cpp
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 32 33 33 34 namespace WebCore { 34 35 35 36 PassRefPtr<WebGLByteArray> WebGLByteArray::create(unsigned length) 36 37 { … … 47 48 } 48 49 49 PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length)50 PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 50 51 { 51 52 if (buffer) { 52 53 // Check to make sure we are talking about a valid region of 53 54 // the given WebGLArrayBuffer's storage. 54 if (( offset + (length * sizeof(signed char))) > buffer->byteLength())55 if ((byteOffset + (length * sizeof(signed char))) > buffer->byteLength()) 55 56 return NULL; 56 57 } 57 58 return adoptRef(new WebGLByteArray(buffer, offset, length));58 59 return adoptRef(new WebGLByteArray(buffer, byteOffset, length)); 59 60 } 60 61 … … 68 69 return m_size; 69 70 } 70 71 unsigned WebGLByteArray::sizeInBytes() const { 72 return length() * sizeof(signed char); 71 72 unsigned WebGLByteArray::byteLength() const { 73 return m_size * sizeof(signed char); 74 } 75 76 PassRefPtr<WebGLArray> WebGLByteArray::slice(unsigned offset, unsigned length) { 77 // Check to make sure the specified region is within the bounds of 78 // the WebGLArrayBuffer. 79 unsigned startByte = m_byteOffset + offset * sizeof(signed char); 80 unsigned limitByte = startByte + length * sizeof(signed char); 81 unsigned bufferLength = buffer()->byteLength(); 82 if (startByte >= bufferLength || limitByte > bufferLength) 83 return 0; 84 return create(buffer(), startByte, length); 85 } 86 87 void WebGLByteArray::set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec) { 88 setImpl(array, offset * sizeof(signed char), ec); 73 89 } 74 90 -
trunk/WebCore/html/canvas/WebGLByteArray.h
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 34 35 35 36 namespace WebCore { 36 37 class WebGLArrayBuffer;38 37 39 class WebGLByteArray : public WebGLArray { 40 public: 41 virtual bool isByteArray() const { return true; } 38 class WebGLArrayBuffer; 42 39 43 static PassRefPtr<WebGLByteArray> create(unsigned length); 44 static PassRefPtr<WebGLByteArray> create(signed char* array, unsigned length);45 static PassRefPtr<WebGLByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);40 class WebGLByteArray : public WebGLArray { 41 public: 42 virtual bool isByteArray() const { return true; } 46 43 47 char* data() { return static_cast<char*>(baseAddress()); } 44 static PassRefPtr<WebGLByteArray> create(unsigned length); 45 static PassRefPtr<WebGLByteArray> create(signed char* array, unsigned length); 46 static PassRefPtr<WebGLByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 48 47 49 virtual unsigned length() const; 50 virtual unsigned sizeInBytes() const; 48 char* data() { return static_cast<char*>(baseAddress()); } 51 49 52 void set(unsigned index, double value) 53 { 54 if (index >= m_size) 55 return; 56 if (isnan(value)) // Clamp NaN to 0 57 value = 0; 58 if (value < std::numeric_limits<signed char>::min()) 59 value = std::numeric_limits<signed char>::min(); 60 else if (value > std::numeric_limits<signed char>::max()) 61 value = std::numeric_limits<signed char>::max(); 62 signed char* storage = static_cast<signed char*>(m_baseAddress); 63 storage[index] = static_cast<signed char>(value); 64 } 65 66 bool get(unsigned index, signed char& result) const 67 { 68 if (index >= m_size) 69 return false; 70 signed char* storage = static_cast<signed char*>(m_baseAddress); 71 result = storage[index]; 72 return true; 73 } 50 virtual unsigned length() const; 51 virtual unsigned byteLength() const; 52 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 74 53 75 signed char item(unsigned index) const 76 { 77 ASSERT(index < m_size); 78 signed char* storage = static_cast<signed char*>(m_baseAddress); 79 return storage[index]; 80 } 81 private: 82 WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, 83 int offset, 84 unsigned length); 85 unsigned m_size; 86 }; 87 54 void set(unsigned index, double value) 55 { 56 if (index >= m_size) 57 return; 58 if (isnan(value)) // Clamp NaN to 0 59 value = 0; 60 if (value < std::numeric_limits<signed char>::min()) 61 value = std::numeric_limits<signed char>::min(); 62 else if (value > std::numeric_limits<signed char>::max()) 63 value = std::numeric_limits<signed char>::max(); 64 signed char* storage = static_cast<signed char*>(m_baseAddress); 65 storage[index] = static_cast<signed char>(value); 66 } 67 68 bool get(unsigned index, signed char& result) const 69 { 70 if (index >= m_size) 71 return false; 72 signed char* storage = static_cast<signed char*>(m_baseAddress); 73 result = storage[index]; 74 return true; 75 } 76 77 signed char get(unsigned index) const 78 { 79 return item(index); 80 } 81 82 signed char item(unsigned index) const 83 { 84 ASSERT(index < m_size); 85 signed char* storage = static_cast<signed char*>(m_baseAddress); 86 return storage[index]; 87 } 88 89 void set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec); 90 91 private: 92 WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, 93 int offset, 94 unsigned length); 95 unsigned m_size; 96 }; 97 88 98 } // namespace WebCore 89 99 -
trunk/WebCore/html/canvas/WebGLByteArray.idl
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 CustomToJS 34 35 ] WebGLByteArray : WebGLArray { 36 long get(in unsigned long index); 37 // void set(in unsigned long index, in long value); 38 // void set(in WebGLByteArray array, [Optional] in unsigned long offset); 39 // void set(in sequence<long> array, [Optional] in unsigned long offset); 40 [Custom] void set(); 35 41 }; 36 42 } -
trunk/WebCore/html/canvas/WebGLFloatArray.cpp
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 31 32 32 33 namespace WebCore { 33 34 PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(unsigned length) 35 { 36 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(float)); 37 return create(buffer, 0, length); 34 35 PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(float)); 38 return create(buffer, 0, length); 39 } 40 41 PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(float* array, unsigned length) 42 { 43 RefPtr<WebGLFloatArray> a = WebGLFloatArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 47 } 48 49 PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 50 { 51 // Make sure the offset results in valid alignment. 52 if ((byteOffset % sizeof(float)) != 0) 53 return NULL; 54 55 if (buffer) { 56 // Check to make sure we are talking about a valid region of 57 // the given WebGLArrayBuffer's storage. 58 if ((byteOffset + (length * sizeof(float))) > buffer->byteLength()) 59 return NULL; 38 60 } 61 return adoptRef(new WebGLFloatArray(buffer, byteOffset, length)); 62 } 39 63 40 PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(float* array, unsigned length) 41 { 42 RefPtr<WebGLFloatArray> a = WebGLFloatArray::create(length); 43 for (unsigned i = 0; i < length; ++i) 44 a->set(i, array[i]); 45 return a; 46 } 64 WebGLFloatArray::WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 65 : WebGLArray(buffer, byteOffset) 66 , m_size(length) 67 { 68 } 47 69 48 PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) 49 { 50 // Make sure the offset results in valid alignment. 51 if ((offset % sizeof(float)) != 0) 52 return NULL; 70 unsigned WebGLFloatArray::length() const { 71 return m_size; 72 } 53 73 54 if (buffer) { 55 // Check to make sure we are talking about a valid region of 56 // the given WebGLArrayBuffer's storage. 57 if ((offset + (length * sizeof(float))) > buffer->byteLength()) 58 return NULL; 59 } 60 return adoptRef(new WebGLFloatArray(buffer, offset, length)); 61 } 62 63 WebGLFloatArray::WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) 64 : WebGLArray(buffer, offset) 65 , m_size(length) 66 { 67 } 68 69 unsigned WebGLFloatArray::length() const { 70 return m_size; 71 } 72 73 unsigned WebGLFloatArray::sizeInBytes() const { 74 return length() * sizeof(float); 75 } 74 unsigned WebGLFloatArray::byteLength() const { 75 return m_size * sizeof(float); 76 } 77 78 PassRefPtr<WebGLArray> WebGLFloatArray::slice(unsigned offset, unsigned length) { 79 // Check to make sure the specified region is within the bounds of 80 // the WebGLArrayBuffer. 81 unsigned startByte = m_byteOffset + offset * sizeof(float); 82 unsigned limitByte = startByte + length * sizeof(float); 83 unsigned bufferLength = buffer()->byteLength(); 84 if (startByte >= bufferLength || limitByte > bufferLength) 85 return 0; 86 return create(buffer(), startByte, length); 87 } 88 89 void WebGLFloatArray::set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec) { 90 setImpl(array, offset * sizeof(float), ec); 91 } 92 76 93 } 77 94 -
trunk/WebCore/html/canvas/WebGLFloatArray.h
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 34 35 namespace WebCore { 35 36 class WebGLFloatArray : public WebGLArray {37 public:38 virtual bool isFloatArray() const { return true; }39 36 40 static PassRefPtr<WebGLFloatArray> create(unsigned length); 41 static PassRefPtr<WebGLFloatArray> create(float* array, unsigned length);42 static PassRefPtr<WebGLFloatArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);37 class WebGLFloatArray : public WebGLArray { 38 public: 39 virtual bool isFloatArray() const { return true; } 43 40 44 float* data() { return static_cast<float*>(baseAddress()); } 41 static PassRefPtr<WebGLFloatArray> create(unsigned length); 42 static PassRefPtr<WebGLFloatArray> create(float* array, unsigned length); 43 static PassRefPtr<WebGLFloatArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 45 44 46 virtual unsigned length() const; 47 48 virtual unsigned sizeInBytes() const; 45 float* data() { return static_cast<float*>(baseAddress()); } 49 46 50 void set(unsigned index, double value) 51 { 52 if (index >= m_size) 53 return; 54 if (isnan(value)) // Clamp NaN to 0 55 value = 0; 56 float* storage = static_cast<float*>(m_baseAddress); 57 storage[index] = static_cast<float>(value); 47 virtual unsigned length() const; 48 virtual unsigned byteLength() const; 49 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 50 51 void set(unsigned index, double value) 52 { 53 if (index >= m_size) 54 return; 55 if (isnan(value)) // Clamp NaN to 0 56 value = 0; 57 float* storage = static_cast<float*>(m_baseAddress); 58 storage[index] = static_cast<float>(value); 59 } 60 61 bool get(unsigned index, float& result) const 62 { 63 if (index >= m_size) 64 return false; 65 result = item(index); 66 return true; 67 } 68 69 float get(unsigned index) const 70 { 71 return item(index); 72 } 73 74 float item(unsigned index) const 75 { 76 ASSERT(index < m_size); 77 float* storage = static_cast<float*>(m_baseAddress); 78 float result = storage[index]; 79 if (isnan(result)) { 80 // Clamp NaN to 0 81 result = 0; 58 82 } 59 60 bool get(unsigned index, float& result) const 61 { 62 if (index >= m_size) 63 return false; 64 result = item(index); 65 return true; 66 } 67 68 float item(unsigned index) const 69 { 70 ASSERT(index < m_size); 71 float* storage = static_cast<float*>(m_baseAddress); 72 float result = storage[index]; 73 if (isnan(result)) { 74 // Clamp NaN to 0 75 result = 0; 76 } 77 return result; 78 } 79 private: 80 WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length); 81 unsigned m_size; 82 }; 83 83 return result; 84 } 85 86 void set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec); 87 88 private: 89 WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 90 unsigned m_size; 91 }; 92 84 93 } // namespace WebCore 85 94 -
trunk/WebCore/html/canvas/WebGLFloatArray.idl
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 CustomToJS 34 35 ] WebGLFloatArray : WebGLArray { 36 long get(in unsigned long index); 37 // void set(in unsigned long index, in long value); 38 // void set(in WebGLFloatArray array, [Optional] in unsigned long offset); 39 // void set(in sequence<long> array, [Optional] in unsigned long offset); 40 [Custom] void set(); 35 41 }; 36 42 } -
trunk/WebCore/html/canvas/WebGLIntArray.cpp
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 32 33 33 34 namespace WebCore { 34 35 PassRefPtr<WebGLIntArray> WebGLIntArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(int)); 38 return create(buffer, 0, length); 35 36 PassRefPtr<WebGLIntArray> WebGLIntArray::create(unsigned length) 37 { 38 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(int)); 39 return create(buffer, 0, length); 40 } 41 42 PassRefPtr<WebGLIntArray> WebGLIntArray::create(int* array, unsigned length) 43 { 44 RefPtr<WebGLIntArray> a = WebGLIntArray::create(length); 45 for (unsigned i = 0; i < length; ++i) 46 a->set(i, array[i]); 47 return a; 48 } 49 50 PassRefPtr<WebGLIntArray> WebGLIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 51 int byteOffset, 52 unsigned length) 53 { 54 // Make sure the offset results in valid alignment. 55 if ((byteOffset % sizeof(int)) != 0) 56 return NULL; 57 58 if (buffer) { 59 // Check to make sure we are talking about a valid region of 60 // the given WebGLArrayBuffer's storage. 61 if ((byteOffset + (length * sizeof(int))) > buffer->byteLength()) 62 return NULL; 39 63 } 40 64 41 PassRefPtr<WebGLIntArray> WebGLIntArray::create(int* array, unsigned length) 42 { 43 RefPtr<WebGLIntArray> a = WebGLIntArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 47 } 65 return adoptRef(new WebGLIntArray(buffer, byteOffset, length)); 66 } 48 67 49 PassRefPtr<WebGLIntArray> WebGLIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 50 int offset, 51 unsigned length) 52 { 53 // Make sure the offset results in valid alignment. 54 if ((offset % sizeof(int)) != 0) 55 return NULL; 68 WebGLIntArray::WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 69 : WebGLArray(buffer, byteOffset) 70 , m_size(length) 71 { 72 } 56 73 57 if (buffer){58 // Check to make sure we are talking about a valid region of59 // the given WebGLArrayBuffer's storage. 60 if ((offset + (length * sizeof(int))) > buffer->byteLength()) 61 return NULL; 62 }63 64 return adoptRef(new WebGLIntArray(buffer, offset, length)); 65 } 66 67 WebGLIntArray::WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length)68 : WebGLArray(buffer, offset)69 , m_size(length)70 {71 }72 73 unsigned WebGLIntArray::length() const {74 return m_size; 75 } 76 77 unsigned WebGLIntArray::sizeInBytes() const {78 return length() * sizeof(int); 79 } 74 unsigned WebGLIntArray::length() const { 75 return m_size; 76 } 77 78 unsigned WebGLIntArray::byteLength() const { 79 return m_size * sizeof(int); 80 } 81 82 PassRefPtr<WebGLArray> WebGLIntArray::slice(unsigned offset, unsigned length) { 83 // Check to make sure the specified region is within the bounds of 84 // the WebGLArrayBuffer. 85 unsigned startByte = m_byteOffset + offset * sizeof(int); 86 unsigned limitByte = startByte + length * sizeof(int); 87 unsigned bufferLength = buffer()->byteLength(); 88 if (startByte >= bufferLength || limitByte > bufferLength) 89 return 0; 90 return create(buffer(), startByte, length); 91 } 92 93 void WebGLIntArray::set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec) { 94 setImpl(array, offset * sizeof(int), ec); 95 } 96 80 97 } 81 98 -
trunk/WebCore/html/canvas/WebGLIntArray.h
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 34 35 35 36 namespace WebCore { 36 37 class WebGLIntArray : public WebGLArray {38 public:39 virtual bool isIntArray() const { return true; }40 37 41 static PassRefPtr<WebGLIntArray> create(unsigned length); 42 static PassRefPtr<WebGLIntArray> create(int* array, unsigned length);43 static PassRefPtr<WebGLIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);38 class WebGLIntArray : public WebGLArray { 39 public: 40 virtual bool isIntArray() const { return true; } 44 41 45 int* data() { return static_cast<int*>(baseAddress()); } 42 static PassRefPtr<WebGLIntArray> create(unsigned length); 43 static PassRefPtr<WebGLIntArray> create(int* array, unsigned length); 44 static PassRefPtr<WebGLIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 46 45 47 virtual unsigned length() const; 48 virtual unsigned sizeInBytes() const; 46 int* data() { return static_cast<int*>(baseAddress()); } 49 47 50 void set(unsigned index, double value) 51 { 52 if (index >= m_size) 53 return; 54 if (isnan(value)) // Clamp NaN to 0 55 value = 0; 56 if (value < std::numeric_limits<int>::min()) 57 value = std::numeric_limits<int>::min(); 58 else if (value > std::numeric_limits<int>::max()) 59 value = std::numeric_limits<int>::max(); 60 int* storage = static_cast<int*>(m_baseAddress); 61 storage[index] = static_cast<int>(value); 62 } 63 64 bool get(unsigned index, int& result) const 65 { 66 if (index >= m_size) 67 return false; 68 result = item(index); 69 return true; 70 } 71 72 int item(unsigned index) const 73 { 74 ASSERT(index < m_size); 75 int* storage = static_cast<int*>(m_baseAddress); 76 return storage[index]; 77 } 48 virtual unsigned length() const; 49 virtual unsigned byteLength() const; 50 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 78 51 79 private: 80 WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, 81 int offset, 82 unsigned length); 83 unsigned m_size; 84 }; 85 52 void set(unsigned index, double value) 53 { 54 if (index >= m_size) 55 return; 56 if (isnan(value)) // Clamp NaN to 0 57 value = 0; 58 if (value < std::numeric_limits<int>::min()) 59 value = std::numeric_limits<int>::min(); 60 else if (value > std::numeric_limits<int>::max()) 61 value = std::numeric_limits<int>::max(); 62 int* storage = static_cast<int*>(m_baseAddress); 63 storage[index] = static_cast<int>(value); 64 } 65 66 bool get(unsigned index, int& result) const 67 { 68 if (index >= m_size) 69 return false; 70 result = item(index); 71 return true; 72 } 73 74 int get(unsigned index) const 75 { 76 return item(index); 77 } 78 79 int item(unsigned index) const 80 { 81 ASSERT(index < m_size); 82 int* storage = static_cast<int*>(m_baseAddress); 83 return storage[index]; 84 } 85 86 void set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec); 87 88 private: 89 WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, 90 int byteOffset, 91 unsigned length); 92 unsigned m_size; 93 }; 94 86 95 } // namespace WebCore 87 96 -
trunk/WebCore/html/canvas/WebGLIntArray.idl
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 CustomToJS 34 35 ] WebGLIntArray : WebGLArray { 36 long get(in unsigned long index); 37 // void set(in unsigned long index, in long value); 38 // void set(in WebGLIntArray array, [Optional] in unsigned long offset); 39 // void set(in sequence<long> array, [Optional] in unsigned long offset); 40 [Custom] void set(); 35 41 }; 36 42 } -
trunk/WebCore/html/canvas/WebGLShortArray.cpp
r50725 r51049 32 32 33 33 namespace WebCore { 34 35 PassRefPtr<WebGLShortArray> WebGLShortArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(short)); 38 return create(buffer, 0, length); 34 35 PassRefPtr<WebGLShortArray> WebGLShortArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(short)); 38 return create(buffer, 0, length); 39 } 40 41 PassRefPtr<WebGLShortArray> WebGLShortArray::create(short* array, unsigned length) 42 { 43 RefPtr<WebGLShortArray> a = WebGLShortArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 47 } 48 49 PassRefPtr<WebGLShortArray> WebGLShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 50 int byteOffset, 51 unsigned length) 52 { 53 // Make sure the offset results in valid alignment. 54 if ((byteOffset % sizeof(short)) != 0) 55 return NULL; 56 57 if (buffer) { 58 // Check to make sure we are talking about a valid region of 59 // the given WebGLArrayBuffer's storage. 60 if ((byteOffset + (length * sizeof(short))) > buffer->byteLength()) 61 return NULL; 39 62 } 40 63 41 PassRefPtr<WebGLShortArray> WebGLShortArray::create(short* array, unsigned length) 42 { 43 RefPtr<WebGLShortArray> a = WebGLShortArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 47 } 64 return adoptRef(new WebGLShortArray(buffer, byteOffset, length)); 65 } 48 66 49 PassRefPtr<WebGLShortArray> WebGLShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 50 int offset, 51 unsigned length) 52 { 53 // Make sure the offset results in valid alignment. 54 if ((offset % sizeof(short)) != 0) 55 return NULL; 67 WebGLShortArray::WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 68 : WebGLArray(buffer, byteOffset) 69 , m_size(length) 70 { 71 } 56 72 57 if (buffer) { 58 // Check to make sure we are talking about a valid region of 59 // the given WebGLArrayBuffer's storage. 60 if ((offset + (length * sizeof(short))) > buffer->byteLength()) 61 return NULL; 62 } 73 unsigned WebGLShortArray::length() const { 74 return m_size; 75 } 63 76 64 return adoptRef(new WebGLShortArray(buffer, offset, length)); 65 } 66 67 WebGLShortArray::WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) 68 : WebGLArray(buffer, offset) 69 , m_size(length) 70 { 71 } 72 73 unsigned WebGLShortArray::length() const { 74 return m_size; 75 } 76 77 unsigned WebGLShortArray::sizeInBytes() const { 78 return length() * sizeof(short); 79 } 77 unsigned WebGLShortArray::byteLength() const { 78 return m_size * sizeof(short); 79 } 80 81 PassRefPtr<WebGLArray> WebGLShortArray::slice(unsigned offset, unsigned length) { 82 // Check to make sure the specified region is within the bounds of 83 // the WebGLArrayBuffer. 84 unsigned startByte = m_byteOffset + offset * sizeof(short); 85 unsigned limitByte = startByte + length * sizeof(short); 86 unsigned bufferLength = buffer()->byteLength(); 87 if (startByte >= bufferLength || limitByte > bufferLength) 88 return 0; 89 return create(buffer(), startByte, length); 90 } 91 92 void WebGLShortArray::set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec) { 93 setImpl(array, offset * sizeof(short), ec); 94 } 95 80 96 } 81 97 -
trunk/WebCore/html/canvas/WebGLShortArray.h
r50725 r51049 34 34 35 35 namespace WebCore { 36 37 class WebGLShortArray : public WebGLArray {38 public:39 virtual bool isShortArray() const { return true; }40 36 41 static PassRefPtr<WebGLShortArray> create(unsigned length); 42 static PassRefPtr<WebGLShortArray> create(short* array, unsigned length);43 static PassRefPtr<WebGLShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);37 class WebGLShortArray : public WebGLArray { 38 public: 39 virtual bool isShortArray() const { return true; } 44 40 45 short* data() { return static_cast<short*>(baseAddress()); } 41 static PassRefPtr<WebGLShortArray> create(unsigned length); 42 static PassRefPtr<WebGLShortArray> create(short* array, unsigned length); 43 static PassRefPtr<WebGLShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 46 44 47 virtual unsigned length() const; 48 virtual unsigned sizeInBytes() const; 45 short* data() { return static_cast<short*>(baseAddress()); } 49 46 50 void set(unsigned index, double value) 51 { 52 if (index >= m_size) 53 return; 54 if (isnan(value)) // Clamp NaN to 0 55 value = 0; 56 if (value < std::numeric_limits<short>::min()) 57 value = std::numeric_limits<short>::min(); 58 else if (value > std::numeric_limits<short>::max()) 59 value = std::numeric_limits<short>::max(); 60 short* storage = static_cast<short*>(m_baseAddress); 61 storage[index] = static_cast<short>(value); 62 } 63 64 bool get(unsigned index, short& result) const 65 { 66 if (index >= m_size) 67 return false; 68 result = item(index); 69 return true; 70 } 71 72 short item(unsigned index) const 73 { 74 ASSERT(index < m_size); 75 short* storage = static_cast<short*>(m_baseAddress); 76 return storage[index]; 77 } 47 virtual unsigned length() const; 48 virtual unsigned byteLength() const; 49 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 78 50 79 private: 80 WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length); 81 unsigned m_size; 82 }; 83 51 void set(unsigned index, double value) 52 { 53 if (index >= m_size) 54 return; 55 if (isnan(value)) // Clamp NaN to 0 56 value = 0; 57 if (value < std::numeric_limits<short>::min()) 58 value = std::numeric_limits<short>::min(); 59 else if (value > std::numeric_limits<short>::max()) 60 value = std::numeric_limits<short>::max(); 61 short* storage = static_cast<short*>(m_baseAddress); 62 storage[index] = static_cast<short>(value); 63 } 64 65 bool get(unsigned index, short& result) const 66 { 67 if (index >= m_size) 68 return false; 69 result = item(index); 70 return true; 71 } 72 73 short get(unsigned index) const 74 { 75 return item(index); 76 } 77 78 short item(unsigned index) const 79 { 80 ASSERT(index < m_size); 81 short* storage = static_cast<short*>(m_baseAddress); 82 return storage[index]; 83 } 84 85 void set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec); 86 87 private: 88 WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 89 unsigned m_size; 90 }; 91 84 92 } // namespace WebCore 85 93 -
trunk/WebCore/html/canvas/WebGLShortArray.idl
r50725 r51049 33 33 CustomToJS 34 34 ] WebGLShortArray : WebGLArray { 35 long get(in unsigned long index); 36 // void set(in unsigned long index, in long value); 37 // void set(in WebGLShortArray array, [Optional] in unsigned long offset); 38 // void set(in sequence<long> array, [Optional] in unsigned long offset); 39 [Custom] void set(); 35 40 }; 36 41 } -
trunk/WebCore/html/canvas/WebGLUnsignedByteArray.cpp
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 32 33 33 34 namespace WebCore { 34 35 PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned char)); 38 return create(buffer, 0, length); 35 36 PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned length) 37 { 38 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned char)); 39 return create(buffer, 0, length); 40 } 41 42 PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned char* array, unsigned length) 43 { 44 RefPtr<WebGLUnsignedByteArray> a = WebGLUnsignedByteArray::create(length); 45 for (unsigned i = 0; i < length; ++i) 46 a->set(i, array[i]); 47 return a; 48 } 49 50 PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 51 int byteOffset, 52 unsigned length) 53 { 54 if (buffer) { 55 // Check to make sure we are talking about a valid region of 56 // the given WebGLArrayBuffer's storage. 57 if ((byteOffset + (length * sizeof(unsigned char))) > buffer->byteLength()) 58 return NULL; 39 59 } 40 60 41 PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned char* array, unsigned length) 42 { 43 RefPtr<WebGLUnsignedByteArray> a = WebGLUnsignedByteArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 47 } 61 return adoptRef(new WebGLUnsignedByteArray(buffer, byteOffset, length)); 62 } 48 63 49 PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 50 int offset, 51 unsigned length) 52 { 53 if (buffer) { 54 // Check to make sure we are talking about a valid region of 55 // the given WebGLArrayBuffer's storage. 56 if ((offset + (length * sizeof(unsigned char))) > buffer->byteLength()) 57 return NULL; 58 } 64 WebGLUnsignedByteArray::WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 65 : WebGLArray(buffer, byteOffset) 66 , m_size(length) 67 { 68 } 59 69 60 return adoptRef(new WebGLUnsignedByteArray(buffer, offset, length)); 61 } 62 63 WebGLUnsignedByteArray::WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) 64 : WebGLArray(buffer, offset) 65 , m_size(length) 66 { 67 } 68 69 unsigned WebGLUnsignedByteArray::length() const { 70 return m_size; 71 } 72 73 unsigned WebGLUnsignedByteArray::sizeInBytes() const { 74 return length() * sizeof(unsigned char); 75 } 70 unsigned WebGLUnsignedByteArray::length() const { 71 return m_size; 72 } 73 74 unsigned WebGLUnsignedByteArray::byteLength() const { 75 return m_size * sizeof(unsigned char); 76 } 77 78 PassRefPtr<WebGLArray> WebGLUnsignedByteArray::slice(unsigned offset, unsigned length) { 79 // Check to make sure the specified region is within the bounds of 80 // the WebGLArrayBuffer. 81 unsigned startByte = m_byteOffset + offset * sizeof(unsigned char); 82 unsigned limitByte = startByte + length * sizeof(unsigned char); 83 unsigned bufferLength = buffer()->byteLength(); 84 if (startByte >= bufferLength || limitByte > bufferLength) 85 return 0; 86 return create(buffer(), startByte, length); 87 } 88 89 void WebGLUnsignedByteArray::set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec) { 90 setImpl(array, offset * sizeof(unsigned char), ec); 91 } 92 76 93 } 77 94 -
trunk/WebCore/html/canvas/WebGLUnsignedByteArray.h
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 34 35 35 36 namespace WebCore { 36 37 class WebGLUnsignedByteArray : public WebGLArray {38 public:39 virtual bool isUnsignedByteArray() const { return true; }40 37 41 static PassRefPtr<WebGLUnsignedByteArray> create(unsigned length); 42 static PassRefPtr<WebGLUnsignedByteArray> create(unsigned char* array, unsigned length);43 static PassRefPtr<WebGLUnsignedByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);38 class WebGLUnsignedByteArray : public WebGLArray { 39 public: 40 virtual bool isUnsignedByteArray() const { return true; } 44 41 45 unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } 46 47 virtual unsigned length() const; 48 virtual unsigned sizeInBytes() const; 42 static PassRefPtr<WebGLUnsignedByteArray> create(unsigned length); 43 static PassRefPtr<WebGLUnsignedByteArray> create(unsigned char* array, unsigned length); 44 static PassRefPtr<WebGLUnsignedByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 49 45 50 void set(unsigned index, double value) 51 { 52 if (index >= m_size) 53 return; 54 if (isnan(value)) // Clamp NaN to 0 55 value = 0; 56 if (value < std::numeric_limits<unsigned char>::min()) 57 value = std::numeric_limits<unsigned char>::min(); 58 else if (value > std::numeric_limits<unsigned char>::max()) 59 value = std::numeric_limits<unsigned char>::max(); 60 unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); 61 storage[index] = static_cast<unsigned char>(value); 62 } 63 64 bool get(unsigned index, unsigned char& result) const 65 { 66 if (index >= m_size) 67 return false; 68 result = item(index); 69 return true; 70 } 71 72 unsigned char item(unsigned index) const 73 { 74 ASSERT(index < m_size); 75 unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); 76 return storage[index]; 77 } 46 unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } 78 47 79 private: 80 WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length); 81 unsigned m_size; 82 }; 83 48 virtual unsigned length() const; 49 virtual unsigned byteLength() const; 50 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 51 52 void set(unsigned index, double value) 53 { 54 if (index >= m_size) 55 return; 56 if (isnan(value)) // Clamp NaN to 0 57 value = 0; 58 if (value < std::numeric_limits<unsigned char>::min()) 59 value = std::numeric_limits<unsigned char>::min(); 60 else if (value > std::numeric_limits<unsigned char>::max()) 61 value = std::numeric_limits<unsigned char>::max(); 62 unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); 63 storage[index] = static_cast<unsigned char>(value); 64 } 65 66 bool get(unsigned index, unsigned char& result) const 67 { 68 if (index >= m_size) 69 return false; 70 result = item(index); 71 return true; 72 } 73 74 unsigned char get(unsigned index) const 75 { 76 return item(index); 77 } 78 79 unsigned char item(unsigned index) const 80 { 81 ASSERT(index < m_size); 82 unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); 83 return storage[index]; 84 } 85 86 void set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec); 87 88 private: 89 WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 90 unsigned m_size; 91 }; 92 84 93 } // namespace WebCore 85 94 -
trunk/WebCore/html/canvas/WebGLUnsignedByteArray.idl
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 CustomToJS 34 35 ] WebGLUnsignedByteArray : WebGLArray { 36 long get(in unsigned long index); 37 // void set(in unsigned long index, in long value); 38 // void set(in WebGLUnsignedByteArray array, [Optional] in unsigned long offset); 39 // void set(in sequence<long> array, [Optional] in unsigned long offset); 40 [Custom] void set(); 35 41 }; 36 42 } -
trunk/WebCore/html/canvas/WebGLUnsignedIntArray.cpp
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 32 33 33 34 namespace WebCore { 34 35 PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned int)); 38 return create(buffer, 0, length); 35 36 PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned length) 37 { 38 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned int)); 39 return create(buffer, 0, length); 40 } 41 42 PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned int* array, unsigned length) 43 { 44 RefPtr<WebGLUnsignedIntArray> a = WebGLUnsignedIntArray::create(length); 45 for (unsigned i = 0; i < length; ++i) 46 a->set(i, array[i]); 47 return a; 48 } 49 50 PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 51 int byteOffset, 52 unsigned length) 53 { 54 // Make sure the offset results in valid alignment. 55 if ((byteOffset % sizeof(unsigned int)) != 0) { 56 return NULL; 39 57 } 40 58 41 PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned int* array, unsigned length) 42 { 43 RefPtr<WebGLUnsignedIntArray> a = WebGLUnsignedIntArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 59 if (buffer) { 60 // Check to make sure we are talking about a valid region of 61 // the given WebGLArrayBuffer's storage. 62 if ((byteOffset + (length * sizeof(unsigned int))) > buffer->byteLength()) 63 return NULL; 47 64 } 48 65 49 PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 50 int offset, 51 unsigned length) 52 { 53 // Make sure the offset results in valid alignment. 54 if ((offset % sizeof(unsigned int)) != 0) { 55 return NULL; 56 } 66 return adoptRef(new WebGLUnsignedIntArray(buffer, byteOffset, length)); 67 } 57 68 58 if (buffer) { 59 // Check to make sure we are talking about a valid region of 60 // the given WebGLArrayBuffer's storage. 61 if ((offset + (length * sizeof(unsigned int))) > buffer->byteLength()) 62 return NULL; 63 } 69 WebGLUnsignedIntArray::WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) 70 : WebGLArray(buffer, byteOffset) 71 , m_size(length) 72 { 73 } 64 74 65 return adoptRef(new WebGLUnsignedIntArray(buffer, offset, length)); 66 } 67 68 WebGLUnsignedIntArray::WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) 69 : WebGLArray(buffer, offset) 70 , m_size(length) 71 { 72 } 73 74 unsigned WebGLUnsignedIntArray::length() const { 75 return m_size; 76 } 77 78 unsigned WebGLUnsignedIntArray::sizeInBytes() const { 79 return length() * sizeof(unsigned int); 80 } 75 unsigned WebGLUnsignedIntArray::length() const { 76 return m_size; 77 } 78 79 unsigned WebGLUnsignedIntArray::byteLength() const { 80 return m_size * sizeof(unsigned int); 81 } 82 83 PassRefPtr<WebGLArray> WebGLUnsignedIntArray::slice(unsigned offset, unsigned length) { 84 // Check to make sure the specified region is within the bounds of 85 // the WebGLArrayBuffer. 86 unsigned startByte = m_byteOffset + offset * sizeof(unsigned int); 87 unsigned limitByte = startByte + length * sizeof(unsigned int); 88 unsigned bufferLength = buffer()->byteLength(); 89 if (startByte >= bufferLength || limitByte > bufferLength) 90 return 0; 91 return create(buffer(), startByte, length); 92 } 93 94 void WebGLUnsignedIntArray::set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec) { 95 setImpl(array, offset * sizeof(unsigned int), ec); 96 } 97 81 98 } 82 99 -
trunk/WebCore/html/canvas/WebGLUnsignedIntArray.h
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 34 35 35 36 namespace WebCore { 36 37 class WebGLUnsignedIntArray : public WebGLArray {38 public:39 virtual bool isUnsignedIntArray() const { return true; }40 37 41 static PassRefPtr<WebGLUnsignedIntArray> create(unsigned length); 42 static PassRefPtr<WebGLUnsignedIntArray> create(unsigned int* array, unsigned length);43 static PassRefPtr<WebGLUnsignedIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);38 class WebGLUnsignedIntArray : public WebGLArray { 39 public: 40 virtual bool isUnsignedIntArray() const { return true; } 44 41 45 unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } 46 47 virtual unsigned length() const; 48 virtual unsigned sizeInBytes() const; 42 static PassRefPtr<WebGLUnsignedIntArray> create(unsigned length); 43 static PassRefPtr<WebGLUnsignedIntArray> create(unsigned int* array, unsigned length); 44 static PassRefPtr<WebGLUnsignedIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 49 45 50 void set(unsigned index, double value) 51 { 52 if (index >= m_size) 53 return; 54 if (isnan(value)) // Clamp NaN to 0 55 value = 0; 56 if (value < std::numeric_limits<unsigned int>::min()) 57 value = std::numeric_limits<unsigned int>::min(); 58 else if (value > std::numeric_limits<unsigned int>::max()) 59 value = std::numeric_limits<unsigned int>::max(); 60 unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); 61 storage[index] = static_cast<unsigned int>(value); 62 } 63 64 bool get(unsigned index, unsigned int& result) const 65 { 66 if (index >= m_size) 67 return false; 68 result = item(index); 69 return true; 70 } 71 72 unsigned int item(unsigned index) const 73 { 74 ASSERT(index < m_size); 75 unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); 76 return storage[index]; 77 } 46 unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } 78 47 79 private: 80 WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length); 81 unsigned m_size; 82 }; 83 48 virtual unsigned length() const; 49 virtual unsigned byteLength() const; 50 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 51 52 void set(unsigned index, double value) 53 { 54 if (index >= m_size) 55 return; 56 if (isnan(value)) // Clamp NaN to 0 57 value = 0; 58 if (value < std::numeric_limits<unsigned int>::min()) 59 value = std::numeric_limits<unsigned int>::min(); 60 else if (value > std::numeric_limits<unsigned int>::max()) 61 value = std::numeric_limits<unsigned int>::max(); 62 unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); 63 storage[index] = static_cast<unsigned int>(value); 64 } 65 66 bool get(unsigned index, unsigned int& result) const 67 { 68 if (index >= m_size) 69 return false; 70 result = item(index); 71 return true; 72 } 73 74 unsigned int get(unsigned index) const 75 { 76 return item(index); 77 } 78 79 unsigned int item(unsigned index) const 80 { 81 ASSERT(index < m_size); 82 unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); 83 return storage[index]; 84 } 85 86 void set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec); 87 88 private: 89 WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 90 unsigned m_size; 91 }; 92 84 93 } // namespace WebCore 85 94 -
trunk/WebCore/html/canvas/WebGLUnsignedIntArray.idl
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 CustomToJS 34 35 ] WebGLUnsignedIntArray : WebGLArray { 36 long get(in unsigned long index); 37 // void set(in unsigned long index, in long value); 38 // void set(in WebGLUnsignedIntArray array, [Optional] in unsigned long offset); 39 // void set(in sequence<long> array, [Optional] in unsigned long offset); 40 [Custom] void set(); 35 41 }; 36 42 } -
trunk/WebCore/html/canvas/WebGLUnsignedShortArray.cpp
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 32 33 33 34 namespace WebCore { 34 35 PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned length) 36 { 37 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned short)); 38 return create(buffer, 0, length); 35 36 PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned length) 37 { 38 RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned short)); 39 return create(buffer, 0, length); 40 } 41 42 PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned short* array, unsigned length) 43 { 44 RefPtr<WebGLUnsignedShortArray> a = WebGLUnsignedShortArray::create(length); 45 for (unsigned i = 0; i < length; ++i) 46 a->set(i, array[i]); 47 return a; 48 } 49 50 PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 51 int byteOffset, 52 unsigned length) 53 { 54 // Make sure the offset results in valid alignment. 55 if ((byteOffset % sizeof(unsigned short)) != 0) { 56 return NULL; 39 57 } 40 58 41 PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned short* array, unsigned length) 42 { 43 RefPtr<WebGLUnsignedShortArray> a = WebGLUnsignedShortArray::create(length); 44 for (unsigned i = 0; i < length; ++i) 45 a->set(i, array[i]); 46 return a; 59 if (buffer) { 60 // Check to make sure we are talking about a valid region of 61 // the given WebGLArrayBuffer's storage. 62 if ((byteOffset + (length * sizeof(unsigned short))) > buffer->byteLength()) 63 return NULL; 47 64 } 48 65 49 PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, 50 int offset, 51 unsigned length) 52 { 53 // Make sure the offset results in valid alignment. 54 if ((offset % sizeof(unsigned short)) != 0) { 55 return NULL; 56 } 66 return adoptRef(new WebGLUnsignedShortArray(buffer, byteOffset, length)); 67 } 57 68 58 if (buffer) { 59 // Check to make sure we are talking about a valid region of 60 // the given WebGLArrayBuffer's storage. 61 if ((offset + (length * sizeof(unsigned short))) > buffer->byteLength()) 62 return NULL; 63 } 69 WebGLUnsignedShortArray::WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer, 70 int byteOffset, 71 unsigned length) 72 : WebGLArray(buffer, byteOffset) 73 , m_size(length) 74 { 75 } 64 76 65 return adoptRef(new WebGLUnsignedShortArray(buffer, offset, length)); 66 } 67 68 WebGLUnsignedShortArray::WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer, 69 int offset, 70 unsigned length) 71 : WebGLArray(buffer, offset) 72 , m_size(length) 73 { 74 } 75 76 unsigned WebGLUnsignedShortArray::length() const { 77 return m_size; 78 } 79 80 unsigned WebGLUnsignedShortArray::sizeInBytes() const { 81 return length() * sizeof(unsigned short); 82 } 77 unsigned WebGLUnsignedShortArray::length() const { 78 return m_size; 79 } 80 81 unsigned WebGLUnsignedShortArray::byteLength() const { 82 return m_size * sizeof(unsigned short); 83 } 84 85 PassRefPtr<WebGLArray> WebGLUnsignedShortArray::slice(unsigned offset, unsigned length) { 86 // Check to make sure the specified region is within the bounds of 87 // the WebGLArrayBuffer. 88 unsigned startByte = m_byteOffset + offset * sizeof(unsigned short); 89 unsigned limitByte = startByte + length * sizeof(unsigned short); 90 unsigned bufferLength = buffer()->byteLength(); 91 if (startByte >= bufferLength || limitByte > bufferLength) 92 return 0; 93 return create(buffer(), startByte, length); 94 } 95 96 void WebGLUnsignedShortArray::set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec) { 97 setImpl(array, offset * sizeof(unsigned short), ec); 98 } 99 83 100 } 84 101 -
trunk/WebCore/html/canvas/WebGLUnsignedShortArray.h
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 34 35 35 36 namespace WebCore { 36 37 class WebGLUnsignedShortArray : public WebGLArray {38 public:39 virtual bool isUnsignedShortArray() const { return true; }40 37 41 static PassRefPtr<WebGLUnsignedShortArray> create(unsigned length); 42 static PassRefPtr<WebGLUnsignedShortArray> create(unsigned short* array, unsigned length);43 static PassRefPtr<WebGLUnsignedShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length);38 class WebGLUnsignedShortArray : public WebGLArray { 39 public: 40 virtual bool isUnsignedShortArray() const { return true; } 44 41 45 unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } 46 47 virtual unsigned length() const; 48 virtual unsigned sizeInBytes() const; 42 static PassRefPtr<WebGLUnsignedShortArray> create(unsigned length); 43 static PassRefPtr<WebGLUnsignedShortArray> create(unsigned short* array, unsigned length); 44 static PassRefPtr<WebGLUnsignedShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); 49 45 50 void set(unsigned index, double value) 51 { 52 if (index >= m_size) 53 return; 54 if (isnan(value)) // Clamp NaN to 0 55 value = 0; 56 if (value < std::numeric_limits<unsigned short>::min()) 57 value = std::numeric_limits<unsigned short>::min(); 58 else if (value > std::numeric_limits<unsigned short>::max()) 59 value = std::numeric_limits<unsigned short>::max(); 60 unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); 61 storage[index] = static_cast<unsigned short>(value); 62 } 63 64 bool get(unsigned index, unsigned short& result) const 65 { 66 if (index >= m_size) 67 return false; 68 unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); 69 result = storage[index]; 70 return true; 71 } 72 73 unsigned short item(unsigned index) const 74 { 75 ASSERT(index < m_size); 76 unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); 77 return storage[index]; 78 } 46 unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } 79 47 80 private: 81 WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer,int offset,unsigned length); 82 unsigned m_size; 83 }; 84 48 virtual unsigned length() const; 49 virtual unsigned byteLength() const; 50 virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); 51 52 void set(unsigned index, double value) 53 { 54 if (index >= m_size) 55 return; 56 if (isnan(value)) // Clamp NaN to 0 57 value = 0; 58 if (value < std::numeric_limits<unsigned short>::min()) 59 value = std::numeric_limits<unsigned short>::min(); 60 else if (value > std::numeric_limits<unsigned short>::max()) 61 value = std::numeric_limits<unsigned short>::max(); 62 unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); 63 storage[index] = static_cast<unsigned short>(value); 64 } 65 66 bool get(unsigned index, unsigned short& result) const 67 { 68 if (index >= m_size) 69 return false; 70 unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); 71 result = storage[index]; 72 return true; 73 } 74 75 unsigned short get(unsigned index) const 76 { 77 return item(index); 78 } 79 80 unsigned short item(unsigned index) const 81 { 82 ASSERT(index < m_size); 83 unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); 84 return storage[index]; 85 } 86 87 void set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec); 88 89 private: 90 WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer,int byteOffset,unsigned length); 91 unsigned m_size; 92 }; 93 85 94 } // namespace WebCore 86 95 -
trunk/WebCore/html/canvas/WebGLUnsignedShortArray.idl
r50725 r51049 1 1 /* 2 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 CustomToJS 34 35 ] WebGLUnsignedShortArray : WebGLArray { 36 long get(in unsigned long index); 37 // void set(in unsigned long index, in long value); 38 // void set(in WebGLUnsignedShortArray array, [Optional] in unsigned long offset); 39 // void set(in sequence<long> array, [Optional] in unsigned long offset); 40 [Custom] void set(); 35 41 }; 36 42 } -
trunk/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
r50725 r51049 330 330 331 331 ensureContext(m_contextObj); 332 ::glBufferData(target, array-> sizeInBytes(), array->baseAddress(), usage);332 ::glBufferData(target, array->byteLength(), array->baseAddress(), usage); 333 333 } 334 334 … … 339 339 340 340 ensureContext(m_contextObj); 341 ::glBufferSubData(target, offset, array-> sizeInBytes(), array->baseAddress());341 ::glBufferSubData(target, offset, array->byteLength(), array->baseAddress()); 342 342 } 343 343 -
trunk/WebKit/chromium/ChangeLog
r51009 r51049 1 2009-11-16 Kenneth Russell <kbr@google.com> 2 3 Reviewed by Oliver Hunt. 4 5 Update API of WebGLArray and friends 6 https://bugs.webkit.org/show_bug.cgi?id=31175 7 8 * src/GraphicsContext3D.cpp: 9 (WebCore::GraphicsContext3D::bufferData): 10 (WebCore::GraphicsContext3D::bufferSubData): 11 1 12 2009-11-15 Dimitri Glazkov <dglazkov@chromium.org> 2 13 -
trunk/WebKit/chromium/src/GraphicsContext3D.cpp
r50756 r51049 1228 1228 void GraphicsContext3D::bufferData(unsigned long target, WebGLArray* array, unsigned long usage) 1229 1229 { 1230 m_internal->bufferDataImpl(target, array-> sizeInBytes(), array->baseAddress(), usage);1230 m_internal->bufferDataImpl(target, array->byteLength(), array->baseAddress(), usage); 1231 1231 } 1232 1232 … … 1248 1248 return; 1249 1249 } 1250 glBufferSubData(target, offset, array-> sizeInBytes(), array->baseAddress());1250 glBufferSubData(target, offset, array->byteLength(), array->baseAddress()); 1251 1251 } 1252 1252
Note: See TracChangeset
for help on using the changeset viewer.