diff options
author | Alex Sakhartchouk <alexst@google.com> | 2010-05-17 15:12:54 -0700 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2010-05-17 15:12:54 -0700 |
commit | 31be678ff706bdf7e7c9f34c9ffcd8d2794643e2 (patch) | |
tree | bbb138bd1f72fef63d76a9da747754052317b1fe /src | |
parent | 8bc6296d6120655dc30b2d4f7905c07224783705 (diff) | |
download | android_packages_wallpapers_MagicSmoke-31be678ff706bdf7e7c9f34c9ffcd8d2794643e2.tar.gz android_packages_wallpapers_MagicSmoke-31be678ff706bdf7e7c9f34c9ffcd8d2794643e2.tar.bz2 android_packages_wallpapers_MagicSmoke-31be678ff706bdf7e7c9f34c9ffcd8d2794643e2.zip |
Removing setName based on feedback.
After compiler fix, everything seems to match reference.
Mostly working, but patterns mismatch reference.
Magic smoke bug repro case.
Added missing files.
Change-Id: I3260848b40040d10abe8e15f2ac3b24d6c51d040
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/magicsmoke/MagicSmokeRS.java | 142 | ||||
-rw-r--r-- | src/com/android/magicsmoke/RenderScriptScene.java | 13 | ||||
-rw-r--r-- | src/com/android/magicsmoke/RenderScriptWallpaper.java | 16 | ||||
-rw-r--r-- | src/com/android/magicsmoke/ScriptC_MagicSmoke.java | 203 |
4 files changed, 303 insertions, 71 deletions
diff --git a/src/com/android/magicsmoke/MagicSmokeRS.java b/src/com/android/magicsmoke/MagicSmokeRS.java index 3ab431c..4089d65 100644 --- a/src/com/android/magicsmoke/MagicSmokeRS.java +++ b/src/com/android/magicsmoke/MagicSmokeRS.java @@ -45,6 +45,7 @@ import android.renderscript.ProgramStore.BlendDstFunc; import android.renderscript.ProgramStore.BlendSrcFunc; import android.util.Log; import android.view.MotionEvent; +import android.os.Bundle; import java.util.TimeZone; @@ -66,8 +67,8 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange public int mBlendFunc; } WorldState mWorldState = new WorldState(); - private Type mStateType; - private Allocation mState; + //private Type mStateType; + //private Allocation mState; private ProgramStore mPfsBackgroundOne; private ProgramStore mPfsBackgroundSrc; @@ -76,6 +77,8 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange private Allocation[] mSourceTextures; private Allocation[] mRealTextures; + private ScriptC_MagicSmoke mScript; + private ProgramVertex mPVBackground; private ProgramVertex.MatrixAllocation mPVAlloc; @@ -161,7 +164,6 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { makeNewState(); - mState.data(mWorldState); } void makeNewState() { @@ -180,6 +182,20 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange mWorldState.mAlphaMul = mPreset[p].mAlphaMul; mWorldState.mPreMul = mPreset[p].mPreMul ? 1 : 0; mWorldState.mBlendFunc = mPreset[p].mBlendFunc; + + if(mScript != null) { + mScript.set_gPreset(mWorldState.mPreset); + mScript.set_gTextureMask(mWorldState.mTextureMask); + mScript.set_gRotate(mWorldState.mRotate); + mScript.set_gTextureSwap(mWorldState.mTextureSwap); + mScript.set_gProcessTextureMode(mWorldState.mProcessTextureMode); + mScript.set_gBackCol(mWorldState.mBackCol); + mScript.set_gLowCol(mWorldState.mLowCol); + mScript.set_gHighCol(mWorldState.mHighCol); + mScript.set_gAlphaMul(mWorldState.mAlphaMul); + mScript.set_gPreMul(mWorldState.mPreMul); + mScript.set_gBlendFunc(mWorldState.mBlendFunc); + } } @Override @@ -191,6 +207,18 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange } @Override + public Bundle onCommand(String action, int x, int y, int z, Bundle extras, + boolean resultRequested) { + + if ("android.wallpaper.tap".equals(action)) { + mTouchY = y; + } + mWorldState.mTilt = 0; + mScript.set_gTilt(mWorldState.mTilt); + return null; + } + + /*@Override public void onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: @@ -207,16 +235,16 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange dy = -4; } mWorldState.mTilt = dy; - mState.data(mWorldState); + mScript.set_gTilt(mWorldState.mTilt); + //mState.data(mWorldState); } - } + }*/ @Override - public void setOffset(float xOffset, float yOffset, float xStep, float yStep, - int xPixels, int yPixels) { + public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) { // update our state, then push it to the renderscript mWorldState.mXOffset = xOffset; - mState.data(mWorldState); + mScript.set_gXOffset(mWorldState.mXOffset); } @Override @@ -230,7 +258,6 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange super.start(); mSharedPref.registerOnSharedPreferenceChangeListener(this); makeNewState(); - mState.data(mWorldState); } float alphafactor; @@ -245,9 +272,7 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange in.getPixels(pixels, 0, 256, 0, 0, 256, 256); mRealTextures[index] = Allocation.createTyped(mRS, mTextureType); mSourceTextures[index] = Allocation.createTyped(mRS, mTextureType); - mSourceTextures[index].setName(name+"_src"); mSourceTextures[index].data(pixels); - mRealTextures[index].setName(name); in.recycle(); } @@ -265,27 +290,40 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange loadBitmap(R.drawable.noise3, 2, "Tnoise3", alphamul, lowcol, highcol); loadBitmap(R.drawable.noise4, 3, "Tnoise4", alphamul, lowcol, highcol); loadBitmap(R.drawable.noise5, 4, "Tnoise5", alphamul, lowcol, highcol); + + mScript.set_gTnoise1(mRealTextures[0]); + mScript.set_gTnoise2(mRealTextures[1]); + mScript.set_gTnoise3(mRealTextures[2]); + mScript.set_gTnoise4(mRealTextures[3]); + mScript.set_gTnoise5(mRealTextures[4]); + + mScript.bind_gNoisesrc1(mSourceTextures[0]); + mScript.bind_gNoisesrc2(mSourceTextures[1]); + mScript.bind_gNoisesrc3(mSourceTextures[2]); + mScript.bind_gNoisesrc4(mSourceTextures[3]); + mScript.bind_gNoisesrc5(mSourceTextures[4]); + + mScript.bind_gNoisedst1(mRealTextures[0]); + mScript.bind_gNoisedst2(mRealTextures[1]); + mScript.bind_gNoisedst3(mRealTextures[2]); + mScript.bind_gNoisedst4(mRealTextures[3]); + mScript.bind_gNoisedst5(mRealTextures[4]); } @Override protected ScriptC createScript() { -/* - // Create a renderscript type from a java class. The specified name doesn't - // really matter; the name by which we refer to the object in RenderScript - // will be specified later. - mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState"); - // Create an allocation from the type we just created. - mState = Allocation.createTyped(mRS, mStateType); - mState.data(mWorldState); + + mScript = new ScriptC_MagicSmoke(mRS, mResources, R.raw.clouds_bc, true); // First set up the coordinate system and such ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); mPVBackground = pvb.create(); - mPVBackground.setName("PVBackground"); mPVAlloc = new ProgramVertex.MatrixAllocation(mRS); mPVBackground.bindAllocation(mPVAlloc); mPVAlloc.setupProjectionNormalized(mWidth, mHeight); + mScript.set_gPVBackground(mPVBackground); + mSourceTextures = new Allocation[5]; mRealTextures = new Allocation[5]; @@ -307,10 +345,11 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, ProgramFragment.Builder.Format.RGBA, 0); mPfBackground = builder.create(); - mPfBackground.setName("PFBackground"); mPfBackground.bindSampler(mSampler, 0); } + mScript.set_gPFBackground(mPfBackground); + { ProgramStore.Builder builder = new ProgramStore.Builder(mRS, null, null); builder.setDepthFunc(ProgramStore.DepthFunc.EQUAL); @@ -318,50 +357,29 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange builder.setDitherEnable(true); // without dithering there is severe banding builder.setDepthMask(false); mPfsBackgroundOne = builder.create(); - mPfsBackgroundOne.setName("PFSBackgroundOne"); builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); mPfsBackgroundSrc = builder.create(); - mPfsBackgroundSrc.setName("PFSBackgroundSrc"); } - // Time to create the script - ScriptC.Builder sb = new ScriptC.Builder(mRS); - // Specify the name by which to refer to the WorldState object in the - // renderscript. - sb.setType(mStateType, "State", RSID_STATE); - sb.setType(mTextureType, "noisesrc1", RSID_NOISESRC1); - sb.setType(mTextureType, "noisedst1", RSID_NOISEDST1); - sb.setType(mTextureType, "noisesrc2", RSID_NOISESRC2); - sb.setType(mTextureType, "noisedst2", RSID_NOISEDST2); - sb.setType(mTextureType, "noisesrc3", RSID_NOISESRC3); - sb.setType(mTextureType, "noisedst3", RSID_NOISEDST3); - sb.setType(mTextureType, "noisesrc4", RSID_NOISESRC4); - sb.setType(mTextureType, "noisedst4", RSID_NOISEDST4); - sb.setType(mTextureType, "noisesrc5", RSID_NOISESRC5); - sb.setType(mTextureType, "noisedst5", RSID_NOISEDST5); - sb.setScript(mResources, R.raw.clouds); - sb.setRoot(true); - - ScriptC script = sb.create(); - script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); - script.setTimeZone(TimeZone.getDefault().getID()); - - script.bindAllocation(mState, RSID_STATE); - script.bindAllocation(mSourceTextures[0], RSID_NOISESRC1); - script.bindAllocation(mRealTextures[0], RSID_NOISEDST1); - script.bindAllocation(mSourceTextures[1], RSID_NOISESRC2); - script.bindAllocation(mRealTextures[1], RSID_NOISEDST2); - script.bindAllocation(mSourceTextures[2], RSID_NOISESRC3); - script.bindAllocation(mRealTextures[2], RSID_NOISEDST3); - script.bindAllocation(mSourceTextures[3], RSID_NOISESRC4); - script.bindAllocation(mRealTextures[3], RSID_NOISEDST4); - script.bindAllocation(mSourceTextures[4], RSID_NOISESRC5); - script.bindAllocation(mRealTextures[4], RSID_NOISEDST5); - //script.bindAllocation(mPVAlloc.mAlloc, RSID_PROGRAMVERTEX); - - - return script; - */ - return null; + mScript.set_gPFSBackgroundOne(mPfsBackgroundOne); + mScript.set_gPFSBackgroundSrc(mPfsBackgroundSrc); + + mScript.setClearColor(0.5f, 0.0f, 0.0f, 1.0f); + + mScript.set_gPreset(mWorldState.mPreset); + mScript.set_gTextureMask(mWorldState.mTextureMask); + mScript.set_gRotate(mWorldState.mRotate); + mScript.set_gTextureSwap(mWorldState.mTextureSwap); + mScript.set_gProcessTextureMode(mWorldState.mProcessTextureMode); + mScript.set_gBackCol(mWorldState.mBackCol); + mScript.set_gLowCol(mWorldState.mLowCol); + mScript.set_gHighCol(mWorldState.mHighCol); + mScript.set_gAlphaMul(mWorldState.mAlphaMul); + mScript.set_gPreMul(mWorldState.mPreMul); + mScript.set_gBlendFunc(mWorldState.mBlendFunc); + mScript.set_gTilt(mWorldState.mTilt); + mScript.set_gXOffset(mWorldState.mXOffset); + + return mScript; } } diff --git a/src/com/android/magicsmoke/RenderScriptScene.java b/src/com/android/magicsmoke/RenderScriptScene.java index 8a5e213..23b3360 100644 --- a/src/com/android/magicsmoke/RenderScriptScene.java +++ b/src/com/android/magicsmoke/RenderScriptScene.java @@ -18,9 +18,10 @@ package com.android.magicsmoke; import android.content.res.Resources; +import android.os.Bundle; import android.renderscript.RenderScriptGL; import android.renderscript.ScriptC; -import android.view.MotionEvent; +//import android.view.MotionEvent; public abstract class RenderScriptScene { protected int mWidth; @@ -82,10 +83,12 @@ public abstract class RenderScriptScene { } @SuppressWarnings({"UnusedDeclaration"}) - public void setOffset(float xOffset, float yOffset, - float xStep, float yStep, int xPixels, int yPixels) { - } - public void onTouchEvent(MotionEvent event) { + public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) { } + @SuppressWarnings({"UnusedDeclaration"}) + public Bundle onCommand(String action, int x, int y, int z, Bundle extras, + boolean resultRequested) { + return null; + } } diff --git a/src/com/android/magicsmoke/RenderScriptWallpaper.java b/src/com/android/magicsmoke/RenderScriptWallpaper.java index 1f24812..75abf0d 100644 --- a/src/com/android/magicsmoke/RenderScriptWallpaper.java +++ b/src/com/android/magicsmoke/RenderScriptWallpaper.java @@ -18,6 +18,7 @@ package com.android.magicsmoke; import android.service.wallpaper.WallpaperService; +import android.os.Bundle; import android.renderscript.RenderScriptGL; import android.renderscript.RenderScript; import android.util.Log; @@ -39,7 +40,7 @@ public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends @Override public void onCreate(SurfaceHolder surfaceHolder) { super.onCreate(surfaceHolder); - setTouchEventsEnabled(true); + setTouchEventsEnabled(false); surfaceHolder.setSizeFromLayout(); } @@ -87,15 +88,15 @@ public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends } } - @Override + /*@Override public void onTouchEvent(MotionEvent event) { mRenderer.onTouchEvent(event); - } + }*/ @Override public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) { - mRenderer.setOffset(xOffset, yOffset, xStep, yStep, xPixels, yPixels); + mRenderer.setOffset(xOffset, yOffset, xPixels, yPixels); } @Override @@ -115,5 +116,12 @@ public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends super.onSurfaceDestroyed(holder); destroyRenderer(); } + + @Override + public Bundle onCommand(String action, int x, int y, int z, + Bundle extras, boolean resultRequested) { + return mRenderer.onCommand(action, x, y, z, extras, resultRequested); + } + } } diff --git a/src/com/android/magicsmoke/ScriptC_MagicSmoke.java b/src/com/android/magicsmoke/ScriptC_MagicSmoke.java new file mode 100644 index 0000000..7a6cd54 --- /dev/null +++ b/src/com/android/magicsmoke/ScriptC_MagicSmoke.java @@ -0,0 +1,203 @@ + +package com.android.magicsmoke; + +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; + +public class ScriptC_MagicSmoke + extends android.renderscript.ScriptC +{ + + public ScriptC_MagicSmoke(RenderScript rs, Resources resources, int id, boolean isRoot) { + super(rs, resources, id, isRoot); + } + + private float mField_gXOffset; + public void set_gXOffset(float v) { + mField_gXOffset = v; + setVar(0, v); + } + private float mField_gTilt; + public void set_gTilt(float v) { + mField_gTilt = v; + setVar(1, v); + } + private int mField_gPreset; + public void set_gPreset(int v) { + mField_gPreset = v; + setVar(2, v); + } + private int mField_gTextureMask; + public void set_gTextureMask(int v) { + mField_gTextureMask = v; + setVar(3, v); + } + private int mField_gRotate; + public void set_gRotate(int v) { + mField_gRotate = v; + setVar(4, v); + } + private int mField_gTextureSwap; + public void set_gTextureSwap(int v) { + mField_gTextureSwap = v; + setVar(5, v); + } + private int mField_gProcessTextureMode; + public void set_gProcessTextureMode(int v) { + mField_gProcessTextureMode = v; + setVar(6, v); + } + private int mField_gBackCol; + public void set_gBackCol(int v) { + mField_gBackCol = v; + setVar(7, v); + } + private int mField_gLowCol; + public void set_gLowCol(int v) { + mField_gLowCol = v; + setVar(8, v); + } + private int mField_gHighCol; + public void set_gHighCol(int v) { + mField_gHighCol = v; + setVar(9, v); + } + private float mField_gAlphaMul; + public void set_gAlphaMul(float v) { + mField_gAlphaMul = v; + setVar(10, v); + } + private int mField_gPreMul; + public void set_gPreMul(int v) { + mField_gPreMul = v; + setVar(11, v); + } + private int mField_gBlendFunc; + public void set_gBlendFunc(int v) { + mField_gBlendFunc = v; + setVar(12, v); + } + + private ProgramVertex mField_gPVBackground; + public void set_gPVBackground(ProgramVertex v) { + mField_gPVBackground = v; + setVar(13, v.getID()); + } + private ProgramFragment mField_gPFBackground; + public void set_gPFBackground(ProgramFragment v) { + mField_gPFBackground = v; + setVar(14, v.getID()); + } + private ProgramStore mField_gPFSBackgroundOne; + public void set_gPFSBackgroundOne(ProgramStore v) { + mField_gPFSBackgroundOne = v; + setVar(15, v.getID()); + } + private ProgramStore mField_gPFSBackgroundSrc; + public void set_gPFSBackgroundSrc(ProgramStore v) { + mField_gPFSBackgroundSrc = v; + setVar(16, v.getID()); + } + + private Allocation mField_gTnoise1; + public void set_gTnoise1(Allocation v) { + mField_gTnoise1 = v; + setVar(17, v.getID()); + } + private Allocation mField_gTnoise2; + public void set_gTnoise2(Allocation v) { + mField_gTnoise2 = v; + setVar(18, v.getID()); + } + private Allocation mField_gTnoise3; + public void set_gTnoise3(Allocation v) { + mField_gTnoise3 = v; + setVar(19, v.getID()); + } + private Allocation mField_gTnoise4; + public void set_gTnoise4(Allocation v) { + mField_gTnoise4 = v; + setVar(20, v.getID()); + } + private Allocation mField_gTnoise5; + public void set_gTnoise5(Allocation v) { + mField_gTnoise5 = v; + setVar(21, v.getID()); + } + + // Pointers + public void bind_gNoisesrc1(Allocation v) { + if (v == null) { + bindAllocation(null, 22); + } else { + bindAllocation(v, 22); + } + } + public void bind_gNoisesrc2(Allocation v) { + if (v == null) { + bindAllocation(null, 23); + } else { + bindAllocation(v, 23); + } + } + public void bind_gNoisesrc3(Allocation v) { + if (v == null) { + bindAllocation(null, 24); + } else { + bindAllocation(v, 24); + } + } + public void bind_gNoisesrc4(Allocation v) { + if (v == null) { + bindAllocation(null, 25); + } else { + bindAllocation(v, 25); + } + } + public void bind_gNoisesrc5(Allocation v) { + if (v == null) { + bindAllocation(null, 26); + } else { + bindAllocation(v, 26); + } + } + + public void bind_gNoisedst1(Allocation v) { + if (v == null) { + bindAllocation(null, 27); + } else { + bindAllocation(v, 27); + } + } + public void bind_gNoisedst2(Allocation v) { + if (v == null) { + bindAllocation(null, 28); + } else { + bindAllocation(v, 28); + } + } + public void bind_gNoisedst3(Allocation v) { + if (v == null) { + bindAllocation(null, 29); + } else { + bindAllocation(v, 29); + } + } + public void bind_gNoisedst4(Allocation v) { + if (v == null) { + bindAllocation(null, 30); + } else { + bindAllocation(v, 30); + } + } + public void bind_gNoisedst5(Allocation v) { + if (v == null) { + bindAllocation(null, 31); + } else { + bindAllocation(v, 31); + } + } + +} + |