aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2016-12-15 09:23:05 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-15 15:07:39 +0000
commite2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0b (patch)
treed290f1a9d5d5e828c7177d230f56356f9fc9bf2e /src/image
parentdb8f44f497f2b67b2500bbfc7b11ce7a510c5e5c (diff)
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>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage_Gpu.cpp27
-rw-r--r--src/image/SkSurface_Gpu.cpp33
2 files changed, 46 insertions, 14 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index cc11f6dcdb..c347a1f606 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 @@ sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
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);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index f99d3c2102..c81c06ed53 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -14,6 +14,7 @@
#include "SkImage_Base.h"
#include "SkImage_Gpu.h"
#include "SkImagePriv.h"
+#include "GrRenderTargetContextPriv.h"
#include "SkSurface_Base.h"
#if SK_SUPPORT_GPU
@@ -82,29 +83,39 @@ sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
}
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixelsMode cpm) {
- GrRenderTarget* rt = fDevice->accessRenderTargetContext()->accessRenderTarget();
- if (!rt) {
+ GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
+ if (!rtc) {
return nullptr;
}
- GrTexture* tex = rt->asTexture();
- sk_sp<GrTexture> copy;
+ GrContext* ctx = fDevice->context();
+
+ GrSurfaceProxy* srcProxy = rtc->asDeferredSurface();
+ sk_sp<GrSurfaceContext> copyCtx;
// If the original render target is a buffer originally created by the client, then we don't
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
- if (kAlways_SkCopyPixelsMode == cpm || !tex || rt->resourcePriv().refsWrappedObjects()) {
- GrSurfaceDesc desc = fDevice->accessRenderTargetContext()->desc();
- GrContext* ctx = fDevice->context();
+ if (kAlways_SkCopyPixelsMode == cpm || !srcProxy || rtc->priv().refsWrappedObjects()) {
+ GrSurfaceDesc desc = rtc->desc();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
- copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));
- if (!copy) {
+
+ copyCtx = ctx->contextPriv().makeDeferredSurfaceContext(desc,
+ SkBackingFit::kExact,
+ budgeted);
+ if (!copyCtx) {
return nullptr;
}
- if (!ctx->copySurface(copy.get(), rt)) {
+
+ if (!copyCtx->copy(srcProxy)) {
return nullptr;
}
- tex = copy.get();
+
+ srcProxy = copyCtx->asDeferredSurface();
}
+
+ // TODO: add proxy-backed SkImage_Gpu
+ GrTexture* tex = srcProxy->instantiate(ctx->textureProvider())->asTexture();
+
const SkImageInfo info = fDevice->imageInfo();
sk_sp<SkImage> image;
if (tex) {