Revert "Add a deferred copy surface (take 2)"
authorRobert Phillips <robertphillips@google.com>
Wed, 14 Dec 2016 12:04:46 +0000 (12:04 +0000)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 14 Dec 2016 12:05:06 +0000 (12:05 +0000)
This reverts commit 398487a850431cf495330d4023607df5305a311f.

Reason for revert: See if this is causing the roll failure

Original change's description:
> Add a deferred copy surface (take 2)
>
> 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: Ide560f569aede5e622420dc2f30eef76357d69f4
> Reviewed-on: https://skia-review.googlesource.com/5939
> Reviewed-by: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
>

TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: I1ef40f0d5fb0bca62031f94f10eb18acd753e913
Reviewed-on: https://skia-review.googlesource.com/6024
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
23 files changed:
gm/image_pict.cpp
include/gpu/GrContext.h
include/gpu/GrRenderTargetContext.h
include/gpu/GrSurfaceContext.h
include/gpu/GrTextureContext.h
include/private/GrRenderTargetProxy.h
include/private/GrSurfaceProxy.h
src/core/SkSpecialImage.cpp
src/gpu/GrContext.cpp
src/gpu/GrContextPriv.h
src/gpu/GrRenderTargetContext.cpp
src/gpu/GrRenderTargetContextPriv.h
src/gpu/GrRenderTargetProxy.cpp
src/gpu/GrSurfaceProxy.cpp
src/gpu/GrTextureContext.cpp
src/gpu/SkGpuDevice.cpp
src/image/SkImage_Gpu.cpp
src/image/SkSurface_Gpu.cpp
tests/CopySurfaceTest.cpp
tests/EGLImageTest.cpp
tests/GrTextureStripAtlasTest.cpp
tests/IntTextureTest.cpp
tests/RectangleTextureTest.cpp

index aa28249..3a84905 100644 (file)
 
 #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
 
@@ -213,15 +209,15 @@ class TextureGenerator : public SkImageGenerator {
 public:
     TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic)
         : SkImageGenerator(info)
-        , fCtx(SkRef(ctx)) {
-
-        sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
+        , fCtx(SkRef(ctx))
+    {
+        auto 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());
-            fProxy = GrSurfaceProxy::MakeWrapped(sk_ref_sp(as_IB(image)->peekTexture()));
+            fTexture.reset(SkRef(as_IB(image)->peekTexture()));
         }
     }
 protected:
@@ -230,41 +226,22 @@ protected:
             SkASSERT(ctx == fCtx.get());
         }
 
-        if (!fProxy) {
+        if (!fTexture) {
             return nullptr;
         }
 
-        if (subset.fLeft == 0 && subset.fTop == 0 &&
-            subset.fRight == fProxy->width() && subset.fBottom == fProxy->height()) {
-            return SkSafeRef(fProxy->instantiate(fCtx->textureProvider())->asTexture());
-        }
-
         // need to copy the subset into a new texture
-        GrSurfaceDesc desc = fProxy->desc();
+        GrSurfaceDesc desc = fTexture->desc();
         desc.fWidth = subset.width();
         desc.fHeight = subset.height();
 
-        sk_sp<GrSurfaceContext> dstContext(fCtx->contextPriv().makeDeferredSurfaceContext(
-                                                                                desc,
-                                                                                SkBudgeted::kNo));
-        if (!dstContext) {
-            return nullptr;
-        }
-
-        if (!dstContext->copy(fProxy.get(), subset, SkIPoint::Make(0, 0))) {
-            return nullptr;
-        }
-
-        GrSurface* dstSurf = dstContext->asDeferredSurface()->instantiate(fCtx->textureProvider());
-        if (!dstSurf) {
-            return nullptr;
-        }
-
-        return SkRef(dstSurf->asTexture());
+        GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted::kNo);
+        fCtx->copySurface(dst, fTexture.get(), subset, SkIPoint::Make(0, 0));
+        return dst;
     }
 private:
-    sk_sp<GrContext>      fCtx;
-    sk_sp<GrSurfaceProxy> fProxy;
+    sk_sp<GrContext> fCtx;
+    sk_sp<GrTexture> fTexture;
 };
 static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) {
     const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
index 9e9773c..9ccda23 100644 (file)
@@ -302,6 +302,25 @@ public:
                             uint32_t pixelOpsFlags = 0);
 
     /**
+     * Copies a rectangle of texels from src to dst.
+     * @param dst           the surface to copy to.
+     * @param src           the surface to copy from.
+     * @param srcRect       the rectangle of the src that should be copied.
+     * @param dstPoint      the translation applied when writing the srcRect's pixels to the dst.
+     */
+    bool copySurface(GrSurface* dst,
+                     GrSurface* src,
+                     const SkIRect& srcRect,
+                     const SkIPoint& dstPoint);
+
+    /** Helper that copies the whole surface but fails when the two surfaces are not identically
+        sized. */
+    bool copySurface(GrSurface* dst, GrSurface* src) {
+        return this->copySurface(dst, src, SkIRect::MakeWH(dst->width(), dst->height()),
+                                 SkIPoint::Make(0,0));
+    }
+
+    /**
      * After this returns any pending writes to the surface will have been issued to the backend 3D API.
      */
     void flushSurfaceWrites(GrSurface* surface);
index 5fca845..5317c3e 100644 (file)
@@ -50,6 +50,8 @@ class SK_API GrRenderTargetContext : public GrSurfaceContext {
 public:
     ~GrRenderTargetContext() override;
 
+    bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
+
     // TODO: it is odd that we need both the SkPaint in the following 3 methods.
     // We should extract the text parameters from SkPaint and pass them separately
     // akin to GrStyle (GrTextInfo?)
@@ -370,7 +372,6 @@ public:
         return fRenderTargetProxy->instantiate(fContext->textureProvider());
     }
 
-    GrSurfaceProxy* asDeferredSurface() override { return fRenderTargetProxy.get(); }
     GrTextureProxy* asDeferredTexture();
 
     sk_sp<GrTexture> asTexture() {
@@ -466,8 +467,6 @@ private:
                           const SkPath&,
                           const GrStyle&);
 
-    bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
-
     // This entry point allows the GrTextContext-derived classes to add their ops to the GrOpList.
     void addDrawOp(const GrPipelineBuilder&, const GrClip&, sk_sp<GrDrawOp>);
 
@@ -484,8 +483,6 @@ private:
     sk_sp<SkColorSpace>               fColorSpace;
     sk_sp<GrColorSpaceXform>          fColorXformFromSRGB;
     SkSurfaceProps                    fSurfaceProps;
-
-    typedef GrSurfaceContext INHERITED;
 };
 
 #endif
index e1c799e..a05d37f 100644 (file)
@@ -8,8 +8,6 @@
 #ifndef GrSurfaceContext_DEFINED
 #define GrSurfaceContext_DEFINED
 
-#include "../private/GrSurfaceProxy.h"
-
 #include "SkRefCnt.h"
 
 class GrAuditTrail;
@@ -26,30 +24,7 @@ class SK_API GrSurfaceContext : public SkRefCnt {
 public:
     ~GrSurfaceContext() override {}
 
-    /*
-     * Copy 'src' into the proxy backing this context
-     * @param src       src of pixels
-     * @param srcRect   the subset of 'src' to copy
-     * @param dstPoint  the origin of the 'srcRect' in the destination coordinate space
-     * @return          true if the copy succeeded; false otherwise
-     *
-     * Note: Notionally, 'srcRect' is clipped to 'src's extent with 'dstPoint' being adjusted.
-     *       Then the 'srcRect' offset by 'dstPoint' is clipped against the dst's extent.
-     *       The end result is only valid src pixels and dst pixels will be touched but the copied
-     *       regions will not be shifted.
-     */
-    bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
-        return this->onCopy(src, srcRect, dstPoint);
-    }
-
-    bool copy(GrSurfaceProxy* src) {
-        return this->onCopy(src,
-                            SkIRect::MakeWH(src->width(), src->height()),
-                            SkIPoint::Make(0, 0));
-    }
-
-    // TODO: this is virtual b.c. this object doesn't have a pointer to the wrapped GrSurfaceProxy?
-    virtual GrSurfaceProxy* asDeferredSurface() = 0;
+    virtual bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) = 0;
 
     GrAuditTrail* auditTrail() { return fAuditTrail; }
 
@@ -63,13 +38,6 @@ protected:
 
     // In debug builds we guard against improper thread handling
     SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
-
-private:
-    virtual bool onCopy(GrSurfaceProxy* src,
-                        const SkIRect& srcRect,
-                        const SkIPoint& dstPoint) = 0;
-
-    typedef SkRefCnt INHERITED;
 };
 
 #endif
index 3052f0c..da71c07 100644 (file)
@@ -27,7 +27,7 @@ class SK_API GrTextureContext : public GrSurfaceContext {
 public:
     ~GrTextureContext() override;
 
-    GrSurfaceProxy* asDeferredSurface() override { return fTextureProxy.get(); }
+    bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
 
 protected:
     GrTextureContext(GrContext*, GrDrawingManager*, sk_sp<GrTextureProxy>, GrAuditTrail*,
@@ -40,8 +40,6 @@ protected:
 private:
     friend class GrDrawingManager; // for ctor
 
-    bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
-
     GrTextureOpList* getOpList();
 
     GrDrawingManager*            fDrawingManager;
@@ -50,8 +48,6 @@ private:
     // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
     // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
     GrTextureOpList*             fOpList;
-
-    typedef GrSurfaceContext INHERITED;
 };
 
 #endif
index 7f026ba..83107da 100644 (file)
@@ -53,9 +53,6 @@ public:
 
     GrRenderTarget::Flags testingOnly_getFlags() const;
 
-    // TODO: move this to a priv class!
-    bool refsWrappedObjects() const;
-
 protected:
     friend class GrSurfaceProxy;  // for ctors
 
index 12972c2..731603b 100644 (file)
@@ -266,20 +266,6 @@ public:
         return fGpuMemorySize;
     }
 
-    // Helper function that creates a temporary SurfaceContext to perform the copy
-    static sk_sp<GrSurfaceProxy> Copy(GrContext*, GrSurfaceProxy* src,
-                                      SkIRect srcRect, SkBudgeted);
-
-    // Copy the entire 'src'
-    static sk_sp<GrSurfaceProxy> Copy(GrContext* context, GrSurfaceProxy* src,
-                                      SkBudgeted budgeted) {
-        return Copy(context, src, SkIRect::MakeWH(src->width(), src->height()), budgeted);
-    }
-
-    // Test-only entry point - should decrease in use as proxies propagate
-    static sk_sp<GrSurfaceProxy> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
-                                          GrTexture* srcTexture, SkBudgeted budgeted);
-
     bool isWrapped_ForTesting() const;
 
     SkDEBUGCODE(void validate(GrContext*) const;)
index 4f48f78..2567bf1 100644 (file)
@@ -17,7 +17,6 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
-#include "GrSurfaceContext.h"
 #include "GrTexture.h"
 #include "GrSamplerParams.h"
 #include "GrTextureProxy.h"
@@ -347,20 +346,6 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset,
 #include "GrTexture.h"
 #include "SkImage_Gpu.h"
 
-static sk_sp<SkImage> wrap_proxy_in_image(GrContext* context, GrSurfaceProxy* proxy,
-                                          SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) {
-    // TODO: add GrTextureProxy-backed SkImage_Gpus
-    GrSurface* surf = proxy->instantiate(context->textureProvider());
-    if (!surf) {
-        return nullptr;
-    }
-
-    return sk_make_sp<SkImage_Gpu>(proxy->width(), proxy->height(),
-                                   kNeedNewImageUniqueID, alphaType,
-                                   sk_ref_sp(surf->asTexture()),
-                                   std::move(colorSpace), SkBudgeted::kYes);
-}
-
 class SkSpecialImage_Gpu : public SkSpecialImage_Base {
 public:
     SkSpecialImage_Gpu(const SkIRect& subset,
@@ -493,21 +478,34 @@ public:
                                                    fAlphaType);
     }
 
-    // TODO: move all the logic here into the subset-flavor GrSurfaceProxy::copy?
     sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override {
-        // TODO: this is problematic since the surfaceProxy could be loose
+        // TODO: add GrTextureProxy-backed SkImage_Gpus
+        GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider());
+        if (!surf) {
+            return nullptr;
+        }
+
         if (0 == subset.fLeft && 0 == subset.fTop &&
             fSurfaceProxy->width() == subset.width() &&
             fSurfaceProxy->height() == subset.height()) {
             // The existing GrTexture is already tight so reuse it in the SkImage
-            return wrap_proxy_in_image(fContext, fSurfaceProxy.get(),
-                                       fAlphaType, fColorSpace);
+            return sk_make_sp<SkImage_Gpu>(surf->width(), surf->height(),
+                                           kNeedNewImageUniqueID, fAlphaType,
+                                           sk_ref_sp(surf->asTexture()),
+                                           fColorSpace, SkBudgeted::kYes);
         }
 
-        sk_sp<GrSurfaceProxy> subsetProxy(GrSurfaceProxy::Copy(fContext, fSurfaceProxy.get(),
-                                                               subset, SkBudgeted::kYes));
+        GrSurfaceDesc desc = fSurfaceProxy->desc();
+        desc.fWidth = subset.width();
+        desc.fHeight = subset.height();
 
-        return wrap_proxy_in_image(fContext, subsetProxy.get(), fAlphaType, fColorSpace);
+        sk_sp<GrTexture> subTx(fContext->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+        if (!subTx) {
+            return nullptr;
+        }
+        fContext->copySurface(subTx.get(), surf, subset, SkIPoint::Make(0, 0));
+        return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
+                                       fAlphaType, std::move(subTx), fColorSpace, SkBudgeted::kYes);
     }
 
     sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
index 2e66c0c..ff5b026 100644 (file)
@@ -541,6 +541,43 @@ void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) {
     fDrawingManager->prepareSurfaceForExternalIO(surface);
 }
 
+bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
+                            const SkIPoint& dstPoint) {
+    ASSERT_SINGLE_OWNER
+    RETURN_FALSE_IF_ABANDONED
+    GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::copySurface");
+
+    if (!src || !dst) {
+        return false;
+    }
+    ASSERT_OWNED_RESOURCE(src);
+    ASSERT_OWNED_RESOURCE(dst);
+
+    // We don't allow conversion between integer configs and float/fixed configs.
+    if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) {
+        return false;
+    }
+
+#ifndef ENABLE_MDB
+    // We can't yet fully defer copies to textures, so GrTextureContext::copySurface will
+    // execute the copy immediately. Ensure the data is ready.
+    src->flushWrites();
+#endif
+
+    sk_sp<GrSurfaceContext> surfaceContext(
+        this->contextPriv().makeWrappedSurfaceContext(sk_ref_sp(dst)));
+
+    if (!surfaceContext) {
+        return false;
+    }
+
+    if (!surfaceContext->copySurface(src, srcRect, dstPoint)) {
+        return false;
+    }
+
+    return true;
+}
+
 void GrContext::flushSurfaceWrites(GrSurface* surface) {
     ASSERT_SINGLE_OWNER
     RETURN_IF_ABANDONED
@@ -602,36 +639,8 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurface
     }
 }
 
-sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
-                                                                  SkBudgeted isDstBudgeted) {
-
-    sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*fContext->caps(), dstDesc,
-                                                               SkBackingFit::kExact, isDstBudgeted);
-
-    if (proxy->asRenderTargetProxy()) {
-        return this->drawingManager()->makeRenderTargetContext(std::move(proxy), nullptr, nullptr);
-    } else {
-        SkASSERT(proxy->asTextureProxy());
-        return this->drawingManager()->makeTextureContext(std::move(proxy));
-    }
-
-    return nullptr;
-}
-
-sk_sp<GrSurfaceContext> GrContextPriv::makeTestSurfaceContext(sk_sp<GrSurfaceProxy> proxy) {
-
-    if (proxy->asRenderTargetProxy()) {
-        return this->drawingManager()->makeRenderTargetContext(std::move(proxy), nullptr, nullptr);
-    } else {
-        SkASSERT(proxy->asTextureProxy());
-        return this->drawingManager()->makeTextureContext(std::move(proxy));
-    }
-
-    return nullptr;
-}
-
 sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext(
-                                                                   const GrBackendTextureDesc& desc,
+                                                                   const GrBackendTextureDesc& desc, 
                                                                    sk_sp<SkColorSpace> colorSpace,
                                                                    const SkSurfaceProps* props,
                                                                    GrWrapOwnership ownership) {
index 2b2a39e..dcf0807 100644 (file)
@@ -11,8 +11,6 @@
 #include "GrContext.h"
 #include "GrSurfaceContext.h"
 
-class GrSurfaceProxy;
-
 /** Class that adds methods to GrContext that are only intended for use internal to Skia.
     This class is purely a privileged window into GrContext. It should never have additional
     data members or virtual methods. */
@@ -28,11 +26,6 @@ public:
     // Create a surfaceContext that wraps an existing texture or renderTarget
     sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex);
 
-    sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
-                                                       SkBudgeted isDstBudgeted);
-
-    sk_sp<GrSurfaceContext> makeTestSurfaceContext(sk_sp<GrSurfaceProxy> proxy);
-
     sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
                                                          const GrBackendTextureDesc& desc,
                                                          sk_sp<SkColorSpace> colorSpace,
index f32bf8f..1a1f6a5 100644 (file)
@@ -133,20 +133,12 @@ GrRenderTargetOpList* GrRenderTargetContext::getOpList() {
     return fOpList;
 }
 
-// TODO: move this (and GrTextContext::copy) to GrSurfaceContext?
-bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy,
-                                   const SkIRect& srcRect,
-                                   const SkIPoint& dstPoint) {
+bool GrRenderTargetContext::copySurface(GrSurface* src, const SkIRect& srcRect,
+                                        const SkIPoint& dstPoint) {
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
-    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::copy");
-
-    // TODO: defer instantiation until flush time
-    sk_sp<GrSurface> src(sk_ref_sp(srcProxy->instantiate(fContext->textureProvider())));
-    if (!src) {
-        return false;
-    }
+    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::copySurface");
 
     // TODO: this needs to be fixed up since it ends the deferrable of the GrRenderTarget
     sk_sp<GrRenderTarget> rt(
@@ -155,7 +147,7 @@ bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy,
         return false;
     }
 
-    return this->getOpList()->copySurface(rt.get(), src.get(), srcRect, dstPoint);
+    return this->getOpList()->copySurface(rt.get(), src, srcRect, dstPoint);
 }
 
 void GrRenderTargetContext::drawText(const GrClip& clip, const GrPaint& grPaint,
index f1548cc..b3bd72a 100644 (file)
@@ -114,10 +114,6 @@ public:
                                const GrUserStencilSettings* = nullptr,
                                bool snapToCenters = false);
 
-    bool refsWrappedObjects() const {
-        return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
-    }
-
 private:
     explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
         : fRenderTargetContext(renderTargetContext) {}
index 882acf6..03637cf 100644 (file)
@@ -8,7 +8,6 @@
 #include "GrRenderTargetProxy.h"
 
 #include "GrCaps.h"
-#include "GrGpuResourcePriv.h"
 #include "GrRenderTargetOpList.h"
 #include "GrRenderTargetPriv.h"
 #include "GrTextureProvider.h"
@@ -64,10 +63,3 @@ size_t GrRenderTargetProxy::onGpuMemorySize() const {
     return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit);
 }
 
-bool GrRenderTargetProxy::refsWrappedObjects() const {
-    if (!fTarget) {
-        return false;
-    }
-
-    return fTarget->resourcePriv().refsWrappedObjects();
-}
index 24c7cfe..4a0c348 100644 (file)
@@ -8,11 +8,8 @@
 #include "GrSurfaceProxy.h"
 
 #include "GrCaps.h"
-#include "GrContext.h"
-#include "GrContextPriv.h"
 #include "GrGpuResourcePriv.h"
 #include "GrOpList.h"
-#include "GrSurfaceContext.h"
 #include "GrTextureProvider.h"
 #include "GrTextureRenderTargetProxy.h"
 
@@ -164,50 +161,3 @@ void GrSurfaceProxy::validate(GrContext* context) const {
     INHERITED::validate();
 }
 #endif
-
-sk_sp<GrSurfaceProxy> GrSurfaceProxy::Copy(GrContext* context,
-                                           GrSurfaceProxy* src,
-                                           SkIRect srcRect,
-                                           SkBudgeted budgeted) {
-    if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) {
-        return nullptr;
-    }
-
-    GrSurfaceDesc dstDesc = src->desc();
-    dstDesc.fWidth = srcRect.width();
-    dstDesc.fHeight = srcRect.height();
-
-    sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(dstDesc,
-                                                                                         budgeted));
-    if (!dstContext) {
-        return nullptr;
-    }
-
-    if (!dstContext->copy(src, srcRect, SkIPoint::Make(0, 0))) {
-        return nullptr;
-    }
-
-    return sk_ref_sp(dstContext->asDeferredSurface());
-}
-
-sk_sp<GrSurfaceProxy> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
-                                               GrTexture* srcTexture, SkBudgeted budgeted) {
-
-    sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
-                                                                                dstDesc,
-                                                                                budgeted));
-    if (!dstContext) {
-        return nullptr;
-    }
-
-    sk_sp<GrSurfaceProxy> srcProxy(GrSurfaceProxy::MakeWrapped(sk_ref_sp(srcTexture)));
-    if (!srcProxy) {
-        return nullptr;
-    }
-
-    if (!dstContext->copy(srcProxy.get())) {
-        return nullptr;
-    }
-
-    return sk_ref_sp(dstContext->asDeferredSurface());
-}
index 28240f8..22620fe 100644 (file)
@@ -24,7 +24,8 @@ GrTextureContext::GrTextureContext(GrContext* context,
     : GrSurfaceContext(context, auditTrail, singleOwner)
     , fDrawingManager(drawingMgr)
     , fTextureProxy(std::move(textureProxy))
-    , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList())) {
+    , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList()))
+{
     SkDEBUGCODE(this->validate();)
 }
 
@@ -55,26 +56,12 @@ GrTextureOpList* GrTextureContext::getOpList() {
     return fOpList;
 }
 
-// TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext?
-bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
-                              const SkIRect& srcRect,
-                              const SkIPoint& dstPoint) {
+bool GrTextureContext::copySurface(GrSurface* src, const SkIRect& srcRect,
+                                   const SkIPoint& dstPoint) {
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
-    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::copy");
-
-    // TODO: defer instantiation until flush time
-    sk_sp<GrSurface> src(sk_ref_sp(srcProxy->instantiate(fContext->textureProvider())));
-    if (!src) {
-        return false;
-    }
-\r
-#ifndef ENABLE_MDB\r
-    // We can't yet fully defer copies to textures, so GrTextureContext::copySurface will\r
-    // execute the copy immediately. Ensure the data is ready.\r
-    src->flushWrites();\r
-#endif
+    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::copySurface");
 
     // TODO: this needs to be fixed up since it ends the deferrable of the GrTexture
     sk_sp<GrTexture> tex(sk_ref_sp(fTextureProxy->instantiate(fContext->textureProvider())));
@@ -83,7 +70,7 @@ bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
     }
 
     GrTextureOpList* opList = this->getOpList();
-    bool result = opList->copySurface(tex.get(), src.get(), srcRect, dstPoint);
+    bool result = opList->copySurface(tex.get(), src, srcRect, dstPoint);
 
 #ifndef ENABLE_MDB
     GrOpFlushState flushState(fContext->getGpu(), nullptr);
index 5738764..3cdc34e 100644 (file)
@@ -15,7 +15,6 @@
 #include "GrRenderTargetContextPriv.h"
 #include "GrStyle.h"
 #include "GrTextureAdjuster.h"
-#include "GrTextureProxy.h"
 #include "GrTracing.h"
 
 #include "SkCanvasPriv.h"
@@ -263,7 +262,9 @@ void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) {
         if (fRenderTargetContext->wasAbandoned()) {
             return;
         }
-        newRTC->copy(fRenderTargetContext->asDeferredSurface());
+        newRTC->copySurface(fRenderTargetContext->asTexture().get(),
+                            SkIRect::MakeWH(this->width(), this->height()),
+                            SkIPoint::Make(0, 0));
     }
 
     fRenderTargetContext = newRTC;
@@ -1331,15 +1332,19 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
 }
 
 sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
-    sk_sp<GrSurfaceProxy> sProxy(sk_ref_sp(this->accessRenderTargetContext()->asDeferredTexture()));
-    if (!sProxy) {
+    sk_sp<GrTexture> texture(this->accessRenderTargetContext()->asTexture());
+    if (!texture) {
         // When the device doesn't have a texture, we create a temporary texture.
         // TODO: we should actually only copy the portion of the source needed to apply the image
         // filter
-        sProxy = GrSurfaceProxy::Copy(fContext.get(),
-                                      this->accessRenderTargetContext()->asDeferredSurface(),
-                                      SkBudgeted::kYes);
-        if (!sProxy) {
+        texture.reset(fContext->textureProvider()->createTexture(
+            this->accessRenderTargetContext()->desc(), SkBudgeted::kYes));
+        if (!texture) {
+            return nullptr;
+        }
+
+        if (!fContext->copySurface(texture.get(),
+                                   this->accessRenderTargetContext()->accessRenderTarget())) {
             return nullptr;
         }
     }
@@ -1347,12 +1352,11 @@ sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
     const SkImageInfo ii = this->imageInfo();
     const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height());
 
-    return SkSpecialImage::MakeDeferredFromGpu(fContext.get(),
-                                               srcRect,
-                                               kNeedNewImageUniqueID_SpecialImage,
-                                               sProxy,
-                                               sk_ref_sp(ii.colorSpace()),
-                                               &this->surfaceProps());
+    return SkSpecialImage::MakeFromGpu(srcRect,
+                                       kNeedNewImageUniqueID_SpecialImage,
+                                       std::move(texture),
+                                       sk_ref_sp(ii.colorSpace()),
+                                       &this->surfaceProps());
 }
 
 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
index a290ce5..cc11f6d 100644 (file)
@@ -13,7 +13,6 @@
 #include "GrBitmapTextureMaker.h"
 #include "GrCaps.h"
 #include "GrContext.h"
-#include "GrContextPriv.h"
 #include "GrImageTextureMaker.h"
 #include "GrRenderTargetContext.h"
 #include "GrTextureAdjuster.h"
@@ -154,31 +153,13 @@ sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
     desc.fWidth = subset.width();
     desc.fHeight = subset.height();
 
-    sk_sp<GrSurfaceContext> sContext(ctx->contextPriv().makeDeferredSurfaceContext(desc,
-                                                                                   fBudgeted));
-    if (!sContext) {
-        return nullptr;
-    }
-
-    // TODO: make gpu images be proxy-backed to 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 to we don't need to do this
-    GrSurface* subTx = sContext->asDeferredSurface()->instantiate(ctx->textureProvider());
+    sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted));
     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, sk_ref_sp(subTx->asTexture()),
-                                   fColorSpace, fBudgeted);
+                                   fAlphaType, std::move(subTx), fColorSpace, fBudgeted);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
index 55b216b..f99d3c2 100644 (file)
@@ -14,7 +14,6 @@
 #include "SkImage_Base.h"
 #include "SkImage_Gpu.h"
 #include "SkImagePriv.h"
-#include "GrRenderTargetContextPriv.h"
 #include "SkSurface_Base.h"
 
 #if SK_SUPPORT_GPU
@@ -83,37 +82,29 @@ sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
 }
 
 sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixelsMode cpm) {
-    GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
-    if (!rtc) {
+    GrRenderTarget* rt = fDevice->accessRenderTargetContext()->accessRenderTarget();
+    if (!rt) {
         return nullptr;
     }
 
-    GrContext* ctx = fDevice->context();
-
-    GrSurfaceProxy* srcProxy = rtc->asDeferredSurface();
-    sk_sp<GrSurfaceContext> copyCtx;
+    GrTexture* tex = rt->asTexture();
+    sk_sp<GrTexture> copy;
     // 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 || !srcProxy || rtc->priv().refsWrappedObjects()) {
-        GrSurfaceDesc desc = rtc->desc();
+    if (kAlways_SkCopyPixelsMode == cpm || !tex || rt->resourcePriv().refsWrappedObjects()) {
+        GrSurfaceDesc desc = fDevice->accessRenderTargetContext()->desc();
+        GrContext* ctx = fDevice->context();
         desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
-
-        copyCtx = ctx->contextPriv().makeDeferredSurfaceContext(desc, budgeted);
-        if (!copyCtx) {
+        copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));
+        if (!copy) {
             return nullptr;
         }
-
-        if (!copyCtx->copy(srcProxy)) {
+        if (!ctx->copySurface(copy.get(), rt)) {
             return nullptr;
         }
-
-        srcProxy = copyCtx->asDeferredSurface();
+        tex = copy.get();
     }
-
-    // TODO: add proxy-backed SkImage_Gpu
-    GrTexture* tex = srcProxy->instantiate(ctx->textureProvider())->asTexture();
-
     const SkImageInfo info = fDevice->imageInfo();
     sk_sp<SkImage> image;
     if (tex) {
index 68113e7..053b456 100644 (file)
@@ -10,9 +10,6 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
-#include "GrContextPriv.h"
-#include "GrSurfaceContext.h"
-#include "GrSurfaceProxy.h"
 #include "GrTexture.h"
 #include "GrTextureProvider.h"
 
@@ -71,29 +68,22 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
                             dstDesc.fOrigin = dOrigin;
                             dstDesc.fFlags = dFlags;
 
-                            sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(
-                                                                    *context->caps(),
-                                                                    context->textureProvider(),
-                                                                    srcDesc, SkBudgeted::kNo,
-                                                                    srcPixels.get(),
-                                                                    kRowBytes));
-
-                            sk_sp<GrSurfaceProxy> dst(GrSurfaceProxy::MakeDeferred(
-                                                                    *context->caps(),
-                                                                    context->textureProvider(),
-                                                                    dstDesc, SkBudgeted::kNo,
-                                                                    dstPixels.get(),
-                                                                    kRowBytes));
+                            sk_sp<GrTexture> src(
+                                context->textureProvider()->createTexture(srcDesc, SkBudgeted::kNo,
+                                                                          srcPixels.get(),
+                                                                          kRowBytes));
+                            sk_sp<GrTexture> dst(
+                                context->textureProvider()->createTexture(dstDesc, SkBudgeted::kNo,
+                                                                          dstPixels.get(),
+                                                                          kRowBytes));
                             if (!src || !dst) {
                                 ERRORF(reporter,
                                        "Could not create surfaces for copy surface test.");
                                 continue;
                             }
 
-                            sk_sp<GrSurfaceContext> sContext =
-                                                context->contextPriv().makeTestSurfaceContext(dst);
-
-                            bool result = sContext->copy(src.get(), srcRect, dstPoint);
+                            bool result
+                                    = context->copySurface(dst.get(), src.get(), srcRect, dstPoint);
 
                             bool expectedResult = true;
                             SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft,
@@ -130,11 +120,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
                                 continue;
                             }
 
-                            GrSurface* dstSurf = dst->instantiate(context->textureProvider());
-
                             sk_memset32(read.get(), 0, kW * kH);
-                            if (!dstSurf->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.get(),
-                                                     kRowBytes)) {
+                            if (!dst->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.get(),
+                                                 kRowBytes)) {
                                 ERRORF(reporter, "Error calling readPixels");
                                 continue;
                             }
index 0dcacf9..f78a0ea 100644 (file)
@@ -10,7 +10,6 @@
 #include "GrContext.h"
 #include "GrContextFactory.h"
 #include "GrShaderCaps.h"
-#include "GrSurfaceContext.h"
 #include "gl/GrGLGpu.h"
 #include "gl/GrGLUtil.h"
 #include "gl/GLTestContext.h"
@@ -41,7 +40,7 @@ static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx
 }
 
 static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
-                             GrSurface* externalTexture, uint32_t expectedPixelValues[]) {
+                             GrTexture* externalTexture, uint32_t expectedPixelValues[]) {
     int pixelCnt = externalTexture->width() * externalTexture->height();
     SkAutoTMalloc<uint32_t> pixels(pixelCnt);
     memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
@@ -77,13 +76,9 @@ static void test_copy_surface(skiatest::Reporter* reporter, GrContext* context,
     copyDesc.fWidth = externalTexture->width();
     copyDesc.fHeight = externalTexture->height();
     copyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
-
-    sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, copyDesc,
-                                                        externalTexture, SkBudgeted::kYes));
-
-    GrSurface* copySurf = copy->instantiate(context->textureProvider());
-
-    test_read_pixels(reporter, context, copySurf, expectedPixelValues);
+    sk_sp<GrTexture> copy(context->textureProvider()->createTexture(copyDesc, SkBudgeted::kYes));
+    context->copySurface(copy.get(), externalTexture);
+    test_read_pixels(reporter, context, copy.get(), expectedPixelValues);
 }
 
 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
index d3f5598..60b8a6d 100644 (file)
@@ -9,7 +9,6 @@
 #if SK_SUPPORT_GPU
 
 #include "GrContext.h"
-#include "GrContextPriv.h"
 #include "GrGpu.h"
 #include "GrTextureStripAtlas.h"
 #include "GrTypes.h"
@@ -22,97 +21,51 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTextureStripAtlasFlush, reporter, ctxInfo)
     desc.fWidth = 32;
     desc.fHeight = 32;
     desc.fConfig = kRGBA_8888_GrPixelConfig;
+    GrTexture* texture = context->textureProvider()->createTexture(desc, SkBudgeted::kYes,
+                                                                   nullptr, 0);
 
-    sk_sp<GrSurfaceProxy> srcProxy;
+    GrSurfaceDesc targetDesc = desc;
+    targetDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+    GrTexture* target = context->textureProvider()->createTexture(targetDesc, SkBudgeted::kYes,
+                                                                  nullptr, 0);
 
-    {
-        SkAutoTMalloc<uint32_t> pixels(desc.fWidth * desc.fHeight);
-        memset(pixels.get(), 0xFF, sizeof(uint32_t) * desc.fWidth * desc.fHeight);
+    SkAutoTMalloc<uint32_t> pixels(desc.fWidth * desc.fHeight);
+    memset(pixels.get(), 0xFF, sizeof(uint32_t) * desc.fWidth * desc.fHeight);
+    texture->writePixels(0, 0, desc.fWidth, desc.fHeight, kRGBA_8888_GrPixelConfig, pixels.get());
 
-        srcProxy = GrSurfaceProxy::MakeDeferred(*context->caps(), context->textureProvider(),
-                                                desc, SkBudgeted::kYes,
-                                                pixels.get(), 0);
-    }
-
-    // Add a pending read to the src texture, and then make it available for reuse.
-    sk_sp<GrSurfaceProxy> targetProxy;
-    GrSurface* srcSurface;
-
-    {
-        GrSurfaceDesc targetDesc = desc;
-        targetDesc.fFlags = kRenderTarget_GrSurfaceFlag;
-
-        // We can't use GrSurfaceProxy::Copy bc we may be changing the dst proxy type
-        sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
-                                                                                targetDesc,
-                                                                                SkBudgeted::kYes));
-        REPORTER_ASSERT(reporter, dstContext);
-
-        if (!dstContext->copy(srcProxy.get())) {
-            return;
-        }
-
-        targetProxy = sk_ref_sp(dstContext->asDeferredSurface());
-
-        srcSurface = srcProxy->instantiate(context->textureProvider());
-        srcProxy.reset();
-    }
+    // Add a pending read to the texture, and then make it available for reuse.
+    context->copySurface(target, texture);
+    texture->unref();
 
     // Create an atlas with parameters that allow it to reuse the texture.
-    GrTextureStripAtlas* atlas;
-
-    {
-        GrTextureStripAtlas::Desc atlasDesc;
-        atlasDesc.fContext = context;
-        atlasDesc.fConfig = desc.fConfig;
-        atlasDesc.fWidth = desc.fWidth;
-        atlasDesc.fHeight = desc.fHeight;
-        atlasDesc.fRowHeight = 1;
-        atlas = GrTextureStripAtlas::GetAtlas(atlasDesc);
-    }
+    GrTextureStripAtlas::Desc atlasDesc;
+    atlasDesc.fContext = context;
+    atlasDesc.fConfig = desc.fConfig;
+    atlasDesc.fWidth = desc.fWidth;
+    atlasDesc.fHeight = desc.fHeight;
+    atlasDesc.fRowHeight = 1;
+    GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(atlasDesc);
 
     // Write to the atlas' texture.
-    int lockedRow;
-
-    {
-        SkImageInfo info = SkImageInfo::MakeN32(desc.fWidth, desc.fHeight, kPremul_SkAlphaType);
-        size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig);
-        SkBitmap bitmap;
-        bitmap.allocPixels(info, rowBytes);
-        memset(bitmap.getPixels(), 1, rowBytes * desc.fHeight);
-        lockedRow = atlas->lockRow(bitmap);
-    }
+    SkImageInfo info = SkImageInfo::MakeN32(desc.fWidth, desc.fHeight, kPremul_SkAlphaType);
+    size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig);
+    SkBitmap bitmap;
+    bitmap.allocPixels(info, rowBytes);
+    memset(bitmap.getPixels(), 1, rowBytes * desc.fHeight);
+    int row = atlas->lockRow(bitmap);
+    if (!context->caps()->preferVRAMUseOverFlushes())
+        REPORTER_ASSERT(reporter, texture == atlas->getTexture());
 
     // The atlas' use of its texture shouldn't change which pixels got copied to the target.
-    {
-        SkAutoTMalloc<uint8_t> actualPixels(sizeof(uint32_t) * desc.fWidth * desc.fHeight);
-
-        // TODO: move readPixels to GrSurfaceProxy?
-        GrSurface* surf = targetProxy->instantiate(context->textureProvider());
-
-        bool success = surf->readPixels(0, 0, desc.fWidth, desc.fHeight,
-                                        kRGBA_8888_GrPixelConfig, actualPixels.get());
-        REPORTER_ASSERT(reporter, success);
-
-        bool good = true;
-
-        const uint8_t* bytes = actualPixels.get();
-        for (size_t i = 0; i < sizeof(uint32_t) * desc.fWidth * desc.fHeight; ++i, ++bytes) {
-            if (0xFF != *bytes) {
-                good = false;
-                break;
-            }
-        }
-
-        REPORTER_ASSERT(reporter, good);
-    }
-
-    if (!context->caps()->preferVRAMUseOverFlushes()) {
-        // This is kindof dodgy since we released it!
-        REPORTER_ASSERT(reporter, srcSurface == atlas->getTexture());
-    }
-
-    atlas->unlockRow(lockedRow);
+    SkAutoTMalloc<uint32_t> actualPixels(desc.fWidth * desc.fHeight);
+    bool success = target->readPixels(0, 0, desc.fWidth, desc.fHeight, kRGBA_8888_GrPixelConfig,
+                                      actualPixels.get());
+    REPORTER_ASSERT(reporter, success);
+    REPORTER_ASSERT(reporter,
+                    !memcmp(pixels.get(), actualPixels.get(),
+                            sizeof(uint32_t) * desc.fWidth * desc.fHeight));
+    target->unref();
+    atlas->unlockRow(row);
 }
 
 #endif
index 5e3fde2..a6eaf98 100644 (file)
@@ -95,48 +95,40 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
     REPORTER_ASSERT(reporter, !success);
 
     // Test that copying from one integer texture to another succeeds.
-    {
-        sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, desc,
-                                                            texture.get(), SkBudgeted::kYes));
-        REPORTER_ASSERT(reporter, copy);
-        if (!copy) {
-            return;
-        }
-
-        GrSurface* copySurface = copy->instantiate(context->textureProvider());
-        REPORTER_ASSERT(reporter, copySurface);
-        if (!copySurface) {
-            return;
-        }
-
-        sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
-        success = copySurface->readPixels(0, 0, kS, kS,
-                                          kRGBA_8888_sint_GrPixelConfig, readData.get());
-        REPORTER_ASSERT(reporter, success);
-        if (success) {
-            check_pixels(reporter, kS, kS, testData.get(), readData.get());
-        }
+    sk_sp<GrTexture> copy(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+    REPORTER_ASSERT(reporter, copy);
+    if (!copy) {
+        return;
     }
-
-
-    // Test that copying to a non-integer (8888) texture fails.
-    {
-        GrSurfaceDesc nonIntDesc = desc;
-        nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig;
-
-        sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, nonIntDesc,
-                                                            texture.get(), SkBudgeted::kYes));
-        REPORTER_ASSERT(reporter, !copy);
+    success = context->copySurface(copy.get(), texture.get());
+    REPORTER_ASSERT(reporter, success);
+    if (!success) {
+        return;
+    }
+    sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
+    success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get());
+    REPORTER_ASSERT(reporter, success);
+    if (success) {
+        check_pixels(reporter, kS, kS, testData.get(), readData.get());
     }
 
-    // Test that copying to a non-integer (RGBA_half) texture fails.
-    if (context->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
-        GrSurfaceDesc nonIntDesc = desc;
-        nonIntDesc.fConfig = kRGBA_half_GrPixelConfig;
-
-        sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, nonIntDesc,
-                                                            texture.get(), SkBudgeted::kYes));
-        REPORTER_ASSERT(reporter, !copy);
+    // Test that copying to a non-integer texture fails.
+    GrSurfaceDesc nonIntDesc = desc;
+    nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig;
+    copy.reset(context->textureProvider()->createTexture(nonIntDesc, SkBudgeted::kYes));
+    REPORTER_ASSERT(reporter, copy);
+    if (!copy) {
+        return;
+    }
+    success = context->copySurface(copy.get(), texture.get());
+    REPORTER_ASSERT(reporter, !success);
+    nonIntDesc.fConfig = kRGBA_half_GrPixelConfig;
+    copy.reset(context->textureProvider()->createTexture(nonIntDesc, SkBudgeted::kYes));
+    REPORTER_ASSERT(reporter, copy ||
+                    !context->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig));
+    if (copy) {
+        success = context->copySurface(copy.get(), texture.get());
+        REPORTER_ASSERT(reporter, !success);
     }
 
     // We overwrite the top left quarter of the texture with the bottom right quarter of the
index 5871604..cc0c4d1 100644 (file)
@@ -15,7 +15,7 @@
 #include "gl/GLTestContext.h"
 
 static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
-                             GrSurface* texture, uint32_t expectedPixelValues[]) {
+                             GrTexture* texture, uint32_t expectedPixelValues[]) {
     int pixelCnt = texture->width() * texture->height();
     SkAutoTMalloc<uint32_t> pixels(pixelCnt);
     memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
@@ -52,30 +52,22 @@ static void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
 }
 
 static void test_copy_surface_src(skiatest::Reporter* reporter, GrContext* context,
-                                  GrTexture* rectTexture, uint32_t expectedPixelValues[]) {
-    GrSurfaceDesc copyDstDesc;
-    copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
-    copyDstDesc.fWidth = rectTexture->width();
-    copyDstDesc.fHeight = rectTexture->height();
-
+                                  GrTexture* rectangleTexture, uint32_t expectedPixelValues[]) {
     for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) {
+        GrSurfaceDesc copyDstDesc;
+        copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
+        copyDstDesc.fWidth = rectangleTexture->width();
+        copyDstDesc.fHeight = rectangleTexture->height();
         copyDstDesc.fFlags = flags;
-
-        sk_sp<GrSurfaceProxy> dst(GrSurfaceProxy::TestCopy(context, copyDstDesc,
-                                                           rectTexture, SkBudgeted::kYes));
-
-        GrSurface* dstSurf = dst->instantiate(context->textureProvider());
-
-        test_read_pixels(reporter, context, dstSurf, expectedPixelValues);
+        sk_sp<GrTexture> dst(
+                context->textureProvider()->createTexture(copyDstDesc, SkBudgeted::kYes));
+        context->copySurface(dst.get(), rectangleTexture);
+        test_read_pixels(reporter, context, dst.get(), expectedPixelValues);
     }
 }
 
 static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* context,
                                   GrTexture* rectangleTexture) {
-
-    sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext(
-                                                                    sk_ref_sp(rectangleTexture)));
-
     int pixelCnt = rectangleTexture->width() * rectangleTexture->height();
     SkAutoTMalloc<uint32_t> pixels(pixelCnt);
     for (int y = 0; y < rectangleTexture->width(); ++y) {
@@ -89,13 +81,10 @@ static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* conte
         copySrcDesc.fWidth = rectangleTexture->width();
         copySrcDesc.fHeight = rectangleTexture->height();
         copySrcDesc.fFlags = flags;
+        sk_sp<GrTexture> src(context->textureProvider()->createTexture(
+                copySrcDesc, SkBudgeted::kYes, pixels.get(), 0));
 
-        sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(*context->caps(),
-                                                               context->textureProvider(),
-                                                               copySrcDesc,
-                                                               SkBudgeted::kYes, pixels.get(), 0));
-        sContext->copy(src.get());
-
+        context->copySurface(rectangleTexture, src.get());
         test_read_pixels(reporter, context, rectangleTexture, pixels.get());
     }
 }