OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; | 1199 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; |
1200 SkRect paintRect; | 1200 SkRect paintRect; |
1201 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); | 1201 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
1202 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); | 1202 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
1203 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1203 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
1204 SkScalarMul(srcRect.fTop, hInv), | 1204 SkScalarMul(srcRect.fTop, hInv), |
1205 SkScalarMul(srcRect.fRight, wInv), | 1205 SkScalarMul(srcRect.fRight, wInv), |
1206 SkScalarMul(srcRect.fBottom, hInv)); | 1206 SkScalarMul(srcRect.fBottom, hInv)); |
1207 | 1207 |
1208 SkRect textureDomain = SkRect::MakeEmpty(); | 1208 SkRect textureDomain = SkRect::MakeEmpty(); |
| 1209 |
| 1210 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
| 1211 // the rest from the SkPaint. |
| 1212 GrPaint grPaint; |
1209 SkAutoTUnref<GrFragmentProcessor> fp; | 1213 SkAutoTUnref<GrFragmentProcessor> fp; |
| 1214 |
1210 if (needsTextureDomain && !(flags & SkCanvas::kBleed_DrawBitmapRectFlag)) { | 1215 if (needsTextureDomain && !(flags & SkCanvas::kBleed_DrawBitmapRectFlag)) { |
1211 // Use a constrained texture domain to avoid color bleeding | 1216 // Use a constrained texture domain to avoid color bleeding |
1212 SkScalar left, top, right, bottom; | 1217 SkScalar left, top, right, bottom; |
1213 if (srcRect.width() > SK_Scalar1) { | 1218 if (srcRect.width() > SK_Scalar1) { |
1214 SkScalar border = SK_ScalarHalf / texture->width(); | 1219 SkScalar border = SK_ScalarHalf / texture->width(); |
1215 left = paintRect.left() + border; | 1220 left = paintRect.left() + border; |
1216 right = paintRect.right() - border; | 1221 right = paintRect.right() - border; |
1217 } else { | 1222 } else { |
1218 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1223 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
1219 } | 1224 } |
1220 if (srcRect.height() > SK_Scalar1) { | 1225 if (srcRect.height() > SK_Scalar1) { |
1221 SkScalar border = SK_ScalarHalf / texture->height(); | 1226 SkScalar border = SK_ScalarHalf / texture->height(); |
1222 top = paintRect.top() + border; | 1227 top = paintRect.top() + border; |
1223 bottom = paintRect.bottom() - border; | 1228 bottom = paintRect.bottom() - border; |
1224 } else { | 1229 } else { |
1225 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); | 1230 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
1226 } | 1231 } |
1227 textureDomain.setLTRB(left, top, right, bottom); | 1232 textureDomain.setLTRB(left, top, right, bottom); |
1228 if (bicubic) { | 1233 if (bicubic) { |
1229 fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), textureDoma
in)); | 1234 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(),
texture, |
| 1235 SkMatrix::I(), textureDomain)); |
1230 } else { | 1236 } else { |
1231 fp.reset(GrTextureDomainEffect::Create(texture, | 1237 fp.reset(GrTextureDomainEffect::Create(grPaint.getProcessorDataManag
er(), |
| 1238 texture, |
1232 SkMatrix::I(), | 1239 SkMatrix::I(), |
1233 textureDomain, | 1240 textureDomain, |
1234 GrTextureDomain::kClamp_Mode, | 1241 GrTextureDomain::kClamp_Mode, |
1235 params.filterMode())); | 1242 params.filterMode())); |
1236 } | 1243 } |
1237 } else if (bicubic) { | 1244 } else if (bicubic) { |
1238 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1245 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
1239 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; | 1246 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; |
1240 fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes)); | 1247 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text
ure, SkMatrix::I(), |
| 1248 tileModes)); |
1241 } else { | 1249 } else { |
1242 fp.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), params)); | 1250 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager()
, texture, |
| 1251 SkMatrix::I(), params)); |
1243 } | 1252 } |
1244 | 1253 |
1245 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | |
1246 // the rest from the SkPaint. | |
1247 GrPaint grPaint; | |
1248 grPaint.addColorProcessor(fp); | 1254 grPaint.addColorProcessor(fp); |
1249 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); | 1255 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); |
1250 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : | 1256 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : |
1251 SkColor2GrColor(paint.getColor()); | 1257 SkColor2GrColor(paint.getColor()); |
1252 if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintCol
or, false, | 1258 if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintCol
or, false, |
1253 &grPaint)) { | 1259 &grPaint)) { |
1254 return; | 1260 return; |
1255 } | 1261 } |
1256 | 1262 |
1257 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix,
dstRect, | 1263 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix,
dstRect, |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 #endif | 1853 #endif |
1848 } | 1854 } |
1849 | 1855 |
1850 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1856 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1851 // We always return a transient cache, so it is freed after each | 1857 // We always return a transient cache, so it is freed after each |
1852 // filter traversal. | 1858 // filter traversal. |
1853 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1859 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1854 } | 1860 } |
1855 | 1861 |
1856 #endif | 1862 #endif |
OLD | NEW |