| 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 "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
| 10 #include "SkAutoKern.h" | 10 #include "SkAutoKern.h" |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 } | 1812 } |
| 1813 | 1813 |
| 1814 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024 | 1814 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024 |
| 1815 | 1815 |
| 1816 #ifdef SK_DEBUG | 1816 #ifdef SK_DEBUG |
| 1817 #define TEST_DESC | 1817 #define TEST_DESC |
| 1818 #endif | 1818 #endif |
| 1819 | 1819 |
| 1820 /* | 1820 /* |
| 1821 * ignoreGamma tells us that the caller just wants metrics that are unaffected | 1821 * ignoreGamma tells us that the caller just wants metrics that are unaffected |
| 1822 * by gamma correction, so we jam the luminance field to 0 (most common value | 1822 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, |
| 1823 * for black text) in hopes that we get a cache hit easier. A better solution | 1823 * contrast = 0, luminanceColor = transparent black. |
| 1824 * would be for the fontcache lookup to know to ignore the luminance field | |
| 1825 * entirely, but not sure how to do that and keep it fast. | |
| 1826 */ | 1824 */ |
| 1827 void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, | 1825 void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, |
| 1828 const SkMatrix* deviceMatrix, | 1826 const SkMatrix* deviceMatrix, |
| 1829 void (*proc)(SkTypeface*, const SkDescriptor*, void
*), | 1827 void (*proc)(SkTypeface*, const SkDescriptor*, void
*), |
| 1830 void* context, bool ignoreGamma) const { | 1828 void* context, bool ignoreGamma) const { |
| 1831 SkScalerContext::Rec rec; | 1829 SkScalerContext::Rec rec; |
| 1832 | 1830 |
| 1833 SkScalerContext::MakeRec(*this, deviceProperties, deviceMatrix, &rec); | 1831 SkScalerContext::MakeRec(*this, deviceProperties, deviceMatrix, &rec); |
| 1834 if (ignoreGamma) { | 1832 if (ignoreGamma) { |
| 1835 rec.setLuminanceColor(0); | 1833 rec.ignorePreBlend(); |
| 1836 } | 1834 } |
| 1837 | 1835 |
| 1838 size_t descSize = sizeof(rec); | 1836 size_t descSize = sizeof(rec); |
| 1839 int entryCount = 1; | 1837 int entryCount = 1; |
| 1840 SkPathEffect* pe = this->getPathEffect(); | 1838 SkPathEffect* pe = this->getPathEffect(); |
| 1841 SkMaskFilter* mf = this->getMaskFilter(); | 1839 SkMaskFilter* mf = this->getMaskFilter(); |
| 1842 SkRasterizer* ra = this->getRasterizer(); | 1840 SkRasterizer* ra = this->getRasterizer(); |
| 1843 | 1841 |
| 1844 SkWriteBuffer peBuffer, mfBuffer, raBuffer; | 1842 SkWriteBuffer peBuffer, mfBuffer, raBuffer; |
| 1845 | 1843 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 desc2->computeChecksum(); | 1947 desc2->computeChecksum(); |
| 1950 SkASSERT(!memcmp(desc, desc1, descSize)); | 1948 SkASSERT(!memcmp(desc, desc1, descSize)); |
| 1951 SkASSERT(!memcmp(desc, desc2, descSize)); | 1949 SkASSERT(!memcmp(desc, desc2, descSize)); |
| 1952 } | 1950 } |
| 1953 #endif | 1951 #endif |
| 1954 | 1952 |
| 1955 proc(fTypeface, desc, context); | 1953 proc(fTypeface, desc, context); |
| 1956 } | 1954 } |
| 1957 | 1955 |
| 1958 SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties, | 1956 SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties, |
| 1959 const SkMatrix* deviceMatrix) const { | 1957 const SkMatrix* deviceMatrix, |
| 1958 bool ignoreGamma) const { |
| 1960 SkGlyphCache* cache; | 1959 SkGlyphCache* cache; |
| 1961 this->descriptorProc(deviceProperties, deviceMatrix, DetachDescProc, &cache,
false); | 1960 this->descriptorProc(deviceProperties, deviceMatrix, DetachDescProc, &cache,
ignoreGamma); |
| 1962 return cache; | 1961 return cache; |
| 1963 } | 1962 } |
| 1964 | 1963 |
| 1965 /** | 1964 /** |
| 1966 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl
end. | 1965 * Expands fDeviceGamma, fPaintGamma, fContrast, and fLumBits into a mask pre-bl
end. |
| 1967 */ | 1966 */ |
| 1968 //static | 1967 //static |
| 1969 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re
c& rec) { | 1968 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re
c& rec) { |
| 1970 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); | 1969 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); |
| 1971 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), | 1970 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), |
| 1972 rec.getPaintGamma(), | 1971 rec.getPaintGamma(), |
| 1973 rec.getDeviceGamma()); | 1972 rec.getDeviceGamma()); |
| 1974 return maskGamma.preBlend(rec.getLuminanceColor()); | 1973 return maskGamma.preBlend(rec.getLuminanceColor()); |
| 1975 } | 1974 } |
| 1976 | 1975 |
| 1976 size_t SkScalerContext::getGammaLUTSize(SkScalar contrast, SkScalar paintGamma, |
| 1977 SkScalar deviceGamma, int* width, int* h
eight) { |
| 1978 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); |
| 1979 const SkMaskGamma& maskGamma = cachedMaskGamma(contrast, |
| 1980 paintGamma, |
| 1981 deviceGamma); |
| 1982 |
| 1983 maskGamma.getGammaTableDimensions(width, height); |
| 1984 size_t size = (*width)*(*height)*sizeof(uint8_t); |
| 1985 |
| 1986 return size; |
| 1987 } |
| 1988 |
| 1989 void SkScalerContext::getGammaLUTData(SkScalar contrast, SkScalar paintGamma, Sk
Scalar deviceGamma, |
| 1990 void* data) { |
| 1991 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); |
| 1992 const SkMaskGamma& maskGamma = cachedMaskGamma(contrast, |
| 1993 paintGamma, |
| 1994 deviceGamma); |
| 1995 int width, height; |
| 1996 maskGamma.getGammaTableDimensions(&width, &height); |
| 1997 size_t size = width*height*sizeof(uint8_t); |
| 1998 const uint8_t* gammaTables = maskGamma.getGammaTables(); |
| 1999 memcpy(data, gammaTables, size); |
| 2000 } |
| 2001 |
| 2002 |
| 1977 /////////////////////////////////////////////////////////////////////////////// | 2003 /////////////////////////////////////////////////////////////////////////////// |
| 1978 | 2004 |
| 1979 #include "SkStream.h" | 2005 #include "SkStream.h" |
| 1980 | 2006 |
| 1981 static uintptr_t asint(const void* p) { | 2007 static uintptr_t asint(const void* p) { |
| 1982 return reinterpret_cast<uintptr_t>(p); | 2008 return reinterpret_cast<uintptr_t>(p); |
| 1983 } | 2009 } |
| 1984 | 2010 |
| 1985 union Scalar32 { | 2011 union Scalar32 { |
| 1986 SkScalar fScalar; | 2012 SkScalar fScalar; |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2555 } | 2581 } |
| 2556 } else { | 2582 } else { |
| 2557 fScale = SK_Scalar1; | 2583 fScale = SK_Scalar1; |
| 2558 } | 2584 } |
| 2559 | 2585 |
| 2560 if (!applyStrokeAndPathEffects) { | 2586 if (!applyStrokeAndPathEffects) { |
| 2561 fPaint.setStyle(SkPaint::kFill_Style); | 2587 fPaint.setStyle(SkPaint::kFill_Style); |
| 2562 fPaint.setPathEffect(NULL); | 2588 fPaint.setPathEffect(NULL); |
| 2563 } | 2589 } |
| 2564 | 2590 |
| 2565 fCache = fPaint.detachCache(NULL, NULL); | 2591 fCache = fPaint.detachCache(NULL, NULL, false); |
| 2566 | 2592 |
| 2567 SkPaint::Style style = SkPaint::kFill_Style; | 2593 SkPaint::Style style = SkPaint::kFill_Style; |
| 2568 SkPathEffect* pe = NULL; | 2594 SkPathEffect* pe = NULL; |
| 2569 | 2595 |
| 2570 if (!applyStrokeAndPathEffects) { | 2596 if (!applyStrokeAndPathEffects) { |
| 2571 style = paint.getStyle(); // restore | 2597 style = paint.getStyle(); // restore |
| 2572 pe = paint.getPathEffect(); // restore | 2598 pe = paint.getPathEffect(); // restore |
| 2573 } | 2599 } |
| 2574 fPaint.setStyle(style); | 2600 fPaint.setStyle(style); |
| 2575 fPaint.setPathEffect(pe); | 2601 fPaint.setPathEffect(pe); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2734 } | 2760 } |
| 2735 #ifdef SK_BUILD_FOR_ANDROID | 2761 #ifdef SK_BUILD_FOR_ANDROID |
| 2736 if (dirty & kPaintOptionsAndroid_DirtyBit) { | 2762 if (dirty & kPaintOptionsAndroid_DirtyBit) { |
| 2737 SkPaintOptionsAndroid options; | 2763 SkPaintOptionsAndroid options; |
| 2738 options.unflatten(buffer); | 2764 options.unflatten(buffer); |
| 2739 paint->setPaintOptionsAndroid(options); | 2765 paint->setPaintOptionsAndroid(options); |
| 2740 } | 2766 } |
| 2741 #endif | 2767 #endif |
| 2742 SkASSERT(dirty == paint->fDirtyBits); | 2768 SkASSERT(dirty == paint->fDirtyBits); |
| 2743 } | 2769 } |
| OLD | NEW |