Index: src/gpu/SkGpuDevice.cpp |
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
index c97d24809a2036c16d473437fd3b9bc56737e2f0..a67ca73d7d2ae207ca81723dfe6eccadd6fd3650 100644 |
--- a/src/gpu/SkGpuDevice.cpp |
+++ b/src/gpu/SkGpuDevice.cpp |
@@ -30,6 +30,7 @@ |
#include "SkImageFilter.h" |
#include "SkLayerInfo.h" |
#include "SkMaskFilter.h" |
+#include "SkNinePatchIter.h" |
#include "SkPathEffect.h" |
#include "SkPicture.h" |
#include "SkPictureData.h" |
@@ -1727,6 +1728,93 @@ void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const |
this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
} |
+void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, const SkIRect& center, |
+ const SkRect& dst, const SkPaint& paint) { |
+ |
+ SkBitmap bitmap; |
+ if (!wrap_as_bm(this->context(), image, &bitmap)) { |
bsalomon
2015/11/17 22:26:09
Let's do a real impl here... this has a malloc hid
joshualitt
2015/11/18 17:46:15
per conversation, lets defer until you finish what
|
+ return; |
+ } |
+ |
+ this->drawBitmapNine(draw, bitmap, center, dst, paint); |
+} |
+ |
+void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, const SkIRect& center, |
+ const SkRect& dst, const SkPaint& paint) { |
+ GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawBitmapNine", fContext); |
+ |
+ CHECK_FOR_ANNOTATION(paint); |
+ CHECK_SHOULD_DRAW(draw); |
+ |
bsalomon
2015/11/17 22:26:09
Let's just fail if the bitmap is texture backed. D
joshualitt
2015/11/18 17:46:15
we can't because it seems that wrap_as_bm seems to
|
+ bool useFallback = paint.getMaskFilter() || paint.isAntiAlias(); |
+ bool doBicubic; |
+ GrTextureParams::FilterMode textureFilterMode = |
+ GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I(), |
+ &doBicubic); |
+ |
+ // TODO handle bilerp |
+ if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != textureFilterMode) { |
+ SkNinePatchIter iter(bitmap.width(), bitmap.height(), center, dst); |
+ |
+ SkRect srcR, dstR; |
+ while (iter.next(&srcR, &dstR)) { |
+ this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint, |
+ SkCanvas::kStrict_SrcRectConstraint); |
+ } |
+ return; |
+ } |
+ |
+ GrTextureParams params; |
+ if (GrTextureParams::kBilerp_FilterMode == textureFilterMode) { |
+ params = GrTextureParams::ClampBilerp(); |
+ } else { |
+ params = GrTextureParams::ClampNoFilter(); |
+ } |
+ |
+ GrTexture* texture; |
+ AutoBitmapTexture abt(fContext, bitmap, params, &texture); |
bsalomon
2015/11/17 22:26:09
Let's not expand the use of this. It used to do a
joshualitt
2015/11/18 17:46:15
Acknowledged.
|
+ if (nullptr == texture) { |
+ return; |
+ } |
+ |
+ // TODO Brian, help? |
+ SkMatrix texMatrix = SkMatrix::I(); |
bsalomon
2015/11/17 22:26:09
SkMatrix texMatrix;
texMatrix.setIDiv(texture->wid
joshualitt
2015/11/18 17:46:15
Acknowledged.
|
+ |
+ SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
+ SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
+ texMatrix.setScale(wInv, hInv); |
+ |
+ SkAutoTUnref<const GrFragmentProcessor> fp(GrSimpleTextureEffect::Create(texture, texMatrix, |
+ params)); |
+ SkAutoTUnref<const GrFragmentProcessor> shaderFP; |
+ |
+ if (kAlpha_8_SkColorType == bitmap.colorType()) { |
bsalomon
2015/11/17 22:26:09
we do this logic in a bunch of places.. maybe this
joshualitt
2015/11/18 17:46:15
Acknowledged.
|
+ if (const SkShader* shader = paint.getShader()) { |
+ shaderFP.reset(shader->asFragmentProcessor(this->context(), |
+ *draw.fMatrix, |
+ nullptr, |
+ paint.getFilterQuality())); |
+ if (!shaderFP) { |
+ return; |
+ } |
+ const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp.get() }; |
+ fp.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); |
+ } else { |
+ fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); |
+ } |
+ } else { |
+ fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
+ } |
+ |
+ GrPaint grPaint; |
+ if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { |
+ return; |
+ } |
+ |
+ fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, bitmap.width(), bitmap.height(), |
+ center, dst); |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
// must be in SkCanvas::VertexMode order |