diff options
author | Steve Block <steveblock@google.com> | 2009-12-15 10:12:09 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2009-12-17 17:41:10 +0000 |
commit | 643ca7872b450ea4efacab6188849e5aac2ba161 (patch) | |
tree | 6982576c228bcd1a7efe98afed544d840751094c /WebCore/html | |
parent | d026980fde6eb3b01c1fe49441174e89cd1be298 (diff) | |
download | external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.zip external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.gz external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.bz2 |
Merge webkit.org at r51976 : Initial merge by git.
Change-Id: Ib0e7e2f0fb4bee5a186610272edf3186f0986b43
Diffstat (limited to 'WebCore/html')
136 files changed, 6852 insertions, 3699 deletions
diff --git a/WebCore/html/CollectionCache.h b/WebCore/html/CollectionCache.h index 7cdcdd5..0a49fb8 100644 --- a/WebCore/html/CollectionCache.h +++ b/WebCore/html/CollectionCache.h @@ -29,7 +29,7 @@ namespace WebCore { class AtomicStringImpl; class Element; -struct CollectionCache { +struct CollectionCache : FastAllocBase { CollectionCache(); CollectionCache(const CollectionCache&); CollectionCache& operator=(const CollectionCache& other) diff --git a/WebCore/html/HTMLAnchorElement.cpp b/WebCore/html/HTMLAnchorElement.cpp index f735104..1d5d569 100644 --- a/WebCore/html/HTMLAnchorElement.cpp +++ b/WebCore/html/HTMLAnchorElement.cpp @@ -58,6 +58,15 @@ PassRefPtr<HTMLAnchorElement> HTMLAnchorElement::create(const QualifiedName& tag return adoptRef(new HTMLAnchorElement(tagName, document)); } +// This function does not allow leading spaces before the port number. +static unsigned parsePortFromStringPosition(const String& value, unsigned portStart, unsigned& portEnd) +{ + portEnd = portStart; + while (isASCIIDigit(value[portEnd])) + ++portEnd; + return value.substring(portStart, portEnd - portStart).toUInt(); +} + bool HTMLAnchorElement::supportsFocus() const { if (isContentEditable()) @@ -69,10 +78,12 @@ bool HTMLAnchorElement::supportsFocus() const bool HTMLAnchorElement::isMouseFocusable() const { // Anchor elements should be mouse focusable, https://bugs.webkit.org/show_bug.cgi?id=26856 -#if PLATFORM(MAC) +#if !PLATFORM(GTK) && !PLATFORM(QT) if (isLink()) - return false; + // Only allow links with tabIndex or contentEditable to be mouse focusable. + return HTMLElement::supportsFocus(); #endif + // Allow tab index etc to control focus. return HTMLElement::isMouseFocusable(); } @@ -332,7 +343,7 @@ bool HTMLAnchorElement::hasRel(uint32_t relation) const void HTMLAnchorElement::setRel(const String& value) { m_linkRelations = 0; - ClassNames newLinkRelations(value, true); + SpaceSplitString newLinkRelations(value, true); // FIXME: Add link relations as they are implemented if (newLinkRelations.contains("noreferrer")) m_linkRelations |= RelationNoReferrer; @@ -360,42 +371,165 @@ String HTMLAnchorElement::hash() const return fragmentIdentifier.isEmpty() ? "" : "#" + fragmentIdentifier; } +void HTMLAnchorElement::setHash(const String& value) +{ + KURL url = href(); + if (value[0] == '#') + url.setFragmentIdentifier(value.substring(1)); + else + url.setFragmentIdentifier(value); + setHref(url.string()); +} + String HTMLAnchorElement::host() const { const KURL& url = href(); if (url.hostEnd() == url.pathStart()) return url.host(); - if (SecurityOrigin::isDefaultPortForProtocol(url.port(), url.protocol())) + if (isDefaultPortForProtocol(url.port(), url.protocol())) return url.host(); return url.host() + ":" + String::number(url.port()); } +void HTMLAnchorElement::setHost(const String& value) +{ + if (value.isEmpty()) + return; + KURL url = href(); + if (!url.canSetHostOrPort()) + return; + + int separator = value.find(':'); + if (!separator) + return; + + if (separator == -1) + url.setHostAndPort(value); + else { + unsigned portEnd; + unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd); + if (!port) { + // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes + // specifically goes against RFC 3986 (p3.2) and + // requires setting the port to "0" if it is set to empty string. + url.setHostAndPort(value.substring(0, separator + 1) + "0"); + } else { + if (isDefaultPortForProtocol(port, url.protocol())) + url.setHostAndPort(value.substring(0, separator)); + else + url.setHostAndPort(value.substring(0, portEnd)); + } + } + setHref(url.string()); +} + String HTMLAnchorElement::hostname() const { return href().host(); } +void HTMLAnchorElement::setHostname(const String& value) +{ + // Before setting new value: + // Remove all leading U+002F SOLIDUS ("/") characters. + unsigned i = 0; + unsigned hostLength = value.length(); + while (value[i] == '/') + i++; + + if (i == hostLength) + return; + + KURL url = href(); + if (!url.canSetHostOrPort()) + return; + + url.setHost(value.substring(i)); + setHref(url.string()); +} + String HTMLAnchorElement::pathname() const { return href().path(); } +void HTMLAnchorElement::setPathname(const String& value) +{ + KURL url = href(); + if (!url.canSetPathname()) + return; + + if (value[0] == '/') + url.setPath(value); + else + url.setPath("/" + value); + + setHref(url.string()); +} + String HTMLAnchorElement::port() const { return String::number(href().port()); } +void HTMLAnchorElement::setPort(const String& value) +{ + KURL url = href(); + if (!url.canSetHostOrPort()) + return; + + // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes + // specifically goes against RFC 3986 (p3.2) and + // requires setting the port to "0" if it is set to empty string. + unsigned port = value.toUInt(); + if (isDefaultPortForProtocol(port, url.protocol())) + url.removePort(); + else + url.setPort(port); + + setHref(url.string()); +} + String HTMLAnchorElement::protocol() const { return href().protocol() + ":"; } +void HTMLAnchorElement::setProtocol(const String& value) +{ + int separator = value.find(':'); + + if (!separator) + return; + if (value.isEmpty()) + return; + + KURL url = href(); + // Following Firefox 3.5.2 which removes anything after the first ":" + String newProtocol = value.substring(0, separator); + if (!isValidProtocol(newProtocol)) + return; + url.setProtocol(newProtocol); + + setHref(url.string()); +} + String HTMLAnchorElement::search() const { String query = href().query(); return query.isEmpty() ? "" : "?" + query; } +void HTMLAnchorElement::setSearch(const String& value) +{ + KURL url = href(); + String newSearch = (value[0] == '?') ? value.substring(1) : value; + // Make sure that '#' in the query does not leak to the hash. + url.setQuery(newSearch.replace('#', "%23")); + + setHref(url.string()); +} + String HTMLAnchorElement::text() const { return innerText(); diff --git a/WebCore/html/HTMLAnchorElement.h b/WebCore/html/HTMLAnchorElement.h index e47ea99..03d3529 100644 --- a/WebCore/html/HTMLAnchorElement.h +++ b/WebCore/html/HTMLAnchorElement.h @@ -62,12 +62,26 @@ public: const AtomicString& name() const; String hash() const; + void setHash(const String&); + String host() const; + void setHost(const String&); + String hostname() const; + void setHostname(const String&); + String pathname() const; + void setPathname(const String&); + String port() const; + void setPort(const String&); + String protocol() const; + void setProtocol(const String&); + String search() const; + void setSearch(const String&); + String text() const; String toString() const; diff --git a/WebCore/html/HTMLAnchorElement.idl b/WebCore/html/HTMLAnchorElement.idl index 057358e..e55bd86 100644 --- a/WebCore/html/HTMLAnchorElement.idl +++ b/WebCore/html/HTMLAnchorElement.idl @@ -37,7 +37,7 @@ module html { attribute [ConvertNullToNullString, Reflect] DOMString target; attribute [ConvertNullToNullString, Reflect] DOMString type; - // IE Extensions +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C readonly attribute DOMString hash; readonly attribute DOMString host; readonly attribute DOMString hostname; @@ -45,6 +45,16 @@ module html { readonly attribute DOMString port; readonly attribute DOMString protocol; readonly attribute DOMString search; +#else + attribute [ConvertNullToNullString] DOMString hash; + attribute [ConvertNullToNullString] DOMString host; + attribute [ConvertNullToNullString] DOMString hostname; + attribute [ConvertNullToNullString] DOMString pathname; + attribute [ConvertNullToNullString] DOMString port; + attribute [ConvertNullToNullString] DOMString protocol; + attribute [ConvertNullToNullString] DOMString search; +#endif + readonly attribute DOMString text; #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT diff --git a/WebCore/html/HTMLAppletElement.cpp b/WebCore/html/HTMLAppletElement.cpp index 46045d6..f67e9dc 100644 --- a/WebCore/html/HTMLAppletElement.cpp +++ b/WebCore/html/HTMLAppletElement.cpp @@ -28,6 +28,7 @@ #include "HTMLNames.h" #include "MappedAttribute.h" #include "RenderApplet.h" +#include "SecurityOrigin.h" #include "Settings.h" namespace WebCore { @@ -108,9 +109,7 @@ bool HTMLAppletElement::rendererIsNeeded(RenderStyle* style) RenderObject* HTMLAppletElement::createRenderer(RenderArena*, RenderStyle* style) { - Settings* settings = document()->settings(); - - if (settings && settings->isJavaEnabled()) { + if (canEmbedJava()) { HashMap<String, String> args; args.set("code", getAttribute(codeAttr)); @@ -142,8 +141,7 @@ RenderObject* HTMLAppletElement::createRenderer(RenderArena*, RenderStyle* style RenderWidget* HTMLAppletElement::renderWidgetForJSBindings() const { - Settings* settings = document()->settings(); - if (!settings || !settings->isJavaEnabled()) + if (!canEmbedJava()) return 0; RenderApplet* applet = toRenderApplet(renderer()); @@ -153,6 +151,15 @@ RenderWidget* HTMLAppletElement::renderWidgetForJSBindings() const return applet; } +bool HTMLAppletElement::canEmbedJava() const +{ + if (document()->securityOrigin()->isSandboxed(SandboxPlugins)) + return false; + + Settings* settings = document()->settings(); + return settings && settings->isJavaEnabled(); +} + void HTMLAppletElement::finishParsingChildren() { // The parser just reached </applet>, so all the params are available now. diff --git a/WebCore/html/HTMLAppletElement.h b/WebCore/html/HTMLAppletElement.h index baaab38..a53bd5c 100644 --- a/WebCore/html/HTMLAppletElement.h +++ b/WebCore/html/HTMLAppletElement.h @@ -51,6 +51,7 @@ private: virtual RenderWidget* renderWidgetForJSBindings() const; void setupApplet() const; + bool canEmbedJava() const; virtual void insertedIntoDocument(); virtual void removedFromDocument(); diff --git a/WebCore/html/HTMLAttributeNames.in b/WebCore/html/HTMLAttributeNames.in index ac8ce11..c989dbd 100644 --- a/WebCore/html/HTMLAttributeNames.in +++ b/WebCore/html/HTMLAttributeNames.in @@ -14,16 +14,25 @@ alt archive aria-activedescendant aria-checked +aria-controls aria-describedby aria-disabled +aria-dropeffect +aria-expanded +aria-flowto +aria-grabbed aria-hidden aria-label aria-labeledby aria-labelledby aria-level +aria-multiselectable +aria-orientation +aria-owns aria-pressed aria-readonly aria-required +aria-selected aria-valuemax aria-valuemin aria-valuenow @@ -174,6 +183,7 @@ onpaste onpause onplay onplaying +onpopstate onprogress onratechange onreset @@ -201,6 +211,8 @@ onwaiting onwebkitanimationstart onwebkitanimationiteration onwebkitanimationend +onwebkitbeginfullscreen +onwebkitendfullscreen onwebkittransitionend pattern placeholder @@ -220,6 +232,7 @@ role rows rowspan rules +sandbox scheme scope scrollamount @@ -235,6 +248,7 @@ spellcheck src standby start +step style summary tabindex diff --git a/WebCore/html/HTMLBodyElement.cpp b/WebCore/html/HTMLBodyElement.cpp index b203cc0..b9e2c75 100644 --- a/WebCore/html/HTMLBodyElement.cpp +++ b/WebCore/html/HTMLBodyElement.cpp @@ -144,6 +144,8 @@ void HTMLBodyElement::parseMappedAttribute(MappedAttribute *attr) document()->setWindowAttributeEventListener(eventNames().pagehideEvent, createAttributeEventListener(document()->frame(), attr)); else if (attr->name() == onpageshowAttr) document()->setWindowAttributeEventListener(eventNames().pageshowEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == onpopstateAttr) + document()->setWindowAttributeEventListener(eventNames().popstateEvent, createAttributeEventListener(document()->frame(), attr)); else if (attr->name() == onblurAttr) document()->setWindowAttributeEventListener(eventNames().blurEvent, createAttributeEventListener(document()->frame(), attr)); else if (attr->name() == onfocusAttr) diff --git a/WebCore/html/HTMLBodyElement.h b/WebCore/html/HTMLBodyElement.h index e898c88..76b49a1 100644 --- a/WebCore/html/HTMLBodyElement.h +++ b/WebCore/html/HTMLBodyElement.h @@ -52,13 +52,15 @@ public: DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(load); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(beforeunload); - DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(message); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(hashchange); + DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(message); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(offline); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(online); + DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(popstate); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(resize); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(storage); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(unload); + #if ENABLE(ORIENTATION_EVENTS) DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(orientationchange); #endif diff --git a/WebCore/html/HTMLBodyElement.idl b/WebCore/html/HTMLBodyElement.idl index 2e93e2e..b2f0c65 100644 --- a/WebCore/html/HTMLBodyElement.idl +++ b/WebCore/html/HTMLBodyElement.idl @@ -40,6 +40,7 @@ module html { attribute [DontEnum] EventListener onmessage; attribute [DontEnum] EventListener onoffline; attribute [DontEnum] EventListener ononline; + attribute [DontEnum] EventListener onpopstate; attribute [DontEnum] EventListener onresize; attribute [DontEnum] EventListener onstorage; attribute [DontEnum] EventListener onunload; diff --git a/WebCore/html/HTMLButtonElement.idl b/WebCore/html/HTMLButtonElement.idl index 55803df..cb9383d 100644 --- a/WebCore/html/HTMLButtonElement.idl +++ b/WebCore/html/HTMLButtonElement.idl @@ -37,6 +37,7 @@ module html { readonly attribute DOMString type; attribute [ConvertNullToNullString] DOMString value; readonly attribute boolean willValidate; + readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error); void click(); diff --git a/WebCore/html/HTMLCanvasElement.cpp b/WebCore/html/HTMLCanvasElement.cpp index 0405669..be0fa36 100644 --- a/WebCore/html/HTMLCanvasElement.cpp +++ b/WebCore/html/HTMLCanvasElement.cpp @@ -31,7 +31,7 @@ #include "CanvasPattern.h" #include "CanvasRenderingContext2D.h" #if ENABLE(3D_CANVAS) -#include "CanvasRenderingContext3D.h" +#include "WebGLRenderingContext.h" #endif #include "CanvasStyle.h" #include "Chrome.h" @@ -149,9 +149,9 @@ String HTMLCanvasElement::toDataURL(const String& mimeType, ExceptionCode& ec) CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type) { - // A Canvas can either be "2D" or "3D" never both. If you request a 2D canvas and the existing - // context is already 2D, just return that. If the existing context is 3D, then destroy it - // before creating a new 2D context. Vice versa when requesting a 3D canvas. Requesting a + // A Canvas can either be "2D" or "webgl" but never both. If you request a 2D canvas and the existing + // context is already 2D, just return that. If the existing context is WebGL, then destroy it + // before creating a new 2D context. Vice versa when requesting a WebGL canvas. Requesting a // context with any other type string will destroy any existing context. // FIXME - The code depends on the context not going away once created, to prevent JS from @@ -167,12 +167,14 @@ CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type) #if ENABLE(3D_CANVAS) Settings* settings = document()->settings(); if (settings && settings->webGLEnabled()) { + // Accept the legacy "webkit-3d" name as well as the provisional "experimental-webgl" name. + // Once ratified, we will also accept "webgl" as the context name. if ((type == "webkit-3d") || - (type == "GL")) { + (type == "experimental-webgl")) { if (m_context && !m_context->is3d()) return 0; if (!m_context) { - m_context = CanvasRenderingContext3D::create(this); + m_context = WebGLRenderingContext::create(this); if (m_context) { // Need to make sure a RenderLayer and compositing layer get created for the Canvas setNeedsStyleRecalc(SyntheticStyleChange); @@ -249,9 +251,9 @@ void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r) return; #if ENABLE(3D_CANVAS) - CanvasRenderingContext3D* context3D = NULL; + WebGLRenderingContext* context3D = NULL; if (m_context && m_context->is3d()) { - context3D = static_cast<CanvasRenderingContext3D*>(m_context.get()); + context3D = static_cast<WebGLRenderingContext*>(m_context.get()); context3D->beginPaint(); } #endif @@ -259,7 +261,7 @@ void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r) if (m_imageBuffer) { Image* image = m_imageBuffer->image(); if (image) - context->drawImage(image, r); + context->drawImage(image, DeviceColorSpace, r); } #if ENABLE(3D_CANVAS) diff --git a/WebCore/html/HTMLFieldSetElement.idl b/WebCore/html/HTMLFieldSetElement.idl index ca8563b..c55e604 100644 --- a/WebCore/html/HTMLFieldSetElement.idl +++ b/WebCore/html/HTMLFieldSetElement.idl @@ -29,6 +29,7 @@ module html { readonly attribute ValidityState validity; #endif readonly attribute boolean willValidate; + readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error); }; diff --git a/WebCore/html/HTMLFormControlElement.cpp b/WebCore/html/HTMLFormControlElement.cpp index 96ecc7d..2531c48 100644 --- a/WebCore/html/HTMLFormControlElement.cpp +++ b/WebCore/html/HTMLFormControlElement.cpp @@ -288,6 +288,11 @@ bool HTMLFormControlElement::willValidate() const return form() && !name().isEmpty() && !disabled() && !isReadOnlyFormControl(); } +String HTMLFormControlElement::validationMessage() +{ + return validity()->validationMessage(); +} + bool HTMLFormControlElement::checkValidity() { if (willValidate() && !isValidFormControlElement()) { diff --git a/WebCore/html/HTMLFormControlElement.h b/WebCore/html/HTMLFormControlElement.h index b5dc7ce..7105112 100644 --- a/WebCore/html/HTMLFormControlElement.h +++ b/WebCore/html/HTMLFormControlElement.h @@ -107,6 +107,7 @@ public: virtual short tabIndex() const; virtual bool willValidate() const; + String validationMessage(); bool checkValidity(); void updateValidity(); void setCustomValidity(const String&); diff --git a/WebCore/html/HTMLFrameOwnerElement.cpp b/WebCore/html/HTMLFrameOwnerElement.cpp index 84958c2..7598da2 100644 --- a/WebCore/html/HTMLFrameOwnerElement.cpp +++ b/WebCore/html/HTMLFrameOwnerElement.cpp @@ -35,6 +35,7 @@ namespace WebCore { HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document* document) : HTMLElement(tagName, document, CreateElement) , m_contentFrame(0) + , m_sandboxFlags(SandboxNone) { } @@ -64,6 +65,17 @@ DOMWindow* HTMLFrameOwnerElement::contentWindow() const return m_contentFrame ? m_contentFrame->domWindow() : 0; } +void HTMLFrameOwnerElement::setSandboxFlags(SandboxFlags flags) +{ + if (m_sandboxFlags == flags) + return; + + m_sandboxFlags = flags; + + if (Frame* frame = contentFrame()) + frame->loader()->ownerElementSandboxFlagsChanged(); +} + #if ENABLE(SVG) SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionCode& ec) const { diff --git a/WebCore/html/HTMLFrameOwnerElement.h b/WebCore/html/HTMLFrameOwnerElement.h index 1437e2c..308a100 100644 --- a/WebCore/html/HTMLFrameOwnerElement.h +++ b/WebCore/html/HTMLFrameOwnerElement.h @@ -21,6 +21,7 @@ #ifndef HTMLFrameOwnerElement_h #define HTMLFrameOwnerElement_h +#include "FrameLoaderTypes.h" #include "HTMLElement.h" namespace WebCore { @@ -46,9 +47,13 @@ public: virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; } + SandboxFlags sandboxFlags() const { return m_sandboxFlags; } + protected: HTMLFrameOwnerElement(const QualifiedName& tagName, Document*); + void setSandboxFlags(SandboxFlags); + private: friend class Frame; @@ -58,6 +63,7 @@ private: virtual void willRemove(); Frame* m_contentFrame; + SandboxFlags m_sandboxFlags; }; } // namespace WebCore diff --git a/WebCore/html/HTMLFrameSetElement.cpp b/WebCore/html/HTMLFrameSetElement.cpp index 5874b84..f4d1558 100644 --- a/WebCore/html/HTMLFrameSetElement.cpp +++ b/WebCore/html/HTMLFrameSetElement.cpp @@ -151,6 +151,8 @@ void HTMLFrameSetElement::parseMappedAttribute(MappedAttribute *attr) document()->setWindowAttributeEventListener(eventNames().onlineEvent, createAttributeEventListener(document()->frame(), attr)); else if (attr->name() == onofflineAttr) document()->setWindowAttributeEventListener(eventNames().offlineEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == onpopstateAttr) + document()->setWindowAttributeEventListener(eventNames().popstateEvent, createAttributeEventListener(document()->frame(), attr)); else HTMLElement::parseMappedAttribute(attr); } diff --git a/WebCore/html/HTMLFrameSetElement.h b/WebCore/html/HTMLFrameSetElement.h index 2b2d7ea..0c75efe 100644 --- a/WebCore/html/HTMLFrameSetElement.h +++ b/WebCore/html/HTMLFrameSetElement.h @@ -79,6 +79,7 @@ public: DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(message); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(offline); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(online); + DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(popstate); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(resize); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(storage); DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(unload); diff --git a/WebCore/html/HTMLFrameSetElement.idl b/WebCore/html/HTMLFrameSetElement.idl index b44a071..6ab1a8b 100644 --- a/WebCore/html/HTMLFrameSetElement.idl +++ b/WebCore/html/HTMLFrameSetElement.idl @@ -37,6 +37,7 @@ module html { attribute [DontEnum] EventListener onmessage; attribute [DontEnum] EventListener onoffline; attribute [DontEnum] EventListener ononline; + attribute [DontEnum] EventListener onpopstate; attribute [DontEnum] EventListener onresize; attribute [DontEnum] EventListener onstorage; attribute [DontEnum] EventListener onunload; diff --git a/WebCore/html/HTMLHeadElement.h b/WebCore/html/HTMLHeadElement.h index 21d8a2f..14a4409 100644 --- a/WebCore/html/HTMLHeadElement.h +++ b/WebCore/html/HTMLHeadElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> diff --git a/WebCore/html/HTMLHeadingElement.cpp b/WebCore/html/HTMLHeadingElement.cpp index 452f7c3..95c82d1 100644 --- a/WebCore/html/HTMLHeadingElement.cpp +++ b/WebCore/html/HTMLHeadingElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * Copyright (C) 2003 Apple Computer, Inc. diff --git a/WebCore/html/HTMLHeadingElement.h b/WebCore/html/HTMLHeadingElement.h index dac1107..765bede 100644 --- a/WebCore/html/HTMLHeadingElement.h +++ b/WebCore/html/HTMLHeadingElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * diff --git a/WebCore/html/HTMLHtmlElement.h b/WebCore/html/HTMLHtmlElement.h index 86603b5..de80ba8 100644 --- a/WebCore/html/HTMLHtmlElement.h +++ b/WebCore/html/HTMLHtmlElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> diff --git a/WebCore/html/HTMLIFrameElement.cpp b/WebCore/html/HTMLIFrameElement.cpp index cae9b8d..a2f287e 100644 --- a/WebCore/html/HTMLIFrameElement.cpp +++ b/WebCore/html/HTMLIFrameElement.cpp @@ -4,6 +4,7 @@ * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) * Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Ericsson AB. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -66,6 +67,40 @@ bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttribut return HTMLFrameElementBase::mapToEntry(attrName, result); } +static SandboxFlags parseSandboxAttribute(MappedAttribute* attribute) +{ + if (attribute->isNull()) + return SandboxNone; + + // Parse the unordered set of unique space-separated tokens. + SandboxFlags flags = SandboxAll; + const UChar* characters = attribute->value().characters(); + unsigned length = attribute->value().length(); + unsigned start = 0; + while (true) { + while (start < length && isASCIISpace(characters[start])) + ++start; + if (start >= length) + break; + unsigned end = start + 1; + while (end < length && !isASCIISpace(characters[end])) + ++end; + + // Turn off the corresponding sandbox flag if it's set as "allowed". + String sandboxToken = String(characters + start, end - start); + if (equalIgnoringCase(sandboxToken, "allow-same-origin")) + flags &= ~SandboxOrigin; + else if (equalIgnoringCase(sandboxToken, "allow-forms")) + flags &= ~SandboxForms; + else if (equalIgnoringCase(sandboxToken, "allow-scripts")) + flags &= ~SandboxScripts; + + start = end + 1; + } + + return flags; +} + void HTMLIFrameElement::parseMappedAttribute(MappedAttribute* attr) { if (attr->name() == widthAttr) @@ -88,7 +123,9 @@ void HTMLIFrameElement::parseMappedAttribute(MappedAttribute* attr) if (!attr->isNull() && !attr->value().toInt()) // Add a rule that nulls out our border width. addCSSLength(attr, CSSPropertyBorderWidth, "0"); - } else + } else if (attr->name() == sandboxAttr) + setSandboxFlags(parseSandboxAttribute(attr)); + else HTMLFrameElementBase::parseMappedAttribute(attr); } diff --git a/WebCore/html/HTMLIFrameElement.idl b/WebCore/html/HTMLIFrameElement.idl index e288b54..dad8416 100644 --- a/WebCore/html/HTMLIFrameElement.idl +++ b/WebCore/html/HTMLIFrameElement.idl @@ -33,6 +33,7 @@ module html { attribute [ConvertNullToNullString, Reflect=marginheight] DOMString marginHeight; attribute [ConvertNullToNullString, Reflect=marginwidth] DOMString marginWidth; attribute [ConvertNullToNullString, Reflect] DOMString name; + attribute [ConvertNullToNullString, Reflect] DOMString sandbox; attribute [ConvertNullToNullString, Reflect] DOMString scrolling; attribute [ConvertNullToNullString, CustomSetter, Reflect] DOMString src; attribute [ConvertNullToNullString, Reflect] DOMString width; diff --git a/WebCore/html/HTMLImageLoader.h b/WebCore/html/HTMLImageLoader.h index 9e9564b..d3b6068 100644 --- a/WebCore/html/HTMLImageLoader.h +++ b/WebCore/html/HTMLImageLoader.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * Copyright (C) 2004 Apple Computer, Inc. diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp index f63ccc8..85fa64d 100644 --- a/WebCore/html/HTMLInputElement.cpp +++ b/WebCore/html/HTMLInputElement.cpp @@ -45,6 +45,7 @@ #include "HTMLImageLoader.h" #include "HTMLNames.h" #include "HTMLOptionElement.h" +#include "ISODateTime.h" #include "ScriptEventListener.h" #include "KeyboardEvent.h" #include "LocalizedStrings.h" @@ -59,12 +60,18 @@ #include "RenderText.h" #include "RenderTextControlSingleLine.h" #include "RenderTheme.h" +#include "StringHash.h" #include "TextEvent.h" +<<<<<<< HEAD:WebCore/html/HTMLInputElement.cpp #ifdef ANDROID_ACCEPT_CHANGES_TO_FOCUSED_TEXTFIELDS #include "WebViewCore.h" #endif +======= +#include <wtf/HashMap.h> +>>>>>>> webkit.org at r51976:WebCore/html/HTMLInputElement.cpp #include <wtf/MathExtras.h> #include <wtf/StdLibExtras.h> +#include <wtf/dtoa.h> using namespace std; @@ -74,6 +81,16 @@ using namespace HTMLNames; const int maxSavedResults = 256; +// Constant values for getAllowedValueStep(). +static const double numberDefaultStep = 1.0; +static const double numberStepScaleFactor = 1.0; +// Constant values for minimum(). +static const double numberDefaultMinimum = -DBL_MAX; +static const double rangeDefaultMinimum = 0.0; +// Constant values for maximum(). +static const double numberDefaultMaximum = DBL_MAX; +static const double rangeDefaultMaximum = 100.0; + HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) : HTMLTextFormControlElement(tagName, doc, f) , m_xPos(0) @@ -129,14 +146,20 @@ bool HTMLInputElement::valueMissing() const return false; switch (inputType()) { - case TEXT: - case SEARCH: - case URL: - case TELEPHONE: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: - case PASSWORD: - case NUMBER: case FILE: + case MONTH: + case NUMBER: + case PASSWORD: + case SEARCH: + case TELEPHONE: + case TEXT: + case TIME: + case URL: + case WEEK: return value().isEmpty(); case CHECKBOX: return !checked(); @@ -144,13 +167,13 @@ bool HTMLInputElement::valueMissing() const return !document()->checkedRadioButtons().checkedButtonForGroup(name()); case COLOR: return false; + case BUTTON: case HIDDEN: - case RANGE: - case SUBMIT: case IMAGE: - case RESET: - case BUTTON: case ISINDEX: + case RANGE: + case RESET: + case SUBMIT: break; } @@ -161,25 +184,31 @@ bool HTMLInputElement::valueMissing() const bool HTMLInputElement::patternMismatch() const { switch (inputType()) { - case ISINDEX: + case BUTTON: case CHECKBOX: - case RADIO: - case SUBMIT: - case RESET: + case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case FILE: case HIDDEN: case IMAGE: - case BUTTON: - case RANGE: + case ISINDEX: + case MONTH: case NUMBER: - case COLOR: + case RADIO: + case RANGE: + case RESET: + case SUBMIT: + case TIME: + case WEEK: return false; - case TEXT: - case SEARCH: - case URL: - case TELEPHONE: case EMAIL: case PASSWORD: + case SEARCH: + case TELEPHONE: + case TEXT: + case URL: const AtomicString& pattern = getAttribute(patternAttr); String value = this->value(); @@ -220,15 +249,21 @@ bool HTMLInputElement::tooLong() const case BUTTON: case CHECKBOX: case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: + case MONTH: case NUMBER: case RADIO: case RANGE: case RESET: case SUBMIT: + case TIME: + case WEEK: return false; } ASSERT_NOT_REACHED(); @@ -237,60 +272,204 @@ bool HTMLInputElement::tooLong() const bool HTMLInputElement::rangeUnderflow() const { - if (inputType() == NUMBER) { - double min = 0.0; - double doubleValue = 0.0; - if (formStringToDouble(getAttribute(minAttr), &min) && formStringToDouble(value(), &doubleValue)) - return doubleValue < min; - } else if (inputType() == RANGE) { + if (inputType() == NUMBER || inputType() == RANGE) { double doubleValue; if (formStringToDouble(value(), &doubleValue)) - return doubleValue < rangeMinimum(); + return doubleValue < minimum(); } return false; } bool HTMLInputElement::rangeOverflow() const { - if (inputType() == NUMBER) { - double max = 0.0; - double doubleValue = 0.0; - if (formStringToDouble(getAttribute(maxAttr), &max) && formStringToDouble(value(), &doubleValue)) - return doubleValue > max; - } else if (inputType() == RANGE) { + if (inputType() == NUMBER || inputType() == RANGE) { double doubleValue; if (formStringToDouble(value(), &doubleValue)) - return doubleValue > rangeMaximum(); + return doubleValue > maximum(); } return false; } -double HTMLInputElement::rangeMinimum() const +double HTMLInputElement::minimum() const { - ASSERT(inputType() == RANGE); - // The range type's "default minimum" is 0. - double min = 0.0; + ASSERT(inputType() == NUMBER || inputType() == RANGE); + double min = inputType() == RANGE ? rangeDefaultMinimum : numberDefaultMinimum; formStringToDouble(getAttribute(minAttr), &min); return min; } -double HTMLInputElement::rangeMaximum() const +double HTMLInputElement::maximum() const { - ASSERT(inputType() == RANGE); - // The range type's "default maximum" is 100. - static const double defaultMaximum = 100.0; + ASSERT(inputType() == NUMBER || inputType() == RANGE); + double defaultMaximum = inputType() == RANGE ? rangeDefaultMaximum : numberDefaultMaximum; double max = defaultMaximum; formStringToDouble(getAttribute(maxAttr), &max); - const double min = rangeMinimum(); - - if (max < min) { - // A remedy for the inconsistent min/max values. - // Sets the maxmimum to the default (100.0) or the minimum value. - max = min < defaultMaximum ? defaultMaximum : min; + if (inputType() == RANGE) { + // A remedy for the inconsistent min/max values for RANGE. + // Sets the maxmimum to the default or the minimum value. + double min = minimum(); + if (max < min) + max = std::max(min, defaultMaximum); } return max; } +double HTMLInputElement::stepBase() const +{ + if (inputType() == RANGE) + return minimum(); + if (inputType() == NUMBER) { + static const double defaultStepBase = 0.0; + double min = defaultStepBase; + formStringToDouble(getAttribute(minAttr), &min); + return min; + } + ASSERT_NOT_REACHED(); + return 0.0; +} + +bool HTMLInputElement::stepMismatch() const +{ + double step; + if (!getAllowedValueStep(&step)) + return false; + if (inputType() == NUMBER) { + double doubleValue; + if (!formStringToDouble(value(), &doubleValue)) + return false; + doubleValue = fabs(doubleValue - stepBase()); + if (isinf(doubleValue)) + return false; + // double's fractional part size is DBL_MAN_DIG-bit. If the current + // value is greater than step*2^DBL_MANT_DIG, the following fmod() makes + // no sense. + if (doubleValue / pow(2, DBL_MANT_DIG) > step) + return false; + double remainder = fmod(doubleValue, step); + // Accepts errors in lower 7-bit. + double acceptableError = step / pow(2, DBL_MANT_DIG - 7); + return acceptableError < remainder && remainder < (step - acceptableError); + } + // Non-RANGE types should be rejected by getAllowedValueStep(). + ASSERT(inputType() == RANGE); + // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the + // value matches to step. + return false; +} + +bool HTMLInputElement::getStepParameters(double* defaultStep, double* stepScaleFactor) const +{ + ASSERT(defaultStep); + ASSERT(stepScaleFactor); + switch (inputType()) { + case NUMBER: + case RANGE: + *defaultStep = numberDefaultStep; + *stepScaleFactor = numberStepScaleFactor; + return true; + case DATE: + case DATETIME: + case DATETIMELOCAL: + case MONTH: + case TIME: + case WEEK: + // FIXME: Implement for these types. + return false; + case BUTTON: + case CHECKBOX: + case COLOR: + case EMAIL: + case FILE: + case HIDDEN: + case IMAGE: + case ISINDEX: + case PASSWORD: + case RADIO: + case RESET: + case SEARCH: + case SUBMIT: + case TELEPHONE: + case TEXT: + case URL: + return false; + } + ASSERT_NOT_REACHED(); + return false; +} + +bool HTMLInputElement::getAllowedValueStep(double* step) const +{ + ASSERT(step); + double defaultStep; + double stepScaleFactor; + if (!getStepParameters(&defaultStep, &stepScaleFactor)) + return false; + const AtomicString& stepString = getAttribute(stepAttr); + if (stepString.isEmpty()) { + *step = defaultStep * stepScaleFactor; + return true; + } + if (equalIgnoringCase(stepString, "any")) + return false; + double parsed; + if (!formStringToDouble(stepString, &parsed) || parsed <= 0.0) { + *step = defaultStep * stepScaleFactor; + return true; + } + *step = parsed * stepScaleFactor; + ASSERT(*step > 0); + return true; +} + +void HTMLInputElement::applyStepForNumberOrRange(double count, ExceptionCode& ec) +{ + ASSERT(inputType() == NUMBER || inputType() == RANGE); + double step; + if (!getAllowedValueStep(&step)) { + ec = INVALID_STATE_ERR; + return; + } + double current; + if (!formStringToDouble(value(), ¤t)) { + ec = INVALID_STATE_ERR; + return; + } + double newValue = current + step * count; + if (isinf(newValue)) { + ec = INVALID_STATE_ERR; + return; + } + if (newValue < minimum()) { + ec = INVALID_STATE_ERR; + return; + } + double base = stepBase(); + newValue = base + round((newValue - base) / step) * step; + if (newValue > maximum()) { + ec = INVALID_STATE_ERR; + return; + } + setValue(formStringFromDouble(newValue)); +} + +void HTMLInputElement::stepUp(int n, ExceptionCode& ec) +{ + if (inputType() != NUMBER && inputType() != RANGE) { + ec = INVALID_STATE_ERR; + return; + } + applyStepForNumberOrRange(n, ec); +} + +void HTMLInputElement::stepDown(int n, ExceptionCode& ec) +{ + if (inputType() != NUMBER && inputType() != RANGE) { + ec = INVALID_STATE_ERR; + return; + } + applyStepForNumberOrRange(-n, ec); +} + static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element) { if (HTMLFormElement* form = element->form()) @@ -375,8 +554,40 @@ void HTMLInputElement::setType(const String& t) setAttribute(typeAttr, t); } +typedef HashMap<String, HTMLInputElement::InputType, CaseFoldingHash> InputTypeMap; +static const InputTypeMap* createTypeMap() +{ + InputTypeMap* map = new InputTypeMap; + map->add("button", HTMLInputElement::BUTTON); + map->add("checkbox", HTMLInputElement::CHECKBOX); + map->add("color", HTMLInputElement::COLOR); + map->add("date", HTMLInputElement::DATE); + map->add("datetime", HTMLInputElement::DATETIME); + map->add("datetime-local", HTMLInputElement::DATETIMELOCAL); + map->add("email", HTMLInputElement::EMAIL); + map->add("file", HTMLInputElement::FILE); + map->add("hidden", HTMLInputElement::HIDDEN); + map->add("image", HTMLInputElement::IMAGE); + map->add("khtml_isindex", HTMLInputElement::ISINDEX); + map->add("month", HTMLInputElement::MONTH); + map->add("number", HTMLInputElement::NUMBER); + map->add("password", HTMLInputElement::PASSWORD); + map->add("radio", HTMLInputElement::RADIO); + map->add("range", HTMLInputElement::RANGE); + map->add("reset", HTMLInputElement::RESET); + map->add("search", HTMLInputElement::SEARCH); + map->add("submit", HTMLInputElement::SUBMIT); + map->add("tel", HTMLInputElement::TELEPHONE); + map->add("time", HTMLInputElement::TIME); + map->add("url", HTMLInputElement::URL); + map->add("week", HTMLInputElement::WEEK); + // No need to register "text" because it is the default type. + return map; +} + void HTMLInputElement::setInputType(const String& t) { +<<<<<<< HEAD:WebCore/html/HTMLInputElement.cpp InputType newType; if (equalIgnoringCase(t, "password")) @@ -425,6 +636,10 @@ void HTMLInputElement::setInputType(const String& t) newType = COLOR; else newType = TEXT; +======= + static const InputTypeMap* typeMap = createTypeMap(); + InputType newType = t.isNull() ? TEXT : typeMap->get(t); +>>>>>>> webkit.org at r51976:WebCore/html/HTMLInputElement.cpp // IMPORTANT: Don't allow the type to be changed to FILE after the first // type change, otherwise a JavaScript programmer would be able to set a text @@ -495,82 +710,42 @@ void HTMLInputElement::setInputType(const String& t) m_imageLoader.clear(); } +static const AtomicString* createFormControlTypes() +{ + AtomicString* types = new AtomicString[HTMLInputElement::numberOfTypes]; + // The values must be lowercased because they will be the return values of + // input.type and it must be lowercase according to DOM Level 2. + types[HTMLInputElement::BUTTON] = "button"; + types[HTMLInputElement::CHECKBOX] = "checkbox"; + types[HTMLInputElement::COLOR] = "color"; + types[HTMLInputElement::DATE] = "date"; + types[HTMLInputElement::DATETIME] = "datetime"; + types[HTMLInputElement::DATETIMELOCAL] = "datetime-local"; + types[HTMLInputElement::EMAIL] = "email"; + types[HTMLInputElement::FILE] = "file"; + types[HTMLInputElement::HIDDEN] = "hidden"; + types[HTMLInputElement::IMAGE] = "image"; + types[HTMLInputElement::ISINDEX] = emptyAtom; + types[HTMLInputElement::MONTH] = "month"; + types[HTMLInputElement::NUMBER] = "number"; + types[HTMLInputElement::PASSWORD] = "password"; + types[HTMLInputElement::RADIO] = "radio"; + types[HTMLInputElement::RANGE] = "range"; + types[HTMLInputElement::RESET] = "reset"; + types[HTMLInputElement::SEARCH] = "search"; + types[HTMLInputElement::SUBMIT] = "submit"; + types[HTMLInputElement::TELEPHONE] = "tel"; + types[HTMLInputElement::TEXT] = "text"; + types[HTMLInputElement::TIME] = "time"; + types[HTMLInputElement::URL] = "url"; + types[HTMLInputElement::WEEK] = "week"; + return types; +} + const AtomicString& HTMLInputElement::formControlType() const { - // needs to be lowercase according to DOM spec - switch (inputType()) { - case BUTTON: { - DEFINE_STATIC_LOCAL(const AtomicString, button, ("button")); - return button; - } - case CHECKBOX: { - DEFINE_STATIC_LOCAL(const AtomicString, checkbox, ("checkbox")); - return checkbox; - } - case COLOR: { - DEFINE_STATIC_LOCAL(const AtomicString, color, ("color")); - return color; - } - case EMAIL: { - DEFINE_STATIC_LOCAL(const AtomicString, email, ("email")); - return email; - } - case FILE: { - DEFINE_STATIC_LOCAL(const AtomicString, file, ("file")); - return file; - } - case HIDDEN: { - DEFINE_STATIC_LOCAL(const AtomicString, hidden, ("hidden")); - return hidden; - } - case IMAGE: { - DEFINE_STATIC_LOCAL(const AtomicString, image, ("image")); - return image; - } - case ISINDEX: - return emptyAtom; - case NUMBER: { - DEFINE_STATIC_LOCAL(const AtomicString, number, ("number")); - return number; - } - case PASSWORD: { - DEFINE_STATIC_LOCAL(const AtomicString, password, ("password")); - return password; - } - case RADIO: { - DEFINE_STATIC_LOCAL(const AtomicString, radio, ("radio")); - return radio; - } - case RANGE: { - DEFINE_STATIC_LOCAL(const AtomicString, range, ("range")); - return range; - } - case RESET: { - DEFINE_STATIC_LOCAL(const AtomicString, reset, ("reset")); - return reset; - } - case SEARCH: { - DEFINE_STATIC_LOCAL(const AtomicString, search, ("search")); - return search; - } - case SUBMIT: { - DEFINE_STATIC_LOCAL(const AtomicString, submit, ("submit")); - return submit; - } - case TELEPHONE: { - DEFINE_STATIC_LOCAL(const AtomicString, telephone, ("tel")); - return telephone; - } - case TEXT: { - DEFINE_STATIC_LOCAL(const AtomicString, text, ("text")); - return text; - } - case URL: { - DEFINE_STATIC_LOCAL(const AtomicString, url, ("url")); - return url; - } - } - return emptyAtom; + static const AtomicString* formControlTypes = createFormControlTypes(); + return formControlTypes[inputType()]; } bool HTMLInputElement::saveFormControlState(String& result) const @@ -581,11 +756,15 @@ bool HTMLInputElement::saveFormControlState(String& result) const switch (inputType()) { case BUTTON: case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: + case MONTH: case NUMBER: case RANGE: case RESET: @@ -593,7 +772,9 @@ bool HTMLInputElement::saveFormControlState(String& result) const case SUBMIT: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: result = value(); return true; case CHECKBOX: @@ -613,11 +794,15 @@ void HTMLInputElement::restoreFormControlState(const String& state) switch (inputType()) { case BUTTON: case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: + case MONTH: case NUMBER: case RANGE: case RESET: @@ -625,7 +810,9 @@ void HTMLInputElement::restoreFormControlState(const String& state) case SUBMIT: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: setValue(state); break; case CHECKBOX: @@ -668,14 +855,20 @@ void HTMLInputElement::accessKeyAction(bool sendToAnyElement) // a no-op for this type break; case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: // should never restore previous selection here focus(false); break; @@ -714,12 +907,15 @@ void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr) m_autocomplete = Off; registerForActivationCallbackIfNeeded(); } else { - if (m_autocomplete == Off) - unregisterForActivationCallbackIfNeeded(); + bool needsToUnregister = m_autocomplete == Off; + if (attr->isEmpty()) m_autocomplete = Uninitialized; else m_autocomplete = On; + + if (needsToUnregister) + unregisterForActivationCallbackIfNeeded(); } } else if (attr->name() == typeAttr) { setInputType(attr->value()); @@ -802,30 +998,9 @@ void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr) bool HTMLInputElement::rendererIsNeeded(RenderStyle *style) { - switch (inputType()) { - case BUTTON: - case CHECKBOX: - case COLOR: - case EMAIL: - case FILE: - case IMAGE: - case ISINDEX: - case NUMBER: - case PASSWORD: - case RADIO: - case RANGE: - case RESET: - case SEARCH: - case SUBMIT: - case TELEPHONE: - case TEXT: - case URL: - return HTMLFormControlElementWithState::rendererIsNeeded(style); - case HIDDEN: - return false; - } - ASSERT(false); - return false; + if (inputType() == HIDDEN) + return false; + return HTMLFormControlElementWithState::rendererIsNeeded(style); } RenderObject *HTMLInputElement::createRenderer(RenderArena *arena, RenderStyle *style) @@ -847,14 +1022,20 @@ RenderObject *HTMLInputElement::createRenderer(RenderArena *arena, RenderStyle * case RANGE: return new (arena) RenderSlider(this); case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: return new (arena) RenderTextControlSingleLine(this, placeholderShouldBeVisible()); } ASSERT(false); @@ -934,16 +1115,22 @@ bool HTMLInputElement::appendFormData(FormDataList& encoding, bool multipart) switch (inputType()) { case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case HIDDEN: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case RANGE: case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: // always successful encoding.appendData(name(), value()); return true; @@ -1021,6 +1208,40 @@ void HTMLInputElement::reset() m_useDefaultChecked = true; } +bool HTMLInputElement::isTextField() const +{ + switch (inputType()) { + case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: + case EMAIL: + case ISINDEX: + case MONTH: + case NUMBER: + case PASSWORD: + case SEARCH: + case TELEPHONE: + case TEXT: + case TIME: + case URL: + case WEEK: + return true; + case BUTTON: + case CHECKBOX: + case FILE: + case HIDDEN: + case IMAGE: + case RADIO: + case RANGE: + case RESET: + case SUBMIT: + return false; + } + ASSERT_NOT_REACHED(); + return false; +} + void HTMLInputElement::setChecked(bool nowChecked, bool sendChangeEvent) { if (checked() == nowChecked) @@ -1112,11 +1333,15 @@ String HTMLInputElement::valueWithDefault() const case BUTTON: case CHECKBOX: case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case RADIO: @@ -1124,7 +1349,9 @@ String HTMLInputElement::valueWithDefault() const case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: break; case RESET: v = resetButtonDefaultLabel(); @@ -1137,7 +1364,13 @@ String HTMLInputElement::valueWithDefault() const return v; } -void HTMLInputElement::setValue(const String& value) +void HTMLInputElement::setValueForUser(const String& value) +{ + // Call setValue and make it send a change event. + setValue(value, true); +} + +void HTMLInputElement::setValue(const String& value, bool sendChangeEvent) { // For security reasons, we don't allow setting the filename, but we do allow clearing it. // The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't applicable to the file upload control @@ -1162,7 +1395,7 @@ void HTMLInputElement::setValue(const String& value) setNeedsStyleRecalc(); } else setAttribute(valueAttr, sanitizeValue(value)); - + if (isTextField()) { unsigned max = m_data.value().length(); #ifdef ANDROID_ACCEPT_CHANGES_TO_FOCUSED_TEXTFIELDS @@ -1174,6 +1407,12 @@ void HTMLInputElement::setValue(const String& value) else cacheSelection(max, max); } + + // Don't dispatch the change event when focused, it will be dispatched + // when the control loses focus. + if (sendChangeEvent && document()->focusedNode() != this) + dispatchFormControlChangeEvent(); + InputElement::notifyFormStateChanged(this); updateValidity(); } @@ -1226,16 +1465,22 @@ bool HTMLInputElement::storesValueSeparateFromAttribute() const case SUBMIT: return false; case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case FILE: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case RANGE: case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: return true; } return false; @@ -1402,16 +1647,22 @@ void HTMLInputElement::defaultEventHandler(Event* evt) switch (inputType()) { case CHECKBOX: case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case HIDDEN: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case RANGE: case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: // Simulate mouse click on the default form button for enter for these types of elements. clickDefaultFormButton = true; break; @@ -1531,16 +1782,22 @@ void HTMLInputElement::defaultEventHandler(Event* evt) clickElement = true; break; case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: case HIDDEN: case ISINDEX: + case MONTH: case NUMBER: case PASSWORD: case RANGE: case SEARCH: case TELEPHONE: case TEXT: + case TIME: case URL: + case WEEK: break; } } @@ -1560,12 +1817,12 @@ void HTMLInputElement::defaultEventHandler(Event* evt) } // Fire onChange for text fields. RenderObject* r = renderer(); - if (r && r->isTextField() && toRenderTextControl(r)->isEdited()) { + if (r && r->isTextField() && toRenderTextControl(r)->wasChangedSinceLastChangeEvent()) { dispatchFormControlChangeEvent(); // Refetch the renderer since arbitrary JS code run during onchange can do anything, including destroying it. r = renderer(); if (r && r->isTextField()) - toRenderTextControl(r)->setEdited(false); + toRenderTextControl(r)->setChangedSinceLastChangeEvent(false); } RefPtr<HTMLFormElement> formForSubmission = form(); @@ -1771,25 +2028,31 @@ bool HTMLInputElement::isRequiredFormControl() const return false; switch (inputType()) { - case TEXT: - case SEARCH: - case URL: - case TELEPHONE: + case CHECKBOX: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: - case PASSWORD: + case FILE: + case MONTH: case NUMBER: - case CHECKBOX: + case PASSWORD: case RADIO: - case FILE: + case SEARCH: + case TELEPHONE: + case TEXT: + case TIME: + case URL: + case WEEK: return true; - case HIDDEN: - case RANGE: - case SUBMIT: - case IMAGE: - case RESET: case BUTTON: case COLOR: + case HIDDEN: + case IMAGE: case ISINDEX: + case RANGE: + case RESET: + case SUBMIT: return false; } @@ -1856,6 +2119,16 @@ bool HTMLInputElement::willValidate() const inputType() != BUTTON && inputType() != RESET; } +String HTMLInputElement::formStringFromDouble(double number) +{ + // According to HTML5, "the best representation of the number n as a floating + // point number" is a string produced by applying ToString() to n. + DtoaBuffer buffer; + unsigned length; + doubleToStringInJavaScriptFormat(number, buffer, &length); + return String(buffer, length); +} + bool HTMLInputElement::formStringToDouble(const String& src, double* out) { // See HTML5 2.4.4.3 `Real numbers.' @@ -1879,6 +2152,34 @@ bool HTMLInputElement::formStringToDouble(const String& src, double* out) return true; } +bool HTMLInputElement::formStringToISODateTime(InputType type, const String& formString, ISODateTime* out) +{ + ISODateTime ignoredResult; + if (!out) + out = &ignoredResult; + const UChar* characters = formString.characters(); + unsigned length = formString.length(); + unsigned end; + + switch (type) { + case DATE: + return out->parseDate(characters, length, 0, end) && end == length; + case DATETIME: + return out->parseDateTime(characters, length, 0, end) && end == length; + case DATETIMELOCAL: + return out->parseDateTimeLocal(characters, length, 0, end) && end == length; + case MONTH: + return out->parseMonth(characters, length, 0, end) && end == length; + case WEEK: + return out->parseWeek(characters, length, 0, end) && end == length; + case TIME: + return out->parseTime(characters, length, 0, end) && end == length; + default: + ASSERT_NOT_REACHED(); + return false; + } +} + #if ENABLE(DATALIST) HTMLElement* HTMLInputElement::list() const { @@ -1891,29 +2192,35 @@ HTMLDataListElement* HTMLInputElement::dataList() const return 0; switch (inputType()) { - case TEXT: - case SEARCH: - case URL: - case TELEPHONE: + case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: case EMAIL: + case MONTH: case NUMBER: case RANGE: - case COLOR: { + case SEARCH: + case TELEPHONE: + case TEXT: + case TIME: + case URL: + case WEEK: { Element* element = document()->getElementById(getAttribute(listAttr)); if (element && element->hasTagName(datalistTag)) return static_cast<HTMLDataListElement*>(element); break; } - case HIDDEN: - case PASSWORD: + case BUTTON: case CHECKBOX: - case RADIO: case FILE: - case SUBMIT: + case HIDDEN: case IMAGE: - case RESET: - case BUTTON: case ISINDEX: + case PASSWORD: + case RADIO: + case RESET: + case SUBMIT: break; } return 0; diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h index 0e2da32..8f00aeb 100644 --- a/WebCore/html/HTMLInputElement.h +++ b/WebCore/html/HTMLInputElement.h @@ -34,13 +34,14 @@ class FileList; class HTMLDataListElement; class HTMLImageLoader; class HTMLOptionElement; +class ISODateTime; class KURL; class VisibleSelection; class HTMLInputElement : public HTMLTextFormControlElement, public InputElement { public: enum InputType { - TEXT, + TEXT = 0, // TEXT must be 0. PASSWORD, ISINDEX, CHECKBOX, @@ -57,9 +58,17 @@ public: NUMBER, TELEPHONE, URL, - COLOR + COLOR, + DATE, + DATETIME, + DATETIMELOCAL, + MONTH, + TIME, + WEEK, + // If you add new types or change the order of enum values, update numberOfTypes below. }; - + static const int numberOfTypes = WEEK + 1; + enum AutoCompleteSetting { Uninitialized, On, @@ -97,15 +106,25 @@ public: // For ValidityState bool rangeUnderflow() const; bool rangeOverflow() const; - // Returns the minimum value for type=range. Don't call this for other types. - double rangeMinimum() const; - // Returns the maximum value for type=range. Don't call this for other types. - // This always returns a value which is <= rangeMinimum(). - double rangeMaximum() const; + // Returns the minimum value for type=number or range. Don't call this for other types. + double minimum() const; + // Returns the maximum value for type=number or range. Don't call this for other types. + // This always returns a value which is >= minimum(). + double maximum() const; + // Sets the "allowed value step" defined in the HTML spec to the specified double pointer. + // Returns false if there is no "allowed value step." + bool getAllowedValueStep(double*) const; + // For ValidityState. + bool stepMismatch() const; + // Implementations of HTMLInputElement::stepUp() and stepDown(). + void stepUp(int, ExceptionCode&); + void stepDown(int, ExceptionCode&); + void stepUp(ExceptionCode& ec) { stepUp(1, ec); } + void stepDown(ExceptionCode& ec) { stepDown(1, ec); } bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; } virtual bool isRadioButton() const { return m_type == RADIO; } - virtual bool isTextField() const { return m_type == TEXT || m_type == PASSWORD || m_type == SEARCH || m_type == ISINDEX || m_type == EMAIL || m_type == NUMBER || m_type == TELEPHONE || m_type == URL || m_type == COLOR; } + virtual bool isTextField() const; virtual bool isSearchField() const { return m_type == SEARCH; } virtual bool isInputTypeHidden() const { return m_type == HIDDEN; } virtual bool isPasswordField() const { return m_type == PASSWORD; } @@ -119,7 +138,8 @@ public: void setType(const String&); virtual String value() const; - virtual void setValue(const String&); + virtual void setValue(const String&, bool sendChangeEvent = false); + virtual void setValueForUser(const String&); virtual String placeholder() const; virtual void setPlaceholder(const String&); @@ -234,6 +254,13 @@ public: // If the conversion fails, the return value is false. Take care that leading or trailing unnecessary characters make failures. This returns false for an empty string input. // The double* parameter may be 0. static bool formStringToDouble(const String&, double*); + // Converts the specified number to a string. This is an implementation of + // HTML5's "algorithm to convert a number to a string" for NUMBER/RANGE types. + static String formStringFromDouble(double); + // Parses the specified string as the InputType, and returns true if it is successfully parsed. + // An instance pointed by the ISODateTime* parameter will have parsed values and be + // modified even if the parsing fails. The ISODateTime* parameter may be 0. + static bool formStringToISODateTime(InputType, const String&, ISODateTime*); protected: virtual void willMoveToNewOwnerDocument(); @@ -257,6 +284,12 @@ private: virtual bool isRequiredFormControl() const; PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex(); + // Helper for getAllowedValueStep(); + bool getStepParameters(double* defaultStep, double* stepScaleFactor) const; + // Helper for stepUp()/stepDown(). Adds step value * count to the current number/range value. + void applyStepForNumberOrRange(double count, ExceptionCode&); + // Helper for applyStepForNumberOrRange(). + double stepBase() const; #if ENABLE(DATALIST) HTMLDataListElement* dataList() const; diff --git a/WebCore/html/HTMLInputElement.idl b/WebCore/html/HTMLInputElement.idl index 59248f4..2ac6674 100644 --- a/WebCore/html/HTMLInputElement.idl +++ b/WebCore/html/HTMLInputElement.idl @@ -43,16 +43,16 @@ module html { readonly attribute HTMLElement list; #endif #if !defined(LANGUAGE_COM) || !LANGUAGE_COM - attribute [Reflect] DOMString max; + attribute [ConvertNullToNullString, Reflect] DOMString max; #endif attribute long maxLength setter raises(DOMException); #if !defined(LANGUAGE_COM) || !LANGUAGE_COM - attribute [Reflect] DOMString min; + attribute [ConvertNullToNullString, Reflect] DOMString min; #endif attribute boolean multiple; attribute [ConvertNullToNullString] DOMString name; - attribute [Reflect] DOMString pattern; + attribute [ConvertNullToNullString, Reflect] DOMString pattern; attribute DOMString placeholder; attribute boolean readOnly; attribute boolean required; @@ -63,18 +63,30 @@ module html { attribute unsigned long size; // Changed string -> long as part of DOM level 2 #endif attribute [ConvertNullToNullString] DOMString src; + attribute [ConvertNullToNullString, Reflect] DOMString step; attribute [ConvertNullToNullString, JSCCustomGetter] DOMString type; // readonly dropped as part of DOM level 2 attribute [ConvertNullToNullString] DOMString useMap; attribute [ConvertNullToNullString] DOMString value; #if defined(ENABLE_DATALIST) && ENABLE_DATALIST readonly attribute HTMLOptionElement selectedOption; #endif + + void stepUp(in [Optional] long n) + raises(DOMException); + void stepDown(in [Optional] long n) + raises(DOMException); + readonly attribute boolean willValidate; + readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error); void select(); void click(); - + +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + void setValueForUser(in [ConvertNullToNullString] DOMString value); +#endif + // WinIE extension: attribute boolean indeterminate; diff --git a/WebCore/html/HTMLLinkElement.cpp b/WebCore/html/HTMLLinkElement.cpp index 47bcca8..ab06544 100644 --- a/WebCore/html/HTMLLinkElement.cpp +++ b/WebCore/html/HTMLLinkElement.cpp @@ -218,7 +218,7 @@ void HTMLLinkElement::process() // Stylesheet // This was buggy and would incorrectly match <link rel="alternate">, which has a different specified meaning. -dwh - if (m_disabledState != 2 && (m_isStyleSheet || acceptIfTypeContainsTextCSS && type.contains("text/css")) && document()->frame() && m_url.isValid()) { + if (m_disabledState != 2 && (m_isStyleSheet || (acceptIfTypeContainsTextCSS && type.contains("text/css"))) && document()->frame() && m_url.isValid()) { // also, don't load style sheets for standalone documents String charset = getAttribute(charsetAttr); diff --git a/WebCore/html/HTMLMediaElement.cpp b/WebCore/html/HTMLMediaElement.cpp index 729aceb..30f762a 100644 --- a/WebCore/html/HTMLMediaElement.cpp +++ b/WebCore/html/HTMLMediaElement.cpp @@ -117,6 +117,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* doc) , m_pausedInternal(false) , m_sendProgressEvents(true) , m_isFullscreen(false) + , m_closedCaptionsVisible(false) #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) , m_needWidgetUpdate(false) #endif @@ -213,6 +214,10 @@ void HTMLMediaElement::parseMappedAttribute(MappedAttribute* attr) setAttributeEventListener(eventNames().volumechangeEvent, createAttributeEventListener(this, attr)); else if (attrName == onwaitingAttr) setAttributeEventListener(eventNames().waitingEvent, createAttributeEventListener(this, attr)); + else if (attrName == onwebkitbeginfullscreenAttr) + setAttributeEventListener(eventNames().webkitbeginfullscreenEvent, createAttributeEventListener(this, attr)); + else if (attrName == onwebkitendfullscreenAttr) + setAttributeEventListener(eventNames().webkitendfullscreenEvent, createAttributeEventListener(this, attr)); else HTMLElement::parseMappedAttribute(attr); } @@ -292,24 +297,6 @@ void HTMLMediaElement::scheduleNextSourceChild() m_loadTimer.startOneShot(0); } -void HTMLMediaElement::scheduleProgressEvent(const AtomicString& eventName) -{ - if (!m_sendProgressEvents) - return; - - // FIXME: don't schedule timeupdate or progress events unless there are registered listeners - - bool totalKnown = m_player && m_player->totalBytesKnown(); - unsigned loaded = m_player ? m_player->bytesLoaded() : 0; - unsigned total = m_player ? m_player->totalBytes() : 0; - - RefPtr<ProgressEvent> evt = ProgressEvent::create(eventName, totalKnown, loaded, total); - enqueueEvent(evt); - - if (renderer()) - renderer()->updateFromElement(); -} - void HTMLMediaElement::scheduleEvent(const AtomicString& eventName) { enqueueEvent(Event::create(eventName, false, true)); @@ -478,6 +465,7 @@ void HTMLMediaElement::loadInternal() m_autoplaying = true; m_playedTimeRanges = TimeRanges::create(); m_lastSeekTime = 0; + m_closedCaptionsVisible = false; // 6 setPlaybackRate(defaultPlaybackRate()); @@ -523,7 +511,7 @@ void HTMLMediaElement::selectMediaResource() m_networkState = NETWORK_LOADING; // 5 - scheduleProgressEvent(eventNames().loadstartEvent); + scheduleEvent(eventNames().loadstartEvent); // 6 - If the media element has a src attribute, then run these substeps ContentType contentType(""); @@ -582,11 +570,10 @@ void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& content startProgressEventTimer(); #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) - m_player.clear(); - m_player.set(new MediaPlayer(this)); + m_player = MediaPlayer::create(this); #else if (!m_player) - m_player.set(new MediaPlayer(this)); + m_player = MediaPlayer::create(this); #endif m_player->setPreservesPitch(m_webkitPreservesPitch); @@ -647,7 +634,7 @@ void HTMLMediaElement::noneSupported() // 7 - Queue a task to fire a progress event called error at the media element, in // the context of the fetching process that was used to try to obtain the media // resource in the resource fetch algorithm. - scheduleProgressEvent(eventNames().errorEvent); + scheduleEvent(eventNames().errorEvent); // 8 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event. m_delayingTheLoadEvent = false; @@ -672,7 +659,7 @@ void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err) // 3 - Queue a task to fire a progress event called error at the media element, in // the context of the fetching process started by this instance of this algorithm. - scheduleProgressEvent(eventNames().errorEvent); + scheduleEvent(eventNames().errorEvent); // 4 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a // task to fire a simple event called emptied at the element. @@ -739,7 +726,7 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) if (state == MediaPlayer::Idle) { if (m_networkState > NETWORK_IDLE) { stopPeriodicTimers(); - scheduleProgressEvent(eventNames().suspendEvent); + scheduleEvent(eventNames().suspendEvent); } m_networkState = NETWORK_IDLE; } @@ -759,7 +746,7 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) // Schedule one last progress event so we guarantee that at least one is fired // for files that load very quickly. - scheduleProgressEvent(eventNames().progressEvent); + scheduleEvent(eventNames().progressEvent); // Check to see if readyState changes need to be dealt with before sending the // 'load' event so we report 'canplaythrough' first. This is necessary because a @@ -768,7 +755,7 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) if (static_cast<ReadyState>(currentState) != m_readyState) setReadyState(currentState); - scheduleProgressEvent(eventNames().loadEvent); + scheduleEvent(eventNames().loadEvent); } } } @@ -885,14 +872,16 @@ void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*) if (progress == m_previousProgress) { if (timedelta > 3.0 && !m_sentStalledEvent) { - scheduleProgressEvent(eventNames().stalledEvent); + scheduleEvent(eventNames().stalledEvent); m_sentStalledEvent = true; } } else { - scheduleProgressEvent(eventNames().progressEvent); + scheduleEvent(eventNames().progressEvent); m_previousProgress = progress; m_previousProgressTime = time; m_sentStalledEvent = false; + if (renderer()) + renderer()->updateFromElement(); } } @@ -1652,7 +1641,7 @@ void HTMLMediaElement::userCancelledLoad() // 3 - Queue a task to fire a progress event called abort at the media element, in the context // of the fetching process started by this instance of this algorithm. - scheduleProgressEvent(eventNames().abortEvent); + scheduleEvent(eventNames().abortEvent); // 5 - If the media element's readyState attribute has a value equal to HAVE_NOTHING, set the // element's networkState attribute to the NETWORK_EMPTY value and queue a task to fire a @@ -1784,7 +1773,7 @@ void HTMLMediaElement::finishParsingChildren() { HTMLElement::finishParsingChildren(); if (!m_player) - m_player.set(new MediaPlayer(this)); + m_player = MediaPlayer::create(this); document()->updateStyleIfNeeded(); if (m_needWidgetUpdate && renderer()) @@ -1796,25 +1785,96 @@ void HTMLMediaElement::finishParsingChildren() void HTMLMediaElement::enterFullscreen() { ASSERT(!m_isFullscreen); - if (!renderer()) - return; - if (document() && document()->page()) + if (document() && document()->page()) { document()->page()->chrome()->client()->enterFullscreenForNode(this); - m_isFullscreen = true; + scheduleEvent(eventNames().webkitbeginfullscreenEvent); + m_isFullscreen = true; + } } void HTMLMediaElement::exitFullscreen() { ASSERT(m_isFullscreen); - if (document() && document()->page()) + if (document() && document()->page()) { document()->page()->chrome()->client()->exitFullscreenForNode(this); + scheduleEvent(eventNames().webkitendfullscreenEvent); + } m_isFullscreen = false; } PlatformMedia HTMLMediaElement::platformMedia() const { return m_player ? m_player->platformMedia() : NoPlatformMedia; -} +} + +void HTMLMediaElement::webkitEnterFullScreen(ExceptionCode& ec) +{ + if (m_isFullscreen) + return; + + // Generate an exception if this isn't called in response to a user gesture, or if the + // element does not support fullscreen. + if (!processingUserGesture() || !supportsFullscreen()) { + ec = INVALID_STATE_ERR; + return; + } + + enterFullscreen(); +} + +void HTMLMediaElement::webkitExitFullScreen() +{ + if (m_isFullscreen) + exitFullscreen(); +} + +bool HTMLMediaElement::webkitSupportsFullscreen() +{ + return supportsFullscreen(); +} + +bool HTMLMediaElement::webkitDisplayingFullscreen() +{ + return m_isFullscreen; +} + +bool HTMLMediaElement::hasClosedCaptions() const +{ + return m_player && m_player->hasClosedCaptions(); +} + +bool HTMLMediaElement::closedCaptionsVisible() const +{ + return m_closedCaptionsVisible; +} + +void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible) +{ + if (!m_player ||!hasClosedCaptions()) + return; + + m_closedCaptionsVisible = closedCaptionVisible; + m_player->setClosedCaptionsVisible(closedCaptionVisible); + if (renderer()) + renderer()->updateFromElement(); +} + +void HTMLMediaElement::setWebkitClosedCaptionsVisible(bool visible) +{ + setClosedCaptionsVisible(visible); +} + +bool HTMLMediaElement::webkitClosedCaptionsVisible() const +{ + return closedCaptionsVisible(); +} + + +bool HTMLMediaElement::webkitHasClosedCaptions() const +{ + return hasClosedCaptions(); +} + } #endif diff --git a/WebCore/html/HTMLMediaElement.h b/WebCore/html/HTMLMediaElement.h index 405f013..bc39dd7 100644 --- a/WebCore/html/HTMLMediaElement.h +++ b/WebCore/html/HTMLMediaElement.h @@ -131,7 +131,18 @@ public: void setLoop(bool b); void play(); void pause(); - + +// fullscreen + void webkitEnterFullScreen(ExceptionCode&); + void webkitExitFullScreen(); + bool webkitSupportsFullscreen(); + bool webkitDisplayingFullscreen(); + +// captions + bool webkitHasClosedCaptions() const; + bool webkitClosedCaptionsVisible() const; + void setWebkitClosedCaptionsVisible(bool); + // controls bool controls() const; void setControls(bool); @@ -162,6 +173,10 @@ public: void enterFullscreen(); void exitFullscreen(); + bool hasClosedCaptions() const; + bool closedCaptionsVisible() const; + void setClosedCaptionsVisible(bool); + protected: float getTimeOffsetAttribute(const QualifiedName&, float valueOnError) const; void setTimeOffsetAttribute(const QualifiedName&, float value); @@ -203,7 +218,6 @@ private: void addPlayedRange(float start, float end); void scheduleTimeupdateEvent(bool periodicEvent); - void scheduleProgressEvent(const AtomicString& eventName); void scheduleEvent(const AtomicString& eventName); void enqueueEvent(RefPtr<Event> event); @@ -319,6 +333,7 @@ protected: bool m_sendProgressEvents : 1; bool m_isFullscreen : 1; + bool m_closedCaptionsVisible : 1; #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) bool m_needWidgetUpdate : 1; diff --git a/WebCore/html/HTMLMediaElement.idl b/WebCore/html/HTMLMediaElement.idl index 7278fa6..e418a63 100644 --- a/WebCore/html/HTMLMediaElement.idl +++ b/WebCore/html/HTMLMediaElement.idl @@ -77,7 +77,17 @@ interface [GenerateConstructor, Conditional=VIDEO] HTMLMediaElement : HTMLElemen setter raises (DOMException); attribute boolean muted; - // WebKit extension + // WebKit extensions attribute boolean webkitPreservesPitch; + + readonly attribute boolean webkitSupportsFullscreen; + readonly attribute boolean webkitDisplayingFullscreen; + + void webkitEnterFullScreen() + raises (DOMException); + void webkitExitFullScreen(); + + readonly attribute boolean webkitHasClosedCaptions; + attribute boolean webkitClosedCaptionsVisible; }; } diff --git a/WebCore/html/HTMLMetaElement.h b/WebCore/html/HTMLMetaElement.h index d86df2e..19e8ecd 100644 --- a/WebCore/html/HTMLMetaElement.h +++ b/WebCore/html/HTMLMetaElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * Copyright (C) 2003 Apple Computer, Inc. diff --git a/WebCore/html/HTMLModElement.cpp b/WebCore/html/HTMLModElement.cpp index b48182a..19b3403 100644 --- a/WebCore/html/HTMLModElement.cpp +++ b/WebCore/html/HTMLModElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> diff --git a/WebCore/html/HTMLModElement.h b/WebCore/html/HTMLModElement.h index 83697f9..9d9e6c1 100644 --- a/WebCore/html/HTMLModElement.h +++ b/WebCore/html/HTMLModElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> diff --git a/WebCore/html/HTMLOptionsCollection.cpp b/WebCore/html/HTMLOptionsCollection.cpp index 0b88183..db9a457 100644 --- a/WebCore/html/HTMLOptionsCollection.cpp +++ b/WebCore/html/HTMLOptionsCollection.cpp @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 2006 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or diff --git a/WebCore/html/HTMLParser.cpp b/WebCore/html/HTMLParser.cpp index 1cb47ae..f13c19b 100644 --- a/WebCore/html/HTMLParser.cpp +++ b/WebCore/html/HTMLParser.cpp @@ -203,6 +203,25 @@ void HTMLParser::setCurrent(Node* newCurrent) m_didRefCurrent = didRefNewCurrent; } +inline static int tagPriorityOfNode(Node* n) +{ + return n->isHTMLElement() ? static_cast<HTMLElement*>(n)->tagPriority() : 0; +} + +inline void HTMLParser::limitBlockDepth(int tagPriority) +{ + if (tagPriority >= minBlockLevelTagPriority) { + while (m_blocksInStack >= cMaxBlockDepth) + popBlock(m_blockStack->tagName); + } +} + +inline bool HTMLParser::insertNodeAfterLimitBlockDepth(Node* n, bool flat) +{ + limitBlockDepth(tagPriorityOfNode(n)); + return insertNode(n, flat); +} + PassRefPtr<Node> HTMLParser::parseToken(Token* t) { if (!m_skipModeTag.isNull()) { @@ -241,7 +260,7 @@ PassRefPtr<Node> HTMLParser::parseToken(Token* t) while (charsLeft) { // split large blocks of text to nodes of manageable size n = Text::createWithLengthLimit(m_document, text, charsLeft); - if (!insertNode(n.get(), t->selfClosingTag)) + if (!insertNodeAfterLimitBlockDepth(n.get(), t->selfClosingTag)) return 0; } return n; @@ -271,7 +290,7 @@ PassRefPtr<Node> HTMLParser::parseToken(Token* t) } } - if (!insertNode(n.get(), t->selfClosingTag)) { + if (!insertNodeAfterLimitBlockDepth(n.get(), t->selfClosingTag)) { // we couldn't insert the node if (n->isElementNode()) { @@ -329,21 +348,17 @@ bool HTMLParser::insertNode(Node* n, bool flat) RefPtr<Node> protectNode(n); const AtomicString& localName = n->localName(); - int tagPriority = n->isHTMLElement() ? static_cast<HTMLElement*>(n)->tagPriority() : 0; // <table> is never allowed inside stray table content. Always pop out of the stray table content // and close up the first table, and then start the second table as a sibling. if (m_inStrayTableContent && localName == tableTag) popBlock(tableTag); - if (tagPriority >= minBlockLevelTagPriority) { - while (m_blocksInStack >= cMaxBlockDepth) - popBlock(m_blockStack->tagName); - } - if (m_parserQuirks && !m_parserQuirks->shouldInsertNode(m_current, n)) return false; + int tagPriority = tagPriorityOfNode(n); + // let's be stupid and just try to insert it. // this should work if the document is well-formed Node* newNode = m_current->addChild(n); diff --git a/WebCore/html/HTMLParser.h b/WebCore/html/HTMLParser.h index 0945826..f07b64b 100644 --- a/WebCore/html/HTMLParser.h +++ b/WebCore/html/HTMLParser.h @@ -111,6 +111,9 @@ private: void processCloseTag(Token*); + void limitBlockDepth(int tagPriority); + + bool insertNodeAfterLimitBlockDepth(Node*, bool flat = false); bool insertNode(Node*, bool flat = false); bool handleError(Node*, bool flat, const AtomicString& localName, int tagPriority); diff --git a/WebCore/html/HTMLPlugInElement.cpp b/WebCore/html/HTMLPlugInElement.cpp index 2f429b4..9626c83 100644 --- a/WebCore/html/HTMLPlugInElement.cpp +++ b/WebCore/html/HTMLPlugInElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Stefan Schimanski (1Stein@gmx.de) diff --git a/WebCore/html/HTMLPreElement.cpp b/WebCore/html/HTMLPreElement.cpp index f340ae3..030660f 100644 --- a/WebCore/html/HTMLPreElement.cpp +++ b/WebCore/html/HTMLPreElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * Copyright (C) 2003 Apple Computer, Inc. diff --git a/WebCore/html/HTMLPreElement.h b/WebCore/html/HTMLPreElement.h index 691daf8..e84f4b3 100644 --- a/WebCore/html/HTMLPreElement.h +++ b/WebCore/html/HTMLPreElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * diff --git a/WebCore/html/HTMLSelectElement.idl b/WebCore/html/HTMLSelectElement.idl index 53fe848..ae47896 100644 --- a/WebCore/html/HTMLSelectElement.idl +++ b/WebCore/html/HTMLSelectElement.idl @@ -45,6 +45,7 @@ module html { readonly attribute ValidityState validity; #endif readonly attribute boolean willValidate; + readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error); diff --git a/WebCore/html/HTMLTableCellElement.cpp b/WebCore/html/HTMLTableCellElement.cpp index f3b4674..94bf82e 100644 --- a/WebCore/html/HTMLTableCellElement.cpp +++ b/WebCore/html/HTMLTableCellElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) diff --git a/WebCore/html/HTMLTableCellElement.h b/WebCore/html/HTMLTableCellElement.h index fc74cae..9cb7cf5 100644 --- a/WebCore/html/HTMLTableCellElement.h +++ b/WebCore/html/HTMLTableCellElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) diff --git a/WebCore/html/HTMLTableColElement.cpp b/WebCore/html/HTMLTableColElement.cpp index e1008d1..27ff6f7 100644 --- a/WebCore/html/HTMLTableColElement.cpp +++ b/WebCore/html/HTMLTableColElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) diff --git a/WebCore/html/HTMLTableColElement.h b/WebCore/html/HTMLTableColElement.h index 83a26aa..af785f3 100644 --- a/WebCore/html/HTMLTableColElement.h +++ b/WebCore/html/HTMLTableColElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) diff --git a/WebCore/html/HTMLTablePartElement.cpp b/WebCore/html/HTMLTablePartElement.cpp index 0f9a3e8..f060dce 100644 --- a/WebCore/html/HTMLTablePartElement.cpp +++ b/WebCore/html/HTMLTablePartElement.cpp @@ -1,6 +1,4 @@ /** - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) diff --git a/WebCore/html/HTMLTablePartElement.h b/WebCore/html/HTMLTablePartElement.h index adbd63b..1fd5218 100644 --- a/WebCore/html/HTMLTablePartElement.h +++ b/WebCore/html/HTMLTablePartElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) diff --git a/WebCore/html/HTMLTextAreaElement.idl b/WebCore/html/HTMLTextAreaElement.idl index db5154e..107a1fe 100644 --- a/WebCore/html/HTMLTextAreaElement.idl +++ b/WebCore/html/HTMLTextAreaElement.idl @@ -48,6 +48,7 @@ module html { void select(); readonly attribute boolean willValidate; + readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error); diff --git a/WebCore/html/HTMLTitleElement.h b/WebCore/html/HTMLTitleElement.h index 5335d8d..677bffd 100644 --- a/WebCore/html/HTMLTitleElement.h +++ b/WebCore/html/HTMLTitleElement.h @@ -1,6 +1,4 @@ /* - * This file is part of the DOM implementation for KDE. - * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * Copyright (C) 2003 Apple Computer, Inc. diff --git a/WebCore/html/HTMLTokenizer.cpp b/WebCore/html/HTMLTokenizer.cpp index c38a9be..3ca6958 100644 --- a/WebCore/html/HTMLTokenizer.cpp +++ b/WebCore/html/HTMLTokenizer.cpp @@ -564,12 +564,6 @@ HTMLTokenizer::State HTMLTokenizer::scriptExecution(const ScriptSourceCode& sour return state; m_executingScript++; -#if ENABLE(INSPECTOR) - InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent(); - if (timelineAgent) - timelineAgent->willEvaluateScriptTag(sourceCode.url().isNull() ? String() : sourceCode.url().string(), sourceCode.startLine()); -#endif - SegmentedString* savedPrependingSrc = m_currentPrependingSrc; SegmentedString prependingSrc; m_currentPrependingSrc = &prependingSrc; @@ -627,11 +621,6 @@ HTMLTokenizer::State HTMLTokenizer::scriptExecution(const ScriptSourceCode& sour m_currentPrependingSrc = savedPrependingSrc; -#if ENABLE(INSPECTOR) - if (timelineAgent) - timelineAgent->didEvaluateScriptTag(); -#endif - return state; } @@ -1692,8 +1681,7 @@ void HTMLTokenizer::write(const SegmentedString& str, bool appendData) #endif #if ENABLE(INSPECTOR) - InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent(); - if (timelineAgent) + if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) timelineAgent->willWriteHTML(); #endif @@ -1819,7 +1807,7 @@ void HTMLTokenizer::write(const SegmentedString& str, bool appendData) #endif #if ENABLE(INSPECTOR) - if (timelineAgent) + if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) timelineAgent->didWriteHTML(); #endif diff --git a/WebCore/html/HTMLVideoElement.cpp b/WebCore/html/HTMLVideoElement.cpp index 5bbc167..d0b1042 100644 --- a/WebCore/html/HTMLVideoElement.cpp +++ b/WebCore/html/HTMLVideoElement.cpp @@ -35,6 +35,7 @@ #include "HTMLImageLoader.h" #include "HTMLNames.h" #include "MappedAttribute.h" +#include "Page.h" #include "RenderImage.h" #include "RenderVideo.h" @@ -119,9 +120,10 @@ bool HTMLVideoElement::supportsFullscreen() const if (!page) return false; - if (!m_player || !m_player->supportsFullscreen()) + if (!m_player || !m_player->supportsFullscreen() || !m_player->hasVideo()) return false; - + + // Check with the platform client. return page->chrome()->client()->supportsFullscreenForNode(this); } diff --git a/WebCore/html/ISODateTime.cpp b/WebCore/html/ISODateTime.cpp new file mode 100644 index 0000000..4c28ac0 --- /dev/null +++ b/WebCore/html/ISODateTime.cpp @@ -0,0 +1,435 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ISODateTime.h" + +#include <limits.h> +#include <wtf/ASCIICType.h> + +namespace WebCore { + +// The oldest day of Gregorian Calendar is 1582-10-15. We don't support dates older than it. +static const int gregorianStartYear = 1582; +static const int gregorianStartMonth = 9; // This is October, since months are 0 based. +static const int gregorianStartDay = 15; + +static const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static bool isLeapYear(int year) +{ + if (year % 4) + return false; + if (!(year % 400)) + return true; + if (!(year % 100)) + return false; + return true; +} + +// `month' is 0-based. +static int maxDayOfMonth(int year, int month) +{ + if (month != 1) // February? + return daysInMonth[month]; + return isLeapYear(year) ? 29 : 28; +} + +// `month' is 0-based. +static int dayOfWeek(int year, int month, int day) +{ + int shiftedMonth = month + 2; + // 2:January, 3:Feburuary, 4:March, ... + + // Zeller's congruence + if (shiftedMonth <= 3) { + shiftedMonth += 12; + year--; + } + // 4:March, ..., 14:January, 15:February + + int highYear = year / 100; + int lowYear = year % 100; + // We add 6 to make the result Sunday-origin. + int result = (day + 13 * shiftedMonth / 5 + lowYear + lowYear / 4 + highYear / 4 + 5 * highYear + 6) % 7; + return result; +} + +int ISODateTime::maxWeekNumberInYear() const +{ + int day = dayOfWeek(m_year, 0, 1); // January 1. + return day == Thursday || (day == Wednesday && isLeapYear(m_year)) ? 53 : 52; +} + +static unsigned countDigits(const UChar* src, unsigned length, unsigned start) +{ + unsigned index = start; + for (; index < length; ++index) { + if (!isASCIIDigit(src[index])) + break; + } + return index - start; +} + +// Very strict integer parser. Do not allow leading or trailing whitespace unlike charactersToIntStrict(). +static bool toInt(const UChar* src, unsigned length, unsigned parseStart, unsigned parseLength, int& out) +{ + if (parseStart + parseLength > length || parseLength <= 0) + return false; + int value = 0; + const UChar* current = src + parseStart; + const UChar* end = current + parseLength; + + // We don't need to handle negative numbers for ISO 8601. + for (; current < end; ++current) { + if (!isASCIIDigit(*current)) + return false; + int digit = *current - '0'; + if (value > (INT_MAX - digit) / 10) // Check for overflow. + return false; + value = value * 10 + digit; + } + out = value; + return true; +} + +bool ISODateTime::parseYear(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + unsigned digitsLength = countDigits(src, length, start); + // Needs at least 4 digits according to the standard. + if (digitsLength < 4) + return false; + int year; + if (!toInt(src, length, start, digitsLength, year)) + return false; + // No support for years before Gregorian calendar. + if (year < gregorianStartYear) + return false; + m_year = year; + end = start + digitsLength; + return true; +} + +bool ISODateTime::addDay(int dayDiff) +{ + ASSERT(m_monthDay); + + int day = m_monthDay + dayDiff; + if (day > maxDayOfMonth(m_year, m_month)) { + day = m_monthDay; + int year = m_year; + int month = m_month; + int maxDay = maxDayOfMonth(year, month); + for (; dayDiff > 0; --dayDiff) { + ++day; + if (day > maxDay) { + day = 1; + ++month; + if (month >= 12) { // month is 0-origin. + month = 0; + ++year; + if (year < 0) // Check for overflow. + return false; + } + maxDay = maxDayOfMonth(year, month); + } + } + m_year = year; + m_month = month; + } else if (day < 1) { + int month = m_month; + int year = m_year; + day = m_monthDay; + for (; dayDiff < 0; ++dayDiff) { + --day; + if (day < 1) { + --month; + if (month < 0) { + month = 11; + --year; + } + day = maxDayOfMonth(year, month); + } + if (year < gregorianStartYear + || (year == gregorianStartYear && month < gregorianStartMonth) + || (year == gregorianStartYear && month == gregorianStartMonth && day < gregorianStartDay)) + return false; + } + m_year = year; + m_month = month; + } + m_monthDay = day; + return true; +} + +bool ISODateTime::addMinute(int minute) +{ + int carry; + // min can be negative or greater than 59. + minute += m_minute; + if (minute > 59) { + carry = minute / 60; + minute = minute % 60; + } else if (m_minute < 0) { + carry = (59 - m_minute) / 60; + minute += carry * 60; + carry = -carry; + ASSERT(minute >= 0 && minute <= 59); + } else { + m_minute = minute; + return true; + } + + int hour = m_hour + carry; + if (hour > 23) { + carry = hour / 24; + hour = hour % 24; + } else if (hour < 0) { + carry = (23 - hour) / 24; + hour += carry * 24; + carry = -carry; + ASSERT(hour >= 0 && hour <= 23); + } else { + m_minute = minute; + m_hour = hour; + return true; + } + if (!addDay(carry)) + return false; + m_minute = minute; + m_hour = hour; + return true; +} + +// Parses a timezone part, and adjust year, month, monthDay, hour, minute, second, millisecond. +bool ISODateTime::parseTimeZone(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + if (start >= length) + return false; + unsigned index = start; + if (src[index] == 'Z') { + end = index + 1; + return true; + } + + bool minus; + if (src[index] == '+') + minus = false; + else if (src[index] == '-') + minus = true; + else + return false; + ++index; + + int hour; + int minute; + if (!toInt(src, length, index, 2, hour) || hour < 0 || hour > 23) + return false; + index += 2; + + if (index >= length || src[index] != ':') + return false; + ++index; + + if (!toInt(src, length, index, 2, minute) || minute < 0 || minute > 59) + return false; + index += 2; + + if (minus) { + hour = -hour; + minute = -minute; + } + + // Subtract the timezone offset. + if (!addMinute(-(hour * 60 + minute))) + return false; + end = index; + return true; +} + +bool ISODateTime::parseMonth(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + ASSERT(src); + unsigned index; + if (!parseYear(src, length, start, index)) + return false; + if (index >= length || src[index] != '-') + return false; + ++index; + + int month; + if (!toInt(src, length, index, 2, month) || month < 1 || month > 12) + return false; + --month; + // No support for months before Gregorian calendar. + if (m_year == gregorianStartYear && month < gregorianStartMonth) + return false; + m_month = month; + end = index + 2; + return true; +} + +bool ISODateTime::parseDate(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + ASSERT(src); + unsigned index; + if (!parseMonth(src, length, start, index)) + return false; + // '-' and 2-digits are needed. + if (index + 2 >= length) + return false; + if (src[index] != '-') + return false; + ++index; + + int day; + if (!toInt(src, length, index, 2, day) || day < 1 || day > maxDayOfMonth(m_year, m_month)) + return false; + // No support for dates before Gregorian calendar. + if (m_year == gregorianStartYear && m_month == gregorianStartMonth && day < gregorianStartDay) + return false; + m_monthDay = day; + end = index + 2; + return true; +} + +bool ISODateTime::parseWeek(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + ASSERT(src); + unsigned index; + if (!parseYear(src, length, start, index)) + return false; + + // 4 characters ('-' 'W' digit digit) are needed. + if (index + 3 >= length) + return false; + if (src[index] != '-') + return false; + ++index; + if (src[index] != 'W') + return false; + ++index; + + int week; + if (!toInt(src, length, index, 2, week) || week < 1 || week > maxWeekNumberInYear()) + return false; + // No support for years older than or equals to Gregorian calendar start year. + if (m_year <= gregorianStartYear) + return false; + m_week = week; + end = index + 2; + return true; +} + +bool ISODateTime::parseTime(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + ASSERT(src); + int hour; + if (!toInt(src, length, start, 2, hour) || hour < 0 || hour > 23) + return false; + unsigned index = start + 2; + if (index >= length) + return false; + if (src[index] != ':') + return false; + ++index; + + int minute; + if (!toInt(src, length, index, 2, minute) || minute < 0 || minute > 59) + return false; + index += 2; + + int second = 0; + int millisecond = 0; + // Optional second part. + // Do not return with false because the part is optional. + if (index + 2 < length && src[index] == ':') { + if (toInt(src, length, index + 1, 2, second) && second >= 0 && second <= 59) { + index += 3; + + // Optional fractional second part. + if (index < length && src[index] == '.') { + unsigned digitsLength = countDigits(src, length, index + 1); + if (digitsLength > 0) { + ++index; + bool ok; + if (digitsLength == 1) { + ok = toInt(src, length, index, 1, millisecond); + millisecond *= 100; + } else if (digitsLength == 2) { + ok = toInt(src, length, index, 2, millisecond); + millisecond *= 10; + } else // digitsLength >= 3 + ok = toInt(src, length, index, 3, millisecond); + ASSERT(ok); + index += digitsLength; + } + } + } + } + m_hour = hour; + m_minute = minute; + m_second = second; + m_millisecond = millisecond; + end = index; + return true; +} + +bool ISODateTime::parseDateTimeLocal(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + ASSERT(src); + unsigned index; + if (!parseDate(src, length, start, index)) + return false; + if (index >= length) + return false; + if (src[index] != 'T') + return false; + ++index; + return parseTime(src, length, index, end); +} + +bool ISODateTime::parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end) +{ + ASSERT(src); + unsigned index; + if (!parseDate(src, length, start, index)) + return false; + if (index >= length) + return false; + if (src[index] != 'T') + return false; + ++index; + if (!parseTime(src, length, index, index)) + return false; + return parseTimeZone(src, length, index, end); +} + +} // namespace WebCore diff --git a/WebCore/html/ISODateTime.h b/WebCore/html/ISODateTime.h new file mode 100644 index 0000000..ee4cfb9 --- /dev/null +++ b/WebCore/html/ISODateTime.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT + * OWNER 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 ISODateTime_h +#define ISODateTime_h + +#include <wtf/unicode/Unicode.h> + +namespace WebCore { + +// An ISODateTime instance represents one of the following date and time combinations: +// * year-month +// * year-month-day +// * year-week +// * hour-minute-second-millisecond +// * year-month-day hour-minute-second-millisecond +class ISODateTime { +public: + ISODateTime() + : m_millisecond(0) + , m_second(0) + , m_minute(0) + , m_hour(0) + , m_monthDay(0) + , m_month(0) + , m_year(0) + , m_week(0) + { + } + + int millisecond() const { return m_millisecond; } + int second() const { return m_second; } + int minute() const { return m_minute; } + int hour() const { return m_hour; } + int monthDay() const { return m_monthDay; } + int month() const { return m_month; } + int fullYear() const { return m_year; } + int week() const { return m_week; } + + // The following six functions parse the input `src' whose length is + // `length', and updates some fields of this instance. The parsing starts at + // src[start] and examines characters before src[length]. + // `src' `date' must be non-null. The `src' string doesn't need to be + // null-terminated. + // The functions return true if the parsing succeeds, and set `end' to the + // next index after the last consumed. Extra leading characters cause parse + // failures, and the trailing extra characters don't cause parse failures. + + // Sets year and month. + bool parseMonth(const UChar* src, unsigned length, unsigned start, unsigned& end); + // Sets year, month and monthDay. + bool parseDate(const UChar* src, unsigned length, unsigned start, unsigned& end); + // Sets year and week. + bool parseWeek(const UChar* src, unsigned length, unsigned start, unsigned& end); + // Sets hour, minute, second and millisecond. + bool parseTime(const UChar* src, unsigned length, unsigned start, unsigned& end); + // Sets year, month, monthDay, hour, minute, second and millisecond. + bool parseDateTimeLocal(const UChar* src, unsigned length, unsigned start, unsigned& end); + // Sets year, month, monthDay, hour, minute, second and millisecond, and adjusts timezone. + bool parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end); + +private: + // Returns the maximum week number in this ISODateTime's year. + // The result is either of 52 and 53. + int maxWeekNumberInYear() const; + bool parseYear(const UChar* src, unsigned length, unsigned start, unsigned& end); + bool addDay(int); + bool addMinute(int); + bool parseTimeZone(const UChar* src, unsigned length, unsigned start, unsigned& end); + + // m_weekDay values + enum { + Sunday = 0, + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + }; + + int m_millisecond; // 0 - 999 + int m_second; + int m_minute; + int m_hour; + int m_monthDay; // 1 - 31 + int m_month; // 0:January - 11:December + int m_year; // 1582 - + int m_week; // 1 - 53 +}; + + +} // namespace WebCore + +#endif // ISODateTime_h diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp index 6b0a0b4..e7df225 100644 --- a/WebCore/html/ValidityState.cpp +++ b/WebCore/html/ValidityState.cpp @@ -26,6 +26,7 @@ #include "HTMLInputElement.h" #include "HTMLNames.h" #include "KURL.h" +#include "LocalizedStrings.h" #include "RegularExpression.h" #include <wtf/StdLibExtras.h> @@ -43,6 +44,31 @@ ValidityState::ValidityState(HTMLFormControlElement* parent) ASSERT(parent); } +String ValidityState::validationMessage() +{ + if (!control()->willValidate()) + return String(); + + if (customError()) + return m_customErrorMessage; + if (valueMissing()) + return validationMessageValueMissingText(); + if (typeMismatch()) + return validationMessageTypeMismatchText(); + if (patternMismatch()) + return validationMessagePatternMismatchText(); + if (tooLong()) + return validationMessageTooLongText(); + if (rangeUnderflow()) + return validationMessageRangeUnderflowText(); + if (rangeOverflow()) + return validationMessageRangeOverflowText(); + if (stepMismatch()) + return validationMessageStepMismatchText(); + + return String(); +} + bool ValidityState::typeMismatch() { if (!control()->hasTagName(inputTag)) @@ -74,6 +100,13 @@ bool ValidityState::typeMismatch() return false; } + case HTMLInputElement::DATE: + case HTMLInputElement::DATETIME: + case HTMLInputElement::DATETIMELOCAL: + case HTMLInputElement::MONTH: + case HTMLInputElement::TIME: + case HTMLInputElement::WEEK: + return !HTMLInputElement::formStringToISODateTime(input->inputType(), value, 0); default: return false; } @@ -93,6 +126,13 @@ bool ValidityState::rangeOverflow() return static_cast<HTMLInputElement*>(control())->rangeOverflow(); } +bool ValidityState::stepMismatch() +{ + if (!control()->hasTagName(inputTag)) + return false; + return static_cast<HTMLInputElement*>(control())->stepMismatch(); +} + bool ValidityState::valid() { bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() || diff --git a/WebCore/html/ValidityState.h b/WebCore/html/ValidityState.h index 1dee306..7ae95d7 100644 --- a/WebCore/html/ValidityState.h +++ b/WebCore/html/ValidityState.h @@ -38,6 +38,7 @@ namespace WebCore { HTMLFormControlElement* control() const { return m_control; } + String validationMessage(); void setCustomErrorMessage(const String& message) { m_customErrorMessage = message; } bool valueMissing() { return control()->valueMissing(); } @@ -46,7 +47,7 @@ namespace WebCore { bool tooLong() { return control()->tooLong(); } bool rangeUnderflow(); bool rangeOverflow(); - bool stepMismatch() { return false; } + bool stepMismatch(); bool customError() { return !m_customErrorMessage.isEmpty(); } bool valid(); diff --git a/WebCore/html/canvas/CanvasArray.idl b/WebCore/html/canvas/CanvasArray.idl deleted file mode 100644 index 63b2dcd..0000000 --- a/WebCore/html/canvas/CanvasArray.idl +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -module html { - interface [Conditional=3D_CANVAS, CustomToJS] CanvasArray { - readonly attribute long length; - int sizeInBytes(); - int alignedSizeInBytes(); - }; -} diff --git a/WebCore/html/canvas/CanvasArrayBuffer.cpp b/WebCore/html/canvas/CanvasArrayBuffer.cpp deleted file mode 100644 index c8a1397..0000000 --- a/WebCore/html/canvas/CanvasArrayBuffer.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasArrayBuffer.h" - -namespace WebCore { - - PassRefPtr<CanvasArrayBuffer> CanvasArrayBuffer::create(unsigned sizeInBytes) - { - return adoptRef(new CanvasArrayBuffer(sizeInBytes)); - } - - CanvasArrayBuffer::CanvasArrayBuffer(unsigned sizeInBytes) { - m_sizeInBytes = sizeInBytes; - m_data = WTF::fastZeroedMalloc(sizeInBytes); - } - - void* CanvasArrayBuffer::data() { - return m_data; - } - - unsigned CanvasArrayBuffer::byteLength() const { - return m_sizeInBytes; - } - - CanvasArrayBuffer::~CanvasArrayBuffer() { - WTF::fastFree(m_data); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasByteArray.h b/WebCore/html/canvas/CanvasByteArray.h deleted file mode 100644 index 69cadf7..0000000 --- a/WebCore/html/canvas/CanvasByteArray.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasByteArray_h -#define CanvasByteArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasArrayBuffer; - - class CanvasByteArray : public CanvasArray { - public: - virtual bool isByteArray() const { return true; } - - static PassRefPtr<CanvasByteArray> create(unsigned length); - static PassRefPtr<CanvasByteArray> create(signed char* array, unsigned length); - static PassRefPtr<CanvasByteArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - char* data() { return static_cast<char*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<signed char>::min()) - value = std::numeric_limits<signed char>::min(); - else if (value > std::numeric_limits<signed char>::max()) - value = std::numeric_limits<signed char>::max(); - signed char* storage = static_cast<signed char*>(m_baseAddress); - storage[index] = static_cast<signed char>(value); - } - - bool get(unsigned index, signed char& result) const - { - if (index >= m_size) - return false; - signed char* storage = static_cast<signed char*>(m_baseAddress); - result = storage[index]; - return true; - } - - signed char item(unsigned index) const - { - ASSERT(index < m_size); - signed char* storage = static_cast<signed char*>(m_baseAddress); - return storage[index]; - } - private: - CanvasByteArray(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasByteArray_h diff --git a/WebCore/html/canvas/CanvasFloatArray.cpp b/WebCore/html/canvas/CanvasFloatArray.cpp deleted file mode 100644 index 09561cb..0000000 --- a/WebCore/html/canvas/CanvasFloatArray.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasFloatArray.h" - -namespace WebCore { - - PassRefPtr<CanvasFloatArray> CanvasFloatArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(float)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasFloatArray> CanvasFloatArray::create(float* array, unsigned length) - { - RefPtr<CanvasFloatArray> a = CanvasFloatArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasFloatArray> CanvasFloatArray::create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(float)) != 0) - return NULL; - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(float))) > buffer->byteLength()) - return NULL; - } - return adoptRef(new CanvasFloatArray(buffer, offset, length)); - } - - CanvasFloatArray::CanvasFloatArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasFloatArray::length() const { - return m_size; - } - - unsigned CanvasFloatArray::sizeInBytes() const { - return length() * sizeof(float); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasFloatArray.h b/WebCore/html/canvas/CanvasFloatArray.h deleted file mode 100644 index d2dc4ff..0000000 --- a/WebCore/html/canvas/CanvasFloatArray.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasFloatArray_h -#define CanvasFloatArray_h - -#include "CanvasArray.h" -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasFloatArray : public CanvasArray { - public: - virtual bool isFloatArray() const { return true; } - - static PassRefPtr<CanvasFloatArray> create(unsigned length); - static PassRefPtr<CanvasFloatArray> create(float* array, unsigned length); - static PassRefPtr<CanvasFloatArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - float* data() { return static_cast<float*>(baseAddress()); } - - virtual unsigned length() const; - - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - float* storage = static_cast<float*>(m_baseAddress); - storage[index] = static_cast<float>(value); - } - - bool get(unsigned index, float& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - float item(unsigned index) const - { - ASSERT(index < m_size); - float* storage = static_cast<float*>(m_baseAddress); - float result = storage[index]; - if (isnan(result)) { - // Clamp NaN to 0 - result = 0; - } - return result; - } - private: - CanvasFloatArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasFloatArray_h diff --git a/WebCore/html/canvas/CanvasIntArray.cpp b/WebCore/html/canvas/CanvasIntArray.cpp deleted file mode 100644 index 4716d7b..0000000 --- a/WebCore/html/canvas/CanvasIntArray.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasArrayBuffer.h" -#include "CanvasIntArray.h" - -namespace WebCore { - - PassRefPtr<CanvasIntArray> CanvasIntArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(int)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasIntArray> CanvasIntArray::create(int* array, unsigned length) - { - RefPtr<CanvasIntArray> a = CanvasIntArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasIntArray> CanvasIntArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(int)) != 0) - return NULL; - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(int))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasIntArray(buffer, offset, length)); - } - - CanvasIntArray::CanvasIntArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasIntArray::length() const { - return m_size; - } - - unsigned CanvasIntArray::sizeInBytes() const { - return length() * sizeof(int); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasIntArray.h b/WebCore/html/canvas/CanvasIntArray.h deleted file mode 100644 index 4977034..0000000 --- a/WebCore/html/canvas/CanvasIntArray.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasIntArray_h -#define CanvasIntArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasIntArray : public CanvasArray { - public: - virtual bool isIntArray() const { return true; } - - static PassRefPtr<CanvasIntArray> create(unsigned length); - static PassRefPtr<CanvasIntArray> create(int* array, unsigned length); - static PassRefPtr<CanvasIntArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - int* data() { return static_cast<int*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<int>::min()) - value = std::numeric_limits<int>::min(); - else if (value > std::numeric_limits<int>::max()) - value = std::numeric_limits<int>::max(); - int* storage = static_cast<int*>(m_baseAddress); - storage[index] = static_cast<int>(value); - } - - bool get(unsigned index, int& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - int item(unsigned index) const - { - ASSERT(index < m_size); - int* storage = static_cast<int*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasIntArray(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasIntArray_h diff --git a/WebCore/html/canvas/CanvasObject.cpp b/WebCore/html/canvas/CanvasObject.cpp index 8a71a45..6c7667b 100644 --- a/WebCore/html/canvas/CanvasObject.cpp +++ b/WebCore/html/canvas/CanvasObject.cpp @@ -28,12 +28,13 @@ #if ENABLE(3D_CANVAS) #include "CanvasObject.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLRenderingContext.h" namespace WebCore { -CanvasObject::CanvasObject(CanvasRenderingContext3D* context) +CanvasObject::CanvasObject(WebGLRenderingContext* context) : m_object(0) + , m_shouldDeleteObject(true) , m_context(context) { } @@ -44,24 +45,27 @@ CanvasObject::~CanvasObject() m_context->removeObject(this); } -void CanvasObject::setObject(Platform3DObject object) +void CanvasObject::setObject(Platform3DObject object, bool shouldDeleteObject) { if (object == m_object) return; deleteObject(); m_object = object; + m_shouldDeleteObject = shouldDeleteObject; } void CanvasObject::deleteObject() { if (m_object) { - if (m_context) { - m_context->graphicsContext3D()->makeContextCurrent(); - _deleteObject(m_object); - } + if (m_shouldDeleteObject) + if (m_context) { + m_context->graphicsContext3D()->makeContextCurrent(); + _deleteObject(m_object); + } m_object = 0; } + m_shouldDeleteObject = true; } } diff --git a/WebCore/html/canvas/CanvasObject.h b/WebCore/html/canvas/CanvasObject.h index 748278d..b7b016a 100644 --- a/WebCore/html/canvas/CanvasObject.h +++ b/WebCore/html/canvas/CanvasObject.h @@ -33,14 +33,14 @@ namespace WebCore { - class CanvasRenderingContext3D; + class WebGLRenderingContext; class CanvasObject : public RefCounted<CanvasObject> { public: virtual ~CanvasObject(); Platform3DObject object() const { return m_object; } - void setObject(Platform3DObject); + void setObject(Platform3DObject, bool shouldDeleteObject = true); void deleteObject(); void detachContext() @@ -49,15 +49,22 @@ namespace WebCore { m_context = 0; } - CanvasRenderingContext3D* context() const { return m_context; } + WebGLRenderingContext* context() const { return m_context; } protected: - CanvasObject(CanvasRenderingContext3D*); + CanvasObject(WebGLRenderingContext*); virtual void _deleteObject(Platform3DObject) = 0; private: Platform3DObject m_object; - CanvasRenderingContext3D* m_context; + // The shouldDeleteObject flag indicates whether this wrapper + // owns the underlying resource and should delete it when the + // wrapper is unreferenced for the last time and deleted. It + // is only set to false for certain objects returned from get + // queries. FIXME: should consider canonicalizing all of these + // objects in the future. + bool m_shouldDeleteObject; + WebGLRenderingContext* m_context; }; } // namespace WebCore diff --git a/WebCore/html/canvas/CanvasRenderbuffer.idl b/WebCore/html/canvas/CanvasRenderbuffer.idl deleted file mode 100644 index 5e47cc3..0000000 --- a/WebCore/html/canvas/CanvasRenderbuffer.idl +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -module html { - interface [Conditional=3D_CANVAS] CanvasRenderbuffer { - }; -} diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 3341901..1ae9f75 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -355,6 +355,9 @@ void CanvasRenderingContext2D::scale(float sx, float sy) if (!state().m_invertibleCTM) return; + if (!isfinite(sx) | !isfinite(sy)) + return; + TransformationMatrix newTransform = state().m_transform; newTransform.scaleNonUniform(sx, sy); if (!newTransform.isInvertible()) { @@ -375,6 +378,9 @@ void CanvasRenderingContext2D::rotate(float angleInRadians) if (!state().m_invertibleCTM) return; + if (!isfinite(angleInRadians)) + return; + TransformationMatrix newTransform = state().m_transform; newTransform.rotate(angleInRadians / piDouble * 180.0); if (!newTransform.isInvertible()) { @@ -395,6 +401,9 @@ void CanvasRenderingContext2D::translate(float tx, float ty) if (!state().m_invertibleCTM) return; + if (!isfinite(tx) | !isfinite(ty)) + return; + TransformationMatrix newTransform = state().m_transform; newTransform.translate(tx, ty); if (!newTransform.isInvertible()) { @@ -414,8 +423,7 @@ void CanvasRenderingContext2D::transform(float m11, float m12, float m21, float return; if (!state().m_invertibleCTM) return; - - // HTML5 3.14.11.1 -- ignore any calls that pass non-finite numbers + if (!isfinite(m11) | !isfinite(m21) | !isfinite(dx) | !isfinite(m12) | !isfinite(m22) | !isfinite(dy)) return; @@ -438,7 +446,6 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo if (!c) return; - // HTML5 3.14.11.1 -- ignore any calls that pass non-finite numbers if (!isfinite(m11) | !isfinite(m21) | !isfinite(dx) | !isfinite(m12) | !isfinite(m22) | !isfinite(dy)) return; @@ -817,7 +824,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, return; RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha) @@ -833,7 +840,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, RGBA32 rgba = 0; // default is transparent black if (!state().m_shadowColor.isEmpty()) CSSParser::parseColor(rgba, state().m_shadowColor); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha))); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha)), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha) @@ -847,7 +854,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, return; RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float r, float g, float b, float a) @@ -863,7 +870,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, RGBA32 rgba = makeRGBA32FromFloats(r, g, b, a); // default is transparent black if (!state().m_shadowColor.isEmpty()) CSSParser::parseColor(rgba, state().m_shadowColor); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a) @@ -883,7 +890,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, CGContextSetShadowWithColor(dc->platformContext(), adjustedShadowSize(width, -height), blur, shadowColor); CGColorRelease(shadowColor); #else - dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a)); + dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a), DeviceColorSpace); #endif } @@ -906,7 +913,7 @@ void CanvasRenderingContext2D::applyShadow() CSSParser::parseColor(rgba, state().m_shadowColor); float width = state().m_shadowOffset.width(); float height = state().m_shadowOffset.height(); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba)); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); } static IntSize size(HTMLImageElement* image) @@ -995,7 +1002,7 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec FloatRect sourceRect = c->roundToDevicePixels(srcRect); FloatRect destRect = c->roundToDevicePixels(dstRect); willDraw(destRect); - c->drawImage(cachedImage->image(), destRect, sourceRect, state().m_globalComposite); + c->drawImage(cachedImage->image(), DeviceColorSpace, destRect, sourceRect, state().m_globalComposite); } void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, float x, float y) @@ -1045,7 +1052,7 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, const if (!sourceCanvas->originClean()) canvas()->setOriginTainted(); - c->drawImage(buffer->image(), destRect, sourceRect, state().m_globalComposite); + c->drawImage(buffer->image(), DeviceColorSpace, destRect, sourceRect, state().m_globalComposite); willDraw(destRect); // This call comes after drawImage, since the buffer we draw into may be our own, and we need to make sure it is dirty. // FIXME: Arguably willDraw should become didDraw and occur after drawing calls and not before them to avoid problems like this. } @@ -1139,7 +1146,7 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image, FloatRect destRect = FloatRect(dx, dy, dw, dh); willDraw(destRect); - c->drawImage(cachedImage->image(), destRect, FloatRect(sx, sy, sw, sh), op); + c->drawImage(cachedImage->image(), DeviceColorSpace, destRect, FloatRect(sx, sy, sw, sh), op); } void CanvasRenderingContext2D::setAlpha(float alpha) @@ -1526,9 +1533,9 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo GraphicsContext* maskImageContext = maskImage->context(); if (fill) - maskImageContext->setFillColor(Color::black); + maskImageContext->setFillColor(Color::black, DeviceColorSpace); else { - maskImageContext->setStrokeColor(Color::black); + maskImageContext->setStrokeColor(Color::black, DeviceColorSpace); maskImageContext->setStrokeThickness(c->strokeThickness()); } diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.cpp b/WebCore/html/canvas/CanvasRenderingContext3D.cpp deleted file mode 100644 index 612b4c3..0000000 --- a/WebCore/html/canvas/CanvasRenderingContext3D.cpp +++ /dev/null @@ -1,1441 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasRenderingContext3D.h" - -#include "CanvasActiveInfo.h" -#include "CanvasBuffer.h" -#include "CanvasFramebuffer.h" -#include "CanvasProgram.h" -#include "CanvasRenderbuffer.h" -#include "CanvasTexture.h" -#include "CanvasShader.h" -#include "HTMLCanvasElement.h" -#include "RenderBox.h" -#include "RenderLayer.h" - -namespace WebCore { - -PassOwnPtr<CanvasRenderingContext3D> CanvasRenderingContext3D::create(HTMLCanvasElement* canvas) -{ - OwnPtr<GraphicsContext3D> context(GraphicsContext3D::create()); - if (!context) - return 0; - - return new CanvasRenderingContext3D(canvas, context.release()); -} - -CanvasRenderingContext3D::CanvasRenderingContext3D(HTMLCanvasElement* passedCanvas, PassOwnPtr<GraphicsContext3D> context) - : CanvasRenderingContext(passedCanvas) - , m_context(context) - , m_needsUpdate(true) - , m_markedCanvasDirty(false) -{ - ASSERT(m_context); - m_context->reshape(canvas()->width(), canvas()->height()); -} - -CanvasRenderingContext3D::~CanvasRenderingContext3D() -{ - detachAndRemoveAllObjects(); -} - -void CanvasRenderingContext3D::markContextChanged() -{ -#if USE(ACCELERATED_COMPOSITING) - if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) { - canvas()->renderBox()->layer()->rendererContentChanged(); - } else { -#endif - if (!m_markedCanvasDirty) { - // Make sure the canvas's image buffer is allocated. - canvas()->buffer(); - canvas()->willDraw(FloatRect(0, 0, canvas()->width(), canvas()->height())); - m_markedCanvasDirty = true; - } -#if USE(ACCELERATED_COMPOSITING) - } -#endif -} - -void CanvasRenderingContext3D::beginPaint() -{ - if (m_markedCanvasDirty) { - m_context->beginPaint(this); - } -} - -void CanvasRenderingContext3D::endPaint() -{ - if (m_markedCanvasDirty) { - m_markedCanvasDirty = false; - m_context->endPaint(); - } -} - -void CanvasRenderingContext3D::reshape(int width, int height) -{ - if (m_needsUpdate) { -#if USE(ACCELERATED_COMPOSITING) - if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) - canvas()->renderBox()->layer()->rendererContentChanged(); -#endif - m_needsUpdate = false; - } - - m_context->reshape(width, height); -} - -int CanvasRenderingContext3D::sizeInBytes(int type, ExceptionCode& ec) -{ - int result = m_context->sizeInBytes(type); - if (result <= 0) { - ec = SYNTAX_ERR; - } - return result; -} - -void CanvasRenderingContext3D::activeTexture(unsigned long texture) -{ - m_context->activeTexture(texture); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::attachShader(CanvasProgram* program, CanvasShader* shader) -{ - if (!program || !shader) - return; - m_context->attachShader(program, shader); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bindAttribLocation(CanvasProgram* program, unsigned long index, const String& name) -{ - if (!program) - return; - m_context->bindAttribLocation(program, index, name); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bindBuffer(unsigned long target, CanvasBuffer* buffer) -{ - m_context->bindBuffer(target, buffer); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::bindFramebuffer(unsigned long target, CanvasFramebuffer* buffer) -{ - m_context->bindFramebuffer(target, buffer); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bindRenderbuffer(unsigned long target, CanvasRenderbuffer* renderbuffer) -{ - m_context->bindRenderbuffer(target, renderbuffer); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::bindTexture(unsigned long target, CanvasTexture* texture) -{ - m_context->bindTexture(target, texture); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendColor(double red, double green, double blue, double alpha) -{ - m_context->blendColor(red, green, blue, alpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendEquation( unsigned long mode ) -{ - m_context->blendEquation(mode); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha) -{ - m_context->blendEquationSeparate(modeRGB, modeAlpha); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor) -{ - m_context->blendFunc(sfactor, dfactor); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha) -{ - m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bufferData(unsigned long target, int size, unsigned long usage) -{ - m_context->bufferData(target, size, usage); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bufferData(unsigned long target, CanvasArray* data, unsigned long usage) -{ - m_context->bufferData(target, data, usage); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::bufferSubData(unsigned long target, long offset, CanvasArray* data) -{ - m_context->bufferSubData(target, offset, data); - cleanupAfterGraphicsCall(false); -} - -unsigned long CanvasRenderingContext3D::checkFramebufferStatus(unsigned long target) -{ - return m_context->checkFramebufferStatus(target); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::clear(unsigned long mask) -{ - m_context->clear(mask); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::clearColor(double r, double g, double b, double a) -{ - if (isnan(r)) - r = 0; - if (isnan(g)) - g = 0; - if (isnan(b)) - b = 0; - if (isnan(a)) - a = 1; - m_context->clearColor(r, g, b, a); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::clearDepth(double depth) -{ - m_context->clearDepth(depth); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::clearStencil(long s) -{ - m_context->clearStencil(s); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::colorMask(bool red, bool green, bool blue, bool alpha) -{ - m_context->colorMask(red, green, blue, alpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::compileShader(CanvasShader* shader) -{ - m_context->compileShader(shader); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) -{ - m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height) -{ - m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); - cleanupAfterGraphicsCall(false); -} - -PassRefPtr<CanvasBuffer> CanvasRenderingContext3D::createBuffer() -{ - RefPtr<CanvasBuffer> o = CanvasBuffer::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasFramebuffer> CanvasRenderingContext3D::createFramebuffer() -{ - RefPtr<CanvasFramebuffer> o = CanvasFramebuffer::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasTexture> CanvasRenderingContext3D::createTexture() -{ - RefPtr<CanvasTexture> o = CanvasTexture::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasProgram> CanvasRenderingContext3D::createProgram() -{ - RefPtr<CanvasProgram> o = CanvasProgram::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasRenderbuffer> CanvasRenderingContext3D::createRenderbuffer() -{ - RefPtr<CanvasRenderbuffer> o = CanvasRenderbuffer::create(this); - addObject(o.get()); - return o; -} - -PassRefPtr<CanvasShader> CanvasRenderingContext3D::createShader(unsigned long type) -{ - // FIXME: Need to include GL_ constants for internal use - // FIXME: Need to do param checking and throw exception if an illegal value is passed in - GraphicsContext3D::ShaderType shaderType = GraphicsContext3D::VERTEX_SHADER; - if (type == 0x8B30) // GL_FRAGMENT_SHADER - shaderType = GraphicsContext3D::FRAGMENT_SHADER; - - RefPtr<CanvasShader> o = CanvasShader::create(this, shaderType); - addObject(o.get()); - return o; -} - -void CanvasRenderingContext3D::cullFace(unsigned long mode) -{ - m_context->cullFace(mode); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::deleteBuffer(CanvasBuffer* buffer) -{ - if (!buffer) - return; - - buffer->deleteObject(); -} - -void CanvasRenderingContext3D::deleteFramebuffer(CanvasFramebuffer* framebuffer) -{ - if (!framebuffer) - return; - - framebuffer->deleteObject(); -} - -void CanvasRenderingContext3D::deleteProgram(CanvasProgram* program) -{ - if (!program) - return; - - program->deleteObject(); -} - -void CanvasRenderingContext3D::deleteRenderbuffer(CanvasRenderbuffer* renderbuffer) -{ - if (!renderbuffer) - return; - - renderbuffer->deleteObject(); -} - -void CanvasRenderingContext3D::deleteShader(CanvasShader* shader) -{ - if (!shader) - return; - - shader->deleteObject(); -} - -void CanvasRenderingContext3D::deleteTexture(CanvasTexture* texture) -{ - if (!texture) - return; - - texture->deleteObject(); -} - -void CanvasRenderingContext3D::depthFunc(unsigned long func) -{ - m_context->depthFunc(func); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::depthMask(bool flag) -{ - m_context->depthMask(flag); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::depthRange(double zNear, double zFar) -{ - m_context->depthRange(zNear, zFar); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::detachShader(CanvasProgram* program, CanvasShader* shader) -{ - if (!program || !shader) - return; - - m_context->detachShader(program, shader); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::disable(unsigned long cap) -{ - m_context->disable(cap); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::disableVertexAttribArray(unsigned long index) -{ - m_context->disableVertexAttribArray(index); - cleanupAfterGraphicsCall(false); -} - - -void CanvasRenderingContext3D::drawArrays(unsigned long mode, long first, long count) -{ - m_context->drawArrays(mode, first, count); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset) -{ - m_context->drawElements(mode, count, type, offset); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::enable(unsigned long cap) -{ - m_context->enable(cap); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::enableVertexAttribArray(unsigned long index) -{ - m_context->enableVertexAttribArray(index); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::finish() -{ - m_context->finish(); - cleanupAfterGraphicsCall(true); -} - - -void CanvasRenderingContext3D::flush() -{ - m_context->flush(); - cleanupAfterGraphicsCall(true); -} - -void CanvasRenderingContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, CanvasRenderbuffer* buffer) -{ - if (!buffer) - return; - - m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, CanvasTexture* texture, long level) -{ - if (!texture) - return; - - m_context->framebufferTexture2D(target, attachment, textarget, texture, level); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::frontFace(unsigned long mode) -{ - m_context->frontFace(mode); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::generateMipmap(unsigned long target) -{ - m_context->generateMipmap(target); - cleanupAfterGraphicsCall(false); -} - -PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveAttrib(CanvasProgram* program, unsigned long index, ExceptionCode& ec) -{ - ActiveInfo info; - if (!program || program->context() != this || !m_context->getActiveAttrib(program, index, info)) { - ec = INDEX_SIZE_ERR; - return 0; - } - return CanvasActiveInfo::create(info.name, info.type, info.size); -} - -PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveUniform(CanvasProgram* program, unsigned long index, ExceptionCode& ec) -{ - ActiveInfo info; - if (!program || program->context() != this || !m_context->getActiveUniform(program, index, info)) { - ec = INDEX_SIZE_ERR; - return 0; - } - return CanvasActiveInfo::create(info.name, info.type, info.size); -} - -int CanvasRenderingContext3D::getAttribLocation(CanvasProgram* program, const String& name) -{ - return m_context->getAttribLocation(program, name); -} - -bool CanvasRenderingContext3D::getBoolean(unsigned long pname) -{ - bool result = m_context->getBoolean(pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasUnsignedByteArray> CanvasRenderingContext3D::getBooleanv(unsigned long pname) -{ - RefPtr<CanvasUnsignedByteArray> array = m_context->getBooleanv(pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getBufferParameteri(unsigned long target, unsigned long pname) -{ - int result = m_context->getBufferParameteri(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getBufferParameteriv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getBufferParameteriv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -unsigned long CanvasRenderingContext3D::getError() -{ - return m_context->getError(); -} - -float CanvasRenderingContext3D::getFloat(unsigned long pname) -{ - float result = m_context->getFloat(pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getFloatv(unsigned long pname) -{ - RefPtr<CanvasFloatArray> array = m_context->getFloatv(pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getFramebufferAttachmentParameteri(unsigned long target, unsigned long attachment, unsigned long pname) -{ - int result = m_context->getFramebufferAttachmentParameteri(target, attachment, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getFramebufferAttachmentParameteriv(target, attachment, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getInteger(unsigned long pname) -{ - float result = m_context->getInteger(pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getIntegerv(unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getIntegerv(pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getProgrami(CanvasProgram* program, unsigned long pname) -{ - int result = m_context->getProgrami(program, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getProgramiv(CanvasProgram* program, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getProgramiv(program, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -String CanvasRenderingContext3D::getProgramInfoLog(CanvasProgram* program) -{ - String s = m_context->getProgramInfoLog(program); - cleanupAfterGraphicsCall(false); - return s; -} - -int CanvasRenderingContext3D::getRenderbufferParameteri(unsigned long target, unsigned long pname) -{ - int result = m_context->getRenderbufferParameteri(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getRenderbufferParameteriv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getShaderi(CanvasShader* shader, unsigned long pname) -{ - int result = m_context->getShaderi(shader, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getShaderiv(CanvasShader* shader, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getShaderiv(shader, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -String CanvasRenderingContext3D::getShaderInfoLog(CanvasShader* shader) -{ - String s = m_context->getShaderInfoLog(shader); - cleanupAfterGraphicsCall(false); - return s; -} - -String CanvasRenderingContext3D::getShaderSource(CanvasShader* shader) -{ - String s = m_context->getShaderSource(shader); - cleanupAfterGraphicsCall(false); - return s; -} - -String CanvasRenderingContext3D::getString(unsigned long name) -{ - return m_context->getString(name); -} - -float CanvasRenderingContext3D::getTexParameterf(unsigned long target, unsigned long pname) -{ - float result = m_context->getTexParameterf(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getTexParameterfv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasFloatArray> array = m_context->getTexParameterfv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -int CanvasRenderingContext3D::getTexParameteri(unsigned long target, unsigned long pname) -{ - int result = m_context->getTexParameteri(target, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getTexParameteriv(unsigned long target, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getTexParameteriv(target, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -float CanvasRenderingContext3D::getUniformf(CanvasProgram* program, long location) -{ - float result = m_context->getUniformf(program, location); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getUniformfv(CanvasProgram* program, long location) -{ - RefPtr<CanvasFloatArray> array = m_context->getUniformfv(program, location); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getUniformi(CanvasProgram* program, long location) -{ - long result = m_context->getUniformi(program, location); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getUniformiv(CanvasProgram* program, long location) -{ - RefPtr<CanvasIntArray> array = m_context->getUniformiv(program, location); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getUniformLocation(CanvasProgram* program, const String& name) -{ - return m_context->getUniformLocation(program, name); -} - -float CanvasRenderingContext3D::getVertexAttribf(unsigned long index, unsigned long pname) -{ - float result = m_context->getVertexAttribf(index, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getVertexAttribfv(unsigned long index, unsigned long pname) -{ - RefPtr<CanvasFloatArray> array = m_context->getVertexAttribfv(index, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getVertexAttribi(unsigned long index, unsigned long pname) -{ - long result = m_context->getVertexAttribi(index, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getVertexAttribiv(unsigned long index, unsigned long pname) -{ - RefPtr<CanvasIntArray> array = m_context->getVertexAttribiv(index, pname); - cleanupAfterGraphicsCall(false); - return array; -} - -long CanvasRenderingContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname) -{ - long result = m_context->getVertexAttribOffset(index, pname); - cleanupAfterGraphicsCall(false); - return result; -} - -void CanvasRenderingContext3D::hint(unsigned long target, unsigned long mode) -{ - m_context->hint(target, mode); - cleanupAfterGraphicsCall(false); -} - -bool CanvasRenderingContext3D::isBuffer(CanvasBuffer* buffer) -{ - if (!buffer) - return false; - - return m_context->isBuffer(buffer); -} - -bool CanvasRenderingContext3D::isEnabled(unsigned long cap) -{ - return m_context->isEnabled(cap); -} - -bool CanvasRenderingContext3D::isFramebuffer(CanvasFramebuffer* framebuffer) -{ - return m_context->isFramebuffer(framebuffer); -} - -bool CanvasRenderingContext3D::isProgram(CanvasProgram* program) -{ - return m_context->isProgram(program); -} - -bool CanvasRenderingContext3D::isRenderbuffer(CanvasRenderbuffer* renderbuffer) -{ - return m_context->isRenderbuffer(renderbuffer); -} - -bool CanvasRenderingContext3D::isShader(CanvasShader* shader) -{ - return m_context->isShader(shader); -} - -bool CanvasRenderingContext3D::isTexture(CanvasTexture* texture) -{ - return m_context->isTexture(texture); -} - -void CanvasRenderingContext3D::lineWidth(double width) -{ - m_context->lineWidth((float) width); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::linkProgram(CanvasProgram* program) -{ - if (!program) - return; - - m_context->linkProgram(program); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::pixelStorei(unsigned long pname, long param) -{ - m_context->pixelStorei(pname, param); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::polygonOffset(double factor, double units) -{ - m_context->polygonOffset((float) factor, (float) units); - cleanupAfterGraphicsCall(false); -} - -PassRefPtr<CanvasArray> CanvasRenderingContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type) -{ - RefPtr<CanvasArray> array = m_context->readPixels(x, y, width, height, format, type); - cleanupAfterGraphicsCall(false); - return array; -} - -void CanvasRenderingContext3D::releaseShaderCompiler() -{ - m_context->releaseShaderCompiler(); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height) -{ - m_context->renderbufferStorage(target, internalformat, width, height); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::sampleCoverage(double value, bool invert) -{ - m_context->sampleCoverage((float) value, invert); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::scissor(long x, long y, unsigned long width, unsigned long height) -{ - m_context->scissor(x, y, width, height); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::shaderSource(CanvasShader* shader, const String& string) -{ - m_context->shaderSource(shader, string); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask) -{ - m_context->stencilFunc(func, ref, mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask) -{ - m_context->stencilFuncSeparate(face, func, ref, mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilMask(unsigned long mask) -{ - m_context->stencilMask(mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask) -{ - m_context->stencilMaskSeparate(face, mask); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass) -{ - m_context->stencilOp(fail, zfail, zpass); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass) -{ - m_context->stencilOpSeparate(face, fail, zfail, zpass); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, internalformat, width, height, - border, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, internalformat, width, height, - border, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, image, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, canvas, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texImage2D(target, level, video, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texParameterf(unsigned target, unsigned pname, float param) -{ - m_context->texParameterf(target, pname, param); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texParameteri(unsigned target, unsigned pname, int param) -{ - m_context->texParameteri(target, pname, param); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, image, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, canvas, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode& ec) -{ - // FIXME: For now we ignore any errors returned - ec = 0; - m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1f(long location, float x) -{ - m_context->uniform1f(location, x); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1fv(location, v->data(), v->length()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1fv(location, v, size); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1i(long location, int x) -{ - m_context->uniform1i(location, x); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1iv(location, v->data(), v->length()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform1iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - m_context->uniform1iv(location, v, size); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2f(long location, float x, float y) -{ - m_context->uniform2f(location, x, y); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2fv(location, v->data(), v->length() / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2fv(location, v, size / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2i(long location, int x, int y) -{ - m_context->uniform2i(location, x, y); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2iv(location, v->data(), v->length() / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform2iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 2 - m_context->uniform2iv(location, v, size / 2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3f(long location, float x, float y, float z) -{ - m_context->uniform3f(location, x, y, z); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3fv(location, v->data(), v->length() / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3fv(location, v, size / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3i(long location, int x, int y, int z) -{ - m_context->uniform3i(location, x, y, z); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3iv(location, v->data(), v->length() / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform3iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 3 - m_context->uniform3iv(location, v, size / 3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4f(long location, float x, float y, float z, float w) -{ - m_context->uniform4f(location, x, y, z, w); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4fv(long location, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4fv(location, v->data(), v->length() / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4fv(long location, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4fv(location, v, size / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4i(long location, int x, int y, int z, int w) -{ - m_context->uniform4i(location, x, y, z, w); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4iv(long location, CanvasIntArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4iv(location, v->data(), v->length() / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniform4iv(long location, int* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniform4iv(location, v, size / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix2fv(long location, bool transpose, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniformMatrix2fv(location, transpose, v->data(), v->length() / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix2fv(long location, bool transpose, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 4 - m_context->uniformMatrix2fv(location, transpose, v, size / 4); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix3fv(long location, bool transpose, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 9 - m_context->uniformMatrix3fv(location, transpose, v->data(), v->length() / 9); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix3fv(long location, bool transpose, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 9 - m_context->uniformMatrix3fv(location, transpose, v, size / 9); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix4fv(long location, bool transpose, CanvasFloatArray* v) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 16 - m_context->uniformMatrix4fv(location, transpose, v->data(), v->length() / 16); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::uniformMatrix4fv(long location, bool transpose, float* v, int size) -{ - // FIXME: we need to throw if no array passed in - if (!v) - return; - - // FIXME: length needs to be a multiple of 16 - m_context->uniformMatrix4fv(location, transpose, v, size / 16); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::useProgram(CanvasProgram* program) -{ - m_context->useProgram(program); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::validateProgram(CanvasProgram* program) -{ - m_context->validateProgram(program); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib1f(unsigned long indx, float v0) -{ - m_context->vertexAttrib1f(indx, v0); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib1fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib1fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib1fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib1fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1) -{ - m_context->vertexAttrib2f(indx, v0, v1); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib2fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib2fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib2fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib2fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2) -{ - m_context->vertexAttrib3f(indx, v0, v1, v2); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib3fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib3fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib3fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib3fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3) -{ - m_context->vertexAttrib4f(indx, v0, v1, v2, v3); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib4fv(unsigned long indx, CanvasFloatArray* v) -{ - // FIXME: Need to make sure array is big enough for attribute being set - m_context->vertexAttrib4fv(indx, v->data()); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttrib4fv(unsigned long indx, float* v, int size) -{ - // FIXME: Need to make sure array is big enough for attribute being set - UNUSED_PARAM(size); - - m_context->vertexAttrib4fv(indx, v); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, unsigned long stride, unsigned long offset) -{ - m_context->vertexAttribPointer(indx, size, type, normalized, stride, offset); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::viewport(long x, long y, unsigned long width, unsigned long height) -{ - if (isnan(x)) - x = 0; - if (isnan(y)) - y = 0; - if (isnan(width)) - width = 100; - if (isnan(height)) - height = 100; - m_context->viewport(x, y, width, height); - cleanupAfterGraphicsCall(false); -} - -void CanvasRenderingContext3D::removeObject(CanvasObject* object) -{ - m_canvasObjects.remove(object); -} - -void CanvasRenderingContext3D::addObject(CanvasObject* object) -{ - removeObject(object); - m_canvasObjects.add(object); -} - -void CanvasRenderingContext3D::detachAndRemoveAllObjects() -{ - HashSet<CanvasObject*>::iterator pend = m_canvasObjects.end(); - for (HashSet<CanvasObject*>::iterator it = m_canvasObjects.begin(); it != pend; ++it) - (*it)->detachContext(); - - m_canvasObjects.clear(); -} - -} // namespace WebCore - -#endif // ENABLE(3D_CANVAS) - diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.h b/WebCore/html/canvas/CanvasRenderingContext3D.h deleted file mode 100644 index 70d9b95..0000000 --- a/WebCore/html/canvas/CanvasRenderingContext3D.h +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasRenderingContext3D_h -#define CanvasRenderingContext3D_h - -#include "CanvasRenderingContext.h" -#include "ExceptionCode.h" -#include "CanvasFloatArray.h" -#include "CanvasIntArray.h" -#include "CanvasUnsignedByteArray.h" -#include "GraphicsContext3D.h" -#include "PlatformString.h" - -namespace WebCore { - -class CanvasActiveInfo; -class CanvasBuffer; -class CanvasFramebuffer; -class CanvasObject; -class CanvasProgram; -class CanvasRenderbuffer; -class CanvasShader; -class CanvasTexture; -class HTMLImageElement; -class HTMLVideoElement; -class ImageData; -class WebKitCSSMatrix; - - class CanvasRenderingContext3D : public CanvasRenderingContext { - public: - static PassOwnPtr<CanvasRenderingContext3D> create(HTMLCanvasElement*); - virtual ~CanvasRenderingContext3D(); - - virtual bool is3d() const { return true; } - - // Helper to return the size in bytes of OpenGL data types - // like GL_FLOAT, GL_INT, etc. - int sizeInBytes(int type, ExceptionCode& ec); - - void activeTexture(unsigned long texture); - void attachShader(CanvasProgram*, CanvasShader*); - void bindAttribLocation(CanvasProgram*, unsigned long index, const String& name); - void bindBuffer(unsigned long target, CanvasBuffer*); - void bindFramebuffer(unsigned long target, CanvasFramebuffer*); - void bindRenderbuffer(unsigned long target, CanvasRenderbuffer*); - void bindTexture(unsigned long target, CanvasTexture*); - void blendColor(double red, double green, double blue, double alpha); - void blendEquation(unsigned long mode); - void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha); - void blendFunc(unsigned long sfactor, unsigned long dfactor); - void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha); - - void bufferData(unsigned long target, int size, unsigned long usage); - void bufferData(unsigned long target, CanvasArray* data, unsigned long usage); - void bufferSubData(unsigned long target, long offset, CanvasArray* data); - - unsigned long checkFramebufferStatus(unsigned long target); - void clear(unsigned long mask); - void clearColor(double red, double green, double blue, double alpha); - void clearDepth(double); - void clearStencil(long); - void colorMask(bool red, bool green, bool blue, bool alpha); - void compileShader(CanvasShader*); - - //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data); - //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data); - - void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border); - void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height); - - PassRefPtr<CanvasBuffer> createBuffer(); - PassRefPtr<CanvasFramebuffer> createFramebuffer(); - PassRefPtr<CanvasProgram> createProgram(); - PassRefPtr<CanvasRenderbuffer> createRenderbuffer(); - PassRefPtr<CanvasShader> createShader(unsigned long type); - PassRefPtr<CanvasTexture> createTexture(); - - void cullFace(unsigned long mode); - - void deleteBuffer(CanvasBuffer*); - void deleteFramebuffer(CanvasFramebuffer*); - void deleteProgram(CanvasProgram*); - void deleteRenderbuffer(CanvasRenderbuffer*); - void deleteShader(CanvasShader*); - void deleteTexture(CanvasTexture*); - - void depthFunc(unsigned long); - void depthMask(bool); - void depthRange(double zNear, double zFar); - void detachShader(CanvasProgram*, CanvasShader*); - void disable(unsigned long cap); - void disableVertexAttribArray(unsigned long index); - void drawArrays(unsigned long mode, long first, long count); - void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset); - - void enable(unsigned long cap); - void enableVertexAttribArray(unsigned long index); - void finish(); - void flush(); - void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, CanvasRenderbuffer*); - void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, CanvasTexture*, long level); - void frontFace(unsigned long mode); - void generateMipmap(unsigned long target); - - PassRefPtr<CanvasActiveInfo> getActiveAttrib(CanvasProgram*, unsigned long index, ExceptionCode&); - PassRefPtr<CanvasActiveInfo> getActiveUniform(CanvasProgram*, unsigned long index, ExceptionCode&); - - int getAttribLocation(CanvasProgram*, const String& name); - - bool getBoolean(unsigned long pname); - PassRefPtr<CanvasUnsignedByteArray> getBooleanv(unsigned long pname); - int getBufferParameteri(unsigned long target, unsigned long pname); - PassRefPtr<CanvasIntArray> getBufferParameteriv(unsigned long target, unsigned long pname); - - unsigned long getError(); - - float getFloat(unsigned long pname); - PassRefPtr<CanvasFloatArray> getFloatv(unsigned long pname); - int getFramebufferAttachmentParameteri(unsigned long target, unsigned long attachment, unsigned long pname); - PassRefPtr<CanvasIntArray> getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname); - int getInteger(unsigned long pname); - PassRefPtr<CanvasIntArray> getIntegerv(unsigned long pname); - int getProgrami(CanvasProgram*, unsigned long pname); - PassRefPtr<CanvasIntArray> getProgramiv(CanvasProgram*, unsigned long pname); - String getProgramInfoLog(CanvasProgram*); - int getRenderbufferParameteri(unsigned long target, unsigned long pname); - PassRefPtr<CanvasIntArray> getRenderbufferParameteriv(unsigned long target, unsigned long pname); - int getShaderi(CanvasShader*, unsigned long pname); - PassRefPtr<CanvasIntArray> getShaderiv(CanvasShader*, unsigned long pname); - - String getShaderInfoLog(CanvasShader*); - - // TBD - // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); - - String getShaderSource(CanvasShader*); - String getString(unsigned long name); - - float getTexParameterf(unsigned long target, unsigned long pname); - PassRefPtr<CanvasFloatArray> getTexParameterfv(unsigned long target, unsigned long pname); - int getTexParameteri(unsigned long target, unsigned long pname); - PassRefPtr<CanvasIntArray> getTexParameteriv(unsigned long target, unsigned long pname); - - float getUniformf(CanvasProgram* program, long location); - PassRefPtr<CanvasFloatArray> getUniformfv(CanvasProgram* program, long location); - long getUniformi(CanvasProgram* program, long location); - PassRefPtr<CanvasIntArray> getUniformiv(CanvasProgram* program, long location); - - long getUniformLocation(CanvasProgram*, const String& name); - - float getVertexAttribf(unsigned long index, unsigned long pname); - PassRefPtr<CanvasFloatArray> getVertexAttribfv(unsigned long index, unsigned long pname); - long getVertexAttribi(unsigned long index, unsigned long pname); - PassRefPtr<CanvasIntArray> getVertexAttribiv(unsigned long index, unsigned long pname); - - long getVertexAttribOffset(unsigned long index, unsigned long pname); - - void hint(unsigned long target, unsigned long mode); - bool isBuffer(CanvasBuffer*); - bool isEnabled(unsigned long cap); - bool isFramebuffer(CanvasFramebuffer*); - bool isProgram(CanvasProgram*); - bool isRenderbuffer(CanvasRenderbuffer*); - bool isShader(CanvasShader*); - bool isTexture(CanvasTexture*); - void lineWidth(double); - void linkProgram(CanvasProgram*); - void pixelStorei(unsigned long pname, long param); - void polygonOffset(double factor, double units); - - PassRefPtr<CanvasArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type); - - void releaseShaderCompiler(); - void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height); - void sampleCoverage(double value, bool invert); - void scissor(long x, long y, unsigned long width, unsigned long height); - void shaderSource(CanvasShader*, const String&); - void stencilFunc(unsigned long func, long ref, unsigned long mask); - void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask); - void stencilMask(unsigned long); - void stencilMaskSeparate(unsigned long face, unsigned long mask); - void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass); - void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass); - - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, unsigned internalformat, - unsigned width, unsigned height, unsigned border, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - - void texParameterf(unsigned target, unsigned pname, float param); - void texParameteri(unsigned target, unsigned pname, int param); - - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, CanvasArray* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, - unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLImageElement* image, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLCanvasElement* canvas, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, - unsigned width, unsigned height, HTMLVideoElement* video, - bool flipY, bool premultiplyAlpha, ExceptionCode&); - - void uniform1f(long location, float x); - void uniform1fv(long location, CanvasFloatArray* v); - void uniform1fv(long location, float* v, int size); - void uniform1i(long location, int x); - void uniform1iv(long location, CanvasIntArray* v); - void uniform1iv(long location, int* v, int size); - void uniform2f(long location, float x, float y); - void uniform2fv(long location, CanvasFloatArray* v); - void uniform2fv(long location, float* v, int size); - void uniform2i(long location, int x, int y); - void uniform2iv(long location, CanvasIntArray* v); - void uniform2iv(long location, int* v, int size); - void uniform3f(long location, float x, float y, float z); - void uniform3fv(long location, CanvasFloatArray* v); - void uniform3fv(long location, float* v, int size); - void uniform3i(long location, int x, int y, int z); - void uniform3iv(long location, CanvasIntArray* v); - void uniform3iv(long location, int* v, int size); - void uniform4f(long location, float x, float y, float z, float w); - void uniform4fv(long location, CanvasFloatArray* v); - void uniform4fv(long location, float* v, int size); - void uniform4i(long location, int x, int y, int z, int w); - void uniform4iv(long location, CanvasIntArray* v); - void uniform4iv(long location, int* v, int size); - void uniformMatrix2fv(long location, bool transpose, CanvasFloatArray* value); - void uniformMatrix2fv(long location, bool transpose, float* value, int size); - void uniformMatrix3fv(long location, bool transpose, CanvasFloatArray* value); - void uniformMatrix3fv(long location, bool transpose, float* value, int size); - void uniformMatrix4fv(long location, bool transpose, CanvasFloatArray* value); - void uniformMatrix4fv(long location, bool transpose, float* value, int size); - - void useProgram(CanvasProgram*); - void validateProgram(CanvasProgram*); - - void vertexAttrib1f(unsigned long indx, float x); - void vertexAttrib1fv(unsigned long indx, CanvasFloatArray* values); - void vertexAttrib1fv(unsigned long indx, float* values, int size); - void vertexAttrib2f(unsigned long indx, float x, float y); - void vertexAttrib2fv(unsigned long indx, CanvasFloatArray* values); - void vertexAttrib2fv(unsigned long indx, float* values, int size); - void vertexAttrib3f(unsigned long indx, float x, float y, float z); - void vertexAttrib3fv(unsigned long indx, CanvasFloatArray* values); - void vertexAttrib3fv(unsigned long indx, float* values, int size); - void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w); - void vertexAttrib4fv(unsigned long indx, CanvasFloatArray* values); - void vertexAttrib4fv(unsigned long indx, float* values, int size); - void vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, - unsigned long stride, unsigned long offset); - - void viewport(long x, long y, unsigned long width, unsigned long height); - - GraphicsContext3D* graphicsContext3D() const { return m_context.get(); } - - void reshape(int width, int height); - - // Helpers for notification about paint events. - void beginPaint(); - void endPaint(); - - void removeObject(CanvasObject*); - - private: - friend class CanvasObject; - - CanvasRenderingContext3D(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>); - - void addObject(CanvasObject*); - void detachAndRemoveAllObjects(); - - void markContextChanged(); - void cleanupAfterGraphicsCall(bool changed) - { - m_context->checkError(); - if (changed) - markContextChanged(); - } - - OwnPtr<GraphicsContext3D> m_context; - bool m_needsUpdate; - bool m_markedCanvasDirty; - // FIXME: I think this is broken -- it does not increment any - // reference counts, so may refer to destroyed objects. - HashSet<CanvasObject*> m_canvasObjects; - }; - -} // namespace WebCore - -#endif diff --git a/WebCore/html/canvas/CanvasShortArray.cpp b/WebCore/html/canvas/CanvasShortArray.cpp deleted file mode 100644 index d0cf135..0000000 --- a/WebCore/html/canvas/CanvasShortArray.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasArrayBuffer.h" -#include "CanvasShortArray.h" - -namespace WebCore { - - PassRefPtr<CanvasShortArray> CanvasShortArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(short)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasShortArray> CanvasShortArray::create(short* array, unsigned length) - { - RefPtr<CanvasShortArray> a = CanvasShortArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasShortArray> CanvasShortArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(short)) != 0) - return NULL; - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(short))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasShortArray(buffer, offset, length)); - } - - CanvasShortArray::CanvasShortArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasShortArray::length() const { - return m_size; - } - - unsigned CanvasShortArray::sizeInBytes() const { - return length() * sizeof(short); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasShortArray.h b/WebCore/html/canvas/CanvasShortArray.h deleted file mode 100644 index 1eeef0c..0000000 --- a/WebCore/html/canvas/CanvasShortArray.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasShortArray_h -#define CanvasShortArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasShortArray : public CanvasArray { - public: - virtual bool isShortArray() const { return true; } - - static PassRefPtr<CanvasShortArray> create(unsigned length); - static PassRefPtr<CanvasShortArray> create(short* array, unsigned length); - static PassRefPtr<CanvasShortArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - short* data() { return static_cast<short*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<short>::min()) - value = std::numeric_limits<short>::min(); - else if (value > std::numeric_limits<short>::max()) - value = std::numeric_limits<short>::max(); - short* storage = static_cast<short*>(m_baseAddress); - storage[index] = static_cast<short>(value); - } - - bool get(unsigned index, short& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - short item(unsigned index) const - { - ASSERT(index < m_size); - short* storage = static_cast<short*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasShortArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasShortArray_h diff --git a/WebCore/html/canvas/CanvasStyle.cpp b/WebCore/html/canvas/CanvasStyle.cpp index 946cac7..5352473 100644 --- a/WebCore/html/canvas/CanvasStyle.cpp +++ b/WebCore/html/canvas/CanvasStyle.cpp @@ -114,33 +114,33 @@ void CanvasStyle::applyStrokeColor(GraphicsContext* context) case ColorString: { Color c = Color(m_color); if (c.isValid()) { - context->setStrokeColor(c.rgb()); + context->setStrokeColor(c.rgb(), DeviceColorSpace); break; } RGBA32 color = 0; // default is transparent black if (CSSParser::parseColor(color, m_color)) - context->setStrokeColor(color); + context->setStrokeColor(color, DeviceColorSpace); break; } case ColorStringWithAlpha: { Color c = Color(m_color); if (c.isValid()) { - context->setStrokeColor(colorWithOverrideAlpha(c.rgb(), m_alpha)); + context->setStrokeColor(colorWithOverrideAlpha(c.rgb(), m_alpha), DeviceColorSpace); break; } RGBA32 color = 0; // default is transparent black if (CSSParser::parseColor(color, m_color)) - context->setStrokeColor(colorWithOverrideAlpha(color, m_alpha)); + context->setStrokeColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); break; } case GrayLevel: // We're only supporting 255 levels of gray here. Since this isn't // even part of HTML5, I don't expect anyone will care. If they do // we'll make a fancier Color abstraction. - context->setStrokeColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha)); + context->setStrokeColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); break; case RGBA: - context->setStrokeColor(Color(m_red, m_green, m_blue, m_alpha)); + context->setStrokeColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); break; case CMYKA: { // FIXME: Do this through platform-independent GraphicsContext API. @@ -154,7 +154,7 @@ void CanvasStyle::applyStrokeColor(GraphicsContext* context) currentPen.setColor(clr); context->platformContext()->setPen(currentPen); #else - context->setStrokeColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha)); + context->setStrokeColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace); #endif break; } @@ -175,33 +175,33 @@ void CanvasStyle::applyFillColor(GraphicsContext* context) case ColorString: { Color c = Color(m_color); if (c.isValid()) { - context->setFillColor(c.rgb()); + context->setFillColor(c.rgb(), DeviceColorSpace); break; } RGBA32 rgba = 0; // default is transparent black if (CSSParser::parseColor(rgba, m_color)) - context->setFillColor(rgba); + context->setFillColor(rgba, DeviceColorSpace); break; } case ColorStringWithAlpha: { Color c = Color(m_color); if (c.isValid()) { - context->setFillColor(colorWithOverrideAlpha(c.rgb(), m_alpha)); + context->setFillColor(colorWithOverrideAlpha(c.rgb(), m_alpha), DeviceColorSpace); break; } RGBA32 color = 0; // default is transparent black if (CSSParser::parseColor(color, m_color)) - context->setFillColor(colorWithOverrideAlpha(color, m_alpha)); + context->setFillColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); break; } case GrayLevel: // We're only supporting 255 levels of gray here. Since this isn't // even part of HTML5, I don't expect anyone will care. If they do // we'll make a fancier Color abstraction. - context->setFillColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha)); + context->setFillColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); break; case RGBA: - context->setFillColor(Color(m_red, m_green, m_blue, m_alpha)); + context->setFillColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); break; case CMYKA: { // FIXME: Do this through platform-independent GraphicsContext API. @@ -215,7 +215,7 @@ void CanvasStyle::applyFillColor(GraphicsContext* context) currentBrush.setColor(clr); context->platformContext()->setBrush(currentBrush); #else - context->setFillColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha)); + context->setFillColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace); #endif break; } diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.cpp b/WebCore/html/canvas/CanvasUnsignedByteArray.cpp deleted file mode 100644 index a75066c..0000000 --- a/WebCore/html/canvas/CanvasUnsignedByteArray.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasArrayBuffer.h" -#include "CanvasUnsignedByteArray.h" - -namespace WebCore { - - PassRefPtr<CanvasUnsignedByteArray> CanvasUnsignedByteArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(unsigned char)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasUnsignedByteArray> CanvasUnsignedByteArray::create(unsigned char* array, unsigned length) - { - RefPtr<CanvasUnsignedByteArray> a = CanvasUnsignedByteArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasUnsignedByteArray> CanvasUnsignedByteArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(unsigned char))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasUnsignedByteArray(buffer, offset, length)); - } - - CanvasUnsignedByteArray::CanvasUnsignedByteArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasUnsignedByteArray::length() const { - return m_size; - } - - unsigned CanvasUnsignedByteArray::sizeInBytes() const { - return length() * sizeof(unsigned char); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.h b/WebCore/html/canvas/CanvasUnsignedByteArray.h deleted file mode 100644 index d8864e0..0000000 --- a/WebCore/html/canvas/CanvasUnsignedByteArray.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasUnsignedByteArray_h -#define CanvasUnsignedByteArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasUnsignedByteArray : public CanvasArray { - public: - virtual bool isUnsignedByteArray() const { return true; } - - static PassRefPtr<CanvasUnsignedByteArray> create(unsigned length); - static PassRefPtr<CanvasUnsignedByteArray> create(unsigned char* array, unsigned length); - static PassRefPtr<CanvasUnsignedByteArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<unsigned char>::min()) - value = std::numeric_limits<unsigned char>::min(); - else if (value > std::numeric_limits<unsigned char>::max()) - value = std::numeric_limits<unsigned char>::max(); - unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); - storage[index] = static_cast<unsigned char>(value); - } - - bool get(unsigned index, unsigned char& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - unsigned char item(unsigned index) const - { - ASSERT(index < m_size); - unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasUnsignedByteArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasUnsignedByteArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.cpp b/WebCore/html/canvas/CanvasUnsignedIntArray.cpp deleted file mode 100644 index bd26343..0000000 --- a/WebCore/html/canvas/CanvasUnsignedIntArray.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasArrayBuffer.h" -#include "CanvasUnsignedIntArray.h" - -namespace WebCore { - - PassRefPtr<CanvasUnsignedIntArray> CanvasUnsignedIntArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(unsigned int)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasUnsignedIntArray> CanvasUnsignedIntArray::create(unsigned int* array, unsigned length) - { - RefPtr<CanvasUnsignedIntArray> a = CanvasUnsignedIntArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasUnsignedIntArray> CanvasUnsignedIntArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(unsigned int)) != 0) { - return NULL; - } - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(unsigned int))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasUnsignedIntArray(buffer, offset, length)); - } - - CanvasUnsignedIntArray::CanvasUnsignedIntArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasUnsignedIntArray::length() const { - return m_size; - } - - unsigned CanvasUnsignedIntArray::sizeInBytes() const { - return length() * sizeof(unsigned int); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.h b/WebCore/html/canvas/CanvasUnsignedIntArray.h deleted file mode 100644 index 10b8edf..0000000 --- a/WebCore/html/canvas/CanvasUnsignedIntArray.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasUnsignedIntArray_h -#define CanvasUnsignedIntArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasUnsignedIntArray : public CanvasArray { - public: - virtual bool isUnsignedIntArray() const { return true; } - - static PassRefPtr<CanvasUnsignedIntArray> create(unsigned length); - static PassRefPtr<CanvasUnsignedIntArray> create(unsigned int* array, unsigned length); - static PassRefPtr<CanvasUnsignedIntArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<unsigned int>::min()) - value = std::numeric_limits<unsigned int>::min(); - else if (value > std::numeric_limits<unsigned int>::max()) - value = std::numeric_limits<unsigned int>::max(); - unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); - storage[index] = static_cast<unsigned int>(value); - } - - bool get(unsigned index, unsigned int& result) const - { - if (index >= m_size) - return false; - result = item(index); - return true; - } - - unsigned int item(unsigned index) const - { - ASSERT(index < m_size); - unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasUnsignedIntArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasUnsignedIntArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.cpp b/WebCore/html/canvas/CanvasUnsignedShortArray.cpp deleted file mode 100644 index 45d827b..0000000 --- a/WebCore/html/canvas/CanvasUnsignedShortArray.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(3D_CANVAS) - -#include "CanvasArrayBuffer.h" -#include "CanvasUnsignedShortArray.h" - -namespace WebCore { - - PassRefPtr<CanvasUnsignedShortArray> CanvasUnsignedShortArray::create(unsigned length) - { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(unsigned short)); - return create(buffer, 0, length); - } - - PassRefPtr<CanvasUnsignedShortArray> CanvasUnsignedShortArray::create(unsigned short* array, unsigned length) - { - RefPtr<CanvasUnsignedShortArray> a = CanvasUnsignedShortArray::create(length); - for (unsigned i = 0; i < length; ++i) - a->set(i, array[i]); - return a; - } - - PassRefPtr<CanvasUnsignedShortArray> CanvasUnsignedShortArray::create(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - { - // Make sure the offset results in valid alignment. - if ((offset % sizeof(unsigned short)) != 0) { - return NULL; - } - - if (buffer) { - // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(unsigned short))) > buffer->byteLength()) - return NULL; - } - - return adoptRef(new CanvasUnsignedShortArray(buffer, offset, length)); - } - - CanvasUnsignedShortArray::CanvasUnsignedShortArray(PassRefPtr<CanvasArrayBuffer> buffer, - int offset, - unsigned length) - : CanvasArray(buffer, offset) - , m_size(length) - { - } - - unsigned CanvasUnsignedShortArray::length() const { - return m_size; - } - - unsigned CanvasUnsignedShortArray::sizeInBytes() const { - return length() * sizeof(unsigned short); - } -} - -#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.h b/WebCore/html/canvas/CanvasUnsignedShortArray.h deleted file mode 100644 index 9e27566..0000000 --- a/WebCore/html/canvas/CanvasUnsignedShortArray.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CanvasUnsignedShortArray_h -#define CanvasUnsignedShortArray_h - -#include "CanvasArray.h" -#include <limits> -#include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - - class CanvasUnsignedShortArray : public CanvasArray { - public: - virtual bool isUnsignedShortArray() const { return true; } - - static PassRefPtr<CanvasUnsignedShortArray> create(unsigned length); - static PassRefPtr<CanvasUnsignedShortArray> create(unsigned short* array, unsigned length); - static PassRefPtr<CanvasUnsignedShortArray> create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length); - - unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } - - virtual unsigned length() const; - virtual unsigned sizeInBytes() const; - - void set(unsigned index, double value) - { - if (index >= m_size) - return; - if (isnan(value)) // Clamp NaN to 0 - value = 0; - if (value < std::numeric_limits<unsigned short>::min()) - value = std::numeric_limits<unsigned short>::min(); - else if (value > std::numeric_limits<unsigned short>::max()) - value = std::numeric_limits<unsigned short>::max(); - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - storage[index] = static_cast<unsigned short>(value); - } - - bool get(unsigned index, unsigned short& result) const - { - if (index >= m_size) - return false; - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - result = storage[index]; - return true; - } - - unsigned short item(unsigned index) const - { - ASSERT(index < m_size); - unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); - return storage[index]; - } - - private: - CanvasUnsignedShortArray(PassRefPtr<CanvasArrayBuffer> buffer,int offset,unsigned length); - unsigned m_size; - }; - -} // namespace WebCore - -#endif // CanvasUnsignedShortArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedShortArray.idl b/WebCore/html/canvas/CanvasUnsignedShortArray.idl deleted file mode 100644 index 99fc6a2..0000000 --- a/WebCore/html/canvas/CanvasUnsignedShortArray.idl +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2009 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -module html { - interface [ - Conditional=3D_CANVAS, - HasNumericIndexGetter, - HasCustomIndexSetter, - GenerateNativeConverter, - GenerateCustomConstructor, - CustomToJS - ] CanvasUnsignedShortArray : CanvasArray { - }; -} diff --git a/WebCore/html/canvas/CanvasActiveInfo.h b/WebCore/html/canvas/WebGLActiveInfo.h index b04b0d0..4650ea1 100644 --- a/WebCore/html/canvas/CanvasActiveInfo.h +++ b/WebCore/html/canvas/WebGLActiveInfo.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasActiveInfo_h -#define CanvasActiveInfo_h +#ifndef WebGLActiveInfo_h +#define WebGLActiveInfo_h #include "PlatformString.h" #include <wtf/PassRefPtr.h> @@ -32,18 +32,18 @@ namespace WebCore { -class CanvasActiveInfo : public RefCounted<CanvasActiveInfo> { +class WebGLActiveInfo : public RefCounted<WebGLActiveInfo> { public: - static PassRefPtr<CanvasActiveInfo> create(const String& name, unsigned type, int size) + static PassRefPtr<WebGLActiveInfo> create(const String& name, unsigned type, int size) { - return adoptRef(new CanvasActiveInfo(name, type, size)); + return adoptRef(new WebGLActiveInfo(name, type, size)); } String name() const { return m_name; } unsigned type() const { return m_type; } int size() const { return m_size; } private: - CanvasActiveInfo(const String& name, unsigned type, int size) + WebGLActiveInfo(const String& name, unsigned type, int size) : m_name(name) , m_type(type) , m_size(size) @@ -59,4 +59,4 @@ private: } -#endif // CanvasActiveInfo_h +#endif // WebGLActiveInfo_h diff --git a/WebCore/html/canvas/CanvasActiveInfo.idl b/WebCore/html/canvas/WebGLActiveInfo.idl index 6ceae29..a3f79b8 100644 --- a/WebCore/html/canvas/CanvasActiveInfo.idl +++ b/WebCore/html/canvas/WebGLActiveInfo.idl @@ -27,7 +27,7 @@ module html { interface [ Conditional=3D_CANVAS, - ] CanvasActiveInfo { + ] WebGLActiveInfo { readonly attribute int size; readonly attribute unsigned int type; readonly attribute DOMString name; diff --git a/WebCore/html/canvas/CanvasArray.cpp b/WebCore/html/canvas/WebGLArray.cpp index 6b5688a..c5a712d 100644 --- a/WebCore/html/canvas/CanvasArray.cpp +++ b/WebCore/html/canvas/WebGLArray.cpp @@ -27,26 +27,34 @@ #if ENABLE(3D_CANVAS) -#include "CanvasArray.h" -#include "CanvasArrayBuffer.h" +#include "WebGLArray.h" +#include "WebGLArrayBuffer.h" namespace WebCore { - CanvasArray::CanvasArray(PassRefPtr<CanvasArrayBuffer> buffer, - unsigned offset) - : m_offset(offset) + +WebGLArray::WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, + unsigned byteOffset) + : m_byteOffset(byteOffset) , m_buffer(buffer) - { - m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_offset) : 0; - } +{ + m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_byteOffset) : 0; +} - CanvasArray::~CanvasArray() - { - } +WebGLArray::~WebGLArray() +{ +} - unsigned CanvasArray::alignedSizeInBytes() const { - // Assume we only need to round up to 4-byte boundaries for alignment. - return ((sizeInBytes() + 3) / 4) * 4; +void WebGLArray::setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec) +{ + if (byteOffset + array->byteLength() > byteLength()) { + ec = INDEX_SIZE_ERR; + return; } + + char* base = static_cast<char*>(baseAddress()); + memcpy(base + byteOffset, array->baseAddress(), array->byteLength()); +} + } #endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasArray.h b/WebCore/html/canvas/WebGLArray.h index 8cedbbe..11065cc 100644 --- a/WebCore/html/canvas/CanvasArray.h +++ b/WebCore/html/canvas/WebGLArray.h @@ -23,53 +23,59 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasArray_h -#define CanvasArray_h +#ifndef WebGLArray_h +#define WebGLArray_h +#include "ExceptionCode.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> -#include "CanvasArrayBuffer.h" +#include "WebGLArrayBuffer.h" namespace WebCore { - class CanvasArray : public RefCounted<CanvasArray> { - public: - virtual bool isByteArray() const { return false; } - virtual bool isUnsignedByteArray() const { return false; } - virtual bool isShortArray() const { return false; } - virtual bool isUnsignedShortArray() const { return false; } - virtual bool isIntArray() const { return false; } - virtual bool isUnsignedIntArray() const { return false; } - virtual bool isFloatArray() const { return false; } - - PassRefPtr<CanvasArrayBuffer> buffer() { - return m_buffer; - } - - void* baseAddress() { - return m_baseAddress; - } - - unsigned offset() const { - return m_offset; - } - - virtual unsigned length() const = 0; - virtual unsigned sizeInBytes() const = 0; - virtual unsigned alignedSizeInBytes() const; - virtual ~CanvasArray(); - - protected: - CanvasArray(PassRefPtr<CanvasArrayBuffer> buffer, unsigned offset); - - // This is the address of the CanvasArrayBuffer's storage, plus the offset. - void* m_baseAddress; - unsigned m_offset; - - private: - RefPtr<CanvasArrayBuffer> m_buffer; - }; - + +class WebGLArray : public RefCounted<WebGLArray> { + public: + virtual bool isByteArray() const { return false; } + virtual bool isUnsignedByteArray() const { return false; } + virtual bool isShortArray() const { return false; } + virtual bool isUnsignedShortArray() const { return false; } + virtual bool isIntArray() const { return false; } + virtual bool isUnsignedIntArray() const { return false; } + virtual bool isFloatArray() const { return false; } + + PassRefPtr<WebGLArrayBuffer> buffer() { + return m_buffer; + } + + void* baseAddress() { + return m_baseAddress; + } + + unsigned byteOffset() const { + return m_byteOffset; + } + + virtual unsigned length() const = 0; + virtual unsigned byteLength() const = 0; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length) = 0; + + virtual ~WebGLArray(); + + protected: + WebGLArray(PassRefPtr<WebGLArrayBuffer> buffer, unsigned byteOffset); + + void setImpl(WebGLArray* array, unsigned byteOffset, ExceptionCode& ec); + + // This is the address of the WebGLArrayBuffer's storage, plus the byte offset. + void* m_baseAddress; + + unsigned m_byteOffset; + + private: + RefPtr<WebGLArrayBuffer> m_buffer; +}; + } // namespace WebCore -#endif // CanvasArray_h +#endif // WebGLArray_h diff --git a/WebCore/html/canvas/CanvasByteArray.idl b/WebCore/html/canvas/WebGLArray.idl index ccf49ad..156ca5b 100644 --- a/WebCore/html/canvas/CanvasByteArray.idl +++ b/WebCore/html/canvas/WebGLArray.idl @@ -24,13 +24,12 @@ */ module html { - interface [ - Conditional=3D_CANVAS, - HasNumericIndexGetter, - HasCustomIndexSetter, - GenerateNativeConverter, - GenerateCustomConstructor, - CustomToJS - ] CanvasByteArray : CanvasArray { + interface [Conditional=3D_CANVAS, CustomToJS] WebGLArray { + readonly attribute WebGLArrayBuffer buffer; + readonly attribute unsigned long byteOffset; + readonly attribute unsigned long byteLength; + readonly attribute unsigned long length; + + WebGLArray slice(in unsigned long offset, in unsigned long length); }; } diff --git a/WebCore/html/canvas/WebGLArrayBuffer.cpp b/WebCore/html/canvas/WebGLArrayBuffer.cpp new file mode 100644 index 0000000..c565691 --- /dev/null +++ b/WebCore/html/canvas/WebGLArrayBuffer.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLArrayBuffer.h" + +#include <wtf/RefPtr.h> + +namespace WebCore { + +PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(unsigned sizeInBytes) +{ + return adoptRef(new WebGLArrayBuffer(sizeInBytes)); +} + +PassRefPtr<WebGLArrayBuffer> WebGLArrayBuffer::create(WebGLArrayBuffer* other) +{ + RefPtr<WebGLArrayBuffer> buffer = adoptRef(new WebGLArrayBuffer(other->byteLength())); + memcpy(buffer->data(), other->data(), other->byteLength()); + return buffer.release(); +} + +WebGLArrayBuffer::WebGLArrayBuffer(unsigned sizeInBytes) { + m_sizeInBytes = sizeInBytes; + m_data = WTF::fastZeroedMalloc(sizeInBytes); +} + +void* WebGLArrayBuffer::data() { + return m_data; +} + +const void* WebGLArrayBuffer::data() const { + return m_data; +} + +unsigned WebGLArrayBuffer::byteLength() const { + return m_sizeInBytes; +} + +WebGLArrayBuffer::~WebGLArrayBuffer() { + WTF::fastFree(m_data); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/CanvasArrayBuffer.h b/WebCore/html/canvas/WebGLArrayBuffer.h index e3ff2b0..a076e16 100644 --- a/WebCore/html/canvas/CanvasArrayBuffer.h +++ b/WebCore/html/canvas/WebGLArrayBuffer.h @@ -23,29 +23,31 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasArrayBuffer_h -#define CanvasArrayBuffer_h +#ifndef WebGLArrayBuffer_h +#define WebGLArrayBuffer_h #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class CanvasArrayBuffer : public RefCounted<CanvasArrayBuffer> { - public: - static PassRefPtr<CanvasArrayBuffer> create(unsigned sizeInBytes); - - void* data(); - unsigned byteLength() const; - - ~CanvasArrayBuffer(); - - private: - CanvasArrayBuffer(unsigned sizeInBytes); - unsigned m_sizeInBytes; - void* m_data; - }; - + +class WebGLArrayBuffer : public RefCounted<WebGLArrayBuffer> { + public: + static PassRefPtr<WebGLArrayBuffer> create(unsigned sizeInBytes); + static PassRefPtr<WebGLArrayBuffer> create(WebGLArrayBuffer*); + + void* data(); + const void* data() const; + unsigned byteLength() const; + + ~WebGLArrayBuffer(); + + private: + WebGLArrayBuffer(unsigned sizeInBytes); + unsigned m_sizeInBytes; + void* m_data; +}; + } // namespace WebCore -#endif // CanvasArrayBuffer_h +#endif // WebGLArrayBuffer_h diff --git a/WebCore/html/canvas/CanvasArrayBuffer.idl b/WebCore/html/canvas/WebGLArrayBuffer.idl index 5dc0f7f..ec4a67a 100644 --- a/WebCore/html/canvas/CanvasArrayBuffer.idl +++ b/WebCore/html/canvas/WebGLArrayBuffer.idl @@ -24,7 +24,7 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasArrayBuffer { + interface [Conditional=3D_CANVAS] WebGLArrayBuffer { readonly attribute int byteLength; }; } diff --git a/WebCore/html/canvas/WebGLBuffer.cpp b/WebCore/html/canvas/WebGLBuffer.cpp new file mode 100644 index 0000000..cbad6a0 --- /dev/null +++ b/WebCore/html/canvas/WebGLBuffer.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLBuffer.h" +#include "WebGLRenderingContext.h" + +namespace WebCore { + +PassRefPtr<WebGLBuffer> WebGLBuffer::create(WebGLRenderingContext* ctx) +{ + return adoptRef(new WebGLBuffer(ctx)); +} + +PassRefPtr<WebGLBuffer> WebGLBuffer::create(WebGLRenderingContext* ctx, Platform3DObject obj) +{ + return adoptRef(new WebGLBuffer(ctx, obj)); +} + +WebGLBuffer::WebGLBuffer(WebGLRenderingContext* ctx) + : CanvasObject(ctx) + , m_elementArrayBufferByteLength(0) + , m_arrayBufferByteLength(0) + , m_elementArrayBufferCloned(false) +{ + setObject(context()->graphicsContext3D()->createBuffer()); +} + +WebGLBuffer::WebGLBuffer(WebGLRenderingContext* ctx, Platform3DObject obj) + : CanvasObject(ctx) +{ + setObject(obj, false); +} + +void WebGLBuffer::_deleteObject(Platform3DObject object) +{ + context()->graphicsContext3D()->deleteBuffer(object); +} + +bool WebGLBuffer::associateBufferData(unsigned long target, int size) +{ + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + m_elementArrayBufferByteLength = size; + return true; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) { + m_arrayBufferByteLength = size; + return true; + } + + return false; +} + +bool WebGLBuffer::associateBufferData(unsigned long target, WebGLArray* array) +{ + if (!array) + return false; + + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + m_elementArrayBufferByteLength = array->byteLength(); + m_elementArrayBuffer = array->buffer(); + m_elementArrayBufferCloned = false; + return true; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) { + m_arrayBufferByteLength = array->byteLength(); + return true; + } + + return false; +} + +bool WebGLBuffer::associateBufferSubData(unsigned long target, long offset, WebGLArray* array) +{ + if (!array) + return false; + + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + // We need to protect against integer overflow with these tests + if (offset < 0) + return false; + + unsigned long uoffset = static_cast<unsigned long>(offset); + if (uoffset > m_elementArrayBufferByteLength || array->byteLength() > m_elementArrayBufferByteLength - uoffset) + return false; + + // If we already have a buffer, we need to clone it and add the new data + if (m_elementArrayBuffer && !m_elementArrayBufferCloned) { + m_elementArrayBuffer = WebGLArrayBuffer::create(m_elementArrayBuffer.get()); + m_elementArrayBufferCloned = true; + } + + memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()) + offset, array->baseAddress(), array->byteLength()); + return true; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) + return array->byteLength() + offset <= m_arrayBufferByteLength; + + return false; +} + +unsigned WebGLBuffer::byteLength(unsigned long target) const +{ + return (target == GraphicsContext3D::ARRAY_BUFFER) ? m_arrayBufferByteLength : m_elementArrayBufferByteLength; +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLBuffer.h b/WebCore/html/canvas/WebGLBuffer.h new file mode 100644 index 0000000..cb953c6 --- /dev/null +++ b/WebCore/html/canvas/WebGLBuffer.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLBuffer_h +#define WebGLBuffer_h + +#include "CanvasObject.h" +#include "WebGLArrayBuffer.h" + +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + + class WebGLBuffer : public CanvasObject { + public: + virtual ~WebGLBuffer() { deleteObject(); } + + static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*); + + // For querying previously created objects via e.g. getFramebufferAttachmentParameter + // FIXME: should consider canonicalizing these objects + static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*, Platform3DObject); + + bool associateBufferData(unsigned long target, int size); + bool associateBufferData(unsigned long target, WebGLArray* array); + bool associateBufferSubData(unsigned long target, long offset, WebGLArray* array); + + unsigned byteLength(unsigned long target) const; + const WebGLArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); } + + protected: + WebGLBuffer(WebGLRenderingContext*); + WebGLBuffer(WebGLRenderingContext*, Platform3DObject obj); + + virtual void _deleteObject(Platform3DObject o); + + private: + RefPtr<WebGLArrayBuffer> m_elementArrayBuffer; + unsigned m_elementArrayBufferByteLength; + unsigned m_arrayBufferByteLength; + bool m_elementArrayBufferCloned; + }; + +} // namespace WebCore + +#endif // WebGLBuffer_h diff --git a/WebCore/html/canvas/CanvasBuffer.idl b/WebCore/html/canvas/WebGLBuffer.idl index 9bca42b..30b7606 100644 --- a/WebCore/html/canvas/CanvasBuffer.idl +++ b/WebCore/html/canvas/WebGLBuffer.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasBuffer { + interface [Conditional=3D_CANVAS] WebGLBuffer { }; } diff --git a/WebCore/html/canvas/CanvasByteArray.cpp b/WebCore/html/canvas/WebGLByteArray.cpp index 0f72ccf..1c2849b 100644 --- a/WebCore/html/canvas/CanvasByteArray.cpp +++ b/WebCore/html/canvas/WebGLByteArray.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,49 +28,64 @@ #if ENABLE(3D_CANVAS) -#include "CanvasArrayBuffer.h" -#include "CanvasByteArray.h" +#include "WebGLArrayBuffer.h" +#include "WebGLByteArray.h" namespace WebCore { - -PassRefPtr<CanvasByteArray> CanvasByteArray::create(unsigned length) + +PassRefPtr<WebGLByteArray> WebGLByteArray::create(unsigned length) { - RefPtr<CanvasArrayBuffer> buffer = CanvasArrayBuffer::create(length * sizeof(signed char)); + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(signed char)); return create(buffer, 0, length); } -PassRefPtr<CanvasByteArray> CanvasByteArray::create(signed char* array, unsigned length) +PassRefPtr<WebGLByteArray> WebGLByteArray::create(signed char* array, unsigned length) { - RefPtr<CanvasByteArray> a = CanvasByteArray::create(length); + RefPtr<WebGLByteArray> a = WebGLByteArray::create(length); for (unsigned i = 0; i < length; ++i) a->set(i, array[i]); return a; } -PassRefPtr<CanvasByteArray> CanvasByteArray::create(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) +PassRefPtr<WebGLByteArray> WebGLByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) { if (buffer) { // Check to make sure we are talking about a valid region of - // the given CanvasArrayBuffer's storage. - if ((offset + (length * sizeof(signed char))) > buffer->byteLength()) + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(signed char))) > buffer->byteLength()) return NULL; } - - return adoptRef(new CanvasByteArray(buffer, offset, length)); + + return adoptRef(new WebGLByteArray(buffer, byteOffset, length)); } -CanvasByteArray::CanvasByteArray(PassRefPtr<CanvasArrayBuffer> buffer, int offset, unsigned length) - : CanvasArray(buffer, offset) +WebGLByteArray::WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int offset, unsigned length) + : WebGLArray(buffer, offset) , m_size(length) { } -unsigned CanvasByteArray::length() const { +unsigned WebGLByteArray::length() const { return m_size; } - -unsigned CanvasByteArray::sizeInBytes() const { - return length() * sizeof(signed char); + +unsigned WebGLByteArray::byteLength() const { + return m_size * sizeof(signed char); +} + +PassRefPtr<WebGLArray> WebGLByteArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(signed char); + unsigned limitByte = startByte + length * sizeof(signed char); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLByteArray::set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(signed char), ec); } } diff --git a/WebCore/html/canvas/WebGLByteArray.h b/WebCore/html/canvas/WebGLByteArray.h new file mode 100644 index 0000000..c517c03 --- /dev/null +++ b/WebCore/html/canvas/WebGLByteArray.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLByteArray_h +#define WebGLByteArray_h + +#include "WebGLArray.h" +#include <limits> +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLArrayBuffer; + +class WebGLByteArray : public WebGLArray { + public: + virtual bool isByteArray() const { return true; } + + static PassRefPtr<WebGLByteArray> create(unsigned length); + static PassRefPtr<WebGLByteArray> create(signed char* array, unsigned length); + static PassRefPtr<WebGLByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + char* data() { return static_cast<char*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<signed char>::min()) + value = std::numeric_limits<signed char>::min(); + else if (value > std::numeric_limits<signed char>::max()) + value = std::numeric_limits<signed char>::max(); + signed char* storage = static_cast<signed char*>(m_baseAddress); + storage[index] = static_cast<signed char>(value); + } + + bool get(unsigned index, signed char& result) const + { + if (index >= m_size) + return false; + signed char* storage = static_cast<signed char*>(m_baseAddress); + result = storage[index]; + return true; + } + + signed char get(unsigned index) const + { + return item(index); + } + + signed char item(unsigned index) const + { + ASSERT(index < m_size); + signed char* storage = static_cast<signed char*>(m_baseAddress); + return storage[index]; + } + + void set(WebGLByteArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLByteArray(PassRefPtr<WebGLArrayBuffer> buffer, + int offset, + unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLByteArray_h diff --git a/WebCore/html/canvas/CanvasIntArray.idl b/WebCore/html/canvas/WebGLByteArray.idl index 2c81b87..054a912 100644 --- a/WebCore/html/canvas/CanvasIntArray.idl +++ b/WebCore/html/canvas/WebGLByteArray.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasIntArray : CanvasArray { + ] WebGLByteArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLByteArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/WebGLFloatArray.cpp b/WebCore/html/canvas/WebGLFloatArray.cpp new file mode 100644 index 0000000..6192898 --- /dev/null +++ b/WebCore/html/canvas/WebGLFloatArray.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLFloatArray.h" + +namespace WebCore { + +PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(unsigned length) +{ + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(float)); + return create(buffer, 0, length); +} + +PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(float* array, unsigned length) +{ + RefPtr<WebGLFloatArray> a = WebGLFloatArray::create(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; +} + +PassRefPtr<WebGLFloatArray> WebGLFloatArray::create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(float)) != 0) + return NULL; + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(float))) > buffer->byteLength()) + return NULL; + } + return adoptRef(new WebGLFloatArray(buffer, byteOffset, length)); +} + +WebGLFloatArray::WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) + : WebGLArray(buffer, byteOffset) + , m_size(length) +{ +} + +unsigned WebGLFloatArray::length() const { + return m_size; +} + +unsigned WebGLFloatArray::byteLength() const { + return m_size * sizeof(float); +} + +PassRefPtr<WebGLArray> WebGLFloatArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(float); + unsigned limitByte = startByte + length * sizeof(float); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLFloatArray::set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(float), ec); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLFloatArray.h b/WebCore/html/canvas/WebGLFloatArray.h new file mode 100644 index 0000000..4607962 --- /dev/null +++ b/WebCore/html/canvas/WebGLFloatArray.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLFloatArray_h +#define WebGLFloatArray_h + +#include "WebGLArray.h" +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLFloatArray : public WebGLArray { + public: + virtual bool isFloatArray() const { return true; } + + static PassRefPtr<WebGLFloatArray> create(unsigned length); + static PassRefPtr<WebGLFloatArray> create(float* array, unsigned length); + static PassRefPtr<WebGLFloatArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + float* data() { return static_cast<float*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + float* storage = static_cast<float*>(m_baseAddress); + storage[index] = static_cast<float>(value); + } + + bool get(unsigned index, float& result) const + { + if (index >= m_size) + return false; + result = item(index); + return true; + } + + float get(unsigned index) const + { + return item(index); + } + + float item(unsigned index) const + { + ASSERT(index < m_size); + float* storage = static_cast<float*>(m_baseAddress); + float result = storage[index]; + if (isnan(result)) { + // Clamp NaN to 0 + result = 0; + } + return result; + } + + void set(WebGLFloatArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLFloatArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLFloatArray_h diff --git a/WebCore/html/canvas/CanvasShortArray.idl b/WebCore/html/canvas/WebGLFloatArray.idl index 6d64e1c..83479b3 100644 --- a/WebCore/html/canvas/CanvasShortArray.idl +++ b/WebCore/html/canvas/WebGLFloatArray.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasShortArray : CanvasArray { + ] WebGLFloatArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLFloatArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/CanvasFramebuffer.cpp b/WebCore/html/canvas/WebGLFramebuffer.cpp index 9700354..7ade990 100644 --- a/WebCore/html/canvas/CanvasFramebuffer.cpp +++ b/WebCore/html/canvas/WebGLFramebuffer.cpp @@ -27,23 +27,23 @@ #if ENABLE(3D_CANVAS) -#include "CanvasFramebuffer.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLFramebuffer.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasFramebuffer> CanvasFramebuffer::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasFramebuffer(ctx)); + return adoptRef(new WebGLFramebuffer(ctx)); } -CanvasFramebuffer::CanvasFramebuffer(CanvasRenderingContext3D* ctx) +WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createFramebuffer()); } -void CanvasFramebuffer::_deleteObject(Platform3DObject object) +void WebGLFramebuffer::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteFramebuffer(object); } diff --git a/WebCore/html/canvas/CanvasFramebuffer.h b/WebCore/html/canvas/WebGLFramebuffer.h index ec3cb97..10b6772 100644 --- a/WebCore/html/canvas/CanvasFramebuffer.h +++ b/WebCore/html/canvas/WebGLFramebuffer.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasFramebuffer_h -#define CanvasFramebuffer_h +#ifndef WebGLFramebuffer_h +#define WebGLFramebuffer_h #include "CanvasObject.h" @@ -33,18 +33,18 @@ namespace WebCore { - class CanvasFramebuffer : public CanvasObject { + class WebGLFramebuffer : public CanvasObject { public: - virtual ~CanvasFramebuffer() { deleteObject(); } + virtual ~WebGLFramebuffer() { deleteObject(); } - static PassRefPtr<CanvasFramebuffer> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*); protected: - CanvasFramebuffer(CanvasRenderingContext3D*); + WebGLFramebuffer(WebGLRenderingContext*); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasFramebuffer_h +#endif // WebGLFramebuffer_h diff --git a/WebCore/html/canvas/WebGLFramebuffer.idl b/WebCore/html/canvas/WebGLFramebuffer.idl new file mode 100644 index 0000000..8c1d9fd --- /dev/null +++ b/WebCore/html/canvas/WebGLFramebuffer.idl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module html { + interface [Conditional=3D_CANVAS] WebGLFramebuffer { + }; +} diff --git a/WebCore/html/canvas/WebGLGetInfo.cpp b/WebCore/html/canvas/WebGLGetInfo.cpp new file mode 100644 index 0000000..96218e5 --- /dev/null +++ b/WebCore/html/canvas/WebGLGetInfo.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * Copyright (C) 2009 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLGetInfo.h" +#include "WebGLBuffer.h" +#include "WebGLFloatArray.h" +#include "WebGLFramebuffer.h" +#include "WebGLIntArray.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" +#include "WebGLUnsignedByteArray.h" + +namespace WebCore { + +WebGLGetInfo::WebGLGetInfo(bool value) + : m_type(kTypeBool) + , m_bool(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(float value) + : m_type(kTypeFloat) + , m_float(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(long value) + : m_type(kTypeLong) + , m_long(value) +{ +} + +WebGLGetInfo::WebGLGetInfo() + : m_type(kTypeNull) +{ +} + +WebGLGetInfo::WebGLGetInfo(const String& value) + : m_type(kTypeString) + , m_string(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(unsigned long value) + : m_type(kTypeUnsignedLong) + , m_unsignedLong(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLBuffer> value) + : m_type(kTypeWebGLBuffer) + , m_webglBuffer(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLFloatArray> value) + : m_type(kTypeWebGLFloatArray) + , m_webglFloatArray(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLFramebuffer> value) + : m_type(kTypeWebGLFramebuffer) + , m_webglFramebuffer(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLIntArray> value) + : m_type(kTypeWebGLIntArray) + , m_webglIntArray(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLProgram> value) + : m_type(kTypeWebGLProgram) + , m_webglProgram(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLRenderbuffer> value) + : m_type(kTypeWebGLRenderbuffer) + , m_webglRenderbuffer(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLTexture> value) + : m_type(kTypeWebGLTexture) + , m_webglTexture(value) +{ +} + +WebGLGetInfo::WebGLGetInfo(PassRefPtr<WebGLUnsignedByteArray> value) + : m_type(kTypeWebGLUnsignedByteArray) + , m_webglUnsignedByteArray(value) +{ +} + +WebGLGetInfo::~WebGLGetInfo() +{ +} + +WebGLGetInfo::Type WebGLGetInfo::getType() const +{ + return m_type; +} + +bool WebGLGetInfo::getBool() const +{ + ASSERT(getType() == kTypeBool); + return m_bool; +} + +float WebGLGetInfo::getFloat() const +{ + ASSERT(getType() == kTypeFloat); + return m_float; +} + +long WebGLGetInfo::getLong() const +{ + ASSERT(getType() == kTypeLong); + return m_long; +} + +const String& WebGLGetInfo::getString() const +{ + ASSERT(getType() == kTypeString); + return m_string; +} + +unsigned long WebGLGetInfo::getUnsignedLong() const +{ + ASSERT(getType() == kTypeUnsignedLong); + return m_unsignedLong; +} + +PassRefPtr<WebGLBuffer> WebGLGetInfo::getWebGLBuffer() const +{ + ASSERT(getType() == kTypeWebGLBuffer); + return m_webglBuffer; +} + +PassRefPtr<WebGLFloatArray> WebGLGetInfo::getWebGLFloatArray() const +{ + ASSERT(getType() == kTypeWebGLFloatArray); + return m_webglFloatArray; +} + +PassRefPtr<WebGLFramebuffer> WebGLGetInfo::getWebGLFramebuffer() const +{ + ASSERT(getType() == kTypeWebGLFramebuffer); + return m_webglFramebuffer; +} + +PassRefPtr<WebGLIntArray> WebGLGetInfo::getWebGLIntArray() const +{ + ASSERT(getType() == kTypeWebGLIntArray); + return m_webglIntArray; +} + +PassRefPtr<WebGLProgram> WebGLGetInfo::getWebGLProgram() const +{ + ASSERT(getType() == kTypeWebGLProgram); + return m_webglProgram; +} + +PassRefPtr<WebGLRenderbuffer> WebGLGetInfo::getWebGLRenderbuffer() const +{ + ASSERT(getType() == kTypeWebGLRenderbuffer); + return m_webglRenderbuffer; +} + +PassRefPtr<WebGLTexture> WebGLGetInfo::getWebGLTexture() const +{ + ASSERT(getType() == kTypeWebGLTexture); + return m_webglTexture; +} + +PassRefPtr<WebGLUnsignedByteArray> WebGLGetInfo::getWebGLUnsignedByteArray() const +{ + ASSERT(getType() == kTypeWebGLUnsignedByteArray); + return m_webglUnsignedByteArray; +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLGetInfo.h b/WebCore/html/canvas/WebGLGetInfo.h new file mode 100644 index 0000000..8ac42c4 --- /dev/null +++ b/WebCore/html/canvas/WebGLGetInfo.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * Copyright (C) 2009 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLGetInfo_h +#define WebGLGetInfo_h + +#include "wtf/PassRefPtr.h" +#include "wtf/RefPtr.h" +#include "PlatformString.h" + +#include "WebGLBuffer.h" +#include "WebGLFloatArray.h" +#include "WebGLFramebuffer.h" +#include "WebGLIntArray.h" +// FIXME: implement WebGLObjectArray +//#include "WebGLObjectArray.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" +#include "WebGLUnsignedByteArray.h" + +namespace WebCore { + +// A tagged union representing the result of get queries like +// getParameter (encompassing getBooleanv, getIntegerv, getFloatv) and +// similar variants. For reference counted types, increments and +// decrements the reference count of the target object. + +class WebGLGetInfo { +public: + enum Type { + kTypeBool, + kTypeFloat, + kTypeLong, + kTypeNull, + kTypeString, + kTypeUnsignedLong, + kTypeWebGLBuffer, + kTypeWebGLFloatArray, + kTypeWebGLFramebuffer, + kTypeWebGLIntArray, + kTypeWebGLObjectArray, + kTypeWebGLProgram, + kTypeWebGLRenderbuffer, + kTypeWebGLTexture, + kTypeWebGLUnsignedByteArray + }; + + WebGLGetInfo(bool value); + WebGLGetInfo(float value); + WebGLGetInfo(long value); + // Represents the NULL value and type + WebGLGetInfo(); + WebGLGetInfo(const String& value); + WebGLGetInfo(unsigned long value); + WebGLGetInfo(PassRefPtr<WebGLBuffer> value); + WebGLGetInfo(PassRefPtr<WebGLFloatArray> value); + WebGLGetInfo(PassRefPtr<WebGLFramebuffer> value); + WebGLGetInfo(PassRefPtr<WebGLIntArray> value); + // FIXME: implement WebGLObjectArray + // WebGLGetInfo(PassRefPtr<WebGLObjectArray> value); + WebGLGetInfo(PassRefPtr<WebGLProgram> value); + WebGLGetInfo(PassRefPtr<WebGLRenderbuffer> value); + WebGLGetInfo(PassRefPtr<WebGLTexture> value); + WebGLGetInfo(PassRefPtr<WebGLUnsignedByteArray> value); + + virtual ~WebGLGetInfo(); + + Type getType() const; + + bool getBool() const; + float getFloat() const; + long getLong() const; + const String& getString() const; + unsigned long getUnsignedLong() const; + PassRefPtr<WebGLBuffer> getWebGLBuffer() const; + PassRefPtr<WebGLFloatArray> getWebGLFloatArray() const; + PassRefPtr<WebGLFramebuffer> getWebGLFramebuffer() const; + PassRefPtr<WebGLIntArray> getWebGLIntArray() const; + // FIXME: implement WebGLObjectArray + // PassRefPtr<WebGLObjectArray> getWebGLObjectArray() const; + PassRefPtr<WebGLProgram> getWebGLProgram() const; + PassRefPtr<WebGLRenderbuffer> getWebGLRenderbuffer() const; + PassRefPtr<WebGLTexture> getWebGLTexture() const; + PassRefPtr<WebGLUnsignedByteArray> getWebGLUnsignedByteArray() const; + +private: + Type m_type; + bool m_bool; + float m_float; + long m_long; + String m_string; + unsigned long m_unsignedLong; + RefPtr<WebGLBuffer> m_webglBuffer; + RefPtr<WebGLFloatArray> m_webglFloatArray; + RefPtr<WebGLFramebuffer> m_webglFramebuffer; + RefPtr<WebGLIntArray> m_webglIntArray; + // FIXME: implement WebGLObjectArray + // RefPtr<WebGLObjectArray> m_webglObjectArray; + RefPtr<WebGLProgram> m_webglProgram; + RefPtr<WebGLRenderbuffer> m_webglRenderbuffer; + RefPtr<WebGLTexture> m_webglTexture; + RefPtr<WebGLUnsignedByteArray> m_webglUnsignedByteArray; +}; + +} // namespace WebCore + +#endif // WebGLGetInfo_h diff --git a/WebCore/html/canvas/WebGLIntArray.cpp b/WebCore/html/canvas/WebGLIntArray.cpp new file mode 100644 index 0000000..4617010 --- /dev/null +++ b/WebCore/html/canvas/WebGLIntArray.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLArrayBuffer.h" +#include "WebGLIntArray.h" + +namespace WebCore { + +PassRefPtr<WebGLIntArray> WebGLIntArray::create(unsigned length) +{ + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(int)); + return create(buffer, 0, length); +} + +PassRefPtr<WebGLIntArray> WebGLIntArray::create(int* array, unsigned length) +{ + RefPtr<WebGLIntArray> a = WebGLIntArray::create(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; +} + +PassRefPtr<WebGLIntArray> WebGLIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(int)) != 0) + return NULL; + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(int))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLIntArray(buffer, byteOffset, length)); +} + +WebGLIntArray::WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) + : WebGLArray(buffer, byteOffset) + , m_size(length) +{ +} + +unsigned WebGLIntArray::length() const { + return m_size; +} + +unsigned WebGLIntArray::byteLength() const { + return m_size * sizeof(int); +} + +PassRefPtr<WebGLArray> WebGLIntArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(int); + unsigned limitByte = startByte + length * sizeof(int); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLIntArray::set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(int), ec); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLIntArray.h b/WebCore/html/canvas/WebGLIntArray.h new file mode 100644 index 0000000..25108ac --- /dev/null +++ b/WebCore/html/canvas/WebGLIntArray.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLIntArray_h +#define WebGLIntArray_h + +#include "WebGLArray.h" +#include <limits> +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLIntArray : public WebGLArray { + public: + virtual bool isIntArray() const { return true; } + + static PassRefPtr<WebGLIntArray> create(unsigned length); + static PassRefPtr<WebGLIntArray> create(int* array, unsigned length); + static PassRefPtr<WebGLIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + int* data() { return static_cast<int*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<int>::min()) + value = std::numeric_limits<int>::min(); + else if (value > std::numeric_limits<int>::max()) + value = std::numeric_limits<int>::max(); + int* storage = static_cast<int*>(m_baseAddress); + storage[index] = static_cast<int>(value); + } + + bool get(unsigned index, int& result) const + { + if (index >= m_size) + return false; + result = item(index); + return true; + } + + int get(unsigned index) const + { + return item(index); + } + + int item(unsigned index) const + { + ASSERT(index < m_size); + int* storage = static_cast<int*>(m_baseAddress); + return storage[index]; + } + + void set(WebGLIntArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLIntArray(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLIntArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedByteArray.idl b/WebCore/html/canvas/WebGLIntArray.idl index d46f708..3bc037c 100644 --- a/WebCore/html/canvas/CanvasUnsignedByteArray.idl +++ b/WebCore/html/canvas/WebGLIntArray.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasUnsignedByteArray : CanvasArray { + ] WebGLIntArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLIntArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/CanvasProgram.cpp b/WebCore/html/canvas/WebGLProgram.cpp index 83da270..c2606c1 100644 --- a/WebCore/html/canvas/CanvasProgram.cpp +++ b/WebCore/html/canvas/WebGLProgram.cpp @@ -27,23 +27,23 @@ #if ENABLE(3D_CANVAS) -#include "CanvasProgram.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLProgram.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasProgram> CanvasProgram::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLProgram> WebGLProgram::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasProgram(ctx)); + return adoptRef(new WebGLProgram(ctx)); } -CanvasProgram::CanvasProgram(CanvasRenderingContext3D* ctx) +WebGLProgram::WebGLProgram(WebGLRenderingContext* ctx) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createProgram()); } -void CanvasProgram::_deleteObject(Platform3DObject object) +void WebGLProgram::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteProgram(object); } diff --git a/WebCore/html/canvas/CanvasProgram.h b/WebCore/html/canvas/WebGLProgram.h index af817c8..8804d39 100644 --- a/WebCore/html/canvas/CanvasProgram.h +++ b/WebCore/html/canvas/WebGLProgram.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasProgram_h -#define CanvasProgram_h +#ifndef WebGLProgram_h +#define WebGLProgram_h #include "CanvasObject.h" @@ -33,18 +33,18 @@ namespace WebCore { - class CanvasProgram : public CanvasObject { + class WebGLProgram : public CanvasObject { public: - virtual ~CanvasProgram() { deleteObject(); } + virtual ~WebGLProgram() { deleteObject(); } - static PassRefPtr<CanvasProgram> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); protected: - CanvasProgram(CanvasRenderingContext3D*); + WebGLProgram(WebGLRenderingContext*); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasProgram_h +#endif // WebGLProgram_h diff --git a/WebCore/html/canvas/CanvasShader.idl b/WebCore/html/canvas/WebGLProgram.idl index 7474c3a..562fa3a 100644 --- a/WebCore/html/canvas/CanvasShader.idl +++ b/WebCore/html/canvas/WebGLProgram.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasShader { + interface [Conditional=3D_CANVAS] WebGLProgram { }; } diff --git a/WebCore/html/canvas/CanvasRenderbuffer.cpp b/WebCore/html/canvas/WebGLRenderbuffer.cpp index 51054cd..286ad2e 100644 --- a/WebCore/html/canvas/CanvasRenderbuffer.cpp +++ b/WebCore/html/canvas/WebGLRenderbuffer.cpp @@ -27,23 +27,34 @@ #if ENABLE(3D_CANVAS) -#include "CanvasRenderbuffer.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLRenderbuffer.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasRenderbuffer> CanvasRenderbuffer::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLRenderbuffer> WebGLRenderbuffer::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasRenderbuffer(ctx)); + return adoptRef(new WebGLRenderbuffer(ctx)); } -CanvasRenderbuffer::CanvasRenderbuffer(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLRenderbuffer> WebGLRenderbuffer::create(WebGLRenderingContext* ctx, Platform3DObject obj) +{ + return adoptRef(new WebGLRenderbuffer(ctx, obj)); +} + +WebGLRenderbuffer::WebGLRenderbuffer(WebGLRenderingContext* ctx) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createRenderbuffer()); } -void CanvasRenderbuffer::_deleteObject(Platform3DObject object) +WebGLRenderbuffer::WebGLRenderbuffer(WebGLRenderingContext* ctx, Platform3DObject obj) + : CanvasObject(ctx) +{ + setObject(obj, false); +} + +void WebGLRenderbuffer::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteRenderbuffer(object); } diff --git a/WebCore/html/canvas/CanvasRenderbuffer.h b/WebCore/html/canvas/WebGLRenderbuffer.h index 3fb99e9..790fdcd 100644 --- a/WebCore/html/canvas/CanvasRenderbuffer.h +++ b/WebCore/html/canvas/WebGLRenderbuffer.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasRenderbuffer_h -#define CanvasRenderbuffer_h +#ifndef WebGLRenderbuffer_h +#define WebGLRenderbuffer_h #include "CanvasObject.h" @@ -33,18 +33,23 @@ namespace WebCore { - class CanvasRenderbuffer : public CanvasObject { + class WebGLRenderbuffer : public CanvasObject { public: - virtual ~CanvasRenderbuffer() { deleteObject(); } + virtual ~WebGLRenderbuffer() { deleteObject(); } - static PassRefPtr<CanvasRenderbuffer> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*); + // For querying previously created objects via e.g. getFramebufferAttachmentParameter + // FIXME: should consider canonicalizing these objects + static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*, Platform3DObject renderbuffer); + protected: - CanvasRenderbuffer(CanvasRenderingContext3D*); + WebGLRenderbuffer(WebGLRenderingContext*); + WebGLRenderbuffer(WebGLRenderingContext*, Platform3DObject); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasRenderbuffer_h +#endif // WebGLRenderbuffer_h diff --git a/WebCore/html/canvas/CanvasFramebuffer.idl b/WebCore/html/canvas/WebGLRenderbuffer.idl index 0a9b668..2524433 100644 --- a/WebCore/html/canvas/CanvasFramebuffer.idl +++ b/WebCore/html/canvas/WebGLRenderbuffer.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasFramebuffer { + interface [Conditional=3D_CANVAS] WebGLRenderbuffer { }; } diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp new file mode 100644 index 0000000..7a7215d --- /dev/null +++ b/WebCore/html/canvas/WebGLRenderingContext.cpp @@ -0,0 +1,2424 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLRenderingContext.h" + +#include "WebGLActiveInfo.h" +#include "WebGLBuffer.h" +#include "WebGLFramebuffer.h" +#include "WebGLProgram.h" +#include "WebGLRenderbuffer.h" +#include "WebGLTexture.h" +#include "WebGLShader.h" +#include "WebGLUniformLocation.h" +#include "HTMLCanvasElement.h" +#include "HTMLImageElement.h" +#include "ImageBuffer.h" +#include "NotImplemented.h" +#include "RenderBox.h" +#include "RenderLayer.h" + +namespace WebCore { + +class WebGLStateRestorer { +public: + WebGLStateRestorer(WebGLRenderingContext* context, + bool changed) + : m_context(context) + , m_changed(changed) + { + } + + ~WebGLStateRestorer() + { + m_context->cleanupAfterGraphicsCall(m_changed); + } + +private: + WebGLRenderingContext* m_context; + bool m_changed; +}; + +PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElement* canvas) +{ + OwnPtr<GraphicsContext3D> context(GraphicsContext3D::create()); + if (!context) + return 0; + + return new WebGLRenderingContext(canvas, context.release()); +} + +WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr<GraphicsContext3D> context) + : CanvasRenderingContext(passedCanvas) + , m_context(context) + , m_needsUpdate(true) + , m_markedCanvasDirty(false) + , m_activeTextureUnit(0) +{ + ASSERT(m_context); + int numVertexAttribs = 0; + m_context->getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &numVertexAttribs); + m_maxVertexAttribs = numVertexAttribs; + m_context->reshape(canvas()->width(), canvas()->height()); +} + +WebGLRenderingContext::~WebGLRenderingContext() +{ + detachAndRemoveAllObjects(); +} + +void WebGLRenderingContext::markContextChanged() +{ +#if USE(ACCELERATED_COMPOSITING) + if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) { + canvas()->renderBox()->layer()->rendererContentChanged(); + } else { +#endif + if (!m_markedCanvasDirty) { + // Make sure the canvas's image buffer is allocated. + canvas()->buffer(); + canvas()->willDraw(FloatRect(0, 0, canvas()->width(), canvas()->height())); + m_markedCanvasDirty = true; + } +#if USE(ACCELERATED_COMPOSITING) + } +#endif +} + +void WebGLRenderingContext::beginPaint() +{ + if (m_markedCanvasDirty) { + m_context->beginPaint(this); + } +} + +void WebGLRenderingContext::endPaint() +{ + if (m_markedCanvasDirty) { + m_markedCanvasDirty = false; + m_context->endPaint(); + } +} + +void WebGLRenderingContext::reshape(int width, int height) +{ + if (m_needsUpdate) { +#if USE(ACCELERATED_COMPOSITING) + if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) + canvas()->renderBox()->layer()->rendererContentChanged(); +#endif + m_needsUpdate = false; + } + + m_context->reshape(width, height); +} + +int WebGLRenderingContext::sizeInBytes(int type, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + int result = m_context->sizeInBytes(type); + if (result <= 0) + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + + return result; +} + +void WebGLRenderingContext::activeTexture(unsigned long texture, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if ((texture - GraphicsContext3D::TEXTURE0) > sizeof(m_textureUnits) / sizeof(TextureUnitState)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_activeTextureUnit = texture - GraphicsContext3D::TEXTURE0; + m_context->activeTexture(texture); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this || !shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->attachShader(program, shader); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, unsigned long index, const String& name, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->bindAttribLocation(program, index, name); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bindBuffer(unsigned long target, WebGLBuffer* buffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (buffer && buffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (target == GraphicsContext3D::ARRAY_BUFFER) + m_boundArrayBuffer = buffer; + else if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) + m_boundElementArrayBuffer = buffer; + else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bindBuffer(target, buffer); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::bindFramebuffer(unsigned long target, WebGLFramebuffer* buffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (buffer && buffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + if (target != GraphicsContext3D::FRAMEBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_framebufferBinding = buffer; + m_context->bindFramebuffer(target, buffer); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bindRenderbuffer(unsigned long target, WebGLRenderbuffer* renderBuffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (renderBuffer && renderBuffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + if (target != GraphicsContext3D::RENDERBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_renderbufferBinding = renderBuffer; + m_context->bindRenderbuffer(target, renderBuffer); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::bindTexture(unsigned long target, WebGLTexture* texture, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (texture && texture->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + if (target == GraphicsContext3D::TEXTURE_2D) + m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; + else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) + m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; + else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + m_context->bindTexture(target, texture); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendColor(double red, double green, double blue, double alpha) +{ + m_context->blendColor(red, green, blue, alpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendEquation( unsigned long mode ) +{ + m_context->blendEquation(mode); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha) +{ + m_context->blendEquationSeparate(modeRGB, modeAlpha); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::blendFunc(unsigned long sfactor, unsigned long dfactor) +{ + m_context->blendFunc(sfactor, dfactor); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha) +{ + m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { + if (!m_boundElementArrayBuffer->associateBufferData(target, size)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else if (target == GraphicsContext3D::ARRAY_BUFFER && m_boundArrayBuffer) { + if (!m_boundArrayBuffer->associateBufferData(target, size)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bufferData(target, size, usage); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bufferData(unsigned long target, WebGLArray* data, unsigned long usage, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { + if (!m_boundElementArrayBuffer->associateBufferData(target, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else if (target == GraphicsContext3D::ARRAY_BUFFER && m_boundArrayBuffer) { + if (!m_boundArrayBuffer->associateBufferData(target, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bufferData(target, data, usage); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::bufferSubData(unsigned long target, long offset, WebGLArray* data, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER && m_boundElementArrayBuffer) { + if (!m_boundElementArrayBuffer->associateBufferSubData(target, offset, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else if (target == GraphicsContext3D::ARRAY_BUFFER && m_boundArrayBuffer) { + if (!m_boundArrayBuffer->associateBufferSubData(target, offset, data)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + } else { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return; + } + + m_context->bufferSubData(target, offset, data); + cleanupAfterGraphicsCall(false); +} + +unsigned long WebGLRenderingContext::checkFramebufferStatus(unsigned long target) +{ + return m_context->checkFramebufferStatus(target); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::clear(unsigned long mask) +{ + m_context->clear(mask); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::clearColor(double r, double g, double b, double a) +{ + if (isnan(r)) + r = 0; + if (isnan(g)) + g = 0; + if (isnan(b)) + b = 0; + if (isnan(a)) + a = 1; + m_context->clearColor(r, g, b, a); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::clearDepth(double depth) +{ + m_context->clearDepth(depth); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::clearStencil(long s) +{ + m_context->clearStencil(s); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::colorMask(bool red, bool green, bool blue, bool alpha) +{ + m_context->colorMask(red, green, blue, alpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->compileShader(shader); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) +{ + m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height) +{ + m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); + cleanupAfterGraphicsCall(false); +} + +PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer() +{ + RefPtr<WebGLBuffer> o = WebGLBuffer::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLFramebuffer> WebGLRenderingContext::createFramebuffer() +{ + RefPtr<WebGLFramebuffer> o = WebGLFramebuffer::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLTexture> WebGLRenderingContext::createTexture() +{ + RefPtr<WebGLTexture> o = WebGLTexture::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLProgram> WebGLRenderingContext::createProgram() +{ + RefPtr<WebGLProgram> o = WebGLProgram::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLRenderbuffer> WebGLRenderingContext::createRenderbuffer() +{ + RefPtr<WebGLRenderbuffer> o = WebGLRenderbuffer::create(this); + addObject(o.get()); + return o; +} + +PassRefPtr<WebGLShader> WebGLRenderingContext::createShader(unsigned long type, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (type != GraphicsContext3D::VERTEX_SHADER && type != GraphicsContext3D::FRAGMENT_SHADER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return 0; + } + + RefPtr<WebGLShader> o = WebGLShader::create(this, static_cast<GraphicsContext3D::WebGLEnumType>(type)); + addObject(o.get()); + return o; +} + +void WebGLRenderingContext::cullFace(unsigned long mode) +{ + m_context->cullFace(mode); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer) +{ + if (!buffer) + return; + + buffer->deleteObject(); +} + +void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer) +{ + if (!framebuffer) + return; + + framebuffer->deleteObject(); +} + +void WebGLRenderingContext::deleteProgram(WebGLProgram* program) +{ + if (!program) + return; + + program->deleteObject(); +} + +void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer) +{ + if (!renderbuffer) + return; + + renderbuffer->deleteObject(); +} + +void WebGLRenderingContext::deleteShader(WebGLShader* shader) +{ + if (!shader) + return; + + shader->deleteObject(); +} + +void WebGLRenderingContext::deleteTexture(WebGLTexture* texture) +{ + if (!texture) + return; + + texture->deleteObject(); +} + +void WebGLRenderingContext::depthFunc(unsigned long func) +{ + m_context->depthFunc(func); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::depthMask(bool flag) +{ + m_context->depthMask(flag); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::depthRange(double zNear, double zFar) +{ + m_context->depthRange(zNear, zFar); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this || !shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->detachShader(program, shader); + cleanupAfterGraphicsCall(false); +} + + +void WebGLRenderingContext::disable(unsigned long cap) +{ + m_context->disable(cap); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::disableVertexAttribArray(unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (index >= m_maxVertexAttribs) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + if (index < m_vertexAttribState.size()) + m_vertexAttribState[index].enabled = false; + + m_context->disableVertexAttribArray(index); + cleanupAfterGraphicsCall(false); +} + +bool WebGLRenderingContext::validateIndexArray(unsigned long count, unsigned long type, long offset, long& numElements) +{ + long lastIndex = -1; + if (!m_boundElementArrayBuffer) + return false; + + if (offset < 0) + return false; + + // The GL spec says that count must be "greater + + unsigned long uoffset = static_cast<unsigned long>(offset); + + if (type == GraphicsContext3D::UNSIGNED_SHORT) { + // For an unsigned short array, offset must be divisible by 2 for alignment reasons. + if (uoffset & 1) + return false; + + // Make uoffset an element offset. + uoffset /= 2; + + unsigned long n = m_boundElementArrayBuffer->byteLength(GraphicsContext3D::ELEMENT_ARRAY_BUFFER) / 2; + if (uoffset > n || count > n - uoffset) + return false; + + const unsigned short* p = static_cast<const unsigned short*>(m_boundElementArrayBuffer->elementArrayBuffer()->data()); + while (n-- > 0) { + if (*p > lastIndex) + lastIndex = *p; + ++p; + } + } else if (type == GraphicsContext3D::UNSIGNED_BYTE) { + unsigned long n = m_boundElementArrayBuffer->byteLength(GraphicsContext3D::ELEMENT_ARRAY_BUFFER); + if (uoffset > n || count > n - uoffset) + return false; + + const unsigned char* p = static_cast<const unsigned char*>(m_boundElementArrayBuffer->elementArrayBuffer()->data()); + while (n-- > 0) { + if (*p > lastIndex) + lastIndex = *p; + ++p; + } + } + + // Then set the last index in the index array and make sure it is valid. + numElements = lastIndex + 1; + return numElements > 0; +} + +bool WebGLRenderingContext::validateRenderingState(long numElements) +{ + // Look in each enabled vertex attrib and find the smallest buffer size + long smallestNumElements = LONG_MAX; + for (unsigned i = 0; i < m_vertexAttribState.size(); ++i) { + const VertexAttribState& state = m_vertexAttribState[i]; + if (state.enabled && state.numElements < smallestNumElements) + smallestNumElements = state.numElements; + } + + if (smallestNumElements == LONG_MAX) + smallestNumElements = 0; + + return numElements <= smallestNumElements; +} + +void WebGLRenderingContext::drawArrays(unsigned long mode, long first, long count, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + // Ensure we have a valid rendering state + if (first < 0 || count < 0 || !validateRenderingState(first + count)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->drawArrays(mode, first, count); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + // Ensure we have a valid rendering state + long numElements; + + if (offset < 0 || !validateIndexArray(count, type, offset, numElements) || !validateRenderingState(numElements)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->drawElements(mode, count, type, offset); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::enable(unsigned long cap) +{ + m_context->enable(cap); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::enableVertexAttribArray(unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (index >= m_maxVertexAttribs) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + if (index >= m_vertexAttribState.size()) + m_vertexAttribState.resize(index + 1); + + m_vertexAttribState[index].enabled = true; + + m_context->enableVertexAttribArray(index); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::finish() +{ + m_context->finish(); + cleanupAfterGraphicsCall(true); +} + + +void WebGLRenderingContext::flush() +{ + m_context->flush(); + cleanupAfterGraphicsCall(true); +} + +void WebGLRenderingContext::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer* buffer, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (buffer && buffer->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture* texture, long level, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (texture && texture->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->framebufferTexture2D(target, attachment, textarget, texture, level); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::frontFace(unsigned long mode) +{ + m_context->frontFace(mode); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::generateMipmap(unsigned long target) +{ + m_context->generateMipmap(target); + cleanupAfterGraphicsCall(false); +} + +PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* program, unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + ActiveInfo info; + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return 0; + } + if (!m_context->getActiveAttrib(program, index, info)) { + return 0; + } + return WebGLActiveInfo::create(info.name, info.type, info.size); +} + +PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram* program, unsigned long index, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + ActiveInfo info; + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return 0; + } + if (!m_context->getActiveUniform(program, index, info)) { + return 0; + } + return WebGLActiveInfo::create(info.name, info.type, info.size); +} + +int WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const String& name) +{ + return m_context->getAttribLocation(program, name); +} + +WebGLGetInfo WebGLRenderingContext::getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::ARRAY_BUFFER && target != GraphicsContext3D::ELEMENT_ARRAY_BUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + if (pname != GraphicsContext3D::BUFFER_SIZE && pname != GraphicsContext3D::BUFFER_USAGE) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + WebGLStateRestorer(this, false); + int value; + m_context->getBufferParameteriv(target, pname, &value); + if (pname == GraphicsContext3D::BUFFER_SIZE) + return WebGLGetInfo(static_cast<long>(value)); + else + return WebGLGetInfo(static_cast<unsigned long>(value)); +} + +unsigned long WebGLRenderingContext::getError() +{ + return m_context->getError(); +} + +WebGLGetInfo WebGLRenderingContext::getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::FRAMEBUFFER + || (attachment != GraphicsContext3D::COLOR_ATTACHMENT0 + && attachment != GraphicsContext3D::DEPTH_ATTACHMENT + && attachment != GraphicsContext3D::STENCIL_ATTACHMENT) + || (pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE + && pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME + && pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL + && pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + if (pname != GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { + WebGLStateRestorer(this, false); + int value; + m_context->getFramebufferAttachmentParameteriv(target, attachment, pname, &value); + if (pname == GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) + return WebGLGetInfo(static_cast<unsigned long>(value)); + else + return WebGLGetInfo(static_cast<long>(value)); + } else { + WebGLStateRestorer(this, false); + int type = 0; + m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); + int value = 0; + m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &value); + // FIXME: should consider canonicalizing these objects + switch (type) { + case GraphicsContext3D::RENDERBUFFER: { + RefPtr<WebGLRenderbuffer> tmp = WebGLRenderbuffer::create(this, value); + addObject(tmp.get()); + return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(tmp)); + } + case GraphicsContext3D::TEXTURE: { + RefPtr<WebGLTexture> tmp = WebGLTexture::create(this, value); + addObject(tmp.get()); + return WebGLGetInfo(PassRefPtr<WebGLTexture>(tmp)); + } + default: + // FIXME: raise exception? + return WebGLGetInfo(); + } + } +} + +WebGLGetInfo WebGLRenderingContext::getParameter(unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + WebGLStateRestorer(this, false); + switch (pname) { + case GraphicsContext3D::ACTIVE_TEXTURE: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::ALPHA_BITS: + return getLongParameter(pname); + case GraphicsContext3D::ARRAY_BUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLBuffer>(m_boundArrayBuffer)); + case GraphicsContext3D::BLEND: + return getBooleanParameter(pname); + case GraphicsContext3D::BLEND_COLOR: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::BLEND_DST_ALPHA: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_DST_RGB: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_EQUATION_ALPHA: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_EQUATION_RGB: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_SRC_ALPHA: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLEND_SRC_RGB: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::BLUE_BITS: + return getLongParameter(pname); + case GraphicsContext3D::COLOR_CLEAR_VALUE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::COLOR_WRITEMASK: + return getWebGLUnsignedByteArrayParameter(pname); + case GraphicsContext3D::COMPRESSED_TEXTURE_FORMATS: + // Defined as null in the spec + return WebGLGetInfo(); + case GraphicsContext3D::CULL_FACE: + return getBooleanParameter(pname); + case GraphicsContext3D::CULL_FACE_MODE: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::CURRENT_PROGRAM: + return WebGLGetInfo(PassRefPtr<WebGLProgram>(m_currentProgram)); + case GraphicsContext3D::DEPTH_BITS: + return getLongParameter(pname); + case GraphicsContext3D::DEPTH_CLEAR_VALUE: + return getFloatParameter(pname); + case GraphicsContext3D::DEPTH_FUNC: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::DEPTH_RANGE: + return getWebGLFloatArrayParameter(pname); + case GraphicsContext3D::DEPTH_TEST: + return getBooleanParameter(pname); + case GraphicsContext3D::DEPTH_WRITEMASK: + return getBooleanParameter(pname); + case GraphicsContext3D::DITHER: + return getBooleanParameter(pname); + case GraphicsContext3D::ELEMENT_ARRAY_BUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLBuffer>(m_boundElementArrayBuffer)); + case GraphicsContext3D::FRAMEBUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLFramebuffer>(m_framebufferBinding)); + case GraphicsContext3D::FRONT_FACE: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::GENERATE_MIPMAP_HINT: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::GREEN_BITS: + return getLongParameter(pname); + case GraphicsContext3D::LINE_WIDTH: + return getFloatParameter(pname); + case GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_CUBE_MAP_TEXTURE_SIZE: + return getLongParameter(pname); + case GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_RENDERBUFFER_SIZE: + return getLongParameter(pname); + case GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_TEXTURE_SIZE: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VARYING_VECTORS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VERTEX_ATTRIBS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS: + return getLongParameter(pname); + case GraphicsContext3D::MAX_VIEWPORT_DIMS: + return getWebGLIntArrayParameter(pname); + case GraphicsContext3D::NUM_COMPRESSED_TEXTURE_FORMATS: + return getLongParameter(pname); + case GraphicsContext3D::NUM_SHADER_BINARY_FORMATS: + // FIXME: should we always return 0 for this? + return getLongParameter(pname); + case GraphicsContext3D::PACK_ALIGNMENT: + return getLongParameter(pname); + case GraphicsContext3D::POLYGON_OFFSET_FACTOR: + return getFloatParameter(pname); + case GraphicsContext3D::POLYGON_OFFSET_FILL: + return getBooleanParameter(pname); + case GraphicsContext3D::POLYGON_OFFSET_UNITS: + return getFloatParameter(pname); + case GraphicsContext3D::RED_BITS: + return getLongParameter(pname); + case GraphicsContext3D::RENDERBUFFER_BINDING: + return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(m_renderbufferBinding)); + case GraphicsContext3D::SAMPLE_BUFFERS: + return getLongParameter(pname); + case GraphicsContext3D::SAMPLE_COVERAGE_INVERT: + return getBooleanParameter(pname); + case GraphicsContext3D::SAMPLE_COVERAGE_VALUE: + return getFloatParameter(pname); + case GraphicsContext3D::SAMPLES: + return getLongParameter(pname); + case GraphicsContext3D::SCISSOR_BOX: + return getWebGLIntArrayParameter(pname); + case GraphicsContext3D::SCISSOR_TEST: + return getBooleanParameter(pname); + case GraphicsContext3D::STENCIL_BACK_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_FUNC: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_PASS_DEPTH_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_PASS_DEPTH_PASS: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_REF: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_VALUE_MASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BACK_WRITEMASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_BITS: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_CLEAR_VALUE: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_FUNC: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_PASS_DEPTH_FAIL: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_PASS_DEPTH_PASS: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_REF: + return getLongParameter(pname); + case GraphicsContext3D::STENCIL_TEST: + return getBooleanParameter(pname); + case GraphicsContext3D::STENCIL_VALUE_MASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::STENCIL_WRITEMASK: + return getUnsignedLongParameter(pname); + case GraphicsContext3D::SUBPIXEL_BITS: + return getLongParameter(pname); + case GraphicsContext3D::TEXTURE_BINDING_2D: + return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_texture2DBinding)); + case GraphicsContext3D::TEXTURE_BINDING_CUBE_MAP: + return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding)); + case GraphicsContext3D::UNPACK_ALIGNMENT: + // FIXME: should this be "long" in the spec? + return getIntParameter(pname); + case GraphicsContext3D::VIEWPORT: + return getWebGLIntArrayParameter(pname); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return WebGLGetInfo(); + } + + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::DELETE_STATUS: + case GraphicsContext3D::LINK_STATUS: + case GraphicsContext3D::VALIDATE_STATUS: + m_context->getProgramiv(program, pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); + case GraphicsContext3D::INFO_LOG_LENGTH: + case GraphicsContext3D::ATTACHED_SHADERS: + case GraphicsContext3D::ACTIVE_ATTRIBUTES: + case GraphicsContext3D::ACTIVE_ATTRIBUTE_MAX_LENGTH: + case GraphicsContext3D::ACTIVE_UNIFORMS: + case GraphicsContext3D::ACTIVE_UNIFORM_MAX_LENGTH: + m_context->getProgramiv(program, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return ""; + } + WebGLStateRestorer(this, false); + return m_context->getProgramInfoLog(program); +} + +WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::RENDERBUFFER) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::RENDERBUFFER_WIDTH: + case GraphicsContext3D::RENDERBUFFER_HEIGHT: + case GraphicsContext3D::RENDERBUFFER_RED_SIZE: + case GraphicsContext3D::RENDERBUFFER_GREEN_SIZE: + case GraphicsContext3D::RENDERBUFFER_BLUE_SIZE: + case GraphicsContext3D::RENDERBUFFER_ALPHA_SIZE: + case GraphicsContext3D::RENDERBUFFER_DEPTH_SIZE: + case GraphicsContext3D::RENDERBUFFER_STENCIL_SIZE: + m_context->getRenderbufferParameteriv(target, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + case GraphicsContext3D::RENDERBUFFER_INTERNAL_FORMAT: + m_context->getRenderbufferParameteriv(target, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return WebGLGetInfo(); + } + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::DELETE_STATUS: + case GraphicsContext3D::COMPILE_STATUS: + m_context->getShaderiv(shader, pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); + case GraphicsContext3D::SHADER_TYPE: + m_context->getShaderiv(shader, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + case GraphicsContext3D::INFO_LOG_LENGTH: + case GraphicsContext3D::SHADER_SOURCE_LENGTH: + m_context->getShaderiv(shader, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return ""; + } + WebGLStateRestorer(this, false); + return m_context->getShaderInfoLog(shader); +} + +String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return ""; + } + WebGLStateRestorer(this, false); + return m_context->getShaderSource(shader); +} + +String WebGLRenderingContext::getString(unsigned long name) +{ + WebGLStateRestorer(this, false); + return m_context->getString(name); +} + +WebGLGetInfo WebGLRenderingContext::getTexParameter(unsigned long target, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (target != GraphicsContext3D::TEXTURE_2D + && target != GraphicsContext3D::TEXTURE_CUBE_MAP) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + WebGLStateRestorer(this, false); + int value = 0; + switch (pname) { + case GraphicsContext3D::TEXTURE_MAG_FILTER: + case GraphicsContext3D::TEXTURE_MIN_FILTER: + case GraphicsContext3D::TEXTURE_WRAP_S: + case GraphicsContext3D::TEXTURE_WRAP_T: + m_context->getTexParameteriv(target, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + default: + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } +} + +WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebGLUniformLocation* uniformLocation, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || uniformLocation->program() != program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return WebGLGetInfo(); + } + long location = uniformLocation->location(); + + WebGLStateRestorer(this, false); + // FIXME: make this more efficient using WebGLUniformLocation and caching types in it + int activeUniforms = 0; + m_context->getProgramiv(program, GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms); + for (int i = 0; i < activeUniforms; i++) { + ActiveInfo info; + if (!m_context->getActiveUniform(program, i, info)) + return WebGLGetInfo(); + // Now need to look this up by name again to find its location + long loc = m_context->getUniformLocation(program, info.name); + if (loc == location) { + // Found it. Use the type in the ActiveInfo to determine the return type. + GraphicsContext3D::WebGLEnumType baseType; + unsigned length; + switch (info.type) { + case GraphicsContext3D::BOOL: + baseType = GraphicsContext3D::BOOL; + length = 1; + break; + case GraphicsContext3D::BOOL_VEC2: + baseType = GraphicsContext3D::BOOL; + length = 2; + break; + case GraphicsContext3D::BOOL_VEC3: + baseType = GraphicsContext3D::BOOL; + length = 3; + break; + case GraphicsContext3D::BOOL_VEC4: + baseType = GraphicsContext3D::BOOL; + length = 4; + break; + case GraphicsContext3D::INT: + baseType = GraphicsContext3D::INT; + length = 1; + break; + case GraphicsContext3D::INT_VEC2: + baseType = GraphicsContext3D::INT; + length = 2; + break; + case GraphicsContext3D::INT_VEC3: + baseType = GraphicsContext3D::INT; + length = 3; + break; + case GraphicsContext3D::INT_VEC4: + baseType = GraphicsContext3D::INT; + length = 4; + break; + case GraphicsContext3D::FLOAT: + baseType = GraphicsContext3D::FLOAT; + length = 1; + break; + case GraphicsContext3D::FLOAT_VEC2: + baseType = GraphicsContext3D::FLOAT; + length = 2; + break; + case GraphicsContext3D::FLOAT_VEC3: + baseType = GraphicsContext3D::FLOAT; + length = 3; + break; + case GraphicsContext3D::FLOAT_VEC4: + baseType = GraphicsContext3D::FLOAT; + length = 4; + break; + case GraphicsContext3D::FLOAT_MAT2: + baseType = GraphicsContext3D::FLOAT; + length = 4; + break; + case GraphicsContext3D::FLOAT_MAT3: + baseType = GraphicsContext3D::FLOAT; + length = 9; + break; + case GraphicsContext3D::FLOAT_MAT4: + baseType = GraphicsContext3D::FLOAT; + length = 16; + break; + default: + // Can't handle this type + // FIXME: what to do about samplers? + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return WebGLGetInfo(); + } + switch (baseType) { + case GraphicsContext3D::FLOAT: { + float value[16] = {0}; + m_context->getUniformfv(program, location, value); + if (length == 1) + return WebGLGetInfo(value[0]); + else + return WebGLGetInfo(WebGLFloatArray::create(value, length)); + } + case GraphicsContext3D::INT: { + int value[16] = {0}; + m_context->getUniformiv(program, location, value); + if (length == 1) + return WebGLGetInfo(static_cast<long>(value[0])); + else + return WebGLGetInfo(WebGLIntArray::create(value, length)); + } + case GraphicsContext3D::BOOL: { + int value[16] = {0}; + m_context->getUniformiv(program, location, value); + if (length == 1) + return WebGLGetInfo(static_cast<bool>(value[0])); + else { + unsigned char boolValue[16] = {0}; + for (unsigned j = 0; j < length; j++) + boolValue[j] = static_cast<bool>(value[j]); + return WebGLGetInfo(WebGLUnsignedByteArray::create(boolValue, length)); + } + } + default: + notImplemented(); + } + } + } + // If we get here, something went wrong in our unfortunately complex logic above + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return WebGLGetInfo(); +} + +PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGLProgram* program, const String& name, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return 0; + } + WebGLStateRestorer(this, false); + return WebGLUniformLocation::create(program, m_context->getUniformLocation(program, name)); +} + +WebGLGetInfo WebGLRenderingContext::getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + WebGLStateRestorer(this, false); + switch (pname) { + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { + int name = 0; + m_context->getVertexAttribiv(index, pname, &name); + if (name == 0) + return WebGLGetInfo(); + RefPtr<WebGLBuffer> tmp = WebGLBuffer::create(this, name); + addObject(tmp.get()); + return WebGLGetInfo(PassRefPtr<WebGLBuffer>(tmp)); + } + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_ENABLED: + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_NORMALIZED: { + int value = 0; + m_context->getVertexAttribiv(index, pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); + } + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_SIZE: + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_STRIDE: { + int value = 0; + m_context->getVertexAttribiv(index, pname, &value); + return WebGLGetInfo(static_cast<long>(value)); + } + case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_TYPE: { + int value = 0; + m_context->getVertexAttribiv(index, pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); + } + case GraphicsContext3D::CURRENT_VERTEX_ATTRIB: { + float value[4] = {0}; + m_context->getVertexAttribfv(index, pname, value); + return WebGLGetInfo(WebGLFloatArray::create(value, 4)); + } + default: { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM); + return WebGLGetInfo(); + } + } +} + +long WebGLRenderingContext::getVertexAttribOffset(unsigned long index, unsigned long pname) +{ + long result = m_context->getVertexAttribOffset(index, pname); + cleanupAfterGraphicsCall(false); + return result; +} + +void WebGLRenderingContext::hint(unsigned long target, unsigned long mode) +{ + m_context->hint(target, mode); + cleanupAfterGraphicsCall(false); +} + +bool WebGLRenderingContext::isBuffer(WebGLBuffer* buffer) +{ + if (!buffer) + return false; + + return m_context->isBuffer(buffer); +} + +bool WebGLRenderingContext::isEnabled(unsigned long cap) +{ + return m_context->isEnabled(cap); +} + +bool WebGLRenderingContext::isFramebuffer(WebGLFramebuffer* framebuffer) +{ + if (!framebuffer) + return false; + + return m_context->isFramebuffer(framebuffer); +} + +bool WebGLRenderingContext::isProgram(WebGLProgram* program) +{ + if (!program) + return false; + + return m_context->isProgram(program); +} + +bool WebGLRenderingContext::isRenderbuffer(WebGLRenderbuffer* renderbuffer) +{ + if (!renderbuffer) + return false; + + return m_context->isRenderbuffer(renderbuffer); +} + +bool WebGLRenderingContext::isShader(WebGLShader* shader) +{ + if (!shader) + return false; + + return m_context->isShader(shader); +} + +bool WebGLRenderingContext::isTexture(WebGLTexture* texture) +{ + if (!texture) + return false; + + return m_context->isTexture(texture); +} + +void WebGLRenderingContext::lineWidth(double width) +{ + m_context->lineWidth((float) width); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::linkProgram(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->linkProgram(program); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::pixelStorei(unsigned long pname, long param) +{ + m_context->pixelStorei(pname, param); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::polygonOffset(double factor, double units) +{ + m_context->polygonOffset((float) factor, (float) units); + cleanupAfterGraphicsCall(false); +} + +PassRefPtr<WebGLArray> WebGLRenderingContext::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type) +{ + RefPtr<WebGLArray> array = m_context->readPixels(x, y, width, height, format, type); + cleanupAfterGraphicsCall(false); + return array; +} + +void WebGLRenderingContext::releaseShaderCompiler() +{ + m_context->releaseShaderCompiler(); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height) +{ + m_context->renderbufferStorage(target, internalformat, width, height); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::sampleCoverage(double value, bool invert) +{ + m_context->sampleCoverage((float) value, invert); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::scissor(long x, long y, unsigned long width, unsigned long height) +{ + m_context->scissor(x, y, width, height); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& string, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!shader || shader->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + m_context->shaderSource(shader, string); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilFunc(unsigned long func, long ref, unsigned long mask) +{ + m_context->stencilFunc(func, ref, mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask) +{ + m_context->stencilFuncSeparate(face, func, ref, mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilMask(unsigned long mask) +{ + m_context->stencilMask(mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilMaskSeparate(unsigned long face, unsigned long mask) +{ + m_context->stencilMaskSeparate(face, mask); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass) +{ + m_context->stencilOp(fail, zfail, zpass); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass) +{ + m_context->stencilOpSeparate(face, fail, zfail, zpass); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texImage2D(target, level, internalformat, width, height, + border, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texImage2D(target, level, internalformat, width, height, + border, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + ec = 0; + if (!image) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + CachedImage* cachedImage = image->cachedImage(); + if (!cachedImage) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + // FIXME: For now we ignore any errors returned + m_context->texImage2D(target, level, cachedImage->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + ec = 0; + if (!canvas) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + ImageBuffer* buffer = canvas->buffer(); + if (!buffer) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + // FIXME: For now we ignore any errors returned + m_context->texImage2D(target, level, buffer->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texImage2D(target, level, video, flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texParameterf(unsigned target, unsigned pname, float param) +{ + m_context->texParameterf(target, pname, param); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texParameteri(unsigned target, unsigned pname, int param) +{ + m_context->texParameteri(target, pname, param); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + if (!image) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + CachedImage* cachedImage = image->cachedImage(); + if (!cachedImage) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, cachedImage->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + ec = 0; + if (!canvas) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + ImageBuffer* buffer = canvas->buffer(); + if (!buffer) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + // FIXME: For now we ignore any errors returned + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, buffer->image(), flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode& ec) +{ + // FIXME: For now we ignore any errors returned + ec = 0; + m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform1f(location->location(), x); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1fv(location->location(), v->data(), v->length()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1fv(location->location(), v, size); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform1i(location->location(), x); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1iv(location->location(), v->data(), v->length()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + m_context->uniform1iv(location->location(), v, size); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform2f(location->location(), x, y); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2fv(location->location(), v->data(), v->length() / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2fv(location->location(), v, size / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform2i(location->location(), x, y); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2iv(location->location(), v->data(), v->length() / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 2 + m_context->uniform2iv(location->location(), v, size / 2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform3f(location->location(), x, y, z); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3fv(location->location(), v->data(), v->length() / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3fv(location->location(), v, size / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform3i(location->location(), x, y, z); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3iv(location->location(), v->data(), v->length() / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 3 + m_context->uniform3iv(location->location(), v, size / 3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform4f(location->location(), x, y, z, w); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4fv(location->location(), v->data(), v->length() / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4fv(location->location(), v, size / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->uniform4i(location->location(), x, y, z, w); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4iv(location->location(), v->data(), v->length() / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniform4iv(location->location(), v, size / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniformMatrix2fv(location->location(), transpose, v->data(), v->length() / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 4 + m_context->uniformMatrix2fv(location->location(), transpose, v, size / 4); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 9 + m_context->uniformMatrix3fv(location->location(), transpose, v->data(), v->length() / 9); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 9 + m_context->uniformMatrix3fv(location->location(), transpose, v, size / 9); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* v, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 16 + m_context->uniformMatrix4fv(location->location(), transpose, v->data(), v->length() / 16); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* v, int size, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!location || location->program() != m_currentProgram) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + if (!v) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + // FIXME: length needs to be a multiple of 16 + m_context->uniformMatrix4fv(location->location(), transpose, v, size / 16); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::useProgram(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + m_currentProgram = program; + m_context->useProgram(program); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::validateProgram(WebGLProgram* program, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!program || program->context() != this) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); + return; + } + + m_context->validateProgram(program); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib1f(unsigned long indx, float v0) +{ + m_context->vertexAttrib1f(indx, v0); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib1fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib1fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib1fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib1fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib2f(unsigned long indx, float v0, float v1) +{ + m_context->vertexAttrib2f(indx, v0, v1); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib2fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib2fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib2fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib2fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2) +{ + m_context->vertexAttrib3f(indx, v0, v1, v2); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib3fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib3fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib3fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib3fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3) +{ + m_context->vertexAttrib4f(indx, v0, v1, v2, v3); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib4fv(unsigned long indx, WebGLFloatArray* v) +{ + // FIXME: Need to make sure array is big enough for attribute being set + m_context->vertexAttrib4fv(indx, v->data()); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttrib4fv(unsigned long indx, float* v, int size) +{ + // FIXME: Need to make sure array is big enough for attribute being set + UNUSED_PARAM(size); + + m_context->vertexAttrib4fv(indx, v); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, unsigned long stride, unsigned long offset, ExceptionCode& ec) +{ + UNUSED_PARAM(ec); + if (!m_boundArrayBuffer || indx >= m_maxVertexAttribs) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + if (indx >= m_vertexAttribState.size()) + m_vertexAttribState.resize(indx + 1); + + // Determine the number of elements the bound buffer can hold, given the offset, size, type and stride + long bytesPerElement = size * sizeInBytes(type, ec); + if (bytesPerElement <= 0) + return; + long validatedStride = bytesPerElement; + if (stride != 0) { + if ((long) stride < bytesPerElement) { + m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); + return; + } + + validatedStride = stride; + } + + // Avoid off-by-one errors in numElements computation. + // For the last element, we will only touch the data for the + // element and nothing beyond it. + long bytesRemaining = m_boundArrayBuffer->byteLength(GraphicsContext3D::ARRAY_BUFFER) - offset; + if (bytesRemaining < bytesPerElement) + m_vertexAttribState[indx].numElements = 0; + else + m_vertexAttribState[indx].numElements = 1 + (bytesRemaining - bytesPerElement) / validatedStride; + + m_context->vertexAttribPointer(indx, size, type, normalized, stride, offset); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::viewport(long x, long y, unsigned long width, unsigned long height) +{ + if (isnan(x)) + x = 0; + if (isnan(y)) + y = 0; + if (isnan(width)) + width = 100; + if (isnan(height)) + height = 100; + m_context->viewport(x, y, width, height); + cleanupAfterGraphicsCall(false); +} + +void WebGLRenderingContext::removeObject(CanvasObject* object) +{ + m_canvasObjects.remove(object); +} + +void WebGLRenderingContext::addObject(CanvasObject* object) +{ + removeObject(object); + m_canvasObjects.add(object); +} + +void WebGLRenderingContext::detachAndRemoveAllObjects() +{ + HashSet<RefPtr<CanvasObject> >::iterator pend = m_canvasObjects.end(); + for (HashSet<RefPtr<CanvasObject> >::iterator it = m_canvasObjects.begin(); it != pend; ++it) + (*it)->detachContext(); + + m_canvasObjects.clear(); +} + +WebGLGetInfo WebGLRenderingContext::getBooleanParameter(unsigned long pname) +{ + unsigned char value; + m_context->getBooleanv(pname, &value); + return WebGLGetInfo(static_cast<bool>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getFloatParameter(unsigned long pname) +{ + float value; + m_context->getFloatv(pname, &value); + return WebGLGetInfo(static_cast<float>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getIntParameter(unsigned long pname) +{ + return getLongParameter(pname); +} + +WebGLGetInfo WebGLRenderingContext::getLongParameter(unsigned long pname) +{ + int value; + m_context->getIntegerv(pname, &value); + return WebGLGetInfo(static_cast<long>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getUnsignedLongParameter(unsigned long pname) +{ + int value; + m_context->getIntegerv(pname, &value); + return WebGLGetInfo(static_cast<unsigned long>(value)); +} + +WebGLGetInfo WebGLRenderingContext::getWebGLFloatArrayParameter(unsigned long pname) +{ + float value[4] = {0}; + m_context->getFloatv(pname, value); + unsigned length = 0; + switch (pname) { + case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE: + case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE: + case GraphicsContext3D::DEPTH_RANGE: + length = 2; + break; + case GraphicsContext3D::BLEND_COLOR: + case GraphicsContext3D::COLOR_CLEAR_VALUE: + length = 4; + break; + default: + notImplemented(); + } + return WebGLGetInfo(WebGLFloatArray::create(value, length)); +} + +WebGLGetInfo WebGLRenderingContext::getWebGLIntArrayParameter(unsigned long pname) +{ + int value[4] = {0}; + m_context->getIntegerv(pname, value); + unsigned length = 0; + switch (pname) { + case GraphicsContext3D::MAX_VIEWPORT_DIMS: + length = 2; + break; + case GraphicsContext3D::SCISSOR_BOX: + case GraphicsContext3D::VIEWPORT: + length = 4; + break; + default: + notImplemented(); + } + return WebGLGetInfo(WebGLIntArray::create(value, length)); +} + +WebGLGetInfo WebGLRenderingContext::getWebGLUnsignedByteArrayParameter(unsigned long pname) +{ + unsigned char value[4] = {0}; + m_context->getBooleanv(pname, value); + unsigned length = 0; + switch (pname) { + case GraphicsContext3D::COLOR_WRITEMASK: + length = 4; + break; + default: + notImplemented(); + } + return WebGLGetInfo(WebGLUnsignedByteArray::create(value, length)); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLRenderingContext.h b/WebCore/html/canvas/WebGLRenderingContext.h new file mode 100644 index 0000000..3335eba --- /dev/null +++ b/WebCore/html/canvas/WebGLRenderingContext.h @@ -0,0 +1,355 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLRenderingContext_h +#define WebGLRenderingContext_h + +#include "CanvasRenderingContext.h" +#include "ExceptionCode.h" +#include "WebGLFloatArray.h" +#include "WebGLGetInfo.h" +#include "WebGLIntArray.h" +#include "WebGLUnsignedByteArray.h" +#include "GraphicsContext3D.h" +#include "PlatformString.h" + +namespace WebCore { + +class WebGLActiveInfo; +class WebGLBuffer; +class WebGLFramebuffer; +class CanvasObject; +class WebGLProgram; +class WebGLRenderbuffer; +class WebGLShader; +class WebGLTexture; +class WebGLUniformLocation; +class HTMLImageElement; +class HTMLVideoElement; +class ImageData; +class WebKitCSSMatrix; + + class WebGLRenderingContext : public CanvasRenderingContext { + public: + static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*); + virtual ~WebGLRenderingContext(); + + virtual bool is3d() const { return true; } + + // Helper to return the size in bytes of OpenGL data types + // like GL_FLOAT, GL_INT, etc. + int sizeInBytes(int type, ExceptionCode& ec); + + void activeTexture(unsigned long texture, ExceptionCode& ec); + void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec); + void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name, ExceptionCode& ec); + void bindBuffer(unsigned long target, WebGLBuffer*, ExceptionCode& ec); + void bindFramebuffer(unsigned long target, WebGLFramebuffer*, ExceptionCode& ec); + void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*, ExceptionCode& ec); + void bindTexture(unsigned long target, WebGLTexture*, ExceptionCode& ec); + void blendColor(double red, double green, double blue, double alpha); + void blendEquation(unsigned long mode); + void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha); + void blendFunc(unsigned long sfactor, unsigned long dfactor); + void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha); + + void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&); + void bufferData(unsigned long target, WebGLArray* data, unsigned long usage, ExceptionCode&); + void bufferSubData(unsigned long target, long offset, WebGLArray* data, ExceptionCode&); + + unsigned long checkFramebufferStatus(unsigned long target); + void clear(unsigned long mask); + void clearColor(double red, double green, double blue, double alpha); + void clearDepth(double); + void clearStencil(long); + void colorMask(bool red, bool green, bool blue, bool alpha); + void compileShader(WebGLShader*, ExceptionCode& ec); + + //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data); + //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data); + + void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border); + void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height); + + PassRefPtr<WebGLBuffer> createBuffer(); + PassRefPtr<WebGLFramebuffer> createFramebuffer(); + PassRefPtr<WebGLProgram> createProgram(); + PassRefPtr<WebGLRenderbuffer> createRenderbuffer(); + PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&); + PassRefPtr<WebGLTexture> createTexture(); + + void cullFace(unsigned long mode); + + void deleteBuffer(WebGLBuffer*); + void deleteFramebuffer(WebGLFramebuffer*); + void deleteProgram(WebGLProgram*); + void deleteRenderbuffer(WebGLRenderbuffer*); + void deleteShader(WebGLShader*); + void deleteTexture(WebGLTexture*); + + void depthFunc(unsigned long); + void depthMask(bool); + void depthRange(double zNear, double zFar); + void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&); + void disable(unsigned long cap); + void disableVertexAttribArray(unsigned long index, ExceptionCode&); + void drawArrays(unsigned long mode, long first, long count, ExceptionCode&); + void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset, ExceptionCode&); + + void enable(unsigned long cap); + void enableVertexAttribArray(unsigned long index, ExceptionCode&); + void finish(); + void flush(); + void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec); + void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec); + void frontFace(unsigned long mode); + void generateMipmap(unsigned long target); + + PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&); + PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&); + + int getAttribLocation(WebGLProgram*, const String& name); + + WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + unsigned long getError(); + + WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&); + + WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&); + + WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&); + + String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec); + + WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec); + + String getShaderInfoLog(WebGLShader*, ExceptionCode& ec); + + // TBD + // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); + + String getShaderSource(WebGLShader*, ExceptionCode&); + String getString(unsigned long name); + + WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&); + + WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&); + + PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&); + + WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&); + + long getVertexAttribOffset(unsigned long index, unsigned long pname); + + void hint(unsigned long target, unsigned long mode); + bool isBuffer(WebGLBuffer*); + bool isEnabled(unsigned long cap); + bool isFramebuffer(WebGLFramebuffer*); + bool isProgram(WebGLProgram*); + bool isRenderbuffer(WebGLRenderbuffer*); + bool isShader(WebGLShader*); + bool isTexture(WebGLTexture*); + void lineWidth(double); + void linkProgram(WebGLProgram*, ExceptionCode&); + void pixelStorei(unsigned long pname, long param); + void polygonOffset(double factor, double units); + + PassRefPtr<WebGLArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type); + + void releaseShaderCompiler(); + void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height); + void sampleCoverage(double value, bool invert); + void scissor(long x, long y, unsigned long width, unsigned long height); + void shaderSource(WebGLShader*, const String&, ExceptionCode&); + void stencilFunc(unsigned long func, long ref, unsigned long mask); + void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask); + void stencilMask(unsigned long); + void stencilMaskSeparate(unsigned long face, unsigned long mask); + void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass); + void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass); + + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + + void texParameterf(unsigned target, unsigned pname, float param); + void texParameteri(unsigned target, unsigned pname, int param); + + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, WebGLArray* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, ImageData* pixels, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha, ExceptionCode&); + + void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&); + void uniform1fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); + void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&); + void uniform1iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&); + void uniform2fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); + void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&); + void uniform2iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&); + void uniform3fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); + void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&); + void uniform3iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&); + void uniform4fv(const WebGLUniformLocation* location, WebGLFloatArray* v, ExceptionCode&); + void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&); + void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&); + void uniform4iv(const WebGLUniformLocation* location, WebGLIntArray* v, ExceptionCode&); + void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&); + void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* value, ExceptionCode&); + void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); + void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* value, ExceptionCode&); + void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); + void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, WebGLFloatArray* value, ExceptionCode&); + void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&); + + void useProgram(WebGLProgram*, ExceptionCode&); + void validateProgram(WebGLProgram*, ExceptionCode&); + + void vertexAttrib1f(unsigned long indx, float x); + void vertexAttrib1fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib1fv(unsigned long indx, float* values, int size); + void vertexAttrib2f(unsigned long indx, float x, float y); + void vertexAttrib2fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib2fv(unsigned long indx, float* values, int size); + void vertexAttrib3f(unsigned long indx, float x, float y, float z); + void vertexAttrib3fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib3fv(unsigned long indx, float* values, int size); + void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w); + void vertexAttrib4fv(unsigned long indx, WebGLFloatArray* values); + void vertexAttrib4fv(unsigned long indx, float* values, int size); + void vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, + unsigned long stride, unsigned long offset, ExceptionCode&); + + void viewport(long x, long y, unsigned long width, unsigned long height); + + GraphicsContext3D* graphicsContext3D() const { return m_context.get(); } + + void reshape(int width, int height); + + // Helpers for notification about paint events. + void beginPaint(); + void endPaint(); + + void removeObject(CanvasObject*); + + private: + friend class CanvasObject; + + WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>); + + void addObject(CanvasObject*); + void detachAndRemoveAllObjects(); + + void markContextChanged(); + void cleanupAfterGraphicsCall(bool changed) + { + if (changed) + markContextChanged(); + } + + bool validateIndexArray(unsigned long count, unsigned long type, long offset, long& numElements); + bool validateRenderingState(long numElements); + + OwnPtr<GraphicsContext3D> m_context; + bool m_needsUpdate; + bool m_markedCanvasDirty; + // FIXME: I think this is broken -- it does not increment any + // reference counts, so may refer to destroyed objects. + HashSet<RefPtr<CanvasObject> > m_canvasObjects; + + // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER + RefPtr<WebGLBuffer> m_boundArrayBuffer; + RefPtr<WebGLBuffer> m_boundElementArrayBuffer; + + // Cached values for vertex attrib range checks + class VertexAttribState { + public: + VertexAttribState() : enabled(false), numElements(0) { } + bool enabled; + long numElements; + }; + + Vector<VertexAttribState> m_vertexAttribState; + unsigned m_maxVertexAttribs; + + RefPtr<WebGLProgram> m_currentProgram; + RefPtr<WebGLFramebuffer> m_framebufferBinding; + RefPtr<WebGLRenderbuffer> m_renderbufferBinding; + class TextureUnitState { + public: + RefPtr<WebGLTexture> m_texture2DBinding; + RefPtr<WebGLTexture> m_textureCubeMapBinding; + }; + TextureUnitState m_textureUnits[32]; + unsigned long m_activeTextureUnit; + + // Helpers for getParameter and others + WebGLGetInfo getBooleanParameter(unsigned long pname); + WebGLGetInfo getFloatParameter(unsigned long pname); + WebGLGetInfo getIntParameter(unsigned long pname); + WebGLGetInfo getLongParameter(unsigned long pname); + WebGLGetInfo getUnsignedLongParameter(unsigned long pname); + WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname); + WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname); + WebGLGetInfo getWebGLUnsignedByteArrayParameter(unsigned long pname); + + friend class WebGLStateRestorer; + }; + +} // namespace WebCore + +#endif diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.idl b/WebCore/html/canvas/WebGLRenderingContext.idl index db0fff3..78de8c8 100644 --- a/WebCore/html/canvas/CanvasRenderingContext3D.idl +++ b/WebCore/html/canvas/WebGLRenderingContext.idl @@ -30,7 +30,7 @@ module html { GenerateConstructor, InterfaceUUID=98fb48ae-7216-489c-862b-8e1217fc4443, ImplementationUUID=ab4f0781-152f-450e-9546-5b3987491a54 - ] CanvasRenderingContext3D : CanvasRenderingContext { + ] WebGLRenderingContext : CanvasRenderingContext { /* ClearBufferMask */ const unsigned int DEPTH_BUFFER_BIT = 0x00000100; @@ -460,25 +460,26 @@ module html { long sizeInBytes(in unsigned long type) raises(DOMException); - void activeTexture(in unsigned long texture); - void attachShader(in CanvasProgram program, in CanvasShader shader); - void bindAttribLocation(in CanvasProgram program, in unsigned long index, in DOMString name); - void bindBuffer(in unsigned long target, in CanvasBuffer buffer); - void bindFramebuffer(in unsigned long target, in CanvasFramebuffer framebuffer); - void bindRenderbuffer(in unsigned long target, in CanvasRenderbuffer renderbuffer); - void bindTexture(in unsigned long target, in CanvasTexture texture); + void activeTexture(in unsigned long texture) raises(DOMException); + void attachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); + void bindAttribLocation(in WebGLProgram program, in unsigned long index, in DOMString name) raises(DOMException); + void bindBuffer(in unsigned long target, in WebGLBuffer buffer) raises(DOMException); + void bindFramebuffer(in unsigned long target, in WebGLFramebuffer framebuffer) raises(DOMException); + void bindRenderbuffer(in unsigned long target, in WebGLRenderbuffer renderbuffer) raises(DOMException); + void bindTexture(in unsigned long target, in WebGLTexture texture) raises(DOMException); void blendColor(in double red, in double green, in double blue, in double alpha); void blendEquation( in unsigned long mode ); void blendEquationSeparate(in unsigned long modeRGB, in unsigned long modeAlpha); void blendFunc(in unsigned long sfactor, in unsigned long dfactor); void blendFuncSeparate(in unsigned long srcRGB, in unsigned long dstRGB, in unsigned long srcAlpha, in unsigned long dstAlpha); + // Supported forms: // void bufferData (in GLenum target, in GLsizei size, in GLenum usage); - // void bufferData (in GLenum target, in CanvasArray data, in GLenum usage); - [Custom] void bufferData(); + // void bufferData (in GLenum target, in WebGLArray data, in GLenum usage); + [Custom] void bufferData() raises(DOMException); // Supported forms: - // void bufferSubData (in GLenum target, in GLsizeiptr offset, in CanvasArray data); - [Custom] void bufferSubData(); + // void bufferSubData (in GLenum target, in GLsizeiptr offset, in WebGLArray data); + [Custom] void bufferSubData() raises(DOMException); unsigned long checkFramebufferStatus(in unsigned long target); void clear(in unsigned long mask); @@ -486,7 +487,7 @@ module html { void clearDepth(in double depth); void clearStencil(in long s); void colorMask(in boolean red, in boolean green, in boolean blue, in boolean alpha); - void compileShader(in CanvasShader shader); + void compileShader(in WebGLShader shader) raises(DOMException); //void compressedTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in unsigned long width, in unsigned long height, in long border, in unsigned long imageSize, const void* data); //void compressedTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long imageSize, const void* data); @@ -494,119 +495,108 @@ module html { void copyTexImage2D(in unsigned long target, in long level, in unsigned long internalformat, in long x, in long y, in unsigned long width, in unsigned long height, in long border); void copyTexSubImage2D(in unsigned long target, in long level, in long xoffset, in long yoffset, in long x, in long y, in unsigned long width, in unsigned long height); - CanvasBuffer createBuffer(); - CanvasFramebuffer createFramebuffer(); - CanvasProgram createProgram(); - CanvasRenderbuffer createRenderbuffer(); - CanvasShader createShader(in unsigned long type); - CanvasTexture createTexture(); + WebGLBuffer createBuffer(); + WebGLFramebuffer createFramebuffer(); + WebGLProgram createProgram(); + WebGLRenderbuffer createRenderbuffer(); + WebGLShader createShader(in unsigned long type) raises(DOMException); + WebGLTexture createTexture(); void cullFace(in unsigned long mode); - void deleteBuffer(in CanvasBuffer buffer); - void deleteFramebuffer(in CanvasFramebuffer framebuffer); - void deleteProgram(in CanvasProgram program); - void deleteRenderbuffer(in CanvasRenderbuffer renderbuffer); - void deleteShader(in CanvasShader shader); - void deleteTexture(in CanvasTexture texture); + void deleteBuffer(in WebGLBuffer buffer); + void deleteFramebuffer(in WebGLFramebuffer framebuffer); + void deleteProgram(in WebGLProgram program); + void deleteRenderbuffer(in WebGLRenderbuffer renderbuffer); + void deleteShader(in WebGLShader shader); + void deleteTexture(in WebGLTexture texture); void depthFunc(in unsigned long func); void depthMask(in boolean flag); // FIXME: this differs from the current WebGL spec (depthRangef) void depthRange(in double zNear, in double zFar); - void detachShader(in CanvasProgram program, in CanvasShader shader); + void detachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException); void disable(in unsigned long cap); - void disableVertexAttribArray(in unsigned long index); - void drawArrays(in unsigned long mode, in long first, in unsigned long count); - void drawElements (in unsigned long mode, in long count, in unsigned long type, in unsigned long offset); + void disableVertexAttribArray(in unsigned long index) raises(DOMException); + void drawArrays(in unsigned long mode, in long first, in unsigned long count) raises(DOMException); + void drawElements (in unsigned long mode, in long count, in unsigned long type, in unsigned long offset) raises(DOMException); void enable(in unsigned long cap); - void enableVertexAttribArray(in unsigned long index); + void enableVertexAttribArray(in unsigned long index) raises(DOMException); void finish(); void flush(); - void framebufferRenderbuffer(in unsigned long target, in unsigned long attachment, in unsigned long renderbuffertarget, in CanvasRenderbuffer renderbuffer); - void framebufferTexture2D(in unsigned long target, in unsigned long attachment, in unsigned long textarget, in CanvasTexture texture, in long level); + void framebufferRenderbuffer(in unsigned long target, in unsigned long attachment, in unsigned long renderbuffertarget, in WebGLRenderbuffer renderbuffer) raises(DOMException); + void framebufferTexture2D(in unsigned long target, in unsigned long attachment, in unsigned long textarget, in WebGLTexture texture, in long level) raises(DOMException); void frontFace(in unsigned long mode); void generateMipmap(in unsigned long target); - // FIXME: these need to be added per the WebGL spec - CanvasActiveInfo getActiveAttrib(in CanvasProgram program, in unsigned long index) + WebGLActiveInfo getActiveAttrib(in WebGLProgram program, in unsigned long index) raises (DOMException); - CanvasActiveInfo getActiveUniform(in CanvasProgram program, in unsigned long index) + WebGLActiveInfo getActiveUniform(in WebGLProgram program, in unsigned long index) raises (DOMException); - // CanvasShaderArray glGetAttachedShaders(GLuint program); + // WebGLShaderArray glGetAttachedShaders(GLuint program); - int getAttribLocation(in CanvasProgram program, in DOMString name); + int getAttribLocation(in WebGLProgram program, in DOMString name); - boolean getBoolean(in unsigned long pname); - CanvasUnsignedByteArray getBooleanv(in unsigned long pname); - long getBufferParameteri(in unsigned long target, in unsigned long pname); - CanvasIntArray getBufferParameteriv(in unsigned long target, in unsigned long pname); + // any getBufferParameter(in unsigned long target, in unsigned long pname) raises(DOMException); + [Custom] void getBufferParameter(); unsigned long getError(); - float getFloat(in unsigned long pname); - CanvasFloatArray getFloatv(in unsigned long pname); - long getFramebufferAttachmentParameteri(in unsigned long target, in unsigned long attachment, in unsigned long pname); - CanvasIntArray getFramebufferAttachmentParameteriv(in unsigned long target, in unsigned long attachment, in unsigned long pname); - long getInteger(in unsigned long pname); - CanvasIntArray getIntegerv(in unsigned long pname); - long getProgrami(in CanvasProgram program, in unsigned long pname); - CanvasIntArray getProgramiv(in CanvasProgram program, in unsigned long pname); - DOMString getProgramInfoLog(in CanvasProgram program); - long getRenderbufferParameteri(in unsigned long target, in unsigned long pname); - CanvasIntArray getRenderbufferParameteriv(in unsigned long target, in unsigned long pname); - long getShaderi(in CanvasShader shader, in unsigned long pname); - CanvasIntArray getShaderiv(in CanvasShader shader, in unsigned long pname); - - DOMString getShaderInfoLog(in CanvasShader shader); + // any getFramebufferAttachmentParameter(in unsigned long target, in unsigned long attachment, in unsigned long pname) raises(DOMException); + [Custom] void getFramebufferAttachmentParameter(); + // any getParameter(in unsigned long pname) raises(DOMException); + [Custom] void getParameter(); + // any getProgramParameter(in WebGLProgram program, in unsigned long pname) raises(DOMException); + [Custom] void getProgramParameter(); + DOMString getProgramInfoLog(in WebGLProgram program) raises(DOMException); + // any getRenderbufferParameter(in unsigned long target, in unsigned long pname) raises(DOMException); + [Custom] void getRenderbufferParameter(); + // any getShaderParameter(in WebGLShader shader, in unsigned long pname) raises(DOMException); + [Custom] void getShaderParameter() raises(DOMException); + + DOMString getShaderInfoLog(in WebGLShader shader) raises(DOMException); // TBD // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); - DOMString getShaderSource(in CanvasShader shader); + DOMString getShaderSource(in WebGLShader shader) raises(DOMException); DOMString getString(in unsigned long name); - float getTexParameterf(in unsigned long target, in unsigned long pname); - CanvasFloatArray getTexParameterfv(in unsigned long target, in unsigned long pname); - long getTexParameteri(in unsigned long target, in unsigned long pname); - CanvasIntArray getTexParameteriv(in unsigned long target, in unsigned long pname); + // any getTexParameter(in unsigned long target, in unsigned long pname) raises(DOMException); + [Custom] void getTexParameter(); - float getUniformf(in CanvasProgram program, in long location); - CanvasFloatArray getUniformfv(in CanvasProgram program, in long location); - long getUniformi(in CanvasProgram program, in long location); - CanvasIntArray getUniformiv(in CanvasProgram program, in long location); - - long getUniformLocation(in CanvasProgram program, in DOMString name); + // any getUniform(in WebGLProgram program, in WebGLUniformLocation location) raises(DOMException); + [Custom] void getUniform(); - float getVertexAttribf(in unsigned long index, in unsigned long pname); - CanvasFloatArray getVertexAttribfv(in unsigned long index, in unsigned long pname); - long getVertexAttribi(in unsigned long index, in unsigned long pname); - CanvasIntArray getVertexAttribiv(in unsigned long index, in unsigned long pname); + WebGLUniformLocation getUniformLocation(in WebGLProgram program, in DOMString name) raises(DOMException); + + // any getVertexAttrib(in unsigned long index, in unsigned long pname) raises(DOMException); + [Custom] void getVertexAttrib(); long getVertexAttribOffset(in unsigned long index, in unsigned long pname); void hint(in unsigned long target, in unsigned long mode); - boolean isBuffer(in CanvasBuffer buffer); + boolean isBuffer(in WebGLBuffer buffer); boolean isEnabled(in unsigned long cap); - boolean isFramebuffer(in CanvasFramebuffer framebuffer); - boolean isProgram(in CanvasProgram program); - boolean isRenderbuffer(in CanvasRenderbuffer renderbuffer); - boolean isShader(in CanvasShader shader); - boolean isTexture(in CanvasTexture texture); + boolean isFramebuffer(in WebGLFramebuffer framebuffer); + boolean isProgram(in WebGLProgram program); + boolean isRenderbuffer(in WebGLRenderbuffer renderbuffer); + boolean isShader(in WebGLShader shader); + boolean isTexture(in WebGLTexture texture); void lineWidth(in double width); - void linkProgram(in CanvasProgram program); + void linkProgram(in WebGLProgram program) raises(DOMException); void pixelStorei(in unsigned long pname, in long param); void polygonOffset(in double factor, in double units); - - CanvasArray readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type); + + WebGLArray readPixels(in long x, in long y, in unsigned long width, in unsigned long height, in unsigned long format, in unsigned long type); void releaseShaderCompiler(); void renderbufferStorage(in unsigned long target, in unsigned long internalformat, in unsigned long width, in unsigned long height); void sampleCoverage(in double value, in boolean invert); void scissor(in long x, in long y, in unsigned long width, in unsigned long height); - void shaderSource(in CanvasShader shader, in DOMString string); + void shaderSource(in WebGLShader shader, in DOMString string) raises(DOMException); void stencilFunc(in unsigned long func, in long ref, in unsigned long mask); void stencilFuncSeparate(in unsigned long face, in unsigned long func, in long ref, in unsigned long mask); void stencilMask(in unsigned long mask); @@ -619,7 +609,7 @@ module html { // Supported forms: // void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, - // in GLint border, in GLenum format, in GLenum type, in CanvasArray pixels); + // in GLint border, in GLenum format, in GLenum type, in WebGLArray pixels); // void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, // in GLint border, in GLenum format, in GLenum type, in ImageData pixels); // void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image, @@ -633,7 +623,7 @@ module html { // Supported forms: // void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, // in GLsizei width, in GLsizei height, - // in GLenum format, in GLenum type, in CanvasArray pixels); + // in GLenum format, in GLenum type, in WebGLArray pixels); // void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, // in GLsizei width, in GLsizei height, // in GLenum format, in GLenum type, in ImageData pixels); @@ -648,40 +638,40 @@ module html { // [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); [Custom] void texSubImage2D(); - void uniform1f(in long location, in float x); - [Custom] void uniform1fv(in long location, in CanvasFloatArray v); - void uniform1i(in long location, in long x); - [Custom] void uniform1iv(in long location, in CanvasIntArray v); - void uniform2f(in long location, in float x, in float y); - [Custom] void uniform2fv(in long location, in CanvasFloatArray v); - void uniform2i(in long location, in long x, in long y); - [Custom] void uniform2iv(in long location, in CanvasIntArray v); - void uniform3f(in long location, in float x, in float y, in float z); - [Custom] void uniform3fv(in long location, in CanvasFloatArray v); - void uniform3i(in long location, in long x, in long y, in long z); - [Custom] void uniform3iv(in long location, in CanvasIntArray v); - void uniform4f(in long location, in float x, in float y, in float z, in float w); - [Custom] void uniform4fv(in long location, in CanvasFloatArray v); - void uniform4i(in long location, in long x, in long y, in long z, in long w); - [Custom] void uniform4iv(in long location, in CanvasIntArray v); - - [Custom] void uniformMatrix2fv(in long location, in boolean transpose, in CanvasFloatArray array); - [Custom] void uniformMatrix3fv(in long location, in boolean transpose, in CanvasFloatArray array); - [Custom] void uniformMatrix4fv(in long location, in boolean transpose, in CanvasFloatArray array); - - void useProgram(in CanvasProgram program); - void validateProgram(in CanvasProgram program); + void uniform1f(in WebGLUniformLocation location, in float x) raises(DOMException); + [Custom] void uniform1fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + void uniform1i(in WebGLUniformLocation location, in long x) raises(DOMException); + [Custom] void uniform1iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + void uniform2f(in WebGLUniformLocation location, in float x, in float y) raises(DOMException); + [Custom] void uniform2fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + void uniform2i(in WebGLUniformLocation location, in long x, in long y) raises(DOMException); + [Custom] void uniform2iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + void uniform3f(in WebGLUniformLocation location, in float x, in float y, in float z) raises(DOMException); + [Custom] void uniform3fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + void uniform3i(in WebGLUniformLocation location, in long x, in long y, in long z) raises(DOMException); + [Custom] void uniform3iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + void uniform4f(in WebGLUniformLocation location, in float x, in float y, in float z, in float w) raises(DOMException); + [Custom] void uniform4fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException); + void uniform4i(in WebGLUniformLocation location, in long x, in long y, in long z, in long w) raises(DOMException); + [Custom] void uniform4iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException); + + [Custom] void uniformMatrix2fv(in WebGLUniformLocation location, in boolean transpose, in WebGLFloatArray array) raises(DOMException); + [Custom] void uniformMatrix3fv(in WebGLUniformLocation location, in boolean transpose, in WebGLFloatArray array) raises(DOMException); + [Custom] void uniformMatrix4fv(in WebGLUniformLocation location, in boolean transpose, in WebGLFloatArray array) raises(DOMException); + + void useProgram(in WebGLProgram program) raises(DOMException); + void validateProgram(in WebGLProgram program) raises(DOMException); void vertexAttrib1f(in unsigned long indx, in float x); - [Custom] void vertexAttrib1fv(in unsigned long indx, in CanvasFloatArray values); + [Custom] void vertexAttrib1fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttrib2f(in unsigned long indx, in float x, in float y); - [Custom] void vertexAttrib2fv(in unsigned long indx, in CanvasFloatArray values); + [Custom] void vertexAttrib2fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttrib3f(in unsigned long indx, in float x, in float y, in float z); - [Custom] void vertexAttrib3fv(in unsigned long indx, in CanvasFloatArray values); + [Custom] void vertexAttrib3fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttrib4f(in unsigned long indx, in float x, in float y, in float z, in float w); - [Custom] void vertexAttrib4fv(in unsigned long indx, in CanvasFloatArray values); + [Custom] void vertexAttrib4fv(in unsigned long indx, in WebGLFloatArray values); void vertexAttribPointer(in unsigned long indx, in long size, in unsigned long type, in boolean normalized, - in long stride, in unsigned long offset); + in long stride, in unsigned long offset) raises(DOMException); void viewport(in long x, in long y, in unsigned long width, in unsigned long height); }; diff --git a/WebCore/html/canvas/CanvasShader.cpp b/WebCore/html/canvas/WebGLShader.cpp index 7f134fa..a353b15 100644 --- a/WebCore/html/canvas/CanvasShader.cpp +++ b/WebCore/html/canvas/WebGLShader.cpp @@ -27,23 +27,23 @@ #if ENABLE(3D_CANVAS) -#include "CanvasShader.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLShader.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasShader> CanvasShader::create(CanvasRenderingContext3D* ctx, GraphicsContext3D::ShaderType type) +PassRefPtr<WebGLShader> WebGLShader::create(WebGLRenderingContext* ctx, GraphicsContext3D::WebGLEnumType type) { - return adoptRef(new CanvasShader(ctx, type)); + return adoptRef(new WebGLShader(ctx, type)); } -CanvasShader::CanvasShader(CanvasRenderingContext3D* ctx, GraphicsContext3D::ShaderType type) +WebGLShader::WebGLShader(WebGLRenderingContext* ctx, GraphicsContext3D::WebGLEnumType type) : CanvasObject(ctx) { setObject(context()->graphicsContext3D()->createShader(type)); } -void CanvasShader::_deleteObject(Platform3DObject object) +void WebGLShader::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteShader(object); } diff --git a/WebCore/html/canvas/CanvasShader.h b/WebCore/html/canvas/WebGLShader.h index bb7980e..1ef912c 100644 --- a/WebCore/html/canvas/CanvasShader.h +++ b/WebCore/html/canvas/WebGLShader.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasShader_h -#define CanvasShader_h +#ifndef WebGLShader_h +#define WebGLShader_h #include "CanvasObject.h" @@ -33,18 +33,18 @@ namespace WebCore { - class CanvasShader : public CanvasObject { + class WebGLShader : public CanvasObject { public: - virtual ~CanvasShader() { deleteObject(); } + virtual ~WebGLShader() { deleteObject(); } - static PassRefPtr<CanvasShader> create(CanvasRenderingContext3D*, GraphicsContext3D::ShaderType); + static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); private: - CanvasShader(CanvasRenderingContext3D*, GraphicsContext3D::ShaderType); + WebGLShader(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType); virtual void _deleteObject(Platform3DObject); }; } // namespace WebCore -#endif // CanvasShader_h +#endif // WebGLShader_h diff --git a/WebCore/html/canvas/CanvasTexture.idl b/WebCore/html/canvas/WebGLShader.idl index 77eedd7..45e7f54 100644 --- a/WebCore/html/canvas/CanvasTexture.idl +++ b/WebCore/html/canvas/WebGLShader.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasTexture { + interface [Conditional=3D_CANVAS] WebGLShader { }; } diff --git a/WebCore/html/canvas/WebGLShortArray.cpp b/WebCore/html/canvas/WebGLShortArray.cpp new file mode 100644 index 0000000..f96a290 --- /dev/null +++ b/WebCore/html/canvas/WebGLShortArray.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLArrayBuffer.h" +#include "WebGLShortArray.h" + +namespace WebCore { + +PassRefPtr<WebGLShortArray> WebGLShortArray::create(unsigned length) +{ + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(short)); + return create(buffer, 0, length); +} + +PassRefPtr<WebGLShortArray> WebGLShortArray::create(short* array, unsigned length) +{ + RefPtr<WebGLShortArray> a = WebGLShortArray::create(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; +} + +PassRefPtr<WebGLShortArray> WebGLShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(short)) != 0) + return NULL; + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(short))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLShortArray(buffer, byteOffset, length)); +} + +WebGLShortArray::WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) + : WebGLArray(buffer, byteOffset) + , m_size(length) +{ +} + +unsigned WebGLShortArray::length() const { + return m_size; +} + +unsigned WebGLShortArray::byteLength() const { + return m_size * sizeof(short); +} + +PassRefPtr<WebGLArray> WebGLShortArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(short); + unsigned limitByte = startByte + length * sizeof(short); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLShortArray::set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(short), ec); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLShortArray.h b/WebCore/html/canvas/WebGLShortArray.h new file mode 100644 index 0000000..70c66ca --- /dev/null +++ b/WebCore/html/canvas/WebGLShortArray.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLShortArray_h +#define WebGLShortArray_h + +#include "WebGLArray.h" +#include <limits> +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLShortArray : public WebGLArray { + public: + virtual bool isShortArray() const { return true; } + + static PassRefPtr<WebGLShortArray> create(unsigned length); + static PassRefPtr<WebGLShortArray> create(short* array, unsigned length); + static PassRefPtr<WebGLShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + short* data() { return static_cast<short*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<short>::min()) + value = std::numeric_limits<short>::min(); + else if (value > std::numeric_limits<short>::max()) + value = std::numeric_limits<short>::max(); + short* storage = static_cast<short*>(m_baseAddress); + storage[index] = static_cast<short>(value); + } + + bool get(unsigned index, short& result) const + { + if (index >= m_size) + return false; + result = item(index); + return true; + } + + short get(unsigned index) const + { + return item(index); + } + + short item(unsigned index) const + { + ASSERT(index < m_size); + short* storage = static_cast<short*>(m_baseAddress); + return storage[index]; + } + + void set(WebGLShortArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLShortArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLShortArray_h diff --git a/WebCore/html/canvas/CanvasFloatArray.idl b/WebCore/html/canvas/WebGLShortArray.idl index bb236b9..bd8380f 100644 --- a/WebCore/html/canvas/CanvasFloatArray.idl +++ b/WebCore/html/canvas/WebGLShortArray.idl @@ -31,6 +31,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasFloatArray : CanvasArray { + ] WebGLShortArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLShortArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/CanvasTexture.cpp b/WebCore/html/canvas/WebGLTexture.cpp index 624c275..ae09b48 100644 --- a/WebCore/html/canvas/CanvasTexture.cpp +++ b/WebCore/html/canvas/WebGLTexture.cpp @@ -27,24 +27,36 @@ #if ENABLE(3D_CANVAS) -#include "CanvasTexture.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLTexture.h" +#include "WebGLRenderingContext.h" namespace WebCore { -PassRefPtr<CanvasTexture> CanvasTexture::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx) { - return adoptRef(new CanvasTexture(ctx)); + return adoptRef(new WebGLTexture(ctx)); } -CanvasTexture::CanvasTexture(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx, Platform3DObject obj) +{ + return adoptRef(new WebGLTexture(ctx, obj)); +} + +WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) : CanvasObject(ctx) , cubeMapRWrapModeInitialized(false) { setObject(context()->graphicsContext3D()->createTexture()); } -void CanvasTexture::_deleteObject(Platform3DObject object) +WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx, Platform3DObject obj) + : CanvasObject(ctx) + , cubeMapRWrapModeInitialized(false) +{ + setObject(obj, false); +} + +void WebGLTexture::_deleteObject(Platform3DObject object) { context()->graphicsContext3D()->deleteTexture(object); } diff --git a/WebCore/html/canvas/CanvasTexture.h b/WebCore/html/canvas/WebGLTexture.h index 32a669a..c64dd41 100644 --- a/WebCore/html/canvas/CanvasTexture.h +++ b/WebCore/html/canvas/WebGLTexture.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasTexture_h -#define CanvasTexture_h +#ifndef WebGLTexture_h +#define WebGLTexture_h #include "CanvasObject.h" @@ -33,12 +33,16 @@ namespace WebCore { - class CanvasTexture : public CanvasObject { + class WebGLTexture : public CanvasObject { public: - virtual ~CanvasTexture() { deleteObject(); } + virtual ~WebGLTexture() { deleteObject(); } - static PassRefPtr<CanvasTexture> create(CanvasRenderingContext3D*); + static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*); + // For querying previously created objects via e.g. getFramebufferAttachmentParameter + // FIXME: should consider canonicalizing these objects + static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*, Platform3DObject); + bool isCubeMapRWrapModeInitialized() { return cubeMapRWrapModeInitialized; } @@ -48,7 +52,8 @@ namespace WebCore { } protected: - CanvasTexture(CanvasRenderingContext3D*); + WebGLTexture(WebGLRenderingContext*); + WebGLTexture(WebGLRenderingContext*, Platform3DObject); virtual void _deleteObject(Platform3DObject); @@ -58,4 +63,4 @@ namespace WebCore { } // namespace WebCore -#endif // CanvasTexture_h +#endif // WebGLTexture_h diff --git a/WebCore/html/canvas/CanvasProgram.idl b/WebCore/html/canvas/WebGLTexture.idl index 46daaf2..da7e066 100644 --- a/WebCore/html/canvas/CanvasProgram.idl +++ b/WebCore/html/canvas/WebGLTexture.idl @@ -24,6 +24,6 @@ */ module html { - interface [Conditional=3D_CANVAS] CanvasProgram { + interface [Conditional=3D_CANVAS] WebGLTexture { }; } diff --git a/WebCore/html/canvas/CanvasBuffer.cpp b/WebCore/html/canvas/WebGLUniformLocation.cpp index 009f8ad..2157470 100644 --- a/WebCore/html/canvas/CanvasBuffer.cpp +++ b/WebCore/html/canvas/WebGLUniformLocation.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,25 +28,19 @@ #if ENABLE(3D_CANVAS) -#include "CanvasBuffer.h" -#include "CanvasRenderingContext3D.h" +#include "WebGLUniformLocation.h" namespace WebCore { -PassRefPtr<CanvasBuffer> CanvasBuffer::create(CanvasRenderingContext3D* ctx) +PassRefPtr<WebGLUniformLocation> WebGLUniformLocation::create(WebGLProgram* program, long location) { - return adoptRef(new CanvasBuffer(ctx)); + return adoptRef(new WebGLUniformLocation(program, location)); } -CanvasBuffer::CanvasBuffer(CanvasRenderingContext3D* ctx) - : CanvasObject(ctx) +WebGLUniformLocation::WebGLUniformLocation(WebGLProgram* program, long location) + : m_program(program) + , m_location(location) { - setObject(context()->graphicsContext3D()->createBuffer()); -} - -void CanvasBuffer::_deleteObject(Platform3DObject object) -{ - context()->graphicsContext3D()->deleteBuffer(object); } } diff --git a/WebCore/html/canvas/CanvasBuffer.h b/WebCore/html/canvas/WebGLUniformLocation.h index 8fdab82..f9f7a11 100644 --- a/WebCore/html/canvas/CanvasBuffer.h +++ b/WebCore/html/canvas/WebGLUniformLocation.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,28 +24,35 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CanvasBuffer_h -#define CanvasBuffer_h +#ifndef WebGLUniformLocation_h +#define WebGLUniformLocation_h #include "CanvasObject.h" +#include "WebGLProgram.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { - - class CanvasBuffer : public CanvasObject { - public: - virtual ~CanvasBuffer() { deleteObject(); } - - static PassRefPtr<CanvasBuffer> create(CanvasRenderingContext3D*); - - protected: - CanvasBuffer(CanvasRenderingContext3D*); - - virtual void _deleteObject(Platform3DObject o); - }; - + +class WebGLUniformLocation : public RefCounted<WebGLUniformLocation> { +public: + virtual ~WebGLUniformLocation() { } + + static PassRefPtr<WebGLUniformLocation> create(WebGLProgram* program, long location); + + WebGLProgram* program() const { return m_program.get(); } + + long location() const { return m_location; } + +protected: + WebGLUniformLocation(WebGLProgram* program, long location); + +private: + RefPtr<WebGLProgram> m_program; + long m_location; +}; + } // namespace WebCore -#endif // CanvasBuffer_h +#endif // WebGLUniformLocation_h diff --git a/WebCore/html/canvas/WebGLUniformLocation.idl b/WebCore/html/canvas/WebGLUniformLocation.idl new file mode 100644 index 0000000..b080241 --- /dev/null +++ b/WebCore/html/canvas/WebGLUniformLocation.idl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module html { + interface [Conditional=3D_CANVAS] WebGLUniformLocation { + }; +} diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.cpp b/WebCore/html/canvas/WebGLUnsignedByteArray.cpp new file mode 100644 index 0000000..3fd1b50 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedByteArray.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLArrayBuffer.h" +#include "WebGLUnsignedByteArray.h" + +namespace WebCore { + +PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned length) +{ + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned char)); + return create(buffer, 0, length); +} + +PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(unsigned char* array, unsigned length) +{ + RefPtr<WebGLUnsignedByteArray> a = WebGLUnsignedByteArray::create(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; +} + +PassRefPtr<WebGLUnsignedByteArray> WebGLUnsignedByteArray::create(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length) +{ + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(unsigned char))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLUnsignedByteArray(buffer, byteOffset, length)); +} + +WebGLUnsignedByteArray::WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) + : WebGLArray(buffer, byteOffset) + , m_size(length) +{ +} + +unsigned WebGLUnsignedByteArray::length() const { + return m_size; +} + +unsigned WebGLUnsignedByteArray::byteLength() const { + return m_size * sizeof(unsigned char); +} + +PassRefPtr<WebGLArray> WebGLUnsignedByteArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(unsigned char); + unsigned limitByte = startByte + length * sizeof(unsigned char); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLUnsignedByteArray::set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(unsigned char), ec); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.h b/WebCore/html/canvas/WebGLUnsignedByteArray.h new file mode 100644 index 0000000..6909de5 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedByteArray.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLUnsignedByteArray_h +#define WebGLUnsignedByteArray_h + +#include "WebGLArray.h" +#include <limits> +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLUnsignedByteArray : public WebGLArray { + public: + virtual bool isUnsignedByteArray() const { return true; } + + static PassRefPtr<WebGLUnsignedByteArray> create(unsigned length); + static PassRefPtr<WebGLUnsignedByteArray> create(unsigned char* array, unsigned length); + static PassRefPtr<WebGLUnsignedByteArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + unsigned char* data() { return static_cast<unsigned char*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<unsigned char>::min()) + value = std::numeric_limits<unsigned char>::min(); + else if (value > std::numeric_limits<unsigned char>::max()) + value = std::numeric_limits<unsigned char>::max(); + unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); + storage[index] = static_cast<unsigned char>(value); + } + + bool get(unsigned index, unsigned char& result) const + { + if (index >= m_size) + return false; + result = item(index); + return true; + } + + unsigned char get(unsigned index) const + { + return item(index); + } + + unsigned char item(unsigned index) const + { + ASSERT(index < m_size); + unsigned char* storage = static_cast<unsigned char*>(m_baseAddress); + return storage[index]; + } + + void set(WebGLUnsignedByteArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLUnsignedByteArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLUnsignedByteArray_h diff --git a/WebCore/html/canvas/WebGLUnsignedByteArray.idl b/WebCore/html/canvas/WebGLUnsignedByteArray.idl new file mode 100644 index 0000000..57aa4ff --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedByteArray.idl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module html { + interface [ + Conditional=3D_CANVAS, + HasNumericIndexGetter, + HasCustomIndexSetter, + GenerateNativeConverter, + GenerateCustomConstructor, + CustomToJS + ] WebGLUnsignedByteArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLUnsignedByteArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); + }; +} diff --git a/WebCore/html/canvas/WebGLUnsignedIntArray.cpp b/WebCore/html/canvas/WebGLUnsignedIntArray.cpp new file mode 100644 index 0000000..97910f9 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedIntArray.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLArrayBuffer.h" +#include "WebGLUnsignedIntArray.h" + +namespace WebCore { + +PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned length) +{ + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned int)); + return create(buffer, 0, length); +} + +PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(unsigned int* array, unsigned length) +{ + RefPtr<WebGLUnsignedIntArray> a = WebGLUnsignedIntArray::create(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; +} + +PassRefPtr<WebGLUnsignedIntArray> WebGLUnsignedIntArray::create(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(unsigned int)) != 0) { + return NULL; + } + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(unsigned int))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLUnsignedIntArray(buffer, byteOffset, length)); +} + +WebGLUnsignedIntArray::WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length) + : WebGLArray(buffer, byteOffset) + , m_size(length) +{ +} + +unsigned WebGLUnsignedIntArray::length() const { + return m_size; +} + +unsigned WebGLUnsignedIntArray::byteLength() const { + return m_size * sizeof(unsigned int); +} + +PassRefPtr<WebGLArray> WebGLUnsignedIntArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(unsigned int); + unsigned limitByte = startByte + length * sizeof(unsigned int); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLUnsignedIntArray::set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(unsigned int), ec); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLUnsignedIntArray.h b/WebCore/html/canvas/WebGLUnsignedIntArray.h new file mode 100644 index 0000000..b0d9b65 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedIntArray.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLUnsignedIntArray_h +#define WebGLUnsignedIntArray_h + +#include "WebGLArray.h" +#include <limits> +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLUnsignedIntArray : public WebGLArray { + public: + virtual bool isUnsignedIntArray() const { return true; } + + static PassRefPtr<WebGLUnsignedIntArray> create(unsigned length); + static PassRefPtr<WebGLUnsignedIntArray> create(unsigned int* array, unsigned length); + static PassRefPtr<WebGLUnsignedIntArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + unsigned int* data() { return static_cast<unsigned int*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<unsigned int>::min()) + value = std::numeric_limits<unsigned int>::min(); + else if (value > std::numeric_limits<unsigned int>::max()) + value = std::numeric_limits<unsigned int>::max(); + unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); + storage[index] = static_cast<unsigned int>(value); + } + + bool get(unsigned index, unsigned int& result) const + { + if (index >= m_size) + return false; + result = item(index); + return true; + } + + unsigned int get(unsigned index) const + { + return item(index); + } + + unsigned int item(unsigned index) const + { + ASSERT(index < m_size); + unsigned int* storage = static_cast<unsigned int*>(m_baseAddress); + return storage[index]; + } + + void set(WebGLUnsignedIntArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLUnsignedIntArray(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLUnsignedIntArray_h diff --git a/WebCore/html/canvas/CanvasUnsignedIntArray.idl b/WebCore/html/canvas/WebGLUnsignedIntArray.idl index 3ab60d6..8697e70 100644 --- a/WebCore/html/canvas/CanvasUnsignedIntArray.idl +++ b/WebCore/html/canvas/WebGLUnsignedIntArray.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,6 +32,11 @@ module html { GenerateNativeConverter, GenerateCustomConstructor, CustomToJS - ] CanvasUnsignedIntArray : CanvasArray { + ] WebGLUnsignedIntArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLUnsignedIntArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); }; } diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.cpp b/WebCore/html/canvas/WebGLUnsignedShortArray.cpp new file mode 100644 index 0000000..86fae8c --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedShortArray.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "WebGLArrayBuffer.h" +#include "WebGLUnsignedShortArray.h" + +namespace WebCore { + +PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned length) +{ + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(length * sizeof(unsigned short)); + return create(buffer, 0, length); +} + +PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(unsigned short* array, unsigned length) +{ + RefPtr<WebGLUnsignedShortArray> a = WebGLUnsignedShortArray::create(length); + for (unsigned i = 0; i < length; ++i) + a->set(i, array[i]); + return a; +} + +PassRefPtr<WebGLUnsignedShortArray> WebGLUnsignedShortArray::create(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length) +{ + // Make sure the offset results in valid alignment. + if ((byteOffset % sizeof(unsigned short)) != 0) { + return NULL; + } + + if (buffer) { + // Check to make sure we are talking about a valid region of + // the given WebGLArrayBuffer's storage. + if ((byteOffset + (length * sizeof(unsigned short))) > buffer->byteLength()) + return NULL; + } + + return adoptRef(new WebGLUnsignedShortArray(buffer, byteOffset, length)); +} + +WebGLUnsignedShortArray::WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer, + int byteOffset, + unsigned length) + : WebGLArray(buffer, byteOffset) + , m_size(length) +{ +} + +unsigned WebGLUnsignedShortArray::length() const { + return m_size; +} + +unsigned WebGLUnsignedShortArray::byteLength() const { + return m_size * sizeof(unsigned short); +} + +PassRefPtr<WebGLArray> WebGLUnsignedShortArray::slice(unsigned offset, unsigned length) { + // Check to make sure the specified region is within the bounds of + // the WebGLArrayBuffer. + unsigned startByte = m_byteOffset + offset * sizeof(unsigned short); + unsigned limitByte = startByte + length * sizeof(unsigned short); + unsigned bufferLength = buffer()->byteLength(); + if (startByte >= bufferLength || limitByte > bufferLength) + return 0; + return create(buffer(), startByte, length); +} + +void WebGLUnsignedShortArray::set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec) { + setImpl(array, offset * sizeof(unsigned short), ec); +} + +} + +#endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.h b/WebCore/html/canvas/WebGLUnsignedShortArray.h new file mode 100644 index 0000000..3bad1b6 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedShortArray.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebGLUnsignedShortArray_h +#define WebGLUnsignedShortArray_h + +#include "WebGLArray.h" +#include <limits> +#include <wtf/MathExtras.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class WebGLUnsignedShortArray : public WebGLArray { + public: + virtual bool isUnsignedShortArray() const { return true; } + + static PassRefPtr<WebGLUnsignedShortArray> create(unsigned length); + static PassRefPtr<WebGLUnsignedShortArray> create(unsigned short* array, unsigned length); + static PassRefPtr<WebGLUnsignedShortArray> create(PassRefPtr<WebGLArrayBuffer> buffer, int byteOffset, unsigned length); + + unsigned short* data() { return static_cast<unsigned short*>(baseAddress()); } + + virtual unsigned length() const; + virtual unsigned byteLength() const; + virtual PassRefPtr<WebGLArray> slice(unsigned offset, unsigned length); + + void set(unsigned index, double value) + { + if (index >= m_size) + return; + if (isnan(value)) // Clamp NaN to 0 + value = 0; + if (value < std::numeric_limits<unsigned short>::min()) + value = std::numeric_limits<unsigned short>::min(); + else if (value > std::numeric_limits<unsigned short>::max()) + value = std::numeric_limits<unsigned short>::max(); + unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); + storage[index] = static_cast<unsigned short>(value); + } + + bool get(unsigned index, unsigned short& result) const + { + if (index >= m_size) + return false; + unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); + result = storage[index]; + return true; + } + + unsigned short get(unsigned index) const + { + return item(index); + } + + unsigned short item(unsigned index) const + { + ASSERT(index < m_size); + unsigned short* storage = static_cast<unsigned short*>(m_baseAddress); + return storage[index]; + } + + void set(WebGLUnsignedShortArray* array, unsigned offset, ExceptionCode& ec); + + private: + WebGLUnsignedShortArray(PassRefPtr<WebGLArrayBuffer> buffer,int byteOffset,unsigned length); + unsigned m_size; +}; + +} // namespace WebCore + +#endif // WebGLUnsignedShortArray_h diff --git a/WebCore/html/canvas/WebGLUnsignedShortArray.idl b/WebCore/html/canvas/WebGLUnsignedShortArray.idl new file mode 100644 index 0000000..d546444 --- /dev/null +++ b/WebCore/html/canvas/WebGLUnsignedShortArray.idl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module html { + interface [ + Conditional=3D_CANVAS, + HasNumericIndexGetter, + HasCustomIndexSetter, + GenerateNativeConverter, + GenerateCustomConstructor, + CustomToJS + ] WebGLUnsignedShortArray : WebGLArray { + long get(in unsigned long index); + // void set(in unsigned long index, in long value); + // void set(in WebGLUnsignedShortArray array, [Optional] in unsigned long offset); + // void set(in sequence<long> array, [Optional] in unsigned long offset); + [Custom] void set(); + }; +} |