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

Side by Side Diff: src/gpu/GrAtlasTextContext.cpp

Issue 1189223002: Remove gamma field from SkDeviceProperties (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Cleanup DistanceAdjustTable Created 5 years, 6 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/gpu/GrAtlasTextContext.h ('k') | no next file » | 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 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 #include "GrAtlasTextContext.h" 7 #include "GrAtlasTextContext.h"
8 8
9 #include "GrBatch.h" 9 #include "GrBatch.h"
10 #include "GrBatchFontCache.h" 10 #include "GrBatchFontCache.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 }; 93 };
94 94
95 // TODO 95 // TODO
96 // Distance field text in textblobs 96 // Distance field text in textblobs
97 97
98 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, 98 GrAtlasTextContext::GrAtlasTextContext(GrContext* context,
99 GrDrawContext* drawContext, 99 GrDrawContext* drawContext,
100 const SkDeviceProperties& properties) 100 const SkDeviceProperties& properties)
101 : INHERITED(context, drawContext, properties) 101 : INHERITED(context, drawContext, properties)
102 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma())) ) { 102 , fDistanceAdjustTable(SkNEW(DistanceAdjustTable)) {
103 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest 103 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
104 // vertexStride 104 // vertexStride
105 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize, 105 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize,
106 vertex_attribute_changed); 106 vertex_attribute_changed);
107 fCurrStrike = NULL; 107 fCurrStrike = NULL;
108 fCache = context->getTextBlobCache(); 108 fCache = context->getTextBlobCache();
109 } 109 }
110 110
111 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gam ma) { 111 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable() {
112 112
113 // This is used for an approximation of the mask gamma hack, used by raster and bitmap 113 // This is used for an approximation of the mask gamma hack, used by raster and bitmap
114 // text. The mask gamma hack is based off of guessing what the blend color i s going to 114 // text. The mask gamma hack is based off of guessing what the blend color i s going to
115 // be, and adjusting the mask so that when run through the linear blend will 115 // be, and adjusting the mask so that when run through the linear blend will
116 // produce the value closest to the desired result. However, in practice thi s means 116 // produce the value closest to the desired result. However, in practice thi s means
117 // that the 'adjusted' mask is just increasing or decreasing the coverage of 117 // that the 'adjusted' mask is just increasing or decreasing the coverage of
118 // the mask depending on what it is thought it will blit against. For black (on 118 // the mask depending on what it is thought it will blit against. For black (on
119 // assumed white) this means that coverages are decreased (on a curve). For white (on 119 // assumed white) this means that coverages are decreased (on a curve). For white (on
120 // assumed black) this means that coverages are increased (on a a curve). At 120 // assumed black) this means that coverages are increased (on a a curve). At
121 // middle (perceptual) gray (which could be blit against anything) the cover ages 121 // middle (perceptual) gray (which could be blit against anything) the cover ages
(...skipping 24 matching lines...) Expand all
146 // previously covered at all. 146 // previously covered at all.
147 147
148 int width, height; 148 int width, height;
149 size_t size; 149 size_t size;
150 150
151 #ifdef SK_GAMMA_CONTRAST 151 #ifdef SK_GAMMA_CONTRAST
152 SkScalar contrast = SK_GAMMA_CONTRAST; 152 SkScalar contrast = SK_GAMMA_CONTRAST;
153 #else 153 #else
154 SkScalar contrast = 0.5f; 154 SkScalar contrast = 0.5f;
155 #endif 155 #endif
156 SkScalar paintGamma = gamma; 156 SkScalar paintGamma = SK_GAMMA_EXPONENT;
157 SkScalar deviceGamma = gamma; 157 SkScalar deviceGamma = SK_GAMMA_EXPONENT;
158 158
159 size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, 159 size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma,
160 &width, &height); 160 &width, &height);
161 161
162 SkASSERT(kExpectedDistanceAdjustTableSize == height); 162 SkASSERT(kExpectedDistanceAdjustTableSize == height);
163 fTable = SkNEW_ARRAY(SkScalar, height); 163 fTable = SkNEW_ARRAY(SkScalar, height);
164 164
165 SkAutoTArray<uint8_t> data((int)size); 165 SkAutoTArray<uint8_t> data((int)size);
166 SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get ()); 166 SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get ());
167 167
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 1443
1444 static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount, 1444 static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount,
1445 GrBatchFontCache* fontCache) { 1445 GrBatchFontCache* fontCache) {
1446 return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache)); 1446 return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache));
1447 } 1447 }
1448 1448
1449 static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount, 1449 static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount,
1450 GrBatchFontCache* fontCache, 1450 GrBatchFontCache* fontCache,
1451 DistanceAdjustTable* distanceAdjustTable, 1451 DistanceAdjustTable* distanceAdjustTable,
1452 SkColor filteredColor, bool useLCDText, 1452 SkColor filteredColor, bool useLCDText,
1453 bool useBGR, float gamma) { 1453 bool useBGR) {
1454 return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache, d istanceAdjustTable, 1454 return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache, d istanceAdjustTable,
1455 filteredColor, useLCDText, useBGR, g amma)); 1455 filteredColor, useLCDText, useBGR));
1456 } 1456 }
1457 1457
1458 const char* name() const override { return "BitmapTextBatch"; } 1458 const char* name() const override { return "BitmapTextBatch"; }
1459 1459
1460 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 1460 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
1461 if (kARGB_GrMaskFormat == fMaskFormat) { 1461 if (kARGB_GrMaskFormat == fMaskFormat) {
1462 out->setUnknownFourComponents(); 1462 out->setUnknownFourComponents();
1463 } else { 1463 } else {
1464 out->setKnownFourComponents(fBatch.fColor); 1464 out->setKnownFourComponents(fBatch.fColor);
1465 } 1465 }
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 , fFontCache(fontCache) 1766 , fFontCache(fontCache)
1767 , fUseDistanceFields(false) { 1767 , fUseDistanceFields(false) {
1768 this->initClassID<BitmapTextBatch>(); 1768 this->initClassID<BitmapTextBatch>();
1769 fBatch.fNumGlyphs = glyphCount; 1769 fBatch.fNumGlyphs = glyphCount;
1770 fInstanceCount = 1; 1770 fInstanceCount = 1;
1771 fAllocatedCount = kMinAllocated; 1771 fAllocatedCount = kMinAllocated;
1772 } 1772 }
1773 1773
1774 BitmapTextBatch(GrMaskFormat maskFormat, int glyphCount, GrBatchFontCache* f ontCache, 1774 BitmapTextBatch(GrMaskFormat maskFormat, int glyphCount, GrBatchFontCache* f ontCache,
1775 DistanceAdjustTable* distanceAdjustTable, SkColor filteredCo lor, 1775 DistanceAdjustTable* distanceAdjustTable, SkColor filteredCo lor,
1776 bool useLCDText, bool useBGR, float gamma) 1776 bool useLCDText, bool useBGR)
1777 : fMaskFormat(maskFormat) 1777 : fMaskFormat(maskFormat)
1778 , fPixelConfig(fontCache->getPixelConfig(maskFormat)) 1778 , fPixelConfig(fontCache->getPixelConfig(maskFormat))
1779 , fFontCache(fontCache) 1779 , fFontCache(fontCache)
1780 , fDistanceAdjustTable(SkRef(distanceAdjustTable)) 1780 , fDistanceAdjustTable(SkRef(distanceAdjustTable))
1781 , fFilteredColor(filteredColor) 1781 , fFilteredColor(filteredColor)
1782 , fUseDistanceFields(true) 1782 , fUseDistanceFields(true)
1783 , fUseLCDText(useLCDText) 1783 , fUseLCDText(useLCDText)
1784 , fUseBGR(useBGR) 1784 , fUseBGR(useBGR) {
1785 , fGamma(gamma) {
1786 this->initClassID<BitmapTextBatch>(); 1785 this->initClassID<BitmapTextBatch>();
1787 fBatch.fNumGlyphs = glyphCount; 1786 fBatch.fNumGlyphs = glyphCount;
1788 fInstanceCount = 1; 1787 fInstanceCount = 1;
1789 fAllocatedCount = kMinAllocated; 1788 fAllocatedCount = kMinAllocated;
1790 SkASSERT(fMaskFormat == kA8_GrMaskFormat); 1789 SkASSERT(fMaskFormat == kA8_GrMaskFormat);
1791 } 1790 }
1792 1791
1793 ~BitmapTextBatch() { 1792 ~BitmapTextBatch() {
1794 for (int i = 0; i < fInstanceCount; i++) { 1793 for (int i = 0; i < fInstanceCount; i++) {
1795 fGeoData[i].fBlob->unref(); 1794 fGeoData[i].fBlob->unref();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 } 1904 }
1906 1905
1907 if (fUseLCDText != that->fUseLCDText) { 1906 if (fUseLCDText != that->fUseLCDText) {
1908 return false; 1907 return false;
1909 } 1908 }
1910 1909
1911 if (fUseBGR != that->fUseBGR) { 1910 if (fUseBGR != that->fUseBGR) {
1912 return false; 1911 return false;
1913 } 1912 }
1914 1913
1915 if (fGamma != that->fGamma) {
1916 return false;
1917 }
1918
1919 // TODO see note above 1914 // TODO see note above
1920 if (fUseLCDText && this->color() != that->color()) { 1915 if (fUseLCDText && this->color() != that->color()) {
1921 return false; 1916 return false;
1922 } 1917 }
1923 } 1918 }
1924 1919
1925 fBatch.fNumGlyphs += that->numGlyphs(); 1920 fBatch.fNumGlyphs += that->numGlyphs();
1926 1921
1927 // copy that->geoData(). We do this manually for performance reasons 1922 // copy that->geoData(). We do this manually for performance reasons
1928 SkAutoSTMalloc<kMinAllocated, Geometry>* otherGeoData = that->geoData(); 1923 SkAutoSTMalloc<kMinAllocated, Geometry>* otherGeoData = that->geoData();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 return GrDistanceFieldLCDTextGeoProc::Create(color, 1974 return GrDistanceFieldLCDTextGeoProc::Create(color,
1980 viewMatrix, 1975 viewMatrix,
1981 texture, 1976 texture,
1982 params, 1977 params,
1983 widthAdjust, 1978 widthAdjust,
1984 flags, 1979 flags,
1985 this->usesLocalCoords() ); 1980 this->usesLocalCoords() );
1986 } else { 1981 } else {
1987 flags |= kColorAttr_DistanceFieldEffectFlag; 1982 flags |= kColorAttr_DistanceFieldEffectFlag;
1988 #ifdef SK_GAMMA_APPLY_TO_A8 1983 #ifdef SK_GAMMA_APPLY_TO_A8
1989 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fGamma, filtered Color); 1984 U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONEN T, filteredColor);
1990 float correction = (*fDistanceAdjustTable)[lum >> kDistanceAdjustLum Shift]; 1985 float correction = (*fDistanceAdjustTable)[lum >> kDistanceAdjustLum Shift];
1991 return GrDistanceFieldA8TextGeoProc::Create(color, 1986 return GrDistanceFieldA8TextGeoProc::Create(color,
1992 viewMatrix, 1987 viewMatrix,
1993 texture, 1988 texture,
1994 params, 1989 params,
1995 correction, 1990 correction,
1996 flags, 1991 flags,
1997 this->usesLocalCoords()) ; 1992 this->usesLocalCoords()) ;
1998 #else 1993 #else
1999 return GrDistanceFieldA8TextGeoProc::Create(color, 1994 return GrDistanceFieldA8TextGeoProc::Create(color,
(...skipping 18 matching lines...) Expand all
2018 2013
2019 BatchTracker fBatch; 2014 BatchTracker fBatch;
2020 SkAutoSTMalloc<kMinAllocated, Geometry> fGeoData; 2015 SkAutoSTMalloc<kMinAllocated, Geometry> fGeoData;
2021 int fInstanceCount; 2016 int fInstanceCount;
2022 int fAllocatedCount; 2017 int fAllocatedCount;
2023 GrMaskFormat fMaskFormat; 2018 GrMaskFormat fMaskFormat;
2024 GrPixelConfig fPixelConfig; 2019 GrPixelConfig fPixelConfig;
2025 GrBatchFontCache* fFontCache; 2020 GrBatchFontCache* fFontCache;
2026 2021
2027 // Distance field properties 2022 // Distance field properties
2028 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; 2023 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable;
2029 SkColor fFilteredColor; 2024 SkColor fFilteredColor;
2030 bool fUseDistanceFields; 2025 bool fUseDistanceFields;
2031 bool fUseLCDText; 2026 bool fUseLCDText;
2032 bool fUseBGR; 2027 bool fUseBGR;
2033 float fGamma;
2034 }; 2028 };
2035 2029
2036 void GrAtlasTextContext::flushRunAsPaths(GrRenderTarget* rt, const SkTextBlob::R unIterator& it, 2030 void GrAtlasTextContext::flushRunAsPaths(GrRenderTarget* rt, const SkTextBlob::R unIterator& it,
2037 const GrClip& clip, const SkPaint& skPa int, 2031 const GrClip& clip, const SkPaint& skPa int,
2038 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix, 2032 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix,
2039 const SkIRect& clipBounds, SkScalar x, SkScalar y) { 2033 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
2040 SkPaint runPaint = skPaint; 2034 SkPaint runPaint = skPaint;
2041 2035
2042 size_t textLen = it.glyphCount() * sizeof(uint16_t); 2036 size_t textLen = it.glyphCount() * sizeof(uint16_t);
2043 const SkPoint& offset = it.offset(); 2037 const SkPoint& offset = it.offset();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 BitmapTextBatch* batch; 2082 BitmapTextBatch* batch;
2089 if (info.fDrawAsDistanceFields) { 2083 if (info.fDrawAsDistanceFields) {
2090 SkColor filteredColor; 2084 SkColor filteredColor;
2091 SkColorFilter* colorFilter = skPaint.getColorFilter(); 2085 SkColorFilter* colorFilter = skPaint.getColorFilter();
2092 if (colorFilter) { 2086 if (colorFilter) {
2093 filteredColor = colorFilter->filterColor(skPaint.getColor()); 2087 filteredColor = colorFilter->filterColor(skPaint.getColor());
2094 } else { 2088 } else {
2095 filteredColor = skPaint.getColor(); 2089 filteredColor = skPaint.getColor();
2096 } 2090 }
2097 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); 2091 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry());
2098 float gamma = fDeviceProperties.gamma();
2099 batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFo ntCache(), 2092 batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFo ntCache(),
2100 fDistanceAdjustTable, filteredColor, 2093 fDistanceAdjustTable, filteredColor,
2101 info.fUseLCDText, useBGR, 2094 info.fUseLCDText, useBGR);
2102 gamma);
2103 } else { 2095 } else {
2104 batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFo ntCache()); 2096 batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFo ntCache());
2105 } 2097 }
2106 BitmapTextBatch::Geometry& geometry = batch->geometry(); 2098 BitmapTextBatch::Geometry& geometry = batch->geometry();
2107 geometry.fBlob = SkRef(cacheBlob); 2099 geometry.fBlob = SkRef(cacheBlob);
2108 geometry.fRun = run; 2100 geometry.fRun = run;
2109 geometry.fSubRun = subRun; 2101 geometry.fSubRun = subRun;
2110 geometry.fColor = subRunColor; 2102 geometry.fColor = subRunColor;
2111 geometry.fTransX = transX; 2103 geometry.fTransX = transX;
2112 geometry.fTransY = transY; 2104 geometry.fTransY = transY;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text, 2264 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text,
2273 static_cast<size_t>(textLen), 0, 0, noClip)); 2265 static_cast<size_t>(textLen), 0, 0, noClip));
2274 2266
2275 SkScalar transX = static_cast<SkScalar>(random->nextU()); 2267 SkScalar transX = static_cast<SkScalar>(random->nextU());
2276 SkScalar transY = static_cast<SkScalar>(random->nextU()); 2268 SkScalar transY = static_cast<SkScalar>(random->nextU());
2277 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun s[0].fSubRunInfo[0]; 2269 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun s[0].fSubRunInfo[0];
2278 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 2270 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
2279 } 2271 }
2280 2272
2281 #endif 2273 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698