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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 if (fFilterLevel <= SkPaint::kLow_FilterLevel) { | 139 if (fFilterLevel <= SkPaint::kLow_FilterLevel) { |
140 return false; | 140 return false; |
141 } | 141 } |
142 | 142 |
143 // Check to see if the transformation matrix is simple, and if we're | 143 // Check to see if the transformation matrix is simple, and if we're |
144 // doing high quality scaling. If so, do the bitmap scale here and | 144 // doing high quality scaling. If so, do the bitmap scale here and |
145 // remove the scaling component from the matrix. | 145 // remove the scaling component from the matrix. |
146 | 146 |
147 if (SkPaint::kHigh_FilterLevel == fFilterLevel && | 147 if (SkPaint::kHigh_FilterLevel == fFilterLevel && |
148 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && | 148 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && |
149 fOrigBitmap.config() == SkBitmap::kARGB_8888_Config) { | 149 kN32_SkColorType == fOrigBitmap.colorType()) { |
150 | 150 |
151 SkScalar invScaleX = fInvMatrix.getScaleX(); | 151 SkScalar invScaleX = fInvMatrix.getScaleX(); |
152 SkScalar invScaleY = fInvMatrix.getScaleY(); | 152 SkScalar invScaleY = fInvMatrix.getScaleY(); |
153 | 153 |
154 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, | 154 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, |
155 invScaleX, invScaleY, | 155 invScaleX, invScaleY, |
156 &fScaledBitmap); | 156 &fScaledBitmap); |
157 if (fScaledCacheID) { | 157 if (fScaledCacheID) { |
158 fScaledBitmap.lockPixels(); | 158 fScaledBitmap.lockPixels(); |
159 if (!fScaledBitmap.getPixels()) { | 159 if (!fScaledBitmap.getPixels()) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 SkASSERT(mip); | 271 SkASSERT(mip); |
272 } | 272 } |
273 | 273 |
274 if (mip) { | 274 if (mip) { |
275 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); | 275 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); |
276 SkMipMap::Level level; | 276 SkMipMap::Level level; |
277 if (mip->extractLevel(levelScale, &level)) { | 277 if (mip->extractLevel(levelScale, &level)) { |
278 SkScalar invScaleFixup = level.fScale; | 278 SkScalar invScaleFixup = level.fScale; |
279 fInvMatrix.postScale(invScaleFixup, invScaleFixup); | 279 fInvMatrix.postScale(invScaleFixup, invScaleFixup); |
280 | 280 |
281 fScaledBitmap.setConfig(fOrigBitmap.config(), | 281 SkImageInfo info = fOrigBitmap.info(); |
282 level.fWidth, level.fHeight, | 282 info.fWidth = level.fWidth; |
283 level.fRowBytes); | 283 info.fHeight = level.fHeight; |
284 fScaledBitmap.setPixels(level.fPixels); | 284 fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes ); |
285 fBitmap = &fScaledBitmap; | 285 fBitmap = &fScaledBitmap; |
286 fFilterLevel = SkPaint::kLow_FilterLevel; | 286 fFilterLevel = SkPaint::kLow_FilterLevel; |
287 unlocker.release(); | 287 unlocker.release(); |
288 return true; | 288 return true; |
289 } | 289 } |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 return false; | 293 return false; |
294 } | 294 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 if (fAlphaScale < 256) { // note: this distinction is not used for D16 | 494 if (fAlphaScale < 256) { // note: this distinction is not used for D16 |
495 index |= 1; | 495 index |= 1; |
496 } | 496 } |
497 if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { | 497 if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { |
498 index |= 2; | 498 index |= 2; |
499 } | 499 } |
500 if (fFilterLevel > SkPaint::kNone_FilterLevel) { | 500 if (fFilterLevel > SkPaint::kNone_FilterLevel) { |
501 index |= 4; | 501 index |= 4; |
502 } | 502 } |
503 // bits 3,4,5 encoding the source bitmap format | 503 // bits 3,4,5 encoding the source bitmap format |
504 switch (fBitmap->config()) { | 504 switch (fBitmap->colorType()) { |
505 case SkBitmap::kARGB_8888_Config: | 505 case kN32_SkColorType: |
506 index |= 0; | 506 index |= 0; |
507 break; | 507 break; |
508 case SkBitmap::kRGB_565_Config: | 508 case kRGB_565_SkColorType: |
509 index |= 8; | 509 index |= 8; |
510 break; | 510 break; |
511 case SkBitmap::kIndex8_Config: | 511 case kIndex_8_SkColorType: |
512 index |= 16; | 512 index |= 16; |
513 break; | 513 break; |
514 case SkBitmap::kARGB_4444_Config: | 514 case kARGB_4444_SkColorType: |
515 index |= 24; | 515 index |= 24; |
516 break; | 516 break; |
517 case SkBitmap::kA8_Config: | 517 case kAlpha_8_SkColorType: |
518 index |= 32; | 518 index |= 32; |
519 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); | 519 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); |
520 break; | 520 break; |
521 default: | 521 default: |
522 // TODO(dominikg): Should we ever get here? SkASSERT(false) inst ead? | 522 // TODO(dominikg): Should we ever get here? SkASSERT(false) inst ead? |
523 return false; | 523 return false; |
524 } | 524 } |
525 | 525 |
526 #if !SK_ARM_NEON_IS_ALWAYS | 526 #if !SK_ARM_NEON_IS_ALWAYS |
527 static const SampleProc32 gSkBitmapProcStateSample32[] = { | 527 static const SampleProc32 gSkBitmapProcStateSample32[] = { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 | 871 |
872 // Since we know we're not filtered, we re-purpose these fields allow | 872 // Since we know we're not filtered, we re-purpose these fields allow |
873 // us to go from device -> src coordinates w/ just an integer add, | 873 // us to go from device -> src coordinates w/ just an integer add, |
874 // rather than running through the inverse-matrix | 874 // rather than running through the inverse-matrix |
875 fFilterOneX = SkScalarFloorToInt(pt.fX); | 875 fFilterOneX = SkScalarFloorToInt(pt.fX); |
876 fFilterOneY = SkScalarFloorToInt(pt.fY); | 876 fFilterOneY = SkScalarFloorToInt(pt.fY); |
877 return true; | 877 return true; |
878 } | 878 } |
879 | 879 |
880 SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() { | 880 SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() { |
881 | 881 |
robertphillips
2014/05/29 12:13:42
4?
reed1
2014/05/29 12:31:23
Was waffling about supporting both swizzles of 32b
reed1
2014/05/29 12:33:34
and yes, if I'm going to count bytes, I should cou
| |
882 if (SkBitmap::kARGB_8888_Config != fBitmap->config()) { | 882 if (32 != fBitmap->bytesPerPixel()) { |
883 return NULL; | 883 return NULL; |
884 } | 884 } |
885 | 885 |
886 static const unsigned kMask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_M ask; | 886 static const unsigned kMask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_M ask; |
887 | 887 |
888 if (1 == fBitmap->width() && 0 == (fInvType & ~kMask)) { | 888 if (1 == fBitmap->width() && 0 == (fInvType & ~kMask)) { |
889 if (SkPaint::kNone_FilterLevel == fFilterLevel && | 889 if (SkPaint::kNone_FilterLevel == fFilterLevel && |
890 fInvType <= SkMatrix::kTranslate_Mask && | 890 fInvType <= SkMatrix::kTranslate_Mask && |
891 !this->setupForTranslate()) { | 891 !this->setupForTranslate()) { |
892 return DoNothing_shaderproc; | 892 return DoNothing_shaderproc; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 } else { | 1032 } else { |
1033 size >>= 2; | 1033 size >>= 2; |
1034 } | 1034 } |
1035 | 1035 |
1036 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1036 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
1037 size >>= 1; | 1037 size >>= 1; |
1038 } | 1038 } |
1039 | 1039 |
1040 return size; | 1040 return size; |
1041 } | 1041 } |
OLD | NEW |