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

Unified Diff: tests/PDFInvalidBitmapTest.cpp

Issue 802713002: Handle SkBitmaps which have no pixels in SkPDFImage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « src/pdf/SkPDFImage.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PDFInvalidBitmapTest.cpp
diff --git a/tests/PDFInvalidBitmapTest.cpp b/tests/PDFInvalidBitmapTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..2f4753e4a440f1d29abb431a1921745d9be71664
--- /dev/null
+++ b/tests/PDFInvalidBitmapTest.cpp
@@ -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.
+}
« no previous file with comments | « src/pdf/SkPDFImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698