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

Side by Side Diff: tests/BitmapCopyTest.cpp

Issue 134453002: Revert of Fix genID cloning bugs. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | tests/GpuBitmapCopyTest.cpp » ('j') | 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 /*
2 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
3 * 4 *
4 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 6 * found in the LICENSE file.
6 */ 7 */
7 #include "Test.h" 8 #include "Test.h"
8 #include "TestClassDef.h" 9 #include "TestClassDef.h"
9 #include "SkBitmap.h" 10 #include "SkBitmap.h"
10 #include "SkRect.h" 11 #include "SkRect.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 ERRORF(reporter, "%s [config = %s]", msg, getSkConfigName(bm1)); 193 ERRORF(reporter, "%s [config = %s]", msg, getSkConfigName(bm1));
193 } 194 }
194 } 195 }
195 196
196 // Writes unique pixel values at locations specified by coords. 197 // Writes unique pixel values at locations specified by coords.
197 static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { 198 static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) {
198 for (int i = 0; i < coords.length; ++i) 199 for (int i = 0; i < coords.length; ++i)
199 setPixel(coords[i]->fX, coords[i]->fY, i, bm); 200 setPixel(coords[i]->fX, coords[i]->fY, i, bm);
200 } 201 }
201 202
202 static const Pair gPairs[] = { 203 DEF_TEST(BitmapCopy, reporter) {
203 { SkBitmap::kNo_Config, "0000000" }, 204 static const Pair gPairs[] = {
204 { SkBitmap::kA8_Config, "0101010" }, 205 { SkBitmap::kNo_Config, "0000000" },
205 { SkBitmap::kIndex8_Config, "0111010" }, 206 { SkBitmap::kA8_Config, "0101010" },
206 { SkBitmap::kRGB_565_Config, "0101010" }, 207 { SkBitmap::kIndex8_Config, "0111010" },
207 { SkBitmap::kARGB_4444_Config, "0101110" }, 208 { SkBitmap::kRGB_565_Config, "0101010" },
208 { SkBitmap::kARGB_8888_Config, "0101110" }, 209 { SkBitmap::kARGB_4444_Config, "0101110" },
209 }; 210 { SkBitmap::kARGB_8888_Config, "0101110" },
211 };
210 212
211 static const int W = 20;
212 static const int H = 33;
213
214 static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
215 SkBitmap::Config config) {
216 SkColorTable* ctOpaque = NULL;
217 SkColorTable* ctPremul = NULL;
218
219 srcOpaque->setConfig(config, W, H, 0, kOpaque_SkAlphaType);
220 srcPremul->setConfig(config, W, H, 0, kPremul_SkAlphaType);
221 if (SkBitmap::kIndex8_Config == config) {
222 ctOpaque = init_ctable(kOpaque_SkAlphaType);
223 ctPremul = init_ctable(kPremul_SkAlphaType);
224 }
225 srcOpaque->allocPixels(ctOpaque);
226 srcPremul->allocPixels(ctPremul);
227 SkSafeUnref(ctOpaque);
228 SkSafeUnref(ctPremul);
229 init_src(*srcOpaque);
230 init_src(*srcPremul);
231 }
232
233 DEF_TEST(BitmapCopy_extractSubset, reporter) {
234 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
235 SkBitmap srcOpaque, srcPremul;
236 setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fConfig);
237
238 SkBitmap bitmap(srcOpaque);
239 SkBitmap subset;
240 SkIRect r;
241 // Extract a subset which has the same width as the original. This
242 // catches a bug where we cloned the genID incorrectly.
243 r.set(0, 1, W, 3);
244 bitmap.setIsVolatile(true);
245 if (bitmap.extractSubset(&subset, r)) {
246 REPORTER_ASSERT(reporter, subset.width() == W);
247 REPORTER_ASSERT(reporter, subset.height() == 2);
248 REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
249 REPORTER_ASSERT(reporter, subset.isVolatile() == true);
250
251 // Test copying an extracted subset.
252 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
253 SkBitmap copy;
254 bool success = subset.copyTo(&copy, gPairs[j].fConfig);
255 if (!success) {
256 // Skip checking that success matches fValid, which is redun dant
257 // with the code below.
258 REPORTER_ASSERT(reporter, gPairs[i].fConfig != gPairs[j].fCo nfig);
259 continue;
260 }
261
262 // When performing a copy of an extracted subset, the gen id sho uld
263 // change.
264 REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.getGe nerationID());
265
266 REPORTER_ASSERT(reporter, copy.width() == W);
267 REPORTER_ASSERT(reporter, copy.height() == 2);
268
269 if (gPairs[i].fConfig == gPairs[j].fConfig) {
270 SkAutoLockPixels alp0(subset);
271 SkAutoLockPixels alp1(copy);
272 // they should both have, or both not-have, a colortable
273 bool hasCT = subset.getColorTable() != NULL;
274 REPORTER_ASSERT(reporter, (copy.getColorTable() != NULL) == hasCT);
275 }
276 }
277 }
278
279 bitmap = srcPremul;
280 bitmap.setIsVolatile(false);
281 if (bitmap.extractSubset(&subset, r)) {
282 REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
283 REPORTER_ASSERT(reporter, subset.isVolatile() == false);
284 }
285 }
286 }
287
288 DEF_TEST(BitmapCopy, reporter) {
289 static const bool isExtracted[] = { 213 static const bool isExtracted[] = {
290 false, true 214 false, true
291 }; 215 };
292 216
217 const int W = 20;
218 const int H = 33;
219
293 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { 220 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
294 SkBitmap srcOpaque, srcPremul; 221 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
295 setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fConfig); 222 SkBitmap srcOpaque, srcPremul, dst;
296 223
297 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { 224 {
298 SkBitmap dst; 225 SkColorTable* ctOpaque = NULL;
226 SkColorTable* ctPremul = NULL;
227
228 srcOpaque.setConfig(gPairs[i].fConfig, W, H, 0, kOpaque_SkAlphaT ype);
229 srcPremul.setConfig(gPairs[i].fConfig, W, H, 0, kPremul_SkAlphaT ype);
230 if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) {
231 ctOpaque = init_ctable(kOpaque_SkAlphaType);
232 ctPremul = init_ctable(kPremul_SkAlphaType);
233 }
234 srcOpaque.allocPixels(ctOpaque);
235 srcPremul.allocPixels(ctPremul);
236 SkSafeUnref(ctOpaque);
237 SkSafeUnref(ctPremul);
238 }
239 init_src(srcOpaque);
240 init_src(srcPremul);
299 241
300 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); 242 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig);
301 bool expected = gPairs[i].fValid[j] != '0'; 243 bool expected = gPairs[i].fValid[j] != '0';
302 if (success != expected) { 244 if (success != expected) {
303 ERRORF(reporter, "SkBitmap::copyTo from %s to %s. expected %s " 245 ERRORF(reporter, "SkBitmap::copyTo from %s to %s. expected %s "
304 "returned %s", gConfigName[i], gConfigName[j], 246 "returned %s", gConfigName[i], gConfigName[j],
305 boolStr(expected), boolStr(success)); 247 boolStr(expected), boolStr(success));
306 } 248 }
307 249
308 bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig); 250 bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig);
(...skipping 15 matching lines...) Expand all
324 REPORTER_ASSERT(reporter, dst.readyToDraw()); 266 REPORTER_ASSERT(reporter, dst.readyToDraw());
325 const char* srcP = (const char*)srcPremul.getAddr(0, 0); 267 const char* srcP = (const char*)srcPremul.getAddr(0, 0);
326 const char* dstP = (const char*)dst.getAddr(0, 0); 268 const char* dstP = (const char*)dst.getAddr(0, 0);
327 REPORTER_ASSERT(reporter, srcP != dstP); 269 REPORTER_ASSERT(reporter, srcP != dstP);
328 REPORTER_ASSERT(reporter, !memcmp(srcP, dstP, 270 REPORTER_ASSERT(reporter, !memcmp(srcP, dstP,
329 srcPremul.getSize())); 271 srcPremul.getSize()));
330 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() == dst .getGenerationID()); 272 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() == dst .getGenerationID());
331 } else { 273 } else {
332 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() != dst .getGenerationID()); 274 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() != dst .getGenerationID());
333 } 275 }
276 // test extractSubset
277 {
278 SkBitmap bitmap(srcOpaque);
279 SkBitmap subset;
280 SkIRect r;
281 r.set(1, 1, 2, 2);
282 bitmap.setIsVolatile(true);
283 if (bitmap.extractSubset(&subset, r)) {
284 REPORTER_ASSERT(reporter, subset.width() == 1);
285 REPORTER_ASSERT(reporter, subset.height() == 1);
286 REPORTER_ASSERT(reporter,
287 subset.alphaType() == bitmap.alphaType() );
288 REPORTER_ASSERT(reporter,
289 subset.isVolatile() == true);
290
291 SkBitmap copy;
292 REPORTER_ASSERT(reporter,
293 subset.copyTo(&copy, subset.config()));
294 REPORTER_ASSERT(reporter, copy.width() == 1);
295 REPORTER_ASSERT(reporter, copy.height() == 1);
296 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4);
297
298 SkAutoLockPixels alp0(subset);
299 SkAutoLockPixels alp1(copy);
300 // they should both have, or both not-have, a colortable
301 bool hasCT = subset.getColorTable() != NULL;
302 REPORTER_ASSERT(reporter,
303 (copy.getColorTable() != NULL) == hasCT);
304 }
305 bitmap = srcPremul;
306 bitmap.setIsVolatile(false);
307 if (bitmap.extractSubset(&subset, r)) {
308 REPORTER_ASSERT(reporter,
309 subset.alphaType() == bitmap.alphaType() );
310 REPORTER_ASSERT(reporter,
311 subset.isVolatile() == false);
312 }
313 }
334 } else { 314 } else {
335 // dst should be unchanged from its initial state 315 // dst should be unchanged from its initial state
336 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config); 316 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config);
337 REPORTER_ASSERT(reporter, dst.width() == 0); 317 REPORTER_ASSERT(reporter, dst.width() == 0);
338 REPORTER_ASSERT(reporter, dst.height() == 0); 318 REPORTER_ASSERT(reporter, dst.height() == 0);
339 } 319 }
340 } // for (size_t j = ... 320 } // for (size_t j = ...
341 321
342 // Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(), 322 // Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(),
343 // copyPixelsFrom(). 323 // copyPixelsFrom().
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // for the transfer. 531 // for the transfer.
552 REPORTER_ASSERT(reporter, 532 REPORTER_ASSERT(reporter,
553 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) == 533 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) ==
554 false); 534 false);
555 535
556 #endif 536 #endif
557 } 537 }
558 } // for (size_t copyCase ... 538 } // for (size_t copyCase ...
559 } 539 }
560 } 540 }
OLDNEW
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | tests/GpuBitmapCopyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698