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

Side by Side Diff: tests/ImageTest.cpp

Issue 2250663002: Add alphaType() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@special-image-alpha-type
Patch Set: Remove virtuals from SkImage, slight cleanup Created 4 years, 4 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/pdf/SkPDFBitmap.cpp ('k') | tests/SurfaceTest.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 * 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 <functional> 8 #include <functional>
9 #include <initializer_list> 9 #include <initializer_list>
10 #include <vector> 10 #include <vector>
(...skipping 25 matching lines...) Expand all
36 SkImage* b) { 36 SkImage* b) {
37 const int widthA = subsetA ? subsetA->width() : a->width(); 37 const int widthA = subsetA ? subsetA->width() : a->width();
38 const int heightA = subsetA ? subsetA->height() : a->height(); 38 const int heightA = subsetA ? subsetA->height() : a->height();
39 39
40 REPORTER_ASSERT(reporter, widthA == b->width()); 40 REPORTER_ASSERT(reporter, widthA == b->width());
41 REPORTER_ASSERT(reporter, heightA == b->height()); 41 REPORTER_ASSERT(reporter, heightA == b->height());
42 42
43 // see https://bug.skia.org/3965 43 // see https://bug.skia.org/3965
44 //REPORTER_ASSERT(reporter, a->isOpaque() == b->isOpaque()); 44 //REPORTER_ASSERT(reporter, a->isOpaque() == b->isOpaque());
45 45
46 SkImageInfo info = SkImageInfo::MakeN32(widthA, heightA, 46 SkImageInfo info = SkImageInfo::MakeN32(widthA, heightA, a->alphaType());
47 a->isOpaque() ? kOpaque_SkAlphaType : kP remul_SkAlphaType);
48 SkAutoPixmapStorage pmapA, pmapB; 47 SkAutoPixmapStorage pmapA, pmapB;
49 pmapA.alloc(info); 48 pmapA.alloc(info);
50 pmapB.alloc(info); 49 pmapB.alloc(info);
51 50
52 const int srcX = subsetA ? subsetA->x() : 0; 51 const int srcX = subsetA ? subsetA->x() : 0;
53 const int srcY = subsetA ? subsetA->y() : 0; 52 const int srcY = subsetA ? subsetA->y() : 0;
54 53
55 REPORTER_ASSERT(reporter, a->readPixels(pmapA, srcX, srcY)); 54 REPORTER_ASSERT(reporter, a->readPixels(pmapA, srcX, srcY));
56 REPORTER_ASSERT(reporter, b->readPixels(pmapB, 0, 0)); 55 REPORTER_ASSERT(reporter, b->readPixels(pmapB, 0, 0));
57 56
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 continue; 497 continue;
499 } 498 }
500 if (origTexture) { 499 if (origTexture) {
501 if (origTexture != copyTexture) { 500 if (origTexture != copyTexture) {
502 ERRORF(reporter, "newTextureImage made unnecessary texture copy. "); 501 ERRORF(reporter, "newTextureImage made unnecessary texture copy. ");
503 } 502 }
504 } 503 }
505 if (image->width() != texImage->width() || image->height() != texImage-> height()) { 504 if (image->width() != texImage->width() || image->height() != texImage-> height()) {
506 ERRORF(reporter, "newTextureImage changed the image size."); 505 ERRORF(reporter, "newTextureImage changed the image size.");
507 } 506 }
508 if (image->isOpaque() != texImage->isOpaque()) { 507 if (image->alphaType() != texImage->alphaType()) {
509 ERRORF(reporter, "newTextureImage changed image opaqueness."); 508 ERRORF(reporter, "newTextureImage changed image alpha type.");
510 } 509 }
511 } 510 }
512 } 511 }
513 512
514 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contex tInfo) { 513 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contex tInfo) {
515 GrContext* context = contextInfo.grContext(); 514 GrContext* context = contextInfo.grContext();
516 515
517 std::function<sk_sp<SkImage>()> imageFactories[] = { 516 std::function<sk_sp<SkImage>()> imageFactories[] = {
518 create_image, 517 create_image,
519 create_codec_image, 518 create_codec_image,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 #if SK_SUPPORT_GPU 661 #if SK_SUPPORT_GPU
663 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) { 662 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) {
664 test_read_pixels(reporter, create_gpu_image(ctxInfo.grContext()).get()); 663 test_read_pixels(reporter, create_gpu_image(ctxInfo.grContext()).get());
665 } 664 }
666 #endif 665 #endif
667 666
668 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima ge, 667 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima ge,
669 const SkBitmap& bitmap, SkImage::LegacyBitmapMod e mode) { 668 const SkBitmap& bitmap, SkImage::LegacyBitmapMod e mode) {
670 REPORTER_ASSERT(reporter, image->width() == bitmap.width()); 669 REPORTER_ASSERT(reporter, image->width() == bitmap.width());
671 REPORTER_ASSERT(reporter, image->height() == bitmap.height()); 670 REPORTER_ASSERT(reporter, image->height() == bitmap.height());
672 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque()); 671 REPORTER_ASSERT(reporter, image->alphaType() == bitmap.alphaType());
673 672
674 if (SkImage::kRO_LegacyBitmapMode == mode) { 673 if (SkImage::kRO_LegacyBitmapMode == mode) {
675 REPORTER_ASSERT(reporter, bitmap.isImmutable()); 674 REPORTER_ASSERT(reporter, bitmap.isImmutable());
676 } 675 }
677 676
678 SkAutoLockPixels alp(bitmap); 677 SkAutoLockPixels alp(bitmap);
679 REPORTER_ASSERT(reporter, bitmap.getPixels()); 678 REPORTER_ASSERT(reporter, bitmap.getPixels());
680 679
681 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType()); 680 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
682 SkPMColor imageColor; 681 SkPMColor imageColor;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); 804 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
806 805
807 ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendDesc.f TextureHandle); 806 ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendDesc.f TextureHandle);
808 } 807 }
809 808
810 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co nst SkImage* b) { 809 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co nst SkImage* b) {
811 if (a->width() != b->width() || a->height() != b->height()) { 810 if (a->width() != b->width() || a->height() != b->height()) {
812 ERRORF(reporter, "Images must have the same size"); 811 ERRORF(reporter, "Images must have the same size");
813 return; 812 return;
814 } 813 }
815 if (a->isOpaque() != b->isOpaque()) { 814 if (a->alphaType() != b->alphaType()) {
816 ERRORF(reporter, "Images must have the same opaquness"); 815 ERRORF(reporter, "Images must have the same alpha type");
817 return; 816 return;
818 } 817 }
819 818
820 SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); 819 SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height());
821 SkAutoPixmapStorage apm; 820 SkAutoPixmapStorage apm;
822 SkAutoPixmapStorage bpm; 821 SkAutoPixmapStorage bpm;
823 822
824 apm.alloc(info); 823 apm.alloc(info);
825 bpm.alloc(info); 824 bpm.alloc(info);
826 825
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 buffer)) { 940 buffer)) {
942 ERRORF(reporter, "deferred image size succeeded but creation fai led."); 941 ERRORF(reporter, "deferred image size succeeded but creation fai led.");
943 } else { 942 } else {
944 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 943 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
945 sk_sp<SkImage> newImage( 944 sk_sp<SkImage> newImage(
946 SkImage::MakeFromDeferredTextureImageData(context, buffe r, budgeted)); 945 SkImage::MakeFromDeferredTextureImageData(context, buffe r, budgeted));
947 REPORTER_ASSERT(reporter, newImage != nullptr); 946 REPORTER_ASSERT(reporter, newImage != nullptr);
948 if (newImage) { 947 if (newImage) {
949 // Scale the image in software for comparison. 948 // Scale the image in software for comparison.
950 SkImageInfo scaled_info = SkImageInfo::MakeN32( 949 SkImageInfo scaled_info = SkImageInfo::MakeN32(
951 image->width() / testCase.fExpectedScaleFactor, 950 image->width() / testCase.fE xpectedScaleFactor,
952 image->height() / testCase.fExpectedScaleFactor, 951 image->height() / testCase.f ExpectedScaleFactor,
953 image->isOpaque() ? kOpaque_SkAlphaType : kPremu l_SkAlphaType); 952 image->alphaType());
954 SkAutoPixmapStorage scaled; 953 SkAutoPixmapStorage scaled;
955 scaled.alloc(scaled_info); 954 scaled.alloc(scaled_info);
956 image->scalePixels(scaled, testCase.fExpectedQuality); 955 image->scalePixels(scaled, testCase.fExpectedQuality);
957 sk_sp<SkImage> scaledImage = SkImage::MakeRasterCopy(sca led); 956 sk_sp<SkImage> scaledImage = SkImage::MakeRasterCopy(sca led);
958 check_images_same(reporter, scaledImage.get(), newImage. get()); 957 check_images_same(reporter, scaledImage.get(), newImage. get());
959 } 958 }
960 // The other context should not be able to create images fro m texture data 959 // The other context should not be able to create images fro m texture data
961 // created by the original context. 960 // created by the original context.
962 sk_sp<SkImage> newImage2(SkImage::MakeFromDeferredTextureIma geData( 961 sk_sp<SkImage> newImage2(SkImage::MakeFromDeferredTextureIma geData(
963 otherContextInfo.grContext(), buffer, budgeted)); 962 otherContextInfo.grContext(), buffer, budgeted));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 SkBitmap bm1; 1016 SkBitmap bm1;
1018 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); 1017 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType));
1019 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); 1018 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
1020 1019
1021 SkBitmap bm2; 1020 SkBitmap bm2;
1022 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); 1021 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
1023 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); 1022 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0);
1024 1023
1025 REPORTER_ASSERT(reporter, equal(bm0, bm2)); 1024 REPORTER_ASSERT(reporter, equal(bm0, bm2));
1026 } 1025 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFBitmap.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698