OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
8 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
10 * | 10 * |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1246 drawImage(bitmap, x, y, bitmap->width(), bitmap->height(), ec); | 1246 drawImage(bitmap, x, y, bitmap->width(), bitmap->height(), ec); |
1247 } | 1247 } |
1248 | 1248 |
1249 void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap, | 1249 void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap, |
1250 float x, float y, float width, float height, ExceptionCode& ec) | 1250 float x, float y, float width, float height, ExceptionCode& ec) |
1251 { | 1251 { |
1252 if (!bitmap) { | 1252 if (!bitmap) { |
1253 ec = TypeMismatchError; | 1253 ec = TypeMismatchError; |
1254 return; | 1254 return; |
1255 } | 1255 } |
1256 if (!bitmap->bitmapWidth() || !bitmap->bitmapHeight()) | 1256 if (!bitmap->bitmapRect().width() || !bitmap->bitmapRect().height()) |
1257 return; | 1257 return; |
1258 | 1258 |
1259 drawImage(bitmap, 0, 0, bitmap->bitmapWidth(), bitmap->bitmapHeight(), x, y, width, height, ec); | 1259 drawImage(bitmap, 0, 0, bitmap->width(), bitmap->height(), x, y, width, heig ht, ec); |
1260 } | 1260 } |
1261 | 1261 |
1262 void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap, | 1262 void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap, |
1263 float sx, float sy, float sw, float sh, | 1263 float sx, float sy, float sw, float sh, |
1264 float dx, float dy, float dw, float dh, ExceptionCode& ec) | 1264 float dx, float dy, float dw, float dh, ExceptionCode& ec) |
1265 { | 1265 { |
1266 if (!bitmap) { | 1266 if (!bitmap) { |
1267 ec = TypeMismatchError; | 1267 ec = TypeMismatchError; |
1268 return; | 1268 return; |
1269 } | 1269 } |
1270 | 1270 |
1271 FloatRect srcRect(sx, sy, sw, sh); | 1271 FloatRect srcRect(sx, sy, sw, sh); |
1272 FloatRect dstRect(dx, dy, dw, dh); | 1272 FloatRect dstRect(dx, dy, dw, dh); |
1273 FloatRect bitmapRect = bitmap->bitmapRect(); | |
1273 | 1274 |
1274 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi nite(dstRect.width()) || !std::isfinite(dstRect.height()) | 1275 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi nite(dstRect.width()) || !std::isfinite(dstRect.height()) |
1275 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i sfinite(srcRect.width()) || !std::isfinite(srcRect.height())) | 1276 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i sfinite(srcRect.width()) || !std::isfinite(srcRect.height())) |
1276 return; | 1277 return; |
1277 | 1278 |
1278 if (!dstRect.width() || !dstRect.height()) | 1279 if (!dstRect.width() || !dstRect.height()) |
1279 return; | 1280 return; |
1280 | 1281 |
1281 ASSERT(bitmap->height() && bitmap->width()); | 1282 ASSERT(bitmap->height() && bitmap->width()); |
1282 | |
1283 FloatRect normalizedSrcRect = normalizeRect(srcRect); | 1283 FloatRect normalizedSrcRect = normalizeRect(srcRect); |
1284 FloatRect normalizedDstRect = normalizeRect(dstRect); | 1284 FloatRect normalizedDstRect = normalizeRect(dstRect); |
1285 FloatRect actualDstRect(FloatPoint(bitmap->bitmapOffset()), bitmap->bitmapSi ze()); | 1285 // We clip our rects to where the user thinks that the image is situated |
1286 actualDstRect.scale(normalizedDstRect.width() / bitmap->width(), normalizedD stRect.height() / bitmap->height()); | 1286 clipRectsToImageRect(IntRect(IntPoint(), bitmap->size()), &normalizedSrcRect , &normalizedDstRect); |
1287 | |
1288 FloatRect intersectRect = intersection(bitmapRect, normalizedSrcRect); | |
1289 FloatRect actualSrcRect(intersectRect); | |
1290 actualSrcRect.move(-bitmapRect.x(), -bitmapRect.y()); | |
1291 | |
1292 FloatRect imageRect = FloatRect(FloatPoint(), bitmapRect.size()); | |
1293 | |
1294 FloatRect actualDstRect(FloatPoint(intersectRect.location() - normalizedSrcR ect.location()), bitmapRect.size()); | |
1295 actualDstRect.scale(normalizedDstRect.width() / normalizedSrcRect.width() * intersectRect.width() / bitmapRect.width(), | |
1296 normalizedDstRect.height() / normalizedSrcRect.height() * intersectRect. height() / bitmapRect.height()); | |
Stephen White
2013/07/25 18:01:07
Should we be checking for zero in normalizedSrcRec
| |
1287 actualDstRect.moveBy(normalizedDstRect.location()); | 1297 actualDstRect.moveBy(normalizedDstRect.location()); |
1288 | 1298 |
1289 FloatRect imageRect = FloatRect(FloatPoint(), bitmap->bitmapSize()); | |
1290 if (!srcRect.width() || !srcRect.height()) { | 1299 if (!srcRect.width() || !srcRect.height()) { |
1291 ec = IndexSizeError; | 1300 ec = IndexSizeError; |
1292 return; | 1301 return; |
1293 } | 1302 } |
1294 if (!imageRect.intersects(normalizedSrcRect)) | 1303 if (!imageRect.intersects(actualSrcRect)) |
1295 return; | 1304 return; |
1296 | 1305 |
1297 clipRectsToImageRect(imageRect, &normalizedSrcRect, &actualDstRect); | 1306 RefPtr<Image> imageForRendering = bitmap->bitmapImage(); |
1298 | 1307 |
1299 Image* imageForRendering = bitmap->bitmapImage(); | 1308 drawImageInternal(imageForRendering.get(), actualSrcRect, actualDstRect, sta te().m_globalComposite, state().m_globalBlend); |
1300 | |
1301 drawImageInternal(imageForRendering, normalizedSrcRect, actualDstRect, state ().m_globalComposite, state().m_globalBlend); | |
1302 } | 1309 } |
1303 | 1310 |
1304 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec) | 1311 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec) |
1305 { | 1312 { |
1306 if (!image) { | 1313 if (!image) { |
1307 ec = TypeMismatchError; | 1314 ec = TypeMismatchError; |
1308 return; | 1315 return; |
1309 } | 1316 } |
1310 LayoutSize s = size(image); | 1317 LayoutSize s = size(image); |
1311 drawImage(image, x, y, s.width(), s.height(), ec); | 1318 drawImage(image, x, y, s.width(), s.height(), ec); |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2331 } | 2338 } |
2332 | 2339 |
2333 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const | 2340 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const |
2334 { | 2341 { |
2335 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); | 2342 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); |
2336 attributes->setAlpha(m_hasAlpha); | 2343 attributes->setAlpha(m_hasAlpha); |
2337 return attributes.release(); | 2344 return attributes.release(); |
2338 } | 2345 } |
2339 | 2346 |
2340 } // namespace WebCore | 2347 } // namespace WebCore |
OLD | NEW |