Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: src/core/SkBitmapProcState.cpp

Issue 246403013: Revert of Revert of Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkBitmapProcState.h ('k') | src/core/SkBlitter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 fScaledBitmap.reset(); 353 fScaledBitmap.reset();
354 return false; 354 return false;
355 } 355 }
356 } 356 }
357 } 357 }
358 fBitmap = &fScaledBitmap; 358 fBitmap = &fScaledBitmap;
359 unlocker.release(); 359 unlocker.release();
360 return true; 360 return true;
361 } 361 }
362 362
363 void SkBitmapProcState::endContext() {
364 SkDELETE(fBitmapFilter);
365 fBitmapFilter = NULL;
366 fScaledBitmap.reset();
367
368 if (fScaledCacheID) {
369 SkScaledImageCache::Unlock(fScaledCacheID);
370 fScaledCacheID = NULL;
371 }
372 }
373
374 SkBitmapProcState::~SkBitmapProcState() { 363 SkBitmapProcState::~SkBitmapProcState() {
375 if (fScaledCacheID) { 364 if (fScaledCacheID) {
376 SkScaledImageCache::Unlock(fScaledCacheID); 365 SkScaledImageCache::Unlock(fScaledCacheID);
377 } 366 }
378 SkDELETE(fBitmapFilter); 367 SkDELETE(fBitmapFilter);
379 } 368 }
380 369
381 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { 370 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) {
382 SkASSERT(fOrigBitmap.width() && fOrigBitmap.height()); 371 SkASSERT(fOrigBitmap.width() && fOrigBitmap.height());
383 372
384 fBitmap = NULL; 373 fBitmap = NULL;
385 fInvMatrix = inv; 374 fInvMatrix = inv;
386 fFilterLevel = paint.getFilterLevel(); 375 fFilterLevel = paint.getFilterLevel();
387 376
388 SkASSERT(NULL == fScaledCacheID); 377 SkASSERT(NULL == fScaledCacheID);
389 378
390 // possiblyScaleImage will look to see if it can rescale the image as a 379 // possiblyScaleImage will look to see if it can rescale the image as a
391 // preprocess; either by scaling up to the target size, or by selecting 380 // preprocess; either by scaling up to the target size, or by selecting
392 // a nearby mipmap level. If it does, it will adjust the working 381 // a nearby mipmap level. If it does, it will adjust the working
393 // matrix as well as the working bitmap. It may also adjust the filter 382 // matrix as well as the working bitmap. It may also adjust the filter
394 // quality to avoid re-filtering an already perfectly scaled image. 383 // quality to avoid re-filtering an already perfectly scaled image.
395 if (!this->possiblyScaleImage()) { 384 if (!this->possiblyScaleImage()) {
396 if (!this->lockBaseBitmap()) { 385 if (!this->lockBaseBitmap()) {
397 return false; 386 return false;
398 } 387 }
399 } 388 }
400 // The above logic should have always assigned fBitmap, but in case it 389 // The above logic should have always assigned fBitmap, but in case it
401 // didn't, we check for that now... 390 // didn't, we check for that now...
391 // TODO(dominikg): Ask humper@ if we can just use an SkASSERT(fBitmap)?
402 if (NULL == fBitmap) { 392 if (NULL == fBitmap) {
403 return false; 393 return false;
404 } 394 }
405 395
406 // If we are "still" kMedium_FilterLevel, then the request was not fulfilled by possiblyScale, 396 // If we are "still" kMedium_FilterLevel, then the request was not fulfilled by possiblyScale,
407 // so we downgrade to kLow (so the rest of the sniffing code can assume that ) 397 // so we downgrade to kLow (so the rest of the sniffing code can assume that )
408 if (SkPaint::kMedium_FilterLevel == fFilterLevel) { 398 if (SkPaint::kMedium_FilterLevel == fFilterLevel) {
409 fFilterLevel = SkPaint::kLow_FilterLevel; 399 fFilterLevel = SkPaint::kLow_FilterLevel;
410 } 400 }
411 401
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if (fInvType <= SkMatrix::kTranslate_Mask || 470 if (fInvType <= SkMatrix::kTranslate_Mask ||
481 !valid_for_filtering(fBitmap->width() | fBitmap->height())) { 471 !valid_for_filtering(fBitmap->width() | fBitmap->height())) {
482 fFilterLevel = SkPaint::kNone_FilterLevel; 472 fFilterLevel = SkPaint::kNone_FilterLevel;
483 } 473 }
484 } 474 }
485 475
486 // At this point, we know exactly what kind of sampling the per-scanline 476 // At this point, we know exactly what kind of sampling the per-scanline
487 // shader will perform. 477 // shader will perform.
488 478
489 fMatrixProc = this->chooseMatrixProc(trivialMatrix); 479 fMatrixProc = this->chooseMatrixProc(trivialMatrix);
480 // TODO(dominikg): SkASSERT(fMatrixProc) instead? chooseMatrixProc never ret urns NULL.
490 if (NULL == fMatrixProc) { 481 if (NULL == fMatrixProc) {
491 return false; 482 return false;
492 } 483 }
493 484
494 /////////////////////////////////////////////////////////////////////// 485 ///////////////////////////////////////////////////////////////////////
495 486
496 // No need to do this if we're doing HQ sampling; if filter quality is 487 // No need to do this if we're doing HQ sampling; if filter quality is
497 // still set to HQ by the time we get here, then we must have installed 488 // still set to HQ by the time we get here, then we must have installed
498 // the shader procs above and can skip all this. 489 // the shader procs above and can skip all this.
499 490
(...skipping 21 matching lines...) Expand all
521 index |= 16; 512 index |= 16;
522 break; 513 break;
523 case SkBitmap::kARGB_4444_Config: 514 case SkBitmap::kARGB_4444_Config:
524 index |= 24; 515 index |= 24;
525 break; 516 break;
526 case SkBitmap::kA8_Config: 517 case SkBitmap::kA8_Config:
527 index |= 32; 518 index |= 32;
528 fPaintPMColor = SkPreMultiplyColor(paint.getColor()); 519 fPaintPMColor = SkPreMultiplyColor(paint.getColor());
529 break; 520 break;
530 default: 521 default:
522 // TODO(dominikg): Should we ever get here? SkASSERT(false) inst ead?
531 return false; 523 return false;
532 } 524 }
533 525
534 #if !SK_ARM_NEON_IS_ALWAYS 526 #if !SK_ARM_NEON_IS_ALWAYS
535 static const SampleProc32 gSkBitmapProcStateSample32[] = { 527 static const SampleProc32 gSkBitmapProcStateSample32[] = {
536 S32_opaque_D32_nofilter_DXDY, 528 S32_opaque_D32_nofilter_DXDY,
537 S32_alpha_D32_nofilter_DXDY, 529 S32_alpha_D32_nofilter_DXDY,
538 S32_opaque_D32_nofilter_DX, 530 S32_opaque_D32_nofilter_DX,
539 S32_alpha_D32_nofilter_DX, 531 S32_alpha_D32_nofilter_DX,
540 S32_opaque_D32_filter_DXDY, 532 S32_opaque_D32_filter_DXDY,
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 } else { 1032 } else {
1041 size >>= 2; 1033 size >>= 2;
1042 } 1034 }
1043 1035
1044 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 1036 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
1045 size >>= 1; 1037 size >>= 1;
1046 } 1038 }
1047 1039
1048 return size; 1040 return size;
1049 } 1041 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcState.h ('k') | src/core/SkBlitter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698