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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1227413002: Fix SkImage::asLegacyBitmap() rowBytes assert (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 | « src/image/SkImage_Raster.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 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected)); 383 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected));
384 384
385 // partial bottom-right should succeed 385 // partial bottom-right should succeed
386 set_pixels(pixels, w*h, notExpected); 386 set_pixels(pixels, w*h, notExpected);
387 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, 387 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes,
388 image->width() - 1, image->heigh t() - 1)); 388 image->width() - 1, image->heigh t() - 1));
389 REPORTER_ASSERT(reporter, pixels[0] == expected); 389 REPORTER_ASSERT(reporter, pixels[0] == expected);
390 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected)); 390 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
391 } 391 }
392 392
393 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima ge,
394 const SkBitmap& bitmap, SkImage::LegacyBitmapMod e mode) {
395 REPORTER_ASSERT(reporter, image->width() == bitmap.width());
396 REPORTER_ASSERT(reporter, image->height() == bitmap.height());
397 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque());
398
399 if (SkImage::kRO_LegacyBitmapMode == mode) {
400 REPORTER_ASSERT(reporter, bitmap.isImmutable());
401 }
402
403 SkAutoLockPixels alp(bitmap);
404 REPORTER_ASSERT(reporter, bitmap.getPixels());
405
406 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
407 SkPMColor imageColor;
408 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMCo lor), 0, 0));
409 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
410 }
411
393 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag e) { 412 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag e) {
394 const SkImage::LegacyBitmapMode modes[] = { 413 const SkImage::LegacyBitmapMode modes[] = {
395 SkImage::kRO_LegacyBitmapMode, 414 SkImage::kRO_LegacyBitmapMode,
396 SkImage::kRW_LegacyBitmapMode, 415 SkImage::kRW_LegacyBitmapMode,
397 }; 416 };
398 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) { 417 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
399 SkBitmap bitmap; 418 SkBitmap bitmap;
400 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, modes[i])); 419 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, modes[i]));
420 check_legacy_bitmap(reporter, image, bitmap, modes[i]);
401 421
402 REPORTER_ASSERT(reporter, image->width() == bitmap.width()); 422 // Test subsetting to exercise the rowBytes logic.
403 REPORTER_ASSERT(reporter, image->height() == bitmap.height()); 423 SkBitmap tmp;
404 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque()); 424 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(ima ge->width() / 2,
425 ima ge->height() / 2)));
426 SkAutoTUnref<SkImage> subsetImage(SkImage::NewFromBitmap(tmp));
427 REPORTER_ASSERT(reporter, subsetImage);
405 428
406 bitmap.lockPixels(); 429 SkBitmap subsetBitmap;
407 REPORTER_ASSERT(reporter, bitmap.getPixels()); 430 REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap, mod es[i]));
408 431 check_legacy_bitmap(reporter, subsetImage, subsetBitmap, modes[i]);
409 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
410 SkPMColor imageColor;
411 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(Sk PMColor), 0, 0));
412 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
413
414 if (SkImage::kRO_LegacyBitmapMode == modes[i]) {
415 REPORTER_ASSERT(reporter, bitmap.isImmutable());
416 }
417 } 432 }
418 } 433 }
419 434
420 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) { 435 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) {
421 static const struct { 436 static const struct {
422 ImageType fType; 437 ImageType fType;
423 bool fPeekShouldSucceed; 438 bool fPeekShouldSucceed;
424 const char* fName; 439 const char* fName;
425 } gRec[] = { 440 } gRec[] = {
426 { kRasterCopy_ImageType, true, "RasterCopy" }, 441 { kRasterCopy_ImageType, true, "RasterCopy" },
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color 1006 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color
992 test_image_color(reporter, refImg, expected1); 1007 test_image_color(reporter, refImg, expected1);
993 test_image_color(reporter, cpyImg, expected0); 1008 test_image_color(reporter, cpyImg, expected0);
994 1009
995 // Now exercise the release proc 1010 // Now exercise the release proc
996 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); 1011 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased);
997 refImg.reset(NULL); // force a release of the image 1012 refImg.reset(NULL); // force a release of the image
998 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); 1013 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased);
999 } 1014 }
1000 #endif 1015 #endif
OLDNEW
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698