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

Unified Diff: tests/image-bitmap.cpp

Issue 1813793002: images with offset bitmap don't share genid (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-17 (Thursday) 12:13:54 EDT Created 4 years, 9 months 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/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/image-bitmap.cpp
diff --git a/tests/image-bitmap.cpp b/tests/image-bitmap.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fee5f0d7a6de92203fb7862059b42a2b1bf90613
--- /dev/null
+++ b/tests/image-bitmap.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+
+#include "SkBitmap.h"
+#include "SkImage.h"
+
+namespace {
+class BitmapKey {
+public:
+ BitmapKey() : fSubset(SkIRect::MakeEmpty()), fID(0) {}
+ explicit BitmapKey(const SkBitmap& bm)
+ : fSubset(bm.getSubset()), fID(bm.getGenerationID()) {}
+ explicit BitmapKey(const SkImage* img)
+ : fSubset(img->bounds()), fID(img->uniqueID()) {}
+ explicit BitmapKey(const sk_sp<SkImage> img)
+ : fSubset(img->bounds()), fID(img->uniqueID()) {}
+ bool operator==(const BitmapKey& rhs) const {
+ return fID == rhs.fID && fSubset == rhs.fSubset;
+ }
+ bool operator!=(const BitmapKey& rhs) const { return !(*this == rhs); }
+
+private:
+ SkIRect fSubset;
+ uint32_t fID;
+};
+}
+static SkBitmap makebitmap() {
+ SkBitmap bm;
+ bm.allocN32Pixels(32, 64);
+ bm.eraseColor(SK_ColorBLACK);
+ bm.setImmutable();
+ return bm;
+}
+
reed1 2016/03/17 17:34:15 // Test that when we make an image from a subset o
hal.canary 2016/03/17 17:57:02 Done.
+DEF_TEST(ImageBitmapIdentity, r) {
+ SkBitmap bm = makebitmap();
+ auto img = SkImage::MakeFromBitmap(bm);
+ if (img) {
reed1 2016/03/17 17:34:15 Not sure these runtime checks are needed, unless i
hal.canary 2016/03/17 17:57:02 Done.
+ REPORTER_ASSERT(r, BitmapKey(img) == BitmapKey(bm));
+ } else {
+ ERRORF(r, "SkImage::MakeFromBitmap failed");
+ }
+ SkBitmap a, b;
+ if (!bm.extractSubset(&a, SkIRect::MakeXYWH(0, 0, 32, 32))) {
+ ERRORF(r, "SkBitmap::extractSubset failed.");
+ return;
+ }
+ REPORTER_ASSERT(r, a.dimensions() == SkISize::Make(32, 32));
+ if (!bm.extractSubset(&b, SkIRect::MakeXYWH(0, 32, 32, 32))) {
+ ERRORF(r, "SkBitmap::extractSubset failed.");
+ return;
+ }
+ REPORTER_ASSERT(r, b.dimensions() == SkISize::Make(32, 32));
+ auto imgA = SkImage::MakeFromBitmap(a);
+ if (!imgA) {
+ ERRORF(r, "SkImage::MakeFromBitmap failed.");
+ return;
+ }
+ auto imgB = SkImage::MakeFromBitmap(b);
+ if (!imgB) {
+ ERRORF(r, "SkImage::MakeFromBitmap failed.");
+ return;
+ }
+ REPORTER_ASSERT(r, imgA->uniqueID() != imgB->uniqueID());
+ REPORTER_ASSERT(r, BitmapKey(imgA) != BitmapKey(imgB));
+ REPORTER_ASSERT(r, BitmapKey(imgA) == BitmapKey(a));
+ REPORTER_ASSERT(r, BitmapKey(imgB) != BitmapKey(b));
+ REPORTER_ASSERT(r, BitmapKey(a) != BitmapKey(b));
+}
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698