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 ////////////////////////////////////////////////////////////////////////////// | 26 ////////////////////////////////////////////////////////////////////////////// |
56 // Helper functions for dropping src rect constraint in bilerp mode. | 27 // Helper functions for dropping src rect constraint in bilerp mode. |
57 | 28 |
58 static const SkScalar kColorBleedTolerance = 0.001f; | 29 static const SkScalar kColorBleedTolerance = 0.001f; |
59 | 30 |
60 static bool has_aligned_samples(const SkRect& srcRect, const SkRect& transformed
Rect) { | 31 static bool has_aligned_samples(const SkRect& srcRect, const SkRect& transformed
Rect) { |
61 // detect pixel disalignment | 32 // detect pixel disalignment |
62 if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - transformedR
ect.left()) < kColorBleedTolerance && | 33 if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - transformedR
ect.left()) < kColorBleedTolerance && |
63 SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - transformedR
ect.top()) < kColorBleedTolerance && | 34 SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - transformedR
ect.top()) < kColorBleedTolerance && |
64 SkScalarAbs(transformedRect.width() - srcRect.width()) < kColorBleedTo
lerance && | 35 SkScalarAbs(transformedRect.width() - srcRect.width()) < kColorBleedTo
lerance && |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 if (!srcToDstMatrix.invert(&tempMatrix)) { | 195 if (!srcToDstMatrix.invert(&tempMatrix)) { |
225 return; | 196 return; |
226 } | 197 } |
227 textureMatrix = &tempMatrix; | 198 textureMatrix = &tempMatrix; |
228 } | 199 } |
229 SkAutoTUnref<const GrFragmentProcessor> fp(producer->createFragmentProcessor
( | 200 SkAutoTUnref<const GrFragmentProcessor> fp(producer->createFragmentProcessor
( |
230 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); | 201 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); |
231 if (!fp) { | 202 if (!fp) { |
232 return; | 203 return; |
233 } | 204 } |
234 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this->
context(), | 205 |
235 viewMatrix, paint)); | |
236 GrPaint grPaint; | 206 GrPaint grPaint; |
237 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) { | 207 if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, alphaTextu
re, &grPaint)) { |
238 return; | 208 return; |
239 } | 209 } |
240 | 210 |
241 if (canUseTextureCoordsAsLocalCoords) { | 211 if (canUseTextureCoordsAsLocalCoords) { |
242 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); | 212 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); |
243 return; | 213 return; |
244 } | 214 } |
245 | 215 |
246 if (!mf) { | 216 if (!mf) { |
247 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); | 217 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); |
(...skipping 12 matching lines...) Expand all Loading... |
260 rec, | 230 rec, |
261 rrect)) { | 231 rrect)) { |
262 return; | 232 return; |
263 } | 233 } |
264 SkPath rectPath; | 234 SkPath rectPath; |
265 rectPath.addRect(clippedDstRect); | 235 rectPath.addRect(clippedDstRect); |
266 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, | 236 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, |
267 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), | 237 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), |
268 GrStrokeInfo::FillInfo()); | 238 GrStrokeInfo::FillInfo()); |
269 } | 239 } |
OLD | NEW |