@@ -126,14 +126,21 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixels(const SkImageInfo& info,
126126 SkFilterQuality rescaleQuality,
127127 ReadPixelsCallback callback,
128128 ReadPixelsContext context) {
129+ auto dContext = fContext ->asDirectContext ();
130+ if (!dContext) {
131+ // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
132+ callback (context, nullptr );
133+ return ;
134+ }
129135 GrColorType ct = SkColorTypeToGrColorType (this ->colorType ());
130- auto ctx = GrSurfaceContext::Make (fContext . get () , fView , ct, this ->alphaType (),
136+ auto ctx = GrSurfaceContext::Make (dContext , fView , ct, this ->alphaType (),
131137 this ->refColorSpace ());
132138 if (!ctx) {
133139 callback (context, nullptr );
134140 return ;
135141 }
136- ctx->asyncRescaleAndReadPixels (info, srcRect, rescaleGamma, rescaleQuality, callback, context);
142+ ctx->asyncRescaleAndReadPixels (dContext, info, srcRect, rescaleGamma, rescaleQuality,
143+ callback, context);
137144}
138145
139146void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace,
@@ -144,14 +151,21 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpac
144151 SkFilterQuality rescaleQuality,
145152 ReadPixelsCallback callback,
146153 ReadPixelsContext context) {
154+ auto dContext = fContext ->asDirectContext ();
155+ if (!dContext) {
156+ // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
157+ callback (context, nullptr );
158+ return ;
159+ }
147160 GrColorType ct = SkColorTypeToGrColorType (this ->colorType ());
148- auto ctx = GrSurfaceContext::Make (fContext . get () , fView , ct, this ->alphaType (),
161+ auto ctx = GrSurfaceContext::Make (dContext , fView , ct, this ->alphaType (),
149162 this ->refColorSpace ());
150163 if (!ctx) {
151164 callback (context, nullptr );
152165 return ;
153166 }
154- ctx->asyncRescaleAndReadPixelsYUV420 (yuvColorSpace,
167+ ctx->asyncRescaleAndReadPixelsYUV420 (dContext,
168+ yuvColorSpace,
155169 std::move (dstColorSpace),
156170 srcRect,
157171 dstSize,
@@ -660,13 +674,13 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
660674 return nullptr ;
661675 }
662676
663- auto direct = GrAsDirectContext (context);
664- if (!direct ) {
677+ auto dContext = GrAsDirectContext (context);
678+ if (!dContext ) {
665679 SkDebugf (" Direct context required\n " );
666680 return nullptr ;
667681 }
668682
669- GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat (direct ,
683+ GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat (dContext ,
670684 hardwareBuffer,
671685 bufferDesc.format ,
672686 true );
@@ -680,7 +694,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
680694 GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr ;
681695
682696 GrBackendTexture backendTexture =
683- GrAHardwareBufferUtils::MakeBackendTexture (direct , hardwareBuffer,
697+ GrAHardwareBufferUtils::MakeBackendTexture (dContext , hardwareBuffer,
684698 bufferDesc.width , bufferDesc.height ,
685699 &deleteImageProc, &updateImageProc,
686700 &deleteImageCtx, false , backendFormat, true );
@@ -697,7 +711,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
697711
698712 GrColorType grColorType = SkColorTypeToGrColorType (colorType);
699713
700- GrProxyProvider* proxyProvider = direct ->priv ().proxyProvider ();
714+ GrProxyProvider* proxyProvider = dContext ->priv ().proxyProvider ();
701715 if (!proxyProvider) {
702716 return nullptr ;
703717 }
@@ -712,26 +726,26 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
712726 sk_sp<SkColorSpace> cs = pixmap.refColorSpace ();
713727 SkAlphaType at = pixmap.alphaType ();
714728
715- GrSwizzle swizzle = direct ->priv ().caps ()->getReadSwizzle (backendFormat, grColorType);
729+ GrSwizzle swizzle = dContext ->priv ().caps ()->getReadSwizzle (backendFormat, grColorType);
716730 GrSurfaceProxyView view (std::move (proxy), surfaceOrigin, swizzle);
717- sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp (direct ), kNeedNewImageUniqueID , view,
731+ sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp (dContext ), kNeedNewImageUniqueID , view,
718732 colorType, at, cs);
719733 if (!image) {
720734 return nullptr ;
721735 }
722736
723- GrDrawingManager* drawingManager = direct ->priv ().drawingManager ();
737+ GrDrawingManager* drawingManager = dContext ->priv ().drawingManager ();
724738 if (!drawingManager) {
725739 return nullptr ;
726740 }
727741
728- GrSurfaceContext surfaceContext (direct , std::move (view),
742+ GrSurfaceContext surfaceContext (dContext , std::move (view),
729743 SkColorTypeToGrColorType (pixmap.colorType ()),
730744 pixmap.alphaType (), cs);
731745
732746 SkImageInfo srcInfo = SkImageInfo::Make (bufferDesc.width , bufferDesc.height , colorType, at,
733747 std::move (cs));
734- surfaceContext.writePixels (srcInfo, pixmap.addr (0 , 0 ), pixmap.rowBytes (), {0 , 0 });
748+ surfaceContext.writePixels (dContext, srcInfo, pixmap.addr (0 , 0 ), pixmap.rowBytes (), {0 , 0 });
735749
736750 GrSurfaceProxy* p[1 ] = {surfaceContext.asSurfaceProxy ()};
737751 drawingManager->flush (p, 1 , SkSurface::BackendSurfaceAccess::kNoAccess , {}, nullptr );
0 commit comments