| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
| 11 #include "GrCaps.h" | 11 #include "GrCaps.h" |
| 12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
| 13 #include "GrStrokeInfo.h" | 13 #include "GrStrokeInfo.h" |
| 14 #include "GrTextureParamsAdjuster.h" | 14 #include "GrTextureParamsAdjuster.h" |
| 15 #include "SkDraw.h" | 15 #include "SkDraw.h" |
| 16 #include "SkGrPriv.h" | 16 #include "SkGrPriv.h" |
| 17 #include "SkMaskFilter.h" | 17 #include "SkMaskFilter.h" |
| 18 #include "effects/GrBicubicEffect.h" | 18 #include "effects/GrBicubicEffect.h" |
| 19 #include "effects/GrSimpleTextureEffect.h" | 19 #include "effects/GrSimpleTextureEffect.h" |
| 20 #include "effects/GrTextureDomain.h" | 20 #include "effects/GrTextureDomain.h" |
| 21 | 21 |
| 22 static inline bool use_shader(bool textureIsAlphaOnly, const SkPaint& paint) { | 22 static inline bool use_shader(bool textureIsAlphaOnly, const SkPaint& paint) { |
| 23 return textureIsAlphaOnly && paint.getShader(); | 23 return textureIsAlphaOnly && paint.getShader(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 /** Determines how to combine the texture FP with the paint's color and SkShader
, if any. */ | |
| 27 static const GrFragmentProcessor* mix_texture_fp_with_paint_color_and_shader( | |
| 28 const GrFragmentProc
essor* textureFP, | |
| 29 bool textureIsAlphaO
nly, | |
| 30 GrContext* context, | |
| 31 const SkMatrix& view
Matrix, | |
| 32 const SkPaint& paint
) { | |
| 33 // According to the SkCanvas API, we only consider the shader if the bitmap
or image being | |
| 34 // rendered is alpha-only. | |
| 35 if (textureIsAlphaOnly) { | |
| 36 if (const SkShader* shader = paint.getShader()) { | |
| 37 SkAutoTUnref<const GrFragmentProcessor> shaderFP( | |
| 38 shader->asFragmentProcessor(context, | |
| 39 viewMatrix, | |
| 40 nullptr, | |
| 41 paint.getFilterQuality())); | |
| 42 if (!shaderFP) { | |
| 43 return nullptr; | |
| 44 } | |
| 45 const GrFragmentProcessor* fpSeries[] = { shaderFP, textureFP }; | |
| 46 return GrFragmentProcessor::RunInSeries(fpSeries, 2); | |
| 47 } else { | |
| 48 return GrFragmentProcessor::MulOutputByInputUnpremulColor(textureFP)
; | |
| 49 } | |
| 50 } else { | |
| 51 return GrFragmentProcessor::MulOutputByInputAlpha(textureFP); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void SkGpuDevice::drawTextureAdjuster(GrTextureAdjuster* adjuster, | 26 void SkGpuDevice::drawTextureAdjuster(GrTextureAdjuster* adjuster, |
| 56 bool alphaOnly, | 27 bool alphaOnly, |
| 57 const SkRect* srcRect, | 28 const SkRect* srcRect, |
| 58 const SkRect* dstRect, | 29 const SkRect* dstRect, |
| 59 SkCanvas::SrcRectConstraint constraint, | 30 SkCanvas::SrcRectConstraint constraint, |
| 60 const SkMatrix& viewMatrix, | 31 const SkMatrix& viewMatrix, |
| 61 const GrClip& clip, | 32 const GrClip& clip, |
| 62 const SkPaint& paint) { | 33 const SkPaint& paint) { |
| 63 // Figure out the actual dst and src rect by clipping the src rect to the bo
unds of the | 34 // Figure out the actual dst and src rect by clipping the src rect to the bo
unds of the |
| 64 // adjuster. If the src rect is clipped then the dst rect must be recomputed
. Also determine | 35 // adjuster. If the src rect is clipped then the dst rect must be recomputed
. Also determine |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (!srcToDstMatrix.invert(&tempMatrix)) { | 120 if (!srcToDstMatrix.invert(&tempMatrix)) { |
| 150 return; | 121 return; |
| 151 } | 122 } |
| 152 textureMatrix = &tempMatrix; | 123 textureMatrix = &tempMatrix; |
| 153 } | 124 } |
| 154 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor
( | 125 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor
( |
| 155 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); | 126 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); |
| 156 if (!fp) { | 127 if (!fp) { |
| 157 return; | 128 return; |
| 158 } | 129 } |
| 159 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this->
context(), | 130 |
| 160 viewMatrix, paint)); | |
| 161 GrPaint grPaint; | 131 GrPaint grPaint; |
| 162 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) { | 132 if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, alphaTextu
re, &grPaint)) { |
| 163 return; | 133 return; |
| 164 } | 134 } |
| 165 | 135 |
| 166 if (canUseTextureCoordsAsLocalCoords) { | 136 if (canUseTextureCoordsAsLocalCoords) { |
| 167 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); | 137 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); |
| 168 return; | 138 return; |
| 169 } | 139 } |
| 170 | 140 |
| 171 if (!mf) { | 141 if (!mf) { |
| 172 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); | 142 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 185 rec, | 155 rec, |
| 186 rrect)) { | 156 rrect)) { |
| 187 return; | 157 return; |
| 188 } | 158 } |
| 189 SkPath rectPath; | 159 SkPath rectPath; |
| 190 rectPath.addRect(clippedDstRect); | 160 rectPath.addRect(clippedDstRect); |
| 191 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, | 161 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, |
| 192 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), | 162 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), |
| 193 GrStrokeInfo::FillInfo()); | 163 GrStrokeInfo::FillInfo()); |
| 194 } | 164 } |
| OLD | NEW |