aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/DrawBitmapRectTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-15 20:05:24 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-15 20:05:24 +0000
commitcef5bb4e424344769493886b700f6013add4ad48 (patch)
treea10ff19d5249026a59e723ba636f714269cffe20 /tests/DrawBitmapRectTest.cpp
parentdb62709fc19522b39a645557e45417aa82708107 (diff)
test for failing pixelref (crashes, so disable for now)
test for a pixelref that fails to lock BUG= Review URL: https://codereview.chromium.org/26539012 git-svn-id: http://skia.googlecode.com/svn/trunk@11787 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/DrawBitmapRectTest.cpp')
-rw-r--r--tests/DrawBitmapRectTest.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index bdfa755781..68e8a97fd5 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -8,10 +8,64 @@
#include "Test.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
+#include "SkData.h"
+#include "SkPaint.h"
#include "SkShader.h"
+#include "SkSurface.h"
#include "SkRandom.h"
#include "SkMatrixUtils.h"
+#include "SkLazyPixelRef.h"
+#include "SkLruImageCache.h"
+
+// A BitmapFactory that always fails when asked to return pixels.
+static bool FailureDecoder(const void* data, size_t length, SkImage::Info* info,
+ const SkBitmapFactory::Target* target) {
+ if (info) {
+ info->fWidth = info->fHeight = 100;
+ info->fColorType = SkImage::kRGBA_8888_ColorType;
+ info->fAlphaType = kPremul_SkAlphaType;
+ }
+ // this will deliberately return false if they are asking us to decode
+ // into pixels.
+ return NULL == target;
+}
+
+// crbug.com/295895
+// Crashing in skia when a pixelref fails in lockPixels
+//
+static void test_faulty_pixelref(skiatest::Reporter* reporter) {
+ // need a cache, but don't expect to use it, so the budget is not critical
+ SkLruImageCache cache(10 * 1000);
+ // construct a garbage data represent "bad" encoded data.
+ SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000));
+ SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache));
+
+ SkBitmap bm;
+ bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
+ bm.setPixelRef(pr);
+ // now our bitmap has a pixelref, but we know it will fail to lock
+
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));
+ SkCanvas* canvas = surface->getCanvas();
+
+ const SkPaint::FilterLevel levels[] = {
+ SkPaint::kNone_FilterLevel,
+ SkPaint::kLow_FilterLevel,
+ SkPaint::kMedium_FilterLevel,
+ SkPaint::kHigh_FilterLevel,
+ };
+
+ SkPaint paint;
+ canvas->scale(2, 2); // need a scale, otherwise we may ignore filtering
+ for (size_t i = 0; i < SK_ARRAY_COUNT(levels); ++i) {
+ paint.setFilterLevel(levels[i]);
+ canvas->drawBitmap(bm, 0, 0, &paint);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
static void rand_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) {
mat->setIdentity();
if (mask & SkMatrix::kTranslate_Mask) {
@@ -268,6 +322,10 @@ static void TestDrawBitmapRect(skiatest::Reporter* reporter) {
test_giantrepeat_crbug118018(reporter);
test_treatAsSprite(reporter);
+
+ if (false) { // will enable when fix lands
+ test_faulty_pixelref(reporter);
+ }
}
#include "TestClassDef.h"