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

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

Issue 1285283002: Refactor helper function for SkBitmapShader to GrFragmentProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 | « include/gpu/SkGr.h ('k') | src/gpu/SkGpuDevice.cpp » ('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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 str->append(")"); 343 str->append(")");
344 } 344 }
345 #endif 345 #endif
346 346
347 /////////////////////////////////////////////////////////////////////////////// 347 ///////////////////////////////////////////////////////////////////////////////
348 348
349 #if SK_SUPPORT_GPU 349 #if SK_SUPPORT_GPU
350 350
351 #include "GrTextureAccess.h" 351 #include "GrTextureAccess.h"
352 #include "SkGr.h"
352 #include "effects/GrSimpleTextureEffect.h" 353 #include "effects/GrSimpleTextureEffect.h"
353 #include "SkGr.h"
354 354
355 bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, 355 bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint,
356 const SkMatrix& viewM, 356 const SkMatrix& viewM,
357 const SkMatrix* localMatrix, GrColo r* paintColor, 357 const SkMatrix* localMatrix, GrColo r* paintColor,
358 GrProcessorDataManager* procDataMan ager, 358 GrProcessorDataManager* procDataMan ager,
359 GrFragmentProcessor** fp) const { 359 GrFragmentProcessor** fp) const {
360 SkMatrix matrix; 360 SkMatrix matrix;
361 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); 361 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
362 362
363 SkMatrix lmInverse; 363 SkMatrix lmInverse;
(...skipping 11 matching lines...) Expand all
375 375
376 SkShader::TileMode tm[] = { 376 SkShader::TileMode tm[] = {
377 (TileMode)fTileModeX, 377 (TileMode)fTileModeX,
378 (TileMode)fTileModeY, 378 (TileMode)fTileModeY,
379 }; 379 };
380 380
381 // Must set wrap and filter on the sampler before requesting a texture. In t wo places below 381 // Must set wrap and filter on the sampler before requesting a texture. In t wo places below
382 // we check the matrix scale factors to determine how to interpret the filte r quality setting. 382 // we check the matrix scale factors to determine how to interpret the filte r quality setting.
383 // This completely ignores the complexity of the drawVertices case where exp licit local coords 383 // This completely ignores the complexity of the drawVertices case where exp licit local coords
384 // are provided by the caller. 384 // are provided by the caller.
385 bool useBicubic = false; 385 bool doBicubic;
386 GrTextureParams::FilterMode textureFilterMode; 386 GrTextureParams::FilterMode textureFilterMode =
387 switch(paint.getFilterQuality()) { 387 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, thi s->getLocalMatrix(),
388 case kNone_SkFilterQuality: 388 &doBicubic);
389 textureFilterMode = GrTextureParams::kNone_FilterMode;
390 break;
391 case kLow_SkFilterQuality:
392 textureFilterMode = GrTextureParams::kBilerp_FilterMode;
393 break;
394 case kMedium_SkFilterQuality: {
395 SkMatrix matrix;
396 matrix.setConcat(viewM, this->getLocalMatrix());
397 if (matrix.getMinScale() < SK_Scalar1) {
398 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
399 } else {
400 // Don't trigger MIP level generation unnecessarily.
401 textureFilterMode = GrTextureParams::kBilerp_FilterMode;
402 }
403 break;
404 }
405 case kHigh_SkFilterQuality: {
406 SkMatrix matrix;
407 matrix.setConcat(viewM, this->getLocalMatrix());
408 useBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilte rMode);
409 break;
410 }
411 default:
412 SkErrorInternals::SetError( kInvalidPaint_SkError,
413 "Sorry, I don't understand the filtering "
414 "mode you asked for. Falling back to "
415 "MIPMaps.");
416 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
417 break;
418
419 }
420 GrTextureParams params(tm, textureFilterMode); 389 GrTextureParams params(tm, textureFilterMode);
421 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap , &params)); 390 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap , &params));
422 391
423 if (!texture) { 392 if (!texture) {
424 SkErrorInternals::SetError( kInternalError_SkError, 393 SkErrorInternals::SetError( kInternalError_SkError,
425 "Couldn't convert bitmap to texture."); 394 "Couldn't convert bitmap to texture.");
426 return false; 395 return false;
427 } 396 }
428 397
429 *paintColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ? 398 *paintColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ?
430 SkColor2GrColor(paint.getColor() ) : 399 SkColor2GrColor(paint.getColor() ) :
431 SkColor2GrColorJustAlpha(paint.g etColor()); 400 SkColor2GrColorJustAlpha(paint.g etColor());
432 401
433 if (useBicubic) { 402 if (doBicubic) {
434 *fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm); 403 *fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm);
435 } else { 404 } else {
436 *fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, pa rams); 405 *fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, pa rams);
437 } 406 }
438 407
439 return true; 408 return true;
440 } 409 }
441 410
442 #else 411 #else
443 412
444 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S kMatrix&, 413 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S kMatrix&,
445 const SkMatrix*, GrColor*, GrProces sorDataManager*, 414 const SkMatrix*, GrColor*, GrProces sorDataManager*,
446 GrFragmentProcessor**) const { 415 GrFragmentProcessor**) const {
447 SkDEBUGFAIL("Should not call in GPU-less build"); 416 SkDEBUGFAIL("Should not call in GPU-less build");
448 return false; 417 return false;
449 } 418 }
450 419
451 #endif 420 #endif
OLDNEW
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698