OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkSwizzler.h" | 8 #include "SkSwizzler.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 | 10 |
11 // These are the values that we will look for to indicate that the fill was succ
essful | 11 // These are the values that we will look for to indicate that the fill was succ
essful |
12 static const uint8_t kFillIndex = 0x1; | 12 static const uint8_t kFillIndex = 0x1; |
13 static const uint32_t kFillColor = 0x22334455; | 13 static const uint32_t kFillColor = 0x22334455; |
14 | 14 |
15 static void check_fill(skiatest::Reporter* r, | 15 static void check_fill(skiatest::Reporter* r, |
16 const SkImageInfo& imageInfo, | 16 const SkImageInfo& imageInfo, |
17 uint32_t startRow, | 17 uint32_t startRow, |
| 18 uint32_t endRow, |
18 size_t rowBytes, | 19 size_t rowBytes, |
19 uint32_t offset, | 20 uint32_t offset, |
20 uint32_t colorOrIndex, | 21 uint32_t colorOrIndex, |
21 SkPMColor* colorTable) { | 22 SkPMColor* colorTable) { |
22 | 23 |
23 // Calculate the total size of the image in bytes. Use the smallest possibl
e size. | 24 // Calculate the total size of the image in bytes. Use the smallest possibl
e size. |
24 // The offset value tells us to adjust the pointer from the memory we alloca
te in order | 25 // The offset value tells us to adjust the pointer from the memory we alloca
te in order |
25 // to test on different memory alignments. If offset is nonzero, we need to
increase the | 26 // to test on different memory alignments. If offset is nonzero, we need to
increase the |
26 // size of the memory we allocate in order to make sure that we have enough.
We are | 27 // size of the memory we allocate in order to make sure that we have enough.
We are |
27 // still allocating the smallest possible size. | 28 // still allocating the smallest possible size. |
28 const size_t totalBytes = imageInfo.getSafeSize(rowBytes) + offset; | 29 const size_t totalBytes = imageInfo.getSafeSize(rowBytes) + offset; |
29 | 30 |
30 // Create fake image data where every byte has a value of 0 | 31 // Create fake image data where every byte has a value of 0 |
31 SkAutoTDeleteArray<uint8_t> storage(SkNEW_ARRAY(uint8_t, totalBytes)); | 32 SkAutoTDeleteArray<uint8_t> storage(SkNEW_ARRAY(uint8_t, totalBytes)); |
32 memset(storage.get(), 0, totalBytes); | 33 memset(storage.get(), 0, totalBytes); |
33 // Adjust the pointer in order to test on different memory alignments | 34 // Adjust the pointer in order to test on different memory alignments |
34 uint8_t* imageData = storage.get() + offset; | 35 uint8_t* imageData = storage.get() + offset; |
| 36 uint8_t* imageStart = imageData + rowBytes * startRow; |
35 | 37 |
36 // Fill image with the fill value starting at the indicated row | 38 // Fill image with the fill value starting at the indicated row |
37 SkSwizzler::Fill(imageData, imageInfo, rowBytes, startRow, colorOrIndex, col
orTable); | 39 SkSwizzler::Fill(imageStart, imageInfo, rowBytes, endRow - startRow + 1, col
orOrIndex, |
| 40 colorTable); |
38 | 41 |
39 // Ensure that the pixels are filled properly | 42 // Ensure that the pixels are filled properly |
40 // The bots should catch any memory corruption | 43 // The bots should catch any memory corruption |
41 uint8_t* indexPtr = imageData + startRow * rowBytes; | 44 uint8_t* indexPtr = imageData + startRow * rowBytes; |
42 uint32_t* colorPtr = (uint32_t*) indexPtr; | 45 uint32_t* colorPtr = (uint32_t*) indexPtr; |
43 for (int32_t y = startRow; y < imageInfo.height(); y++) { | 46 for (uint32_t y = startRow; y <= endRow; y++) { |
44 for (int32_t x = 0; x < imageInfo.width(); x++) { | 47 for (int32_t x = 0; x < imageInfo.width(); x++) { |
45 if (kIndex_8_SkColorType == imageInfo.colorType()) { | 48 if (kIndex_8_SkColorType == imageInfo.colorType()) { |
46 REPORTER_ASSERT(r, kFillIndex == indexPtr[x]); | 49 REPORTER_ASSERT(r, kFillIndex == indexPtr[x]); |
47 } else { | 50 } else { |
48 REPORTER_ASSERT(r, kFillColor == colorPtr[x]); | 51 REPORTER_ASSERT(r, kFillColor == colorPtr[x]); |
49 } | 52 } |
50 } | 53 } |
51 indexPtr += rowBytes; | 54 indexPtr += rowBytes; |
52 colorPtr = (uint32_t*) indexPtr; | 55 colorPtr = (uint32_t*) indexPtr; |
53 } | 56 } |
(...skipping 29 matching lines...) Expand all Loading... |
83 for (uint32_t padding : paddings) { | 86 for (uint32_t padding : paddings) { |
84 | 87 |
85 // Calculate row bytes | 88 // Calculate row bytes |
86 size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType
) * width + | 89 size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType
) * width + |
87 padding; | 90 padding; |
88 size_t indexRowBytes = width + padding; | 91 size_t indexRowBytes = width + padding; |
89 | 92 |
90 // If there is padding, we can invent an offset to change the me
mory alignment | 93 // If there is padding, we can invent an offset to change the me
mory alignment |
91 for (uint32_t offset = 0; offset <= padding; offset++) { | 94 for (uint32_t offset = 0; offset <= padding; offset++) { |
92 | 95 |
93 // Test all possible start rows | 96 // Test all possible start rows with all possible end rows |
94 for (uint32_t startRow = 0; startRow < height; startRow++) { | 97 for (uint32_t startRow = 0; startRow < height; startRow++) { |
| 98 for (uint32_t endRow = startRow; endRow < height; endRow
++) { |
95 | 99 |
96 // Fill with an index that we use to look up a color | 100 // Fill with an index that we use to look up a color |
97 check_fill(r, colorInfo, startRow, colorRowBytes, offset
, kFillIndex, | 101 check_fill(r, colorInfo, startRow, endRow, colorRowB
ytes, offset, |
98 colorTable); | 102 kFillIndex, colorTable); |
99 | 103 |
100 // Fill with a color | 104 // Fill with a color |
101 check_fill(r, colorInfo, startRow, colorRowBytes, offset
, kFillColor, | 105 check_fill(r, colorInfo, startRow, endRow, colorRowB
ytes, offset, |
102 NULL); | 106 kFillColor, NULL); |
103 | 107 |
104 // Fill with an index | 108 // Fill with an index |
105 check_fill(r, indexInfo, startRow, indexRowBytes, offset
, kFillIndex, | 109 check_fill(r, indexInfo, startRow, endRow, indexRowB
ytes, offset, |
106 NULL); | 110 kFillIndex, NULL); |
| 111 } |
107 } | 112 } |
108 } | 113 } |
109 } | 114 } |
110 } | 115 } |
111 } | 116 } |
112 } | 117 } |
OLD | NEW |