Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/core/SkPaint.cpp

Issue 1866293003: Decouple contrast boost from fake gamma. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Improve ignorePreBlend API, add storage type to enum Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | src/core/SkScalerContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_ScalerContextFlags, zoomPtr, FontMetrics DescProc, 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
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();
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
(...skipping 14 matching lines...) Expand all
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->ignoreGamma();
1562 }
1563 if (!boostContrast) {
1564 rec->setContrast(0);
1562 } 1565 }
1563 1566
1564 int entryCount = 1; 1567 int entryCount = 1;
1565 size_t descSize = sizeof(*rec); 1568 size_t descSize = sizeof(*rec);
1566 1569
1567 if (pe) { 1570 if (pe) {
1568 peBuffer->writeFlattenable(pe); 1571 peBuffer->writeFlattenable(pe);
1569 descSize += peBuffer->bytesWritten(); 1572 descSize += peBuffer->bytesWritten();
1570 entryCount += 1; 1573 entryCount += 1;
1571 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion 1574 rec->fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 desc1->computeChecksum(); 1643 desc1->computeChecksum();
1641 desc2->computeChecksum(); 1644 desc2->computeChecksum();
1642 SkASSERT(!memcmp(desc, desc1, descSize)); 1645 SkASSERT(!memcmp(desc, desc1, descSize));
1643 SkASSERT(!memcmp(desc, desc2, descSize)); 1646 SkASSERT(!memcmp(desc, desc2, descSize));
1644 } 1647 }
1645 #endif 1648 #endif
1646 1649
1647 /* see the note on ignoreGamma on descriptorProc */ 1650 /* see the note on ignoreGamma on descriptorProc */
1648 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad, 1651 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad,
1649 const SkSurfaceProps& surfaceProps, 1652 const SkSurfaceProps& surfaceProps,
1650 FakeGamma fakeGamma, 1653 uint32_t scalerContextFlags,
1651 const SkMatrix* deviceMatrix) const { 1654 const SkMatrix* deviceMatrix) const {
1652 SkScalerContext::Rec rec; 1655 SkScalerContext::Rec rec;
1653 1656
1654 SkPathEffect* pe = this->getPathEffect(); 1657 SkPathEffect* pe = this->getPathEffect();
1655 SkMaskFilter* mf = this->getMaskFilter(); 1658 SkMaskFilter* mf = this->getMaskFilter();
1656 SkRasterizer* ra = this->getRasterizer(); 1659 SkRasterizer* ra = this->getRasterizer();
1657 1660
1658 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1661 SkWriteBuffer peBuffer, mfBuffer, raBuffer;
1659 size_t descSize = fill_out_rec(*this, &rec, 1662 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps,
1660 &surfaceProps, FakeGamma::On == fakeGamma, de viceMatrix, 1663 SkToBool(scalerContextFlags & kFakeGamma_Scal erContextFlag),
1661 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); 1664 SkToBool(scalerContextFlags & kBoostContrast_ ScalerContextFlag),
1665 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer);
1662 1666
1663 ad->reset(descSize); 1667 ad->reset(descSize);
1664 SkDescriptor* desc = ad->getDesc(); 1668 SkDescriptor* desc = ad->getDesc();
1665 1669
1666 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1670 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1667 1671
1668 SkASSERT(descSize == desc->getLength()); 1672 SkASSERT(descSize == desc->getLength());
1669 1673
1670 #ifdef TEST_DESC 1674 #ifdef TEST_DESC
1671 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); 1675 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
1672 #endif 1676 #endif
1673 } 1677 }
1674 1678
1675 /* 1679 /*
1676 * ignoreGamma tells us that the caller just wants metrics that are unaffected 1680 * 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, 1681 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1,
1678 * contrast = 0, luminanceColor = transparent black. 1682 * contrast = 0, luminanceColor = transparent black.
1679 */ 1683 */
1680 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, 1684 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps,
1681 FakeGamma fakeGamma, 1685 uint32_t scalerContextFlags,
1682 const SkMatrix* deviceMatrix, 1686 const SkMatrix* deviceMatrix,
1683 void (*proc)(SkTypeface*, const SkDescriptor*, void *), 1687 void (*proc)(SkTypeface*, const SkDescriptor*, void *),
1684 void* context) const { 1688 void* context) const {
1685 SkScalerContext::Rec rec; 1689 SkScalerContext::Rec rec;
1686 1690
1687 SkPathEffect* pe = this->getPathEffect(); 1691 SkPathEffect* pe = this->getPathEffect();
1688 SkMaskFilter* mf = this->getMaskFilter(); 1692 SkMaskFilter* mf = this->getMaskFilter();
1689 SkRasterizer* ra = this->getRasterizer(); 1693 SkRasterizer* ra = this->getRasterizer();
1690 1694
1691 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1695 SkWriteBuffer peBuffer, mfBuffer, raBuffer;
1692 size_t descSize = fill_out_rec(*this, &rec, 1696 size_t descSize = fill_out_rec(*this, &rec, surfaceProps,
1693 surfaceProps, FakeGamma::On == fakeGamma, dev iceMatrix, 1697 SkToBool(scalerContextFlags & kFakeGamma_Scal erContextFlag),
1694 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); 1698 SkToBool(scalerContextFlags & kBoostContrast_ ScalerContextFlag),
1699 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r a, &raBuffer);
1695 1700
1696 SkAutoDescriptor ad(descSize); 1701 SkAutoDescriptor ad(descSize);
1697 SkDescriptor* desc = ad.getDesc(); 1702 SkDescriptor* desc = ad.getDesc();
1698 1703
1699 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1704 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1700 1705
1701 SkASSERT(descSize == desc->getLength()); 1706 SkASSERT(descSize == desc->getLength());
1702 1707
1703 #ifdef TEST_DESC 1708 #ifdef TEST_DESC
1704 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); 1709 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
1705 #endif 1710 #endif
1706 1711
1707 proc(fTypeface.get(), desc, context); 1712 proc(fTypeface.get(), desc, context);
1708 } 1713 }
1709 1714
1710 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, 1715 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps,
1711 FakeGamma fakeGamma, 1716 uint32_t scalerContextFlags,
1712 const SkMatrix* deviceMatrix) const { 1717 const SkMatrix* deviceMatrix) const {
1713 SkGlyphCache* cache; 1718 SkGlyphCache* cache;
1714 this->descriptorProc(surfaceProps, fakeGamma, deviceMatrix, DetachDescProc, &cache); 1719 this->descriptorProc(surfaceProps, scalerContextFlags, deviceMatrix, DetachD escProc, &cache);
1715 return cache; 1720 return cache;
1716 } 1721 }
1717 1722
1718 /** 1723 /**
1719 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl end. 1724 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl end.
1720 */ 1725 */
1721 //static 1726 //static
1722 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) { 1727 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) {
1723 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); 1728 SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
1724 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), 1729 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(),
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 } 2244 }
2240 } else { 2245 } else {
2241 fScale = SK_Scalar1; 2246 fScale = SK_Scalar1;
2242 } 2247 }
2243 2248
2244 if (!applyStrokeAndPathEffects) { 2249 if (!applyStrokeAndPathEffects) {
2245 fPaint.setStyle(SkPaint::kFill_Style); 2250 fPaint.setStyle(SkPaint::kFill_Style);
2246 fPaint.setPathEffect(nullptr); 2251 fPaint.setPathEffect(nullptr);
2247 } 2252 }
2248 2253
2249 fCache = fPaint.detachCache(nullptr, SkPaint::FakeGamma::On, nullptr); 2254 // SRGBTODO: Is this correct?
2255 fCache = fPaint.detachCache(nullptr, SkPaint::kFakeGammaAndBoostContrast_Sca lerContextFlags,
2256 nullptr);
2250 2257
2251 SkPaint::Style style = SkPaint::kFill_Style; 2258 SkPaint::Style style = SkPaint::kFill_Style;
2252 sk_sp<SkPathEffect> pe; 2259 sk_sp<SkPathEffect> pe;
2253 2260
2254 if (!applyStrokeAndPathEffects) { 2261 if (!applyStrokeAndPathEffects) {
2255 style = paint.getStyle(); // restore 2262 style = paint.getStyle(); // restore
2256 pe = sk_ref_sp(paint.getPathEffect()); // restore 2263 pe = sk_ref_sp(paint.getPathEffect()); // restore
2257 } 2264 }
2258 fPaint.setStyle(style); 2265 fPaint.setStyle(style);
2259 fPaint.setPathEffect(pe); 2266 fPaint.setPathEffect(pe);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 } 2366 }
2360 2367
2361 uint32_t SkPaint::getHash() const { 2368 uint32_t SkPaint::getHash() const {
2362 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, 2369 // 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. 2370 // 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), 2371 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t),
2365 "SkPaint_notPackedTightly"); 2372 "SkPaint_notPackedTightly");
2366 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), 2373 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this),
2367 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); 2374 offsetof(SkPaint, fBitfields) + sizeof(fBitfields ));
2368 } 2375 }
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | src/core/SkScalerContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698