Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 1454933002: Initial implementation of GPU no filter NinePatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 36e0342f78b2a522e1c1c47af8e1772f3a5b7b1f..c26ad87253d8951cc1cbd8a74b775d750618ca60 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"
@@ -1286,7 +1287,6 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
}
}
-
/*
* This is called by drawBitmap(), which has to handle images that may be too
* large to be represented by a single texture.
@@ -1340,7 +1340,6 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
// Construct a GrPaint by setting the bitmap texture as the first effect and then configuring
// the rest from the SkPaint.
- GrPaint grPaint;
SkAutoTUnref<const GrFragmentProcessor> fp;
if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) {
@@ -1378,27 +1377,9 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params));
}
- SkAutoTUnref<const GrFragmentProcessor> shaderFP;
-
- if (kAlpha_8_SkColorType == bitmap.colorType()) {
- if (const SkShader* shader = paint.getShader()) {
- shaderFP.reset(shader->asFragmentProcessor(this->context(),
- viewMatrix,
- 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));
- }
-
- if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) {
+ GrPaint grPaint;
+ if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, fp,
+ kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) {
return;
}
@@ -1727,6 +1708,65 @@ 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) {
+ // TODO write native implementation
+ SkBitmap bitmap;
+ if (!wrap_as_bm(this->context(), image, &bitmap)) {
+ return;
+ }
+ 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);
+
robertphillips 2015/11/18 18:12:07 This comment seems wrong ...
joshualitt 2015/11/18 19:07:07 Acknowledged.
+ // we fallback for bitmap backed textures
+ 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 = GrTextureParams::ClampNoFilter();
+
+ GrTexture* texture(GrRefCachedBitmapTexture(this->context(), bitmap, params));
+ if (nullptr == texture) {
+ return;
+ }
+
+ SkMatrix texMatrix;
+ texMatrix.setIDiv(texture->width(), texture->height());
+
+ SkAutoTUnref<const GrFragmentProcessor> fp(GrSimpleTextureEffect::Create(texture, texMatrix,
+ params));
+
+ GrPaint grPaint;
+ if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp,
+ kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) {
+ return;
+ }
+
+ fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, bitmap.width(), bitmap.height(),
+ center, dst);
+}
+
///////////////////////////////////////////////////////////////////////////////
// must be in SkCanvas::VertexMode order

Powered by Google App Engine
This is Rietveld 408576698