Skip to content

Commit 79235d2

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "adding getters to Sampler ProgramRaster, ProgramStore, Element. Element adds ability to get subelement info. Tests for new stuff."
2 parents 5b6f238 + 7d5f5e7 commit 79235d2

File tree

12 files changed

+514
-64
lines changed

12 files changed

+514
-64
lines changed

graphics/java/android/renderscript/Element.java

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ public class Element extends BaseObj {
4646
Element[] mElements;
4747
String[] mElementNames;
4848
int[] mArraySizes;
49+
int[] mOffsetInBytes;
4950

5051
DataType mType;
5152
DataKind mKind;
5253
boolean mNormalized;
5354
int mVectorSize;
5455

55-
int getSizeBytes() {return mSize;}
56+
/**
57+
* @hide
58+
* @return element size in bytes
59+
*/
60+
public int getSizeBytes() {return mSize;}
5661

5762

5863
/**
@@ -151,6 +156,77 @@ public boolean isComplex() {
151156
return false;
152157
}
153158

159+
/**
160+
* @hide
161+
* @return number of sub-elements in this element
162+
*/
163+
public int getSubElementCount() {
164+
if (mElements == null) {
165+
return 0;
166+
}
167+
return mElements.length;
168+
}
169+
170+
/**
171+
* @hide
172+
* @param index index of the sub-element to return
173+
* @return sub-element in this element at given index
174+
*/
175+
public Element getSubElement(int index) {
176+
if (mElements == null) {
177+
throw new RSIllegalArgumentException("Element contains no sub-elements");
178+
}
179+
if (index < 0 || index >= mElements.length) {
180+
throw new RSIllegalArgumentException("Illegal sub-element index");
181+
}
182+
return mElements[index];
183+
}
184+
185+
/**
186+
* @hide
187+
* @param index index of the sub-element
188+
* @return sub-element in this element at given index
189+
*/
190+
public String getSubElementName(int index) {
191+
if (mElements == null) {
192+
throw new RSIllegalArgumentException("Element contains no sub-elements");
193+
}
194+
if (index < 0 || index >= mElements.length) {
195+
throw new RSIllegalArgumentException("Illegal sub-element index");
196+
}
197+
return mElementNames[index];
198+
}
199+
200+
/**
201+
* @hide
202+
* @param index index of the sub-element
203+
* @return array size of sub-element in this element at given index
204+
*/
205+
public int getSubElementArraySize(int index) {
206+
if (mElements == null) {
207+
throw new RSIllegalArgumentException("Element contains no sub-elements");
208+
}
209+
if (index < 0 || index >= mElements.length) {
210+
throw new RSIllegalArgumentException("Illegal sub-element index");
211+
}
212+
return mArraySizes[index];
213+
}
214+
215+
/**
216+
* @hide
217+
* @param index index of the sub-element
218+
* @return offset in bytes of sub-element in this element at given index
219+
*/
220+
public int getSubElementOffsetBytes(int index) {
221+
if (mElements == null) {
222+
throw new RSIllegalArgumentException("Element contains no sub-elements");
223+
}
224+
if (index < 0 || index >= mElements.length) {
225+
throw new RSIllegalArgumentException("Illegal sub-element index");
226+
}
227+
return mOffsetInBytes[index];
228+
}
229+
154230
/**
155231
* Utility function for returning an Element containing a single Boolean.
156232
*
@@ -602,7 +678,9 @@ public static Element MATRIX_2X2(RenderScript rs) {
602678
mElements = e;
603679
mElementNames = n;
604680
mArraySizes = as;
681+
mOffsetInBytes = new int[mElements.length];
605682
for (int ct = 0; ct < mElements.length; ct++ ) {
683+
mOffsetInBytes[ct] = mSize;
606684
mSize += mElements[ct].mSize * mArraySizes[ct];
607685
}
608686
}
@@ -653,13 +731,16 @@ void updateFromNative() {
653731
if(numSubElements > 0) {
654732
mElements = new Element[numSubElements];
655733
mElementNames = new String[numSubElements];
734+
mArraySizes = new int[numSubElements];
735+
mOffsetInBytes = new int[numSubElements];
656736

657737
int[] subElementIds = new int[numSubElements];
658-
mRS.nElementGetSubElements(getID(), subElementIds, mElementNames);
738+
mRS.nElementGetSubElements(getID(), subElementIds, mElementNames, mArraySizes);
659739
for(int i = 0; i < numSubElements; i ++) {
660740
mElements[i] = new Element(subElementIds[i], mRS);
661741
mElements[i].updateFromNative();
662-
mSize += mElements[i].mSize;
742+
mOffsetInBytes[i] = mSize;
743+
mSize += mElements[i].mSize * mArraySizes[i];
663744
}
664745
}
665746

graphics/java/android/renderscript/ProgramRaster.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,32 @@ public enum CullMode {
3737
}
3838
}
3939

40-
boolean mPointSmooth;
41-
boolean mLineSmooth;
4240
boolean mPointSprite;
43-
float mLineWidth;
4441
CullMode mCullMode;
4542

4643
ProgramRaster(int id, RenderScript rs) {
4744
super(id, rs);
4845

49-
mLineWidth = 1.0f;
50-
mPointSmooth = false;
51-
mLineSmooth = false;
5246
mPointSprite = false;
53-
5447
mCullMode = CullMode.BACK;
5548
}
5649

50+
/**
51+
* @hide
52+
* @return whether point sprites are enabled
53+
*/
54+
public boolean getPointSpriteEnabled() {
55+
return mPointSprite;
56+
}
57+
58+
/**
59+
* @hide
60+
* @return cull mode
61+
*/
62+
public CullMode getCullMode() {
63+
return mCullMode;
64+
}
65+
5766
public static ProgramRaster CULL_BACK(RenderScript rs) {
5867
if(rs.mProgramRaster_CULL_BACK == null) {
5968
ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
@@ -105,7 +114,10 @@ public Builder setCullMode(CullMode m) {
105114
public ProgramRaster create() {
106115
mRS.validate();
107116
int id = mRS.nProgramRasterCreate(mPointSprite, mCullMode.mID);
108-
return new ProgramRaster(id, mRS);
117+
ProgramRaster programRaster = new ProgramRaster(id, mRS);
118+
programRaster.mPointSprite = mPointSprite;
119+
programRaster.mCullMode = mCullMode;
120+
return programRaster;
109121
}
110122
}
111123

graphics/java/android/renderscript/ProgramStore.java

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,92 @@ public enum BlendDstFunc {
135135
}
136136
}
137137

138+
DepthFunc mDepthFunc;
139+
boolean mDepthMask;
140+
boolean mColorMaskR;
141+
boolean mColorMaskG;
142+
boolean mColorMaskB;
143+
boolean mColorMaskA;
144+
BlendSrcFunc mBlendSrc;
145+
BlendDstFunc mBlendDst;
146+
boolean mDither;
138147

139148
ProgramStore(int id, RenderScript rs) {
140149
super(id, rs);
141150
}
142151

152+
/**
153+
* @hide
154+
* @return depth function
155+
*/
156+
public DepthFunc getDepthFunc() {
157+
return mDepthFunc;
158+
}
159+
160+
/**
161+
* @hide
162+
* @return whether depth writes are enabled
163+
*/
164+
public boolean getDepthMaskEnabled() {
165+
return mDepthMask;
166+
}
167+
168+
/**
169+
* @hide
170+
* @return red color channel mask
171+
*/
172+
public boolean getColorMaskREnabled() {
173+
return mColorMaskR;
174+
}
175+
176+
/**
177+
* @hide
178+
* @return green color channel mask
179+
*/
180+
public boolean getColorMaskGEnabled() {
181+
return mColorMaskG;
182+
}
183+
184+
/**
185+
* @hide
186+
* @return blue color channel mask
187+
*/
188+
public boolean getColorMaskBEnabled() {
189+
return mColorMaskB;
190+
}
191+
192+
/**
193+
* @hide
194+
* @return alpha channel mask
195+
*/
196+
public boolean getColorMaskAEnabled() {
197+
return mColorMaskA;
198+
}
199+
200+
/**
201+
* @hide
202+
* @return source blend function
203+
*/
204+
public BlendSrcFunc getBlendSrcFunc() {
205+
return mBlendSrc;
206+
}
207+
208+
/**
209+
* @hide
210+
* @return destination blend function
211+
*/
212+
public BlendDstFunc getBlendDstFunc() {
213+
return mBlendDst;
214+
}
215+
216+
/**
217+
* @hide
218+
* @return whether dither is enabled
219+
*/
220+
public boolean getDitherEnabled() {
221+
return mDither;
222+
}
223+
143224
/**
144225
* Returns a pre-defined program store object with the following
145226
* characteristics:
@@ -340,7 +421,17 @@ public ProgramStore create() {
340421
int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
341422
mDepthMask, mDither,
342423
mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
343-
return new ProgramStore(id, mRS);
424+
ProgramStore programStore = new ProgramStore(id, mRS);
425+
programStore.mDepthFunc = mDepthFunc;
426+
programStore.mDepthMask = mDepthMask;
427+
programStore.mColorMaskR = mColorMaskR;
428+
programStore.mColorMaskG = mColorMaskG;
429+
programStore.mColorMaskB = mColorMaskB;
430+
programStore.mColorMaskA = mColorMaskA;
431+
programStore.mBlendSrc = mBlendSrc;
432+
programStore.mBlendDst = mBlendDst;
433+
programStore.mDither = mDither;
434+
return programStore;
344435
}
345436
}
346437

graphics/java/android/renderscript/RenderScript.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ synchronized void nElementGetNativeData(int id, int[] elementData) {
210210
validate();
211211
rsnElementGetNativeData(mContext, id, elementData);
212212
}
213-
native void rsnElementGetSubElements(int con, int id, int[] IDs, String[] names);
214-
synchronized void nElementGetSubElements(int id, int[] IDs, String[] names) {
213+
native void rsnElementGetSubElements(int con, int id,
214+
int[] IDs, String[] names, int[] arraySizes);
215+
synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
215216
validate();
216-
rsnElementGetSubElements(mContext, id, IDs, names);
217+
rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
217218
}
218219

219220
native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces);

graphics/java/android/renderscript/Sampler.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,57 @@ public enum Value {
4747
}
4848
}
4949

50+
Value mMin;
51+
Value mMag;
52+
Value mWrapS;
53+
Value mWrapT;
54+
Value mWrapR;
55+
float mAniso;
56+
5057
Sampler(int id, RenderScript rs) {
5158
super(id, rs);
5259
}
5360

61+
/**
62+
* @hide
63+
* @return minification setting for the sampler
64+
*/
65+
public Value getMinification() {
66+
return mMin;
67+
}
68+
69+
/**
70+
* @hide
71+
* @return magnification setting for the sampler
72+
*/
73+
public Value getMagnification() {
74+
return mMag;
75+
}
76+
77+
/**
78+
* @hide
79+
* @return S wrapping mode for the sampler
80+
*/
81+
public Value getWrapS() {
82+
return mWrapS;
83+
}
84+
85+
/**
86+
* @hide
87+
* @return T wrapping mode for the sampler
88+
*/
89+
public Value getWrapT() {
90+
return mWrapT;
91+
}
92+
93+
/**
94+
* @hide
95+
* @return anisotropy setting for the sampler
96+
*/
97+
public float getAnisotropy() {
98+
return mAniso;
99+
}
100+
54101
/**
55102
* Retrieve a sampler with min and mag set to nearest and wrap modes set to
56103
* clamp.
@@ -241,8 +288,16 @@ public void setAnisotropy(float v) {
241288

242289
public Sampler create() {
243290
mRS.validate();
244-
int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
245-
return new Sampler(id, mRS);
291+
int id = mRS.nSamplerCreate(mMag.mID, mMin.mID,
292+
mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
293+
Sampler sampler = new Sampler(id, mRS);
294+
sampler.mMin = mMin;
295+
sampler.mMag = mMag;
296+
sampler.mWrapS = mWrapS;
297+
sampler.mWrapT = mWrapT;
298+
sampler.mWrapR = mWrapR;
299+
sampler.mAniso = mAniso;
300+
return sampler;
246301
}
247302
}
248303

0 commit comments

Comments
 (0)