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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 backendDesc.fConfig = kSkia8888_GrPixelConfig; | 775 backendDesc.fConfig = kSkia8888_GrPixelConfig; |
776 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | 776 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
777 backendDesc.fWidth = w; | 777 backendDesc.fWidth = w; |
778 backendDesc.fHeight = h; | 778 backendDesc.fHeight = h; |
779 backendDesc.fSampleCnt = 0; | 779 backendDesc.fSampleCnt = 0; |
780 backendDesc.fTextureHandle = tex->getTextureHandle(); | 780 backendDesc.fTextureHandle = tex->getTextureHandle(); |
781 TextureReleaseChecker releaseChecker; | 781 TextureReleaseChecker releaseChecker; |
782 sk_sp<SkImage> refImg( | 782 sk_sp<SkImage> refImg( |
783 SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlp
haType, | 783 SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlp
haType, |
784 TextureReleaseChecker::Release, &releaseChecker
)); | 784 TextureReleaseChecker::Release, &releaseChecker
)); |
785 sk_sp<SkImage> cpyImg(SkImage::MakeFromTextureCopy(ctxInfo.grContext(), back
endDesc, | |
786 kPremul_SkAlphaType)); | |
787 | 785 |
788 check_image_color(reporter, refImg.get(), expected0); | 786 check_image_color(reporter, refImg.get(), expected0); |
789 check_image_color(reporter, cpyImg.get(), expected0); | |
790 | 787 |
791 // Now lets jam new colors into our "external" texture, and see if the image
s notice | 788 // Now lets jam new colors into our "external" texture, and see if the image
s notice |
792 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); | 789 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); |
793 sk_memset32(storage, expected1, w * h); | 790 sk_memset32(storage, expected1, w * h); |
794 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF
lushWrites_PixelOp); | 791 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF
lushWrites_PixelOp); |
795 | 792 |
796 // The cpy'd one should still see the old color | 793 // The cpy'd one should still see the old color |
797 #if 0 | 794 #if 0 |
798 // There is no guarantee that refImg sees the new color. We are free to have
made a copy. Our | 795 // There is no guarantee that refImg sees the new color. We are free to have
made a copy. Our |
799 // write pixels call violated the contract with refImg and refImg is now und
efined. | 796 // write pixels call violated the contract with refImg and refImg is now und
efined. |
800 check_image_color(reporter, refImg, expected1); | 797 check_image_color(reporter, refImg, expected1); |
801 #endif | 798 #endif |
802 check_image_color(reporter, cpyImg.get(), expected0); | |
803 | 799 |
804 // Now exercise the release proc | 800 // Now exercise the release proc |
805 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); | 801 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); |
806 refImg.reset(nullptr); // force a release of the image | 802 refImg.reset(nullptr); // force a release of the image |
807 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); | 803 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); |
808 } | 804 } |
809 | 805 |
810 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co
nst SkImage* b) { | 806 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()) { | 807 if (a->width() != b->width() || a->height() != b->height()) { |
812 ERRORF(reporter, "Images must have the same size"); | 808 ERRORF(reporter, "Images must have the same size"); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 otherContextInfo.grContext(), buffer, budgeted)); | 959 otherContextInfo.grContext(), buffer, budgeted)); |
964 REPORTER_ASSERT(reporter, !newImage2); | 960 REPORTER_ASSERT(reporter, !newImage2); |
965 testContext->makeCurrent(); | 961 testContext->makeCurrent(); |
966 } | 962 } |
967 } | 963 } |
968 sk_free(buffer); | 964 sk_free(buffer); |
969 } | 965 } |
970 } | 966 } |
971 } | 967 } |
972 #endif | 968 #endif |
OLD | NEW |