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 <initializer_list> | 9 #include <initializer_list> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 test_peek(reporter, image.get(), false); | 731 test_peek(reporter, image.get(), false); |
| 732 } | 732 } |
| 733 #if SK_SUPPORT_GPU | 733 #if SK_SUPPORT_GPU |
| 734 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, ctxInfo) { | 734 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, ctxInfo) { |
| 735 sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext())); | 735 sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext())); |
| 736 test_peek(reporter, image.get(), false); | 736 test_peek(reporter, image.get(), false); |
| 737 } | 737 } |
| 738 #endif | 738 #endif |
| 739 | 739 |
| 740 #if SK_SUPPORT_GPU | 740 #if SK_SUPPORT_GPU |
| 741 struct TextureReleaseChecker { | |
| 742 TextureReleaseChecker() : fReleaseCount(0) {} | |
| 743 int fReleaseCount; | |
| 744 static void Release(void* self) { | |
| 745 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; | |
| 746 } | |
| 747 }; | |
| 748 static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM Color expected) { | |
| 749 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | |
| 750 SkPMColor pixel; | |
| 751 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0, 0)); | |
| 752 REPORTER_ASSERT(reporter, pixel == expected); | |
| 753 } | |
| 754 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, ctxInfo) { | |
| 755 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider(); | |
| 756 const int w = 10; | |
| 757 const int h = 10; | |
| 758 SkPMColor storage[w * h]; | |
| 759 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED); | |
| 760 sk_memset32(storage, expected0, w * h); | |
| 761 GrSurfaceDesc desc; | |
| 762 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo r readpixels(); | |
| 763 desc.fOrigin = kDefault_GrSurfaceOrigin; | |
| 764 desc.fWidth = w; | |
| 765 desc.fHeight = h; | |
| 766 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 767 desc.fSampleCnt = 0; | |
| 768 SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, SkBudgeted::kNo, s torage, w * 4)); | |
| 769 if (!tex) { | |
| 770 REPORTER_ASSERT(reporter, false); | |
| 771 return; | |
| 772 } | |
| 773 | |
| 774 GrBackendTextureDesc backendDesc; | |
| 775 backendDesc.fConfig = kSkia8888_GrPixelConfig; | |
| 776 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 777 backendDesc.fWidth = w; | |
| 778 backendDesc.fHeight = h; | |
| 779 backendDesc.fSampleCnt = 0; | |
| 780 backendDesc.fTextureHandle = tex->getTextureHandle(); | |
| 781 TextureReleaseChecker releaseChecker; | |
| 782 sk_sp<SkImage> refImg( | |
| 783 SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlp haType, | |
| 784 TextureReleaseChecker::Release, &releaseChecker )); | |
| 785 | |
| 786 check_image_color(reporter, refImg.get(), expected0); | |
| 787 | |
| 788 // Now lets jam new colors into our "external" texture, and see if the image s notice | |
| 789 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); | |
| 790 sk_memset32(storage, expected1, w * h); | |
| 791 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); | |
| 792 | |
| 793 // The cpy'd one should still see the old color | |
| 794 #if 0 | |
| 795 // There is no guarantee that refImg sees the new color. We are free to have made a copy. Our | |
| 796 // write pixels call violated the contract with refImg and refImg is now und efined. | |
| 797 check_image_color(reporter, refImg, expected1); | |
| 798 #endif | |
| 799 | |
| 800 // Now exercise the release proc | |
|
robertphillips
2016/07/21 15:11:30
Do we test, somewhere else, that we correctly call
bsalomon
2016/07/21 15:16:00
Ah, that is probably worth testing (with a much sm
| |
| 801 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); | |
| 802 refImg.reset(nullptr); // force a release of the image | |
| 803 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); | |
| 804 } | |
| 805 | |
| 806 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co nst SkImage* b) { | 741 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co nst SkImage* b) { |
| 807 if (a->width() != b->width() || a->height() != b->height()) { | 742 if (a->width() != b->width() || a->height() != b->height()) { |
| 808 ERRORF(reporter, "Images must have the same size"); | 743 ERRORF(reporter, "Images must have the same size"); |
| 809 return; | 744 return; |
| 810 } | 745 } |
| 811 if (a->isOpaque() != b->isOpaque()) { | 746 if (a->isOpaque() != b->isOpaque()) { |
| 812 ERRORF(reporter, "Images must have the same opaquness"); | 747 ERRORF(reporter, "Images must have the same opaquness"); |
| 813 return; | 748 return; |
| 814 } | 749 } |
| 815 | 750 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 otherContextInfo.grContext(), buffer, budgeted)); | 894 otherContextInfo.grContext(), buffer, budgeted)); |
| 960 REPORTER_ASSERT(reporter, !newImage2); | 895 REPORTER_ASSERT(reporter, !newImage2); |
| 961 testContext->makeCurrent(); | 896 testContext->makeCurrent(); |
| 962 } | 897 } |
| 963 } | 898 } |
| 964 sk_free(buffer); | 899 sk_free(buffer); |
| 965 } | 900 } |
| 966 } | 901 } |
| 967 } | 902 } |
| 968 #endif | 903 #endif |
| OLD | NEW |