Revert "Make GrCopySurfaceOp friendlier to GrSurfaceProxy"
authorRobert Phillips <robertphillips@google.com>
Thu, 6 Apr 2017 21:17:15 +0000 (21:17 +0000)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 6 Apr 2017 21:17:26 +0000 (21:17 +0000)
This reverts commit d7cda9a6f050c30e65b0744b3cfb45cecdc40834.

Reason for revert: Tegra3!!!!

Original change's description:
> Make GrCopySurfaceOp friendlier to GrSurfaceProxy
>
> Change-Id: Iba8c068bd96ab154d466e485a9db31dd552138de
> Reviewed-on: https://skia-review.googlesource.com/11325
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
>

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

Change-Id: Idc31d469d94e6e2772ee5714987b3a05bb902d88
Reviewed-on: https://skia-review.googlesource.com/11580
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

17 files changed:
include/gpu/GrCaps.h
src/gpu/GrContextPriv.h
src/gpu/GrRenderTargetContext.cpp
src/gpu/GrRenderTargetContext.h
src/gpu/GrRenderTargetOpList.cpp
src/gpu/GrRenderTargetOpList.h
src/gpu/GrTextureContext.cpp
src/gpu/GrTextureOpList.cpp
src/gpu/GrTextureOpList.h
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGLCaps.h
src/gpu/ops/GrCopySurfaceOp.cpp
src/gpu/ops/GrCopySurfaceOp.h
src/gpu/vk/GrVkCaps.cpp
src/gpu/vk/GrVkCaps.h
tests/BlendTest.cpp
tools/gpu/GrTest.cpp

index 0d05d4730dc8e645681b6da29e7969f1a1088c55..a7096e3fd9476802a8c949557086036a179c0c47 100644 (file)
@@ -17,7 +17,7 @@
 #include "SkString.h"
 
 struct GrContextOptions;
-class GrRenderTargetProxy;
+class GrRenderTarget;
 
 /**
  * Represents the capabilities of a GrContext.
@@ -187,13 +187,13 @@ public:
 
     /**
      * This is can be called before allocating a texture to be a dst for copySurface. This is only
-     * used for doing dst copies needed in blends, thus the src is always a GrRenderTargetProxy. It
-     * will populate the origin, config, and flags fields of the desc such that copySurface can
+     * used for doing dst copies needed in blends, thus the src is always a GrRenderTarget. It will
+     * populate the origin, config, and flags fields of the desc such that copySurface can
      * efficiently succeed. rectsMustMatch will be set to true if the copy operation must ensure
      * that the src and dest rects are identical. disallowSubrect will be set to true if copy rect
      * must equal src's bounds.
      */
-    virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
+    virtual bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc,
                                     bool* rectsMustMatch, bool* disallowSubrect) const = 0;
 
 protected:
index 6ed53ff9d532116b1c0b3e60b7649924074e057e..369e8e7ff9eb3d700142610ff6d71e79e0b08517 100644 (file)
@@ -23,18 +23,19 @@ public:
     GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
 
     // Create a renderTargetContext that wraps an existing renderTarget
-    sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget>,
-                                                                sk_sp<SkColorSpace>,
+    sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget> rt,
+                                                                sk_sp<SkColorSpace> colorSpace,
                                                                 const SkSurfaceProps* = nullptr);
 
     // Create a surfaceContext that wraps an existing texture or renderTarget
-    sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface>);
+    sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex);
 
-    sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
+    sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy,
+                                                      sk_sp<SkColorSpace>);
 
-    sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
-                                                       SkBackingFit,
-                                                       SkBudgeted);
+    sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
+                                                       SkBackingFit dstFit,
+                                                       SkBudgeted isDstBudgeted);
 
     // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove
     // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext
index 1207c7c2893cc7fca65cb45ae6f8bb6b36359bf9..76a67c083e6a61c42bdfbbb1bccc4846f736f9b5 100644 (file)
@@ -134,10 +134,22 @@ bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy,
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
-    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::onCopy");
+    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::copy");
 
-    return this->getOpList()->copySurface(fContext->resourceProvider(),
-                                          fRenderTargetProxy.get(), srcProxy, srcRect, dstPoint);
+    // TODO: defer instantiation until flush time
+    sk_sp<GrSurface> src(sk_ref_sp(srcProxy->instantiate(fContext->resourceProvider())));
+    if (!src) {
+        return false;
+    }
+
+    // TODO: This needs to be fixed up since it ends the deferral of the GrRenderTarget.
+    sk_sp<GrRenderTarget> rt(
+                        sk_ref_sp(fRenderTargetProxy->instantiate(fContext->resourceProvider())));
+    if (!rt) {
+        return false;
+    }
+
+    return this->getOpList()->copySurface(rt.get(), src.get(), srcRect, dstPoint);
 }
 
 // TODO: move this (and GrTextureContext::onReadPixels) to GrSurfaceContext?
@@ -1647,7 +1659,8 @@ uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<Gr
 
     GrXferProcessor::DstTexture dstTexture;
     if (op->xpRequiresDstTexture(*this->caps(), &appliedClip)) {
-        if (!this->setupDstTexture(fRenderTargetProxy.get(), clip, op->bounds(), &dstTexture)) {
+        this->setupDstTexture(rt, clip, op->bounds(), &dstTexture);
+        if (!dstTexture.texture()) {
             return SK_InvalidUniqueID;
         }
     }
@@ -1702,7 +1715,8 @@ uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipeline
     args.fXPInputCoverage = analysis.outputCoverage();
 
     if (analysis.requiresDstTexture()) {
-        if (!this->setupDstTexture(fRenderTargetProxy.get(), clip, bounds, &args.fDstTexture)) {
+        this->setupDstTexture(rt, clip, bounds, &args.fDstTexture);
+        if (!args.fDstTexture.texture()) {
             return SK_InvalidUniqueID;
         }
     }
@@ -1712,39 +1726,33 @@ uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipeline
     return this->getOpList()->addOp(std::move(op), this);
 }
 
-bool GrRenderTargetContext::setupDstTexture(GrRenderTargetProxy* rtProxy, const GrClip& clip,
+void GrRenderTargetContext::setupDstTexture(GrRenderTarget* rt, const GrClip& clip,
                                             const SkRect& opBounds,
                                             GrXferProcessor::DstTexture* dstTexture) {
     if (this->caps()->textureBarrierSupport()) {
-        if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) {
-            // MDB TODO: remove this instantiation. Blocked on making DstTexture be proxy-based
-            sk_sp<GrTexture> tex(sk_ref_sp(texProxy->instantiate(fContext->resourceProvider())));
-            if (!tex) {
-                SkDebugf("setupDstTexture: instantiation of src texture failed.\n");
-                return false;  // We have bigger problems now
-            }
-
+        if (GrTexture* rtTex = rt->asTexture()) {
             // The render target is a texture, so we can read from it directly in the shader. The XP
             // will be responsible to detect this situation and request a texture barrier.
-            dstTexture->setTexture(std::move(tex));
+            dstTexture->setTexture(sk_ref_sp(rtTex));
             dstTexture->setOffset(0, 0);
-            return true;
+            return;
         }
     }
 
-    SkIRect copyRect = SkIRect::MakeWH(rtProxy->width(), rtProxy->height());
+    SkIRect copyRect = SkIRect::MakeWH(rt->width(), rt->height());
 
     SkIRect clippedRect;
-    clip.getConservativeBounds(rtProxy->width(), rtProxy->height(), &clippedRect);
+    clip.getConservativeBounds(rt->width(), rt->height(), &clippedRect);
     SkIRect drawIBounds;
     opBounds.roundOut(&drawIBounds);
     // Cover up for any precision issues by outsetting the op bounds a pixel in each direction.
     drawIBounds.outset(1, 1);
     if (!clippedRect.intersect(drawIBounds)) {
 #ifdef SK_DEBUG
-        GrCapsDebugf(this->caps(), "setupDstTexture: Missed an early reject bailing on draw.");
+        GrCapsDebugf(this->caps(), "Missed an early reject. "
+                                   "Bailing on draw from setupDstTexture.\n");
 #endif
-        return false;
+        return;
     }
 
     // MSAA consideration: When there is support for reading MSAA samples in the shader we could
@@ -1752,56 +1760,41 @@ bool GrRenderTargetContext::setupDstTexture(GrRenderTargetProxy* rtProxy, const
     GrSurfaceDesc desc;
     bool rectsMustMatch = false;
     bool disallowSubrect = false;
-    if (!this->caps()->initDescForDstCopy(rtProxy, &desc, &rectsMustMatch, &disallowSubrect)) {
-        desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
+    if (!this->caps()->initDescForDstCopy(rt, &desc, &rectsMustMatch, &disallowSubrect)) {
+        desc.fOrigin = kDefault_GrSurfaceOrigin;
         desc.fFlags = kRenderTarget_GrSurfaceFlag;
-        desc.fConfig = rtProxy->config();
+        desc.fConfig = rt->config();
     }
 
     if (!disallowSubrect) {
         copyRect = clippedRect;
     }
 
-    SkIPoint dstPoint, dstOffset;
-    SkBackingFit fit;
+    SkIPoint dstPoint;
+    SkIPoint dstOffset;
+    static const uint32_t kFlags = 0;
+    sk_sp<GrTexture> copy;
     if (rectsMustMatch) {
-        SkASSERT(desc.fOrigin == rtProxy->origin());
-        desc.fWidth = rtProxy->width();
-        desc.fHeight = rtProxy->height();
+        SkASSERT(desc.fOrigin == rt->origin());
+        desc.fWidth = rt->width();
+        desc.fHeight = rt->height();
         dstPoint = {copyRect.fLeft, copyRect.fTop};
         dstOffset = {0, 0};
-        fit = SkBackingFit::kExact;
+        copy = fContext->resourceProvider()->createTexture(desc, SkBudgeted::kYes, kFlags);
     } else {
         desc.fWidth = copyRect.width();
         desc.fHeight = copyRect.height();
         dstPoint = {0, 0};
         dstOffset = {copyRect.fLeft, copyRect.fTop};
-        fit = SkBackingFit::kApprox;
-    }
-
-    sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeDeferredSurfaceContext(
-                                                                                desc,
-                                                                                fit,
-                                                                                SkBudgeted::kYes);
-    if (!sContext) {
-        SkDebugf("setupDstTexture: surfaceContext creation failed.\n");
-        return false;
+        copy.reset(fContext->resourceProvider()->createApproxTexture(desc, kFlags));
     }
 
-    if (!sContext->copy(rtProxy, copyRect, dstPoint)) {
-        SkDebugf("setupDstTexture: copy failed.\n");
-        return false;
-    }
-
-    GrTextureProxy* copyProxy = sContext->asTextureProxy();
-    // MDB TODO: remove this instantiation once DstTexture is proxy-backed
-    sk_sp<GrTexture> copy(sk_ref_sp(copyProxy->instantiate(fContext->resourceProvider())));
     if (!copy) {
-        SkDebugf("setupDstTexture: instantiation of copied texture failed.\n");
-        return false;
+        SkDebugf("Failed to create temporary copy of destination texture.\n");
+        return;
     }
 
+    this->getOpList()->copySurface(copy.get(), rt, copyRect, dstPoint);
     dstTexture->setTexture(std::move(copy));
     dstTexture->setOffset(dstOffset);
-    return true;
 }
index 8feec78c3b1f163c6ec699dfcfff39e67b1d5f2f..fe32faf1b9a5c4db250c52a297680ca6752604a9 100644 (file)
@@ -469,13 +469,12 @@ private:
     uint32_t addLegacyMeshDrawOp(GrPipelineBuilder&&, const GrClip&,
                                  std::unique_ptr<GrLegacyMeshDrawOp>);
 
-    // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
-    // be used by GrXferProcessor to access the destination color in 'result'. If the return
-    // value is false then a texture copy could not be made.
-    bool SK_WARN_UNUSED_RESULT setupDstTexture(GrRenderTargetProxy*,
-                                               const GrClip&,
-                                               const SkRect& opBounds,
-                                               GrXferProcessor::DstTexture* result);
+    // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
+    // be used by GrXferProcessor to access the destination color. If the texture is nullptr then
+    // a texture copy could not be made.
+    void setupDstTexture(GrRenderTarget*, const GrClip&, const SkRect& opBounds,
+                         GrXferProcessor::DstTexture*);
+
 
     GrRenderTargetOpList* getOpList();
 
index aee7c1cc1c3d43c68f22a563ffcbbdc61598db27..bbe1055f208ac6e5563810acfafb2803bb3469be 100644 (file)
@@ -236,12 +236,11 @@ void GrRenderTargetOpList::discard(GrRenderTargetContext* renderTargetContext) {
 
 ////////////////////////////////////////////////////////////////////////////////
 
-bool GrRenderTargetOpList::copySurface(GrResourceProvider* resourceProvider,
-                                       GrSurfaceProxy* dst,
-                                       GrSurfaceProxy* src,
+bool GrRenderTargetOpList::copySurface(GrSurface* dst,
+                                       GrSurface* src,
                                        const SkIRect& srcRect,
                                        const SkIPoint& dstPoint) {
-    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint);
+    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
     if (!op) {
         return false;
     }
index 156e601431c7f87233b2ba1b84750690ea2e68c4..b527b64b95009952481438caf5c87ade63b8185d 100644 (file)
@@ -98,9 +98,8 @@ public:
      * depending on the type of surface, configs, etc, and the backend-specific
      * limitations.
      */
-    bool copySurface(GrResourceProvider* resourceProvider,
-                     GrSurfaceProxy* dst,
-                     GrSurfaceProxy* src,
+    bool copySurface(GrSurface* dst,
+                     GrSurface* src,
                      const SkIRect& srcRect,
                      const SkIPoint& dstPoint);
 
index ca6f7a20bd847b5a7140ecfecb95e6a134f4a251..f9462907956aa2d29e71ad7a663abb34c8ef8ff6 100644 (file)
@@ -84,9 +84,20 @@ bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
     fContext->contextPriv().flushSurfaceWrites(srcProxy);
 #endif
 
+    // TODO: defer instantiation until flush time
+    sk_sp<GrSurface> src(sk_ref_sp(srcProxy->instantiate(fContext->resourceProvider())));
+    if (!src) {
+        return false;
+    }
+
+    // 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->resourceProvider())));
+    if (!tex) {
+        return false;
+    }
+
     GrTextureOpList* opList = this->getOpList();
-    bool result = opList->copySurface(fContext->resourceProvider(),
-                                      fTextureProxy.get(), srcProxy, srcRect, dstPoint);
+    bool result = opList->copySurface(tex.get(), src.get(), srcRect, dstPoint);
 
 #ifndef ENABLE_MDB
     GrOpFlushState flushState(fContext->getGpu(), nullptr);
index d2d922643a19a38111e4e5f7ef515edeff0897f2..668e8a3bc86884f6af93c2ea74866d0646b1e409 100644 (file)
@@ -76,12 +76,11 @@ void GrTextureOpList::reset() {
 
 ////////////////////////////////////////////////////////////////////////////////
 
-bool GrTextureOpList::copySurface(GrResourceProvider* resourceProvider,
-                                  GrSurfaceProxy* dst,
-                                  GrSurfaceProxy* src,
+bool GrTextureOpList::copySurface(GrSurface* dst,
+                                  GrSurface* src,
                                   const SkIRect& srcRect,
                                   const SkIPoint& dstPoint) {
-    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint);
+    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
     if (!op) {
         return false;
     }
index 22828fd936690d4cb799320aa818945a87f71165..954289c1e327e6c5d47b689b9fc8784dc8e8331c 100644 (file)
@@ -52,9 +52,8 @@ public:
      * depending on the type of surface, configs, etc, and the backend-specific
      * limitations.
      */
-    bool copySurface(GrResourceProvider* resourceProvider,
-                     GrSurfaceProxy* dst,
-                     GrSurfaceProxy* src,
+    bool copySurface(GrSurface* dst,
+                     GrSurface* src,
                      const SkIRect& srcRect,
                      const SkIPoint& dstPoint);
 
index bc894c30d13dea0f5e0482f707d84834e1758a57..6b3e3a72dd2fc3157711d813e18517ecedfa6099 100644 (file)
@@ -11,7 +11,6 @@
 #include "GrGLRenderTarget.h"
 #include "GrGLTexture.h"
 #include "GrShaderCaps.h"
-#include "GrSurfaceProxyPriv.h"
 #include "SkTSearch.h"
 #include "SkTSort.h"
 #include "instanced/GLInstancedRendering.h"
@@ -2072,7 +2071,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
 #endif
 }
 
-bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
+bool GrGLCaps::initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc,
                                   bool* rectsMustMatch, bool* disallowSubrect) const {
     // By default, we don't require rects to match.
     *rectsMustMatch = false;
@@ -2082,22 +2081,17 @@ bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc*
 
     // If the src is a texture, we can implement the blit as a draw assuming the config is
     // renderable.
-    if (src->asTextureProxy() && this->isConfigRenderable(src->config(), false)) {
-        desc->fOrigin = kBottomLeft_GrSurfaceOrigin;
+    if (src->asTexture() && this->isConfigRenderable(src->config(), false)) {
+        desc->fOrigin = kDefault_GrSurfaceOrigin;
         desc->fFlags = kRenderTarget_GrSurfaceFlag;
         desc->fConfig = src->config();
         return true;
     }
 
-    {
-        // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
-        // wrapped. In that case the proxy would already be instantiated.
-        const GrTexture* srcTexture = src->priv().peekTexture();
-        const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
-        if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
-            // Not supported for FBO blit or CopyTexSubImage
-            return false;
-        }
+    const GrGLTexture* srcTexture = static_cast<const GrGLTexture*>(src->asTexture());
+    if (srcTexture && srcTexture->target() != GR_GL_TEXTURE_2D) {
+        // Not supported for FBO blit or CopyTexSubImage
+        return false;
     }
 
     // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
@@ -2136,20 +2130,18 @@ bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc*
         return false;
     }
 
-    {
-        bool srcIsMSAARenderbuffer = src->desc().fSampleCnt > 0 && this->usesMSAARenderBuffers();
-        if (srcIsMSAARenderbuffer) {
-            // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
-            // blit or fail.
-            if (this->canConfigBeFBOColorAttachment(src->config())) {
-                desc->fOrigin = originForBlitFramebuffer;
-                desc->fConfig = src->config();
-                *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
-                *disallowSubrect = disallowSubrectForBlitFramebuffer;
-                return true;
-            }
-            return false;
+    const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src);
+    if (srcRT->renderFBOID() != srcRT->textureFBOID()) {
+        // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO blit or
+        // fail.
+        if (this->canConfigBeFBOColorAttachment(src->config())) {
+            desc->fOrigin = originForBlitFramebuffer;
+            desc->fConfig = src->config();
+            *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
+            *disallowSubrect = disallowSubrectForBlitFramebuffer;
+            return true;
         }
+        return false;
     }
 
     // We'll do a CopyTexSubImage. Make the dst a plain old texture.
index 7439711c6dbea5ab64641fab16e457b41bca7ed3..b8c4745a50acbd363552a81e8efda2d27d73f24b 100644 (file)
@@ -359,8 +359,8 @@ public:
         return fRGBAToBGRAReadbackConversionsAreSlow;
     }
 
-    bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
-                            bool* rectsMustMatch, bool* disallowSubrect) const override;
+    bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc, bool* rectsMustMatch,
+                            bool* disallowSubrect) const override;
 
 private:
     enum ExternalFormatUsage {
index 5feed18f76fb03ada3fd2e232766db0cc7581a71..87c490b1105f77ad7bbef683287442ff84f9ce84 100644 (file)
@@ -8,12 +8,12 @@
 #include "GrCopySurfaceOp.h"
 
 // returns true if the read/written rect intersects the src/dst and false if not.
-static bool clip_src_rect_and_dst_point(const GrSurfaceProxy* dst,
-                                        const GrSurfaceProxy* src,
-                                        const SkIRect& srcRect,
-                                        const SkIPoint& dstPoint,
-                                        SkIRect* clippedSrcRect,
-                                        SkIPoint* clippedDstPoint) {
+bool GrCopySurfaceOp::ClipSrcRectAndDstPoint(const GrSurface* dst,
+                                             const GrSurface* src,
+                                             const SkIRect& srcRect,
+                                             const SkIPoint& dstPoint,
+                                             SkIRect* clippedSrcRect,
+                                             SkIPoint* clippedDstPoint) {
     *clippedSrcRect = srcRect;
     *clippedDstPoint = dstPoint;
 
@@ -58,37 +58,21 @@ static bool clip_src_rect_and_dst_point(const GrSurfaceProxy* dst,
     return !clippedSrcRect->isEmpty();
 }
 
-std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrResourceProvider* resourceProvider,
-                                            GrSurfaceProxy* dstProxy, GrSurfaceProxy* srcProxy,
-                                            const SkIRect& srcRect,
+std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
                                             const SkIPoint& dstPoint) {
-    SkASSERT(dstProxy);
-    SkASSERT(srcProxy);
-    if (GrPixelConfigIsSint(dstProxy->config()) != GrPixelConfigIsSint(srcProxy->config())) {
+    SkASSERT(dst);
+    SkASSERT(src);
+    if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) {
         return nullptr;
     }
-    if (GrPixelConfigIsCompressed(dstProxy->config())) {
+    if (GrPixelConfigIsCompressed(dst->config())) {
         return nullptr;
     }
     SkIRect clippedSrcRect;
     SkIPoint clippedDstPoint;
-    // If the rect is outside the srcProxy or dstProxy then we've already succeeded.
-    if (!clip_src_rect_and_dst_point(dstProxy, srcProxy, srcRect, dstPoint,
-                                     &clippedSrcRect, &clippedDstPoint)) {
+    // If the rect is outside the src or dst then we've already succeeded.
+    if (!ClipSrcRectAndDstPoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) {
         return nullptr;
     }
-
-    // MDB TODO: remove this instantiation
-    GrSurface* dstTex = dstProxy->instantiate(resourceProvider);
-    if (!dstTex) {
-        return nullptr;
-    }
-    GrSurface* srcTex = srcProxy->instantiate(resourceProvider);
-    if (!srcTex) {
-        return nullptr;
-    }
-
-    return std::unique_ptr<GrOp>(new GrCopySurfaceOp(dstTex, srcTex,
-                                                     dstProxy->uniqueID(), srcProxy->uniqueID(),
-                                                     clippedSrcRect, clippedDstPoint));
+    return std::unique_ptr<GrOp>(new GrCopySurfaceOp(dst, src, clippedSrcRect, clippedDstPoint));
 }
index 05ee8d0a004377c0ab6eea0f5b220995327b9d6e..4c4500b44564575a2526c4a75d94eb0c2b3ec5bd 100644 (file)
@@ -8,44 +8,45 @@
 #ifndef GrCopySurfaceOp_DEFINED
 #define GrCopySurfaceOp_DEFINED
 
+#include "GrGpu.h"
 #include "GrOp.h"
 #include "GrOpFlushState.h"
+#include "GrRenderTarget.h"
 
 class GrCopySurfaceOp final : public GrOp {
 public:
     DEFINE_OP_CLASS_ID
 
-    // MDB TODO: remove the resourceProvider parameter
-    static std::unique_ptr<GrOp> Make(GrResourceProvider*,
-                                      GrSurfaceProxy* dst, GrSurfaceProxy* src,
-                                      const SkIRect& srcRect,
+    /** This should not really be exposed as Create() will apply this clipping, but there is
+     *  currently a workaround in GrContext::copySurface() for non-render target dsts that relies
+     *  on it. */
+    static bool ClipSrcRectAndDstPoint(const GrSurface* dst,
+                                       const GrSurface* src,
+                                       const SkIRect& srcRect,
+                                       const SkIPoint& dstPoint,
+                                       SkIRect* clippedSrcRect,
+                                       SkIPoint* clippedDstPoint);
+
+    static std::unique_ptr<GrOp> Make(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
                                       const SkIPoint& dstPoint);
 
     const char* name() const override { return "CopySurface"; }
 
     SkString dumpInfo() const override {
         SkString string;
-        string.printf("src: (proxyID: %d, rtID: %d), dst: (proxyID: %d, rtID: %d), "
-                      "srcRect: [L: %d, T: %d, R: %d, B: %d], dstPt: [X: %d, Y: %d]",
-                      fSrcProxyID.asUInt(), fSrc.get()->uniqueID().asUInt(),
-                      fDstProxyID.asUInt(), fDst.get()->uniqueID().asUInt(),
-                      fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom,
-                      fDstPoint.fX, fDstPoint.fY);
+        string.printf(
+                "SRC: 0x%p, DST: 0x%p, SRECT: [L: %d, T: %d, R: %d, B: %d], "
+                "DPT:[X: %d, Y: %d]",
+                fDst.get(), fSrc.get(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight,
+                fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY);
         string.append(INHERITED::dumpInfo());
         return string;
     }
 
 private:
-    GrCopySurfaceOp(GrSurface* dst, GrSurface* src,
-                    GrSurfaceProxy::UniqueID dstID, GrSurfaceProxy::UniqueID srcID,
-                    const SkIRect& srcRect, const SkIPoint& dstPoint)
-            : INHERITED(ClassID())
-            , fDstProxyID(dstID)
-            , fSrcProxyID(srcID)
-            , fDst(dst)
-            , fSrc(src)
-            , fSrcRect(srcRect)
-            , fDstPoint(dstPoint) {
+    GrCopySurfaceOp(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
+                    const SkIPoint& dstPoint)
+            : INHERITED(ClassID()), fDst(dst), fSrc(src), fSrcRect(srcRect), fDstPoint(dstPoint) {
         SkRect bounds =
                 SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY),
                                  SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
@@ -66,14 +67,10 @@ private:
         }
     }
 
-    // MDB TODO: remove the proxy IDs once the GrSurfaceProxy carries the ref since they will
-    // be redundant
-    GrSurfaceProxy::UniqueID                        fDstProxyID;
-    GrSurfaceProxy::UniqueID                        fSrcProxyID;
     GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
-    GrPendingIOResource<GrSurface, kRead_GrIOType>  fSrc;
-    SkIRect                                         fSrcRect;
-    SkIPoint                                        fDstPoint;
+    GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
+    SkIRect fSrcRect;
+    SkIPoint fDstPoint;
 
     typedef GrOp INHERITED;
 };
index 4f05b4fc96be06b6edfc177d95d16fad3b09ce08..bf7e5ad3cea63fe958b96488a5fba0239273d75c 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "GrVkCaps.h"
-#include "GrRenderTargetProxy.h"
+#include "GrRenderTarget.h"
 #include "GrShaderCaps.h"
 #include "GrVkUtil.h"
 #include "vk/GrVkBackendContext.h"
@@ -53,7 +53,7 @@ GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface*
     this->init(contextOptions, vkInterface, physDev, featureFlags, extensionFlags);
 }
 
-bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
+bool GrVkCaps::initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc,
                                   bool* rectsMustMatch, bool* disallowSubrect) const {
     // Vk doesn't use rectsMustMatch or disallowSubrect. Always return false.
     *rectsMustMatch = false;
@@ -64,7 +64,7 @@ bool GrVkCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc*
     // render target as well.
     desc->fOrigin = src->origin();
     desc->fConfig = src->config();
-    if (src->numColorSamples() > 1 || (src->asTextureProxy() && this->supportsCopiesAsDraws())) {
+    if (src->numColorSamples() > 1 || (src->asTexture() && this->supportsCopiesAsDraws())) {
         desc->fFlags = kRenderTarget_GrSurfaceFlag;
     } else {
         // Just going to use CopyImage here
index e7ffe053e0bc2e2caa3229b66c5bc889761fe1e9..dce9ce22004476b17630d9f1d51ababb0610995b 100644 (file)
@@ -104,8 +104,8 @@ public:
         return fPreferedStencilFormat;
     }
 
-    bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
-                            bool* rectsMustMatch, bool* disallowSubrect) const override;
+    bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc, bool* rectsMustMatch,
+                            bool* disallowSubrect) const override;
 
 private:
     enum VkVendor {
index 08190f17620a55ed0ae143e0fcff9766b7e528f0..2d16fb2ff2d46ac9624cb9b6f8afa3eecb3ce294 100644 (file)
@@ -84,26 +84,23 @@ DEF_TEST(Blend_byte_multiply, r) {
 namespace {
 static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
         GrContext* context, int sampleCnt, int width, int height, GrPixelConfig config,
-        GrSurfaceOrigin origin,
         sk_sp<GrTexture>* backingSurface) {
     GrSurfaceDesc backingDesc;
-    backingDesc.fFlags = kRenderTarget_GrSurfaceFlag;
-    backingDesc.fOrigin = origin;
-    backingDesc.fWidth = width;
     backingDesc.fHeight = height;
+    backingDesc.fWidth = width;
     backingDesc.fConfig = config;
-    backingDesc.fSampleCnt = sampleCnt;
+    backingDesc.fOrigin = kDefault_GrSurfaceOrigin;
+    backingDesc.fFlags = kRenderTarget_GrSurfaceFlag;
 
     *backingSurface = context->resourceProvider()->createTexture(backingDesc, SkBudgeted::kNo);
 
     GrBackendTextureDesc desc;
-    desc.fFlags = kRenderTarget_GrBackendTextureFlag;
-    desc.fOrigin = origin;
+    desc.fConfig = config;
     desc.fWidth = width;
     desc.fHeight = height;
-    desc.fConfig = config;
-    desc.fSampleCnt = sampleCnt;
+    desc.fFlags = kRenderTarget_GrBackendTextureFlag;
     desc.fTextureHandle = (*backingSurface)->getTextureHandle();
+    desc.fSampleCnt = sampleCnt;
     sk_sp<SkSurface> surface =
             SkSurface::MakeFromBackendTextureAsRenderTarget(context, desc, nullptr);
     return surface;
@@ -130,35 +127,31 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ES2BlendWithNoTexture, reporter, ctxInfo)
     };
 
     struct TestCase {
-        RectAndSamplePoint fRectAndPoints;
-        SkRect             fClip;
-        int                fSampleCnt;
-        GrSurfaceOrigin    fOrigin;
+        RectAndSamplePoint rectAndPoints;
+        SkRect clip;
+        int sampleCnt;
     };
     std::vector<TestCase> testCases;
 
-    for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
-        for (int sampleCnt : {0, 4}) {
-            for (auto rectAndPoints : allRectsAndPoints) {
-                for (auto clip : {SkRect::MakeXYWH(0, 0, 10, 10), SkRect::MakeXYWH(1, 1, 8, 8)}) {
-                    testCases.push_back({rectAndPoints, clip, sampleCnt, origin});
-                }
+    for (int sampleCnt : {0, 4}) {
+        for (auto rectAndPoints : allRectsAndPoints) {
+            for (auto clip : {SkRect::MakeXYWH(0, 0, 10, 10), SkRect::MakeXYWH(1, 1, 8, 8)}) {
+                testCases.push_back({rectAndPoints, clip, sampleCnt});
             }
         }
     }
 
     // Run each test case:
     for (auto testCase : testCases) {
-        int sampleCnt = testCase.fSampleCnt;
-        SkRect paintRect = testCase.fRectAndPoints.rect;
-        SkIPoint outPoint = testCase.fRectAndPoints.outPoint;
-        SkIPoint inPoint = testCase.fRectAndPoints.inPoint;
-        GrSurfaceOrigin origin = testCase.fOrigin;
+        int sampleCnt = testCase.sampleCnt;
+        SkRect paintRect = testCase.rectAndPoints.rect;
+        SkIPoint outPoint = testCase.rectAndPoints.outPoint;
+        SkIPoint inPoint = testCase.rectAndPoints.inPoint;
 
         sk_sp<GrTexture> backingSurface;
         // BGRA forces a framebuffer blit on ES2.
         sk_sp<SkSurface> surface = create_gpu_surface_backend_texture_as_render_target(
-                context, sampleCnt, kWidth, kHeight, kConfig, origin, &backingSurface);
+                context, sampleCnt, kWidth, kHeight, kConfig, &backingSurface);
 
         if (!surface && sampleCnt > 0) {
             // Some platforms don't support MSAA.
@@ -168,7 +161,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ES2BlendWithNoTexture, reporter, ctxInfo)
 
         // Fill our canvas with 0xFFFF80
         SkCanvas* canvas = surface->getCanvas();
-        canvas->clipRect(testCase.fClip, false);
+        canvas->clipRect(testCase.clip, false);
         SkPaint black_paint;
         black_paint.setColor(SkColorSetRGB(0xFF, 0xFF, 0x80));
         canvas->drawRect(SkRect::MakeXYWH(0, 0, kWidth, kHeight), black_paint);
index 56d47c514951bbe21ecdcf1dbfadfb31c8fbfc59..0350ff3e5a33791aba76d803f099db9cb91e0679 100644 (file)
@@ -273,8 +273,8 @@ public:
     bool isConfigTexturable(GrPixelConfig config) const override { return false; }
     bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
     bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
-    bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
-                            bool* rectsMustMatch, bool* disallowSubrect) const override {
+    bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc, bool* rectsMustMatch,
+                            bool* disallowSubrect) const override {
         return false;
     }