| 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 #define __STDC_LIMIT_MACROS | 7 #define __STDC_LIMIT_MACROS |
| 8 | 8 |
| 9 #include "SkDraw.h" | 9 #include "SkDraw.h" |
| 10 #include "SkBlitter.h" | 10 #include "SkBlitter.h" |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 SkGlyphCache * const fGlyphCache; | 1548 SkGlyphCache * const fGlyphCache; |
| 1549 SkBlitter * const fBlitter; | 1549 SkBlitter * const fBlitter; |
| 1550 const SkRegion* const fClip; | 1550 const SkRegion* const fClip; |
| 1551 const SkDraw& fDraw; | 1551 const SkDraw& fDraw; |
| 1552 const SkPaint& fPaint; | 1552 const SkPaint& fPaint; |
| 1553 const SkIRect fClipBounds; | 1553 const SkIRect fClipBounds; |
| 1554 }; | 1554 }; |
| 1555 | 1555 |
| 1556 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 1556 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 1557 | 1557 |
| 1558 SkPaint::FakeGamma SkDraw::fakeGamma() const { | 1558 uint32_t SkDraw::scalerContextFlags() const { |
| 1559 return fDevice->imageInfo().isLinear() ? SkPaint::FakeGamma::On : SkPaint::F
akeGamma::Off; | 1559 uint32_t flags = SkPaint::kBoostContrast_ScalerContextFlag; |
| 1560 if (fDevice->imageInfo().isLinear()) { |
| 1561 flags |= SkPaint::kFakeGamma_ScalerContextFlag; |
| 1562 } |
| 1563 return flags; |
| 1560 } | 1564 } |
| 1561 | 1565 |
| 1562 void SkDraw::drawText(const char text[], size_t byteLength, | 1566 void SkDraw::drawText(const char text[], size_t byteLength, |
| 1563 SkScalar x, SkScalar y, const SkPaint& paint) const { | 1567 SkScalar x, SkScalar y, const SkPaint& paint) const { |
| 1564 SkASSERT(byteLength == 0 || text != nullptr); | 1568 SkASSERT(byteLength == 0 || text != nullptr); |
| 1565 | 1569 |
| 1566 SkDEBUGCODE(this->validate();) | 1570 SkDEBUGCODE(this->validate();) |
| 1567 | 1571 |
| 1568 // nothing to draw | 1572 // nothing to draw |
| 1569 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { | 1573 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { |
| 1570 return; | 1574 return; |
| 1571 } | 1575 } |
| 1572 | 1576 |
| 1573 // SkScalarRec doesn't currently have a way of representing hairline stroke
and | 1577 // SkScalarRec doesn't currently have a way of representing hairline stroke
and |
| 1574 // will fill if its frame-width is 0. | 1578 // will fill if its frame-width is 0. |
| 1575 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { | 1579 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { |
| 1576 this->drawText_asPaths(text, byteLength, x, y, paint); | 1580 this->drawText_asPaths(text, byteLength, x, y, paint); |
| 1577 return; | 1581 return; |
| 1578 } | 1582 } |
| 1579 | 1583 |
| 1580 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma(), f
Matrix); | 1584 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->scalerContextF
lags(), fMatrix); |
| 1581 | 1585 |
| 1582 // The Blitter Choose needs to be live while using the blitter below. | 1586 // The Blitter Choose needs to be live while using the blitter below. |
| 1583 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); | 1587 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); |
| 1584 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get()); | 1588 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get()); |
| 1585 DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBl
itter()); | 1589 DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBl
itter()); |
| 1586 | 1590 |
| 1587 SkFindAndPlaceGlyph::ProcessText( | 1591 SkFindAndPlaceGlyph::ProcessText( |
| 1588 paint.getTextEncoding(), text, byteLength, | 1592 paint.getTextEncoding(), text, byteLength, |
| 1589 {x, y}, *fMatrix, paint.getTextAlign(), cache.get(), drawOneGlyph); | 1593 {x, y}, *fMatrix, paint.getTextAlign(), cache.get(), drawOneGlyph); |
| 1590 } | 1594 } |
| 1591 | 1595 |
| 1592 ////////////////////////////////////////////////////////////////////////////// | 1596 ////////////////////////////////////////////////////////////////////////////// |
| 1593 | 1597 |
| 1594 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, | 1598 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, |
| 1595 const SkScalar pos[], int scalarsPerPosition, | 1599 const SkScalar pos[], int scalarsPerPosition, |
| 1596 const SkPoint& offset, const SkPaint& origPaint
) const { | 1600 const SkPoint& offset, const SkPaint& origPaint
) const { |
| 1597 // setup our std paint, in hopes of getting hits in the cache | 1601 // setup our std paint, in hopes of getting hits in the cache |
| 1598 SkPaint paint(origPaint); | 1602 SkPaint paint(origPaint); |
| 1599 SkScalar matrixScale = paint.setupForAsPaths(); | 1603 SkScalar matrixScale = paint.setupForAsPaths(); |
| 1600 | 1604 |
| 1601 SkMatrix matrix; | 1605 SkMatrix matrix; |
| 1602 matrix.setScale(matrixScale, matrixScale); | 1606 matrix.setScale(matrixScale, matrixScale); |
| 1603 | 1607 |
| 1604 // Temporarily jam in kFill, so we only ever ask for the raw outline from th
e cache. | 1608 // Temporarily jam in kFill, so we only ever ask for the raw outline from th
e cache. |
| 1605 paint.setStyle(SkPaint::kFill_Style); | 1609 paint.setStyle(SkPaint::kFill_Style); |
| 1606 paint.setPathEffect(nullptr); | 1610 paint.setPathEffect(nullptr); |
| 1607 | 1611 |
| 1608 SkPaint::GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(true); | 1612 SkPaint::GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(true); |
| 1609 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGam
ma(), nullptr); | 1613 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->scalerContextF
lags(), nullptr); |
| 1610 | 1614 |
| 1611 const char* stop = text + byteLength; | 1615 const char* stop = text + byteLength; |
| 1612 SkTextAlignProc alignProc(paint.getTextAlign()); | 1616 SkTextAlignProc alignProc(paint.getTextAlign()); |
| 1613 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); | 1617 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
| 1614 | 1618 |
| 1615 // Now restore the original settings, so we "draw" with whatever style/strok
ing. | 1619 // Now restore the original settings, so we "draw" with whatever style/strok
ing. |
| 1616 paint.setStyle(origPaint.getStyle()); | 1620 paint.setStyle(origPaint.getStyle()); |
| 1617 paint.setPathEffect(sk_ref_sp(origPaint.getPathEffect())); | 1621 paint.setPathEffect(sk_ref_sp(origPaint.getPathEffect())); |
| 1618 | 1622 |
| 1619 while (text < stop) { | 1623 while (text < stop) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1650 // nothing to draw | 1654 // nothing to draw |
| 1651 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { | 1655 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { |
| 1652 return; | 1656 return; |
| 1653 } | 1657 } |
| 1654 | 1658 |
| 1655 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { | 1659 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { |
| 1656 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off
set, paint); | 1660 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off
set, paint); |
| 1657 return; | 1661 return; |
| 1658 } | 1662 } |
| 1659 | 1663 |
| 1660 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma(), f
Matrix); | 1664 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->scalerContextF
lags(), fMatrix); |
| 1661 | 1665 |
| 1662 // The Blitter Choose needs to be live while using the blitter below. | 1666 // The Blitter Choose needs to be live while using the blitter below. |
| 1663 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); | 1667 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); |
| 1664 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get()); | 1668 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get()); |
| 1665 DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBl
itter()); | 1669 DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBl
itter()); |
| 1666 SkPaint::Align textAlignment = paint.getTextAlign(); | 1670 SkPaint::Align textAlignment = paint.getTextAlign(); |
| 1667 | 1671 |
| 1668 SkFindAndPlaceGlyph::ProcessPosText( | 1672 SkFindAndPlaceGlyph::ProcessPosText( |
| 1669 paint.getTextEncoding(), text, byteLength, | 1673 paint.getTextEncoding(), text, byteLength, |
| 1670 offset, *fMatrix, pos, scalarsPerPosition, textAlignment, cache.get(), d
rawOneGlyph); | 1674 offset, *fMatrix, pos, scalarsPerPosition, textAlignment, cache.get(), d
rawOneGlyph); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 mask->fImage = SkMask::AllocImage(size); | 2068 mask->fImage = SkMask::AllocImage(size); |
| 2065 memset(mask->fImage, 0, mask->computeImageSize()); | 2069 memset(mask->fImage, 0, mask->computeImageSize()); |
| 2066 } | 2070 } |
| 2067 | 2071 |
| 2068 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2072 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
| 2069 draw_into_mask(*mask, devPath, style); | 2073 draw_into_mask(*mask, devPath, style); |
| 2070 } | 2074 } |
| 2071 | 2075 |
| 2072 return true; | 2076 return true; |
| 2073 } | 2077 } |
| OLD | NEW |