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

Unified Diff: src/core/SkPictureShader.cpp

Issue 238253005: Fixes for SkPictureShader. (Closed) Base URL: https://skia.googlesource.com/skia.git@shaders
Patch Set: Created 6 years, 8 months 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
« include/core/SkShader.h ('K') | « include/core/SkShader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()) {
« include/core/SkShader.h ('K') | « include/core/SkShader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698