diff options
Diffstat (limited to 'WebCore/html/canvas')
78 files changed, 5274 insertions, 3383 deletions
diff --git a/WebCore/html/canvas/CanvasArray.idl b/WebCore/html/canvas/CanvasArray.idl deleted file mode 100644 index 63b2dcd..0000000 --- a/WebCore/html/canvas/CanvasArray.idl +++ /dev/null @@ -1,32 +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. - */ - -module html { - interface [Conditional=3D_CANVAS, CustomToJS] CanvasArray { - readonly attribute long length; - int sizeInBytes(); - int alignedSizeInBytes(); - }; -} diff --git a/WebCore/html/canvas/CanvasArrayBuffer.cpp b/WebCore/html/canvas/CanvasArrayBuffer.cpp deleted file mode 100644 index c8a1397..0000000 --- a/WebCore/html/canvas/CanvasArrayBuffer.cpp +++ /dev/null @@ -1,57 +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 "CanvasArrayBuffer.h" - -namespace WebCore { - - PassRefPtr<CanvasArrayBuffer> CanvasArrayBuffer::create(unsigned sizeInBytes) - { - return adoptRef(new CanvasArrayBuffer(sizeInBytes)); - } - - CanvasArrayBuffer::CanvasArrayBuffer(unsigned sizeInBytes) { - m_sizeInBytes = sizeInBytes; - m_data = WTF::fastZeroedMalloc(sizeInBytes); - } - - void* CanvasArrayBuffer::data() { - return m_data; - } - - unsigned CanvasArrayBuffer::byteLength() const { - return m_sizeInBytes; - } - - CanvasArrayBuffer::~CanvasArrayBuffer() { - WTF::fastFree(m_data); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasByteArray.h b/WebCore/html/canvas/CanvasByteArray.h deleted file mode 100644 index 69cadf7..0000000 --- a/WebCore/html/canvas/CanvasByteArray.h +++ /dev/null @@ -1,90 +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 CanvasByteArray_h -#define CanvasByteArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasArrayBuffer; - - class CanvasByteArray : public CanvasArray { - public: - virtual bool isByteArray() const { return true; } - - static PassRefPtr<CanvasByteArray> create(unsigned length); - static PassRefPtr<CanvasByteArray> create(signed char* array, unsigned length); - static PassRefPtr<CanvasByteArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - char* data() { return static_cast<char*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - 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 item(unsigned index) const - { - ASSERT(index < m_size); - signed char* storage = static_cast<signed char*>(m_baseAddress); - return storage[index]; - } - private: - CanvasByteArray(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasByteArray_h diff --git a/WebCore/html/canvas/CanvasFloatArray.cpp b/WebCore/html/canvas/CanvasFloatArray.cpp deleted file mode 100644 index 09561cb..0000000 --- a/WebCore/html/canvas/CanvasFloatArray.cpp +++ /dev/null @@ -1,78 +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 "CanvasFloatArray.h" - -namespace WebCore { - - PassRefPtr<CanvasFloatArray> CanvasFloatArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(float)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasFloatArray> CanvasFloatArray::create(float* array, unsigned length) - { - RefPtr<CanvasFloatArray> a = CanvasFloatArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasFloatArray> CanvasFloatArray::create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(float)) != 0) - return NULL; - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(float))) > buffer->byteLength()) - return NULL; - } - return adoptRef(new CanvasFloatArray(buffer, offset, length)); - } - - CanvasFloatArray::CanvasFloatArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasFloatArray::length() const { - return m_size; - } - - unsigned CanvasFloatArray::sizeInBytes() const { - return length() * sizeof(float); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasFloatArray.h b/WebCore/html/canvas/CanvasFloatArray.h deleted file mode 100644 index d2dc4ff..0000000 --- a/WebCore/html/canvas/CanvasFloatArray.h +++ /dev/null @@ -1,86 +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 CanvasFloatArray_h -#define CanvasFloatArray_h - -#include "CanvasArray.h" -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasFloatArray : public CanvasArray { - public: - virtual bool isFloatArray() const { return true; } - - static PassRefPtr<CanvasFloatArray> create(unsigned length); - static PassRefPtr<CanvasFloatArray> create(float* array, unsigned length); - static PassRefPtr<CanvasFloatArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - float* data() { return static_cast<float*>(baseAddress()); } - - virtual unsigned length() const; - - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - 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 item(unsigned index) const - { - ASSERT(index < m_size); - float* storage = static_cast<float*>(m_baseAddress); - float result = storage[index]; - if (isnan(result)) { - // Clamp NaN to 0 - result = 0; - } - return result; - } - private: - CanvasFloatArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasFloatArray_h diff --git a/WebCore/html/canvas/CanvasIntArray.cpp b/WebCore/html/canvas/CanvasIntArray.cpp deleted file mode 100644 index 4716d7b..0000000 --- a/WebCore/html/canvas/CanvasIntArray.cpp +++ /dev/null @@ -1,82 +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 "CanvasArrayBuffer.h" -#include "CanvasIntArray.h" - -namespace WebCore { - - PassRefPtr<CanvasIntArray> CanvasIntArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(int)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasIntArray> CanvasIntArray::create(int* array, unsigned length) - { - RefPtr<CanvasIntArray> a = CanvasIntArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasIntArray> CanvasIntArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(int)) != 0) - return NULL; - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(int))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasIntArray(buffer, offset, length)); - } - - CanvasIntArray::CanvasIntArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasIntArray::length() const { - return m_size; - } - - unsigned CanvasIntArray::sizeInBytes() const { - return length() * sizeof(int); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasIntArray.h b/WebCore/html/canvas/CanvasIntArray.h deleted file mode 100644 index 4977034..0000000 --- a/WebCore/html/canvas/CanvasIntArray.h +++ /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. - */ - -#ifndef CanvasIntArray_h -#define CanvasIntArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasIntArray : public CanvasArray { - public: - virtual bool isIntArray() const { return true; } - - static PassRefPtr<CanvasIntArray> create(unsigned length); - static PassRefPtr<CanvasIntArray> create(int* array, unsigned length); - static PassRefPtr<CanvasIntArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - int* data() { return static_cast<int*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - 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 item(unsigned index) const - { - ASSERT(index < m_size); - int* storage = static_cast<int*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasIntArray(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasIntArray_h diff --git a/WebCore/html/canvas/CanvasObject.cpp b/WebCore/html/canvas/CanvasObject.cpp index 8a71a45..6c7667b 100644 --- a/WebCore/html/canvas/CanvasObject.cpp +++ b/WebCore/html/canvas/CanvasObject.cpp @@ -28,12 +28,13 @@ #if ENABLE(3D_CANVAS) #include "CanvasObject.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLRenderingContext.h" namespace WebCore { -CanvasObject::CanvasObject(CanvasRenderingContext3D* context) +CanvasObject::CanvasObject(WebGLRenderingContext* context) : m_object(0) + , m_shouldDeleteObject(true) , m_context(context) { } @@ -44,24 +45,27 @@ CanvasObject::~CanvasObject() m_context->removeObject(this); } -void CanvasObject::setObject(Platform3DObject object) +void CanvasObject::setObject(Platform3DObject object, bool shouldDeleteObject) { if (object == m_object) return; deleteObject(); m_object = object; + m_shouldDeleteObject = shouldDeleteObject; } void CanvasObject::deleteObject() { if (m_object) { - if (m_context) { - m_context->graphicsContext3D()->makeContextCurrent(); - _deleteObject(m_object); - } + if (m_shouldDeleteObject) + if (m_context) { + m_context->graphicsContext3D()->makeContextCurrent(); + _deleteObject(m_object); + } m_object = 0; } + m_shouldDeleteObject = true; } } diff --git a/WebCore/html/canvas/CanvasObject.h b/WebCore/html/canvas/CanvasObject.h index 748278d..b7b016a 100644 --- a/WebCore/html/canvas/CanvasObject.h +++ b/WebCore/html/canvas/CanvasObject.h @@ -33,14 +33,14 @@ namespace WebCore { - class CanvasRenderingContext3D; + class WebGLRenderingContext; class CanvasObject : public RefCounted<CanvasObject> { public: virtual ~CanvasObject(); Platform3DObject object() const { return m_object; } - void setObject(Platform3DObject); + void setObject(Platform3DObject, bool shouldDeleteObject = true); void deleteObject(); void detachContext() @@ -49,15 +49,22 @@ namespace WebCore { m_context = 0; } - CanvasRenderingContext3D* context() const { return m_context; } + WebGLRenderingContext* context() const { return m_context; } protected: - CanvasObject(CanvasRenderingContext3D*); + CanvasObject(WebGLRenderingContext*); virtual void _deleteObject(Platform3DObject) = 0; private: Platform3DObject m_object; - CanvasRenderingContext3D* m_context; + // The shouldDeleteObject flag indicates whether this wrapper + // owns the underlying resource and should delete it when the + // wrapper is unreferenced for the last time and deleted. It + // is only set to false for certain objects returned from get + // queries. FIXME: should consider canonicalizing all of these + // objects in the future. + bool m_shouldDeleteObject; + WebGLRenderingContext* m_context; }; } // namespace WebCore diff --git a/WebCore/html/canvas/CanvasRenderbuffer.idl b/WebCore/html/canvas/CanvasRenderbuffer.idl deleted file mode 100644 index 5e47cc3..0000000 --- a/WebCore/html/canvas/CanvasRenderbuffer.idl +++ /dev/null @@ -1,29 +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. - */ - -module html { - interface [Conditional=3D_CANVAS] CanvasRenderbuffer { - }; -} diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 3341901..1ae9f75 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -355,6 +355,9 @@ void CanvasRenderingContext2D::scale(float sx, float sy) if (!state().m_invertibleCTM) return; + if (!isfinite(sx) | !isfinite(sy)) + return; + TransformationMatrix newTransform = state().m_transform; newTransform.scaleNonUniform(sx, sy); if (!newTransform.isInvertible()) { @@ -375,6 +378,9 @@ void CanvasRenderingContext2D::rotate(float angleInRadians) if (!state().m_invertibleCTM) return; + if (!isfinite(angleInRadians)) + return; + TransformationMatrix newTransform = state().m_transform; newTransform.rotate(angleInRadians / piDouble * 180.0); if (!newTransform.isInvertible()) { @@ -395,6 +401,9 @@ void CanvasRenderingContext2D::translate(float tx, float ty) if (!state().m_invertibleCTM) return; + if (!isfinite(tx) | !isfinite(ty)) + return; + TransformationMatrix newTransform = state().m_transform; newTransform.translate(tx, ty); if (!newTransform.isInvertible()) { @@ -414,8 +423,7 @@ void CanvasRenderingContext2D::transform(float m11, float m12, float m21, float return; if (!state().m_invertibleCTM) return; - - // HTML5 3.14.11.1 -- ignore any calls that pass non-finite numbers + if (!isfinite(m11) | !isfinite(m21) | !isfinite(dx) | !isfinite(m12) | !isfinite(m22) | !isfinite(dy)) return; @@ -438,7 +446,6 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo if (!c) return; - // HTML5 3.14.11.1 -- ignore any calls that pass non-finite numbers if (!isfinite(m11) | !isfinite(m21) | !isfinite(dx) | !isfinite(m12) | !isfinite(m22) | !isfinite(dy)) return; @@ -817,7 +824,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, return; RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha) @@ -833,7 +840,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, RGBA32 rgba = 0; // default is transparent black if (!state().m_shadowColor.isEmpty()) CSSParser::parseColor(rgba, state().m_shadowColor); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha))); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha)), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha) @@ -847,7 +854,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, return; RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float r, float g, float b, float a) @@ -863,7 +870,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, 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)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a) @@ -883,7 +890,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, CGContextSetShadowWithColor(dc->platformContext(), adjustedShadowSize(width, -height), blur, shadowColor); CGColorRelease(shadowColor); #else - dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a)); + dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a), DeviceColorSpace); #endif } @@ -906,7 +913,7 @@ void CanvasRenderingContext2D::applyShadow() CSSParser::parseColor(rgba, state().m_shadowColor); float width = state().m_shadowOffset.width(); float height = state().m_shadowOffset.height(); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } static IntSize size(HTMLImageElement* image) @@ -995,7 +1002,7 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec FloatRect sourceRect = c->roundToDevicePixels(srcRect); FloatRect destRect = c->roundToDevicePixels(dstRect); willDraw(destRect); - c->drawImage(cachedImage->image(), destRect, sourceRect, state().m_globalComposite); + c->drawImage(cachedImage->image(), DeviceColorSpace, destRect, sourceRect, state().m_globalComposite); } void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, float x, float y) @@ -1045,7 +1052,7 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, const if (!sourceCanvas->originClean()) canvas()->setOriginTainted(); - c->drawImage(buffer->image(), destRect, sourceRect, state().m_globalComposite); + c->drawImage(buffer->image(), DeviceColorSpace, destRect, sourceRect, state().m_globalComposite); willDraw(destRect); // This call comes after drawImage, since the buffer we draw into may be our own, and we need to make sure it is dirty. // FIXME: Arguably willDraw should become didDraw and occur after drawing calls and not before them to avoid problems like this. } @@ -1139,7 +1146,7 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image, FloatRect destRect = FloatRect(dx, dy, dw, dh); willDraw(destRect); - c->drawImage(cachedImage->image(), destRect, FloatRect(sx, sy, sw, sh), op); + c->drawImage(cachedImage->image(), DeviceColorSpace, destRect, FloatRect(sx, sy, sw, sh), op); } void CanvasRenderingContext2D::setAlpha(float alpha) @@ -1526,9 +1533,9 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo GraphicsContext* maskImageContext = maskImage->context(); if (fill) - maskImageContext->setFillColor(Color::black); + maskImageContext->setFillColor(Color::black, DeviceColorSpace); else { - maskImageContext->setStrokeColor(Color::black); + maskImageContext->setStrokeColor(Color::black, DeviceColorSpace); maskImageContext->setStrokeThickness(c->strokeThickness()); } diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.cpp b/WebCore/html/canvas/CanvasRenderingContext3D.cpp deleted file mode 100644 index 612b4c3..0000000 --- a/WebCore/html/canvas/CanvasRenderingContext3D.cpp +++ /dev/null @@ -1,1441 +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 "CanvasRenderingContext3D.h" - -#include "CanvasActiveInfo.h" -#include "CanvasBuffer.h" -#include "CanvasFramebuffer.h" -#include "CanvasProgram.h" -#include "CanvasRenderbuffer.h" -#include "CanvasTexture.h" -#include "CanvasShader.h" -#include "HTMLCanvasElement.h" -#include "RenderBox.h" -#include "RenderLayer.h" - -namespace WebCore { - -PassOwnPtr<CanvasRenderingContext3D> CanvasRenderingContext3D::create(HTMLCanvasElement* canvas) -{ - OwnPtr<GraphicsContext3D> context(GraphicsContext3D::create()); - if (!context) - return 0; - - return new CanvasRenderingContext3D(canvas, context.release()); -} - -CanvasRenderingContext3D::CanvasRenderingContext3D(HTMLCanvasElement* passedCanvas, PassOwnPtr<GraphicsContext3D> context) - : CanvasRenderingContext(passedCanvas) - , m_context(context) - , m_needsUpdate(true) - , m_markedCanvasDirty(false) -{ - ASSERT(m_context); - m_context->reshape(canvas()->width(), canvas()->height()); -} - -CanvasRenderingContext3D::~CanvasRenderingContext3D() -{ - detachAndRemoveAllObjects(); -} - -void CanvasRenderingContext3D::markContextChanged() -{ -#if USE(ACCELERATED_COMPOSITING) - if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) { - canvas()->renderBox()->layer()->rendererContentChanged(); - } else { -#endif - if (!m_markedCanvasDirty) { - // Make sure the canvas's image buffer is allocated. - canvas()->buffer(); - canvas()->willDraw(FloatRect(0, 0, canvas()->width(), canvas()->height())); - m_markedCanvasDirty = true; - } -#if USE(ACCELERATED_COMPOSITING) - } -#endif -} - -void CanvasRenderingContext3D::beginPaint() -{ - if (m_markedCanvasDirty) { - m_context->beginPaint(this); - } -} - -void CanvasRenderingContext3D::endPaint() -{ - if (m_markedCanvasDirty) { - m_markedCanvasDirty = false; - m_context->endPaint(); - } -} - -void CanvasRenderingContext3D::reshape(int width, int height) -{ - if (m_needsUpdate) { -#if USE(ACCELERATED_COMPOSITING) - if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) - canvas()->renderBox()->layer()->rendererContentChanged(); -#endif - m_needsUpdate = false; - } - - m_context->reshape(width, height); -} - -int CanvasRenderingContext3D::sizeInBytes(int type, ExceptionCode& ec) -{ - int result = m_context->sizeInBytes(type); - if (result <= 0) { - ec = SYNTAX_ERR; - } - return result; -} - -void CanvasRenderingContext3D::activeTexture(unsigned long texture) -{ - m_context->activeTexture(texture); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::attachShader(CanvasProgram* program, CanvasShader* shader) -{ - if (!program || !shader) - return; - m_context->attachShader(program, shader); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bindAttribLocation(CanvasProgram* program, unsigned long index, const String& name) -{ - if (!program) - return; - m_context->bindAttribLocation(program, index, name); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bindBuffer(unsigned long target, CanvasBuffer* buffer) -{ - m_context->bindBuffer(target, buffer); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::bindFramebuffer(unsigned long target, CanvasFramebuffer* buffer) -{ - m_context->bindFramebuffer(target, buffer); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bindRenderbuffer(unsigned long target, CanvasRenderbuffer* renderbuffer) -{ - m_context->bindRenderbuffer(target, renderbuffer); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::bindTexture(unsigned long target, CanvasTexture* texture) -{ - m_context->bindTexture(target, texture); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendColor(double red, double green, double blue, double alpha) -{ - m_context->blendColor(red, green, blue, alpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendEquation( unsigned long mode ) -{ - m_context->blendEquation(mode); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha) -{ - m_context->blendEquationSeparate(modeRGB, modeAlpha); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor) -{ - m_context->blendFunc(sfactor, dfactor); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha) -{ - m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bufferData(unsigned long target, int size, unsigned long usage) -{ - m_context->bufferData(target, size, usage); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bufferData(unsigned long target, CanvasArray* data, unsigned long usage) -{ - m_context->bufferData(target, data, usage); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bufferSubData(unsigned long target, long offset, CanvasArray* data) -{ - m_context->bufferSubData(target, offset, data); - cleanupAfterGraphicsCall(false); -} - -unsigned long CanvasRenderingContext3D::checkFramebufferStatus(unsigned long target) -{ - return m_context->checkFramebufferStatus(target); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::clear(unsigned long mask) -{ - m_context->clear(mask); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::clearColor(double r, double g, double b, double a) -{ - if (isnan(r)) - r = 0; - if (isnan(g)) - g = 0; - if (isnan(b)) - b = 0; - if (isnan(a)) - a = 1; - m_context->clearColor(r, g, b, a); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::clearDepth(double depth) -{ - m_context->clearDepth(depth); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::clearStencil(long s) -{ - m_context->clearStencil(s); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::colorMask(bool red, bool green, bool blue, bool alpha) -{ - m_context->colorMask(red, green, blue, alpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::compileShader(CanvasShader* shader) -{ - m_context->compileShader(shader); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) -{ - m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height) -{ - m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); - cleanupAfterGraphicsCall(false); -} - -PassRefPtr<CanvasBuffer> CanvasRenderingContext3D::createBuffer() -{ - RefPtr<CanvasBuffer> o = CanvasBuffer::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasFramebuffer> CanvasRenderingContext3D::createFramebuffer() -{ - RefPtr<CanvasFramebuffer> o = CanvasFramebuffer::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasTexture> CanvasRenderingContext3D::createTexture() -{ - RefPtr<CanvasTexture> o = CanvasTexture::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasProgram> CanvasRenderingContext3D::createProgram() -{ - RefPtr<CanvasProgram> o = CanvasProgram::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasRenderbuffer> CanvasRenderingContext3D::createRenderbuffer() -{ - RefPtr<CanvasRenderbuffer> o = CanvasRenderbuffer::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasShader> CanvasRenderingContext3D::createShader(unsigned long type) -{ - // FIXME: Need to include GL_ constants for internal use - // FIXME: Need to do param checking and throw exception if an illegal value is passed in - GraphicsContext3D::ShaderType shaderType = GraphicsContext3D::VERTEX_SHADER; - if (type == 0x8B30) // GL_FRAGMENT_SHADER - shaderType = GraphicsContext3D::FRAGMENT_SHADER; - - RefPtr<CanvasShader> o = CanvasShader::create(this, shaderType); - addObject(o.get()); - return o; -} - -void CanvasRenderingContext3D::cullFace(unsigned long mode) -{ - m_context->cullFace(mode); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::deleteBuffer(CanvasBuffer* buffer) -{ - if (!buffer) - return; - - buffer->deleteObject(); -} - -void CanvasRenderingContext3D::deleteFramebuffer(CanvasFramebuffer* framebuffer) -{ - if (!framebuffer) - return; - - framebuffer->deleteObject(); -} - -void CanvasRenderingContext3D::deleteProgram(CanvasProgram* program) -{ - if (!program) - return; - - program->deleteObject(); -} - -void CanvasRenderingContext3D::deleteRenderbuffer(CanvasRenderbuffer* renderbuffer) -{ - if (!renderbuffer) - return; - - renderbuffer->deleteObject(); -} - -void CanvasRenderingContext3D::deleteShader(CanvasShader* shader) -{ - if (!shader) - return; - - shader->deleteObject(); -} - -void CanvasRenderingContext3D::deleteTexture(CanvasTexture* texture) -{ - if (!texture) - return; - - texture->deleteObject(); -} - -void CanvasRenderingContext3D::depthFunc(unsigned long func) -{ - m_context->depthFunc(func); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::depthMask(bool flag) -{ - m_context->depthMask(flag); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::depthRange(double zNear, double zFar) -{ - m_context->depthRange(zNear, zFar); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::detachShader(CanvasProgram* program, CanvasShader* shader) -{ - if (!program || !shader) - return; - - m_context->detachShader(program, shader); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::disable(unsigned long cap) -{ - m_context->disable(cap); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::disableVertexAttribArray(unsigned long index) -{ - m_context->disableVertexAttribArray(index); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::drawArrays(unsigned long mode, long first, long count) -{ - m_context->drawArrays(mode, first, count); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset) -{ - m_context->drawElements(mode, count, type, offset); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::enable(unsigned long cap) -{ - m_context->enable(cap); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::enableVertexAttribArray(unsigned long index) -{ - m_context->enableVertexAttribArray(index); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::finish() -{ - m_context->finish(); - cleanupAfterGraphicsCall(true); -} - - -void CanvasRenderingContext3D::flush() -{ - m_context->flush(); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, CanvasRenderbuffer* buffer) -{ - if (!buffer) - return; - - m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, CanvasTexture* texture, long level) -{ - if (!texture) - return; - - m_context->framebufferTexture2D(target, attachment, textarget, texture, level); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::frontFace(unsigned long mode) -{ - m_context->frontFace(mode); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::generateMipmap(unsigned long target) -{ - m_context->generateMipmap(target); - cleanupAfterGraphicsCall(false); -} - -PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveAttrib(CanvasProgram* program, unsigned long index, ExceptionCode& ec) -{ - ActiveInfo info; - if (!program || program->context() != this || !m_context->getActiveAttrib(program, index, info)) { - ec = INDEX_SIZE_ERR; - return 0; - } - return CanvasActiveInfo::create(info.name, info.type, info.size); -} - -PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveUniform(CanvasProgram* program, unsigned long index, ExceptionCode& ec) -{ - ActiveInfo info; - if (!program || program->context() != this || !m_context->getActiveUniform(program, index, info)) { - ec = INDEX_SIZE_ERR; - return 0; - } - return CanvasActiveInfo::create(info.name, info.type, info.size); -} - -int CanvasRenderingContext3D::getAttribLocation(CanvasProgram* program, const String& name) -{ - return m_context->getAttribLocation(program, name); -} - -bool CanvasRenderingContext3D::getBoolean(unsigned long pname) -{ - bool result = m_context->getBoolean(pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasUnsignedByteArray> CanvasRenderingContext3D::getBooleanv(unsigned long pname) -{ - RefPtr<CanvasUnsignedByteArray> array = m_context->getBooleanv(pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getBufferParameteri(unsigned long target, unsigned long pname) -{ - int result = m_context->getBufferParameteri(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getBufferParameteriv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getBufferParameteriv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -unsigned long CanvasRenderingContext3D::getError() -{ - return m_context->getError(); -} - -float CanvasRenderingContext3D::getFloat(unsigned long pname) -{ - float result = m_context->getFloat(pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getFloatv(unsigned long pname) -{ - RefPtr<CanvasFloatArray> array = m_context->getFloatv(pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getFramebufferAttachmentParameteri(unsigned long target, unsigned long attachment, unsigned long pname) -{ - int result = m_context->getFramebufferAttachmentParameteri(target, attachment, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getFramebufferAttachmentParameteriv(target, attachment, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getInteger(unsigned long pname) -{ - float result = m_context->getInteger(pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getIntegerv(unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getIntegerv(pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getProgrami(CanvasProgram* program, unsigned long pname) -{ - int result = m_context->getProgrami(program, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getProgramiv(CanvasProgram* program, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getProgramiv(program, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -String CanvasRenderingContext3D::getProgramInfoLog(CanvasProgram* program) -{ - String s = m_context->getProgramInfoLog(program); - cleanupAfterGraphicsCall(false); - return s; -} - -int CanvasRenderingContext3D::getRenderbufferParameteri(unsigned long target, unsigned long pname) -{ - int result = m_context->getRenderbufferParameteri(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getRenderbufferParameteriv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getShaderi(CanvasShader* shader, unsigned long pname) -{ - int result = m_context->getShaderi(shader, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getShaderiv(CanvasShader* shader, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getShaderiv(shader, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -String CanvasRenderingContext3D::getShaderInfoLog(CanvasShader* shader) -{ - String s = m_context->getShaderInfoLog(shader); - cleanupAfterGraphicsCall(false); - return s; -} - -String CanvasRenderingContext3D::getShaderSource(CanvasShader* shader) -{ - String s = m_context->getShaderSource(shader); - cleanupAfterGraphicsCall(false); - return s; -} - -String CanvasRenderingContext3D::getString(unsigned long name) -{ - return m_context->getString(name); -} - -float CanvasRenderingContext3D::getTexParameterf(unsigned long target, unsigned long pname) -{ - float result = m_context->getTexParameterf(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getTexParameterfv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasFloatArray> array = m_context->getTexParameterfv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getTexParameteri(unsigned long target, unsigned long pname) -{ - int result = m_context->getTexParameteri(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getTexParameteriv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getTexParameteriv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -float CanvasRenderingContext3D::getUniformf(CanvasProgram* program, long location) -{ - float result = m_context->getUniformf(program, location); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getUniformfv(CanvasProgram* program, long location) -{ - RefPtr<CanvasFloatArray> array = m_context->getUniformfv(program, location); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getUniformi(CanvasProgram* program, long location) -{ - long result = m_context->getUniformi(program, location); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getUniformiv(CanvasProgram* program, long location) -{ - RefPtr<CanvasIntArray> array = m_context->getUniformiv(program, location); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getUniformLocation(CanvasProgram* program, const String& name) -{ - return m_context->getUniformLocation(program, name); -} - -float CanvasRenderingContext3D::getVertexAttribf(unsigned long index, unsigned long pname) -{ - float result = m_context->getVertexAttribf(index, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getVertexAttribfv(unsigned long index, unsigned long pname) -{ - RefPtr<CanvasFloatArray> array = m_context->getVertexAttribfv(index, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getVertexAttribi(unsigned long index, unsigned long pname) -{ - long result = m_context->getVertexAttribi(index, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getVertexAttribiv(unsigned long index, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getVertexAttribiv(index, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname) -{ - long result = m_context->getVertexAttribOffset(index, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -void CanvasRenderingContext3D::hint(unsigned long target, unsigned long mode) -{ - m_context->hint(target, mode); - cleanupAfterGraphicsCall(false); -} - -bool CanvasRenderingContext3D::isBuffer(CanvasBuffer* buffer) -{ - if (!buffer) - return false; - - return m_context->isBuffer(buffer); -} - -bool CanvasRenderingContext3D::isEnabled(unsigned long cap) -{ - return m_context->isEnabled(cap); -} - -bool CanvasRenderingContext3D::isFramebuffer(CanvasFramebuffer* framebuffer) -{ - return m_context->isFramebuffer(framebuffer); -} - -bool CanvasRenderingContext3D::isProgram(CanvasProgram* program) -{ - return m_context->isProgram(program); -} - -bool CanvasRenderingContext3D::isRenderbuffer(CanvasRenderbuffer* renderbuffer) -{ - return m_context->isRenderbuffer(renderbuffer); -} - -bool CanvasRenderingContext3D::isShader(CanvasShader* shader) -{ - return m_context->isShader(shader); -} - -bool CanvasRenderingContext3D::isTexture(CanvasTexture* texture) -{ - return m_context->isTexture(texture); -} - -void CanvasRenderingContext3D::lineWidth(double width) -{ - m_context->lineWidth((float) width); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::linkProgram(CanvasProgram* program) -{ - if (!program) - return; - - m_context->linkProgram(program); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::pixelStorei(unsigned long pname, long param) -{ - m_context->pixelStorei(pname, param); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::polygonOffset(double factor, double units) -{ - m_context->polygonOffset((float) factor, (float) units); - cleanupAfterGraphicsCall(false); -} - -PassRefPtr<CanvasArray> CanvasRenderingContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type) -{ - RefPtr<CanvasArray> array = m_context->readPixels(x, y, width, height, format, type); - cleanupAfterGraphicsCall(false); - return array; -} - -void CanvasRenderingContext3D::releaseShaderCompiler() -{ - m_context->releaseShaderCompiler(); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height) -{ - m_context->renderbufferStorage(target, internalformat, width, height); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::sampleCoverage(double value, bool invert) -{ - m_context->sampleCoverage((float) value, invert); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::scissor(long x, long y, unsigned long width, unsigned long height) -{ - m_context->scissor(x, y, width, height); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::shaderSource(CanvasShader* shader, const String& string) -{ - m_context->shaderSource(shader, string); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask) -{ - m_context->stencilFunc(func, ref, mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask) -{ - m_context->stencilFuncSeparate(face, func, ref, mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilMask(unsigned long mask) -{ - m_context->stencilMask(mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask) -{ - m_context->stencilMaskSeparate(face, mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass) -{ - m_context->stencilOp(fail, zfail, zpass); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass) -{ - m_context->stencilOpSeparate(face, fail, zfail, zpass); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, internalformat, width, height, - border, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, internalformat, width, height, - border, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, image, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, canvas, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, video, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texParameterf(unsigned target, unsigned pname, float param) -{ - m_context->texParameterf(target, pname, param); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texParameteri(unsigned target, unsigned pname, int param) -{ - m_context->texParameteri(target, pname, param); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, image, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, canvas, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1f(long location, float x) -{ - m_context->uniform1f(location, x); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1fv(location, v->data(), v->length()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1fv(location, v, size); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1i(long location, int x) -{ - m_context->uniform1i(location, x); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1iv(location, v->data(), v->length()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1iv(location, v, size); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2f(long location, float x, float y) -{ - m_context->uniform2f(location, x, y); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2fv(location, v->data(), v->length() / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2fv(location, v, size / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2i(long location, int x, int y) -{ - m_context->uniform2i(location, x, y); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2iv(location, v->data(), v->length() / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2iv(location, v, size / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3f(long location, float x, float y, float z) -{ - m_context->uniform3f(location, x, y, z); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3fv(location, v->data(), v->length() / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3fv(location, v, size / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3i(long location, int x, int y, int z) -{ - m_context->uniform3i(location, x, y, z); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3iv(location, v->data(), v->length() / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3iv(location, v, size / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4f(long location, float x, float y, float z, float w) -{ - m_context->uniform4f(location, x, y, z, w); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4fv(location, v->data(), v->length() / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4fv(location, v, size / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4i(long location, int x, int y, int z, int w) -{ - m_context->uniform4i(location, x, y, z, w); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4iv(location, v->data(), v->length() / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4iv(location, v, size / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix2fv(long location, bool transpose, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniformMatrix2fv(location, transpose, v->data(), v->length() / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix2fv(long location, bool transpose, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniformMatrix2fv(location, transpose, v, size / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix3fv(long location, bool transpose, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 9 - m_context->uniformMatrix3fv(location, transpose, v->data(), v->length() / 9); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix3fv(long location, bool transpose, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 9 - m_context->uniformMatrix3fv(location, transpose, v, size / 9); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix4fv(long location, bool transpose, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 16 - m_context->uniformMatrix4fv(location, transpose, v->data(), v->length() / 16); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix4fv(long location, bool transpose, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 16 - m_context->uniformMatrix4fv(location, transpose, v, size / 16); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::useProgram(CanvasProgram* program) -{ - m_context->useProgram(program); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::validateProgram(CanvasProgram* program) -{ - m_context->validateProgram(program); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib1f(unsigned long indx, float v0) -{ - m_context->vertexAttrib1f(indx, v0); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib1fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib1fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib1fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib1fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1) -{ - m_context->vertexAttrib2f(indx, v0, v1); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib2fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib2fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib2fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib2fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2) -{ - m_context->vertexAttrib3f(indx, v0, v1, v2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib3fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib3fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib3fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib3fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3) -{ - m_context->vertexAttrib4f(indx, v0, v1, v2, v3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib4fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib4fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib4fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib4fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, unsigned long stride, unsigned long offset) -{ - m_context->vertexAttribPointer(indx, size, type, normalized, stride, offset); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::viewport(long x, long y, unsigned long width, unsigned long height) -{ - if (isnan(x)) - x = 0; - if (isnan(y)) - y = 0; - if (isnan(width)) - width = 100; - if (isnan(height)) - height = 100; - m_context->viewport(x, y, width, height); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::removeObject(CanvasObject* object) -{ - m_canvasObjects.remove(object); -} - -void CanvasRenderingContext3D::addObject(CanvasObject* object) -{ - removeObject(object); - m_canvasObjects.add(object); -} - -void CanvasRenderingContext3D::detachAndRemoveAllObjects() -{ - HashSet<CanvasObject*>::iterator pend = m_canvasObjects.end(); - for (HashSet<CanvasObject*>::iterator it = m_canvasObjects.begin(); it != pend; ++it) - (*it)->detachContext(); - - m_canvasObjects.clear(); -} - -} // namespace WebCore - -#endif // ENABLE(3D_CANVAS) - diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.h b/WebCore/html/canvas/CanvasRenderingContext3D.h deleted file mode 100644 index 70d9b95..0000000 --- a/WebCore/html/canvas/CanvasRenderingContext3D.h +++ /dev/null @@ -1,327 +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 CanvasRenderingContext3D_h -#define CanvasRenderingContext3D_h - -#include "CanvasRenderingContext.h" -#include "ExceptionCode.h" -#include "CanvasFloatArray.h" -#include "CanvasIntArray.h" -#include "CanvasUnsignedByteArray.h" -#include "GraphicsContext3D.h" -#include "PlatformString.h" - -namespace WebCore { - -class CanvasActiveInfo; -class CanvasBuffer; -class CanvasFramebuffer; -class CanvasObject; -class CanvasProgram; -class CanvasRenderbuffer; -class CanvasShader; -class CanvasTexture; -class HTMLImageElement; -class HTMLVideoElement; -class ImageData; -class WebKitCSSMatrix; - - class CanvasRenderingContext3D : public CanvasRenderingContext { - public: - static PassOwnPtr<CanvasRenderingContext3D> create(HTMLCanvasElement*); - virtual ~CanvasRenderingContext3D(); - - virtual bool is3d() const { return true; } - - // Helper to return the size in bytes of OpenGL data types - // like GL_FLOAT, GL_INT, etc. - int sizeInBytes(int type, ExceptionCode& ec); - - void activeTexture(unsigned long texture); - void attachShader(CanvasProgram*, CanvasShader*); - void bindAttribLocation(CanvasProgram*, unsigned long index, const String& name); - void bindBuffer(unsigned long target, CanvasBuffer*); - void bindFramebuffer(unsigned long target, CanvasFramebuffer*); - void bindRenderbuffer(unsigned long target, CanvasRenderbuffer*); - void bindTexture(unsigned long target, CanvasTexture*); - void blendColor(double red, double green, double blue, double alpha); - void blendEquation(unsigned long mode); - void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha); - void blendFunc(unsigned long sfactor, unsigned long dfactor); - void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha); - - void bufferData(unsigned long target, int size, unsigned long usage); - void bufferData(unsigned long target, CanvasArray* data, unsigned long usage); - void bufferSubData(unsigned long target, long offset, CanvasArray* data); - - unsigned long checkFramebufferStatus(unsigned long target); - void clear(unsigned long mask); - void clearColor(double red, double green, double blue, double alpha); - void clearDepth(double); - void clearStencil(long); - void colorMask(bool red, bool green, bool blue, bool alpha); - void compileShader(CanvasShader*); - - //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data); - //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data); - - void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border); - void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height); - - PassRefPtr<CanvasBuffer> createBuffer(); - PassRefPtr<CanvasFramebuffer> createFramebuffer(); - PassRefPtr<CanvasProgram> createProgram(); - PassRefPtr<CanvasRenderbuffer> createRenderbuffer(); - PassRefPtr<CanvasShader> createShader(unsigned long type); - PassRefPtr<CanvasTexture> createTexture(); - - void cullFace(unsigned long mode); - - void deleteBuffer(CanvasBuffer*); - void deleteFramebuffer(CanvasFramebuffer*); - void deleteProgram(CanvasProgram*); - void deleteRenderbuffer(CanvasRenderbuffer*); - void deleteShader(CanvasShader*); - void deleteTexture(CanvasTexture*); - - void depthFunc(unsigned long); - void depthMask(bool); - void depthRange(double zNear, double zFar); - void detachShader(CanvasProgram*, CanvasShader*); - void disable(unsigned long cap); - void disableVertexAttribArray(unsigned long index); - void drawArrays(unsigned long mode, long first, long count); - void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset); - - void enable(unsigned long cap); - void enableVertexAttribArray(unsigned long index); - void finish(); - void flush(); - void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, CanvasRenderbuffer*); - void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, CanvasTexture*, long level); - void frontFace(unsigned long mode); - void generateMipmap(unsigned long target); - - PassRefPtr<CanvasActiveInfo> getActiveAttrib(CanvasProgram*, unsigned long index, ExceptionCode&); - PassRefPtr<CanvasActiveInfo> getActiveUniform(CanvasProgram*, unsigned long index, ExceptionCode&); - - int getAttribLocation(CanvasProgram*, const String& name); - - bool getBoolean(unsigned long pname); - PassRefPtr<CanvasUnsignedByteArray> getBooleanv(unsigned long pname); - int getBufferParameteri(unsigned long target, unsigned long pname); - PassRefPtr<CanvasIntArray> getBufferParameteriv(unsigned long target, unsigned long pname); - - unsigned long getError(); - - float getFloat(unsigned long pname); - PassRefPtr<CanvasFloatArray> getFloatv(unsigned long pname); - int getFramebufferAttachmentParameteri(unsigned long target, unsigned long attachment, unsigned long pname); - PassRefPtr<CanvasIntArray> getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname); - int getInteger(unsigned long pname); - PassRefPtr<CanvasIntArray> getIntegerv(unsigned long pname); - int getProgrami(CanvasProgram*, unsigned long pname); - PassRefPtr<CanvasIntArray> getProgramiv(CanvasProgram*, unsigned long pname); - String getProgramInfoLog(CanvasProgram*); - int getRenderbufferParameteri(unsigned long target, unsigned long pname); - PassRefPtr<CanvasIntArray> getRenderbufferParameteriv(unsigned long target, unsigned long pname); - int getShaderi(CanvasShader*, unsigned long pname); - PassRefPtr<CanvasIntArray> getShaderiv(CanvasShader*, unsigned long pname); - - String getShaderInfoLog(CanvasShader*); - - // TBD - // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); - - String getShaderSource(CanvasShader*); - String getString(unsigned long name); - - float getTexParameterf(unsigned long target, unsigned long pname); - PassRefPtr<CanvasFloatArray> getTexParameterfv(unsigned long target, unsigned long pname); - int getTexParameteri(unsigned long target, unsigned long pname); - PassRefPtr<CanvasIntArray> getTexParameteriv(unsigned long target, unsigned long pname); - - float getUniformf(CanvasProgram* program, long location); - PassRefPtr<CanvasFloatArray> getUniformfv(CanvasProgram* program, long location); - long getUniformi(CanvasProgram* program, long location); - PassRefPtr<CanvasIntArray> getUniformiv(CanvasProgram* program, long location); - - long getUniformLocation(CanvasProgram*, const String& name); - - float getVertexAttribf(unsigned long index, unsigned long pname); - PassRefPtr<CanvasFloatArray> getVertexAttribfv(unsigned long index, unsigned long pname); - long getVertexAttribi(unsigned long index, unsigned long pname); - PassRefPtr<CanvasIntArray> getVertexAttribiv(unsigned long index, unsigned long pname); - - long getVertexAttribOffset(unsigned long index, unsigned long pname); - - void hint(unsigned long target, unsigned long mode); - bool isBuffer(CanvasBuffer*); - bool isEnabled(unsigned long cap); - bool isFramebuffer(CanvasFramebuffer*); - bool isProgram(CanvasProgram*); - bool isRenderbuffer(CanvasRenderbuffer*); - bool isShader(CanvasShader*); - bool isTexture(CanvasTexture*); - void lineWidth(double); - void linkProgram(CanvasProgram*); - void pixelStorei(unsigned long pname, long param); - void polygonOffset(double factor, double units); - - PassRefPtr<CanvasArray> 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); - void sampleCoverage(double value, bool invert); - void scissor(long x, long y, unsigned long width, unsigned long height); - void shaderSource(CanvasShader*, const String&); - void stencilFunc(unsigned long func, long ref, unsigned long mask); - void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask); - void stencilMask(unsigned long); - void stencilMaskSeparate(unsigned long face, unsigned long mask); - void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass); - void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass); - - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - - void texParameterf(unsigned target, unsigned pname, float param); - void texParameteri(unsigned target, unsigned pname, int param); - - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - - void uniform1f(long location, float x); - void uniform1fv(long location, CanvasFloatArray* v); - void uniform1fv(long location, float* v, int size); - void uniform1i(long location, int x); - void uniform1iv(long location, CanvasIntArray* v); - void uniform1iv(long location, int* v, int size); - void uniform2f(long location, float x, float y); - void uniform2fv(long location, CanvasFloatArray* v); - void uniform2fv(long location, float* v, int size); - void uniform2i(long location, int x, int y); - void uniform2iv(long location, CanvasIntArray* v); - void uniform2iv(long location, int* v, int size); - void uniform3f(long location, float x, float y, float z); - void uniform3fv(long location, CanvasFloatArray* v); - void uniform3fv(long location, float* v, int size); - void uniform3i(long location, int x, int y, int z); - void uniform3iv(long location, CanvasIntArray* v); - void uniform3iv(long location, int* v, int size); - void uniform4f(long location, float x, float y, float z, float w); - void uniform4fv(long location, CanvasFloatArray* v); - void uniform4fv(long location, float* v, int size); - void uniform4i(long location, int x, int y, int z, int w); - void uniform4iv(long location, CanvasIntArray* v); - void uniform4iv(long location, int* v, int size); - void uniformMatrix2fv(long location, bool transpose, CanvasFloatArray* value); - void uniformMatrix2fv(long location, bool transpose, float* value, int size); - void uniformMatrix3fv(long location, bool transpose, CanvasFloatArray* value); - void uniformMatrix3fv(long location, bool transpose, float* value, int size); - void uniformMatrix4fv(long location, bool transpose, CanvasFloatArray* value); - void uniformMatrix4fv(long location, bool transpose, float* value, int size); - - void useProgram(CanvasProgram*); - void validateProgram(CanvasProgram*); - - void vertexAttrib1f(unsigned long indx, float x); - void vertexAttrib1fv(unsigned long indx, CanvasFloatArray* values); - void vertexAttrib1fv(unsigned long indx, float* values, int size); - void vertexAttrib2f(unsigned long indx, float x, float y); - void vertexAttrib2fv(unsigned long indx, CanvasFloatArray* 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, CanvasFloatArray* 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, CanvasFloatArray* 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); - - void viewport(long x, long y, unsigned long width, unsigned long height); - - GraphicsContext3D* graphicsContext3D() const { return m_context.get(); } - - void reshape(int width, int height); - - // Helpers for notification about paint events. - void beginPaint(); - void endPaint(); - - void removeObject(CanvasObject*); - - private: - friend class CanvasObject; - - CanvasRenderingContext3D(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>); - - void addObject(CanvasObject*); - void detachAndRemoveAllObjects(); - - void markContextChanged(); - void cleanupAfterGraphicsCall(bool changed) - { - m_context->checkError(); - if (changed) - markContextChanged(); - } - - OwnPtr<GraphicsContext3D> m_context; - bool m_needsUpdate; - bool m_markedCanvasDirty; - // FIXME: I think this is broken -- it does not increment any - // reference counts, so may refer to destroyed objects. - HashSet<CanvasObject*> m_canvasObjects; - }; - -} // namespace WebCore - -#endif diff --git a/WebCore/html/canvas/CanvasShortArray.cpp b/WebCore/html/canvas/CanvasShortArray.cpp deleted file mode 100644 index d0cf135..0000000 --- a/WebCore/html/canvas/CanvasShortArray.cpp +++ /dev/null @@ -1,82 +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 "CanvasArrayBuffer.h" -#include "CanvasShortArray.h" - -namespace WebCore { - - PassRefPtr<CanvasShortArray> CanvasShortArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(short)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasShortArray> CanvasShortArray::create(short* array, unsigned length) - { - RefPtr<CanvasShortArray> a = CanvasShortArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasShortArray> CanvasShortArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(short)) != 0) - return NULL; - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(short))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasShortArray(buffer, offset, length)); - } - - CanvasShortArray::CanvasShortArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasShortArray::length() const { - return m_size; - } - - unsigned CanvasShortArray::sizeInBytes() const { - return length() * sizeof(short); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasShortArray.h b/WebCore/html/canvas/CanvasShortArray.h deleted file mode 100644 index 1eeef0c..0000000 --- a/WebCore/html/canvas/CanvasShortArray.h +++ /dev/null @@ -1,86 +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 CanvasShortArray_h -#define CanvasShortArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasShortArray : public CanvasArray { - public: - virtual bool isShortArray() const { return true; } - - static PassRefPtr<CanvasShortArray> create(unsigned length); - static PassRefPtr<CanvasShortArray> create(short* array, unsigned length); - static PassRefPtr<CanvasShortArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - short* data() { return static_cast<short*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - 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 item(unsigned index) const - { - ASSERT(index < m_size); - short* storage = static_cast<short*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasShortArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasShortArray_h diff --git a/WebCore/html/canvas/CanvasStyle.cpp b/WebCore/html/canvas/CanvasStyle.cpp index 946cac7..5352473 100644 --- a/WebCore/html/canvas/CanvasStyle.cpp +++ b/WebCore/html/canvas/CanvasStyle.cpp @@ -114,33 +114,33 @@ void CanvasStyle::applyStrokeColor(GraphicsContext* context) case ColorString: { Color c = Color(m_color); if (c.isValid()) { - context->setStrokeColor(c.rgb()); + context->setStrokeColor(c.rgb(), DeviceColorSpace); break; } RGBA32 color = 0; // default is transparent black if (CSSParser::parseColor(color, m_color)) - context->setStrokeColor(color); + context->setStrokeColor(color, DeviceColorSpace); break; } case ColorStringWithAlpha: { Color c = Color(m_color); if (c.isValid()) { - context->setStrokeColor(colorWithOverrideAlpha(c.rgb(), m_alpha)); + context->setStrokeColor(colorWithOverrideAlpha(c.rgb(), m_alpha), DeviceColorSpace); break; } RGBA32 color = 0; // default is transparent black if (CSSParser::parseColor(color, m_color)) - context->setStrokeColor(colorWithOverrideAlpha(color, m_alpha)); + context->setStrokeColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); break; } case GrayLevel: // We're only supporting 255 levels of gray here. Since this isn't // even part of HTML5, I don't expect anyone will care. If they do // we'll make a fancier Color abstraction. - context->setStrokeColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha)); + context->setStrokeColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); break; case RGBA: - context->setStrokeColor(Color(m_red, m_green, m_blue, m_alpha)); + context->setStrokeColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); break; case CMYKA: { // FIXME: Do this through platform-independent GraphicsContext API. @@ -154,7 +154,7 @@ void CanvasStyle::applyStrokeColor(GraphicsContext* context) currentPen.setColor(clr); context->platformContext()->setPen(currentPen); #else - context->setStrokeColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha)); + context->setStrokeColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace); #endif break; } @@ -175,33 +175,33 @@ void CanvasStyle::applyFillColor(GraphicsContext* context) case ColorString: { Color c = Color(m_color); if (c.isValid()) { - context->setFillColor(c.rgb()); + context->setFillColor(c.rgb(), DeviceColorSpace); break; } RGBA32 rgba = 0; // default is transparent black if (CSSParser::parseColor(rgba, m_color)) - context->setFillColor(rgba); + context->setFillColor(rgba, DeviceColorSpace); break; } case ColorStringWithAlpha: { Color c = Color(m_color); if (c.isValid()) { - context->setFillColor(colorWithOverrideAlpha(c.rgb(), m_alpha)); + context->setFillColor(colorWithOverrideAlpha(c.rgb(), m_alpha), DeviceColorSpace); break; } RGBA32 color = 0; // default is transparent black if (CSSParser::parseColor(color, m_color)) - context->setFillColor(colorWithOverrideAlpha(color, m_alpha)); + context->setFillColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); break; } case GrayLevel: // We're only supporting 255 levels of gray here. Since this isn't // even part of HTML5, I don't expect anyone will care. If they do // we'll make a fancier Color abstraction. - context->setFillColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha)); + context->setFillColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); break; case RGBA: - context->setFillColor(Color(m_red, m_green, m_blue, m_alpha)); + context->setFillColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); break; case CMYKA: { // FIXME: Do this through platform-independent GraphicsContext API. @@ -215,7 +215,7 @@ void CanvasStyle::applyFillColor(GraphicsContext* context) currentBrush.setColor(clr); context->platformContext()->setBrush(currentBrush); #else - context->setFillColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha)); + context->setFillColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace); #endif break; } diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.cpp b/WebCore/html/canvas/CanvasUnsignedByteArray.cpp deleted file mode 100644 index a75066c..0000000 --- a/WebCore/html/canvas/CanvasUnsignedByteArray.cpp +++ /dev/null @@ -1,78 +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 "CanvasArrayBuffer.h" -#include "CanvasUnsignedByteArray.h" - -namespace WebCore { - - PassRefPtr<CanvasUnsignedByteArray> CanvasUnsignedByteArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(unsigned char)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasUnsignedByteArray> CanvasUnsignedByteArray::create(unsigned char* array, unsigned length) - { - RefPtr<CanvasUnsignedByteArray> a = CanvasUnsignedByteArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasUnsignedByteArray> CanvasUnsignedByteArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(unsigned char))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasUnsignedByteArray(buffer, offset, length)); - } - - CanvasUnsignedByteArray::CanvasUnsignedByteArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasUnsignedByteArray::length() const { - return m_size; - } - - unsigned CanvasUnsignedByteArray::sizeInBytes() const { - return length() * sizeof(unsigned char); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.h b/WebCore/html/canvas/CanvasUnsignedByteArray.h deleted file mode 100644 index d8864e0..0000000 --- a/WebCore/html/canvas/CanvasUnsignedByteArray.h +++ /dev/null @@ -1,86 +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 CanvasUnsignedByteArray_h -#define CanvasUnsignedByteArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasUnsignedByteArray : public CanvasArray { - public: - virtual bool isUnsignedByteArray() const { return true; } - - static PassRefPtr<CanvasUnsignedByteArray> create(unsigned length); - static PassRefPtr<CanvasUnsignedByteArray> create(unsigned char* array, unsigned length); - static PassRefPtr<CanvasUnsignedByteArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - 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 item(unsigned index) const - { - ASSERT(index < m_size); - unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasUnsignedByteArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasUnsignedByteArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.cpp b/WebCore/html/canvas/CanvasUnsignedIntArray.cpp deleted file mode 100644 index bd26343..0000000 --- a/WebCore/html/canvas/CanvasUnsignedIntArray.cpp +++ /dev/null @@ -1,83 +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 "CanvasArrayBuffer.h" -#include "CanvasUnsignedIntArray.h" - -namespace WebCore { - - PassRefPtr<CanvasUnsignedIntArray> CanvasUnsignedIntArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(unsigned int)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasUnsignedIntArray> CanvasUnsignedIntArray::create(unsigned int* array, unsigned length) - { - RefPtr<CanvasUnsignedIntArray> a = CanvasUnsignedIntArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasUnsignedIntArray> CanvasUnsignedIntArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(unsigned int)) != 0) { - return NULL; - } - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(unsigned int))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasUnsignedIntArray(buffer, offset, length)); - } - - CanvasUnsignedIntArray::CanvasUnsignedIntArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasUnsignedIntArray::length() const { - return m_size; - } - - unsigned CanvasUnsignedIntArray::sizeInBytes() const { - return length() * sizeof(unsigned int); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.h b/WebCore/html/canvas/CanvasUnsignedIntArray.h deleted file mode 100644 index 10b8edf..0000000 --- a/WebCore/html/canvas/CanvasUnsignedIntArray.h +++ /dev/null @@ -1,86 +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 CanvasUnsignedIntArray_h -#define CanvasUnsignedIntArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasUnsignedIntArray : public CanvasArray { - public: - virtual bool isUnsignedIntArray() const { return true; } - - static PassRefPtr<CanvasUnsignedIntArray> create(unsigned length); - static PassRefPtr<CanvasUnsignedIntArray> create(unsigned int* array, unsigned length); - static PassRefPtr<CanvasUnsignedIntArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - 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 item(unsigned index) const - { - ASSERT(index < m_size); - unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasUnsignedIntArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasUnsignedIntArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.cpp b/WebCore/html/canvas/CanvasUnsignedShortArray.cpp deleted file mode 100644 index 45d827b..0000000 --- a/WebCore/html/canvas/CanvasUnsignedShortArray.cpp +++ /dev/null @@ -1,85 +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 "CanvasArrayBuffer.h" -#include "CanvasUnsignedShortArray.h" - -namespace WebCore { - - PassRefPtr<CanvasUnsignedShortArray> CanvasUnsignedShortArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(unsigned short)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasUnsignedShortArray> CanvasUnsignedShortArray::create(unsigned short* array, unsigned length) - { - RefPtr<CanvasUnsignedShortArray> a = CanvasUnsignedShortArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasUnsignedShortArray> CanvasUnsignedShortArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(unsigned short)) != 0) { - return NULL; - } - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(unsigned short))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasUnsignedShortArray(buffer, offset, length)); - } - - CanvasUnsignedShortArray::CanvasUnsignedShortArray(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasUnsignedShortArray::length() const { - return m_size; - } - - unsigned CanvasUnsignedShortArray::sizeInBytes() const { - return length() * sizeof(unsigned short); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.h b/WebCore/html/canvas/CanvasUnsignedShortArray.h deleted file mode 100644 index 9e27566..0000000 --- a/WebCore/html/canvas/CanvasUnsignedShortArray.h +++ /dev/null @@ -1,87 +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 CanvasUnsignedShortArray_h -#define CanvasUnsignedShortArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasUnsignedShortArray : public CanvasArray { - public: - virtual bool isUnsignedShortArray() const { return true; } - - static PassRefPtr<CanvasUnsignedShortArray> create(unsigned length); - static PassRefPtr<CanvasUnsignedShortArray> create(unsigned short* array, unsigned length); - static PassRefPtr<CanvasUnsignedShortArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - 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 item(unsigned index) const - { - ASSERT(index < m_size); - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasUnsignedShortArray(PassRefPtr<CanvasArrayBuffer> buffer,int offset,unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasUnsignedShortArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.idl b/WebCore/html/canvas/CanvasUnsignedShortArray.idl deleted file mode 100644 index 99fc6a2..0000000 --- a/WebCore/html/canvas/CanvasUnsignedShortArray.idl +++ /dev/null @@ -1,36 +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. - */ - -module html { - interface [ - Conditional=3D_CANVAS, - HasNumericIndexGetter, - HasCustomIndexSetter, - GenerateNativeConverter, - GenerateCustomConstructor, - CustomToJS - ] CanvasUnsignedShortArray : CanvasArray { - }; -} diff --git a/WebCore/html/canvas/CanvasActiveInfo.h b/WebCore/html/canvas/WebGLActiveInfo.h index b04b0d0..4650ea1 100644 --- a/WebCore/html/canvas/CanvasActiveInfo.h +++ b/WebCore/html/canvas/WebGLActiveInfo.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasActiveInfo_h -#define CanvasActiveInfo_h +#ifndef WebGLActiveInfo_h +#define WebGLActiveInfo_h #include "PlatformString.h" #include <wtf/PassRefPtr.h> @@ -32,18 +32,18 @@ namespace WebCore { -class CanvasActiveInfo : public RefCounted<CanvasActiveInfo> { +class WebGLActiveInfo : public RefCounted<WebGLActiveInfo> { public: - static PassRefPtr<CanvasActiveInfo> create(const String& name, unsigned type, int size) + static PassRefPtr<WebGLActiveInfo> create(const String& name, unsigned type, int size) { - return adoptRef(new CanvasActiveInfo(name, type, size)); + return adoptRef(new WebGLActiveInfo(name, type, size)); } String name() const { return m_name; } unsigned type() const { return m_type; } int size() const { return m_size; } private: - CanvasActiveInfo(const String& name, unsigned type, int size) + WebGLActiveInfo(const String& name, unsigned type, int size) : m_name(name) , m_type(type) , m_size(size) @@ -59,4 +59,4 @@ private: } -#endif // CanvasActiveInfo_h +#endif // WebGLActiveInfo_h diff --git a/WebCore/html/canvas/CanvasActiveInfo.idl b/WebCore/html/canvas/WebGLActiveInfo.idl index 6ceae29..a3f79b8 100644 --- a/WebCore/html/canvas/CanvasActiveInfo.idl +++ b/WebCore/html/canvas/WebGLActiveInfo.idl @@ -27,7 +27,7 @@ module html { interface [ Conditional=3D_CANVAS, - ] CanvasActiveInfo { + ] WebGLActiveInfo { readonly attribute int size; readonly attribute unsigned int type; readonly attribute DOMString name; diff --git a/WebCore/html/canvas/CanvasArray.cpp b/WebCore/html/canvas/WebGLArray.cpp index 6b5688a..c5a712d 100644 --- a/WebCore/html/canvas/CanvasArray.cpp +++ b/WebCore/html/canvas/WebGLArray.cpp @@ -27,26 +27,34 @@ #if ENABLE(3D_CANVAS) -#include "CanvasArray.h" -#include "CanvasArrayBuffer.h" +#include "WebGLArray.h" +#include "WebGLArrayBuffer.h" namespace WebCore { - CanvasArray::CanvasArray(PassRefPtr<CanvasArrayBuffer> buffer, - unsigned offset) - : m_offset(offset) + +WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, + unsigned byteOffset) + : m_byteOffset(byteOffset) , m_buffer(buffer) - { - m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_offset) : 0; - } +{ + m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_byteOffset) : 0; +} - CanvasArray::~CanvasArray() - { - } +WebGLArray::~WebGLArray() +{ +} - unsigned CanvasArray::alignedSizeInBytes() const { - // Assume we only need to round up to 4-byte boundaries for alignment. - return ((sizeInBytes() + 3) / 4) * 4; +void WebGLArray::setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec) +{ + if (byteOffset + array->byteLength() > byteLength()) { + ec = INDEX_SIZE_ERR; + return; } + + char* base = static_cast<char*>(baseAddress()); + memcpy(base + byteOffset, array->baseAddress(), array->byteLength()); +} + } #endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasArray.h b/WebCore/html/canvas/WebGLArray.h index 8cedbbe..11065cc 100644 --- a/WebCore/html/canvas/CanvasArray.h +++ b/WebCore/html/canvas/WebGLArray.h @@ -23,53 +23,59 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasArray_h -#define CanvasArray_h +#ifndef WebGLArray_h +#define WebGLArray_h +#include "ExceptionCode.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> -#include "CanvasArrayBuffer.h" +#include "WebGLArrayBuffer.h" namespace WebCore { - class CanvasArray : public RefCounted<CanvasArray> { - public: - virtual bool isByteArray() const { return false; } - virtual bool isUnsignedByteArray() const { return false; } - virtual bool isShortArray() const { return false; } - virtual bool isUnsignedShortArray() const { return false; } - virtual bool isIntArray() const { return false; } - virtual bool isUnsignedIntArray() const { return false; } - virtual bool isFloatArray() const { return false; } - - PassRefPtr<CanvasArrayBuffer> buffer() { - return m_buffer; - } - - void* baseAddress() { - return m_baseAddress; - } - - unsigned offset() const { - return m_offset; - } - - virtual unsigned length() const = 0; - virtual unsigned sizeInBytes() const = 0; - virtual unsigned alignedSizeInBytes() const; - virtual ~CanvasArray(); - - protected: - CanvasArray(PassRefPtr<CanvasArrayBuffer> buffer, unsigned offset); - - // This is the address of the CanvasArrayBuffer's storage, plus the offset. - void* m_baseAddress; - unsigned m_offset; - - private: - RefPtr<CanvasArrayBuffer> m_buffer; - }; - + +class WebGLArray : public RefCounted<WebGLArray> { + public: + virtual bool isByteArray() const { return false; } + virtual bool isUnsignedByteArray() const { return false; } + virtual bool isShortArray() const { return false; } + virtual bool isUnsignedShortArray() const { return false; } + virtual bool isIntArray() const { return false; } + virtual bool isUnsignedIntArray() const { return false; } + virtual bool isFloatArray() const { return false; } + + PassRefPtr<WebGLArrayBuffer> buffer() { + return m_buffer; + } + + void* baseAddress() { + return m_baseAddress; + } + + unsigned byteOffset() const { + return m_byteOffset; + } + + virtual unsigned length() const = 0; + virtual unsigned byteLength() const = 0; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length) = 0; + + virtual ~WebGLArray(); + + protected: + WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset); + + void setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec); + + // This is the address of the WebGLArrayBuffer's storage, plus the byte offset. + void* m_baseAddress; + + unsigned m_byteOffset; + + private: + RefPtr<WebGLArrayBuffer> m_buffer; +}; + } // namespace WebCore -#endif // CanvasArray_h +#endif // WebGLArray_h diff --git a/WebCore/html/canvas/CanvasByteArray.idl b/WebCore/html/canvas/WebGLArray.idl index ccf49ad..156ca5b 100644 --- a/WebCore/html/canvas/CanvasByteArray.idl +++ b/WebCore/html/canvas/WebGLArray.idl @@ -24,13 +24,12 @@ */ module html { - interface [ - Conditional=3D_CANVAS, - HasNumericIndexGetter, - HasCustomIndexSetter, - GenerateNativeConverter, - GenerateCustomConstructor, - CustomToJS - ] CanvasByteArray : CanvasArray { + interface [Conditional=3D_CANVAS, CustomToJS] WebGLArray { + readonly attribute WebGLArrayBuffer buffer; + readonly attribute unsigned long byteOffset; + readonly attribute unsigned long byteLength; + readonly attribute unsigned long length; + + WebGLArray slice(in unsigned long offset, in unsigned long length); }; } diff --git a/WebCore/html/canvas/WebGLArrayBuffer.cpp b/WebCore/html/canvas/WebGLArrayBuffer.cpp new file mode 100644 index 0000000..c565691 --- /dev/null +++ b/WebCore/html/canvas/WebGLArrayBuffer.cpp @@ -0,0 +1,71 @@ +/* + * 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 <wtf/RefPtr.h> + +namespace WebCore { + +PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(unsigned sizeInBytes) +{ + return adoptRef(new WebGLArrayBuffer(sizeInBytes)); +} + +PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(WebGLArrayBuffer* other) +{ + RefPtr<WebGLArrayBuffer> buffer = adoptRef(new WebGLArrayBuffer(other->byteLength())); + memcpy(buffer->data(), other->data(), other->byteLength()); + return buffer.release(); +} + +WebGLArrayBuffer::WebGLArrayBuffer(unsigned sizeInBytes) { + m_sizeInBytes = sizeInBytes; + m_data = WTF::fastZeroedMalloc(sizeInBytes); +} + +void* WebGLArrayBuffer::data() { + return m_data; +} + +const void* WebGLArrayBuffer::data() const { + return m_data; +} + +unsigned WebGLArrayBuffer::byteLength() const { + return m_sizeInBytes; +} + +WebGLArrayBuffer::~WebGLArrayBuffer() { + WTF::fastFree(m_data); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasArrayBuffer.h b/WebCore/html/canvas/WebGLArrayBuffer.h index e3ff2b0..a076e16 100644 --- a/WebCore/html/canvas/CanvasArrayBuffer.h +++ b/WebCore/html/canvas/WebGLArrayBuffer.h @@ -23,29 +23,31 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasArrayBuffer_h -#define CanvasArrayBuffer_h +#ifndef WebGLArrayBuffer_h +#define WebGLArrayBuffer_h #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class CanvasArrayBuffer : public RefCounted<CanvasArrayBuffer> { - public: - static PassRefPtr<CanvasArrayBuffer> create(unsigned sizeInBytes); - - void* data(); - unsigned byteLength() const; - - ~CanvasArrayBuffer(); - - private: - CanvasArrayBuffer(unsigned sizeInBytes); - unsigned m_sizeInBytes; - void* m_data; - }; - + +class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> { + public: + static PassRefPtr<WebGLArrayBuffer> create(unsigned sizeInBytes); + static PassRefPtr<WebGLArrayBuffer> create(WebGLArrayBuffer*); + + void* data(); + const void* data() const; + unsigned byteLength() const; + + ~WebGLArrayBuffer(); + + private: + WebGLArrayBuffer(unsigned sizeInBytes); + unsigned m_sizeInBytes; + void* m_data; +}; + } // namespace WebCore -#endif // CanvasArrayBuffer_h +#endif // WebGLArrayBuffer_h diff --git a/WebCore/html/canvas/CanvasArrayBuffer.idl b/WebCore/html/canvas/WebGLArrayBuffer.idl index 5dc0f7f..ec4a67a 100644 --- a/WebCore/html/canvas/CanvasArrayBuffer.idl +++ b/WebCore/html/canvas/WebGLArrayBuffer.idl @@ -24,7 +24,7 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasArrayBuffer { + interface [Conditional=3D_CANVAS] WebGLArrayBuffer { readonly attribute int byteLength; }; } diff --git a/WebCore/html/canvas/WebGLBuffer.cpp b/WebCore/html/canvas/WebGLBuffer.cpp new file mode 100644 index 0000000..cbad6a0 --- /dev/null +++ b/WebCore/html/canvas/WebGLBuffer.cpp @@ -0,0 +1,137 @@ +/* + * 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 "WebGLBuffer.h" +#include "WebGLRenderingContext.h" + +namespace WebCore { + +PassRefPtr<WebGLBuffer> WebGLBuffer::create(WebGLRenderingContext* ctx) +{ + return adoptRef(new WebGLBuffer(ctx)); +} + +PassRefPtr<WebGLBuffer> WebGLBuffer::create(WebGLRenderingContext* ctx, Platform3DObject obj) +{ + return adoptRef(new WebGLBuffer(ctx, obj)); +} + +WebGLBuffer::WebGLBuffer(WebGLRenderingContext* ctx) + : CanvasObject(ctx) + , m_elementArrayBufferByteLength(0) + , m_arrayBufferByteLength(0) + , m_elementArrayBufferCloned(false) +{ + setObject(context()->graphicsContext3D()->createBuffer()); +} + +WebGLBuffer::WebGLBuffer(WebGLRenderingContext* ctx, Platform3DObject obj) + : CanvasObject(ctx) +{ + setObject(obj, false); +} + +void WebGLBuffer::_deleteObject(Platform3DObject object) +{ + context()->graphicsContext3D()->deleteBuffer(object); +} + +bool WebGLBuffer::associateBufferData(unsigned long target, int size) +{ + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + m_elementArrayBufferByteLength = size; + return true; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) { + m_arrayBufferByteLength = size; + return true; + } + + return false; +} + +bool WebGLBuffer::associateBufferData(unsigned long target, WebGLArray* array) +{ + if (!array) + return false; + + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + m_elementArrayBufferByteLength = array->byteLength(); + m_elementArrayBuffer = array->buffer(); + m_elementArrayBufferCloned = false; + return true; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) { + m_arrayBufferByteLength = array->byteLength(); + return true; + } + + return false; +} + +bool WebGLBuffer::associateBufferSubData(unsigned long target, long offset, WebGLArray* array) +{ + if (!array) + return false; + + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + // We need to protect against integer overflow with these tests + if (offset < 0) + return false; + + unsigned long uoffset = static_cast<unsigned long>(offset); + if (uoffset > m_elementArrayBufferByteLength || array->byteLength() > m_elementArrayBufferByteLength - uoffset) + return false; + + // If we already have a buffer, we need to clone it and add the new data + if (m_elementArrayBuffer && !m_elementArrayBufferCloned) { + m_elementArrayBuffer = WebGLArrayBuffer::create(m_elementArrayBuffer.get()); + m_elementArrayBufferCloned = true; + } + + memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()) + offset, array->baseAddress(), array->byteLength()); + return true; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) + return array->byteLength() + offset <= m_arrayBufferByteLength; + + return false; +} + +unsigned WebGLBuffer::byteLength(unsigned long target) const +{ + return (target == GraphicsContext3D::ARRAY_BUFFER) ? m_arrayBufferByteLength : m_elementArrayBufferByteLength; +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLBuffer.h b/WebCore/html/canvas/WebGLBuffer.h new file mode 100644 index 0000000..cb953c6 --- /dev/null +++ b/WebCore/html/canvas/WebGLBuffer.h @@ -0,0 +1,69 @@ +/* + * 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 WebGLBuffer_h +#define WebGLBuffer_h + +#include "CanvasObject.h" +#include "WebGLArrayBuffer.h" + +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + + class WebGLBuffer : public CanvasObject { + public: + virtual ~WebGLBuffer() { deleteObject(); } + + static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*); + + // For querying previously created objects via e.g. getFramebufferAttachmentParameter + // FIXME: should consider canonicalizing these objects + 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); + + unsigned byteLength(unsigned long target) const; + const WebGLArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); } + + protected: + WebGLBuffer(WebGLRenderingContext*); + WebGLBuffer(WebGLRenderingContext*, Platform3DObject obj); + + virtual void _deleteObject(Platform3DObject o); + + private: + RefPtr<WebGLArrayBuffer> m_elementArrayBuffer; + unsigned m_elementArrayBufferByteLength; + unsigned m_arrayBufferByteLength; + bool m_elementArrayBufferCloned; + }; + +} // namespace WebCore + +#endif // WebGLBuffer_h diff --git a/WebCore/html/canvas/CanvasBuffer.idl b/WebCore/html/canvas/WebGLBuffer.idl index 9bca42b..30b7606 100644 --- a/WebCore/html/canvas/CanvasBuffer.idl +++ b/WebCore/html/canvas/WebGLBuffer.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasBuffer { + interface [Conditional=3D_CANVAS] WebGLBuffer { }; } diff --git a/WebCore/html/canvas/CanvasByteArray.cpp b/WebCore/html/canvas/WebGLByteArray.cpp index 0f72ccf..1c2849b 100644 --- a/WebCore/html/canvas/CanvasByteArray.cpp +++ b/WebCore/html/canvas/WebGLByteArray.cpp @@ -1,5 +1,6 @@ /* * 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 @@ -27,49 +28,64 @@ #if ENABLE(3D_CANVAS) -#include "CanvasArrayBuffer.h" -#include "CanvasByteArray.h" +#include "WebGLArrayBuffer.h" +#include "WebGLByteArray.h" namespace WebCore { - -PassRefPtr<CanvasByteArray> CanvasByteArray::create(unsigned length) + +PassRefPtr<WebGLByteArray> WebGLByteArray::create(unsigned length) { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(signed char)); + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(signed char)); return create(buffer, 0, length); } -PassRefPtr<CanvasByteArray> CanvasByteArray::create(signed char* array, unsigned length) +PassRefPtr<WebGLByteArray> WebGLByteArray::create(signed char* array, unsigned length) { - RefPtr<CanvasByteArray> a = CanvasByteArray::create(length); + RefPtr<WebGLByteArray> a = WebGLByteArray::create(length); for (unsigned i = 0; i < length; ++i) a->set(i, array[i]); return a; } -PassRefPtr<CanvasByteArray> CanvasByteArray::create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) +PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) { if (buffer) { // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(signed char))) > buffer->byteLength()) + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(signed char))) > buffer->byteLength()) return NULL; } - - return adoptRef(new CanvasByteArray(buffer, offset, length)); + + return adoptRef(new WebGLByteArray(buffer, byteOffset, length)); } -CanvasByteArray::CanvasByteArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) +WebGLByteArray::WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) + : WebGLArray(buffer, offset) , m_size(length) { } -unsigned CanvasByteArray::length() const { +unsigned WebGLByteArray::length() const { return m_size; } - -unsigned CanvasByteArray::sizeInBytes() const { - return length() * sizeof(signed char); + +unsigned WebGLByteArray::byteLength() const { + return m_size * sizeof(signed char); +} + +PassRefPtr<WebGLArray> WebGLByteArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(signed char); + unsigned limitByte = startByte + length * sizeof(signed char); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLByteArray::set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(signed char), ec); } } diff --git a/WebCore/html/canvas/WebGLByteArray.h b/WebCore/html/canvas/WebGLByteArray.h new file mode 100644 index 0000000..c517c03 --- /dev/null +++ b/WebCore/html/canvas/WebGLByteArray.h @@ -0,0 +1,100 @@ +/* + * 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, int byteOffset, unsigned length); + + char* data() { return static_cast<char*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + 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, + int offset, + unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLByteArray_h diff --git a/WebCore/html/canvas/CanvasIntArray.idl b/WebCore/html/canvas/WebGLByteArray.idl index 2c81b87..054a912 100644 --- a/WebCore/html/canvas/CanvasIntArray.idl +++ b/WebCore/html/canvas/WebGLByteArray.idl @@ -1,5 +1,6 @@ /* * 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 @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasIntArray : CanvasArray { + ] 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); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/WebGLFloatArray.cpp b/WebCore/html/canvas/WebGLFloatArray.cpp new file mode 100644 index 0000000..6192898 --- /dev/null +++ b/WebCore/html/canvas/WebGLFloatArray.cpp @@ -0,0 +1,95 @@ +/* + * 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, int byteOffset, unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(float)) != 0) + return NULL; + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(float))) > buffer->byteLength()) + return NULL; + } + return adoptRef(new WebGLFloatArray(buffer, byteOffset, length)); +} + +WebGLFloatArray::WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int 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(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(float); + unsigned limitByte = startByte + length * sizeof(float); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, 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/WebGLFloatArray.h b/WebCore/html/canvas/WebGLFloatArray.h new file mode 100644 index 0000000..4607962 --- /dev/null +++ b/WebCore/html/canvas/WebGLFloatArray.h @@ -0,0 +1,95 @@ +/* + * 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 WebGLFloatArray_h +#define WebGLFloatArray_h + +#include "WebGLArray.h" +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLFloatArray : public WebGLArray { + 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, int byteOffset, unsigned length); + + float* data() { return static_cast<float*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + 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); + } + + float item(unsigned index) const + { + ASSERT(index < m_size); + float* storage = static_cast<float*>(m_baseAddress); + float result = storage[index]; + if (isnan(result)) { + // Clamp NaN to 0 + result = 0; + } + return result; + } + + void set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLFloatArray_h diff --git a/WebCore/html/canvas/CanvasShortArray.idl b/WebCore/html/canvas/WebGLFloatArray.idl index 6d64e1c..83479b3 100644 --- a/WebCore/html/canvas/CanvasShortArray.idl +++ b/WebCore/html/canvas/WebGLFloatArray.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2006 Apple Computer, 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 @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasShortArray : CanvasArray { + ] WebGLFloatArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLFloatArray 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/CanvasFramebuffer.cpp b/WebCore/html/canvas/WebGLFramebuffer.cpp index 9700354..7ade990 100644 --- a/WebCore/html/canvas/CanvasFramebuffer.cpp +++ b/WebCore/html/canvas/WebGLFramebuffer.cpp @@ -27,23 +27,23 @@ #if ENABLE(3D_CANVAS) -#include "CanvasFramebuffer.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLFramebuffer.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasFramebuffer> CanvasFramebuffer::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasFramebuffer(ctx)); + return adoptRef(new WebGLFramebuffer(ctx)); } -CanvasFramebuffer::CanvasFramebuffer(CanvasRenderingContext3D* ctx) +WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createFramebuffer()); } -void CanvasFramebuffer::_deleteObject(Platform3DObject object) +void WebGLFramebuffer::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteFramebuffer(object); } diff --git a/WebCore/html/canvas/CanvasFramebuffer.h b/WebCore/html/canvas/WebGLFramebuffer.h index ec3cb97..10b6772 100644 --- a/WebCore/html/canvas/CanvasFramebuffer.h +++ b/WebCore/html/canvas/WebGLFramebuffer.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasFramebuffer_h -#define CanvasFramebuffer_h +#ifndef WebGLFramebuffer_h +#define WebGLFramebuffer_h #include "CanvasObject.h" @@ -33,18 +33,18 @@ namespace WebCore { - class CanvasFramebuffer : public CanvasObject { + class WebGLFramebuffer : public CanvasObject { public: - virtual ~CanvasFramebuffer() { deleteObject(); } + virtual ~WebGLFramebuffer() { deleteObject(); } - static PassRefPtr<CanvasFramebuffer> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*); protected: - CanvasFramebuffer(CanvasRenderingContext3D*); + WebGLFramebuffer(WebGLRenderingContext*); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasFramebuffer_h +#endif // WebGLFramebuffer_h diff --git a/WebCore/html/canvas/WebGLFramebuffer.idl b/WebCore/html/canvas/WebGLFramebuffer.idl new file mode 100644 index 0000000..8c1d9fd --- /dev/null +++ b/WebCore/html/canvas/WebGLFramebuffer.idl @@ -0,0 +1,29 @@ +/* + * 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. + */ + +module html { + interface [Conditional=3D_CANVAS] WebGLFramebuffer { + }; +} diff --git a/WebCore/html/canvas/WebGLGetInfo.cpp b/WebCore/html/canvas/WebGLGetInfo.cpp new file mode 100644 index 0000000..96218e5 --- /dev/null +++ b/WebCore/html/canvas/WebGLGetInfo.cpp @@ -0,0 +1,215 @@ +/* + * 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 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 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 "WebGLGetInfo.h" +#include "WebGLBuffer.h" +#include "WebGLFloatArray.h" +#include "WebGLFramebuffer.h" +#include "WebGLIntArray.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" +#include "WebGLUnsignedByteArray.h" + +namespace WebCore { + +WebGLGetInfo::WebGLGetInfo(bool value) + : m_type(kTypeBool) + , m_bool(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(float value) + : m_type(kTypeFloat) + , m_float(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(long value) + : m_type(kTypeLong) + , m_long(value) +{ +} + +WebGLGetInfo::WebGLGetInfo() + : m_type(kTypeNull) +{ +} + +WebGLGetInfo::WebGLGetInfo(const String& value) + : m_type(kTypeString) + , m_string(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(unsigned long value) + : m_type(kTypeUnsignedLong) + , m_unsignedLong(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLBuffer> value) + : m_type(kTypeWebGLBuffer) + , m_webglBuffer(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLFloatArray> value) + : m_type(kTypeWebGLFloatArray) + , m_webglFloatArray(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLFramebuffer> value) + : m_type(kTypeWebGLFramebuffer) + , m_webglFramebuffer(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLIntArray> value) + : m_type(kTypeWebGLIntArray) + , m_webglIntArray(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLProgram> value) + : m_type(kTypeWebGLProgram) + , m_webglProgram(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLRenderbuffer> value) + : m_type(kTypeWebGLRenderbuffer) + , m_webglRenderbuffer(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLTexture> value) + : m_type(kTypeWebGLTexture) + , m_webglTexture(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLUnsignedByteArray> value) + : m_type(kTypeWebGLUnsignedByteArray) + , m_webglUnsignedByteArray(value) +{ +} + +WebGLGetInfo::~WebGLGetInfo() +{ +} + +WebGLGetInfo::Type WebGLGetInfo::getType() const +{ + return m_type; +} + +bool WebGLGetInfo::getBool() const +{ + ASSERT(getType() == kTypeBool); + return m_bool; +} + +float WebGLGetInfo::getFloat() const +{ + ASSERT(getType() == kTypeFloat); + return m_float; +} + +long WebGLGetInfo::getLong() const +{ + ASSERT(getType() == kTypeLong); + return m_long; +} + +const String& WebGLGetInfo::getString() const +{ + ASSERT(getType() == kTypeString); + return m_string; +} + +unsigned long WebGLGetInfo::getUnsignedLong() const +{ + ASSERT(getType() == kTypeUnsignedLong); + return m_unsignedLong; +} + +PassRefPtr<WebGLBuffer> WebGLGetInfo::getWebGLBuffer() const +{ + ASSERT(getType() == kTypeWebGLBuffer); + return m_webglBuffer; +} + +PassRefPtr<WebGLFloatArray> WebGLGetInfo::getWebGLFloatArray() const +{ + ASSERT(getType() == kTypeWebGLFloatArray); + return m_webglFloatArray; +} + +PassRefPtr<WebGLFramebuffer> WebGLGetInfo::getWebGLFramebuffer() const +{ + ASSERT(getType() == kTypeWebGLFramebuffer); + return m_webglFramebuffer; +} + +PassRefPtr<WebGLIntArray> WebGLGetInfo::getWebGLIntArray() const +{ + ASSERT(getType() == kTypeWebGLIntArray); + return m_webglIntArray; +} + +PassRefPtr<WebGLProgram> WebGLGetInfo::getWebGLProgram() const +{ + ASSERT(getType() == kTypeWebGLProgram); + return m_webglProgram; +} + +PassRefPtr<WebGLRenderbuffer> WebGLGetInfo::getWebGLRenderbuffer() const +{ + ASSERT(getType() == kTypeWebGLRenderbuffer); + return m_webglRenderbuffer; +} + +PassRefPtr<WebGLTexture> WebGLGetInfo::getWebGLTexture() const +{ + ASSERT(getType() == kTypeWebGLTexture); + return m_webglTexture; +} + +PassRefPtr<WebGLUnsignedByteArray> WebGLGetInfo::getWebGLUnsignedByteArray() const +{ + ASSERT(getType() == kTypeWebGLUnsignedByteArray); + return m_webglUnsignedByteArray; +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLGetInfo.h b/WebCore/html/canvas/WebGLGetInfo.h new file mode 100644 index 0000000..8ac42c4 --- /dev/null +++ b/WebCore/html/canvas/WebGLGetInfo.h @@ -0,0 +1,131 @@ +/* + * 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 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 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 WebGLGetInfo_h +#define WebGLGetInfo_h + +#include "wtf/PassRefPtr.h" +#include "wtf/RefPtr.h" +#include "PlatformString.h" + +#include "WebGLBuffer.h" +#include "WebGLFloatArray.h" +#include "WebGLFramebuffer.h" +#include "WebGLIntArray.h" +// FIXME: implement WebGLObjectArray +//#include "WebGLObjectArray.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" +#include "WebGLUnsignedByteArray.h" + +namespace WebCore { + +// A tagged union representing the result of get queries like +// getParameter (encompassing getBooleanv, getIntegerv, getFloatv) and +// similar variants. For reference counted types, increments and +// decrements the reference count of the target object. + +class WebGLGetInfo { +public: + enum Type { + kTypeBool, + kTypeFloat, + kTypeLong, + kTypeNull, + kTypeString, + kTypeUnsignedLong, + kTypeWebGLBuffer, + kTypeWebGLFloatArray, + kTypeWebGLFramebuffer, + kTypeWebGLIntArray, + kTypeWebGLObjectArray, + kTypeWebGLProgram, + kTypeWebGLRenderbuffer, + kTypeWebGLTexture, + kTypeWebGLUnsignedByteArray + }; + + WebGLGetInfo(bool value); + WebGLGetInfo(float value); + WebGLGetInfo(long value); + // Represents the NULL value and type + WebGLGetInfo(); + WebGLGetInfo(const String& value); + WebGLGetInfo(unsigned long value); + WebGLGetInfo(PassRefPtr<WebGLBuffer> value); + WebGLGetInfo(PassRefPtr<WebGLFloatArray> value); + WebGLGetInfo(PassRefPtr<WebGLFramebuffer> value); + WebGLGetInfo(PassRefPtr<WebGLIntArray> value); + // FIXME: implement WebGLObjectArray + // WebGLGetInfo(PassRefPtr<WebGLObjectArray> value); + WebGLGetInfo(PassRefPtr<WebGLProgram> value); + WebGLGetInfo(PassRefPtr<WebGLRenderbuffer> value); + WebGLGetInfo(PassRefPtr<WebGLTexture> value); + WebGLGetInfo(PassRefPtr<WebGLUnsignedByteArray> value); + + virtual ~WebGLGetInfo(); + + Type getType() const; + + bool getBool() const; + float getFloat() const; + long getLong() const; + const String& getString() const; + unsigned long getUnsignedLong() const; + PassRefPtr<WebGLBuffer> getWebGLBuffer() const; + PassRefPtr<WebGLFloatArray> getWebGLFloatArray() const; + PassRefPtr<WebGLFramebuffer> getWebGLFramebuffer() const; + PassRefPtr<WebGLIntArray> 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; + +private: + Type m_type; + bool m_bool; + float m_float; + long m_long; + String m_string; + unsigned long m_unsignedLong; + RefPtr<WebGLBuffer> m_webglBuffer; + RefPtr<WebGLFloatArray> m_webglFloatArray; + RefPtr<WebGLFramebuffer> m_webglFramebuffer; + RefPtr<WebGLIntArray> 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; +}; + +} // namespace WebCore + +#endif // WebGLGetInfo_h diff --git a/WebCore/html/canvas/WebGLIntArray.cpp b/WebCore/html/canvas/WebGLIntArray.cpp new file mode 100644 index 0000000..4617010 --- /dev/null +++ b/WebCore/html/canvas/WebGLIntArray.cpp @@ -0,0 +1,99 @@ +/* + * 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, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(int)) != 0) + return NULL; + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(int))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLIntArray(buffer, byteOffset, length)); +} + +WebGLIntArray::WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int 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(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(int); + unsigned limitByte = startByte + length * sizeof(int); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, 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 new file mode 100644 index 0000000..25108ac --- /dev/null +++ b/WebCore/html/canvas/WebGLIntArray.h @@ -0,0 +1,97 @@ +/* + * 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, int byteOffset, unsigned length); + + int* data() { return static_cast<int*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + 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, + int byteOffset, + unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLIntArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.idl b/WebCore/html/canvas/WebGLIntArray.idl index d46f708..3bc037c 100644 --- a/WebCore/html/canvas/CanvasUnsignedByteArray.idl +++ b/WebCore/html/canvas/WebGLIntArray.idl @@ -1,5 +1,6 @@ /* * 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 @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasUnsignedByteArray : CanvasArray { + ] 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); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/CanvasProgram.cpp b/WebCore/html/canvas/WebGLProgram.cpp index 83da270..c2606c1 100644 --- a/WebCore/html/canvas/CanvasProgram.cpp +++ b/WebCore/html/canvas/WebGLProgram.cpp @@ -27,23 +27,23 @@ #if ENABLE(3D_CANVAS) -#include "CanvasProgram.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLProgram.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasProgram> CanvasProgram::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLProgram> WebGLProgram::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasProgram(ctx)); + return adoptRef(new WebGLProgram(ctx)); } -CanvasProgram::CanvasProgram(CanvasRenderingContext3D* ctx) +WebGLProgram::WebGLProgram(WebGLRenderingContext* ctx) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createProgram()); } -void CanvasProgram::_deleteObject(Platform3DObject object) +void WebGLProgram::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteProgram(object); } diff --git a/WebCore/html/canvas/CanvasProgram.h b/WebCore/html/canvas/WebGLProgram.h index af817c8..8804d39 100644 --- a/WebCore/html/canvas/CanvasProgram.h +++ b/WebCore/html/canvas/WebGLProgram.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasProgram_h -#define CanvasProgram_h +#ifndef WebGLProgram_h +#define WebGLProgram_h #include "CanvasObject.h" @@ -33,18 +33,18 @@ namespace WebCore { - class CanvasProgram : public CanvasObject { + class WebGLProgram : public CanvasObject { public: - virtual ~CanvasProgram() { deleteObject(); } + virtual ~WebGLProgram() { deleteObject(); } - static PassRefPtr<CanvasProgram> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); protected: - CanvasProgram(CanvasRenderingContext3D*); + WebGLProgram(WebGLRenderingContext*); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasProgram_h +#endif // WebGLProgram_h diff --git a/WebCore/html/canvas/CanvasShader.idl b/WebCore/html/canvas/WebGLProgram.idl index 7474c3a..562fa3a 100644 --- a/WebCore/html/canvas/CanvasShader.idl +++ b/WebCore/html/canvas/WebGLProgram.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasShader { + interface [Conditional=3D_CANVAS] WebGLProgram { }; } diff --git a/WebCore/html/canvas/CanvasRenderbuffer.cpp b/WebCore/html/canvas/WebGLRenderbuffer.cpp index 51054cd..286ad2e 100644 --- a/WebCore/html/canvas/CanvasRenderbuffer.cpp +++ b/WebCore/html/canvas/WebGLRenderbuffer.cpp @@ -27,23 +27,34 @@ #if ENABLE(3D_CANVAS) -#include "CanvasRenderbuffer.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLRenderbuffer.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasRenderbuffer> CanvasRenderbuffer::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLRenderbuffer> WebGLRenderbuffer::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasRenderbuffer(ctx)); + return adoptRef(new WebGLRenderbuffer(ctx)); } -CanvasRenderbuffer::CanvasRenderbuffer(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLRenderbuffer> WebGLRenderbuffer::create(WebGLRenderingContext* ctx, Platform3DObject obj) +{ + return adoptRef(new WebGLRenderbuffer(ctx, obj)); +} + +WebGLRenderbuffer::WebGLRenderbuffer(WebGLRenderingContext* ctx) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createRenderbuffer()); } -void CanvasRenderbuffer::_deleteObject(Platform3DObject object) +WebGLRenderbuffer::WebGLRenderbuffer(WebGLRenderingContext* ctx, Platform3DObject obj) + : CanvasObject(ctx) +{ + setObject(obj, false); +} + +void WebGLRenderbuffer::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteRenderbuffer(object); } diff --git a/WebCore/html/canvas/CanvasRenderbuffer.h b/WebCore/html/canvas/WebGLRenderbuffer.h index 3fb99e9..790fdcd 100644 --- a/WebCore/html/canvas/CanvasRenderbuffer.h +++ b/WebCore/html/canvas/WebGLRenderbuffer.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasRenderbuffer_h -#define CanvasRenderbuffer_h +#ifndef WebGLRenderbuffer_h +#define WebGLRenderbuffer_h #include "CanvasObject.h" @@ -33,18 +33,23 @@ namespace WebCore { - class CanvasRenderbuffer : public CanvasObject { + class WebGLRenderbuffer : public CanvasObject { public: - virtual ~CanvasRenderbuffer() { deleteObject(); } + virtual ~WebGLRenderbuffer() { deleteObject(); } - static PassRefPtr<CanvasRenderbuffer> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*); + // For querying previously created objects via e.g. getFramebufferAttachmentParameter + // FIXME: should consider canonicalizing these objects + static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*, Platform3DObject renderbuffer); + protected: - CanvasRenderbuffer(CanvasRenderingContext3D*); + WebGLRenderbuffer(WebGLRenderingContext*); + WebGLRenderbuffer(WebGLRenderingContext*, Platform3DObject); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasRenderbuffer_h +#endif // WebGLRenderbuffer_h diff --git a/WebCore/html/canvas/CanvasFramebuffer.idl b/WebCore/html/canvas/WebGLRenderbuffer.idl index 0a9b668..2524433 100644 --- a/WebCore/html/canvas/CanvasFramebuffer.idl +++ b/WebCore/html/canvas/WebGLRenderbuffer.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasFramebuffer { + interface [Conditional=3D_CANVAS] WebGLRenderbuffer { }; } diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp new file mode 100644 index 0000000..7a7215d --- /dev/null +++ b/WebCore/html/canvas/WebGLRenderingContext.cpp @@ -0,0 +1,2424 @@ +/* + * 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 "WebGLRenderingContext.h" + +#include "WebGLActiveInfo.h" +#include "WebGLBuffer.h" +#include "WebGLFramebuffer.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" +#include "WebGLShader.h" +#include "WebGLUniformLocation.h" +#include "HTMLCanvasElement.h" +#include "HTMLImageElement.h" +#include "ImageBuffer.h" +#include "NotImplemented.h" +#include "RenderBox.h" +#include "RenderLayer.h" + +namespace WebCore { + +class WebGLStateRestorer { +public: + WebGLStateRestorer(WebGLRenderingContext* context, + bool changed) + : m_context(context) + , m_changed(changed) + { + } + + ~WebGLStateRestorer() + { + m_context->cleanupAfterGraphicsCall(m_changed); + } + +private: + WebGLRenderingContext* m_context; + bool m_changed; +}; + +PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElement* canvas) +{ + OwnPtr<GraphicsContext3D> context(GraphicsContext3D::create()); + if (!context) + return 0; + + return new WebGLRenderingContext(canvas, context.release()); +} + +WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr<GraphicsContext3D> context) + : CanvasRenderingContext(passedCanvas) + , m_context(context) + , m_needsUpdate(true) + , m_markedCanvasDirty(false) + , m_activeTextureUnit(0) +{ + ASSERT(m_context); + int numVertexAttribs = 0; + m_context->getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &numVertexAttribs); + m_maxVertexAttribs = numVertexAttribs; + m_context->reshape(canvas()->width(), canvas()->height()); +} + +WebGLRenderingContext::~WebGLRenderingContext() +{ + detachAndRemoveAllObjects(); +} + +void WebGLRenderingContext::markContextChanged() +{ +#if USE(ACCELERATED_COMPOSITING) + if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) { + canvas()->renderBox()->layer()->rendererContentChanged(); + } else { +#endif + if (!m_markedCanvasDirty) { + // Make sure the canvas's image buffer is allocated. + canvas()->buffer(); + canvas()->willDraw(FloatRect(0, 0, canvas()->width(), canvas()->height())); + m_markedCanvasDirty = true; + } +#if USE(ACCELERATED_COMPOSITING) + } +#endif +} + +void WebGLRenderingContext::beginPaint() +{ + if (m_markedCanvasDirty) { + m_context->beginPaint(this); + } +} + +void WebGLRenderingContext::endPaint() +{ + if (m_markedCanvasDirty) { + m_markedCanvasDirty = false; + m_context->endPaint(); + } +} + +void WebGLRenderingContext::reshape(int width, int height) +{ + if (m_needsUpdate) { +#if USE(ACCELERATED_COMPOSITING) + if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) + canvas()->renderBox()->layer()->rendererContentChanged(); +#endif + m_needsUpdate = false; + } + + m_context->reshape(width, height); +} + +int WebGLRenderingContext::sizeInBytes(int type, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + int result = m_context->sizeInBytes(type); + if (result <= 0) + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + + return result; +} + +void WebGLRenderingContext::activeTexture(unsigned long texture, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if ((texture - GraphicsContext3D::TEXTURE0) > sizeof(m_textureUnits) / sizeof(TextureUnitState)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_activeTextureUnit = texture - GraphicsContext3D::TEXTURE0; + m_context->activeTexture(texture); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this || !shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->attachShader(program, shader); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, unsigned long index, const String& name, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->bindAttribLocation(program, index, name); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bindBuffer(unsigned long target, WebGLBuffer* buffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (buffer && buffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) + m_boundArrayBuffer = buffer; + else if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) + m_boundElementArrayBuffer = buffer; + else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bindBuffer(target, buffer); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::bindFramebuffer(unsigned long target, WebGLFramebuffer* buffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (buffer && buffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + if (target != GraphicsContext3D::FRAMEBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_framebufferBinding = buffer; + m_context->bindFramebuffer(target, buffer); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bindRenderbuffer(unsigned long target, WebGLRenderbuffer* renderBuffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (renderBuffer && renderBuffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + if (target != GraphicsContext3D::RENDERBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_renderbufferBinding = renderBuffer; + m_context->bindRenderbuffer(target, renderBuffer); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::bindTexture(unsigned long target, WebGLTexture* texture, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (texture && texture->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + if (target == GraphicsContext3D::TEXTURE_2D) + m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; + else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) + m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; + else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_context->bindTexture(target, texture); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendColor(double red, double green, double blue, double alpha) +{ + m_context->blendColor(red, green, blue, alpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendEquation( unsigned long mode ) +{ + m_context->blendEquation(mode); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha) +{ + m_context->blendEquationSeparate(modeRGB, modeAlpha); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::blendFunc(unsigned long sfactor, unsigned long dfactor) +{ + m_context->blendFunc(sfactor, dfactor); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha) +{ + m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { + if (!m_boundElementArrayBuffer->associateBufferData(target, size)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else if (target == GraphicsContext3D::ARRAY_BUFFER && m_boundArrayBuffer) { + if (!m_boundArrayBuffer->associateBufferData(target, size)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bufferData(target, size, usage); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bufferData(unsigned long target, WebGLArray* data, unsigned long usage, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { + if (!m_boundElementArrayBuffer->associateBufferData(target, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else if (target == GraphicsContext3D::ARRAY_BUFFER && m_boundArrayBuffer) { + if (!m_boundArrayBuffer->associateBufferData(target, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bufferData(target, data, usage); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bufferSubData(unsigned long target, long offset, WebGLArray* data, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { + if (!m_boundElementArrayBuffer->associateBufferSubData(target, offset, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else if (target == GraphicsContext3D::ARRAY_BUFFER && m_boundArrayBuffer) { + if (!m_boundArrayBuffer->associateBufferSubData(target, offset, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bufferSubData(target, offset, data); + cleanupAfterGraphicsCall(false); +} + +unsigned long WebGLRenderingContext::checkFramebufferStatus(unsigned long target) +{ + return m_context->checkFramebufferStatus(target); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::clear(unsigned long mask) +{ + m_context->clear(mask); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::clearColor(double r, double g, double b, double a) +{ + if (isnan(r)) + r = 0; + if (isnan(g)) + g = 0; + if (isnan(b)) + b = 0; + if (isnan(a)) + a = 1; + m_context->clearColor(r, g, b, a); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::clearDepth(double depth) +{ + m_context->clearDepth(depth); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::clearStencil(long s) +{ + m_context->clearStencil(s); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::colorMask(bool red, bool green, bool blue, bool alpha) +{ + m_context->colorMask(red, green, blue, alpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->compileShader(shader); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) +{ + m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height) +{ + m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); + cleanupAfterGraphicsCall(false); +} + +PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer() +{ + RefPtr<WebGLBuffer> o = WebGLBuffer::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLFramebuffer> WebGLRenderingContext::createFramebuffer() +{ + RefPtr<WebGLFramebuffer> o = WebGLFramebuffer::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLTexture> WebGLRenderingContext::createTexture() +{ + RefPtr<WebGLTexture> o = WebGLTexture::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLProgram> WebGLRenderingContext::createProgram() +{ + RefPtr<WebGLProgram> o = WebGLProgram::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLRenderbuffer> WebGLRenderingContext::createRenderbuffer() +{ + RefPtr<WebGLRenderbuffer> o = WebGLRenderbuffer::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLShader> WebGLRenderingContext::createShader(unsigned long type, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (type != GraphicsContext3D::VERTEX_SHADER && type != GraphicsContext3D::FRAGMENT_SHADER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return 0; + } + + RefPtr<WebGLShader> o = WebGLShader::create(this, static_cast<GraphicsContext3D::WebGLEnumType>(type)); + addObject(o.get()); + return o; +} + +void WebGLRenderingContext::cullFace(unsigned long mode) +{ + m_context->cullFace(mode); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer) +{ + if (!buffer) + return; + + buffer->deleteObject(); +} + +void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer) +{ + if (!framebuffer) + return; + + framebuffer->deleteObject(); +} + +void WebGLRenderingContext::deleteProgram(WebGLProgram* program) +{ + if (!program) + return; + + program->deleteObject(); +} + +void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer) +{ + if (!renderbuffer) + return; + + renderbuffer->deleteObject(); +} + +void WebGLRenderingContext::deleteShader(WebGLShader* shader) +{ + if (!shader) + return; + + shader->deleteObject(); +} + +void WebGLRenderingContext::deleteTexture(WebGLTexture* texture) +{ + if (!texture) + return; + + texture->deleteObject(); +} + +void WebGLRenderingContext::depthFunc(unsigned long func) +{ + m_context->depthFunc(func); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::depthMask(bool flag) +{ + m_context->depthMask(flag); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::depthRange(double zNear, double zFar) +{ + m_context->depthRange(zNear, zFar); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this || !shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->detachShader(program, shader); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::disable(unsigned long cap) +{ + m_context->disable(cap); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::disableVertexAttribArray(unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (index >= m_maxVertexAttribs) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + if (index < m_vertexAttribState.size()) + m_vertexAttribState[index].enabled = false; + + m_context->disableVertexAttribArray(index); + cleanupAfterGraphicsCall(false); +} + +bool WebGLRenderingContext::validateIndexArray(unsigned long count, unsigned long type, long offset, long& numElements) +{ + long lastIndex = -1; + if (!m_boundElementArrayBuffer) + return false; + + if (offset < 0) + return false; + + // The GL spec says that count must be "greater + + unsigned long uoffset = static_cast<unsigned long>(offset); + + if (type == GraphicsContext3D::UNSIGNED_SHORT) { + // For an unsigned short array, offset must be divisible by 2 for alignment reasons. + if (uoffset & 1) + return false; + + // Make uoffset an element offset. + uoffset /= 2; + + unsigned long n = m_boundElementArrayBuffer->byteLength(GraphicsContext3D::ELEMENT_ARRAY_BUFFER) / 2; + if (uoffset > n || count > n - uoffset) + return false; + + const unsigned short* p = static_cast<const unsigned short*>(m_boundElementArrayBuffer->elementArrayBuffer()->data()); + while (n-- > 0) { + if (*p > lastIndex) + lastIndex = *p; + ++p; + } + } else if (type == GraphicsContext3D::UNSIGNED_BYTE) { + unsigned long n = m_boundElementArrayBuffer->byteLength(GraphicsContext3D::ELEMENT_ARRAY_BUFFER); + if (uoffset > n || count > n - uoffset) + return false; + + const unsigned char* p = static_cast<const unsigned char*>(m_boundElementArrayBuffer->elementArrayBuffer()->data()); + while (n-- > 0) { + if (*p > lastIndex) + lastIndex = *p; + ++p; + } + } + + // Then set the last index in the index array and make sure it is valid. + numElements = lastIndex + 1; + return numElements > 0; +} + +bool WebGLRenderingContext::validateRenderingState(long numElements) +{ + // Look in each enabled vertex attrib and find the smallest buffer size + long smallestNumElements = LONG_MAX; + for (unsigned i = 0; i < m_vertexAttribState.size(); ++i) { + const VertexAttribState& state = m_vertexAttribState[i]; + if (state.enabled && state.numElements < smallestNumElements) + smallestNumElements = state.numElements; + } + + if (smallestNumElements == LONG_MAX) + smallestNumElements = 0; + + return numElements <= smallestNumElements; +} + +void WebGLRenderingContext::drawArrays(unsigned long mode, long first, long count, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + // Ensure we have a valid rendering state + if (first < 0 || count < 0 || !validateRenderingState(first + count)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->drawArrays(mode, first, count); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + // Ensure we have a valid rendering state + long numElements; + + if (offset < 0 || !validateIndexArray(count, type, offset, numElements) || !validateRenderingState(numElements)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->drawElements(mode, count, type, offset); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::enable(unsigned long cap) +{ + m_context->enable(cap); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::enableVertexAttribArray(unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (index >= m_maxVertexAttribs) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + if (index >= m_vertexAttribState.size()) + m_vertexAttribState.resize(index + 1); + + m_vertexAttribState[index].enabled = true; + + m_context->enableVertexAttribArray(index); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::finish() +{ + m_context->finish(); + cleanupAfterGraphicsCall(true); +} + + +void WebGLRenderingContext::flush() +{ + m_context->flush(); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer* buffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (buffer && buffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture* texture, long level, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (texture && texture->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->framebufferTexture2D(target, attachment, textarget, texture, level); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::frontFace(unsigned long mode) +{ + m_context->frontFace(mode); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::generateMipmap(unsigned long target) +{ + m_context->generateMipmap(target); + cleanupAfterGraphicsCall(false); +} + +PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* program, unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + ActiveInfo info; + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return 0; + } + if (!m_context->getActiveAttrib(program, index, info)) { + return 0; + } + return WebGLActiveInfo::create(info.name, info.type, info.size); +} + +PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram* program, unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + ActiveInfo info; + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return 0; + } + if (!m_context->getActiveUniform(program, index, info)) { + return 0; + } + return WebGLActiveInfo::create(info.name, info.type, info.size); +} + +int WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const String& name) +{ + return m_context->getAttribLocation(program, name); +} + +WebGLGetInfo WebGLRenderingContext::getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::ARRAY_BUFFER && target != GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + if (pname != GraphicsContext3D::BUFFER_SIZE && pname != GraphicsContext3D::BUFFER_USAGE) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + WebGLStateRestorer(this, false); + int value; + m_context->getBufferParameteriv(target, pname, &value); + if (pname == GraphicsContext3D::BUFFER_SIZE) + return WebGLGetInfo(static_cast<long>(value)); + else + return WebGLGetInfo(static_cast<unsigned long>(value)); +} + +unsigned long WebGLRenderingContext::getError() +{ + return m_context->getError(); +} + +WebGLGetInfo WebGLRenderingContext::getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::FRAMEBUFFER + || (attachment != GraphicsContext3D::COLOR_ATTACHMENT0 + && attachment != GraphicsContext3D::DEPTH_ATTACHMENT + && attachment != GraphicsContext3D::STENCIL_ATTACHMENT) + || (pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE + && pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME + && pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL + && pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + if (pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { + WebGLStateRestorer(this, false); + int value; + m_context->getFramebufferAttachmentParameteriv(target, attachment, pname, &value); + if (pname == GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) + return WebGLGetInfo(static_cast<unsigned long>(value)); + else + return WebGLGetInfo(static_cast<long>(value)); + } else { + WebGLStateRestorer(this, false); + int type = 0; + m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); + int value = 0; + m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &value); + // FIXME: should consider canonicalizing these objects + switch (type) { + case GraphicsContext3D::RENDERBUFFER: { + RefPtr<WebGLRenderbuffer> tmp = WebGLRenderbuffer::create(this, value); + addObject(tmp.get()); + return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(tmp)); + } + case GraphicsContext3D::TEXTURE: { + RefPtr<WebGLTexture> tmp = WebGLTexture::create(this, value); + addObject(tmp.get()); + return WebGLGetInfo(PassRefPtr<WebGLTexture>(tmp)); + } + default: + // FIXME: raise exception? + return WebGLGetInfo(); + } + } +} + +WebGLGetInfo WebGLRenderingContext::getParameter(unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + WebGLStateRestorer(this, false); + switch (pname) { + case GraphicsContext3D::ACTIVE_TEXTURE: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::ALPHA_BITS: + return getLongParameter(pname); + case GraphicsContext3D::ARRAY_BUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLBuffer>(m_boundArrayBuffer)); + case GraphicsContext3D::BLEND: + return getBooleanParameter(pname); + case GraphicsContext3D::BLEND_COLOR: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::BLEND_DST_ALPHA: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_DST_RGB: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_EQUATION_ALPHA: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_EQUATION_RGB: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_SRC_ALPHA: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_SRC_RGB: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLUE_BITS: + return getLongParameter(pname); + case GraphicsContext3D::COLOR_CLEAR_VALUE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::COLOR_WRITEMASK: + return getWebGLUnsignedByteArrayParameter(pname); + case GraphicsContext3D::COMPRESSED_TEXTURE_FORMATS: + // Defined as null in the spec + return WebGLGetInfo(); + case GraphicsContext3D::CULL_FACE: + return getBooleanParameter(pname); + case GraphicsContext3D::CULL_FACE_MODE: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::CURRENT_PROGRAM: + return WebGLGetInfo(PassRefPtr<WebGLProgram>(m_currentProgram)); + case GraphicsContext3D::DEPTH_BITS: + return getLongParameter(pname); + case GraphicsContext3D::DEPTH_CLEAR_VALUE: + return getFloatParameter(pname); + case GraphicsContext3D::DEPTH_FUNC: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::DEPTH_RANGE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::DEPTH_TEST: + return getBooleanParameter(pname); + case GraphicsContext3D::DEPTH_WRITEMASK: + return getBooleanParameter(pname); + case GraphicsContext3D::DITHER: + return getBooleanParameter(pname); + case GraphicsContext3D::ELEMENT_ARRAY_BUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLBuffer>(m_boundElementArrayBuffer)); + case GraphicsContext3D::FRAMEBUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLFramebuffer>(m_framebufferBinding)); + case GraphicsContext3D::FRONT_FACE: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::GENERATE_MIPMAP_HINT: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::GREEN_BITS: + return getLongParameter(pname); + case GraphicsContext3D::LINE_WIDTH: + return getFloatParameter(pname); + case GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_CUBE_MAP_TEXTURE_SIZE: + return getLongParameter(pname); + case GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_RENDERBUFFER_SIZE: + return getLongParameter(pname); + case GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_TEXTURE_SIZE: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VARYING_VECTORS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VERTEX_ATTRIBS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VIEWPORT_DIMS: + return getWebGLIntArrayParameter(pname); + case GraphicsContext3D::NUM_COMPRESSED_TEXTURE_FORMATS: + return getLongParameter(pname); + case GraphicsContext3D::NUM_SHADER_BINARY_FORMATS: + // FIXME: should we always return 0 for this? + return getLongParameter(pname); + case GraphicsContext3D::PACK_ALIGNMENT: + return getLongParameter(pname); + case GraphicsContext3D::POLYGON_OFFSET_FACTOR: + return getFloatParameter(pname); + case GraphicsContext3D::POLYGON_OFFSET_FILL: + return getBooleanParameter(pname); + case GraphicsContext3D::POLYGON_OFFSET_UNITS: + return getFloatParameter(pname); + case GraphicsContext3D::RED_BITS: + return getLongParameter(pname); + case GraphicsContext3D::RENDERBUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(m_renderbufferBinding)); + case GraphicsContext3D::SAMPLE_BUFFERS: + return getLongParameter(pname); + case GraphicsContext3D::SAMPLE_COVERAGE_INVERT: + return getBooleanParameter(pname); + case GraphicsContext3D::SAMPLE_COVERAGE_VALUE: + return getFloatParameter(pname); + case GraphicsContext3D::SAMPLES: + return getLongParameter(pname); + case GraphicsContext3D::SCISSOR_BOX: + return getWebGLIntArrayParameter(pname); + case GraphicsContext3D::SCISSOR_TEST: + return getBooleanParameter(pname); + case GraphicsContext3D::STENCIL_BACK_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_FUNC: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_PASS_DEPTH_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_PASS_DEPTH_PASS: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_REF: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_VALUE_MASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_WRITEMASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BITS: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_CLEAR_VALUE: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_FUNC: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_PASS_DEPTH_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_PASS_DEPTH_PASS: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_REF: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_TEST: + return getBooleanParameter(pname); + case GraphicsContext3D::STENCIL_VALUE_MASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_WRITEMASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::SUBPIXEL_BITS: + return getLongParameter(pname); + case GraphicsContext3D::TEXTURE_BINDING_2D: + return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_texture2DBinding)); + case GraphicsContext3D::TEXTURE_BINDING_CUBE_MAP: + return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding)); + case GraphicsContext3D::UNPACK_ALIGNMENT: + // FIXME: should this be "long" in the spec? + return getIntParameter(pname); + case GraphicsContext3D::VIEWPORT: + return getWebGLIntArrayParameter(pname); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return WebGLGetInfo(); + } + + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::DELETE_STATUS: + case GraphicsContext3D::LINK_STATUS: + case GraphicsContext3D::VALIDATE_STATUS: + m_context->getProgramiv(program, pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); + case GraphicsContext3D::INFO_LOG_LENGTH: + case GraphicsContext3D::ATTACHED_SHADERS: + case GraphicsContext3D::ACTIVE_ATTRIBUTES: + case GraphicsContext3D::ACTIVE_ATTRIBUTE_MAX_LENGTH: + case GraphicsContext3D::ACTIVE_UNIFORMS: + case GraphicsContext3D::ACTIVE_UNIFORM_MAX_LENGTH: + m_context->getProgramiv(program, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return ""; + } + WebGLStateRestorer(this, false); + return m_context->getProgramInfoLog(program); +} + +WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::RENDERBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::RENDERBUFFER_WIDTH: + case GraphicsContext3D::RENDERBUFFER_HEIGHT: + case GraphicsContext3D::RENDERBUFFER_RED_SIZE: + case GraphicsContext3D::RENDERBUFFER_GREEN_SIZE: + case GraphicsContext3D::RENDERBUFFER_BLUE_SIZE: + case GraphicsContext3D::RENDERBUFFER_ALPHA_SIZE: + case GraphicsContext3D::RENDERBUFFER_DEPTH_SIZE: + case GraphicsContext3D::RENDERBUFFER_STENCIL_SIZE: + m_context->getRenderbufferParameteriv(target, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + case GraphicsContext3D::RENDERBUFFER_INTERNAL_FORMAT: + m_context->getRenderbufferParameteriv(target, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return WebGLGetInfo(); + } + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::DELETE_STATUS: + case GraphicsContext3D::COMPILE_STATUS: + m_context->getShaderiv(shader, pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); + case GraphicsContext3D::SHADER_TYPE: + m_context->getShaderiv(shader, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + case GraphicsContext3D::INFO_LOG_LENGTH: + case GraphicsContext3D::SHADER_SOURCE_LENGTH: + m_context->getShaderiv(shader, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return ""; + } + WebGLStateRestorer(this, false); + return m_context->getShaderInfoLog(shader); +} + +String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return ""; + } + WebGLStateRestorer(this, false); + return m_context->getShaderSource(shader); +} + +String WebGLRenderingContext::getString(unsigned long name) +{ + WebGLStateRestorer(this, false); + return m_context->getString(name); +} + +WebGLGetInfo WebGLRenderingContext::getTexParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::TEXTURE_2D + && target != GraphicsContext3D::TEXTURE_CUBE_MAP) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::TEXTURE_MAG_FILTER: + case GraphicsContext3D::TEXTURE_MIN_FILTER: + case GraphicsContext3D::TEXTURE_WRAP_S: + case GraphicsContext3D::TEXTURE_WRAP_T: + m_context->getTexParameteriv(target, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebGLUniformLocation* uniformLocation, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || uniformLocation->program() != program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return WebGLGetInfo(); + } + long location = uniformLocation->location(); + + WebGLStateRestorer(this, false); + // FIXME: make this more efficient using WebGLUniformLocation and caching types in it + int activeUniforms = 0; + m_context->getProgramiv(program, GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms); + for (int i = 0; i < activeUniforms; i++) { + ActiveInfo info; + if (!m_context->getActiveUniform(program, i, info)) + return WebGLGetInfo(); + // Now need to look this up by name again to find its location + long loc = m_context->getUniformLocation(program, info.name); + if (loc == location) { + // Found it. Use the type in the ActiveInfo to determine the return type. + GraphicsContext3D::WebGLEnumType baseType; + unsigned length; + switch (info.type) { + case GraphicsContext3D::BOOL: + baseType = GraphicsContext3D::BOOL; + length = 1; + break; + case GraphicsContext3D::BOOL_VEC2: + baseType = GraphicsContext3D::BOOL; + length = 2; + break; + case GraphicsContext3D::BOOL_VEC3: + baseType = GraphicsContext3D::BOOL; + length = 3; + break; + case GraphicsContext3D::BOOL_VEC4: + baseType = GraphicsContext3D::BOOL; + length = 4; + break; + case GraphicsContext3D::INT: + baseType = GraphicsContext3D::INT; + length = 1; + break; + case GraphicsContext3D::INT_VEC2: + baseType = GraphicsContext3D::INT; + length = 2; + break; + case GraphicsContext3D::INT_VEC3: + baseType = GraphicsContext3D::INT; + length = 3; + break; + case GraphicsContext3D::INT_VEC4: + baseType = GraphicsContext3D::INT; + length = 4; + break; + case GraphicsContext3D::FLOAT: + baseType = GraphicsContext3D::FLOAT; + length = 1; + break; + case GraphicsContext3D::FLOAT_VEC2: + baseType = GraphicsContext3D::FLOAT; + length = 2; + break; + case GraphicsContext3D::FLOAT_VEC3: + baseType = GraphicsContext3D::FLOAT; + length = 3; + break; + case GraphicsContext3D::FLOAT_VEC4: + baseType = GraphicsContext3D::FLOAT; + length = 4; + break; + case GraphicsContext3D::FLOAT_MAT2: + baseType = GraphicsContext3D::FLOAT; + length = 4; + break; + case GraphicsContext3D::FLOAT_MAT3: + baseType = GraphicsContext3D::FLOAT; + length = 9; + break; + case GraphicsContext3D::FLOAT_MAT4: + baseType = GraphicsContext3D::FLOAT; + length = 16; + break; + default: + // Can't handle this type + // FIXME: what to do about samplers? + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return WebGLGetInfo(); + } + switch (baseType) { + case GraphicsContext3D::FLOAT: { + float value[16] = {0}; + m_context->getUniformfv(program, location, value); + if (length == 1) + return WebGLGetInfo(value[0]); + else + return WebGLGetInfo(WebGLFloatArray::create(value, length)); + } + case GraphicsContext3D::INT: { + int value[16] = {0}; + m_context->getUniformiv(program, location, value); + if (length == 1) + return WebGLGetInfo(static_cast<long>(value[0])); + else + return WebGLGetInfo(WebGLIntArray::create(value, length)); + } + case GraphicsContext3D::BOOL: { + int value[16] = {0}; + m_context->getUniformiv(program, location, value); + if (length == 1) + return WebGLGetInfo(static_cast<bool>(value[0])); + else { + 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)); + } + } + default: + notImplemented(); + } + } + } + // If we get here, something went wrong in our unfortunately complex logic above + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return WebGLGetInfo(); +} + +PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGLProgram* program, const String& name, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return 0; + } + WebGLStateRestorer(this, false); + return WebGLUniformLocation::create(program, m_context->getUniformLocation(program, name)); +} + +WebGLGetInfo WebGLRenderingContext::getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + WebGLStateRestorer(this, false); + switch (pname) { + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { + int name = 0; + m_context->getVertexAttribiv(index, pname, &name); + if (name == 0) + return WebGLGetInfo(); + RefPtr<WebGLBuffer> tmp = WebGLBuffer::create(this, name); + addObject(tmp.get()); + return WebGLGetInfo(PassRefPtr<WebGLBuffer>(tmp)); + } + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_ENABLED: + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_NORMALIZED: { + int value = 0; + m_context->getVertexAttribiv(index, pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); + } + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_SIZE: + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_STRIDE: { + int value = 0; + m_context->getVertexAttribiv(index, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + } + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_TYPE: { + int value = 0; + m_context->getVertexAttribiv(index, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + } + case GraphicsContext3D::CURRENT_VERTEX_ATTRIB: { + float value[4] = {0}; + m_context->getVertexAttribfv(index, pname, value); + return WebGLGetInfo(WebGLFloatArray::create(value, 4)); + } + default: { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + } +} + +long WebGLRenderingContext::getVertexAttribOffset(unsigned long index, unsigned long pname) +{ + long result = m_context->getVertexAttribOffset(index, pname); + cleanupAfterGraphicsCall(false); + return result; +} + +void WebGLRenderingContext::hint(unsigned long target, unsigned long mode) +{ + m_context->hint(target, mode); + cleanupAfterGraphicsCall(false); +} + +bool WebGLRenderingContext::isBuffer(WebGLBuffer* buffer) +{ + if (!buffer) + return false; + + return m_context->isBuffer(buffer); +} + +bool WebGLRenderingContext::isEnabled(unsigned long cap) +{ + return m_context->isEnabled(cap); +} + +bool WebGLRenderingContext::isFramebuffer(WebGLFramebuffer* framebuffer) +{ + if (!framebuffer) + return false; + + return m_context->isFramebuffer(framebuffer); +} + +bool WebGLRenderingContext::isProgram(WebGLProgram* program) +{ + if (!program) + return false; + + return m_context->isProgram(program); +} + +bool WebGLRenderingContext::isRenderbuffer(WebGLRenderbuffer* renderbuffer) +{ + if (!renderbuffer) + return false; + + return m_context->isRenderbuffer(renderbuffer); +} + +bool WebGLRenderingContext::isShader(WebGLShader* shader) +{ + if (!shader) + return false; + + return m_context->isShader(shader); +} + +bool WebGLRenderingContext::isTexture(WebGLTexture* texture) +{ + if (!texture) + return false; + + return m_context->isTexture(texture); +} + +void WebGLRenderingContext::lineWidth(double width) +{ + m_context->lineWidth((float) width); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::linkProgram(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->linkProgram(program); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::pixelStorei(unsigned long pname, long param) +{ + m_context->pixelStorei(pname, param); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::polygonOffset(double factor, double units) +{ + m_context->polygonOffset((float) factor, (float) units); + cleanupAfterGraphicsCall(false); +} + +PassRefPtr<WebGLArray> WebGLRenderingContext::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type) +{ + RefPtr<WebGLArray> array = m_context->readPixels(x, y, width, height, format, type); + cleanupAfterGraphicsCall(false); + return array; +} + +void WebGLRenderingContext::releaseShaderCompiler() +{ + m_context->releaseShaderCompiler(); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height) +{ + m_context->renderbufferStorage(target, internalformat, width, height); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::sampleCoverage(double value, bool invert) +{ + m_context->sampleCoverage((float) value, invert); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::scissor(long x, long y, unsigned long width, unsigned long height) +{ + m_context->scissor(x, y, width, height); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& string, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->shaderSource(shader, string); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilFunc(unsigned long func, long ref, unsigned long mask) +{ + m_context->stencilFunc(func, ref, mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask) +{ + m_context->stencilFuncSeparate(face, func, ref, mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilMask(unsigned long mask) +{ + m_context->stencilMask(mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilMaskSeparate(unsigned long face, unsigned long mask) +{ + m_context->stencilMaskSeparate(face, mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass) +{ + m_context->stencilOp(fail, zfail, zpass); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass) +{ + m_context->stencilOpSeparate(face, fail, zfail, zpass); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texImage2D(target, level, internalformat, width, height, + border, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texImage2D(target, level, internalformat, width, height, + border, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + ec = 0; + if (!image) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + CachedImage* cachedImage = image->cachedImage(); + if (!cachedImage) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + // FIXME: For now we ignore any errors returned + m_context->texImage2D(target, level, cachedImage->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + ec = 0; + if (!canvas) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + ImageBuffer* buffer = canvas->buffer(); + if (!buffer) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + // FIXME: For now we ignore any errors returned + m_context->texImage2D(target, level, buffer->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texImage2D(target, level, video, flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texParameterf(unsigned target, unsigned pname, float param) +{ + m_context->texParameterf(target, pname, param); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texParameteri(unsigned target, unsigned pname, int param) +{ + m_context->texParameteri(target, pname, param); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + if (!image) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + CachedImage* cachedImage = image->cachedImage(); + if (!cachedImage) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, cachedImage->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + ec = 0; + if (!canvas) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + ImageBuffer* buffer = canvas->buffer(); + if (!buffer) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + // FIXME: For now we ignore any errors returned + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, buffer->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform1f(location->location(), x); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1fv(location->location(), v->data(), v->length()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1fv(location->location(), v, size); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform1i(location->location(), x); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1iv(location->location(), v->data(), v->length()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1iv(location->location(), v, size); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform2f(location->location(), x, y); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2fv(location->location(), v->data(), v->length() / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2fv(location->location(), v, size / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform2i(location->location(), x, y); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2iv(location->location(), v->data(), v->length() / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2iv(location->location(), v, size / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform3f(location->location(), x, y, z); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3fv(location->location(), v->data(), v->length() / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3fv(location->location(), v, size / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform3i(location->location(), x, y, z); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3iv(location->location(), v->data(), v->length() / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3iv(location->location(), v, size / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform4f(location->location(), x, y, z, w); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4fv(location->location(), v->data(), v->length() / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4fv(location->location(), v, size / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform4i(location->location(), x, y, z, w); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4iv(location->location(), v->data(), v->length() / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4iv(location->location(), v, size / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniformMatrix2fv(location->location(), transpose, v->data(), v->length() / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniformMatrix2fv(location->location(), transpose, v, size / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 9 + m_context->uniformMatrix3fv(location->location(), transpose, v->data(), v->length() / 9); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 9 + m_context->uniformMatrix3fv(location->location(), transpose, v, size / 9); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 16 + m_context->uniformMatrix4fv(location->location(), transpose, v->data(), v->length() / 16); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 16 + m_context->uniformMatrix4fv(location->location(), transpose, v, size / 16); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::useProgram(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + m_currentProgram = program; + m_context->useProgram(program); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::validateProgram(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->validateProgram(program); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib1f(unsigned long indx, float v0) +{ + m_context->vertexAttrib1f(indx, v0); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib1fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib1fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib1fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib1fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib2f(unsigned long indx, float v0, float v1) +{ + m_context->vertexAttrib2f(indx, v0, v1); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib2fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib2fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib2fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib2fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2) +{ + m_context->vertexAttrib3f(indx, v0, v1, v2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib3fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib3fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib3fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib3fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3) +{ + m_context->vertexAttrib4f(indx, v0, v1, v2, v3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib4fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib4fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib4fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib4fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, unsigned long stride, unsigned long offset, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!m_boundArrayBuffer || indx >= m_maxVertexAttribs) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + if (indx >= m_vertexAttribState.size()) + m_vertexAttribState.resize(indx + 1); + + // Determine the number of elements the bound buffer can hold, given the offset, size, type and stride + long bytesPerElement = size * sizeInBytes(type, ec); + if (bytesPerElement <= 0) + return; + long validatedStride = bytesPerElement; + if (stride != 0) { + if ((long) stride < bytesPerElement) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + validatedStride = stride; + } + + // Avoid off-by-one errors in numElements computation. + // For the last element, we will only touch the data for the + // element and nothing beyond it. + long bytesRemaining = m_boundArrayBuffer->byteLength(GraphicsContext3D::ARRAY_BUFFER) - offset; + if (bytesRemaining < bytesPerElement) + m_vertexAttribState[indx].numElements = 0; + else + m_vertexAttribState[indx].numElements = 1 + (bytesRemaining - bytesPerElement) / validatedStride; + + m_context->vertexAttribPointer(indx, size, type, normalized, stride, offset); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::viewport(long x, long y, unsigned long width, unsigned long height) +{ + if (isnan(x)) + x = 0; + if (isnan(y)) + y = 0; + if (isnan(width)) + width = 100; + if (isnan(height)) + height = 100; + m_context->viewport(x, y, width, height); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::removeObject(CanvasObject* object) +{ + m_canvasObjects.remove(object); +} + +void WebGLRenderingContext::addObject(CanvasObject* object) +{ + removeObject(object); + m_canvasObjects.add(object); +} + +void WebGLRenderingContext::detachAndRemoveAllObjects() +{ + HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) + (*it)->detachContext(); + + m_canvasObjects.clear(); +} + +WebGLGetInfo WebGLRenderingContext::getBooleanParameter(unsigned long pname) +{ + unsigned char value; + m_context->getBooleanv(pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getFloatParameter(unsigned long pname) +{ + float value; + m_context->getFloatv(pname, &value); + return WebGLGetInfo(static_cast<float>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getIntParameter(unsigned long pname) +{ + return getLongParameter(pname); +} + +WebGLGetInfo WebGLRenderingContext::getLongParameter(unsigned long pname) +{ + int value; + m_context->getIntegerv(pname, &value); + return WebGLGetInfo(static_cast<long>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getUnsignedLongParameter(unsigned long pname) +{ + int value; + m_context->getIntegerv(pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getWebGLFloatArrayParameter(unsigned long pname) +{ + float value[4] = {0}; + m_context->getFloatv(pname, value); + unsigned length = 0; + switch (pname) { + case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE: + case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE: + case GraphicsContext3D::DEPTH_RANGE: + length = 2; + break; + case GraphicsContext3D::BLEND_COLOR: + case GraphicsContext3D::COLOR_CLEAR_VALUE: + length = 4; + break; + default: + notImplemented(); + } + return WebGLGetInfo(WebGLFloatArray::create(value, length)); +} + +WebGLGetInfo WebGLRenderingContext::getWebGLIntArrayParameter(unsigned long pname) +{ + int value[4] = {0}; + m_context->getIntegerv(pname, value); + unsigned length = 0; + switch (pname) { + case GraphicsContext3D::MAX_VIEWPORT_DIMS: + length = 2; + break; + case GraphicsContext3D::SCISSOR_BOX: + case GraphicsContext3D::VIEWPORT: + length = 4; + break; + default: + notImplemented(); + } + return WebGLGetInfo(WebGLIntArray::create(value, length)); +} + +WebGLGetInfo WebGLRenderingContext::getWebGLUnsignedByteArrayParameter(unsigned long pname) +{ + unsigned char value[4] = {0}; + m_context->getBooleanv(pname, value); + unsigned length = 0; + switch (pname) { + case GraphicsContext3D::COLOR_WRITEMASK: + length = 4; + break; + default: + notImplemented(); + } + return WebGLGetInfo(WebGLUnsignedByteArray::create(value, length)); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLRenderingContext.h b/WebCore/html/canvas/WebGLRenderingContext.h new file mode 100644 index 0000000..3335eba --- /dev/null +++ b/WebCore/html/canvas/WebGLRenderingContext.h @@ -0,0 +1,355 @@ +/* + * 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 WebGLRenderingContext_h +#define WebGLRenderingContext_h + +#include "CanvasRenderingContext.h" +#include "ExceptionCode.h" +#include "WebGLFloatArray.h" +#include "WebGLGetInfo.h" +#include "WebGLIntArray.h" +#include "WebGLUnsignedByteArray.h" +#include "GraphicsContext3D.h" +#include "PlatformString.h" + +namespace WebCore { + +class WebGLActiveInfo; +class WebGLBuffer; +class WebGLFramebuffer; +class CanvasObject; +class WebGLProgram; +class WebGLRenderbuffer; +class WebGLShader; +class WebGLTexture; +class WebGLUniformLocation; +class HTMLImageElement; +class HTMLVideoElement; +class ImageData; +class WebKitCSSMatrix; + + class WebGLRenderingContext : public CanvasRenderingContext { + public: + static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*); + virtual ~WebGLRenderingContext(); + + virtual bool is3d() const { return true; } + + // Helper to return the size in bytes of OpenGL data types + // like GL_FLOAT, GL_INT, etc. + int sizeInBytes(int type, ExceptionCode& ec); + + void activeTexture(unsigned long texture, ExceptionCode& ec); + void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec); + void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name, ExceptionCode& ec); + void bindBuffer(unsigned long target, WebGLBuffer*, ExceptionCode& ec); + void bindFramebuffer(unsigned long target, WebGLFramebuffer*, ExceptionCode& ec); + void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*, ExceptionCode& ec); + void bindTexture(unsigned long target, WebGLTexture*, ExceptionCode& ec); + void blendColor(double red, double green, double blue, double alpha); + void blendEquation(unsigned long mode); + void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha); + void blendFunc(unsigned long sfactor, unsigned long dfactor); + 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&); + + unsigned long checkFramebufferStatus(unsigned long target); + void clear(unsigned long mask); + void clearColor(double red, double green, double blue, double alpha); + void clearDepth(double); + void clearStencil(long); + void colorMask(bool red, bool green, bool blue, bool alpha); + void compileShader(WebGLShader*, ExceptionCode& ec); + + //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data); + //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data); + + void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border); + void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height); + + PassRefPtr<WebGLBuffer> createBuffer(); + PassRefPtr<WebGLFramebuffer> createFramebuffer(); + PassRefPtr<WebGLProgram> createProgram(); + PassRefPtr<WebGLRenderbuffer> createRenderbuffer(); + PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&); + PassRefPtr<WebGLTexture> createTexture(); + + void cullFace(unsigned long mode); + + void deleteBuffer(WebGLBuffer*); + void deleteFramebuffer(WebGLFramebuffer*); + void deleteProgram(WebGLProgram*); + void deleteRenderbuffer(WebGLRenderbuffer*); + void deleteShader(WebGLShader*); + void deleteTexture(WebGLTexture*); + + void depthFunc(unsigned long); + void depthMask(bool); + void depthRange(double zNear, double zFar); + void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&); + void disable(unsigned long cap); + void disableVertexAttribArray(unsigned long index, ExceptionCode&); + void drawArrays(unsigned long mode, long first, long count, ExceptionCode&); + void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset, ExceptionCode&); + + void enable(unsigned long cap); + void enableVertexAttribArray(unsigned long index, ExceptionCode&); + void finish(); + void flush(); + void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec); + void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec); + void frontFace(unsigned long mode); + void generateMipmap(unsigned long target); + + PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&); + PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&); + + int getAttribLocation(WebGLProgram*, const String& name); + + WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + unsigned long getError(); + + WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&); + + WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&); + + WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&); + + String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec); + + WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec); + + String getShaderInfoLog(WebGLShader*, ExceptionCode& ec); + + // TBD + // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); + + String getShaderSource(WebGLShader*, ExceptionCode&); + String getString(unsigned long name); + + WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&); + + PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&); + + WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&); + + long getVertexAttribOffset(unsigned long index, unsigned long pname); + + void hint(unsigned long target, unsigned long mode); + bool isBuffer(WebGLBuffer*); + bool isEnabled(unsigned long cap); + bool isFramebuffer(WebGLFramebuffer*); + bool isProgram(WebGLProgram*); + bool isRenderbuffer(WebGLRenderbuffer*); + bool isShader(WebGLShader*); + bool isTexture(WebGLTexture*); + void lineWidth(double); + void linkProgram(WebGLProgram*, ExceptionCode&); + 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); + + void releaseShaderCompiler(); + void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height); + void sampleCoverage(double value, bool invert); + void scissor(long x, long y, unsigned long width, unsigned long height); + void shaderSource(WebGLShader*, const String&, ExceptionCode&); + void stencilFunc(unsigned long func, long ref, unsigned long mask); + void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask); + void stencilMask(unsigned long); + void stencilMaskSeparate(unsigned long face, unsigned long mask); + void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass); + void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass); + + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + + void texParameterf(unsigned target, unsigned pname, float param); + void texParameteri(unsigned target, unsigned pname, int param); + + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, 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, 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, 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, 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, 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, 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, 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, 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, int* v, int size, ExceptionCode&); + void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* 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, float* value, int size, ExceptionCode&); + void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* 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, 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, 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, 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, float* values, int size); + void vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, + unsigned long stride, unsigned long offset, ExceptionCode&); + + void viewport(long x, long y, unsigned long width, unsigned long height); + + GraphicsContext3D* graphicsContext3D() const { return m_context.get(); } + + void reshape(int width, int height); + + // Helpers for notification about paint events. + void beginPaint(); + void endPaint(); + + void removeObject(CanvasObject*); + + private: + friend class CanvasObject; + + WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>); + + void addObject(CanvasObject*); + void detachAndRemoveAllObjects(); + + void markContextChanged(); + void cleanupAfterGraphicsCall(bool changed) + { + if (changed) + markContextChanged(); + } + + bool validateIndexArray(unsigned long count, unsigned long type, long offset, long& numElements); + bool validateRenderingState(long numElements); + + OwnPtr<GraphicsContext3D> m_context; + bool m_needsUpdate; + bool m_markedCanvasDirty; + // FIXME: I think this is broken -- it does not increment any + // reference counts, so may refer to destroyed objects. + HashSet<RefPtr<CanvasObject> > m_canvasObjects; + + // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER + RefPtr<WebGLBuffer> m_boundArrayBuffer; + RefPtr<WebGLBuffer> m_boundElementArrayBuffer; + + // Cached values for vertex attrib range checks + class VertexAttribState { + public: + VertexAttribState() : enabled(false), numElements(0) { } + bool enabled; + long numElements; + }; + + Vector<VertexAttribState> m_vertexAttribState; + unsigned m_maxVertexAttribs; + + RefPtr<WebGLProgram> m_currentProgram; + RefPtr<WebGLFramebuffer> m_framebufferBinding; + RefPtr<WebGLRenderbuffer> m_renderbufferBinding; + class TextureUnitState { + public: + RefPtr<WebGLTexture> m_texture2DBinding; + RefPtr<WebGLTexture> m_textureCubeMapBinding; + }; + TextureUnitState m_textureUnits[32]; + unsigned long m_activeTextureUnit; + + // Helpers for getParameter and others + WebGLGetInfo getBooleanParameter(unsigned long pname); + WebGLGetInfo getFloatParameter(unsigned long pname); + WebGLGetInfo getIntParameter(unsigned long pname); + WebGLGetInfo getLongParameter(unsigned long pname); + WebGLGetInfo getUnsignedLongParameter(unsigned long pname); + WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname); + WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname); + WebGLGetInfo getWebGLUnsignedByteArrayParameter(unsigned long pname); + + friend class WebGLStateRestorer; + }; + +} // namespace WebCore + +#endif diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.idl b/WebCore/html/canvas/WebGLRenderingContext.idl index db0fff3..78de8c8 100644 --- a/WebCore/html/canvas/CanvasRenderingContext3D.idl +++ b/WebCore/html/canvas/WebGLRenderingContext.idl @@ -30,7 +30,7 @@ module html { GenerateConstructor, InterfaceUUID=98fb48ae-7216-489c-862b-8e1217fc4443, ImplementationUUID=ab4f0781-152f-450e-9546-5b3987491a54 - ] CanvasRenderingContext3D : CanvasRenderingContext { + ] WebGLRenderingContext : CanvasRenderingContext { /* ClearBufferMask */ const unsigned int DEPTH_BUFFER_BIT = 0x00000100; @@ -460,25 +460,26 @@ module html { long sizeInBytes(in unsigned long type) raises(DOMException); - void activeTexture(in unsigned long texture); - void attachShader(in CanvasProgram program, in CanvasShader shader); - void bindAttribLocation(in CanvasProgram program, in unsigned long index, in DOMString name); - void bindBuffer(in unsigned long target, in CanvasBuffer buffer); - void bindFramebuffer(in unsigned long target, in CanvasFramebuffer framebuffer); - void bindRenderbuffer(in unsigned long target, in CanvasRenderbuffer renderbuffer); - void bindTexture(in unsigned long target, in CanvasTexture texture); + void activeTexture(in unsigned long texture) raises(DOMException); + void attachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); + void bindAttribLocation(in WebGLProgram program, in unsigned long index, in DOMString name) raises(DOMException); + void bindBuffer(in unsigned long target, in WebGLBuffer buffer) raises(DOMException); + void bindFramebuffer(in unsigned long target, in WebGLFramebuffer framebuffer) raises(DOMException); + void bindRenderbuffer(in unsigned long target, in WebGLRenderbuffer renderbuffer) raises(DOMException); + void bindTexture(in unsigned long target, in WebGLTexture texture) raises(DOMException); void blendColor(in double red, in double green, in double blue, in double alpha); void blendEquation( in unsigned long mode ); void blendEquationSeparate(in unsigned long modeRGB, in unsigned long modeAlpha); void blendFunc(in unsigned long sfactor, in unsigned long dfactor); void blendFuncSeparate(in unsigned long srcRGB, in unsigned long dstRGB, in unsigned long srcAlpha, in unsigned long dstAlpha); + // Supported forms: // void bufferData (in GLenum target, in GLsizei size, in GLenum usage); - // void bufferData (in GLenum target, in CanvasArray data, in GLenum usage); - [Custom] void bufferData(); + // void bufferData (in GLenum target, in WebGLArray data, in GLenum usage); + [Custom] void bufferData() raises(DOMException); // Supported forms: - // void bufferSubData (in GLenum target, in GLsizeiptr offset, in CanvasArray data); - [Custom] void bufferSubData(); + // void bufferSubData (in GLenum target, in GLsizeiptr offset, in WebGLArray data); + [Custom] void bufferSubData() raises(DOMException); unsigned long checkFramebufferStatus(in unsigned long target); void clear(in unsigned long mask); @@ -486,7 +487,7 @@ module html { void clearDepth(in double depth); void clearStencil(in long s); void colorMask(in boolean red, in boolean green, in boolean blue, in boolean alpha); - void compileShader(in CanvasShader shader); + void compileShader(in WebGLShader shader) raises(DOMException); //void compressedTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in unsigned long width, in unsigned long height, in long border, in unsigned long imageSize, const void* data); //void compressedTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long imageSize, const void* data); @@ -494,119 +495,108 @@ module html { void copyTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long x, in long y, in unsigned long width, in unsigned long height, in long border); void copyTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in long x, in long y, in unsigned long width, in unsigned long height); - CanvasBuffer createBuffer(); - CanvasFramebuffer createFramebuffer(); - CanvasProgram createProgram(); - CanvasRenderbuffer createRenderbuffer(); - CanvasShader createShader(in unsigned long type); - CanvasTexture createTexture(); + WebGLBuffer createBuffer(); + WebGLFramebuffer createFramebuffer(); + WebGLProgram createProgram(); + WebGLRenderbuffer createRenderbuffer(); + WebGLShader createShader(in unsigned long type) raises(DOMException); + WebGLTexture createTexture(); void cullFace(in unsigned long mode); - void deleteBuffer(in CanvasBuffer buffer); - void deleteFramebuffer(in CanvasFramebuffer framebuffer); - void deleteProgram(in CanvasProgram program); - void deleteRenderbuffer(in CanvasRenderbuffer renderbuffer); - void deleteShader(in CanvasShader shader); - void deleteTexture(in CanvasTexture texture); + void deleteBuffer(in WebGLBuffer buffer); + void deleteFramebuffer(in WebGLFramebuffer framebuffer); + void deleteProgram(in WebGLProgram program); + void deleteRenderbuffer(in WebGLRenderbuffer renderbuffer); + void deleteShader(in WebGLShader shader); + void deleteTexture(in WebGLTexture texture); void depthFunc(in unsigned long func); void depthMask(in boolean flag); // FIXME: this differs from the current WebGL spec (depthRangef) void depthRange(in double zNear, in double zFar); - void detachShader(in CanvasProgram program, in CanvasShader shader); + void detachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); void disable(in unsigned long cap); - void disableVertexAttribArray(in unsigned long index); - void drawArrays(in unsigned long mode, in long first, in unsigned long count); - void drawElements (in unsigned long mode, in long count, in unsigned long type, in unsigned long offset); + void disableVertexAttribArray(in unsigned long index) raises(DOMException); + void drawArrays(in unsigned long mode, in long first, in unsigned long count) raises(DOMException); + void drawElements (in unsigned long mode, in long count, in unsigned long type, in unsigned long offset) raises(DOMException); void enable(in unsigned long cap); - void enableVertexAttribArray(in unsigned long index); + void enableVertexAttribArray(in unsigned long index) raises(DOMException); void finish(); void flush(); - void framebufferRenderbuffer(in unsigned long target, in unsigned long attachment, in unsigned long renderbuffertarget, in CanvasRenderbuffer renderbuffer); - void framebufferTexture2D(in unsigned long target, in unsigned long attachment, in unsigned long textarget, in CanvasTexture texture, in long level); + void framebufferRenderbuffer(in unsigned long target, in unsigned long attachment, in unsigned long renderbuffertarget, in WebGLRenderbuffer renderbuffer) raises(DOMException); + void framebufferTexture2D(in unsigned long target, in unsigned long attachment, in unsigned long textarget, in WebGLTexture texture, in long level) raises(DOMException); void frontFace(in unsigned long mode); void generateMipmap(in unsigned long target); - // FIXME: these need to be added per the WebGL spec - CanvasActiveInfo getActiveAttrib(in CanvasProgram program, in unsigned long index) + WebGLActiveInfo getActiveAttrib(in WebGLProgram program, in unsigned long index) raises (DOMException); - CanvasActiveInfo getActiveUniform(in CanvasProgram program, in unsigned long index) + WebGLActiveInfo getActiveUniform(in WebGLProgram program, in unsigned long index) raises (DOMException); - // CanvasShaderArray glGetAttachedShaders(GLuint program); + // WebGLShaderArray glGetAttachedShaders(GLuint program); - int getAttribLocation(in CanvasProgram program, in DOMString name); + int getAttribLocation(in WebGLProgram program, in DOMString name); - boolean getBoolean(in unsigned long pname); - CanvasUnsignedByteArray getBooleanv(in unsigned long pname); - long getBufferParameteri(in unsigned long target, in unsigned long pname); - CanvasIntArray getBufferParameteriv(in unsigned long target, in unsigned long pname); + // any getBufferParameter(in unsigned long target, in unsigned long pname) raises(DOMException); + [Custom] void getBufferParameter(); unsigned long getError(); - float getFloat(in unsigned long pname); - CanvasFloatArray getFloatv(in unsigned long pname); - long getFramebufferAttachmentParameteri(in unsigned long target, in unsigned long attachment, in unsigned long pname); - CanvasIntArray getFramebufferAttachmentParameteriv(in unsigned long target, in unsigned long attachment, in unsigned long pname); - long getInteger(in unsigned long pname); - CanvasIntArray getIntegerv(in unsigned long pname); - long getProgrami(in CanvasProgram program, in unsigned long pname); - CanvasIntArray getProgramiv(in CanvasProgram program, in unsigned long pname); - DOMString getProgramInfoLog(in CanvasProgram program); - long getRenderbufferParameteri(in unsigned long target, in unsigned long pname); - CanvasIntArray getRenderbufferParameteriv(in unsigned long target, in unsigned long pname); - long getShaderi(in CanvasShader shader, in unsigned long pname); - CanvasIntArray getShaderiv(in CanvasShader shader, in unsigned long pname); - - DOMString getShaderInfoLog(in CanvasShader shader); + // any getFramebufferAttachmentParameter(in unsigned long target, in unsigned long attachment, in unsigned long pname) raises(DOMException); + [Custom] void getFramebufferAttachmentParameter(); + // any getParameter(in unsigned long pname) raises(DOMException); + [Custom] void getParameter(); + // any getProgramParameter(in WebGLProgram program, in unsigned long pname) raises(DOMException); + [Custom] void getProgramParameter(); + DOMString getProgramInfoLog(in WebGLProgram program) raises(DOMException); + // any getRenderbufferParameter(in unsigned long target, in unsigned long pname) raises(DOMException); + [Custom] void getRenderbufferParameter(); + // any getShaderParameter(in WebGLShader shader, in unsigned long pname) raises(DOMException); + [Custom] void getShaderParameter() raises(DOMException); + + DOMString getShaderInfoLog(in WebGLShader shader) raises(DOMException); // TBD // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); - DOMString getShaderSource(in CanvasShader shader); + DOMString getShaderSource(in WebGLShader shader) raises(DOMException); DOMString getString(in unsigned long name); - float getTexParameterf(in unsigned long target, in unsigned long pname); - CanvasFloatArray getTexParameterfv(in unsigned long target, in unsigned long pname); - long getTexParameteri(in unsigned long target, in unsigned long pname); - CanvasIntArray getTexParameteriv(in unsigned long target, in unsigned long pname); + // any getTexParameter(in unsigned long target, in unsigned long pname) raises(DOMException); + [Custom] void getTexParameter(); - float getUniformf(in CanvasProgram program, in long location); - CanvasFloatArray getUniformfv(in CanvasProgram program, in long location); - long getUniformi(in CanvasProgram program, in long location); - CanvasIntArray getUniformiv(in CanvasProgram program, in long location); - - long getUniformLocation(in CanvasProgram program, in DOMString name); + // any getUniform(in WebGLProgram program, in WebGLUniformLocation location) raises(DOMException); + [Custom] void getUniform(); - float getVertexAttribf(in unsigned long index, in unsigned long pname); - CanvasFloatArray getVertexAttribfv(in unsigned long index, in unsigned long pname); - long getVertexAttribi(in unsigned long index, in unsigned long pname); - CanvasIntArray getVertexAttribiv(in unsigned long index, in unsigned long pname); + WebGLUniformLocation getUniformLocation(in WebGLProgram program, in DOMString name) raises(DOMException); + + // any getVertexAttrib(in unsigned long index, in unsigned long pname) raises(DOMException); + [Custom] void getVertexAttrib(); long getVertexAttribOffset(in unsigned long index, in unsigned long pname); void hint(in unsigned long target, in unsigned long mode); - boolean isBuffer(in CanvasBuffer buffer); + boolean isBuffer(in WebGLBuffer buffer); boolean isEnabled(in unsigned long cap); - boolean isFramebuffer(in CanvasFramebuffer framebuffer); - boolean isProgram(in CanvasProgram program); - boolean isRenderbuffer(in CanvasRenderbuffer renderbuffer); - boolean isShader(in CanvasShader shader); - boolean isTexture(in CanvasTexture texture); + boolean isFramebuffer(in WebGLFramebuffer framebuffer); + boolean isProgram(in WebGLProgram program); + boolean isRenderbuffer(in WebGLRenderbuffer renderbuffer); + boolean isShader(in WebGLShader shader); + boolean isTexture(in WebGLTexture texture); void lineWidth(in double width); - void linkProgram(in CanvasProgram program); + void linkProgram(in WebGLProgram program) raises(DOMException); void pixelStorei(in unsigned long pname, in long param); void polygonOffset(in double factor, in double units); - - CanvasArray readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type); + + WebGLArray 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); void sampleCoverage(in double value, in boolean invert); void scissor(in long x, in long y, in unsigned long width, in unsigned long height); - void shaderSource(in CanvasShader shader, in DOMString string); + void shaderSource(in WebGLShader shader, in DOMString string) raises(DOMException); void stencilFunc(in unsigned long func, in long ref, in unsigned long mask); void stencilFuncSeparate(in unsigned long face, in unsigned long func, in long ref, in unsigned long mask); void stencilMask(in unsigned long mask); @@ -619,7 +609,7 @@ module html { // Supported forms: // void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, - // in GLint border, in GLenum format, in GLenum type, in CanvasArray pixels); + // in GLint border, in GLenum format, in GLenum type, in WebGLArray pixels); // void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, // in GLint border, in GLenum format, in GLenum type, in ImageData pixels); // void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image, @@ -633,7 +623,7 @@ module html { // Supported forms: // void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, // in GLsizei width, in GLsizei height, - // in GLenum format, in GLenum type, in CanvasArray pixels); + // in GLenum format, in GLenum type, in WebGLArray pixels); // void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, // in GLsizei width, in GLsizei height, // in GLenum format, in GLenum type, in ImageData pixels); @@ -648,40 +638,40 @@ module html { // [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); [Custom] void texSubImage2D(); - void uniform1f(in long location, in float x); - [Custom] void uniform1fv(in long location, in CanvasFloatArray v); - void uniform1i(in long location, in long x); - [Custom] void uniform1iv(in long location, in CanvasIntArray v); - void uniform2f(in long location, in float x, in float y); - [Custom] void uniform2fv(in long location, in CanvasFloatArray v); - void uniform2i(in long location, in long x, in long y); - [Custom] void uniform2iv(in long location, in CanvasIntArray v); - void uniform3f(in long location, in float x, in float y, in float z); - [Custom] void uniform3fv(in long location, in CanvasFloatArray v); - void uniform3i(in long location, in long x, in long y, in long z); - [Custom] void uniform3iv(in long location, in CanvasIntArray v); - void uniform4f(in long location, in float x, in float y, in float z, in float w); - [Custom] void uniform4fv(in long location, in CanvasFloatArray v); - void uniform4i(in long location, in long x, in long y, in long z, in long w); - [Custom] void uniform4iv(in long location, in CanvasIntArray v); - - [Custom] void uniformMatrix2fv(in long location, in boolean transpose, in CanvasFloatArray array); - [Custom] void uniformMatrix3fv(in long location, in boolean transpose, in CanvasFloatArray array); - [Custom] void uniformMatrix4fv(in long location, in boolean transpose, in CanvasFloatArray array); - - void useProgram(in CanvasProgram program); - void validateProgram(in CanvasProgram program); + void uniform1f(in WebGLUniformLocation location, in float x) raises(DOMException); + [Custom] void uniform1fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + void uniform1i(in WebGLUniformLocation location, in long x) raises(DOMException); + [Custom] void uniform1iv(in WebGLUniformLocation location, in WebGLIntArray 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); + void uniform2i(in WebGLUniformLocation location, in long x, in long y) raises(DOMException); + [Custom] void uniform2iv(in WebGLUniformLocation location, in WebGLIntArray 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); + 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); + 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); + 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 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); + + 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 CanvasFloatArray values); + [Custom] void vertexAttrib1fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttrib2f(in unsigned long indx, in float x, in float y); - [Custom] void vertexAttrib2fv(in unsigned long indx, in CanvasFloatArray values); + [Custom] void vertexAttrib2fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttrib3f(in unsigned long indx, in float x, in float y, in float z); - [Custom] void vertexAttrib3fv(in unsigned long indx, in CanvasFloatArray values); + [Custom] void vertexAttrib3fv(in unsigned long indx, in WebGLFloatArray 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 CanvasFloatArray values); + [Custom] void vertexAttrib4fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttribPointer(in unsigned long indx, in long size, in unsigned long type, in boolean normalized, - in long stride, in unsigned long offset); + in long stride, in unsigned long offset) raises(DOMException); void viewport(in long x, in long y, in unsigned long width, in unsigned long height); }; diff --git a/WebCore/html/canvas/CanvasShader.cpp b/WebCore/html/canvas/WebGLShader.cpp index 7f134fa..a353b15 100644 --- a/WebCore/html/canvas/CanvasShader.cpp +++ b/WebCore/html/canvas/WebGLShader.cpp @@ -27,23 +27,23 @@ #if ENABLE(3D_CANVAS) -#include "CanvasShader.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLShader.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasShader> CanvasShader::create(CanvasRenderingContext3D* ctx, GraphicsContext3D::ShaderType type) +PassRefPtr<WebGLShader> WebGLShader::create(WebGLRenderingContext* ctx, GraphicsContext3D::WebGLEnumType type) { - return adoptRef(new CanvasShader(ctx, type)); + return adoptRef(new WebGLShader(ctx, type)); } -CanvasShader::CanvasShader(CanvasRenderingContext3D* ctx, GraphicsContext3D::ShaderType type) +WebGLShader::WebGLShader(WebGLRenderingContext* ctx, GraphicsContext3D::WebGLEnumType type) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createShader(type)); } -void CanvasShader::_deleteObject(Platform3DObject object) +void WebGLShader::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteShader(object); } diff --git a/WebCore/html/canvas/CanvasShader.h b/WebCore/html/canvas/WebGLShader.h index bb7980e..1ef912c 100644 --- a/WebCore/html/canvas/CanvasShader.h +++ b/WebCore/html/canvas/WebGLShader.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasShader_h -#define CanvasShader_h +#ifndef WebGLShader_h +#define WebGLShader_h #include "CanvasObject.h" @@ -33,18 +33,18 @@ namespace WebCore { - class CanvasShader : public CanvasObject { + class WebGLShader : public CanvasObject { public: - virtual ~CanvasShader() { deleteObject(); } + virtual ~WebGLShader() { deleteObject(); } - static PassRefPtr<CanvasShader> create(CanvasRenderingContext3D*, GraphicsContext3D::ShaderType); + static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); private: - CanvasShader(CanvasRenderingContext3D*, GraphicsContext3D::ShaderType); + WebGLShader(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasShader_h +#endif // WebGLShader_h diff --git a/WebCore/html/canvas/CanvasTexture.idl b/WebCore/html/canvas/WebGLShader.idl index 77eedd7..45e7f54 100644 --- a/WebCore/html/canvas/CanvasTexture.idl +++ b/WebCore/html/canvas/WebGLShader.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasTexture { + interface [Conditional=3D_CANVAS] WebGLShader { }; } diff --git a/WebCore/html/canvas/WebGLShortArray.cpp b/WebCore/html/canvas/WebGLShortArray.cpp new file mode 100644 index 0000000..f96a290 --- /dev/null +++ b/WebCore/html/canvas/WebGLShortArray.cpp @@ -0,0 +1,98 @@ +/* + * 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, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(short)) != 0) + return NULL; + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(short))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLShortArray(buffer, byteOffset, length)); +} + +WebGLShortArray::WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int 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(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(short); + unsigned limitByte = startByte + length * sizeof(short); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, 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 new file mode 100644 index 0000000..70c66ca --- /dev/null +++ b/WebCore/html/canvas/WebGLShortArray.h @@ -0,0 +1,94 @@ +/* + * 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, int byteOffset, unsigned length); + + short* data() { return static_cast<short*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + 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, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLShortArray_h diff --git a/WebCore/html/canvas/CanvasFloatArray.idl b/WebCore/html/canvas/WebGLShortArray.idl index bb236b9..bd8380f 100644 --- a/WebCore/html/canvas/CanvasFloatArray.idl +++ b/WebCore/html/canvas/WebGLShortArray.idl @@ -31,6 +31,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasFloatArray : CanvasArray { + ] 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); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/CanvasTexture.cpp b/WebCore/html/canvas/WebGLTexture.cpp index 624c275..ae09b48 100644 --- a/WebCore/html/canvas/CanvasTexture.cpp +++ b/WebCore/html/canvas/WebGLTexture.cpp @@ -27,24 +27,36 @@ #if ENABLE(3D_CANVAS) -#include "CanvasTexture.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLTexture.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasTexture> CanvasTexture::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasTexture(ctx)); + return adoptRef(new WebGLTexture(ctx)); } -CanvasTexture::CanvasTexture(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx, Platform3DObject obj) +{ + return adoptRef(new WebGLTexture(ctx, obj)); +} + +WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) : CanvasObject(ctx) , cubeMapRWrapModeInitialized(false) { setObject(context()->graphicsContext3D()->createTexture()); } -void CanvasTexture::_deleteObject(Platform3DObject object) +WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx, Platform3DObject obj) + : CanvasObject(ctx) + , cubeMapRWrapModeInitialized(false) +{ + setObject(obj, false); +} + +void WebGLTexture::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteTexture(object); } diff --git a/WebCore/html/canvas/CanvasTexture.h b/WebCore/html/canvas/WebGLTexture.h index 32a669a..c64dd41 100644 --- a/WebCore/html/canvas/CanvasTexture.h +++ b/WebCore/html/canvas/WebGLTexture.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasTexture_h -#define CanvasTexture_h +#ifndef WebGLTexture_h +#define WebGLTexture_h #include "CanvasObject.h" @@ -33,12 +33,16 @@ namespace WebCore { - class CanvasTexture : public CanvasObject { + class WebGLTexture : public CanvasObject { public: - virtual ~CanvasTexture() { deleteObject(); } + virtual ~WebGLTexture() { deleteObject(); } - static PassRefPtr<CanvasTexture> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*); + // For querying previously created objects via e.g. getFramebufferAttachmentParameter + // FIXME: should consider canonicalizing these objects + static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*, Platform3DObject); + bool isCubeMapRWrapModeInitialized() { return cubeMapRWrapModeInitialized; } @@ -48,7 +52,8 @@ namespace WebCore { } protected: - CanvasTexture(CanvasRenderingContext3D*); + WebGLTexture(WebGLRenderingContext*); + WebGLTexture(WebGLRenderingContext*, Platform3DObject); virtual void _deleteObject(Platform3DObject); @@ -58,4 +63,4 @@ namespace WebCore { } // namespace WebCore -#endif // CanvasTexture_h +#endif // WebGLTexture_h diff --git a/WebCore/html/canvas/CanvasProgram.idl b/WebCore/html/canvas/WebGLTexture.idl index 46daaf2..da7e066 100644 --- a/WebCore/html/canvas/CanvasProgram.idl +++ b/WebCore/html/canvas/WebGLTexture.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasProgram { + interface [Conditional=3D_CANVAS] WebGLTexture { }; } diff --git a/WebCore/html/canvas/CanvasBuffer.cpp b/WebCore/html/canvas/WebGLUniformLocation.cpp index 009f8ad..2157470 100644 --- a/WebCore/html/canvas/CanvasBuffer.cpp +++ b/WebCore/html/canvas/WebGLUniformLocation.cpp @@ -1,5 +1,6 @@ /* * 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 @@ -27,25 +28,19 @@ #if ENABLE(3D_CANVAS) -#include "CanvasBuffer.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLUniformLocation.h" namespace WebCore { -PassRefPtr<CanvasBuffer> CanvasBuffer::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLUniformLocation> WebGLUniformLocation::create(WebGLProgram* program, long location) { - return adoptRef(new CanvasBuffer(ctx)); + return adoptRef(new WebGLUniformLocation(program, location)); } -CanvasBuffer::CanvasBuffer(CanvasRenderingContext3D* ctx) - : CanvasObject(ctx) +WebGLUniformLocation::WebGLUniformLocation(WebGLProgram* program, long location) + : m_program(program) + , m_location(location) { - setObject(context()->graphicsContext3D()->createBuffer()); -} - -void CanvasBuffer::_deleteObject(Platform3DObject object) -{ - context()->graphicsContext3D()->deleteBuffer(object); } } diff --git a/WebCore/html/canvas/CanvasBuffer.h b/WebCore/html/canvas/WebGLUniformLocation.h index 8fdab82..f9f7a11 100644 --- a/WebCore/html/canvas/CanvasBuffer.h +++ b/WebCore/html/canvas/WebGLUniformLocation.h @@ -1,5 +1,6 @@ /* * 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 @@ -23,28 +24,35 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasBuffer_h -#define CanvasBuffer_h +#ifndef WebGLUniformLocation_h +#define WebGLUniformLocation_h #include "CanvasObject.h" +#include "WebGLProgram.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class CanvasBuffer : public CanvasObject { - public: - virtual ~CanvasBuffer() { deleteObject(); } - - static PassRefPtr<CanvasBuffer> create(CanvasRenderingContext3D*); - - protected: - CanvasBuffer(CanvasRenderingContext3D*); - - virtual void _deleteObject(Platform3DObject o); - }; - + +class WebGLUniformLocation : public RefCounted<WebGLUniformLocation> { +public: + virtual ~WebGLUniformLocation() { } + + static PassRefPtr<WebGLUniformLocation> create(WebGLProgram* program, long location); + + WebGLProgram* program() const { return m_program.get(); } + + long location() const { return m_location; } + +protected: + WebGLUniformLocation(WebGLProgram* program, long location); + +private: + RefPtr<WebGLProgram> m_program; + long m_location; +}; + } // namespace WebCore -#endif // CanvasBuffer_h +#endif // WebGLUniformLocation_h diff --git a/WebCore/html/canvas/WebGLUniformLocation.idl b/WebCore/html/canvas/WebGLUniformLocation.idl new file mode 100644 index 0000000..b080241 --- /dev/null +++ b/WebCore/html/canvas/WebGLUniformLocation.idl @@ -0,0 +1,30 @@ +/* + * 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] WebGLUniformLocation { + }; +} diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.cpp b/WebCore/html/canvas/WebGLUnsignedByteArray.cpp new file mode 100644 index 0000000..3fd1b50 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedByteArray.cpp @@ -0,0 +1,95 @@ +/* + * 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, + int byteOffset, + unsigned length) +{ + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(unsigned char))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLUnsignedByteArray(buffer, byteOffset, length)); +} + +WebGLUnsignedByteArray::WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int 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(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(unsigned char); + unsigned limitByte = startByte + length * sizeof(unsigned char); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, 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 new file mode 100644 index 0000000..6909de5 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedByteArray.h @@ -0,0 +1,95 @@ +/* + * 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, int byteOffset, unsigned length); + + unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + 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, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLUnsignedByteArray_h diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.idl b/WebCore/html/canvas/WebGLUnsignedByteArray.idl new file mode 100644 index 0000000..57aa4ff --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedByteArray.idl @@ -0,0 +1,42 @@ +/* + * 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, + GenerateCustomConstructor, + 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); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); + }; +} diff --git a/WebCore/html/canvas/WebGLUnsignedIntArray.cpp b/WebCore/html/canvas/WebGLUnsignedIntArray.cpp new file mode 100644 index 0000000..97910f9 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedIntArray.cpp @@ -0,0 +1,100 @@ +/* + * 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, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(unsigned int)) != 0) { + return NULL; + } + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(unsigned int))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLUnsignedIntArray(buffer, byteOffset, length)); +} + +WebGLUnsignedIntArray::WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int 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(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(unsigned int); + unsigned limitByte = startByte + length * sizeof(unsigned int); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, 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 new file mode 100644 index 0000000..b0d9b65 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedIntArray.h @@ -0,0 +1,95 @@ +/* + * 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, int byteOffset, unsigned length); + + unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + 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, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLUnsignedIntArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.idl b/WebCore/html/canvas/WebGLUnsignedIntArray.idl index 3ab60d6..8697e70 100644 --- a/WebCore/html/canvas/CanvasUnsignedIntArray.idl +++ b/WebCore/html/canvas/WebGLUnsignedIntArray.idl @@ -1,5 +1,6 @@ /* * 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 @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasUnsignedIntArray : CanvasArray { + ] WebGLUnsignedIntArray : WebGLArray { + 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(); }; } diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.cpp b/WebCore/html/canvas/WebGLUnsignedShortArray.cpp new file mode 100644 index 0000000..86fae8c --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedShortArray.cpp @@ -0,0 +1,102 @@ +/* + * 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, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(unsigned short)) != 0) { + return NULL; + } + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(unsigned short))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLUnsignedShortArray(buffer, byteOffset, length)); +} + +WebGLUnsignedShortArray::WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer, + int 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(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(unsigned short); + unsigned limitByte = startByte + length * sizeof(unsigned short); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, 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 new file mode 100644 index 0000000..3bad1b6 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedShortArray.h @@ -0,0 +1,96 @@ +/* + * 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, int byteOffset, unsigned length); + + unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + 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,int byteOffset,unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLUnsignedShortArray_h diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.idl b/WebCore/html/canvas/WebGLUnsignedShortArray.idl new file mode 100644 index 0000000..d546444 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedShortArray.idl @@ -0,0 +1,42 @@ +/* + * 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, + GenerateCustomConstructor, + 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); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); + }; +} |