| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011, Google Inc. | |
| 2 // 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 are | |
| 6 // met: | |
| 7 // | |
| 8 // * Redistributions of source code must retain the above copyright | |
| 9 // notice, this list of conditions and the following disclaimer. | |
| 10 // * Redistributions in binary form must reproduce the above | |
| 11 // copyright notice, this list of conditions and the following disclaimer | |
| 12 // in the documentation and/or other materials provided with the | |
| 13 // distribution. | |
| 14 // * Neither the name of Google Inc. nor the names of its | |
| 15 // contributors may be used to endorse or promote products derived from | |
| 16 // this software without specific prior written permission. | |
| 17 // | |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | |
| 30 #include "config.h" | |
| 31 #include "bindings/core/dart/DartHTMLCanvasElement.h" | |
| 32 | |
| 33 #include "bindings/core/dart/DartCanvasRenderingContext2D.h" | |
| 34 #include "bindings/core/dart/DartDOMWrapper.h" | |
| 35 #include "bindings/core/dart/DartUtilities.h" | |
| 36 #include "bindings/core/dart/DartWebGLRenderingContext.h" | |
| 37 #include "core/html/canvas/CanvasContextAttributes.h" | |
| 38 #include "core/html/canvas/CanvasRenderingContext2D.h" | |
| 39 #include "core/html/canvas/CanvasRenderingContext.h" | |
| 40 #include "core/html/canvas/WebGLContextAttributes.h" | |
| 41 #include "core/html/canvas/WebGLRenderingContext.h" | |
| 42 #include "core/html/HTMLCanvasElement.h" | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 namespace DartHTMLCanvasElementInternal { | |
| 47 | |
| 48 void toDataURLCallback(Dart_NativeArguments args) | |
| 49 { | |
| 50 Dart_Handle exception = 0; | |
| 51 { | |
| 52 HTMLCanvasElement* receiver = DartDOMWrapper::receiver<HTMLCanvasElement
>(args); | |
| 53 | |
| 54 DartStringAdapter type = DartUtilities::dartToString(args, 1, exception)
; | |
| 55 if (exception) | |
| 56 goto fail; | |
| 57 | |
| 58 double quality; | |
| 59 double* qualityPtr = 0; | |
| 60 Dart_Handle secondArgument = Dart_GetNativeArgument(args, 2); | |
| 61 if (!Dart_IsNull(secondArgument)) { | |
| 62 quality = DartUtilities::dartToDouble(secondArgument, exception); | |
| 63 if (exception) | |
| 64 goto fail; | |
| 65 qualityPtr = &quality; | |
| 66 } | |
| 67 | |
| 68 DartExceptionState es; | |
| 69 String result = receiver->toDataURL(type, qualityPtr, es); | |
| 70 if (es.hadException()) { | |
| 71 exception = es.toDart(args); | |
| 72 goto fail; | |
| 73 } | |
| 74 | |
| 75 Dart_SetReturnValue(args, DartUtilities::stringToDartWithNullCheck(resul
t)); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 fail: | |
| 80 Dart_ThrowException(exception); | |
| 81 ASSERT_NOT_REACHED(); | |
| 82 } | |
| 83 | |
| 84 void getContextCallback(Dart_NativeArguments args) | |
| 85 { | |
| 86 Dart_Handle exception = 0; | |
| 87 { | |
| 88 HTMLCanvasElement* receiver = DartDOMWrapper::receiver<HTMLCanvasElement
>(args); | |
| 89 | |
| 90 DartStringAdapter contextId = DartUtilities::dartToString(args, 1, excep
tion); | |
| 91 if (exception) | |
| 92 goto fail; | |
| 93 | |
| 94 RefPtr<CanvasContextAttributes> attrs; | |
| 95 const String& contextIdStr = contextId; | |
| 96 if (contextIdStr == "webgl" || contextIdStr == "experimental-webgl" || c
ontextIdStr == "webkit-3d") { | |
| 97 attrs = WebGLContextAttributes::create(); | |
| 98 WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttribu
tes*>(attrs.get()); | |
| 99 Dart_Handle attrsAsMapHandle = Dart_GetNativeArgument(args, 2); | |
| 100 if (!Dart_IsNull(attrsAsMapHandle)) { | |
| 101 Dart_Handle attrsAsIntHandle = DartUtilities::invokeUtilsMethod(
"convertCanvasElementGetContextMap", 1, &attrsAsMapHandle); | |
| 102 if (!DartUtilities::checkResult(attrsAsIntHandle, exception)) | |
| 103 goto fail; | |
| 104 int attrsAsInt = DartUtilities::toInteger(attrsAsIntHandle, exce
ption); | |
| 105 if (exception) | |
| 106 goto fail; | |
| 107 | |
| 108 webGLAttrs->setAlpha(attrsAsInt & 0x01); | |
| 109 webGLAttrs->setDepth(attrsAsInt & 0x02); | |
| 110 webGLAttrs->setStencil(attrsAsInt & 0x04); | |
| 111 webGLAttrs->setAntialias(attrsAsInt & 0x08); | |
| 112 webGLAttrs->setPremultipliedAlpha(attrsAsInt & 0x10); | |
| 113 webGLAttrs->setPreserveDrawingBuffer(attrsAsInt & 0x20); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 CanvasRenderingContext* result = receiver->getContext(contextId, attrs.g
et()); | |
| 118 if (!result) | |
| 119 return; | |
| 120 if (result->is2d()) | |
| 121 DartDOMWrapper::returnToDart<DartCanvasRenderingContext2D>(args, sta
tic_cast<CanvasRenderingContext2D*>(result)); | |
| 122 else if (result->is3d()) | |
| 123 DartDOMWrapper::returnToDart<DartWebGLRenderingContext>(args, static
_cast<WebGLRenderingContext*>(result)); | |
| 124 else | |
| 125 ASSERT_NOT_REACHED(); | |
| 126 return; | |
| 127 } | |
| 128 | |
| 129 fail: | |
| 130 Dart_ThrowException(exception); | |
| 131 ASSERT_NOT_REACHED(); | |
| 132 } | |
| 133 | |
| 134 void getContextCallback_1(Dart_NativeArguments args) | |
| 135 { | |
| 136 return getContextCallback(args); | |
| 137 } | |
| 138 | |
| 139 void getContextCallback_2(Dart_NativeArguments args) | |
| 140 { | |
| 141 return getContextCallback(args); | |
| 142 } | |
| 143 | |
| 144 } // namespace DartHTMLCanvasElementInternal | |
| 145 | |
| 146 } // namespace blink | |
| OLD | NEW |