From 7d34d2eecc40d150d867e37d5160a1bc3cfccbde Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Mon, 24 Jan 2011 17:41:47 +0000 Subject: [PATCH] Increase number of stages from 1 to 2 Move GrTextContext from stage 0 to stage 1 so it doesn't conflict with GrPaint (allow textured text) Switch to dynamically generated shaders git-svn-id: http://skia.googlecode.com/svn/trunk@721 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gpu/include/GrDrawTarget.h | 2 +- gpu/include/GrTextContext.h | 3 ++- gpu/src/GrDrawTarget.cpp | 9 +++++++-- gpu/src/GrGpu.cpp | 6 ++++-- gpu/src/GrGpuFactory.cpp | 2 +- gpu/src/GrGpuGL.cpp | 10 ++++++++-- gpu/src/GrGpuGLShaders2.cpp | 9 ++++++--- gpu/src/GrTextContext.cpp | 32 ++++++++++++++++++++++---------- 8 files changed, 51 insertions(+), 22 deletions(-) diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h index ec84cda..862559e 100644 --- a/gpu/include/GrDrawTarget.h +++ b/gpu/include/GrDrawTarget.h @@ -50,7 +50,7 @@ public: // Currently there is just one stage but this will be changed soon. enum { - kNumStages = 1, + kNumStages = 2, kMaxTexCoords = kNumStages }; diff --git a/gpu/include/GrTextContext.h b/gpu/include/GrTextContext.h index d813c09..727358e 100644 --- a/gpu/include/GrTextContext.h +++ b/gpu/include/GrTextContext.h @@ -38,7 +38,8 @@ public: void flush(); // optional; automatically called by destructor private: - const GrPaint& fPaint; + GrPaint fPaint; + GrVertexLayout fVertexLayout; GrContext* fContext; GrDrawTarget* fDrawTarget; diff --git a/gpu/src/GrDrawTarget.cpp b/gpu/src/GrDrawTarget.cpp index abc9fb4..0101ecd 100644 --- a/gpu/src/GrDrawTarget.cpp +++ b/gpu/src/GrDrawTarget.cpp @@ -472,9 +472,14 @@ void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) { fDrawTarget = target; - fDrawTarget->saveCurrentDrawState(&fDrawState); + if (NULL != fDrawTarget) { + fDrawTarget->saveCurrentDrawState(&fDrawState); + } } GrDrawTarget::AutoStateRestore::~AutoStateRestore() { - fDrawTarget->restoreDrawState(fDrawState); + if (NULL != fDrawTarget) { + fDrawTarget->restoreDrawState(fDrawState); + } } + diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp index c48bd19..d8bbcd2 100644 --- a/gpu/src/GrGpu.cpp +++ b/gpu/src/GrGpu.cpp @@ -74,7 +74,9 @@ void GrGpu::resetContext() { } void GrGpu::unimpl(const char msg[]) { -// GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg); +#if GR_DEBUG + GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg); +#endif } /////////////////////////////////////////////////////////////////////////////// @@ -108,7 +110,7 @@ bool GrGpu::canDisableBlend() const { if (VertexUsesStage(s, fGeometrySrc.fVertexLayout)) { GrAssert(NULL != fCurrDrawState.fTextures[s]); GrTexture::PixelConfig config = fCurrDrawState.fTextures[s]->config(); - + if (GrTexture::kRGB_565_PixelConfig != config && GrTexture::kRGBX_8888_PixelConfig != config) { return false; diff --git a/gpu/src/GrGpuFactory.cpp b/gpu/src/GrGpuFactory.cpp index b3627c9..5e61609 100644 --- a/gpu/src/GrGpuFactory.cpp +++ b/gpu/src/GrGpuFactory.cpp @@ -24,7 +24,7 @@ #include "GrGLConfig.h" -#define GR_USE_GLSHADERS2 0 +#define GR_USE_GLSHADERS2 1 #if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP #include "GrGpuGLFixed.h" diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp index 1dbc5fb..f0c7cff 100644 --- a/gpu/src/GrGpuGL.cpp +++ b/gpu/src/GrGpuGL.cpp @@ -1019,9 +1019,13 @@ void GrGpuGL::flushScissor(const GrIRect* rect) { } void GrGpuGL::eraseColor(GrColor color) { + if (NULL == fCurrDrawState.fRenderTarget) { + return; + } flushRenderTarget(); if (fHWBounds.fScissorEnabled) { GR_GL(Disable(GL_SCISSOR_TEST)); + fHWBounds.fScissorEnabled = false; } GR_GL(ColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE)); GR_GL(ClearColor(GrColorUnpackR(color)/255.f, @@ -1029,19 +1033,21 @@ void GrGpuGL::eraseColor(GrColor color) { GrColorUnpackB(color)/255.f, GrColorUnpackA(color)/255.f)); GR_GL(Clear(GL_COLOR_BUFFER_BIT)); - fHWBounds.fScissorEnabled = false; fWriteMaskChanged = true; } void GrGpuGL::eraseStencil(uint32_t value, uint32_t mask) { + if (NULL == fCurrDrawState.fRenderTarget) { + return; + } flushRenderTarget(); if (fHWBounds.fScissorEnabled) { GR_GL(Disable(GL_SCISSOR_TEST)); + fHWBounds.fScissorEnabled = false; } GR_GL(StencilMask(mask)); GR_GL(ClearStencil(value)); GR_GL(Clear(GL_STENCIL_BUFFER_BIT)); - fHWBounds.fScissorEnabled = false; fWriteMaskChanged = true; } diff --git a/gpu/src/GrGpuGLShaders2.cpp b/gpu/src/GrGpuGLShaders2.cpp index 1218a36..25d0aeb 100644 --- a/gpu/src/GrGpuGLShaders2.cpp +++ b/gpu/src/GrGpuGLShaders2.cpp @@ -236,13 +236,17 @@ static uint32_t ror(uint32_t x) { return (x >> 8) | (x << 24); } +static uint32_t rol(uint32_t x) { + return (x << 8) | (x >> 24); +} + GrGpuGLShaders2::ProgramCache::HashKey::HashKey(const ProgramDesc& desc) { fDesc = desc; // if you change the size of the desc, need to update the hash function - GR_STATIC_ASSERT(8 == sizeof(ProgramDesc)); + GR_STATIC_ASSERT(12 == sizeof(ProgramDesc)); uint32_t* d = (uint32_t*) &fDesc; - fHash = d[0] ^ ror(d[1]); + fHash = d[0] ^ ror(d[1]) ^ rol(d[2]); } bool GrGpuGLShaders2::ProgramCache::HashKey::EQ(const Entry& entry, @@ -267,7 +271,6 @@ uint32_t GrGpuGLShaders2::ProgramCache::HashKey::getHash() const { return fHash; } - struct GrGpuGLShaders2::ShaderCodeSegments { GrSStringBuilder<256> fVSUnis; GrSStringBuilder<256> fVSAttrs; diff --git a/gpu/src/GrTextContext.cpp b/gpu/src/GrTextContext.cpp index 59a907e..d59f4ce 100644 --- a/gpu/src/GrTextContext.cpp +++ b/gpu/src/GrTextContext.cpp @@ -23,9 +23,11 @@ #include "GrTextStrike_impl.h" #include "GrFontScaler.h" -static const GrVertexLayout VLAYOUT = - GrDrawTarget::kTextFormat_VertexLayoutBit | - GrDrawTarget::StageTexCoordVertexLayoutBit(0,0); +static const int TEXT_STAGE = 1; + +static const GrVertexLayout BASE_VLAYOUT = + GrDrawTarget::kTextFormat_VertexLayoutBit | + GrDrawTarget::StageTexCoordVertexLayoutBit(TEXT_STAGE,0); void GrTextContext::flushGlyphs() { if (fCurrVertex > 0) { @@ -36,18 +38,17 @@ void GrTextContext::flushGlyphs() { GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode, GrSamplerState::kRepeat_WrapMode, !fExtMatrix.isIdentity()); - fDrawTarget->setSamplerState(0, sampler); + fDrawTarget->setSamplerState(TEXT_STAGE, sampler); GrAssert(GrIsALIGN4(fCurrVertex)); int nIndices = fCurrVertex + (fCurrVertex >> 1); GrAssert(fCurrTexture); - fDrawTarget->setTexture(0, fCurrTexture); - fDrawTarget->setTextureMatrix(0, GrMatrix::I()); + fDrawTarget->setTexture(TEXT_STAGE, fCurrTexture); + fDrawTarget->setTextureMatrix(TEXT_STAGE, GrMatrix::I()); fDrawTarget->setIndexSourceToBuffer(fContext->quadIndexBuffer()); fDrawTarget->drawIndexed(GrDrawTarget::kTriangles_PrimitiveType, 0, 0, fCurrVertex, nIndices); - fDrawTarget->releaseReservedGeometry(); fVertices = NULL; fMaxVertices = 0; @@ -82,9 +83,20 @@ GrTextContext::GrTextContext(GrContext* context, } } + // save the context's original matrix off and restore in destructor + // this must be done before getTextTarget. fOrigViewMatrix = fContext->getMatrix(); fContext->setMatrix(fExtMatrix); + fVertexLayout = BASE_VLAYOUT; + if (NULL != paint.getTexture()) { + fVertexLayout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0); + GrMatrix inverseViewMatrix; + if (fOrigViewMatrix.invert(&inverseViewMatrix)) { + fPaint.fTextureMatrix.preConcat(inverseViewMatrix); + } + } + fVertices = NULL; fMaxVertices = 0; fDrawTarget = fContext->getTextTarget(fPaint); @@ -191,7 +203,7 @@ HAS_ATLAS: // If we need to reserve vertices allow the draw target to suggest // a number of verts to reserve and whether to perform a flush. fMaxVertices = kMinRequestedVerts; - bool flush = fDrawTarget->geometryHints(VLAYOUT, + bool flush = fDrawTarget->geometryHints(fVertexLayout, &fMaxVertices, NULL); if (flush) { @@ -200,7 +212,7 @@ HAS_ATLAS: fDrawTarget = fContext->getTextTarget(fPaint); fMaxVertices = kDefaultRequestedVerts; // ignore return, no point in flushing again. - fDrawTarget->geometryHints(VLAYOUT, + fDrawTarget->geometryHints(fVertexLayout, &fMaxVertices, NULL); } @@ -211,7 +223,7 @@ HAS_ATLAS: // don't exceed the limit of the index buffer fMaxVertices = (fContext->maxQuadsInIndexBuffer() * 4); } - bool success = fDrawTarget->reserveAndLockGeometry(VLAYOUT, + bool success = fDrawTarget->reserveAndLockGeometry(fVertexLayout, fMaxVertices, 0, GrTCast(&fVertices), NULL); -- 2.7.4