diff --git a/res/raw/allapps.rs b/res/raw/allapps.rs index 6f0046e96e..edbbcd8263 100644 --- a/res/raw/allapps.rs +++ b/res/raw/allapps.rs @@ -250,40 +250,6 @@ void updatePos() { g_PosPage = clampf(g_PosPage, -0.49, g_PosMax + 0.49); } -int positionStrip(float row, float column, int isTop, float p, int isText) -{ - float mat1[16]; - float x = 0.5f * (column - 1.5f); - float scale = 72.f * 3 / getWidth(); - - if (isTop) { - matrixLoadTranslate(mat1, x, 0.8f, 0.f); - matrixScale(mat1, scale, scale, 1.f); - } else { - matrixLoadTranslate(mat1, x, -0.9f, 0.f); - matrixScale(mat1, scale, -scale, 1.f); - } - matrixTranslate(mat1, 0, p * 2, 0.f); - matrixRotate(mat1, -p * 50, 1, 0, 0); - vpLoadModelMatrix(mat1); - - float soff = -(row * 1.4); - if (isTop) { - matrixLoadScale(mat1, 1.f, -0.85f, 1.f); - if (isText) { - matrixScale(mat1, 1.f, 2.f, 1.f); - } - matrixTranslate(mat1, 0, soff - 0.97f, 0); - } else { - matrixLoadScale(mat1, 1.f, 0.85f, 1.f); - if (isText) { - matrixScale(mat1, 1.f, 2.f, 1.f); - } - matrixTranslate(mat1, 0, soff - 0.45f, 0); - } - vpLoadTextureMatrix(mat1); - return -soff * 10.f; -} void draw_home_button() @@ -306,16 +272,16 @@ void drawFrontGrid(float rowOffset, float p) float rowFrac = rowOffset - intRowOffset; float colWidth = getWidth() / 4; float rowHeight = colWidth + 25.f; - float yoff = h - ((h - (rowHeight * 4.f)) / 2); - - yoff -= 110; + float yoff = 0.5f * h + 1.5f * rowHeight; int row, col; - int iconNum = intRowOffset * 4; - float ymax = yoff; - float ymin = yoff - (3 * rowHeight) - 70; + int iconNum = (intRowOffset - 5) * 4; - for (row = 0; row < 5; row++) { + bindProgramVertex(NAMED_PVCurve); + + storeF(ALLOC_VP_CONSTANTS, 4, p); + + for (row = -5; row < 15; row++) { float y = yoff - ((-rowFrac + row) * rowHeight); for (col=0; col < 4; col++) { @@ -324,103 +290,26 @@ void drawFrontGrid(float rowOffset, float p) } if (iconNum >= 0) { - float x = colWidth * col - ((128 - colWidth) / 2); + float x = colWidth * col + (colWidth / 2); - if ((y >= ymin) && (y <= ymax)) { - setColor(1.f, 1.f, 1.f, 1.f); - if (state->selectedIconIndex == iconNum && !p) { - bindTexture(NAMED_PFTexNearest, 0, state->selectedIconTexture); - drawSpriteScreenspace(x, y, 0, 128, 128); - } + storeF(ALLOC_VP_CONSTANTS, 0, 74.f); + storeF(ALLOC_VP_CONSTANTS, 1, 74.f); + storeF(ALLOC_VP_CONSTANTS, 2, x); + storeF(ALLOC_VP_CONSTANTS, 3, y); + bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum)); + drawSimpleMesh(NAMED_SMCell); - bindTexture(NAMED_PFTexNearest, 0, loadI32(ALLOC_ICON_IDS, iconNum)); - if (!p) { - drawSpriteScreenspace(x, y, 0, 128, 128); - } else { - float px = ((x + 64) - (getWidth() / 2)) / (getWidth() / 2); - float py = ((y + 64) - (getHeight() / 2)) / (getWidth() / 2); - float d = 64.f / (getWidth() / 2); - px *= p + 1; - py *= p + 1; - drawQuadTexCoords(px - d, py - d, -p, 0, 1, - px - d, py + d, -p, 0, 0, - px + d, py + d, -p, 1, 0, - px + d, py - d, -p, 1, 1); - } - } - - float y2 = y - 44; - if ((y2 >= ymin) && (y2 <= ymax)) { - float a = maxf(0, 1.f - p * 5.f); - setColor(1.f, 1.f, 1.f, a); - bindTexture(NAMED_PFTexNearest, 0, loadI32(ALLOC_LABEL_IDS, iconNum)); - drawSpriteScreenspace(x, y - 44, 0, - params->bubbleBitmapWidth, params->bubbleBitmapHeight); - } + storeF(ALLOC_VP_CONSTANTS, 0, 128.f); + storeF(ALLOC_VP_CONSTANTS, 1, 64.f); + storeF(ALLOC_VP_CONSTANTS, 3, y - 64.f); + bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_LABEL_IDS, iconNum)); + drawSimpleMesh(NAMED_SMCell); } iconNum++; } } } -void drawStrip(float row, float column, int isTop, int iconNum, float p) -{ - if (iconNum < 0) return; - int offset = positionStrip(row, column, isTop, p, 0); - bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum)); - if (offset < -20) return; - offset = clamp(offset, 0, 199 - 20); - drawSimpleMeshRange(NAMED_SMMesh, offset * 6, 20 * 6); - - if (isTop) { - offset = positionStrip(row - 0.72f, column, isTop, p, 1); - } else { - offset = positionStrip(row + 0.73f, column, isTop, p, 1); - } - if (offset < -20) return; - if (offset > 200) return; - bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_LABEL_IDS, iconNum)); - offset = clamp(offset, 0, 199 - 20); - drawSimpleMeshRange(NAMED_SMMesh, offset * 6, 20 * 6); - //drawSimpleMesh(NAMED_SMMesh); -} - -void drawTop(float rowOffset, float p) -{ - int row, col; - int iconNum = 0; - for (row = 0; row < rowOffset; row++) { - for (col=0; col < 4; col++) { - if (iconNum >= state->iconCount) { - return; - } - drawStrip(rowOffset - row, col, 1, iconNum, p); - iconNum++; - } - } -} - -void drawBottom(float rowOffset, float p) -{ - float pos = -1.f; - int intRowOffset = rowOffset; - pos -= rowOffset - intRowOffset; - - int row, col; - int iconNum = (intRowOffset + 3) * 4; - while (1) { - for (col=0; col < 4; col++) { - if (iconNum >= state->iconCount) { - return; - } - if (pos > -1) { - drawStrip(pos, col, 0, iconNum, p); - } - iconNum++; - } - pos += 1.f; - } -} int main(int launchID) @@ -483,29 +372,12 @@ main(int launchID) //debugF(" draw g_PosPage", g_PosPage); // Draw the icons ======================================== - - //bindProgramFragment(NAMED_PFColor); - //positionStrip(1, 0, 0); - //drawSimpleMesh(NAMED_SMMesh); - bindProgramFragment(NAMED_PFTexMip); - - - drawTop(g_PosPage, 1-g_Zoom); - drawBottom(g_PosPage, 1-g_Zoom); - - { - float mat1[16]; - matrixLoadIdentity(mat1); - vpLoadModelMatrix(mat1); - vpLoadTextureMatrix(mat1); - } + drawFrontGrid(g_PosPage, 1-g_Zoom); bindProgramFragment(NAMED_PFTexNearest); - drawFrontGrid(g_PosPage, 1-g_Zoom); draw_home_button(); - // This is a WAR to do a rendering pass without drawing during init to // force the driver to preload and compile its shaders. // Without this the first animation does not appear due to the time it diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java index 1d21da8926..20572766ef 100644 --- a/src/com/android/launcher2/AllAppsView.java +++ b/src/com/android/launcher2/AllAppsView.java @@ -128,6 +128,7 @@ public class AllAppsView extends RSSurfaceView public static final int ALLOC_STATE = 1; public static final int ALLOC_ICON_IDS = 3; public static final int ALLOC_LABEL_IDS = 4; + public static final int ALLOC_VP_CONSTANTS = 5; public static final int COLUMNS_PER_PAGE = 4; public static final int ROWS_PER_PAGE = 4; @@ -575,15 +576,18 @@ public class AllAppsView extends RSSurfaceView && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) { ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex); + Bitmap bmp = app.iconBitmap; + final int w = bmp.getWidth(); + final int h = bmp.getHeight(); + // We don't really have an accurate location to use. This will do. - int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2); - int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX; + int screenX = mMotionDownRawX - (w / 2); + int screenY = mMotionDownRawY - h; int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2; int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2; - mDragController.startDrag(app.iconBitmap, screenX, screenY, - left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX, - this, app, DragController.DRAG_ACTION_COPY); + mDragController.startDrag(bmp, screenX, screenY, + 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY); mLauncher.closeAllApps(true); } @@ -783,10 +787,12 @@ public class AllAppsView extends RSSurfaceView private ProgramFragment mPFTexNearest; private ProgramVertex mPV; private ProgramVertex mPVOrtho; + private ProgramVertex mPVCurve; private SimpleMesh mMesh; - private SimpleMesh mMesh2; private ProgramVertex.MatrixAllocation mPVA; + private Allocation mUniformAlloc; + private Allocation mHomeButtonNormal; private Allocation mHomeButtonFocused; private Allocation mHomeButtonPressed; @@ -869,49 +875,27 @@ public class AllAppsView extends RSSurfaceView initProgramVertex(); initProgramFragment(); initProgramStore(); - initMesh(); + //initMesh(); initGl(); initData(); initTouchState(); initRs(); } - public void initMesh() { - SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3, - SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR); + public void initMesh2() { + SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 2, 0); - float y = 0; - float z = 0; - for (int ct=0; ct < 200; ct++) { - float angle = 0; - float maxAngle = 3.14f * 0.16f; - float l = 1.f; - - l = 1 - ((ct-5) * 0.10f); - if (ct > 7) { - angle = maxAngle * (ct - 7) * 0.2f; - angle = Math.min(angle, maxAngle); - } - l = Math.max(0.4f, l); - l = Math.min(1.0f, l); - - y += 0.1f * Math.cos(angle); - z += 0.1f * Math.sin(angle); - - float t = 0.1f * ct; - float ds = 0.08f; - tm.setColor(l, l, l, 0.99f); - tm.setTexture(ds, t); - tm.addVertex(-0.5f, y, z); - tm.setTexture(1 - ds, t); - tm.addVertex(0.5f, y, z); + for (int ct=0; ct < 16; ct++) { + float pos = (1.f / 16.f) * ct; + tm.addVertex(0.0f, pos); + tm.addVertex(1.0f, pos); } - for (int ct=0; ct < (200 * 2 - 2); ct+= 2) { + for (int ct=0; ct < (16 * 2 - 2); ct+= 2) { tm.addTriangle(ct, ct+1, ct+2); tm.addTriangle(ct+1, ct+3, ct+2); } - mMesh2 = tm.create(); - mMesh2.setName("SMMesh"); + mMesh = tm.create(); + mMesh.setName("SMCell"); } void resize(int w, int h) { @@ -930,6 +914,72 @@ public class AllAppsView extends RSSurfaceView mPV.setName("PV"); mPV.bindAllocation(mPVA); + Element.Builder eb = new Element.Builder(mRS); + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 2), "ImgSize"); + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Position"); + Element e = eb.create(); + + mUniformAlloc = Allocation.createSized(mRS, e, 1); + + initMesh2(); + ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS); + String t = new String("void main() {\n" + + // Animation + " float ani = UNI_Position.z;\n" + + + " float scale = (2.0 / 480.0);\n" + + " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" + + " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" + + " float y = 0.0;\n" + + " float z = 0.0;\n" + + " float lum = 1.0;\n" + + + " float cv = min(ys, 50.0) - 50.0;\n" + + " y += cv * 0.681;\n" + // Roughy 47 degrees + " z += -cv * 0.731;\n" + + " cv = clamp(ys, 50.0, 120.0) - 120.0;\n" + // curve range + " y += cv * cos(cv * 0.4 / (180.0 / 3.14));\n" + + " z += cv * sin(cv * 0.4 / (180.0 / 3.14));\n" + + + " cv = max(ys, 750.0) - 750.0;\n" + + " y += cv * 0.681;\n" + + " z += cv * 0.731;\n" + + " cv = clamp(ys, 680.0, 750.0) - 680.0;\n" + + " y += cv * cos(cv * 0.4 / (180.0 / 3.14));\n" + + " z += cv * sin(cv * 0.4 / (180.0 / 3.14));\n" + + + " y += clamp(ys, 120.0, 680.0);\n" + + " lum += (clamp(ys, 60.0, 115.0) - 115.0) / 100.0;\n" + + " lum -= (clamp(ys, 685.0, 740.0) - 685.0) / 100.0;\n" + + + " vec4 pos;\n" + + " pos.x = x * scale - 1.0;\n" + + " pos.y = y * scale - 1.66;\n" + + " pos.z = z * scale;\n" + + " pos.w = 1.0;\n" + + + " pos.x *= 1.0 + ani * 4.0;\n" + + " pos.y *= 1.0 + ani * 4.0;\n" + + " pos.z -= ani * 1.5;\n" + + " lum *= 1.0 - ani;\n" + + + " gl_Position = UNI_MVP * pos;\n" + + " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" + + " varTex0.xy = ATTRIB_position;\n" + + " varTex0.y = 1.0 - varTex0.y;\n" + + " varTex0.zw = vec2(0.0, 0.0);\n" + + "}\n"); + sb.setShader(t); + sb.addConstant(mUniformAlloc.getType()); + sb.addInput(mMesh.getVertexType(0).getElement()); + mPVCurve = sb.create(); + mPVCurve.setName("PVCurve"); + mPVCurve.bindAllocation(mPVA); + mPVCurve.bindConstants(mUniformAlloc, 1); + + float tf[] = new float[] {72.f, 72.f, 0.f, 0.f, 120.f, 120.f, 0.f, 0.f}; + mUniformAlloc.data(tf); + //pva = new ProgramVertex.MatrixAllocation(mRS); //pva.setupOrthoWindow(mWidth, mHeight); //pvb.setTextureMatrixEnable(true); @@ -943,7 +993,7 @@ public class AllAppsView extends RSSurfaceView private void initProgramFragment() { Sampler.Builder sb = new Sampler.Builder(mRS); sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR); - sb.setMag(Sampler.Value.LINEAR); + sb.setMag(Sampler.Value.NEAREST); sb.setWrapS(Sampler.Value.CLAMP); sb.setWrapT(Sampler.Value.CLAMP); Sampler linear = sb.create(); @@ -956,7 +1006,7 @@ public class AllAppsView extends RSSurfaceView //mPFColor = bf.create(); //mPFColor.setName("PFColor"); - bf.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, + bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, ProgramFragment.Builder.Format.RGBA, 0); mPFTexMip = bf.create(); mPFTexMip.setName("PFTexMip"); @@ -1034,6 +1084,7 @@ public class AllAppsView extends RSSurfaceView sb.addDefines(mDefines); sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS); sb.setType(mState.mType, "state", Defines.ALLOC_STATE); + sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS); mInvokeMove = sb.addInvokable("move"); mInvokeFling = sb.addInvokable("fling"); mInvokeMoveTo = sb.addInvokable("moveTo"); @@ -1045,6 +1096,7 @@ public class AllAppsView extends RSSurfaceView mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); + mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS); mRS.contextBindRootScript(mScript); } @@ -1096,34 +1148,11 @@ public class AllAppsView extends RSSurfaceView } } - private void frameBitmapAllocMips(Allocation alloc, int w, int h) { - int black[] = new int[w > h ? w : h]; - Allocation.Adapter2D a = alloc.createAdapter2D(); - int mip = 0; - while (w > 1 || h > 1) { - a.subData(0, 0, 1, h, black); - a.subData(w-1, 0, 1, h, black); - a.subData(0, 0, w, 1, black); - a.subData(0, h-1, w, 1, black); - mip++; - w = (w + 1) >> 1; - h = (h + 1) >> 1; - a.setConstraint(Dimension.LOD, mip); - } - a.subData(0, 0, 1, 1, black); - } - private void createAppIconAllocations(int index, ApplicationInfo item) { mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap, Element.RGBA_8888(mRS), true); - frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(), - item.iconBitmap.getHeight()); - mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap, Element.RGBA_8888(mRS), true); - frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(), - item.titleBitmap.getHeight()); - mIconIds[index] = mIcons[index].getID(); mLabelIds[index] = mLabels[index].getID(); } diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java index 55cb509bcd..507096cff2 100644 --- a/src/com/android/launcher2/Utilities.java +++ b/src/com/android/launcher2/Utilities.java @@ -257,7 +257,7 @@ final class Utilities { } dest.drawColor(0, PorterDuff.Mode.CLEAR); - + int[] xy = new int[2]; Bitmap mask = src.extractAlpha(sBlurPaint, xy); @@ -296,13 +296,13 @@ final class Utilities { if (width > 0 && height > 0) { if (width < bitmapWidth || height < bitmapHeight) { final float ratio = (float) bitmapWidth / bitmapHeight; - + if (bitmapWidth > bitmapHeight) { height = (int) (width / ratio); } else if (bitmapHeight > bitmapWidth) { width = (int) (height * ratio); } - + final Bitmap.Config c = (width == sIconWidth && height == sIconHeight) ? bitmap.getConfig() : Bitmap.Config.ARGB_8888; final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c); @@ -339,7 +339,7 @@ final class Utilities { final float density = metrics.density; sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size); - sIconTextureWidth = sIconTextureHeight = roundToPow2(sIconWidth); + sIconTextureWidth = sIconTextureHeight = sIconWidth + 2; sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL)); sGlowColorPressedPaint.setColor(0xffffc300);