Changeset 51049 in webkit


Ignore:
Timestamp:
Nov 16, 2009 1:30:15 PM (14 years ago)
Author:
cmarrin@apple.com
Message:

Update API of WebGLArray and friends
https://bugs.webkit.org/show_bug.cgi?id=31175

Location:
trunk
Files:
53 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r51041 r51049  
     12009-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
    1112009-11-16  Alexey Proskuryakov  <ap@apple.com>
    212
  • trunk/LayoutTests/fast/canvas/webgl/array-unit-tests-expected.txt

    r50725 r51049  
    44
    55PASS test WebGLByteArray SetAndGetPos10ToNeg10
     6PASS test WebGLByteArray SetAndGetMethodsPos10ToNeg10
    67PASS test WebGLByteArray ConstructWithArrayOfSignedValues
     8PASS test WebGLByteArray ConstructWithWebGLArrayOfSignedValues
     9PASS test WebGLByteArray OffsetsAndSizes
     10PASS test WebGLByteArray SetFromWebGLArray
     11PASS negativeTest WebGLByteArray SetFromWebGLArray
     12PASS test WebGLByteArray SetFromArray
     13PASS test WebGLByteArray Slice
     14PASS negativeTest WebGLByteArray Slice
    715PASS test WebGLByteArray BoundaryConditions(-128, -128, 127, 127)
    816PASS test WebGLFloatArray SetAndGetPos10ToNeg10
     17PASS test WebGLFloatArray SetAndGetMethodsPos10ToNeg10
    918PASS test WebGLFloatArray ConstructWithArrayOfSignedValues
     19PASS test WebGLFloatArray ConstructWithWebGLArrayOfSignedValues
     20PASS test WebGLFloatArray OffsetsAndSizes
     21PASS test WebGLFloatArray SetFromWebGLArray
     22PASS negativeTest WebGLFloatArray SetFromWebGLArray
     23PASS test WebGLFloatArray SetFromArray
     24PASS test WebGLFloatArray Slice
     25PASS negativeTest WebGLFloatArray Slice
    1026PASS test WebGLFloatArray BoundaryConditions(-500, -500, 500, 500)
    1127PASS test WebGLIntArray SetAndGetPos10ToNeg10
     28PASS test WebGLIntArray SetAndGetMethodsPos10ToNeg10
    1229PASS test WebGLIntArray ConstructWithArrayOfSignedValues
     30PASS test WebGLIntArray ConstructWithWebGLArrayOfSignedValues
     31PASS test WebGLIntArray OffsetsAndSizes
     32PASS test WebGLIntArray SetFromWebGLArray
     33PASS negativeTest WebGLIntArray SetFromWebGLArray
     34PASS test WebGLIntArray SetFromArray
     35PASS test WebGLIntArray Slice
     36PASS negativeTest WebGLIntArray Slice
    1337PASS test WebGLIntArray BoundaryConditions(-2147483648, -2147483648, 2147483647, 2147483647)
    1438PASS test WebGLShortArray SetAndGetPos10ToNeg10
     39PASS test WebGLShortArray SetAndGetMethodsPos10ToNeg10
    1540PASS test WebGLShortArray ConstructWithArrayOfSignedValues
     41PASS test WebGLShortArray ConstructWithWebGLArrayOfSignedValues
     42PASS test WebGLShortArray OffsetsAndSizes
     43PASS test WebGLShortArray SetFromWebGLArray
     44PASS negativeTest WebGLShortArray SetFromWebGLArray
     45PASS test WebGLShortArray SetFromArray
     46PASS test WebGLShortArray Slice
     47PASS negativeTest WebGLShortArray Slice
    1648PASS test WebGLShortArray BoundaryConditions(-32768, -32768, 32767, 32767)
    1749PASS test WebGLUnsignedByteArray SetAndGet10To1
     50PASS test WebGLUnsignedByteArray SetAndGetMethods10To1
    1851PASS test WebGLUnsignedByteArray ConstructWithArrayOfUnsignedValues
     52PASS test WebGLUnsignedByteArray ConstructWithWebGLArrayOfUnsignedValues
     53PASS test WebGLUnsignedByteArray OffsetsAndSizes
     54PASS test WebGLUnsignedByteArray SetFromWebGLArray
     55PASS negativeTest WebGLUnsignedByteArray SetFromWebGLArray
     56PASS test WebGLUnsignedByteArray SetFromArray
     57PASS test WebGLUnsignedByteArray Slice
     58PASS negativeTest WebGLUnsignedByteArray Slice
    1959PASS test WebGLUnsignedByteArray BoundaryConditions(0, 0, 255, 255)
    2060PASS test WebGLUnsignedIntArray SetAndGet10To1
     61PASS test WebGLUnsignedIntArray SetAndGetMethods10To1
    2162PASS test WebGLUnsignedIntArray ConstructWithArrayOfUnsignedValues
     63PASS test WebGLUnsignedIntArray ConstructWithWebGLArrayOfUnsignedValues
     64PASS test WebGLUnsignedIntArray OffsetsAndSizes
     65PASS test WebGLUnsignedIntArray SetFromWebGLArray
     66PASS negativeTest WebGLUnsignedIntArray SetFromWebGLArray
     67PASS test WebGLUnsignedIntArray SetFromArray
     68PASS test WebGLUnsignedIntArray Slice
     69PASS negativeTest WebGLUnsignedIntArray Slice
    2270PASS test WebGLUnsignedIntArray BoundaryConditions(0, 0, 4294967295, 4294967295)
    2371PASS test WebGLUnsignedShortArray SetAndGet10To1
     72PASS test WebGLUnsignedShortArray SetAndGetMethods10To1
    2473PASS test WebGLUnsignedShortArray ConstructWithArrayOfUnsignedValues
     74PASS test WebGLUnsignedShortArray ConstructWithWebGLArrayOfUnsignedValues
     75PASS test WebGLUnsignedShortArray OffsetsAndSizes
     76PASS test WebGLUnsignedShortArray SetFromWebGLArray
     77PASS negativeTest WebGLUnsignedShortArray SetFromWebGLArray
     78PASS test WebGLUnsignedShortArray SetFromArray
     79PASS test WebGLUnsignedShortArray Slice
     80PASS negativeTest WebGLUnsignedShortArray Slice
    2581PASS test WebGLUnsignedShortArray BoundaryConditions(0, 0, 65535, 65535)
    2682Test passed.
  • trunk/LayoutTests/fast/canvas/webgl/array-unit-tests.html

    r50725 r51049  
    2828
    2929function 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);
    3237}
    3338
    3439function assertEq(prefix, expected, val) {
    3540  if (expected != val) {
    36     fail(prefix + ': expected ' + expected + ', got ' + val);
     41    var str = prefix + ': expected ' + expected + ', got ' + val;
     42    throw str;
     43  }
     44}
     45
     46function assert(prefix, expected) {
     47  if (!expected) {
     48    var str = prefix + ': expected value / true';
     49    throw str;
    3750  }
    3851}
     
    6679}
    6780
     81function 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
    6897function testConstructWithArrayOfUnsignedValues(type, name) {
    6998  running('test ' + name + ' ConstructWithArrayOfUnsignedValues');
     
    80109}
    81110
     111function 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
    82126//
    83127// Tests for signed array variants
     
    100144}
    101145
     146function 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
    102162function testConstructWithArrayOfSignedValues(type, name) {
    103163  running('test ' + name + ' ConstructWithArrayOfSignedValues');
     
    114174}
    115175
     176function 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
    116191//
    117192// Test cases for both signed and unsigned types
    118193//
     194
     195function 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
     215function 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
     240function 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
     269function 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
     287function 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
     307function 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}
    119326
    120327function testBoundaryConditions(type, name, lowValue, expectedLowValue, highValue, expectedHighValue) {
     
    147354    [ {name: "WebGLByteArray",
    148355       unsigned: false,
     356       elementSizeInBytes: 1,
    149357       low: -128,
    150358       expectedLow: -128,
     
    153361      {name: "WebGLFloatArray",
    154362       unsigned: false,
     363       elementSizeInBytes: 4,
    155364       low: -500,
    156365       expectedLow: -500,
     
    159368      {name: "WebGLIntArray",
    160369       unsigned: false,
     370       elementSizeInBytes: 4,
    161371       low: -2147483648,
    162372       expectedLow: -2147483648,
     
    165375      {name: "WebGLShortArray",
    166376       unsigned: false,
     377       elementSizeInBytes: 2,
    167378       low: -32768,
    168379       expectedLow: -32768,
     
    171382      {name: "WebGLUnsignedByteArray",
    172383       unsigned: true,
     384       elementSizeInBytes: 1,
    173385       low: 0,
    174386       expectedLow: 0,
     
    177389      {name: "WebGLUnsignedIntArray",
    178390       unsigned: true,
     391       elementSizeInBytes: 4,
    179392       low: 0,
    180393       expectedLow: 0,
     
    183396      {name: "WebGLUnsignedShortArray",
    184397       unsigned: true,
     398       elementSizeInBytes: 2,
    185399       low: 0,
    186400       expectedLow: 0,
     
    199413    if (testCase.unsigned) {
    200414      testSetAndGet10To1(type, name);
     415      testSetAndGetMethods10To1(type, name);
    201416      testConstructWithArrayOfUnsignedValues(type, name);
     417      testConstructWithWebGLArrayOfUnsignedValues(type, name);
    202418    } else {
    203419      testSetAndGetPos10ToNeg10(type, name);
     420      testSetAndGetMethodsPos10ToNeg10(type, name);
    204421      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);
    206430    testBoundaryConditions(type,
    207431                           name,
  • trunk/WebCore/ChangeLog

    r51048 r51049  
     12009-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
    11742009-11-16  Alexey Proskuryakov  <ap@apple.com>
    2175
  • trunk/WebCore/bindings/js/JSWebGLArrayCustom.cpp

    r50725 r51049  
    4646JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, WebGLArray* object)
    4747{
    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    }
    6264    return jsUndefined();
    6365}
  • trunk/WebCore/bindings/js/JSWebGLByteArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLByteArray.h"
    3132
    3233#include "WebGLByteArray.h"
     34
     35#include <runtime/Error.h>
    3336
    3437using namespace JSC;
     
    4649}
    4750
     51JSC::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
    4878} // namespace WebCore
    4979
  • trunk/WebCore/bindings/js/JSWebGLFloatArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLFloatArray.h"
    3132
     
    4647}
    4748
     49JSC::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
    4876} // namespace WebCore
    4977
  • trunk/WebCore/bindings/js/JSWebGLIntArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLIntArray.h"
    3132
     
    4647}
    4748
     49JSC::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
    4876} // namespace WebCore
    4977
  • trunk/WebCore/bindings/js/JSWebGLShortArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLShortArray.h"
    3132
     
    4647}
    4748
     49JSC::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
    4876} // namespace WebCore
    4977
  • trunk/WebCore/bindings/js/JSWebGLUnsignedByteArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLUnsignedByteArray.h"
    3132
     
    4647}
    4748
     49JSC::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
    4876} // namespace WebCore
    4977
  • trunk/WebCore/bindings/js/JSWebGLUnsignedIntArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLUnsignedIntArray.h"
    3132
     
    4647}
    4748
     49JSC::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
    4876} // namespace WebCore
    4977
  • trunk/WebCore/bindings/js/JSWebGLUnsignedShortArrayCustom.cpp

    r50725 r51049  
    2828#if ENABLE(3D_CANVAS)
    2929
     30#include "JSWebGLArrayHelper.h"
    3031#include "JSWebGLUnsignedShortArray.h"
    3132
     
    4647}
    4748
     49JSC::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
    4876} // namespace WebCore
    4977
  • trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r50972 r51049  
    17471747    my $type = shift;
    17481748    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";
    17521749    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";
    17571750    return 1 if $type eq "CanvasGradient";
    1758     return 1 if $type eq "WebGLIntArray";
    17591751    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";
    17681752    return 1 if $type eq "ClientRect";
    17691753    return 1 if $type eq "ClientRectList";
     
    18131797    return 1 if $type eq "TimeRanges";
    18141798    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";
    18151815    return 1 if $type eq "WebKitCSSMatrix";
    18161816    return 1 if $type eq "WebKitPoint";
  • trunk/WebCore/bindings/v8/V8DOMWrapper.cpp

    r51004 r51049  
    3232#include "V8DOMWrapper.h"
    3333
    34 #include "WebGLArray.h"
    3534#include "CSSMutableStyleDeclaration.h"
    3635#include "ChromiumBridge.h"
     
    5251#include "V8IsolatedWorld.h"
    5352#include "V8Proxy.h"
     53#include "WebGLArray.h"
    5454#include "WorkerContextExecutionProxy.h"
    5555
     
    721721    v8::Persistent<v8::Object> result = isActiveDomObject ? getActiveDOMObjectMap().get(impl) : getDOMObjectMap().get(impl);
    722722    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
    723744        v8::Local<v8::Object> v8Object = instantiateV8Object(type, type, impl);
    724745        if (!v8Object.IsEmpty()) {
  • trunk/WebCore/bindings/v8/custom/V8CustomBinding.h

    r50933 r51049  
    532532        DECLARE_NAMED_PROPERTY_GETTER(HTMLCollection);
    533533
     534        DECLARE_INDEXED_PROPERTY_GETTER(CanvasPixelArray);
     535        DECLARE_INDEXED_PROPERTY_SETTER(CanvasPixelArray);
     536
    534537#if ENABLE(3D_CANVAS)
     538        DECLARE_CALLBACK(WebGLByteArrayGet);
     539        DECLARE_CALLBACK(WebGLByteArraySet);
    535540        DECLARE_INDEXED_PROPERTY_GETTER(WebGLByteArray);
    536541        DECLARE_INDEXED_PROPERTY_SETTER(WebGLByteArray);
    537542
     543        DECLARE_CALLBACK(WebGLFloatArrayGet);
     544        DECLARE_CALLBACK(WebGLFloatArraySet);
    538545        DECLARE_INDEXED_PROPERTY_GETTER(WebGLFloatArray);
    539546        DECLARE_INDEXED_PROPERTY_SETTER(WebGLFloatArray);
    540547
     548        DECLARE_CALLBACK(WebGLIntArrayGet);
     549        DECLARE_CALLBACK(WebGLIntArraySet);
    541550        DECLARE_INDEXED_PROPERTY_GETTER(WebGLIntArray);
    542551        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);
    549555        DECLARE_INDEXED_PROPERTY_GETTER(WebGLShortArray);
    550556        DECLARE_INDEXED_PROPERTY_SETTER(WebGLShortArray);
    551557
     558        DECLARE_CALLBACK(WebGLUnsignedByteArrayGet);
     559        DECLARE_CALLBACK(WebGLUnsignedByteArraySet);
    552560        DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedByteArray);
    553561        DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedByteArray);
    554562
     563        DECLARE_CALLBACK(WebGLUnsignedIntArrayGet);
     564        DECLARE_CALLBACK(WebGLUnsignedIntArraySet);
    555565        DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedIntArray);
    556566        DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedIntArray);
    557567
     568        DECLARE_CALLBACK(WebGLUnsignedShortArrayGet);
     569        DECLARE_CALLBACK(WebGLUnsignedShortArraySet);
    558570        DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedShortArray);
    559571        DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedShortArray);
  • trunk/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp

    r50730 r51049  
    4444CALLBACK_FUNC_DECL(WebGLArrayBufferConstructor)
    4545{
    46     INC_STATS("DOM.WebGLArrayBuffer.Contructor");
     46    INC_STATS("DOM.WebGLArrayBuffer.Constructor");
    4747
    4848    if (!args.IsConstructCall())
     
    5050
    5151    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
    5262    // Supported constructors:
    5363    // WebGLArrayBuffer(n) where n is an integer:
  • trunk/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h

    r50730 r51049  
    4242namespace WebCore {
    4343
    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.
     45template<class ArrayClass>
     46v8::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 =
    7279                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)");
    133102        // Transform the holder into a wrapper object for the array.
    134103        V8DOMWrapper::setDOMWrapper(args.Holder(), classIndex, array.get());
     
    140109    }
    141110
     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
     144template <class T, typename ElementType>
     145v8::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
     167template <class T>
     168v8::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
     185template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType>
     186v8::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
    142218}
    143219
  • trunk/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp

    r50730 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLByteArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLByteArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLBYTEARRAY));
     51    return constructWebGLArray<WebGLByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLBYTEARRAY));
    5152}
    5253
     
    7980}
    8081
     82CALLBACK_FUNC_DECL(WebGLByteArrayGet)
     83{
     84    INC_STATS("DOM.WebGLByteArray.get()");
     85    return getWebGLArrayElement<WebGLByteArray, signed char>(args, V8ClassIndex::WEBGLBYTEARRAY);
     86}
     87
     88CALLBACK_FUNC_DECL(WebGLByteArraySet)
     89{
     90    INC_STATS("DOM.WebGLByteArray.set()");
     91    return setWebGLArray<WebGLByteArray, V8WebGLByteArray>(args, V8ClassIndex::WEBGLBYTEARRAY);
     92}
     93
    8194} // namespace WebCore
    8295
  • trunk/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp

    r50730 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLFloatArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLFloatArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLFloatArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLFLOATARRAY));
     51    return constructWebGLArray<WebGLFloatArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLFLOATARRAY));
    5152}
    5253
     
    7677}
    7778
     79CALLBACK_FUNC_DECL(WebGLFloatArrayGet)
     80{
     81    INC_STATS("DOM.WebGLFloatArray.get()");
     82    return getWebGLArrayElement<WebGLFloatArray, float>(args, V8ClassIndex::WEBGLFLOATARRAY);
     83}
     84
     85CALLBACK_FUNC_DECL(WebGLFloatArraySet)
     86{
     87    INC_STATS("DOM.WebGLFloatArray.set()");
     88    return setWebGLArray<WebGLFloatArray, V8WebGLFloatArray>(args, V8ClassIndex::WEBGLFLOATARRAY);
     89}
     90
    7891} // namespace WebCore
    7992
  • trunk/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp

    r50734 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLIntArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLIntArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLINTARRAY));
     51    return constructWebGLArray<WebGLIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLINTARRAY));
    5152}
    5253
     
    7980}
    8081
     82CALLBACK_FUNC_DECL(WebGLIntArrayGet)
     83{
     84    INC_STATS("DOM.WebGLIntArray.get()");
     85    return getWebGLArrayElement<WebGLIntArray, int>(args, V8ClassIndex::WEBGLINTARRAY);
     86}
     87
     88CALLBACK_FUNC_DECL(WebGLIntArraySet)
     89{
     90    INC_STATS("DOM.WebGLIntArray.set()");
     91    return setWebGLArray<WebGLIntArray, V8WebGLIntArray>(args, V8ClassIndex::WEBGLINTARRAY);
     92}
     93
    8194} // namespace WebCore
    8295
  • trunk/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp

    r50730 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLShortArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLShortArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLSHORTARRAY));
     51    return constructWebGLArray<WebGLShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLSHORTARRAY));
    5152}
    5253
     
    7980}
    8081
     82CALLBACK_FUNC_DECL(WebGLShortArrayGet)
     83{
     84    INC_STATS("DOM.WebGLShortArray.get()");
     85    return getWebGLArrayElement<WebGLShortArray, short>(args, V8ClassIndex::WEBGLSHORTARRAY);
     86}
     87
     88CALLBACK_FUNC_DECL(WebGLShortArraySet)
     89{
     90    INC_STATS("DOM.WebGLShortArray.set()");
     91    return setWebGLArray<WebGLShortArray, V8WebGLShortArray>(args, V8ClassIndex::WEBGLSHORTARRAY);
     92}
     93
    8194} // namespace WebCore
    8295
  • trunk/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp

    r50730 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLUnsignedByteArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLUnsignedByteArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLUnsignedByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY));
     51    return constructWebGLArray<WebGLUnsignedByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY));
    5152}
    5253
     
    7980}
    8081
     82CALLBACK_FUNC_DECL(WebGLUnsignedByteArrayGet)
     83{
     84    INC_STATS("DOM.WebGLUnsignedByteArray.get()");
     85    return getWebGLArrayElement<WebGLUnsignedByteArray, unsigned char>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY);
     86}
     87
     88CALLBACK_FUNC_DECL(WebGLUnsignedByteArraySet)
     89{
     90    INC_STATS("DOM.WebGLUnsignedByteArray.set()");
     91    return setWebGLArray<WebGLUnsignedByteArray, V8WebGLUnsignedByteArray>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY);
     92}
     93
    8194} // namespace WebCore
    8295
  • trunk/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp

    r50730 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLUnsignedIntArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLUnsignedIntArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLUnsignedIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDINTARRAY));
     51    return constructWebGLArray<WebGLUnsignedIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDINTARRAY));
    5152}
    5253
     
    7980}
    8081
     82CALLBACK_FUNC_DECL(WebGLUnsignedIntArrayGet)
     83{
     84    INC_STATS("DOM.WebGLUnsignedIntArray.get()");
     85    return getWebGLArrayElement<WebGLUnsignedIntArray, unsigned int>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY);
     86}
     87
     88CALLBACK_FUNC_DECL(WebGLUnsignedIntArraySet)
     89{
     90    INC_STATS("DOM.WebGLUnsignedIntArray.set()");
     91    return setWebGLArray<WebGLUnsignedIntArray, V8WebGLUnsignedIntArray>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY);
     92}
     93
    8194} // namespace WebCore
    8295
  • trunk/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp

    r50730 r51049  
    3939#include "V8WebGLArrayBuffer.h"
    4040#include "V8WebGLArrayCustom.h"
     41#include "V8WebGLUnsignedShortArray.h"
    4142#include "V8CustomBinding.h"
    4243#include "V8Proxy.h"
     
    4849    INC_STATS("DOM.WebGLUnsignedShortArray.Contructor");
    4950
    50     return constructCanvasArray<WebGLUnsignedShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY));
     51    return constructWebGLArray<WebGLUnsignedShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY));
    5152}
    5253
     
    7980}
    8081
     82CALLBACK_FUNC_DECL(WebGLUnsignedShortArrayGet)
     83{
     84    INC_STATS("DOM.WebGLUnsignedShortArray.get()");
     85    return getWebGLArrayElement<WebGLUnsignedShortArray, unsigned short>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY);
     86}
     87
     88CALLBACK_FUNC_DECL(WebGLUnsignedShortArraySet)
     89{
     90    INC_STATS("DOM.WebGLUnsignedShortArray.set()");
     91    return setWebGLArray<WebGLUnsignedShortArray, V8WebGLUnsignedShortArray>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY);
     92}
     93
    8194} // namespace WebCore
    8295
  • trunk/WebCore/html/canvas/WebGLArray.cpp

    r50725 r51049  
    3232
    3333namespace WebCore {
    34     WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer,
    35                              unsigned offset)
    36         : m_offset(offset)
     34
     35WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer,
     36                       unsigned byteOffset)
     37        : m_byteOffset(byteOffset)
    3738        , 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
     43WebGLArray::~WebGLArray()
     44{
     45}
     46
     47void WebGLArray::setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec)
     48{
     49    if (byteOffset + array->byteLength() > byteLength()) {
     50        ec = INDEX_SIZE_ERR;
     51        return;
    4052    }
    4153
    42     WebGLArray::~WebGLArray()
    43     {
    44     }
     54    char* base = static_cast<char*>(baseAddress());
     55    memcpy(base + byteOffset, array->baseAddress(), array->byteLength());
     56}
    4557
    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     }
    5058}
    5159
  • trunk/WebCore/html/canvas/WebGLArray.h

    r50725 r51049  
    2727#define WebGLArray_h
    2828
     29#include "ExceptionCode.h"
    2930#include <wtf/PassRefPtr.h>
    3031#include <wtf/RefCounted.h>
     
    3334
    3435namespace 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         }
    4836
    49         void* baseAddress() {
    50             return m_baseAddress;
    51         }
     37class 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; }
    5246
    53         unsigned offset() const {
    54             return m_offset;
    55         }
     47    PassRefPtr<WebGLArrayBuffer> buffer() {
     48        return m_buffer;
     49    }
    5650
    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    }
    6154
    62     protected:
    63         WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned offset);
     55    unsigned byteOffset() const {
     56        return m_byteOffset;
     57    }
    6458
    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
    7379} // namespace WebCore
    7480
  • trunk/WebCore/html/canvas/WebGLArray.idl

    r50725 r51049  
    2626module html {
    2727    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);
    3134    };
    3235}
  • trunk/WebCore/html/canvas/WebGLArrayBuffer.cpp

    r50725 r51049  
    3131
    3232namespace 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     }
    4733
    48     unsigned WebGLArrayBuffer::byteLength() const {
    49         return m_sizeInBytes;
    50     }
     34PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(unsigned sizeInBytes)
     35{
     36    return adoptRef(new WebGLArrayBuffer(sizeInBytes));
     37}
    5138
    52     WebGLArrayBuffer::~WebGLArrayBuffer() {
    53         WTF::fastFree(m_data);
    54     }
     39WebGLArrayBuffer::WebGLArrayBuffer(unsigned sizeInBytes) {
     40    m_sizeInBytes = sizeInBytes;
     41    m_data = WTF::fastZeroedMalloc(sizeInBytes);
     42}
     43
     44void* WebGLArrayBuffer::data() {
     45    return m_data;
     46}
     47
     48unsigned WebGLArrayBuffer::byteLength() const {
     49    return m_sizeInBytes;
     50}
     51
     52WebGLArrayBuffer::~WebGLArrayBuffer() {
     53    WTF::fastFree(m_data);
     54}
     55
    5556}
    5657
  • trunk/WebCore/html/canvas/WebGLArrayBuffer.h

    r50725 r51049  
    3131
    3232namespace WebCore {
    33    
    34     class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> {
    35     public:
    36         static PassRefPtr<WebGLArrayBuffer> create(unsigned sizeInBytes);
    3733
    38         void* data();
    39         unsigned byteLength() const;
     34class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> {
     35  public:
     36    static PassRefPtr<WebGLArrayBuffer> create(unsigned sizeInBytes);
    4037
    41         ~WebGLArrayBuffer();
     38    void* data();
     39    unsigned byteLength() const;
    4240
    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
    4949} // namespace WebCore
    5050
  • trunk/WebCore/html/canvas/WebGLByteArray.cpp

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3233
    3334namespace WebCore {
    34    
     35
    3536PassRefPtr<WebGLByteArray> WebGLByteArray::create(unsigned length)
    3637{
     
    4748}
    4849
    49 PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length)
     50PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length)
    5051{
    5152    if (buffer) {
    5253        // Check to make sure we are talking about a valid region of
    5354        // the given WebGLArrayBuffer's storage.
    54         if ((offset + (length * sizeof(signed char))) > buffer->byteLength())
     55        if ((byteOffset + (length * sizeof(signed char))) > buffer->byteLength())
    5556            return NULL;
    5657    }
    57    
    58     return adoptRef(new WebGLByteArray(buffer, offset, length));
     58
     59    return adoptRef(new WebGLByteArray(buffer, byteOffset, length));
    5960}
    6061
     
    6869    return m_size;
    6970}
    70    
    71 unsigned WebGLByteArray::sizeInBytes() const {
    72     return length() * sizeof(signed char);
     71
     72unsigned WebGLByteArray::byteLength() const {
     73    return m_size * sizeof(signed char);
     74}
     75
     76PassRefPtr<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
     87void WebGLByteArray::set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec) {
     88    setImpl(array, offset * sizeof(signed char), ec);
    7389}
    7490
  • trunk/WebCore/html/canvas/WebGLByteArray.h

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435
    3536namespace WebCore {
    36    
    37     class WebGLArrayBuffer;
    3837
    39     class WebGLByteArray : public WebGLArray {
    40     public:
    41         virtual bool isByteArray() const { return true; }
     38class WebGLArrayBuffer;
    4239
    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);
     40class WebGLByteArray : public WebGLArray {
     41  public:
     42    virtual bool isByteArray() const { return true; }
    4643
    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);
    4847
    49         virtual unsigned length() const;
    50         virtual unsigned sizeInBytes() const;
     48    char* data() { return static_cast<char*>(baseAddress()); }
    5149
    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);
    7453
    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
    8898} // namespace WebCore
    8999
  • trunk/WebCore/html/canvas/WebGLByteArray.idl

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        CustomToJS
    3435    ] 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();
    3541    };
    3642}
  • trunk/WebCore/html/canvas/WebGLFloatArray.cpp

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3132
    3233namespace 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
     35PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(unsigned length)
     36{
     37    RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(float));
     38    return create(buffer, 0, length);
     39}
     40
     41PassRefPtr<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
     49PassRefPtr<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;
    3860    }
     61    return adoptRef(new WebGLFloatArray(buffer, byteOffset, length));
     62}
    3963
    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     }
     64WebGLFloatArray::WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length)
     65        : WebGLArray(buffer, byteOffset)
     66        , m_size(length)
     67{
     68}
    4769
    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;
     70unsigned WebGLFloatArray::length() const {
     71    return m_size;
     72}
    5373
    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     }
     74unsigned WebGLFloatArray::byteLength() const {
     75    return m_size * sizeof(float);
     76}
     77
     78PassRefPtr<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
     89void WebGLFloatArray::set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec) {
     90    setImpl(array, offset * sizeof(float), ec);
     91}
     92
    7693}
    7794
  • trunk/WebCore/html/canvas/WebGLFloatArray.h

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334
    3435namespace WebCore {
    35    
    36     class WebGLFloatArray : public WebGLArray {
    37     public:
    38         virtual bool isFloatArray() const { return true; }
    3936
    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);
     37class WebGLFloatArray : public WebGLArray {
     38  public:
     39    virtual bool isFloatArray() const { return true; }
    4340
    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);
    4544
    46         virtual unsigned length() const;
    47        
    48         virtual unsigned sizeInBytes() const;
     45    float* data() { return static_cast<float*>(baseAddress()); }
    4946
    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;
    5882        }
    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
    8493} // namespace WebCore
    8594
  • trunk/WebCore/html/canvas/WebGLFloatArray.idl

    r50725 r51049  
    11/*
    22 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        CustomToJS
    3435    ] 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();
    3541    };
    3642}
  • trunk/WebCore/html/canvas/WebGLIntArray.cpp

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3233
    3334namespace 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
     36PassRefPtr<WebGLIntArray> WebGLIntArray::create(unsigned length)
     37{
     38    RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(int));
     39    return create(buffer, 0, length);
     40}
     41
     42PassRefPtr<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
     50PassRefPtr<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;
    3963    }
    4064
    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}
    4867
    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;
     68WebGLIntArray::WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length)
     69        : WebGLArray(buffer, byteOffset)
     70        , m_size(length)
     71{
     72}
    5673
    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(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     }
     74unsigned WebGLIntArray::length() const {
     75    return m_size;
     76}
     77
     78unsigned WebGLIntArray::byteLength() const {
     79    return m_size * sizeof(int);
     80}
     81
     82PassRefPtr<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
     93void WebGLIntArray::set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec) {
     94    setImpl(array, offset * sizeof(int), ec);
     95}
     96
    8097}
    8198
  • trunk/WebCore/html/canvas/WebGLIntArray.h

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435
    3536namespace WebCore {
    36    
    37     class WebGLIntArray : public WebGLArray {
    38     public:
    39         virtual bool isIntArray() const { return true; }
    4037
    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);
     38class WebGLIntArray : public WebGLArray {
     39  public:
     40    virtual bool isIntArray() const { return true; }
    4441
    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);
    4645
    47         virtual unsigned length() const;
    48         virtual unsigned sizeInBytes() const;
     46    int* data() { return static_cast<int*>(baseAddress()); }
    4947
    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);
    7851
    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
    8695} // namespace WebCore
    8796
  • trunk/WebCore/html/canvas/WebGLIntArray.idl

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        CustomToJS
    3435    ] 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();
    3541    };
    3642}
  • trunk/WebCore/html/canvas/WebGLShortArray.cpp

    r50725 r51049  
    3232
    3333namespace 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
     35PassRefPtr<WebGLShortArray> WebGLShortArray::create(unsigned length)
     36{
     37    RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(short));
     38    return create(buffer, 0, length);
     39}
     40
     41PassRefPtr<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
     49PassRefPtr<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;
    3962    }
    4063
    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}
    4866
    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;
     67WebGLShortArray::WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length)
     68        : WebGLArray(buffer, byteOffset)
     69        , m_size(length)
     70{
     71}
    5672
    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         }
     73unsigned WebGLShortArray::length() const {
     74    return m_size;
     75}
    6376
    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     }
     77unsigned WebGLShortArray::byteLength() const {
     78    return m_size * sizeof(short);
     79}
     80
     81PassRefPtr<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
     92void WebGLShortArray::set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec) {
     93    setImpl(array, offset * sizeof(short), ec);
     94}
     95
    8096}
    8197
  • trunk/WebCore/html/canvas/WebGLShortArray.h

    r50725 r51049  
    3434
    3535namespace WebCore {
    36    
    37     class WebGLShortArray : public WebGLArray {
    38     public:
    39         virtual bool isShortArray() const { return true; }
    4036
    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);
     37class WebGLShortArray : public WebGLArray {
     38  public:
     39    virtual bool isShortArray() const { return true; }
    4440
    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);
    4644
    47         virtual unsigned length() const;
    48         virtual unsigned sizeInBytes() const;
     45    short* data() { return static_cast<short*>(baseAddress()); }
    4946
    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);
    7850
    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
    8492} // namespace WebCore
    8593
  • trunk/WebCore/html/canvas/WebGLShortArray.idl

    r50725 r51049  
    3333        CustomToJS
    3434    ] 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();
    3540    };
    3641}
  • trunk/WebCore/html/canvas/WebGLUnsignedByteArray.cpp

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3233
    3334namespace 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
     36PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned length)
     37{
     38    RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned char));
     39    return create(buffer, 0, length);
     40}
     41
     42PassRefPtr<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
     50PassRefPtr<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;
    3959    }
    4060
    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}
    4863
    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         }
     64WebGLUnsignedByteArray::WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length)
     65        : WebGLArray(buffer, byteOffset)
     66        , m_size(length)
     67{
     68}
    5969
    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     }
     70unsigned WebGLUnsignedByteArray::length() const {
     71    return m_size;
     72}
     73
     74unsigned WebGLUnsignedByteArray::byteLength() const {
     75    return m_size * sizeof(unsigned char);
     76}
     77
     78PassRefPtr<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
     89void WebGLUnsignedByteArray::set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec) {
     90    setImpl(array, offset * sizeof(unsigned char), ec);
     91}
     92
    7693}
    7794
  • trunk/WebCore/html/canvas/WebGLUnsignedByteArray.h

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435
    3536namespace WebCore {
    36    
    37     class WebGLUnsignedByteArray : public WebGLArray {
    38     public:
    39         virtual bool isUnsignedByteArray() const { return true; }
    4037
    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);
     38class WebGLUnsignedByteArray : public WebGLArray {
     39  public:
     40    virtual bool isUnsignedByteArray() const { return true; }
    4441
    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);
    4945
    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()); }
    7847
    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
    8493} // namespace WebCore
    8594
  • trunk/WebCore/html/canvas/WebGLUnsignedByteArray.idl

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        CustomToJS
    3435    ] 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();
    3541    };
    3642}
  • trunk/WebCore/html/canvas/WebGLUnsignedIntArray.cpp

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3233
    3334namespace 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
     36PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned length)
     37{
     38    RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned int));
     39    return create(buffer, 0, length);
     40}
     41
     42PassRefPtr<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
     50PassRefPtr<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;
    3957    }
    4058
    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;
    4764    }
    4865
    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}
    5768
    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         }
     69WebGLUnsignedIntArray::WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length)
     70        : WebGLArray(buffer, byteOffset)
     71        , m_size(length)
     72{
     73}
    6474
    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     }
     75unsigned WebGLUnsignedIntArray::length() const {
     76    return m_size;
     77}
     78
     79unsigned WebGLUnsignedIntArray::byteLength() const {
     80    return m_size * sizeof(unsigned int);
     81}
     82
     83PassRefPtr<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
     94void WebGLUnsignedIntArray::set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec) {
     95    setImpl(array, offset * sizeof(unsigned int), ec);
     96}
     97
    8198}
    8299
  • trunk/WebCore/html/canvas/WebGLUnsignedIntArray.h

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435
    3536namespace WebCore {
    36    
    37     class WebGLUnsignedIntArray : public WebGLArray {
    38     public:
    39         virtual bool isUnsignedIntArray() const { return true; }
    4037
    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);
     38class WebGLUnsignedIntArray : public WebGLArray {
     39  public:
     40    virtual bool isUnsignedIntArray() const { return true; }
    4441
    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);
    4945
    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()); }
    7847
    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
    8493} // namespace WebCore
    8594
  • trunk/WebCore/html/canvas/WebGLUnsignedIntArray.idl

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        CustomToJS
    3435    ] 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();
    3541    };
    3642}
  • trunk/WebCore/html/canvas/WebGLUnsignedShortArray.cpp

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3233
    3334namespace 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
     36PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned length)
     37{
     38    RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned short));
     39    return create(buffer, 0, length);
     40}
     41
     42PassRefPtr<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
     50PassRefPtr<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;
    3957    }
    4058
    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;
    4764    }
    4865
    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}
    5768
    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         }
     69WebGLUnsignedShortArray::WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer,
     70                                                 int byteOffset,
     71                                                 unsigned length)
     72        : WebGLArray(buffer, byteOffset)
     73        , m_size(length)
     74{
     75}
    6476
    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     }
     77unsigned WebGLUnsignedShortArray::length() const {
     78    return m_size;
     79}
     80
     81unsigned WebGLUnsignedShortArray::byteLength() const {
     82    return m_size * sizeof(unsigned short);
     83}
     84
     85PassRefPtr<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
     96void WebGLUnsignedShortArray::set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec) {
     97    setImpl(array, offset * sizeof(unsigned short), ec);
     98}
     99
    83100}
    84101
  • trunk/WebCore/html/canvas/WebGLUnsignedShortArray.h

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435
    3536namespace WebCore {
    36    
    37     class WebGLUnsignedShortArray : public WebGLArray {
    38     public:
    39         virtual bool isUnsignedShortArray() const { return true; }
    4037
    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);
     38class WebGLUnsignedShortArray : public WebGLArray {
     39  public:
     40    virtual bool isUnsignedShortArray() const { return true; }
    4441
    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);
    4945
    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()); }
    7947
    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
    8594} // namespace WebCore
    8695
  • trunk/WebCore/html/canvas/WebGLUnsignedShortArray.idl

    r50725 r51049  
    11/*
    22 * Copyright (C) 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        CustomToJS
    3435    ] 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();
    3541    };
    3642}
  • trunk/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp

    r50725 r51049  
    330330   
    331331    ensureContext(m_contextObj);
    332     ::glBufferData(target, array->sizeInBytes(), array->baseAddress(), usage);
     332    ::glBufferData(target, array->byteLength(), array->baseAddress(), usage);
    333333}
    334334
     
    339339   
    340340    ensureContext(m_contextObj);
    341     ::glBufferSubData(target, offset, array->sizeInBytes(), array->baseAddress());
     341    ::glBufferSubData(target, offset, array->byteLength(), array->baseAddress());
    342342}
    343343
  • trunk/WebKit/chromium/ChangeLog

    r51009 r51049  
     12009-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
    1122009-11-15  Dimitri Glazkov  <dglazkov@chromium.org>
    213
  • trunk/WebKit/chromium/src/GraphicsContext3D.cpp

    r50756 r51049  
    12281228void GraphicsContext3D::bufferData(unsigned long target, WebGLArray* array, unsigned long usage)
    12291229{
    1230     m_internal->bufferDataImpl(target, array->sizeInBytes(), array->baseAddress(), usage);
     1230    m_internal->bufferDataImpl(target, array->byteLength(), array->baseAddress(), usage);
    12311231}
    12321232
     
    12481248        return;
    12491249    }
    1250     glBufferSubData(target, offset, array->sizeInBytes(), array->baseAddress());
     1250    glBufferSubData(target, offset, array->byteLength(), array->baseAddress());
    12511251}
    12521252
Note: See TracChangeset for help on using the changeset viewer.