OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkErrorInternals.h" | 11 #include "SkErrorInternals.h" |
12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
14 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
15 | 15 |
16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
17 #include "effects/GrBicubicEffect.h" | 17 #include "effects/GrBicubicEffect.h" |
| 18 #include "effects/GrExtractAlphaFragmentProcessor.h" |
18 #include "effects/GrSimpleTextureEffect.h" | 19 #include "effects/GrSimpleTextureEffect.h" |
19 #endif | 20 #endif |
20 | 21 |
21 SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, | 22 SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, |
22 const SkMatrix* localMatrix) | 23 const SkMatrix* localMatrix) |
23 : INHERITED(localMatrix) { | 24 : INHERITED(localMatrix) { |
24 fRawBitmap = src; | 25 fRawBitmap = src; |
25 fTileModeX = (uint8_t)tmx; | 26 fTileModeX = (uint8_t)tmx; |
26 fTileModeY = (uint8_t)tmy; | 27 fTileModeY = (uint8_t)tmy; |
27 } | 28 } |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 #endif | 347 #endif |
347 | 348 |
348 /////////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////////// |
349 | 350 |
350 #if SK_SUPPORT_GPU | 351 #if SK_SUPPORT_GPU |
351 | 352 |
352 #include "GrTextureAccess.h" | 353 #include "GrTextureAccess.h" |
353 #include "SkGr.h" | 354 #include "SkGr.h" |
354 #include "effects/GrSimpleTextureEffect.h" | 355 #include "effects/GrSimpleTextureEffect.h" |
355 | 356 |
356 bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint&
paint, | 357 const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* co
ntext, |
357 const SkMatrix& viewM, | 358 const SkMatrix& viewM, const SkMatr
ix* localMatrix, |
358 const SkMatrix* localMatrix, GrColo
r* paintColor, | 359 SkFilterQuality filterQuality, |
359 GrProcessorDataManager* procDataMan
ager, | 360 GrProcessorDataManager* procDataMan
ager) const { |
360 GrFragmentProcessor** fp) const { | |
361 SkMatrix matrix; | 361 SkMatrix matrix; |
362 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); | 362 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); |
363 | 363 |
364 SkMatrix lmInverse; | 364 SkMatrix lmInverse; |
365 if (!this->getLocalMatrix().invert(&lmInverse)) { | 365 if (!this->getLocalMatrix().invert(&lmInverse)) { |
366 return false; | 366 return nullptr; |
367 } | 367 } |
368 if (localMatrix) { | 368 if (localMatrix) { |
369 SkMatrix inv; | 369 SkMatrix inv; |
370 if (!localMatrix->invert(&inv)) { | 370 if (!localMatrix->invert(&inv)) { |
371 return false; | 371 return nullptr; |
372 } | 372 } |
373 lmInverse.postConcat(inv); | 373 lmInverse.postConcat(inv); |
374 } | 374 } |
375 matrix.preConcat(lmInverse); | 375 matrix.preConcat(lmInverse); |
376 | 376 |
377 SkShader::TileMode tm[] = { | 377 SkShader::TileMode tm[] = { |
378 (TileMode)fTileModeX, | 378 (TileMode)fTileModeX, |
379 (TileMode)fTileModeY, | 379 (TileMode)fTileModeY, |
380 }; | 380 }; |
381 | 381 |
382 // Must set wrap and filter on the sampler before requesting a texture. In t
wo places below | 382 // Must set wrap and filter on the sampler before requesting a texture. In t
wo places below |
383 // we check the matrix scale factors to determine how to interpret the filte
r quality setting. | 383 // we check the matrix scale factors to determine how to interpret the filte
r quality setting. |
384 // This completely ignores the complexity of the drawVertices case where exp
licit local coords | 384 // This completely ignores the complexity of the drawVertices case where exp
licit local coords |
385 // are provided by the caller. | 385 // are provided by the caller. |
386 bool doBicubic; | 386 bool doBicubic; |
387 GrTextureParams::FilterMode textureFilterMode = | 387 GrTextureParams::FilterMode textureFilterMode = |
388 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, thi
s->getLocalMatrix(), | 388 GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocal
Matrix(), |
389 &doBicubic); | 389 &doBicubic); |
390 GrTextureParams params(tm, textureFilterMode); | 390 GrTextureParams params(tm, textureFilterMode); |
391 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap
, ¶ms)); | 391 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap
, ¶ms)); |
392 | 392 |
393 if (!texture) { | 393 if (!texture) { |
394 SkErrorInternals::SetError( kInternalError_SkError, | 394 SkErrorInternals::SetError( kInternalError_SkError, |
395 "Couldn't convert bitmap to texture."); | 395 "Couldn't convert bitmap to texture."); |
396 return false; | 396 return nullptr; |
397 } | 397 } |
398 | 398 |
399 *paintColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ? | 399 SkAutoTUnref<GrFragmentProcessor> inner; |
400 SkColor2GrColor(paint.getColor()
) : | |
401 SkColor2GrColorJustAlpha(paint.g
etColor()); | |
402 | |
403 if (doBicubic) { | 400 if (doBicubic) { |
404 *fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm); | 401 inner.reset(GrBicubicEffect::Create(procDataManager, texture, matrix, tm
)); |
405 } else { | 402 } else { |
406 *fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, pa
rams); | 403 inner.reset(GrSimpleTextureEffect::Create(procDataManager, texture, matr
ix, params)); |
407 } | 404 } |
408 | 405 |
409 return true; | 406 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { |
410 } | 407 return SkRef(inner.get()); |
411 | 408 } |
412 #else | 409 return GrExtractAlphaFragmentProcessor::Create(inner); |
413 | |
414 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S
kMatrix&, | |
415 const SkMatrix*, GrColor*, GrProces
sorDataManager*, | |
416 GrFragmentProcessor**) const { | |
417 SkDEBUGFAIL("Should not call in GPU-less build"); | |
418 return false; | |
419 } | 410 } |
420 | 411 |
421 #endif | 412 #endif |
OLD | NEW |