| 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 12 matching lines...) Expand all Loading... |
| 23 #include "SkDrawProcs.h" | 23 #include "SkDrawProcs.h" |
| 24 #include "SkErrorInternals.h" | 24 #include "SkErrorInternals.h" |
| 25 #include "SkGlyphCache.h" | 25 #include "SkGlyphCache.h" |
| 26 #include "SkGrTexturePixelRef.h" | 26 #include "SkGrTexturePixelRef.h" |
| 27 #include "SkGr.h" | 27 #include "SkGr.h" |
| 28 #include "SkGrPriv.h" | 28 #include "SkGrPriv.h" |
| 29 #include "SkImage_Base.h" | 29 #include "SkImage_Base.h" |
| 30 #include "SkImageFilter.h" | 30 #include "SkImageFilter.h" |
| 31 #include "SkLayerInfo.h" | 31 #include "SkLayerInfo.h" |
| 32 #include "SkMaskFilter.h" | 32 #include "SkMaskFilter.h" |
| 33 #include "SkNinePatchIter.h" |
| 33 #include "SkPathEffect.h" | 34 #include "SkPathEffect.h" |
| 34 #include "SkPicture.h" | 35 #include "SkPicture.h" |
| 35 #include "SkPictureData.h" | 36 #include "SkPictureData.h" |
| 36 #include "SkRRect.h" | 37 #include "SkRRect.h" |
| 37 #include "SkRecord.h" | 38 #include "SkRecord.h" |
| 38 #include "SkStroke.h" | 39 #include "SkStroke.h" |
| 39 #include "SkSurface.h" | 40 #include "SkSurface.h" |
| 40 #include "SkSurface_Gpu.h" | 41 #include "SkSurface_Gpu.h" |
| 41 #include "SkTLazy.h" | 42 #include "SkTLazy.h" |
| 42 #include "SkUtils.h" | 43 #include "SkUtils.h" |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 paramsTemp, | 1014 paramsTemp, |
| 1014 *paint, | 1015 *paint, |
| 1015 constraint, | 1016 constraint, |
| 1016 bicubic, | 1017 bicubic, |
| 1017 needsTextureDomain); | 1018 needsTextureDomain); |
| 1018 } | 1019 } |
| 1019 } | 1020 } |
| 1020 } | 1021 } |
| 1021 } | 1022 } |
| 1022 | 1023 |
| 1023 | |
| 1024 /* | 1024 /* |
| 1025 * This is called by drawBitmap(), which has to handle images that may be too | 1025 * This is called by drawBitmap(), which has to handle images that may be too |
| 1026 * large to be represented by a single texture. | 1026 * large to be represented by a single texture. |
| 1027 * | 1027 * |
| 1028 * internalDrawBitmap assumes that the specified bitmap will fit in a texture | 1028 * internalDrawBitmap assumes that the specified bitmap will fit in a texture |
| 1029 * and that non-texture portion of the GrPaint has already been setup. | 1029 * and that non-texture portion of the GrPaint has already been setup. |
| 1030 */ | 1030 */ |
| 1031 void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, | 1031 void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, |
| 1032 const SkMatrix& viewMatrix, | 1032 const SkMatrix& viewMatrix, |
| 1033 const SkRect& srcRect, | 1033 const SkRect& srcRect, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 // local coords with the bitmap draw since it may mess up texture look u
ps for the shader. | 1067 // local coords with the bitmap draw since it may mess up texture look u
ps for the shader. |
| 1068 // Thus we need to pass in the transform matrix directly to the texture
processor used for | 1068 // Thus we need to pass in the transform matrix directly to the texture
processor used for |
| 1069 // the bitmap draw. | 1069 // the bitmap draw. |
| 1070 texMatrix.setScale(wInv, hInv); | 1070 texMatrix.setScale(wInv, hInv); |
| 1071 } | 1071 } |
| 1072 | 1072 |
| 1073 SkRect textureDomain = SkRect::MakeEmpty(); | 1073 SkRect textureDomain = SkRect::MakeEmpty(); |
| 1074 | 1074 |
| 1075 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | 1075 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
| 1076 // the rest from the SkPaint. | 1076 // the rest from the SkPaint. |
| 1077 GrPaint grPaint; | |
| 1078 SkAutoTUnref<const GrFragmentProcessor> fp; | 1077 SkAutoTUnref<const GrFragmentProcessor> fp; |
| 1079 | 1078 |
| 1080 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint
)) { | 1079 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint
)) { |
| 1081 // Use a constrained texture domain to avoid color bleeding | 1080 // Use a constrained texture domain to avoid color bleeding |
| 1082 SkScalar left, top, right, bottom; | 1081 SkScalar left, top, right, bottom; |
| 1083 if (srcRect.width() > SK_Scalar1) { | 1082 if (srcRect.width() > SK_Scalar1) { |
| 1084 SkScalar border = SK_ScalarHalf / texture->width(); | 1083 SkScalar border = SK_ScalarHalf / texture->width(); |
| 1085 left = paintRect.left() + border; | 1084 left = paintRect.left() + border; |
| 1086 right = paintRect.right() - border; | 1085 right = paintRect.right() - border; |
| 1087 } else { | 1086 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1105 params.filterMode())); | 1104 params.filterMode())); |
| 1106 } | 1105 } |
| 1107 } else if (bicubic) { | 1106 } else if (bicubic) { |
| 1108 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1107 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
| 1109 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; | 1108 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; |
| 1110 fp.reset(GrBicubicEffect::Create(texture, texMatrix, tileModes)); | 1109 fp.reset(GrBicubicEffect::Create(texture, texMatrix, tileModes)); |
| 1111 } else { | 1110 } else { |
| 1112 fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params)); | 1111 fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params)); |
| 1113 } | 1112 } |
| 1114 | 1113 |
| 1115 SkAutoTUnref<const GrFragmentProcessor> shaderFP; | 1114 GrPaint grPaint; |
| 1116 | 1115 if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, fp, |
| 1117 if (kAlpha_8_SkColorType == bitmap.colorType()) { | 1116 kAlpha_8_SkColorType == bitmap.colorType(),
&grPaint)) { |
| 1118 if (const SkShader* shader = paint.getShader()) { | |
| 1119 shaderFP.reset(shader->asFragmentProcessor(this->context(), | |
| 1120 viewMatrix, | |
| 1121 nullptr, | |
| 1122 paint.getFilterQuality())
); | |
| 1123 if (!shaderFP) { | |
| 1124 return; | |
| 1125 } | |
| 1126 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp.get() }
; | |
| 1127 fp.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); | |
| 1128 } else { | |
| 1129 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | |
| 1130 } | |
| 1131 } else { | |
| 1132 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | |
| 1133 } | |
| 1134 | |
| 1135 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | |
| 1136 return; | 1117 return; |
| 1137 } | 1118 } |
| 1138 | 1119 |
| 1139 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { | 1120 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { |
| 1140 // We don't have local coords in this case and have previously set the t
ransform | 1121 // We don't have local coords in this case and have previously set the t
ransform |
| 1141 // matrices directly on the texture processor. | 1122 // matrices directly on the texture processor. |
| 1142 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); | 1123 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); |
| 1143 } else { | 1124 } else { |
| 1144 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR
ect); | 1125 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR
ect); |
| 1145 } | 1126 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 return; | 1469 return; |
| 1489 } | 1470 } |
| 1490 } else { | 1471 } else { |
| 1491 if (!wrap_as_bm(this->context(), image, &bm)) { | 1472 if (!wrap_as_bm(this->context(), image, &bm)) { |
| 1492 return; | 1473 return; |
| 1493 } | 1474 } |
| 1494 } | 1475 } |
| 1495 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); | 1476 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
| 1496 } | 1477 } |
| 1497 | 1478 |
| 1479 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
| 1480 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { |
| 1481 // TODO write native implementation |
| 1482 SkBitmap bitmap; |
| 1483 if (!wrap_as_bm(this->context(), image, &bitmap)) { |
| 1484 return; |
| 1485 } |
| 1486 return this->drawBitmapNine(draw, bitmap, center, dst, paint); |
| 1487 } |
| 1488 |
| 1489 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, |
| 1490 const SkRect& dst, const SkPaint& paint) { |
| 1491 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawBitmapNine", fContext); |
| 1492 |
| 1493 CHECK_FOR_ANNOTATION(paint); |
| 1494 CHECK_SHOULD_DRAW(draw); |
| 1495 |
| 1496 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias(); |
| 1497 bool doBicubic; |
| 1498 GrTextureParams::FilterMode textureFilterMode = |
| 1499 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMat
rix, SkMatrix::I(), |
| 1500 &doBicubic); |
| 1501 |
| 1502 // TODO handle bilerp |
| 1503 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { |
| 1504 SkNinePatchIter iter(bitmap.width(), bitmap.height(), center, dst); |
| 1505 |
| 1506 SkRect srcR, dstR; |
| 1507 while (iter.next(&srcR, &dstR)) { |
| 1508 this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint, |
| 1509 SkCanvas::kStrict_SrcRectConstraint); |
| 1510 } |
| 1511 return; |
| 1512 } |
| 1513 |
| 1514 GrTextureParams params = GrTextureParams::ClampNoFilter(); |
| 1515 |
| 1516 GrTexture* texture(GrRefCachedBitmapTexture(this->context(), bitmap, params)
); |
| 1517 if (nullptr == texture) { |
| 1518 return; |
| 1519 } |
| 1520 |
| 1521 SkMatrix texMatrix; |
| 1522 texMatrix.setIDiv(texture->width(), texture->height()); |
| 1523 |
| 1524 SkAutoTUnref<const GrFragmentProcessor> fp(GrSimpleTextureEffect::Create(tex
ture, texMatrix, |
| 1525 par
ams)); |
| 1526 |
| 1527 GrPaint grPaint; |
| 1528 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, |
| 1529 kAlpha_8_SkColorType == bitmap.colorType(),
&grPaint)) { |
| 1530 return; |
| 1531 } |
| 1532 |
| 1533 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, bitmap.width(), b
itmap.height(), |
| 1534 center, dst); |
| 1535 } |
| 1536 |
| 1498 /////////////////////////////////////////////////////////////////////////////// | 1537 /////////////////////////////////////////////////////////////////////////////// |
| 1499 | 1538 |
| 1500 // must be in SkCanvas::VertexMode order | 1539 // must be in SkCanvas::VertexMode order |
| 1501 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1540 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1502 kTriangles_GrPrimitiveType, | 1541 kTriangles_GrPrimitiveType, |
| 1503 kTriangleStrip_GrPrimitiveType, | 1542 kTriangleStrip_GrPrimitiveType, |
| 1504 kTriangleFan_GrPrimitiveType, | 1543 kTriangleFan_GrPrimitiveType, |
| 1505 }; | 1544 }; |
| 1506 | 1545 |
| 1507 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1546 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1838 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1877 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1839 } | 1878 } |
| 1840 | 1879 |
| 1841 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1880 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1842 // We always return a transient cache, so it is freed after each | 1881 // We always return a transient cache, so it is freed after each |
| 1843 // filter traversal. | 1882 // filter traversal. |
| 1844 return SkGpuDevice::NewImageFilterCache(); | 1883 return SkGpuDevice::NewImageFilterCache(); |
| 1845 } | 1884 } |
| 1846 | 1885 |
| 1847 #endif | 1886 #endif |
| OLD | NEW |