829 {
832 enum class ShutdownSequence {
833 kFreeResult_DestroyContext,
834 kDestroyContext_FreeResult,
835 kFreeResult_ReleaseAndAbandon_DestroyContext,
836 kFreeResult_Abandon_DestroyContext,
837 kReleaseAndAbandon_FreeResult_DestroyContext,
838 kAbandon_FreeResult_DestroyContext,
839 kReleaseAndAbandon_DestroyContext_FreeResult,
840 kAbandon_DestroyContext_FreeResult,
841 };
844 for (auto sequence : {ShutdownSequence::kFreeResult_DestroyContext,
845 ShutdownSequence::kDestroyContext_FreeResult,
846 ShutdownSequence::kFreeResult_ReleaseAndAbandon_DestroyContext,
847 ShutdownSequence::kFreeResult_Abandon_DestroyContext,
848 ShutdownSequence::kReleaseAndAbandon_FreeResult_DestroyContext,
849 ShutdownSequence::kAbandon_FreeResult_DestroyContext,
850 ShutdownSequence::kReleaseAndAbandon_DestroyContext_FreeResult,
851 ShutdownSequence::kAbandon_DestroyContext_FreeResult}) {
852
853
854 if ((
type == skgpu::ContextType::kVulkan ||
type == skgpu::ContextType::kDirect3D) &&
855 (sequence == ShutdownSequence::kFreeResult_ReleaseAndAbandon_DestroyContext ||
856 sequence == ShutdownSequence::kFreeResult_Abandon_DestroyContext ||
857 sequence == ShutdownSequence::kReleaseAndAbandon_FreeResult_DestroyContext ||
858 sequence == ShutdownSequence::kReleaseAndAbandon_DestroyContext_FreeResult ||
859 sequence == ShutdownSequence::kAbandon_FreeResult_DestroyContext ||
860 sequence == ShutdownSequence::kAbandon_DestroyContext_FreeResult)) {
861 continue;
862 }
863 enum class ReadType {
865 kYUV,
867 };
868 for (ReadType readType : {ReadType::kRGBA, ReadType::kYUV, ReadType::kYUVA}) {
870 auto direct = factory.get(
type);
871 if (!direct) {
872 continue;
873 }
874
875
876 if (!direct->priv().caps()->transferFromSurfaceToBufferSupport()) {
877 continue;
878 }
880 if (!surf) {
881 continue;
882 }
883 AsyncContext cbContext;
884 switch (readType) {
885 case ReadType::kRGBA:
886 surf->asyncRescaleAndReadPixels(ii, ii.bounds(),
887 SkImage::RescaleGamma::kSrc,
888 SkImage::RescaleMode::kNearest,
890 break;
891 case ReadType::kYUV:
892 surf->asyncRescaleAndReadPixelsYUV420(
894 ii.dimensions(), SkImage::RescaleGamma::kSrc,
896 break;
897 case ReadType::kYUVA:
898 surf->asyncRescaleAndReadPixelsYUVA420(
900 ii.dimensions(), SkImage::RescaleGamma::kSrc,
902 break;
903 }
904
905 direct->submit();
906 while (!cbContext.fCalled) {
907 direct->checkAsyncWorkCompletion();
908 }
909 if (!cbContext.fResult) {
910 const char* readTypeStr;
911 switch (readType) {
912 case ReadType::kRGBA: readTypeStr = "rgba"; break;
913 case ReadType::kYUV: readTypeStr = "yuv"; break;
914 case ReadType::kYUVA: readTypeStr = "yuva"; break;
915 }
918 continue;
919 }
920
921
922 surf.reset();
923
924
925
926 switch (sequence) {
927 case ShutdownSequence::kFreeResult_DestroyContext:
928 case ShutdownSequence::kFreeResult_ReleaseAndAbandon_DestroyContext:
929 case ShutdownSequence::kFreeResult_Abandon_DestroyContext:
930 break;
931 case ShutdownSequence::kDestroyContext_FreeResult:
932 factory.destroyContexts();
933 break;
934 case ShutdownSequence::kReleaseAndAbandon_FreeResult_DestroyContext:
935 factory.releaseResourcesAndAbandonContexts();
936 break;
937 case ShutdownSequence::kAbandon_FreeResult_DestroyContext:
938 factory.abandonContexts();
939 break;
940 case ShutdownSequence::kReleaseAndAbandon_DestroyContext_FreeResult:
941 factory.releaseResourcesAndAbandonContexts();
942 factory.destroyContexts();
943 break;
944 case ShutdownSequence::kAbandon_DestroyContext_FreeResult:
945 factory.abandonContexts();
946 factory.destroyContexts();
947 break;
948 }
949 cbContext.fResult.reset();
950 switch (sequence) {
951 case ShutdownSequence::kFreeResult_ReleaseAndAbandon_DestroyContext:
952 factory.releaseResourcesAndAbandonContexts();
953 break;
954 case ShutdownSequence::kFreeResult_Abandon_DestroyContext:
955 factory.abandonContexts();
956 break;
957 case ShutdownSequence::kFreeResult_DestroyContext:
958 case ShutdownSequence::kDestroyContext_FreeResult:
959 case ShutdownSequence::kReleaseAndAbandon_FreeResult_DestroyContext:
960 case ShutdownSequence::kAbandon_FreeResult_DestroyContext:
961 case ShutdownSequence::kReleaseAndAbandon_DestroyContext_FreeResult:
962 case ShutdownSequence::kAbandon_DestroyContext_FreeResult:
963 break;
964 }
965 }
966 }
967 }
968}
static void async_callback(void *c, std::unique_ptr< const SkImage::AsyncReadResult > result)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kIdentity_SkYUVColorSpace
maps Y->R, U->G, V->B
static sk_sp< SkColorSpace > MakeSRGB()
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static const int kContextTypeCount
const char * ContextTypeName(skgpu::ContextType type)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)