1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "JSHTMLCanvasElement.h" 28 29 #include "CanvasContextAttributes.h" 30 #include "HTMLCanvasElement.h" 31 #include "JSCanvasRenderingContext2D.h" 32 #if ENABLE(3D_CANVAS) 33 #include "JSWebGLRenderingContext.h" 34 #include "WebGLContextAttributes.h" 35 #endif 36 #include <wtf/GetPtr.h> 37 38 using namespace JSC; 39 40 namespace WebCore { 41 42 void JSHTMLCanvasElement::markChildren(MarkStack& markStack) 43 { 44 Base::markChildren(markStack); 45 46 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); 47 JSGlobalData& globalData = *Heap::heap(this)->globalData(); 48 49 markDOMObjectWrapper(markStack, globalData, canvas->renderingContext()); 50 } 51 52 JSValue JSHTMLCanvasElement::getContext(ExecState* exec, const ArgList& args) 53 { 54 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); 55 const UString& contextId = args.at(0).toString(exec); 56 RefPtr<CanvasContextAttributes> attrs; 57 #if ENABLE(3D_CANVAS) 58 if (contextId == "experimental-webgl" || contextId == "webkit-3d") { 59 attrs = WebGLContextAttributes::create(); 60 WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get()); 61 if (args.size() > 1 && args.at(1).isObject()) { 62 JSObject* jsAttrs = args.at(1).getObject(); 63 Identifier alpha(exec, "alpha"); 64 if (jsAttrs->hasProperty(exec, alpha)) 65 webGLAttrs->setAlpha(jsAttrs->get(exec, alpha).toBoolean(exec)); 66 Identifier depth(exec, "depth"); 67 if (jsAttrs->hasProperty(exec, depth)) 68 webGLAttrs->setDepth(jsAttrs->get(exec, depth).toBoolean(exec)); 69 Identifier stencil(exec, "stencil"); 70 if (jsAttrs->hasProperty(exec, stencil)) 71 webGLAttrs->setStencil(jsAttrs->get(exec, stencil).toBoolean(exec)); 72 Identifier antialias(exec, "antialias"); 73 if (jsAttrs->hasProperty(exec, antialias)) 74 webGLAttrs->setAntialias(jsAttrs->get(exec, antialias).toBoolean(exec)); 75 Identifier premultipliedAlpha(exec, "premultipliedAlpha"); 76 if (jsAttrs->hasProperty(exec, premultipliedAlpha)) 77 webGLAttrs->setPremultipliedAlpha(jsAttrs->get(exec, premultipliedAlpha).toBoolean(exec)); 78 } 79 } 80 #endif 81 return toJS(exec, globalObject(), WTF::getPtr(canvas->getContext(contextId, attrs.get()))); 82 } 83 84 } // namespace WebCore 85