aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreed <reed@google.com>2015-08-19 11:46:38 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-19 11:46:38 -0700
commitf5822825ec2d5dd24ab476fdd42db2a6573f9756 (patch)
tree82ceed34d38dc683e63a2cf9c6f75808eaba46ec
parent790d74f7c1db73e2938eee6a6eb78bc29be7b851 (diff)
downloadplatform_external_skqp-f5822825ec2d5dd24ab476fdd42db2a6573f9756.tar.gz
platform_external_skqp-f5822825ec2d5dd24ab476fdd42db2a6573f9756.tar.bz2
platform_external_skqp-f5822825ec2d5dd24ab476fdd42db2a6573f9756.zip
change asABitmap to isABitmap on shader
BUG=skia: TBR= Review URL: https://codereview.chromium.org/1287263005
-rw-r--r--gyp/skia_for_android_framework_defines.gypi1
-rw-r--r--include/core/SkShader.h37
-rw-r--r--src/core/SkColorShader.h5
-rw-r--r--src/core/SkPictureCommon.h3
-rw-r--r--src/core/SkPictureShader.cpp14
-rw-r--r--src/core/SkShader.cpp6
-rw-r--r--src/device/xps/SkXPSDevice.cpp39
-rw-r--r--src/effects/gradients/SkLinearGradient.cpp16
-rw-r--r--src/effects/gradients/SkLinearGradient.h1
-rw-r--r--src/effects/gradients/SkRadialGradient.cpp17
-rw-r--r--src/effects/gradients/SkRadialGradient.h1
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp15
-rw-r--r--src/effects/gradients/SkSweepGradient.h2
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient.cpp29
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient.h1
-rw-r--r--src/pdf/SkPDFShader.cpp8
-rw-r--r--src/utils/SkLua.cpp23
-rw-r--r--src/utils/android/SkAndroidSDKCanvas.cpp2
-rw-r--r--tests/PictureTest.cpp3
19 files changed, 53 insertions, 170 deletions
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi
index 166bd785a3..92452117e9 100644
--- a/gyp/skia_for_android_framework_defines.gypi
+++ b/gyp/skia_for_android_framework_defines.gypi
@@ -17,6 +17,7 @@
# Needed until we fix skbug.com/2440.
'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
'SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS',
+ 'SK_SUPPORT_LEGACY_SHADERBITMAPTYPE',
],
},
}
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index fae3ba35b5..47fdc9492f 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -223,6 +223,11 @@ public:
return (flags & kHasSpan16_Flag) != 0;
}
+#ifdef SK_SUPPORT_LEGACY_SHADERBITMAPTYPE
+public:
+#else
+protected:
+#endif
/**
Gives method bitmap should be read to implement a shader.
Also determines number and interpretation of "extra" parameters returned
@@ -231,30 +236,6 @@ public:
enum BitmapType {
kNone_BitmapType, //<! Shader is not represented as a bitmap
kDefault_BitmapType,//<! Access bitmap using local coords transformed
- // by matrix. No extras
- kRadial_BitmapType, //<! Access bitmap by transforming local coordinates
- // by the matrix and taking the distance of result
- // from (0,0) as bitmap column. Bitmap is 1 pixel
- // tall. No extras
- kSweep_BitmapType, //<! Access bitmap by transforming local coordinates
- // by the matrix and taking the angle of result
- // to (0,0) as bitmap x coord, where angle = 0 is
- // bitmap left edge of bitmap = 2pi is the
- // right edge. Bitmap is 1 pixel tall. No extras
- kTwoPointConical_BitmapType,
- //<! Matrix transforms to space where (0,0) is
- // the center of the starting circle. The second
- // circle will be centered (x, 0) where x may be
- // 0.
- // Three extra parameters are returned:
- // 0: x-offset of second circle center
- // to first.
- // 1: radius of first circle
- // 2: the second radius minus the first radius
- kLinear_BitmapType, //<! Access bitmap using local coords transformed
- // by matrix. No extras
-
- kLast_BitmapType = kLinear_BitmapType
};
/** Optional methods for shaders that can pretend to be a bitmap/texture
to play along with opengl. Default just returns kNone_BitmapType and
@@ -274,6 +255,14 @@ public:
virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
TileMode xy[2]) const;
+public:
+ bool isABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode xy[2]) const {
+ return this->asABitmap(bitmap, matrix, xy) == kDefault_BitmapType;
+ }
+ bool isABitmap() const {
+ return this->isABitmap(nullptr, nullptr, nullptr);
+ }
+
/**
* If the shader subclass can be represented as a gradient, asAGradient
* returns the matching GradientType enum (or kNone_GradientType if it
diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h
index ee196c09ff..6702ef6085 100644
--- a/src/core/SkColorShader.h
+++ b/src/core/SkColorShader.h
@@ -47,11 +47,6 @@ public:
typedef SkShader::Context INHERITED;
};
- // we return false for this, use asAGradient
- virtual BitmapType asABitmap(SkBitmap* outTexture,
- SkMatrix* outMatrix,
- TileMode xy[2]) const override;
-
GradientType asAGradient(GradientInfo* info) const override;
bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
diff --git a/src/core/SkPictureCommon.h b/src/core/SkPictureCommon.h
index 827bf117de..3d64888641 100644
--- a/src/core/SkPictureCommon.h
+++ b/src/core/SkPictureCommon.h
@@ -59,8 +59,7 @@ struct SkBitmapHunter {
const SkPaint* paint = AsPtr(r.paint);
if (paint) {
const SkShader* shader = paint->getShader();
- if (shader &&
- shader->asABitmap(nullptr, nullptr, nullptr) == SkShader::kDefault_BitmapType) {
+ if (shader && shader->isABitmap()) {
return true;
}
}
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index e04e248756..f8c2ab09f8 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -83,12 +83,14 @@ struct BitmapShaderRec : public SkResourceCache::Rec {
result->reset(SkRef(rec.fShader.get()));
SkBitmap tile;
- rec.fShader.get()->asABitmap(&tile, NULL, NULL);
- // FIXME: this doesn't protect the pixels from being discarded as soon as we unlock.
- // Should be handled via a pixel ref generator instead
- // (https://code.google.com/p/skia/issues/detail?id=3220).
- SkAutoLockPixels alp(tile, true);
- return tile.getPixels() != NULL;
+ if (rec.fShader.get()->isABitmap(&tile, NULL, NULL)) {
+ // FIXME: this doesn't protect the pixels from being discarded as soon as we unlock.
+ // Should be handled via a pixel ref generator instead
+ // (https://code.google.com/p/skia/issues/detail?id=3220).
+ SkAutoLockPixels alp(tile, true);
+ return tile.getPixels() != NULL;
+ }
+ return false;
}
};
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index e5c879eecb..41724d9048 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -325,12 +325,6 @@ void SkColorShader::ColorShaderContext::shadeSpanAlpha(int x, int y, uint8_t alp
memset(alpha, SkGetPackedA32(fPMColor), count);
}
-// if we had a asAColor method, that would be more efficient...
-SkShader::BitmapType SkColorShader::asABitmap(SkBitmap* bitmap, SkMatrix* matrix,
- TileMode modes[]) const {
- return kNone_BitmapType;
-}
-
SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const {
if (info) {
if (info->fColors && info->fColorCount >= 1) {
diff --git a/src/device/xps/SkXPSDevice.cpp b/src/device/xps/SkXPSDevice.cpp
index 56800d1540..2b15cd9f4a 100644
--- a/src/device/xps/SkXPSDevice.cpp
+++ b/src/device/xps/SkXPSDevice.cpp
@@ -1071,33 +1071,24 @@ HRESULT SkXPSDevice::createXpsBrush(const SkPaint& skPaint,
SkBitmap outTexture;
SkMatrix outMatrix;
SkShader::TileMode xy[2];
- SkShader::BitmapType bitmapType = shader->asABitmap(&outTexture,
- &outMatrix,
- xy);
- switch (bitmapType) {
- case SkShader::kDefault_BitmapType: {
- //TODO: outMatrix??
- SkMatrix localMatrix = shader->getLocalMatrix();
- if (parentTransform) {
- localMatrix.preConcat(*parentTransform);
- }
-
- SkTScopedComPtr<IXpsOMTileBrush> tileBrush;
- HR(this->createXpsImageBrush(outTexture,
- localMatrix,
- xy,
- skPaint.getAlpha(),
- &tileBrush));
+ if (shader->isABitmap(&outTexture, &outMatrix, xy)) {
+ //TODO: outMatrix??
+ SkMatrix localMatrix = shader->getLocalMatrix();
+ if (parentTransform) {
+ localMatrix.preConcat(*parentTransform);
+ }
- HRM(tileBrush->QueryInterface<IXpsOMBrush>(brush), "QI failed.");
+ SkTScopedComPtr<IXpsOMTileBrush> tileBrush;
+ HR(this->createXpsImageBrush(outTexture,
+ localMatrix,
+ xy,
+ skPaint.getAlpha(),
+ &tileBrush));
- return S_OK;
- }
- default:
- break;
+ HRM(tileBrush->QueryInterface<IXpsOMBrush>(brush), "QI failed.");
+ } else {
+ HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush));
}
-
- HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush));
return S_OK;
}
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index fb0aa9836a..d9b4a5c9b0 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -261,22 +261,6 @@ void SkLinearGradient::LinearGradientContext::shadeSpan(int x, int y, SkPMColor*
}
}
-SkShader::BitmapType SkLinearGradient::asABitmap(SkBitmap* bitmap,
- SkMatrix* matrix,
- TileMode xy[]) const {
- if (bitmap) {
- this->getGradientTableBitmap(bitmap);
- }
- if (matrix) {
- matrix->preConcat(fPtsToUnit);
- }
- if (xy) {
- xy[0] = fTileMode;
- xy[1] = kClamp_TileMode;
- }
- return kLinear_BitmapType;
-}
-
SkShader::GradientType SkLinearGradient::asAGradient(GradientInfo* info) const {
if (info) {
commonAsAGradient(info);
diff --git a/src/effects/gradients/SkLinearGradient.h b/src/effects/gradients/SkLinearGradient.h
index 2330f5be06..eddb35512f 100644
--- a/src/effects/gradients/SkLinearGradient.h
+++ b/src/effects/gradients/SkLinearGradient.h
@@ -28,7 +28,6 @@ public:
typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
};
- BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const override;
GradientType asAGradient(GradientInfo* info) const override;
bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
const SkMatrix*, GrColor*, GrProcessorDataManager*,
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 4ff635ab47..a6a00cdf7b 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -225,23 +225,6 @@ void SkRadialGradient::RadialGradientContext::shadeSpan16(int x, int y, uint16_t
}
}
-SkShader::BitmapType SkRadialGradient::asABitmap(SkBitmap* bitmap,
- SkMatrix* matrix, SkShader::TileMode* xy) const {
- if (bitmap) {
- this->getGradientTableBitmap(bitmap);
- }
- if (matrix) {
- matrix->setScale(SkIntToScalar(kCache32Count),
- SkIntToScalar(kCache32Count));
- matrix->preConcat(fPtsToUnit);
- }
- if (xy) {
- xy[0] = fTileMode;
- xy[1] = kClamp_TileMode;
- }
- return kRadial_BitmapType;
-}
-
SkShader::GradientType SkRadialGradient::asAGradient(GradientInfo* info) const {
if (info) {
commonAsAGradient(info);
diff --git a/src/effects/gradients/SkRadialGradient.h b/src/effects/gradients/SkRadialGradient.h
index 0e3a893eae..d0f63ac54d 100644
--- a/src/effects/gradients/SkRadialGradient.h
+++ b/src/effects/gradients/SkRadialGradient.h
@@ -28,7 +28,6 @@ public:
typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
};
- BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* xy) const override;
GradientType asAGradient(GradientInfo* info) const override;
bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
const SkMatrix*, GrColor*, GrProcessorDataManager*,
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 1881690494..22bf68eaea 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -22,21 +22,6 @@ SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor& des
fTileMode = SkShader::kClamp_TileMode;
}
-SkShader::BitmapType SkSweepGradient::asABitmap(SkBitmap* bitmap,
- SkMatrix* matrix, SkShader::TileMode* xy) const {
- if (bitmap) {
- this->getGradientTableBitmap(bitmap);
- }
- if (matrix) {
- *matrix = fPtsToUnit;
- }
- if (xy) {
- xy[0] = fTileMode;
- xy[1] = kClamp_TileMode;
- }
- return kSweep_BitmapType;
-}
-
SkShader::GradientType SkSweepGradient::asAGradient(GradientInfo* info) const {
if (info) {
commonAsAGradient(info);
diff --git a/src/effects/gradients/SkSweepGradient.h b/src/effects/gradients/SkSweepGradient.h
index e9d5fb781f..bc465bdc44 100644
--- a/src/effects/gradients/SkSweepGradient.h
+++ b/src/effects/gradients/SkSweepGradient.h
@@ -28,8 +28,6 @@ public:
typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
};
- BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* xy) const override;
-
GradientType asAGradient(GradientInfo* info) const override;
bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 56b9458605..1cdb19e1b9 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -292,35 +292,6 @@ void SkTwoPointConicalGradient::TwoPointConicalGradientContext::shadeSpan(
}
}
-SkShader::BitmapType SkTwoPointConicalGradient::asABitmap(
- SkBitmap* bitmap, SkMatrix* matrix, SkShader::TileMode* xy) const {
- SkPoint diff = fCenter2 - fCenter1;
- SkScalar diffLen = 0;
-
- if (bitmap) {
- this->getGradientTableBitmap(bitmap);
- }
- if (matrix) {
- diffLen = diff.length();
- }
- if (matrix) {
- if (diffLen) {
- SkScalar invDiffLen = SkScalarInvert(diffLen);
- // rotate to align circle centers with the x-axis
- matrix->setSinCos(-SkScalarMul(invDiffLen, diff.fY),
- SkScalarMul(invDiffLen, diff.fX));
- } else {
- matrix->reset();
- }
- matrix->preTranslate(-fCenter1.fX, -fCenter1.fY);
- }
- if (xy) {
- xy[0] = fTileMode;
- xy[1] = kClamp_TileMode;
- }
- return kTwoPointConical_BitmapType;
-}
-
// Returns the original non-sorted version of the gradient
SkShader::GradientType SkTwoPointConicalGradient::asAGradient(
GradientInfo* info) const {
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h
index 010857c55e..8bba9e1b7f 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.h
+++ b/src/effects/gradients/SkTwoPointConicalGradient.h
@@ -58,7 +58,6 @@ public:
typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
};
- BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* xy) const override;
SkShader::GradientType asAGradient(GradientInfo* info) const override;
bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, const SkMatrix*,
GrColor*, GrProcessorDataManager*,
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index c627c14257..e518bcf89c 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -1110,10 +1110,10 @@ SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransfor
fType = shader.asAGradient(&fInfo);
if (fType == SkShader::kNone_GradientType) {
- SkShader::BitmapType bitmapType;
SkMatrix matrix;
- bitmapType = shader.asABitmap(&fImage, &matrix, fImageTileModes);
- if (bitmapType != SkShader::kDefault_BitmapType) {
+ if (shader.isABitmap(&fImage, &matrix, fImageTileModes)) {
+ SkASSERT(matrix.isIdentity());
+ } else {
// Generic fallback for unsupported shaders:
// * allocate a bbox-sized bitmap
// * shade the whole area
@@ -1153,8 +1153,6 @@ SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransfor
fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y());
fShaderTransform.preScale(1 / scale.width(), 1 / scale.height());
- } else {
- SkASSERT(matrix.isIdentity());
}
fPixelGeneration = fImage.getGenerationID();
} else {
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 7c378c9b81..e5d4c2b3a4 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -1200,23 +1200,20 @@ static int lshader_isOpaque(lua_State* L) {
return shader && shader->isOpaque();
}
-static int lshader_asABitmap(lua_State* L) {
+static int lshader_isABitmap(lua_State* L) {
SkShader* shader = get_ref<SkShader>(L, 1);
if (shader) {
SkBitmap bm;
SkMatrix matrix;
SkShader::TileMode modes[2];
- switch (shader->asABitmap(&bm, &matrix, modes)) {
- case SkShader::kDefault_BitmapType:
- lua_newtable(L);
- setfield_number(L, "genID", bm.pixelRef() ? bm.pixelRef()->getGenerationID() : 0);
- setfield_number(L, "width", bm.width());
- setfield_number(L, "height", bm.height());
- setfield_string(L, "tileX", mode2string(modes[0]));
- setfield_string(L, "tileY", mode2string(modes[1]));
- return 1;
- default:
- break;
+ if (shader->isABitmap(&bm, &matrix, modes)) {
+ lua_newtable(L);
+ setfield_number(L, "genID", bm.pixelRef() ? bm.pixelRef()->getGenerationID() : 0);
+ setfield_number(L, "width", bm.width());
+ setfield_number(L, "height", bm.height());
+ setfield_string(L, "tileX", mode2string(modes[0]));
+ setfield_string(L, "tileY", mode2string(modes[1]));
+ return 1;
}
}
return 0;
@@ -1260,7 +1257,7 @@ static int lshader_gc(lua_State* L) {
static const struct luaL_Reg gSkShader_Methods[] = {
{ "isOpaque", lshader_isOpaque },
- { "asABitmap", lshader_asABitmap },
+ { "isABitmap", lshader_isABitmap },
{ "asAGradient", lshader_asAGradient },
{ "__gc", lshader_gc },
{ NULL, NULL }
diff --git a/src/utils/android/SkAndroidSDKCanvas.cpp b/src/utils/android/SkAndroidSDKCanvas.cpp
index b05605bbf9..2eec95f66c 100644
--- a/src/utils/android/SkAndroidSDKCanvas.cpp
+++ b/src/utils/android/SkAndroidSDKCanvas.cpp
@@ -23,7 +23,7 @@ void CheckShader(SkPaint* paint) {
return;
}
- if (shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType) {
+ if (shader->isABitmap()) {
return;
}
if (shader->asACompose(NULL)) {
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 17a8f31585..2afb0dd73d 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -71,8 +71,7 @@ static void test_analysis(skiatest::Reporter* reporter) {
SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode);
paint.setShader(shader)->unref();
- REPORTER_ASSERT(reporter,
- shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType);
+ REPORTER_ASSERT(reporter, shader->isABitmap());
canvas->drawRect(SkRect::MakeWH(10, 10), paint);
}