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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const SkRect& clippedDstRect, | 113 const SkRect& clippedDstRect, |
114 SkCanvas::SrcRectConstraint constraint
, | 114 SkCanvas::SrcRectConstraint constraint
, |
115 const SkMatrix& viewMatrix, | 115 const SkMatrix& viewMatrix, |
116 const SkMatrix& srcToDstMatrix, | 116 const SkMatrix& srcToDstMatrix, |
117 const GrClip& clip, | 117 const GrClip& clip, |
118 const SkPaint& paint) { | 118 const SkPaint& paint) { |
119 // Specifying the texture coords as local coordinates is an attempt to enabl
e more batching | 119 // Specifying the texture coords as local coordinates is an attempt to enabl
e more batching |
120 // by not baking anything about the srcRect, dstRect, or viewMatrix, into th
e texture FP. In | 120 // by not baking anything about the srcRect, dstRect, or viewMatrix, into th
e texture FP. In |
121 // the future this should be an opaque optimization enabled by the combinati
on of batch/GP and | 121 // the future this should be an opaque optimization enabled by the combinati
on of batch/GP and |
122 // FP. | 122 // FP. |
123 const SkMatrix* textureFPMatrix; | 123 SkMatrix textureFPMatrix; |
124 SkMatrix tempMatrix; | |
125 const SkMaskFilter* mf = paint.getMaskFilter(); | 124 const SkMaskFilter* mf = paint.getMaskFilter(); |
126 GrTexture* texture = adjuster->originalTexture(); | 125 GrTexture* texture = adjuster->originalTexture(); |
127 // The shader expects proper local coords, so we can't replace local coords
with texture coords | 126 // The shader expects proper local coords, so we can't replace local coords
with texture coords |
128 // if the shader will be used. If we have a mask filter we will change the u
nderlying geometry | 127 // if the shader will be used. If we have a mask filter we will change the u
nderlying geometry |
129 // that is rendered. | 128 // that is rendered. |
130 bool canUseTextureCoordsAsLocalCoords = !use_shader(alphaTexture, paint) &&
!mf; | 129 bool canUseTextureCoordsAsLocalCoords = !use_shader(alphaTexture, paint) &&
!mf; |
131 if (canUseTextureCoordsAsLocalCoords) { | 130 if (canUseTextureCoordsAsLocalCoords) { |
132 textureFPMatrix = &SkMatrix::I(); | 131 textureFPMatrix.setIDiv(texture->width(), texture->height()); |
133 } else { | 132 } else { |
134 if (!srcToDstMatrix.invert(&tempMatrix)) { | 133 if (!srcToDstMatrix.invert(&textureFPMatrix)) { |
135 return; | 134 return; |
136 } | 135 } |
137 tempMatrix.postIDiv(texture->width(), texture->height()); | 136 textureFPMatrix.postIDiv(texture->width(), texture->height()); |
138 textureFPMatrix = &tempMatrix; | |
139 } | 137 } |
140 | 138 |
141 bool doBicubic; | 139 bool doBicubic; |
142 GrTextureParams::FilterMode fm = | 140 GrTextureParams::FilterMode fm = |
143 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, sr
cToDstMatrix, | 141 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, sr
cToDstMatrix, |
144 &doBicubic); | 142 &doBicubic); |
145 const GrTextureParams::FilterMode* filterMode = doBicubic ? nullptr : &fm; | 143 const GrTextureParams::FilterMode* filterMode = doBicubic ? nullptr : &fm; |
146 | 144 |
147 GrTextureAdjuster::FilterConstraint constraintMode; | 145 GrTextureAdjuster::FilterConstraint constraintMode; |
148 if (SkCanvas::kFast_SrcRectConstraint == constraint) { | 146 if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
149 constraintMode = GrTextureAdjuster::kNo_FilterConstraint; | 147 constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
150 } else { | 148 } else { |
151 constraintMode = GrTextureAdjuster::kYes_FilterConstraint; | 149 constraintMode = GrTextureAdjuster::kYes_FilterConstraint; |
152 } | 150 } |
153 | 151 |
154 // If we have to outset for AA then we will generate texture coords outside
the src rect. The | 152 // 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. | 153 // 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. | 154 // This is conservative as a mask filter does not have to expand the bounds
rendered. |
157 bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf; | 155 bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf; |
158 | 156 |
159 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor
( | 157 SkAutoTUnref<const GrFragmentProcessor> fp(adjuster->createFragmentProcessor
( |
160 *textureFPMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect
, filterMode)); | 158 textureFPMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); |
161 if (!fp) { | 159 if (!fp) { |
162 return; | 160 return; |
163 } | 161 } |
164 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this->
context(), | 162 fp.reset(mix_texture_fp_with_paint_color_and_shader(fp, alphaTexture, this->
context(), |
165 viewMatrix, paint)); | 163 viewMatrix, paint)); |
166 GrPaint grPaint; | 164 GrPaint grPaint; |
167 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) { | 165 if (!SkPaintToGrPaintReplaceShader(fContext, paint, fp, &grPaint)) { |
168 return; | 166 return; |
169 } | 167 } |
170 | 168 |
171 if (canUseTextureCoordsAsLocalCoords) { | 169 if (canUseTextureCoordsAsLocalCoords) { |
172 SkRect localRect; | 170 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); |
173 localRect.fLeft = clippedSrcRect.fLeft / texture->width(); | |
174 localRect.fBottom = clippedSrcRect.fBottom / texture->height(); | |
175 localRect.fRight = clippedSrcRect.fRight / texture->width(); | |
176 localRect.fTop = clippedSrcRect.fTop / texture->height(); | |
177 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
localRect); | |
178 return; | 171 return; |
179 } | 172 } |
180 | 173 |
181 if (!mf) { | 174 if (!mf) { |
182 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); | 175 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); |
183 return; | 176 return; |
184 } | 177 } |
185 | 178 |
186 // First see if we can do the draw + mask filter direct to the dst. | 179 // First see if we can do the draw + mask filter direct to the dst. |
187 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); | 180 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
188 SkRRect rrect; | 181 SkRRect rrect; |
189 rrect.setRect(clippedDstRect); | 182 rrect.setRect(clippedDstRect); |
190 if (mf->directFilterRRectMaskGPU(fContext->textureProvider(), | 183 if (mf->directFilterRRectMaskGPU(fContext->textureProvider(), |
191 fDrawContext, | 184 fDrawContext, |
192 &grPaint, | 185 &grPaint, |
193 clip, | 186 clip, |
194 viewMatrix, | 187 viewMatrix, |
195 rec, | 188 rec, |
196 rrect)) { | 189 rrect)) { |
197 return; | 190 return; |
198 } | 191 } |
199 SkPath rectPath; | 192 SkPath rectPath; |
200 rectPath.addRect(clippedDstRect); | 193 rectPath.addRect(clippedDstRect); |
201 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, | 194 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fRenderTa
rget, fClip, |
202 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), | 195 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), |
203 GrStrokeInfo::FillInfo()); | 196 GrStrokeInfo::FillInfo()); |
204 } | 197 } |
OLD | NEW |