| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/canvas2d/BaseRenderingContext2D.h" | 5 #include "modules/canvas2d/BaseRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 10 #include "core/css/parser/CSSParser.h" | 10 #include "core/css/parser/CSSParser.h" |
| (...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 static_cast<SkRect>(canvasRect).roundOut(&canvasIRect); | 1133 static_cast<SkRect>(canvasRect).roundOut(&canvasIRect); |
| 1134 if (!canvasIRect.intersect(transformedClipBounds)) | 1134 if (!canvasIRect.intersect(transformedClipBounds)) |
| 1135 return false; | 1135 return false; |
| 1136 | 1136 |
| 1137 if (dirtyRect) | 1137 if (dirtyRect) |
| 1138 *dirtyRect = canvasIRect; | 1138 *dirtyRect = canvasIRect; |
| 1139 | 1139 |
| 1140 return true; | 1140 return true; |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 ImageData* BaseRenderingContext2D::createImageData(ImageData* imageData) const | 1143 ImageData* BaseRenderingContext2D::createImageData(ImageData* imageData, Excepti
onState &exceptionState) const |
| 1144 { | 1144 { |
| 1145 return ImageData::create(imageData->size()); | 1145 ImageData* result = ImageData::create(imageData->size()); |
| 1146 if (!result) |
| 1147 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| 1148 return result; |
| 1146 } | 1149 } |
| 1147 | 1150 |
| 1148 ImageData* BaseRenderingContext2D::createImageData(double sw, double sh, Excepti
onState& exceptionState) const | 1151 ImageData* BaseRenderingContext2D::createImageData(double sw, double sh, Excepti
onState& exceptionState) const |
| 1149 { | 1152 { |
| 1150 if (!sw || !sh) { | 1153 if (!sw || !sh) { |
| 1151 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is 0.", sw ? "height" : "width")); | 1154 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is 0.", sw ? "height" : "width")); |
| 1152 return nullptr; | 1155 return nullptr; |
| 1153 } | 1156 } |
| 1154 | 1157 |
| 1155 FloatSize logicalSize(fabs(sw), fabs(sh)); | 1158 FloatSize logicalSize(fabs(sw), fabs(sh)); |
| 1156 if (!logicalSize.isExpressibleAsIntSize()) | 1159 if (!logicalSize.isExpressibleAsIntSize()) |
| 1157 return nullptr; | 1160 return nullptr; |
| 1158 | 1161 |
| 1159 IntSize size = expandedIntSize(logicalSize); | 1162 IntSize size = expandedIntSize(logicalSize); |
| 1160 if (size.width() < 1) | 1163 if (size.width() < 1) |
| 1161 size.setWidth(1); | 1164 size.setWidth(1); |
| 1162 if (size.height() < 1) | 1165 if (size.height() < 1) |
| 1163 size.setHeight(1); | 1166 size.setHeight(1); |
| 1164 | 1167 |
| 1165 return ImageData::create(size); | 1168 ImageData* result = ImageData::create(size); |
| 1169 if (!result) |
| 1170 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| 1171 return result; |
| 1166 } | 1172 } |
| 1167 | 1173 |
| 1168 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw,
double sh, ExceptionState& exceptionState) const | 1174 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw,
double sh, ExceptionState& exceptionState) const |
| 1169 { | 1175 { |
| 1170 if (!originClean()) | 1176 if (!originClean()) |
| 1171 exceptionState.throwSecurityError("The canvas has been tainted by cross-
origin data."); | 1177 exceptionState.throwSecurityError("The canvas has been tainted by cross-
origin data."); |
| 1172 else if (!sw || !sh) | 1178 else if (!sw || !sh) |
| 1173 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is 0.", sw ? "height" : "width")); | 1179 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is 0.", sw ? "height" : "width")); |
| 1174 | 1180 |
| 1175 if (exceptionState.hadException()) | 1181 if (exceptionState.hadException()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1187 FloatRect logicalRect(sx, sy, sw, sh); | 1193 FloatRect logicalRect(sx, sy, sw, sh); |
| 1188 if (logicalRect.width() < 1) | 1194 if (logicalRect.width() < 1) |
| 1189 logicalRect.setWidth(1); | 1195 logicalRect.setWidth(1); |
| 1190 if (logicalRect.height() < 1) | 1196 if (logicalRect.height() < 1) |
| 1191 logicalRect.setHeight(1); | 1197 logicalRect.setHeight(1); |
| 1192 if (!logicalRect.isExpressibleAsIntRect()) | 1198 if (!logicalRect.isExpressibleAsIntRect()) |
| 1193 return nullptr; | 1199 return nullptr; |
| 1194 | 1200 |
| 1195 IntRect imageDataRect = enclosingIntRect(logicalRect); | 1201 IntRect imageDataRect = enclosingIntRect(logicalRect); |
| 1196 ImageBuffer* buffer = imageBuffer(); | 1202 ImageBuffer* buffer = imageBuffer(); |
| 1197 if (!buffer || isContextLost()) | 1203 if (!buffer || isContextLost()) { |
| 1198 return ImageData::create(imageDataRect.size()); | 1204 ImageData* result = ImageData::create(imageDataRect.size()); |
| 1205 if (!result) |
| 1206 exceptionState.throwRangeError("Out of memory at ImageData creation"
); |
| 1207 return result; |
| 1208 } |
| 1199 | 1209 |
| 1200 WTF::ArrayBufferContents contents; | 1210 WTF::ArrayBufferContents contents; |
| 1201 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) | 1211 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) { |
| 1212 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| 1202 return nullptr; | 1213 return nullptr; |
| 1214 } |
| 1203 | 1215 |
| 1204 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(contents); | 1216 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(contents); |
| 1205 return ImageData::create( | 1217 return ImageData::create( |
| 1206 imageDataRect.size(), | 1218 imageDataRect.size(), |
| 1207 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength()))
; | 1219 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength()))
; |
| 1208 } | 1220 } |
| 1209 | 1221 |
| 1210 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy,
ExceptionState& exceptionState) | 1222 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy,
ExceptionState& exceptionState) |
| 1211 { | 1223 { |
| 1212 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta
te); | 1224 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta
te); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 | 1369 |
| 1358 imageBuffer()->willOverwriteCanvas(); | 1370 imageBuffer()->willOverwriteCanvas(); |
| 1359 } | 1371 } |
| 1360 | 1372 |
| 1361 DEFINE_TRACE(BaseRenderingContext2D) | 1373 DEFINE_TRACE(BaseRenderingContext2D) |
| 1362 { | 1374 { |
| 1363 visitor->trace(m_stateStack); | 1375 visitor->trace(m_stateStack); |
| 1364 } | 1376 } |
| 1365 | 1377 |
| 1366 } // namespace blink | 1378 } // namespace blink |
| OLD | NEW |