| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 !may_color_bleed(srcRect, transformedRect, srcRectToDeviceSpace, isM
SAA)) { | 81 !may_color_bleed(srcRect, transformedRect, srcRectToDeviceSpace, isM
SAA)) { |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 | 87 |
| 88 ////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////// |
| 89 | 89 |
| 90 void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, | 90 void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, |
| 91 bool alphaOnly, | |
| 92 const SkRect* srcRect, | 91 const SkRect* srcRect, |
| 93 const SkRect* dstRect, | 92 const SkRect* dstRect, |
| 94 SkCanvas::SrcRectConstraint constraint, | 93 SkCanvas::SrcRectConstraint constraint, |
| 95 const SkMatrix& viewMatrix, | 94 const SkMatrix& viewMatrix, |
| 96 const GrClip& clip, | 95 const GrClip& clip, |
| 97 const SkPaint& paint) { | 96 const SkPaint& paint) { |
| 98 // Figure out the actual dst and src rect by clipping the src rect to the bo
unds of the | 97 // Figure out the actual dst and src rect by clipping the src rect to the bo
unds of the |
| 99 // adjuster. If the src rect is clipped then the dst rect must be recomputed
. Also determine | 98 // adjuster. If the src rect is clipped then the dst rect must be recomputed
. Also determine |
| 100 // the matrix that maps the src rect to the dst rect. | 99 // the matrix that maps the src rect to the dst rect. |
| 101 SkRect clippedSrcRect; | 100 SkRect clippedSrcRect; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 128 clippedDstRect = *dstRect; | 127 clippedDstRect = *dstRect; |
| 129 if (!srcToDstMatrix.setRectToRect(srcBounds, *dstRect, SkMatrix::kFi
ll_ScaleToFit)) { | 128 if (!srcToDstMatrix.setRectToRect(srcBounds, *dstRect, SkMatrix::kFi
ll_ScaleToFit)) { |
| 130 return; | 129 return; |
| 131 } | 130 } |
| 132 } else { | 131 } else { |
| 133 clippedDstRect = srcBounds; | 132 clippedDstRect = srcBounds; |
| 134 srcToDstMatrix.reset(); | 133 srcToDstMatrix.reset(); |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 | 136 |
| 138 this->drawTextureProducerImpl(producer, alphaOnly, clippedSrcRect, clippedDs
tRect, constraint, | 137 this->drawTextureProducerImpl(producer, clippedSrcRect, clippedDstRect, cons
traint, viewMatrix, |
| 139 viewMatrix, srcToDstMatrix, clip, paint); | 138 srcToDstMatrix, clip, paint); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, | 141 void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, |
| 143 bool alphaTexture, | |
| 144 const SkRect& clippedSrcRect, | 142 const SkRect& clippedSrcRect, |
| 145 const SkRect& clippedDstRect, | 143 const SkRect& clippedDstRect, |
| 146 SkCanvas::SrcRectConstraint constraint
, | 144 SkCanvas::SrcRectConstraint constraint
, |
| 147 const SkMatrix& viewMatrix, | 145 const SkMatrix& viewMatrix, |
| 148 const SkMatrix& srcToDstMatrix, | 146 const SkMatrix& srcToDstMatrix, |
| 149 const GrClip& clip, | 147 const GrClip& clip, |
| 150 const SkPaint& paint) { | 148 const SkPaint& paint) { |
| 151 // Specifying the texture coords as local coordinates is an attempt to enabl
e more batching | 149 // Specifying the texture coords as local coordinates is an attempt to enabl
e more batching |
| 152 // by not baking anything about the srcRect, dstRect, or viewMatrix, into th
e texture FP. In | 150 // by not baking anything about the srcRect, dstRect, or viewMatrix, into th
e texture FP. In |
| 153 // the future this should be an opaque optimization enabled by the combinati
on of batch/GP and | 151 // the future this should be an opaque optimization enabled by the combinati
on of batch/GP and |
| 154 // FP. | 152 // FP. |
| 155 const SkMaskFilter* mf = paint.getMaskFilter(); | 153 const SkMaskFilter* mf = paint.getMaskFilter(); |
| 156 // The shader expects proper local coords, so we can't replace local coords
with texture coords | 154 // The shader expects proper local coords, so we can't replace local coords
with texture coords |
| 157 // if the shader will be used. If we have a mask filter we will change the u
nderlying geometry | 155 // if the shader will be used. If we have a mask filter we will change the u
nderlying geometry |
| 158 // that is rendered. | 156 // that is rendered. |
| 159 bool canUseTextureCoordsAsLocalCoords = !use_shader(alphaTexture, paint) &&
!mf; | 157 bool canUseTextureCoordsAsLocalCoords = !use_shader(producer->isAlphaOnly(),
paint) && !mf; |
| 160 | 158 |
| 161 bool doBicubic; | 159 bool doBicubic; |
| 162 GrTextureParams::FilterMode fm = | 160 GrTextureParams::FilterMode fm = |
| 163 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, sr
cToDstMatrix, | 161 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, sr
cToDstMatrix, |
| 164 &doBicubic); | 162 &doBicubic); |
| 165 const GrTextureParams::FilterMode* filterMode = doBicubic ? nullptr : &fm; | 163 const GrTextureParams::FilterMode* filterMode = doBicubic ? nullptr : &fm; |
| 166 | 164 |
| 167 GrTextureAdjuster::FilterConstraint constraintMode; | 165 GrTextureAdjuster::FilterConstraint constraintMode; |
| 168 if (SkCanvas::kFast_SrcRectConstraint == constraint) { | 166 if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
| 169 constraintMode = GrTextureAdjuster::kNo_FilterConstraint; | 167 constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 197 } | 195 } |
| 198 textureMatrix = &tempMatrix; | 196 textureMatrix = &tempMatrix; |
| 199 } | 197 } |
| 200 SkAutoTUnref<const GrFragmentProcessor> fp(producer->createFragmentProcessor
( | 198 SkAutoTUnref<const GrFragmentProcessor> fp(producer->createFragmentProcessor
( |
| 201 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); | 199 *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect,
filterMode)); |
| 202 if (!fp) { | 200 if (!fp) { |
| 203 return; | 201 return; |
| 204 } | 202 } |
| 205 | 203 |
| 206 GrPaint grPaint; | 204 GrPaint grPaint; |
| 207 if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, alphaTextu
re, &grPaint)) { | 205 if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, producer->
isAlphaOnly(), |
| 206 &grPaint)) { |
| 208 return; | 207 return; |
| 209 } | 208 } |
| 210 | 209 |
| 211 if (canUseTextureCoordsAsLocalCoords) { | 210 if (canUseTextureCoordsAsLocalCoords) { |
| 212 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); | 211 fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect); |
| 213 return; | 212 return; |
| 214 } | 213 } |
| 215 | 214 |
| 216 if (!mf) { | 215 if (!mf) { |
| 217 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); | 216 fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 231 rrect)) { | 230 rrect)) { |
| 232 return; | 231 return; |
| 233 } | 232 } |
| 234 SkPath rectPath; | 233 SkPath rectPath; |
| 235 rectPath.addRect(clippedDstRect); | 234 rectPath.addRect(clippedDstRect); |
| 236 rectPath.setIsVolatile(true); | 235 rectPath.setIsVolatile(true); |
| 237 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fClip, | 236 GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fClip, |
| 238 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), | 237 rectPath, &grPaint, viewMatrix, mf, pain
t.getPathEffect(), |
| 239 GrStrokeInfo::FillInfo(), true); | 238 GrStrokeInfo::FillInfo(), true); |
| 240 } | 239 } |
| OLD | NEW |