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> |
11 #include "DMGpuSupport.h" | 11 #include "DMGpuSupport.h" |
12 | 12 |
13 #include "SkAutoPixmapStorage.h" | 13 #include "SkAutoPixmapStorage.h" |
14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
16 #include "SkData.h" | 16 #include "SkData.h" |
17 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
18 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
19 #include "SkImage_Base.h" | 19 #include "SkImage_Base.h" |
20 #include "SkPicture.h" | 20 #include "SkPicture.h" |
21 #include "SkPictureRecorder.h" | 21 #include "SkPictureRecorder.h" |
22 #include "SkPixelSerializer.h" | 22 #include "SkPixelSerializer.h" |
23 #include "SkRRect.h" | 23 #include "SkRRect.h" |
24 #include "SkStream.h" | 24 #include "SkStream.h" |
25 #include "SkSurface.h" | 25 #include "SkSurface.h" |
26 #include "SkUtils.h" | 26 #include "SkUtils.h" |
27 #include "Test.h" | 27 #include "Test.h" |
28 | 28 |
| 29 #if SK_SUPPORT_GPU |
| 30 #include "GrGpu.h" |
| 31 #endif |
| 32 |
29 using namespace sk_gpu_test; | 33 using namespace sk_gpu_test; |
30 | 34 |
31 static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect
* subsetA, | 35 static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect
* subsetA, |
32 SkImage* b) { | 36 SkImage* b) { |
33 const int widthA = subsetA ? subsetA->width() : a->width(); | 37 const int widthA = subsetA ? subsetA->width() : a->width(); |
34 const int heightA = subsetA ? subsetA->height() : a->height(); | 38 const int heightA = subsetA ? subsetA->height() : a->height(); |
35 | 39 |
36 REPORTER_ASSERT(reporter, widthA == b->width()); | 40 REPORTER_ASSERT(reporter, widthA == b->width()); |
37 REPORTER_ASSERT(reporter, heightA == b->height()); | 41 REPORTER_ASSERT(reporter, heightA == b->height()); |
38 | 42 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 #endif | 742 #endif |
739 | 743 |
740 #if SK_SUPPORT_GPU | 744 #if SK_SUPPORT_GPU |
741 struct TextureReleaseChecker { | 745 struct TextureReleaseChecker { |
742 TextureReleaseChecker() : fReleaseCount(0) {} | 746 TextureReleaseChecker() : fReleaseCount(0) {} |
743 int fReleaseCount; | 747 int fReleaseCount; |
744 static void Release(void* self) { | 748 static void Release(void* self) { |
745 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; | 749 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; |
746 } | 750 } |
747 }; | 751 }; |
748 static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM
Color expected) { | 752 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
txInfo) { |
749 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 753 const int kWidth = 10; |
750 SkPMColor pixel; | 754 const int kHeight = 10; |
751 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0,
0)); | 755 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]); |
752 REPORTER_ASSERT(reporter, pixel == expected); | 756 GrBackendTextureDesc backendDesc; |
753 } | 757 backendDesc.fConfig = kRGBA_8888_GrPixelConfig; |
754 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, ctxInfo)
{ | 758 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
755 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider(); | 759 backendDesc.fWidth = kWidth; |
756 const int w = 10; | 760 backendDesc.fHeight = kHeight; |
757 const int h = 10; | 761 backendDesc.fSampleCnt = 0; |
758 SkPMColor storage[w * h]; | 762 backendDesc.fTextureHandle = ctxInfo.grContext()->getGpu()->createTestingOnl
yBackendTexture( |
759 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED); | 763 pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true); |
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 | 764 |
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; | 765 TextureReleaseChecker releaseChecker; |
782 sk_sp<SkImage> refImg( | 766 sk_sp<SkImage> refImg( |
783 SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlp
haType, | 767 SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlp
haType, |
784 TextureReleaseChecker::Release, &releaseChecker
)); | 768 TextureReleaseChecker::Release, &releaseChecker
)); |
785 | 769 |
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 | 770 // Now exercise the release proc |
801 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); | 771 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); |
802 refImg.reset(nullptr); // force a release of the image | 772 refImg.reset(nullptr); // force a release of the image |
803 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); | 773 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); |
| 774 |
| 775 ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendDesc.f
TextureHandle); |
804 } | 776 } |
805 | 777 |
806 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co
nst SkImage* b) { | 778 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()) { | 779 if (a->width() != b->width() || a->height() != b->height()) { |
808 ERRORF(reporter, "Images must have the same size"); | 780 ERRORF(reporter, "Images must have the same size"); |
809 return; | 781 return; |
810 } | 782 } |
811 if (a->isOpaque() != b->isOpaque()) { | 783 if (a->isOpaque() != b->isOpaque()) { |
812 ERRORF(reporter, "Images must have the same opaquness"); | 784 ERRORF(reporter, "Images must have the same opaquness"); |
813 return; | 785 return; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 otherContextInfo.grContext(), buffer, budgeted)); | 931 otherContextInfo.grContext(), buffer, budgeted)); |
960 REPORTER_ASSERT(reporter, !newImage2); | 932 REPORTER_ASSERT(reporter, !newImage2); |
961 testContext->makeCurrent(); | 933 testContext->makeCurrent(); |
962 } | 934 } |
963 } | 935 } |
964 sk_free(buffer); | 936 sk_free(buffer); |
965 } | 937 } |
966 } | 938 } |
967 } | 939 } |
968 #endif | 940 #endif |
OLD | NEW |