Fixing FBO font rendering bug that resulted from using old surface size.
Change-Id: I31d0967bb36ca6ffb6a4c8194597d3c523cfe954
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index f8213a1..293fc3a 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -472,6 +472,30 @@
}
}
+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;
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 199cc5a..c6582c9 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -164,6 +164,9 @@
uint32_t getWidth() const {return mWidth;}
uint32_t getHeight() const {return mHeight;}
+ uint32_t getCurrentSurfaceWidth() const;
+ uint32_t getCurrentSurfaceHeight() const;
+
mutable ThreadIO mIO;
// Timers
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index 7efed9d..81b96af 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -654,11 +654,7 @@
const uint32_t floatsPerVert = 5;
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;
}
@@ -746,6 +742,10 @@
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);
diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h
index 679591c..4ca794d 100644
--- a/libs/rs/rsFont.h
+++ b/libs/rs/rsFont.h
@@ -160,6 +160,9 @@
protected:
+ float mSurfaceWidth;
+ float mSurfaceHeight;
+
friend class Font;
struct CacheTextureLine {
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index 4a13622..871caac 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -206,8 +206,11 @@
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));
diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp
index 7862f3c..26e2374 100644
--- a/libs/rs/rsScriptC_LibGL.cpp
+++ b/libs/rs/rsScriptC_LibGL.cpp
@@ -79,23 +79,28 @@
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);
}
//////////////////////////////////////////////////////////////////////////////