aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/image_pict.cpp
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 /gm/image_pict.cpp
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 'gm/image_pict.cpp')
-rw-r--r--gm/image_pict.cpp51
1 files changed, 38 insertions, 13 deletions
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index 7f9454923f..d2e1ebad95 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -14,7 +14,11 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrContextPriv.h"
+#include "GrSurfaceContext.h"
+#include "GrSurfaceProxy.h"
#include "GrTexture.h"
+#include "GrTextureProxy.h"
#include "../src/image/SkImage_Gpu.h"
#endif
@@ -209,15 +213,15 @@ class TextureGenerator : public SkImageGenerator {
public:
TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic)
: SkImageGenerator(info)
- , fCtx(SkRef(ctx))
- {
- auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
+ , fCtx(SkRef(ctx)) {
+
+ sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
if (surface) {
surface->getCanvas()->clear(0);
surface->getCanvas()->translate(-100, -100);
surface->getCanvas()->drawPicture(pic);
sk_sp<SkImage> image(surface->makeImageSnapshot());
- fTexture.reset(SkRef(as_IB(image)->peekTexture()));
+ fProxy = GrSurfaceProxy::MakeWrapped(sk_ref_sp(as_IB(image)->peekTexture()));
}
}
protected:
@@ -227,24 +231,45 @@ protected:
SkASSERT(ctx == fCtx.get());
}
- if (!fTexture) {
+ if (!fProxy) {
return nullptr;
}
+ if (origin.fX == 0 && origin.fY == 0 &&
+ info.width() == fProxy->width() && info.height() == fProxy->height()) {
+ return SkSafeRef(fProxy->instantiate(fCtx->textureProvider())->asTexture());
+ }
+
// need to copy the subset into a new texture
- GrSurfaceDesc desc = fTexture->desc();
+ GrSurfaceDesc desc = fProxy->desc();
desc.fWidth = info.width();
desc.fHeight = info.height();
- GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted::kNo);
- fCtx->copySurface(dst, fTexture.get(),
- SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height()),
- SkIPoint::Make(0, 0));
- return dst;
+ sk_sp<GrSurfaceContext> dstContext(fCtx->contextPriv().makeDeferredSurfaceContext(
+ desc,
+ SkBackingFit::kExact,
+ SkBudgeted::kNo));
+ if (!dstContext) {
+ return nullptr;
+ }
+
+ if (!dstContext->copy(
+ fProxy.get(),
+ SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height()),
+ SkIPoint::Make(0, 0))) {
+ return nullptr;
+ }
+
+ GrSurface* dstSurf = dstContext->asDeferredSurface()->instantiate(fCtx->textureProvider());
+ if (!dstSurf) {
+ return nullptr;
+ }
+
+ return SkRef(dstSurf->asTexture());
}
private:
- sk_sp<GrContext> fCtx;
- sk_sp<GrTexture> fTexture;
+ sk_sp<GrContext> fCtx;
+ sk_sp<GrSurfaceProxy> fProxy;
};
static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) {
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);