Use SkError for a bitmap that could not be decoded.
When recreating an SkPicture from an SkStream, use the new error reporting system to report that an SkBitmap could not be decoded. Add a test that the parse error is thrown. Review URL: https://codereview.chromium.org/13892009 git-svn-id: http://skia.googlecode.com/svn/trunk@8866 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
bb6b5baa96
commit
49ce11ba14
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user