diff options
Diffstat (limited to 'graphics')
4 files changed, 50 insertions, 185 deletions
diff --git a/graphics/java/android/graphics/utils/BoundaryPatch.java b/graphics/java/android/graphics/utils/BoundaryPatch.java deleted file mode 100644 index 1cd5e13..0000000 --- a/graphics/java/android/graphics/utils/BoundaryPatch.java +++ /dev/null @@ -1,173 +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. - */ - -package android.graphics.utils; - -import android.graphics.Bitmap; -import android.graphics.BitmapShader; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Shader; -import android.graphics.Xfermode; - -/** - * @hide - */ -public class BoundaryPatch { - private Paint mPaint; - private Bitmap mTexture; - private int mRows; - private int mCols; - private float[] mCubicPoints; - private boolean mDirty; - // these are the computed output of the native code - private float[] mVerts; - private short[] mIndices; - - public BoundaryPatch() { - mRows = mCols = 2; // default minimum - mCubicPoints = new float[24]; - mPaint = new Paint(); - mPaint.setDither(true); - mPaint.setFilterBitmap(true); - mDirty = true; - } - - /** - * Set the boundary to be 4 cubics. This takes a single array of floats, - * and picks up the 12 pairs starting at offset, and treats them as - * the x,y coordinates of the cubic control points. The points wrap around - * a patch, as follows. For documentation purposes, pts[i] will mean the - * x,y pair of floats, as if pts[] were an array of "points". - * - * Top: pts[0..3] - * Right: pts[3..6] - * Bottom: pts[6..9] - * Right: pts[9..11], pts[0] - * - * The coordinates are copied from the input array, so subsequent changes - * to pts[] will not be reflected in the boundary. - * - * @param pts The src array of x,y pairs for the boundary cubics - * @param offset The index into pts of the first pair - * @param rows The number of points across to approximate the boundary. - * Must be >= 2, though very large values may slow down drawing - * @param cols The number of points down to approximate the boundary. - * Must be >= 2, though very large values may slow down drawing - */ - public void setCubicBoundary(float[] pts, int offset, int rows, int cols) { - if (rows < 2 || cols < 2) { - throw new RuntimeException("rows and cols must be >= 2"); - } - System.arraycopy(pts, offset, mCubicPoints, 0, 24); - if (mRows != rows || mCols != cols) { - mRows = rows; - mCols = cols; - } - mDirty = true; - } - - /** - * Reference a bitmap texture to be mapped onto the patch. - */ - public void setTexture(Bitmap texture) { - if (mTexture != texture) { - if (mTexture == null || - mTexture.getWidth() != texture.getWidth() || - mTexture.getHeight() != texture.getHeight()) { - // need to recompute texture coordinates - mDirty = true; - } - mTexture = texture; - mPaint.setShader(new BitmapShader(texture, - Shader.TileMode.CLAMP, - Shader.TileMode.CLAMP)); - } - } - - /** - * Return the paint flags for the patch - */ - public int getPaintFlags() { - return mPaint.getFlags(); - } - - /** - * Set the paint flags for the patch - */ - public void setPaintFlags(int flags) { - mPaint.setFlags(flags); - } - - /** - * Set the xfermode for the patch - */ - public void setXfermode(Xfermode mode) { - mPaint.setXfermode(mode); - } - - /** - * Set the alpha for the patch - */ - public void setAlpha(int alpha) { - mPaint.setAlpha(alpha); - } - - /** - * Draw the patch onto the canvas. - * - * setCubicBoundary() and setTexture() must be called before drawing. - */ - public void draw(Canvas canvas) { - if (mDirty) { - buildCache(); - mDirty = false; - } - - // cut the count in half, since mVerts.length is really the length of - // the verts[] and tex[] arrays combined - // (tex[] are stored after verts[]) - int vertCount = mVerts.length >> 1; - canvas.drawVertices(Canvas.VertexMode.TRIANGLES, vertCount, - mVerts, 0, mVerts, vertCount, null, 0, - mIndices, 0, mIndices.length, - mPaint); - } - - private void buildCache() { - // we need mRows * mCols points, for verts and another set for textures - // so *2 for going from points -> floats, and *2 for verts and textures - int vertCount = mRows * mCols * 4; - if (mVerts == null || mVerts.length != vertCount) { - mVerts = new float[vertCount]; - } - - int indexCount = (mRows - 1) * (mCols - 1) * 6; - if (mIndices == null || mIndices.length != indexCount) { - mIndices = new short[indexCount]; - } - - nativeComputeCubicPatch(mCubicPoints, - mTexture.getWidth(), mTexture.getHeight(), - mRows, mCols, mVerts, mIndices); - } - - private static native - void nativeComputeCubicPatch(float[] cubicPoints, - int texW, int texH, int rows, int cols, - float[] verts, short[] indices); -} - diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 0f9ed87..97ce7dc 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -69,9 +69,22 @@ public class RenderScript { // Methods below are wrapped to protect the non-threadsafe // lockless fifo. - native int rsnContextCreateGL(int dev, int ver, boolean useDepth); - synchronized int nContextCreateGL(int dev, int ver, boolean useDepth) { - return rsnContextCreateGL(dev, ver, useDepth); + native int rsnContextCreateGL(int dev, int ver, + int colorMin, int colorPref, + int alphaMin, int alphaPref, + int depthMin, int depthPref, + int stencilMin, int stencilPref, + int samplesMin, int samplesPref, float samplesQ); + synchronized int nContextCreateGL(int dev, int ver, + int colorMin, int colorPref, + int alphaMin, int alphaPref, + int depthMin, int depthPref, + int stencilMin, int stencilPref, + int samplesMin, int samplesPref, float samplesQ) { + return rsnContextCreateGL(dev, ver, colorMin, colorPref, + alphaMin, alphaPref, depthMin, depthPref, + stencilMin, stencilPref, + samplesMin, samplesPref, samplesQ); } native int rsnContextCreate(int dev, int ver); synchronized int nContextCreate(int dev, int ver) { diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index b60c689..0477d75 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -18,6 +18,7 @@ package android.renderscript; import java.lang.reflect.Field; +import android.graphics.PixelFormat; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Config; @@ -103,7 +104,11 @@ public class RenderScriptGL extends RenderScript { SurfaceConfig mSurfaceConfig; public void configureSurface(SurfaceHolder sh) { - //getHolder().setFormat(PixelFormat.TRANSLUCENT); + if (mSurfaceConfig.mAlphaMin > 1) { + sh.setFormat(PixelFormat.RGBA_8888); + } else { + sh.setFormat(PixelFormat.RGBX_8888); + } } public void checkSurface(SurfaceHolder sh) { @@ -112,13 +117,17 @@ public class RenderScriptGL extends RenderScript { public RenderScriptGL(SurfaceConfig sc) { mSurfaceConfig = new SurfaceConfig(sc); - - mSurface = null; mWidth = 0; mHeight = 0; mDev = nDeviceCreate(); - mContext = nContextCreateGL(mDev, 0, mSurfaceConfig.mDepthMin > 0); + mContext = nContextCreateGL(mDev, 0, + mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref, + mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref, + mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref, + mSurfaceConfig.mStencilMin, mSurfaceConfig.mStencilPref, + mSurfaceConfig.mSamplesMin, mSurfaceConfig.mSamplesPref, + mSurfaceConfig.mSamplesQ); mMessageThread = new MessageThread(this); mMessageThread.start(); Element.initPredefined(this); diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 014f03b..ce2a40c 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -158,10 +158,26 @@ nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver) } static jint -nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jboolean useDepth) -{ +nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, + int colorMin, int colorPref, + int alphaMin, int alphaPref, + int depthMin, int depthPref, + int stencilMin, int stencilPref, + int samplesMin, int samplesPref, float samplesQ) +{ + RsSurfaceConfig sc; + sc.alphaMin = alphaMin; + sc.alphaPref = alphaPref; + sc.colorMin = colorMin; + sc.colorPref = colorPref; + sc.depthMin = depthMin; + sc.depthPref = depthPref; + sc.samplesMin = samplesMin; + sc.samplesPref = samplesPref; + sc.samplesQ = samplesQ; + LOG_API("nContextCreateGL"); - return (jint)rsContextCreateGL((RsDevice)dev, ver, useDepth); + return (jint)rsContextCreateGL((RsDevice)dev, ver, sc); } static void @@ -309,7 +325,7 @@ nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jint rsElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize); - for(jint i = 0; i < dataSize; i ++) { + for(jint i = 0; i < dataSize; i++) { _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); } @@ -1220,7 +1236,7 @@ static JNINativeMethod methods[] = { // All methods below are thread protected in java. {"rsnContextCreate", "(II)I", (void*)nContextCreate }, -{"rsnContextCreateGL", "(IIZ)I", (void*)nContextCreateGL }, +{"rsnContextCreateGL", "(IIIIIIIIIIIIF)I", (void*)nContextCreateGL }, {"rsnContextFinish", "(I)V", (void*)nContextFinish }, {"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, {"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface }, |