Make GrGpuCommandBuffer's methods take a GrRenderTargetProxy (rather than a GrRenderTarget)

In https://skia-review.googlesource.com/c/26363/ (Remove origin field from GrSurface) I just passed
an extra GrSurfaceOrigin parameter to all these methods. Besides being verbose this also led to
the "discard" method having an origin (to support the GrVkGpuCommandBuffer). It think this approach
is better and is plausible if the GrGpuCommandBuffer is viewed as an intermediary between the
GrProxy-based Ops and the Gpu.

In isolation this CL doesn't really show why we want to percolate the Proxy down. Once GrSurface
no longer has an origin a lot of the GrGpu methods need it passed in explicitly. By having the
GrGpuCommandBuffer get the proxy it can then pass the origin to GrGpu and removes a layer of
functions with an extra origin parameter.

Change-Id: Ie223fdee930171a32a5923155a0322e9a9c2aaa9
Reviewed-on: https://skia-review.googlesource.com/27980
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-07-28 08:42:04 -04:00 committed by Skia Commit-Bot
parent f7928b4f33
commit 4f101a77a7
10 changed files with 56 additions and 48 deletions

View File

@ -21,19 +21,20 @@ void GrGpuCommandBuffer::submit() {
this->onSubmit();
}
void GrGpuCommandBuffer::clear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) {
void GrGpuCommandBuffer::clear(GrRenderTargetProxy* proxy, const GrFixedClip& clip, GrColor color) {
#ifdef SK_DEBUG
GrRenderTarget* rt = proxy->priv().peekRenderTarget();
SkASSERT(rt);
SkASSERT(!clip.scissorEnabled() ||
(SkIRect::MakeWH(rt->width(), rt->height()).contains(clip.scissorRect()) &&
SkIRect::MakeWH(rt->width(), rt->height()) != clip.scissorRect()));
#endif
this->onClear(rt, clip, color);
this->onClear(proxy, clip, color);
}
void GrGpuCommandBuffer::clearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip,
void GrGpuCommandBuffer::clearStencilClip(GrRenderTargetProxy* proxy, const GrFixedClip& clip,
bool insideStencilMask) {
this->onClearStencilClip(rt, clip, insideStencilMask);
this->onClearStencilClip(proxy, clip, insideStencilMask);
}
bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline,

View File

@ -75,22 +75,22 @@ public:
const SkRect& bounds);
// Performs an upload of vertex data in the middle of a set of a set of draws
virtual void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload,
GrRenderTarget* rt) = 0;
virtual void inlineUpload(GrOpFlushState*, GrDrawOp::DeferredUploadFn&,
GrRenderTargetProxy*) = 0;
/**
* Clear the passed in render target. Ignores the draw state and clip.
*/
void clear(GrRenderTarget*, const GrFixedClip&, GrColor);
void clear(GrRenderTargetProxy*, const GrFixedClip&, GrColor);
void clearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask);
void clearStencilClip(GrRenderTargetProxy*, const GrFixedClip&, bool insideStencilMask);
/**
* Discards the contents render target. nullptr indicates that the current render target should
* be discarded.
*/
// TODO: This should be removed in the future to favor using the load and store ops for discard
virtual void discard(GrRenderTarget*) = 0;
virtual void discard(GrRenderTargetProxy*) = 0;
private:
virtual GrGpu* gpu() = 0;
@ -107,9 +107,9 @@ private:
const SkRect& bounds) = 0;
// overridden by backend-specific derived class to perform the clear.
virtual void onClear(GrRenderTarget*, const GrFixedClip&, GrColor) = 0;
virtual void onClear(GrRenderTargetProxy*, const GrFixedClip&, GrColor) = 0;
virtual void onClearStencilClip(GrRenderTarget*, const GrFixedClip&,
virtual void onClearStencilClip(GrRenderTargetProxy*, const GrFixedClip&,
bool insideStencilMask) = 0;
};

View File

@ -30,8 +30,8 @@ public:
void end() override {}
void discard(GrRenderTarget* rt) override {
GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
void discard(GrRenderTargetProxy* proxy) override {
GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
fRenderTarget = target;
}
@ -39,7 +39,7 @@ public:
}
void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload,
GrRenderTarget*) override {
GrRenderTargetProxy*) override {
state->doUpload(upload);
}
@ -63,8 +63,8 @@ private:
fGpu->draw(pipeline, primProc, mesh, dynamicStates, meshCount);
}
void onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) override {
GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
void onClear(GrRenderTargetProxy* proxy, const GrFixedClip& clip, GrColor color) override {
GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
fRenderTarget = target;
}
@ -72,9 +72,9 @@ private:
fGpu->clear(clip, color, fRenderTarget);
}
void onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip,
void onClearStencilClip(GrRenderTargetProxy* proxy, const GrFixedClip& clip,
bool insideStencilMask) override {
GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
fRenderTarget = target;
}

View File

@ -16,8 +16,9 @@ public:
GrMockGpuCommandBuffer(GrMockGpu* gpu) : fGpu(gpu) {}
GrGpu* gpu() override { return fGpu; }
void inlineUpload(GrOpFlushState*, GrDrawOp::DeferredUploadFn&, GrRenderTarget*) override {}
void discard(GrRenderTarget*) override {}
void inlineUpload(GrOpFlushState*, GrDrawOp::DeferredUploadFn&,
GrRenderTargetProxy*) override {}
void discard(GrRenderTargetProxy*) override {}
void end() override {}
int numDraws() const { return fNumDraws; }
@ -28,8 +29,9 @@ private:
const GrPipeline::DynamicState[], int meshCount, const SkRect& bounds) override {
++fNumDraws;
}
void onClear(GrRenderTarget*, const GrFixedClip&, GrColor) override {}
void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) override {}
void onClear(GrRenderTargetProxy*, const GrFixedClip&, GrColor) override {}
void onClearStencilClip(GrRenderTargetProxy*, const GrFixedClip&,
bool insideStencilMask) override {}
GrRenderTarget* renderTarget() override { return nullptr; }
GrMockGpu* fGpu;

View File

@ -34,5 +34,5 @@ GrClearOp::GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* pro
void GrClearOp::onExecute(GrOpFlushState* state) {
SkASSERT(state->drawOpArgs().renderTarget());
state->commandBuffer()->clear(state->drawOpArgs().renderTarget(), fClip, fColor);
state->commandBuffer()->clear(state->drawOpArgs().fProxy, fClip, fColor);
}

View File

@ -57,8 +57,8 @@ private:
void onExecute(GrOpFlushState* state) override {
SkASSERT(state->drawOpArgs().renderTarget());
GrRenderTarget* rt = state->drawOpArgs().renderTarget();
state->commandBuffer()->clearStencilClip(rt, fClip, fInsideStencilMask);
GrRenderTargetProxy* proxy = state->drawOpArgs().fProxy;
state->commandBuffer()->clearStencilClip(proxy, fClip, fInsideStencilMask);
}
const GrFixedClip fClip;

View File

@ -42,7 +42,7 @@ private:
void onExecute(GrOpFlushState* state) override {
SkASSERT(state->drawOpArgs().renderTarget());
state->commandBuffer()->discard(state->drawOpArgs().renderTarget());
state->commandBuffer()->discard(state->drawOpArgs().fProxy);
}
typedef GrOp INHERITED;

View File

@ -70,7 +70,7 @@ void GrMeshDrawOp::onExecute(GrOpFlushState* state) {
while (currUploadIdx < fInlineUploads.count() &&
fInlineUploads[currUploadIdx].fUploadBeforeToken == drawToken) {
state->commandBuffer()->inlineUpload(state, fInlineUploads[currUploadIdx++].fUpload,
state->drawOpArgs().renderTarget());
state->drawOpArgs().fProxy);
}
const QueuedDraw& draw = fQueuedDraws[currDrawIdx];
SkASSERT(draw.fPipeline->proxy() == state->drawOpArgs().fProxy);

View File

@ -57,6 +57,7 @@ GrVkGpuCommandBuffer::GrVkGpuCommandBuffer(GrVkGpu* gpu,
const LoadAndStoreInfo& stencilInfo)
: fGpu(gpu)
, fRenderTarget(nullptr)
, fOrigin(kTopLeft_GrSurfaceOrigin)
, fClearColor(GrColor4f::FromGrColor(colorInfo.fClearColor))
, fLastPipelineState(nullptr) {
@ -67,9 +68,10 @@ GrVkGpuCommandBuffer::GrVkGpuCommandBuffer(GrVkGpu* gpu,
fCurrentCmdInfo = -1;
}
void GrVkGpuCommandBuffer::init(GrVkRenderTarget* target) {
void GrVkGpuCommandBuffer::init(GrVkRenderTarget* target, GrSurfaceOrigin origin) {
SkASSERT(!fRenderTarget);
fRenderTarget = target;
fOrigin = origin;
GrVkRenderPass::LoadStoreOps vkColorOps(fVkColorLoadOp, fVkColorStoreOp);
GrVkRenderPass::LoadStoreOps vkStencilOps(fVkStencilLoadOp, fVkStencilStoreOp);
@ -181,10 +183,10 @@ void GrVkGpuCommandBuffer::onSubmit() {
}
}
void GrVkGpuCommandBuffer::discard(GrRenderTarget* rt) {
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt);
void GrVkGpuCommandBuffer::discard(GrRenderTargetProxy* proxy) {
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
this->init(target);
this->init(target, proxy->origin());
}
SkASSERT(target == fRenderTarget);
@ -217,13 +219,13 @@ void GrVkGpuCommandBuffer::discard(GrRenderTarget* rt) {
}
}
void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip,
void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTargetProxy* proxy, const GrFixedClip& clip,
bool insideStencilMask) {
SkASSERT(!clip.hasWindowRectangles());
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt);
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
this->init(target);
this->init(target, proxy->origin());
}
SkASSERT(target == fRenderTarget);
@ -251,7 +253,7 @@ void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* rt, const GrFixedC
SkIRect vkRect;
if (!clip.scissorEnabled()) {
vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height());
} else if (kBottomLeft_GrSurfaceOrigin != fRenderTarget->origin()) {
} else if (kBottomLeft_GrSurfaceOrigin != fOrigin) {
vkRect = clip.scissorRect();
} else {
const SkIRect& scissor = clip.scissorRect();
@ -284,13 +286,14 @@ void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* rt, const GrFixedC
}
}
void GrVkGpuCommandBuffer::onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) {
void GrVkGpuCommandBuffer::onClear(GrRenderTargetProxy* proxy, const GrFixedClip& clip,
GrColor color) {
// parent class should never let us get here with no RT
SkASSERT(!clip.hasWindowRectangles());
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt);
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
this->init(target);
this->init(target, proxy->origin());
}
SkASSERT(target == fRenderTarget);
@ -337,7 +340,7 @@ void GrVkGpuCommandBuffer::onClear(GrRenderTarget* rt, const GrFixedClip& clip,
SkIRect vkRect;
if (!clip.scissorEnabled()) {
vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height());
} else if (kBottomLeft_GrSurfaceOrigin != fRenderTarget->origin()) {
} else if (kBottomLeft_GrSurfaceOrigin != fOrigin) {
vkRect = clip.scissorRect();
} else {
const SkIRect& scissor = clip.scissorRect();
@ -411,10 +414,10 @@ void GrVkGpuCommandBuffer::addAdditionalRenderPass() {
}
void GrVkGpuCommandBuffer::inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload,
GrRenderTarget* rt) {
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt);
GrRenderTargetProxy* proxy) {
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(proxy->priv().peekRenderTarget());
if (!fRenderTarget) {
this->init(target);
this->init(target, proxy->origin());
}
if (!fCommandBufferInfos[fCurrentCmdInfo].fIsEmpty) {
this->addAdditionalRenderPass();
@ -551,7 +554,7 @@ void GrVkGpuCommandBuffer::onDraw(const GrPipeline& pipeline,
const SkRect& bounds) {
GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(pipeline.renderTarget());
if (!fRenderTarget) {
this->init(target);
this->init(target, pipeline.proxy()->origin());
}
SkASSERT(target == fRenderTarget);

View File

@ -31,14 +31,14 @@ public:
void end() override;
void discard(GrRenderTarget*) override;
void discard(GrRenderTargetProxy*) override;
void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload,
GrRenderTarget*) override;
GrRenderTargetProxy*) override;
private:
// Performs lazy initialization on the first operation seen by the command buffer.
void init(GrVkRenderTarget* rt);
void init(GrVkRenderTarget*, GrSurfaceOrigin);
GrGpu* gpu() override;
GrRenderTarget* renderTarget() override;
@ -90,9 +90,10 @@ private:
const GrBuffer* instanceBuffer, int instanceCount,
int baseInstance) final;
void onClear(GrRenderTarget*, const GrFixedClip&, GrColor color) override;
void onClear(GrRenderTargetProxy*, const GrFixedClip&, GrColor color) override;
void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) override;
void onClearStencilClip(GrRenderTargetProxy*, const GrFixedClip&,
bool insideStencilMask) override;
void addAdditionalCommandBuffer();
void addAdditionalRenderPass();
@ -124,6 +125,7 @@ private:
GrVkGpu* fGpu;
GrVkRenderTarget* fRenderTarget;
GrSurfaceOrigin fOrigin;
VkAttachmentLoadOp fVkColorLoadOp;
VkAttachmentStoreOp fVkColorStoreOp;
VkAttachmentLoadOp fVkStencilLoadOp;