Add a deferred copy surface (take 3)
This CL forces all GrSurface copies to go through a GrSurfaceContext (rather than GrContext).
There is a bit of goofiness going on here until read/writePixels is also consolidated in GrSurfaceContext and a proxy-backed SkImage/SkSurface is added.
This is a reland of https://skia-review.googlesource.com/c/5773/ (Add a deferred copy surface)
Change-Id: Ib8fd96d0569274ef781366eb900ed8ee839ae9bd
Reviewed-on: https://skia-review.googlesource.com/6109
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index cc11f6d..c347a1f 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -13,6 +13,7 @@
#include "GrBitmapTextureMaker.h"
#include "GrCaps.h"
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "GrImageTextureMaker.h"
#include "GrRenderTargetContext.h"
#include "GrTextureAdjuster.h"
@@ -153,13 +154,33 @@
desc.fWidth = subset.width();
desc.fHeight = subset.height();
- sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted));
+ sk_sp<GrSurfaceContext> sContext(ctx->contextPriv().makeDeferredSurfaceContext(
+ desc,
+ SkBackingFit::kExact,
+ fBudgeted));
+ if (!sContext) {
+ return nullptr;
+ }
+
+ // TODO: make gpu images be proxy-backed so we don't need to do this
+ sk_sp<GrSurfaceProxy> tmpSrc(GrSurfaceProxy::MakeWrapped(fTexture));
+ if (!tmpSrc) {
+ return nullptr;
+ }
+
+ if (!sContext->copy(tmpSrc.get(), subset, SkIPoint::Make(0, 0))) {
+ return nullptr;
+ }
+
+ // TODO: make gpu images be proxy-backed so we don't need to do this
+ GrSurface* subTx = sContext->asDeferredSurface()->instantiate(ctx->textureProvider());
if (!subTx) {
return nullptr;
}
- ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0));
+
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
- fAlphaType, std::move(subTx), fColorSpace, fBudgeted);
+ fAlphaType, sk_ref_sp(subTx->asTexture()),
+ fColorSpace, fBudgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////