@@ -327,63 +327,50 @@ 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-
335330 GrBackendFormat format;
331+ GrPixelConfig config;
336332 if (canvas2DFastPath) {
337- desc.fFlags = kRenderTarget_GrSurfaceFlag ;
338- desc.fConfig = kRGBA_8888_GrPixelConfig ;
333+ config = kRGBA_8888_GrPixelConfig ;
339334 format = this ->caps ()->getBackendFormatFromColorType (kRGBA_8888_SkColorType );
340335 } else {
341- desc.fFlags = kNone_GrSurfaceFlags ;
342- desc.fConfig = srcProxy->config ();
336+ config = srcProxy->config ();
343337 format = srcProxy->backendFormat ().makeTexture2D ();
344338 if (!format.isValid ()) {
345339 return false ;
346340 }
347341 }
342+ sk_sp<SkColorSpace> cs = canvas2DFastPath ? nullptr : src->colorSpaceInfo ().refColorSpace ();
348343
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- }
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 );
364347 if (!tempCtx) {
365348 return false ;
366349 }
350+
351+ std::unique_ptr<GrFragmentProcessor> fp;
367352 if (canvas2DFastPath) {
368- GrPaint paint;
369- paint.setPorterDuffXPFactory (SkBlendMode::kSrc );
370- auto fp = fContext ->createPMToUPMEffect (
353+ fp = fContext ->createPMToUPMEffect (
371354 GrSimpleTextureEffect::Make (sk_ref_sp (srcProxy->asTextureProxy ()),
372355 SkMatrix::I ()));
373356 if (dstColorType == GrColorType::kBGRA_8888 ) {
374357 fp = GrFragmentProcessor::SwizzleOutput (std::move (fp), GrSwizzle::BGRA ());
375358 dstColorType = GrColorType::kRGBA_8888 ;
376359 }
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 })) {
360+ } else {
361+ fp = GrSimpleTextureEffect::Make (sk_ref_sp (srcProxy->asTextureProxy ()), SkMatrix::I ());
362+ }
363+ if (!fp) {
385364 return false ;
386365 }
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+
387374 uint32_t flags = canvas2DFastPath ? 0 : pixelOpsFlags;
388375 return this ->readSurfacePixels (tempCtx.get (), 0 , 0 , width, height, dstColorType,
389376 dstColorSpace, buffer, rowBytes, flags);
@@ -545,26 +532,26 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top,
545532 srcColorSpace, buffer, rowBytes, flags)) {
546533 return false ;
547534 }
535+
536+ std::unique_ptr<GrFragmentProcessor> fp;
548537 if (canvas2DFastPath) {
549- GrPaint paint;
550- paint.setPorterDuffXPFactory (SkBlendMode::kSrc );
551- auto fp = fContext ->createUPMToPMEffect (
538+ fp = fContext ->createUPMToPMEffect (
552539 GrSimpleTextureEffect::Make (std::move (tempProxy), SkMatrix::I ()));
553540 if (srcColorType == GrColorType::kBGRA_8888 ) {
554541 fp = GrFragmentProcessor::SwizzleOutput (std::move (fp), GrSwizzle::BGRA ());
555542 }
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));
563543 } else {
564- if (!dst->copy (tempProxy.get (), SkIRect::MakeWH (width, height), {left, top})) {
565- return false ;
566- }
544+ fp = GrSimpleTextureEffect::Make (std::move (tempProxy), SkMatrix::I ());
545+ }
546+ if (!fp) {
547+ return false ;
567548 }
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));
568555
569556 return true ;
570557 }
0 commit comments