Support downscaling to max texture size when making cross-context images
This is one solution to https://github.com/flutter/flutter/issues/16454
Change-Id: Iacd59f07e1bf87b6caccb64df16ab8827dfc78b1
Reviewed-on: https://skia-review.googlesource.com/121342
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/docs/SkImage_Reference.bmh b/docs/SkImage_Reference.bmh
index 7d93555..32ddbe3 100644
--- a/docs/SkImage_Reference.bmh
+++ b/docs/SkImage_Reference.bmh
@@ -465,7 +465,8 @@
#Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
bool buildMips,
- SkColorSpace* dstColorSpace)
+ SkColorSpace* dstColorSpace,
+ bool limitToMaxTextureSize = false)
#In Constructor
#Line # creates Image from encoded data, and uploads to GPU ##
@@ -491,6 +492,7 @@
#Param data Image to decode ##
#Param buildMips create Image as Mip_Map if true ##
#Param dstColorSpace range of colors of matching Surface on GPU ##
+#Param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary ##
#Return created Image, or nullptr ##
@@ -512,7 +514,8 @@
#Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
bool buildMips,
- SkColorSpace* dstColorSpace)
+ SkColorSpace* dstColorSpace,
+ bool limitToMaxTextureSize = false)
#In Constructor
#Line # creates Image from Pixmap, and uploads to GPU ##
@@ -538,6 +541,7 @@
#Param pixmap Image_Info, pixel address, and row bytes ##
#Param buildMips create Image as Mip_Map if true ##
#Param dstColorSpace range of colors of matching Surface on GPU ##
+#Param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary ##
#Return created Image, or nullptr ##
@@ -1413,20 +1417,20 @@
#Example
#Image 3
#Platform gpu
- GrContext* grContext = canvas->getGrContext();
- if (!grContext) {
- canvas->drawString("GPU only!", 20, 40, SkPaint());
- return;
- }
- sk_sp<SkImage> imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, backEndTexture,
- kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
- GrBackendTexture textureFromImage = imageFromBackend->getBackendTexture(false);
- if (!textureFromImage.isValid()) {
- return;
- }
- sk_sp<SkImage> imageFromTexture = SkImage::MakeFromAdoptedTexture(grContext, textureFromImage,
- kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
- canvas->drawImage(imageFromTexture, 0, 0);
+ GrContext* grContext = canvas->getGrContext();
+ if (!grContext) {
+ canvas->drawString("GPU only!", 20, 40, SkPaint());
+ return;
+ }
+ sk_sp<SkImage> imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, backEndTexture,
+ kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
+ GrBackendTexture textureFromImage = imageFromBackend->getBackendTexture(false);
+ if (!textureFromImage.isValid()) {
+ return;
+ }
+ sk_sp<SkImage> imageFromTexture = SkImage::MakeFromAdoptedTexture(grContext, textureFromImage,
+ kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
+ canvas->drawImage(imageFromTexture, 0, 0);
canvas->drawImage(imageFromBackend, 128, 128);
##