aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-08-12 12:57:54 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-12 12:57:54 -0700
commit9bc3954fc1b6c3fb609cbb10d42f659b9d762eb0 (patch)
tree4b915a701b43217e08c3fa0ae551011c504a9542
parent33e00db73d5f1836481cf4053c64e4ed20537662 (diff)
Refactor helper function for SkBitmapShader to GrFragmentProcessor
-rw-r--r--include/gpu/SkGr.h8
-rw-r--r--src/core/SkBitmapProcShader.cpp43
-rw-r--r--src/gpu/SkGpuDevice.cpp37
-rw-r--r--src/gpu/SkGr.cpp43
4 files changed, 60 insertions, 71 deletions
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 4de61afffb..e46479eb0f 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -14,8 +14,9 @@
#include <stddef.h>
// Gr headers
-#include "GrTypes.h"
#include "GrContext.h"
+#include "GrTextureAccess.h"
+#include "GrTypes.h"
// skia headers
#include "SkBitmap.h"
@@ -96,6 +97,11 @@ SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque);
// Using the dreaded SkGrPixelRef ...
void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap* dst);
+GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
+ const SkMatrix& viewM,
+ const SkMatrix& localM,
+ bool* doBicubic);
+
////////////////////////////////////////////////////////////////////////////////
// Classes
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp
index 5a33af55ba..9086072f98 100644
--- a/src/core/SkBitmapProcShader.cpp
+++ b/src/core/SkBitmapProcShader.cpp
@@ -349,8 +349,8 @@ void SkBitmapProcShader::toString(SkString* str) const {
#if SK_SUPPORT_GPU
#include "GrTextureAccess.h"
-#include "effects/GrSimpleTextureEffect.h"
#include "SkGr.h"
+#include "effects/GrSimpleTextureEffect.h"
bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint,
const SkMatrix& viewM,
@@ -382,41 +382,10 @@ bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint&
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
- bool useBicubic = false;
- GrTextureParams::FilterMode textureFilterMode;
- switch(paint.getFilterQuality()) {
- case kNone_SkFilterQuality:
- textureFilterMode = GrTextureParams::kNone_FilterMode;
- break;
- case kLow_SkFilterQuality:
- textureFilterMode = GrTextureParams::kBilerp_FilterMode;
- break;
- case kMedium_SkFilterQuality: {
- SkMatrix matrix;
- matrix.setConcat(viewM, this->getLocalMatrix());
- if (matrix.getMinScale() < SK_Scalar1) {
- textureFilterMode = GrTextureParams::kMipMap_FilterMode;
- } else {
- // Don't trigger MIP level generation unnecessarily.
- textureFilterMode = GrTextureParams::kBilerp_FilterMode;
- }
- break;
- }
- case kHigh_SkFilterQuality: {
- SkMatrix matrix;
- matrix.setConcat(viewM, this->getLocalMatrix());
- useBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode);
- break;
- }
- default:
- SkErrorInternals::SetError( kInvalidPaint_SkError,
- "Sorry, I don't understand the filtering "
- "mode you asked for. Falling back to "
- "MIPMaps.");
- textureFilterMode = GrTextureParams::kMipMap_FilterMode;
- break;
-
- }
+ bool doBicubic;
+ GrTextureParams::FilterMode textureFilterMode =
+ GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, this->getLocalMatrix(),
+ &doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, &params));
@@ -430,7 +399,7 @@ bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint&
SkColor2GrColor(paint.getColor()) :
SkColor2GrColorJustAlpha(paint.getColor());
- if (useBicubic) {
+ if (doBicubic) {
*fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm);
} else {
*fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index c5fccfc2e2..f8318c52d8 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1034,39 +1034,10 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
viewM.preConcat(m);
GrTextureParams params;
- SkFilterQuality paintFilterQuality = paint.getFilterQuality();
- GrTextureParams::FilterMode textureFilterMode;
-
- bool doBicubic = false;
-
- switch(paintFilterQuality) {
- case kNone_SkFilterQuality:
- textureFilterMode = GrTextureParams::kNone_FilterMode;
- break;
- case kLow_SkFilterQuality:
- textureFilterMode = GrTextureParams::kBilerp_FilterMode;
- break;
- case kMedium_SkFilterQuality:
- if (viewM.getMinScale() < SK_Scalar1) {
- textureFilterMode = GrTextureParams::kMipMap_FilterMode;
- } else {
- // Don't trigger MIP level generation unnecessarily.
- textureFilterMode = GrTextureParams::kBilerp_FilterMode;
- }
- break;
- case kHigh_SkFilterQuality:
- // Minification can look bad with the bicubic effect.
- doBicubic =
- GrBicubicEffect::ShouldUseBicubic(viewM, &textureFilterMode);
- break;
- default:
- SkErrorInternals::SetError( kInvalidPaint_SkError,
- "Sorry, I don't understand the filtering "
- "mode you asked for. Falling back to "
- "MIPMaps.");
- textureFilterMode = GrTextureParams::kMipMap_FilterMode;
- break;
- }
+ bool doBicubic;
+ GrTextureParams::FilterMode textureFilterMode =
+ GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, SkMatrix::I(),
+ &doBicubic);
int tileFilterPad;
if (doBicubic) {
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 9aa79618a2..53f640b601 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -21,6 +21,7 @@
#include "SkResourceCache.h"
#include "SkTextureCompressor.h"
#include "SkYUVPlanesCache.h"
+#include "effects/GrBicubicEffect.h"
#include "effects/GrDitherEffect.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "effects/GrYUVtoRGBEffect.h"
@@ -835,3 +836,45 @@ void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap
dst->setInfo(info);
dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref();
}
+
+GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
+ const SkMatrix& viewM,
+ const SkMatrix& localM,
+ bool* doBicubic) {
+ *doBicubic = false;
+ GrTextureParams::FilterMode textureFilterMode;
+ switch (paintFilterQuality) {
+ case kNone_SkFilterQuality:
+ textureFilterMode = GrTextureParams::kNone_FilterMode;
+ break;
+ case kLow_SkFilterQuality:
+ textureFilterMode = GrTextureParams::kBilerp_FilterMode;
+ break;
+ case kMedium_SkFilterQuality: {
+ SkMatrix matrix;
+ matrix.setConcat(viewM, localM);
+ if (matrix.getMinScale() < SK_Scalar1) {
+ textureFilterMode = GrTextureParams::kMipMap_FilterMode;
+ } else {
+ // Don't trigger MIP level generation unnecessarily.
+ textureFilterMode = GrTextureParams::kBilerp_FilterMode;
+ }
+ break;
+ }
+ case kHigh_SkFilterQuality: {
+ SkMatrix matrix;
+ matrix.setConcat(viewM, localM);
+ *doBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode);
+ break;
+ }
+ default:
+ SkErrorInternals::SetError( kInvalidPaint_SkError,
+ "Sorry, I don't understand the filtering "
+ "mode you asked for. Falling back to "
+ "MIPMaps.");
+ textureFilterMode = GrTextureParams::kMipMap_FilterMode;
+ break;
+
+ }
+ return textureFilterMode;
+}