| 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 | 372 |
| 373 SkBitmapProcState::~SkBitmapProcState() { | 373 SkBitmapProcState::~SkBitmapProcState() { |
| 374 if (fScaledCacheID) { | 374 if (fScaledCacheID) { |
| 375 SkScaledImageCache::Unlock(fScaledCacheID); | 375 SkScaledImageCache::Unlock(fScaledCacheID); |
| 376 } | 376 } |
| 377 SkDELETE(fBitmapFilter); | 377 SkDELETE(fBitmapFilter); |
| 378 } | 378 } |
| 379 | 379 |
| 380 SkBitmapProcState::SkBitmapProcState(const SkBitmapProcState& src) |
| 381 : fInvMatrix(src.fInvMatrix), fInvProc(src.fInvProc), |
| 382 fInvSxFractionalInt(src.fInvSxFractionalInt), fInvKyFractionalInt(src.fInv
KyFractionalInt), |
| 383 fTileProcX(src.fTileProcX), fTileProcY(src.fTileProcY), |
| 384 fTileLowBitsProcX(src.fTileLowBitsProcX), fTileLowBitsProcY(src.fTileLowBi
tsProcY), |
| 385 fIntTileProcY(src.fIntTileProcY), fFilterOneX(src.fFilterOneX), fFilterOne
Y(src.fFilterOneY), |
| 386 fPaintPMColor(src.fPaintPMColor), fInvSx(src.fInvSx), fInvKy(src.fInvKy), |
| 387 fAlphaScale(src.fAlphaScale), fInvType(src.fInvType), |
| 388 fTileModeX(src.fTileModeX), fTileModeY(src.fTileModeY), fFilterLevel(src.f
FilterLevel), |
| 389 fShaderProc32(src.fShaderProc32), fShaderProc16(src.fShaderProc16), |
| 390 fMatrixProc(src.fMatrixProc), fSampleProc32(src.fSampleProc32), |
| 391 fSampleProc16(src.fSampleProc16), fOrigBitmap(src.fOrigBitmap), |
| 392 fScaledBitmap(src.fScaledBitmap) |
| 393 { |
| 394 // TODO(dominikg): Doesn't work yet. Assert in SkBitmapProcShader.cpp on lin
e 224 fails. |
| 395 fBitmap = src.fBitmap == &src.fOrigBitmap ? &fOrigBitmap : &fScaledBitmap; |
| 396 |
| 397 fBitmapFilter = src.fBitmapFilter; |
| 398 } |
| 399 |
| 380 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { | 400 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { |
| 381 SkASSERT(fOrigBitmap.width() && fOrigBitmap.height()); | 401 SkASSERT(fOrigBitmap.width() && fOrigBitmap.height()); |
| 382 | 402 |
| 383 fBitmap = NULL; | 403 fBitmap = NULL; |
| 384 fInvMatrix = inv; | 404 fInvMatrix = inv; |
| 385 fFilterLevel = paint.getFilterLevel(); | 405 fFilterLevel = paint.getFilterLevel(); |
| 386 | 406 |
| 387 SkASSERT(NULL == fScaledCacheID); | 407 SkASSERT(NULL == fScaledCacheID); |
| 388 | 408 |
| 389 // possiblyScaleImage will look to see if it can rescale the image as a | 409 // possiblyScaleImage will look to see if it can rescale the image as a |
| 390 // preprocess; either by scaling up to the target size, or by selecting | 410 // preprocess; either by scaling up to the target size, or by selecting |
| 391 // a nearby mipmap level. If it does, it will adjust the working | 411 // a nearby mipmap level. If it does, it will adjust the working |
| 392 // matrix as well as the working bitmap. It may also adjust the filter | 412 // matrix as well as the working bitmap. It may also adjust the filter |
| 393 // quality to avoid re-filtering an already perfectly scaled image. | 413 // quality to avoid re-filtering an already perfectly scaled image. |
| 394 if (!this->possiblyScaleImage()) { | 414 if (!this->possiblyScaleImage()) { |
| 395 if (!this->lockBaseBitmap()) { | 415 if (!this->lockBaseBitmap()) { |
| 396 return false; | 416 return false; |
| 397 } | 417 } |
| 398 } | 418 } |
| 399 // The above logic should have always assigned fBitmap, but in case it | 419 // The above logic should have always assigned fBitmap, but in case it |
| 400 // didn't, we check for that now... | 420 // didn't, we check for that now... |
| 421 // TODO(dominikg): Ask humper@ if we can just use an SkASSERT(fBitmap)? |
| 401 if (NULL == fBitmap) { | 422 if (NULL == fBitmap) { |
| 402 return false; | 423 return false; |
| 403 } | 424 } |
| 404 | 425 |
| 405 bool trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) ==
0; | 426 bool trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) ==
0; |
| 406 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && | 427 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && |
| 407 SkShader::kClamp_TileMode == fTileModeY; | 428 SkShader::kClamp_TileMode == fTileModeY; |
| 408 | 429 |
| 409 if (!(clampClamp || trivialMatrix)) { | 430 if (!(clampClamp || trivialMatrix)) { |
| 410 fInvMatrix.postIDiv(fOrigBitmap.width(), fOrigBitmap.height()); | 431 fInvMatrix.postIDiv(fOrigBitmap.width(), fOrigBitmap.height()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 if (fInvType <= SkMatrix::kTranslate_Mask || | 494 if (fInvType <= SkMatrix::kTranslate_Mask || |
| 474 !valid_for_filtering(fBitmap->width() | fBitmap->height())) { | 495 !valid_for_filtering(fBitmap->width() | fBitmap->height())) { |
| 475 fFilterLevel = SkPaint::kNone_FilterLevel; | 496 fFilterLevel = SkPaint::kNone_FilterLevel; |
| 476 } | 497 } |
| 477 } | 498 } |
| 478 | 499 |
| 479 // At this point, we know exactly what kind of sampling the per-scanline | 500 // At this point, we know exactly what kind of sampling the per-scanline |
| 480 // shader will perform. | 501 // shader will perform. |
| 481 | 502 |
| 482 fMatrixProc = this->chooseMatrixProc(trivialMatrix); | 503 fMatrixProc = this->chooseMatrixProc(trivialMatrix); |
| 504 // TODO(dominikg): SkASSERT(fMatrixProc) instead? chooseMatrixProc never ret
urns NULL. |
| 483 if (NULL == fMatrixProc) { | 505 if (NULL == fMatrixProc) { |
| 484 return false; | 506 return false; |
| 485 } | 507 } |
| 486 | 508 |
| 487 /////////////////////////////////////////////////////////////////////// | 509 /////////////////////////////////////////////////////////////////////// |
| 488 | 510 |
| 489 // No need to do this if we're doing HQ sampling; if filter quality is | 511 // No need to do this if we're doing HQ sampling; if filter quality is |
| 490 // still set to HQ by the time we get here, then we must have installed | 512 // still set to HQ by the time we get here, then we must have installed |
| 491 // the shader procs above and can skip all this. | 513 // the shader procs above and can skip all this. |
| 492 | 514 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 514 index |= 16; | 536 index |= 16; |
| 515 break; | 537 break; |
| 516 case SkBitmap::kARGB_4444_Config: | 538 case SkBitmap::kARGB_4444_Config: |
| 517 index |= 24; | 539 index |= 24; |
| 518 break; | 540 break; |
| 519 case SkBitmap::kA8_Config: | 541 case SkBitmap::kA8_Config: |
| 520 index |= 32; | 542 index |= 32; |
| 521 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); | 543 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); |
| 522 break; | 544 break; |
| 523 default: | 545 default: |
| 546 // TODO(dominikg): Should we ever get here? SkASSERT(false) inst
ead? |
| 524 return false; | 547 return false; |
| 525 } | 548 } |
| 526 | 549 |
| 527 #if !SK_ARM_NEON_IS_ALWAYS | 550 #if !SK_ARM_NEON_IS_ALWAYS |
| 528 static const SampleProc32 gSkBitmapProcStateSample32[] = { | 551 static const SampleProc32 gSkBitmapProcStateSample32[] = { |
| 529 S32_opaque_D32_nofilter_DXDY, | 552 S32_opaque_D32_nofilter_DXDY, |
| 530 S32_alpha_D32_nofilter_DXDY, | 553 S32_alpha_D32_nofilter_DXDY, |
| 531 S32_opaque_D32_nofilter_DX, | 554 S32_opaque_D32_nofilter_DX, |
| 532 S32_alpha_D32_nofilter_DX, | 555 S32_alpha_D32_nofilter_DX, |
| 533 S32_opaque_D32_filter_DXDY, | 556 S32_opaque_D32_filter_DXDY, |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 } else { | 1056 } else { |
| 1034 size >>= 2; | 1057 size >>= 2; |
| 1035 } | 1058 } |
| 1036 | 1059 |
| 1037 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1060 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
| 1038 size >>= 1; | 1061 size >>= 1; |
| 1039 } | 1062 } |
| 1040 | 1063 |
| 1041 return size; | 1064 return size; |
| 1042 } | 1065 } |
| OLD | NEW |