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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 if (!c) | 892 if (!c) |
893 return; | 893 return; |
894 | 894 |
895 if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) || !std
::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy)) | 895 if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) || !std
::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy)) |
896 return; | 896 return; |
897 | 897 |
898 resetTransform(); | 898 resetTransform(); |
899 transform(m11, m12, m21, m22, dx, dy); | 899 transform(m11, m12, m21, m22, dx, dy); |
900 } | 900 } |
901 | 901 |
902 void CanvasRenderingContext2D::setStrokeColor(const String& color) | |
903 { | |
904 if (color == state().m_unparsedStrokeColor) | |
905 return; | |
906 realizeSaves(nullptr); | |
907 setStrokeStyle(CanvasStyle::createFromString(color)); | |
908 modifiableState().m_unparsedStrokeColor = color; | |
909 } | |
910 | |
911 void CanvasRenderingContext2D::setStrokeColor(float grayLevel) | |
912 { | |
913 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(grayLev
el, grayLevel, grayLevel, 1.0f)) | |
914 return; | |
915 setStrokeStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, 1.0f)); | |
916 } | |
917 | |
918 void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha) | |
919 { | |
920 setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha))
; | |
921 } | |
922 | |
923 void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha) | |
924 { | |
925 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(grayLev
el, grayLevel, grayLevel, alpha)) | |
926 return; | |
927 setStrokeStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, alpha)); | |
928 } | |
929 | |
930 void CanvasRenderingContext2D::setStrokeColor(float r, float g, float b, float a
) | |
931 { | |
932 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(r, g, b
, a)) | |
933 return; | |
934 setStrokeStyle(CanvasStyle::createFromRGBAChannels(r, g, b, a)); | |
935 } | |
936 | |
937 void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k
, float a) | |
938 { | |
939 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentCMYKA(c, m,
y, k, a)) | |
940 return; | |
941 setStrokeStyle(CanvasStyle::createFromCMYKAChannels(c, m, y, k, a)); | |
942 } | |
943 | |
944 void CanvasRenderingContext2D::setFillColor(const String& color) | |
945 { | |
946 if (color == state().m_unparsedFillColor) | |
947 return; | |
948 realizeSaves(nullptr); | |
949 setFillStyle(CanvasStyle::createFromString(color)); | |
950 modifiableState().m_unparsedFillColor = color; | |
951 } | |
952 | |
953 void CanvasRenderingContext2D::setFillColor(float grayLevel) | |
954 { | |
955 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(grayLevel,
grayLevel, grayLevel, 1.0f)) | |
956 return; | |
957 setFillStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, 1.0f)); | |
958 } | |
959 | |
960 void CanvasRenderingContext2D::setFillColor(const String& color, float alpha) | |
961 { | |
962 setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha)); | |
963 } | |
964 | |
965 void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha) | |
966 { | |
967 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(grayLevel,
grayLevel, grayLevel, alpha)) | |
968 return; | |
969 setFillStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, alpha)); | |
970 } | |
971 | |
972 void CanvasRenderingContext2D::setFillColor(float r, float g, float b, float a) | |
973 { | |
974 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(r, g, b, a)
) | |
975 return; | |
976 setFillStyle(CanvasStyle::createFromRGBAChannels(r, g, b, a)); | |
977 } | |
978 | |
979 void CanvasRenderingContext2D::setFillColor(float c, float m, float y, float k,
float a) | |
980 { | |
981 if (state().m_fillStyle && state().m_fillStyle->isEquivalentCMYKA(c, m, y, k
, a)) | |
982 return; | |
983 setFillStyle(CanvasStyle::createFromCMYKAChannels(c, m, y, k, a)); | |
984 } | |
985 | |
986 void CanvasRenderingContext2D::beginPath() | 902 void CanvasRenderingContext2D::beginPath() |
987 { | 903 { |
988 m_path.clear(); | 904 m_path.clear(); |
989 } | 905 } |
990 | 906 |
991 static bool validateRectForCanvas(float& x, float& y, float& width, float& heigh
t) | 907 static bool validateRectForCanvas(float& x, float& y, float& width, float& heigh
t) |
992 { | 908 { |
993 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std:
:isfinite(height)) | 909 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std:
:isfinite(height)) |
994 return false; | 910 return false; |
995 | 911 |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 FloatRect boundingRect = rect; | 1314 FloatRect boundingRect = rect; |
1399 boundingRect.inflate(state().m_lineWidth / 2); | 1315 boundingRect.inflate(state().m_lineWidth / 2); |
1400 FloatRect dirtyRect; | 1316 FloatRect dirtyRect; |
1401 if (computeDirtyRect(boundingRect, clipBounds, &dirtyRect)) { | 1317 if (computeDirtyRect(boundingRect, clipBounds, &dirtyRect)) { |
1402 c->strokeRect(rect); | 1318 c->strokeRect(rect); |
1403 didDraw(dirtyRect); | 1319 didDraw(dirtyRect); |
1404 } | 1320 } |
1405 } | 1321 } |
1406 } | 1322 } |
1407 | 1323 |
1408 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) | |
1409 { | |
1410 setShadow(FloatSize(width, height), blur, Color::transparent); | |
1411 } | |
1412 | |
1413 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
const String& color) | |
1414 { | |
1415 RGBA32 rgba; | |
1416 if (!parseColorOrCurrentColor(rgba, color, canvas())) | |
1417 return; | |
1418 setShadow(FloatSize(width, height), blur, rgba); | |
1419 } | |
1420 | |
1421 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float grayLevel) | |
1422 { | |
1423 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, gr
ayLevel, grayLevel, 1)); | |
1424 } | |
1425 | |
1426 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
const String& color, float alpha) | |
1427 { | |
1428 RGBA32 rgba; | |
1429 if (!parseColorOrCurrentColor(rgba, color, canvas())) | |
1430 return; | |
1431 setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(rgba, alpha
)); | |
1432 } | |
1433 | |
1434 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float grayLevel, float alpha) | |
1435 { | |
1436 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, gr
ayLevel, grayLevel, alpha)); | |
1437 } | |
1438 | |
1439 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float r, float g, float b, float a) | |
1440 { | |
1441 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(r, g, b, a)); | |
1442 } | |
1443 | |
1444 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float c, float m, float y, float k, float a) | |
1445 { | |
1446 setShadow(FloatSize(width, height), blur, makeRGBAFromCMYKA(c, m, y, k, a)); | |
1447 } | |
1448 | |
1449 void CanvasRenderingContext2D::clearShadow() | |
1450 { | |
1451 setShadow(FloatSize(), 0, Color::transparent); | |
1452 } | |
1453 | |
1454 void CanvasRenderingContext2D::setShadow(const FloatSize& offset, float blur, RG
BA32 color) | |
1455 { | |
1456 if (state().m_shadowOffset == offset && state().m_shadowBlur == blur && stat
e().m_shadowColor == color) | |
1457 return; | |
1458 bool wasDrawingShadows = shouldDrawShadows(); | |
1459 realizeSaves(nullptr); | |
1460 modifiableState().m_shadowOffset = offset; | |
1461 modifiableState().m_shadowBlur = blur; | |
1462 modifiableState().m_shadowColor = color; | |
1463 if (!wasDrawingShadows && !shouldDrawShadows()) | |
1464 return; | |
1465 applyShadow(); | |
1466 } | |
1467 | |
1468 void CanvasRenderingContext2D::applyShadow(ShadowMode shadowMode) | 1324 void CanvasRenderingContext2D::applyShadow(ShadowMode shadowMode) |
1469 { | 1325 { |
1470 GraphicsContext* c = drawingContext(); | 1326 GraphicsContext* c = drawingContext(); |
1471 if (!c) | 1327 if (!c) |
1472 return; | 1328 return; |
1473 | 1329 |
1474 if (shouldDrawShadows()) { | 1330 if (shouldDrawShadows()) { |
1475 c->setShadow(state().m_shadowOffset, state().m_shadowBlur, state().m_sha
dowColor, | 1331 c->setShadow(state().m_shadowOffset, state().m_shadowBlur, state().m_sha
dowColor, |
1476 DrawLooperBuilder::ShadowIgnoresTransforms, DrawLooperBuilder::Shado
wRespectsAlpha, shadowMode); | 1332 DrawLooperBuilder::ShadowIgnoresTransforms, DrawLooperBuilder::Shado
wRespectsAlpha, shadowMode); |
1477 } else { | 1333 } else { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 } | 1490 } |
1635 validateStateStack(); | 1491 validateStateStack(); |
1636 | 1492 |
1637 if (sourceImageStatus == ExternalSourceImageStatus && isAccelerated() && can
vas()->buffer()) | 1493 if (sourceImageStatus == ExternalSourceImageStatus && isAccelerated() && can
vas()->buffer()) |
1638 canvas()->buffer()->flush(); | 1494 canvas()->buffer()->flush(); |
1639 | 1495 |
1640 if (canvas()->originClean() && wouldTaintOrigin(imageSource)) | 1496 if (canvas()->originClean() && wouldTaintOrigin(imageSource)) |
1641 canvas()->setOriginTainted(); | 1497 canvas()->setOriginTainted(); |
1642 } | 1498 } |
1643 | 1499 |
1644 void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image, | |
1645 float sx, float sy, float sw, float sh, | |
1646 float dx, float dy, float dw, float dh, | |
1647 const String& compositeOperation) | |
1648 { | |
1649 if (!image) | |
1650 return; | |
1651 save(); | |
1652 setGlobalCompositeOperation(compositeOperation); | |
1653 drawImageInternal(image, sx, sy, sw, sh, dx, dy, dw, dh, IGNORE_EXCEPTION); | |
1654 restore(); | |
1655 } | |
1656 | |
1657 void CanvasRenderingContext2D::setAlpha(float alpha) | |
1658 { | |
1659 setGlobalAlpha(alpha); | |
1660 } | |
1661 | |
1662 void CanvasRenderingContext2D::setCompositeOperation(const String& operation) | |
1663 { | |
1664 setGlobalCompositeOperation(operation); | |
1665 } | |
1666 | |
1667 void CanvasRenderingContext2D::clearCanvas() | 1500 void CanvasRenderingContext2D::clearCanvas() |
1668 { | 1501 { |
1669 FloatRect canvasRect(0, 0, canvas()->width(), canvas()->height()); | 1502 FloatRect canvasRect(0, 0, canvas()->width(), canvas()->height()); |
1670 GraphicsContext* c = drawingContext(); | 1503 GraphicsContext* c = drawingContext(); |
1671 if (!c) | 1504 if (!c) |
1672 return; | 1505 return; |
1673 | 1506 |
1674 c->save(); | 1507 c->save(); |
1675 c->setCTM(canvas()->baseTransform()); | 1508 c->setCTM(canvas()->baseTransform()); |
1676 c->clearRect(canvasRect); | 1509 c->clearRect(canvasRect); |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 | 2327 |
2495 unsigned CanvasRenderingContext2D::hitRegionsCount() const | 2328 unsigned CanvasRenderingContext2D::hitRegionsCount() const |
2496 { | 2329 { |
2497 if (m_hitRegionManager) | 2330 if (m_hitRegionManager) |
2498 return m_hitRegionManager->getHitRegionsCount(); | 2331 return m_hitRegionManager->getHitRegionsCount(); |
2499 | 2332 |
2500 return 0; | 2333 return 0; |
2501 } | 2334 } |
2502 | 2335 |
2503 } // namespace blink | 2336 } // namespace blink |
OLD | NEW |