diff options
Diffstat (limited to 'WebCore/html/canvas')
54 files changed, 1538 insertions, 1440 deletions
diff --git a/WebCore/html/canvas/WebGLArrayBuffer.cpp b/WebCore/html/canvas/ArrayBuffer.cpp index 7d3cd33..0ba2ffd 100644 --- a/WebCore/html/canvas/WebGLArrayBuffer.cpp +++ b/WebCore/html/canvas/ArrayBuffer.cpp @@ -27,52 +27,52 @@ #if ENABLE(3D_CANVAS) -#include "WebGLArrayBuffer.h" +#include "ArrayBuffer.h" #include <wtf/RefPtr.h> namespace WebCore { -PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(unsigned numElements, unsigned elementByteSize) +PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize) { void* data = tryAllocate(numElements, elementByteSize); if (!data) return 0; - return adoptRef(new WebGLArrayBuffer(data, numElements * elementByteSize)); + return adoptRef(new ArrayBuffer(data, numElements * elementByteSize)); } -PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(WebGLArrayBuffer* other) +PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other) { void* data = tryAllocate(other->byteLength(), 1); if (!data) return 0; - RefPtr<WebGLArrayBuffer> buffer = adoptRef(new WebGLArrayBuffer(data, other->byteLength())); + RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(data, other->byteLength())); memcpy(buffer->data(), other->data(), other->byteLength()); return buffer.release(); } -WebGLArrayBuffer::WebGLArrayBuffer(void* data, unsigned sizeInBytes) +ArrayBuffer::ArrayBuffer(void* data, unsigned sizeInBytes) : m_sizeInBytes(sizeInBytes) , m_data(data) { } -void* WebGLArrayBuffer::data() { +void* ArrayBuffer::data() { return m_data; } -const void* WebGLArrayBuffer::data() const { +const void* ArrayBuffer::data() const { return m_data; } -unsigned WebGLArrayBuffer::byteLength() const { +unsigned ArrayBuffer::byteLength() const { return m_sizeInBytes; } -WebGLArrayBuffer::~WebGLArrayBuffer() { +ArrayBuffer::~ArrayBuffer() { WTF::fastFree(m_data); } -void* WebGLArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize) { +void* ArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize) { void* result; // Do not allow 32-bit overflow of the total size if (numElements) { diff --git a/WebCore/html/canvas/WebGLArrayBuffer.h b/WebCore/html/canvas/ArrayBuffer.h index 59e0ddd..f538080 100644 --- a/WebCore/html/canvas/WebGLArrayBuffer.h +++ b/WebCore/html/canvas/ArrayBuffer.h @@ -23,28 +23,28 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebGLArrayBuffer_h -#define WebGLArrayBuffer_h +#ifndef ArrayBuffer_h +#define ArrayBuffer_h #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { -class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> { +class ArrayBuffer : public RefCounted<ArrayBuffer> { public: - static PassRefPtr<WebGLArrayBuffer> create(unsigned numElements, unsigned elementByteSize); - static PassRefPtr<WebGLArrayBuffer> create(WebGLArrayBuffer*); + static PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize); + static PassRefPtr<ArrayBuffer> create(ArrayBuffer*); void* data(); const void* data() const; unsigned byteLength() const; - ~WebGLArrayBuffer(); + ~ArrayBuffer(); private: - WebGLArrayBuffer(void* data, unsigned sizeInBytes); - WebGLArrayBuffer(unsigned numElements, unsigned elementByteSize); + ArrayBuffer(void* data, unsigned sizeInBytes); + ArrayBuffer(unsigned numElements, unsigned elementByteSize); static void* tryAllocate(unsigned numElements, unsigned elementByteSize); unsigned m_sizeInBytes; void* m_data; @@ -52,4 +52,4 @@ class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> { } // namespace WebCore -#endif // WebGLArrayBuffer_h +#endif // ArrayBuffer_h diff --git a/WebCore/html/canvas/WebGLArrayBuffer.idl b/WebCore/html/canvas/ArrayBuffer.idl index 3325210..3165494 100644 --- a/WebCore/html/canvas/WebGLArrayBuffer.idl +++ b/WebCore/html/canvas/ArrayBuffer.idl @@ -24,7 +24,7 @@ */ module html { - interface [Conditional=3D_CANVAS, CustomConstructor] WebGLArrayBuffer { + interface [Conditional=3D_CANVAS, CustomConstructor] ArrayBuffer { readonly attribute int byteLength; }; } diff --git a/WebCore/html/canvas/WebGLArray.cpp b/WebCore/html/canvas/ArrayBufferView.cpp index 038aea4..787fd61 100644 --- a/WebCore/html/canvas/WebGLArray.cpp +++ b/WebCore/html/canvas/ArrayBufferView.cpp @@ -27,12 +27,12 @@ #if ENABLE(3D_CANVAS) -#include "WebGLArray.h" -#include "WebGLArrayBuffer.h" +#include "ArrayBufferView.h" +#include "ArrayBuffer.h" namespace WebCore { -WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, +ArrayBufferView::ArrayBufferView(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset) : m_byteOffset(byteOffset) , m_buffer(buffer) @@ -40,11 +40,11 @@ WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_byteOffset) : 0; } -WebGLArray::~WebGLArray() +ArrayBufferView::~ArrayBufferView() { } -void WebGLArray::setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec) +void ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset, ExceptionCode& ec) { if (byteOffset > byteLength() || byteOffset + array->byteLength() > byteLength() || @@ -58,7 +58,7 @@ void WebGLArray::setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& memmove(base + byteOffset, array->baseAddress(), array->byteLength()); } -void WebGLArray::calculateOffsetAndLength(int start, int end, unsigned arraySize, +void ArrayBufferView::calculateOffsetAndLength(int start, int end, unsigned arraySize, unsigned* offset, unsigned* length) { if (start < 0) diff --git a/WebCore/html/canvas/WebGLArray.h b/WebCore/html/canvas/ArrayBufferView.h index 7d67474..dcf6d13 100644 --- a/WebCore/html/canvas/WebGLArray.h +++ b/WebCore/html/canvas/ArrayBufferView.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebGLArray_h -#define WebGLArray_h +#ifndef ArrayBufferView_h +#define ArrayBufferView_h #include <algorithm> #include "ExceptionCode.h" @@ -32,11 +32,11 @@ #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> -#include "WebGLArrayBuffer.h" +#include "ArrayBuffer.h" namespace WebCore { -class WebGLArray : public RefCounted<WebGLArray> { +class ArrayBufferView : public RefCounted<ArrayBufferView> { public: virtual bool isByteArray() const { return false; } virtual bool isUnsignedByteArray() const { return false; } @@ -46,36 +46,39 @@ class WebGLArray : public RefCounted<WebGLArray> { virtual bool isUnsignedIntArray() const { return false; } virtual bool isFloatArray() const { return false; } - PassRefPtr<WebGLArrayBuffer> buffer() { + PassRefPtr<ArrayBuffer> buffer() const + { return m_buffer; } - void* baseAddress() { + void* baseAddress() const + { return m_baseAddress; } - unsigned byteOffset() const { + unsigned byteOffset() const + { return m_byteOffset; } virtual unsigned length() const = 0; virtual unsigned byteLength() const = 0; - virtual PassRefPtr<WebGLArray> slice(int start, int end) = 0; + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const = 0; - virtual ~WebGLArray(); + virtual ~ArrayBufferView(); protected: - WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset); + ArrayBufferView(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset); - void setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec); + void setImpl(ArrayBufferView* array, unsigned byteOffset, ExceptionCode& ec); - void calculateOffsetAndLength(int start, int end, unsigned arraySize, - unsigned* offset, unsigned* length); + static void calculateOffsetAndLength(int start, int end, unsigned arraySize, + unsigned* offset, unsigned* length); // Helper to verify that a given sub-range of an ArrayBuffer is // within range. template <typename T> - static bool verifySubRange(PassRefPtr<WebGLArrayBuffer> buffer, + static bool verifySubRange(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned numElements) { @@ -94,7 +97,7 @@ class WebGLArray : public RefCounted<WebGLArray> { // Input offset is in number of elements from this array's view; // output offset is in number of bytes from the underlying buffer's view. template <typename T> - static void clampOffsetAndNumElements(PassRefPtr<WebGLArrayBuffer> buffer, + static void clampOffsetAndNumElements(PassRefPtr<ArrayBuffer> buffer, unsigned arrayByteOffset, unsigned *offset, unsigned *numElements) @@ -111,15 +114,15 @@ class WebGLArray : public RefCounted<WebGLArray> { *numElements = std::min(remainingElements, *numElements); } - // This is the address of the WebGLArrayBuffer's storage, plus the byte offset. + // This is the address of the ArrayBuffer's storage, plus the byte offset. void* m_baseAddress; unsigned m_byteOffset; private: - RefPtr<WebGLArrayBuffer> m_buffer; + RefPtr<ArrayBuffer> m_buffer; }; } // namespace WebCore -#endif // WebGLArray_h +#endif // ArrayBufferView_h diff --git a/WebCore/html/canvas/WebGLArray.idl b/WebCore/html/canvas/ArrayBufferView.idl index 2cc00d0..450345e 100644 --- a/WebCore/html/canvas/WebGLArray.idl +++ b/WebCore/html/canvas/ArrayBufferView.idl @@ -24,12 +24,12 @@ */ module html { - interface [Conditional=3D_CANVAS, CustomToJS, OmitConstructor] WebGLArray { - readonly attribute WebGLArrayBuffer buffer; + interface [Conditional=3D_CANVAS, CustomToJS, OmitConstructor] ArrayBufferView { + readonly attribute ArrayBuffer buffer; readonly attribute unsigned long byteOffset; readonly attribute unsigned long byteLength; readonly attribute unsigned long length; - [Custom] WebGLArray slice(in long start, in long end); + [Custom] ArrayBufferView slice(in long start, in long end); }; } diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 615b45d..7cdf5d6 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -114,11 +114,12 @@ void CanvasRenderingContext2D::reset() { m_stateStack.resize(1); m_stateStack.first() = State(); + m_path.clear(); } CanvasRenderingContext2D::State::State() - : m_strokeStyle(CanvasStyle::create("black")) - , m_fillStyle(CanvasStyle::create("black")) + : m_strokeStyle(CanvasStyle::create("#000000")) + , m_fillStyle(CanvasStyle::create("#000000")) , m_lineWidth(1) , m_lineCap(ButtCap) , m_lineJoin(MiterJoin) @@ -214,7 +215,7 @@ float CanvasRenderingContext2D::lineWidth() const void CanvasRenderingContext2D::setLineWidth(float width) { - if (!(width > 0)) + if (!(isfinite(width) && width > 0)) return; state().m_lineWidth = width; GraphicsContext* c = drawingContext(); @@ -264,7 +265,7 @@ float CanvasRenderingContext2D::miterLimit() const void CanvasRenderingContext2D::setMiterLimit(float limit) { - if (!(limit > 0)) + if (!(isfinite(limit) && limit > 0)) return; state().m_miterLimit = limit; GraphicsContext* c = drawingContext(); @@ -280,6 +281,8 @@ float CanvasRenderingContext2D::shadowOffsetX() const void CanvasRenderingContext2D::setShadowOffsetX(float x) { + if (!isfinite(x)) + return; state().m_shadowOffset.setWidth(x); applyShadow(); } @@ -291,6 +294,8 @@ float CanvasRenderingContext2D::shadowOffsetY() const void CanvasRenderingContext2D::setShadowOffsetY(float y) { + if (!isfinite(y)) + return; state().m_shadowOffset.setHeight(y); applyShadow(); } @@ -302,6 +307,8 @@ float CanvasRenderingContext2D::shadowBlur() const void CanvasRenderingContext2D::setShadowBlur(float blur) { + if (!(isfinite(blur) && blur >= 0)) + return; state().m_shadowBlur = blur; applyShadow(); } @@ -874,8 +881,6 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, return; RGBA32 rgba = makeRGBA32FromFloats(r, g, b, a); // default is transparent black - if (!state().m_shadowColor.isEmpty()) - CSSParser::parseColor(rgba, state().m_shadowColor); c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } @@ -1337,14 +1342,30 @@ static PassRefPtr<ImageData> createEmptyImageData(const IntSize& size) return data.get(); } +PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(PassRefPtr<ImageData> imageData, ExceptionCode& ec) const +{ + if (!imageData) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + IntSize size(imageData->width(), imageData->height()); + return createEmptyImageData(size); +} + PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh, ExceptionCode& ec) const { ec = 0; + if (!sw || !sh) { + ec = INDEX_SIZE_ERR; + return 0; + } if (!isfinite(sw) || !isfinite(sh)) { ec = NOT_SUPPORTED_ERR; return 0; } - FloatSize unscaledSize(sw, sh); + + FloatSize unscaledSize(fabs(sw), fabs(sh)); IntSize scaledSize = canvas()->convertLogicalToDevice(unscaledSize); if (scaledSize.width() < 1) scaledSize.setWidth(1); @@ -1360,7 +1381,15 @@ PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy, ec = SECURITY_ERR; return 0; } - + if (!sw || !sh) { + ec = INDEX_SIZE_ERR; + return 0; + } + if (!isfinite(sx) || !isfinite(sy) || !isfinite(sw) || !isfinite(sh)) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + FloatRect unscaledRect(sx, sy, sw, sh); IntRect scaledRect = canvas()->convertLogicalToDevice(unscaledRect); if (scaledRect.width() < 1) @@ -1391,7 +1420,7 @@ void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, } if (!isfinite(dx) || !isfinite(dy) || !isfinite(dirtyX) || !isfinite(dirtyY) || !isfinite(dirtyWidth) || !isfinite(dirtyHeight)) { - ec = INDEX_SIZE_ERR; + ec = NOT_SUPPORTED_ERR; return; } diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.h b/WebCore/html/canvas/CanvasRenderingContext2D.h index 2bac902..a49ff81 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.h +++ b/WebCore/html/canvas/CanvasRenderingContext2D.h @@ -181,6 +181,7 @@ namespace WebCore { PassRefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType, ExceptionCode&); PassRefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String& repetitionType, ExceptionCode&); + PassRefPtr<ImageData> createImageData(PassRefPtr<ImageData> imageData, ExceptionCode&) const; PassRefPtr<ImageData> createImageData(float width, float height, ExceptionCode&) const; PassRefPtr<ImageData> getImageData(float sx, float sy, float sw, float sh, ExceptionCode&) const; void putImageData(ImageData*, float dx, float dy, ExceptionCode&); diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.idl b/WebCore/html/canvas/CanvasRenderingContext2D.idl index a3c83ca..da4dd72 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.idl +++ b/WebCore/html/canvas/CanvasRenderingContext2D.idl @@ -148,6 +148,10 @@ module html { raises (DOMException); void putImageData(in ImageData imagedata, in float dx, in float dy, in [Optional] float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight) raises(DOMException); + ImageData createImageData(in ImageData imagedata) + raises (DOMException); + ImageData createImageData(in float sw, in float sh) + raises (DOMException); #else // FIXME: Remove 'else' once JSC supports overloads too. [Custom] void fillText(/* 4 */); @@ -160,14 +164,13 @@ module html { [Custom] void setShadow(/* 3 */); [Custom] void createPattern(/* 2 */); [Custom] void putImageData(/* in ImageData imagedata, in float dx, in float dy [, in float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight] */); + [Custom] ImageData createImageData(/* 3 */); #endif // defined(V8_BINDING) attribute [Custom] custom strokeStyle; attribute [Custom] custom fillStyle; // pixel manipulation - ImageData createImageData(in float sw, in float sh) - raises (DOMException); ImageData getImageData(in float sx, in float sy, in float sw, in float sh) raises(DOMException); }; diff --git a/WebCore/html/canvas/FloatArray.cpp b/WebCore/html/canvas/FloatArray.cpp new file mode 100644 index 0000000..942a123 --- /dev/null +++ b/WebCore/html/canvas/FloatArray.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "FloatArray.h" + +namespace WebCore { + +PassRefPtr<FloatArray> FloatArray::create(unsigned length) +{ + return TypedArrayBase<float>::create<FloatArray>(length); +} + +PassRefPtr<FloatArray> FloatArray::create(float* array, unsigned length) +{ + return TypedArrayBase<float>::create<FloatArray>(array, length); +} + +PassRefPtr<FloatArray> FloatArray::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<float>::create<FloatArray>(buffer, byteOffset, length); +} + +FloatArray::FloatArray(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : TypedArrayBase<float>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> FloatArray::slice(int start, int end) const +{ + return sliceImpl<FloatArray>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLFloatArray.h b/WebCore/html/canvas/FloatArray.h index 5b4e6c9..9211a40 100644 --- a/WebCore/html/canvas/WebGLFloatArray.h +++ b/WebCore/html/canvas/FloatArray.h @@ -24,58 +24,37 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebGLFloatArray_h -#define WebGLFloatArray_h +#ifndef FloatArray_h +#define FloatArray_h -#include "WebGLArray.h" +#include "TypedArrayBase.h" #include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> namespace WebCore { -class WebGLFloatArray : public WebGLArray { +class FloatArray : public TypedArrayBase<float> { public: - virtual bool isFloatArray() const { return true; } - - static PassRefPtr<WebGLFloatArray> create(unsigned length); - static PassRefPtr<WebGLFloatArray> create(float* array, unsigned length); - static PassRefPtr<WebGLFloatArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - float* data() { return static_cast<float*>(baseAddress()); } + static PassRefPtr<FloatArray> create(unsigned length); + static PassRefPtr<FloatArray> create(float* array, unsigned length); + static PassRefPtr<FloatArray> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); + using TypedArrayBase<float>::set; void set(unsigned index, double value) { - if (index >= m_size) + if (index >= TypedArrayBase<float>::m_length) return; if (isnan(value)) // Clamp NaN to 0 value = 0; - float* storage = static_cast<float*>(m_baseAddress); - storage[index] = static_cast<float>(value); - } - - bool get(unsigned index, float& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - float get(unsigned index) const - { - return item(index); + TypedArrayBase<float>::data()[index] = static_cast<float>(value); } + // Invoked by the indexed getter. Does not perform range checks; caller + // is responsible for doing so and returning undefined as necessary. float item(unsigned index) const { - ASSERT(index < m_size); - float* storage = static_cast<float*>(m_baseAddress); - float result = storage[index]; + ASSERT(index < TypedArrayBase<float>::m_length); + float result = TypedArrayBase<float>::data()[index]; if (isnan(result)) { // Clamp NaN to 0 result = 0; @@ -83,13 +62,18 @@ class WebGLFloatArray : public WebGLArray { return result; } - void set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec); - private: - WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - unsigned m_size; + FloatArray(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<float>; + + // Overridden from ArrayBufferView. + virtual bool isFloatArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; }; } // namespace WebCore -#endif // WebGLFloatArray_h +#endif // FloatArray_h diff --git a/WebCore/html/canvas/WebGLFloatArray.idl b/WebCore/html/canvas/FloatArray.idl index e0a80f2..41b2c94 100644 --- a/WebCore/html/canvas/WebGLFloatArray.idl +++ b/WebCore/html/canvas/FloatArray.idl @@ -32,10 +32,8 @@ module html { GenerateNativeConverter, CustomConstructor, CustomToJS - ] WebGLFloatArray : WebGLArray { - float get(in unsigned long index); - // void set(in unsigned long index, in float value); - // void set(in WebGLFloatArray array, [Optional] in unsigned long offset); + ] FloatArray : ArrayBufferView { + // void set(in FloatArray array, [Optional] in unsigned long offset); // void set(in sequence<long> array, [Optional] in unsigned long offset); [Custom] void set(); }; diff --git a/WebCore/html/canvas/Int16Array.cpp b/WebCore/html/canvas/Int16Array.cpp new file mode 100644 index 0000000..f3f9742 --- /dev/null +++ b/WebCore/html/canvas/Int16Array.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "Int16Array.h" + +namespace WebCore { + +PassRefPtr<Int16Array> Int16Array::create(unsigned length) +{ + return TypedArrayBase<short>::create<Int16Array>(length); +} + +PassRefPtr<Int16Array> Int16Array::create(short* array, unsigned length) +{ + return TypedArrayBase<short>::create<Int16Array>(array, length); +} + +PassRefPtr<Int16Array> Int16Array::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<short>::create<Int16Array>(buffer, byteOffset, length); +} + +Int16Array::Int16Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : IntegralTypedArrayBase<short>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> Int16Array::slice(int start, int end) const +{ + return sliceImpl<Int16Array>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/Int16Array.h b/WebCore/html/canvas/Int16Array.h new file mode 100644 index 0000000..00877ef --- /dev/null +++ b/WebCore/html/canvas/Int16Array.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Int16Array_h +#define Int16Array_h + +#include "IntegralTypedArrayBase.h" + +namespace WebCore { + +class ArrayBuffer; + +class Int16Array : public IntegralTypedArrayBase<short> { + public: + static PassRefPtr<Int16Array> create(unsigned length); + static PassRefPtr<Int16Array> create(short* array, unsigned length); + static PassRefPtr<Int16Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); + + using TypedArrayBase<short>::set; + using IntegralTypedArrayBase<short>::set; + + private: + Int16Array(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<short>; + + // Overridden from ArrayBufferView. + virtual bool isShortArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; +}; + +} // namespace WebCore + +#endif // Int16Array_h diff --git a/WebCore/html/canvas/WebGLShortArray.idl b/WebCore/html/canvas/Int16Array.idl index 59dce76..2ac52fe 100644 --- a/WebCore/html/canvas/WebGLShortArray.idl +++ b/WebCore/html/canvas/Int16Array.idl @@ -31,10 +31,8 @@ module html { GenerateNativeConverter, CustomConstructor, CustomToJS - ] WebGLShortArray : WebGLArray { - long get(in unsigned long index); - // void set(in unsigned long index, in long value); - // void set(in WebGLShortArray array, [Optional] in unsigned long offset); + ] Int16Array : ArrayBufferView { + // void set(in Int16Array array, [Optional] in unsigned long offset); // void set(in sequence<long> array, [Optional] in unsigned long offset); [Custom] void set(); }; diff --git a/WebCore/html/canvas/WebGLUnsignedIntArray.idl b/WebCore/html/canvas/Int32Array.cpp index 75ff598..423c36b 100644 --- a/WebCore/html/canvas/WebGLUnsignedIntArray.idl +++ b/WebCore/html/canvas/Int32Array.cpp @@ -24,19 +24,39 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -module html { - interface [ - Conditional=3D_CANVAS, - CustomConstructor, - HasNumericIndexGetter, - HasCustomIndexSetter, - GenerateNativeConverter, - CustomToJS - ] WebGLUnsignedIntArray : WebGLArray { - unsigned long get(in unsigned long index); - // void set(in unsigned long index, in long value); - // void set(in WebGLUnsignedIntArray array, [Optional] in unsigned long offset); - // void set(in sequence<long> array, [Optional] in unsigned long offset); - [Custom] void set(); - }; +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "Int32Array.h" + +namespace WebCore { + +PassRefPtr<Int32Array> Int32Array::create(unsigned length) +{ + return TypedArrayBase<int>::create<Int32Array>(length); +} + +PassRefPtr<Int32Array> Int32Array::create(int* array, unsigned length) +{ + return TypedArrayBase<int>::create<Int32Array>(array, length); +} + +PassRefPtr<Int32Array> Int32Array::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<int>::create<Int32Array>(buffer, byteOffset, length); } + +Int32Array::Int32Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : IntegralTypedArrayBase<int>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> Int32Array::slice(int start, int end) const +{ + return sliceImpl<Int32Array>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/Int32Array.h b/WebCore/html/canvas/Int32Array.h new file mode 100644 index 0000000..72fb579 --- /dev/null +++ b/WebCore/html/canvas/Int32Array.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Int32Array_h +#define Int32Array_h + +#include "IntegralTypedArrayBase.h" + +namespace WebCore { + +class Int32Array : public IntegralTypedArrayBase<int> { + public: + static PassRefPtr<Int32Array> create(unsigned length); + static PassRefPtr<Int32Array> create(int* array, unsigned length); + static PassRefPtr<Int32Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); + + using TypedArrayBase<int>::set; + using IntegralTypedArrayBase<int>::set; + + private: + Int32Array(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<int>; + + // Overridden from ArrayBufferView. + virtual bool isIntArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; +}; + +} // namespace WebCore + +#endif // Int32Array_h diff --git a/WebCore/html/canvas/WebGLIntArray.idl b/WebCore/html/canvas/Int32Array.idl index ef0d92f..80a885e 100644 --- a/WebCore/html/canvas/WebGLIntArray.idl +++ b/WebCore/html/canvas/Int32Array.idl @@ -32,10 +32,8 @@ module html { GenerateNativeConverter, CustomConstructor, CustomToJS - ] WebGLIntArray : WebGLArray { - long get(in unsigned long index); - // void set(in unsigned long index, in long value); - // void set(in WebGLIntArray array, [Optional] in unsigned long offset); + ] Int32Array : ArrayBufferView { + // void set(in Int32Array array, [Optional] in unsigned long offset); // void set(in sequence<long> array, [Optional] in unsigned long offset); [Custom] void set(); }; diff --git a/WebCore/html/canvas/Int8Array.cpp b/WebCore/html/canvas/Int8Array.cpp new file mode 100644 index 0000000..20ff32a --- /dev/null +++ b/WebCore/html/canvas/Int8Array.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "Int8Array.h" + +namespace WebCore { + +PassRefPtr<Int8Array> Int8Array::create(unsigned length) +{ + return TypedArrayBase<signed char>::create<Int8Array>(length); +} + +PassRefPtr<Int8Array> Int8Array::create(signed char* array, unsigned length) +{ + return TypedArrayBase<signed char>::create<Int8Array>(array, length); +} + +PassRefPtr<Int8Array> Int8Array::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<signed char>::create<Int8Array>(buffer, byteOffset, length); +} + +Int8Array::Int8Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : IntegralTypedArrayBase<signed char>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> Int8Array::slice(int start, int end) const +{ + return sliceImpl<Int8Array>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/Int8Array.h b/WebCore/html/canvas/Int8Array.h new file mode 100644 index 0000000..d267f7f --- /dev/null +++ b/WebCore/html/canvas/Int8Array.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Int8Array_h +#define Int8Array_h + +#include "IntegralTypedArrayBase.h" + +namespace WebCore { + +class ArrayBuffer; + +class Int8Array : public IntegralTypedArrayBase<signed char> { + public: + static PassRefPtr<Int8Array> create(unsigned length); + static PassRefPtr<Int8Array> create(signed char* array, unsigned length); + static PassRefPtr<Int8Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); + + using TypedArrayBase<signed char>::set; + using IntegralTypedArrayBase<signed char>::set; + + private: + Int8Array(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<signed char>; + + // Overridden from ArrayBufferView. + virtual bool isByteArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; +}; + +} // namespace WebCore + +#endif // Int8Array_h diff --git a/WebCore/html/canvas/WebGLByteArray.idl b/WebCore/html/canvas/Int8Array.idl index dbb3bb2..1124ac1 100644 --- a/WebCore/html/canvas/WebGLByteArray.idl +++ b/WebCore/html/canvas/Int8Array.idl @@ -32,10 +32,8 @@ module html { GenerateNativeConverter, CustomConstructor, CustomToJS - ] WebGLByteArray : WebGLArray { - long get(in unsigned long index); - // void set(in unsigned long index, in long value); - // void set(in WebGLByteArray array, [Optional] in unsigned long offset); + ] Int8Array : ArrayBufferView { + // void set(in Int8Array array, [Optional] in unsigned long offset); // void set(in sequence<long> array, [Optional] in unsigned long offset); [Custom] void set(); }; diff --git a/WebCore/html/canvas/IntegralTypedArrayBase.h b/WebCore/html/canvas/IntegralTypedArrayBase.h new file mode 100644 index 0000000..b87d832 --- /dev/null +++ b/WebCore/html/canvas/IntegralTypedArrayBase.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (c) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef IntegralTypedArrayBase_h +#define IntegralTypedArrayBase_h + +#include "TypedArrayBase.h" +#include <limits> +#include <wtf/MathExtras.h> + +// Base class for all WebGL<T>Array types holding integral +// (non-floating-point) values. + +namespace WebCore { + +template <typename T> +class IntegralTypedArrayBase : public TypedArrayBase<T> { + public: + void set(unsigned index, double value) + { + if (index >= TypedArrayBase<T>::m_length) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<T>::min()) + value = std::numeric_limits<T>::min(); + else if (value > std::numeric_limits<T>::max()) + value = std::numeric_limits<T>::max(); + TypedArrayBase<T>::data()[index] = static_cast<T>(value); + } + + // Invoked by the indexed getter. Does not perform range checks; caller + // is responsible for doing so and returning undefined as necessary. + T item(unsigned index) const + { + ASSERT(index < TypedArrayBase<T>::m_length); + return TypedArrayBase<T>::data()[index]; + } + + protected: + IntegralTypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : TypedArrayBase<T>(buffer, byteOffset, length) + { + } +}; + +} // namespace WebCore + +#endif // IntegralTypedArrayBase_h diff --git a/WebCore/html/canvas/TypedArrayBase.h b/WebCore/html/canvas/TypedArrayBase.h new file mode 100644 index 0000000..06d7ed5 --- /dev/null +++ b/WebCore/html/canvas/TypedArrayBase.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (c) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TypedArrayBase_h +#define TypedArrayBase_h + +#include "ArrayBufferView.h" +#include "ArrayBuffer.h" + +namespace WebCore { + +template <typename T> +class TypedArrayBase : public ArrayBufferView { + public: + T* data() const { return static_cast<T*>(baseAddress()); } + + void set(TypedArrayBase<T>* array, unsigned offset, ExceptionCode& ec) + { + setImpl(array, offset * sizeof(T), ec); + } + + // Overridden from ArrayBufferView. This must be public because of + // rules about inheritance of members in template classes, and + // because it is accessed via pointers to subclasses. + virtual unsigned length() const + { + return m_length; + } + + protected: + TypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : ArrayBufferView(buffer, byteOffset) + , m_length(length) + { + } + + template <class Subclass> + static PassRefPtr<Subclass> create(unsigned length) + { + RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, sizeof(T)); + return create<Subclass>(buffer, 0, length); + } + + template <class Subclass> + static PassRefPtr<Subclass> create(T* array, unsigned length) + { + RefPtr<Subclass> a = create<Subclass>(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; + } + + template <class Subclass> + static PassRefPtr<Subclass> create(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length) + { + RefPtr<ArrayBuffer> buf(buffer); + if (!verifySubRange<T>(buf, byteOffset, length)) + return 0; + + return adoptRef(new Subclass(buf, byteOffset, length)); + } + + template <class Subclass> + PassRefPtr<Subclass> sliceImpl(int start, int end) const + { + unsigned offset, length; + calculateOffsetAndLength(start, end, m_length, &offset, &length); + clampOffsetAndNumElements<T>(buffer(), m_byteOffset, &offset, &length); + return create<Subclass>(buffer(), offset, length); + } + + // We do not want to have to access this via a virtual function in subclasses, + // which is why it is protected rather than private. + unsigned m_length; + + private: + // Overridden from ArrayBufferView. + virtual unsigned byteLength() const + { + return m_length * sizeof(T); + } +}; + +} // namespace WebCore + +#endif // TypedArrayBase_h diff --git a/WebCore/html/canvas/Uint16Array.cpp b/WebCore/html/canvas/Uint16Array.cpp new file mode 100644 index 0000000..4656173 --- /dev/null +++ b/WebCore/html/canvas/Uint16Array.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "Uint16Array.h" + +namespace WebCore { + +PassRefPtr<Uint16Array> Uint16Array::create(unsigned length) +{ + return TypedArrayBase<unsigned short>::create<Uint16Array>(length); +} + +PassRefPtr<Uint16Array> Uint16Array::create(unsigned short* array, unsigned length) +{ + return TypedArrayBase<unsigned short>::create<Uint16Array>(array, length); +} + +PassRefPtr<Uint16Array> Uint16Array::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<unsigned short>::create<Uint16Array>(buffer, byteOffset, length); +} + +Uint16Array::Uint16Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : IntegralTypedArrayBase<unsigned short>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> Uint16Array::slice(int start, int end) const +{ + return sliceImpl<Uint16Array>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/Uint16Array.h b/WebCore/html/canvas/Uint16Array.h new file mode 100644 index 0000000..fee31f6 --- /dev/null +++ b/WebCore/html/canvas/Uint16Array.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Uint16Array_h +#define Uint16Array_h + +#include "IntegralTypedArrayBase.h" + +namespace WebCore { + +class ArrayBuffer; + +class Uint16Array : public IntegralTypedArrayBase<unsigned short> { + public: + static PassRefPtr<Uint16Array> create(unsigned length); + static PassRefPtr<Uint16Array> create(unsigned short* array, unsigned length); + static PassRefPtr<Uint16Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); + + using TypedArrayBase<unsigned short>::set; + using IntegralTypedArrayBase<unsigned short>::set; + + private: + Uint16Array(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<unsigned short>; + + // Overridden from ArrayBufferView. + virtual bool isUnsignedShortArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; +}; + +} // namespace WebCore + +#endif // Uint16Array_h diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.idl b/WebCore/html/canvas/Uint16Array.idl index 4de8b42..2d5b34e 100644 --- a/WebCore/html/canvas/WebGLUnsignedByteArray.idl +++ b/WebCore/html/canvas/Uint16Array.idl @@ -27,15 +27,13 @@ module html { interface [ Conditional=3D_CANVAS, + CustomConstructor, HasNumericIndexGetter, HasCustomIndexSetter, GenerateNativeConverter, - CustomConstructor, CustomToJS - ] WebGLUnsignedByteArray : WebGLArray { - long get(in unsigned long index); - // void set(in unsigned long index, in long value); - // void set(in WebGLUnsignedByteArray array, [Optional] in unsigned long offset); + ] Uint16Array : ArrayBufferView { + // void set(in Uint16Array array, [Optional] in unsigned long offset); // void set(in sequence<long> array, [Optional] in unsigned long offset); [Custom] void set(); }; diff --git a/WebCore/html/canvas/Uint32Array.cpp b/WebCore/html/canvas/Uint32Array.cpp new file mode 100644 index 0000000..3f43bef --- /dev/null +++ b/WebCore/html/canvas/Uint32Array.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "Uint32Array.h" + +namespace WebCore { + +PassRefPtr<Uint32Array> Uint32Array::create(unsigned length) +{ + return TypedArrayBase<unsigned int>::create<Uint32Array>(length); +} + +PassRefPtr<Uint32Array> Uint32Array::create(unsigned int* array, unsigned length) +{ + return TypedArrayBase<unsigned int>::create<Uint32Array>(array, length); +} + +PassRefPtr<Uint32Array> Uint32Array::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<unsigned int>::create<Uint32Array>(buffer, byteOffset, length); +} + +Uint32Array::Uint32Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : IntegralTypedArrayBase<unsigned int>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> Uint32Array::slice(int start, int end) const +{ + return sliceImpl<Uint32Array>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/Uint32Array.h b/WebCore/html/canvas/Uint32Array.h new file mode 100644 index 0000000..db23088 --- /dev/null +++ b/WebCore/html/canvas/Uint32Array.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Uint32Array_h +#define Uint32Array_h + +#include "IntegralTypedArrayBase.h" + +namespace WebCore { + +class ArrayBuffer; + +class Uint32Array : public IntegralTypedArrayBase<unsigned int> { + public: + static PassRefPtr<Uint32Array> create(unsigned length); + static PassRefPtr<Uint32Array> create(unsigned int* array, unsigned length); + static PassRefPtr<Uint32Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); + + using TypedArrayBase<unsigned int>::set; + using IntegralTypedArrayBase<unsigned int>::set; + + private: + Uint32Array(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<unsigned int>; + + // Overridden from ArrayBufferView. + virtual bool isUnsignedIntArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; +}; + +} // namespace WebCore + +#endif // Uint32Array_h diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.idl b/WebCore/html/canvas/Uint32Array.idl index fc53929..bab0f8d 100644 --- a/WebCore/html/canvas/WebGLUnsignedShortArray.idl +++ b/WebCore/html/canvas/Uint32Array.idl @@ -32,10 +32,8 @@ module html { HasCustomIndexSetter, GenerateNativeConverter, CustomToJS - ] WebGLUnsignedShortArray : WebGLArray { - long get(in unsigned long index); - // void set(in unsigned long index, in long value); - // void set(in WebGLUnsignedShortArray array, [Optional] in unsigned long offset); + ] Uint32Array : ArrayBufferView { + // void set(in Uint32Array array, [Optional] in unsigned long offset); // void set(in sequence<long> array, [Optional] in unsigned long offset); [Custom] void set(); }; diff --git a/WebCore/html/canvas/Uint8Array.cpp b/WebCore/html/canvas/Uint8Array.cpp new file mode 100644 index 0000000..13b7022 --- /dev/null +++ b/WebCore/html/canvas/Uint8Array.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "Uint8Array.h" + +namespace WebCore { + +PassRefPtr<Uint8Array> Uint8Array::create(unsigned length) +{ + return TypedArrayBase<unsigned char>::create<Uint8Array>(length); +} + +PassRefPtr<Uint8Array> Uint8Array::create(unsigned char* array, unsigned length) +{ + return TypedArrayBase<unsigned char>::create<Uint8Array>(array, length); +} + +PassRefPtr<Uint8Array> Uint8Array::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) +{ + return TypedArrayBase<unsigned char>::create<Uint8Array>(buffer, byteOffset, length); +} + +Uint8Array::Uint8Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) + : IntegralTypedArrayBase<unsigned char>(buffer, byteOffset, length) +{ +} + +PassRefPtr<ArrayBufferView> Uint8Array::slice(int start, int end) const +{ + return sliceImpl<Uint8Array>(start, end); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/Uint8Array.h b/WebCore/html/canvas/Uint8Array.h new file mode 100644 index 0000000..6e20b42 --- /dev/null +++ b/WebCore/html/canvas/Uint8Array.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Uint8Array_h +#define Uint8Array_h + +#include "IntegralTypedArrayBase.h" + +namespace WebCore { + +class ArrayBuffer; + +class Uint8Array : public IntegralTypedArrayBase<unsigned char> { + public: + static PassRefPtr<Uint8Array> create(unsigned length); + static PassRefPtr<Uint8Array> create(unsigned char* array, unsigned length); + static PassRefPtr<Uint8Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); + + using TypedArrayBase<unsigned char>::set; + using IntegralTypedArrayBase<unsigned char>::set; + + private: + Uint8Array(PassRefPtr<ArrayBuffer> buffer, + unsigned byteOffset, + unsigned length); + // Make constructor visible to superclass. + friend class TypedArrayBase<unsigned char>; + + // Overridden from ArrayBufferView. + virtual bool isUnsignedByteArray() const { return true; } + virtual PassRefPtr<ArrayBufferView> slice(int start, int end) const; +}; + +} // namespace WebCore + +#endif // Uint8Array_h diff --git a/WebCore/html/canvas/Uint8Array.idl b/WebCore/html/canvas/Uint8Array.idl new file mode 100644 index 0000000..7031bfc --- /dev/null +++ b/WebCore/html/canvas/Uint8Array.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module html { + interface [ + Conditional=3D_CANVAS, + HasNumericIndexGetter, + HasCustomIndexSetter, + GenerateNativeConverter, + CustomConstructor, + CustomToJS + ] Uint8Array : ArrayBufferView { + // void set(in Uint8Array array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); + }; +} diff --git a/WebCore/html/canvas/WebGLBuffer.cpp b/WebCore/html/canvas/WebGLBuffer.cpp index 958bedc..192967e 100644 --- a/WebCore/html/canvas/WebGLBuffer.cpp +++ b/WebCore/html/canvas/WebGLBuffer.cpp @@ -80,7 +80,7 @@ bool WebGLBuffer::associateBufferData(unsigned long target, int size) return false; } -bool WebGLBuffer::associateBufferData(unsigned long target, WebGLArray* array) +bool WebGLBuffer::associateBufferData(unsigned long target, ArrayBufferView* array) { if (!array) return false; @@ -91,7 +91,7 @@ bool WebGLBuffer::associateBufferData(unsigned long target, WebGLArray* array) // We must always clone the incoming data because client-side // modifications without calling bufferData or bufferSubData // must never be able to change the validation results. - m_elementArrayBuffer = WebGLArrayBuffer::create(array->buffer().get()); + m_elementArrayBuffer = ArrayBuffer::create(array->buffer().get()); return true; } @@ -103,7 +103,7 @@ bool WebGLBuffer::associateBufferData(unsigned long target, WebGLArray* array) return false; } -bool WebGLBuffer::associateBufferSubData(unsigned long target, long offset, WebGLArray* array) +bool WebGLBuffer::associateBufferSubData(unsigned long target, long offset, ArrayBufferView* array) { if (!array) return false; diff --git a/WebCore/html/canvas/WebGLBuffer.h b/WebCore/html/canvas/WebGLBuffer.h index f56d374..feaadbb 100644 --- a/WebCore/html/canvas/WebGLBuffer.h +++ b/WebCore/html/canvas/WebGLBuffer.h @@ -27,7 +27,7 @@ #define WebGLBuffer_h #include "CanvasObject.h" -#include "WebGLArrayBuffer.h" +#include "ArrayBuffer.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> @@ -45,11 +45,11 @@ namespace WebCore { static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*, Platform3DObject); bool associateBufferData(unsigned long target, int size); - bool associateBufferData(unsigned long target, WebGLArray* array); - bool associateBufferSubData(unsigned long target, long offset, WebGLArray* array); + bool associateBufferData(unsigned long target, ArrayBufferView* array); + bool associateBufferSubData(unsigned long target, long offset, ArrayBufferView* array); unsigned byteLength(unsigned long target) const; - const WebGLArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); } + const ArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); } // Gets the cached max index for the given type. Returns -1 if // none has been set. @@ -66,7 +66,7 @@ namespace WebCore { private: virtual bool isBuffer() const { return true; } - RefPtr<WebGLArrayBuffer> m_elementArrayBuffer; + RefPtr<ArrayBuffer> m_elementArrayBuffer; unsigned m_elementArrayBufferByteLength; unsigned m_arrayBufferByteLength; diff --git a/WebCore/html/canvas/WebGLByteArray.cpp b/WebCore/html/canvas/WebGLByteArray.cpp deleted file mode 100644 index 603e4d1..0000000 --- a/WebCore/html/canvas/WebGLByteArray.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLArrayBuffer.h" -#include "WebGLByteArray.h" - -namespace WebCore { - -PassRefPtr<WebGLByteArray> WebGLByteArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(signed char)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLByteArray> WebGLByteArray::create(signed char* array, unsigned length) -{ - RefPtr<WebGLByteArray> a = WebGLByteArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<signed char>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLByteArray(buf, byteOffset, length)); -} - -WebGLByteArray::WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned offset, unsigned length) - : WebGLArray(buffer, offset) - , m_size(length) -{ -} - -unsigned WebGLByteArray::length() const { - return m_size; -} - -unsigned WebGLByteArray::byteLength() const { - return m_size * sizeof(signed char); -} - -PassRefPtr<WebGLArray> WebGLByteArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<signed char>(buffer().get(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLByteArray::set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(signed char), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLByteArray.h b/WebCore/html/canvas/WebGLByteArray.h deleted file mode 100644 index 60d301c..0000000 --- a/WebCore/html/canvas/WebGLByteArray.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebGLByteArray_h -#define WebGLByteArray_h - -#include "WebGLArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - -class WebGLArrayBuffer; - -class WebGLByteArray : public WebGLArray { - public: - virtual bool isByteArray() const { return true; } - - static PassRefPtr<WebGLByteArray> create(unsigned length); - static PassRefPtr<WebGLByteArray> create(signed char* array, unsigned length); - static PassRefPtr<WebGLByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - char* data() { return static_cast<char*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<signed char>::min()) - value = std::numeric_limits<signed char>::min(); - else if (value > std::numeric_limits<signed char>::max()) - value = std::numeric_limits<signed char>::max(); - signed char* storage = static_cast<signed char*>(m_baseAddress); - storage[index] = static_cast<signed char>(value); - } - - bool get(unsigned index, signed char& result) const - { - if (index >= m_size) - return false; - signed char* storage = static_cast<signed char*>(m_baseAddress); - result = storage[index]; - return true; - } - - signed char get(unsigned index) const - { - return item(index); - } - - signed char item(unsigned index) const - { - ASSERT(index < m_size); - signed char* storage = static_cast<signed char*>(m_baseAddress); - return storage[index]; - } - - void set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec); - - private: - WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned offset, - unsigned length); - unsigned m_size; -}; - -} // namespace WebCore - -#endif // WebGLByteArray_h diff --git a/WebCore/html/canvas/WebGLFloatArray.cpp b/WebCore/html/canvas/WebGLFloatArray.cpp deleted file mode 100644 index ca93c4c..0000000 --- a/WebCore/html/canvas/WebGLFloatArray.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLFloatArray.h" - -namespace WebCore { - -PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(float)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(float* array, unsigned length) -{ - RefPtr<WebGLFloatArray> a = WebGLFloatArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<float>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLFloatArray(buf, byteOffset, length)); -} - -WebGLFloatArray::WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) - : WebGLArray(buffer, byteOffset) - , m_size(length) -{ -} - -unsigned WebGLFloatArray::length() const { - return m_size; -} - -unsigned WebGLFloatArray::byteLength() const { - return m_size * sizeof(float); -} - -PassRefPtr<WebGLArray> WebGLFloatArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<float>(buffer(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLFloatArray::set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(float), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLGetInfo.cpp b/WebCore/html/canvas/WebGLGetInfo.cpp index 96218e5..d5fcd92 100644 --- a/WebCore/html/canvas/WebGLGetInfo.cpp +++ b/WebCore/html/canvas/WebGLGetInfo.cpp @@ -30,13 +30,13 @@ #include "WebGLGetInfo.h" #include "WebGLBuffer.h" -#include "WebGLFloatArray.h" +#include "FloatArray.h" #include "WebGLFramebuffer.h" -#include "WebGLIntArray.h" +#include "Int32Array.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" #include "WebGLTexture.h" -#include "WebGLUnsignedByteArray.h" +#include "Uint8Array.h" namespace WebCore { @@ -81,7 +81,7 @@ WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLBuffer> value) { } -WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLFloatArray> value) +WebGLGetInfo::WebGLGetInfo(PassRefPtr<FloatArray> value) : m_type(kTypeWebGLFloatArray) , m_webglFloatArray(value) { @@ -93,7 +93,7 @@ WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLFramebuffer> value) { } -WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLIntArray> value) +WebGLGetInfo::WebGLGetInfo(PassRefPtr<Int32Array> value) : m_type(kTypeWebGLIntArray) , m_webglIntArray(value) { @@ -117,7 +117,7 @@ WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLTexture> value) { } -WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLUnsignedByteArray> value) +WebGLGetInfo::WebGLGetInfo(PassRefPtr<Uint8Array> value) : m_type(kTypeWebGLUnsignedByteArray) , m_webglUnsignedByteArray(value) { @@ -168,7 +168,7 @@ PassRefPtr<WebGLBuffer> WebGLGetInfo::getWebGLBuffer() const return m_webglBuffer; } -PassRefPtr<WebGLFloatArray> WebGLGetInfo::getWebGLFloatArray() const +PassRefPtr<FloatArray> WebGLGetInfo::getWebGLFloatArray() const { ASSERT(getType() == kTypeWebGLFloatArray); return m_webglFloatArray; @@ -180,7 +180,7 @@ PassRefPtr<WebGLFramebuffer> WebGLGetInfo::getWebGLFramebuffer() const return m_webglFramebuffer; } -PassRefPtr<WebGLIntArray> WebGLGetInfo::getWebGLIntArray() const +PassRefPtr<Int32Array> WebGLGetInfo::getWebGLIntArray() const { ASSERT(getType() == kTypeWebGLIntArray); return m_webglIntArray; @@ -204,7 +204,7 @@ PassRefPtr<WebGLTexture> WebGLGetInfo::getWebGLTexture() const return m_webglTexture; } -PassRefPtr<WebGLUnsignedByteArray> WebGLGetInfo::getWebGLUnsignedByteArray() const +PassRefPtr<Uint8Array> WebGLGetInfo::getWebGLUnsignedByteArray() const { ASSERT(getType() == kTypeWebGLUnsignedByteArray); return m_webglUnsignedByteArray; diff --git a/WebCore/html/canvas/WebGLGetInfo.h b/WebCore/html/canvas/WebGLGetInfo.h index 8ac42c4..969e05d 100644 --- a/WebCore/html/canvas/WebGLGetInfo.h +++ b/WebCore/html/canvas/WebGLGetInfo.h @@ -32,15 +32,15 @@ #include "PlatformString.h" #include "WebGLBuffer.h" -#include "WebGLFloatArray.h" +#include "FloatArray.h" #include "WebGLFramebuffer.h" -#include "WebGLIntArray.h" +#include "Int32Array.h" // FIXME: implement WebGLObjectArray //#include "WebGLObjectArray.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" #include "WebGLTexture.h" -#include "WebGLUnsignedByteArray.h" +#include "Uint8Array.h" namespace WebCore { @@ -77,15 +77,15 @@ public: WebGLGetInfo(const String& value); WebGLGetInfo(unsigned long value); WebGLGetInfo(PassRefPtr<WebGLBuffer> value); - WebGLGetInfo(PassRefPtr<WebGLFloatArray> value); + WebGLGetInfo(PassRefPtr<FloatArray> value); WebGLGetInfo(PassRefPtr<WebGLFramebuffer> value); - WebGLGetInfo(PassRefPtr<WebGLIntArray> value); + WebGLGetInfo(PassRefPtr<Int32Array> value); // FIXME: implement WebGLObjectArray // WebGLGetInfo(PassRefPtr<WebGLObjectArray> value); WebGLGetInfo(PassRefPtr<WebGLProgram> value); WebGLGetInfo(PassRefPtr<WebGLRenderbuffer> value); WebGLGetInfo(PassRefPtr<WebGLTexture> value); - WebGLGetInfo(PassRefPtr<WebGLUnsignedByteArray> value); + WebGLGetInfo(PassRefPtr<Uint8Array> value); virtual ~WebGLGetInfo(); @@ -97,15 +97,15 @@ public: const String& getString() const; unsigned long getUnsignedLong() const; PassRefPtr<WebGLBuffer> getWebGLBuffer() const; - PassRefPtr<WebGLFloatArray> getWebGLFloatArray() const; + PassRefPtr<FloatArray> getWebGLFloatArray() const; PassRefPtr<WebGLFramebuffer> getWebGLFramebuffer() const; - PassRefPtr<WebGLIntArray> getWebGLIntArray() const; + PassRefPtr<Int32Array> getWebGLIntArray() const; // FIXME: implement WebGLObjectArray // PassRefPtr<WebGLObjectArray> getWebGLObjectArray() const; PassRefPtr<WebGLProgram> getWebGLProgram() const; PassRefPtr<WebGLRenderbuffer> getWebGLRenderbuffer() const; PassRefPtr<WebGLTexture> getWebGLTexture() const; - PassRefPtr<WebGLUnsignedByteArray> getWebGLUnsignedByteArray() const; + PassRefPtr<Uint8Array> getWebGLUnsignedByteArray() const; private: Type m_type; @@ -115,15 +115,15 @@ private: String m_string; unsigned long m_unsignedLong; RefPtr<WebGLBuffer> m_webglBuffer; - RefPtr<WebGLFloatArray> m_webglFloatArray; + RefPtr<FloatArray> m_webglFloatArray; RefPtr<WebGLFramebuffer> m_webglFramebuffer; - RefPtr<WebGLIntArray> m_webglIntArray; + RefPtr<Int32Array> m_webglIntArray; // FIXME: implement WebGLObjectArray // RefPtr<WebGLObjectArray> m_webglObjectArray; RefPtr<WebGLProgram> m_webglProgram; RefPtr<WebGLRenderbuffer> m_webglRenderbuffer; RefPtr<WebGLTexture> m_webglTexture; - RefPtr<WebGLUnsignedByteArray> m_webglUnsignedByteArray; + RefPtr<Uint8Array> m_webglUnsignedByteArray; }; } // namespace WebCore diff --git a/WebCore/html/canvas/WebGLIntArray.cpp b/WebCore/html/canvas/WebGLIntArray.cpp deleted file mode 100644 index 21b7a88..0000000 --- a/WebCore/html/canvas/WebGLIntArray.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLArrayBuffer.h" -#include "WebGLIntArray.h" - -namespace WebCore { - -PassRefPtr<WebGLIntArray> WebGLIntArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(int)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLIntArray> WebGLIntArray::create(int* array, unsigned length) -{ - RefPtr<WebGLIntArray> a = WebGLIntArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLIntArray> WebGLIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<int>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLIntArray(buf, byteOffset, length)); -} - -WebGLIntArray::WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) - : WebGLArray(buffer, byteOffset) - , m_size(length) -{ -} - -unsigned WebGLIntArray::length() const { - return m_size; -} - -unsigned WebGLIntArray::byteLength() const { - return m_size * sizeof(int); -} - -PassRefPtr<WebGLArray> WebGLIntArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<int>(buffer(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLIntArray::set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(int), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLIntArray.h b/WebCore/html/canvas/WebGLIntArray.h deleted file mode 100644 index 5929e75..0000000 --- a/WebCore/html/canvas/WebGLIntArray.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebGLIntArray_h -#define WebGLIntArray_h - -#include "WebGLArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - -class WebGLIntArray : public WebGLArray { - public: - virtual bool isIntArray() const { return true; } - - static PassRefPtr<WebGLIntArray> create(unsigned length); - static PassRefPtr<WebGLIntArray> create(int* array, unsigned length); - static PassRefPtr<WebGLIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - int* data() { return static_cast<int*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<int>::min()) - value = std::numeric_limits<int>::min(); - else if (value > std::numeric_limits<int>::max()) - value = std::numeric_limits<int>::max(); - int* storage = static_cast<int*>(m_baseAddress); - storage[index] = static_cast<int>(value); - } - - bool get(unsigned index, int& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - int get(unsigned index) const - { - return item(index); - } - - int item(unsigned index) const - { - ASSERT(index < m_size); - int* storage = static_cast<int*>(m_baseAddress); - return storage[index]; - } - - void set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec); - - private: - WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length); - unsigned m_size; -}; - -} // namespace WebCore - -#endif // WebGLIntArray_h diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp index 54ba17f..fe192a6 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.cpp +++ b/WebCore/html/canvas/WebGLRenderingContext.cpp @@ -39,7 +39,7 @@ #include "RenderBox.h" #include "RenderLayer.h" #include "WebGLActiveInfo.h" -#include "WebGLUnsignedShortArray.h" +#include "Uint16Array.h" #include "WebGLBuffer.h" #include "WebGLContextAttributes.h" #include "WebGLFramebuffer.h" @@ -102,6 +102,8 @@ WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa int implementationColorReadType = GraphicsContext3D::UNSIGNED_BYTE; m_context->getIntegerv(GraphicsContext3D::IMPLEMENTATION_COLOR_READ_TYPE, &implementationColorReadType); m_implementationColorReadType = implementationColorReadType; + if (!isGLES2Compliant()) + createFallbackBlackTextures1x1(); m_context->reshape(canvas()->width(), canvas()->height()); m_context->viewport(0, 0, canvas()->width(), canvas()->height()); } @@ -272,6 +274,8 @@ void WebGLRenderingContext::bindTexture(unsigned long target, WebGLTexture* text return; } m_context->bindTexture(target, texture); + if (!isGLES2Compliant() && texture) + texture->setTarget(target); cleanupAfterGraphicsCall(false); } @@ -328,7 +332,7 @@ void WebGLRenderingContext::bufferData(unsigned long target, int size, unsigned cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::bufferData(unsigned long target, WebGLArray* data, unsigned long usage, ExceptionCode& ec) +void WebGLRenderingContext::bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode& ec) { UNUSED_PARAM(ec); if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { @@ -350,7 +354,7 @@ void WebGLRenderingContext::bufferData(unsigned long target, WebGLArray* data, u cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::bufferSubData(unsigned long target, long offset, WebGLArray* data, ExceptionCode& ec) +void WebGLRenderingContext::bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode& ec) { UNUSED_PARAM(ec); if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { @@ -427,6 +431,28 @@ void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec void WebGLRenderingContext::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) { + if (!isGLES2Compliant()) { + if (level && WebGLTexture::isNPOT(width, height)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + RefPtr<WebGLTexture> tex = 0; + switch (target) { + case GraphicsContext3D::TEXTURE_2D: + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + break; + } + if (tex && !level) // only for level 0 + tex->setSize(target, width, height); + } m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); cleanupAfterGraphicsCall(false); } @@ -737,8 +763,10 @@ void WebGLRenderingContext::drawArrays(unsigned long mode, long first, long coun m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; } - + + handleNPOTTextures(true); m_context->drawArrays(mode, first, count); + handleNPOTTextures(false); cleanupAfterGraphicsCall(true); } @@ -758,8 +786,10 @@ void WebGLRenderingContext::drawElements(unsigned long mode, unsigned long count m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; } - + + handleNPOTTextures(true); m_context->drawElements(mode, count, type, offset); + handleNPOTTextures(false); cleanupAfterGraphicsCall(true); } @@ -882,6 +912,17 @@ void WebGLRenderingContext::frontFace(unsigned long mode) void WebGLRenderingContext::generateMipmap(unsigned long target) { + if (!isGLES2Compliant()) { + RefPtr<WebGLTexture> tex = 0; + if (target == GraphicsContext3D::TEXTURE_2D) + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + if (tex && tex->isNPOT()) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + } m_context->generateMipmap(target); cleanupAfterGraphicsCall(false); } @@ -1410,7 +1451,7 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG if (length == 1) return WebGLGetInfo(value[0]); else - return WebGLGetInfo(WebGLFloatArray::create(value, length)); + return WebGLGetInfo(FloatArray::create(value, length)); } case GraphicsContext3D::INT: { int value[16] = {0}; @@ -1418,7 +1459,7 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG if (length == 1) return WebGLGetInfo(static_cast<long>(value[0])); else - return WebGLGetInfo(WebGLIntArray::create(value, length)); + return WebGLGetInfo(Int32Array::create(value, length)); } case GraphicsContext3D::BOOL: { int value[16] = {0}; @@ -1429,7 +1470,7 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG unsigned char boolValue[16] = {0}; for (unsigned j = 0; j < length; j++) boolValue[j] = static_cast<bool>(value[j]); - return WebGLGetInfo(WebGLUnsignedByteArray::create(boolValue, length)); + return WebGLGetInfo(Uint8Array::create(boolValue, length)); } } default: @@ -1488,7 +1529,7 @@ WebGLGetInfo WebGLRenderingContext::getVertexAttrib(unsigned long index, unsigne case GraphicsContext3D::CURRENT_VERTEX_ATTRIB: { float value[4] = {0}; m_context->getVertexAttribfv(index, pname, value); - return WebGLGetInfo(WebGLFloatArray::create(value, 4)); + return WebGLGetInfo(FloatArray::create(value, 4)); } default: { m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); @@ -1601,7 +1642,7 @@ void WebGLRenderingContext::polygonOffset(double factor, double units) cleanupAfterGraphicsCall(false); } -PassRefPtr<WebGLArray> WebGLRenderingContext::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type) +PassRefPtr<ArrayBufferView> WebGLRenderingContext::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type) { // Validate enums. unsigned long componentsPerPixel = 0; @@ -1649,11 +1690,11 @@ PassRefPtr<WebGLArray> WebGLRenderingContext::readPixels(long x, long y, unsigne // The last row needs no padding. unsigned long totalBytes = bytesPerRow * height - padding; unsigned long num = totalBytes / bytesPerComponent; - RefPtr<WebGLArray> array; + RefPtr<ArrayBufferView> array; if (type == GraphicsContext3D::UNSIGNED_BYTE) - array = WebGLUnsignedByteArray::create(num); + array = Uint8Array::create(num); else - array = WebGLUnsignedShortArray::create(num); + array = Uint16Array::create(num); void* data = array->baseAddress(); m_context->readPixels(x, y, width, height, format, type, data); #if PLATFORM(CG) @@ -1765,6 +1806,28 @@ void WebGLRenderingContext::texImage2DBase(unsigned target, unsigned level, unsi { // FIXME: For now we ignore any errors returned ec = 0; + if (!isGLES2Compliant()) { + if (level && WebGLTexture::isNPOT(width, height)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + RefPtr<WebGLTexture> tex = 0; + switch (target) { + case GraphicsContext3D::TEXTURE_2D: + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + break; + } + if (tex && !level) // only for level 0 + tex->setSize(target, width, height); + } m_context->texImage2D(target, level, internalformat, width, height, border, format, type, pixels); cleanupAfterGraphicsCall(false); @@ -1786,7 +1849,7 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, Image* i void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec) + unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode& ec) { // FIXME: Need to make sure passed buffer has enough bytes to define the texture texImage2DBase(target, level, internalformat, width, height, border, @@ -1894,12 +1957,30 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLVide void WebGLRenderingContext::texParameterf(unsigned target, unsigned pname, float param) { m_context->texParameterf(target, pname, param); + if (!isGLES2Compliant()) { + RefPtr<WebGLTexture> tex = 0; + if (target == GraphicsContext3D::TEXTURE_2D) + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + if (tex) + tex->setParameterf(pname, param); + } cleanupAfterGraphicsCall(false); } void WebGLRenderingContext::texParameteri(unsigned target, unsigned pname, int param) { m_context->texParameteri(target, pname, param); + if (!isGLES2Compliant()) { + RefPtr<WebGLTexture> tex = 0; + if (target == GraphicsContext3D::TEXTURE_2D) + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + if (tex) + tex->setParameteri(pname, param); + } cleanupAfterGraphicsCall(false); } @@ -1929,7 +2010,7 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, - unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec) + unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode& ec) { // FIXME: Need to make sure passed buffer has enough bytes to define the texture texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, type, pixels ? pixels->baseAddress() : 0, ec); @@ -2052,7 +2133,7 @@ void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, floa cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2111,7 +2192,7 @@ void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, int cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2170,7 +2251,7 @@ void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, floa cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2231,7 +2312,7 @@ void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, int cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2292,7 +2373,7 @@ void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, floa cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2353,7 +2434,7 @@ void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, int cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2414,7 +2495,7 @@ void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, floa cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2475,7 +2556,7 @@ void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, int cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2519,7 +2600,7 @@ void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, int cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2563,7 +2644,7 @@ void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2607,7 +2688,7 @@ void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, FloatArray* v, ExceptionCode& ec) { UNUSED_PARAM(ec); if (!location) { @@ -2682,7 +2763,7 @@ void WebGLRenderingContext::vertexAttrib1f(unsigned long indx, float v0) cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::vertexAttrib1fv(unsigned long indx, WebGLFloatArray* v) +void WebGLRenderingContext::vertexAttrib1fv(unsigned long indx, FloatArray* v) { // FIXME: Need to make sure array is big enough for attribute being set m_context->vertexAttrib1fv(indx, v->data()); @@ -2704,7 +2785,7 @@ void WebGLRenderingContext::vertexAttrib2f(unsigned long indx, float v0, float v cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::vertexAttrib2fv(unsigned long indx, WebGLFloatArray* v) +void WebGLRenderingContext::vertexAttrib2fv(unsigned long indx, FloatArray* v) { // FIXME: Need to make sure array is big enough for attribute being set m_context->vertexAttrib2fv(indx, v->data()); @@ -2726,7 +2807,7 @@ void WebGLRenderingContext::vertexAttrib3f(unsigned long indx, float v0, float v cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::vertexAttrib3fv(unsigned long indx, WebGLFloatArray* v) +void WebGLRenderingContext::vertexAttrib3fv(unsigned long indx, FloatArray* v) { // FIXME: Need to make sure array is big enough for attribute being set m_context->vertexAttrib3fv(indx, v->data()); @@ -2748,7 +2829,7 @@ void WebGLRenderingContext::vertexAttrib4f(unsigned long indx, float v0, float v cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::vertexAttrib4fv(unsigned long indx, WebGLFloatArray* v) +void WebGLRenderingContext::vertexAttrib4fv(unsigned long indx, FloatArray* v) { // FIXME: Need to make sure array is big enough for attribute being set m_context->vertexAttrib4fv(indx, v->data()); @@ -2911,7 +2992,7 @@ WebGLGetInfo WebGLRenderingContext::getWebGLFloatArrayParameter(unsigned long pn default: notImplemented(); } - return WebGLGetInfo(WebGLFloatArray::create(value, length)); + return WebGLGetInfo(FloatArray::create(value, length)); } WebGLGetInfo WebGLRenderingContext::getWebGLIntArrayParameter(unsigned long pname) @@ -2930,7 +3011,7 @@ WebGLGetInfo WebGLRenderingContext::getWebGLIntArrayParameter(unsigned long pnam default: notImplemented(); } - return WebGLGetInfo(WebGLIntArray::create(value, length)); + return WebGLGetInfo(Int32Array::create(value, length)); } WebGLGetInfo WebGLRenderingContext::getWebGLUnsignedByteArrayParameter(unsigned long pname) @@ -2945,7 +3026,7 @@ WebGLGetInfo WebGLRenderingContext::getWebGLUnsignedByteArrayParameter(unsigned default: notImplemented(); } - return WebGLGetInfo(WebGLUnsignedByteArray::create(value, length)); + return WebGLGetInfo(Uint8Array::create(value, length)); } bool WebGLRenderingContext::isGLES2Compliant() @@ -2953,6 +3034,66 @@ bool WebGLRenderingContext::isGLES2Compliant() return m_context->isGLES2Compliant(); } +void WebGLRenderingContext::handleNPOTTextures(bool prepareToDraw) +{ + if (isGLES2Compliant()) + return; + bool resetActiveUnit = false; + // FIXME: active texture unit limits should be queries instead of 32. + for (unsigned long ii = 0; ii < 32; ++ii) { + if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture() + || m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture()) { + if (ii != m_activeTextureUnit) { + m_context->activeTexture(ii); + resetActiveUnit = true; + } else if (resetActiveUnit) { + m_context->activeTexture(ii); + resetActiveUnit = false; + } + WebGLTexture* tex2D; + WebGLTexture* texCubeMap; + if (prepareToDraw) { + tex2D = m_blackTexture2D.get(); + texCubeMap = m_blackTextureCubeMap.get(); + } else { + tex2D = m_textureUnits[ii].m_texture2DBinding.get(); + texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get(); + } + if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture()) + m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, tex2D); + if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture()) + m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, texCubeMap); + } + } + if (resetActiveUnit) + m_context->activeTexture(m_activeTextureUnit); +} + +void WebGLRenderingContext::createFallbackBlackTextures1x1() +{ + unsigned char black[] = {0, 0, 0, 255}; + m_blackTexture2D = createTexture(); + m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D.get()); + m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); + m_blackTextureCubeMap = createTexture(); + m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, m_blackTextureCubeMap.get()); + m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GraphicsContext3D::RGBA, 1, 1, + 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); + m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, 0); +} + } // namespace WebCore #endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLRenderingContext.h b/WebCore/html/canvas/WebGLRenderingContext.h index aefa6cc..d447529 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.h +++ b/WebCore/html/canvas/WebGLRenderingContext.h @@ -28,10 +28,10 @@ #include "CanvasRenderingContext.h" #include "ExceptionCode.h" -#include "WebGLFloatArray.h" +#include "FloatArray.h" #include "WebGLGetInfo.h" -#include "WebGLIntArray.h" -#include "WebGLUnsignedByteArray.h" +#include "Int32Array.h" +#include "Uint8Array.h" #include "GraphicsContext3D.h" #include "PlatformString.h" @@ -77,8 +77,8 @@ class WebKitCSSMatrix; void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha); void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&); - void bufferData(unsigned long target, WebGLArray* data, unsigned long usage, ExceptionCode&); - void bufferSubData(unsigned long target, long offset, WebGLArray* data, ExceptionCode&); + void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&); + void bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode&); unsigned long checkFramebufferStatus(unsigned long target); void clear(unsigned long mask); @@ -182,7 +182,7 @@ class WebKitCSSMatrix; void pixelStorei(unsigned long pname, long param); void polygonOffset(double factor, double units); - PassRefPtr<WebGLArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type); + PassRefPtr<ArrayBufferView> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type); void releaseShaderCompiler(); void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height); @@ -198,7 +198,7 @@ class WebKitCSSMatrix; void texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&); + unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&); void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&); void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&); void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&); @@ -217,7 +217,7 @@ class WebKitCSSMatrix; void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, - unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&); + unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&); void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&); void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&); void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&); @@ -232,50 +232,50 @@ class WebKitCSSMatrix; void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&); void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&); - void uniform1fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform1fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode&); void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&); - void uniform1iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&); void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&); - void uniform2fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform2fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode&); void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&); - void uniform2iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&); void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&); - void uniform3fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform3fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode&); void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&); - void uniform3iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&); void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&); - void uniform4fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform4fv(const WebGLUniformLocation* location, FloatArray* v, ExceptionCode&); void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&); - void uniform4iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&); void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); - void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* value, ExceptionCode&); + void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, FloatArray* value, ExceptionCode&); void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); - void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* value, ExceptionCode&); + void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, FloatArray* value, ExceptionCode&); void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); - void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* value, ExceptionCode&); + void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, FloatArray* value, ExceptionCode&); void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); void useProgram(WebGLProgram*, ExceptionCode&); void validateProgram(WebGLProgram*, ExceptionCode&); void vertexAttrib1f(unsigned long indx, float x); - void vertexAttrib1fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib1fv(unsigned long indx, FloatArray* values); void vertexAttrib1fv(unsigned long indx, float* values, int size); void vertexAttrib2f(unsigned long indx, float x, float y); - void vertexAttrib2fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib2fv(unsigned long indx, FloatArray* values); void vertexAttrib2fv(unsigned long indx, float* values, int size); void vertexAttrib3f(unsigned long indx, float x, float y, float z); - void vertexAttrib3fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib3fv(unsigned long indx, FloatArray* values); void vertexAttrib3fv(unsigned long indx, float* values, int size); void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w); - void vertexAttrib4fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib4fv(unsigned long indx, FloatArray* values); void vertexAttrib4fv(unsigned long indx, float* values, int size); void vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, unsigned long stride, unsigned long offset, ExceptionCode&); @@ -356,6 +356,9 @@ class WebKitCSSMatrix; TextureUnitState m_textureUnits[32]; unsigned long m_activeTextureUnit; + RefPtr<WebGLTexture> m_blackTexture2D; + RefPtr<WebGLTexture> m_blackTextureCubeMap; + int m_packAlignment; int m_unpackAlignment; unsigned long m_implementationColorReadFormat; @@ -382,6 +385,10 @@ class WebKitCSSMatrix; void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void handleNPOTTextures(bool prepareToDraw); + + void createFallbackBlackTextures1x1(); + friend class WebGLStateRestorer; }; diff --git a/WebCore/html/canvas/WebGLRenderingContext.idl b/WebCore/html/canvas/WebGLRenderingContext.idl index b775378..029cae3 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.idl +++ b/WebCore/html/canvas/WebGLRenderingContext.idl @@ -475,9 +475,9 @@ module html { void blendFuncSeparate(in unsigned long srcRGB, in unsigned long dstRGB, in unsigned long srcAlpha, in unsigned long dstAlpha); #if defined(V8_BINDING) && V8_BINDING - void bufferData(in unsigned long target, in WebGLArray data, in unsigned long usage) raises (DOMException); + void bufferData(in unsigned long target, in ArrayBufferView data, in unsigned long usage) raises (DOMException); void bufferData(in unsigned long target, in long size, in unsigned long usage) raises (DOMException); - void bufferSubData(in unsigned long target, in long offset, in WebGLArray data) raises (DOMException); + void bufferSubData(in unsigned long target, in long offset, in ArrayBufferView data) raises (DOMException); #else // FIXME: Unfork once JSC supports overload generation too. [Custom] void bufferData() raises(DOMException); @@ -595,7 +595,7 @@ module html { void pixelStorei(in unsigned long pname, in long param); void polygonOffset(in double factor, in double units); - WebGLArray readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type); + ArrayBufferView readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type); void releaseShaderCompiler(); void renderbufferStorage(in unsigned long target, in unsigned long internalformat, in unsigned long width, in unsigned long height); @@ -615,7 +615,7 @@ module html { // Supported forms: #if defined(V8_BINDING) && V8_BINDING void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long width, in long height, - in long border, in unsigned long format, in unsigned long type, in WebGLArray pixels) raises (DOMException); + in long border, in unsigned long format, in unsigned long type, in ArrayBufferView pixels) raises (DOMException); void texImage2D(in unsigned long target, in long level, in ImageData pixels, in [Optional] boolean flipY, in [Optional] boolean premultiplyAlpha) raises (DOMException); void texImage2D(in unsigned long target, in long level, in HTMLImageElement image, @@ -627,7 +627,7 @@ module html { void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in long width, in long height, - in unsigned long format, in unsigned long type, in WebGLArray pixels) raises (DOMException); + in unsigned long format, in unsigned long type, in ArrayBufferView pixels) raises (DOMException); void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in ImageData pixels, in [Optional] boolean flipY, in [Optional] boolean premultiplyAlpha) raises (DOMException); void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, @@ -642,37 +642,37 @@ module html { [Custom] void texSubImage2D(); #endif void uniform1f(in WebGLUniformLocation location, in float x) raises(DOMException); - [Custom] void uniform1fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + [Custom] void uniform1fv(in WebGLUniformLocation location, in FloatArray v) raises(DOMException); void uniform1i(in WebGLUniformLocation location, in long x) raises(DOMException); - [Custom] void uniform1iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + [Custom] void uniform1iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); void uniform2f(in WebGLUniformLocation location, in float x, in float y) raises(DOMException); - [Custom] void uniform2fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + [Custom] void uniform2fv(in WebGLUniformLocation location, in FloatArray v) raises(DOMException); void uniform2i(in WebGLUniformLocation location, in long x, in long y) raises(DOMException); - [Custom] void uniform2iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + [Custom] void uniform2iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); void uniform3f(in WebGLUniformLocation location, in float x, in float y, in float z) raises(DOMException); - [Custom] void uniform3fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + [Custom] void uniform3fv(in WebGLUniformLocation location, in FloatArray v) raises(DOMException); void uniform3i(in WebGLUniformLocation location, in long x, in long y, in long z) raises(DOMException); - [Custom] void uniform3iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + [Custom] void uniform3iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); void uniform4f(in WebGLUniformLocation location, in float x, in float y, in float z, in float w) raises(DOMException); - [Custom] void uniform4fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + [Custom] void uniform4fv(in WebGLUniformLocation location, in FloatArray v) raises(DOMException); void uniform4i(in WebGLUniformLocation location, in long x, in long y, in long z, in long w) raises(DOMException); - [Custom] void uniform4iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + [Custom] void uniform4iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); - [Custom] void uniformMatrix2fv(in WebGLUniformLocation location, in boolean transpose, in WebGLFloatArray array) raises(DOMException); - [Custom] void uniformMatrix3fv(in WebGLUniformLocation location, in boolean transpose, in WebGLFloatArray array) raises(DOMException); - [Custom] void uniformMatrix4fv(in WebGLUniformLocation location, in boolean transpose, in WebGLFloatArray array) raises(DOMException); + [Custom] void uniformMatrix2fv(in WebGLUniformLocation location, in boolean transpose, in FloatArray array) raises(DOMException); + [Custom] void uniformMatrix3fv(in WebGLUniformLocation location, in boolean transpose, in FloatArray array) raises(DOMException); + [Custom] void uniformMatrix4fv(in WebGLUniformLocation location, in boolean transpose, in FloatArray array) raises(DOMException); void useProgram(in WebGLProgram program) raises(DOMException); void validateProgram(in WebGLProgram program) raises(DOMException); void vertexAttrib1f(in unsigned long indx, in float x); - [Custom] void vertexAttrib1fv(in unsigned long indx, in WebGLFloatArray values); + [Custom] void vertexAttrib1fv(in unsigned long indx, in FloatArray values); void vertexAttrib2f(in unsigned long indx, in float x, in float y); - [Custom] void vertexAttrib2fv(in unsigned long indx, in WebGLFloatArray values); + [Custom] void vertexAttrib2fv(in unsigned long indx, in FloatArray values); void vertexAttrib3f(in unsigned long indx, in float x, in float y, in float z); - [Custom] void vertexAttrib3fv(in unsigned long indx, in WebGLFloatArray values); + [Custom] void vertexAttrib3fv(in unsigned long indx, in FloatArray values); void vertexAttrib4f(in unsigned long indx, in float x, in float y, in float z, in float w); - [Custom] void vertexAttrib4fv(in unsigned long indx, in WebGLFloatArray values); + [Custom] void vertexAttrib4fv(in unsigned long indx, in FloatArray values); void vertexAttribPointer(in unsigned long indx, in long size, in unsigned long type, in boolean normalized, in long stride, in unsigned long offset) raises(DOMException); diff --git a/WebCore/html/canvas/WebGLShortArray.cpp b/WebCore/html/canvas/WebGLShortArray.cpp deleted file mode 100644 index a9b0f0d..0000000 --- a/WebCore/html/canvas/WebGLShortArray.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLArrayBuffer.h" -#include "WebGLShortArray.h" - -namespace WebCore { - -PassRefPtr<WebGLShortArray> WebGLShortArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(short)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLShortArray> WebGLShortArray::create(short* array, unsigned length) -{ - RefPtr<WebGLShortArray> a = WebGLShortArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLShortArray> WebGLShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<short>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLShortArray(buf, byteOffset, length)); -} - -WebGLShortArray::WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) - : WebGLArray(buffer, byteOffset) - , m_size(length) -{ -} - -unsigned WebGLShortArray::length() const { - return m_size; -} - -unsigned WebGLShortArray::byteLength() const { - return m_size * sizeof(short); -} - -PassRefPtr<WebGLArray> WebGLShortArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<short>(buffer(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLShortArray::set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(short), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLShortArray.h b/WebCore/html/canvas/WebGLShortArray.h deleted file mode 100644 index af4befb..0000000 --- a/WebCore/html/canvas/WebGLShortArray.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebGLShortArray_h -#define WebGLShortArray_h - -#include "WebGLArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - -class WebGLShortArray : public WebGLArray { - public: - virtual bool isShortArray() const { return true; } - - static PassRefPtr<WebGLShortArray> create(unsigned length); - static PassRefPtr<WebGLShortArray> create(short* array, unsigned length); - static PassRefPtr<WebGLShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - short* data() { return static_cast<short*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<short>::min()) - value = std::numeric_limits<short>::min(); - else if (value > std::numeric_limits<short>::max()) - value = std::numeric_limits<short>::max(); - short* storage = static_cast<short*>(m_baseAddress); - storage[index] = static_cast<short>(value); - } - - bool get(unsigned index, short& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - short get(unsigned index) const - { - return item(index); - } - - short item(unsigned index) const - { - ASSERT(index < m_size); - short* storage = static_cast<short*>(m_baseAddress); - return storage[index]; - } - - void set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec); - - private: - WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - unsigned m_size; -}; - -} // namespace WebCore - -#endif // WebGLShortArray_h diff --git a/WebCore/html/canvas/WebGLTexture.cpp b/WebCore/html/canvas/WebGLTexture.cpp index 0c58edb..4e4096b 100644 --- a/WebCore/html/canvas/WebGLTexture.cpp +++ b/WebCore/html/canvas/WebGLTexture.cpp @@ -40,8 +40,131 @@ PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx) WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) : CanvasObject(ctx) , cubeMapRWrapModeInitialized(false) + , m_target(0) + , m_minFilter(GraphicsContext3D::NEAREST_MIPMAP_LINEAR) + , m_magFilter(GraphicsContext3D::LINEAR) + , m_wrapS(GraphicsContext3D::REPEAT) + , m_wrapT(GraphicsContext3D::REPEAT) + , m_isNPOT(false) + , m_needToUseBlackTexture(false) { setObject(context()->graphicsContext3D()->createTexture()); + for (int ii = 0; ii < 6; ++ii) { + m_width[ii] = 0; + m_height[ii] = 0; + } +} + +void WebGLTexture::setTarget(unsigned long target) +{ + // Target is finalized the first time bindTexture() is called. + if (m_target) + return; + switch (target) { + case GraphicsContext3D::TEXTURE_2D: + case GraphicsContext3D::TEXTURE_CUBE_MAP: + m_target = target; + break; + } +} + +void WebGLTexture::setParameteri(unsigned long pname, int param) +{ + switch (pname) { + case GraphicsContext3D::TEXTURE_MIN_FILTER: + switch (param) { + case GraphicsContext3D::NEAREST: + case GraphicsContext3D::LINEAR: + case GraphicsContext3D::NEAREST_MIPMAP_NEAREST: + case GraphicsContext3D::LINEAR_MIPMAP_NEAREST: + case GraphicsContext3D::NEAREST_MIPMAP_LINEAR: + case GraphicsContext3D::LINEAR_MIPMAP_LINEAR: + m_minFilter = param; + break; + } + break; + case GraphicsContext3D::TEXTURE_MAG_FILTER: + switch (param) { + case GraphicsContext3D::NEAREST: + case GraphicsContext3D::LINEAR: + m_magFilter = param; + break; + } + break; + case GraphicsContext3D::TEXTURE_WRAP_S: + switch (param) { + case GraphicsContext3D::CLAMP_TO_EDGE: + case GraphicsContext3D::MIRRORED_REPEAT: + case GraphicsContext3D::REPEAT: + m_wrapS = param; + break; + } + break; + case GraphicsContext3D::TEXTURE_WRAP_T: + switch (param) { + case GraphicsContext3D::CLAMP_TO_EDGE: + case GraphicsContext3D::MIRRORED_REPEAT: + case GraphicsContext3D::REPEAT: + m_wrapT = param; + break; + } + break; + default: + return; + } + updateNPOTStates(); +} + +void WebGLTexture::setParameterf(unsigned long pname, float param) +{ + int iparam = static_cast<int>(param); + setParameteri(pname, iparam); +} + +void WebGLTexture::setSize(unsigned long target, unsigned width, unsigned height) +{ + if (!width || !height) + return; + int iTarget = -1; + if (m_target == GraphicsContext3D::TEXTURE_2D) { + if (target == GraphicsContext3D::TEXTURE_2D) + iTarget = 0; + } else if (m_target == GraphicsContext3D::TEXTURE_CUBE_MAP && width == height) { + switch (target) { + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: + iTarget = 0; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: + iTarget = 1; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: + iTarget = 2; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: + iTarget = 3; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: + iTarget = 4; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: + iTarget = 5; + break; + } + } + if (iTarget < 0) + return; + m_width[iTarget] = width; + m_height[iTarget] = height; + updateNPOTStates(); +} + +bool WebGLTexture::isNPOT(unsigned width, unsigned height) +{ + if (!width || !height) + return false; + if ((width & (width - 1)) || (height & (height - 1))) + return true; + return false; } void WebGLTexture::_deleteObject(Platform3DObject object) @@ -49,6 +172,30 @@ void WebGLTexture::_deleteObject(Platform3DObject object) context()->graphicsContext3D()->deleteTexture(object); } +void WebGLTexture::updateNPOTStates() +{ + int numTargets = 0; + if (m_target == GraphicsContext3D::TEXTURE_2D) + numTargets = 1; + else if (m_target == GraphicsContext3D::TEXTURE_CUBE_MAP) + numTargets = 6; + m_isNPOT = false; + unsigned w0 = m_width[0], h0 = m_height[0]; + for (int ii = 0; ii < numTargets; ++ii) { + if (ii && (!m_width[ii] || !m_height[ii] || m_width[ii] != w0 || m_height[ii] != h0)) { + // We only set NPOT for complete cube map textures. + m_isNPOT = false; + break; + } + if (isNPOT(m_width[ii], m_height[ii])) + m_isNPOT = true; + } + m_needToUseBlackTexture = false; + if (m_isNPOT && ((m_minFilter != GraphicsContext3D::NEAREST && m_minFilter != GraphicsContext3D::LINEAR) + || m_wrapS != GraphicsContext3D::CLAMP_TO_EDGE || m_wrapT != GraphicsContext3D::CLAMP_TO_EDGE)) + m_needToUseBlackTexture = true; +} + } #endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLTexture.h b/WebCore/html/canvas/WebGLTexture.h index b3c1f05..864533e 100644 --- a/WebCore/html/canvas/WebGLTexture.h +++ b/WebCore/html/canvas/WebGLTexture.h @@ -47,6 +47,17 @@ namespace WebCore { cubeMapRWrapModeInitialized = initialized; } + void setTarget(unsigned long); + void setParameteri(unsigned long pname, int param); + void setParameterf(unsigned long pname, float param); + void setSize(unsigned long target, unsigned width, unsigned height); + + static bool isNPOT(unsigned, unsigned); + + bool isNPOT() const { return m_isNPOT; } + // Determine if texture sampling should always return [0, 0, 0, 1] (OpenGL ES 2.0 Sec 3.8.2). + bool needToUseBlackTexture() const { return m_needToUseBlackTexture; } + protected: WebGLTexture(WebGLRenderingContext*); @@ -55,7 +66,22 @@ namespace WebCore { private: virtual bool isTexture() const { return true; } + void updateNPOTStates(); + bool cubeMapRWrapModeInitialized; + + unsigned long m_target; + + int m_minFilter; + int m_magFilter; + int m_wrapS; + int m_wrapT; + + unsigned m_width[6]; + unsigned m_height[6]; + + bool m_isNPOT; + bool m_needToUseBlackTexture; }; } // namespace WebCore diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.cpp b/WebCore/html/canvas/WebGLUnsignedByteArray.cpp deleted file mode 100644 index 81e0135..0000000 --- a/WebCore/html/canvas/WebGLUnsignedByteArray.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLArrayBuffer.h" -#include "WebGLUnsignedByteArray.h" - -namespace WebCore { - -PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(unsigned char)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned char* array, unsigned length) -{ - RefPtr<WebGLUnsignedByteArray> a = WebGLUnsignedByteArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<unsigned char>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLUnsignedByteArray(buf, byteOffset, length)); -} - -WebGLUnsignedByteArray::WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) - : WebGLArray(buffer, byteOffset) - , m_size(length) -{ -} - -unsigned WebGLUnsignedByteArray::length() const { - return m_size; -} - -unsigned WebGLUnsignedByteArray::byteLength() const { - return m_size * sizeof(unsigned char); -} - -PassRefPtr<WebGLArray> WebGLUnsignedByteArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<unsigned char>(buffer(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLUnsignedByteArray::set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(unsigned char), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.h b/WebCore/html/canvas/WebGLUnsignedByteArray.h deleted file mode 100644 index 505b2fd..0000000 --- a/WebCore/html/canvas/WebGLUnsignedByteArray.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebGLUnsignedByteArray_h -#define WebGLUnsignedByteArray_h - -#include "WebGLArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - -class WebGLUnsignedByteArray : public WebGLArray { - public: - virtual bool isUnsignedByteArray() const { return true; } - - static PassRefPtr<WebGLUnsignedByteArray> create(unsigned length); - static PassRefPtr<WebGLUnsignedByteArray> create(unsigned char* array, unsigned length); - static PassRefPtr<WebGLUnsignedByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<unsigned char>::min()) - value = std::numeric_limits<unsigned char>::min(); - else if (value > std::numeric_limits<unsigned char>::max()) - value = std::numeric_limits<unsigned char>::max(); - unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); - storage[index] = static_cast<unsigned char>(value); - } - - bool get(unsigned index, unsigned char& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - unsigned char get(unsigned index) const - { - return item(index); - } - - unsigned char item(unsigned index) const - { - ASSERT(index < m_size); - unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); - return storage[index]; - } - - void set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec); - - private: - WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - unsigned m_size; -}; - -} // namespace WebCore - -#endif // WebGLUnsignedByteArray_h diff --git a/WebCore/html/canvas/WebGLUnsignedIntArray.cpp b/WebCore/html/canvas/WebGLUnsignedIntArray.cpp deleted file mode 100644 index 59d895f..0000000 --- a/WebCore/html/canvas/WebGLUnsignedIntArray.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLArrayBuffer.h" -#include "WebGLUnsignedIntArray.h" - -namespace WebCore { - -PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(unsigned int)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned int* array, unsigned length) -{ - RefPtr<WebGLUnsignedIntArray> a = WebGLUnsignedIntArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<unsigned int>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLUnsignedIntArray(buf, byteOffset, length)); -} - -WebGLUnsignedIntArray::WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length) - : WebGLArray(buffer, byteOffset) - , m_size(length) -{ -} - -unsigned WebGLUnsignedIntArray::length() const { - return m_size; -} - -unsigned WebGLUnsignedIntArray::byteLength() const { - return m_size * sizeof(unsigned int); -} - -PassRefPtr<WebGLArray> WebGLUnsignedIntArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<unsigned int>(buffer(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLUnsignedIntArray::set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(unsigned int), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLUnsignedIntArray.h b/WebCore/html/canvas/WebGLUnsignedIntArray.h deleted file mode 100644 index 6e9b220..0000000 --- a/WebCore/html/canvas/WebGLUnsignedIntArray.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebGLUnsignedIntArray_h -#define WebGLUnsignedIntArray_h - -#include "WebGLArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - -class WebGLUnsignedIntArray : public WebGLArray { - public: - virtual bool isUnsignedIntArray() const { return true; } - - static PassRefPtr<WebGLUnsignedIntArray> create(unsigned length); - static PassRefPtr<WebGLUnsignedIntArray> create(unsigned int* array, unsigned length); - static PassRefPtr<WebGLUnsignedIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<unsigned int>::min()) - value = std::numeric_limits<unsigned int>::min(); - else if (value > std::numeric_limits<unsigned int>::max()) - value = std::numeric_limits<unsigned int>::max(); - unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); - storage[index] = static_cast<unsigned int>(value); - } - - bool get(unsigned index, unsigned int& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - unsigned int get(unsigned index) const - { - return item(index); - } - - unsigned int item(unsigned index) const - { - ASSERT(index < m_size); - unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); - return storage[index]; - } - - void set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec); - - private: - WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - unsigned m_size; -}; - -} // namespace WebCore - -#endif // WebGLUnsignedIntArray_h diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.cpp b/WebCore/html/canvas/WebGLUnsignedShortArray.cpp deleted file mode 100644 index c283a81..0000000 --- a/WebCore/html/canvas/WebGLUnsignedShortArray.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "WebGLArrayBuffer.h" -#include "WebGLUnsignedShortArray.h" - -namespace WebCore { - -PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned length) -{ - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length, sizeof(unsigned short)); - return create(buffer, 0, length); -} - -PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned short* array, unsigned length) -{ - RefPtr<WebGLUnsignedShortArray> a = WebGLUnsignedShortArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; -} - -PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length) -{ - RefPtr<WebGLArrayBuffer> buf(buffer); - if (!verifySubRange<unsigned short>(buf, byteOffset, length)) - return 0; - - return adoptRef(new WebGLUnsignedShortArray(buf, byteOffset, length)); -} - -WebGLUnsignedShortArray::WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer, - unsigned byteOffset, - unsigned length) - : WebGLArray(buffer, byteOffset) - , m_size(length) -{ -} - -unsigned WebGLUnsignedShortArray::length() const { - return m_size; -} - -unsigned WebGLUnsignedShortArray::byteLength() const { - return m_size * sizeof(unsigned short); -} - -PassRefPtr<WebGLArray> WebGLUnsignedShortArray::slice(int start, int end) -{ - unsigned offset, length; - calculateOffsetAndLength(start, end, m_size, &offset, &length); - clampOffsetAndNumElements<unsigned short>(buffer(), m_byteOffset, &offset, &length); - return create(buffer(), offset, length); -} - -void WebGLUnsignedShortArray::set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec) { - setImpl(array, offset * sizeof(unsigned short), ec); -} - -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.h b/WebCore/html/canvas/WebGLUnsignedShortArray.h deleted file mode 100644 index 94b428a..0000000 --- a/WebCore/html/canvas/WebGLUnsignedShortArray.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef WebGLUnsignedShortArray_h -#define WebGLUnsignedShortArray_h - -#include "WebGLArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - -class WebGLUnsignedShortArray : public WebGLArray { - public: - virtual bool isUnsignedShortArray() const { return true; } - - static PassRefPtr<WebGLUnsignedShortArray> create(unsigned length); - static PassRefPtr<WebGLUnsignedShortArray> create(unsigned short* array, unsigned length); - static PassRefPtr<WebGLUnsignedShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset, unsigned length); - - unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned byteLength() const; - virtual PassRefPtr<WebGLArray> slice(int start, int end); - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<unsigned short>::min()) - value = std::numeric_limits<unsigned short>::min(); - else if (value > std::numeric_limits<unsigned short>::max()) - value = std::numeric_limits<unsigned short>::max(); - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - storage[index] = static_cast<unsigned short>(value); - } - - bool get(unsigned index, unsigned short& result) const - { - if (index >= m_size) - return false; - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - result = storage[index]; - return true; - } - - unsigned short get(unsigned index) const - { - return item(index); - } - - unsigned short item(unsigned index) const - { - ASSERT(index < m_size); - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - return storage[index]; - } - - void set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec); - - private: - WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset,unsigned length); - unsigned m_size; -}; - -} // namespace WebCore - -#endif // WebGLUnsignedShortArray_h |