Index: src/core/SkPictureShader.cpp |
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp |
index 1e9507190c60a4ac4e8b16785c9dc06948f13e55..76aa857e229297b04d1fa36e5382e701cb791423 100644 |
--- a/src/core/SkPictureShader.cpp |
+++ b/src/core/SkPictureShader.cpp |
@@ -19,11 +19,9 @@ |
#endif |
SkPictureShader::SkPictureShader(SkPicture* picture, TileMode tmx, TileMode tmy) |
- : fPicture(picture) |
+ : fPicture(SkRef(picture)) |
, fTmx(tmx) |
- , fTmy(tmy) { |
- SkSafeRef(fPicture); |
-} |
+ , fTmy(tmy) { } |
SkPictureShader::SkPictureShader(SkReadBuffer& buffer) |
: INHERITED(buffer) { |
@@ -32,15 +30,22 @@ SkPictureShader::SkPictureShader(SkReadBuffer& buffer) |
if (buffer.readBool()) { |
fPicture = SkPicture::CreateFromBuffer(buffer); |
} else { |
- fPicture = NULL; |
+ // For backwards compatibility, create a dummy picture. Older versions allowed |
scroggo
2014/04/15 19:15:49
This code is only for handling already existing SK
f(malita)
2014/04/15 19:40:40
Yes, should be safe to remove.
scroggo
2014/04/15 20:33:20
Done.
|
+ // creating an SkPictureShader with a NULL SkPicture. |
+ SkPictureRecorder factory; |
+ factory.beginRecording(0, 0); |
+ fPicture = factory.endRecording(); |
} |
} |
SkPictureShader::~SkPictureShader() { |
- SkSafeUnref(fPicture); |
+ fPicture->unref(); |
} |
SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileMode tmy) { |
+ if (!picture || 0 == picture->width() || 0 == picture->height()) { |
+ return NULL; |
+ } |
return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy)); |
} |
@@ -56,9 +61,13 @@ void SkPictureShader::flatten(SkWriteBuffer& buffer) const { |
} |
SkShader* SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const { |
- if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) { |
- return NULL; |
- } |
+ // FIXME: Older versions of this class allowed a picture with 0 width or |
+ // height, but would bail out here. Allow a 0 width/height to support |
+ // reading an SkPictureShader from an SKP. Note that we will still return |
+ // NULL in that case due to an empty tileSize. If/when we can disregard |
+ // old SKPs, it is safe to assert the picture's width and height are |
+ // greater than zero. |
f(malita)
2014/04/15 19:40:40
It's safe to disregard old SKPs - the shader is no
scroggo
2014/04/15 20:33:20
Done.
|
+ SkASSERT(fPicture); // && fPicture->width() > 0 && fPicture->height() > 0); |
SkMatrix m; |
if (this->hasLocalMatrix()) { |