diff options
author | Robert Phillips <robertphillips@google.com> | 2017-05-29 15:05:15 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-29 19:26:26 +0000 |
commit | bb581ce30f55360fd3a12e7f5aa1fe324b16d085 (patch) | |
tree | 6ca8902e7c72278a3e796c9b3c2d3de02aa620b2 | |
parent | 9bee2e5894bb8dd374392f238bc429e16f239583 (diff) |
Convert DstTexture to DstProxy (take 2)
The last GrTexture-based TextureSampler::reset call must be removed before the TextureSamplers can become purely GrTextureProxy-backed
Reland of: https://skia-review.googlesource.com/c/16908/ (Convert DstTexture to DstProxy)
Split out of: https://skia-review.googlesource.com/c/10484/ (Omnibus: Push instantiation of GrTextures later (post TextureSampler))
Change-Id: I3a497b6a950fad899f23882c0a9552894ef640f8
Reviewed-on: https://skia-review.googlesource.com/17205
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | src/gpu/GrOpFlushState.h | 10 | ||||
-rw-r--r-- | src/gpu/GrPipeline.cpp | 14 | ||||
-rw-r--r-- | src/gpu/GrPipeline.h | 21 | ||||
-rw-r--r-- | src/gpu/GrProcessor.cpp | 12 | ||||
-rw-r--r-- | src/gpu/GrProcessor.h | 6 | ||||
-rw-r--r-- | src/gpu/GrProcessorUnitTest.h | 1 | ||||
-rw-r--r-- | src/gpu/GrProgramDesc.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 36 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.h | 8 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetOpList.cpp | 20 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetOpList.h | 18 | ||||
-rw-r--r-- | src/gpu/GrXferProcessor.h | 44 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 3 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.cpp | 3 | ||||
-rw-r--r-- | src/gpu/instanced/InstancedOp.cpp | 2 | ||||
-rw-r--r-- | src/gpu/ops/GrDrawPathOp.cpp | 2 | ||||
-rw-r--r-- | src/gpu/ops/GrSimpleMeshDrawOpHelper.h | 2 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpuCommandBuffer.cpp | 4 | ||||
-rw-r--r-- | src/gpu/vk/GrVkPipelineState.cpp | 15 | ||||
-rw-r--r-- | tests/GrPorterDuffTest.cpp | 11 | ||||
-rw-r--r-- | tests/ProcessorTest.cpp | 5 |
22 files changed, 122 insertions, 121 deletions
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h index 0fc7b7f834..85a356e44f 100644 --- a/src/gpu/GrOpFlushState.h +++ b/src/gpu/GrOpFlushState.h @@ -100,9 +100,9 @@ public: /** Additional data required on a per-op basis when executing GrDrawOps. */ struct DrawOpArgs { - GrRenderTarget* fRenderTarget; - const GrAppliedClip* fAppliedClip; - GrXferProcessor::DstTexture fDstTexture; + GrRenderTarget* fRenderTarget; + const GrAppliedClip* fAppliedClip; + GrXferProcessor::DstProxy fDstProxy; }; void setDrawOpArgs(DrawOpArgs* opArgs) { fOpArgs = opArgs; } @@ -224,8 +224,8 @@ public: const GrAppliedClip* clip() const { return this->state()->drawOpArgs().fAppliedClip; } - const GrXferProcessor::DstTexture& dstTexture() const { - return this->state()->drawOpArgs().fDstTexture; + const GrXferProcessor::DstProxy& dstProxy() const { + return this->state()->drawOpArgs().fDstProxy; } template <typename... Args> diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp index 3bdf3bbd69..394d545242 100644 --- a/src/gpu/GrPipeline.cpp +++ b/src/gpu/GrPipeline.cpp @@ -44,9 +44,13 @@ void GrPipeline::init(const InitArgs& args) { fXferProcessor = args.fProcessors->refXferProcessor(); - if (args.fDstTexture.texture()) { - fDstTexture.reset(args.fDstTexture.texture()); - fDstTextureOffset = args.fDstTexture.offset(); + if (args.fDstProxy.proxy()) { + if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) { + this->markAsBad(); + } + + fDstTextureProxy.reset(args.fDstProxy.proxy()); + fDstTextureOffset = args.fDstProxy.offset(); } // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline, possibly removing some of the @@ -91,7 +95,7 @@ static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrFragmentProcessor::TextureAccessIter iter(proc); while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) { SkASSERT(rtp->getLastOpList()); - rtp->getLastOpList()->addDependency(sampler->texture()); + rtp->getLastOpList()->addDependency(sampler->proxy()); } } #endif @@ -104,7 +108,7 @@ void GrPipeline::addDependenciesTo(GrRenderTargetProxy* rtp) const { } #endif - if (fDstTexture) { + if (fDstTextureProxy) { //SkASSERT(rtp->getLastOpList()); // MDB TODO: re-enable when TextureSamplers store texture proxies //rtp->getLastOpList()->addDependency(fDstTexture.get()); diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h index 41f6d59a8e..4f2f010188 100644 --- a/src/gpu/GrPipeline.h +++ b/src/gpu/GrPipeline.h @@ -76,7 +76,7 @@ public: GrRenderTarget* fRenderTarget = nullptr; const GrCaps* fCaps = nullptr; GrResourceProvider* fResourceProvider = nullptr; - GrXferProcessor::DstTexture fDstTexture; + GrXferProcessor::DstProxy fDstProxy; }; /** @@ -158,11 +158,19 @@ public: * If the GrXferProcessor uses a texture to access the dst color, then this returns that * texture and the offset to the dst contents within that texture. */ - GrTexture* dstTexture(SkIPoint* offset = nullptr) const { + GrTextureProxy* dstTextureProxy(SkIPoint* offset = nullptr) const { if (offset) { *offset = fDstTextureOffset; } - return fDstTexture.get(); + return fDstTextureProxy.get(); + } + + GrTexture* peekDstTexture(SkIPoint* offset = nullptr) const { + if (GrTextureProxy* dstProxy = this->dstTextureProxy(offset)) { + return dstProxy->priv().peekTexture(); + } + + return nullptr; } const GrFragmentProcessor& getColorFragmentProcessor(int idx) const { @@ -216,7 +224,8 @@ public: bool isBad() const { return SkToBool(fFlags & kIsBad_Flag); } GrXferBarrierType xferBarrierType(const GrCaps& caps) const { - if (fDstTexture.get() && fDstTexture.get() == fRenderTarget.get()->asTexture()) { + if (fDstTextureProxy.get() && + fDstTextureProxy.get()->priv().peekTexture() == fRenderTarget.get()->asTexture()) { return kTexture_GrXferBarrierType; } return this->getXferProcessor().xferBarrierType(caps); @@ -234,11 +243,11 @@ private: }; using RenderTarget = GrPendingIOResource<GrRenderTarget, kWrite_GrIOType>; - using DstTexture = GrPendingIOResource<GrTexture, kRead_GrIOType>; + using DstTextureProxy = GrPendingIOResource<GrTextureProxy, kRead_GrIOType>; using PendingFragmentProcessor = GrPendingProgramElement<const GrFragmentProcessor>; using FragmentProcessorArray = SkAutoSTArray<8, PendingFragmentProcessor>; - DstTexture fDstTexture; + DstTextureProxy fDstTextureProxy; SkIPoint fDstTextureOffset; RenderTarget fRenderTarget; GrScissorState fScissorState; diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 6895eaa393..7a34238b1f 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -235,18 +235,6 @@ GrResourceIOProcessor::TextureSampler::TextureSampler(GrResourceProvider* resour this->reset(resourceProvider, std::move(proxy), filterMode, tileXAndY, visibility); } -// MDB TODO: remove this! -void GrResourceIOProcessor::TextureSampler::reset(GrTexture* texture, - GrSamplerParams::FilterMode filterMode, - SkShader::TileMode tileXAndY, - GrShaderFlags visibility) { - SkASSERT(texture); - fTexture.set(SkRef(texture), kRead_GrIOType); - filterMode = SkTMin(filterMode, texture->texturePriv().highestFilterMode()); - fParams.reset(tileXAndY, filterMode); - fVisibility = visibility; -} - void GrResourceIOProcessor::TextureSampler::reset(GrResourceProvider* resourceProvider, sk_sp<GrTextureProxy> proxy, const GrSamplerParams& params, diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h index 419569634c..1afb8ca92b 100644 --- a/src/gpu/GrProcessor.h +++ b/src/gpu/GrProcessor.h @@ -219,12 +219,6 @@ public: */ TextureSampler(); - // MDB TODO: this is the last GrTexture-based reset call! - void reset(GrTexture*, - GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, - SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, - GrShaderFlags visibility = kFragment_GrShaderFlag); - // MDB TODO: ultimately we shouldn't need the resource provider parameter TextureSampler(GrResourceProvider*, sk_sp<GrTextureProxy>, const GrSamplerParams&); explicit TextureSampler(GrResourceProvider*, sk_sp<GrTextureProxy>, diff --git a/src/gpu/GrProcessorUnitTest.h b/src/gpu/GrProcessorUnitTest.h index d6269c85bd..a3688233d2 100644 --- a/src/gpu/GrProcessorUnitTest.h +++ b/src/gpu/GrProcessorUnitTest.h @@ -53,6 +53,7 @@ struct GrProcessorTestData { : fRandom(random) , fRenderTargetContext(renderTargetContext) , fContext(context) { + SkASSERT(proxies[0] && proxies[1]); fProxies[0] = proxies[0]; fProxies[1] = proxies[1]; } diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp index ebcfb072ba..ca81e5a793 100644 --- a/src/gpu/GrProgramDesc.cpp +++ b/src/gpu/GrProgramDesc.cpp @@ -199,8 +199,8 @@ bool GrProgramDesc::Build(GrProgramDesc* desc, const GrXferProcessor& xp = pipeline.getXferProcessor(); const GrSurfaceOrigin* originIfDstTexture = nullptr; GrSurfaceOrigin origin; - if (pipeline.dstTexture()) { - origin = pipeline.dstTexture()->origin(); + if (pipeline.dstTextureProxy()) { + origin = pipeline.dstTextureProxy()->origin(); originIfDstTexture = &origin; } xp.getGLSLProcessorKey(shaderCaps, &b, originIfDstTexture); diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index deec8c792a..b05be0bd64 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -1740,15 +1740,15 @@ uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<Gr } } - GrXferProcessor::DstTexture dstTexture; + GrXferProcessor::DstProxy dstProxy; if (op->xpRequiresDstTexture(*this->caps(), &appliedClip)) { - if (!this->setupDstTexture(fRenderTargetProxy.get(), clip, op->bounds(), &dstTexture)) { + if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, op->bounds(), &dstProxy)) { return SK_InvalidUniqueID; } } op->setClippedBounds(bounds); - return this->getOpList()->addOp(std::move(op), this, std::move(appliedClip), dstTexture); + return this->getOpList()->addOp(std::move(op), this, std::move(appliedClip), dstProxy); } uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipelineBuilder, @@ -1801,7 +1801,7 @@ uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipeline args.fResourceProvider = this->resourceProvider(); if (analysis.requiresDstTexture()) { - if (!this->setupDstTexture(fRenderTargetProxy.get(), clip, bounds, &args.fDstTexture)) { + if (!this->setupDstProxy(this->asRenderTargetProxy(), clip, bounds, &args.fDstProxy)) { return SK_InvalidUniqueID; } } @@ -1814,23 +1814,15 @@ uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipeline return this->getOpList()->addOp(std::move(op), this); } -bool GrRenderTargetContext::setupDstTexture(GrRenderTargetProxy* rtProxy, const GrClip& clip, +bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip, const SkRect& opBounds, - GrXferProcessor::DstTexture* dstTexture) { + GrXferProcessor::DstProxy* dstProxy) { 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->instantiateTexture(fContext->resourceProvider()))); - if (!tex) { - SkDebugf("setupDstTexture: instantiation of src texture failed.\n"); - return false; // We have bigger problems now - } - // 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->setOffset(0, 0); + dstProxy->setProxy(sk_ref_sp(texProxy)); + dstProxy->setOffset(0, 0); return true; } } @@ -1896,15 +1888,7 @@ bool GrRenderTargetContext::setupDstTexture(GrRenderTargetProxy* rtProxy, const return false; } - GrTextureProxy* copyProxy = sContext->asTextureProxy(); - // MDB TODO: remove this instantiation once DstTexture is proxy-backed - sk_sp<GrTexture> copy(sk_ref_sp(copyProxy->instantiateTexture(fContext->resourceProvider()))); - if (!copy) { - SkDebugf("setupDstTexture: instantiation of copied texture failed.\n"); - return false; - } - - dstTexture->setTexture(std::move(copy)); - dstTexture->setOffset(dstOffset); + dstProxy->setProxy(sContext->asTextureProxyRef()); + dstProxy->setOffset(dstOffset); return true; } diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index 20df4c5f55..cb4d702c91 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -421,10 +421,10 @@ private: // 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); + bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*, + const GrClip&, + const SkRect& opBounds, + GrXferProcessor::DstProxy* result); GrRenderTargetOpList* getOpList(); diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index 537f9e67fc..0a50f74b20 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -72,7 +72,7 @@ void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) { GrOpFlushState::DrawOpArgs opArgs = { fTarget.get()->priv().peekRenderTarget(), fRecordedOps[i].fAppliedClip, - fRecordedOps[i].fDstTexture + fRecordedOps[i].fDstProxy }; flushState->setDrawOpArgs(&opArgs); @@ -142,7 +142,7 @@ bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) { GrOpFlushState::DrawOpArgs opArgs { fTarget.get()->priv().peekRenderTarget(), fRecordedOps[i].fAppliedClip, - fRecordedOps[i].fDstTexture + fRecordedOps[i].fDstProxy }; flushState->setDrawOpArgs(&opArgs); @@ -248,7 +248,7 @@ static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRec bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip, - const DstTexture* bDstTexture, + const DstProxy* bDstProxy, const GrCaps& caps) { if (a.fAppliedClip) { if (!bClip) { @@ -260,11 +260,11 @@ bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b, } else if (bClip) { return false; } - if (bDstTexture) { - if (a.fDstTexture != *bDstTexture) { + if (bDstProxy) { + if (a.fDstProxy != *bDstProxy) { return false; } - } else if (a.fDstTexture.texture()) { + } else if (a.fDstProxy.proxy()) { return false; } return a.fOp->combineIfPossible(b, caps); @@ -273,7 +273,7 @@ bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b, GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext, GrAppliedClip* clip, - const DstTexture* dstTexture) { + const DstProxy* dstProxy) { SkASSERT(fTarget.get()); const GrCaps* caps = renderTargetContext->caps(); @@ -302,7 +302,7 @@ GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, while (true) { const RecordedOp& candidate = fRecordedOps.fromBack(i); - if (this->combineIfPossible(candidate, op.get(), clip, dstTexture, *caps)) { + if (this->combineIfPossible(candidate, op.get(), clip, dstProxy, *caps)) { GrOP_INFO("\t\tBackward: Combining with (%s, opID: %u)\n", candidate.fOp->name(), candidate.fOp->uniqueID()); GrOP_INFO("\t\t\tBackward: Combined op info:\n"); @@ -330,7 +330,7 @@ GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); SkDEBUGCODE(fNumClips++;) } - fRecordedOps.emplace_back(std::move(op), clip, dstTexture); + fRecordedOps.emplace_back(std::move(op), clip, dstProxy); fRecordedOps.back().fOp->wasRecorded(this); fLastFullClearOp = nullptr; fLastFullClearResourceID.makeInvalid(); @@ -350,7 +350,7 @@ void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) { const RecordedOp& candidate = fRecordedOps[j]; if (this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(), - candidate.fAppliedClip, &candidate.fDstTexture, caps)) { + candidate.fAppliedClip, &candidate.fDstProxy, caps)) { GrOP_INFO("\t\tForward: Combining with (%s, opID: %u)\n", candidate.fOp->name(), candidate.fOp->uniqueID()); GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get()); diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h index 7f407824db..3ee3d9d6e3 100644 --- a/src/gpu/GrRenderTargetOpList.h +++ b/src/gpu/GrRenderTargetOpList.h @@ -30,7 +30,7 @@ class GrRenderTargetProxy; class GrRenderTargetOpList final : public GrOpList { private: - using DstTexture = GrXferProcessor::DstTexture; + using DstProxy = GrXferProcessor::DstProxy; public: GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrAuditTrail*); @@ -70,9 +70,9 @@ public: return this->uniqueID(); } uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext, - GrAppliedClip&& clip, const DstTexture& dstTexture) { + GrAppliedClip&& clip, const DstProxy& dstProxy) { this->recordOp(std::move(op), renderTargetContext, clip.doesClip() ? &clip : nullptr, - &dstTexture); + &dstProxy); return this->uniqueID(); } @@ -113,28 +113,28 @@ private: struct RecordedOp { RecordedOp(std::unique_ptr<GrOp> op, const GrAppliedClip* appliedClip, - const DstTexture* dstTexture) + const DstProxy* dstProxy) : fOp(std::move(op)) , fAppliedClip(appliedClip) { - if (dstTexture) { - fDstTexture = *dstTexture; + if (dstProxy) { + fDstProxy = *dstProxy; } } std::unique_ptr<GrOp> fOp; - DstTexture fDstTexture; + DstProxy fDstProxy; const GrAppliedClip* fAppliedClip; }; // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it // returns the input op. GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr, - const DstTexture* = nullptr); + const DstProxy* = nullptr); void forwardCombine(const GrCaps&); // If this returns true then b has been merged into a's op. bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip, - const DstTexture* bDstTexture, const GrCaps&); + const DstProxy* bDstTexture, const GrCaps&); GrClearOp* fLastFullClearOp = nullptr; GrGpuResource::UniqueID fLastFullClearResourceID = GrGpuResource::UniqueID::InvalidID(); diff --git a/src/gpu/GrXferProcessor.h b/src/gpu/GrXferProcessor.h index ed8e7079cb..b7f465fb45 100644 --- a/src/gpu/GrXferProcessor.h +++ b/src/gpu/GrXferProcessor.h @@ -55,45 +55,55 @@ public: * to the space of the texture. Depending on GPU capabilities a DstTexture may be used by a * GrXferProcessor for blending in the fragment shader. */ - class DstTexture { + class DstProxy { public: - DstTexture() { fOffset.set(0, 0); } + DstProxy() { fOffset.set(0, 0); } - DstTexture(const DstTexture& other) { + DstProxy(const DstProxy& other) { *this = other; } - DstTexture(GrTexture* texture, const SkIPoint& offset) - : fTexture(SkSafeRef(texture)), fOffset(texture ? offset : SkIPoint{0, 0}) {} + DstProxy(sk_sp<GrTextureProxy> proxy, const SkIPoint& offset) + : fProxy(std::move(proxy)) { + if (fProxy) { + fOffset = offset; + } else { + fOffset.set(0, 0); + } + } - DstTexture& operator=(const DstTexture& other) { - fTexture = other.fTexture; + DstProxy& operator=(const DstProxy& other) { + fProxy = other.fProxy; fOffset = other.fOffset; return *this; } - bool operator==(const DstTexture& that) const { - return fTexture == that.fTexture && fOffset == that.fOffset; + bool operator==(const DstProxy& that) const { + return fProxy == that.fProxy && fOffset == that.fOffset; } - bool operator!=(const DstTexture& that) const { return !(*this == that); } + bool operator!=(const DstProxy& that) const { return !(*this == that); } const SkIPoint& offset() const { return fOffset; } void setOffset(const SkIPoint& offset) { fOffset = offset; } void setOffset(int ox, int oy) { fOffset.set(ox, oy); } - GrTexture* texture() const { return fTexture.get(); } + GrTextureProxy* proxy() const { return fProxy.get(); } - void setTexture(sk_sp<GrTexture> texture) { - fTexture = std::move(texture); - if (!fTexture) { + void setProxy(sk_sp<GrTextureProxy> proxy) { + fProxy = std::move(proxy); + if (!fProxy) { fOffset = {0, 0}; } } + bool instantiate(GrResourceProvider* resourceProvider) { + return SkToBool(fProxy->instantiate(resourceProvider)); + } + private: - sk_sp<GrTexture> fTexture; - SkIPoint fOffset; + sk_sp<GrTextureProxy> fProxy; + SkIPoint fOffset; }; /** @@ -240,7 +250,7 @@ private: #endif class GrXPFactory { public: - typedef GrXferProcessor::DstTexture DstTexture; + typedef GrXferProcessor::DstProxy DstProxy; enum class AnalysisProperties : unsigned { kNone = 0x0, diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 6276eaf1c8..df905a4f0f 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -2082,7 +2082,7 @@ bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* // possible and we return false to fallback to creating a render target dst for render-to- // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo // creation. It isn't clear that avoiding temporary fbo creation is actually optimal. - GrSurfaceOrigin originForBlitFramebuffer = kDefault_GrSurfaceOrigin; + GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin; bool rectsMustMatchForBlitFramebuffer = false; bool disallowSubrectForBlitFramebuffer = false; if (src->numColorSamples() && diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 9750e7047d..f133c1b377 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -92,7 +92,8 @@ void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline const GrXferProcessor& xp = pipeline.getXferProcessor(); SkIPoint offset; - GrTexture* dstTexture = pipeline.dstTexture(&offset); + GrTexture* dstTexture = pipeline.peekDstTexture(&offset); + fXferProcessor->setData(fProgramDataManager, xp, dstTexture, offset); if (dstTexture) { fGpu->bindTexture(nextTexSamplerIdx++, GrSamplerParams::ClampNoFilter(), true, diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 756e29c37f..337ee6d0ea 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -237,7 +237,8 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn, SamplerHandle dstTextureSamplerHandle; GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin; - if (GrTexture* dstTexture = fPipeline.dstTexture()) { + + if (GrTexture* dstTexture = fPipeline.peekDstTexture()) { // GrProcessor::TextureSampler sampler(dstTexture); SkString name("DstTextureSampler"); dstTextureSamplerHandle = diff --git a/src/gpu/instanced/InstancedOp.cpp b/src/gpu/instanced/InstancedOp.cpp index 9fbec1328f..f0f1cc0d2d 100644 --- a/src/gpu/instanced/InstancedOp.cpp +++ b/src/gpu/instanced/InstancedOp.cpp @@ -239,7 +239,7 @@ void InstancedOp::onExecute(GrOpFlushState* state) { args.fFlags |= GrPipeline::kDisableOutputConversionToSRGB_Flag; } args.fRenderTarget = state->drawOpArgs().fRenderTarget; - args.fDstTexture = state->drawOpArgs().fDstTexture; + args.fDstProxy = state->drawOpArgs().fDstProxy; pipeline.init(args); if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*state->gpu()->caps())) { diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp index cd4c30ea98..c33af39365 100644 --- a/src/gpu/ops/GrDrawPathOp.cpp +++ b/src/gpu/ops/GrDrawPathOp.cpp @@ -49,7 +49,7 @@ void GrDrawPathOpBase::initPipeline(const GrOpFlushState& state, GrPipeline* pip args.fRenderTarget = state.drawOpArgs().fRenderTarget; args.fCaps = &state.caps(); args.fResourceProvider = state.resourceProvider(); - args.fDstTexture = state.drawOpArgs().fDstTexture; + args.fDstProxy = state.drawOpArgs().fDstProxy; return pipeline->init(args); } diff --git a/src/gpu/ops/GrSimpleMeshDrawOpHelper.h b/src/gpu/ops/GrSimpleMeshDrawOpHelper.h index 9d7cbf96ca..c230257c1c 100644 --- a/src/gpu/ops/GrSimpleMeshDrawOpHelper.h +++ b/src/gpu/ops/GrSimpleMeshDrawOpHelper.h @@ -137,7 +137,7 @@ protected: args.fProcessors = &this->processors(); args.fRenderTarget = target->renderTarget(); args.fAppliedClip = target->clip(); - args.fDstTexture = target->dstTexture(); + args.fDstProxy = target->dstProxy(); args.fCaps = &target->caps(); args.fResourceProvider = target->resourceProvider(); return args; diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp index 0df9cfba70..ad2dc0c06f 100644 --- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp +++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp @@ -532,8 +532,8 @@ void GrVkGpuCommandBuffer::onDraw(const GrPipeline& pipeline, while (const GrFragmentProcessor* fp = iter.next()) { prepare_sampled_images(*fp, fGpu); } - if (GrVkTexture* dstTexture = static_cast<GrVkTexture*>(pipeline.dstTexture())) { - set_texture_layout(dstTexture, fGpu); + if (GrTexture* dstTexture = pipeline.peekDstTexture()) { + set_texture_layout(static_cast<GrVkTexture*>(dstTexture), fGpu); } GrPrimitiveType primitiveType = meshes[0].primitiveType(); diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp index b3f6c1bc3b..525d75f3da 100644 --- a/src/gpu/vk/GrVkPipelineState.cpp +++ b/src/gpu/vk/GrVkPipelineState.cpp @@ -258,13 +258,16 @@ void GrVkPipelineState::setData(GrVkGpu* gpu, } SkASSERT(!fp && !glslFP); - SkIPoint offset; - GrTexture* dstTexture = pipeline.dstTexture(&offset); - fXferProcessor->setData(fDataManager, pipeline.getXferProcessor(), dstTexture, offset); + { + SkIPoint offset; + GrTexture* dstTexture = pipeline.peekDstTexture(&offset); + + fXferProcessor->setData(fDataManager, pipeline.getXferProcessor(), dstTexture, offset); + } + GrResourceIOProcessor::TextureSampler dstTextureSampler; - if (dstTexture) { - // MDB TODO: this is the last usage of a GrTexture-based TextureSampler reset method - dstTextureSampler.reset(dstTexture); + if (GrTextureProxy* dstTextureProxy = pipeline.dstTextureProxy()) { + dstTextureSampler.reset(gpu->getContext()->resourceProvider(), sk_ref_sp(dstTextureProxy)); SkAssertResult(dstTextureSampler.instantiate(gpu->getContext()->resourceProvider())); textureBindings.push_back(&dstTextureSampler); } diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 90c9b50ce2..bf325981b4 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -1068,11 +1068,12 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) { kRGBA_8888_GrPixelConfig, backendTexHandle); - GrXferProcessor::DstTexture fakeDstTexture; - fakeDstTexture.setTexture( - ctx->resourceProvider()->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, 0, - kBorrow_GrWrapOwnership)); + GrXferProcessor::DstProxy fakeDstProxy; + { + sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrappedBackend(ctx, backendTex, + kTopLeft_GrSurfaceOrigin); + fakeDstProxy.setProxy(std::move(proxy)); + } static const GrProcessorAnalysisColor colorInputs[] = { GrProcessorAnalysisColor::Opaque::kNo, GrProcessorAnalysisColor::Opaque::kYes, diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp index 399a307bd9..41bb183884 100644 --- a/tests/ProcessorTest.cpp +++ b/tests/ProcessorTest.cpp @@ -324,6 +324,11 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor } proxies[1] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, SkBudgeted::kYes, alphaData.get(), 256); + + if (!proxies[0] || !proxies[1]) { + return; + } + GrProcessorTestData testData(&random, context, rtc.get(), proxies); // Use a different array of premul colors for the output of the fragment processor that preceeds |