aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-04 15:08:56 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-04 15:08:56 +0000
commit4b90b1122c93e6600ea352f4ccf1dfc54c8bb146 (patch)
tree16ee994e3b2293fde0d1265eb0d57c4164db3dea /src
parentebce0301082cda9dc3e3298f6db91d46fe66298b (diff)
Handle recording a bitmap if copy fails.
If SkBitmapHeap::insert() returns INVALID_SLOT, assert at picture record time so we can debug, but allow it to continue in release mode, so that we can still capture a picture. At playback time, print a message so we know that there was an error. Review URL: https://codereview.appspot.com/6873050 git-svn-id: http://skia.googlecode.com/svn/trunk@6664 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkPicturePlayback.h10
-rw-r--r--src/core/SkPictureRecord.cpp7
2 files changed, 15 insertions, 2 deletions
diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h
index 8a7ee0af32..9e495fa6cf 100644
--- a/src/core/SkPicturePlayback.h
+++ b/src/core/SkPicturePlayback.h
@@ -93,7 +93,11 @@ private:
};
const SkBitmap& getBitmap(SkReader32& reader) {
- int index = reader.readInt();
+ const int index = reader.readInt();
+ if (SkBitmapHeap::INVALID_SLOT == index) {
+ SkDebugf("An invalid bitmap was recorded!\n");
+ return fBadBitmap;
+ }
return (*fBitmaps)[index];
}
@@ -190,6 +194,10 @@ private: // these help us with reading/writing
void flattenToBuffer(SkOrderedWriteBuffer&) const;
private:
+ // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_SLOT. This empty
+ // bitmap allows playback to draw nothing and move on.
+ SkBitmap fBadBitmap;
+
SkAutoTUnref<SkBitmapHeap> fBitmapHeap;
SkAutoTUnref<SkPathHeap> fPathHeap;
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index d6f51e357e..270eee5bd4 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -657,7 +657,12 @@ void SkPictureRecord::drawData(const void* data, size_t length) {
///////////////////////////////////////////////////////////////////////////////
void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
- addInt(fBitmapHeap->insert(bitmap));
+ const int index = fBitmapHeap->insert(bitmap);
+ // In debug builds, a bad return value from insert() will crash, allowing for debugging. In
+ // release builds, the invalid value will be recorded so that the reader will know that there
+ // was a problem.
+ SkASSERT(index != SkBitmapHeap::INVALID_SLOT);
+ addInt(index);
}
void SkPictureRecord::addMatrix(const SkMatrix& matrix) {