Make GrPipeline hold a GrRenderTargetProxy (instead of a GrRenderTarget)

In a future world where GrSurface no longer has an origin it will be
useful for the GrPipeline to be holding the GrRenderTargetProxy (which will
still have an origin).

Change-Id: I743a8cc07b6b92f8116227fb77b7c37da43cde8a
Reviewed-on: https://skia-review.googlesource.com/26804
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index a44f03b..a6a71af 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -245,7 +245,7 @@
         return;
     }
 
-    GrPipeline pipeline(state->drawOpArgs().fRenderTarget, GrPipeline::ScissorState::kDisabled,
+    GrPipeline pipeline(state->drawOpArgs().fProxy, GrPipeline::ScissorState::kDisabled,
                         SkBlendMode::kSrcOver);
 
     GrCCPRCoverageProcessor ccprProc(fView->fMode, pointsBuffer.get());
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index afe3956..3487f6f 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -457,7 +457,7 @@
 }
 
 const GrGpu::MultisampleSpecs& GrGpu::queryMultisampleSpecs(const GrPipeline& pipeline) {
-    GrRenderTarget* rt = pipeline.getRenderTarget();
+    GrRenderTarget* rt = pipeline.renderTarget();
     SkASSERT(rt->numStencilSamples() > 1);
 
     GrStencilSettings stencil;
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h
index a701965..c73fee0 100644
--- a/src/gpu/GrOpFlushState.h
+++ b/src/gpu/GrOpFlushState.h
@@ -97,7 +97,9 @@
 
     /** Additional data required on a per-op basis when executing GrDrawOps. */
     struct DrawOpArgs {
-        GrRenderTarget*           fRenderTarget;
+        GrRenderTarget* renderTarget() const { return fProxy->priv().peekRenderTarget(); }
+
+        GrRenderTargetProxy*      fProxy;
         const GrAppliedClip*      fAppliedClip;
         GrXferProcessor::DstProxy fDstProxy;
     };
@@ -232,7 +234,7 @@
         this->state()->putBackVertexSpace(vertices * vertexStride);
     }
 
-    GrRenderTarget* renderTarget() const { return this->state()->drawOpArgs().fRenderTarget; }
+    GrRenderTargetProxy* proxy() const { return this->state()->drawOpArgs().fProxy; }
 
     const GrAppliedClip* clip() const { return this->state()->drawOpArgs().fAppliedClip; }
 
@@ -253,7 +255,7 @@
         GrPipeline::InitArgs pipelineArgs;
         pipelineArgs.fFlags = pipelineFlags;
         pipelineArgs.fProcessors = processorSet;
-        pipelineArgs.fRenderTarget = this->renderTarget();
+        pipelineArgs.fProxy = this->proxy();
         pipelineArgs.fAppliedClip = this->clip();
         pipelineArgs.fDstProxy = this->dstProxy();
         pipelineArgs.fCaps = &this->caps();
diff --git a/src/gpu/GrPathRendering.cpp b/src/gpu/GrPathRendering.cpp
index 15ae6c1..a40f0af 100644
--- a/src/gpu/GrPathRendering.cpp
+++ b/src/gpu/GrPathRendering.cpp
@@ -118,7 +118,7 @@
                                const GrPath* path) {
     fGpu->handleDirtyContext();
     if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) {
-        fGpu->xferBarrier(pipeline.getRenderTarget(), barrierType);
+        fGpu->xferBarrier(pipeline.renderTarget(), barrierType);
     }
     this->onDrawPath(pipeline, primProc, stencilPassSettings, path);
 }
@@ -135,7 +135,7 @@
                                 int count) {
     fGpu->handleDirtyContext();
     if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) {
-        fGpu->xferBarrier(pipeline.getRenderTarget(), barrierType);
+        fGpu->xferBarrier(pipeline.renderTarget(), barrierType);
     }
 #ifdef SK_DEBUG
     pathRange->assertPathsLoaded(indices, indexType, count);
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index 0483d42..c7f131a 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -18,11 +18,11 @@
 #include "ops/GrOp.h"
 
 void GrPipeline::init(const InitArgs& args) {
-    SkASSERT(args.fRenderTarget);
+    SkASSERT(args.fProxy);
     SkASSERT(args.fProcessors);
     SkASSERT(args.fProcessors->isFinalized());
 
-    fRenderTarget.reset(args.fRenderTarget);
+    fProxy.reset(args.fProxy);
 
     fFlags = args.fFlags;
     if (args.fAppliedClip) {
@@ -99,21 +99,21 @@
 
 GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
     if (fDstTextureProxy.get() &&
-        fDstTextureProxy.get()->priv().peekTexture() == fRenderTarget.get()->asTexture()) {
+        fDstTextureProxy.get()->priv().peekTexture() == fProxy.get()->priv().peekTexture()) {
         return kTexture_GrXferBarrierType;
     }
     return this->getXferProcessor().xferBarrierType(caps);
 }
 
-GrPipeline::GrPipeline(GrRenderTarget* rt, ScissorState scissorState, SkBlendMode blendmode)
-    : fRenderTarget(rt)
-    , fScissorState()
-    , fWindowRectsState()
-    , fUserStencilSettings(&GrUserStencilSettings::kUnused)
-    , fFlags()
-    , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
-    , fFragmentProcessors()
-    , fNumColorProcessors(0) {
+GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, ScissorState scissorState, SkBlendMode blendmode)
+        : fProxy(proxy)
+        , fScissorState()
+        , fWindowRectsState()
+        , fUserStencilSettings(&GrUserStencilSettings::kUnused)
+        , fFlags()
+        , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
+        , fFragmentProcessors()
+        , fNumColorProcessors(0) {
     if (ScissorState::kEnabled == scissorState) {
         fScissorState.set({0, 0, 0, 0}); // caller will use the DynamicState struct.
     }
@@ -124,7 +124,7 @@
 bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) {
     SkASSERT(&a != &b);
 
-    if (a.getRenderTarget() != b.getRenderTarget() ||
+    if (a.proxy() != b.proxy() ||
         a.fFragmentProcessors.count() != b.fFragmentProcessors.count() ||
         a.fNumColorProcessors != b.fNumColorProcessors ||
         a.fScissorState != b.fScissorState ||
diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h
index 3a194d6..b442304 100644
--- a/src/gpu/GrPipeline.h
+++ b/src/gpu/GrPipeline.h
@@ -15,7 +15,7 @@
 #include "GrProcessorSet.h"
 #include "GrProgramDesc.h"
 #include "GrRect.h"
-#include "GrRenderTarget.h"
+#include "GrRenderTargetProxy.h"
 #include "GrScissorState.h"
 #include "GrUserStencilSettings.h"
 #include "GrWindowRectsState.h"
@@ -79,7 +79,7 @@
         const GrProcessorSet* fProcessors = nullptr;  // Must be finalized
         const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
         const GrAppliedClip* fAppliedClip = nullptr;
-        GrRenderTarget* fRenderTarget = nullptr;
+        GrRenderTargetProxy* fProxy = nullptr;
         const GrCaps* fCaps = nullptr;
         GrResourceProvider* fResourceProvider = nullptr;
         GrXferProcessor::DstProxy fDstProxy;
@@ -105,7 +105,7 @@
      * must be "Porter Duff" (<= kLastCoeffMode). If using ScissorState::kEnabled, the caller must
      * specify a scissor rectangle through the DynamicState struct.
      **/
-    GrPipeline(GrRenderTarget*, ScissorState, SkBlendMode);
+    GrPipeline(GrRenderTargetProxy*, ScissorState, SkBlendMode);
 
     GrPipeline(const InitArgs& args) { this->init(args); }
 
@@ -116,7 +116,7 @@
     void init(const InitArgs&);
 
     /** True if the pipeline has been initialized. */
-    bool isInitialized() const { return SkToBool(fRenderTarget.get()); }
+    bool isInitialized() const { return SkToBool(fProxy.get()); }
 
     /// @}
 
@@ -212,7 +212,8 @@
      *
      * @return    The currently set render target.
      */
-    GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
+    GrRenderTargetProxy* proxy() const { return fProxy.get(); }
+    GrRenderTarget* renderTarget() const { return fProxy.get()->priv().peekRenderTarget(); }
 
     const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
 
@@ -270,14 +271,14 @@
         kIsBad_Flag = 0x40,
     };
 
-    using RenderTarget = GrPendingIOResource<GrRenderTarget, kWrite_GrIOType>;
+    using RenderTargetProxy = GrPendingIOResource<GrRenderTargetProxy, kWrite_GrIOType>;
     using DstTextureProxy = GrPendingIOResource<GrTextureProxy, kRead_GrIOType>;
     using PendingFragmentProcessor = GrPendingProgramElement<const GrFragmentProcessor>;
     using FragmentProcessorArray = SkAutoSTArray<8, PendingFragmentProcessor>;
 
     DstTextureProxy fDstTextureProxy;
     SkIPoint fDstTextureOffset;
-    RenderTarget fRenderTarget;
+    RenderTargetProxy fProxy;
     GrScissorState fScissorState;
     GrWindowRectsState fWindowRectsState;
     const GrUserStencilSettings* fUserStencilSettings;
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index ca81e5a..f40c6b6 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -218,17 +218,19 @@
     // make sure any padding in the header is zeroed.
     memset(header, 0, kHeaderSize);
 
-    GrRenderTarget* rt = pipeline.getRenderTarget();
+    GrRenderTargetProxy* proxy = pipeline.proxy();
 
     if (requiredFeatures & GrProcessor::kSampleLocations_RequiredFeature) {
         SkASSERT(pipeline.isHWAntialiasState());
+
+        GrRenderTarget* rt = pipeline.renderTarget();
         header->fSamplePatternKey =
             rt->renderTargetPriv().getMultisampleSpecs(pipeline).fUniqueID;
     } else {
         header->fSamplePatternKey = 0;
     }
 
-    header->fOutputSwizzle = shaderCaps.configOutputSwizzle(rt->config()).asKey();
+    header->fOutputSwizzle = shaderCaps.configOutputSwizzle(proxy->config()).asKey();
 
     header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
     header->fColorFragmentProcessorCnt = pipeline.numColorFragmentProcessors();
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index ae63c23..e43c910 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -91,7 +91,7 @@
 
 const GrGpu::MultisampleSpecs&
 GrRenderTargetPriv::getMultisampleSpecs(const GrPipeline& pipeline) const {
-    SkASSERT(fRenderTarget == pipeline.getRenderTarget()); // TODO: remove RT from pipeline.
+    SkASSERT(fRenderTarget == pipeline.renderTarget()); // TODO: remove RT from pipeline.
     GrGpu* gpu = fRenderTarget->getGpu();
     if (auto id = fRenderTarget->fMultisampleSpecsID) {
         SkASSERT(gpu->queryMultisampleSpecs(pipeline).fUniqueID == id);
diff --git a/src/gpu/GrRenderTargetContextPriv.h b/src/gpu/GrRenderTargetContextPriv.h
index b32eaed..2cfd5c8 100644
--- a/src/gpu/GrRenderTargetContextPriv.h
+++ b/src/gpu/GrRenderTargetContextPriv.h
@@ -14,6 +14,7 @@
 
 class GrFixedClip;
 class GrPath;
+class GrRenderTargetPriv;
 struct GrUserStencilSettings;
 
 /** Class that adds methods to GrRenderTargetContext that are only intended for use internal to
diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp
index d1c1425..f0c97e4 100644
--- a/src/gpu/GrRenderTargetOpList.cpp
+++ b/src/gpu/GrRenderTargetOpList.cpp
@@ -68,7 +68,7 @@
     for (int i = 0; i < fRecordedOps.count(); ++i) {
         if (fRecordedOps[i].fOp) {
             GrOpFlushState::DrawOpArgs opArgs = {
-                fTarget.get()->priv().peekRenderTarget(),
+                fTarget.get()->asRenderTargetProxy(),
                 fRecordedOps[i].fAppliedClip,
                 fRecordedOps[i].fDstProxy
             };
@@ -138,7 +138,7 @@
         }
 
         GrOpFlushState::DrawOpArgs opArgs {
-            fTarget.get()->priv().peekRenderTarget(),
+            fTarget.get()->asRenderTargetProxy(),
             fRecordedOps[i].fAppliedClip,
             fRecordedOps[i].fDstProxy
         };
diff --git a/src/gpu/ccpr/GrCCPRCoverageOpsBuilder.cpp b/src/gpu/ccpr/GrCCPRCoverageOpsBuilder.cpp
index d14cf1e..5beba4c 100644
--- a/src/gpu/ccpr/GrCCPRCoverageOpsBuilder.cpp
+++ b/src/gpu/ccpr/GrCCPRCoverageOpsBuilder.cpp
@@ -498,9 +498,9 @@
 void CoverageOp::onExecute(GrOpFlushState* flushState) {
     using Mode = GrCCPRCoverageProcessor::Mode;
 
-    SkDEBUGCODE(GrCCPRCoverageProcessor::Validate(flushState->drawOpArgs().fRenderTarget));
+    SkDEBUGCODE(GrCCPRCoverageProcessor::Validate(flushState->drawOpArgs().fProxy));
 
-    GrPipeline pipeline(flushState->drawOpArgs().fRenderTarget, GrPipeline::ScissorState::kEnabled,
+    GrPipeline pipeline(flushState->drawOpArgs().fProxy, GrPipeline::ScissorState::kEnabled,
                         SkBlendMode::kPlus);
 
     fMeshesScratchBuffer.reserve(1 + fScissorBatches.count());
diff --git a/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp b/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp
index 5f1833a..85b989b 100644
--- a/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp
@@ -7,6 +7,7 @@
 
 #include "GrCCPRCoverageProcessor.h"
 
+#include "GrRenderTargetProxy.h"
 #include "ccpr/GrCCPRTriangleProcessor.h"
 #include "ccpr/GrCCPRQuadraticProcessor.h"
 #include "ccpr/GrCCPRCubicProcessor.h"
@@ -346,10 +347,10 @@
 
 #include "GrRenderTarget.h"
 
-void GrCCPRCoverageProcessor::Validate(GrRenderTarget* atlasTexture) {
-    SkASSERT(kAtlasOrigin == atlasTexture->origin());
-    SkASSERT(GrPixelConfigIsAlphaOnly(atlasTexture->config()));
-    SkASSERT(GrPixelConfigIsFloatingPoint(atlasTexture->config()));
+void GrCCPRCoverageProcessor::Validate(GrRenderTargetProxy* atlasProxy) {
+    SkASSERT(kAtlasOrigin == atlasProxy->origin());
+    SkASSERT(GrPixelConfigIsAlphaOnly(atlasProxy->config()));
+    SkASSERT(GrPixelConfigIsFloatingPoint(atlasProxy->config()));
 }
 
 #endif
diff --git a/src/gpu/ccpr/GrCCPRCoverageProcessor.h b/src/gpu/ccpr/GrCCPRCoverageProcessor.h
index 86f7d46..574cf4a 100644
--- a/src/gpu/ccpr/GrCCPRCoverageProcessor.h
+++ b/src/gpu/ccpr/GrCCPRCoverageProcessor.h
@@ -104,7 +104,7 @@
     void enableDebugVisualizations() { fDebugVisualizations = true; }
     bool debugVisualizations() const { return fDebugVisualizations; }
 
-    static void Validate(GrRenderTarget* atlasTexture);
+    static void Validate(GrRenderTargetProxy* atlasProxy);
 #endif
 
     class PrimitiveProcessor;
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
index 45fad1f..5a9afa1 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
@@ -298,7 +298,7 @@
     args.fCaps = &flushState->caps();
     args.fProcessors = &fProcessors;
     args.fFlags = fSRGBFlags;
-    args.fRenderTarget = flushState->drawOpArgs().fRenderTarget;
+    args.fProxy = flushState->drawOpArgs().fProxy;
     args.fDstProxy = flushState->drawOpArgs().fDstProxy;
     pipeline.init(args);
 
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 5209e3e..412f3c5 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -1845,13 +1845,13 @@
     if (blendInfo.fWriteColor) {
         // Swizzle the blend to match what the shader will output.
         const GrSwizzle& swizzle = this->caps()->shaderCaps()->configOutputSwizzle(
-            pipeline.getRenderTarget()->config());
+            pipeline.proxy()->config());
         this->flushBlend(blendInfo, swizzle);
     }
 
     program->setData(primProc, pipeline);
 
-    GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
+    GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.renderTarget());
     GrStencilSettings stencil;
     if (pipeline.isStencilEnabled()) {
         // TODO: attach stencil and create settings during render target flush.
@@ -2546,12 +2546,12 @@
 
     for (int i = 0; i < meshCount; ++i) {
         if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*this->caps())) {
-            this->xferBarrier(pipeline.getRenderTarget(), barrierType);
+            this->xferBarrier(pipeline.renderTarget(), barrierType);
         }
 
         if (dynamicStates) {
             if (pipeline.getScissorState().enabled()) {
-                GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
+                GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.renderTarget());
                 this->flushScissor(dynamicStates[i].fScissorRect,
                                    glRT->getViewport(), glRT->origin());
             }
diff --git a/src/gpu/gl/GrGLGpuCommandBuffer.h b/src/gpu/gl/GrGLGpuCommandBuffer.h
index c67aeaf..5ca211a 100644
--- a/src/gpu/gl/GrGLGpuCommandBuffer.h
+++ b/src/gpu/gl/GrGLGpuCommandBuffer.h
@@ -55,7 +55,7 @@
                 const GrPipeline::DynamicState dynamicStates[],
                 int meshCount,
                 const SkRect& bounds) override {
-        GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
+        GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.renderTarget());
         if (!fRenderTarget) {
             fRenderTarget = target;
         }
diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp
index 2ff5dc7..b79c17f 100644
--- a/src/gpu/gl/GrGLGpuProgramCache.cpp
+++ b/src/gpu/gl/GrGLGpuProgramCache.cpp
@@ -82,7 +82,7 @@
     std::unique_ptr<Entry>* entry = fMap.find(desc);
     if (!entry) {
         // Didn't find an origin-independent version, check with the specific origin
-        GrSurfaceOrigin origin = pipeline.getRenderTarget()->origin();
+        GrSurfaceOrigin origin = pipeline.proxy()->origin();
         desc.setSurfaceOriginKey(GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(origin));
         desc.finalize();
         entry = fMap.find(desc);
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index f133c1b..aa67bed 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -70,7 +70,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline) {
-    this->setRenderTargetState(primProc, pipeline.getRenderTarget());
+    this->setRenderTargetState(primProc, pipeline.renderTarget());
 
     // we set the textures, and uniforms for installed processors in a generic way, but subclasses
     // of GLProgram determine how to set coord transforms
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index dc70bd6..8172002 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -90,7 +90,7 @@
     if (outInputs->fFlipY) {
         GrProgramDesc* d = this->desc();
         d->setSurfaceOriginKey(GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(
-                                                     this->pipeline().getRenderTarget()->origin()));
+                                                     this->pipeline().proxy()->origin()));
         d->finalize();
     }
 
@@ -113,7 +113,7 @@
     // compile shaders and bind attributes / uniforms
     SkSL::Program::Settings settings;
     settings.fCaps = this->gpu()->glCaps().shaderCaps();
-    settings.fFlipY = this->pipeline().getRenderTarget()->origin() != kTopLeft_GrSurfaceOrigin;
+    settings.fFlipY = this->pipeline().proxy()->origin() != kTopLeft_GrSurfaceOrigin;
     SkSL::Program::Inputs inputs;
     SkTDArray<GrGLuint> shadersToDelete;
     if (!this->compileAndAttachShaders(fVS, programID, GR_GL_VERTEX_SHADER, &shadersToDelete,
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
index 4fd886b..6c0528e 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
@@ -300,7 +300,7 @@
 void GrGLSLFragmentShaderBuilder::defineSampleOffsetArray(const char* name, const SkMatrix& m) {
     SkASSERT(fProgramBuilder->caps()->sampleLocationsSupport());
     const GrPipeline& pipeline = fProgramBuilder->pipeline();
-    const GrRenderTargetPriv& rtp = pipeline.getRenderTarget()->renderTargetPriv();
+    const GrRenderTargetPriv& rtp = pipeline.renderTarget()->renderTargetPriv();
     const GrGpu::MultisampleSpecs& specs = rtp.getMultisampleSpecs(pipeline);
     SkSTArray<16, SkPoint, true> offsets;
     offsets.push_back_n(specs.fEffectiveSampleCnt);
diff --git a/src/gpu/instanced/InstanceProcessor.cpp b/src/gpu/instanced/InstanceProcessor.cpp
index 500986e..39c1cf2 100644
--- a/src/gpu/instanced/InstanceProcessor.cpp
+++ b/src/gpu/instanced/InstanceProcessor.cpp
@@ -1681,7 +1681,7 @@
             return new BackendCoverage(opInfo, inputs);
         case GrAAType::kMSAA:
         case GrAAType::kMixedSamples: {
-            const GrRenderTargetPriv& rtp = pipeline.getRenderTarget()->renderTargetPriv();
+            const GrRenderTargetPriv& rtp = pipeline.renderTarget()->renderTargetPriv();
             const GrGpu::MultisampleSpecs& specs = rtp.getMultisampleSpecs(pipeline);
             return new BackendMultisample(opInfo, inputs, specs.fEffectiveSampleCnt);
         }
diff --git a/src/gpu/instanced/InstancedOp.cpp b/src/gpu/instanced/InstancedOp.cpp
index 9b80540..ab2b758 100644
--- a/src/gpu/instanced/InstancedOp.cpp
+++ b/src/gpu/instanced/InstancedOp.cpp
@@ -238,12 +238,12 @@
     if (fDisableSRGBOutputConversion) {
         args.fFlags |= GrPipeline::kDisableOutputConversionToSRGB_Flag;
     }
-    args.fRenderTarget = state->drawOpArgs().fRenderTarget;
+    args.fProxy = state->drawOpArgs().fProxy;
     args.fDstProxy = state->drawOpArgs().fDstProxy;
     pipeline.init(args);
 
     if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*state->gpu()->caps())) {
-        state->gpu()->xferBarrier(pipeline.getRenderTarget(), barrierType);
+        state->gpu()->xferBarrier(pipeline.renderTarget(), barrierType);
     }
     fInstancedRendering->draw(pipeline, fInfo, this);
 }
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index d29d4cf..a56c201 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -9,6 +9,7 @@
 #define GrMockGpu_DEFINED
 
 #include "GrGpu.h"
+#include "GrRenderTarget.h"
 #include "GrSemaphore.h"
 #include "GrTexture.h"
 #include "SkTHash.h"
diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h
index 60682b3..3bccd41 100644
--- a/src/gpu/mock/GrMockTexture.h
+++ b/src/gpu/mock/GrMockTexture.h
@@ -8,6 +8,7 @@
 #define GrMockTexture_DEFINED
 
 #include "GrMockGpu.h"
+#include "GrRenderTarget.h"
 #include "GrTexture.h"
 #include "GrTexturePriv.h"
 #include "mock/GrMockTypes.h"
diff --git a/src/gpu/ops/GrClearOp.cpp b/src/gpu/ops/GrClearOp.cpp
index e40862b..722d169 100644
--- a/src/gpu/ops/GrClearOp.cpp
+++ b/src/gpu/ops/GrClearOp.cpp
@@ -32,7 +32,7 @@
 }
 
 void GrClearOp::onExecute(GrOpFlushState* state) {
-    SkASSERT(state->drawOpArgs().fRenderTarget);
+    SkASSERT(state->drawOpArgs().renderTarget());
 
-    state->commandBuffer()->clear(state->drawOpArgs().fRenderTarget, fClip, fColor);
+    state->commandBuffer()->clear(state->drawOpArgs().renderTarget(), fClip, fColor);
 }
diff --git a/src/gpu/ops/GrClearStencilClipOp.h b/src/gpu/ops/GrClearStencilClipOp.h
index 87a2b4d..ac7b0a8 100644
--- a/src/gpu/ops/GrClearStencilClipOp.h
+++ b/src/gpu/ops/GrClearStencilClipOp.h
@@ -55,10 +55,10 @@
     void onPrepare(GrOpFlushState*) override {}
 
     void onExecute(GrOpFlushState* state) override {
-        SkASSERT(state->drawOpArgs().fRenderTarget);
+        SkASSERT(state->drawOpArgs().renderTarget());
 
-        state->commandBuffer()->clearStencilClip(state->drawOpArgs().fRenderTarget,
-                                                 fClip, fInsideStencilMask);
+        GrRenderTarget* rt = state->drawOpArgs().renderTarget();
+        state->commandBuffer()->clearStencilClip(rt, fClip, fInsideStencilMask);
     }
 
     const GrFixedClip fClip;
diff --git a/src/gpu/ops/GrDiscardOp.h b/src/gpu/ops/GrDiscardOp.h
index 822f818..dd707e3 100644
--- a/src/gpu/ops/GrDiscardOp.h
+++ b/src/gpu/ops/GrDiscardOp.h
@@ -40,9 +40,9 @@
     void onPrepare(GrOpFlushState*) override {}
 
     void onExecute(GrOpFlushState* state) override {
-        SkASSERT(state->drawOpArgs().fRenderTarget);
+        SkASSERT(state->drawOpArgs().renderTarget());
 
-        state->commandBuffer()->discard(state->drawOpArgs().fRenderTarget);
+        state->commandBuffer()->discard(state->drawOpArgs().renderTarget());
     }
 
     typedef GrOp INHERITED;
diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp
index c33af39..420a3a2 100644
--- a/src/gpu/ops/GrDrawPathOp.cpp
+++ b/src/gpu/ops/GrDrawPathOp.cpp
@@ -46,7 +46,7 @@
     }
     args.fUserStencil = &kCoverPass;
     args.fAppliedClip = state.drawOpArgs().fAppliedClip;
-    args.fRenderTarget = state.drawOpArgs().fRenderTarget;
+    args.fProxy = state.drawOpArgs().fProxy;
     args.fCaps = &state.caps();
     args.fResourceProvider = state.resourceProvider();
     args.fDstProxy = state.drawOpArgs().fDstProxy;
@@ -61,7 +61,7 @@
     const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
     bool stencilClip = appliedClip && appliedClip->hasStencilClip();
     stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
-                   flushState.drawOpArgs().fRenderTarget->renderTargetPriv().numStencilBits());
+                   flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
 }
 
 //////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/ops/GrMeshDrawOp.cpp b/src/gpu/ops/GrMeshDrawOp.cpp
index e42f319..110f6e5 100644
--- a/src/gpu/ops/GrMeshDrawOp.cpp
+++ b/src/gpu/ops/GrMeshDrawOp.cpp
@@ -70,10 +70,10 @@
         while (currUploadIdx < fInlineUploads.count() &&
                fInlineUploads[currUploadIdx].fUploadBeforeToken == drawToken) {
             state->commandBuffer()->inlineUpload(state, fInlineUploads[currUploadIdx++].fUpload,
-                                                 state->drawOpArgs().fRenderTarget);
+                                                 state->drawOpArgs().renderTarget());
         }
         const QueuedDraw& draw = fQueuedDraws[currDrawIdx];
-        SkASSERT(draw.fPipeline->getRenderTarget() == state->drawOpArgs().fRenderTarget);
+        SkASSERT(draw.fPipeline->proxy() == state->drawOpArgs().fProxy);
         state->commandBuffer()->draw(*draw.fPipeline, *draw.fGeometryProcessor.get(),
                                      fMeshes.begin() + currMeshIdx, nullptr, draw.fMeshCnt,
                                      this->bounds());
diff --git a/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp b/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp
index 0d97de4c..ee59a8e 100644
--- a/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp
+++ b/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp
@@ -126,7 +126,7 @@
     GrPipeline::InitArgs args;
     args.fFlags = this->pipelineFlags();
     args.fProcessors = &this->processors();
-    args.fRenderTarget = target->renderTarget();
+    args.fProxy = target->proxy();
     args.fAppliedClip = target->clip();
     args.fDstProxy = target->dstProxy();
     args.fCaps = &target->caps();
diff --git a/src/gpu/ops/GrStencilPathOp.cpp b/src/gpu/ops/GrStencilPathOp.cpp
index 01042f6..41091f3 100644
--- a/src/gpu/ops/GrStencilPathOp.cpp
+++ b/src/gpu/ops/GrStencilPathOp.cpp
@@ -11,9 +11,9 @@
 #include "GrOpFlushState.h"
 
 void GrStencilPathOp::onExecute(GrOpFlushState* state) {
-    SkASSERT(state->drawOpArgs().fRenderTarget);
+    SkASSERT(state->drawOpArgs().renderTarget());
 
-    GrPathRendering::StencilPathArgs args(fUseHWAA, state->drawOpArgs().fRenderTarget,
+    GrPathRendering::StencilPathArgs args(fUseHWAA, state->drawOpArgs().renderTarget(),
                                           &fViewMatrix, &fScissor, &fStencil);
     state->gpu()->pathRendering()->stencilPath(args, fPath.get());
 }
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index 6e9c292..6cb1d5b 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -493,7 +493,7 @@
 
     pipelineState->bind(fGpu, cbInfo.currentCmdBuf());
 
-    GrRenderTarget* rt = pipeline.getRenderTarget();
+    GrRenderTarget* rt = pipeline.renderTarget();
 
     if (!pipeline.getScissorState().enabled()) {
         GrVkPipeline::SetDynamicScissorRectState(fGpu, cbInfo.currentCmdBuf(), rt,
@@ -549,7 +549,7 @@
                                   const GrPipeline::DynamicState dynamicStates[],
                                   int meshCount,
                                   const SkRect& bounds) {
-    GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(pipeline.getRenderTarget());
+    GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(pipeline.renderTarget());
     if (!fRenderTarget) {
         this->init(target);
     }
diff --git a/src/gpu/vk/GrVkPipeline.cpp b/src/gpu/vk/GrVkPipeline.cpp
index 567d6e8..e356133 100644
--- a/src/gpu/vk/GrVkPipeline.cpp
+++ b/src/gpu/vk/GrVkPipeline.cpp
@@ -239,7 +239,7 @@
     multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
     multisampleInfo->pNext = nullptr;
     multisampleInfo->flags = 0;
-    int numSamples = pipeline.getRenderTarget()->numColorSamples();
+    int numSamples = pipeline.proxy()->numColorSamples();
     SkAssertResult(GrSampleCountToVkSampleCount(numSamples,
                    &multisampleInfo->rasterizationSamples));
     float sampleShading = primProc.getSampleShading();
diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp
index e4f6faf..083d225 100644
--- a/src/gpu/vk/GrVkPipelineState.cpp
+++ b/src/gpu/vk/GrVkPipelineState.cpp
@@ -236,7 +236,7 @@
     // freeing the tempData between calls.
     this->freeTempResources(gpu);
 
-    this->setRenderTargetState(pipeline.getRenderTarget());
+    this->setRenderTargetState(pipeline.proxy());
 
     SkSTArray<8, const GrResourceIOProcessor::TextureSampler*> textureBindings;
     SkSTArray<8, const GrResourceIOProcessor::BufferAccess*> bufferAccesses;
@@ -461,7 +461,9 @@
     }
 }
 
-void GrVkPipelineState::setRenderTargetState(const GrRenderTarget* rt) {
+void GrVkPipelineState::setRenderTargetState(const GrRenderTargetProxy* proxy) {
+    GrRenderTarget* rt = proxy->priv().peekRenderTarget();
+
     // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
     if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
         fRenderTargetState.fRenderTargetSize.fHeight != rt->height()) {
@@ -472,10 +474,10 @@
     SkISize size;
     size.set(rt->width(), rt->height());
     SkASSERT(fBuiltinUniformHandles.fRTAdjustmentUni.isValid());
-    if (fRenderTargetState.fRenderTargetOrigin != rt->origin() ||
+    if (fRenderTargetState.fRenderTargetOrigin != proxy->origin() ||
         fRenderTargetState.fRenderTargetSize != size) {
         fRenderTargetState.fRenderTargetSize = size;
-        fRenderTargetState.fRenderTargetOrigin = rt->origin();
+        fRenderTargetState.fRenderTargetOrigin = proxy->origin();
 
         float rtAdjustmentVec[4];
         fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec);
@@ -576,7 +578,7 @@
     }
 
     GrProcessorKeyBuilder b(&desc->key());
-    GrVkRenderTarget* vkRT = (GrVkRenderTarget*)pipeline.getRenderTarget();
+    GrVkRenderTarget* vkRT = (GrVkRenderTarget*)pipeline.renderTarget();
     vkRT->simpleRenderPass()->genKey(&b);
 
     stencil.genKey(&b);
diff --git a/src/gpu/vk/GrVkPipelineState.h b/src/gpu/vk/GrVkPipelineState.h
index 190ad06..9481aa1 100644
--- a/src/gpu/vk/GrVkPipelineState.h
+++ b/src/gpu/vk/GrVkPipelineState.h
@@ -152,7 +152,7 @@
     };
 
     // Helper for setData() that sets the view matrix and loads the render target height uniform
-    void setRenderTargetState(const GrRenderTarget*);
+    void setRenderTargetState(const GrRenderTargetProxy*);
 
     // GrVkResources
     GrVkPipeline* fPipeline;
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index 05a1e95..a3528dc 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -80,7 +80,7 @@
     }
     if (inputs.fFlipY) {
         desc->setSurfaceOriginKey(GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(
-                                                     this->pipeline().getRenderTarget()->origin()));
+                                                     this->pipeline().proxy()->origin()));
         desc->finalize();
     }
     return result;
@@ -140,7 +140,7 @@
     VkPipelineShaderStageCreateInfo shaderStageInfo[3];
     SkSL::Program::Settings settings;
     settings.fCaps = this->caps()->shaderCaps();
-    settings.fFlipY = this->pipeline().getRenderTarget()->origin() != kTopLeft_GrSurfaceOrigin;
+    settings.fFlipY = this->pipeline().proxy()->origin() != kTopLeft_GrSurfaceOrigin;
     SkAssertResult(this->createVkShaderModule(VK_SHADER_STAGE_VERTEX_BIT,
                                               fVS,
                                               &vertShaderModule,
diff --git a/src/gpu/vk/GrVkPipelineStateCache.cpp b/src/gpu/vk/GrVkPipelineStateCache.cpp
index f8d77a9..66a4bf3 100644
--- a/src/gpu/vk/GrVkPipelineStateCache.cpp
+++ b/src/gpu/vk/GrVkPipelineStateCache.cpp
@@ -83,7 +83,7 @@
 #endif
     GrStencilSettings stencil;
     if (pipeline.isStencilEnabled()) {
-        GrRenderTarget* rt = pipeline.getRenderTarget();
+        GrRenderTarget* rt = pipeline.renderTarget();
         // TODO: attach stencil and create settings during render target flush.
         SkASSERT(rt->renderTargetPriv().getStencilAttachment());
         stencil.reset(*pipeline.getUserStencil(), pipeline.hasStencilClip(),
@@ -102,7 +102,7 @@
     std::unique_ptr<Entry>* entry = fMap.find(desc);
     if (!entry) {
         // Didn't find an origin-independent version, check with the specific origin
-        GrSurfaceOrigin origin = pipeline.getRenderTarget()->origin();
+        GrSurfaceOrigin origin = pipeline.proxy()->origin();
         desc.setSurfaceOriginKey(GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(origin));
         desc.finalize();
         entry = fMap.find(desc);
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index a474ffe..37aa07a 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -9,6 +9,7 @@
 
 #include "GrBackendSurface.h"
 #include "GrContextPriv.h"
+#include "GrRenderTarget.h"
 #include "GrRenderTargetContextPriv.h"
 #include "GrTexture.h"
 
diff --git a/tests/GpuSampleLocationsTest.cpp b/tests/GpuSampleLocationsTest.cpp
index 0f8fd7f..b11c0f2 100644
--- a/tests/GpuSampleLocationsTest.cpp
+++ b/tests/GpuSampleLocationsTest.cpp
@@ -132,7 +132,7 @@
         for (int i = 0; i < numTestPatterns; ++i) {
             testInterface->overrideSamplePattern(kTestPatterns[i]);
             for (GrRenderTargetContext* rtc : {bottomUps[i].get(), topDowns[i].get()}) {
-                GrPipeline dummyPipeline(rtc->accessRenderTarget(),
+                GrPipeline dummyPipeline(rtc->asRenderTargetProxy(),
                                          GrPipeline::ScissorState::kDisabled,
                                          SkBlendMode::kSrcOver);
                 GrRenderTarget* rt = rtc->accessRenderTarget();
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 0e67acf..922a996 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -367,8 +367,8 @@
 }
 
 void DrawMeshHelper::drawMesh(const GrMesh& mesh) {
-    GrRenderTarget* rt = fState->drawOpArgs().fRenderTarget;
-    GrPipeline pipeline(rt, GrPipeline::ScissorState::kDisabled, SkBlendMode::kSrc);
+    GrRenderTargetProxy* proxy = fState->drawOpArgs().fProxy;
+    GrPipeline pipeline(proxy, GrPipeline::ScissorState::kDisabled, SkBlendMode::kSrc);
     GrMeshTestProcessor mtp(mesh.isInstanced(), mesh.hasVertexData());
     fState->commandBuffer()->draw(pipeline, mtp, &mesh, nullptr, 1,
                                   SkRect::MakeIWH(kImageWidth, kImageHeight));
diff --git a/tests/GrPipelineDynamicStateTest.cpp b/tests/GrPipelineDynamicStateTest.cpp
index 007702a..2c9e2c3 100644
--- a/tests/GrPipelineDynamicStateTest.cpp
+++ b/tests/GrPipelineDynamicStateTest.cpp
@@ -125,8 +125,8 @@
     bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
     void onPrepare(GrOpFlushState*) override {}
     void onExecute(GrOpFlushState* state) override {
-        GrRenderTarget* rt = state->drawOpArgs().fRenderTarget;
-        GrPipeline pipeline(rt, fScissorState, SkBlendMode::kSrc);
+        GrRenderTargetProxy* proxy = state->drawOpArgs().fProxy;
+        GrPipeline pipeline(proxy, fScissorState, SkBlendMode::kSrc);
         SkSTArray<kNumMeshes, GrMesh> meshes;
         for (int i = 0; i < kNumMeshes; ++i) {
             GrMesh& mesh = meshes.emplace_back(GrPrimitiveType::kTriangleStrip);
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index f1d6a26..71575c7 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -12,6 +12,7 @@
 #include "GrContext.h"
 #include "GrContextPriv.h"
 #include "GrGpu.h"
+#include "GrRenderTarget.h"
 #include "GrResourceProvider.h"
 #include "GrTest.h"
 #include "GrTexture.h"
diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp
index 4e36315..f64043d 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -12,6 +12,7 @@
 #if SK_SUPPORT_GPU && defined(SK_VULKAN)
 
 #include "GrContextFactory.h"
+#include "GrRenderTarget.h"
 #include "GrTest.h"
 #include "GrTexture.h"