OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkDraw.h" | 9 #include "SkDraw.h" |
10 #include "SkBlitter.h" | 10 #include "SkBlitter.h" |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 if (NULL == aa) { | 1482 if (NULL == aa) { |
1483 aa = (uint8_t*)state.fCache->findImage(glyph); | 1483 aa = (uint8_t*)state.fCache->findImage(glyph); |
1484 if (NULL == aa) { | 1484 if (NULL == aa) { |
1485 return; // can't rasterize glyph | 1485 return; // can't rasterize glyph |
1486 } | 1486 } |
1487 } | 1487 } |
1488 | 1488 |
1489 mask.fRowBytes = glyph.rowBytes(); | 1489 mask.fRowBytes = glyph.rowBytes(); |
1490 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 1490 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
1491 mask.fImage = aa; | 1491 mask.fImage = aa; |
1492 state.fBlitter->blitMask(mask, *bounds); | 1492 state.blitMask(mask, *bounds); |
1493 } | 1493 } |
1494 | 1494 |
1495 static void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state, | 1495 static void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state, |
1496 SkFixed fx, SkFixed fy, | 1496 SkFixed fx, SkFixed fy, |
1497 const SkGlyph& glyph) { | 1497 const SkGlyph& glyph) { |
1498 int left = SkFixedFloor(fx); | 1498 int left = SkFixedFloor(fx); |
1499 int top = SkFixedFloor(fy); | 1499 int top = SkFixedFloor(fy); |
1500 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); | 1500 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
1501 SkASSERT(!state.fClip->isRect()); | 1501 SkASSERT(!state.fClip->isRect()); |
1502 SkASSERT(NULL == state.fBounder); | 1502 SkASSERT(NULL == state.fBounder); |
(...skipping 13 matching lines...) Expand all Loading... |
1516 aa = (uint8_t*)state.fCache->findImage(glyph); | 1516 aa = (uint8_t*)state.fCache->findImage(glyph); |
1517 if (NULL == aa) { | 1517 if (NULL == aa) { |
1518 return; | 1518 return; |
1519 } | 1519 } |
1520 } | 1520 } |
1521 | 1521 |
1522 mask.fRowBytes = glyph.rowBytes(); | 1522 mask.fRowBytes = glyph.rowBytes(); |
1523 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 1523 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
1524 mask.fImage = (uint8_t*)aa; | 1524 mask.fImage = (uint8_t*)aa; |
1525 do { | 1525 do { |
1526 state.fBlitter->blitMask(mask, cr); | 1526 state.blitMask(mask, cr); |
1527 clipper.next(); | 1527 clipper.next(); |
1528 } while (!clipper.done()); | 1528 } while (!clipper.done()); |
1529 } | 1529 } |
1530 } | 1530 } |
1531 | 1531 |
1532 static void D1G_Bounder(const SkDraw1Glyph& state, | 1532 static void D1G_Bounder(const SkDraw1Glyph& state, |
1533 SkFixed fx, SkFixed fy, | 1533 SkFixed fx, SkFixed fy, |
1534 const SkGlyph& glyph) { | 1534 const SkGlyph& glyph) { |
1535 int left = SkFixedFloor(fx); | 1535 int left = SkFixedFloor(fx); |
1536 int top = SkFixedFloor(fy); | 1536 int top = SkFixedFloor(fy); |
(...skipping 19 matching lines...) Expand all Loading... |
1556 | 1556 |
1557 // we need to pass the origin, which we approximate with our | 1557 // we need to pass the origin, which we approximate with our |
1558 // (unadjusted) left,top coordinates (the caller called fixedfloor) | 1558 // (unadjusted) left,top coordinates (the caller called fixedfloor) |
1559 if (state.fBounder->doIRectGlyph(cr, | 1559 if (state.fBounder->doIRectGlyph(cr, |
1560 left - glyph.fLeft, | 1560 left - glyph.fLeft, |
1561 top - glyph.fTop, glyph)) { | 1561 top - glyph.fTop, glyph)) { |
1562 mask.fRowBytes = glyph.rowBytes(); | 1562 mask.fRowBytes = glyph.rowBytes(); |
1563 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 1563 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
1564 mask.fImage = (uint8_t*)aa; | 1564 mask.fImage = (uint8_t*)aa; |
1565 do { | 1565 do { |
1566 state.fBlitter->blitMask(mask, cr); | 1566 state.blitMask(mask, cr); |
1567 clipper.next(); | 1567 clipper.next(); |
1568 } while (!clipper.done()); | 1568 } while (!clipper.done()); |
1569 } | 1569 } |
1570 } | 1570 } |
1571 } | 1571 } |
1572 | 1572 |
1573 static void D1G_Bounder_AAClip(const SkDraw1Glyph& state, | 1573 static void D1G_Bounder_AAClip(const SkDraw1Glyph& state, |
1574 SkFixed fx, SkFixed fy, | 1574 SkFixed fx, SkFixed fy, |
1575 const SkGlyph& glyph) { | 1575 const SkGlyph& glyph) { |
1576 int left = SkFixedFloor(fx); | 1576 int left = SkFixedFloor(fx); |
1577 int top = SkFixedFloor(fy); | 1577 int top = SkFixedFloor(fy); |
1578 SkIRect bounds; | 1578 SkIRect bounds; |
1579 bounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); | 1579 bounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); |
1580 | 1580 |
1581 if (state.fBounder->doIRectGlyph(bounds, left, top, glyph)) { | 1581 if (state.fBounder->doIRectGlyph(bounds, left, top, glyph)) { |
1582 D1G_NoBounder_RectClip(state, fx, fy, glyph); | 1582 D1G_NoBounder_RectClip(state, fx, fy, glyph); |
1583 } | 1583 } |
1584 } | 1584 } |
1585 | 1585 |
1586 static bool hasCustomD1GProc(const SkDraw& draw) { | 1586 static bool hasCustomD1GProc(const SkDraw& draw) { |
1587 return draw.fProcs && draw.fProcs->fD1GProc; | 1587 return draw.fProcs && draw.fProcs->fD1GProc; |
1588 } | 1588 } |
1589 | 1589 |
1590 static bool needsRasterTextBlit(const SkDraw& draw) { | 1590 static bool needsRasterTextBlit(const SkDraw& draw) { |
1591 return !hasCustomD1GProc(draw); | 1591 return !hasCustomD1GProc(draw); |
1592 } | 1592 } |
1593 | 1593 |
1594 SkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, | 1594 SkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, |
1595 SkGlyphCache* cache) { | 1595 SkGlyphCache* cache, const SkPaint& pnt) { |
1596 fDraw = draw; | 1596 fDraw = draw; |
1597 fBounder = draw->fBounder; | 1597 fBounder = draw->fBounder; |
1598 fBlitter = blitter; | 1598 fBlitter = blitter; |
1599 fCache = cache; | 1599 fCache = cache; |
| 1600 fPaint = &pnt; |
1600 | 1601 |
1601 if (cache->isSubpixel()) { | 1602 if (cache->isSubpixel()) { |
1602 fHalfSampleX = fHalfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); | 1603 fHalfSampleX = fHalfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); |
1603 } else { | 1604 } else { |
1604 fHalfSampleX = fHalfSampleY = SK_FixedHalf; | 1605 fHalfSampleX = fHalfSampleY = SK_FixedHalf; |
1605 } | 1606 } |
1606 | 1607 |
1607 if (hasCustomD1GProc(*draw)) { | 1608 if (hasCustomD1GProc(*draw)) { |
1608 // todo: fix this assumption about clips w/ custom | 1609 // todo: fix this assumption about clips w/ custom |
1609 fClip = draw->fClip; | 1610 fClip = draw->fClip; |
(...skipping 19 matching lines...) Expand all Loading... |
1629 fClip = NULL; | 1630 fClip = NULL; |
1630 fClipBounds = fAAClip->getBounds(); | 1631 fClipBounds = fAAClip->getBounds(); |
1631 if (NULL == fBounder) { | 1632 if (NULL == fBounder) { |
1632 return D1G_NoBounder_RectClip; | 1633 return D1G_NoBounder_RectClip; |
1633 } else { | 1634 } else { |
1634 return D1G_Bounder_AAClip; | 1635 return D1G_Bounder_AAClip; |
1635 } | 1636 } |
1636 } | 1637 } |
1637 } | 1638 } |
1638 | 1639 |
| 1640 void SkDraw1Glyph::blitMaskAsSprite(const SkMask& mask) const { |
| 1641 SkASSERT(SkMask::kARGB32_Format == mask.fFormat); |
| 1642 |
| 1643 SkBitmap bm; |
| 1644 bm.setConfig(SkBitmap::kARGB_8888_Config, |
| 1645 mask.fBounds.width(), mask.fBounds.height(), mask.fRowBytes); |
| 1646 bm.setPixels((SkPMColor*)mask.fImage); |
| 1647 |
| 1648 fDraw->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), *fPaint); |
| 1649 } |
| 1650 |
1639 /////////////////////////////////////////////////////////////////////////////// | 1651 /////////////////////////////////////////////////////////////////////////////// |
1640 | 1652 |
1641 void SkDraw::drawText(const char text[], size_t byteLength, | 1653 void SkDraw::drawText(const char text[], size_t byteLength, |
1642 SkScalar x, SkScalar y, const SkPaint& paint) const { | 1654 SkScalar x, SkScalar y, const SkPaint& paint) const { |
1643 SkASSERT(byteLength == 0 || text != NULL); | 1655 SkASSERT(byteLength == 0 || text != NULL); |
1644 | 1656 |
1645 SkDEBUGCODE(this->validate();) | 1657 SkDEBUGCODE(this->validate();) |
1646 | 1658 |
1647 // nothing to draw | 1659 // nothing to draw |
1648 if (text == NULL || byteLength == 0 || fRC->isEmpty()) { | 1660 if (text == NULL || byteLength == 0 || fRC->isEmpty()) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 blitterChooser.choose(*fBitmap, *fMatrix, paint); | 1709 blitterChooser.choose(*fBitmap, *fMatrix, paint); |
1698 blitter = blitterChooser.get(); | 1710 blitter = blitterChooser.get(); |
1699 if (fRC->isAA()) { | 1711 if (fRC->isAA()) { |
1700 aaBlitter.init(blitter, &fRC->aaRgn()); | 1712 aaBlitter.init(blitter, &fRC->aaRgn()); |
1701 blitter = &aaBlitter; | 1713 blitter = &aaBlitter; |
1702 } | 1714 } |
1703 } | 1715 } |
1704 | 1716 |
1705 SkAutoKern autokern; | 1717 SkAutoKern autokern; |
1706 SkDraw1Glyph d1g; | 1718 SkDraw1Glyph d1g; |
1707 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache); | 1719 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint); |
1708 | 1720 |
1709 SkFixed fxMask = ~0; | 1721 SkFixed fxMask = ~0; |
1710 SkFixed fyMask = ~0; | 1722 SkFixed fyMask = ~0; |
1711 if (cache->isSubpixel()) { | 1723 if (cache->isSubpixel()) { |
1712 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); | 1724 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); |
1713 if (kX_SkAxisAlignment == baseline) { | 1725 if (kX_SkAxisAlignment == baseline) { |
1714 fyMask = 0; | 1726 fyMask = 0; |
1715 d1g.fHalfSampleY = SK_FixedHalf; | 1727 d1g.fHalfSampleY = SK_FixedHalf; |
1716 } else if (kY_SkAxisAlignment == baseline) { | 1728 } else if (kY_SkAxisAlignment == baseline) { |
1717 fxMask = 0; | 1729 fxMask = 0; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 blitter = blitterChooser.get(); | 1871 blitter = blitterChooser.get(); |
1860 if (fRC->isAA()) { | 1872 if (fRC->isAA()) { |
1861 wrapper.init(*fRC, blitter); | 1873 wrapper.init(*fRC, blitter); |
1862 blitter = wrapper.getBlitter(); | 1874 blitter = wrapper.getBlitter(); |
1863 } | 1875 } |
1864 } | 1876 } |
1865 | 1877 |
1866 const char* stop = text + byteLength; | 1878 const char* stop = text + byteLength; |
1867 AlignProc alignProc = pick_align_proc(paint.getTextAlign()); | 1879 AlignProc alignProc = pick_align_proc(paint.getTextAlign()); |
1868 SkDraw1Glyph d1g; | 1880 SkDraw1Glyph d1g; |
1869 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache); | 1881 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint); |
1870 TextMapState tms(*fMatrix, constY); | 1882 TextMapState tms(*fMatrix, constY); |
1871 TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); | 1883 TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); |
1872 | 1884 |
1873 if (cache->isSubpixel()) { | 1885 if (cache->isSubpixel()) { |
1874 // maybe we should skip the rounding if linearText is set | 1886 // maybe we should skip the rounding if linearText is set |
1875 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); | 1887 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); |
1876 | 1888 |
1877 SkFixed fxMask = ~0; | 1889 SkFixed fxMask = ~0; |
1878 SkFixed fyMask = ~0; | 1890 SkFixed fyMask = ~0; |
1879 if (kX_SkAxisAlignment == baseline) { | 1891 if (kX_SkAxisAlignment == baseline) { |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2765 mask->fImage = SkMask::AllocImage(size); | 2777 mask->fImage = SkMask::AllocImage(size); |
2766 memset(mask->fImage, 0, mask->computeImageSize()); | 2778 memset(mask->fImage, 0, mask->computeImageSize()); |
2767 } | 2779 } |
2768 | 2780 |
2769 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2781 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2770 draw_into_mask(*mask, devPath, style); | 2782 draw_into_mask(*mask, devPath, style); |
2771 } | 2783 } |
2772 | 2784 |
2773 return true; | 2785 return true; |
2774 } | 2786 } |
OLD | NEW |