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

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

Issue 1711223003: Only use fake gamma with linear devices. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Formatting. Created 4 years, 10 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/gpu/text/GrAtlasTextBlob.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 "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkAutoKern.h" 10 #include "SkAutoKern.h"
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 if (zoom) { 1091 if (zoom) {
1092 zoomMatrix.setScale(zoom, zoom); 1092 zoomMatrix.setScale(zoom, zoom);
1093 zoomPtr = &zoomMatrix; 1093 zoomPtr = &zoomMatrix;
1094 } 1094 }
1095 1095
1096 FontMetrics storage; 1096 FontMetrics storage;
1097 if (nullptr == metrics) { 1097 if (nullptr == metrics) {
1098 metrics = &storage; 1098 metrics = &storage;
1099 } 1099 }
1100 1100
1101 paint.descriptorProc(nullptr, zoomPtr, FontMetricsDescProc, metrics, true); 1101 paint.descriptorProc(nullptr, FakeGamma::Off, zoomPtr, FontMetricsDescProc, metrics);
1102 1102
1103 if (scale) { 1103 if (scale) {
1104 metrics->fTop = SkScalarMul(metrics->fTop, scale); 1104 metrics->fTop = SkScalarMul(metrics->fTop, scale);
1105 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); 1105 metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
1106 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); 1106 metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
1107 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); 1107 metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
1108 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); 1108 metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
1109 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); 1109 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
1110 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); 1110 metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
1111 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); 1111 metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 } 1683 }
1684 if (ra) { 1684 if (ra) {
1685 add_flattenable(desc, kRasterizer_SkDescriptorTag, raBuffer); 1685 add_flattenable(desc, kRasterizer_SkDescriptorTag, raBuffer);
1686 } 1686 }
1687 1687
1688 desc->computeChecksum(); 1688 desc->computeChecksum();
1689 } 1689 }
1690 1690
1691 static size_t fill_out_rec(const SkPaint& paint, SkScalerContext::Rec* rec, 1691 static size_t fill_out_rec(const SkPaint& paint, SkScalerContext::Rec* rec,
1692 const SkSurfaceProps* surfaceProps, 1692 const SkSurfaceProps* surfaceProps,
1693 const SkMatrix* deviceMatrix, bool ignoreGamma, 1693 bool fakeGamma,
1694 const SkMatrix* deviceMatrix,
1694 const SkPathEffect* pe, SkWriteBuffer* peBuffer, 1695 const SkPathEffect* pe, SkWriteBuffer* peBuffer,
1695 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer, 1696 const SkMaskFilter* mf, SkWriteBuffer* mfBuffer,
1696 const SkRasterizer* ra, SkWriteBuffer* raBuffer) { 1697 const SkRasterizer* ra, SkWriteBuffer* raBuffer) {
1697 SkScalerContext::MakeRec(paint, surfaceProps, deviceMatrix, rec); 1698 SkScalerContext::MakeRec(paint, surfaceProps, deviceMatrix, rec);
1698 if (ignoreGamma) { 1699 if (!fakeGamma) {
1699 rec->ignorePreBlend(); 1700 rec->ignorePreBlend();
1700 } 1701 }
1701 1702
1702 int entryCount = 1; 1703 int entryCount = 1;
1703 size_t descSize = sizeof(*rec); 1704 size_t descSize = sizeof(*rec);
1704 1705
1705 if (pe) { 1706 if (pe) {
1706 peBuffer->writeFlattenable(pe); 1707 peBuffer->writeFlattenable(pe);
1707 descSize += peBuffer->bytesWritten(); 1708 descSize += peBuffer->bytesWritten();
1708 entryCount += 1; 1709 entryCount += 1;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 desc1->computeChecksum(); 1779 desc1->computeChecksum();
1779 desc2->computeChecksum(); 1780 desc2->computeChecksum();
1780 SkASSERT(!memcmp(desc, desc1, descSize)); 1781 SkASSERT(!memcmp(desc, desc1, descSize));
1781 SkASSERT(!memcmp(desc, desc2, descSize)); 1782 SkASSERT(!memcmp(desc, desc2, descSize));
1782 } 1783 }
1783 #endif 1784 #endif
1784 1785
1785 /* see the note on ignoreGamma on descriptorProc */ 1786 /* see the note on ignoreGamma on descriptorProc */
1786 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad, 1787 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad,
1787 const SkSurfaceProps& surfaceProps, 1788 const SkSurfaceProps& surfaceProps,
1788 const SkMatrix* deviceMatrix, bool igno reGamma) const { 1789 FakeGamma fakeGamma,
1790 const SkMatrix* deviceMatrix) const {
1789 SkScalerContext::Rec rec; 1791 SkScalerContext::Rec rec;
1790 1792
1791 SkPathEffect* pe = this->getPathEffect(); 1793 SkPathEffect* pe = this->getPathEffect();
1792 SkMaskFilter* mf = this->getMaskFilter(); 1794 SkMaskFilter* mf = this->getMaskFilter();
1793 SkRasterizer* ra = this->getRasterizer(); 1795 SkRasterizer* ra = this->getRasterizer();
1794 1796
1795 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1797 SkWriteBuffer peBuffer, mfBuffer, raBuffer;
1796 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps, deviceMatrix, ign oreGamma, 1798 size_t descSize = fill_out_rec(*this, &rec,
1799 &surfaceProps, FakeGamma::On == fakeGamma, de viceMatrix,
1797 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); 1800 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer);
1798 1801
1799 ad->reset(descSize); 1802 ad->reset(descSize);
1800 SkDescriptor* desc = ad->getDesc(); 1803 SkDescriptor* desc = ad->getDesc();
1801 1804
1802 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1805 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1803 1806
1804 SkASSERT(descSize == desc->getLength()); 1807 SkASSERT(descSize == desc->getLength());
1805 1808
1806 #ifdef TEST_DESC 1809 #ifdef TEST_DESC
1807 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); 1810 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
1808 #endif 1811 #endif
1809 } 1812 }
1810 1813
1811 /* 1814 /*
1812 * ignoreGamma tells us that the caller just wants metrics that are unaffected 1815 * ignoreGamma tells us that the caller just wants metrics that are unaffected
1813 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, 1816 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1,
1814 * contrast = 0, luminanceColor = transparent black. 1817 * contrast = 0, luminanceColor = transparent black.
1815 */ 1818 */
1816 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, 1819 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps,
1820 FakeGamma fakeGamma,
1817 const SkMatrix* deviceMatrix, 1821 const SkMatrix* deviceMatrix,
1818 void (*proc)(SkTypeface*, const SkDescriptor*, void *), 1822 void (*proc)(SkTypeface*, const SkDescriptor*, void *),
1819 void* context, bool ignoreGamma) const { 1823 void* context) const {
1820 SkScalerContext::Rec rec; 1824 SkScalerContext::Rec rec;
1821 1825
1822 SkPathEffect* pe = this->getPathEffect(); 1826 SkPathEffect* pe = this->getPathEffect();
1823 SkMaskFilter* mf = this->getMaskFilter(); 1827 SkMaskFilter* mf = this->getMaskFilter();
1824 SkRasterizer* ra = this->getRasterizer(); 1828 SkRasterizer* ra = this->getRasterizer();
1825 1829
1826 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1830 SkWriteBuffer peBuffer, mfBuffer, raBuffer;
1827 size_t descSize = fill_out_rec(*this, &rec, surfaceProps, deviceMatrix, igno reGamma, 1831 size_t descSize = fill_out_rec(*this, &rec,
1832 surfaceProps, FakeGamma::On == fakeGamma, dev iceMatrix,
1828 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); 1833 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer);
1829 1834
1830 SkAutoDescriptor ad(descSize); 1835 SkAutoDescriptor ad(descSize);
1831 SkDescriptor* desc = ad.getDesc(); 1836 SkDescriptor* desc = ad.getDesc();
1832 1837
1833 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1838 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1834 1839
1835 SkASSERT(descSize == desc->getLength()); 1840 SkASSERT(descSize == desc->getLength());
1836 1841
1837 #ifdef TEST_DESC 1842 #ifdef TEST_DESC
1838 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); 1843 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
1839 #endif 1844 #endif
1840 1845
1841 proc(fTypeface, desc, context); 1846 proc(fTypeface, desc, context);
1842 } 1847 }
1843 1848
1844 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, 1849 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps,
1845 const SkMatrix* deviceMatrix, 1850 FakeGamma fakeGamma,
1846 bool ignoreGamma) const { 1851 const SkMatrix* deviceMatrix) const {
1847 SkGlyphCache* cache; 1852 SkGlyphCache* cache;
1848 this->descriptorProc(surfaceProps, deviceMatrix, DetachDescProc, &cache, ign oreGamma); 1853 this->descriptorProc(surfaceProps, fakeGamma, deviceMatrix, DetachDescProc, &cache);
1849 return cache; 1854 return cache;
1850 } 1855 }
1851 1856
1852 /** 1857 /**
1853 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl end. 1858 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl end.
1854 */ 1859 */
1855 //static 1860 //static
1856 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) { 1861 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) {
1857 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); 1862 SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
1858 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), 1863 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(),
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 } 2415 }
2411 } else { 2416 } else {
2412 fScale = SK_Scalar1; 2417 fScale = SK_Scalar1;
2413 } 2418 }
2414 2419
2415 if (!applyStrokeAndPathEffects) { 2420 if (!applyStrokeAndPathEffects) {
2416 fPaint.setStyle(SkPaint::kFill_Style); 2421 fPaint.setStyle(SkPaint::kFill_Style);
2417 fPaint.setPathEffect(nullptr); 2422 fPaint.setPathEffect(nullptr);
2418 } 2423 }
2419 2424
2420 fCache = fPaint.detachCache(nullptr, nullptr, false); 2425 fCache = fPaint.detachCache(nullptr, SkPaint::FakeGamma::On, nullptr);
2421 2426
2422 SkPaint::Style style = SkPaint::kFill_Style; 2427 SkPaint::Style style = SkPaint::kFill_Style;
2423 SkPathEffect* pe = nullptr; 2428 SkPathEffect* pe = nullptr;
2424 2429
2425 if (!applyStrokeAndPathEffects) { 2430 if (!applyStrokeAndPathEffects) {
2426 style = paint.getStyle(); // restore 2431 style = paint.getStyle(); // restore
2427 pe = paint.getPathEffect(); // restore 2432 pe = paint.getPathEffect(); // restore
2428 } 2433 }
2429 fPaint.setStyle(style); 2434 fPaint.setStyle(style);
2430 fPaint.setPathEffect(pe); 2435 fPaint.setPathEffect(pe);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 } 2535 }
2531 2536
2532 uint32_t SkPaint::getHash() const { 2537 uint32_t SkPaint::getHash() const {
2533 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, 2538 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields,
2534 // so fBitfields should be 10 pointers and 6 32-bit values from the start. 2539 // so fBitfields should be 10 pointers and 6 32-bit values from the start.
2535 static_assert(offsetof(SkPaint, fBitfields) == 10 * sizeof(void*) + 6 * size of(uint32_t), 2540 static_assert(offsetof(SkPaint, fBitfields) == 10 * sizeof(void*) + 6 * size of(uint32_t),
2536 "SkPaint_notPackedTightly"); 2541 "SkPaint_notPackedTightly");
2537 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), 2542 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this),
2538 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); 2543 offsetof(SkPaint, fBitfields) + sizeof(fBitfields ));
2539 } 2544 }
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | src/gpu/text/GrAtlasTextBlob.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698