More non-invertible shader local matrix guards

Change-Id: Ida9a300420ff1d883e617cdaadb80e88c99ad226
Reviewed-on: https://skia-review.googlesource.com/8333
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2017-02-10 15:34:27 -05:00 committed by Skia Commit-Bot
parent 1fe55dc9fa
commit 368af4605d
4 changed files with 14 additions and 12 deletions

View File

@ -39,7 +39,6 @@ class GrFragmentProcessor;
*/
class SK_API SkShader : public SkFlattenable {
public:
SkShader(const SkMatrix* localMatrix = NULL);
virtual ~SkShader();
/**
@ -467,6 +466,8 @@ public:
const SkMatrix& ctm, const SkPaint&) const;
protected:
SkShader(const SkMatrix* localMatrix = nullptr);
void flatten(SkWriteBuffer&) const override;
bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const;
@ -498,9 +499,7 @@ protected:
const SkMatrix* /*local matrix*/) const;
private:
// This is essentially const, but not officially so it can be modified in
// constructors.
SkMatrix fLocalMatrix;
const SkMatrix fLocalMatrix;
// So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer constructor.
friend class SkLocalMatrixShader;

View File

@ -106,7 +106,10 @@ SkPictureShader::SkPictureShader(sk_sp<SkPicture> picture, TileMode tmx, TileMod
sk_sp<SkShader> SkPictureShader::Make(sk_sp<SkPicture> picture, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile) {
if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) {
if (!picture ||
picture->cullRect().isEmpty() ||
(tile && tile->isEmpty()) ||
(localMatrix && !localMatrix->invert(nullptr))) {
return SkShader::MakeEmptyShader();
}
return sk_sp<SkShader>(new SkPictureShader(std::move(picture), tmx, tmy, localMatrix, tile));

View File

@ -45,13 +45,11 @@ static inline void dec_shader_counter() {
#endif
}
SkShader::SkShader(const SkMatrix* localMatrix) {
SkShader::SkShader(const SkMatrix* localMatrix)
: fLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I()) {
SkASSERT(!localMatrix || localMatrix->invert(nullptr));
inc_shader_counter();
if (localMatrix) {
fLocalMatrix = *localMatrix;
} else {
fLocalMatrix.reset();
}
// Pre-cache so future calls to fLocalMatrix.getType() are threadsafe.
(void)fLocalMatrix.getType();
}

View File

@ -100,7 +100,9 @@ sk_sp<SkShader> SkImageShader::Make(sk_sp<SkImage> image, TileMode tx, TileMode
const SkMatrix* localMatrix,
SkTBlitterAllocator* allocator) {
SkShader* shader;
if (!image || bitmap_is_too_big(image->width(), image->height())) {
if (!image ||
bitmap_is_too_big(image->width(), image->height()) ||
(localMatrix && !localMatrix->invert(nullptr))) {
if (nullptr == allocator) {
shader = new SkEmptyShader;
} else {