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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkMallocPixelRef.h" | 9 #include "SkMallocPixelRef.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 static void test_peekpixels(skiatest::Reporter* reporter) { | 12 static void test_peekpixels(skiatest::Reporter* reporter) { |
13 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 13 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
14 | 14 |
15 SkPixmap pmap; | 15 SkPixmap pmap; |
16 SkBitmap bm; | 16 SkBitmap bm; |
17 | 17 |
18 // empty should return false | 18 // empty should return false |
19 REPORTER_ASSERT(reporter, !bm.peekPixels(NULL)); | 19 REPORTER_ASSERT(reporter, !bm.peekPixels(nullptr)); |
20 REPORTER_ASSERT(reporter, !bm.peekPixels(&pmap)); | 20 REPORTER_ASSERT(reporter, !bm.peekPixels(&pmap)); |
21 | 21 |
22 // no pixels should return false | 22 // no pixels should return false |
23 bm.setInfo(SkImageInfo::MakeN32Premul(10, 10)); | 23 bm.setInfo(SkImageInfo::MakeN32Premul(10, 10)); |
24 REPORTER_ASSERT(reporter, !bm.peekPixels(NULL)); | 24 REPORTER_ASSERT(reporter, !bm.peekPixels(nullptr)); |
25 REPORTER_ASSERT(reporter, !bm.peekPixels(&pmap)); | 25 REPORTER_ASSERT(reporter, !bm.peekPixels(&pmap)); |
26 | 26 |
27 // real pixels should return true | 27 // real pixels should return true |
28 bm.allocPixels(info); | 28 bm.allocPixels(info); |
29 REPORTER_ASSERT(reporter, bm.peekPixels(NULL)); | 29 REPORTER_ASSERT(reporter, bm.peekPixels(nullptr)); |
30 REPORTER_ASSERT(reporter, bm.peekPixels(&pmap)); | 30 REPORTER_ASSERT(reporter, bm.peekPixels(&pmap)); |
31 REPORTER_ASSERT(reporter, pmap.info() == bm.info()); | 31 REPORTER_ASSERT(reporter, pmap.info() == bm.info()); |
32 REPORTER_ASSERT(reporter, pmap.addr() == bm.getPixels()); | 32 REPORTER_ASSERT(reporter, pmap.addr() == bm.getPixels()); |
33 REPORTER_ASSERT(reporter, pmap.rowBytes() == bm.rowBytes()); | 33 REPORTER_ASSERT(reporter, pmap.rowBytes() == bm.rowBytes()); |
34 REPORTER_ASSERT(reporter, pmap.ctable() == bm.getColorTable()); | 34 REPORTER_ASSERT(reporter, pmap.ctable() == bm.getColorTable()); |
35 } | 35 } |
36 | 36 |
37 // https://code.google.com/p/chromium/issues/detail?id=446164 | 37 // https://code.google.com/p/chromium/issues/detail?id=446164 |
38 static void test_bigalloc(skiatest::Reporter* reporter) { | 38 static void test_bigalloc(skiatest::Reporter* reporter) { |
39 const int width = 0x40000001; | 39 const int width = 0x40000001; |
40 const int height = 0x00000096; | 40 const int height = 0x00000096; |
41 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 41 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
42 | 42 |
43 SkBitmap bm; | 43 SkBitmap bm; |
44 REPORTER_ASSERT(reporter, !bm.tryAllocPixels(info)); | 44 REPORTER_ASSERT(reporter, !bm.tryAllocPixels(info)); |
45 | 45 |
46 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), NUL
L); | 46 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), nul
lptr); |
47 REPORTER_ASSERT(reporter, !pr); | 47 REPORTER_ASSERT(reporter, !pr); |
48 } | 48 } |
49 | 49 |
50 static void test_allocpixels(skiatest::Reporter* reporter) { | 50 static void test_allocpixels(skiatest::Reporter* reporter) { |
51 const int width = 10; | 51 const int width = 10; |
52 const int height = 10; | 52 const int height = 10; |
53 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 53 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
54 const size_t explicitRowBytes = info.minRowBytes() + 24; | 54 const size_t explicitRowBytes = info.minRowBytes() + 24; |
55 | 55 |
56 SkBitmap bm; | 56 SkBitmap bm; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); | 116 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 test_bigwidth(reporter); | 120 test_bigwidth(reporter); |
121 test_allocpixels(reporter); | 121 test_allocpixels(reporter); |
122 test_bigalloc(reporter); | 122 test_bigalloc(reporter); |
123 test_peekpixels(reporter); | 123 test_peekpixels(reporter); |
124 } | 124 } |
OLD | NEW |