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

Side by Side Diff: tests/TextureCompressionTest.cpp

Issue 1148793007: change SkDraw and all Blitters to use pixmap instead of bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 6 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 | « tests/DeviceLooperTest.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
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkData.h" 9 #include "SkData.h"
10 #include "SkEndian.h" 10 #include "SkEndian.h"
(...skipping 24 matching lines...) Expand all
35 35
36 default: 36 default:
37 return false; 37 return false;
38 } 38 }
39 } 39 }
40 40
41 /** 41 /**
42 * Make sure that we properly fail when we don't have multiple of four image dim ensions. 42 * Make sure that we properly fail when we don't have multiple of four image dim ensions.
43 */ 43 */
44 DEF_TEST(CompressAlphaFailDimensions, reporter) { 44 DEF_TEST(CompressAlphaFailDimensions, reporter) {
45 SkBitmap bitmap;
46 static const int kWidth = 17; 45 static const int kWidth = 17;
47 static const int kHeight = 17; 46 static const int kHeight = 17;
48 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
49 47
50 // R11_EAC and LATC are both dimensions of 4, so we need to make sure that w e 48 // R11_EAC and LATC are both dimensions of 4, so we need to make sure that w e
51 // are violating those assumptions. And if we are, then we're also violating the 49 // are violating those assumptions. And if we are, then we're also violating the
52 // assumptions of ASTC, which is 12x12 since any number not divisible by 4 i s 50 // assumptions of ASTC, which is 12x12 since any number not divisible by 4 i s
53 // also not divisible by 12. Our dimensions are prime, so any block dimensio n 51 // also not divisible by 12. Our dimensions are prime, so any block dimensio n
54 // larger than 1 should fail. 52 // larger than 1 should fail.
55 REPORTER_ASSERT(reporter, kWidth % 4 != 0); 53 REPORTER_ASSERT(reporter, kWidth % 4 != 0);
56 REPORTER_ASSERT(reporter, kHeight % 4 != 0); 54 REPORTER_ASSERT(reporter, kHeight % 4 != 0);
57 55
58 bool setInfoSuccess = bitmap.setInfo(info); 56 SkAutoPixmapStorage pixmap;
59 REPORTER_ASSERT(reporter, setInfoSuccess); 57 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight));
60 58 // leaving the pixels uninitialized, as they don't affect the test...
61 bitmap.allocPixels(info);
62 bitmap.unlockPixels();
63 59
64 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { 60 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
65 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i); 61 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i);
66 if (!compresses_a8(fmt)) { 62 if (!compresses_a8(fmt)) {
67 continue; 63 continue;
68 } 64 }
69 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); 65 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
70 REPORTER_ASSERT(reporter, NULL == data); 66 REPORTER_ASSERT(reporter, NULL == data);
71 } 67 }
72 } 68 }
73 69
74 /** 70 /**
75 * Make sure that we properly fail when we don't have the correct bitmap type. 71 * Make sure that we properly fail when we don't have the correct bitmap type.
76 * compressed textures can (currently) only be created from A8 bitmaps. 72 * compressed textures can (currently) only be created from A8 bitmaps.
77 */ 73 */
78 DEF_TEST(CompressAlphaFailColorType, reporter) { 74 DEF_TEST(CompressAlphaFailColorType, reporter) {
79 SkBitmap bitmap;
80 static const int kWidth = 12; 75 static const int kWidth = 12;
81 static const int kHeight = 12; 76 static const int kHeight = 12;
82 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
83 77
84 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl e 78 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl e
85 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh t 79 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh t
86 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t his would 80 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t his would
87 // need to be updated. 81 // need to be updated.
88 REPORTER_ASSERT(reporter, kWidth % 12 == 0); 82 REPORTER_ASSERT(reporter, kWidth % 12 == 0);
89 REPORTER_ASSERT(reporter, kHeight % 12 == 0); 83 REPORTER_ASSERT(reporter, kHeight % 12 == 0);
90 84
91 bool setInfoSuccess = bitmap.setInfo(info); 85 SkAutoPixmapStorage pixmap;
92 REPORTER_ASSERT(reporter, setInfoSuccess); 86 pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight));
93 87 // leaving the pixels uninitialized, as they don't affect the test...
94 bitmap.allocPixels(info);
95 bitmap.unlockPixels();
96 88
97 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { 89 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
98 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i); 90 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i);
99 if (!compresses_a8(fmt)) { 91 if (!compresses_a8(fmt)) {
100 continue; 92 continue;
101 } 93 }
102 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); 94 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
103 REPORTER_ASSERT(reporter, NULL == data); 95 REPORTER_ASSERT(reporter, NULL == data);
104 } 96 }
105 } 97 }
106 98
107 /** 99 /**
108 * Make sure that if you compress a texture with alternating black/white pixels, and 100 * Make sure that if you compress a texture with alternating black/white pixels, and
109 * then decompress it, you get what you started with. 101 * then decompress it, you get what you started with.
110 */ 102 */
111 DEF_TEST(CompressCheckerboard, reporter) { 103 DEF_TEST(CompressCheckerboard, reporter) {
112 SkBitmap bitmap;
113 static const int kWidth = 48; // We need the number to be divisible by both 104 static const int kWidth = 48; // We need the number to be divisible by both
114 static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC). 105 static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC).
115 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
116 106
117 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl e 107 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl e
118 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh t 108 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh t
119 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t his would 109 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t his would
120 // need to be updated. Additionally, ARM NEON and SSE code paths support up to 110 // need to be updated. Additionally, ARM NEON and SSE code paths support up to
121 // four blocks of R11 EAC at once, so they operate on 16-wide blocks. Hence, the 111 // four blocks of R11 EAC at once, so they operate on 16-wide blocks. Hence, the
122 // valid width and height is going to be the LCM of 12 and 16 which is 4*4*3 = 48 112 // valid width and height is going to be the LCM of 12 and 16 which is 4*4*3 = 48
123 REPORTER_ASSERT(reporter, kWidth % 48 == 0); 113 REPORTER_ASSERT(reporter, kWidth % 48 == 0);
124 REPORTER_ASSERT(reporter, kHeight % 48 == 0); 114 REPORTER_ASSERT(reporter, kHeight % 48 == 0);
125 115
126 bool setInfoSuccess = bitmap.setInfo(info); 116 SkAutoPixmapStorage pixmap;
127 REPORTER_ASSERT(reporter, setInfoSuccess); 117 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight));
128 118
129 bitmap.allocPixels(info); 119 // Populate the pixels
130 bitmap.unlockPixels();
131
132 // Populate bitmap
133 { 120 {
134 SkAutoLockPixels alp(bitmap); 121 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr());
135
136 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
137 REPORTER_ASSERT(reporter, pixels); 122 REPORTER_ASSERT(reporter, pixels);
138 if (NULL == pixels) { 123 if (NULL == pixels) {
139 return; 124 return;
140 } 125 }
141 126
142 for (int y = 0; y < kHeight; ++y) { 127 for (int y = 0; y < kHeight; ++y) {
143 for (int x = 0; x < kWidth; ++x) { 128 for (int x = 0; x < kWidth; ++x) {
144 if ((x ^ y) & 1) { 129 if ((x ^ y) & 1) {
145 pixels[x] = 0xFF; 130 pixels[x] = 0xFF;
146 } else { 131 } else {
147 pixels[x] = 0; 132 pixels[x] = 0;
148 } 133 }
149 } 134 }
150 pixels += bitmap.rowBytes(); 135 pixels += pixmap.rowBytes();
151 } 136 }
152 } 137 }
153 138
154 SkAutoMalloc decompMemory(kWidth*kHeight); 139 SkAutoMalloc decompMemory(kWidth*kHeight);
155 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get()); 140 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get());
156 REPORTER_ASSERT(reporter, decompBuffer); 141 REPORTER_ASSERT(reporter, decompBuffer);
157 if (NULL == decompBuffer) { 142 if (NULL == decompBuffer) {
158 return; 143 return;
159 } 144 }
160 145
161 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { 146 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
162 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i); 147 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i);
163 148
164 // Ignore formats for RGBA data, since the decompressed buffer 149 // Ignore formats for RGBA data, since the decompressed buffer
165 // won't match the size and contents of the original. 150 // won't match the size and contents of the original.
166 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { 151 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) {
167 continue; 152 continue;
168 } 153 }
169 154
170 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); 155 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
171 REPORTER_ASSERT(reporter, data); 156 REPORTER_ASSERT(reporter, data);
172 if (NULL == data) { 157 if (NULL == data) {
173 continue; 158 continue;
174 } 159 }
175 160
176 bool decompResult = 161 bool decompResult =
177 SkTextureCompressor::DecompressBufferFromFormat( 162 SkTextureCompressor::DecompressBufferFromFormat(
178 decompBuffer, kWidth, 163 decompBuffer, kWidth,
179 data->bytes(), 164 data->bytes(),
180 kWidth, kHeight, fmt); 165 kWidth, kHeight, fmt);
181 REPORTER_ASSERT(reporter, decompResult); 166 REPORTER_ASSERT(reporter, decompResult);
182 167
183 SkAutoLockPixels alp(bitmap); 168 const uint8_t* pixels = reinterpret_cast<const uint8_t*>(pixmap.addr());
184 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
185 REPORTER_ASSERT(reporter, pixels); 169 REPORTER_ASSERT(reporter, pixels);
186 if (NULL == pixels) { 170 if (NULL == pixels) {
187 continue; 171 continue;
188 } 172 }
189 173
190 for (int y = 0; y < kHeight; ++y) { 174 for (int y = 0; y < kHeight; ++y) {
191 for (int x = 0; x < kWidth; ++x) { 175 for (int x = 0; x < kWidth; ++x) {
192 bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWid th + x]; 176 bool ok = pixels[y*pixmap.rowBytes() + x] == decompBuffer[y*kWid th + x];
193 REPORTER_ASSERT(reporter, ok); 177 REPORTER_ASSERT(reporter, ok);
194 } 178 }
195 } 179 }
196 } 180 }
197 } 181 }
198 182
199 /** 183 /**
200 * Make sure that if we pass in a solid color bitmap that we get the appropriate results 184 * Make sure that if we pass in a solid color bitmap that we get the appropriate results
201 */ 185 */
202 DEF_TEST(CompressLATC, reporter) { 186 DEF_TEST(CompressLATC, reporter) {
203 187
204 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat; 188 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat;
205 static const int kLATCEncodedBlockSize = 8; 189 static const int kLATCEncodedBlockSize = 8;
206 190
207 SkBitmap bitmap;
208 static const int kWidth = 8; 191 static const int kWidth = 8;
209 static const int kHeight = 8; 192 static const int kHeight = 8;
210 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
211 193
212 bool setInfoSuccess = bitmap.setInfo(info); 194 SkAutoPixmapStorage pixmap;
213 REPORTER_ASSERT(reporter, setInfoSuccess); 195 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight));
214
215 bitmap.allocPixels(info);
216 bitmap.unlockPixels();
217 196
218 int latcDimX, latcDimY; 197 int latcDimX, latcDimY;
219 SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY); 198 SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY);
220 199
221 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0); 200 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0);
222 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0); 201 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0);
223 const size_t kSizeToBe = 202 const size_t kSizeToBe =
224 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight) ; 203 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight) ;
225 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz e)/16)); 204 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz e)/16));
226 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); 205 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0);
227 206
228 for (int lum = 0; lum < 256; ++lum) { 207 for (int lum = 0; lum < 256; ++lum) {
229 bitmap.lockPixels(); 208 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr());
230 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
231 REPORTER_ASSERT(reporter, pixels);
232 if (NULL == pixels) {
233 bitmap.unlockPixels();
234 continue;
235 }
236
237 for (int i = 0; i < kWidth*kHeight; ++i) { 209 for (int i = 0; i < kWidth*kHeight; ++i) {
238 pixels[i] = lum; 210 pixels[i] = lum;
239 } 211 }
240 bitmap.unlockPixels();
241 212
242 SkAutoDataUnref latcData( 213 SkAutoDataUnref latcData(
243 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); 214 SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat));
244 REPORTER_ASSERT(reporter, latcData); 215 REPORTER_ASSERT(reporter, latcData);
245 if (NULL == latcData) { 216 if (NULL == latcData) {
246 continue; 217 continue;
247 } 218 }
248 219
249 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); 220 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size());
250 221
251 // Make sure that it all matches a given block encoding. Since we have 222 // Make sure that it all matches a given block encoding. Since we have
252 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us ing 223 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us ing
253 // an approximation scheme that optimizes for speed against coverage map s. 224 // an approximation scheme that optimizes for speed against coverage map s.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37 ) | 266 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37 ) |
296 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) | 267 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) |
297 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 )); 268 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 ));
298 269
299 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata()); 270 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata());
300 for (size_t i = 0; i < (kSizeToBe/8); ++i) { 271 for (size_t i = 0; i < (kSizeToBe/8); ++i) {
301 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); 272 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding);
302 } 273 }
303 } 274 }
304 } 275 }
OLDNEW
« no previous file with comments | « tests/DeviceLooperTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698