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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
9
10 #include "SkBitmap.h"
11 #include "SkImage.h"
12
13 namespace {
14 class BitmapKey {
15 public:
16 BitmapKey() : fSubset(SkIRect::MakeEmpty()), fID(0) {}
17 explicit BitmapKey(const SkBitmap& bm)
18 : fSubset(bm.getSubset()), fID(bm.getGenerationID()) {}
19 explicit BitmapKey(const SkImage* img)
20 : fSubset(img->bounds()), fID(img->uniqueID()) {}
21 explicit BitmapKey(const sk_sp<SkImage> img)
22 : fSubset(img->bounds()), fID(img->uniqueID()) {}
23 bool operator==(const BitmapKey& rhs) const {
24 return fID == rhs.fID && fSubset == rhs.fSubset;
25 }
26 bool operator!=(const BitmapKey& rhs) const { return !(*this == rhs); }
27
28 private:
29 SkIRect fSubset;
30 uint32_t fID;
31 };
32 }
33 static SkBitmap makebitmap() {
34 SkBitmap bm;
35 bm.allocN32Pixels(32, 64);
36 bm.eraseColor(SK_ColorBLACK);
37 bm.setImmutable();
38 return bm;
39 }
40
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.
41 DEF_TEST(ImageBitmapIdentity, r) {
42 SkBitmap bm = makebitmap();
43 auto img = SkImage::MakeFromBitmap(bm);
44 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.
45 REPORTER_ASSERT(r, BitmapKey(img) == BitmapKey(bm));
46 } else {
47 ERRORF(r, "SkImage::MakeFromBitmap failed");
48 }
49 SkBitmap a, b;
50 if (!bm.extractSubset(&a, SkIRect::MakeXYWH(0, 0, 32, 32))) {
51 ERRORF(r, "SkBitmap::extractSubset failed.");
52 return;
53 }
54 REPORTER_ASSERT(r, a.dimensions() == SkISize::Make(32, 32));
55 if (!bm.extractSubset(&b, SkIRect::MakeXYWH(0, 32, 32, 32))) {
56 ERRORF(r, "SkBitmap::extractSubset failed.");
57 return;
58 }
59 REPORTER_ASSERT(r, b.dimensions() == SkISize::Make(32, 32));
60 auto imgA = SkImage::MakeFromBitmap(a);
61 if (!imgA) {
62 ERRORF(r, "SkImage::MakeFromBitmap failed.");
63 return;
64 }
65 auto imgB = SkImage::MakeFromBitmap(b);
66 if (!imgB) {
67 ERRORF(r, "SkImage::MakeFromBitmap failed.");
68 return;
69 }
70 REPORTER_ASSERT(r, imgA->uniqueID() != imgB->uniqueID());
71 REPORTER_ASSERT(r, BitmapKey(imgA) != BitmapKey(imgB));
72 REPORTER_ASSERT(r, BitmapKey(imgA) == BitmapKey(a));
73 REPORTER_ASSERT(r, BitmapKey(imgB) != BitmapKey(b));
74 REPORTER_ASSERT(r, BitmapKey(a) != BitmapKey(b));
75 }
OLDNEW
« 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