summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/rs/RenderScript.h2
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainView.java28
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java3
-rw-r--r--libs/rs/rs.spec6
-rw-r--r--libs/rs/rsContext.cpp99
-rw-r--r--libs/rs/rsContext.h7
-rw-r--r--libs/rs/rsLocklessFifo.cpp2
-rw-r--r--libs/rs/rsProgramVertex.cpp9
-rw-r--r--libs/rs/rsProgramVertex.h1
-rw-r--r--libs/rs/rsUtils.h2
10 files changed, 97 insertions, 62 deletions
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 9b043930d520..3ca8b158c8b7 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -55,7 +55,7 @@ RsDevice rsDeviceCreate();
void rsDeviceDestroy(RsDevice);
void rsDeviceSetConfig(RsDevice, RsDeviceParam, int32_t value);
-RsContext rsContextCreate(RsDevice, void *, uint32_t version, bool useDepth);
+RsContext rsContextCreate(RsDevice, uint32_t version, bool useDepth);
void rsContextDestroy(RsContext);
void rsObjDestroyOOB(RsContext, void *);
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
index cda005e06930..1e7c5a2f047e 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
@@ -48,29 +48,25 @@ public class FountainView extends RSSurfaceView {
private RenderScript mRS;
private FountainRS mRender;
- private void destroyRS() {
- if(mRS != null) {
- mRS = null;
- destroyRenderScript();
- }
- java.lang.System.gc();
- }
-
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- destroyRS();
- mRS = createRenderScript(false, true);
- mRender = new FountainRS();
- mRender.init(mRS, getResources(), w, h);
+ if (mRS == null) {
+ mRS = createRenderScript(false, true);
+ mRS.contextSetSurface(w, h, holder.getSurface());
+ mRender = new FountainRS();
+ mRender.init(mRS, getResources(), w, h);
+ }
}
- public void surfaceDestroyed(SurfaceHolder holder) {
- // Surface will be destroyed when we return
- destroyRS();
+ @Override
+ protected void onDetachedFromWindow() {
+ if(mRS != null) {
+ mRS = null;
+ destroyRenderScript();
+ }
}
-
@Override
public boolean onTouchEvent(MotionEvent ev)
{
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index b1facfc5a3b8..334fd9c356fa 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -126,13 +126,14 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ mRS.contextSetSurface(width, height, holder.getSurface());
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
private Script.Invokable createScript() {
- mRS = new RenderScript(mSurfaceView.getHolder().getSurface(), false, false);
+ mRS = new RenderScript(false, false);
mRS.mMessageCallback = new FilterCallback();
mParamsType = Type.createFromClass(mRS, Params.class, 1, "Parameters");
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 865e43555ad7..da25a2722df5 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -37,9 +37,15 @@ ContextResume {
}
ContextSetSurface {
+ param uint32_t width
+ param uint32_t height
param void *sur
}
+ContextSetPriority {
+ param uint32_t priority
+ }
+
AssignName {
param void *obj
param const char *name
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 3e4cc36bc36a..c835dda76011 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -92,38 +92,12 @@ void Context::initEGL()
LOGE("eglCreateContext returned EGL_NO_CONTEXT");
}
gGLContextCount++;
-
- if (mWndSurface) {
- setSurface(mWndSurface);
- } else {
- setSurface((Surface *)android_createDisplaySurface());
- }
-
- eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
- eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
-
-
- mGL.mVersion = glGetString(GL_VERSION);
- mGL.mVendor = glGetString(GL_VENDOR);
- mGL.mRenderer = glGetString(GL_RENDERER);
- mGL.mExtensions = glGetString(GL_EXTENSIONS);
-
- LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
- LOGV("GL Version %s", mGL.mVersion);
- LOGV("GL Vendor %s", mGL.mVendor);
- LOGV("GL Renderer %s", mGL.mRenderer);
- LOGV("GL Extensions %s", mGL.mExtensions);
-
- if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
- LOGE("Error, OpenGL ES Lite not supported");
- } else {
- sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
- }
}
void Context::deinitEGL()
{
- setSurface(NULL);
+ LOGV("deinitEGL");
+ setSurface(0, 0, NULL);
eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
checkEglError("eglDestroyContext");
@@ -265,9 +239,9 @@ void * Context::threadProc(void *vrsc)
rsc->props.mLogScripts = getProp("debug.rs.script");
rsc->props.mLogObjects = getProp("debug.rs.objects");
- pthread_mutex_lock(&gInitMutex);
- rsc->initEGL();
- pthread_mutex_unlock(&gInitMutex);
+ //pthread_mutex_lock(&gInitMutex);
+ //rsc->initEGL();
+ //pthread_mutex_unlock(&gInitMutex);
ScriptTLSStruct *tlsStruct = new ScriptTLSStruct;
if (!tlsStruct) {
@@ -342,7 +316,7 @@ void * Context::threadProc(void *vrsc)
return NULL;
}
-Context::Context(Device *dev, Surface *sur, bool useDepth)
+Context::Context(Device *dev, bool useDepth)
{
pthread_mutex_lock(&gInitMutex);
@@ -353,6 +327,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth)
mUseDepth = useDepth;
mPaused = false;
mObjHead = NULL;
+ memset(&mEGL, 0, sizeof(mEGL));
int status;
pthread_attr_t threadAttr;
@@ -380,7 +355,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth)
sparam.sched_priority = ANDROID_PRIORITY_DISPLAY;
pthread_attr_setschedparam(&threadAttr, &sparam);
- mWndSurface = sur;
+ mWndSurface = NULL;
objDestroyOOBInit();
timerInit();
@@ -426,8 +401,10 @@ Context::~Context()
objDestroyOOBDestroy();
}
-void Context::setSurface(Surface *sur)
+void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
{
+ LOGV("setSurface %i %i %p", w, h, sur);
+
EGLBoolean ret;
if (mEGL.mSurface != NULL) {
ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -437,10 +414,22 @@ void Context::setSurface(Surface *sur)
checkEglError("eglDestroySurface", ret);
mEGL.mSurface = NULL;
+ mEGL.mWidth = 0;
+ mEGL.mHeight = 0;
+ mWidth = 0;
+ mHeight = 0;
}
mWndSurface = sur;
if (mWndSurface != NULL) {
+ bool first = false;
+ if (!mEGL.mContext) {
+ first = true;
+ pthread_mutex_lock(&gInitMutex);
+ initEGL();
+ pthread_mutex_unlock(&gInitMutex);
+ }
+
mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
checkEglError("eglCreateWindowSurface");
if (mEGL.mSurface == EGL_NO_SURFACE) {
@@ -449,6 +438,36 @@ void Context::setSurface(Surface *sur)
ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
checkEglError("eglMakeCurrent", ret);
+
+ eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
+ eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
+ mWidth = w;
+ mHeight = h;
+ mStateVertex.updateSize(this, w, h);
+
+ if ((int)mWidth != mEGL.mWidth || (int)mHeight != mEGL.mHeight) {
+ LOGE("EGL/Surface mismatch EGL (%i x %i) SF (%i x %i)", mEGL.mWidth, mEGL.mHeight, mWidth, mHeight);
+ }
+
+ if (first) {
+ mGL.mVersion = glGetString(GL_VERSION);
+ mGL.mVendor = glGetString(GL_VENDOR);
+ mGL.mRenderer = glGetString(GL_RENDERER);
+ mGL.mExtensions = glGetString(GL_EXTENSIONS);
+
+ //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
+ LOGV("GL Version %s", mGL.mVersion);
+ LOGV("GL Vendor %s", mGL.mVendor);
+ LOGV("GL Renderer %s", mGL.mRenderer);
+ //LOGV("GL Extensions %s", mGL.mExtensions);
+
+ if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
+ LOGE("Error, OpenGL ES Lite not supported");
+ } else {
+ sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
+ }
+ }
+
}
}
@@ -767,19 +786,23 @@ void rsi_ContextResume(Context *rsc)
rsc->resume();
}
-void rsi_ContextSetSurface(Context *rsc, void *sur)
+void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, void *sur)
+{
+ rsc->setSurface(w, h, (Surface *)sur);
+}
+
+void rsi_ContextSetPriority(Context *rsc, uint32_t p)
{
- rsc->setSurface((Surface *)sur);
}
}
}
-RsContext rsContextCreate(RsDevice vdev, void *sur, uint32_t version, bool useDepth)
+RsContext rsContextCreate(RsDevice vdev, uint32_t version, bool useDepth)
{
Device * dev = static_cast<Device *>(vdev);
- Context *rsc = new Context(dev, (Surface *)sur, useDepth);
+ Context *rsc = new Context(dev, useDepth);
return rsc;
}
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index bffc55b7cb8b..f3803a5ec23b 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -49,7 +49,7 @@ namespace renderscript {
class Context
{
public:
- Context(Device *, Surface *, bool useDepth);
+ Context(Device *, bool useDepth);
~Context();
static pthread_key_t gThreadTLSKey;
@@ -94,7 +94,7 @@ public:
void pause();
void resume();
- void setSurface(Surface *sur);
+ void setSurface(uint32_t w, uint32_t h, Surface *sur);
void assignName(ObjectBase *obj, const char *name, uint32_t len);
void removeName(ObjectBase *obj);
@@ -189,6 +189,9 @@ protected:
} mGL;
+ uint32_t mWidth;
+ uint32_t mHeight;
+
bool mRunning;
bool mExit;
bool mUseDepth;
diff --git a/libs/rs/rsLocklessFifo.cpp b/libs/rs/rsLocklessFifo.cpp
index 085a81e751bb..c79652016f6e 100644
--- a/libs/rs/rsLocklessFifo.cpp
+++ b/libs/rs/rsLocklessFifo.cpp
@@ -57,7 +57,7 @@ bool LocklessCommandFifo::init(uint32_t sizeInBytes)
mPut = mBuffer;
mGet = mBuffer;
mEnd = mBuffer + (sizeInBytes) - 1;
- dumpState("init");
+ //dumpState("init");
return true;
}
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index eea8b3b67068..68f589f45f82 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -157,12 +157,17 @@ void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
pv->bindAllocation(alloc);
+ updateSize(rsc, w, h);
+}
+
+void ProgramVertexState::updateSize(Context *rsc, int32_t w, int32_t h)
+{
Matrix m;
m.loadOrtho(0,w, h,0, -1,1);
- alloc->subData(RS_PROGRAM_VERTEX_PROJECTION_OFFSET, 16, &m.m[0], 16*4);
+ mDefaultAlloc->subData(RS_PROGRAM_VERTEX_PROJECTION_OFFSET, 16, &m.m[0], 16*4);
m.loadIdentity();
- alloc->subData(RS_PROGRAM_VERTEX_MODELVIEW_OFFSET, 16, &m.m[0], 16*4);
+ mDefaultAlloc->subData(RS_PROGRAM_VERTEX_MODELVIEW_OFFSET, 16, &m.m[0], 16*4);
}
void ProgramVertexState::deinit(Context *rsc)
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index 493668c083a1..a97ba3825ff0 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -63,6 +63,7 @@ public:
void init(Context *rsc, int32_t w, int32_t h);
void deinit(Context *rsc);
+ void updateSize(Context *rsc, int32_t w, int32_t h);
ObjectBaseRef<ProgramVertex> mDefault;
ObjectBaseRef<ProgramVertex> mLast;
diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h
index 63d73a1480d5..07f893338bfa 100644
--- a/libs/rs/rsUtils.h
+++ b/libs/rs/rsUtils.h
@@ -18,7 +18,7 @@
#define ANDROID_RS_UTILS_H
#define LOG_NDEBUG 0
-#define LOG_TAG "rs"
+#define LOG_TAG "RenderScript"
#include <utils/Log.h>
#include <utils/Vector.h>
#include <utils/KeyedVector.h>