summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/Android.mk1
-rw-r--r--libs/rs/RenderScript.h2
-rw-r--r--libs/rs/RenderScriptEnv.h2
-rw-r--r--libs/rs/java/Samples/res/raw/multitexf.glsl2
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java6
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs46
-rw-r--r--libs/rs/rs.spec11
-rw-r--r--libs/rs/rsAllocation.cpp49
-rw-r--r--libs/rs/rsAllocation.h8
-rw-r--r--libs/rs/rsContext.cpp30
-rw-r--r--libs/rs/rsContext.h5
-rw-r--r--libs/rs/rsContextHostStub.h2
-rw-r--r--libs/rs/rsFileA3D.cpp3
-rw-r--r--libs/rs/rsFont.cpp158
-rw-r--r--libs/rs/rsFont.h51
-rw-r--r--libs/rs/rsLight.cpp144
-rw-r--r--libs/rs/rsLight.h67
-rw-r--r--libs/rs/rsProgramFragment.cpp2
-rw-r--r--libs/rs/rsProgramVertex.cpp5
-rw-r--r--libs/rs/rsScriptC_LibGL.cpp52
-rw-r--r--libs/rs/rsType.cpp53
-rw-r--r--libs/rs/rsType.h3
-rw-r--r--libs/rs/rsVertexArray.h3
-rw-r--r--libs/rs/scriptc/rs_graphics.rsh6
24 files changed, 400 insertions, 311 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 37c418b..05c1a48 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -83,7 +83,6 @@ LOCAL_SRC_FILES:= \
rsElement.cpp \
rsFileA3D.cpp \
rsFont.cpp \
- rsLight.cpp \
rsLocklessFifo.cpp \
rsObjectBase.cpp \
rsMatrix.cpp \
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 13ae1fb..66e27f3 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -40,7 +40,6 @@ typedef void * RsSampler;
typedef void * RsScript;
typedef void * RsMesh;
typedef void * RsType;
-typedef void * RsLight;
typedef void * RsObjectBase;
typedef void * RsProgram;
@@ -242,7 +241,6 @@ enum RsA3DClassID {
RS_A3D_CLASS_ID_PROGRAM_STORE,
RS_A3D_CLASS_ID_SAMPLER,
RS_A3D_CLASS_ID_ANIMATION,
- RS_A3D_CLASS_ID_LIGHT,
RS_A3D_CLASS_ID_ADAPTER_1D,
RS_A3D_CLASS_ID_ADAPTER_2D,
RS_A3D_CLASS_ID_SCRIPT_C
diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h
index c83ece4..b82eaf1 100644
--- a/libs/rs/RenderScriptEnv.h
+++ b/libs/rs/RenderScriptEnv.h
@@ -13,8 +13,6 @@ typedef void * RsMesh;
typedef void * RsType;
typedef void * RsProgramFragment;
typedef void * RsProgramStore;
-typedef void * RsLight;
-
typedef struct {
float m[16];
diff --git a/libs/rs/java/Samples/res/raw/multitexf.glsl b/libs/rs/java/Samples/res/raw/multitexf.glsl
index 91151ad..351ff9b 100644
--- a/libs/rs/java/Samples/res/raw/multitexf.glsl
+++ b/libs/rs/java/Samples/res/raw/multitexf.glsl
@@ -1,4 +1,4 @@
-varying vec4 varTex0;
+varying vec2 varTex0;
void main() {
vec2 t0 = varTex0.xy;
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
index a15c4a1..0990da3 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
@@ -84,8 +84,6 @@ public class RsRenderStatesRS {
private Allocation mTexTransparent;
private Allocation mTexChecker;
- private Allocation mAllocPV;
-
private Mesh mMbyNMesh;
private Mesh mTorus;
@@ -95,7 +93,6 @@ public class RsRenderStatesRS {
Font mFontSerifItalic;
Font mFontSerifBoldItalic;
Font mFontMono;
-
private Allocation mTextAlloc;
private ScriptC_rsrenderstates mScript;
@@ -267,12 +264,15 @@ public class RsRenderStatesRS {
mFontSerifBoldItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
mFontMono = Font.createFromFamily(mRS, mRes, "mono", Font.Style.NORMAL, 8);
+ mTextAlloc = Allocation.createFromString(mRS, "String from allocation");
+
mScript.set_gFontSans(mFontSans);
mScript.set_gFontSerif(mFontSerif);
mScript.set_gFontSerifBold(mFontSerifBold);
mScript.set_gFontSerifItalic(mFontSerifItalic);
mScript.set_gFontSerifBoldItalic(mFontSerifBoldItalic);
mScript.set_gFontMono(mFontMono);
+ mScript.set_gTextAlloc(mTextAlloc);
}
private void initMesh() {
diff --git a/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs b/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs
index b471504..77384ef 100644
--- a/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs
+++ b/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs
@@ -42,6 +42,7 @@ rs_font gFontSerifBold;
rs_font gFontSerifItalic;
rs_font gFontSerifBoldItalic;
rs_font gFontMono;
+rs_allocation gTextAlloc;
int gDisplayMode;
@@ -70,7 +71,7 @@ rs_program_fragment gProgFragmentMultitex;
#pragma rs export_var(gProgStoreBlendNoneDepth, gProgStoreBlendNone, gProgStoreBlendAlpha, gProgStoreBlendAdd)
#pragma rs export_var(gTexOpaque, gTexTorus, gTexTransparent, gTexChecker)
#pragma rs export_var(gMbyNMesh, gTorusMesh)
-#pragma rs export_var(gFontSans, gFontSerif, gFontSerifBold, gFontSerifItalic, gFontSerifBoldItalic, gFontMono)
+#pragma rs export_var(gFontSans, gFontSerif, gFontSerifBold, gFontSerifItalic, gFontSerifBoldItalic, gFontMono, gTextAlloc)
#pragma rs export_var(gLinearClamp, gLinearWrap, gMipLinearWrap, gMipLinearAniso8, gMipLinearAniso15, gNearestClamp)
#pragma rs export_var(gCullBack, gCullFront, gCullNone)
#pragma rs export_var(gVSConstants, gFSConstants, gVSInputs, gProgVertexCustom, gProgFragmentCustom, gProgFragmentMultitex)
@@ -85,7 +86,7 @@ void init() {
void displayFontSamples() {
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
- int yPos = 30;
+ int yPos = 100;
rsgBindFont(gFontSans);
rsgDrawText("Sans font sample", 30, yPos);
yPos += 30;
@@ -107,6 +108,47 @@ void displayFontSamples() {
yPos += 30;
rsgBindFont(gFontMono);
rsgDrawText("Monospace font sample", 30, yPos);
+ yPos += 50;
+
+ // Now use text metrics to center the text
+ uint width = rsgGetWidth();
+ uint height = rsgGetHeight();
+ int left = 0, right = 0, top = 0, bottom = 0;
+
+ rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
+ rsgBindFont(gFontSerifBoldItalic);
+
+ rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
+ int centeredPos = width / 2 - (right - left) / 2;
+ rsgDrawText(gTextAlloc, centeredPos, yPos);
+ yPos += 30;
+
+ const char* text = "Centered Text Sample";
+ rsgMeasureText(text, &left, &right, &top, &bottom);
+ centeredPos = width / 2 - (right - left) / 2;
+ rsgDrawText(text, centeredPos, yPos);
+ yPos += 30;
+
+ rsgBindFont(gFontSans);
+ text = "More Centered Text Samples";
+ rsgMeasureText(text, &left, &right, &top, &bottom);
+ centeredPos = width / 2 - (right - left) / 2;
+ rsgDrawText(text, centeredPos, yPos);
+ yPos += 30;
+
+ // Now draw bottom and top right aligned text
+ text = "Top-right aligned text";
+ rsgMeasureText(text, &left, &right, &top, &bottom);
+ rsgDrawText(text, width - right, top);
+
+ text = "Top-left";
+ rsgMeasureText(text, &left, &right, &top, &bottom);
+ rsgDrawText(text, -left, top);
+
+ text = "Bottom-right aligned text";
+ rsgMeasureText(text, &left, &right, &top, &bottom);
+ rsgDrawText(text, width - right, height + bottom);
+
}
void bindProgramVertexOrtho() {
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index a4752f4..0da637e 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -280,6 +280,17 @@ AllocationGetType {
ret const void*
}
+AllocationResize1D {
+ param RsAllocation va
+ param uint32_t dimX
+ }
+
+AllocationResize2D {
+ param RsAllocation va
+ param uint32_t dimX
+ param uint32_t dimY
+ }
+
SamplerBegin {
}
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 0356e4d..2e9e0b3 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -488,12 +488,13 @@ void Allocation::sendDirty() const
}
}
-void Allocation::incRefs(const void *ptr, size_t ct) const
+void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const
{
const uint8_t *p = static_cast<const uint8_t *>(ptr);
const Element *e = mType->getElement();
uint32_t stride = e->getSizeBytes();
+ p += stride * startOff;
while (ct > 0) {
e->incRefs(p);
ct --;
@@ -501,12 +502,13 @@ void Allocation::incRefs(const void *ptr, size_t ct) const
}
}
-void Allocation::decRefs(const void *ptr, size_t ct) const
+void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const
{
const uint8_t *p = static_cast<const uint8_t *>(ptr);
const Element *e = mType->getElement();
uint32_t stride = e->getSizeBytes();
+ p += stride * startOff;
while (ct > 0) {
e->decRefs(p);
ct --;
@@ -514,6 +516,37 @@ void Allocation::decRefs(const void *ptr, size_t ct) const
}
}
+void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len)
+{
+}
+
+void Allocation::resize1D(Context *rsc, uint32_t dimX)
+{
+ Type *t = mType->cloneAndResize1D(rsc, dimX);
+
+ uint32_t oldDimX = mType->getDimX();
+ if (dimX == oldDimX) {
+ return;
+ }
+
+ if (dimX < oldDimX) {
+ decRefs(mPtr, oldDimX - dimX, dimX);
+ }
+ mPtr = realloc(mPtr, t->getSizeBytes());
+
+ if (dimX > oldDimX) {
+ const Element *e = mType->getElement();
+ uint32_t stride = e->getSizeBytes();
+ memset(((uint8_t *)mPtr) + stride * oldDimX, 0, stride * (dimX - oldDimX));
+ }
+ mType.set(t);
+}
+
+void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY)
+{
+ LOGE("not implemented");
+}
+
/////////////////
//
@@ -822,6 +855,18 @@ void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)
a->read(data);
}
+void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX)
+{
+ Allocation *a = static_cast<Allocation *>(va);
+ a->resize1D(rsc, dimX);
+}
+
+void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY)
+{
+ Allocation *a = static_cast<Allocation *>(va);
+ a->resize2D(rsc, dimX, dimY);
+}
+
const void* rsi_AllocationGetType(Context *rsc, RsAllocation va)
{
Allocation *a = static_cast<Allocation *>(va);
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index ce5372f..24e245f 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -55,6 +55,10 @@ public:
void uploadToBufferObject(const Context *rsc);
uint32_t getBufferObjectID() const {return mBufferID;}
+ void copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len);
+
+ void resize1D(Context *rsc, uint32_t dimX);
+ void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY);
void data(Context *rsc, const void *data, uint32_t sizeBytes);
void subData(Context *rsc, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes);
@@ -86,8 +90,8 @@ public:
bool getIsTexture() const {return mIsTexture;}
bool getIsBufferObject() const {return mIsVertexBuffer;}
- void incRefs(const void *ptr, size_t ct) const;
- void decRefs(const void *ptr, size_t ct) const;
+ void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
+ void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
void sendDirty() const;
bool getHasGraphicsMipmaps() const {return mTextureGenMipmap;}
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 6940033..30add62 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -188,6 +188,9 @@ void Context::timerInit()
mTimeFrame = mTimeLast;
mTimeLastFrame = mTimeLast;
mTimerActive = RS_TIMER_INTERNAL;
+ mAverageFPSFrameCount = 0;
+ mAverageFPSStartTime = mTimeLast;
+ mAverageFPS = 0;
timerReset();
}
@@ -195,6 +198,16 @@ void Context::timerFrame()
{
mTimeLastFrame = mTimeFrame;
mTimeFrame = getTime();
+ // Update average fps
+ const uint64_t averageFramerateInterval = 1000 * 1000000;
+ mAverageFPSFrameCount ++;
+ uint64_t inverval = mTimeFrame - mAverageFPSStartTime;
+ if(inverval >= averageFramerateInterval) {
+ inverval = inverval / 1000000;
+ mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval;
+ mAverageFPSFrameCount = 0;
+ mAverageFPSStartTime = mTimeFrame;
+ }
}
void Context::timerSet(Timers tm)
@@ -218,12 +231,13 @@ void Context::timerPrint()
if (props.mLogTimes) {
- LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli)",
+ LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli), Avg fps: %u",
mTimeMSLastFrame,
100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript,
100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap,
100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
- 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
+ 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000,
+ mAverageFPS);
}
}
@@ -255,17 +269,17 @@ static bool getProp(const char *str)
void Context::displayDebugStats()
{
char buffer[128];
- sprintf(buffer, "Frame %i ms, Script %i ms", mTimeMSLastFrame, mTimeMSLastScript);
+ sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript);
float oldR, oldG, oldB, oldA;
mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA);
+ uint32_t bufferLen = strlen(buffer);
- float shadowCol = 0.2f;
+ float shadowCol = 0.1f;
mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f);
- mStateFont.renderText(buffer, 5, getHeight() - 5);
+ mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6);
- float textCol = 0.9f;
- mStateFont.setFontColor(textCol, textCol, textCol, 1.0f);
- mStateFont.renderText(buffer, 4, getHeight() - 6);
+ mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f);
+ mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7);
mStateFont.setFontColor(oldR, oldG, oldB, oldA);
}
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index dabe196..8a8b8a8 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -30,7 +30,6 @@
#include "rsAllocation.h"
#include "rsAdapter.h"
#include "rsSampler.h"
-#include "rsLight.h"
#include "rsFont.h"
#include "rsProgramFragment.h"
#include "rsProgramStore.h"
@@ -94,7 +93,6 @@ public:
ProgramStoreState mStateFragmentStore;
ProgramRasterState mStateRaster;
ProgramVertexState mStateVertex;
- LightState mStateLight;
VertexArrayState mStateVertexArray;
FontState mStateFont;
@@ -296,6 +294,9 @@ private:
uint32_t mTimeMSLastFrame;
uint32_t mTimeMSLastScript;
uint32_t mTimeMSLastSwap;
+ uint32_t mAverageFPSFrameCount;
+ uint64_t mAverageFPSStartTime;
+ uint32_t mAverageFPS;
};
}
diff --git a/libs/rs/rsContextHostStub.h b/libs/rs/rsContextHostStub.h
index 06298e8..aa0205d 100644
--- a/libs/rs/rsContextHostStub.h
+++ b/libs/rs/rsContextHostStub.h
@@ -30,7 +30,6 @@
#include "rsAllocation.h"
#include "rsAdapter.h"
#include "rsSampler.h"
-#include "rsLight.h"
#include "rsProgramFragment.h"
#include "rsProgramStore.h"
#include "rsProgramRaster.h"
@@ -68,7 +67,6 @@ public:
ProgramStoreState mStateFragmentStore;
//ProgramRasterState mStateRaster;
//ProgramVertexState mStateVertex;
- LightState mStateLight;
VertexArrayState mStateVertexArray;
//ScriptCState mScriptC;
diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp
index 893598f..c90edc2 100644
--- a/libs/rs/rsFileA3D.cpp
+++ b/libs/rs/rsFileA3D.cpp
@@ -278,9 +278,6 @@ ObjectBase *FileA3D::initializeFromEntry(size_t index) {
case RS_A3D_CLASS_ID_ANIMATION:
entry->mRsObj = Animation::createFromStream(mRSC, mReadStream);
break;
- case RS_A3D_CLASS_ID_LIGHT:
- entry->mRsObj = Light::createFromStream(mRSC, mReadStream);
- break;
case RS_A3D_CLASS_ID_ADAPTER_1D:
entry->mRsObj = Adapter1D::createFromStream(mRSC, mReadStream);
break;
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index c516ea9..a951005 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -84,34 +84,95 @@ void Font::invalidateTextureCache()
}
}
-void Font::drawCachedGlyph(CachedGlyphInfo *glyph, int x, int y)
+void Font::drawCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y)
{
FontState *state = &mRSC->mStateFont;
- int nPenX = x + glyph->mBitmapLeft;
- int nPenY = y - glyph->mBitmapTop + glyph->mBitmapHeight;
+ int32_t nPenX = x + glyph->mBitmapLeft;
+ int32_t nPenY = y - glyph->mBitmapTop + glyph->mBitmapHeight;
- state->appendMeshQuad(nPenX, nPenY, 0,
- glyph->mBitmapMinU, glyph->mBitmapMaxV,
+ float u1 = glyph->mBitmapMinU;
+ float u2 = glyph->mBitmapMaxU;
+ float v1 = glyph->mBitmapMinV;
+ float v2 = glyph->mBitmapMaxV;
- nPenX + (int)glyph->mBitmapWidth, nPenY, 0,
- glyph->mBitmapMaxU, glyph->mBitmapMaxV,
+ int32_t width = (int32_t) glyph->mBitmapWidth;
+ int32_t height = (int32_t) glyph->mBitmapHeight;
- nPenX + (int)glyph->mBitmapWidth, nPenY - (int)glyph->mBitmapHeight, 0,
- glyph->mBitmapMaxU, glyph->mBitmapMinV,
+ state->appendMeshQuad(nPenX, nPenY, 0, u1, v2,
+ nPenX + width, nPenY, 0, u2, v2,
+ nPenX + width, nPenY - height, 0, u2, v1,
+ nPenX, nPenY - height, 0, u1, v1);
+}
+
+void Font::drawCachedGlyph(CachedGlyphInfo* glyph, int32_t x, int32_t y,
+ uint8_t* bitmap, uint32_t bitmapW, uint32_t bitmapH) {
+ int32_t nPenX = x + glyph->mBitmapLeft;
+ int32_t nPenY = y + glyph->mBitmapTop;
+
+ uint32_t endX = glyph->mBitmapMinX + glyph->mBitmapWidth;
+ uint32_t endY = glyph->mBitmapMinY + glyph->mBitmapHeight;
+
+ FontState *state = &mRSC->mStateFont;
+ uint32_t cacheWidth = state->getCacheTextureType()->getDimX();
+ const uint8_t* cacheBuffer = state->getTextTextureData();
+
+ uint32_t cacheX = 0, cacheY = 0;
+ int32_t bX = 0, bY = 0;
+ for (cacheX = glyph->mBitmapMinX, bX = nPenX; cacheX < endX; cacheX++, bX++) {
+ for (cacheY = glyph->mBitmapMinY, bY = nPenY; cacheY < endY; cacheY++, bY++) {
+ if (bX < 0 || bY < 0 || bX >= (int32_t) bitmapW || bY >= (int32_t) bitmapH) {
+ LOGE("Skipping invalid index");
+ continue;
+ }
+ uint8_t tempCol = cacheBuffer[cacheY * cacheWidth + cacheX];
+ bitmap[bY * bitmapW + bX] = tempCol;
+ }
+ }
- nPenX, nPenY - (int)glyph->mBitmapHeight, 0,
- glyph->mBitmapMinU, glyph->mBitmapMinV);
}
-void Font::renderUTF(const char *text, uint32_t len, uint32_t start, int numGlyphs, int x, int y)
+void Font::measureCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y, Rect *bounds) {
+ int32_t nPenX = x + glyph->mBitmapLeft;
+ int32_t nPenY = y - glyph->mBitmapTop + glyph->mBitmapHeight;
+
+ int32_t width = (int32_t) glyph->mBitmapWidth;
+ int32_t height = (int32_t) glyph->mBitmapHeight;
+
+ if (bounds->bottom > nPenY) {
+ bounds->bottom = nPenY;
+ }
+ if (bounds->left > nPenX) {
+ bounds->left = nPenX;
+ }
+ if (bounds->right < nPenX + width) {
+ bounds->right = nPenX + width;
+ }
+ if (bounds->top < nPenY + height) {
+ bounds->top = nPenY + height;
+ }
+}
+
+void Font::renderUTF(const char *text, uint32_t len, int32_t x, int32_t y,
+ uint32_t start, int32_t numGlyphs,
+ RenderMode mode, Rect *bounds,
+ uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH)
{
if(!mInitialized || numGlyphs == 0 || text == NULL || len == 0) {
return;
}
- int penX = x, penY = y;
- int glyphsLeft = 1;
+ if(mode == Font::MEASURE) {
+ if (bounds == NULL) {
+ LOGE("No return rectangle provided to measure text");
+ return;
+ }
+ // Reset min and max of the bounding box to something large
+ bounds->set(1e6, -1e6, -1e6, 1e6);
+ }
+
+ int32_t penX = x, penY = y;
+ int32_t glyphsLeft = 1;
if(numGlyphs > 0) {
glyphsLeft = numGlyphs;
}
@@ -135,7 +196,17 @@ void Font::renderUTF(const char *text, uint32_t len, uint32_t start, int numGlyp
// If it's still not valid, we couldn't cache it, so we shouldn't draw garbage
if(cachedGlyph->mIsValid) {
- drawCachedGlyph(cachedGlyph, penX, penY);
+ switch(mode) {
+ case FRAMEBUFFER:
+ drawCachedGlyph(cachedGlyph, penX, penY);
+ break;
+ case BITMAP:
+ drawCachedGlyph(cachedGlyph, penX, penY, bitmap, bitmapW, bitmapH);
+ break;
+ case MEASURE:
+ measureCachedGlyph(cachedGlyph, penX, penY, bounds);
+ break;
+ }
}
penX += (cachedGlyph->mAdvance.x >> 6);
@@ -283,7 +354,7 @@ FontState::FontState()
}
// Get the black gamma threshold
- int blackThreshold = DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD;
+ int32_t blackThreshold = DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD;
if (property_get(PROPERTY_TEXT_BLACK_GAMMA_THRESHOLD, property, NULL) > 0) {
LOGD(" Setting text black gamma threshold to %s", property);
blackThreshold = atoi(property);
@@ -294,7 +365,7 @@ FontState::FontState()
mBlackThreshold = (float)(blackThreshold) / 255.0f;
// Get the white gamma threshold
- int whiteThreshold = DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD;
+ int32_t whiteThreshold = DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD;
if (property_get(PROPERTY_TEXT_WHITE_GAMMA_THRESHOLD, property, NULL) > 0) {
LOGD(" Setting text white gamma threshold to %s", property);
whiteThreshold = atoi(property);
@@ -397,13 +468,13 @@ bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *r
uint32_t cacheWidth = getCacheTextureType()->getDimX();
- unsigned char *cacheBuffer = (unsigned char*)mTextTexture->getPtr();
- unsigned char *bitmapBuffer = bitmap->buffer;
+ uint8_t *cacheBuffer = (uint8_t*)mTextTexture->getPtr();
+ uint8_t *bitmapBuffer = bitmap->buffer;
uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0;
for(cacheX = startX, bX = 0; cacheX < endX; cacheX ++, bX ++) {
for(cacheY = startY, bY = 0; cacheY < endY; cacheY ++, bY ++) {
- unsigned char tempCol = bitmapBuffer[bY * bitmap->width + bX];
+ uint8_t tempCol = bitmapBuffer[bY * bitmap->width + bX];
cacheBuffer[cacheY*cacheWidth + cacheX] = tempCol;
}
}
@@ -426,7 +497,7 @@ bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *r
void FontState::initRenderState()
{
- String8 shaderString("varying vec4 varTex0;\n");
+ String8 shaderString("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" lowp vec4 col = UNI_Color;\n");
shaderString.append(" col.a = texture2D(UNI_Tex0, varTex0.xy).a;\n");
@@ -487,7 +558,7 @@ void FontState::initTextTexture()
mTextTexture->deferedUploadToTexture(mRSC, false, 0);
// Split up our cache texture into lines of certain widths
- int nextLine = 0;
+ int32_t nextLine = 0;
mCacheLines.push(new CacheTextureLine(16, texType->getDimX(), nextLine, 0));
nextLine += mCacheLines.top()->mMaxHeight;
mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
@@ -519,8 +590,8 @@ void FontState::initVertexArrayBuffers()
// Four verts, two triangles , six indices per quad
for(uint32_t i = 0; i < mMaxNumberOfQuads; i ++) {
- int i6 = i * 6;
- int i4 = i * 4;
+ int32_t i6 = i * 6;
+ int32_t i4 = i * 4;
indexPtr[i6 + 0] = i4 + 0;
indexPtr[i6 + 1] = i4 + 1;
@@ -713,7 +784,11 @@ void FontState::precacheLatin(Font *font) {
}
-void FontState::renderText(const char *text, uint32_t len, uint32_t startIndex, int numGlyphs, int x, int y)
+void FontState::renderText(const char *text, uint32_t len, int32_t x, int32_t y,
+ uint32_t startIndex, int32_t numGlyphs,
+ Font::RenderMode mode,
+ Font::Rect *bounds,
+ uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH)
{
checkInit();
@@ -730,7 +805,8 @@ void FontState::renderText(const char *text, uint32_t len, uint32_t startIndex,
return;
}
- currentFont->renderUTF(text, len, startIndex, numGlyphs, x, y);
+ currentFont->renderUTF(text, len, x, y, startIndex, numGlyphs,
+ mode, bounds, bitmap, bitmapW, bitmapH);
if(mCurrentQuadIndex != 0) {
issueDrawCommand();
@@ -738,32 +814,8 @@ void FontState::renderText(const char *text, uint32_t len, uint32_t startIndex,
}
}
-void FontState::renderText(const char *text, int x, int y)
-{
- size_t textLen = strlen(text);
- renderText(text, textLen, 0, -1, x, y);
-}
-
-void FontState::renderText(Allocation *alloc, int x, int y)
-{
- if(!alloc) {
- return;
- }
-
- const char *text = (const char *)alloc->getPtr();
- size_t allocSize = alloc->getType()->getSizeBytes();
- renderText(text, allocSize, 0, -1, x, y);
-}
-
-void FontState::renderText(Allocation *alloc, uint32_t start, int len, int x, int y)
-{
- if(!alloc) {
- return;
- }
-
- const char *text = (const char *)alloc->getPtr();
- size_t allocSize = alloc->getType()->getSizeBytes();
- renderText(text, allocSize, start, len, x, y);
+void FontState::measureText(const char *text, uint32_t len, Font::Rect *bounds) {
+ renderText(text, len, 0, 0, 0, -1, Font::MEASURE, bounds);
}
void FontState::setFontColor(float r, float g, float b, float a) {
@@ -773,7 +825,7 @@ void FontState::setFontColor(float r, float g, float b, float a) {
mConstants.mFontColor[3] = a;
mConstants.mGamma = 1.0f;
- const int luminance = (r * 2.0f + g * 5.0f + b) / 8.0f;
+ const float luminance = (r * 2.0f + g * 5.0f + b) / 8.0f;
if (luminance <= mBlackThreshold) {
mConstants.mGamma = mBlackGamma;
} else if (luminance >= mWhiteThreshold) {
diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h
index 16009ef..0012b84 100644
--- a/libs/rs/rsFont.h
+++ b/libs/rs/rsFont.h
@@ -45,12 +45,26 @@ class FontState;
class Font : public ObjectBase
{
public:
- ~Font();
+ enum RenderMode {
+ FRAMEBUFFER,
+ BITMAP,
+ MEASURE,
+ };
- // Pointer to the utf data, length of data, where to start, number of glyphs ot read
- // (each glyph may be longer than a char because we are dealing with utf data)
- // Last two variables are the initial pen position
- void renderUTF(const char *text, uint32_t len, uint32_t start, int numGlyphs, int x, int y);
+ struct Rect {
+ int32_t left;
+ int32_t top;
+ int32_t right;
+ int32_t bottom;
+ void set(int32_t l, int32_t r, int32_t t, int32_t b) {
+ left = l;
+ right = r;
+ top = t;
+ bottom = b;
+ }
+ };
+
+ ~Font();
// Currently files do not get serialized,
// but we need to inherit from ObjectBase for ref tracking
@@ -66,6 +80,14 @@ protected:
friend class FontState;
+ // Pointer to the utf data, length of data, where to start, number of glyphs ot read
+ // (each glyph may be longer than a char because we are dealing with utf data)
+ // Last two variables are the initial pen position
+ void renderUTF(const char *text, uint32_t len, int32_t x, int32_t y,
+ uint32_t start, int32_t numGlyphs,
+ RenderMode mode = FRAMEBUFFER, Rect *bounds = NULL,
+ uint8_t *bitmap = NULL, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
+
void invalidateTextureCache();
struct CachedGlyphInfo
{
@@ -106,7 +128,10 @@ protected:
CachedGlyphInfo *cacheGlyph(uint32_t glyph);
void updateGlyphCache(CachedGlyphInfo *glyph);
- void drawCachedGlyph(CachedGlyphInfo *glyph, int x, int y);
+ void measureCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y, Rect *bounds);
+ void drawCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y);
+ void drawCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y,
+ uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH);
};
class FontState
@@ -121,10 +146,13 @@ public:
ObjectBaseRef<Font> mDefault;
ObjectBaseRef<Font> mLast;
- void renderText(const char *text, uint32_t len, uint32_t startIndex, int numGlyphs, int x, int y);
- void renderText(const char *text, int x, int y);
- void renderText(Allocation *alloc, int x, int y);
- void renderText(Allocation *alloc, uint32_t start, int len, int x, int y);
+ void renderText(const char *text, uint32_t len, int32_t x, int32_t y,
+ uint32_t startIndex = 0, int numGlyphs = -1,
+ Font::RenderMode mode = Font::FRAMEBUFFER,
+ Font::Rect *bounds = NULL,
+ uint8_t *bitmap = NULL, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
+
+ void measureText(const char *text, uint32_t len, Font::Rect *bounds);
void setFontColor(float r, float g, float b, float a);
void getFontColor(float *r, float *g, float *b, float *a) const;
@@ -198,6 +226,9 @@ protected:
// Texture to cache glyph bitmaps
ObjectBaseRef<Allocation> mTextTexture;
void initTextTexture();
+ const uint8_t* getTextTextureData() const {
+ return (uint8_t*)mTextTexture->getPtr();
+ }
bool cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *retOriginY);
const Type* getCacheTextureType() {
diff --git a/libs/rs/rsLight.cpp b/libs/rs/rsLight.cpp
deleted file mode 100644
index eab9a07..0000000
--- a/libs/rs/rsLight.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_RS_BUILD_FOR_HOST
-#include "rsContext.h"
-#include <GLES/gl.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
-
-using namespace android;
-using namespace android::renderscript;
-
-
-Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc)
-{
- mAllocFile = __FILE__;
- mAllocLine = __LINE__;
- mIsLocal = isLocal;
- mIsMono = isMono;
-
- mPosition[0] = 0;
- mPosition[1] = 0;
- mPosition[2] = 1;
- mPosition[3] = 0;
-
- mColor[0] = 1.f;
- mColor[1] = 1.f;
- mColor[2] = 1.f;
- mColor[3] = 1.f;
-}
-
-Light::~Light()
-{
-}
-
-void Light::setPosition(float x, float y, float z)
-{
- mPosition[0] = x;
- mPosition[1] = y;
- mPosition[2] = z;
-}
-
-void Light::setColor(float r, float g, float b)
-{
- mColor[0] = r;
- mColor[1] = g;
- mColor[2] = b;
-}
-
-void Light::setupGL(uint32_t num) const
-{
- glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, mColor);
- glLightfv(GL_LIGHT0 + num, GL_SPECULAR, mColor);
- glLightfv(GL_LIGHT0 + num, GL_POSITION, mPosition);
-}
-
-void Light::serialize(OStream *stream) const
-{
-
-}
-
-Light *Light::createFromStream(Context *rsc, IStream *stream)
-{
- return NULL;
-}
-
-////////////////////////////////////////////
-
-LightState::LightState()
-{
- clear();
-}
-
-LightState::~LightState()
-{
-}
-
-void LightState::clear()
-{
- mIsLocal = false;
- mIsMono = false;
-}
-
-
-////////////////////////////////////////////////////
-//
-
-namespace android {
-namespace renderscript {
-
-void rsi_LightBegin(Context *rsc)
-{
- rsc->mStateLight.clear();
-}
-
-void rsi_LightSetLocal(Context *rsc, bool isLocal)
-{
- rsc->mStateLight.mIsLocal = isLocal;
-}
-
-void rsi_LightSetMonochromatic(Context *rsc, bool isMono)
-{
- rsc->mStateLight.mIsMono = isMono;
-}
-
-RsLight rsi_LightCreate(Context *rsc)
-{
- Light *l = new Light(rsc, rsc->mStateLight.mIsLocal,
- rsc->mStateLight.mIsMono);
- l->incUserRef();
- return l;
-}
-
-void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b)
-{
- Light *l = static_cast<Light *>(vl);
- l->setColor(r, g, b);
-}
-
-void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z)
-{
- Light *l = static_cast<Light *>(vl);
- l->setPosition(x, y, z);
-}
-
-
-
-}
-}
diff --git a/libs/rs/rsLight.h b/libs/rs/rsLight.h
deleted file mode 100644
index bd58979..0000000
--- a/libs/rs/rsLight.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_LIGHT_H
-#define ANDROID_LIGHT_H
-
-
-#include "rsObjectBase.h"
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace renderscript {
-
-
-// An element is a group of Components that occupies one cell in a structure.
-class Light : public ObjectBase
-{
-public:
- Light(Context *, bool isLocal, bool isMono);
- virtual ~Light();
-
- // Values, mutable after creation.
- void setPosition(float x, float y, float z);
- void setColor(float r, float g, float b);
-
- void setupGL(uint32_t num) const;
- virtual void serialize(OStream *stream) const;
- virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_LIGHT; }
- static Light *createFromStream(Context *rsc, IStream *stream);
-
-protected:
- float mColor[4];
- float mPosition[4];
- bool mIsLocal;
- bool mIsMono;
-};
-
-
-class LightState {
-public:
- LightState();
- ~LightState();
-
- void clear();
-
- bool mIsMono;
- bool mIsLocal;
-};
-
-
-}
-}
-#endif //ANDROID_LIGHT_H
-
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index c94f294..81b4fa4 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -190,7 +190,7 @@ void ProgramFragmentState::init(Context *rsc)
{
String8 shaderString(RS_SHADER_INTERNAL);
shaderString.append("varying lowp vec4 varColor;\n");
- shaderString.append("varying vec4 varTex0;\n");
+ shaderString.append("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" lowp vec4 col = UNI_Color;\n");
shaderString.append(" gl_FragColor = col;\n");
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index d3dbfb2..a785262 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -242,6 +242,7 @@ ProgramVertexState::~ProgramVertexState()
void ProgramVertexState::init(Context *rsc)
{
const Element *matrixElem = Element::create(rsc, RS_TYPE_MATRIX_4X4, RS_KIND_USER, false, 1);
+ const Element *f2Elem = Element::create(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 2);
const Element *f3Elem = Element::create(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 3);
const Element *f4Elem = Element::create(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 4);
@@ -256,7 +257,7 @@ void ProgramVertexState::init(Context *rsc)
rsc->mStateElement.elementBuilderAdd(f4Elem, "position", 1);
rsc->mStateElement.elementBuilderAdd(f4Elem, "color", 1);
rsc->mStateElement.elementBuilderAdd(f3Elem, "normal", 1);
- rsc->mStateElement.elementBuilderAdd(f4Elem, "texture0", 1);
+ rsc->mStateElement.elementBuilderAdd(f2Elem, "texture0", 1);
const Element *attrElem = rsc->mStateElement.elementBuilderCreate(rsc);
Type *inputType = new Type(rsc);
@@ -266,7 +267,7 @@ void ProgramVertexState::init(Context *rsc)
String8 shaderString(RS_SHADER_INTERNAL);
shaderString.append("varying vec4 varColor;\n");
- shaderString.append("varying vec4 varTex0;\n");
+ shaderString.append("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" gl_Position = UNI_MVP * ATTRIB_position;\n");
shaderString.append(" gl_PointSize = 1.0;\n");
diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp
index 88db761..b991cab 100644
--- a/libs/rs/rsScriptC_LibGL.cpp
+++ b/libs/rs/rsScriptC_LibGL.cpp
@@ -351,13 +351,59 @@ static void SC_DrawTextAlloc(RsAllocation va, int x, int y)
CHECK_OBJ(va);
GET_TLS();
Allocation *alloc = static_cast<Allocation *>(va);
- rsc->mStateFont.renderText(alloc, x, y);
+ const char *text = (const char *)alloc->getPtr();
+ size_t allocSize = alloc->getType()->getSizeBytes();
+ rsc->mStateFont.renderText(text, allocSize, x, y);
}
static void SC_DrawText(const char *text, int x, int y)
{
GET_TLS();
- rsc->mStateFont.renderText(text, x, y);
+ size_t textLen = strlen(text);
+ rsc->mStateFont.renderText(text, textLen, x, y);
+}
+
+static void SC_setMetrics(Font::Rect *metrics,
+ int32_t *left, int32_t *right,
+ int32_t *top, int32_t *bottom)
+{
+ if(left) {
+ *left = metrics->left;
+ }
+ if(right) {
+ *right = metrics->right;
+ }
+ if(top) {
+ *top = metrics->top;
+ }
+ if(bottom) {
+ *bottom = metrics->bottom;
+ }
+}
+
+static void SC_MeasureTextAlloc(RsAllocation va,
+ int32_t *left, int32_t *right,
+ int32_t *top, int32_t *bottom)
+{
+ CHECK_OBJ(va);
+ GET_TLS();
+ Allocation *alloc = static_cast<Allocation *>(va);
+ const char *text = (const char *)alloc->getPtr();
+ size_t textLen = alloc->getType()->getSizeBytes();
+ Font::Rect metrics;
+ rsc->mStateFont.measureText(text, textLen, &metrics);
+ SC_setMetrics(&metrics, left, right, top, bottom);
+}
+
+static void SC_MeasureText(const char *text,
+ int32_t *left, int32_t *right,
+ int32_t *top, int32_t *bottom)
+{
+ GET_TLS();
+ size_t textLen = strlen(text);
+ Font::Rect metrics;
+ rsc->mStateFont.measureText(text, textLen, &metrics);
+ SC_setMetrics(&metrics, left, right, top, bottom);
}
static void SC_BindFont(RsFont font)
@@ -432,6 +478,8 @@ static ScriptCState::SymbolTable_t gSyms[] = {
{ "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText },
{ "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc },
+ { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText },
+ { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc },
{ "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont },
{ "_Z12rsgFontColorffff", (void *)&SC_FontColor },
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index fc037a3..8cdb48a 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -274,6 +274,59 @@ bool Type::isEqual(const Type *other) const {
return false;
}
+Type * Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const
+{
+ TypeState * stc = &rsc->mStateType;
+ for (uint32_t ct=0; ct < stc->mTypes.size(); ct++) {
+ Type *t = stc->mTypes[ct];
+ if (t->getElement() != mElement.get()) continue;
+ if (t->getDimX() != dimX) continue;
+ if (t->getDimY() != mDimY) continue;
+ if (t->getDimZ() != mDimZ) continue;
+ if (t->getDimLOD() != mDimLOD) continue;
+ if (t->getDimFaces() != mFaces) continue;
+ t->incUserRef();
+ return t;
+ }
+
+ Type *nt = new Type(rsc);
+ nt->mElement.set(mElement);
+ nt->mDimX = dimX;
+ nt->mDimY = mDimY;
+ nt->mDimZ = mDimZ;
+ nt->mDimLOD = mDimLOD;
+ nt->mFaces = mFaces;
+ nt->compute();
+ return nt;
+}
+
+Type * Type::cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const
+{
+ TypeState * stc = &rsc->mStateType;
+ for (uint32_t ct=0; ct < stc->mTypes.size(); ct++) {
+ Type *t = stc->mTypes[ct];
+ if (t->getElement() != mElement.get()) continue;
+ if (t->getDimX() != dimX) continue;
+ if (t->getDimY() != dimY) continue;
+ if (t->getDimZ() != mDimZ) continue;
+ if (t->getDimLOD() != mDimLOD) continue;
+ if (t->getDimFaces() != mFaces) continue;
+ t->incUserRef();
+ return t;
+ }
+
+ Type *nt = new Type(rsc);
+ nt->mElement.set(mElement);
+ nt->mDimX = dimX;
+ nt->mDimY = dimY;
+ nt->mDimZ = mDimZ;
+ nt->mDimLOD = mDimLOD;
+ nt->mFaces = mFaces;
+ nt->compute();
+ return nt;
+}
+
+
//////////////////////////////////////////////////
//
namespace android {
diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h
index 33faa87..b5548c0 100644
--- a/libs/rs/rsType.h
+++ b/libs/rs/rsType.h
@@ -79,6 +79,9 @@ public:
bool isEqual(const Type *other) const;
+ Type * cloneAndResize1D(Context *rsc, uint32_t dimX) const;
+ Type * cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
+
protected:
struct LOD {
size_t mX;
diff --git a/libs/rs/rsVertexArray.h b/libs/rs/rsVertexArray.h
index bd76d87..dea7d41 100644
--- a/libs/rs/rsVertexArray.h
+++ b/libs/rs/rsVertexArray.h
@@ -62,7 +62,6 @@ public:
}
void add(const Attrib &, uint32_t stride);
- //void addLegacy(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset);
void add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name);
void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const;
@@ -89,7 +88,7 @@ public:
}
}
-#endif //ANDROID_LIGHT_H
+#endif //ANDROID_VERTEX_ARRAY_H
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index c0b2d2d..ac6f8cc 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -79,6 +79,12 @@ extern void __attribute__((overloadable))
rsgBindFont(rs_font);
extern void __attribute__((overloadable))
rsgFontColor(float, float, float, float);
+// Returns the bounding box of the text relative to (0, 0)
+// Any of left, right, top, bottom could be NULL
+extern void __attribute__((overloadable))
+ rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
+extern void __attribute__((overloadable))
+ rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
extern void __attribute__((overloadable))
rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,