diff options
Diffstat (limited to 'WebCore/html/canvas')
-rw-r--r-- | WebCore/html/canvas/CanvasRenderingContext.cpp | 13 | ||||
-rw-r--r-- | WebCore/html/canvas/CanvasRenderingContext.h | 1 | ||||
-rw-r--r-- | WebCore/html/canvas/CanvasRenderingContext2D.cpp | 28 | ||||
-rw-r--r-- | WebCore/html/canvas/Float32Array.cpp | 2 | ||||
-rw-r--r-- | WebCore/html/canvas/Float32Array.h | 2 | ||||
-rw-r--r-- | WebCore/html/canvas/TypedArrayBase.h | 2 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLBuffer.cpp | 1 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLBuffer.h | 1 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLFramebuffer.cpp | 2 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLRenderingContext.cpp | 347 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLRenderingContext.h | 23 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLRenderingContext.idl | 345 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLTexture.cpp | 5 | ||||
-rw-r--r-- | WebCore/html/canvas/WebGLTexture.h | 2 |
14 files changed, 438 insertions, 336 deletions
diff --git a/WebCore/html/canvas/CanvasRenderingContext.cpp b/WebCore/html/canvas/CanvasRenderingContext.cpp index fed8cb2..1e897d3 100644 --- a/WebCore/html/canvas/CanvasRenderingContext.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext.cpp @@ -25,7 +25,9 @@ #include "config.h" #include "CanvasRenderingContext.h" - +#if ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(3D_CANVAS) +#include "GraphicsContext3D.h" +#endif #include "HTMLCanvasElement.h" namespace WebCore { @@ -45,4 +47,13 @@ void CanvasRenderingContext::deref() m_canvas->deref(); } +bool CanvasRenderingContext::paintsIntoCanvasBuffer() const +{ +#if ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(3D_CANVAS) + if (GraphicsContext3D* context3D = graphicsContext3D()) + return context3D->paintsIntoCanvasBuffer(); +#endif + return true; +} + } // namespace WebCore diff --git a/WebCore/html/canvas/CanvasRenderingContext.h b/WebCore/html/canvas/CanvasRenderingContext.h index cb26363..2cdbe1d 100644 --- a/WebCore/html/canvas/CanvasRenderingContext.h +++ b/WebCore/html/canvas/CanvasRenderingContext.h @@ -54,6 +54,7 @@ namespace WebCore { virtual GraphicsContext3D* graphicsContext3D() const { return 0; } virtual void paintRenderingResultsToCanvas() {} + bool paintsIntoCanvasBuffer() const; private: HTMLCanvasElement* m_canvas; diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 58ec1d0..2a7b96a 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -1451,7 +1451,7 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme if (!cachedImage || !image->cachedImage()->image()) return CanvasPattern::create(Image::nullImage(), repeatX, repeatY, true); - bool originClean = !canvas()->securityOrigin().taintsCanvas(KURL(KURL(), cachedImage->url())) && cachedImage->image()->hasSingleSecurityOrigin(); + bool originClean = !canvas()->securityOrigin().taintsCanvas(KURL(KURL(), cachedImage->response().url())) && cachedImage->image()->hasSingleSecurityOrigin(); return CanvasPattern::create(cachedImage->image(), repeatX, repeatY, originClean); } @@ -1727,7 +1727,19 @@ void CanvasRenderingContext2D::strokeText(const String& text, float x, float y, PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text) { RefPtr<TextMetrics> metrics = TextMetrics::create(); + +#if PLATFORM(QT) + // We always use complex text shaping since it can't be turned off for QPainterPath::addText(). + Font::CodePath oldCodePath = Font::codePath(); + Font::setCodePath(Font::Complex); +#endif + metrics->setWidth(accessFont().width(TextRun(text.characters(), text.length()))); + +#if PLATFORM(QT) + Font::setCodePath(oldCodePath); +#endif + return metrics; } @@ -1838,7 +1850,18 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo #endif c->setTextDrawingMode(fill ? cTextFill : cTextStroke); + +#if PLATFORM(QT) + // We always use complex text shaping since it can't be turned off for QPainterPath::addText(). + Font::CodePath oldCodePath = Font::codePath(); + Font::setCodePath(Font::Complex); +#endif + c->drawBidiText(font, textRun, location); + +#if PLATFORM(QT) + Font::setCodePath(oldCodePath); +#endif } const Font& CanvasRenderingContext2D::accessFont() @@ -1851,7 +1874,8 @@ const Font& CanvasRenderingContext2D::accessFont() void CanvasRenderingContext2D::paintRenderingResultsToCanvas() { #if ENABLE(ACCELERATED_2D_CANVAS) - drawingContext()->syncSoftwareCanvas(); + if (GraphicsContext* c = drawingContext()) + c->syncSoftwareCanvas(); #endif } diff --git a/WebCore/html/canvas/Float32Array.cpp b/WebCore/html/canvas/Float32Array.cpp index c95fb48..e6e8439 100644 --- a/WebCore/html/canvas/Float32Array.cpp +++ b/WebCore/html/canvas/Float32Array.cpp @@ -37,7 +37,7 @@ PassRefPtr<Float32Array> Float32Array::create(unsigned length) return TypedArrayBase<float>::create<Float32Array>(length); } -PassRefPtr<Float32Array> Float32Array::create(float* array, unsigned length) +PassRefPtr<Float32Array> Float32Array::create(const float* array, unsigned length) { return TypedArrayBase<float>::create<Float32Array>(array, length); } diff --git a/WebCore/html/canvas/Float32Array.h b/WebCore/html/canvas/Float32Array.h index 8112264..ab57087 100644 --- a/WebCore/html/canvas/Float32Array.h +++ b/WebCore/html/canvas/Float32Array.h @@ -35,7 +35,7 @@ namespace WebCore { class Float32Array : public TypedArrayBase<float> { public: static PassRefPtr<Float32Array> create(unsigned length); - static PassRefPtr<Float32Array> create(float* array, unsigned length); + static PassRefPtr<Float32Array> create(const float* array, unsigned length); static PassRefPtr<Float32Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length); using TypedArrayBase<float>::set; diff --git a/WebCore/html/canvas/TypedArrayBase.h b/WebCore/html/canvas/TypedArrayBase.h index c55896b..e69c2b5 100644 --- a/WebCore/html/canvas/TypedArrayBase.h +++ b/WebCore/html/canvas/TypedArrayBase.h @@ -67,7 +67,7 @@ class TypedArrayBase : public ArrayBufferView { } template <class Subclass> - static PassRefPtr<Subclass> create(T* array, unsigned length) + static PassRefPtr<Subclass> create(const T* array, unsigned length) { RefPtr<Subclass> a = create<Subclass>(length); if (a) diff --git a/WebCore/html/canvas/WebGLBuffer.cpp b/WebCore/html/canvas/WebGLBuffer.cpp index fc98a9d..d43868d 100644 --- a/WebCore/html/canvas/WebGLBuffer.cpp +++ b/WebCore/html/canvas/WebGLBuffer.cpp @@ -29,6 +29,7 @@ #include "WebGLBuffer.h" +#include "ArrayBufferView.h" #include "CheckedInt.h" #include "WebGLRenderingContext.h" diff --git a/WebCore/html/canvas/WebGLBuffer.h b/WebCore/html/canvas/WebGLBuffer.h index a7a25b9..f18a9bf 100644 --- a/WebCore/html/canvas/WebGLBuffer.h +++ b/WebCore/html/canvas/WebGLBuffer.h @@ -33,6 +33,7 @@ #include <wtf/RefCounted.h> namespace WebCore { +class ArrayBufferView; class WebGLBuffer : public WebGLObject { public: diff --git a/WebCore/html/canvas/WebGLFramebuffer.cpp b/WebCore/html/canvas/WebGLFramebuffer.cpp index bfa08b7..6291705 100644 --- a/WebCore/html/canvas/WebGLFramebuffer.cpp +++ b/WebCore/html/canvas/WebGLFramebuffer.cpp @@ -101,7 +101,7 @@ unsigned long WebGLFramebuffer::getColorBufferFormat() return GraphicsContext3D::RGB; } } else if (m_colorAttachment->isTexture()) - return (reinterpret_cast<WebGLTexture*>(m_colorAttachment))->getInternalFormat(); + return (reinterpret_cast<WebGLTexture*>(m_colorAttachment))->getInternalFormat(0); } return 0; } diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp index 4465833..44d3e08 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.cpp +++ b/WebCore/html/canvas/WebGLRenderingContext.cpp @@ -36,8 +36,10 @@ #include "FrameView.h" #include "HTMLCanvasElement.h" #include "HTMLImageElement.h" +#include "HTMLVideoElement.h" #include "ImageBuffer.h" #include "ImageData.h" +#include "IntSize.h" #include "NotImplemented.h" #include "RenderBox.h" #include "RenderLayer.h" @@ -98,6 +100,7 @@ WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa , m_needsUpdate(true) , m_markedCanvasDirty(false) , m_activeTextureUnit(0) + , m_videoCache(4) , m_packAlignment(4) , m_unpackAlignment(4) , m_unpackFlipY(false) @@ -127,10 +130,10 @@ WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa m_context->getIntegerv(GraphicsContext3D::MAX_CUBE_MAP_TEXTURE_SIZE, &m_maxCubeMapTextureSize); m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextureSize, m_maxCubeMapTextureSize); - if (!isGLES2Compliant()) { + if (!isGLES2NPOTStrict()) createFallbackBlackTextures1x1(); + if (!isGLES2Compliant()) initVertexAttrib0(); - } m_context->reshape(canvas()->width(), canvas()->height()); m_context->viewport(0, 0, canvas()->width(), canvas()->height()); } @@ -303,7 +306,7 @@ void WebGLRenderingContext::bindTexture(unsigned long target, WebGLTexture* text return; } m_context->bindTexture(target, objectOrZero(texture)); - if (!isGLES2Compliant() && texture) + if (texture) texture->setTarget(target, maxLevel); // FIXME: do we want to do this on all platforms? @@ -335,20 +338,16 @@ void WebGLRenderingContext::blendColor(double red, double green, double blue, do void WebGLRenderingContext::blendEquation(unsigned long mode) { - if (!isGLES2Compliant()) { - if (!validateBlendEquation(mode)) - return; - } + if (!validateBlendEquation(mode)) + return; m_context->blendEquation(mode); cleanupAfterGraphicsCall(false); } void WebGLRenderingContext::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha) { - if (!isGLES2Compliant()) { - if (!validateBlendEquation(modeRGB) || !validateBlendEquation(modeAlpha)) - return; - } + if (!validateBlendEquation(modeRGB) || !validateBlendEquation(modeAlpha)) + return; m_context->blendEquationSeparate(modeRGB, modeAlpha); cleanupAfterGraphicsCall(false); } @@ -372,9 +371,11 @@ void WebGLRenderingContext::bufferData(unsigned long target, int size, unsigned WebGLBuffer* buffer = validateBufferDataParameters(target, usage); if (!buffer) return; - if (!buffer->associateBufferData(size)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + if (!buffer->associateBufferData(size)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } } m_context->bufferData(target, size, usage); @@ -387,12 +388,14 @@ void WebGLRenderingContext::bufferData(unsigned long target, ArrayBuffer* data, WebGLBuffer* buffer = validateBufferDataParameters(target, usage); if (!buffer) return; - if (!buffer->associateBufferData(data)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + if (!buffer->associateBufferData(data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } } - m_context->bufferData(target, data, usage); + m_context->bufferData(target, data->byteLength(), data->data(), usage); cleanupAfterGraphicsCall(false); } @@ -402,12 +405,14 @@ void WebGLRenderingContext::bufferData(unsigned long target, ArrayBufferView* da WebGLBuffer* buffer = validateBufferDataParameters(target, usage); if (!buffer) return; - if (!buffer->associateBufferData(data)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + if (!buffer->associateBufferData(data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } } - m_context->bufferData(target, data, usage); + m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage); cleanupAfterGraphicsCall(false); } @@ -417,12 +422,14 @@ void WebGLRenderingContext::bufferSubData(unsigned long target, long offset, Arr WebGLBuffer* buffer = validateBufferDataParameters(target, GraphicsContext3D::STATIC_DRAW); if (!buffer) return; - if (!buffer->associateBufferSubData(offset, data)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + if (!buffer->associateBufferSubData(offset, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } } - m_context->bufferSubData(target, offset, data); + m_context->bufferSubData(target, offset, data->byteLength(), data->data()); cleanupAfterGraphicsCall(false); } @@ -432,22 +439,22 @@ void WebGLRenderingContext::bufferSubData(unsigned long target, long offset, Arr WebGLBuffer* buffer = validateBufferDataParameters(target, GraphicsContext3D::STATIC_DRAW); if (!buffer) return; - if (!buffer->associateBufferSubData(offset, data)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + if (!buffer->associateBufferSubData(offset, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } } - m_context->bufferSubData(target, offset, data); + m_context->bufferSubData(target, offset, data->byteLength(), data->baseAddress()); cleanupAfterGraphicsCall(false); } unsigned long WebGLRenderingContext::checkFramebufferStatus(unsigned long target) { - if (!isGLES2Compliant()) { - if (target != GraphicsContext3D::FRAMEBUFFER) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); - return 0; - } + if (target != GraphicsContext3D::FRAMEBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return 0; } if (!m_framebufferBinding || !m_framebufferBinding->object()) return GraphicsContext3D::FRAMEBUFFER_COMPLETE; @@ -457,11 +464,9 @@ unsigned long WebGLRenderingContext::checkFramebufferStatus(unsigned long target void WebGLRenderingContext::clear(unsigned long mask) { - if (!isGLES2Compliant()) { - if (mask & ~(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; - } + if (mask & ~(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; } m_context->clear(mask); cleanupAfterGraphicsCall(true); @@ -522,15 +527,14 @@ void WebGLRenderingContext::copyTexImage2D(unsigned long target, long level, uns m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; } - if (level && WebGLTexture::isNPOT(width, height)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); - return; - } + } + if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; } m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); // FIXME: if the framebuffer is not complete, none of the below should be executed. - if (!isGLES2Compliant()) - tex->setLevelInfo(target, level, internalformat, width, height, GraphicsContext3D::UNSIGNED_BYTE); + tex->setLevelInfo(target, level, internalformat, width, height, GraphicsContext3D::UNSIGNED_BYTE); if (m_framebufferBinding) m_framebufferBinding->onAttachedObjectChange(tex); cleanupAfterGraphicsCall(false); @@ -543,7 +547,7 @@ void WebGLRenderingContext::copyTexSubImage2D(unsigned long target, long level, return; if (!isGLES2Compliant()) { if (m_framebufferBinding && m_framebufferBinding->object() - && !isTexInternalFormatColorBufferCombinationValid(tex->getInternalFormat(), + && !isTexInternalFormatColorBufferCombinationValid(tex->getInternalFormat(level), m_framebufferBinding->getColorBufferFormat())) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; @@ -713,10 +717,8 @@ void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha void WebGLRenderingContext::disable(unsigned long cap) { - if (!isGLES2Compliant()) { - if (!validateCapability(cap)) - return; - } + if (!validateCapability(cap)) + return; m_context->disable(cap); cleanupAfterGraphicsCall(false); } @@ -916,26 +918,27 @@ void WebGLRenderingContext::drawArrays(unsigned long mode, long first, long coun return; } - // Ensure we have a valid rendering state - CheckedInt<int32_t> checkedFirst(first); - CheckedInt<int32_t> checkedCount(count); - CheckedInt<int32_t> checkedSum = checkedFirst + checkedCount; - if (!checkedSum.valid() || !validateRenderingState(checkedSum.value())) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); - return; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + // Ensure we have a valid rendering state + CheckedInt<int32_t> checkedFirst(first); + CheckedInt<int32_t> checkedCount(count); + CheckedInt<int32_t> checkedSum = checkedFirst + checkedCount; + if (!checkedSum.valid() || !validateRenderingState(checkedSum.value())) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } } bool vertexAttrib0Simulated = false; - if (!isGLES2Compliant()) { + if (!isGLES2Compliant()) vertexAttrib0Simulated = simulateVertexAttrib0(first + count - 1); + if (!isGLES2NPOTStrict()) handleNPOTTextures(true); - } m_context->drawArrays(mode, first, count); - if (!isGLES2Compliant()) { + if (!isGLES2Compliant() && vertexAttrib0Simulated) + restoreStatesAfterVertexAttrib0Simulation(); + if (!isGLES2NPOTStrict()) handleNPOTTextures(false); - if (vertexAttrib0Simulated) - restoreStatesAfterVertexAttrib0Simulation(); - } cleanupAfterGraphicsCall(true); } @@ -960,40 +963,41 @@ void WebGLRenderingContext::drawElements(unsigned long mode, long count, unsigne return; } - // Ensure we have a valid rendering state - long numElements; - - if (!validateElementArraySize(count, type, offset)) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); - return; - } - - if (!validateIndexArrayConservative(type, numElements) || !validateRenderingState(numElements)) - if (!validateIndexArrayPrecise(count, type, offset, numElements) || !validateRenderingState(numElements)) { + long numElements = 0; + if (!isErrorGeneratedOnOutOfBoundsAccesses()) { + // Ensure we have a valid rendering state + if (!validateElementArraySize(count, type, offset)) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; } + if (!validateIndexArrayConservative(type, numElements) || !validateRenderingState(numElements)) { + if (!validateIndexArrayPrecise(count, type, offset, numElements) || !validateRenderingState(numElements)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + } + } bool vertexAttrib0Simulated = false; if (!isGLES2Compliant()) { + if (!numElements) + validateIndexArrayPrecise(count, type, offset, numElements); vertexAttrib0Simulated = simulateVertexAttrib0(numElements); - handleNPOTTextures(true); } + if (!isGLES2NPOTStrict()) + handleNPOTTextures(true); m_context->drawElements(mode, count, type, offset); - if (!isGLES2Compliant()) { + if (!isGLES2Compliant() && vertexAttrib0Simulated) + restoreStatesAfterVertexAttrib0Simulation(); + if (!isGLES2NPOTStrict()) handleNPOTTextures(false); - if (vertexAttrib0Simulated) - restoreStatesAfterVertexAttrib0Simulation(); - } cleanupAfterGraphicsCall(true); } void WebGLRenderingContext::enable(unsigned long cap) { - if (!isGLES2Compliant()) { - if (!validateCapability(cap)) - return; - } + if (!validateCapability(cap)) + return; m_context->enable(cap); cleanupAfterGraphicsCall(false); } @@ -1116,15 +1120,12 @@ void WebGLRenderingContext::generateMipmap(unsigned long target) WebGLTexture* tex = validateTextureBinding(target, false); if (!tex) return; - if (!isGLES2Compliant()) { - if (!tex->canGenerateMipmaps()) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); - return; - } + if (!tex->canGenerateMipmaps()) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; } m_context->generateMipmap(target); - if (!isGLES2Compliant()) - tex->generateMipmapLevelInfo(); + tex->generateMipmapLevelInfo(); cleanupAfterGraphicsCall(false); } @@ -1804,11 +1805,9 @@ long WebGLRenderingContext::getVertexAttribOffset(unsigned long index, unsigned void WebGLRenderingContext::hint(unsigned long target, unsigned long mode) { - if (!isGLES2Compliant()) { - if (target != GraphicsContext3D::GENERATE_MIPMAP_HINT) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); - return; - } + if (target != GraphicsContext3D::GENERATE_MIPMAP_HINT) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; } m_context->hint(target, mode); cleanupAfterGraphicsCall(false); @@ -1824,10 +1823,8 @@ bool WebGLRenderingContext::isBuffer(WebGLBuffer* buffer) bool WebGLRenderingContext::isEnabled(unsigned long cap) { - if (!isGLES2Compliant()) { - if (!validateCapability(cap)) - return false; - } + if (!validateCapability(cap)) + return false; return m_context->isEnabled(cap); } @@ -2086,7 +2083,7 @@ void WebGLRenderingContext::texImage2DBase(unsigned target, unsigned level, unsi WebGLTexture* tex = validateTextureBinding(target, true); if (!tex) return; - if (!isGLES2Compliant()) { + if (!isGLES2NPOTStrict()) { if (level && WebGLTexture::isNPOT(width, height)) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); return; @@ -2094,8 +2091,7 @@ void WebGLRenderingContext::texImage2DBase(unsigned target, unsigned level, unsi } m_context->texImage2D(target, level, internalformat, width, height, border, format, type, pixels); - if (!isGLES2Compliant()) - tex->setLevelInfo(target, level, internalformat, width, height, type); + tex->setLevelInfo(target, level, internalformat, width, height, type); if (m_framebufferBinding) m_framebufferBinding->onAttachedObjectChange(tex); cleanupAfterGraphicsCall(false); @@ -2128,11 +2124,11 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned void* data = pixels ? pixels->baseAddress() : 0; Vector<uint8_t> tempData; bool changeUnpackAlignment = false; - if (pixels && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { + if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { if (!m_context->extractTextureData(width, height, format, type, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, - pixels, + data, tempData)) return; data = tempData.data(); @@ -2188,19 +2184,32 @@ void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned m_unpackFlipY, m_unpackPremultiplyAlpha, ec); } +PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* video) +{ + if (!video || !video->videoWidth() || !video->videoHeight()) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return 0; + } + IntSize size(video->videoWidth(), video->videoHeight()); + ImageBuffer* buf = m_videoCache.imageBuffer(size); + if (!buf) { + m_context->synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY); + return 0; + } + IntRect destRect(0, 0, size.width(), size.height()); + // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. + video->paintCurrentFrameInContext(buf->context(), destRect); + return buf->copyImage(); +} + void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode& ec) { - // FIXME: Need to implement this call - UNUSED_PARAM(target); - UNUSED_PARAM(level); - UNUSED_PARAM(internalformat); - UNUSED_PARAM(format); - UNUSED_PARAM(type); - UNUSED_PARAM(video); - ec = 0; - cleanupAfterGraphicsCall(false); + RefPtr<Image> image = videoFrameToImage(video); + if (!video) + return; + texImage2DImpl(target, level, internalformat, format, type, image.get(), m_unpackFlipY, m_unpackPremultiplyAlpha, ec); } void WebGLRenderingContext::texParameter(unsigned long target, unsigned long pname, float paramf, int parami, bool isFloat) @@ -2208,32 +2217,29 @@ void WebGLRenderingContext::texParameter(unsigned long target, unsigned long pna WebGLTexture* tex = validateTextureBinding(target, false); if (!tex) return; - if (!isGLES2Compliant()) { - switch (pname) { - case GraphicsContext3D::TEXTURE_MIN_FILTER: - case GraphicsContext3D::TEXTURE_MAG_FILTER: - break; - case GraphicsContext3D::TEXTURE_WRAP_S: - case GraphicsContext3D::TEXTURE_WRAP_T: - if (isFloat && paramf != GraphicsContext3D::CLAMP_TO_EDGE && paramf != GraphicsContext3D::MIRRORED_REPEAT && paramf != GraphicsContext3D::REPEAT - || !isFloat && parami != GraphicsContext3D::CLAMP_TO_EDGE && parami != GraphicsContext3D::MIRRORED_REPEAT && parami != GraphicsContext3D::REPEAT) { - m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); - return; - } - break; - default: + switch (pname) { + case GraphicsContext3D::TEXTURE_MIN_FILTER: + case GraphicsContext3D::TEXTURE_MAG_FILTER: + break; + case GraphicsContext3D::TEXTURE_WRAP_S: + case GraphicsContext3D::TEXTURE_WRAP_T: + if (isFloat && paramf != GraphicsContext3D::CLAMP_TO_EDGE && paramf != GraphicsContext3D::MIRRORED_REPEAT && paramf != GraphicsContext3D::REPEAT + || !isFloat && parami != GraphicsContext3D::CLAMP_TO_EDGE && parami != GraphicsContext3D::MIRRORED_REPEAT && parami != GraphicsContext3D::REPEAT) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); return; } - if (isFloat) - tex->setParameterf(pname, paramf); - else - tex->setParameteri(pname, parami); + break; + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; } - if (isFloat) + if (isFloat) { + tex->setParameterf(pname, paramf); m_context->texParameterf(target, pname, paramf); - else + } else { + tex->setParameteri(pname, parami); m_context->texParameteri(target, pname, parami); + } cleanupAfterGraphicsCall(false); } @@ -2284,11 +2290,11 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig void* data = pixels ? pixels->baseAddress() : 0; Vector<uint8_t> tempData; bool changeUnpackAlignment = false; - if (pixels && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { + if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { if (!m_context->extractTextureData(width, height, format, type, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, - pixels, + data, tempData)) return; data = tempData.data(); @@ -2342,16 +2348,11 @@ void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsig void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode& ec) { - // FIXME: Need to implement this call - UNUSED_PARAM(target); - UNUSED_PARAM(level); - UNUSED_PARAM(xoffset); - UNUSED_PARAM(yoffset); - UNUSED_PARAM(format); - UNUSED_PARAM(type); - UNUSED_PARAM(video); ec = 0; - cleanupAfterGraphicsCall(false); + RefPtr<Image> image = videoFrameToImage(video); + if (!video) + return; + texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get(), m_unpackFlipY, m_unpackPremultiplyAlpha, ec); } void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode& ec) @@ -2999,6 +3000,16 @@ bool WebGLRenderingContext::isGLES2Compliant() return m_context->isGLES2Compliant(); } +bool WebGLRenderingContext::isGLES2NPOTStrict() +{ + return m_context->isGLES2NPOTStrict(); +} + +bool WebGLRenderingContext::isErrorGeneratedOnOutOfBoundsAccesses() +{ + return m_context->isErrorGeneratedOnOutOfBoundsAccesses(); +} + void WebGLRenderingContext::handleNPOTTextures(bool prepareToDraw) { bool resetActiveUnit = false; @@ -3536,14 +3547,14 @@ bool WebGLRenderingContext::simulateVertexAttrib0(long numVertex) || state.value[1] != m_vertexAttrib0BufferValue[1] || state.value[2] != m_vertexAttrib0BufferValue[2] || state.value[3] != m_vertexAttrib0BufferValue[3]) { - RefPtr<Float32Array> bufferData = Float32Array::create((numVertex + 1) * 4); + OwnArrayPtr<float> bufferData(new float[(numVertex + 1) * 4]); for (long ii = 0; ii < numVertex + 1; ++ii) { - bufferData->set(ii * 4, state.value[0]); - bufferData->set(ii * 4 + 1, state.value[1]); - bufferData->set(ii * 4 + 2, state.value[2]); - bufferData->set(ii * 4 + 3, state.value[3]); + bufferData[ii * 4] = state.value[0]; + bufferData[ii * 4 + 1] = state.value[1]; + bufferData[ii * 4 + 2] = state.value[2]; + bufferData[ii * 4 + 3] = state.value[3]; } - m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, bufferData.get(), GraphicsContext3D::DYNAMIC_DRAW); + m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, bufferDataSize, bufferData.get(), GraphicsContext3D::DYNAMIC_DRAW); m_vertexAttrib0BufferSize = bufferDataSize; m_vertexAttrib0BufferValue[0] = state.value[0]; m_vertexAttrib0BufferValue[1] = state.value[1]; @@ -3564,6 +3575,42 @@ void WebGLRenderingContext::restoreStatesAfterVertexAttrib0Simulation() m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(m_boundArrayBuffer.get())); } +WebGLRenderingContext::LRUImageBufferCache::LRUImageBufferCache(int capacity) + : m_buffers(new OwnPtr<ImageBuffer>[capacity]) + , m_capacity(capacity) +{ +} + +ImageBuffer* WebGLRenderingContext::LRUImageBufferCache::imageBuffer(const IntSize& size) +{ + int i; + for (i = 0; i < m_capacity; ++i) { + ImageBuffer* buf = m_buffers[i].get(); + if (!buf) + break; + if (buf->size() != size) + continue; + bubbleToFront(i); + return buf; + } + + OwnPtr<ImageBuffer> temp = ImageBuffer::create(size); + if (!temp) + return 0; + i = std::min(m_capacity - 1, i); + m_buffers[i] = temp.release(); + + ImageBuffer* buf = m_buffers[i].get(); + bubbleToFront(i); + return buf; +} + +void WebGLRenderingContext::LRUImageBufferCache::bubbleToFront(int idx) +{ + for (int i = idx; i > 0; --i) + m_buffers[i].swap(m_buffers[i-1]); +} + } // namespace WebCore #endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLRenderingContext.h b/WebCore/html/canvas/WebGLRenderingContext.h index 48fa7c8..66ec8d8 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.h +++ b/WebCore/html/canvas/WebGLRenderingContext.h @@ -35,6 +35,8 @@ #include "Uint8Array.h" #include "WebGLGetInfo.h" +#include <wtf/OwnArrayPtr.h> + namespace WebCore { class WebGLActiveInfo; @@ -49,7 +51,9 @@ class WebGLTexture; class WebGLUniformLocation; class HTMLImageElement; class HTMLVideoElement; +class ImageBuffer; class ImageData; +class IntSize; class WebKitCSSMatrix; class WebGLRenderingContext : public CanvasRenderingContext { @@ -281,8 +285,6 @@ public: void removeObject(WebGLObject*); - bool paintsIntoCanvasBuffer() const { return m_context->paintsIntoCanvasBuffer(); } - private: friend class WebGLObject; @@ -303,6 +305,8 @@ public: } bool isGLES2Compliant(); + bool isGLES2NPOTStrict(); + bool isErrorGeneratedOnOutOfBoundsAccesses(); // Helper to return the size in bytes of OpenGL data types // like GL_FLOAT, GL_INT, etc. @@ -320,6 +324,8 @@ public: bool validateWebGLObject(WebGLObject* object); + PassRefPtr<Image> videoFrameToImage(HTMLVideoElement* video); + OwnPtr<GraphicsContext3D> m_context; bool m_needsUpdate; bool m_markedCanvasDirty; @@ -387,6 +393,19 @@ public: RefPtr<WebGLTexture> m_blackTexture2D; RefPtr<WebGLTexture> m_blackTextureCubeMap; + // Fixed-size cache of reusable image buffers for video texImage2D calls. + class LRUImageBufferCache { + public: + LRUImageBufferCache(int capacity); + // The pointer returned is owned by the image buffer map. + ImageBuffer* imageBuffer(const IntSize& size); + private: + void bubbleToFront(int idx); + OwnArrayPtr<OwnPtr<ImageBuffer> > m_buffers; + int m_capacity; + }; + LRUImageBufferCache m_videoCache; + int m_maxTextureSize; int m_maxCubeMapTextureSize; int m_maxTextureLevel; diff --git a/WebCore/html/canvas/WebGLRenderingContext.idl b/WebCore/html/canvas/WebGLRenderingContext.idl index 960dd0b..7a63752 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.idl +++ b/WebCore/html/canvas/WebGLRenderingContext.idl @@ -464,213 +464,210 @@ module html { const unsigned int UNPACK_FLIP_Y_WEBGL = 0x9240; const unsigned int UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241; - void activeTexture(in unsigned long texture) raises(DOMException); - void attachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); - void bindAttribLocation(in WebGLProgram program, in unsigned long index, in DOMString name) raises(DOMException); - void bindBuffer(in unsigned long target, in WebGLBuffer buffer) raises(DOMException); - void bindFramebuffer(in unsigned long target, in WebGLFramebuffer framebuffer) raises(DOMException); - void bindRenderbuffer(in unsigned long target, in WebGLRenderbuffer renderbuffer) raises(DOMException); - void bindTexture(in unsigned long target, in WebGLTexture texture) raises(DOMException); - void blendColor(in double red, in double green, in double blue, in double alpha); - void blendEquation( in unsigned long mode ); - void blendEquationSeparate(in unsigned long modeRGB, in unsigned long modeAlpha); - void blendFunc(in unsigned long sfactor, in unsigned long dfactor); - void blendFuncSeparate(in unsigned long srcRGB, in unsigned long dstRGB, in unsigned long srcAlpha, in unsigned long dstAlpha); - void bufferData(in unsigned long target, in ArrayBuffer data, in unsigned long usage) raises (DOMException); - void bufferData(in unsigned long target, in ArrayBufferView data, in unsigned long usage) raises (DOMException); - void bufferData(in unsigned long target, in long size, in unsigned long usage) raises (DOMException); - void bufferSubData(in unsigned long target, in long offset, in ArrayBuffer data) raises (DOMException); - void bufferSubData(in unsigned long target, in long offset, in ArrayBufferView data) raises (DOMException); - - unsigned long checkFramebufferStatus(in unsigned long target); - void clear(in unsigned long mask); - void clearColor(in double red, in double green, in double blue, in double alpha); - void clearDepth(in double depth); - void clearStencil(in long s); - void colorMask(in boolean red, in boolean green, in boolean blue, in boolean alpha); - void compileShader(in WebGLShader shader) raises(DOMException); + [StrictTypeChecking] void activeTexture(in unsigned long texture) raises(DOMException); + [StrictTypeChecking] void attachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); + [StrictTypeChecking] void bindAttribLocation(in WebGLProgram program, in unsigned long index, in DOMString name) raises(DOMException); + [StrictTypeChecking] void bindBuffer(in unsigned long target, in WebGLBuffer buffer) raises(DOMException); + [StrictTypeChecking] void bindFramebuffer(in unsigned long target, in WebGLFramebuffer framebuffer) raises(DOMException); + [StrictTypeChecking] void bindRenderbuffer(in unsigned long target, in WebGLRenderbuffer renderbuffer) raises(DOMException); + [StrictTypeChecking] void bindTexture(in unsigned long target, in WebGLTexture texture) raises(DOMException); + [StrictTypeChecking] void blendColor(in double red, in double green, in double blue, in double alpha); + [StrictTypeChecking] void blendEquation( in unsigned long mode ); + [StrictTypeChecking] void blendEquationSeparate(in unsigned long modeRGB, in unsigned long modeAlpha); + [StrictTypeChecking] void blendFunc(in unsigned long sfactor, in unsigned long dfactor); + [StrictTypeChecking] void blendFuncSeparate(in unsigned long srcRGB, in unsigned long dstRGB, in unsigned long srcAlpha, in unsigned long dstAlpha); + [StrictTypeChecking] void bufferData(in unsigned long target, in ArrayBuffer data, in unsigned long usage) raises (DOMException); + [StrictTypeChecking] void bufferData(in unsigned long target, in ArrayBufferView data, in unsigned long usage) raises (DOMException); + [StrictTypeChecking] void bufferData(in unsigned long target, in long size, in unsigned long usage) raises (DOMException); + [StrictTypeChecking] void bufferSubData(in unsigned long target, in long offset, in ArrayBuffer data) raises (DOMException); + [StrictTypeChecking] void bufferSubData(in unsigned long target, in long offset, in ArrayBufferView data) raises (DOMException); + + [StrictTypeChecking] unsigned long checkFramebufferStatus(in unsigned long target); + [StrictTypeChecking] void clear(in unsigned long mask); + [StrictTypeChecking] void clearColor(in double red, in double green, in double blue, in double alpha); + [StrictTypeChecking] void clearDepth(in double depth); + [StrictTypeChecking] void clearStencil(in long s); + [StrictTypeChecking] void colorMask(in boolean red, in boolean green, in boolean blue, in boolean alpha); + [StrictTypeChecking] void compileShader(in WebGLShader shader) raises(DOMException); //void compressedTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in unsigned long width, in unsigned long height, in long border, in unsigned long imageSize, const void* data); //void compressedTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long imageSize, const void* data); - void copyTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long x, in long y, in unsigned long width, in unsigned long height, in long border); - void copyTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in long x, in long y, in unsigned long width, in unsigned long height); - - WebGLBuffer createBuffer(); - WebGLFramebuffer createFramebuffer(); - WebGLProgram createProgram(); - WebGLRenderbuffer createRenderbuffer(); - WebGLShader createShader(in unsigned long type) raises(DOMException); - WebGLTexture createTexture(); - - void cullFace(in unsigned long mode); - - void deleteBuffer(in WebGLBuffer buffer); - void deleteFramebuffer(in WebGLFramebuffer framebuffer); - void deleteProgram(in WebGLProgram program); - void deleteRenderbuffer(in WebGLRenderbuffer renderbuffer); - void deleteShader(in WebGLShader shader); - void deleteTexture(in WebGLTexture texture); - - void depthFunc(in unsigned long func); - void depthMask(in boolean flag); + [StrictTypeChecking] void copyTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long x, in long y, in unsigned long width, in unsigned long height, in long border); + [StrictTypeChecking] void copyTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in long x, in long y, in unsigned long width, in unsigned long height); + + [StrictTypeChecking] WebGLBuffer createBuffer(); + [StrictTypeChecking] WebGLFramebuffer createFramebuffer(); + [StrictTypeChecking] WebGLProgram createProgram(); + [StrictTypeChecking] WebGLRenderbuffer createRenderbuffer(); + [StrictTypeChecking] WebGLShader createShader(in unsigned long type) raises(DOMException); + [StrictTypeChecking] WebGLTexture createTexture(); + + [StrictTypeChecking] void cullFace(in unsigned long mode); + + [StrictTypeChecking] void deleteBuffer(in WebGLBuffer buffer); + [StrictTypeChecking] void deleteFramebuffer(in WebGLFramebuffer framebuffer); + [StrictTypeChecking] void deleteProgram(in WebGLProgram program); + [StrictTypeChecking] void deleteRenderbuffer(in WebGLRenderbuffer renderbuffer); + [StrictTypeChecking] void deleteShader(in WebGLShader shader); + [StrictTypeChecking] void deleteTexture(in WebGLTexture texture); + + [StrictTypeChecking] void depthFunc(in unsigned long func); + [StrictTypeChecking] void depthMask(in boolean flag); // FIXME: this differs from the current WebGL spec (depthRangef) - void depthRange(in double zNear, in double zFar); - void detachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); - void disable(in unsigned long cap); - void disableVertexAttribArray(in unsigned long index) raises(DOMException); - void drawArrays(in unsigned long mode, in long first, in long count) raises(DOMException); - void drawElements(in unsigned long mode, in long count, in unsigned long type, in long offset) raises(DOMException); - - void enable(in unsigned long cap); - void enableVertexAttribArray(in unsigned long index) raises(DOMException); - void finish(); - void flush(); - void framebufferRenderbuffer(in unsigned long target, in unsigned long attachment, in unsigned long renderbuffertarget, in WebGLRenderbuffer renderbuffer) raises(DOMException); - void framebufferTexture2D(in unsigned long target, in unsigned long attachment, in unsigned long textarget, in WebGLTexture texture, in long level) raises(DOMException); - void frontFace(in unsigned long mode); - void generateMipmap(in unsigned long target); + [StrictTypeChecking] void depthRange(in double zNear, in double zFar); + [StrictTypeChecking] void detachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); + [StrictTypeChecking] void disable(in unsigned long cap); + [StrictTypeChecking] void disableVertexAttribArray(in unsigned long index) raises(DOMException); + [StrictTypeChecking] void drawArrays(in unsigned long mode, in long first, in long count) raises(DOMException); + [StrictTypeChecking] void drawElements(in unsigned long mode, in long count, in unsigned long type, in long offset) raises(DOMException); + + [StrictTypeChecking] void enable(in unsigned long cap); + [StrictTypeChecking] void enableVertexAttribArray(in unsigned long index) raises(DOMException); + [StrictTypeChecking] void finish(); + [StrictTypeChecking] void flush(); + [StrictTypeChecking] void framebufferRenderbuffer(in unsigned long target, in unsigned long attachment, in unsigned long renderbuffertarget, in WebGLRenderbuffer renderbuffer) raises(DOMException); + [StrictTypeChecking] void framebufferTexture2D(in unsigned long target, in unsigned long attachment, in unsigned long textarget, in WebGLTexture texture, in long level) raises(DOMException); + [StrictTypeChecking] void frontFace(in unsigned long mode); + [StrictTypeChecking] void generateMipmap(in unsigned long target); - WebGLActiveInfo getActiveAttrib(in WebGLProgram program, in unsigned long index) - raises (DOMException); - WebGLActiveInfo getActiveUniform(in WebGLProgram program, in unsigned long index) - raises (DOMException); + [StrictTypeChecking] WebGLActiveInfo getActiveAttrib(in WebGLProgram program, in unsigned long index) raises (DOMException); + [StrictTypeChecking] WebGLActiveInfo getActiveUniform(in WebGLProgram program, in unsigned long index) raises (DOMException); - [Custom] void getAttachedShaders(in WebGLProgram program) - raises (DOMException); + [StrictTypeChecking, Custom] void getAttachedShaders(in WebGLProgram program) raises (DOMException); - int getAttribLocation(in WebGLProgram program, in DOMString name); + [StrictTypeChecking] int getAttribLocation(in WebGLProgram program, in DOMString name); // any getBufferParameter(in unsigned long target, in unsigned long pname) raises(DOMException); - [Custom] void getBufferParameter(); + [StrictTypeChecking, Custom] void getBufferParameter(); - WebGLContextAttributes getContextAttributes(); + [StrictTypeChecking] WebGLContextAttributes getContextAttributes(); - unsigned long getError(); + [StrictTypeChecking] unsigned long getError(); // any getFramebufferAttachmentParameter(in unsigned long target, in unsigned long attachment, in unsigned long pname) raises(DOMException); - [Custom] void getFramebufferAttachmentParameter(); + [StrictTypeChecking, Custom] void getFramebufferAttachmentParameter(); // any getParameter(in unsigned long pname) raises(DOMException); - [Custom] void getParameter(); + [StrictTypeChecking, Custom] void getParameter(); // any getProgramParameter(in WebGLProgram program, in unsigned long pname) raises(DOMException); - [Custom] void getProgramParameter(); - DOMString getProgramInfoLog(in WebGLProgram program) raises(DOMException); + [StrictTypeChecking, Custom] void getProgramParameter(); + [StrictTypeChecking] DOMString getProgramInfoLog(in WebGLProgram program) raises(DOMException); // any getRenderbufferParameter(in unsigned long target, in unsigned long pname) raises(DOMException); - [Custom] void getRenderbufferParameter(); + [StrictTypeChecking, Custom] void getRenderbufferParameter(); // any getShaderParameter(in WebGLShader shader, in unsigned long pname) raises(DOMException); - [Custom] void getShaderParameter() raises(DOMException); + [StrictTypeChecking, Custom] void getShaderParameter() raises(DOMException); - DOMString getShaderInfoLog(in WebGLShader shader) raises(DOMException); + [StrictTypeChecking] DOMString getShaderInfoLog(in WebGLShader shader) raises(DOMException); // TBD // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); - DOMString getShaderSource(in WebGLShader shader) raises(DOMException); - DOMString getString(in unsigned long name); + [StrictTypeChecking] DOMString getShaderSource(in WebGLShader shader) raises(DOMException); + [StrictTypeChecking] DOMString getString(in unsigned long name); // any getTexParameter(in unsigned long target, in unsigned long pname) raises(DOMException); - [Custom] void getTexParameter(); + [StrictTypeChecking, Custom] void getTexParameter(); // any getUniform(in WebGLProgram program, in WebGLUniformLocation location) raises(DOMException); - [Custom] void getUniform(); + [StrictTypeChecking, Custom] void getUniform(); - WebGLUniformLocation getUniformLocation(in WebGLProgram program, in DOMString name) raises(DOMException); + [StrictTypeChecking] WebGLUniformLocation getUniformLocation(in WebGLProgram program, in DOMString name) raises(DOMException); // any getVertexAttrib(in unsigned long index, in unsigned long pname) raises(DOMException); - [Custom] void getVertexAttrib(); - - long getVertexAttribOffset(in unsigned long index, in unsigned long pname); - - void hint(in unsigned long target, in unsigned long mode); - boolean isBuffer(in WebGLBuffer buffer); - boolean isEnabled(in unsigned long cap); - boolean isFramebuffer(in WebGLFramebuffer framebuffer); - boolean isProgram(in WebGLProgram program); - boolean isRenderbuffer(in WebGLRenderbuffer renderbuffer); - boolean isShader(in WebGLShader shader); - boolean isTexture(in WebGLTexture texture); - void lineWidth(in double width); - void linkProgram(in WebGLProgram program) raises(DOMException); - void pixelStorei(in unsigned long pname, in long param); - void polygonOffset(in double factor, in double units); - - void readPixels(in long x, in long y, in long width, in long height, in unsigned long format, in unsigned long type, in ArrayBufferView pixels); + [StrictTypeChecking, Custom] void getVertexAttrib(); + + [StrictTypeChecking] long getVertexAttribOffset(in unsigned long index, in unsigned long pname); + + [StrictTypeChecking] void hint(in unsigned long target, in unsigned long mode); + [StrictTypeChecking] boolean isBuffer(in WebGLBuffer buffer); + [StrictTypeChecking] boolean isEnabled(in unsigned long cap); + [StrictTypeChecking] boolean isFramebuffer(in WebGLFramebuffer framebuffer); + [StrictTypeChecking] boolean isProgram(in WebGLProgram program); + [StrictTypeChecking] boolean isRenderbuffer(in WebGLRenderbuffer renderbuffer); + [StrictTypeChecking] boolean isShader(in WebGLShader shader); + [StrictTypeChecking] boolean isTexture(in WebGLTexture texture); + [StrictTypeChecking] void lineWidth(in double width); + [StrictTypeChecking] void linkProgram(in WebGLProgram program) raises(DOMException); + [StrictTypeChecking] void pixelStorei(in unsigned long pname, in long param); + [StrictTypeChecking] void polygonOffset(in double factor, in double units); + + [StrictTypeChecking] void readPixels(in long x, in long y, in long width, in long height, in unsigned long format, in unsigned long type, in ArrayBufferView pixels); - void releaseShaderCompiler(); - void renderbufferStorage(in unsigned long target, in unsigned long internalformat, in unsigned long width, in unsigned long height); - void sampleCoverage(in double value, in boolean invert); - void scissor(in long x, in long y, in unsigned long width, in unsigned long height); - void shaderSource(in WebGLShader shader, in DOMString string) raises(DOMException); - void stencilFunc(in unsigned long func, in long ref, in unsigned long mask); - void stencilFuncSeparate(in unsigned long face, in unsigned long func, in long ref, in unsigned long mask); - void stencilMask(in unsigned long mask); - void stencilMaskSeparate(in unsigned long face, in unsigned long mask); - void stencilOp(in unsigned long fail, in unsigned long zfail, in unsigned long zpass); - void stencilOpSeparate(in unsigned long face, in unsigned long fail, in unsigned long zfail, in unsigned long zpass); - - void texParameterf(in unsigned long target, in unsigned long pname, in float param); - void texParameteri(in unsigned long target, in unsigned long pname, in long param); + [StrictTypeChecking] void releaseShaderCompiler(); + [StrictTypeChecking] void renderbufferStorage(in unsigned long target, in unsigned long internalformat, in unsigned long width, in unsigned long height); + [StrictTypeChecking] void sampleCoverage(in double value, in boolean invert); + [StrictTypeChecking] void scissor(in long x, in long y, in unsigned long width, in unsigned long height); + [StrictTypeChecking] void shaderSource(in WebGLShader shader, in DOMString string) raises(DOMException); + [StrictTypeChecking] void stencilFunc(in unsigned long func, in long ref, in unsigned long mask); + [StrictTypeChecking] void stencilFuncSeparate(in unsigned long face, in unsigned long func, in long ref, in unsigned long mask); + [StrictTypeChecking] void stencilMask(in unsigned long mask); + [StrictTypeChecking] void stencilMaskSeparate(in unsigned long face, in unsigned long mask); + [StrictTypeChecking] void stencilOp(in unsigned long fail, in unsigned long zfail, in unsigned long zpass); + [StrictTypeChecking] void stencilOpSeparate(in unsigned long face, in unsigned long fail, in unsigned long zfail, in unsigned long zpass); + + [StrictTypeChecking] void texParameterf(in unsigned long target, in unsigned long pname, in float param); + [StrictTypeChecking] void texParameteri(in unsigned long target, in unsigned long pname, in long param); // Supported forms: - void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long width, in long height, - in long border, in unsigned long format, in unsigned long type, in ArrayBufferView pixels) raises (DOMException); - void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, - in unsigned long format, in unsigned long type, in ImageData pixels) raises (DOMException); - void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, - in unsigned long format, in unsigned long type, in HTMLImageElement image) raises (DOMException); - void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, - in unsigned long format, in unsigned long type, in HTMLCanvasElement canvas) raises (DOMException); - void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, - in unsigned long format, in unsigned long type, in HTMLVideoElement video) raises (DOMException); - - void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, - in long width, in long height, - in unsigned long format, in unsigned long type, in ArrayBufferView pixels) raises (DOMException); - void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, - in unsigned long format, in unsigned long type, in ImageData pixels) raises (DOMException); - void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, - in unsigned long format, in unsigned long type, in HTMLImageElement image) raises (DOMException); - void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, - in unsigned long format, in unsigned long type, in HTMLCanvasElement canvas) raises (DOMException); - void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, - in unsigned long format, in unsigned long type, in HTMLVideoElement video) raises (DOMException); - - void uniform1f(in WebGLUniformLocation location, in float x) raises(DOMException); - [Custom] void uniform1fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); - void uniform1i(in WebGLUniformLocation location, in long x) raises(DOMException); - [Custom] void uniform1iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); - void uniform2f(in WebGLUniformLocation location, in float x, in float y) raises(DOMException); - [Custom] void uniform2fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); - void uniform2i(in WebGLUniformLocation location, in long x, in long y) raises(DOMException); - [Custom] void uniform2iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); - void uniform3f(in WebGLUniformLocation location, in float x, in float y, in float z) raises(DOMException); - [Custom] void uniform3fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); - void uniform3i(in WebGLUniformLocation location, in long x, in long y, in long z) raises(DOMException); - [Custom] void uniform3iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); - void uniform4f(in WebGLUniformLocation location, in float x, in float y, in float z, in float w) raises(DOMException); - [Custom] void uniform4fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); - void uniform4i(in WebGLUniformLocation location, in long x, in long y, in long z, in long w) raises(DOMException); - [Custom] void uniform4iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); - - [Custom] void uniformMatrix2fv(in WebGLUniformLocation location, in boolean transpose, in Float32Array array) raises(DOMException); - [Custom] void uniformMatrix3fv(in WebGLUniformLocation location, in boolean transpose, in Float32Array array) raises(DOMException); - [Custom] void uniformMatrix4fv(in WebGLUniformLocation location, in boolean transpose, in Float32Array array) raises(DOMException); - - void useProgram(in WebGLProgram program) raises(DOMException); - void validateProgram(in WebGLProgram program) raises(DOMException); - - void vertexAttrib1f(in unsigned long indx, in float x); - [Custom] void vertexAttrib1fv(in unsigned long indx, in Float32Array values); - void vertexAttrib2f(in unsigned long indx, in float x, in float y); - [Custom] void vertexAttrib2fv(in unsigned long indx, in Float32Array values); - void vertexAttrib3f(in unsigned long indx, in float x, in float y, in float z); - [Custom] void vertexAttrib3fv(in unsigned long indx, in Float32Array values); - void vertexAttrib4f(in unsigned long indx, in float x, in float y, in float z, in float w); - [Custom] void vertexAttrib4fv(in unsigned long indx, in Float32Array values); - void vertexAttribPointer(in unsigned long indx, in long size, in unsigned long type, in boolean normalized, - in long stride, in unsigned long offset) raises(DOMException); - - void viewport(in long x, in long y, in unsigned long width, in unsigned long height); + [StrictTypeChecking] void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long width, in long height, + in long border, in unsigned long format, in unsigned long type, in ArrayBufferView pixels) raises (DOMException); + [StrictTypeChecking] void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, + in unsigned long format, in unsigned long type, in ImageData pixels) raises (DOMException); + [StrictTypeChecking] void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, + in unsigned long format, in unsigned long type, in HTMLImageElement image) raises (DOMException); + [StrictTypeChecking] void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, + in unsigned long format, in unsigned long type, in HTMLCanvasElement canvas) raises (DOMException); + [StrictTypeChecking] void texImage2D(in unsigned long target, in long level, in unsigned long internalformat, + in unsigned long format, in unsigned long type, in HTMLVideoElement video) raises (DOMException); + + [StrictTypeChecking] void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, + in long width, in long height, + in unsigned long format, in unsigned long type, in ArrayBufferView pixels) raises (DOMException); + [StrictTypeChecking] void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, + in unsigned long format, in unsigned long type, in ImageData pixels) raises (DOMException); + [StrictTypeChecking] void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, + in unsigned long format, in unsigned long type, in HTMLImageElement image) raises (DOMException); + [StrictTypeChecking] void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, + in unsigned long format, in unsigned long type, in HTMLCanvasElement canvas) raises (DOMException); + [StrictTypeChecking] void texSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, + in unsigned long format, in unsigned long type, in HTMLVideoElement video) raises (DOMException); + + [StrictTypeChecking] void uniform1f(in WebGLUniformLocation location, in float x) raises(DOMException); + [StrictTypeChecking, Custom] void uniform1fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); + [StrictTypeChecking] void uniform1i(in WebGLUniformLocation location, in long x) raises(DOMException); + [StrictTypeChecking, Custom] void uniform1iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); + [StrictTypeChecking] void uniform2f(in WebGLUniformLocation location, in float x, in float y) raises(DOMException); + [StrictTypeChecking, Custom] void uniform2fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); + [StrictTypeChecking] void uniform2i(in WebGLUniformLocation location, in long x, in long y) raises(DOMException); + [StrictTypeChecking, Custom] void uniform2iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); + [StrictTypeChecking] void uniform3f(in WebGLUniformLocation location, in float x, in float y, in float z) raises(DOMException); + [StrictTypeChecking, Custom] void uniform3fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); + [StrictTypeChecking] void uniform3i(in WebGLUniformLocation location, in long x, in long y, in long z) raises(DOMException); + [StrictTypeChecking, Custom] void uniform3iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); + [StrictTypeChecking] void uniform4f(in WebGLUniformLocation location, in float x, in float y, in float z, in float w) raises(DOMException); + [StrictTypeChecking, Custom] void uniform4fv(in WebGLUniformLocation location, in Float32Array v) raises(DOMException); + [StrictTypeChecking] void uniform4i(in WebGLUniformLocation location, in long x, in long y, in long z, in long w) raises(DOMException); + [StrictTypeChecking, Custom] void uniform4iv(in WebGLUniformLocation location, in Int32Array v) raises(DOMException); + + [StrictTypeChecking, Custom] void uniformMatrix2fv(in WebGLUniformLocation location, in boolean transpose, in Float32Array array) raises(DOMException); + [StrictTypeChecking, Custom] void uniformMatrix3fv(in WebGLUniformLocation location, in boolean transpose, in Float32Array array) raises(DOMException); + [StrictTypeChecking, Custom] void uniformMatrix4fv(in WebGLUniformLocation location, in boolean transpose, in Float32Array array) raises(DOMException); + + [StrictTypeChecking] void useProgram(in WebGLProgram program) raises(DOMException); + [StrictTypeChecking] void validateProgram(in WebGLProgram program) raises(DOMException); + + [StrictTypeChecking] void vertexAttrib1f(in unsigned long indx, in float x); + [StrictTypeChecking, Custom] void vertexAttrib1fv(in unsigned long indx, in Float32Array values); + [StrictTypeChecking] void vertexAttrib2f(in unsigned long indx, in float x, in float y); + [StrictTypeChecking, Custom] void vertexAttrib2fv(in unsigned long indx, in Float32Array values); + [StrictTypeChecking] void vertexAttrib3f(in unsigned long indx, in float x, in float y, in float z); + [StrictTypeChecking, Custom] void vertexAttrib3fv(in unsigned long indx, in Float32Array values); + [StrictTypeChecking] void vertexAttrib4f(in unsigned long indx, in float x, in float y, in float z, in float w); + [StrictTypeChecking, Custom] void vertexAttrib4fv(in unsigned long indx, in Float32Array values); + [StrictTypeChecking] void vertexAttribPointer(in unsigned long indx, in long size, in unsigned long type, in boolean normalized, + in long stride, in unsigned long offset) raises(DOMException); + + [StrictTypeChecking] void viewport(in long x, in long y, in unsigned long width, in unsigned long height); }; } diff --git a/WebCore/html/canvas/WebGLTexture.cpp b/WebCore/html/canvas/WebGLTexture.cpp index e6dfd0a..7b2869f 100644 --- a/WebCore/html/canvas/WebGLTexture.cpp +++ b/WebCore/html/canvas/WebGLTexture.cpp @@ -169,11 +169,12 @@ void WebGLTexture::generateMipmapLevelInfo() m_needToUseBlackTexture = false; } -unsigned long WebGLTexture::getInternalFormat() const +unsigned long WebGLTexture::getInternalFormat(int level) const { if (!object() || !m_target) return 0; - return m_info[0][0].internalFormat; + // We assume level has been validated already. + return m_info[0][level].internalFormat; } bool WebGLTexture::isNPOT(unsigned width, unsigned height) diff --git a/WebCore/html/canvas/WebGLTexture.h b/WebCore/html/canvas/WebGLTexture.h index 64bd6e0..a1ce348 100644 --- a/WebCore/html/canvas/WebGLTexture.h +++ b/WebCore/html/canvas/WebGLTexture.h @@ -60,7 +60,7 @@ public: // Generate all level information. void generateMipmapLevelInfo(); - unsigned long getInternalFormat() const; + unsigned long getInternalFormat(int level) const; // Whether width/height is NotPowerOfTwo. static bool isNPOT(unsigned, unsigned); |