Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "DMGpuSupport.h" | 9 #include "DMGpuSupport.h" |
| 10 | 10 |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 // write pixels call violated the contract with refImg and refImg is now und efined. | 730 // write pixels call violated the contract with refImg and refImg is now und efined. |
| 731 check_image_color(reporter, refImg, expected1); | 731 check_image_color(reporter, refImg, expected1); |
| 732 #endif | 732 #endif |
| 733 check_image_color(reporter, cpyImg, expected0); | 733 check_image_color(reporter, cpyImg, expected0); |
| 734 | 734 |
| 735 // Now exercise the release proc | 735 // Now exercise the release proc |
| 736 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); | 736 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); |
| 737 refImg.reset(nullptr); // force a release of the image | 737 refImg.reset(nullptr); // force a release of the image |
| 738 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); | 738 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); |
| 739 } | 739 } |
| 740 | |
| 741 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co nst SkImage* b) { | |
| 742 if (a->width() != b->width() || a->height() != b->height()) { | |
| 743 ERRORF(reporter, "Images must have the same size"); | |
| 744 return; | |
| 745 } | |
| 746 if (a->isOpaque() != b->isOpaque()) { | |
| 747 ERRORF(reporter, "Images must have the same opaquness"); | |
| 748 return; | |
| 749 } | |
| 750 | |
| 751 SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); | |
| 752 SkAutoPixmapStorage apm; | |
| 753 SkAutoPixmapStorage bpm; | |
| 754 | |
| 755 apm.alloc(info); | |
| 756 bpm.alloc(info); | |
| 757 | |
| 758 if (!a->readPixels(apm, 0, 0)) { | |
| 759 ERRORF(reporter, "Could not read image a's pixels"); | |
| 760 return; | |
| 761 } | |
| 762 if (!b->readPixels(bpm, 0, 0)) { | |
| 763 ERRORF(reporter, "Could not read image b's pixels"); | |
| 764 return; | |
| 765 } | |
| 766 | |
| 767 for (auto y = 0; y < info.height(); ++y) { | |
| 768 for (auto x = 0; x < info.width(); ++x) { | |
| 769 uint32_t pixelA = *apm.addr32(x, y); | |
| 770 uint32_t pixelB = *bpm.addr32(x, y); | |
| 771 if (pixelA != pixelB) { | |
| 772 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x", | |
| 773 x, y, pixelA, pixelB); | |
| 774 return; | |
| 775 } | |
| 776 } | |
| 777 } | |
| 778 } | |
| 779 | |
| 780 DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContex t) { | |
| 781 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | |
| 782 | |
| 783 GrContextFactory otherFactory; | |
| 784 GrContextFactory::ContextInfo otherContextInfo = | |
| 785 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); | |
| 786 | |
| 787 glContext->makeCurrent(); | |
| 788 REPORTER_ASSERT(reporter, proxy); | |
|
robertphillips
2016/03/08 18:43:10
stray ';' ?
bsalomon
2016/03/08 19:49:32
Done.
| |
| 789 struct {; | |
| 790 std::function<SkImage *()> fImageFactory; | |
| 791 bool fExpectation; | |
| 792 } testCases[] = { | |
| 793 { create_image, true }, | |
| 794 { create_codec_image, true }, | |
| 795 { create_data_image, true }, | |
| 796 { create_picture_image, false }, | |
| 797 { [context] { return create_gpu_image(context); }, false }, | |
| 798 // Create a texture image in a another GrContext. | |
| 799 { [glContext, otherContextInfo] { | |
| 800 otherContextInfo.fGLContext->makeCurrent(); | |
| 801 SkImage *otherContextImage = create_gpu_image(otherContextInfo.fGrCo ntext); | |
| 802 glContext->makeCurrent(); | |
| 803 return otherContextImage; | |
| 804 }, false }, | |
| 805 }; | |
| 806 | |
| 807 | |
| 808 for (auto testCase : testCases) { | |
| 809 SkAutoTUnref<SkImage> image(testCase.fImageFactory()); | |
| 810 | |
| 811 // This isn't currently used in the implementation, just set any old val ues. | |
| 812 SkImage::DeferredTextureImageUsageParams params; | |
| 813 params.fSrcRect = SkRect::MakeIWH(image->width(), image->height()); | |
| 814 params.fDstRect = params.fSrcRect; | |
| 815 params.fQuality = kLow_SkFilterQuality; | |
| 816 params.fViewMatrix = SkMatrix::I(); | |
| 817 | |
| 818 size_t size = image->getDeferredTextureImageSize(*proxy, ¶ms, 1); | |
| 819 | |
| 820 static const char *const kFS[] = { "fail", "succeed" }; | |
| 821 REPORTER_ASSERT_MESSAGE(reporter, SkToBool(size) == testCase.fExpectatio n, | |
| 822 "This image was expected to %s but did not.", | |
| 823 kFS[testCase.fExpectation]); | |
| 824 if (size) { | |
| 825 void* storage = sk_malloc_throw(size); | |
|
robertphillips
2016/03/08 18:43:10
td -> dti ?
bsalomon
2016/03/08 19:49:32
other changes obsoleted this (the type is gone).
| |
| 826 const SkImage::DeferredTextureImage* td; | |
| 827 td = image->createDeferredTextureImageInClientStorage(*proxy, ¶m s, 1, storage, | |
| 828 size/2); | |
| 829 REPORTER_ASSERT_MESSAGE(reporter, !td, "Should fail when allocation is undersized."); | |
| 830 | |
| 831 td = image->createDeferredTextureImageInClientStorage(*proxy, ¶m s, 1, nullptr, | |
| 832 size); | |
| 833 REPORTER_ASSERT_MESSAGE(reporter, !td, "Should fail when allocation is nullptr."); | |
| 834 td = image->createDeferredTextureImageInClientStorage(*proxy, ¶m s, 1, storage, | |
| 835 size); | |
| 836 if (!td) { | |
| 837 ERRORF(reporter, "deferred image size succeeded but creation fai led."); | |
| 838 } else { | |
| 839 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | |
| 840 SkAutoTUnref<SkImage> newImage( | |
| 841 SkImage::NewFromDeferredTextureImage(context, *td, budge ted)); | |
| 842 REPORTER_ASSERT(reporter, SkToBool(newImage)); | |
| 843 if (newImage) { | |
| 844 check_images_same(reporter, image, newImage); | |
| 845 } | |
| 846 // The other context should not be able to create images fro m texture data | |
| 847 // created by the original context. | |
| 848 SkAutoTUnref<SkImage> newImage2(SkImage::NewFromDeferredText ureImage( | |
| 849 otherContextInfo.fGrContext, *td, budgeted)); | |
| 850 REPORTER_ASSERT(reporter, !newImage2); | |
| 851 glContext->makeCurrent(); | |
| 852 } | |
| 853 } | |
| 854 sk_free(storage); | |
| 855 } | |
| 856 } | |
| 857 } | |
| 740 #endif | 858 #endif |
| OLD | NEW |