@@ -401,18 +401,11 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* ctx,
401401
402402 enum { kLockTexturePathCount = kRGBA_LockTexturePath + 1 };
403403
404- auto satisfiesMipMapRequest = [&](const GrSurfaceProxyView& view) {
405- SkASSERT (view);
406- return mipMapped == GrMipMapped::kNo ||
407- view.asTextureProxy ()->mipMapped () == GrMipMapped::kYes ;
408- };
409-
410404 GrUniqueKey key;
411405 GrMakeKeyFromImageID (&key, this ->uniqueID (), SkIRect::MakeSize (this ->dimensions ()));
412406
413407 const GrCaps* caps = ctx->priv ().caps ();
414408 GrProxyProvider* proxyProvider = ctx->priv ().proxyProvider ();
415- GrSurfaceProxyView view;
416409
417410 auto installKey = [&](const GrSurfaceProxyView& view) {
418411 SkASSERT (view && view.asTextureProxy ());
@@ -432,30 +425,43 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* ctx,
432425 SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kPreExisting_LockTexturePath ,
433426 kLockTexturePathCount );
434427 GrSwizzle swizzle = caps->getReadSwizzle (proxy->backendFormat (), ct);
435- view = GrSurfaceProxyView (std::move (proxy), kTopLeft_GrSurfaceOrigin , swizzle);
436- if (satisfiesMipMapRequest (view)) {
428+ GrSurfaceProxyView view (std::move (proxy), kTopLeft_GrSurfaceOrigin , swizzle);
429+ if (mipMapped == GrMipMapped::kNo ||
430+ view.asTextureProxy ()->mipMapped () == GrMipMapped::kYes ) {
431+ return view;
432+ } else {
433+ // We need a mipped proxy, but we found a cached proxy that wasn't mipped. Thus we
434+ // generate a new mipped surface and copy the original proxy into the base layer. We
435+ // will then let the gpu generate the rest of the mips.
436+ GrSurfaceProxyView mippedView = GrCopyBaseMipMapToTextureProxy (
437+ ctx, view.proxy (), kTopLeft_GrSurfaceOrigin , ct);
438+ if (mippedView) {
439+ proxyProvider->removeUniqueKeyFromProxy (view.asTextureProxy ());
440+ installKey (mippedView);
441+ return mippedView;
442+ }
443+ // We failed to make a mipped proxy with the base copied into it. This could have
444+ // been from failure to make the proxy or failure to do the copy. Thus we will fall
445+ // back to just using the non mipped proxy; See skbug.com/7094.
437446 return view;
438447 }
439448 }
440449 }
441450
442451 // 2. Ask the generator to natively create one
443- if (!view) {
444- ScopedGenerator generator (fSharedGenerator );
445- view = generator->generateTexture (ctx, this ->imageInfo (), fOrigin , mipMapped);
446- if (view) {
447- SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kNative_LockTexturePath ,
448- kLockTexturePathCount );
449- installKey (view);
450- if (satisfiesMipMapRequest (view)) {
451- return view;
452- }
453- }
452+ {
453+ ScopedGenerator generator (fSharedGenerator );
454+ if (auto view = generator->generateTexture (ctx, this ->imageInfo (), fOrigin , mipMapped)) {
455+ SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kNative_LockTexturePath ,
456+ kLockTexturePathCount );
457+ installKey (view);
458+ return view;
459+ }
454460 }
455461
456462 // 3. Ask the generator to return YUV planes, which the GPU can convert. If we will be mipping
457463 // the texture we fall through here and have the CPU generate the mip maps for us.
458- if (!view && mipMapped == GrMipMapped::kNo && !ctx->priv ().options ().fDisableGpuYUVConversion ) {
464+ if (mipMapped == GrMipMapped::kNo && !ctx->priv ().options ().fDisableGpuYUVConversion ) {
459465 SkColorType colorType = this ->colorType ();
460466
461467 ScopedGenerator generator (fSharedGenerator );
@@ -470,9 +476,9 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* ctx,
470476
471477 // TODO: Update to create the mipped surface in the YUV generator and draw the base
472478 // layer directly into the mipped surface.
473- view = provider.refAsTextureProxyView (ctx, this ->imageInfo ().dimensions (),
474- SkColorTypeToGrColorType (colorType),
475- generatorColorSpace, thisColorSpace);
479+ auto view = provider.refAsTextureProxyView (ctx, this ->imageInfo ().dimensions (),
480+ SkColorTypeToGrColorType (colorType),
481+ generatorColorSpace, thisColorSpace);
476482 if (view) {
477483 SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kYUV_LockTexturePath ,
478484 kLockTexturePathCount );
@@ -482,44 +488,19 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* ctx,
482488 }
483489
484490 // 4. Ask the generator to return RGB(A) data, which the GPU can convert
485- SkBitmap bitmap;
486- if (!view && this ->getROPixels (&bitmap, chint)) {
491+ if (SkBitmap bitmap; this ->getROPixels (&bitmap, chint)) {
487492 GrBitmapTextureMaker bitmapMaker (ctx, bitmap, GrBitmapTextureMaker::Cached::kNo );
488- view = bitmapMaker.view (mipMapped);
493+ auto view = bitmapMaker.view (mipMapped);
489494 if (view) {
490495 installKey (view);
491- if (satisfiesMipMapRequest (view)) {
492- SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kRGBA_LockTexturePath ,
493- kLockTexturePathCount );
494- return view;
495- }
496+ SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kRGBA_LockTexturePath ,
497+ kLockTexturePathCount );
498+ return view;
496499 }
497500 }
498501
499- if (!view) {
500- SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kFailure_LockTexturePath ,
501- kLockTexturePathCount );
502- return {};
503- }
504-
505- // We need a mipped proxy, but we either found a proxy earlier that wasn't mipped, generated
506- // a native non mipped proxy, or generated a non-mipped yuv proxy. Thus we generate a new
507- // mipped surface and copy the original proxy into the base layer. We will then let the gpu
508- // generate the rest of the mips.
509- SkASSERT (mipMapped == GrMipMapped::kYes );
510- SkASSERT (view.asTextureProxy ()->mipMapped () == GrMipMapped::kNo );
511- GrColorType srcColorType = SkColorTypeToGrColorType (this ->colorType ());
512- GrSurfaceProxyView mippedView = GrCopyBaseMipMapToTextureProxy (
513- ctx, view.proxy (), kTopLeft_GrSurfaceOrigin , srcColorType);
514- if (mippedView) {
515- proxyProvider->removeUniqueKeyFromProxy (view.asTextureProxy ());
516- installKey (mippedView);
517- return mippedView;
518- }
519- // We failed to make a mipped proxy with the base copied into it. This could have
520- // been from failure to make the proxy or failure to do the copy. Thus we will fall
521- // back to just using the non mipped proxy; See skbug.com/7094.
522- return view;
502+ SK_HISTOGRAM_ENUMERATION (" LockTexturePath" , kFailure_LockTexturePath , kLockTexturePathCount );
503+ return {};
523504}
524505
525506GrColorType SkImage_Lazy::colorTypeOfLockTextureProxy (const GrCaps* caps) const {
0 commit comments