OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 *misspellBitmap[index], SkShader::kRepeat_TileMode, SkShader::kRepeat_Ti
leMode, &localMatrix)); | 839 *misspellBitmap[index], SkShader::kRepeat_TileMode, SkShader::kRepeat_Ti
leMode, &localMatrix)); |
840 | 840 |
841 SkPaint paint; | 841 SkPaint paint; |
842 paint.setShader(shader.get()); | 842 paint.setShader(shader.get()); |
843 | 843 |
844 SkRect rect; | 844 SkRect rect; |
845 rect.set(originX, originY, originX + WebCoreFloatToSkScalar(width) * deviceS
caleFactor, originY + SkIntToScalar(misspellBitmap[index]->height())); | 845 rect.set(originX, originY, originX + WebCoreFloatToSkScalar(width) * deviceS
caleFactor, originY + SkIntToScalar(misspellBitmap[index]->height())); |
846 | 846 |
847 if (deviceScaleFactor == 2) { | 847 if (deviceScaleFactor == 2) { |
848 save(); | 848 save(); |
849 scale(FloatSize(0.5, 0.5)); | 849 scale(0.5, 0.5); |
850 } | 850 } |
851 drawRect(rect, paint); | 851 drawRect(rect, paint); |
852 if (deviceScaleFactor == 2) | 852 if (deviceScaleFactor == 2) |
853 restore(); | 853 restore(); |
854 } | 854 } |
855 | 855 |
856 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width, bool pr
inting) | 856 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width, bool pr
inting) |
857 { | 857 { |
858 if (contextDisabled()) | 858 if (contextDisabled()) |
859 return; | 859 return; |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 void GraphicsContext::rotate(float angleInRadians) | 1462 void GraphicsContext::rotate(float angleInRadians) |
1463 { | 1463 { |
1464 if (contextDisabled()) | 1464 if (contextDisabled()) |
1465 return; | 1465 return; |
1466 | 1466 |
1467 realizeCanvasSave(); | 1467 realizeCanvasSave(); |
1468 | 1468 |
1469 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926
5f))); | 1469 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926
5f))); |
1470 } | 1470 } |
1471 | 1471 |
1472 void GraphicsContext::translate(float w, float h) | 1472 void GraphicsContext::translate(float x, float y) |
1473 { | 1473 { |
1474 if (contextDisabled()) | 1474 if (contextDisabled()) |
1475 return; | 1475 return; |
1476 | 1476 |
1477 if (!w && !h) | 1477 if (!x && !y) |
1478 return; | 1478 return; |
1479 | 1479 |
1480 realizeCanvasSave(); | 1480 realizeCanvasSave(); |
1481 | 1481 |
1482 m_canvas->translate(WebCoreFloatToSkScalar(w), WebCoreFloatToSkScalar(h)); | 1482 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1483 } | 1483 } |
1484 | 1484 |
1485 void GraphicsContext::scale(const FloatSize& size) | 1485 void GraphicsContext::scale(float x, float y) |
1486 { | 1486 { |
1487 if (contextDisabled()) | 1487 if (contextDisabled()) |
1488 return; | 1488 return; |
1489 | 1489 |
1490 if (size.width() == 1.0f && size.height() == 1.0f) | 1490 if (x == 1.0f && y == 1.0f) |
1491 return; | 1491 return; |
1492 | 1492 |
1493 realizeCanvasSave(); | 1493 realizeCanvasSave(); |
1494 | 1494 |
1495 m_canvas->scale(WebCoreFloatToSkScalar(size.width()), WebCoreFloatToSkScalar
(size.height())); | 1495 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1496 } | 1496 } |
1497 | 1497 |
1498 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) | 1498 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) |
1499 { | 1499 { |
1500 if (contextDisabled()) | 1500 if (contextDisabled()) |
1501 return; | 1501 return; |
1502 | 1502 |
1503 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); | 1503 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); |
1504 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); | 1504 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); |
1505 } | 1505 } |
1506 | 1506 |
1507 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec
t& rect) | 1507 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec
t& rect) |
1508 { | 1508 { |
1509 if (contextDisabled()) | 1509 if (contextDisabled()) |
1510 return; | 1510 return; |
1511 | 1511 |
1512 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); | 1512 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); |
1513 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); | 1513 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); |
1514 } | 1514 } |
1515 | 1515 |
1516 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po
s) | 1516 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po
s) |
1517 { | 1517 { |
1518 if (contextDisabled()) | 1518 if (contextDisabled()) |
1519 return; | 1519 return; |
1520 | 1520 |
1521 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); | 1521 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); |
1522 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa
ta); | 1522 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa
ta); |
1523 } | 1523 } |
1524 | 1524 |
1525 AffineTransform GraphicsContext::getCTM(IncludeDeviceScale) const | 1525 AffineTransform GraphicsContext::getCTM() const |
1526 { | 1526 { |
1527 if (contextDisabled()) | 1527 if (contextDisabled()) |
1528 return AffineTransform(); | 1528 return AffineTransform(); |
1529 | 1529 |
1530 SkMatrix m = getTotalMatrix(); | 1530 SkMatrix m = getTotalMatrix(); |
1531 return AffineTransform(SkScalarToDouble(m.getScaleX()), | 1531 return AffineTransform(SkScalarToDouble(m.getScaleX()), |
1532 SkScalarToDouble(m.getSkewY()), | 1532 SkScalarToDouble(m.getSkewY()), |
1533 SkScalarToDouble(m.getSkewX()), | 1533 SkScalarToDouble(m.getSkewX()), |
1534 SkScalarToDouble(m.getScaleY()), | 1534 SkScalarToDouble(m.getScaleY()), |
1535 SkScalarToDouble(m.getTranslateX()), | 1535 SkScalarToDouble(m.getTranslateX()), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 } | 1622 } |
1623 } | 1623 } |
1624 } | 1624 } |
1625 | 1625 |
1626 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s
ize, OpacityMode opacityMode) const | 1626 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s
ize, OpacityMode opacityMode) const |
1627 { | 1627 { |
1628 // Make the buffer larger if the context's transform is scaling it so we nee
d a higher | 1628 // Make the buffer larger if the context's transform is scaling it so we nee
d a higher |
1629 // resolution than one pixel per unit. Also set up a corresponding scale fac
tor on the | 1629 // resolution than one pixel per unit. Also set up a corresponding scale fac
tor on the |
1630 // graphics context. | 1630 // graphics context. |
1631 | 1631 |
1632 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); | 1632 AffineTransform transform = getCTM(); |
1633 IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale()))
, static_cast<int>(ceil(size.height() * transform.yScale()))); | 1633 IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale()))
, static_cast<int>(ceil(size.height() * transform.yScale()))); |
1634 | 1634 |
1635 SkAlphaType alphaType = (opacityMode == Opaque) ? kOpaque_SkAlphaType : kPre
mul_SkAlphaType; | 1635 SkAlphaType alphaType = (opacityMode == Opaque) ? kOpaque_SkAlphaType : kPre
mul_SkAlphaType; |
1636 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), alphaTy
pe); | 1636 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), alphaTy
pe); |
1637 RefPtr<SkSurface> skSurface = adoptRef(m_canvas->newSurface(info)); | 1637 RefPtr<SkSurface> skSurface = adoptRef(m_canvas->newSurface(info)); |
1638 if (!skSurface) | 1638 if (!skSurface) |
1639 return nullptr; | 1639 return nullptr; |
1640 OwnPtr<ImageBufferSurface> surface = adoptPtr(new CompatibleImageBufferSurfa
ce(skSurface.release(), scaledSize, opacityMode)); | 1640 OwnPtr<ImageBufferSurface> surface = adoptPtr(new CompatibleImageBufferSurfa
ce(skSurface.release(), scaledSize, opacityMode)); |
1641 ASSERT(surface->isValid()); | 1641 ASSERT(surface->isValid()); |
1642 OwnPtr<ImageBuffer> buffer = adoptPtr(new ImageBuffer(surface.release())); | 1642 OwnPtr<ImageBuffer> buffer = adoptPtr(new ImageBuffer(surface.release())); |
1643 | 1643 |
1644 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) /
size.width(), | 1644 buffer->context()->scale(static_cast<float>(scaledSize.width()) / size.width
(), |
1645 static_cast<float>(scaledSize.height()) / size.height())); | 1645 static_cast<float>(scaledSize.height()) / size.height()); |
1646 | 1646 |
1647 return buffer.release(); | 1647 return buffer.release(); |
1648 } | 1648 } |
1649 | 1649 |
1650 void GraphicsContext::setPathFromConvexPoints(SkPath* path, size_t numPoints, co
nst FloatPoint* points) | 1650 void GraphicsContext::setPathFromConvexPoints(SkPath* path, size_t numPoints, co
nst FloatPoint* points) |
1651 { | 1651 { |
1652 path->incReserve(numPoints); | 1652 path->incReserve(numPoints); |
1653 path->moveTo(WebCoreFloatToSkScalar(points[0].x()), | 1653 path->moveTo(WebCoreFloatToSkScalar(points[0].x()), |
1654 WebCoreFloatToSkScalar(points[0].y())); | 1654 WebCoreFloatToSkScalar(points[0].y())); |
1655 for (size_t i = 1; i < numPoints; ++i) { | 1655 for (size_t i = 1; i < numPoints; ++i) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 | 1816 |
1817 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 1817 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
1818 { | 1818 { |
1819 if (m_trackTextRegion) { | 1819 if (m_trackTextRegion) { |
1820 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1820 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
1821 m_textRegion.join(textRect); | 1821 m_textRegion.join(textRect); |
1822 } | 1822 } |
1823 } | 1823 } |
1824 | 1824 |
1825 } | 1825 } |
OLD | NEW |