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