Handle SkBitmaps which have no pixels in SkPDFImage.
A test that ensures this no longer crashes has been added. BUG=skia:3232 Review URL: https://codereview.chromium.org/802713002
This commit is contained in:
parent
6005e9b86f
commit
1607156689
@ -147,6 +147,7 @@
|
||||
'../tests/NameAllocatorTest.cpp',
|
||||
'../tests/OSPathTest.cpp',
|
||||
'../tests/OnceTest.cpp',
|
||||
'../tests/PDFInvalidBitmapTest.cpp',
|
||||
'../tests/PDFJpegEmbedTest.cpp',
|
||||
'../tests/PDFPrimitivesTest.cpp',
|
||||
'../tests/PackBitsTest.cpp',
|
||||
|
@ -222,7 +222,11 @@ static SkStream* extract_image_data(const SkBitmap& bitmap,
|
||||
bool transparent = extractAlpha;
|
||||
SkStream* stream = NULL;
|
||||
|
||||
bitmap.lockPixels();
|
||||
SkAutoLockPixels lock(bitmap);
|
||||
if (NULL == bitmap.getPixels()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (colorType) {
|
||||
case kIndex_8_SkColorType:
|
||||
if (!extractAlpha) {
|
||||
@ -253,7 +257,6 @@ static SkStream* extract_image_data(const SkBitmap& bitmap,
|
||||
default:
|
||||
SkASSERT(false);
|
||||
}
|
||||
bitmap.unlockPixels();
|
||||
|
||||
if (isTransparent != NULL) {
|
||||
*isTransparent = transparent;
|
||||
|
60
tests/PDFInvalidBitmapTest.cpp
Normal file
60
tests/PDFInvalidBitmapTest.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDocument.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels
|
||||
// cannot be generated.
|
||||
class InvalidPixelRef : public SkPixelRef {
|
||||
public:
|
||||
InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) {}
|
||||
private:
|
||||
virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE { return false; }
|
||||
virtual void onUnlockPixels() SK_OVERRIDE {
|
||||
SkDEBUGFAIL("InvalidPixelRef can't be locked");
|
||||
}
|
||||
};
|
||||
|
||||
SkBitmap make_invalid_bitmap(const SkImageInfo& imageInfo) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.setInfo(imageInfo);
|
||||
bitmap.setPixelRef(SkNEW_ARGS(InvalidPixelRef, (imageInfo)))->unref();
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
SkBitmap make_invalid_bitmap(SkColorType colorType) {
|
||||
return make_invalid_bitmap(
|
||||
SkImageInfo::Make(100, 100, colorType, kPremul_SkAlphaType));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEF_TEST(PDFInvalidBitmap, reporter) {
|
||||
SkDynamicMemoryWStream stream;
|
||||
SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&stream));
|
||||
SkCanvas* canvas = document->beginPage(100, 100);
|
||||
|
||||
canvas->drawBitmap(SkBitmap(), 0, 0);
|
||||
canvas->drawBitmap(make_invalid_bitmap(SkImageInfo()), 0, 0);
|
||||
canvas->drawBitmap(make_invalid_bitmap(kN32_SkColorType), 0, 0);
|
||||
canvas->drawBitmap(make_invalid_bitmap(kIndex_8_SkColorType), 0, 0);
|
||||
canvas->drawBitmap(make_invalid_bitmap(kARGB_4444_SkColorType), 0, 0);
|
||||
canvas->drawBitmap(make_invalid_bitmap(kRGB_565_SkColorType), 0, 0);
|
||||
canvas->drawBitmap(make_invalid_bitmap(kAlpha_8_SkColorType), 0, 0);
|
||||
|
||||
// This test passes if it does not crash.
|
||||
}
|
Loading…
Reference in New Issue
Block a user