Merge "Fixing FBO font rendering bug that resulted from using old surface size."

This commit is contained in:
Alex Sakhartchouk
2011-11-17 09:13:24 -08:00
committed by Android (Google) Code Review
6 changed files with 44 additions and 6 deletions

View File

@@ -472,6 +472,30 @@ void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) {
}
}
uint32_t Context::getCurrentSurfaceWidth() const {
for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) {
if (mFBOCache.mHal.state.colorTargets[i] != NULL) {
return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimX();
}
}
if (mFBOCache.mHal.state.depthTarget != NULL) {
return mFBOCache.mHal.state.depthTarget->getType()->getDimX();
}
return mWidth;
}
uint32_t Context::getCurrentSurfaceHeight() const {
for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) {
if (mFBOCache.mHal.state.colorTargets[i] != NULL) {
return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimY();
}
}
if (mFBOCache.mHal.state.depthTarget != NULL) {
return mFBOCache.mHal.state.depthTarget->getType()->getDimY();
}
return mHeight;
}
void Context::pause() {
rsAssert(mIsGraphicsContext);
mPaused = true;

View File

@@ -164,6 +164,9 @@ public:
uint32_t getWidth() const {return mWidth;}
uint32_t getHeight() const {return mHeight;}
uint32_t getCurrentSurfaceWidth() const;
uint32_t getCurrentSurfaceHeight() const;
mutable ThreadIO mIO;
// Timers

View File

@@ -654,11 +654,7 @@ void FontState::appendMeshQuad(float x1, float y1, float z1,
const uint32_t floatsPerVert = 6;
float *currentPos = mTextMeshPtr + mCurrentQuadIndex * vertsPerQuad * floatsPerVert;
// Cull things that are off the screen
float width = (float)mRSC->getWidth();
float height = (float)mRSC->getHeight();
if (x1 > width || y1 < 0.0f || x2 < 0 || y4 > height) {
if (x1 > mSurfaceWidth || y1 < 0.0f || x2 < 0 || y4 > mSurfaceHeight) {
return;
}
@@ -750,6 +746,10 @@ void FontState::renderText(const char *text, uint32_t len, int32_t x, int32_t y,
return;
}
// Cull things that are off the screen
mSurfaceWidth = (float)mRSC->getCurrentSurfaceWidth();
mSurfaceHeight = (float)mRSC->getCurrentSurfaceHeight();
currentFont->renderUTF(text, len, x, y, startIndex, numGlyphs,
mode, bounds, bitmap, bitmapW, bitmapH);

View File

@@ -160,6 +160,9 @@ public:
protected:
float mSurfaceWidth;
float mSurfaceHeight;
friend class Font;
struct CacheTextureLine {

View File

@@ -206,8 +206,11 @@ void ProgramVertexState::init(Context *rsc) {
void ProgramVertexState::updateSize(Context *rsc) {
float *f = static_cast<float *>(mDefaultAlloc->getPtr());
float surfaceWidth = (float)rsc->getCurrentSurfaceWidth();
float surfaceHeight = (float)rsc->getCurrentSurfaceHeight();
Matrix4x4 m;
m.loadOrtho(0,rsc->getWidth(), rsc->getHeight(),0, -1,1);
m.loadOrtho(0, surfaceWidth, surfaceHeight, 0, -1, 1);
memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m.m, sizeof(m));
memcpy(&f[RS_PROGRAM_VERTEX_MVP_OFFSET], m.m, sizeof(m));

View File

@@ -79,23 +79,28 @@ void rsrBindProgramRaster(Context *rsc, Script *sc, ProgramRaster *pr) {
void rsrBindFrameBufferObjectColorTarget(Context *rsc, Script *sc, Allocation *a, uint32_t slot) {
CHECK_OBJ(va);
rsc->mFBOCache.bindColorTarget(rsc, a, slot);
rsc->mStateVertex.updateSize(rsc);
}
void rsrBindFrameBufferObjectDepthTarget(Context *rsc, Script *sc, Allocation *a) {
CHECK_OBJ(va);
rsc->mFBOCache.bindDepthTarget(rsc, a);
rsc->mStateVertex.updateSize(rsc);
}
void rsrClearFrameBufferObjectColorTarget(Context *rsc, Script *sc, uint32_t slot) {
rsc->mFBOCache.bindColorTarget(rsc, NULL, slot);
rsc->mStateVertex.updateSize(rsc);
}
void rsrClearFrameBufferObjectDepthTarget(Context *rsc, Script *sc) {
rsc->mFBOCache.bindDepthTarget(rsc, NULL);
rsc->mStateVertex.updateSize(rsc);
}
void rsrClearFrameBufferObjectTargets(Context *rsc, Script *sc) {
rsc->mFBOCache.resetAll(rsc);
rsc->mStateVertex.updateSize(rsc);
}
//////////////////////////////////////////////////////////////////////////////