diff options
author | Brian Salomon <bsalomon@google.com> | 2018-03-15 12:16:02 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-15 19:41:26 +0000 |
commit | 6a426c1d72aba0e37794fb8043cb71645eed4110 (patch) | |
tree | 73ba6627156ddb9e12f482597d08df20beade200 | |
parent | 1a114377898ae10c943695594223e447bee5aeb0 (diff) |
Cleanup SkImage YUV texture factories.
Remove unused GrBackendObject variants.
Add versions without redundant size param.
Make this work with GrBackendTextures that weren't created with a GrPixelConfig.
Change-Id: Ic1bbf5f2817cebab938b4f31000126a6ab5c44d5
Reviewed-on: https://skia-review.googlesource.com/114460
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | docs/SkImage_Reference.bmh | 54 | ||||
-rw-r--r-- | gm/imagefromyuvtextures.cpp | 7 | ||||
-rw-r--r-- | include/core/SkImage.h | 76 | ||||
-rw-r--r-- | include/gpu/GrBackendSurface.h | 1 | ||||
-rw-r--r-- | src/image/SkImage.cpp | 22 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 156 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.h | 6 |
7 files changed, 115 insertions, 207 deletions
diff --git a/docs/SkImage_Reference.bmh b/docs/SkImage_Reference.bmh index f45862af5f..b94e4331b3 100644 --- a/docs/SkImage_Reference.bmh +++ b/docs/SkImage_Reference.bmh @@ -649,25 +649,21 @@ Recognized formats vary by GPU back-end. # ------------------------------------------------------------------------------ #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendObject yuvTextureHandles[3], - const SkISize yuvSizes[3], + const GrBackendTexture yuvTextures[3], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr) #In Constructor #Line # creates Image from YUV_ColorSpace data in three planes ## -Creates Image from copy of yuvTextureHandles, an array of textures on GPU. -yuvTextureHandles contain pixels for YUV planes of Image. -yuvSizes contain dimensions for each pixel plane. Dimensions must be greater than -zero but may differ from plane to plane. Returned Image has the dimensions -yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. +Creates Image from copy of yuvTextures, an array of textures on GPU. +yuvTextures contain pixels for YUV planes of Image. Returned Image has the dimensions +yuvTextures[0]. yuvColorSpace describes how YUV colors convert to RGB colors. #Param context GPU_Context ## #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace ## -#Param yuvTextureHandles array of YUV textures on GPU ## -#Param yuvSizes dimensions of YUV textures ## +#Param yuvTextures array of YUV textures on GPU ## #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## #Param colorSpace range of colors; may be nullptr ## @@ -688,22 +684,17 @@ should this be moved to chrome only? # ------------------------------------------------------------------------------ #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendTexture yuvTextureHandles[3], + const GrBackendTexture yuvTextures[3], const SkISize yuvSizes[3], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr) - -Creates Image from copy of yuvTextureHandles, an array of textures on GPU. -yuvTextureHandles contain pixels for YUV planes of Image. -yuvSizes contain dimensions for each pixel plane. Dimensions must be greater than -zero but may differ from plane to plane. Returned Image has the dimensions -yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. +This version of MakeFromYUVTexturesCopy is over specified and should not be used. #Param context GPU_Context ## #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace ## -#Param yuvTextureHandles array of YUV textures on GPU ## +#Param yuvTextures array of YUV textures on GPU ## #Param yuvSizes dimensions of YUV textures ## #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## #Param colorSpace range of colors; may be nullptr ## @@ -726,27 +717,24 @@ should this be moved to chrome only? #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendObject nv12TextureHandles[2], - const SkISize nv12Sizes[2], + const GrBackendTexture nv12Textures[2], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr) #In Constructor -#Line # creates Image from YUV_ColorSpace data in two planes ## +#Line # creates Image from YUV_ColorSpace data in three planes ## Creates Image from copy of nv12TextureHandles, an array of textures on GPU. -nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. -nv12TextureHandles[1] contains pixels for YUV_Component_U plane, +nv12Textures[0] contains pixels for YUV_Component_Y plane. +nv12Textures[1] contains pixels for YUV_Component_U plane, followed by pixels for YUV_Component_V plane. -nv12Sizes contain dimensions for each pixel plane. Dimensions must be greater than -zero but may differ from plane to plane. Returned Image has the dimensions -nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. +Returned Image has the dimensions +nv12Textures[2]. yuvColorSpace describes how YUV colors convert to RGB colors. #Param context GPU_Context ## #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace ## -#Param nv12TextureHandles array of YUV textures on GPU ## -#Param nv12Sizes dimensions of YUV textures ## +#Param nv12Textures array of YUV textures on GPU ## #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## #Param colorSpace range of colors; may be nullptr ## @@ -768,24 +756,18 @@ should this be moved to chrome only? #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendTexture nv12TextureHandles[2], + const GrBackendTexture nv12Textures[2], const SkISize nv12Sizes[2], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr) -Creates Image from copy of nv12TextureHandles, an array of textures on GPU. -nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. -nv12TextureHandles[1] contains pixels for YUV_Component_U plane, -followed by pixels for YUV_Component_V plane. -nv12Sizes contain dimensions for each pixel plane. Dimensions must be greater than -zero but may differ from plane to plane. Returned Image has the dimensions -nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. +This version of MakeFromYUVTexturesCopy is over specified and should not be used. #Param context GPU_Context ## #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace ## -#Param nv12TextureHandles array of YUV textures on GPU ## +#Param nv12Textures array of YUV textures on GPU ## #Param nv12Sizes dimensions of YUV textures ## #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## #Param colorSpace range of colors; may be nullptr ## diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp index 526350c734..4db805d60e 100644 --- a/gm/imagefromyuvtextures.cpp +++ b/gm/imagefromyuvtextures.cpp @@ -137,11 +137,6 @@ protected: constexpr SkScalar kPad = 10.f; - SkISize sizes[] = { - { fYUVBmps[0].width(), fYUVBmps[0].height()}, - { fYUVBmps[1].width(), fYUVBmps[1].height()}, - { fYUVBmps[2].width(), fYUVBmps[2].height()}, - }; SkTArray<sk_sp<SkImage>> images; images.push_back(fRGBImage); for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) { @@ -149,7 +144,7 @@ protected: this->createYUVTextures(context, yuvTextures); images.push_back(SkImage::MakeFromYUVTexturesCopy(context, static_cast<SkYUVColorSpace>(space), - yuvTextures, sizes, + yuvTextures, kTopLeft_GrSurfaceOrigin)); this->deleteYUVTextures(context, yuvTextures); } diff --git a/include/core/SkImage.h b/include/core/SkImage.h index d8612f01e9..c404643171 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -326,92 +326,54 @@ public: SkAlphaType alphaType = kPremul_SkAlphaType, sk_sp<SkColorSpace> colorSpace = nullptr); - /** Creates SkImage from copy of yuvTextureHandles, an array of textures on GPU. - yuvTextureHandles contain pixels for YUV planes of SkImage. - yuvSizes contain dimensions for each pixel plane. Dimensions must be greater than - zero but may differ from plane to plane. Returned SkImage has the dimensions - yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. + /** Creates SkImage from copy of yuvTextures, an array of textures on GPU. + yuvTextures contain pixels for YUV planes of SkImage. + Returned SkImage has the dimensions yuvTextures[0]. yuvColorSpace describes how YUV colors + convert to RGB colors. @param context GPU context @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace - @param yuvTextureHandles array of YUV textures on GPU - @param yuvSizes dimensions of YUV textures + @param yuvTextures array of YUV textures on GPU @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin @param colorSpace range of colors; may be nullptr @return created SkImage, or nullptr */ static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendObject yuvTextureHandles[3], + const GrBackendTexture yuvTextures[3], + GrSurfaceOrigin surfaceOrigin, + sk_sp<SkColorSpace> colorSpace = nullptr); + /** Deprecated version that takes a redunant array of sizes of the textures. */ + static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, + const GrBackendTexture yuvTextures[3], const SkISize yuvSizes[3], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr); /** Creates SkImage from copy of nv12TextureHandles, an array of textures on GPU. - nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. - nv12TextureHandles[1] contains pixels for YUV_Component_U plane, + yuvTextures[0] contains pixels for YUV_Component_Y plane. + yuvTextures[1] contains pixels for YUV_Component_U plane, followed by pixels for YUV_Component_V plane. - nv12Sizes contain dimensions for each pixel plane. Dimensions must be greater than - zero but may differ from plane to plane. Returned SkImage has the dimensions - nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. + Returned SkImage has the dimensions nv12Textures[0]. yuvColorSpace describes how YUV colors + convert to RGB colors. @param context GPU context @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace - @param nv12TextureHandles array of YUV textures on GPU - @param nv12Sizes dimensions of YUV textures + @param nv12Textures array of YUV textures on GPU @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin @param colorSpace range of colors; may be nullptr @return created SkImage, or nullptr */ static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendObject nv12TextureHandles[2], - const SkISize nv12Sizes[2], + const GrBackendTexture nv12Textures[2], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr); - - /** Creates SkImage from copy of yuvTextureHandles, an array of textures on GPU. - yuvTextureHandles contain pixels for YUV planes of SkImage. - yuvSizes contain dimensions for each pixel plane. Dimensions must be greater than - zero but may differ from plane to plane. Returned SkImage has the dimensions - yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. - - @param context GPU context - @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, - kRec709_SkYUVColorSpace - @param yuvTextureHandles array of YUV textures on GPU - @param yuvSizes dimensions of YUV textures - @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendTexture yuvTextureHandles[3], - const SkISize yuvSizes[3], - GrSurfaceOrigin surfaceOrigin, - sk_sp<SkColorSpace> colorSpace = nullptr); - - /** Creates SkImage from copy of nv12TextureHandles, an array of textures on GPU. - nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. - nv12TextureHandles[1] contains pixels for YUV_Component_U plane, - followed by pixels for YUV_Component_V plane. - nv12Sizes contain dimensions for each pixel plane. Dimensions must be greater than - zero but may differ from plane to plane. Returned SkImage has the dimensions - nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. - - @param context GPU context - @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, - kRec709_SkYUVColorSpace - @param nv12TextureHandles array of YUV textures on GPU - @param nv12Sizes dimensions of YUV textures - @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ + /** Deprecated version that takes a redunant array of sizes of the textures. */ static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, - const GrBackendTexture nv12TextureHandles[2], + const GrBackendTexture nv12Textures[2], const SkISize nv12Sizes[2], GrSurfaceOrigin surfaceOrigin, sk_sp<SkColorSpace> colorSpace = nullptr); diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index a57edcd9d1..1312257805 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -148,6 +148,7 @@ public: private: // Friending for access to the GrPixelConfig friend class SkImage; + friend class SkImage_Gpu; friend class SkSurface; friend class GrBackendTextureImageGenerator; friend class GrProxyProvider; diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 4eebef7eae..2bea441f48 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -375,16 +375,30 @@ sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, } sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space, - const GrBackendObject yuvTextureHandles[3], - const SkISize yuvSizes[3], + const GrBackendTexture[3], + const SkISize[3], GrSurfaceOrigin origin, sk_sp<SkColorSpace> imageColorSpace) { return nullptr; } sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space, - const GrBackendTexture yuvTextureHandles[3], - const SkISize yuvSizes[3], + const GrBackendTexture[3], + GrSurfaceOrigin origin, + sk_sp<SkColorSpace> imageColorSpace) { + return nullptr; +} + +sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace space, + const GrBackendTexture[2], + const SkISize[2], + GrSurfaceOrigin origin, + sk_sp<SkColorSpace> imageColorSpace) { + return nullptr; +} + +sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace space, + const GrBackendTexture[2], GrSurfaceOrigin origin, sk_sp<SkColorSpace> imageColorSpace) { return nullptr; diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index ef8f39c669..6ab2ddc0b8 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -379,54 +379,27 @@ sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, return MakeFromAdoptedTexture(ctx, texCopy, origin, at, cs); } -static GrBackendTexture make_backend_texture_from_handle(GrBackend backend, - int width, int height, - GrPixelConfig config, - GrBackendObject handle) { - switch (backend) { - case kOpenGL_GrBackend: { - const GrGLTextureInfo* glInfo = (const GrGLTextureInfo*)(handle); - return GrBackendTexture(width, height, config, *glInfo); - } -#ifdef SK_VULKAN - case kVulkan_GrBackend: { - const GrVkImageInfo* vkInfo = (const GrVkImageInfo*)(handle); - return GrBackendTexture(width, height, *vkInfo); - } -#endif - case kMock_GrBackend: { - const GrMockTextureInfo* mockInfo = (const GrMockTextureInfo*)(handle); - return GrBackendTexture(width, height, GrMipMapped::kNo, *mockInfo); - } - default: - return GrBackendTexture(); - } -} - -static bool are_yuv_sizes_valid(const SkISize yuvSizes[], bool nv12) { - if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || - yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0) { - return false; - } - if (!nv12 && (yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0)) { - return false; - } - - return true; -} - -static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpace colorSpace, - bool nv12, - const GrBackendTexture yuvBackendTextures[], - const SkISize yuvSizes[], - GrSurfaceOrigin origin, - sk_sp<SkColorSpace> imageColorSpace) { +sk_sp<SkImage> SkImage_Gpu::MakeFromYUVTexturesCopyImpl( + GrContext* ctx, SkYUVColorSpace colorSpace, bool nv12, + const GrBackendTexture yuvBackendTexturesOrig[], GrSurfaceOrigin origin, + sk_sp<SkColorSpace> imageColorSpace) { GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); - if (!are_yuv_sizes_valid(yuvSizes, nv12)) { - return nullptr; + GrBackendTexture yuvBackendTextures[]{ + yuvBackendTexturesOrig[0], + yuvBackendTexturesOrig[1], + yuvBackendTexturesOrig[2], + }; + auto ct = nv12 ? kRGBA_8888_SkColorType : kAlpha_8_SkColorType; + for (int i = 0; i < (nv12 ? 2 : 3); ++i) { + if (yuvBackendTextures[i].fConfig == kUnknown_GrPixelConfig) { + if (!validate_backend_texture(ctx, yuvBackendTextures[i], + &yuvBackendTextures[i].fConfig, ct, kPremul_SkAlphaType, + nullptr)) { + return nullptr; + } + } } - sk_sp<GrTextureProxy> yProxy = proxyProvider->wrapBackendTexture(yuvBackendTextures[0], origin); sk_sp<GrTextureProxy> uProxy = proxyProvider->wrapBackendTexture(yuvBackendTextures[1], origin); sk_sp<GrTextureProxy> vProxy; @@ -440,8 +413,8 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac return nullptr; } - const int width = yuvSizes[0].fWidth; - const int height = yuvSizes[0].fHeight; + const int width = yuvBackendTextures[0].width(); + const int height = yuvBackendTextures[0].height(); // Needs to be a render target in order to draw to it for the yuv->rgb conversion. sk_sp<GrRenderTargetContext> renderTargetContext( @@ -454,8 +427,11 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac GrPaint paint; paint.setPorterDuffXPFactory(SkBlendMode::kSrc); - paint.addColorFragmentProcessor(GrYUVtoRGBEffect::Make(yProxy, uProxy, vProxy, - yuvSizes, colorSpace, nv12)); + SkISize sizes[] = {{yuvBackendTextures[0].width(), yuvBackendTextures[0].height()}, + {yuvBackendTextures[1].width(), yuvBackendTextures[1].height()}, + {yuvBackendTextures[2].width(), yuvBackendTextures[2].height()}}; + paint.addColorFragmentProcessor( + GrYUVtoRGBEffect::Make(yProxy, uProxy, vProxy, sizes, colorSpace, nv12)); const SkRect rect = SkRect::MakeIWH(width, height); @@ -473,77 +449,49 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac SkBudgeted::kYes); } -static sk_sp<SkImage> make_from_yuv_objects_copy(GrContext* ctx, SkYUVColorSpace colorSpace, - bool nv12, - const GrBackendObject yuvTextureHandles[], - const SkISize yuvSizes[], - GrSurfaceOrigin origin, - sk_sp<SkColorSpace> imageColorSpace) { - if (!are_yuv_sizes_valid(yuvSizes, nv12)) { - return nullptr; - } - - GrBackendTexture backendTextures[3]; - - const GrPixelConfig kConfig = nv12 ? kRGBA_8888_GrPixelConfig : kAlpha_8_GrPixelConfig; - - GrBackend backend = ctx->contextPriv().getBackend(); - backendTextures[0] = make_backend_texture_from_handle(backend, - yuvSizes[0].fWidth, - yuvSizes[0].fHeight, - kConfig, - yuvTextureHandles[0]); - backendTextures[1] = make_backend_texture_from_handle(backend, - yuvSizes[1].fWidth, - yuvSizes[1].fHeight, - kConfig, - yuvTextureHandles[1]); - - if (!nv12) { - backendTextures[2] = make_backend_texture_from_handle(backend, - yuvSizes[2].fWidth, - yuvSizes[2].fHeight, - kConfig, - yuvTextureHandles[2]); - } - - return make_from_yuv_textures_copy(ctx, colorSpace, nv12, - backendTextures, yuvSizes, origin, - std::move(imageColorSpace)); +sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, + const GrBackendTexture yuvTextures[3], + GrSurfaceOrigin origin, + sk_sp<SkColorSpace> imageColorSpace) { + return SkImage_Gpu::MakeFromYUVTexturesCopyImpl(ctx, colorSpace, false, yuvTextures, + origin, std::move(imageColorSpace)); } sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, - const GrBackendObject yuvTextureHandles[3], + const GrBackendTexture yuvTextures[3], const SkISize yuvSizes[3], GrSurfaceOrigin origin, sk_sp<SkColorSpace> imageColorSpace) { - return make_from_yuv_objects_copy(ctx, colorSpace, false, yuvTextureHandles, yuvSizes, origin, - std::move(imageColorSpace)); + for (int i = 0; i < 3; ++i) { + if (yuvSizes[i].fWidth != yuvTextures[i].width() || + yuvSizes[i].fHeight != yuvTextures[i].height()) { + return nullptr; + } + } + return SkImage::MakeFromYUVTexturesCopy(ctx, colorSpace, yuvTextures, origin, + std::move(imageColorSpace)); } sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, - const GrBackendObject yuvTextureHandles[2], - const SkISize yuvSizes[2], + const GrBackendTexture nv12Textures[2], GrSurfaceOrigin origin, sk_sp<SkColorSpace> imageColorSpace) { - return make_from_yuv_objects_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin, - std::move(imageColorSpace)); -} - -sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, - const GrBackendTexture yuvBackendTextures[3], - const SkISize yuvSizes[3], GrSurfaceOrigin origin, - sk_sp<SkColorSpace> imageColorSpace) { - return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvBackendTextures, yuvSizes, origin, - std::move(imageColorSpace)); + return SkImage_Gpu::MakeFromYUVTexturesCopyImpl(ctx, colorSpace, true, nv12Textures, + origin, std::move(imageColorSpace)); } sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, - const GrBackendTexture yuvBackendTextures[2], + const GrBackendTexture nv12Textures[2], const SkISize yuvSizes[2], GrSurfaceOrigin origin, sk_sp<SkColorSpace> imageColorSpace) { - return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvBackendTextures, yuvSizes, origin, - std::move(imageColorSpace)); + for (int i = 0; i < 2; ++i) { + if (yuvSizes[i].fWidth != nv12Textures[i].width() || + yuvSizes[i].fHeight != nv12Textures[i].height()) { + return nullptr; + } + } + return SkImage_Gpu::MakeFromNV12TexturesCopy(ctx, colorSpace, nv12Textures, origin, + std::move(imageColorSpace)); } static sk_sp<SkImage> create_image_from_maker(GrContext* context, GrTextureMaker* maker, diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 3c536a4013..e1fd35a766 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -114,6 +114,12 @@ public: TextureReleaseProc textureReleaseProc, TextureContext textureContext); + /** Implementation of MakeFromYUVTexturesCopy and MakeFromNV12TexturesCopy */ + static sk_sp<SkImage> MakeFromYUVTexturesCopyImpl( + GrContext* ctx, SkYUVColorSpace colorSpace, bool nv12, + const GrBackendTexture yuvBackendTextures[], GrSurfaceOrigin origin, + sk_sp<SkColorSpace> imageColorSpace); + bool onIsValid(GrContext*) const override; private: |