Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBitmapProcState.h" | 8 #include "SkBitmapProcState.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkFilterProc.h" | 10 #include "SkFilterProc.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 if (fFilterLevel <= SkPaint::kLow_FilterLevel) { | 140 if (fFilterLevel <= SkPaint::kLow_FilterLevel) { |
| 141 return false; | 141 return false; |
| 142 } | 142 } |
| 143 | 143 |
| 144 // Check to see if the transformation matrix is simple, and if we're | 144 // Check to see if the transformation matrix is simple, and if we're |
| 145 // doing high quality scaling. If so, do the bitmap scale here and | 145 // doing high quality scaling. If so, do the bitmap scale here and |
| 146 // remove the scaling component from the matrix. | 146 // remove the scaling component from the matrix. |
| 147 | 147 |
| 148 if (SkPaint::kHigh_FilterLevel == fFilterLevel && | 148 if (SkPaint::kHigh_FilterLevel == fFilterLevel && |
| 149 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && | 149 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && |
| 150 fOrigBitmap.config() == SkBitmap::kARGB_8888_Config) { | 150 kN32_SkColorType == fOrigBitmap.colorType()) { |
| 151 | 151 |
| 152 SkScalar invScaleX = fInvMatrix.getScaleX(); | 152 SkScalar invScaleX = fInvMatrix.getScaleX(); |
| 153 SkScalar invScaleY = fInvMatrix.getScaleY(); | 153 SkScalar invScaleY = fInvMatrix.getScaleY(); |
| 154 | 154 |
| 155 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, | 155 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, |
| 156 invScaleX, invScaleY, | 156 invScaleX, invScaleY, |
| 157 &fScaledBitmap); | 157 &fScaledBitmap); |
| 158 if (fScaledCacheID) { | 158 if (fScaledCacheID) { |
| 159 fScaledBitmap.lockPixels(); | 159 fScaledBitmap.lockPixels(); |
| 160 if (!fScaledBitmap.getPixels()) { | 160 if (!fScaledBitmap.getPixels()) { |
| 161 fScaledBitmap.unlockPixels(); | 161 fScaledBitmap.unlockPixels(); |
| 162 // found a purged entry (discardablememory?), release it | 162 // found a purged entry (discardablememory?), release it |
| 163 SkScaledImageCache::Unlock(fScaledCacheID); | 163 SkScaledImageCache::Unlock(fScaledCacheID); |
| 164 fScaledCacheID = NULL; | 164 fScaledCacheID = NULL; |
| 165 // fall through to rebuild | 165 // fall through to rebuild |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (NULL == fScaledCacheID) { | 169 if (NULL == fScaledCacheID) { |
|
robertphillips
2014/05/29 14:10:18
destWidth ? destHeight ?
| |
| 170 float dest_width = fOrigBitmap.width() / invScaleX; | 170 float dest_width = fOrigBitmap.width() / invScaleX; |
| 171 float dest_height = fOrigBitmap.height() / invScaleY; | 171 float dest_height = fOrigBitmap.height() / invScaleY; |
| 172 | 172 |
| 173 #ifdef SK_IGNORE_CORRECT_HIGH_QUALITY_IMAGE_SCALE | 173 #ifdef SK_IGNORE_CORRECT_HIGH_QUALITY_IMAGE_SCALE |
| 174 dest_width = SkScalarCeilToScalar(dest_width); | 174 dest_width = SkScalarCeilToScalar(dest_width); |
| 175 dest_height = SkScalarCeilToScalar(dest_height); | 175 dest_height = SkScalarCeilToScalar(dest_height); |
| 176 #endif | 176 #endif |
| 177 | 177 |
| 178 // All the criteria are met; let's make a new bitmap. | 178 // All the criteria are met; let's make a new bitmap. |
| 179 | 179 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 SkASSERT(mip); | 278 SkASSERT(mip); |
| 279 } | 279 } |
| 280 | 280 |
| 281 if (mip) { | 281 if (mip) { |
| 282 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); | 282 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); |
| 283 SkMipMap::Level level; | 283 SkMipMap::Level level; |
| 284 if (mip->extractLevel(levelScale, &level)) { | 284 if (mip->extractLevel(levelScale, &level)) { |
| 285 SkScalar invScaleFixup = level.fScale; | 285 SkScalar invScaleFixup = level.fScale; |
| 286 fInvMatrix.postScale(invScaleFixup, invScaleFixup); | 286 fInvMatrix.postScale(invScaleFixup, invScaleFixup); |
| 287 | 287 |
| 288 fScaledBitmap.setConfig(fOrigBitmap.config(), | 288 SkImageInfo info = fOrigBitmap.info(); |
| 289 level.fWidth, level.fHeight, | 289 info.fWidth = level.fWidth; |
| 290 level.fRowBytes); | 290 info.fHeight = level.fHeight; |
| 291 fScaledBitmap.setPixels(level.fPixels); | 291 fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes ); |
| 292 fBitmap = &fScaledBitmap; | 292 fBitmap = &fScaledBitmap; |
| 293 fFilterLevel = SkPaint::kLow_FilterLevel; | 293 fFilterLevel = SkPaint::kLow_FilterLevel; |
| 294 unlocker.release(); | 294 unlocker.release(); |
| 295 return true; | 295 return true; |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 | 299 |
| 300 return false; | 300 return false; |
| 301 } | 301 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 if (fAlphaScale < 256) { // note: this distinction is not used for D16 | 501 if (fAlphaScale < 256) { // note: this distinction is not used for D16 |
| 502 index |= 1; | 502 index |= 1; |
| 503 } | 503 } |
| 504 if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { | 504 if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { |
| 505 index |= 2; | 505 index |= 2; |
| 506 } | 506 } |
| 507 if (fFilterLevel > SkPaint::kNone_FilterLevel) { | 507 if (fFilterLevel > SkPaint::kNone_FilterLevel) { |
| 508 index |= 4; | 508 index |= 4; |
| 509 } | 509 } |
| 510 // bits 3,4,5 encoding the source bitmap format | 510 // bits 3,4,5 encoding the source bitmap format |
| 511 switch (fBitmap->config()) { | 511 switch (fBitmap->colorType()) { |
| 512 case SkBitmap::kARGB_8888_Config: | 512 case kN32_SkColorType: |
| 513 index |= 0; | 513 index |= 0; |
| 514 break; | 514 break; |
| 515 case SkBitmap::kRGB_565_Config: | 515 case kRGB_565_SkColorType: |
| 516 index |= 8; | 516 index |= 8; |
| 517 break; | 517 break; |
| 518 case SkBitmap::kIndex8_Config: | 518 case kIndex_8_SkColorType: |
| 519 index |= 16; | 519 index |= 16; |
| 520 break; | 520 break; |
| 521 case SkBitmap::kARGB_4444_Config: | 521 case kARGB_4444_SkColorType: |
| 522 index |= 24; | 522 index |= 24; |
| 523 break; | 523 break; |
| 524 case SkBitmap::kA8_Config: | 524 case kAlpha_8_SkColorType: |
| 525 index |= 32; | 525 index |= 32; |
| 526 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); | 526 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); |
| 527 break; | 527 break; |
| 528 default: | 528 default: |
| 529 // TODO(dominikg): Should we ever get here? SkASSERT(false) inst ead? | 529 // TODO(dominikg): Should we ever get here? SkASSERT(false) inst ead? |
| 530 return false; | 530 return false; |
| 531 } | 531 } |
| 532 | 532 |
| 533 #if !SK_ARM_NEON_IS_ALWAYS | 533 #if !SK_ARM_NEON_IS_ALWAYS |
| 534 static const SampleProc32 gSkBitmapProcStateSample32[] = { | 534 static const SampleProc32 gSkBitmapProcStateSample32[] = { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 // Since we know we're not filtered, we re-purpose these fields allow | 879 // Since we know we're not filtered, we re-purpose these fields allow |
| 880 // us to go from device -> src coordinates w/ just an integer add, | 880 // us to go from device -> src coordinates w/ just an integer add, |
| 881 // rather than running through the inverse-matrix | 881 // rather than running through the inverse-matrix |
| 882 fFilterOneX = SkScalarFloorToInt(pt.fX); | 882 fFilterOneX = SkScalarFloorToInt(pt.fX); |
| 883 fFilterOneY = SkScalarFloorToInt(pt.fY); | 883 fFilterOneY = SkScalarFloorToInt(pt.fY); |
| 884 return true; | 884 return true; |
| 885 } | 885 } |
| 886 | 886 |
| 887 SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() { | 887 SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() { |
| 888 | 888 |
| 889 if (SkBitmap::kARGB_8888_Config != fBitmap->config()) { | 889 if (kN32_SkColorType != fBitmap->colorType()) { |
| 890 return NULL; | 890 return NULL; |
| 891 } | 891 } |
| 892 | 892 |
| 893 static const unsigned kMask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_M ask; | 893 static const unsigned kMask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_M ask; |
| 894 | 894 |
| 895 if (1 == fBitmap->width() && 0 == (fInvType & ~kMask)) { | 895 if (1 == fBitmap->width() && 0 == (fInvType & ~kMask)) { |
| 896 if (SkPaint::kNone_FilterLevel == fFilterLevel && | 896 if (SkPaint::kNone_FilterLevel == fFilterLevel && |
| 897 fInvType <= SkMatrix::kTranslate_Mask && | 897 fInvType <= SkMatrix::kTranslate_Mask && |
| 898 !this->setupForTranslate()) { | 898 !this->setupForTranslate()) { |
| 899 return DoNothing_shaderproc; | 899 return DoNothing_shaderproc; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 } else { | 1039 } else { |
| 1040 size >>= 2; | 1040 size >>= 2; |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1043 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
| 1044 size >>= 1; | 1044 size >>= 1; |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 return size; | 1047 return size; |
| 1048 } | 1048 } |
| OLD | NEW |