@@ -327,50 +327,63 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top,
327327
328328 if (!fContext ->priv ().caps ()->surfaceSupportsReadPixels (srcSurface) ||
329329 canvas2DFastPath) {
330+ GrSurfaceDesc desc;
331+ desc.fWidth = width;
332+ desc.fHeight = height;
333+ desc.fSampleCnt = 1 ;
334+
330335 GrBackendFormat format;
331- GrPixelConfig config;
332336 if (canvas2DFastPath) {
333- config = kRGBA_8888_GrPixelConfig ;
337+ desc.fFlags = kRenderTarget_GrSurfaceFlag ;
338+ desc.fConfig = kRGBA_8888_GrPixelConfig ;
334339 format = this ->caps ()->getBackendFormatFromColorType (kRGBA_8888_SkColorType );
335340 } else {
336- config = srcProxy->config ();
341+ desc.fFlags = kNone_GrSurfaceFlags ;
342+ desc.fConfig = srcProxy->config ();
337343 format = srcProxy->backendFormat ().makeTexture2D ();
338344 if (!format.isValid ()) {
339345 return false ;
340346 }
341347 }
342- sk_sp<SkColorSpace> cs = canvas2DFastPath ? nullptr : src->colorSpaceInfo ().refColorSpace ();
343348
344- sk_sp<GrRenderTargetContext> tempCtx = this ->makeDeferredRenderTargetContext (
345- format, SkBackingFit::kApprox , width, height, config, std::move (cs), 1 ,
346- GrMipMapped::kNo , kTopLeft_GrSurfaceOrigin , nullptr , SkBudgeted::kYes );
349+ auto tempProxy = this ->proxyProvider ()->createProxy (
350+ format, desc, kTopLeft_GrSurfaceOrigin , SkBackingFit::kApprox , SkBudgeted::kYes );
351+ if (!tempProxy) {
352+ return false ;
353+ }
354+ sk_sp<GrSurfaceContext> tempCtx;
355+ if (canvas2DFastPath) {
356+ tempCtx = this ->drawingManager ()->makeRenderTargetContext (std::move (tempProxy), nullptr ,
357+ nullptr );
358+ SkASSERT (tempCtx->asRenderTargetContext ());
359+ tempCtx->asRenderTargetContext ()->discard ();
360+ } else {
361+ tempCtx = this ->drawingManager ()->makeTextureContext (
362+ std::move (tempProxy), src->colorSpaceInfo ().refColorSpace ());
363+ }
347364 if (!tempCtx) {
348365 return false ;
349366 }
350-
351- std::unique_ptr<GrFragmentProcessor> fp;
352367 if (canvas2DFastPath) {
353- fp = fContext ->createPMToUPMEffect (
368+ GrPaint paint;
369+ paint.setPorterDuffXPFactory (SkBlendMode::kSrc );
370+ auto fp = fContext ->createPMToUPMEffect (
354371 GrSimpleTextureEffect::Make (sk_ref_sp (srcProxy->asTextureProxy ()),
355372 SkMatrix::I ()));
356373 if (dstColorType == GrColorType::kBGRA_8888 ) {
357374 fp = GrFragmentProcessor::SwizzleOutput (std::move (fp), GrSwizzle::BGRA ());
358375 dstColorType = GrColorType::kRGBA_8888 ;
359376 }
360- } else {
361- fp = GrSimpleTextureEffect::Make (sk_ref_sp (srcProxy->asTextureProxy ()), SkMatrix::I ());
362- }
363- if (!fp) {
377+ if (!fp) {
378+ return false ;
379+ }
380+ paint.addColorFragmentProcessor (std::move (fp));
381+ tempCtx->asRenderTargetContext ()->fillRectToRect (
382+ GrNoClip (), std::move (paint), GrAA::kNo , SkMatrix::I (),
383+ SkRect::MakeWH (width, height), SkRect::MakeXYWH (left, top, width, height));
384+ } else if (!tempCtx->copy (srcProxy, SkIRect::MakeXYWH (left, top, width, height), {0 , 0 })) {
364385 return false ;
365386 }
366- GrPaint paint;
367- paint.setPorterDuffXPFactory (SkBlendMode::kSrc );
368- paint.addColorFragmentProcessor (std::move (fp));
369-
370- tempCtx->asRenderTargetContext ()->fillRectToRect (
371- GrNoClip (), std::move (paint), GrAA::kNo , SkMatrix::I (),
372- SkRect::MakeWH (width, height), SkRect::MakeXYWH (left, top, width, height));
373-
374387 uint32_t flags = canvas2DFastPath ? 0 : pixelOpsFlags;
375388 return this ->readSurfacePixels (tempCtx.get (), 0 , 0 , width, height, dstColorType,
376389 dstColorSpace, buffer, rowBytes, flags);
@@ -532,26 +545,26 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top,
532545 srcColorSpace, buffer, rowBytes, flags)) {
533546 return false ;
534547 }
535-
536- std::unique_ptr<GrFragmentProcessor> fp;
537548 if (canvas2DFastPath) {
538- fp = fContext ->createUPMToPMEffect (
549+ GrPaint paint;
550+ paint.setPorterDuffXPFactory (SkBlendMode::kSrc );
551+ auto fp = fContext ->createUPMToPMEffect (
539552 GrSimpleTextureEffect::Make (std::move (tempProxy), SkMatrix::I ()));
540553 if (srcColorType == GrColorType::kBGRA_8888 ) {
541554 fp = GrFragmentProcessor::SwizzleOutput (std::move (fp), GrSwizzle::BGRA ());
542555 }
556+ if (!fp) {
557+ return false ;
558+ }
559+ paint.addColorFragmentProcessor (std::move (fp));
560+ dst->asRenderTargetContext ()->fillRectToRect (
561+ GrNoClip (), std::move (paint), GrAA::kNo , SkMatrix::I (),
562+ SkRect::MakeXYWH (left, top, width, height), SkRect::MakeWH (width, height));
543563 } else {
544- fp = GrSimpleTextureEffect::Make (std::move (tempProxy), SkMatrix::I ());
545- }
546- if (!fp) {
547- return false ;
564+ if (!dst->copy (tempProxy.get (), SkIRect::MakeWH (width, height), {left, top})) {
565+ return false ;
566+ }
548567 }
549- GrPaint paint;
550- paint.setPorterDuffXPFactory (SkBlendMode::kSrc );
551- paint.addColorFragmentProcessor (std::move (fp));
552- dst->asRenderTargetContext ()->fillRectToRect (
553- GrNoClip (), std::move (paint), GrAA::kNo , SkMatrix::I (),
554- SkRect::MakeXYWH (left, top, width, height), SkRect::MakeWH (width, height));
555568
556569 return true ;
557570 }
0 commit comments