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, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "core/html/TextMetrics.h" | 52 #include "core/html/TextMetrics.h" |
53 #include "core/html/canvas/Canvas2DContextAttributes.h" | 53 #include "core/html/canvas/Canvas2DContextAttributes.h" |
54 #include "core/html/canvas/CanvasGradient.h" | 54 #include "core/html/canvas/CanvasGradient.h" |
55 #include "core/html/canvas/CanvasPattern.h" | 55 #include "core/html/canvas/CanvasPattern.h" |
56 #include "core/html/canvas/CanvasStyle.h" | 56 #include "core/html/canvas/CanvasStyle.h" |
57 #include "core/html/canvas/DOMPath.h" | 57 #include "core/html/canvas/DOMPath.h" |
58 #include "core/frame/ImageBitmap.h" | 58 #include "core/frame/ImageBitmap.h" |
59 #include "core/platform/graphics/DrawLooper.h" | 59 #include "core/platform/graphics/DrawLooper.h" |
60 #include "core/platform/graphics/FontCache.h" | 60 #include "core/platform/graphics/FontCache.h" |
61 #include "core/platform/graphics/GraphicsContextStateSaver.h" | 61 #include "core/platform/graphics/GraphicsContextStateSaver.h" |
| 62 #include "core/rendering/RenderImage.h" |
62 #include "core/rendering/RenderLayer.h" | 63 #include "core/rendering/RenderLayer.h" |
63 #include "core/rendering/RenderTheme.h" | 64 #include "core/rendering/RenderTheme.h" |
64 #include "platform/geometry/FloatQuad.h" | 65 #include "platform/geometry/FloatQuad.h" |
65 #include "platform/graphics/TextRun.h" | 66 #include "platform/graphics/TextRun.h" |
66 #include "platform/transforms/AffineTransform.h" | 67 #include "platform/transforms/AffineTransform.h" |
67 #include "weborigin/SecurityOrigin.h" | 68 #include "weborigin/SecurityOrigin.h" |
68 #include "wtf/CheckedArithmetic.h" | 69 #include "wtf/CheckedArithmetic.h" |
69 #include "wtf/MathExtras.h" | 70 #include "wtf/MathExtras.h" |
70 #include "wtf/OwnPtr.h" | 71 #include "wtf/OwnPtr.h" |
71 #include "wtf/Uint8ClampedArray.h" | 72 #include "wtf/Uint8ClampedArray.h" |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 } else { | 1206 } else { |
1206 c->clearShadow(); | 1207 c->clearShadow(); |
1207 } | 1208 } |
1208 } | 1209 } |
1209 | 1210 |
1210 bool CanvasRenderingContext2D::shouldDrawShadows() const | 1211 bool CanvasRenderingContext2D::shouldDrawShadows() const |
1211 { | 1212 { |
1212 return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !stat
e().m_shadowOffset.isZero()); | 1213 return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !stat
e().m_shadowOffset.isZero()); |
1213 } | 1214 } |
1214 | 1215 |
1215 static LayoutSize sizeFor(HTMLImageElement* image) | 1216 enum ImageSizeType { |
| 1217 ImageSizeAfterDevicePixelRatio, |
| 1218 ImageSizeBeforeDevicePixelRatio |
| 1219 }; |
| 1220 |
| 1221 static LayoutSize sizeFor(HTMLImageElement* image, ImageSizeType sizeType) |
1216 { | 1222 { |
1217 if (ImageResource* cachedImage = image->cachedImage()) | 1223 LayoutSize size; |
1218 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI
XME: Not sure about this. | 1224 ImageResource* cachedImage = image->cachedImage(); |
1219 return IntSize(); | 1225 if (cachedImage) { |
| 1226 size = cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI
XME: Not sure about this. |
| 1227 |
| 1228 if (sizeType == ImageSizeAfterDevicePixelRatio && image->renderer() && i
mage->renderer()->isRenderImage() && cachedImage->image() && !cachedImage->image
()->hasRelativeWidth()) |
| 1229 size.scale(toRenderImage(image->renderer())->imageDevicePixelRatio()
); |
| 1230 } |
| 1231 return size; |
1220 } | 1232 } |
1221 | 1233 |
1222 static IntSize sizeFor(HTMLVideoElement* video) | 1234 static IntSize sizeFor(HTMLVideoElement* video) |
1223 { | 1235 { |
1224 if (MediaPlayer* player = video->player()) | 1236 if (MediaPlayer* player = video->player()) |
1225 return player->naturalSize(); | 1237 return player->naturalSize(); |
1226 return IntSize(); | 1238 return IntSize(); |
1227 } | 1239 } |
1228 | 1240 |
1229 static inline FloatRect normalizeRect(const FloatRect& rect) | 1241 static inline FloatRect normalizeRect(const FloatRect& rect) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 | 1372 |
1361 drawImageInternal(imageForRendering.get(), actualSrcRect, actualDstRect, sta
te().m_globalComposite, state().m_globalBlend); | 1373 drawImageInternal(imageForRendering.get(), actualSrcRect, actualDstRect, sta
te().m_globalComposite, state().m_globalBlend); |
1362 } | 1374 } |
1363 | 1375 |
1364 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float
y, ExceptionState& es) | 1376 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float
y, ExceptionState& es) |
1365 { | 1377 { |
1366 if (!image) { | 1378 if (!image) { |
1367 es.throwUninformativeAndGenericDOMException(TypeMismatchError); | 1379 es.throwUninformativeAndGenericDOMException(TypeMismatchError); |
1368 return; | 1380 return; |
1369 } | 1381 } |
1370 LayoutSize size = sizeFor(image); | 1382 LayoutSize destRectSize = sizeFor(image, ImageSizeAfterDevicePixelRatio); |
1371 drawImage(image, x, y, size.width(), size.height(), es); | 1383 drawImage(image, x, y, destRectSize.width(), destRectSize.height(), es); |
1372 } | 1384 } |
1373 | 1385 |
1374 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, | 1386 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, |
1375 float x, float y, float width, float height, ExceptionState& es) | 1387 float x, float y, float width, float height, ExceptionState& es) |
1376 { | 1388 { |
1377 if (!image) { | 1389 if (!image) { |
1378 es.throwUninformativeAndGenericDOMException(TypeMismatchError); | 1390 es.throwUninformativeAndGenericDOMException(TypeMismatchError); |
1379 return; | 1391 return; |
1380 } | 1392 } |
1381 LayoutSize size = sizeFor(image); | 1393 LayoutSize sourceRectSize = sizeFor(image, ImageSizeBeforeDevicePixelRatio); |
1382 drawImage(image, FloatRect(0, 0, size.width(), size.height()), FloatRect(x,
y, width, height), es); | 1394 drawImage(image, FloatRect(0, 0, sourceRectSize.width(), sourceRectSize.heig
ht()), FloatRect(x, y, width, height), es); |
1383 } | 1395 } |
1384 | 1396 |
1385 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, | 1397 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, |
1386 float sx, float sy, float sw, float sh, | 1398 float sx, float sy, float sw, float sh, |
1387 float dx, float dy, float dw, float dh, ExceptionState& es) | 1399 float dx, float dy, float dw, float dh, ExceptionState& es) |
1388 { | 1400 { |
1389 drawImage(image, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), es); | 1401 drawImage(image, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), es); |
1390 } | 1402 } |
1391 | 1403 |
1392 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec
t& srcRect, const FloatRect& dstRect, ExceptionState& es) | 1404 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec
t& srcRect, const FloatRect& dstRect, ExceptionState& es) |
1393 { | 1405 { |
1394 drawImage(image, srcRect, dstRect, state().m_globalComposite, state().m_glob
alBlend, es); | 1406 drawImage(image, srcRect, dstRect, state().m_globalComposite, state().m_glob
alBlend, es); |
1395 } | 1407 } |
1396 | 1408 |
1397 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec
t& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMo
de& blendMode, ExceptionState& es) | 1409 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec
t& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMo
de& blendMode, ExceptionState& es) |
1398 { | 1410 { |
1399 if (!image) { | 1411 if (!image) { |
1400 es.throwUninformativeAndGenericDOMException(TypeMismatchError); | 1412 es.throwUninformativeAndGenericDOMException(TypeMismatchError); |
1401 return; | 1413 return; |
1402 } | 1414 } |
1403 | 1415 |
1404 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi
nite(dstRect.width()) || !std::isfinite(dstRect.height()) | 1416 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi
nite(dstRect.width()) || !std::isfinite(dstRect.height()) |
1405 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i
sfinite(srcRect.width()) || !std::isfinite(srcRect.height())) | 1417 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i
sfinite(srcRect.width()) || !std::isfinite(srcRect.height())) |
1406 return; | 1418 return; |
1407 | 1419 |
1408 ImageResource* cachedImage = image->cachedImage(); | 1420 ImageResource* cachedImage = image->cachedImage(); |
1409 if (!cachedImage || !image->complete()) | 1421 if (!cachedImage || !image->complete()) |
1410 return; | 1422 return; |
1411 | 1423 |
1412 LayoutSize size = sizeFor(image); | 1424 LayoutSize size = sizeFor(image, ImageSizeBeforeDevicePixelRatio); |
1413 if (!size.width() || !size.height()) { | 1425 if (!size.width() || !size.height()) { |
1414 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 1426 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
1415 return; | 1427 return; |
1416 } | 1428 } |
1417 | 1429 |
1418 if (!dstRect.width() || !dstRect.height()) | 1430 if (!dstRect.width() || !dstRect.height()) |
1419 return; | 1431 return; |
1420 | 1432 |
1421 FloatRect normalizedSrcRect = normalizeRect(srcRect); | 1433 FloatRect normalizedSrcRect = normalizeRect(srcRect); |
1422 FloatRect normalizedDstRect = normalizeRect(dstRect); | 1434 FloatRect normalizedDstRect = normalizeRect(dstRect); |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 const int focusRingWidth = 5; | 2431 const int focusRingWidth = 5; |
2420 const int focusRingOutline = 0; | 2432 const int focusRingOutline = 0; |
2421 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2433 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2422 | 2434 |
2423 c->restore(); | 2435 c->restore(); |
2424 | 2436 |
2425 didDraw(dirtyRect); | 2437 didDraw(dirtyRect); |
2426 } | 2438 } |
2427 | 2439 |
2428 } // namespace WebCore | 2440 } // namespace WebCore |
OLD | NEW |