summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2011-02-09 08:59:32 -0800
committerAlex Sakhartchouk <alexst@google.com>2011-02-09 08:59:32 -0800
commitf82428a932333620401d657017110d5818308016 (patch)
treea6ff0a6eca8351a9cc426d765e6bfb0ccbaf7876 /libs
parent3f41d8f5ee1a8d5366d79ee03d97fac8403c676a (diff)
downloadframeworks_base-f82428a932333620401d657017110d5818308016.zip
frameworks_base-f82428a932333620401d657017110d5818308016.tar.gz
frameworks_base-f82428a932333620401d657017110d5818308016.tar.bz2
Cleanup of the code in view to do creation/destruction in the right places.
Change-Id: I1c87682cc2c35ad5ee15c06cd78f48b612668181
Diffstat (limited to 'libs')
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsList.java18
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsListRS.java7
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsListView.java48
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java18
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java17
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java60
-rw-r--r--libs/rs/java/Samples/src/com/android/samples/rslist.rs1
7 files changed, 46 insertions, 123 deletions
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsList.java b/libs/rs/java/Samples/src/com/android/samples/RsList.java
index d47be42..2d7add0 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsList.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsList.java
@@ -16,26 +16,8 @@
package com.android.samples;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
import android.app.Activity;
-import android.content.res.Configuration;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Config;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-
-import java.lang.Runtime;
public class RsList extends Activity {
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
index 8e2d51f..6ee545ac 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
@@ -73,17 +73,12 @@ public class RsListRS {
"Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
};
- int mWidth;
- int mHeight;
-
public RsListRS() {
}
- public void init(RenderScriptGL rs, Resources res, int width, int height) {
+ public void init(RenderScriptGL rs, Resources res) {
mRS = rs;
mRes = res;
- mWidth = width;
- mHeight = height;
initRS();
}
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListView.java b/libs/rs/java/Samples/src/com/android/samples/RsListView.java
index 00b1723..b67bd48 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsListView.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsListView.java
@@ -15,55 +15,40 @@
*/
package com.android.samples;
-
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
import android.renderscript.RenderScriptGL;
import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
import android.view.MotionEvent;
public class RsListView extends RSSurfaceView {
public RsListView(Context context) {
super(context);
- //setFocusable(true);
+ ensureRenderScript();
}
private RenderScriptGL mRS;
private RsListRS mRender;
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
+ private void ensureRenderScript() {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- sc.setDepth(16, 24);
mRS = createRenderScriptGL(sc);
- mRS.setSurface(holder, w, h);
mRender = new RsListRS();
- mRender.init(mRS, getResources(), w, h);
+ mRender.init(mRS, getResources());
}
}
@Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ ensureRenderScript();
+ }
+
+ @Override
protected void onDetachedFromWindow() {
+ mRender = null;
if (mRS != null) {
mRS = null;
destroyRenderScriptGL();
@@ -71,23 +56,14 @@ public class RsListView extends RSSurfaceView {
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- // break point at here
- // this method doesn't work when 'extends View' include 'extends ScrollView'.
- return super.onKeyDown(keyCode, event);
- }
-
-
- @Override
public boolean onTouchEvent(MotionEvent ev)
{
boolean ret = false;
int act = ev.getAction();
- if (act == ev.ACTION_DOWN) {
+ if (act == MotionEvent.ACTION_DOWN) {
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
ret = true;
- } else if (act == ev.ACTION_MOVE) {
+ } else if (act == MotionEvent.ACTION_MOVE) {
mRender.onActionMove((int)ev.getX(), (int)ev.getY());
ret = true;
}
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java
index 33c1719..ff8c2de 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java
@@ -16,26 +16,8 @@
package com.android.samples;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
import android.app.Activity;
-import android.content.res.Configuration;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Config;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-
-import java.lang.Runtime;
public class RsRenderStates extends Activity {
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 87840a7..49b65d6 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
@@ -16,8 +16,6 @@
package com.android.samples;
-import java.io.Writer;
-
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -39,11 +37,11 @@ public class RsRenderStatesRS {
public RsRenderStatesRS() {
}
- public void init(RenderScriptGL rs, Resources res, int width, int height) {
+ public void init(RenderScriptGL rs, Resources res) {
mRS = rs;
+ mWidth = mRS.getWidth();
+ mHeight = mRS.getHeight();
mRes = res;
- mWidth = width;
- mHeight = height;
mOptionsARGB.inScaled = false;
mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
mMode = 0;
@@ -51,6 +49,15 @@ public class RsRenderStatesRS {
initRS();
}
+ public void surfaceChanged() {
+ mWidth = mRS.getWidth();
+ mHeight = mRS.getHeight();
+
+ Matrix4f proj = new Matrix4f();
+ proj.loadOrthoWindow(mWidth, mHeight);
+ mPVA.setProjection(proj);
+ }
+
private Resources mRes;
private RenderScriptGL mRS;
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java
index 235d29b..4d339dd 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java
@@ -16,54 +16,48 @@
package com.android.samples;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
import android.renderscript.RenderScriptGL;
import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
import android.view.MotionEvent;
+import android.view.SurfaceHolder;
public class RsRenderStatesView extends RSSurfaceView {
public RsRenderStatesView(Context context) {
super(context);
- //setFocusable(true);
+ ensureRenderScript();
}
private RenderScriptGL mRS;
private RsRenderStatesRS mRender;
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
+ private void ensureRenderScript() {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
sc.setDepth(16, 24);
mRS = createRenderScriptGL(sc);
- mRS.setSurface(holder, w, h);
mRender = new RsRenderStatesRS();
- mRender.init(mRS, getResources(), w, h);
+ mRender.init(mRS, getResources());
}
}
@Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ ensureRenderScript();
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ super.surfaceChanged(holder, format, w, h);
+ mRender.surfaceChanged();
+ }
+
+ @Override
protected void onDetachedFromWindow() {
+ mRender = null;
if (mRS != null) {
mRS = null;
destroyRenderScriptGL();
@@ -71,25 +65,13 @@ public class RsRenderStatesView extends RSSurfaceView {
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- // break point at here
- // this method doesn't work when 'extends View' include 'extends ScrollView'.
- return super.onKeyDown(keyCode, event);
- }
-
-
- @Override
- public boolean onTouchEvent(MotionEvent ev)
- {
- boolean ret = false;
- int act = ev.getAction();
- if (act == ev.ACTION_DOWN) {
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
- ret = true;
+ return true;
}
- return ret;
+ return false;
}
}
diff --git a/libs/rs/java/Samples/src/com/android/samples/rslist.rs b/libs/rs/java/Samples/src/com/android/samples/rslist.rs
index b79f4fc..52c870a 100644
--- a/libs/rs/java/Samples/src/com/android/samples/rslist.rs
+++ b/libs/rs/java/Samples/src/com/android/samples/rslist.rs
@@ -37,7 +37,6 @@ int textPos = 0;
int root(int launchID) {
rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- rsgClearDepth(1.0f);
textPos -= (int)gDY*2;
gDY *= 0.95;