diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-01-18 20:57:22 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-01-18 20:57:22 +0000 |
commit | 2e7b43d33cc495663cb814a7a9d1ecdc09c31828 (patch) | |
tree | 10d01113bbac30d6e3b121d4a9ab5552a6567fd6 /gpu | |
parent | 44b2c73ca6358ba9c4a413d7b39db7991612a6a2 (diff) |
Remove notion of default rendertarget. This doesn't map well to usage patterns outside sample app. Make binding between SkGpuDevice and a GrRenderTarget more explicit. Create method on GrContext to wrap the current target in the 3D API with a GrRenderTarget.
git-svn-id: http://skia.googlecode.com/svn/trunk@706 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/include/GrContext.h | 17 | ||||
-rw-r--r-- | gpu/include/GrGpu.h | 26 | ||||
-rw-r--r-- | gpu/src/GrContext.cpp | 8 | ||||
-rw-r--r-- | gpu/src/GrGpu.cpp | 8 | ||||
-rw-r--r-- | gpu/src/GrGpuGL.cpp | 86 | ||||
-rw-r--r-- | gpu/src/GrGpuGL.h | 8 | ||||
-rw-r--r-- | gpu/src/GrGpuGLFixed.cpp | 4 | ||||
-rw-r--r-- | gpu/src/GrGpuGLShaders.cpp | 4 | ||||
-rw-r--r-- | gpu/src/GrGpuGLShaders2.cpp | 4 |
9 files changed, 84 insertions, 81 deletions
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h index a9316957cb..905fe50411 100644 --- a/gpu/include/GrContext.h +++ b/gpu/include/GrContext.h @@ -41,7 +41,7 @@ public: * Helper to create a opengl-shader based context
*/
static GrContext* CreateGLShaderContext();
-
+
virtual ~GrContext();
/**
@@ -115,6 +115,19 @@ public: int width, int height);
/**
+ * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
+ * viewport state from the underlying 3D API and wraps it in a
+ * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
+ * underlying object in its destructor and it is up to caller to guarantee
+ * that it remains valid while the GrRenderTarget is used.
+ *
+ * @return the newly created GrRenderTarget
+ */
+ GrRenderTarget* createRenderTargetFrom3DApiState() {
+ return fGpu->createRenderTargetFrom3DApiState();
+ }
+
+ /**
* Returns true if the specified use of an indexed texture is supported.
*/
bool supportsIndex8PixelConfig(const GrSamplerState&, int width, int height);
@@ -126,8 +139,6 @@ public: const GrClip& getClip() const { return fGpu->getClip(); }
void setRenderTarget(GrRenderTarget* target);
- void setDefaultRenderTargetSize(uint32_t width, uint32_t height);
- GrRenderTarget* defaultRenderTarget() { return fGpu->defaultRenderTarget(); }
void setTexture(int stage, GrTexture* texture);
void setSamplerState(int stage, const GrSamplerState&);
diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h index f1fdf01d50..6cbe53e698 100644 --- a/gpu/include/GrGpu.h +++ b/gpu/include/GrGpu.h @@ -197,6 +197,17 @@ public: int width, int height) = 0; /** + * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and + * viewport state from the underlying 3D API and wraps it in a + * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the + * underlying object in its destructor and it is up to caller to guarantee + * that it remains valid while the GrRenderTarget is used. + * + * @return the newly created GrRenderTarget + */ + virtual GrRenderTarget* createRenderTargetFrom3DApiState() = 0; + + /** * Creates a vertex buffer. * * @param size size in bytes of the vertex buffer @@ -221,21 +232,6 @@ public: virtual GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic) = 0; /** - * Gets the default render target. This is the render target set in the - * 3D API at the time the GrGpu was created. - */ - virtual GrRenderTarget* defaultRenderTarget() = 0; - - /** - * At construction time the GrGpu infers the render target and viewport from - * the state of the underlying 3D API. However, a platform-specific resize - * event may occur. - * @param width new width of the default rendertarget - * @param height new height of the default rendertarget - */ - virtual void setDefaultRenderTargetSize(uint32_t width, uint32_t height) = 0; - - /** * Erase the entire render target, ignoring any clips/scissors. * * This is issued to the GPU driver immediately. diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp index 94398cfaf8..512860210b 100644 --- a/gpu/src/GrContext.cpp +++ b/gpu/src/GrContext.cpp @@ -30,8 +30,8 @@ static const size_t MAX_TEXTURE_CACHE_BYTES = 8 * 1024 * 1024; #if DEFER_TEXT_RENDERING
static const uint32_t POOL_VB_SIZE = 2048 *
- GrDrawTarget::VertexSize( - GrDrawTarget::kTextFormat_VertexLayoutBit | + GrDrawTarget::VertexSize(
+ GrDrawTarget::kTextFormat_VertexLayoutBit |
GrDrawTarget::StageTexCoordVertexLayoutBit(0,0));
static const uint32_t NUM_POOL_VBS = 8;
#else
@@ -856,10 +856,6 @@ GrRenderTarget* GrContext::currentRenderTarget() const { return fGpu->currentRenderTarget();
}
-void GrContext::setDefaultRenderTargetSize(uint32_t width, uint32_t height) {
- fGpu->setDefaultRenderTargetSize(width, height);
-}
-
void GrContext::setSamplerState(int stage, const GrSamplerState& samplerState) {
fGpu->setSamplerState(stage, samplerState);
}
diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp index fe6d0c37f7..c48bd19892 100644 --- a/gpu/src/GrGpu.cpp +++ b/gpu/src/GrGpu.cpp @@ -178,6 +178,14 @@ void GrGpu::clipWillChange(const GrClip& clip) { bool GrGpu::setupClipAndFlushState(PrimitiveType type) { const GrIRect* r = NULL; + // we check this early because we need a valid + // render target to setup stencil clipping + // before even going into flushGraphicsState + if (NULL == fCurrDrawState.fRenderTarget) { + GrAssert(!"No render target bound."); + return false; + } + if (fCurrDrawState.fFlagBits & kClip_StateBit) { fClipState.fClipInStencil = fClip.countRects() > 1; diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp index 23636d1a92..084f98fd4a 100644 --- a/gpu/src/GrGpuGL.cpp +++ b/gpu/src/GrGpuGL.cpp @@ -152,24 +152,7 @@ GrGpuGL::GrGpuGL() { resetContextHelper(); - GrGLRenderTarget::GLRenderTargetIDs defaultRTIDs; - GR_GL_GetIntegerv(GR_FRAMEBUFFER_BINDING, (GLint*)&defaultRTIDs.fRTFBOID); - defaultRTIDs.fTexFBOID = defaultRTIDs.fRTFBOID; - defaultRTIDs.fMSColorRenderbufferID = 0; - defaultRTIDs.fStencilRenderbufferID = 0; - GLint vp[4]; - GR_GL_GetIntegerv(GL_VIEWPORT, vp); - fHWBounds.fViewportRect.setLTRB(vp[0], - vp[1] + vp[3], - vp[0] + vp[2], - vp[1]); - defaultRTIDs.fOwnIDs = false; - - fDefaultRenderTarget = new GrGLRenderTarget(defaultRTIDs, - fHWBounds.fViewportRect, - NULL, - this); - fHWDrawState.fRenderTarget = fDefaultRenderTarget; + fHWDrawState.fRenderTarget = NULL; fRenderTargetChanged = true; GLint maxTextureUnits; @@ -445,17 +428,13 @@ GrGpuGL::GrGpuGL() { fMinRenderTargetWidth = GrMax<GLuint>(fMinRenderTargetWidth, 16); fMinRenderTargetHeight = GrMax<GLuint>(fMinRenderTargetHeight, 16); #endif - // bind back to original FBO - GR_GLEXT(fExts, BindFramebuffer(GR_FRAMEBUFFER, defaultRTIDs.fRTFBOID)); + #if GR_COLLECT_STATS ++fStats.fRenderTargetChngCnt; #endif - eraseStencil(0, ~0); } GrGpuGL::~GrGpuGL() { - fDefaultRenderTarget->abandon(); - fDefaultRenderTarget->unref(); } void GrGpuGL::resetContextHelper() { @@ -501,6 +480,7 @@ void GrGpuGL::resetContextHelper() { fHWBounds.fScissorRect.setLTRB(0,0,0,0); fHWBounds.fScissorEnabled = false; GR_GL(Disable(GL_SCISSOR_TEST)); + fHWBounds.fViewportRect.setLTRB(-1,-1,-1,-1); // disabling the stencil test also disables // stencil buffer writes @@ -546,6 +526,30 @@ GrRenderTarget* GrGpuGL::createPlatformRenderTarget( return rt; } +GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiState() { + + GrGLRenderTarget::GLRenderTargetIDs rtIDs; + + GR_GL_GetIntegerv(GR_FRAMEBUFFER_BINDING, (GLint*)&rtIDs.fRTFBOID); + rtIDs.fTexFBOID = rtIDs.fRTFBOID; + rtIDs.fMSColorRenderbufferID = 0; + rtIDs.fStencilRenderbufferID = 0; + + GLint vp[4]; + GR_GL_GetIntegerv(GL_VIEWPORT, vp); + GrIRect viewportRect; + viewportRect.setLTRB(vp[0], + vp[1] + vp[3], + vp[0] + vp[2], + vp[1]); + rtIDs.fOwnIDs = false; + + return new GrGLRenderTarget(rtIDs, + viewportRect, + NULL, + this); +} + // defines stencil formats from more to less preferred GLenum GR_GL_STENCIL_FORMAT_ARRAY[] = {
GR_STENCIL_INDEX8,
@@ -979,10 +983,6 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc, return tex; } -GrRenderTarget* GrGpuGL::defaultRenderTarget() { - return fDefaultRenderTarget; -} - GrVertexBuffer* GrGpuGL::createVertexBuffer(uint32_t size, bool dynamic) { GLuint id; GR_GL(GenBuffers(1, &id)); @@ -1029,16 +1029,6 @@ GrIndexBuffer* GrGpuGL::createIndexBuffer(uint32_t size, bool dynamic) { return NULL; } -void GrGpuGL::setDefaultRenderTargetSize(uint32_t width, uint32_t height) { - GrIRect viewport(0, height, width, 0); - if (viewport != fDefaultRenderTarget->viewport()) { - fDefaultRenderTarget->setViewport(viewport); - if (fHWDrawState.fRenderTarget == fDefaultRenderTarget) { - fHWDrawState.fRenderTarget = NULL; - } - } -} - void GrGpuGL::flushScissor(const GrIRect* rect) { GrAssert(NULL != fCurrDrawState.fRenderTarget); const GrIRect& vp = @@ -1153,6 +1143,9 @@ bool GrGpuGL::readPixels(int left, int top, int width, int height, } void GrGpuGL::flushRenderTarget() { + + GrAssert(NULL != fCurrDrawState.fRenderTarget); + if (fHWDrawState.fRenderTarget != fCurrDrawState.fRenderTarget) { GrGLRenderTarget* rt = (GrGLRenderTarget*)fCurrDrawState.fRenderTarget; GR_GLEXT(fExts, BindFramebuffer(GR_FRAMEBUFFER, rt->renderFBOID())); @@ -1459,7 +1452,11 @@ void GrGpuGL::flushStencil() { } } -void GrGpuGL::flushGLStateCommon(PrimitiveType type) { +bool GrGpuGL::flushGLStateCommon(PrimitiveType type) { + + // GrGpu::setupClipAndFlushState should have already checked this + // and bailed if not true. + GrAssert(NULL != fCurrDrawState.fRenderTarget); for (int s = 0; s < kNumStages; ++s) { bool usingTexture = VertexUsesStage(s, fGeometrySrc.fVertexLayout); @@ -1521,15 +1518,7 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) { nextTexture->setTexParams(newTexParams); } else { GrAssert(!"Rendering with texture vert flag set but no texture"); - if (NULL != fHWDrawState.fTextures[s]) { - setTextureUnit(s); - GR_GL(BindTexture(GL_TEXTURE_2D, 0)); - // GrPrintf("---- bindtexture 0\n"); - #if GR_COLLECT_STATS - ++fStats.fTextureChngCnt; - #endif - fHWDrawState.fTextures[s] = NULL; - } + return false; } } } @@ -1607,6 +1596,7 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) { flushStencil(); fHWDrawState.fFlagBits = fCurrDrawState.fFlagBits; + return true; } void GrGpuGL::notifyVertexBufferBind(const GrGLVertexBuffer* buffer) { @@ -1645,7 +1635,7 @@ void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { // b) we set more state than just FBO based on the RT // So trash the HW state to force an RT flush next time if (fCurrDrawState.fRenderTarget == renderTarget) { - fCurrDrawState.fRenderTarget = fDefaultRenderTarget; + fCurrDrawState.fRenderTarget = NULL; } if (fHWDrawState.fRenderTarget == renderTarget) { fHWDrawState.fRenderTarget = NULL; diff --git a/gpu/src/GrGpuGL.h b/gpu/src/GrGpuGL.h index 8c2cd80997..611485df1d 100644 --- a/gpu/src/GrGpuGL.h +++ b/gpu/src/GrGpuGL.h @@ -42,9 +42,7 @@ public: intptr_t platformRenderTarget, int width, int height); - virtual GrRenderTarget* defaultRenderTarget(); - - virtual void setDefaultRenderTargetSize(uint32_t width, uint32_t height); + virtual GrRenderTarget* createRenderTargetFrom3DApiState(); virtual void eraseColor(GrColor color); @@ -98,7 +96,7 @@ protected: // sampler state (filtering, tiling) // FBO binding // line width - void flushGLStateCommon(PrimitiveType type); + bool flushGLStateCommon(PrimitiveType type); // set when this class changes the rendertarget. // Subclass should notice at flush time, take appropriate action, @@ -114,8 +112,6 @@ protected: GrGLExts fExts; private: - GrGLRenderTarget* fDefaultRenderTarget; - void resetContextHelper(); // notify callbacks to update state tracking when related diff --git a/gpu/src/GrGpuGLFixed.cpp b/gpu/src/GrGpuGLFixed.cpp index d142b66a0b..99a593daaa 100644 --- a/gpu/src/GrGpuGLFixed.cpp +++ b/gpu/src/GrGpuGLFixed.cpp @@ -140,7 +140,9 @@ bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) { } } - flushGLStateCommon(type); + if (!flushGLStateCommon(type)) { + return false; + } if (fRenderTargetChanged) { flushProjectionMatrix(); diff --git a/gpu/src/GrGpuGLShaders.cpp b/gpu/src/GrGpuGLShaders.cpp index 7cd1891814..03d46741c9 100644 --- a/gpu/src/GrGpuGLShaders.cpp +++ b/gpu/src/GrGpuGLShaders.cpp @@ -741,7 +741,9 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) { } } - flushGLStateCommon(type); + if (!flushGLStateCommon(type)) { + return false; + } if (fRenderTargetChanged) { // our coords are in pixel space and the GL matrices map to NDC diff --git a/gpu/src/GrGpuGLShaders2.cpp b/gpu/src/GrGpuGLShaders2.cpp index e47fe5dc5d..1218a3669a 100644 --- a/gpu/src/GrGpuGLShaders2.cpp +++ b/gpu/src/GrGpuGLShaders2.cpp @@ -1233,7 +1233,9 @@ void GrGpuGLShaders2::flushProgram(PrimitiveType type) { bool GrGpuGLShaders2::flushGraphicsState(PrimitiveType type) { - flushGLStateCommon(type); + if (!flushGLStateCommon(type)) { + return false; + } if (fRenderTargetChanged) { // our coords are in pixel space and the GL matrices map to NDC |