aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-09-03 07:19:50 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-03 07:19:50 -0700
commitb0bd4f64a6827dda6f4ec48e4746b0f0b72a975f (patch)
treecf965c10e8065d4c2fc852e3cbb21c389f8c345d /src
parenteddb113ec65226a1563fe9e623e7408443499028 (diff)
Remove GrDrawTarget::AutoRenderTargetRestore.
Pass GrRenderTarget in GrGpuG clear\bind methods. BUG=skia:2889 R=egdaniel@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/533883004
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrClipMaskManager.cpp2
-rw-r--r--src/gpu/GrDrawState.h34
-rw-r--r--src/gpu/GrGpu.cpp12
-rw-r--r--src/gpu/GrGpu.h9
-rw-r--r--src/gpu/GrRODrawState.h3
-rw-r--r--src/gpu/gl/GrGpuGL.cpp83
-rw-r--r--src/gpu/gl/GrGpuGL.h14
-rw-r--r--src/gpu/gl/GrGpuGL_program.cpp6
8 files changed, 59 insertions, 104 deletions
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index d4ab0b74f9..a0c49b5244 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -739,7 +739,7 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil buffers");
clipBit = (1 << (clipBit-1));
- fGpu->clearStencilClip(stencilSpaceIBounds, kAllIn_InitialState == initialState);
+ fGpu->clearStencilClip(rt, stencilSpaceIBounds, kAllIn_InitialState == initialState);
// walk through each clip element and perform its set op
// with the existing clip.
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index ec0ccade37..00bec9f7c2 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -380,40 +380,6 @@ public:
*/
void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
- class AutoRenderTargetRestore : public ::SkNoncopyable {
- public:
- AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {}
- AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) {
- fDrawState = NULL;
- fSavedTarget = NULL;
- this->set(ds, newTarget);
- }
- ~AutoRenderTargetRestore() { this->restore(); }
-
- void restore() {
- if (NULL != fDrawState) {
- fDrawState->setRenderTarget(fSavedTarget);
- fDrawState = NULL;
- }
- SkSafeSetNull(fSavedTarget);
- }
-
- void set(GrDrawState* ds, GrRenderTarget* newTarget) {
- this->restore();
-
- if (NULL != ds) {
- SkASSERT(NULL == fSavedTarget);
- fSavedTarget = ds->getRenderTarget();
- SkSafeRef(fSavedTarget);
- ds->setRenderTarget(newTarget);
- fDrawState = ds;
- }
- }
- private:
- GrDrawState* fDrawState;
- GrRenderTarget* fSavedTarget;
- };
-
/// @}
///////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 6ada03b62d..2ceef609e8 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -125,8 +125,7 @@ bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
// We used to clear down in the GL subclass using a special purpose
// FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
// FBO status.
- GrDrawState::AutoRenderTargetRestore artr(this->drawState(), rt);
- this->clearStencil();
+ this->clearStencil(rt);
return true;
} else {
return false;
@@ -180,16 +179,15 @@ void GrGpu::clear(const SkIRect* rect,
GrColor color,
bool canIgnoreRect,
GrRenderTarget* renderTarget) {
- GrDrawState::AutoRenderTargetRestore art;
- if (NULL != renderTarget) {
- art.set(this->drawState(), renderTarget);
+ if (NULL == renderTarget) {
+ renderTarget = this->getDrawState().getRenderTarget();
}
- if (NULL == this->getDrawState().getRenderTarget()) {
+ if (NULL == renderTarget) {
SkASSERT(0);
return;
}
this->handleDirtyContext();
- this->onClear(rect, color, canIgnoreRect);
+ this->onClear(renderTarget, rect, color, canIgnoreRect);
}
bool GrGpu::readPixels(GrRenderTarget* target,
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index e495de9afa..1ae2f5856b 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -315,7 +315,7 @@ public:
// GrGpu subclass sets clip bit in the stencil buffer. The subclass is
// free to clear the remaining bits to zero if masked clears are more
// expensive than clearing all bits.
- virtual void clearStencilClip(const SkIRect& rect, bool insideClip) = 0;
+ virtual void clearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0;
enum PrivateDrawStateStateBits {
kFirstBit = (GrDrawState::kLastPublicStateBit << 1),
@@ -435,7 +435,8 @@ private:
// overridden by backend-specific derived class to perform the clear and
// clearRect. NULL rect means clear whole target. If canIgnoreRect is
// true, it is okay to perform a full clear instead of a partial clear
- virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) = 0;
+ virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
+ bool canIgnoreRect) = 0;
// overridden by backend-specific derived class to perform the draw call.
virtual void onGpuDraw(const DrawInfo&) = 0;
@@ -470,8 +471,8 @@ private:
// returns false if current state is unsupported.
virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) = 0;
- // clears the entire stencil buffer to 0
- virtual void clearStencil() = 0;
+ // clears target's entire stencil buffer to 0
+ virtual void clearStencil(GrRenderTarget* target) = 0;
// Given a rt, find or create a stencil buffer and attach it
bool attachStencilBufferToRenderTarget(GrRenderTarget* target);
diff --git a/src/gpu/GrRODrawState.h b/src/gpu/GrRODrawState.h
index 0abd4a6aa5..54d87bdfc8 100644
--- a/src/gpu/GrRODrawState.h
+++ b/src/gpu/GrRODrawState.h
@@ -238,8 +238,7 @@ public:
*
* @return The currently set render target.
*/
- const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
- GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); }
+ GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
/// @}
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 3c22d17b64..f5802ef958 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1349,27 +1349,18 @@ GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(size_t size, bool dynamic) {
}
}
-void GrGpuGL::flushScissor() {
+void GrGpuGL::flushScissor(const GrGLIRect& rtViewport, GrSurfaceOrigin rtOrigin) {
if (fScissorState.fEnabled) {
- // Only access the RT if scissoring is being enabled. We can call this before performing
- // a glBitframebuffer for a surface->surface copy, which requires no RT to be bound to the
- // GrDrawState.
- const GrDrawState& drawState = this->getDrawState();
- const GrGLRenderTarget* rt =
- static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget());
-
- SkASSERT(NULL != rt);
- const GrGLIRect& vp = rt->getViewport();
GrGLIRect scissor;
- scissor.setRelativeTo(vp,
+ scissor.setRelativeTo(rtViewport,
fScissorState.fRect.fLeft,
fScissorState.fRect.fTop,
fScissorState.fRect.width(),
fScissorState.fRect.height(),
- rt->origin());
+ rtOrigin);
// if the scissor fully contains the viewport then we fall through and
// disable the scissor test.
- if (!scissor.contains(vp)) {
+ if (!scissor.contains(rtViewport)) {
if (fHWScissorSettings.fRect != scissor) {
scissor.pushToGLScissor(this->glInterface());
fHWScissorSettings.fRect = scissor;
@@ -1388,11 +1379,11 @@ void GrGpuGL::flushScissor() {
}
}
-void GrGpuGL::onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) {
- const GrDrawState& drawState = this->getDrawState();
- const GrRenderTarget* rt = drawState.getRenderTarget();
+void GrGpuGL::onClear(GrRenderTarget* target, const SkIRect* rect, GrColor color,
+ bool canIgnoreRect) {
// parent class should never let us get here with no RT
- SkASSERT(NULL != rt);
+ SkASSERT(NULL != target);
+ GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
if (canIgnoreRect && this->glCaps().fullClearIsFree()) {
rect = NULL;
@@ -1402,7 +1393,7 @@ void GrGpuGL::onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) {
if (NULL != rect) {
// flushScissor expects rect to be clipped to the target.
clippedRect = *rect;
- SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height());
+ SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height());
if (clippedRect.intersect(rtRect)) {
rect = &clippedRect;
} else {
@@ -1410,13 +1401,13 @@ void GrGpuGL::onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) {
}
}
- this->flushRenderTarget(rect);
+ this->flushRenderTarget(glRT, rect);
GrAutoTRestore<ScissorState> asr(&fScissorState);
fScissorState.fEnabled = (NULL != rect);
if (fScissorState.fEnabled) {
fScissorState.fRect = *rect;
}
- this->flushScissor();
+ this->flushScissor(glRT->getViewport(), glRT->origin());
GrGLfloat r, g, b, a;
static const GrGLfloat scale255 = 1.f / 255.f;
@@ -1486,16 +1477,16 @@ void GrGpuGL::discard(GrRenderTarget* renderTarget) {
}
-void GrGpuGL::clearStencil() {
- if (NULL == this->getDrawState().getRenderTarget()) {
+void GrGpuGL::clearStencil(GrRenderTarget* target) {
+ if (NULL == target) {
return;
}
-
- this->flushRenderTarget(&SkIRect::EmptyIRect());
+ GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
+ this->flushRenderTarget(glRT, &SkIRect::EmptyIRect());
GrAutoTRestore<ScissorState> asr(&fScissorState);
fScissorState.fEnabled = false;
- this->flushScissor();
+ this->flushScissor(glRT->getViewport(), glRT->origin());
GL_CALL(StencilMask(0xffffffff));
GL_CALL(ClearStencil(0));
@@ -1503,15 +1494,13 @@ void GrGpuGL::clearStencil() {
fHWStencilSettings.invalidate();
}
-void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) {
- const GrDrawState& drawState = this->getDrawState();
- const GrRenderTarget* rt = drawState.getRenderTarget();
- SkASSERT(NULL != rt);
+void GrGpuGL::clearStencilClip(GrRenderTarget* target, const SkIRect& rect, bool insideClip) {
+ SkASSERT(NULL != target);
// this should only be called internally when we know we have a
// stencil buffer.
- SkASSERT(NULL != rt->getStencilBuffer());
- GrGLint stencilBitCount = rt->getStencilBuffer()->bits();
+ SkASSERT(NULL != target->getStencilBuffer());
+ GrGLint stencilBitCount = target->getStencilBuffer()->bits();
#if 0
SkASSERT(stencilBitCount > 0);
GrGLint clipStencilMask = (1 << (stencilBitCount - 1));
@@ -1529,12 +1518,13 @@ void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) {
} else {
value = 0;
}
- this->flushRenderTarget(&SkIRect::EmptyIRect());
+ GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
+ this->flushRenderTarget(glRT, &SkIRect::EmptyIRect());
GrAutoTRestore<ScissorState> asr(&fScissorState);
fScissorState.fEnabled = true;
fScissorState.fRect = rect;
- this->flushScissor();
+ this->flushScissor(glRT->getViewport(), glRT->origin());
GL_CALL(StencilMask((uint32_t) clipStencilMask));
GL_CALL(ClearStencil(value));
@@ -1600,13 +1590,12 @@ bool GrGpuGL::onReadPixels(GrRenderTarget* target,
// resolve the render target if necessary
GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target);
- GrDrawState::AutoRenderTargetRestore artr;
switch (tgt->getResolveType()) {
case GrGLRenderTarget::kCantResolve_ResolveType:
return false;
case GrGLRenderTarget::kAutoResolves_ResolveType:
- artr.set(this->drawState(), target);
- this->flushRenderTarget(&SkIRect::EmptyIRect());
+ this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target),
+ &SkIRect::EmptyIRect());
break;
case GrGLRenderTarget::kCanResolve_ResolveType:
this->onResolveRenderTarget(tgt);
@@ -1702,15 +1691,13 @@ bool GrGpuGL::onReadPixels(GrRenderTarget* target,
return true;
}
-void GrGpuGL::flushRenderTarget(const SkIRect* bound) {
+void GrGpuGL::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound) {
- GrGLRenderTarget* rt =
- static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget());
- SkASSERT(NULL != rt);
+ SkASSERT(NULL != target);
- uint32_t rtID = rt->getUniqueID();
+ uint32_t rtID = target->getUniqueID();
if (fHWBoundRenderTargetUniqueID != rtID) {
- GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID()));
#ifdef SK_DEBUG
// don't do this check in Chromium -- this is causing
// lots of repeated command buffer flushes when the compositor is
@@ -1725,17 +1712,17 @@ void GrGpuGL::flushRenderTarget(const SkIRect* bound) {
}
#endif
fHWBoundRenderTargetUniqueID = rtID;
- const GrGLIRect& vp = rt->getViewport();
+ const GrGLIRect& vp = target->getViewport();
if (fHWViewport != vp) {
vp.pushToGLViewport(this->glInterface());
fHWViewport = vp;
}
}
if (NULL == bound || !bound->isEmpty()) {
- rt->flagAsNeedingResolve(bound);
+ target->flagAsNeedingResolve(bound);
}
- GrTexture *texture = rt->asTexture();
+ GrTexture *texture = target->asTexture();
if (NULL != texture) {
texture->impl()->dirtyMipMaps(true);
}
@@ -1829,14 +1816,14 @@ void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) {
asr.reset(&fScissorState);
fScissorState.fEnabled = true;
fScissorState.fRect = dirtyRect;
- this->flushScissor();
+ this->flushScissor(rt->getViewport(), rt->origin());
GL_CALL(ResolveMultisampleFramebuffer());
} else {
if (GrGLCaps::kDesktop_EXT_MSFBOType == this->glCaps().msFBOType()) {
// this respects the scissor during the blit, so disable it.
asr.reset(&fScissorState);
fScissorState.fEnabled = false;
- this->flushScissor();
+ this->flushScissor(rt->getViewport(), rt->origin());
}
int right = r.fLeft + r.fWidth;
int top = r.fBottom + r.fHeight;
@@ -2512,7 +2499,7 @@ bool GrGpuGL::onCopySurface(GrSurface* dst,
// The EXT version applies the scissor during the blit, so disable it.
asr.reset(&fScissorState);
fScissorState.fEnabled = false;
- this->flushScissor();
+ this->flushScissor(dstGLRect, dst->origin());
}
GrGLint srcY0;
GrGLint srcY1;
diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h
index 94fd307f6d..1f748bb826 100644
--- a/src/gpu/gl/GrGpuGL.h
+++ b/src/gpu/gl/GrGpuGL.h
@@ -125,7 +125,8 @@ private:
GrStencilBuffer* sb,
GrRenderTarget* rt) SK_OVERRIDE;
- virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) SK_OVERRIDE;
+ virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
+ bool canIgnoreRect) SK_OVERRIDE;
virtual bool onReadPixels(GrRenderTarget* target,
int left, int top,
@@ -144,8 +145,8 @@ private:
virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE;
- virtual void clearStencil() SK_OVERRIDE;
- virtual void clearStencilClip(const SkIRect& rect,
+ virtual void clearStencil(GrRenderTarget*) SK_OVERRIDE;
+ virtual void clearStencilClip(GrRenderTarget*, const SkIRect& rect,
bool insideClip) SK_OVERRIDE;
virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
@@ -218,7 +219,7 @@ private:
// flushes the scissor. see the note on flushBoundTextureAndParams about
// flushing the scissor after that function is called.
- void flushScissor();
+ void flushScissor(const GrGLIRect& rtViewport, GrSurfaceOrigin rtOrigin);
void initFSAASupport();
@@ -229,9 +230,10 @@ private:
// ensures that such operations don't negatively interact with tracking bound textures.
void setScratchTextureUnit();
- // bound is region that may be modified and therefore has to be resolved.
+ // bounds is region that may be modified and therefore has to be resolved.
// NULL means whole target. Can be an empty rect.
- void flushRenderTarget(const SkIRect* bound);
+ void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds);
+
void flushStencil(DrawType);
void flushAAState(DrawType);
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index beef93e96b..8cdceb86af 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -265,8 +265,10 @@ bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC
dstCopy,
&fSharedGLProgramState);
}
+
+ GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(drawState.getRenderTarget());
this->flushStencil(type);
- this->flushScissor();
+ this->flushScissor(glRT->getViewport(), glRT->origin());
this->flushAAState(type);
SkIRect* devRect = NULL;
@@ -277,7 +279,7 @@ bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC
}
// This must come after textures are flushed because a texture may need
// to be msaa-resolved (which will modify bound FBO state).
- this->flushRenderTarget(devRect);
+ this->flushRenderTarget(glRT, devRect);
return true;
}