OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDeviceLooper.h" | 8 #include "SkDeviceLooper.h" |
9 #include "SkRasterClip.h" | 9 #include "SkRasterClip.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 static void make_bm(SkBitmap* bm, int w, int h) { | 12 static void make_pm(SkAutoPixmapStorage* pixmap, int w, int h) { |
13 bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, | 13 pixmap->alloc(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype)); |
14 kPremul_SkAlphaType)); | |
15 } | 14 } |
16 | 15 |
17 static bool equal(const SkRasterClip& a, const SkRasterClip& b) { | 16 static bool equal(const SkRasterClip& a, const SkRasterClip& b) { |
18 if (a.isBW()) { | 17 if (a.isBW()) { |
19 return b.isBW() && a.bwRgn() == b.bwRgn(); | 18 return b.isBW() && a.bwRgn() == b.bwRgn(); |
20 } else { | 19 } else { |
21 return a.isAA() && a.aaRgn() == b.aaRgn(); | 20 return a.isAA() && a.aaRgn() == b.aaRgn(); |
22 } | 21 } |
23 } | 22 } |
24 | 23 |
25 static const struct { | 24 static const struct { |
26 SkISize fDevSize; | 25 SkISize fDevSize; |
27 SkIRect fRCBounds; | 26 SkIRect fRCBounds; |
28 SkIRect fRect; | 27 SkIRect fRect; |
29 } gRec[] = { | 28 } gRec[] = { |
30 { { 4000, 10 }, { 0, 0, 4000, 10 }, { 0, 0, 4000, 4000 } }, | 29 { { 4000, 10 }, { 0, 0, 4000, 10 }, { 0, 0, 4000, 4000 } }, |
31 { { 10, 4000 }, { 0, 0, 10, 4000 }, { 0, 0, 4000, 4000 } }, | 30 { { 10, 4000 }, { 0, 0, 10, 4000 }, { 0, 0, 4000, 4000 } }, |
32 // very large devce, small rect | 31 // very large devce, small rect |
33 { { 32000, 10 }, { 0, 0, 32000, 10 }, { 0, 0, 4000, 4000 } }, | 32 { { 32000, 10 }, { 0, 0, 32000, 10 }, { 0, 0, 4000, 4000 } }, |
34 { { 10, 32000 }, { 0, 0, 10, 32000 }, { 0, 0, 4000, 4000 } }, | 33 { { 10, 32000 }, { 0, 0, 10, 32000 }, { 0, 0, 4000, 4000 } }, |
35 // very large device, small clip | 34 // very large device, small clip |
36 { { 32000, 10 }, { 0, 0, 4000, 10 }, { 0, 0, 32000, 32000 } }, | 35 { { 32000, 10 }, { 0, 0, 4000, 10 }, { 0, 0, 32000, 32000 } }, |
37 { { 10, 32000 }, { 0, 0, 10, 4000 }, { 0, 0, 32000, 32000 } }, | 36 { { 10, 32000 }, { 0, 0, 10, 4000 }, { 0, 0, 32000, 32000 } }, |
38 }; | 37 }; |
39 | 38 |
40 static void test_simple(skiatest::Reporter* reporter) { | 39 static void test_simple(skiatest::Reporter* reporter) { |
41 | 40 |
42 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 41 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
43 SkBitmap bitmap; | 42 SkAutoPixmapStorage pmap; |
44 make_bm(&bitmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); | 43 make_pm(&pmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); |
45 | 44 |
46 SkRasterClip rc(gRec[i].fRCBounds); | 45 SkRasterClip rc(gRec[i].fRCBounds); |
47 | 46 |
48 for (int aa = 0; aa <= 1; ++aa) { | 47 for (int aa = 0; aa <= 1; ++aa) { |
49 SkDeviceLooper looper(bitmap, rc, gRec[i].fRect, SkToBool(aa)); | 48 SkDeviceLooper looper(pmap, rc, gRec[i].fRect, SkToBool(aa)); |
50 | 49 |
51 bool valid = looper.next(); | 50 bool valid = looper.next(); |
52 REPORTER_ASSERT(reporter, valid); | 51 REPORTER_ASSERT(reporter, valid); |
53 if (valid) { | 52 if (valid) { |
54 REPORTER_ASSERT(reporter, looper.getBitmap().width() == bitmap.w
idth()); | 53 REPORTER_ASSERT(reporter, looper.getPixmap().width() == pmap.wid
th()); |
55 REPORTER_ASSERT(reporter, looper.getBitmap().height() == bitmap.
height()); | 54 REPORTER_ASSERT(reporter, looper.getPixmap().height() == pmap.he
ight()); |
56 REPORTER_ASSERT(reporter, equal(looper.getRC(), rc)); | 55 REPORTER_ASSERT(reporter, equal(looper.getRC(), rc)); |
57 | 56 |
58 REPORTER_ASSERT(reporter, !looper.next()); | 57 REPORTER_ASSERT(reporter, !looper.next()); |
59 } | 58 } |
60 } | 59 } |
61 // test that a rect that doesn't intersect returns no loops | 60 // test that a rect that doesn't intersect returns no loops |
62 { | 61 { |
63 SkIRect r = rc.getBounds(); | 62 SkIRect r = rc.getBounds(); |
64 r.offset(r.width(), 0); | 63 r.offset(r.width(), 0); |
65 SkDeviceLooper looper(bitmap, rc, r, false); | 64 SkDeviceLooper looper(pmap, rc, r, false); |
66 REPORTER_ASSERT(reporter, !looper.next()); | 65 REPORTER_ASSERT(reporter, !looper.next()); |
67 } | 66 } |
68 } | 67 } |
69 } | 68 } |
70 | 69 |
71 // mask-bits are interpreted as the areas where the clip is visible | 70 // mask-bits are interpreted as the areas where the clip is visible |
72 // [ 0x01 0x02 ] | 71 // [ 0x01 0x02 ] |
73 // [ 0x04 0x08 ] | 72 // [ 0x04 0x08 ] |
74 // | 73 // |
75 static void make_rgn(SkRegion* rgn, int w, int h, unsigned mask) { | 74 static void make_rgn(SkRegion* rgn, int w, int h, unsigned mask) { |
(...skipping 26 matching lines...) Expand all Loading... |
102 bool fAA; | 101 bool fAA; |
103 } const gRec[] = { | 102 } const gRec[] = { |
104 { { BW_SIZE, BW_SIZE }, false }, | 103 { { BW_SIZE, BW_SIZE }, false }, |
105 { { AA_SIZE, AA_SIZE }, true }, | 104 { { AA_SIZE, AA_SIZE }, true }, |
106 }; | 105 }; |
107 | 106 |
108 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 107 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
109 const int w = gRec[i].fSize.width(); | 108 const int w = gRec[i].fSize.width(); |
110 const int h = gRec[i].fSize.height(); | 109 const int h = gRec[i].fSize.height(); |
111 | 110 |
112 SkBitmap bitmap; | 111 SkAutoPixmapStorage pmap; |
113 make_bm(&bitmap, w, h); | 112 make_pm(&pmap, w, h); |
114 | 113 |
115 const SkIRect rect = SkIRect::MakeWH(w, h); | 114 const SkIRect rect = SkIRect::MakeWH(w, h); |
116 | 115 |
117 // mask-bits are interpreted as the areas where the clip is visible | 116 // mask-bits are interpreted as the areas where the clip is visible |
118 // [ 0x01 0x02 ] | 117 // [ 0x01 0x02 ] |
119 // [ 0x04 0x08 ] | 118 // [ 0x04 0x08 ] |
120 // | 119 // |
121 for (int mask = 0; mask <= 15; ++mask) { | 120 for (int mask = 0; mask <= 15; ++mask) { |
122 SkRegion rgn; | 121 SkRegion rgn; |
123 make_rgn(&rgn, w, h, mask); | 122 make_rgn(&rgn, w, h, mask); |
124 | 123 |
125 SkRasterClip rc; | 124 SkRasterClip rc; |
126 rc.op(rgn, SkRegion::kReplace_Op); | 125 rc.op(rgn, SkRegion::kReplace_Op); |
127 | 126 |
128 SkDeviceLooper looper(bitmap, rc, rect, gRec[i].fAA); | 127 SkDeviceLooper looper(pmap, rc, rect, gRec[i].fAA); |
129 while (looper.next()) { | 128 while (looper.next()) { |
130 REPORTER_ASSERT(reporter, !looper.getRC().isEmpty()); | 129 REPORTER_ASSERT(reporter, !looper.getRC().isEmpty()); |
131 } | 130 } |
132 } | 131 } |
133 } | 132 } |
134 } | 133 } |
135 | 134 |
136 DEF_TEST(DeviceLooper, reporter) { | 135 DEF_TEST(DeviceLooper, reporter) { |
137 test_simple(reporter); | 136 test_simple(reporter); |
138 test_complex(reporter); | 137 test_complex(reporter); |
139 } | 138 } |
OLD | NEW |