diff options
Diffstat (limited to 'WebCore/html/canvas')
33 files changed, 1191 insertions, 1076 deletions
diff --git a/WebCore/html/canvas/ArrayBuffer.cpp b/WebCore/html/canvas/ArrayBuffer.cpp index 0ba2ffd..3b204ff 100644 --- a/WebCore/html/canvas/ArrayBuffer.cpp +++ b/WebCore/html/canvas/ArrayBuffer.cpp @@ -53,26 +53,32 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other) ArrayBuffer::ArrayBuffer(void* data, unsigned sizeInBytes) : m_sizeInBytes(sizeInBytes) - , m_data(data) { + , m_data(data) +{ } -void* ArrayBuffer::data() { +void* ArrayBuffer::data() +{ return m_data; } -const void* ArrayBuffer::data() const { +const void* ArrayBuffer::data() const +{ return m_data; } -unsigned ArrayBuffer::byteLength() const { +unsigned ArrayBuffer::byteLength() const +{ return m_sizeInBytes; } -ArrayBuffer::~ArrayBuffer() { +ArrayBuffer::~ArrayBuffer() +{ WTF::fastFree(m_data); } -void* ArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize) { +void* ArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize) +{ void* result; // Do not allow 32-bit overflow of the total size if (numElements) { diff --git a/WebCore/html/canvas/ArrayBufferView.cpp b/WebCore/html/canvas/ArrayBufferView.cpp index 787fd61..bd22f88 100644 --- a/WebCore/html/canvas/ArrayBufferView.cpp +++ b/WebCore/html/canvas/ArrayBufferView.cpp @@ -28,6 +28,7 @@ #if ENABLE(3D_CANVAS) #include "ArrayBufferView.h" + #include "ArrayBuffer.h" namespace WebCore { @@ -46,9 +47,9 @@ ArrayBufferView::~ArrayBufferView() void ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset, ExceptionCode& ec) { - if (byteOffset > byteLength() || - byteOffset + array->byteLength() > byteLength() || - byteOffset + array->byteLength() < byteOffset) { + if (byteOffset > byteLength() + || byteOffset + array->byteLength() > byteLength() + || byteOffset + array->byteLength() < byteOffset) { // Out of range offset or overflow ec = INDEX_SIZE_ERR; return; diff --git a/WebCore/html/canvas/ArrayBufferView.h b/WebCore/html/canvas/ArrayBufferView.h index dcf6d13..29ad691 100644 --- a/WebCore/html/canvas/ArrayBufferView.h +++ b/WebCore/html/canvas/ArrayBufferView.h @@ -26,13 +26,14 @@ #ifndef ArrayBufferView_h #define ArrayBufferView_h -#include <algorithm> +#include "ArrayBuffer.h" #include "ExceptionCode.h" + +#include <algorithm> #include <limits.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> -#include "ArrayBuffer.h" namespace WebCore { diff --git a/WebCore/html/canvas/CanvasGradient.h b/WebCore/html/canvas/CanvasGradient.h index 0a77652..7550f9b 100644 --- a/WebCore/html/canvas/CanvasGradient.h +++ b/WebCore/html/canvas/CanvasGradient.h @@ -28,13 +28,12 @@ #define CanvasGradient_h #include "Gradient.h" +#include <wtf/Forward.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - class String; - typedef int ExceptionCode; class CanvasGradient : public RefCounted<CanvasGradient> { diff --git a/WebCore/html/canvas/CanvasNumberArray.h b/WebCore/html/canvas/CanvasNumberArray.h index eb79866..09714a0 100644 --- a/WebCore/html/canvas/CanvasNumberArray.h +++ b/WebCore/html/canvas/CanvasNumberArray.h @@ -26,6 +26,7 @@ #ifndef CanvasNumberArray_h #define CanvasNumberArray_h +#include <wtf/Forward.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> @@ -33,8 +34,6 @@ namespace WebCore { - class String; - class CanvasNumberArray : public RefCounted<CanvasNumberArray> { public: static PassRefPtr<CanvasNumberArray> create(unsigned length); diff --git a/WebCore/html/canvas/CanvasObject.h b/WebCore/html/canvas/CanvasObject.h deleted file mode 100644 index 6f89f12..0000000 --- a/WebCore/html/canvas/CanvasObject.h +++ /dev/null @@ -1,79 +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 CanvasObject_h -#define CanvasObject_h - -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -#include "GraphicsContext3D.h" - -namespace WebCore { - - class WebGLRenderingContext; - - class CanvasObject : public RefCounted<CanvasObject> { - public: - virtual ~CanvasObject(); - - Platform3DObject object() const { return m_object; } - void setObject(Platform3DObject, bool shouldDeleteObject = true); - void deleteObject(); - - void detachContext() - { - deleteObject(); - m_context = 0; - } - - WebGLRenderingContext* context() const { return m_context; } - - virtual bool isBuffer() const { return false; } - virtual bool isFramebuffer() const { return false; } - virtual bool isProgram() const { return false; } - virtual bool isRenderbuffer() const { return false; } - virtual bool isShader() const { return false; } - virtual bool isTexture() const { return false; } - - protected: - CanvasObject(WebGLRenderingContext*); - virtual void _deleteObject(Platform3DObject) = 0; - - private: - Platform3DObject m_object; - // 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 - -#endif // CanvasObject_h diff --git a/WebCore/html/canvas/CanvasPattern.h b/WebCore/html/canvas/CanvasPattern.h index 6c012d1..91e0794 100644 --- a/WebCore/html/canvas/CanvasPattern.h +++ b/WebCore/html/canvas/CanvasPattern.h @@ -27,13 +27,13 @@ #define CanvasPattern_h #include "Pattern.h" +#include <wtf/Forward.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { class Image; - class String; typedef int ExceptionCode; diff --git a/WebCore/html/canvas/CanvasRenderingContext.h b/WebCore/html/canvas/CanvasRenderingContext.h index 2ee1693..cb26363 100644 --- a/WebCore/html/canvas/CanvasRenderingContext.h +++ b/WebCore/html/canvas/CanvasRenderingContext.h @@ -30,7 +30,8 @@ namespace WebCore { - class CanvasObject; + class WebGLObject; + class GraphicsContext3D; class HTMLCanvasElement; class CanvasRenderingContext : public Noncopyable { @@ -47,6 +48,12 @@ namespace WebCore { virtual bool is2d() const { return false; } virtual bool is3d() const { return false; } virtual bool isAccelerated() const { return false; } + + // For accelerated canvases, returns a pointer to the underlying GraphicsContext3D. + // For non accelerated canvases returns 0. + virtual GraphicsContext3D* graphicsContext3D() const { return 0; } + + virtual void paintRenderingResultsToCanvas() {} private: HTMLCanvasElement* m_canvas; diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 3b05348..559ddda 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -58,7 +58,13 @@ #include "StrokeStyleApplier.h" #include "TextMetrics.h" -#include <stdio.h> +#if ENABLE(ACCELERATED_2D_CANVAS) +#include "FrameView.h" +#include "GraphicsContext3D.h" +#if USE(ACCELERATED_COMPOSITING) +#include "RenderLayer.h" +#endif +#endif #include <wtf/ByteArray.h> #include <wtf/MathExtras.h> @@ -100,6 +106,9 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo #if ENABLE(DASHBOARD_SUPPORT) , m_usesDashboardCompatibilityMode(usesDashboardCompatibilityMode) #endif +#if ENABLE(ACCELERATED_2D_CANVAS) + , m_context3D(0) +#endif { #if !ENABLE(DASHBOARD_SUPPORT) ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMode); @@ -108,17 +117,53 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo // Make sure that even if the drawingContext() has a different default // thickness, it is in sync with the canvas thickness. setLineWidth(lineWidth()); + +#if ENABLE(ACCELERATED_2D_CANVAS) + Page* p = canvas->document()->page(); + if (!p) + return; + if (!p->settings()->accelerated2dCanvasEnabled()) + return; + if (FrameView* view = canvas->document()->view()) { + if (ScrollView* rootView = view->root()) { + if (HostWindow* hostWindow = view->root()->hostWindow()) { + // Set up our context + GraphicsContext3D::Attributes attr; + attr.stencil = true; + m_context3D = GraphicsContext3D::create(attr, hostWindow); + if (m_context3D) + if (GraphicsContext* c = drawingContext()) + c->setGraphicsContext3D(m_context3D.get(), IntSize(canvas->width(), canvas->height())); + } + } + } +#endif } CanvasRenderingContext2D::~CanvasRenderingContext2D() { } +bool CanvasRenderingContext2D::isAccelerated() const +{ +#if ENABLE(ACCELERATED_2D_CANVAS) + return m_context3D; +#else + return false; +#endif +} + void CanvasRenderingContext2D::reset() { m_stateStack.resize(1); m_stateStack.first() = State(); m_path.clear(); +#if ENABLE(ACCELERATED_2D_CANVAS) + if (m_context3D) { + if (GraphicsContext* c = drawingContext()) + c->setGraphicsContext3D(m_context3D.get(), IntSize(canvas()->width(), canvas()->height())); + } +#endif } CanvasRenderingContext2D::State::State() @@ -511,6 +556,8 @@ void CanvasRenderingContext2D::setStrokeColor(const String& color) void CanvasRenderingContext2D::setStrokeColor(float grayLevel) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, 1.0f)) + return; setStrokeStyle(CanvasStyle::create(grayLevel, 1)); } @@ -521,16 +568,22 @@ void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha) void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, alpha)) + return; setStrokeStyle(CanvasStyle::create(grayLevel, alpha)); } void CanvasRenderingContext2D::setStrokeColor(float r, float g, float b, float a) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(r, g, b, a)) + return; setStrokeStyle(CanvasStyle::create(r, g, b, a)); } void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k, float a) { + if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(c, m, y, k, a)) + return; setStrokeStyle(CanvasStyle::create(c, m, y, k, a)); } @@ -544,6 +597,8 @@ void CanvasRenderingContext2D::setFillColor(const String& color) void CanvasRenderingContext2D::setFillColor(float grayLevel) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, 1.0f)) + return; setFillStyle(CanvasStyle::create(grayLevel, 1)); } @@ -554,16 +609,22 @@ void CanvasRenderingContext2D::setFillColor(const String& color, float alpha) void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(grayLevel, grayLevel, grayLevel, alpha)) + return; setFillStyle(CanvasStyle::create(grayLevel, alpha)); } void CanvasRenderingContext2D::setFillColor(float r, float g, float b, float a) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(r, g, b, a)) + return; setFillStyle(CanvasStyle::create(r, g, b, a)); } void CanvasRenderingContext2D::setFillColor(float c, float m, float y, float k, float a) { + if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(c, m, y, k, a)) + return; setFillStyle(CanvasStyle::create(c, m, y, k, a)); } @@ -1434,7 +1495,14 @@ void CanvasRenderingContext2D::willDraw(const FloatRect& r, unsigned options) // we'd have to keep the clip path around. } - canvas()->willDraw(dirtyRect); +#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING) + // If we are drawing to hardware and we have a composited layer, just call rendererContentChanged(). + RenderBox* renderBox = canvas()->renderBox(); + if (m_context3D && renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing()) + renderBox->layer()->rendererContentChanged(); + else +#endif + canvas()->willDraw(dirtyRect); } GraphicsContext* CanvasRenderingContext2D::drawingContext() const @@ -1772,4 +1840,11 @@ const Font& CanvasRenderingContext2D::accessFont() return state().m_font; } +void CanvasRenderingContext2D::paintRenderingResultsToCanvas() +{ +#if ENABLE(ACCELERATED_2D_CANVAS) + drawingContext()->syncSoftwareCanvas(); +#endif +} + } // namespace WebCore diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.h b/WebCore/html/canvas/CanvasRenderingContext2D.h index 22ed7fc..f610250 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.h +++ b/WebCore/html/canvas/CanvasRenderingContext2D.h @@ -42,6 +42,10 @@ #include <ApplicationServices/ApplicationServices.h> #endif +#if USE(ACCELERATED_COMPOSITING) +#include "GraphicsLayer.h" +#endif + namespace WebCore { class CanvasGradient; @@ -56,6 +60,10 @@ class ImageData; class KURL; class TextMetrics; +#if ENABLE(ACCELERATED_2D_CANVAS) +class GraphicsContext3D; +#endif + typedef int ExceptionCode; class CanvasRenderingContext2D : public CanvasRenderingContext { @@ -65,6 +73,7 @@ public: virtual ~CanvasRenderingContext2D(); virtual bool is2d() const { return true; } + virtual bool isAccelerated() const; CanvasStyle* strokeStyle() const; void setStrokeStyle(PassRefPtr<CanvasStyle>); @@ -212,6 +221,12 @@ public: LineCap getLineCap() const { return state().m_lineCap; } LineJoin getLineJoin() const { return state().m_lineJoin; } + virtual void paintRenderingResultsToCanvas(); + +#if ENABLE(ACCELERATED_2D_CANVAS) + virtual GraphicsContext3D* graphicsContext3D() const { return m_context3D.get(); } +#endif + private: struct State { State(); @@ -281,6 +296,10 @@ private: #if ENABLE(DASHBOARD_SUPPORT) bool m_usesDashboardCompatibilityMode; #endif + +#if ENABLE(ACCELERATED_2D_CANVAS) + OwnPtr<GraphicsContext3D> m_context3D; +#endif }; } // namespace WebCore diff --git a/WebCore/html/canvas/CanvasStyle.cpp b/WebCore/html/canvas/CanvasStyle.cpp index 1ae5236..52b31c8 100644 --- a/WebCore/html/canvas/CanvasStyle.cpp +++ b/WebCore/html/canvas/CanvasStyle.cpp @@ -144,6 +144,26 @@ bool CanvasStyle::isEquivalentColor(const CanvasStyle& other) const return false; } +bool CanvasStyle::isEquivalentColor(float r, float g, float b, float a) const +{ + if (m_type != RGBA) + return false; + + return m_rgba == makeRGBA32FromFloats(r, g, b, a); +} + +bool CanvasStyle::isEquivalentColor(float c, float m, float y, float k, float a) const +{ + if (m_type != CMYKA) + return false; + + return c == m_cmyka.c + && m == m_cmyka.m + && y == m_cmyka.y + && k == m_cmyka.k + && a == m_cmyka.a; +} + void CanvasStyle::applyStrokeColor(GraphicsContext* context) { if (!context) diff --git a/WebCore/html/canvas/CanvasStyle.h b/WebCore/html/canvas/CanvasStyle.h index 76ba6ef..8e47e63 100644 --- a/WebCore/html/canvas/CanvasStyle.h +++ b/WebCore/html/canvas/CanvasStyle.h @@ -56,6 +56,8 @@ namespace WebCore { void applyStrokeColor(GraphicsContext*); bool isEquivalentColor(const CanvasStyle&) const; + bool isEquivalentColor(float r, float g, float b, float a) const; + bool isEquivalentColor(float c, float m, float y, float k, float a) const; private: CanvasStyle(RGBA32 rgba); diff --git a/WebCore/html/canvas/TypedArrayBase.h b/WebCore/html/canvas/TypedArrayBase.h index a8bebd9..c55896b 100644 --- a/WebCore/html/canvas/TypedArrayBase.h +++ b/WebCore/html/canvas/TypedArrayBase.h @@ -27,8 +27,8 @@ #ifndef TypedArrayBase_h #define TypedArrayBase_h -#include "ArrayBufferView.h" #include "ArrayBuffer.h" +#include "ArrayBufferView.h" namespace WebCore { diff --git a/WebCore/html/canvas/WebGLBuffer.cpp b/WebCore/html/canvas/WebGLBuffer.cpp index e449052..fc98a9d 100644 --- a/WebCore/html/canvas/WebGLBuffer.cpp +++ b/WebCore/html/canvas/WebGLBuffer.cpp @@ -28,6 +28,8 @@ #if ENABLE(3D_CANVAS) #include "WebGLBuffer.h" + +#include "CheckedInt.h" #include "WebGLRenderingContext.h" namespace WebCore { @@ -38,7 +40,7 @@ PassRefPtr<WebGLBuffer> WebGLBuffer::create(WebGLRenderingContext* ctx) } WebGLBuffer::WebGLBuffer(WebGLRenderingContext* ctx) - : CanvasObject(ctx) + : WebGLObject(ctx) , m_target(0) , m_byteLength(0) , m_nextAvailableCacheEntry(0) @@ -47,153 +49,116 @@ WebGLBuffer::WebGLBuffer(WebGLRenderingContext* ctx) clearCachedMaxIndices(); } -void WebGLBuffer::_deleteObject(Platform3DObject object) +void WebGLBuffer::deleteObjectImpl(Platform3DObject object) { context()->graphicsContext3D()->deleteBuffer(object); } -bool WebGLBuffer::associateBufferData(int size) +bool WebGLBuffer::associateBufferDataImpl(ArrayBuffer* array, unsigned byteOffset, unsigned byteLength) { - if (!m_target) - return false; + if (array && byteLength) { + CheckedInt<uint32_t> checkedOffset(byteOffset); + CheckedInt<uint32_t> checkedLength(byteLength); + CheckedInt<uint32_t> checkedMax = checkedOffset + checkedLength; + if (!checkedMax.valid() || checkedMax.value() > array->byteLength()) + return false; + } - if (m_target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { - m_byteLength = size; + switch (m_target) { + case GraphicsContext3D::ELEMENT_ARRAY_BUFFER: + m_byteLength = byteLength; clearCachedMaxIndices(); - m_elementArrayBuffer = ArrayBuffer::create(size, 1); - if (!m_elementArrayBuffer) { - m_byteLength = 0; - return false; - } + if (byteLength) { + m_elementArrayBuffer = ArrayBuffer::create(byteLength, 1); + if (!m_elementArrayBuffer) { + m_byteLength = 0; + return false; + } + if (array) { + // We must always clone the incoming data because client-side + // modifications without calling bufferData or bufferSubData + // must never be able to change the validation results. + memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()), + static_cast<unsigned char*>(array->data()) + byteOffset, + byteLength); + } + } else + m_elementArrayBuffer = 0; return true; - } else if (m_target == GraphicsContext3D::ARRAY_BUFFER) { - m_byteLength = size; + case GraphicsContext3D::ARRAY_BUFFER: + m_byteLength = byteLength; return true; + default: + return false; } +} - return false; +bool WebGLBuffer::associateBufferData(int size) +{ + if (size < 0) + return false; + return associateBufferDataImpl(0, 0, static_cast<unsigned>(size)); } bool WebGLBuffer::associateBufferData(ArrayBuffer* array) { - if (!m_target) - return false; if (!array) return false; - - if (m_target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { - clearCachedMaxIndices(); - m_byteLength = array->byteLength(); - // We must always clone the incoming data because client-side - // modifications without calling bufferData or bufferSubData - // must never be able to change the validation results. - m_elementArrayBuffer = ArrayBuffer::create(array); - if (!m_elementArrayBuffer) { - m_byteLength = 0; - return false; - } - return true; - } - - if (m_target == GraphicsContext3D::ARRAY_BUFFER) { - m_byteLength = array->byteLength(); - return true; - } - - return false; + return associateBufferDataImpl(array, 0, array->byteLength()); } bool WebGLBuffer::associateBufferData(ArrayBufferView* array) { - if (!m_target) - return false; if (!array) return false; + return associateBufferDataImpl(array->buffer().get(), array->byteOffset(), array->byteLength()); +} - if (m_target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { - clearCachedMaxIndices(); - m_byteLength = array->byteLength(); - // We must always clone the incoming data because client-side - // modifications without calling bufferData or bufferSubData - // must never be able to change the validation results. - m_elementArrayBuffer = ArrayBuffer::create(array->buffer().get()); - if (!m_elementArrayBuffer) { - m_byteLength = 0; +bool WebGLBuffer::associateBufferSubDataImpl(long offset, ArrayBuffer* array, unsigned arrayByteOffset, unsigned byteLength) +{ + if (!array || offset < 0) + return false; + + if (byteLength) { + CheckedInt<uint32_t> checkedBufferOffset(offset); + CheckedInt<uint32_t> checkedArrayOffset(arrayByteOffset); + CheckedInt<uint32_t> checkedLength(byteLength); + CheckedInt<uint32_t> checkedArrayMax = checkedArrayOffset + checkedLength; + CheckedInt<uint32_t> checkedBufferMax = checkedBufferOffset + checkedLength; + if (!checkedArrayMax.valid() || checkedArrayMax.value() > array->byteLength() || !checkedBufferMax.valid() || checkedBufferMax.value() > m_byteLength) return false; - } - return true; } - if (m_target == GraphicsContext3D::ARRAY_BUFFER) { - m_byteLength = array->byteLength(); + switch (m_target) { + case GraphicsContext3D::ELEMENT_ARRAY_BUFFER: + clearCachedMaxIndices(); + if (byteLength) { + if (!m_elementArrayBuffer) + return false; + memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()) + offset, + static_cast<unsigned char*>(array->data()) + arrayByteOffset, + byteLength); + } return true; + case GraphicsContext3D::ARRAY_BUFFER: + return true; + default: + return false; } - - return false; } bool WebGLBuffer::associateBufferSubData(long offset, ArrayBuffer* array) { - if (!m_target) - return false; if (!array) return false; - - if (m_target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { - clearCachedMaxIndices(); - - // 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_byteLength || array->byteLength() > m_byteLength - uoffset) - return false; - - if (!m_elementArrayBuffer) - return false; - - memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()) + offset, - static_cast<unsigned char*>(array->data()), - array->byteLength()); - return true; - } - - if (m_target == GraphicsContext3D::ARRAY_BUFFER) - return array->byteLength() + offset <= m_byteLength; - - return false; + return associateBufferSubDataImpl(offset, array, 0, array->byteLength()); } bool WebGLBuffer::associateBufferSubData(long offset, ArrayBufferView* array) { - if (!m_target) - return false; if (!array) return false; - - if (m_target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { - clearCachedMaxIndices(); - - // 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_byteLength || array->byteLength() > m_byteLength - uoffset) - return false; - - if (!m_elementArrayBuffer) - return false; - - memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()) + offset, array->baseAddress(), array->byteLength()); - return true; - } - - if (m_target == GraphicsContext3D::ARRAY_BUFFER) - return array->byteLength() + offset <= m_byteLength; - - return false; + return associateBufferSubDataImpl(offset, array->buffer().get(), array->byteOffset(), array->byteLength()); } unsigned WebGLBuffer::byteLength() const diff --git a/WebCore/html/canvas/WebGLBuffer.h b/WebCore/html/canvas/WebGLBuffer.h index 1280cf9..a7a25b9 100644 --- a/WebCore/html/canvas/WebGLBuffer.h +++ b/WebCore/html/canvas/WebGLBuffer.h @@ -26,72 +26,77 @@ #ifndef WebGLBuffer_h #define WebGLBuffer_h -#include "CanvasObject.h" #include "ArrayBuffer.h" +#include "WebGLObject.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class WebGLBuffer : public CanvasObject { - public: - virtual ~WebGLBuffer() { deleteObject(); } - - static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*); - - bool associateBufferData(int size); - bool associateBufferData(ArrayBuffer* array); - bool associateBufferData(ArrayBufferView* array); - bool associateBufferSubData(long offset, ArrayBuffer* array); - bool associateBufferSubData(long offset, ArrayBufferView* array); - - unsigned byteLength() const; - const ArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); } - - // Gets the cached max index for the given type. Returns -1 if - // none has been set. - long getCachedMaxIndex(unsigned long type); - // Sets the cached max index for the given type. - void setCachedMaxIndex(unsigned long type, long value); - - unsigned long getTarget() const { return m_target; } - void setTarget(unsigned long); - - protected: - WebGLBuffer(WebGLRenderingContext*); - - virtual void _deleteObject(Platform3DObject o); - - private: - virtual bool isBuffer() const { return true; } - - unsigned long m_target; - - RefPtr<ArrayBuffer> m_elementArrayBuffer; - unsigned m_byteLength; - - // Optimization for index validation. For each type of index - // (i.e., UNSIGNED_SHORT), cache the maximum index in the - // entire buffer. - // - // This is sufficient to eliminate a lot of work upon each - // draw call as long as all bound array buffers are at least - // that size. - struct MaxIndexCacheEntry { - unsigned long type; - long maxIndex; - }; - // OpenGL ES 2.0 only has two valid index types (UNSIGNED_BYTE - // and UNSIGNED_SHORT), but might as well leave open the - // possibility of adding others. - MaxIndexCacheEntry m_maxIndexCache[4]; - unsigned m_nextAvailableCacheEntry; - - // Clears all of the cached max indices. - void clearCachedMaxIndices(); + +class WebGLBuffer : public WebGLObject { +public: + virtual ~WebGLBuffer() { deleteObject(); } + + static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*); + + bool associateBufferData(int size); + bool associateBufferData(ArrayBuffer* array); + bool associateBufferData(ArrayBufferView* array); + bool associateBufferSubData(long offset, ArrayBuffer* array); + bool associateBufferSubData(long offset, ArrayBufferView* array); + + unsigned byteLength() const; + const ArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); } + + // Gets the cached max index for the given type. Returns -1 if + // none has been set. + long getCachedMaxIndex(unsigned long type); + // Sets the cached max index for the given type. + void setCachedMaxIndex(unsigned long type, long value); + + unsigned long getTarget() const { return m_target; } + void setTarget(unsigned long); + +protected: + WebGLBuffer(WebGLRenderingContext*); + + virtual void deleteObjectImpl(Platform3DObject o); + +private: + virtual bool isBuffer() const { return true; } + + unsigned long m_target; + + RefPtr<ArrayBuffer> m_elementArrayBuffer; + unsigned m_byteLength; + + // Optimization for index validation. For each type of index + // (i.e., UNSIGNED_SHORT), cache the maximum index in the + // entire buffer. + // + // This is sufficient to eliminate a lot of work upon each + // draw call as long as all bound array buffers are at least + // that size. + struct MaxIndexCacheEntry { + unsigned long type; + long maxIndex; }; - + // OpenGL ES 2.0 only has two valid index types (UNSIGNED_BYTE + // and UNSIGNED_SHORT), but might as well leave open the + // possibility of adding others. + MaxIndexCacheEntry m_maxIndexCache[4]; + unsigned m_nextAvailableCacheEntry; + + // Clears all of the cached max indices. + void clearCachedMaxIndices(); + + // Helper function called by the three associateBufferData(). + bool associateBufferDataImpl(ArrayBuffer* array, unsigned byteOffset, unsigned byteLength); + // Helper function called by the two associateBufferSubData(). + bool associateBufferSubDataImpl(long offset, ArrayBuffer* array, unsigned arrayByteOffset, unsigned byteLength); +}; + } // namespace WebCore #endif // WebGLBuffer_h diff --git a/WebCore/html/canvas/WebGLFramebuffer.cpp b/WebCore/html/canvas/WebGLFramebuffer.cpp index a3d4681..bfa08b7 100644 --- a/WebCore/html/canvas/WebGLFramebuffer.cpp +++ b/WebCore/html/canvas/WebGLFramebuffer.cpp @@ -28,6 +28,7 @@ #if ENABLE(3D_CANVAS) #include "WebGLFramebuffer.h" + #include "WebGLRenderingContext.h" namespace WebCore { @@ -38,7 +39,7 @@ PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx } WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) - : CanvasObject(ctx) + : WebGLObject(ctx) , m_colorAttachment(0) , m_depthAttachment(0) , m_stencilAttachment(0) @@ -47,7 +48,7 @@ WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) setObject(context()->graphicsContext3D()->createFramebuffer()); } -void WebGLFramebuffer::setAttachment(unsigned long attachment, CanvasObject* attachedObject) +void WebGLFramebuffer::setAttachment(unsigned long attachment, WebGLObject* attachedObject) { if (!object()) return; @@ -77,10 +78,10 @@ void WebGLFramebuffer::onBind() initializeRenderbuffers(); } -void WebGLFramebuffer::onAttachedObjectChange(CanvasObject* object) +void WebGLFramebuffer::onAttachedObjectChange(WebGLObject* object) { // Currently object == 0 is not considered, but this might change if the - // lifespan of CanvasObject changes. + // lifespan of WebGLObject changes. if (object && (object == m_colorAttachment || object == m_depthAttachment || object == m_stencilAttachment || object == m_depthStencilAttachment)) @@ -105,12 +106,12 @@ unsigned long WebGLFramebuffer::getColorBufferFormat() return 0; } -void WebGLFramebuffer::_deleteObject(Platform3DObject object) +void WebGLFramebuffer::deleteObjectImpl(Platform3DObject object) { context()->graphicsContext3D()->deleteFramebuffer(object); } -bool WebGLFramebuffer::isUninitialized(CanvasObject* attachedObject) +bool WebGLFramebuffer::isUninitialized(WebGLObject* attachedObject) { if (attachedObject && attachedObject->object() && attachedObject->isRenderbuffer() && !(reinterpret_cast<WebGLRenderbuffer*>(attachedObject))->isInitialized()) @@ -118,7 +119,7 @@ bool WebGLFramebuffer::isUninitialized(CanvasObject* attachedObject) return false; } -void WebGLFramebuffer::setInitialized(CanvasObject* attachedObject) +void WebGLFramebuffer::setInitialized(WebGLObject* attachedObject) { if (attachedObject && attachedObject->object() && attachedObject->isRenderbuffer()) (reinterpret_cast<WebGLRenderbuffer*>(attachedObject))->setInitialized(); diff --git a/WebCore/html/canvas/WebGLFramebuffer.h b/WebCore/html/canvas/WebGLFramebuffer.h index ae1f4dc..ac945dd 100644 --- a/WebCore/html/canvas/WebGLFramebuffer.h +++ b/WebCore/html/canvas/WebGLFramebuffer.h @@ -26,59 +26,59 @@ #ifndef WebGLFramebuffer_h #define WebGLFramebuffer_h -#include "CanvasObject.h" +#include "WebGLObject.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - class WebGLFramebuffer : public CanvasObject { - public: - virtual ~WebGLFramebuffer() { deleteObject(); } - - static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*); - - bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); } - bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); } - bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); } - - void setAttachment(unsigned long, CanvasObject*); - - // This function is called right after a framebuffer is bound. - // Because renderbuffers and textures attached to the framebuffer might - // have changed and the framebuffer might have become complete when it - // isn't bound, so we need to clear un-initialized renderbuffers. - void onBind(); - - // When a texture or a renderbuffer changes, we need to check the - // current bound framebuffer; if the newly changed object is attached - // to the framebuffer and the framebuffer becomes complete, we need to - // clear un-initialized renderbuffers. - void onAttachedObjectChange(CanvasObject*); - - unsigned long getColorBufferFormat(); - - protected: - WebGLFramebuffer(WebGLRenderingContext*); - - virtual void _deleteObject(Platform3DObject); - - private: - virtual bool isFramebuffer() const { return true; } - - bool isUninitialized(CanvasObject*); - void setInitialized(CanvasObject*); - void initializeRenderbuffers(); - - // These objects are kept alive by the global table in - // WebGLRenderingContext. - CanvasObject* m_colorAttachment; - CanvasObject* m_depthAttachment; - CanvasObject* m_stencilAttachment; - CanvasObject* m_depthStencilAttachment; - }; - +class WebGLFramebuffer : public WebGLObject { +public: + virtual ~WebGLFramebuffer() { deleteObject(); } + + static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*); + + bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); } + bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); } + bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); } + + void setAttachment(unsigned long, WebGLObject*); + + // This function is called right after a framebuffer is bound. + // Because renderbuffers and textures attached to the framebuffer might + // have changed and the framebuffer might have become complete when it + // isn't bound, so we need to clear un-initialized renderbuffers. + void onBind(); + + // When a texture or a renderbuffer changes, we need to check the + // current bound framebuffer; if the newly changed object is attached + // to the framebuffer and the framebuffer becomes complete, we need to + // clear un-initialized renderbuffers. + void onAttachedObjectChange(WebGLObject*); + + unsigned long getColorBufferFormat(); + +protected: + WebGLFramebuffer(WebGLRenderingContext*); + + virtual void deleteObjectImpl(Platform3DObject); + +private: + virtual bool isFramebuffer() const { return true; } + + bool isUninitialized(WebGLObject*); + void setInitialized(WebGLObject*); + void initializeRenderbuffers(); + + // These objects are kept alive by the global table in + // WebGLRenderingContext. + WebGLObject* m_colorAttachment; + WebGLObject* m_depthAttachment; + WebGLObject* m_stencilAttachment; + WebGLObject* m_depthStencilAttachment; +}; + } // namespace WebCore #endif // WebGLFramebuffer_h diff --git a/WebCore/html/canvas/WebGLGetInfo.cpp b/WebCore/html/canvas/WebGLGetInfo.cpp index 0c8b548..6aff82f 100644 --- a/WebCore/html/canvas/WebGLGetInfo.cpp +++ b/WebCore/html/canvas/WebGLGetInfo.cpp @@ -29,14 +29,15 @@ #if ENABLE(3D_CANVAS) #include "WebGLGetInfo.h" -#include "WebGLBuffer.h" + #include "Float32Array.h" -#include "WebGLFramebuffer.h" #include "Int32Array.h" +#include "Uint8Array.h" +#include "WebGLBuffer.h" +#include "WebGLFramebuffer.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" #include "WebGLTexture.h" -#include "Uint8Array.h" namespace WebCore { diff --git a/WebCore/html/canvas/WebGLGetInfo.h b/WebCore/html/canvas/WebGLGetInfo.h index 94f6f9b..caee520 100644 --- a/WebCore/html/canvas/WebGLGetInfo.h +++ b/WebCore/html/canvas/WebGLGetInfo.h @@ -27,20 +27,18 @@ #ifndef WebGLGetInfo_h #define WebGLGetInfo_h -#include "wtf/PassRefPtr.h" -#include "wtf/RefPtr.h" +#include "Float32Array.h" +#include "Int32Array.h" #include "PlatformString.h" - +#include "Uint8Array.h" #include "WebGLBuffer.h" -#include "Float32Array.h" #include "WebGLFramebuffer.h" -#include "Int32Array.h" -// FIXME: implement WebGLObjectArray -//#include "WebGLObjectArray.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" #include "WebGLTexture.h" -#include "Uint8Array.h" + +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> namespace WebCore { @@ -74,7 +72,7 @@ public: WebGLGetInfo(const bool* value, int size); WebGLGetInfo(float value); WebGLGetInfo(long value); - // Represents the NULL value and type + // Represents the null value and type. WebGLGetInfo(); WebGLGetInfo(const String& value); WebGLGetInfo(unsigned long value); @@ -132,4 +130,4 @@ private: } // namespace WebCore -#endif // WebGLGetInfo_h +#endif // WebGLGetInfo_h diff --git a/WebCore/html/canvas/CanvasObject.cpp b/WebCore/html/canvas/WebGLObject.cpp index 6c7667b..6a34269 100644 --- a/WebCore/html/canvas/CanvasObject.cpp +++ b/WebCore/html/canvas/WebGLObject.cpp @@ -27,25 +27,26 @@ #if ENABLE(3D_CANVAS) -#include "CanvasObject.h" +#include "WebGLObject.h" + #include "WebGLRenderingContext.h" namespace WebCore { -CanvasObject::CanvasObject(WebGLRenderingContext* context) +WebGLObject::WebGLObject(WebGLRenderingContext* context) : m_object(0) , m_shouldDeleteObject(true) , m_context(context) { } -CanvasObject::~CanvasObject() +WebGLObject::~WebGLObject() { if (m_context) m_context->removeObject(this); } -void CanvasObject::setObject(Platform3DObject object, bool shouldDeleteObject) +void WebGLObject::setObject(Platform3DObject object, bool shouldDeleteObject) { if (object == m_object) return; @@ -55,13 +56,13 @@ void CanvasObject::setObject(Platform3DObject object, bool shouldDeleteObject) m_shouldDeleteObject = shouldDeleteObject; } -void CanvasObject::deleteObject() +void WebGLObject::deleteObject() { if (m_object) { if (m_shouldDeleteObject) if (m_context) { m_context->graphicsContext3D()->makeContextCurrent(); - _deleteObject(m_object); + deleteObjectImpl(m_object); } m_object = 0; } diff --git a/WebCore/html/canvas/WebGLObject.h b/WebCore/html/canvas/WebGLObject.h new file mode 100644 index 0000000..b66311f --- /dev/null +++ b/WebCore/html/canvas/WebGLObject.h @@ -0,0 +1,79 @@ +/* + * 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 WebGLObject_h +#define WebGLObject_h + +#include "GraphicsContext3D.h" + +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLRenderingContext; + +class WebGLObject : public RefCounted<WebGLObject> { +public: + virtual ~WebGLObject(); + + Platform3DObject object() const { return m_object; } + void setObject(Platform3DObject, bool shouldDeleteObject = true); + void deleteObject(); + + void detachContext() + { + deleteObject(); + m_context = 0; + } + + WebGLRenderingContext* context() const { return m_context; } + + virtual bool isBuffer() const { return false; } + virtual bool isFramebuffer() const { return false; } + virtual bool isProgram() const { return false; } + virtual bool isRenderbuffer() const { return false; } + virtual bool isShader() const { return false; } + virtual bool isTexture() const { return false; } + +protected: + WebGLObject(WebGLRenderingContext*); + virtual void deleteObjectImpl(Platform3DObject) = 0; + +private: + Platform3DObject m_object; + // 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 + +#endif // WebGLObject_h diff --git a/WebCore/html/canvas/WebGLProgram.cpp b/WebCore/html/canvas/WebGLProgram.cpp index 0004465..846b171 100644 --- a/WebCore/html/canvas/WebGLProgram.cpp +++ b/WebCore/html/canvas/WebGLProgram.cpp @@ -28,6 +28,7 @@ #if ENABLE(3D_CANVAS) #include "WebGLProgram.h" + #include "WebGLRenderingContext.h" namespace WebCore { @@ -38,13 +39,13 @@ PassRefPtr<WebGLProgram> WebGLProgram::create(WebGLRenderingContext* ctx) } WebGLProgram::WebGLProgram(WebGLRenderingContext* ctx) - : CanvasObject(ctx) + : WebGLObject(ctx) , m_linkFailure(false) { setObject(context()->graphicsContext3D()->createProgram()); } -void WebGLProgram::_deleteObject(Platform3DObject object) +void WebGLProgram::deleteObjectImpl(Platform3DObject object) { context()->graphicsContext3D()->deleteProgram(object); } @@ -56,17 +57,17 @@ bool WebGLProgram::cacheActiveAttribLocations() return false; GraphicsContext3D* context3d = context()->graphicsContext3D(); int linkStatus; - context3d->getProgramiv(this, GraphicsContext3D::LINK_STATUS, &linkStatus); + context3d->getProgramiv(object(), GraphicsContext3D::LINK_STATUS, &linkStatus); if (!linkStatus) return false; int numAttribs = 0; - context3d->getProgramiv(this, GraphicsContext3D::ACTIVE_ATTRIBUTES, &numAttribs); + context3d->getProgramiv(object(), GraphicsContext3D::ACTIVE_ATTRIBUTES, &numAttribs); m_activeAttribLocations.resize(static_cast<size_t>(numAttribs)); for (int i = 0; i < numAttribs; ++i) { ActiveInfo info; - context3d->getActiveAttrib(this, i, info); - m_activeAttribLocations[i] = context3d->getAttribLocation(this, info.name.charactersWithNullTermination()); + context3d->getActiveAttrib(object(), i, info); + m_activeAttribLocations[i] = context3d->getAttribLocation(object(), info.name.charactersWithNullTermination()); } return true; diff --git a/WebCore/html/canvas/WebGLProgram.h b/WebCore/html/canvas/WebGLProgram.h index 1049334..0156938 100644 --- a/WebCore/html/canvas/WebGLProgram.h +++ b/WebCore/html/canvas/WebGLProgram.h @@ -26,47 +26,47 @@ #ifndef WebGLProgram_h #define WebGLProgram_h -#include "CanvasObject.h" +#include "WebGLObject.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> namespace WebCore { - - class WebGLProgram : public CanvasObject { - public: - virtual ~WebGLProgram() { deleteObject(); } - - static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); - - // cacheActiveAttribLocation() is only called once after linkProgram() - // succeeds. - bool cacheActiveAttribLocations(); - int numActiveAttribLocations() const; - int getActiveAttribLocation(int index) const; - - bool isUsingVertexAttrib0() const; - - // Return true means getProgramParameter(LINK_STATUS) should return - // false; return false means we should actually call - // getProgramParameter(LINK_STATUS) to find out. - bool isLinkFailureFlagSet() const { return m_linkFailure; } - void setLinkFailureFlag(bool failed) { m_linkFailure = failed; } - - protected: - WebGLProgram(WebGLRenderingContext*); - - virtual void _deleteObject(Platform3DObject); - - private: - virtual bool isProgram() const { return true; } - - Vector<int> m_activeAttribLocations; - - bool m_linkFailure; - }; - + +class WebGLProgram : public WebGLObject { +public: + virtual ~WebGLProgram() { deleteObject(); } + + static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); + + // cacheActiveAttribLocation() is only called once after linkProgram() + // succeeds. + bool cacheActiveAttribLocations(); + int numActiveAttribLocations() const; + int getActiveAttribLocation(int index) const; + + bool isUsingVertexAttrib0() const; + + // Return true means getProgramParameter(LINK_STATUS) should return + // false; return false means we should actually call + // getProgramParameter(LINK_STATUS) to find out. + bool isLinkFailureFlagSet() const { return m_linkFailure; } + void setLinkFailureFlag(bool failed) { m_linkFailure = failed; } + +protected: + WebGLProgram(WebGLRenderingContext*); + + virtual void deleteObjectImpl(Platform3DObject); + +private: + virtual bool isProgram() const { return true; } + + Vector<int> m_activeAttribLocations; + + bool m_linkFailure; +}; + } // namespace WebCore #endif // WebGLProgram_h diff --git a/WebCore/html/canvas/WebGLRenderbuffer.cpp b/WebCore/html/canvas/WebGLRenderbuffer.cpp index 701e2c9..7bc2eec 100644 --- a/WebCore/html/canvas/WebGLRenderbuffer.cpp +++ b/WebCore/html/canvas/WebGLRenderbuffer.cpp @@ -28,6 +28,7 @@ #if ENABLE(3D_CANVAS) #include "WebGLRenderbuffer.h" + #include "WebGLRenderingContext.h" namespace WebCore { @@ -38,14 +39,14 @@ PassRefPtr<WebGLRenderbuffer> WebGLRenderbuffer::create(WebGLRenderingContext* c } WebGLRenderbuffer::WebGLRenderbuffer(WebGLRenderingContext* ctx) - : CanvasObject(ctx) + : WebGLObject(ctx) , m_internalFormat(GraphicsContext3D::RGBA4) , m_initialized(false) { setObject(context()->graphicsContext3D()->createRenderbuffer()); } -void WebGLRenderbuffer::_deleteObject(Platform3DObject object) +void WebGLRenderbuffer::deleteObjectImpl(Platform3DObject object) { context()->graphicsContext3D()->deleteRenderbuffer(object); } diff --git a/WebCore/html/canvas/WebGLRenderbuffer.h b/WebCore/html/canvas/WebGLRenderbuffer.h index dbb08c1..5765061 100644 --- a/WebCore/html/canvas/WebGLRenderbuffer.h +++ b/WebCore/html/canvas/WebGLRenderbuffer.h @@ -26,37 +26,37 @@ #ifndef WebGLRenderbuffer_h #define WebGLRenderbuffer_h -#include "CanvasObject.h" +#include "WebGLObject.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class WebGLRenderbuffer : public CanvasObject { - public: - virtual ~WebGLRenderbuffer() { deleteObject(); } - - static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*); - - void setInternalFormat(unsigned long internalformat) { m_internalFormat = internalformat; } - unsigned long getInternalFormat() const { return m_internalFormat; } - - bool isInitialized() const { return m_initialized; } - void setInitialized() { m_initialized = true; } - - protected: - WebGLRenderbuffer(WebGLRenderingContext*); - - virtual void _deleteObject(Platform3DObject); - - private: - virtual bool isRenderbuffer() const { return true; } - - unsigned long m_internalFormat; - bool m_initialized; - }; - + +class WebGLRenderbuffer : public WebGLObject { +public: + virtual ~WebGLRenderbuffer() { deleteObject(); } + + static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*); + + void setInternalFormat(unsigned long internalformat) { m_internalFormat = internalformat; } + unsigned long getInternalFormat() const { return m_internalFormat; } + + bool isInitialized() const { return m_initialized; } + void setInitialized() { m_initialized = true; } + +protected: + WebGLRenderbuffer(WebGLRenderingContext*); + + virtual void deleteObjectImpl(Platform3DObject); + +private: + virtual bool isRenderbuffer() const { return true; } + + unsigned long m_internalFormat; + bool m_initialized; +}; + } // namespace WebCore #endif // WebGLRenderbuffer_h diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp index fb17db9..0284ec6 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.cpp +++ b/WebCore/html/canvas/WebGLRenderingContext.cpp @@ -29,8 +29,8 @@ #include "WebGLRenderingContext.h" -#include "CheckedInt.h" #include "CanvasPixelArray.h" +#include "CheckedInt.h" #include "Console.h" #include "DOMWindow.h" #include "FrameView.h" @@ -41,15 +41,15 @@ #include "NotImplemented.h" #include "RenderBox.h" #include "RenderLayer.h" -#include "WebGLActiveInfo.h" #include "Uint16Array.h" +#include "WebGLActiveInfo.h" #include "WebGLBuffer.h" #include "WebGLContextAttributes.h" #include "WebGLFramebuffer.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" -#include "WebGLTexture.h" #include "WebGLShader.h" +#include "WebGLTexture.h" #include "WebGLUniformLocation.h" #include <wtf/ByteArray.h> @@ -57,6 +57,11 @@ namespace WebCore { +static inline Platform3DObject objectOrZero(WebGLObject* object) +{ + return object ? object->object() : 0; +} + class WebGLStateRestorer { public: WebGLStateRestorer(WebGLRenderingContext* context, @@ -151,7 +156,7 @@ void WebGLRenderingContext::markContextChanged() m_markedCanvasDirty = true; } -bool WebGLRenderingContext::paintRenderingResultsToCanvas() +void WebGLRenderingContext::paintRenderingResultsToCanvas() { if (m_markedCanvasDirty) { // FIXME: It should not be necessary to clear the image before doing a readback. @@ -159,16 +164,13 @@ bool WebGLRenderingContext::paintRenderingResultsToCanvas() canvas()->buffer()->clearImage(); m_markedCanvasDirty = false; m_context->paintRenderingResultsToCanvas(this); - return true; } - return false; } void WebGLRenderingContext::beginPaint() { - if (m_markedCanvasDirty) { + if (m_markedCanvasDirty) m_context->beginPaint(this); - } } void WebGLRenderingContext::endPaint() @@ -193,14 +195,9 @@ void WebGLRenderingContext::reshape(int width, int height) m_context->reshape(width, height); } -int WebGLRenderingContext::sizeInBytes(int type, ExceptionCode& ec) +int WebGLRenderingContext::sizeInBytes(int type) { - UNUSED_PARAM(ec); - int result = m_context->sizeInBytes(type); - if (result <= 0) - m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); - - return result; + return m_context->sizeInBytes(type); } void WebGLRenderingContext::activeTexture(unsigned long texture, ExceptionCode& ec) @@ -220,7 +217,7 @@ void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* sha UNUSED_PARAM(ec); if (!validateWebGLObject(program) || !validateWebGLObject(shader)) return; - m_context->attachShader(program, shader); + m_context->attachShader(objectOrZero(program), objectOrZero(shader)); cleanupAfterGraphicsCall(false); } @@ -229,7 +226,7 @@ void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, unsigned l UNUSED_PARAM(ec); if (!validateWebGLObject(program)) return; - m_context->bindAttribLocation(program, index, name); + m_context->bindAttribLocation(objectOrZero(program), index, name); cleanupAfterGraphicsCall(false); } @@ -254,7 +251,7 @@ void WebGLRenderingContext::bindBuffer(unsigned long target, WebGLBuffer* buffer return; } - m_context->bindBuffer(target, buffer); + m_context->bindBuffer(target, objectOrZero(buffer)); if (buffer) buffer->setTarget(target); cleanupAfterGraphicsCall(false); @@ -273,7 +270,7 @@ void WebGLRenderingContext::bindFramebuffer(unsigned long target, WebGLFramebuff return; } m_framebufferBinding = buffer; - m_context->bindFramebuffer(target, buffer); + m_context->bindFramebuffer(target, objectOrZero(buffer)); if (m_framebufferBinding) m_framebufferBinding->onBind(); cleanupAfterGraphicsCall(false); @@ -291,7 +288,7 @@ void WebGLRenderingContext::bindRenderbuffer(unsigned long target, WebGLRenderbu return; } m_renderbufferBinding = renderBuffer; - m_context->bindRenderbuffer(target, renderBuffer); + m_context->bindRenderbuffer(target, objectOrZero(renderBuffer)); cleanupAfterGraphicsCall(false); } @@ -314,9 +311,28 @@ void WebGLRenderingContext::bindTexture(unsigned long target, WebGLTexture* text m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); return; } - m_context->bindTexture(target, texture); + m_context->bindTexture(target, objectOrZero(texture)); if (!isGLES2Compliant() && texture) texture->setTarget(target, maxLevel); + + // FIXME: do we want to do this on all platforms? +#if PLATFORM(CHROMIUM) + // FIXME: GL_TEXTURE_WRAP_R isn't exposed in the OpenGL ES 2.0 + // API. On desktop OpenGL implementations it seems necessary to + // set this wrap mode to GL_CLAMP_TO_EDGE to get correct behavior + // of cube maps. + if (texture) { + if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) { + if (!texture->isCubeMapRWrapModeInitialized()) { + static const int textureWrapR = 0x8072; + texParameteri(GraphicsContext3D::TEXTURE_CUBE_MAP, textureWrapR, GraphicsContext3D::CLAMP_TO_EDGE); + texture->setCubeMapRWrapModeInitialized(true); + } + } else + texture->setCubeMapRWrapModeInitialized(false); + } +#endif + cleanupAfterGraphicsCall(false); } @@ -326,7 +342,7 @@ void WebGLRenderingContext::blendColor(double red, double green, double blue, do cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::blendEquation( unsigned long mode ) +void WebGLRenderingContext::blendEquation(unsigned long mode) { if (!isGLES2Compliant()) { if (!validateBlendEquation(mode)) @@ -497,7 +513,7 @@ void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec UNUSED_PARAM(ec); if (!validateWebGLObject(shader)) return; - m_context->compileShader(shader); + m_context->compileShader(objectOrZero(shader)); cleanupAfterGraphicsCall(false); } @@ -687,7 +703,7 @@ void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha UNUSED_PARAM(ec); if (!validateWebGLObject(program) || !validateWebGLObject(shader)) return; - m_context->detachShader(program, shader); + m_context->detachShader(objectOrZero(program), objectOrZero(shader)); cleanupAfterGraphicsCall(false); } @@ -872,7 +888,7 @@ bool WebGLRenderingContext::validateRenderingState(long numElementsRequired) return numElementsRequired <= smallestNumElements; } -bool WebGLRenderingContext::validateWebGLObject(CanvasObject* object) +bool WebGLRenderingContext::validateWebGLObject(WebGLObject* object) { if (!object) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); @@ -1056,7 +1072,7 @@ void WebGLRenderingContext::framebufferRenderbuffer(unsigned long target, unsign return; } } - m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer); + m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, objectOrZero(buffer)); m_framebufferBinding->setAttachment(attachment, buffer); cleanupAfterGraphicsCall(false); } @@ -1081,7 +1097,7 @@ void WebGLRenderingContext::framebufferTexture2D(unsigned long target, unsigned m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; } - m_context->framebufferTexture2D(target, attachment, textarget, texture, level); + m_context->framebufferTexture2D(target, attachment, textarget, objectOrZero(texture), level); m_framebufferBinding->setAttachment(attachment, texture); cleanupAfterGraphicsCall(false); } @@ -1119,9 +1135,8 @@ PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* ActiveInfo info; if (!validateWebGLObject(program)) return 0; - if (!m_context->getActiveAttrib(program, index, info)) { + if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) return 0; - } return WebGLActiveInfo::create(info.name, info.type, info.size); } @@ -1131,13 +1146,11 @@ PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram ActiveInfo info; if (!validateWebGLObject(program)) return 0; - if (!m_context->getActiveUniform(program, index, info)) { + if (!m_context->getActiveUniform(objectOrZero(program), index, info)) return 0; - } - if (!isGLES2Compliant()) { + if (!isGLES2Compliant()) if (info.size > 1 && !info.name.endsWith("[0]")) info.name.append("[0]"); - } return WebGLActiveInfo::create(info.name, info.type, info.size); } @@ -1148,11 +1161,11 @@ bool WebGLRenderingContext::getAttachedShaders(WebGLProgram* program, Vector<Web if (!validateWebGLObject(program)) return false; int numShaders = 0; - m_context->getProgramiv(program, GraphicsContext3D::ATTACHED_SHADERS, &numShaders); + m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ATTACHED_SHADERS, &numShaders); if (numShaders) { OwnArrayPtr<unsigned int> shaders(new unsigned int[numShaders]); int count; - m_context->getAttachedShaders(program, numShaders, &count, shaders.get()); + m_context->getAttachedShaders(objectOrZero(program), numShaders, &count, shaders.get()); if (count != numShaders) return false; shaderObjects.resize(numShaders); @@ -1170,7 +1183,7 @@ bool WebGLRenderingContext::getAttachedShaders(WebGLProgram* program, Vector<Web int WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const String& name) { - return m_context->getAttribLocation(program, name); + return m_context->getAttribLocation(objectOrZero(program), name); } WebGLGetInfo WebGLRenderingContext::getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) @@ -1191,8 +1204,7 @@ WebGLGetInfo WebGLRenderingContext::getBufferParameter(unsigned long target, uns 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)); + return WebGLGetInfo(static_cast<unsigned long>(value)); } PassRefPtr<WebGLContextAttributes> WebGLRenderingContext::getContextAttributes() @@ -1234,23 +1246,22 @@ WebGLGetInfo WebGLRenderingContext::getFramebufferAttachmentParameter(unsigned l 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); - switch (type) { - case GraphicsContext3D::RENDERBUFFER: - return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(findRenderbuffer(static_cast<Platform3DObject>(value)))); - case GraphicsContext3D::TEXTURE: - return WebGLGetInfo(PassRefPtr<WebGLTexture>(findTexture(static_cast<Platform3DObject>(value)))); - default: - // FIXME: raise exception? - return WebGLGetInfo(); - } + return WebGLGetInfo(static_cast<long>(value)); + } + + 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); + switch (type) { + case GraphicsContext3D::RENDERBUFFER: + return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(findRenderbuffer(static_cast<Platform3DObject>(value)))); + case GraphicsContext3D::TEXTURE: + return WebGLGetInfo(PassRefPtr<WebGLTexture>(findTexture(static_cast<Platform3DObject>(value)))); + default: + // FIXME: raise exception? + return WebGLGetInfo(); } } @@ -1448,12 +1459,12 @@ WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, u switch (pname) { case GraphicsContext3D::DELETE_STATUS: case GraphicsContext3D::VALIDATE_STATUS: - m_context->getProgramiv(program, pname, &value); + m_context->getProgramiv(objectOrZero(program), pname, &value); return WebGLGetInfo(static_cast<bool>(value)); case GraphicsContext3D::LINK_STATUS: if (program->isLinkFailureFlagSet()) return WebGLGetInfo(false); - m_context->getProgramiv(program, pname, &value); + m_context->getProgramiv(objectOrZero(program), pname, &value); return WebGLGetInfo(static_cast<bool>(value)); case GraphicsContext3D::INFO_LOG_LENGTH: case GraphicsContext3D::ATTACHED_SHADERS: @@ -1461,7 +1472,7 @@ WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, u case GraphicsContext3D::ACTIVE_ATTRIBUTE_MAX_LENGTH: case GraphicsContext3D::ACTIVE_UNIFORMS: case GraphicsContext3D::ACTIVE_UNIFORM_MAX_LENGTH: - m_context->getProgramiv(program, pname, &value); + m_context->getProgramiv(objectOrZero(program), pname, &value); return WebGLGetInfo(static_cast<long>(value)); default: m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); @@ -1475,7 +1486,7 @@ String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program, Exception if (!validateWebGLObject(program)) return ""; WebGLStateRestorer(this, false); - return m_context->getProgramInfoLog(program); + return m_context->getProgramInfoLog(objectOrZero(program)); } WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) @@ -1521,14 +1532,14 @@ WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, unsi switch (pname) { case GraphicsContext3D::DELETE_STATUS: case GraphicsContext3D::COMPILE_STATUS: - m_context->getShaderiv(shader, pname, &value); + m_context->getShaderiv(objectOrZero(shader), pname, &value); return WebGLGetInfo(static_cast<bool>(value)); case GraphicsContext3D::SHADER_TYPE: - m_context->getShaderiv(shader, pname, &value); + m_context->getShaderiv(objectOrZero(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); + m_context->getShaderiv(objectOrZero(shader), pname, &value); return WebGLGetInfo(static_cast<long>(value)); default: m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); @@ -1542,7 +1553,7 @@ String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader, ExceptionCod if (!validateWebGLObject(shader)) return ""; WebGLStateRestorer(this, false); - return m_context->getShaderInfoLog(shader); + return m_context->getShaderInfoLog(objectOrZero(shader)); } String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode& ec) @@ -1551,7 +1562,7 @@ String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode if (!validateWebGLObject(shader)) return ""; WebGLStateRestorer(this, false); - return m_context->getShaderSource(shader); + return m_context->getShaderSource(objectOrZero(shader)); } String WebGLRenderingContext::getString(unsigned long name) @@ -1601,10 +1612,10 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG 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); + m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms); for (int i = 0; i < activeUniforms; i++) { ActiveInfo info; - if (!m_context->getActiveUniform(program, i, info)) + if (!m_context->getActiveUniform(objectOrZero(program), i, info)) return WebGLGetInfo(); // Strip "[0]" from the name if it's an array. if (info.size > 1) @@ -1618,7 +1629,7 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG name.append(']'); } // Now need to look this up by name again to find its location - long loc = m_context->getUniformLocation(program, name); + long loc = m_context->getUniformLocation(objectOrZero(program), name); if (loc == location) { // Found it. Use the type in the ActiveInfo to determine the return type. GraphicsContext3D::WebGLEnumType baseType; @@ -1693,21 +1704,21 @@ WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG switch (baseType) { case GraphicsContext3D::FLOAT: { float value[16] = {0}; - m_context->getUniformfv(program, location, value); + m_context->getUniformfv(objectOrZero(program), location, value); if (length == 1) return WebGLGetInfo(value[0]); return WebGLGetInfo(Float32Array::create(value, length)); } case GraphicsContext3D::INT: { int value[16] = {0}; - m_context->getUniformiv(program, location, value); + m_context->getUniformiv(objectOrZero(program), location, value); if (length == 1) return WebGLGetInfo(static_cast<long>(value[0])); return WebGLGetInfo(Int32Array::create(value, length)); } case GraphicsContext3D::BOOL: { int value[16] = {0}; - m_context->getUniformiv(program, location, value); + m_context->getUniformiv(objectOrZero(program), location, value); if (length > 1) { unsigned char boolValue[16] = {0}; for (unsigned j = 0; j < length; j++) @@ -1733,7 +1744,7 @@ PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGL if (!validateWebGLObject(program)) return 0; WebGLStateRestorer(this, false); - long uniformLocation = m_context->getUniformLocation(program, name); + long uniformLocation = m_context->getUniformLocation(objectOrZero(program), name); if (uniformLocation == -1) return 0; return WebGLUniformLocation::create(program, uniformLocation); @@ -1811,7 +1822,7 @@ bool WebGLRenderingContext::isBuffer(WebGLBuffer* buffer) if (!buffer) return false; - return m_context->isBuffer(buffer); + return m_context->isBuffer(buffer->object()); } bool WebGLRenderingContext::isEnabled(unsigned long cap) @@ -1828,7 +1839,7 @@ bool WebGLRenderingContext::isFramebuffer(WebGLFramebuffer* framebuffer) if (!framebuffer) return false; - return m_context->isFramebuffer(framebuffer); + return m_context->isFramebuffer(framebuffer->object()); } bool WebGLRenderingContext::isProgram(WebGLProgram* program) @@ -1836,7 +1847,7 @@ bool WebGLRenderingContext::isProgram(WebGLProgram* program) if (!program) return false; - return m_context->isProgram(program); + return m_context->isProgram(program->object()); } bool WebGLRenderingContext::isRenderbuffer(WebGLRenderbuffer* renderbuffer) @@ -1844,7 +1855,7 @@ bool WebGLRenderingContext::isRenderbuffer(WebGLRenderbuffer* renderbuffer) if (!renderbuffer) return false; - return m_context->isRenderbuffer(renderbuffer); + return m_context->isRenderbuffer(renderbuffer->object()); } bool WebGLRenderingContext::isShader(WebGLShader* shader) @@ -1852,7 +1863,7 @@ bool WebGLRenderingContext::isShader(WebGLShader* shader) if (!shader) return false; - return m_context->isShader(shader); + return m_context->isShader(shader->object()); } bool WebGLRenderingContext::isTexture(WebGLTexture* texture) @@ -1860,7 +1871,7 @@ bool WebGLRenderingContext::isTexture(WebGLTexture* texture) if (!texture) return false; - return m_context->isTexture(texture); + return m_context->isTexture(texture->object()); } void WebGLRenderingContext::lineWidth(double width) @@ -1896,7 +1907,7 @@ void WebGLRenderingContext::linkProgram(WebGLProgram* program, ExceptionCode& ec program->setLinkFailureFlag(false); } - m_context->linkProgram(program); + m_context->linkProgram(objectOrZero(program)); program->cacheActiveAttribLocations(); cleanupAfterGraphicsCall(false); } @@ -2041,7 +2052,7 @@ void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& stri UNUSED_PARAM(ec); if (!validateWebGLObject(shader)) return; - m_context->shaderSource(shader, string); + m_context->shaderSource(objectOrZero(shader), string); cleanupAfterGraphicsCall(false); } @@ -2930,7 +2941,7 @@ void WebGLRenderingContext::useProgram(WebGLProgram* program, ExceptionCode& ec) return; } m_currentProgram = program; - m_context->useProgram(program); + m_context->useProgram(objectOrZero(program)); cleanupAfterGraphicsCall(false); } @@ -2939,7 +2950,7 @@ void WebGLRenderingContext::validateProgram(WebGLProgram* program, ExceptionCode UNUSED_PARAM(ec); if (!validateWebGLObject(program)) return; - m_context->validateProgram(program); + m_context->validateProgram(objectOrZero(program)); cleanupAfterGraphicsCall(false); } @@ -3005,6 +3016,7 @@ void WebGLRenderingContext::vertexAttrib4fv(unsigned long index, float* v, int s void WebGLRenderingContext::vertexAttribPointer(unsigned long index, long size, unsigned long type, bool normalized, long stride, long offset, ExceptionCode& ec) { + UNUSED_PARAM(ec); if (index >= m_maxVertexAttribs) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); return; @@ -3018,15 +3030,17 @@ void WebGLRenderingContext::vertexAttribPointer(unsigned long index, long size, return; } // 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) + long bytesPerElement = size * sizeInBytes(type); + if (bytesPerElement <= 0) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); return; + } if (index >= m_vertexAttribState.size()) m_vertexAttribState.resize(index + 1); long validatedStride = bytesPerElement; - if (stride != 0) { + if (stride) { if ((long) stride < bytesPerElement) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); return; @@ -3059,12 +3073,12 @@ void WebGLRenderingContext::viewport(long x, long y, unsigned long width, unsign cleanupAfterGraphicsCall(false); } -void WebGLRenderingContext::removeObject(CanvasObject* object) +void WebGLRenderingContext::removeObject(WebGLObject* object) { m_canvasObjects.remove(object); } -void WebGLRenderingContext::addObject(CanvasObject* object) +void WebGLRenderingContext::addObject(WebGLObject* object) { removeObject(object); m_canvasObjects.add(object); @@ -3072,8 +3086,8 @@ void WebGLRenderingContext::addObject(CanvasObject* object) void WebGLRenderingContext::detachAndRemoveAllObjects() { - HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); - for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) + HashSet<RefPtr<WebGLObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<WebGLObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) (*it)->detachContext(); m_canvasObjects.clear(); @@ -3083,8 +3097,8 @@ WebGLTexture* WebGLRenderingContext::findTexture(Platform3DObject obj) { if (!obj) return 0; - HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); - for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { + HashSet<RefPtr<WebGLObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<WebGLObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { if ((*it)->isTexture() && (*it)->object() == obj) return reinterpret_cast<WebGLTexture*>((*it).get()); } @@ -3095,8 +3109,8 @@ WebGLRenderbuffer* WebGLRenderingContext::findRenderbuffer(Platform3DObject obj) { if (!obj) return 0; - HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); - for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { + HashSet<RefPtr<WebGLObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<WebGLObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { if ((*it)->isRenderbuffer() && (*it)->object() == obj) return reinterpret_cast<WebGLRenderbuffer*>((*it).get()); } @@ -3107,8 +3121,8 @@ WebGLBuffer* WebGLRenderingContext::findBuffer(Platform3DObject obj) { if (!obj) return 0; - HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); - for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { + HashSet<RefPtr<WebGLObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<WebGLObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { if ((*it)->isBuffer() && (*it)->object() == obj) return reinterpret_cast<WebGLBuffer*>((*it).get()); } @@ -3119,8 +3133,8 @@ WebGLShader* WebGLRenderingContext::findShader(Platform3DObject obj) { if (!obj) return 0; - HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); - for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { + HashSet<RefPtr<WebGLObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<WebGLObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) { if ((*it)->isShader() && (*it)->object() == obj) return reinterpret_cast<WebGLShader*>((*it).get()); } @@ -3242,9 +3256,9 @@ void WebGLRenderingContext::handleNPOTTextures(bool prepareToDraw) texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get(); } if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture()) - m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, tex2D); + m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(tex2D)); if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture()) - m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, texCubeMap); + m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, objectOrZero(texCubeMap)); } } if (resetActiveUnit) @@ -3255,12 +3269,12 @@ void WebGLRenderingContext::createFallbackBlackTextures1x1() { unsigned char black[] = {0, 0, 0, 255}; m_blackTexture2D = createTexture(); - m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D.get()); + m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D->object()); m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, 1, 1, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); m_blackTextureCubeMap = createTexture(); - m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, m_blackTextureCubeMap.get()); + m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, m_blackTextureCubeMap->object()); m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X, 0, GraphicsContext3D::RGBA, 1, 1, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black); m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GraphicsContext3D::RGBA, 1, 1, @@ -3716,7 +3730,7 @@ void WebGLRenderingContext::initVertexAttrib0() { m_vertexAttribState.resize(1); m_vertexAttrib0Buffer = createBuffer(); - m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vertexAttrib0Buffer.get()); + m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vertexAttrib0Buffer->object()); m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, 0, GraphicsContext3D::DYNAMIC_DRAW); m_context->vertexAttribPointer(0, 4, GraphicsContext3D::FLOAT, false, 0, 0); m_vertexAttribState[0].bufferBinding = m_vertexAttrib0Buffer; @@ -3735,7 +3749,7 @@ bool WebGLRenderingContext::simulateVertexAttrib0(long numVertex) if (state.enabled || !m_currentProgram || !m_currentProgram->object() || !m_currentProgram->isUsingVertexAttrib0()) return false; - m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vertexAttrib0Buffer.get()); + m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vertexAttrib0Buffer->object()); long bufferDataSize = (numVertex + 1) * 4 * sizeof(float); if (bufferDataSize > m_vertexAttrib0BufferSize || state.value[0] != m_vertexAttrib0BufferValue[0] @@ -3764,10 +3778,10 @@ void WebGLRenderingContext::restoreStatesAfterVertexAttrib0Simulation() { const VertexAttribState& state = m_vertexAttribState[0]; if (state.bufferBinding != m_vertexAttrib0Buffer) { - m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, state.bufferBinding.get()); + m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(state.bufferBinding.get())); m_context->vertexAttribPointer(0, state.size, state.type, state.normalized, state.originalStride, state.offset); } - m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_boundArrayBuffer.get()); + m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(m_boundArrayBuffer.get())); } } // namespace WebCore diff --git a/WebCore/html/canvas/WebGLRenderingContext.h b/WebCore/html/canvas/WebGLRenderingContext.h index 017570b..608797f 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.h +++ b/WebCore/html/canvas/WebGLRenderingContext.h @@ -29,11 +29,11 @@ #include "CanvasRenderingContext.h" #include "ExceptionCode.h" #include "Float32Array.h" -#include "WebGLGetInfo.h" -#include "Int32Array.h" -#include "Uint8Array.h" #include "GraphicsContext3D.h" +#include "Int32Array.h" #include "PlatformString.h" +#include "Uint8Array.h" +#include "WebGLGetInfo.h" namespace WebCore { @@ -41,7 +41,7 @@ class WebGLActiveInfo; class WebGLBuffer; class WebGLContextAttributes; class WebGLFramebuffer; -class CanvasObject; +class WebGLObject; class WebGLProgram; class WebGLRenderbuffer; class WebGLShader; @@ -52,480 +52,478 @@ class HTMLVideoElement; class ImageData; class WebKitCSSMatrix; - class WebGLRenderingContext : public CanvasRenderingContext { - public: - static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*); - virtual ~WebGLRenderingContext(); - - virtual bool is3d() const { return true; } - virtual bool isAccelerated() 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); +class WebGLRenderingContext : public CanvasRenderingContext { +public: + static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*); + virtual ~WebGLRenderingContext(); - void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&); - void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage, ExceptionCode&); - void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&); - void bufferSubData(unsigned long target, long offset, ArrayBuffer* data, ExceptionCode&); - void bufferSubData(unsigned long target, long offset, ArrayBufferView* 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, 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&); - - bool getAttachedShaders(WebGLProgram*, Vector<WebGLShader*>&, ExceptionCode&); - - int getAttribLocation(WebGLProgram*, const String& name); - - WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&); - - PassRefPtr<WebGLContextAttributes> getContextAttributes(); - - 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); - void readPixels(long x, long y, long width, long height, unsigned long format, unsigned long type, ArrayBufferView* pixels); - 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); + virtual bool is3d() const { return true; } + virtual bool isAccelerated() const { return true; } - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&); - // Obsolete entry points -- to be removed shortly. (FIXME) - void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, 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, ArrayBufferView* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&); - // Obsolete entry points -- to be removed shortly. (FIXME) - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&); - - void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&); - void uniform1fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); - void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); - void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&); - void uniform2fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); - void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); - void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&); - void uniform3fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); - void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); - void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&); - void uniform4fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); - void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); - void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&); - void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); - void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&); - void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); - void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* 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 index, float x); - void vertexAttrib1fv(unsigned long index, Float32Array* values); - void vertexAttrib1fv(unsigned long index, float* values, int size); - void vertexAttrib2f(unsigned long index, float x, float y); - void vertexAttrib2fv(unsigned long index, Float32Array* values); - void vertexAttrib2fv(unsigned long index, float* values, int size); - void vertexAttrib3f(unsigned long index, float x, float y, float z); - void vertexAttrib3fv(unsigned long index, Float32Array* values); - void vertexAttrib3fv(unsigned long index, float* values, int size); - void vertexAttrib4f(unsigned long index, float x, float y, float z, float w); - void vertexAttrib4fv(unsigned long index, Float32Array* values); - void vertexAttrib4fv(unsigned long index, float* values, int size); - void vertexAttribPointer(unsigned long index, long size, unsigned long type, bool normalized, - long stride, 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); - - // Return value true indicates canvas is updated during the call, - // false indicates no updates. - bool paintRenderingResultsToCanvas(); - - // 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(); - WebGLTexture* findTexture(Platform3DObject); - WebGLRenderbuffer* findRenderbuffer(Platform3DObject); - WebGLBuffer* findBuffer(Platform3DObject); - WebGLShader* findShader(Platform3DObject); - - void markContextChanged(); - void cleanupAfterGraphicsCall(bool changed) + 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, ArrayBuffer* data, unsigned long usage, ExceptionCode&); + void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&); + void bufferSubData(unsigned long target, long offset, ArrayBuffer* data, ExceptionCode&); + void bufferSubData(unsigned long target, long offset, ArrayBufferView* 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, 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&); + + bool getAttachedShaders(WebGLProgram*, Vector<WebGLShader*>&, ExceptionCode&); + + int getAttribLocation(WebGLProgram*, const String& name); + + WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + PassRefPtr<WebGLContextAttributes> getContextAttributes(); + + 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); + void readPixels(long x, long y, long width, long height, unsigned long format, unsigned long type, ArrayBufferView* pixels); + 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, ArrayBufferView* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&); + // Obsolete entry points -- to be removed shortly. (FIXME) + void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, 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, ArrayBufferView* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&); + // Obsolete entry points -- to be removed shortly. (FIXME) + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&); + + void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&); + void uniform1fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); + void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&); + void uniform2fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); + void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&); + void uniform3fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); + void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&); + void uniform4fv(const WebGLUniformLocation* location, Float32Array* 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, Int32Array* v, ExceptionCode&); + void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&); + void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); + void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&); + void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); + void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* 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 index, float x); + void vertexAttrib1fv(unsigned long index, Float32Array* values); + void vertexAttrib1fv(unsigned long index, float* values, int size); + void vertexAttrib2f(unsigned long index, float x, float y); + void vertexAttrib2fv(unsigned long index, Float32Array* values); + void vertexAttrib2fv(unsigned long index, float* values, int size); + void vertexAttrib3f(unsigned long index, float x, float y, float z); + void vertexAttrib3fv(unsigned long index, Float32Array* values); + void vertexAttrib3fv(unsigned long index, float* values, int size); + void vertexAttrib4f(unsigned long index, float x, float y, float z, float w); + void vertexAttrib4fv(unsigned long index, Float32Array* values); + void vertexAttrib4fv(unsigned long index, float* values, int size); + void vertexAttribPointer(unsigned long index, long size, unsigned long type, bool normalized, + long stride, long offset, ExceptionCode&); + + void viewport(long x, long y, unsigned long width, unsigned long height); + + virtual GraphicsContext3D* graphicsContext3D() const { return m_context.get(); } + + void reshape(int width, int height); + + virtual void paintRenderingResultsToCanvas(); + + // Helpers for notification about paint events. + void beginPaint(); + void endPaint(); + + void removeObject(WebGLObject*); + + private: + friend class WebGLObject; + + WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>); + + void addObject(WebGLObject*); + void detachAndRemoveAllObjects(); + WebGLTexture* findTexture(Platform3DObject); + WebGLRenderbuffer* findRenderbuffer(Platform3DObject); + WebGLBuffer* findBuffer(Platform3DObject); + WebGLShader* findShader(Platform3DObject); + + void markContextChanged(); + void cleanupAfterGraphicsCall(bool changed) + { + if (changed) + markContextChanged(); + } + + bool isGLES2Compliant(); + + // Helper to return the size in bytes of OpenGL data types + // like GL_FLOAT, GL_INT, etc. + int sizeInBytes(int type); + + // Basic validation of count and offset against number of elements in element array buffer + bool validateElementArraySize(unsigned long count, unsigned long type, long offset); + + // Conservative but quick index validation + bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired); + + // Precise but slow index validation -- only done if conservative checks fail + bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired); + bool validateRenderingState(long numElements); + + bool validateWebGLObject(WebGLObject* object); + + 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<WebGLObject> > 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) + , bytesPerElement(0) + , size(4) + , type(GraphicsContext3D::FLOAT) + , normalized(false) + , stride(16) + , originalStride(0) + , offset(0) { - if (changed) - markContextChanged(); + initValue(); } - bool isGLES2Compliant(); - - // Basic validation of count and offset against number of elements in element array buffer - bool validateElementArraySize(unsigned long count, unsigned long type, long offset); - - // Conservative but quick index validation - bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired); - - // Precise but slow index validation -- only done if conservative checks fail - bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired); - bool validateRenderingState(long numElements); - - bool validateWebGLObject(CanvasObject* object); - - 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) - , bytesPerElement(0) - , size(4) - , type(GraphicsContext3D::FLOAT) - , normalized(false) - , stride(16) - , originalStride(0) - , offset(0) - { - initValue(); - } - - void initValue() - { - value[0] = 0.0f; - value[1] = 0.0f; - value[2] = 0.0f; - value[3] = 1.0f; - } - - bool enabled; - RefPtr<WebGLBuffer> bufferBinding; - long bytesPerElement; - long size; - unsigned long type; - bool normalized; - long stride; - long originalStride; - long offset; - float value[4]; - }; - - Vector<VertexAttribState> m_vertexAttribState; - unsigned m_maxVertexAttribs; - RefPtr<WebGLBuffer> m_vertexAttrib0Buffer; - long m_vertexAttrib0BufferSize; - float m_vertexAttrib0BufferValue[4]; - - RefPtr<WebGLProgram> m_currentProgram; - RefPtr<WebGLFramebuffer> m_framebufferBinding; - RefPtr<WebGLRenderbuffer> m_renderbufferBinding; - class TextureUnitState { - public: - RefPtr<WebGLTexture> m_texture2DBinding; - RefPtr<WebGLTexture> m_textureCubeMapBinding; - }; - Vector<TextureUnitState> m_textureUnits; - unsigned long m_activeTextureUnit; - - RefPtr<WebGLTexture> m_blackTexture2D; - RefPtr<WebGLTexture> m_blackTextureCubeMap; - - int m_maxTextureSize; - int m_maxCubeMapTextureSize; - int m_maxTextureLevel; - int m_maxCubeMapTextureLevel; - - int m_packAlignment; - int m_unpackAlignment; - unsigned long m_implementationColorReadFormat; - unsigned long m_implementationColorReadType; - bool m_unpackFlipY; - bool m_unpackPremultiplyAlpha; - - // Helpers for getParameter and others - WebGLGetInfo getBooleanParameter(unsigned long pname); - WebGLGetInfo getBooleanArrayParameter(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); - - void texImage2DBase(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, void* pixels, ExceptionCode&); - void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat, - unsigned format, unsigned type, Image* image, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, void* pixels, ExceptionCode&); - void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned format, unsigned type, - Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); - - void handleNPOTTextures(bool prepareToDraw); - - void createFallbackBlackTextures1x1(); - - // Helper function for copyTex{Sub}Image, check whether the internalformat - // and the color buffer format of the current bound framebuffer combination - // is valid. - bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat, - unsigned long colorBufferFormat); - - // Helper function to get the current bound texture. - WebGLTexture* getTextureBinding(unsigned long target); - - // Helper function to check input format/type for functions {copy}Tex{Sub}Image. - // Generates GL error and returns false if parameters are invalid. - bool validateTexFuncFormatAndType(unsigned long format, unsigned long type); - - // Helper function to check input parameters for functions {copy}Tex{Sub}Image. - // Generates GL error and returns false if parameters are invalid. - bool validateTexFuncParameters(unsigned long target, long level, - unsigned long internalformat, - long width, long height, long border, - unsigned long format, unsigned long type); - - // Helper function to validate that the given ArrayBufferView - // is of the correct type and contains enough data for the texImage call. - // Generates GL error and returns false if parameters are invalid. - bool validateTexFuncData(long width, long height, - unsigned long format, unsigned long type, - ArrayBufferView* pixels); - - // Helper function to validate mode for draw{Arrays/Elements}. - bool validateDrawMode(unsigned long); - - // Helper function for texParameterf and texParameteri. - void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat); - - // Helper function to print warnings to console. Currently - // used only to warn about use of obsolete functions. - void printWarningToConsole(const String& message); - - // Helper function to validate input parameters for framebuffer functions. - // Generate GL error if parameters are illegal. - bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment); - - // Helper function to validate blend equation mode. - bool validateBlendEquation(unsigned long); - - // Helper function to validate a GL capability. - bool validateCapability(unsigned long); - - // Helper function to validate input parameters for uniform functions. - bool validateUniformParameters(const WebGLUniformLocation* location, Float32Array* v, int mod); - bool validateUniformParameters(const WebGLUniformLocation* location, Int32Array* v, int mod); - bool validateUniformParameters(const WebGLUniformLocation* location, void* v, int size, int mod); - bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, Float32Array* v, int mod); - bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, void* v, int size, int mod); - - // Helper function to validate parameters for bufferData. - // Return the current bound buffer to target, or 0 if parameters are invalid. - WebGLBuffer* validateBufferDataParameters(unsigned long target, unsigned long usage); - - // Helper functions for vertexAttribNf{v}. - void vertexAttribfImpl(unsigned long index, int expectedSize, float v0, float v1, float v2, float v3); - void vertexAttribfvImpl(unsigned long index, Float32Array* v, int expectedSize); - void vertexAttribfvImpl(unsigned long index, float* v, int size, int expectedSize); - - // Helpers for simulating vertexAttrib0 - void initVertexAttrib0(); - bool simulateVertexAttrib0(long numVertex); - void restoreStatesAfterVertexAttrib0Simulation(); - - friend class WebGLStateRestorer; + void initValue() + { + value[0] = 0.0f; + value[1] = 0.0f; + value[2] = 0.0f; + value[3] = 1.0f; + } + + bool enabled; + RefPtr<WebGLBuffer> bufferBinding; + long bytesPerElement; + long size; + unsigned long type; + bool normalized; + long stride; + long originalStride; + long offset; + float value[4]; + }; + + Vector<VertexAttribState> m_vertexAttribState; + unsigned m_maxVertexAttribs; + RefPtr<WebGLBuffer> m_vertexAttrib0Buffer; + long m_vertexAttrib0BufferSize; + float m_vertexAttrib0BufferValue[4]; + + RefPtr<WebGLProgram> m_currentProgram; + RefPtr<WebGLFramebuffer> m_framebufferBinding; + RefPtr<WebGLRenderbuffer> m_renderbufferBinding; + class TextureUnitState { + public: + RefPtr<WebGLTexture> m_texture2DBinding; + RefPtr<WebGLTexture> m_textureCubeMapBinding; }; + Vector<TextureUnitState> m_textureUnits; + unsigned long m_activeTextureUnit; + + RefPtr<WebGLTexture> m_blackTexture2D; + RefPtr<WebGLTexture> m_blackTextureCubeMap; + + int m_maxTextureSize; + int m_maxCubeMapTextureSize; + int m_maxTextureLevel; + int m_maxCubeMapTextureLevel; + + int m_packAlignment; + int m_unpackAlignment; + unsigned long m_implementationColorReadFormat; + unsigned long m_implementationColorReadType; + bool m_unpackFlipY; + bool m_unpackPremultiplyAlpha; + + // Helpers for getParameter and others + WebGLGetInfo getBooleanParameter(unsigned long pname); + WebGLGetInfo getBooleanArrayParameter(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); + + void texImage2DBase(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, void* pixels, ExceptionCode&); + void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat, + unsigned format, unsigned type, Image* image, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, void* pixels, ExceptionCode&); + void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned format, unsigned type, + Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&); + + void handleNPOTTextures(bool prepareToDraw); + + void createFallbackBlackTextures1x1(); + + // Helper function for copyTex{Sub}Image, check whether the internalformat + // and the color buffer format of the current bound framebuffer combination + // is valid. + bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat, + unsigned long colorBufferFormat); + + // Helper function to get the current bound texture. + WebGLTexture* getTextureBinding(unsigned long target); + + // Helper function to check input format/type for functions {copy}Tex{Sub}Image. + // Generates GL error and returns false if parameters are invalid. + bool validateTexFuncFormatAndType(unsigned long format, unsigned long type); + + // Helper function to check input parameters for functions {copy}Tex{Sub}Image. + // Generates GL error and returns false if parameters are invalid. + bool validateTexFuncParameters(unsigned long target, long level, + unsigned long internalformat, + long width, long height, long border, + unsigned long format, unsigned long type); + + // Helper function to validate that the given ArrayBufferView + // is of the correct type and contains enough data for the texImage call. + // Generates GL error and returns false if parameters are invalid. + bool validateTexFuncData(long width, long height, + unsigned long format, unsigned long type, + ArrayBufferView* pixels); + + // Helper function to validate mode for draw{Arrays/Elements}. + bool validateDrawMode(unsigned long); + + // Helper function for texParameterf and texParameteri. + void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat); + + // Helper function to print warnings to console. Currently + // used only to warn about use of obsolete functions. + void printWarningToConsole(const String& message); + + // Helper function to validate input parameters for framebuffer functions. + // Generate GL error if parameters are illegal. + bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment); + + // Helper function to validate blend equation mode. + bool validateBlendEquation(unsigned long); + + // Helper function to validate a GL capability. + bool validateCapability(unsigned long); + + // Helper function to validate input parameters for uniform functions. + bool validateUniformParameters(const WebGLUniformLocation* location, Float32Array* v, int mod); + bool validateUniformParameters(const WebGLUniformLocation* location, Int32Array* v, int mod); + bool validateUniformParameters(const WebGLUniformLocation* location, void* v, int size, int mod); + bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, Float32Array* v, int mod); + bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, void* v, int size, int mod); + + // Helper function to validate parameters for bufferData. + // Return the current bound buffer to target, or 0 if parameters are invalid. + WebGLBuffer* validateBufferDataParameters(unsigned long target, unsigned long usage); + + // Helper functions for vertexAttribNf{v}. + void vertexAttribfImpl(unsigned long index, int expectedSize, float v0, float v1, float v2, float v3); + void vertexAttribfvImpl(unsigned long index, Float32Array* v, int expectedSize); + void vertexAttribfvImpl(unsigned long index, float* v, int size, int expectedSize); + + // Helpers for simulating vertexAttrib0 + void initVertexAttrib0(); + bool simulateVertexAttrib0(long numVertex); + void restoreStatesAfterVertexAttrib0Simulation(); + + friend class WebGLStateRestorer; +}; } // namespace WebCore diff --git a/WebCore/html/canvas/WebGLRenderingContext.idl b/WebCore/html/canvas/WebGLRenderingContext.idl index 654c7aa..711aa42 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.idl +++ b/WebCore/html/canvas/WebGLRenderingContext.idl @@ -464,8 +464,6 @@ module html { const unsigned int UNPACK_FLIP_Y_WEBGL = 0x9240; const unsigned int UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241; - long sizeInBytes(in unsigned long type) raises(DOMException); - 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); @@ -538,8 +536,7 @@ module html { WebGLActiveInfo getActiveUniform(in WebGLProgram program, in unsigned long index) raises (DOMException); - // Array getAttachedShaders(GLuint program) raises (DOMException); - [Custom] void getAttachedShaders(GLuint program) + [Custom] void getAttachedShaders(in WebGLProgram program) raises (DOMException); int getAttribLocation(in WebGLProgram program, in DOMString name); diff --git a/WebCore/html/canvas/WebGLShader.cpp b/WebCore/html/canvas/WebGLShader.cpp index 664d3cb..4f8bf68 100644 --- a/WebCore/html/canvas/WebGLShader.cpp +++ b/WebCore/html/canvas/WebGLShader.cpp @@ -28,6 +28,7 @@ #if ENABLE(3D_CANVAS) #include "WebGLShader.h" + #include "WebGLRenderingContext.h" namespace WebCore { @@ -38,13 +39,13 @@ PassRefPtr<WebGLShader> WebGLShader::create(WebGLRenderingContext* ctx, Graphics } WebGLShader::WebGLShader(WebGLRenderingContext* ctx, GraphicsContext3D::WebGLEnumType type) - : CanvasObject(ctx) + : WebGLObject(ctx) , m_type(type) { setObject(context()->graphicsContext3D()->createShader(type)); } -void WebGLShader::_deleteObject(Platform3DObject object) +void WebGLShader::deleteObjectImpl(Platform3DObject object) { context()->graphicsContext3D()->deleteShader(object); } diff --git a/WebCore/html/canvas/WebGLShader.h b/WebCore/html/canvas/WebGLShader.h index a0daa59..c0c41df 100644 --- a/WebCore/html/canvas/WebGLShader.h +++ b/WebCore/html/canvas/WebGLShader.h @@ -26,31 +26,31 @@ #ifndef WebGLShader_h #define WebGLShader_h -#include "CanvasObject.h" +#include "WebGLObject.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class WebGLShader : public CanvasObject { - public: - virtual ~WebGLShader() { deleteObject(); } - - static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); - GraphicsContext3D::WebGLEnumType getType() const { return m_type; } +class WebGLShader : public WebGLObject { +public: + virtual ~WebGLShader() { deleteObject(); } - private: - WebGLShader(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); + static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); - virtual void _deleteObject(Platform3DObject); + GraphicsContext3D::WebGLEnumType getType() const { return m_type; } - virtual bool isShader() const { return true; } +private: + WebGLShader(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); + + virtual void deleteObjectImpl(Platform3DObject); + + virtual bool isShader() const { return true; } + + GraphicsContext3D::WebGLEnumType m_type; +}; - GraphicsContext3D::WebGLEnumType m_type; - }; - } // namespace WebCore #endif // WebGLShader_h diff --git a/WebCore/html/canvas/WebGLTexture.cpp b/WebCore/html/canvas/WebGLTexture.cpp index d832038..2c50bf8 100644 --- a/WebCore/html/canvas/WebGLTexture.cpp +++ b/WebCore/html/canvas/WebGLTexture.cpp @@ -28,6 +28,7 @@ #if ENABLE(3D_CANVAS) #include "WebGLTexture.h" + #include "WebGLRenderingContext.h" namespace WebCore { @@ -38,7 +39,7 @@ PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx) } WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) - : CanvasObject(ctx) + : WebGLObject(ctx) , cubeMapRWrapModeInitialized(false) , m_target(0) , m_minFilter(GraphicsContext3D::NEAREST_MIPMAP_LINEAR) @@ -197,7 +198,7 @@ bool WebGLTexture::needToUseBlackTexture() const return m_needToUseBlackTexture; } -void WebGLTexture::_deleteObject(Platform3DObject object) +void WebGLTexture::deleteObjectImpl(Platform3DObject object) { context()->graphicsContext3D()->deleteTexture(object); } diff --git a/WebCore/html/canvas/WebGLTexture.h b/WebCore/html/canvas/WebGLTexture.h index d4a32f0..64bd6e0 100644 --- a/WebCore/html/canvas/WebGLTexture.h +++ b/WebCore/html/canvas/WebGLTexture.h @@ -26,104 +26,106 @@ #ifndef WebGLTexture_h #define WebGLTexture_h -#include "CanvasObject.h" +#include "WebGLObject.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> namespace WebCore { - - class WebGLTexture : public CanvasObject { - public: - virtual ~WebGLTexture() { deleteObject(); } - - static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*); - bool isCubeMapRWrapModeInitialized() { - return cubeMapRWrapModeInitialized; - } +class WebGLTexture : public WebGLObject { +public: + virtual ~WebGLTexture() { deleteObject(); } - void setCubeMapRWrapModeInitialized(bool initialized) { - cubeMapRWrapModeInitialized = initialized; - } + static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*); - void setTarget(unsigned long target, int maxLevel); - void setParameteri(unsigned long pname, int param); - void setParameterf(unsigned long pname, float param); + bool isCubeMapRWrapModeInitialized() + { + return cubeMapRWrapModeInitialized; + } - void setLevelInfo(unsigned long target, int level, unsigned long internalFormat, int width, int height, unsigned long type); + void setCubeMapRWrapModeInitialized(bool initialized) + { + cubeMapRWrapModeInitialized = initialized; + } - bool canGenerateMipmaps(); - // Generate all level information. - void generateMipmapLevelInfo(); + void setTarget(unsigned long target, int maxLevel); + void setParameteri(unsigned long pname, int param); + void setParameterf(unsigned long pname, float param); - unsigned long getInternalFormat() const; + void setLevelInfo(unsigned long target, int level, unsigned long internalFormat, int width, int height, unsigned long type); - // Whether width/height is NotPowerOfTwo. - static bool isNPOT(unsigned, unsigned); + bool canGenerateMipmaps(); + // Generate all level information. + void generateMipmapLevelInfo(); - bool isNPOT() const; - // Determine if texture sampling should always return [0, 0, 0, 1] (OpenGL ES 2.0 Sec 3.8.2). - bool needToUseBlackTexture() const; + unsigned long getInternalFormat() const; - static int computeLevelCount(int width, int height); + // Whether width/height is NotPowerOfTwo. + static bool isNPOT(unsigned, unsigned); - protected: - WebGLTexture(WebGLRenderingContext*); + bool isNPOT() const; + // Determine if texture sampling should always return [0, 0, 0, 1] (OpenGL ES 2.0 Sec 3.8.2). + bool needToUseBlackTexture() const; - virtual void _deleteObject(Platform3DObject); + static int computeLevelCount(int width, int height); - private: - virtual bool isTexture() const { return true; } +protected: + WebGLTexture(WebGLRenderingContext*); - void update(); + virtual void deleteObjectImpl(Platform3DObject); - int mapTargetToIndex(unsigned long); +private: + virtual bool isTexture() const { return true; } - bool cubeMapRWrapModeInitialized; + void update(); - unsigned long m_target; + int mapTargetToIndex(unsigned long); - int m_minFilter; - int m_magFilter; - int m_wrapS; - int m_wrapT; + bool cubeMapRWrapModeInitialized; - class LevelInfo { - public: - LevelInfo() - : valid(false) - , internalFormat(0) - , width(0) - , height(0) - , type(0) - { - } + unsigned long m_target; - void setInfo(unsigned long internalFmt, int w, int h, unsigned long tp) - { - valid = true; - internalFormat = internalFmt; - width = w; - height = h; - type = tp; - } + int m_minFilter; + int m_magFilter; + int m_wrapS; + int m_wrapT; - bool valid; - unsigned long internalFormat; - int width; - int height; - unsigned long type; - }; + class LevelInfo { + public: + LevelInfo() + : valid(false) + , internalFormat(0) + , width(0) + , height(0) + , type(0) + { + } - Vector<Vector<LevelInfo> > m_info; + void setInfo(unsigned long internalFmt, int w, int h, unsigned long tp) + { + valid = true; + internalFormat = internalFmt; + width = w; + height = h; + type = tp; + } - bool m_isNPOT; - bool m_isComplete; - bool m_needToUseBlackTexture; + bool valid; + unsigned long internalFormat; + int width; + int height; + unsigned long type; }; - + + Vector<Vector<LevelInfo> > m_info; + + bool m_isNPOT; + bool m_isComplete; + bool m_needToUseBlackTexture; +}; + } // namespace WebCore #endif // WebGLTexture_h diff --git a/WebCore/html/canvas/WebGLUniformLocation.h b/WebCore/html/canvas/WebGLUniformLocation.h index f9f7a11..66647c5 100644 --- a/WebCore/html/canvas/WebGLUniformLocation.h +++ b/WebCore/html/canvas/WebGLUniformLocation.h @@ -27,7 +27,7 @@ #ifndef WebGLUniformLocation_h #define WebGLUniformLocation_h -#include "CanvasObject.h" +#include "WebGLObject.h" #include "WebGLProgram.h" #include <wtf/PassRefPtr.h> |