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 "DMGpuSupport.h" | 10 #include "DMGpuSupport.h" |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 SkBudge
ted::kNo)); | 820 SkBudge
ted::kNo)); |
821 if (!texImage) { | 821 if (!texImage) { |
822 ERRORF(reporter, "NewTextureFromPixmap failed."); | 822 ERRORF(reporter, "NewTextureFromPixmap failed."); |
823 } else { | 823 } else { |
824 check_images_same(reporter, image, texImage); | 824 check_images_same(reporter, image, texImage); |
825 } | 825 } |
826 } | 826 } |
827 } | 827 } |
828 } | 828 } |
829 | 829 |
| 830 DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContex
t) { |
| 831 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
| 832 |
| 833 GrContextFactory otherFactory; |
| 834 GrContextFactory::ContextInfo otherContextInfo = |
| 835 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); |
| 836 |
| 837 glContext->makeCurrent(); |
| 838 REPORTER_ASSERT(reporter, proxy); |
| 839 struct { |
| 840 std::function<SkImage *()> fImageFactory; |
| 841 bool fExpectation; |
| 842 } testCases[] = { |
| 843 { create_image, true }, |
| 844 { create_codec_image, true }, |
| 845 { create_data_image, true }, |
| 846 { create_picture_image, false }, |
| 847 { [context] { return create_gpu_image(context); }, false }, |
| 848 // Create a texture image in a another GrContext. |
| 849 { [glContext, otherContextInfo] { |
| 850 otherContextInfo.fGLContext->makeCurrent(); |
| 851 SkImage *otherContextImage = create_gpu_image(otherContextInfo.fGrCo
ntext); |
| 852 glContext->makeCurrent(); |
| 853 return otherContextImage; |
| 854 }, false }, |
| 855 }; |
| 856 |
| 857 |
| 858 for (auto testCase : testCases) { |
| 859 SkAutoTUnref<SkImage> image(testCase.fImageFactory()); |
| 860 |
| 861 // This isn't currently used in the implementation, just set any old val
ues. |
| 862 SkImage::DeferredTextureImageUsageParams params; |
| 863 params.fQuality = kLow_SkFilterQuality; |
| 864 params.fMatrix = SkMatrix::I(); |
| 865 |
| 866 size_t size = image->getDeferredTextureImageData(*proxy, ¶ms, 1, nul
lptr); |
| 867 |
| 868 static const char *const kFS[] = { "fail", "succeed" }; |
| 869 if (SkToBool(size) != testCase.fExpectation) { |
| 870 ERRORF(reporter, "This image was expected to %s but did not.", |
| 871 kFS[testCase.fExpectation]); |
| 872 } |
| 873 if (size) { |
| 874 void* buffer = sk_malloc_throw(size); |
| 875 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t
>(buffer) + 3); |
| 876 if (image->getDeferredTextureImageData(*proxy, ¶ms, 1, misaligne
d)) { |
| 877 ERRORF(reporter, "Should fail when buffer is misaligned."); |
| 878 } |
| 879 if (!image->getDeferredTextureImageData(*proxy, ¶ms, 1, buffer))
{ |
| 880 ERRORF(reporter, "deferred image size succeeded but creation fai
led."); |
| 881 } else { |
| 882 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 883 SkAutoTUnref<SkImage> newImage( |
| 884 SkImage::NewFromDeferredTextureImageData(context, buffer
, budgeted)); |
| 885 REPORTER_ASSERT(reporter, SkToBool(newImage)); |
| 886 if (newImage) { |
| 887 check_images_same(reporter, image, newImage); |
| 888 } |
| 889 // The other context should not be able to create images fro
m texture data |
| 890 // created by the original context. |
| 891 SkAutoTUnref<SkImage> newImage2(SkImage::NewFromDeferredText
ureImageData( |
| 892 otherContextInfo.fGrContext, buffer, budgeted)); |
| 893 REPORTER_ASSERT(reporter, !newImage2); |
| 894 glContext->makeCurrent(); |
| 895 } |
| 896 } |
| 897 sk_free(buffer); |
| 898 } |
| 899 } |
| 900 } |
830 #endif | 901 #endif |
OLD | NEW |