aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkOrderedReadBuffer.cpp4
-rw-r--r--tests/PictureTest.cpp30
2 files changed, 33 insertions, 1 deletions
diff --git a/src/core/SkOrderedReadBuffer.cpp b/src/core/SkOrderedReadBuffer.cpp
index 2c83ce0ac5..5a4cf96a92 100644
--- a/src/core/SkOrderedReadBuffer.cpp
+++ b/src/core/SkOrderedReadBuffer.cpp
@@ -7,6 +7,7 @@
*/
#include "SkBitmap.h"
+#include "SkErrorInternals.h"
#include "SkOrderedReadBuffer.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -179,7 +180,8 @@ void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) {
} else {
// This bitmap was encoded when written, but we are unable to decode, possibly due to
// not having a decoder. Use a placeholder bitmap.
- SkDebugf("Could not decode bitmap. Resulting bitmap will be red.\n");
+ SkErrorInternals::SetError(kParseError_SkError,
+ "Could not decode bitmap. Resulting bitmap will be red.");
bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
bitmap->allocPixels();
bitmap->eraseColor(SK_ColorRED);
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 6adfd5a9be..c702e9426e 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -8,6 +8,7 @@
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkData.h"
+#include "SkError.h"
#include "SkPaint.h"
#include "SkPicture.h"
#include "SkRandom.h"
@@ -371,6 +372,22 @@ static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
return wStream.copyToData();
}
+struct ErrorContext {
+ int fErrors;
+ skiatest::Reporter* fReporter;
+};
+
+static void assert_one_parse_error_cb(SkError error, void* context) {
+ ErrorContext* errorContext = static_cast<ErrorContext*>(context);
+ errorContext->fErrors++;
+ // This test only expects one error, and that is a kParseError. If there are others,
+ // there is some unknown problem.
+ REPORTER_ASSERT_MESSAGE(errorContext->fReporter, 1 == errorContext->fErrors,
+ "This threw more errors than expected.");
+ REPORTER_ASSERT_MESSAGE(errorContext->fReporter, kParseError_SkError == error,
+ SkGetLastErrorString());
+}
+
static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) {
// Create a bitmap that will be encoded.
SkBitmap original;
@@ -395,6 +412,19 @@ static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) {
SkAutoDataUnref picture1(serialized_picture_from_bitmap(original));
SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm));
REPORTER_ASSERT(reporter, picture1->equals(picture2));
+ // Now test that a parse error was generated when trying to create a new SkPicture without
+ // providing a function to decode the bitmap.
+ ErrorContext context;
+ context.fErrors = 0;
+ context.fReporter = reporter;
+ SkSetErrorCallback(assert_one_parse_error_cb, &context);
+ SkMemoryStream pictureStream(picture1);
+ bool success;
+ SkClearLastError();
+ SkPicture pictureFromStream(&pictureStream, &success, NULL);
+ REPORTER_ASSERT(reporter, success);
+ SkClearLastError();
+ SkSetErrorCallback(NULL, NULL);
}
static void test_clone_empty(skiatest::Reporter* reporter) {