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" |
(...skipping 11 matching lines...) Expand all Loading... |
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. */ | 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( | 27 static const GrFragmentProcessor* mix_texture_fp_with_paint_color_and_shader( |
28 const GrFragmentProc
essor* textureFP, | 28 const GrFragmentProc
essor* textureFP, |
29 bool textureIsAlphaO
nly, | 29 bool textureIsAlphaO
nly, |
30 GrContext* context, | 30 GrContext* context, |
31 const SkMatrix& view
Matrix, | 31 const SkMatrix& view
Matrix, |
32 const SkPaint& paint
) { | 32 const SkPaint& paint
, |
| 33 GrRenderTarget* dst)
{ |
33 // According to the SkCanvas API, we only consider the shader if the bitmap
or image being | 34 // According to the SkCanvas API, we only consider the shader if the bitmap
or image being |
34 // rendered is alpha-only. | 35 // rendered is alpha-only. |
35 if (textureIsAlphaOnly) { | 36 if (textureIsAlphaOnly) { |
36 if (const SkShader* shader = paint.getShader()) { | 37 if (const SkShader* shader = paint.getShader()) { |
37 SkAutoTUnref<const GrFragmentProcessor> shaderFP( | 38 SkAutoTUnref<const GrFragmentProcessor> shaderFP( |
38 shader->asFragmentProcessor(context, | 39 shader->asFragmentProcessor(context, |
39 viewMatrix, | 40 viewMatrix, |
40 nullptr, | 41 nullptr, |
41 paint.getFilterQuality())); | 42 paint.getFilterQuality(), dst)); |
42 if (!shaderFP) { | 43 if (!shaderFP) { |
43 return nullptr; | 44 return nullptr; |
44 } | 45 } |
45 const GrFragmentProcessor* fpSeries[] = { shaderFP, textureFP }; | 46 const GrFragmentProcessor* fpSeries[] = { shaderFP, textureFP }; |
46 return GrFragmentProcessor::RunInSeries(fpSeries, 2); | 47 return GrFragmentProcessor::RunInSeries(fpSeries, 2); |
47 } else { | 48 } else { |
48 return GrFragmentProcessor::MulOutputByInputUnpremulColor(textureFP)
; | 49 return GrFragmentProcessor::MulOutputByInputUnpremulColor(textureFP)
; |
49 } | 50 } |
50 } else { | 51 } else { |
51 return GrFragmentProcessor::MulOutputByInputAlpha(textureFP); | 52 return GrFragmentProcessor::MulOutputByInputAlpha(textureFP); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } else { | 151 } else { |
151 constraintMode = GrTextureAdjuster::kYes_FilterConstraint; | 152 constraintMode = GrTextureAdjuster::kYes_FilterConstraint; |
152 } | 153 } |
153 | 154 |
154 // If we have to outset for AA then we will generate texture coords outside
the src rect. The | 155 // If we have to outset for AA then we will generate texture coords outside
the src rect. The |
155 // same happens for any mask filter that extends the bounds rendered in the
dst. | 156 // same happens for any mask filter that extends the bounds rendered in the
dst. |
156 // This is conservative as a mask filter does not have to expand the bounds
rendered. | 157 // This is conservative as a mask filter does not have to expand the bounds
rendered. |
157 bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf; | 158 bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf; |
158 | 159 |
159 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor
( | 160 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor
( |
160 *textureFPMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect
, filterMode)); | 161 *textureFPMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect
, filterMode, fRenderTarget)); |
161 if (!fp) { | 162 if (!fp) { |
162 return; | 163 return; |
163 } | 164 } |
164 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this->
context(), | 165 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this->
context(), |
165 viewMatrix, paint)); | 166 viewMatrix, paint, fRend
erTarget)); |
166 GrPaint grPaint; | 167 GrPaint grPaint; |
167 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) { | 168 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint, fRenderTar
get)) { |
168 return; | 169 return; |
169 } | 170 } |
170 | 171 |
171 if (canUseTextureCoordsAsLocalCoords) { | 172 if (canUseTextureCoordsAsLocalCoords) { |
172 SkRect localRect; | 173 SkRect localRect; |
173 localRect.fLeft = clippedSrcRect.fLeft / texture->width(); | 174 localRect.fLeft = clippedSrcRect.fLeft / texture->width(); |
174 localRect.fBottom = clippedSrcRect.fBottom / texture->height(); | 175 localRect.fBottom = clippedSrcRect.fBottom / texture->height(); |
175 localRect.fRight = clippedSrcRect.fRight / texture->width(); | 176 localRect.fRight = clippedSrcRect.fRight / texture->width(); |
176 localRect.fTop = clippedSrcRect.fTop / texture->height(); | 177 localRect.fTop = clippedSrcRect.fTop / texture->height(); |
177 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
localRect); | 178 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
localRect); |
(...skipping 17 matching lines...) Expand all Loading... |
195 rec, | 196 rec, |
196 rrect)) { | 197 rrect)) { |
197 return; | 198 return; |
198 } | 199 } |
199 SkPath rectPath; | 200 SkPath rectPath; |
200 rectPath.addRect(clippedDstRect); | 201 rectPath.addRect(clippedDstRect); |
201 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, | 202 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, |
202 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), | 203 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), |
203 GrStrokeInfo::FillInfo()); | 204 GrStrokeInfo::FillInfo()); |
204 } | 205 } |
OLD | NEW |