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

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

Issue 318923005: SkShader::asNewEffect Refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: added macros to check for gpu support Created 6 years, 6 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/SkBitmapProcShader.h ('k') | src/core/SkLocalMatrixShader.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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 #endif 375 #endif
376 376
377 /////////////////////////////////////////////////////////////////////////////// 377 ///////////////////////////////////////////////////////////////////////////////
378 378
379 #if SK_SUPPORT_GPU 379 #if SK_SUPPORT_GPU
380 380
381 #include "GrTextureAccess.h" 381 #include "GrTextureAccess.h"
382 #include "effects/GrSimpleTextureEffect.h" 382 #include "effects/GrSimpleTextureEffect.h"
383 #include "SkGr.h" 383 #include "SkGr.h"
384 384
385 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint, 385 bool SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint,
386 const SkMatrix* localMatrix) const { 386 const SkMatrix* localMatrix, GrColor* grCol or,
387 GrEffectRef** grEffect) const {
387 SkMatrix matrix; 388 SkMatrix matrix;
388 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); 389 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
389 390
390 SkMatrix lmInverse; 391 SkMatrix lmInverse;
391 if (!this->getLocalMatrix().invert(&lmInverse)) { 392 if (!this->getLocalMatrix().invert(&lmInverse)) {
392 return NULL; 393 return false;
393 } 394 }
394 if (localMatrix) { 395 if (localMatrix) {
395 SkMatrix inv; 396 SkMatrix inv;
396 if (!localMatrix->invert(&inv)) { 397 if (!localMatrix->invert(&inv)) {
397 return NULL; 398 return false;
398 } 399 }
399 lmInverse.postConcat(inv); 400 lmInverse.postConcat(inv);
400 } 401 }
401 matrix.preConcat(lmInverse); 402 matrix.preConcat(lmInverse);
402 403
403 SkShader::TileMode tm[] = { 404 SkShader::TileMode tm[] = {
404 (TileMode)fTileModeX, 405 (TileMode)fTileModeX,
405 (TileMode)fTileModeY, 406 (TileMode)fTileModeY,
406 }; 407 };
407 408
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 444 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
444 break; 445 break;
445 446
446 } 447 }
447 GrTextureParams params(tm, textureFilterMode); 448 GrTextureParams params(tm, textureFilterMode);
448 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fRawBitmap, &p arams); 449 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fRawBitmap, &p arams);
449 450
450 if (NULL == texture) { 451 if (NULL == texture) {
451 SkErrorInternals::SetError( kInternalError_SkError, 452 SkErrorInternals::SetError( kInternalError_SkError,
452 "Couldn't convert bitmap to texture."); 453 "Couldn't convert bitmap to texture.");
453 return NULL; 454 return false;
454 } 455 }
456
457 *grColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ? SkColor2GrColo r(paint.getColor())
458 : SkColor2GrColorJustAlpha(paint.getColo r());
455 459
456 GrEffectRef* effect = NULL;
457 if (useBicubic) { 460 if (useBicubic) {
458 effect = GrBicubicEffect::Create(texture, matrix, tm); 461 *grEffect = GrBicubicEffect::Create(texture, matrix, tm);
459 } else { 462 } else {
460 effect = GrSimpleTextureEffect::Create(texture, matrix, params); 463 *grEffect = GrSimpleTextureEffect::Create(texture, matrix, params);
461 } 464 }
462 GrUnlockAndUnrefCachedBitmapTexture(texture); 465 GrUnlockAndUnrefCachedBitmapTexture(texture);
463 return effect; 466
467 return true;
464 } 468 }
469
470 #else
471
472 bool SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint,
473 const SkMatrix* localMatrix, GrColor* grCol or,
474 GrEffectRef** grEffect) const {
475 SkDEBUGFAIL("Should not call in GPU-less build");
476 return false;
477 }
478
465 #endif 479 #endif
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcShader.h ('k') | src/core/SkLocalMatrixShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698