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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1208993017: Add image->bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add check for immutable 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected)); 400 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected));
401 401
402 // partial bottom-right should succeed 402 // partial bottom-right should succeed
403 set_pixels(pixels, w*h, notExpected); 403 set_pixels(pixels, w*h, notExpected);
404 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, 404 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes,
405 image->width() - 1, image->heigh t() - 1)); 405 image->width() - 1, image->heigh t() - 1));
406 REPORTER_ASSERT(reporter, pixels[0] == expected); 406 REPORTER_ASSERT(reporter, pixels[0] == expected);
407 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected)); 407 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
408 } 408 }
409 409
410 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag e) {
411 const SkImage::LegacyBitmapMode modes[] = {
412 SkImage::kRO_LegacyBitmapMode,
413 SkImage::kRW_LegacyBitmapMode,
414 };
415 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
416 SkBitmap bitmap;
417 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, modes[i]));
418
419 REPORTER_ASSERT(reporter, image->width() == bitmap.width());
420 REPORTER_ASSERT(reporter, image->height() == bitmap.height());
421 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque());
422
423 bitmap.lockPixels();
424 REPORTER_ASSERT(reporter, bitmap.getPixels());
425
426 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
427 SkPMColor imageColor;
428 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(Sk PMColor), 0, 0));
429 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
430
431 if (SkImage::kRO_LegacyBitmapMode == modes[i]) {
432 REPORTER_ASSERT(reporter, bitmap.isImmutable());
433 }
434 }
435 }
436
410 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) { 437 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) {
411 static const struct { 438 static const struct {
412 ImageType fType; 439 ImageType fType;
413 bool fPeekShouldSucceed; 440 bool fPeekShouldSucceed;
414 const char* fName; 441 const char* fName;
415 } gRec[] = { 442 } gRec[] = {
416 { kRasterCopy_ImageType, true, "RasterCopy" }, 443 { kRasterCopy_ImageType, true, "RasterCopy" },
417 { kRasterData_ImageType, true, "RasterData" }, 444 { kRasterData_ImageType, true, "RasterData" },
418 { kRasterProc_ImageType, true, "RasterProc" }, 445 { kRasterProc_ImageType, true, "RasterProc" },
419 { kGpu_ImageType, false, "Gpu" }, 446 { kGpu_ImageType, false, "Gpu" },
(...skipping 23 matching lines...) Expand all
443 if (!image.get()) { 470 if (!image.get()) {
444 SkDebugf("failed to createImage[%d] %s\n", i, gRec[i].fName); 471 SkDebugf("failed to createImage[%d] %s\n", i, gRec[i].fName);
445 continue; // gpu may not be enabled 472 continue; // gpu may not be enabled
446 } 473 }
447 if (kRasterProc_ImageType == gRec[i].fType) { 474 if (kRasterProc_ImageType == gRec[i].fType) {
448 REPORTER_ASSERT(reporter, NULL != releaseCtx.fData); // we are trac king the data 475 REPORTER_ASSERT(reporter, NULL != releaseCtx.fData); // we are trac king the data
449 } else { 476 } else {
450 REPORTER_ASSERT(reporter, NULL == releaseCtx.fData); // we ignored the context 477 REPORTER_ASSERT(reporter, NULL == releaseCtx.fData); // we ignored the context
451 } 478 }
452 479
480 test_legacy_bitmap(reporter, image);
481
453 const void* addr = image->peekPixels(&info, &rowBytes); 482 const void* addr = image->peekPixels(&info, &rowBytes);
454 bool success = SkToBool(addr); 483 bool success = SkToBool(addr);
455 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); 484 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
456 if (success) { 485 if (success) {
457 REPORTER_ASSERT(reporter, 10 == info.width()); 486 REPORTER_ASSERT(reporter, 10 == info.width());
458 REPORTER_ASSERT(reporter, 10 == info.height()); 487 REPORTER_ASSERT(reporter, 10 == info.height());
459 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); 488 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
460 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || 489 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
461 kOpaque_SkAlphaType == info.alphaType()); 490 kOpaque_SkAlphaType == info.alphaType());
462 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); 491 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color 1008 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color
980 test_image_color(reporter, refImg, expected1); 1009 test_image_color(reporter, refImg, expected1);
981 test_image_color(reporter, cpyImg, expected0); 1010 test_image_color(reporter, cpyImg, expected0);
982 1011
983 // Now exercise the release proc 1012 // Now exercise the release proc
984 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); 1013 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased);
985 refImg.reset(NULL); // force a release of the image 1014 refImg.reset(NULL); // force a release of the image
986 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); 1015 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased);
987 } 1016 }
988 #endif 1017 #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