Chromium Code Reviews| 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 #include "SkPaint.h" | 8 #include "SkPaint.h" |
| 9 #include "SkAutoKern.h" | 9 #include "SkAutoKern.h" |
| 10 #include "SkChecksum.h" | 10 #include "SkChecksum.h" |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 if (zoom) { | 952 if (zoom) { |
| 953 zoomMatrix.setScale(zoom, zoom); | 953 zoomMatrix.setScale(zoom, zoom); |
| 954 zoomPtr = &zoomMatrix; | 954 zoomPtr = &zoomMatrix; |
| 955 } | 955 } |
| 956 | 956 |
| 957 FontMetrics storage; | 957 FontMetrics storage; |
| 958 if (nullptr == metrics) { | 958 if (nullptr == metrics) { |
| 959 metrics = &storage; | 959 metrics = &storage; |
| 960 } | 960 } |
| 961 | 961 |
| 962 paint.descriptorProc(nullptr, FakeGamma::Off, zoomPtr, FontMetricsDescProc, metrics); | 962 paint.descriptorProc(nullptr, kNone_FontWeightFlag, zoomPtr, FontMetricsDesc Proc, metrics); |
| 963 | 963 |
| 964 if (scale) { | 964 if (scale) { |
| 965 metrics->fTop = SkScalarMul(metrics->fTop, scale); | 965 metrics->fTop = SkScalarMul(metrics->fTop, scale); |
| 966 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); | 966 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); |
| 967 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); | 967 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); |
| 968 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); | 968 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); |
| 969 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); | 969 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); |
| 970 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); | 970 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); |
| 971 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); | 971 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); |
| 972 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); | 972 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1509 SkColor color = rec->getLuminanceColor(); | 1509 SkColor color = rec->getLuminanceColor(); |
| 1510 U8CPU lum = SkComputeLuminance(SkColorGetR(color), | 1510 U8CPU lum = SkComputeLuminance(SkColorGetR(color), |
| 1511 SkColorGetG(color), | 1511 SkColorGetG(color), |
| 1512 SkColorGetB(color)); | 1512 SkColorGetB(color)); |
| 1513 // reduce to our finite number of bits | 1513 // reduce to our finite number of bits |
| 1514 color = SkColorSetRGB(lum, lum, lum); | 1514 color = SkColorSetRGB(lum, lum, lum); |
| 1515 rec->setLuminanceColor(SkMaskGamma::CanonicalColor(color)); | 1515 rec->setLuminanceColor(SkMaskGamma::CanonicalColor(color)); |
| 1516 break; | 1516 break; |
| 1517 } | 1517 } |
| 1518 case SkMask::kBW_Format: | 1518 case SkMask::kBW_Format: |
| 1519 // No need to differentiate gamma if we're BW | 1519 // No need to differentiate gamma or apply contrast if we're BW |
| 1520 rec->ignorePreBlend(); | 1520 rec->ignorePreBlend(false); |
| 1521 break; | 1521 break; |
| 1522 } | 1522 } |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024 | 1525 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024 |
| 1526 | 1526 |
| 1527 #ifdef SK_DEBUG | 1527 #ifdef SK_DEBUG |
| 1528 #define TEST_DESC | 1528 #define TEST_DESC |
| 1529 #endif | 1529 #endif |
| 1530 | 1530 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1544 } | 1544 } |
| 1545 if (ra) { | 1545 if (ra) { |
| 1546 add_flattenable(desc, kRasterizer_SkDescriptorTag, raBuffer); | 1546 add_flattenable(desc, kRasterizer_SkDescriptorTag, raBuffer); |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 desc->computeChecksum(); | 1549 desc->computeChecksum(); |
| 1550 } | 1550 } |
| 1551 | 1551 |
| 1552 static size_t fill_out_rec(const SkPaint& paint, SkScalerContext::Rec* rec, | 1552 static size_t fill_out_rec(const SkPaint& paint, SkScalerContext::Rec* rec, |
| 1553 const SkSurfaceProps* surfaceProps, | 1553 const SkSurfaceProps* surfaceProps, |
| 1554 bool fakeGamma, | 1554 bool fakeGamma, bool boostContrast, |
| 1555 const SkMatrix* deviceMatrix, | 1555 const SkMatrix* deviceMatrix, |
| 1556 const SkPathEffect* pe, SkWriteBuffer* peBuffer, | 1556 const SkPathEffect* pe, SkWriteBuffer* peBuffer, |
| 1557 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer, | 1557 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer, |
| 1558 const SkRasterizer* ra, SkWriteBuffer* raBuffer) { | 1558 const SkRasterizer* ra, SkWriteBuffer* raBuffer) { |
| 1559 SkScalerContext::MakeRec(paint, surfaceProps, deviceMatrix, rec); | 1559 SkScalerContext::MakeRec(paint, surfaceProps, deviceMatrix, rec); |
| 1560 if (!fakeGamma) { | 1560 if (!fakeGamma) { |
| 1561 rec->ignorePreBlend(); | 1561 rec->ignorePreBlend(boostContrast); |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 int entryCount = 1; | 1564 int entryCount = 1; |
| 1565 size_t descSize = sizeof(*rec); | 1565 size_t descSize = sizeof(*rec); |
| 1566 | 1566 |
| 1567 if (pe) { | 1567 if (pe) { |
| 1568 peBuffer->writeFlattenable(pe); | 1568 peBuffer->writeFlattenable(pe); |
| 1569 descSize += peBuffer->bytesWritten(); | 1569 descSize += peBuffer->bytesWritten(); |
| 1570 entryCount += 1; | 1570 entryCount += 1; |
| 1571 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion | 1571 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion |
| 1572 // seems like we could support kLCD as well at this point... | 1572 // seems like we could support kLCD as well at this point... |
| 1573 } | 1573 } |
| 1574 if (mf) { | 1574 if (mf) { |
| 1575 mfBuffer->writeFlattenable(mf); | 1575 mfBuffer->writeFlattenable(mf); |
| 1576 descSize += mfBuffer->bytesWritten(); | 1576 descSize += mfBuffer->bytesWritten(); |
| 1577 entryCount += 1; | 1577 entryCount += 1; |
| 1578 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing with mask filters | 1578 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing with mask filters |
| 1579 /* Pre-blend is not currently applied to filtered text. | 1579 /* Pre-blend is not currently applied to filtered text. |
| 1580 The primary filter is blur, for which contrast makes no sense, | 1580 The primary filter is blur, for which contrast makes no sense, |
| 1581 and for which the destination guess error is more visible. | 1581 and for which the destination guess error is more visible. |
| 1582 Also, all existing users of blur have calibrated for linear. */ | 1582 Also, all existing users of blur have calibrated for linear. */ |
| 1583 rec->ignorePreBlend(); | 1583 rec->ignorePreBlend(false); |
| 1584 } | 1584 } |
| 1585 if (ra) { | 1585 if (ra) { |
| 1586 raBuffer->writeFlattenable(ra); | 1586 raBuffer->writeFlattenable(ra); |
| 1587 descSize += raBuffer->bytesWritten(); | 1587 descSize += raBuffer->bytesWritten(); |
| 1588 entryCount += 1; | 1588 entryCount += 1; |
| 1589 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion | 1589 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion |
| 1590 } | 1590 } |
| 1591 | 1591 |
| 1592 /////////////////////////////////////////////////////////////////////////// | 1592 /////////////////////////////////////////////////////////////////////////// |
| 1593 // Now that we're done tweaking the rec, call the PostMakeRec cleanup | 1593 // Now that we're done tweaking the rec, call the PostMakeRec cleanup |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 desc1->computeChecksum(); | 1640 desc1->computeChecksum(); |
| 1641 desc2->computeChecksum(); | 1641 desc2->computeChecksum(); |
| 1642 SkASSERT(!memcmp(desc, desc1, descSize)); | 1642 SkASSERT(!memcmp(desc, desc1, descSize)); |
| 1643 SkASSERT(!memcmp(desc, desc2, descSize)); | 1643 SkASSERT(!memcmp(desc, desc2, descSize)); |
| 1644 } | 1644 } |
| 1645 #endif | 1645 #endif |
| 1646 | 1646 |
| 1647 /* see the note on ignoreGamma on descriptorProc */ | 1647 /* see the note on ignoreGamma on descriptorProc */ |
| 1648 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad, | 1648 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad, |
| 1649 const SkSurfaceProps& surfaceProps, | 1649 const SkSurfaceProps& surfaceProps, |
| 1650 FakeGamma fakeGamma, | 1650 uint32_t fontWeightFlags, |
| 1651 const SkMatrix* deviceMatrix) const { | 1651 const SkMatrix* deviceMatrix) const { |
| 1652 SkScalerContext::Rec rec; | 1652 SkScalerContext::Rec rec; |
| 1653 | 1653 |
| 1654 SkPathEffect* pe = this->getPathEffect(); | 1654 SkPathEffect* pe = this->getPathEffect(); |
| 1655 SkMaskFilter* mf = this->getMaskFilter(); | 1655 SkMaskFilter* mf = this->getMaskFilter(); |
| 1656 SkRasterizer* ra = this->getRasterizer(); | 1656 SkRasterizer* ra = this->getRasterizer(); |
| 1657 | 1657 |
| 1658 SkWriteBuffer peBuffer, mfBuffer, raBuffer; | 1658 SkWriteBuffer peBuffer, mfBuffer, raBuffer; |
| 1659 size_t descSize = fill_out_rec(*this, &rec, | 1659 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps, |
| 1660 &surfaceProps, FakeGamma::On == fakeGamma, de viceMatrix, | 1660 SkToBool(fontWeightFlags & kFakeGamma_FontWei ghtFlag), |
| 1661 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); | 1661 SkToBool(fontWeightFlags & kBoostContrast_Fon tWeightFlag), |
| 1662 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer); | |
| 1662 | 1663 |
| 1663 ad->reset(descSize); | 1664 ad->reset(descSize); |
| 1664 SkDescriptor* desc = ad->getDesc(); | 1665 SkDescriptor* desc = ad->getDesc(); |
| 1665 | 1666 |
| 1666 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); | 1667 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); |
| 1667 | 1668 |
| 1668 SkASSERT(descSize == desc->getLength()); | 1669 SkASSERT(descSize == desc->getLength()); |
| 1669 | 1670 |
| 1670 #ifdef TEST_DESC | 1671 #ifdef TEST_DESC |
| 1671 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); | 1672 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); |
| 1672 #endif | 1673 #endif |
| 1673 } | 1674 } |
| 1674 | 1675 |
| 1675 /* | 1676 /* |
| 1676 * ignoreGamma tells us that the caller just wants metrics that are unaffected | 1677 * ignoreGamma tells us that the caller just wants metrics that are unaffected |
| 1677 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, | 1678 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, |
| 1678 * contrast = 0, luminanceColor = transparent black. | 1679 * contrast = 0, luminanceColor = transparent black. |
| 1679 */ | 1680 */ |
| 1680 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, | 1681 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, |
| 1681 FakeGamma fakeGamma, | 1682 uint32_t fontWeightFlags, |
| 1682 const SkMatrix* deviceMatrix, | 1683 const SkMatrix* deviceMatrix, |
| 1683 void (*proc)(SkTypeface*, const SkDescriptor*, void *), | 1684 void (*proc)(SkTypeface*, const SkDescriptor*, void *), |
| 1684 void* context) const { | 1685 void* context) const { |
| 1685 SkScalerContext::Rec rec; | 1686 SkScalerContext::Rec rec; |
| 1686 | 1687 |
| 1687 SkPathEffect* pe = this->getPathEffect(); | 1688 SkPathEffect* pe = this->getPathEffect(); |
| 1688 SkMaskFilter* mf = this->getMaskFilter(); | 1689 SkMaskFilter* mf = this->getMaskFilter(); |
| 1689 SkRasterizer* ra = this->getRasterizer(); | 1690 SkRasterizer* ra = this->getRasterizer(); |
| 1690 | 1691 |
| 1691 SkWriteBuffer peBuffer, mfBuffer, raBuffer; | 1692 SkWriteBuffer peBuffer, mfBuffer, raBuffer; |
| 1692 size_t descSize = fill_out_rec(*this, &rec, | 1693 size_t descSize = fill_out_rec(*this, &rec, surfaceProps, |
| 1693 surfaceProps, FakeGamma::On == fakeGamma, dev iceMatrix, | 1694 SkToBool(fontWeightFlags & kFakeGamma_FontWei ghtFlag), |
| 1694 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); | 1695 SkToBool(fontWeightFlags & kBoostContrast_Fon tWeightFlag), |
| 1696 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer); | |
| 1695 | 1697 |
| 1696 SkAutoDescriptor ad(descSize); | 1698 SkAutoDescriptor ad(descSize); |
| 1697 SkDescriptor* desc = ad.getDesc(); | 1699 SkDescriptor* desc = ad.getDesc(); |
| 1698 | 1700 |
| 1699 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); | 1701 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); |
| 1700 | 1702 |
| 1701 SkASSERT(descSize == desc->getLength()); | 1703 SkASSERT(descSize == desc->getLength()); |
| 1702 | 1704 |
| 1703 #ifdef TEST_DESC | 1705 #ifdef TEST_DESC |
| 1704 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); | 1706 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); |
| 1705 #endif | 1707 #endif |
| 1706 | 1708 |
| 1707 proc(fTypeface.get(), desc, context); | 1709 proc(fTypeface.get(), desc, context); |
| 1708 } | 1710 } |
| 1709 | 1711 |
| 1710 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, | 1712 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, |
| 1711 FakeGamma fakeGamma, | 1713 uint32_t fontWeightFlags, |
| 1712 const SkMatrix* deviceMatrix) const { | 1714 const SkMatrix* deviceMatrix) const { |
| 1713 SkGlyphCache* cache; | 1715 SkGlyphCache* cache; |
| 1714 this->descriptorProc(surfaceProps, fakeGamma, deviceMatrix, DetachDescProc, &cache); | 1716 this->descriptorProc(surfaceProps, fontWeightFlags, deviceMatrix, DetachDesc Proc, &cache); |
| 1715 return cache; | 1717 return cache; |
| 1716 } | 1718 } |
| 1717 | 1719 |
| 1718 /** | 1720 /** |
| 1719 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl end. | 1721 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl end. |
| 1720 */ | 1722 */ |
| 1721 //static | 1723 //static |
| 1722 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) { | 1724 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) { |
| 1723 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); | 1725 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); |
| 1724 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), | 1726 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2239 } | 2241 } |
| 2240 } else { | 2242 } else { |
| 2241 fScale = SK_Scalar1; | 2243 fScale = SK_Scalar1; |
| 2242 } | 2244 } |
| 2243 | 2245 |
| 2244 if (!applyStrokeAndPathEffects) { | 2246 if (!applyStrokeAndPathEffects) { |
| 2245 fPaint.setStyle(SkPaint::kFill_Style); | 2247 fPaint.setStyle(SkPaint::kFill_Style); |
| 2246 fPaint.setPathEffect(nullptr); | 2248 fPaint.setPathEffect(nullptr); |
| 2247 } | 2249 } |
| 2248 | 2250 |
| 2249 fCache = fPaint.detachCache(nullptr, SkPaint::FakeGamma::On, nullptr); | 2251 // SRGBTODO: Is this correct? |
| 2252 fCache = fPaint.detachCache(nullptr, SkPaint::kFakeGammaAndContrast_FontWeig htFlag, nullptr); | |
|
Brian Osman
2016/04/07 17:08:32
It seems like the choice of flags here may be arbi
| |
| 2250 | 2253 |
| 2251 SkPaint::Style style = SkPaint::kFill_Style; | 2254 SkPaint::Style style = SkPaint::kFill_Style; |
| 2252 sk_sp<SkPathEffect> pe; | 2255 sk_sp<SkPathEffect> pe; |
| 2253 | 2256 |
| 2254 if (!applyStrokeAndPathEffects) { | 2257 if (!applyStrokeAndPathEffects) { |
| 2255 style = paint.getStyle(); // restore | 2258 style = paint.getStyle(); // restore |
| 2256 pe = sk_ref_sp(paint.getPathEffect()); // restore | 2259 pe = sk_ref_sp(paint.getPathEffect()); // restore |
| 2257 } | 2260 } |
| 2258 fPaint.setStyle(style); | 2261 fPaint.setStyle(style); |
| 2259 fPaint.setPathEffect(pe); | 2262 fPaint.setPathEffect(pe); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2359 } | 2362 } |
| 2360 | 2363 |
| 2361 uint32_t SkPaint::getHash() const { | 2364 uint32_t SkPaint::getHash() const { |
| 2362 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, | 2365 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, |
| 2363 // so fBitfields should be 10 pointers and 6 32-bit values from the start. | 2366 // so fBitfields should be 10 pointers and 6 32-bit values from the start. |
| 2364 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t), | 2367 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t), |
| 2365 "SkPaint_notPackedTightly"); | 2368 "SkPaint_notPackedTightly"); |
| 2366 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), | 2369 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), |
| 2367 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); | 2370 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); |
| 2368 } | 2371 } |
| OLD | NEW |