diff options
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state')
32 files changed, 0 insertions, 4407 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/DisplayRadix.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/DisplayRadix.java deleted file mode 100644 index 935f4d79c..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/DisplayRadix.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2014 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 com.android.ide.eclipse.gltrace.state; - -public enum DisplayRadix { - DECIMAL, HEX -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLAbstractAtomicProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLAbstractAtomicProperty.java deleted file mode 100644 index cb96312b8..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLAbstractAtomicProperty.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - - -/** - * Abstract implementation of {@link IGLProperty}. This provides the basics that can be - * used by leaf level properties. - */ -public abstract class GLAbstractAtomicProperty implements IGLProperty { - private final GLStateType mType; - private IGLProperty mParent; - - public GLAbstractAtomicProperty(GLStateType type) { - mType = type; - } - - @Override - public GLStateType getType() { - return mType; - } - - @Override - public IGLProperty getParent() { - return mParent; - } - - @Override - public void setParent(IGLProperty parent) { - mParent = parent; - } - - @Override - public boolean isComposite() { - return false; - } - - @Override - public IGLProperty clone() { - try { - return (IGLProperty) super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } - } - - @Override - public void prettyPrint(StatePrettyPrinter pp) { - pp.prettyPrint(mType, getStringValue()); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLBooleanProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLBooleanProperty.java deleted file mode 100644 index 8332b0a65..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLBooleanProperty.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - - -/** Properties that hold boolean values. */ -public final class GLBooleanProperty extends GLAbstractAtomicProperty { - private final Boolean mDefaultValue; - private Boolean mCurrentValue; - - public GLBooleanProperty(GLStateType name, Boolean defaultValue) { - super(name); - - mDefaultValue = mCurrentValue = defaultValue; - } - - @Override - public boolean isDefault() { - return mDefaultValue != null & mDefaultValue.equals(mCurrentValue); - } - - public void setValue(Boolean newValue) { - mCurrentValue = newValue; - } - - @Override - public String getStringValue() { - return mCurrentValue.toString(); - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - } - - @Override - public void setValue(Object value) { - if (value instanceof Boolean) { - mCurrentValue = (Boolean) value; - } else { - throw new IllegalArgumentException("Attempt to set non-boolean value for " //$NON-NLS-1$ - + getType()); - } - } - - @Override - public Object getValue() { - return mCurrentValue; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLCompositeProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLCompositeProperty.java deleted file mode 100644 index ff8b83a86..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLCompositeProperty.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - -import java.util.Collection; -import java.util.EnumMap; -import java.util.Map; - -/** - * A composite property is a container for multiple named properties, kind of like a dictionary. - */ -public class GLCompositeProperty implements IGLProperty { - private final GLStateType mType; - private final Map<GLStateType, IGLProperty> mPropertiesMap; - private IGLProperty mParent; - - /** Construct a composite property given a list of {@link IGLProperty} objects. */ - public GLCompositeProperty(GLStateType type, IGLProperty... iglProperties) { - mType = type; - mPropertiesMap = new EnumMap<GLStateType, IGLProperty>(GLStateType.class); - - for (IGLProperty p : iglProperties) { - mPropertiesMap.put(p.getType(), p); - p.setParent(this); - } - } - - public Collection<IGLProperty> getProperties() { - return mPropertiesMap.values(); - } - - public IGLProperty getProperty(GLStateType name) { - return mPropertiesMap.get(name); - } - - @Override - public GLCompositeProperty clone() { - IGLProperty []props = new IGLProperty[mPropertiesMap.size()]; - - int i = 0; - for (IGLProperty p : mPropertiesMap.values()) { - props[i++] = p.clone(); - } - - return new GLCompositeProperty(getType(), props); - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("GLCompositeProperty {"); //$NON-NLS-1$ - - for (IGLProperty p : mPropertiesMap.values()) { - sb.append(p.toString()); - sb.append(", "); //$NON-NLS-1$ - } - - sb.append("}"); - return sb.toString(); - } - - @Override - public String getStringValue() { - // This method is called for displaying objects in the UI. - // We do not display any values for composites in the UI as they are only intermediate - // nodes in the tree. - return ""; - } - - @Override - public GLStateType getType() { - return mType; - } - - @Override - public boolean isComposite() { - return true; - } - - @Override - public boolean isDefault() { - for (IGLProperty p : mPropertiesMap.values()) { - if (!p.isDefault()) { - return false; - } - } - - return true; - } - - @Override - public IGLProperty getParent() { - return mParent; - } - - @Override - public void setParent(IGLProperty parent) { - mParent = parent; - } - - @Override - public void setValue(Object value) { - throw new UnsupportedOperationException( - "Values cannot be set for composite properties."); //$NON-NLS-1$ - } - - @Override - public Object getValue() { - throw new UnsupportedOperationException( - "Values cannot be obtained for composite properties."); //$NON-NLS-1$ - } - - @Override - public void prettyPrint(StatePrettyPrinter pp) { - pp.prettyPrint(mType, null); - pp.incrementIndentLevel(); - for (IGLProperty p : mPropertiesMap.values()) { - p.prettyPrint(pp); - } - pp.decrementIndentLevel(); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLEnumProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLEnumProperty.java deleted file mode 100644 index a3acbd4c8..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLEnumProperty.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - -import com.android.ide.eclipse.gltrace.GLEnum; - -/** Properties that hold a {@link GLEnum}. */ -public final class GLEnumProperty extends GLAbstractAtomicProperty { - private GLEnum mCurrentValue; - private final GLEnum mDefaultValue; - - public GLEnumProperty(GLStateType name, GLEnum defaultValue) { - super(name); - - mCurrentValue = mDefaultValue = defaultValue; - } - - @Override - public boolean isDefault() { - return mDefaultValue == mCurrentValue; - } - - public void setValue(GLEnum newValue) { - mCurrentValue = newValue; - } - - @Override - public String getStringValue() { - return mCurrentValue.toString(); - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - } - - @Override - public void setValue(Object value) { - if (value instanceof GLEnum) { - mCurrentValue = (GLEnum) value; - } else { - throw new IllegalArgumentException("Attempt to set invalid value for " + getType()); //$NON-NLS-1$ - } - } - - @Override - public Object getValue() { - return mCurrentValue; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLFloatProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLFloatProperty.java deleted file mode 100644 index 387a88c6d..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLFloatProperty.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state; - -/** Properties that hold float values. */ -public class GLFloatProperty extends GLAbstractAtomicProperty { - private final Float mDefaultValue; - private Float mCurrentValue; - - public GLFloatProperty(GLStateType name, Float defaultValue) { - super(name); - - mDefaultValue = mCurrentValue = defaultValue; - } - - @Override - public boolean isDefault() { - return Math.abs(mCurrentValue - mDefaultValue) < 0.000000001; - } - - public void setValue(Float newValue) { - mCurrentValue = newValue; - } - - @Override - public void setValue(Object value) { - if (value instanceof Float) { - mCurrentValue = (Float) value; - } else { - throw new IllegalArgumentException("Attempt to set non float value for " - + getType()); - } - } - - @Override - public Object getValue() { - return mCurrentValue; - } - - @Override - public String getStringValue() { - return mCurrentValue.toString(); - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLIntegerProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLIntegerProperty.java deleted file mode 100644 index 7374ff087..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLIntegerProperty.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - -/** Properties that hold an integer value. */ -public class GLIntegerProperty extends GLAbstractAtomicProperty { - private final Integer mDefaultValue; - private Integer mCurrentValue; - private final DisplayRadix mRadix; - - public GLIntegerProperty(GLStateType name, Integer defaultValue, DisplayRadix radix) { - super(name); - - mDefaultValue = mCurrentValue = defaultValue; - mRadix = radix; - } - - public GLIntegerProperty(GLStateType name, Integer defaultValue) { - this(name, defaultValue, DisplayRadix.DECIMAL); - } - - @Override - public boolean isDefault() { - return mDefaultValue != null & mDefaultValue.equals(mCurrentValue); - } - - public void setValue(Integer newValue) { - mCurrentValue = newValue; - } - - @Override - public String getStringValue() { - if (mRadix == DisplayRadix.HEX) { - return String.format("0x%08x", Integer.valueOf(mCurrentValue)); - } - - return mCurrentValue.toString(); - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - } - - @Override - public void setValue(Object value) { - if (value instanceof Integer) { - mCurrentValue = (Integer) value; - } else { - throw new IllegalArgumentException("Attempt to set non-integer value for " //$NON-NLS-1$ - + getType()); - } - } - - @Override - public Object getValue() { - return mCurrentValue; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLListProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLListProperty.java deleted file mode 100644 index 6840abff4..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLListProperty.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -/** - * A list property is a container for a list of properties, addressed by index. - */ -public class GLListProperty implements IGLProperty { - private final List<IGLProperty> mList; - private final GLStateType mType; - private IGLProperty mParent; - private IGLProperty mTemplate; - - /** - * Construct a list of properties of given size from the provided template. - * @param template property that will be cloned and used as members of the list - * @param size size of the list - */ - public GLListProperty(GLStateType type, IGLProperty template, int size) { - mType = type; - mTemplate = template; - - mList = new ArrayList<IGLProperty>(size); - for (int i = 0; i < size; i++) { - IGLProperty p = template.clone(); - mList.add(p); - - p.setParent(this); - } - } - - private GLListProperty(GLStateType type, List<IGLProperty> props) { - mList = props; - mType = type; - - for (IGLProperty p : mList) { - p.setParent(this); - } - } - - public List<IGLProperty> getList() { - return mList; - } - - public IGLProperty get(int index) { - return mList.get(index); - } - - public boolean add(IGLProperty property) { - property.setParent(this); - return mList.add(property); - } - - public boolean remove(IGLProperty property) { - return mList.remove(property); - } - - public void set(int index, IGLProperty property) { - ensureCapacity(index + 1); - mList.set(index, property); - property.setParent(this); - } - - private void ensureCapacity(int capactiy) { - for (int i = mList.size(); i < capactiy; i++) { - mList.add(mTemplate); - } - } - - @Override - public GLListProperty clone() { - List<IGLProperty> props = new ArrayList<IGLProperty>( - mList.size()); - - for (IGLProperty p : mList) { - props.add(p.clone()); - } - - return new GLListProperty(getType(), props); - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("GLListProperty ["); //$NON-NLS-1$ - - int i = 0; - for (IGLProperty p : mList) { - sb.append(i); - sb.append(':'); - sb.append(p.toString()); - sb.append(", "); //$NON-NLS-1$ - i++; - } - - sb.append("]"); - return sb.toString(); - } - - @Override - public String getStringValue() { - // This method is called for displaying objects in the UI. - // We do not display any values for composites in the UI as they are only intermediate - // nodes in the tree. - return ""; - } - - @Override - public GLStateType getType() { - return mType; - } - - @Override - public boolean isComposite() { - return true; - } - - @Override - public boolean isDefault() { - return false; - } - - @Override - public IGLProperty getParent() { - return mParent; - } - - @Override - public void setParent(IGLProperty parent) { - mParent = parent; - } - - public int indexOf(IGLProperty property) { - return mList.indexOf(property); - } - - @Override - public void setValue(Object value) { - throw new UnsupportedOperationException( - "Values cannot be set for composite properties."); //$NON-NLS-1$ - } - - @Override - public Object getValue() { - throw new UnsupportedOperationException( - "Values cannot be obtained for composite properties."); //$NON-NLS-1$ - } - - public int size() { - return mList.size(); - } - - @Override - public void prettyPrint(StatePrettyPrinter pp) { - pp.prettyPrint(mType, null); - pp.incrementIndentLevel(); - for (int i = 0; i < mList.size(); i++) { - pp.prettyPrint(String.format(Locale.US, "Index %d:", i)); - IGLProperty p = mList.get(i); - p.prettyPrint(pp); - } - pp.decrementIndentLevel(); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLLongProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLLongProperty.java deleted file mode 100644 index 44c04ec57..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLLongProperty.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2014 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 com.android.ide.eclipse.gltrace.state; - -/** Properties that hold a long value. */ -public class GLLongProperty extends GLAbstractAtomicProperty { - private final Long mDefaultValue; - private Long mCurrentValue; - private final DisplayRadix mRadix; - - public GLLongProperty(GLStateType name, Long defaultValue, DisplayRadix radix) { - super(name); - - mDefaultValue = mCurrentValue = defaultValue; - mRadix = radix; - } - - public GLLongProperty(GLStateType name, Long defaultValue) { - this(name, defaultValue, DisplayRadix.DECIMAL); - } - - @Override - public boolean isDefault() { - return mDefaultValue != null & mDefaultValue.equals(mCurrentValue); - } - - public void setValue(Long newValue) { - mCurrentValue = newValue; - } - - @Override - public String getStringValue() { - if (mRadix == DisplayRadix.HEX) { - return String.format("0x%08x", Long.valueOf(mCurrentValue)); - } - - return mCurrentValue.toString(); - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - } - - @Override - public void setValue(Object value) { - if (value instanceof Long) { - mCurrentValue = (Long) value; - } else { - throw new IllegalArgumentException("Attempt to set non-integer value for " //$NON-NLS-1$ - + getType()); - } - } - - @Override - public Object getValue() { - return mCurrentValue; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java deleted file mode 100644 index 703d4da6b..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state; - -import com.google.common.base.Joiner; - -import java.util.List; - -public class GLObjectProperty extends GLAbstractAtomicProperty { - private final Object mDefaultValue; - private Object mCurrentValue; - - private static final Joiner JOINER = Joiner.on(", "); //$NON-NLS-1$ - - public GLObjectProperty(GLStateType type, Object defaultValue) { - super(type); - - mDefaultValue = mCurrentValue = defaultValue; - } - - @Override - public boolean isDefault() { - return mDefaultValue != null & mDefaultValue.equals(mCurrentValue); - } - - @Override - public void setValue(Object newValue) { - mCurrentValue = newValue; - } - - @Override - public String getStringValue() { - if (mCurrentValue == null) { - return "null"; - } else { - if (mCurrentValue instanceof List<?>) { - return "[" + JOINER.join((List<?>) mCurrentValue) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - return mCurrentValue.toString(); - } - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - } - - @Override - public Object getValue() { - return mCurrentValue; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLSparseArrayProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLSparseArrayProperty.java deleted file mode 100644 index c45002857..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLSparseArrayProperty.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import com.android.utils.SparseArray; - -public class GLSparseArrayProperty implements IGLProperty { - private final GLStateType mType; - private final IGLProperty mDefaultValue; - private final boolean mCreateOnAccess; - private final SparseArray<IGLProperty> mSparseArray; - private IGLProperty mParent; - - public GLSparseArrayProperty(GLStateType type, IGLProperty defaultValue) { - this(type, defaultValue, false); - } - - /** - * Constructs a sparse array property. - * @param type GL state corresponding to this property - * @param defaultValue default value of each item - * @param createOnAccess create an item on access if it is not present - */ - public GLSparseArrayProperty(GLStateType type, IGLProperty defaultValue, - boolean createOnAccess) { - mType = type; - mDefaultValue = defaultValue; - mCreateOnAccess = createOnAccess; - mSparseArray = new SparseArray<IGLProperty>(20); - } - - private GLSparseArrayProperty(GLStateType type, IGLProperty defaultValue, - boolean createOnAccess, SparseArray<IGLProperty> contents) { - mType = type; - mDefaultValue = defaultValue; - mCreateOnAccess = createOnAccess; - mSparseArray = contents; - } - - public List<IGLProperty> getValues() { - List<IGLProperty> values = new ArrayList<IGLProperty>(mSparseArray.size()); - - for (int i = 0; i < mSparseArray.size(); i++) { - values.add(mSparseArray.valueAt(i)); - } - - return values; - } - - public IGLProperty getProperty(int key) { - IGLProperty p = mSparseArray.get(key); - if (p == null && mCreateOnAccess) { - add(key); - p = mSparseArray.get(key); - } - return p; - } - - public int keyFor(IGLProperty element) { - int index = mSparseArray.indexOfValue(element); - return mSparseArray.keyAt(index); - } - - public void put(int key, IGLProperty element) { - element.setParent(this); - mSparseArray.put(key, element); - } - - public void add(int key) { - IGLProperty prop = mDefaultValue.clone(); - prop.setParent(this); - mSparseArray.put(key, prop); - } - - public void delete(int key) { - mSparseArray.delete(key); - } - - @Override - public GLStateType getType() { - return mType; - } - - @Override - public boolean isComposite() { - return true; - } - - @Override - public boolean isDefault() { - return false; - } - - @Override - public IGLProperty getParent() { - return mParent; - } - - @Override - public void setParent(IGLProperty parent) { - mParent = parent; - } - - @Override - public GLSparseArrayProperty clone() { - SparseArray<IGLProperty> copy = new SparseArray<IGLProperty>(mSparseArray.size()); - for (int i = 0; i < mSparseArray.size(); i++) { - int key = mSparseArray.keyAt(i); - IGLProperty value = mSparseArray.get(key); - copy.put(key, value); - } - - return new GLSparseArrayProperty(mType, mDefaultValue, mCreateOnAccess, copy); - } - - @Override - public String getStringValue() { - // This method is called for displaying objects in the UI. - // We do not display any values for composites in the UI as they are only intermediate - // nodes in the tree. - return ""; - } - - @Override - public void setValue(Object value) { - throw new UnsupportedOperationException( - "Values cannot be set for composite properties."); //$NON-NLS-1$ - } - - @Override - public Object getValue() { - throw new UnsupportedOperationException( - "Values cannot be obtained for composite properties."); //$NON-NLS-1$ - } - - @Override - public void prettyPrint(StatePrettyPrinter pp) { - pp.prettyPrint(mType, null); - pp.incrementIndentLevel(); - for (int i = 0; i < mSparseArray.size(); i++) { - int key = mSparseArray.keyAt(i); - pp.prettyPrint(String.format(Locale.US, "Index %d:", key)); - IGLProperty prop = mSparseArray.get(key); - - assert prop != null; - if (prop != null) { - prop.prettyPrint(pp); - } - } - pp.decrementIndentLevel(); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java deleted file mode 100644 index 04ce676c2..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - -import com.android.ide.eclipse.gltrace.GLEnum; -import com.android.ide.eclipse.gltrace.state.DisplayRadix; - -import java.util.Collections; - -public class GLState { - /** # of texture units modeled in the GL State. */ - public static final int TEXTURE_UNIT_COUNT = 32; - - /** # of vertex attributes */ - private static final int MAX_VERTEX_ATTRIBS = 16; - - private static GLState sGLState = new GLState(); - - private IGLProperty createBufferBindings() { - IGLProperty array, eArray, vArray; - - array = new GLIntegerProperty(GLStateType.ARRAY_BUFFER_BINDING, 0); - eArray = new GLIntegerProperty(GLStateType.ELEMENT_ARRAY_BUFFER_BINDING, 0); - - vArray = new GLIntegerProperty( - GLStateType.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_PER_INDEX, 0); - IGLProperty vArray8 = new GLListProperty(GLStateType.VERTEX_ATTRIB_ARRAY_BUFFER_BINDINGS, - vArray, MAX_VERTEX_ATTRIBS); - - return new GLCompositeProperty( - GLStateType.BUFFER_BINDINGS, - array, - eArray, - vArray8); - } - - private IGLProperty createVertexAttribArrays() { - IGLProperty enabled, size, stride, type, normalized, pointer; - - enabled = new GLBooleanProperty(GLStateType.VERTEX_ATTRIB_ARRAY_ENABLED, false); - size = new GLIntegerProperty(GLStateType.VERTEX_ATTRIB_ARRAY_SIZE, 4); - stride = new GLIntegerProperty(GLStateType.VERTEX_ATTRIB_ARRAY_STRIDE, 0); - type = new GLEnumProperty(GLStateType.VERTEX_ATTRIB_ARRAY_TYPE, GLEnum.GL_FLOAT); - normalized = new GLBooleanProperty(GLStateType.VERTEX_ATTRIB_ARRAY_NORMALIZED, false); - pointer = new GLLongProperty(GLStateType.VERTEX_ATTRIB_ARRAY_POINTER, 0L, - DisplayRadix.HEX); - - IGLProperty perVertexAttribArrayState = new GLCompositeProperty( - GLStateType.VERTEX_ATTRIB_ARRAY_COMPOSITE, - enabled, - size, - stride, - type, - normalized, - pointer); - - return new GLListProperty( - GLStateType.VERTEX_ATTRIB_ARRAY, - perVertexAttribArrayState, - MAX_VERTEX_ATTRIBS); - } - - private IGLProperty createGenericVertexAttributeState() { - IGLProperty v0 = new GLFloatProperty(GLStateType.GENERIC_VERTEX_ATTRIB_V0, - Float.valueOf(0)); - IGLProperty v1 = new GLFloatProperty(GLStateType.GENERIC_VERTEX_ATTRIB_V1, - Float.valueOf(0)); - IGLProperty v2 = new GLFloatProperty(GLStateType.GENERIC_VERTEX_ATTRIB_V2, - Float.valueOf(0)); - IGLProperty v3 = new GLFloatProperty(GLStateType.GENERIC_VERTEX_ATTRIB_V3, - Float.valueOf(0)); - - IGLProperty perGenericVertexAttribState = new GLCompositeProperty( - GLStateType.GENERIC_VERTEX_ATTRIBUTE_DATA_COMPOSITE, - v0, v1, v2, v3); - - return new GLListProperty( - GLStateType.GENERIC_VERTEX_ATTRIBUTES, - perGenericVertexAttribState, - MAX_VERTEX_ATTRIBS); - } - - private IGLProperty createVboState() { - IGLProperty size = new GLIntegerProperty(GLStateType.BUFFER_SIZE, Integer.valueOf(0)); - IGLProperty usage = new GLEnumProperty(GLStateType.BUFFER_USAGE, GLEnum.GL_STATIC_DRAW); - IGLProperty data = new GLObjectProperty(GLStateType.BUFFER_DATA, new byte[0]); - IGLProperty type = new GLEnumProperty(GLStateType.BUFFER_TYPE, GLEnum.GL_ARRAY_BUFFER); - - IGLProperty perVboState = new GLCompositeProperty(GLStateType.VBO_COMPOSITE, - size, usage, data, type); - - return new GLSparseArrayProperty(GLStateType.VBO, perVboState); - } - - private IGLProperty createVertexArrayData() { - IGLProperty vertexAttribArrays = createVertexAttribArrays(); - IGLProperty bufferBindings = createBufferBindings(); - IGLProperty genericAttribs = createGenericVertexAttributeState(); - IGLProperty vboState = createVboState(); - - return new GLCompositeProperty(GLStateType.VERTEX_ARRAY_DATA, - genericAttribs, - vertexAttribArrays, - bufferBindings, - vboState); - } - - private IGLProperty createTransformationState() { - IGLProperty viewPortX = new GLIntegerProperty(GLStateType.VIEWPORT_X, 0); - IGLProperty viewPortY = new GLIntegerProperty(GLStateType.VIEWPORT_Y, 0); - IGLProperty viewPortW = new GLIntegerProperty(GLStateType.VIEWPORT_WIDTH, 0); - IGLProperty viewPortH = new GLIntegerProperty(GLStateType.VIEWPORT_HEIGHT, 0); - IGLProperty viewPort = new GLCompositeProperty(GLStateType.VIEWPORT, - viewPortX, viewPortY, viewPortW, viewPortH); - - IGLProperty clampNear = new GLFloatProperty(GLStateType.DEPTH_RANGE_NEAR, - Float.valueOf(0.0f)); - IGLProperty clampFar = new GLFloatProperty(GLStateType.DEPTH_RANGE_FAR, - Float.valueOf(1.0f)); - IGLProperty depthRange = new GLCompositeProperty(GLStateType.DEPTH_RANGE, - clampNear, - clampFar); - - IGLProperty transformationState = new GLCompositeProperty(GLStateType.TRANSFORMATION_STATE, - viewPort, - depthRange); - return transformationState; - } - - private IGLProperty createRasterizationState() { - IGLProperty lineWidth = new GLFloatProperty(GLStateType.LINE_WIDTH, Float.valueOf(1.0f)); - IGLProperty cullFace = new GLBooleanProperty(GLStateType.CULL_FACE, Boolean.FALSE); - IGLProperty cullFaceMode = new GLEnumProperty(GLStateType.CULL_FACE_MODE, GLEnum.GL_BACK); - IGLProperty frontFace = new GLEnumProperty(GLStateType.FRONT_FACE, GLEnum.GL_CCW); - IGLProperty polyOffsetFactor = new GLFloatProperty(GLStateType.POLYGON_OFFSET_FACTOR, - Float.valueOf(0f)); - IGLProperty polyOffsetUnits = new GLFloatProperty(GLStateType.POLYGON_OFFSET_UNITS, - Float.valueOf(0f)); - IGLProperty polyOffsetFill = new GLBooleanProperty(GLStateType.POLYGON_OFFSET_FILL, - Boolean.FALSE); - - return new GLCompositeProperty(GLStateType.RASTERIZATION_STATE, - lineWidth, - cullFace, - cullFaceMode, - frontFace, - polyOffsetFactor, - polyOffsetUnits, - polyOffsetFill); - } - - private IGLProperty createPixelOperationsState() { - IGLProperty scissorTest = new GLBooleanProperty(GLStateType.SCISSOR_TEST, Boolean.FALSE); - IGLProperty scissorBoxX = new GLIntegerProperty(GLStateType.SCISSOR_BOX_X, 0); - IGLProperty scissorBoxY = new GLIntegerProperty(GLStateType.SCISSOR_BOX_Y, 0); - IGLProperty scissorBoxW = new GLIntegerProperty(GLStateType.SCISSOR_BOX_WIDTH, 0); - IGLProperty scissorBoxH = new GLIntegerProperty(GLStateType.SCISSOR_BOX_HEIGHT, 0); - IGLProperty scissorBox = new GLCompositeProperty(GLStateType.SCISSOR_BOX, - scissorBoxX, scissorBoxY, scissorBoxW, scissorBoxH); - - IGLProperty stencilTest = new GLBooleanProperty(GLStateType.STENCIL_TEST, Boolean.FALSE); - IGLProperty stencilFunc = new GLEnumProperty(GLStateType.STENCIL_FUNC, GLEnum.GL_ALWAYS); - IGLProperty stencilMask = new GLIntegerProperty(GLStateType.STENCIL_VALUE_MASK, - Integer.valueOf(0xffffffff), DisplayRadix.HEX); - IGLProperty stencilRef = new GLIntegerProperty(GLStateType.STENCIL_REF, - Integer.valueOf(0)); - IGLProperty stencilFail = new GLEnumProperty(GLStateType.STENCIL_FAIL, GLEnum.GL_KEEP); - IGLProperty stencilPassDepthFail = new GLEnumProperty(GLStateType.STENCIL_PASS_DEPTH_FAIL, - GLEnum.GL_KEEP); - IGLProperty stencilPassDepthPass = new GLEnumProperty(GLStateType.STENCIL_PASS_DEPTH_PASS, - GLEnum.GL_KEEP); - IGLProperty stencilBackFunc = new GLEnumProperty(GLStateType.STENCIL_BACK_FUNC, - GLEnum.GL_ALWAYS); - IGLProperty stencilBackValueMask = new GLIntegerProperty( - GLStateType.STENCIL_BACK_VALUE_MASK, Integer.valueOf(0xffffffff), DisplayRadix.HEX); - IGLProperty stencilBackRef = new GLIntegerProperty(GLStateType.STENCIL_BACK_REF, 0); - IGLProperty stencilBackFail = new GLEnumProperty(GLStateType.STENCIL_BACK_FAIL, - GLEnum.GL_KEEP); - IGLProperty stencilBackPassDepthFail = new GLEnumProperty( - GLStateType.STENCIL_BACK_PASS_DEPTH_FAIL, GLEnum.GL_KEEP); - IGLProperty stencilBackPassDepthPass = new GLEnumProperty( - GLStateType.STENCIL_BACK_PASS_DEPTH_PASS, GLEnum.GL_KEEP); - IGLProperty stencil = new GLCompositeProperty(GLStateType.STENCIL, - stencilTest, stencilFunc, - stencilMask, stencilRef, stencilFail, - stencilPassDepthFail, stencilPassDepthPass, - stencilBackFunc, stencilBackValueMask, - stencilBackRef, stencilBackFail, - stencilBackPassDepthFail, stencilBackPassDepthPass); - - IGLProperty depthTest = new GLBooleanProperty(GLStateType.DEPTH_TEST, Boolean.FALSE); - IGLProperty depthFunc = new GLEnumProperty(GLStateType.DEPTH_FUNC, GLEnum.GL_LESS); - - IGLProperty blendEnabled = new GLBooleanProperty(GLStateType.BLEND_ENABLED, Boolean.FALSE); - // FIXME: BLEND_SRC_RGB should be set to GL_ONE, but GL_LINES is already 0x1. - IGLProperty blendSrcRgb = new GLEnumProperty(GLStateType.BLEND_SRC_RGB, GLEnum.GL_LINES); - IGLProperty blendSrcAlpha = new GLEnumProperty(GLStateType.BLEND_SRC_ALPHA, - GLEnum.GL_LINES); - IGLProperty blendDstRgb = new GLEnumProperty(GLStateType.BLEND_DST_RGB, GLEnum.GL_NONE); - IGLProperty blendDstAlpha = new GLEnumProperty(GLStateType.BLEND_DST_ALPHA, - GLEnum.GL_NONE); - IGLProperty blendEquationRgb = new GLEnumProperty(GLStateType.BLEND_EQUATION_RGB, - GLEnum.GL_FUNC_ADD); - IGLProperty blendEquationAlpha = new GLEnumProperty(GLStateType.BLEND_EQUATION_ALPHA, - GLEnum.GL_FUNC_ADD); - IGLProperty blend = new GLCompositeProperty(GLStateType.BLEND, - blendEnabled, blendSrcRgb, blendSrcAlpha, blendDstRgb, blendDstAlpha, - blendEquationRgb, blendEquationAlpha); - - IGLProperty dither = new GLBooleanProperty(GLStateType.DITHER, Boolean.TRUE); - - return new GLCompositeProperty(GLStateType.PIXEL_OPERATIONS, - scissorTest, scissorBox, stencil, - depthTest, depthFunc, blend, dither); - } - - private IGLProperty createPixelPackState() { - IGLProperty packAlignment = new GLIntegerProperty(GLStateType.PACK_ALIGNMENT, - Integer.valueOf(4)); - IGLProperty unpackAlignment = new GLIntegerProperty(GLStateType.UNPACK_ALIGNMENT, - Integer.valueOf(4)); - IGLProperty pixelPack = new GLCompositeProperty(GLStateType.PIXEL_PACKING, - packAlignment, unpackAlignment); - return pixelPack; - } - - private IGLProperty createFramebufferState() { - IGLProperty binding = new GLIntegerProperty(GLStateType.FRAMEBUFFER_BINDING, 0); - GLCompositeProperty framebufferState = new GLCompositeProperty( - GLStateType.FRAMEBUFFER_STATE, - binding); - return framebufferState; - } - - private IGLProperty createTextureState() { - IGLProperty activeTexture = new GLIntegerProperty(GLStateType.ACTIVE_TEXTURE_UNIT, - Integer.valueOf(0)); - - IGLProperty binding2D = new GLIntegerProperty(GLStateType.TEXTURE_BINDING_2D, - Integer.valueOf(0)); - IGLProperty bindingCubeMap = new GLIntegerProperty(GLStateType.TEXTURE_BINDING_CUBE_MAP, - Integer.valueOf(0)); - IGLProperty bindingExternal = new GLIntegerProperty(GLStateType.TEXTURE_BINDING_EXTERNAL, - Integer.valueOf(0)); - IGLProperty perTextureUnitState = new GLCompositeProperty( - GLStateType.PER_TEXTURE_UNIT_STATE, binding2D, bindingCubeMap, bindingExternal); - IGLProperty textureUnitState = new GLListProperty(GLStateType.TEXTURE_UNITS, - perTextureUnitState, TEXTURE_UNIT_COUNT); - - IGLProperty swizzleR = new GLEnumProperty(GLStateType.TEXTURE_SWIZZLE_R, GLEnum.GL_RED); - IGLProperty swizzleG = new GLEnumProperty(GLStateType.TEXTURE_SWIZZLE_G, GLEnum.GL_GREEN); - IGLProperty swizzleB = new GLEnumProperty(GLStateType.TEXTURE_SWIZZLE_B, GLEnum.GL_BLUE); - IGLProperty swizzleA = new GLEnumProperty(GLStateType.TEXTURE_SWIZZLE_A, GLEnum.GL_ALPHA); - IGLProperty minFilter = new GLEnumProperty(GLStateType.TEXTURE_MIN_FILTER, - GLEnum.GL_NEAREST); - IGLProperty magFilter = new GLEnumProperty(GLStateType.TEXTURE_MAG_FILTER, - GLEnum.GL_NEAREST); - IGLProperty wrapS = new GLEnumProperty(GLStateType.TEXTURE_WRAP_S, GLEnum.GL_REPEAT); - IGLProperty wrapT = new GLEnumProperty(GLStateType.TEXTURE_WRAP_T, GLEnum.GL_REPEAT); - IGLProperty wrapR = new GLEnumProperty(GLStateType.TEXTURE_WRAP_R, GLEnum.GL_REPEAT); - IGLProperty minLod = new GLFloatProperty(GLStateType.TEXTURE_MIN_LOD, Float.valueOf(-1000)); - IGLProperty maxLod = new GLFloatProperty(GLStateType.TEXTURE_MAX_LOD, Float.valueOf(1000)); - IGLProperty baseLevel = new GLIntegerProperty(GLStateType.TEXTURE_BASE_LEVEL, 0); - IGLProperty maxLevel = new GLIntegerProperty(GLStateType.TEXTURE_MAX_LEVEL, 1000); - IGLProperty cmpMode = new GLEnumProperty(GLStateType.TEXTURE_COMPARE_MODE, GLEnum.GL_NONE); - IGLProperty cmpFunc = new GLEnumProperty(GLStateType.TEXTURE_COMPARE_FUNC, - GLEnum.GL_LEQUAL); - IGLProperty immutableFormat = new GLBooleanProperty(GLStateType.TEXTURE_IMMUTABLE_FORMAT, - Boolean.FALSE); - IGLProperty immutableLevels = new GLIntegerProperty(GLStateType.TEXTURE_IMMUTABLE_LEVELS, - 0); - - IGLProperty width = new GLIntegerProperty(GLStateType.TEXTURE_WIDTH, Integer.valueOf(-1)); - IGLProperty height = new GLIntegerProperty(GLStateType.TEXTURE_HEIGHT, - Integer.valueOf(-1)); - IGLProperty format = new GLEnumProperty(GLStateType.TEXTURE_FORMAT, - GLEnum.GL_INVALID_VALUE); - IGLProperty imageType = new GLEnumProperty(GLStateType.TEXTURE_IMAGE_TYPE, - GLEnum.GL_UNSIGNED_BYTE); - IGLProperty image = new GLStringProperty(GLStateType.TEXTURE_IMAGE, null); - - IGLProperty perTextureLevelState = new GLCompositeProperty( - GLStateType.PER_TEXTURE_LEVEL_STATE, - width, height, format, imageType, image); - IGLProperty mipmapState = new GLSparseArrayProperty(GLStateType.TEXTURE_MIPMAPS, - perTextureLevelState, true); - - IGLProperty textureDefaultState = new GLCompositeProperty(GLStateType.PER_TEXTURE_STATE, - swizzleR, swizzleG, swizzleB, swizzleA, - minFilter, magFilter, - wrapS, wrapT, wrapR, - minLod, maxLod, - baseLevel, maxLevel, - cmpMode, cmpFunc, - immutableFormat, immutableLevels, - mipmapState); - GLSparseArrayProperty textures = new GLSparseArrayProperty(GLStateType.TEXTURES, - textureDefaultState); - textures.add(0); - - return new GLCompositeProperty(GLStateType.TEXTURE_STATE, - activeTexture, - textureUnitState, - textures); - } - - private IGLProperty createProgramState() { - IGLProperty currentProgram = new GLIntegerProperty(GLStateType.CURRENT_PROGRAM, - Integer.valueOf(0)); - - IGLProperty attachedShaderId = new GLIntegerProperty(GLStateType.ATTACHED_SHADER_ID, - Integer.valueOf(0)); - IGLProperty attachedShaders = new GLSparseArrayProperty(GLStateType.ATTACHED_SHADERS, - attachedShaderId); - - IGLProperty attributeName = new GLStringProperty(GLStateType.ATTRIBUTE_NAME, ""); - IGLProperty attributeType = new GLEnumProperty(GLStateType.ATTRIBUTE_TYPE, - GLEnum.GL_FLOAT_MAT4); - IGLProperty attributeSize = new GLIntegerProperty(GLStateType.ATTRIBUTE_SIZE, - Integer.valueOf(1)); - IGLProperty attributeValue = new GLObjectProperty(GLStateType.ATTRIBUTE_VALUE, - Collections.emptyList()); - IGLProperty perAttributeProperty = new GLCompositeProperty(GLStateType.PER_ATTRIBUTE_STATE, - attributeName, attributeType, attributeSize, attributeValue); - IGLProperty attributes = new GLSparseArrayProperty(GLStateType.ACTIVE_ATTRIBUTES, - perAttributeProperty); - - IGLProperty uniformName = new GLStringProperty(GLStateType.UNIFORM_NAME, ""); - IGLProperty uniformType = new GLEnumProperty(GLStateType.UNIFORM_TYPE, - GLEnum.GL_FLOAT_MAT4); - IGLProperty uniformSize = new GLIntegerProperty(GLStateType.UNIFORM_SIZE, - Integer.valueOf(1)); - IGLProperty uniformValue = new GLObjectProperty(GLStateType.UNIFORM_VALUE, - Collections.emptyList()); - IGLProperty perUniformProperty = new GLCompositeProperty(GLStateType.PER_UNIFORM_STATE, - uniformName, uniformType, uniformSize, uniformValue); - IGLProperty uniforms = new GLSparseArrayProperty(GLStateType.ACTIVE_UNIFORMS, - perUniformProperty); - - IGLProperty perProgramState = new GLCompositeProperty(GLStateType.PER_PROGRAM_STATE, - attachedShaders, attributes, uniforms); - - IGLProperty programs = new GLSparseArrayProperty(GLStateType.PROGRAMS, perProgramState); - - return new GLCompositeProperty(GLStateType.PROGRAM_STATE, - currentProgram, programs); - } - - private IGLProperty createShaderState() { - IGLProperty shaderType = new GLEnumProperty(GLStateType.SHADER_TYPE, - GLEnum.GL_VERTEX_SHADER); - IGLProperty shaderSource = new GLStringProperty(GLStateType.SHADER_SOURCE, - ""); //$NON-NLS-1$ - IGLProperty perShaderState = new GLCompositeProperty(GLStateType.PER_SHADER_STATE, - shaderType, shaderSource); - return new GLSparseArrayProperty(GLStateType.SHADERS, perShaderState); - } - - public static IGLProperty createDefaultES2State() { - GLCompositeProperty glState = new GLCompositeProperty(GLStateType.GL_STATE_ES2, - sGLState.createVertexArrayData(), - sGLState.createFramebufferState(), - sGLState.createTransformationState(), - sGLState.createRasterizationState(), - sGLState.createPixelOperationsState(), - sGLState.createPixelPackState(), - sGLState.createTextureState(), - sGLState.createProgramState(), - sGLState.createShaderState()); - return glState; - } - - public static IGLProperty createDefaultES1State() { - GLCompositeProperty glState = new GLCompositeProperty(GLStateType.GL_STATE_ES1, - sGLState.createVertexArrayData(), - sGLState.createFramebufferState(), - sGLState.createTransformationState(), - sGLState.createRasterizationState(), - sGLState.createPixelOperationsState(), - sGLState.createPixelPackState(), - sGLState.createTextureState()); - return glState; - } - - public static IGLProperty createDefaultState() { - return new GLListProperty(GLStateType.GL_STATE, null, 0); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java deleted file mode 100644 index a0a7ce470..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - -/** The type for each OpenGL State Property {@link IGLProperty}. */ -public enum GLStateType { - // Note: the indentation reflects the state hierarchy. - - GL_STATE("OpenGL State Variables"), - GL_STATE_ES1("OpenGL ES 1.1 State"), - GL_STATE_ES2("OpenGL ES 2.0 State"), - - VERTEX_ARRAY_DATA("Vertex Array Data"), - GENERIC_VERTEX_ATTRIBUTES("Generic Vertex Attributes"), - GENERIC_VERTEX_ATTRIBUTE_DATA_COMPOSITE("Generic Vertex Attribute Data"), - GENERIC_VERTEX_ATTRIB_V0("x"), - GENERIC_VERTEX_ATTRIB_V1("y"), - GENERIC_VERTEX_ATTRIB_V2("z"), - GENERIC_VERTEX_ATTRIB_V3("w"), - - VERTEX_ATTRIB_ARRAY("Vertex Attrib Array Properties"), - VERTEX_ATTRIB_ARRAY_COMPOSITE("Vertex Attrib Array #n Properties"), - VERTEX_ATTRIB_ARRAY_ENABLED("Vertex Attrib Array Enable"), - VERTEX_ATTRIB_ARRAY_SIZE("Vertex Attrib Array Size"), - VERTEX_ATTRIB_ARRAY_STRIDE("Vertex Attrib Array Stride"), - VERTEX_ATTRIB_ARRAY_TYPE("Vertex Attrib Array Type"), - VERTEX_ATTRIB_ARRAY_NORMALIZED("Vertex Attrib Array Normalized"), - VERTEX_ATTRIB_ARRAY_POINTER("Vertex Attrib Array Pointer"), - - BUFFER_BINDINGS("Buffer Bindings"), - ARRAY_BUFFER_BINDING("Current Buffer Binding"), - ELEMENT_ARRAY_BUFFER_BINDING("Element Array Buffer Binding"), - VERTEX_ATTRIB_ARRAY_BUFFER_BINDINGS("Attribute Array Buffer Bindings"), - VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_PER_INDEX("Attribute Array Buffer Binding"), - - VBO("Vertex Buffer Objects"), - VBO_COMPOSITE("Per VBO State"), - BUFFER_SIZE("Size"), - BUFFER_USAGE("Usage"), - BUFFER_DATA("Data"), - BUFFER_TYPE("Type"), - - TRANSFORMATION_STATE("Transformation State"), - VIEWPORT("Viewport"), - VIEWPORT_X("Lower Left X"), - VIEWPORT_Y("Lower Left Y"), - VIEWPORT_WIDTH("Width"), - VIEWPORT_HEIGHT("Height"), - DEPTH_RANGE("Depth Range"), - DEPTH_RANGE_NEAR("Near Clipping Plane"), - DEPTH_RANGE_FAR("Far Clipping Plane"), - - RASTERIZATION_STATE("Rasterization State"), - LINE_WIDTH("Line Width"), - CULL_FACE("Polygon Culling Enabled"), - CULL_FACE_MODE("Cull front/back facing polygons"), - FRONT_FACE("Polygon frontface CW/CCW indicator"), - POLYGON_OFFSET_FACTOR("Polygon Offset Factor"), - POLYGON_OFFSET_UNITS("Polygon Offset Units"), - POLYGON_OFFSET_FILL("Polygon Offset Enable"), - - PIXEL_OPERATIONS("Pixel Operations"), - SCISSOR_TEST("Scissoring enabled"), - SCISSOR_BOX("Scissor Box"), - SCISSOR_BOX_X("Lower Left X"), - SCISSOR_BOX_Y("Lower Left Y"), - SCISSOR_BOX_WIDTH("Width"), - SCISSOR_BOX_HEIGHT("Height"), - STENCIL("Stencil"), - STENCIL_TEST("Stenciling enabled"), - STENCIL_FUNC("Front Stencil Function"), - STENCIL_VALUE_MASK("Front Stencil Mask"), - STENCIL_REF("Front Stencil Reference Value"), - STENCIL_FAIL("Front Stencil Fail Action"), - STENCIL_PASS_DEPTH_FAIL("Front stencil depth buffer fail action"), - STENCIL_PASS_DEPTH_PASS("Front stencil depth buffer pass action"), - STENCIL_BACK_FUNC("Back stencil function"), - STENCIL_BACK_VALUE_MASK("Back stencil mask"), - STENCIL_BACK_REF("Back stencil reference value"), - STENCIL_BACK_FAIL("Back stencil fail action"), - STENCIL_BACK_PASS_DEPTH_FAIL("Back stencil depth buffer fail action"), - STENCIL_BACK_PASS_DEPTH_PASS("Back stencil depth buffer pass action"), - DEPTH_TEST("Depth buffer enabled"), - DEPTH_FUNC("Depth buffer test function"), - BLEND("Blending"), - BLEND_ENABLED("Enabled"), - BLEND_SRC_RGB("Source RGB function"), - BLEND_SRC_ALPHA("Source A function"), - BLEND_DST_RGB("Dest. RGB function"), - BLEND_DST_ALPHA("Dest. A function"), - BLEND_EQUATION_RGB("RGB Equation"), - BLEND_EQUATION_ALPHA("Alpha Equation"), - DITHER("Dithering enabled"), - - PIXEL_PACKING("Pixel Packing"), - PACK_ALIGNMENT("Pack Alignment"), - UNPACK_ALIGNMENT("Unpack Alignment"), - - TEXTURE_STATE("Texture State"), - ACTIVE_TEXTURE_UNIT("Active Texture Unit"), - TEXTURE_UNITS("Texture Units"), - PER_TEXTURE_UNIT_STATE("Texture Unit Properties"), - TEXTURE_BINDING_2D("TEXTURE_2D Binding"), - TEXTURE_BINDING_CUBE_MAP("TEXTURE_CUBE_MAP Binding"), - TEXTURE_BINDING_EXTERNAL("TEXTURE_EXTERNAL Binding"), - TEXTURES("Textures"), - PER_TEXTURE_STATE("Per Texture State"), - TEXTURE_SWIZZLE_R("Red Component Swizzle"), - TEXTURE_SWIZZLE_G("Green Component Swizzle"), - TEXTURE_SWIZZLE_B("Blue Component Swizzle"), - TEXTURE_SWIZZLE_A("Alpha Component Swizzle"), - TEXTURE_MIN_FILTER("Minification Function"), - TEXTURE_MAG_FILTER("Magnification Function"), - TEXTURE_WRAP_S("Texcoord s Wrap Mode"), - TEXTURE_WRAP_T("Texcoord t Wrap Mode"), - TEXTURE_WRAP_R("Texcoord r Wrap Mode"), - TEXTURE_MIN_LOD("Min Level of Detail"), - TEXTURE_MAX_LOD("Max Level of Detail"), - TEXTURE_BASE_LEVEL("Base Texture Array"), - TEXTURE_MAX_LEVEL("Max Texture Array Level"), - TEXTURE_COMPARE_MODE("Comparison Mode"), - TEXTURE_COMPARE_FUNC("Comparison Function"), - TEXTURE_IMMUTABLE_FORMAT("Size and format immutable?"), - TEXTURE_IMMUTABLE_LEVELS("# of levels in immutable textures"), - TEXTURE_MIPMAPS("Texture Mipmap State"), - PER_TEXTURE_LEVEL_STATE("Per Texture Level State"), - TEXTURE_FORMAT("Format"), - TEXTURE_WIDTH("Width"), - TEXTURE_HEIGHT("Height"), - TEXTURE_IMAGE_TYPE("Image Type"), - TEXTURE_IMAGE("Image"), - - PROGRAM_STATE("Program Object State"), - CURRENT_PROGRAM("Current Program"), - PROGRAMS("Programs"), - PER_PROGRAM_STATE("Per Program State"), - ATTACHED_SHADERS("Attached Shaders"), - ATTACHED_SHADER_ID("Attached Shader ID"), - ACTIVE_ATTRIBUTES("Attributes"), - PER_ATTRIBUTE_STATE("Per Attribute State"), - ATTRIBUTE_NAME("Name"), - ATTRIBUTE_TYPE("Type"), - ATTRIBUTE_SIZE("Size"), - ATTRIBUTE_VALUE("Value"), - ACTIVE_UNIFORMS("Uniforms"), - PER_UNIFORM_STATE("Per Uniform State"), - UNIFORM_NAME("Name"), - UNIFORM_TYPE("Type"), - UNIFORM_SIZE("Size"), - UNIFORM_VALUE("Value"), - - SHADERS("Shader Objects"), - PER_SHADER_STATE("Per Shader State"), - SHADER_TYPE("Shader Type"), - SHADER_SOURCE("Source"), - - FRAMEBUFFER_STATE("Framebuffer State"), - FRAMEBUFFER_BINDING("Framebuffer Binding"), - FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE("Framebuffer object type"), - FRAMEBUFFER_ATTACHMENT_OBJECT_NAME("Framebuffer object name"), - FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL("Framebuffer texture level"), - FRAMEBUFFER_ATTACHEMENT_TEXTURE_CUBE_MAP_FACE("Framebuffer texture cubemap face"); - - private final String mDescription; - - GLStateType(String description) { - mDescription = description; - } - - public String getDescription() { - return mDescription; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStringProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStringProperty.java deleted file mode 100644 index d95651fe3..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStringProperty.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state; - -public class GLStringProperty extends GLAbstractAtomicProperty { - private final String mDefaultValue; - private String mCurrentValue; - - public GLStringProperty(GLStateType type, String defaultValue) { - super(type); - - mDefaultValue = mCurrentValue = defaultValue; - } - - @Override - public boolean isDefault() { - return mDefaultValue.equalsIgnoreCase(mCurrentValue); - } - - @Override - public void setValue(Object value) { - if (value instanceof String) { - mCurrentValue = (String) value; - } else { - throw new IllegalArgumentException("Attempt to set non-string value for " //$NON-NLS-1$ - + getType()); - } - } - - public void setValue(String value) { - mCurrentValue = value; - } - - @Override - public Object getValue() { - return mCurrentValue; - } - - @Override - public String getStringValue() { - return mCurrentValue; - } - - @Override - public String toString() { - return getType() + "=" + getStringValue(); //$NON-NLS-1$ - }; -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/IGLProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/IGLProperty.java deleted file mode 100644 index ed87fd231..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/IGLProperty.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state; - - -/** - * The GL state is modeled as a hierarchical set of properties, all of which implement - * this interface. - */ -public interface IGLProperty extends Cloneable { - /** Obtain the type of the property. */ - GLStateType getType(); - - /** Is this a composite property? - * @return true if it is a list or structure of properties, - * false if it is a leaf level atomic property - * */ - boolean isComposite(); - - /** - * Is the currently set value the default? - * @return true if current value matches the default (initial) value - */ - boolean isDefault(); - - /** Set the current value for this property. */ - void setValue(Object value); - - /** Get the current value for this property. */ - Object getValue(); - - /** Get the string representation for this property. */ - String getStringValue(); - - /** - * Get the parent property that holds this property. - * @return null if this property is at the top level, parent otherwise - */ - IGLProperty getParent(); - - /** Set the parent property that holds this property. */ - void setParent(IGLProperty parent); - - /** Deep clone this property. */ - IGLProperty clone(); - - /** Pretty print current property value to the given writer. */ - void prettyPrint(StatePrettyPrinter pp); -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/StatePrettyPrinter.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/StatePrettyPrinter.java deleted file mode 100644 index 0ad9aa4d7..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/StatePrettyPrinter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state; - -import com.android.annotations.NonNull; -import com.android.annotations.Nullable; -import com.android.utils.SdkUtils; - -public class StatePrettyPrinter { - private static final int SPACES_PER_INDENT = 4; - private final String mLineSeparator = SdkUtils.getLineSeparator(); - - private StringBuilder mSb = new StringBuilder(1000); - private int mIndentLevel = 0; - - public void prettyPrint(@NonNull GLStateType name, @Nullable String value) { - indentLine(mIndentLevel * SPACES_PER_INDENT); - - mSb.append(name.toString()); - - if (value != null) { - mSb.append(':'); - mSb.append(value); - } - mSb.append(mLineSeparator); - } - - public void prettyPrint(@NonNull String s) { - indentLine(mIndentLevel * SPACES_PER_INDENT); - - mSb.append(s); - mSb.append(mLineSeparator); - } - - private void indentLine(int spaces) { - for (int i = 0; i < spaces; i++) { - mSb.append(' '); - } - } - - public void incrementIndentLevel() { - mIndentLevel++; - } - - public void decrementIndentLevel() { - mIndentLevel--; - } - - @Override - public String toString() { - return mSb.toString(); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/BufferSubDataTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/BufferSubDataTransform.java deleted file mode 100644 index 393f1b9b7..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/BufferSubDataTransform.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.GLProtoBuf.GLMessage.Function; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -import java.nio.ByteBuffer; - -/** - * A {@link BufferSubDataTransform} updates a portion of the buffer data as specified by - * the {@link Function#glBufferSubData} function. - */ -public class BufferSubDataTransform implements IStateTransform { - private final IGLPropertyAccessor mAccessor; - private final int mOffset; - - private final byte[] mSubData; - private byte[] mOldData; - private byte[] mNewData; - - public BufferSubDataTransform(IGLPropertyAccessor accessor, int offset, byte[] data) { - mAccessor = accessor; - mOffset = offset; - mSubData = data; - } - - @Override - public void apply(IGLProperty state) { - IGLProperty property = mAccessor.getProperty(state); - mOldData = (byte[]) property.getValue(); - - if (mOldData != null) { - mNewData = new byte[mOldData.length]; - ByteBuffer bb = ByteBuffer.wrap(mNewData); - - // copy all of the old buffer - bb.put(mOldData); - bb.rewind(); - - // update with the sub buffer data at specified offset - bb.position(mOffset); - bb.put(mSubData); - } - - property.setValue(mNewData); - } - - @Override - public void revert(IGLProperty state) { - if (mOldData != null) { - IGLProperty property = mAccessor.getProperty(state); - property.setValue(mOldData); - mOldData = null; - } - } - - @Override - public IGLProperty getChangedProperty(IGLProperty state) { - return mAccessor.getProperty(state); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java deleted file mode 100644 index 9cc3cb885..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.GLIntegerProperty; -import com.android.ide.eclipse.gltrace.state.GLStateType; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -public class CurrentProgramPropertyAccessor implements IGLPropertyAccessor { - private final int mContextId; - private final GLStateType mStateCategory; - private final int mLocation; - private final GLStateType mStateType; - private final IGLPropertyAccessor mCurrentProgramAccessor; - - public CurrentProgramPropertyAccessor(int contextid, GLStateType stateCategory, - int location, GLStateType stateType) { - mContextId = contextid; - mStateCategory = stateCategory; - mLocation = location; - mStateType = stateType; - - mCurrentProgramAccessor = GLPropertyAccessor.makeAccessor(contextid, - GLStateType.PROGRAM_STATE, - GLStateType.CURRENT_PROGRAM); - } - - @Override - public IGLProperty getProperty(IGLProperty state) { - // obtain the current program - IGLProperty currentProgramProperty = mCurrentProgramAccessor.getProperty(state); - if (!(currentProgramProperty instanceof GLIntegerProperty)) { - return null; - } - - Integer program = (Integer) currentProgramProperty.getValue(); - - // now access the required program property - return GLPropertyAccessor.makeAccessor(mContextId, - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - program, - mStateCategory, - Integer.valueOf(mLocation), - mStateType).getProperty(state); - } - - @Override - public String getPath() { - return String.format("PROGRAM_STATE/PROGRAMS/${program}/%s/%d/%s", - mStateCategory, mLocation, mStateType); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentVboPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentVboPropertyAccessor.java deleted file mode 100644 index bd1286d5b..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentVboPropertyAccessor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.GLEnum; -import com.android.ide.eclipse.gltrace.state.GLIntegerProperty; -import com.android.ide.eclipse.gltrace.state.GLStateType; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * An {@link IGLPropertyAccessor} that retrieves the requested property in the - * currently bound {@link GLEnum#GL_ARRAY_BUFFER} or {@link GLEnum#GL_ELEMENT_ARRAY_BUFFER}. - */ -public class CurrentVboPropertyAccessor implements IGLPropertyAccessor { - private final int mContextId; - private final IGLPropertyAccessor mVboBindingAccessor; - private final GLStateType mVboProperty; - - public CurrentVboPropertyAccessor(int contextId, GLEnum target, GLStateType vboProperty) { - mContextId = contextId; - mVboProperty = vboProperty; - - GLStateType vboType; - if (target == GLEnum.GL_ARRAY_BUFFER) { - vboType = GLStateType.ARRAY_BUFFER_BINDING; - } else { - vboType = GLStateType.ELEMENT_ARRAY_BUFFER_BINDING; - } - - mVboBindingAccessor = GLPropertyAccessor.makeAccessor(contextId, - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.BUFFER_BINDINGS, - vboType); - } - - @Override - public IGLProperty getProperty(IGLProperty state) { - // obtain the current bound buffer - IGLProperty currentBinding = mVboBindingAccessor.getProperty(state); - if (!(currentBinding instanceof GLIntegerProperty)) { - return null; - } - - Integer buffer = (Integer) currentBinding.getValue(); - - return GLPropertyAccessor.makeAccessor(mContextId, - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VBO, - buffer, - mVboProperty).getProperty(state); - } - - @Override - public String getPath() { - return String.format("VERTEX_ARRAY_DATA/VBO/${currentBuffer}/%s", mVboProperty); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/GLPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/GLPropertyAccessor.java deleted file mode 100644 index be338be19..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/GLPropertyAccessor.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.GLCompositeProperty; -import com.android.ide.eclipse.gltrace.state.GLListProperty; -import com.android.ide.eclipse.gltrace.state.GLSparseArrayProperty; -import com.android.ide.eclipse.gltrace.state.GLStateType; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -import java.util.ArrayList; -import java.util.List; - -/** - * GLPropertyAccessor's can be used to extract a certain property from the provided - * OpenGL State hierarchy. - */ -public class GLPropertyAccessor implements IGLPropertyAccessor { - private final int mContextId; - private final List<GLPropertyExtractor> mExtractors; - - private GLPropertyAccessor(int contextId, List<GLPropertyExtractor> extractors) { - mContextId = contextId; - mExtractors = extractors; - } - - @Override - public IGLProperty getProperty(IGLProperty state) { - IGLProperty root = ((GLListProperty) state).get(mContextId); - - for (GLPropertyExtractor e : mExtractors) { - IGLProperty successor = e.getProperty(root); - if (successor == null) { - root = null; - break; - } - root = successor; - } - - return root; - } - - /** - * Factory method used to construct a {@link GLPropertyAccessor}. - * @param contextId id of affected context - * @param accessors list of accessor's to be used to navigate the property hierarchy. The - * accessors are either Integers or {@link GLStateType} objects. Integers - * are assumed to be indexes in a {@link GLListProperty} or - * {@link GLSparseArrayProperty}, and the GLStateType enum objects are - * used to query {@link GLCompositeProperty}'s. - */ - public static IGLPropertyAccessor makeAccessor(int contextId, Object...accessors) { - List<GLPropertyExtractor> extractors = new ArrayList<GLPropertyExtractor>(); - - for (Object accessor : accessors) { - if (accessor instanceof GLStateType) { - extractors.add(new GLNamePropertyExtractor((GLStateType) accessor)); - } else if (accessor instanceof Integer) { - extractors.add(new GLIndexPropertyExtractor((Integer) accessor)); - } else { - throw new IllegalArgumentException("Unknown property (" + accessor - + ") used to access members of IGLProperty"); - } - } - - return new GLPropertyAccessor(contextId, extractors); - } - - private interface GLPropertyExtractor { - IGLProperty getProperty(IGLProperty p); - } - - /** Extract properties by name. */ - private static class GLNamePropertyExtractor implements GLPropertyExtractor { - private final GLStateType mType; - - public GLNamePropertyExtractor(GLStateType type) { - mType = type; - } - - @Override - public IGLProperty getProperty(IGLProperty p) { - if (p instanceof GLCompositeProperty) { - return ((GLCompositeProperty) p).getProperty(mType); - } - - return null; - } - } - - /** Extract properties by index. */ - private static class GLIndexPropertyExtractor implements GLPropertyExtractor { - private final int mIndex; - - public GLIndexPropertyExtractor(int index) { - mIndex = index; - } - - @Override - public IGLProperty getProperty(IGLProperty p) { - if (p instanceof GLListProperty && mIndex >= 0) { - return ((GLListProperty) p).get(mIndex); - } - if (p instanceof GLSparseArrayProperty) { - return ((GLSparseArrayProperty) p).getProperty(mIndex); - } - return null; - } - } - - @Override - public String getPath() { - StringBuilder sb = new StringBuilder(mExtractors.size() * 10); - for (GLPropertyExtractor e: mExtractors) { - if (e instanceof GLNamePropertyExtractor) { - sb.append(((GLNamePropertyExtractor) e).mType); - } else { - sb.append(((GLIndexPropertyExtractor) e).mIndex); - } - sb.append('/'); - } - - return sb.toString(); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IGLPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IGLPropertyAccessor.java deleted file mode 100644 index 5df21b950..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IGLPropertyAccessor.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * An {@link IGLPropertyAccessor} provides an interface to extract - * a specific property from a composite property. - */ -public interface IGLPropertyAccessor { - /** Obtain a specific property from the given state. */ - IGLProperty getProperty(IGLProperty state); - - /** Returns the string representation of this property accessor. */ - String getPath(); -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IPredicate.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IPredicate.java deleted file mode 100644 index e31226ffb..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IPredicate.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -public interface IPredicate { - boolean apply(Object value); -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IStateTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IStateTransform.java deleted file mode 100644 index de33a08f0..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/IStateTransform.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * This interface encapsulates a single change to the GL state. GL Calls that affect - * multiple state variables would use a list of these state transformations. - */ -public interface IStateTransform { - /** Apply this transformation on the given state. */ - void apply(IGLProperty currentState); - - /** Revert this transformation from the given state. */ - void revert(IGLProperty currentState); - - /** Obtain the property that will be affected by this transformation. */ - IGLProperty getChangedProperty(IGLProperty currentState); -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/ListElementAddTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/ListElementAddTransform.java deleted file mode 100644 index dcf50d7e8..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/ListElementAddTransform.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.GLListProperty; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * A {@link ListElementAddTransform} provides the ability to add a new property to a list of - * properties in the GL State. - */ -public class ListElementAddTransform implements IStateTransform { - private final IGLPropertyAccessor mAccessor; - private final IGLProperty mElement; - - public ListElementAddTransform(IGLPropertyAccessor accessor, IGLProperty element) { - mAccessor = accessor; - mElement = element; - } - - @Override - public void apply(IGLProperty currentState) { - GLListProperty list = getList(currentState); - if (list != null) { - list.add(mElement); - } - } - - @Override - public void revert(IGLProperty currentState) { - GLListProperty list = getList(currentState); - if (list != null) { - list.remove(mElement); - } - } - - @Override - public IGLProperty getChangedProperty(IGLProperty currentState) { - return getList(currentState); - } - - private GLListProperty getList(IGLProperty state) { - IGLProperty p = state; - - if (mAccessor != null) { - p = mAccessor.getProperty(p); - } - - if (p instanceof GLListProperty) { - return (GLListProperty) p; - } else { - return null; - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/Predicates.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/Predicates.java deleted file mode 100644 index 0de8358c8..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/Predicates.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -public class Predicates { - private static class IntegerPropertyEqualsPredicate implements IPredicate { - private int mExpected; - - public IntegerPropertyEqualsPredicate(Integer expected) { - mExpected = expected.intValue(); - } - - @Override - public boolean apply(Object value) { - return value instanceof Integer && ((Integer) value).intValue() == mExpected; - } - } - - public static IPredicate matchesInteger(int expected) { - return new IntegerPropertyEqualsPredicate(expected); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/PropertyChangeTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/PropertyChangeTransform.java deleted file mode 100644 index 276f6f49b..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/PropertyChangeTransform.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * A PropertyChangeTransform object provides the ability to alter the value of a - * single GL State variable. An optional predicate provides the ability to perform - * the change only if the predicate succeeds. - */ -public class PropertyChangeTransform implements IStateTransform { - private final IGLPropertyAccessor mAccessor; - private final Object mNewValue; - private final IPredicate mPredicate; - private Object mOldValue; - - /** - * Construct a state transform that will extract the property using the accessor, - * and modify its value to the provided value. - */ - PropertyChangeTransform(IGLPropertyAccessor accessor, Object newValue) { - this(accessor, newValue, null); - } - - /** - * Construct a state transform that will extract the property using the accessor, - * check if the predicate function accepts the current value, and if so modify its - * value to the provided value. - */ - public PropertyChangeTransform(IGLPropertyAccessor accessor, Object newValue, - IPredicate predicate) { - mAccessor = accessor; - mNewValue = newValue; - mPredicate = predicate; - mOldValue = null; - } - - /** Apply the state transformation on the given OpenGL state. */ - @Override - public void apply(IGLProperty state) { - IGLProperty property = mAccessor.getProperty(state); - - assert mOldValue == null : "Transform cannot be applied multiple times"; - if (mPredicate != null) { - // if predicate is not null, then first check if the current value - // passes the predicate function. - if (!mPredicate.apply(property.getValue())) { - return; - } - } - - if (property != null) { - mOldValue = property.getValue(); - property.setValue(mNewValue); - } else { - throw new RuntimeException("No such property: " + mAccessor.getPath()); - } - } - - /** - * Reverses the effect of this state transform. It restores the property's value to the same - * state as it was before this transformation was applied. If this transform was never - * {@link #apply(IGLProperty)}'ed, then performing a revert has no effect. - */ - @Override - public void revert(IGLProperty state) { - if (mOldValue != null) { - IGLProperty property = mAccessor.getProperty(state); - property.setValue(mOldValue); - mOldValue = null; - } - } - - /** Gets the property that will be affected by applying this transformation. */ - @Override - public IGLProperty getChangedProperty(IGLProperty state) { - if (mPredicate != null) { - Object value = mOldValue == null ? mNewValue : mOldValue; - if (!mPredicate.apply(value)) { - // if the value doesn't match the predicate, then this property - // is not altered. - return null; - } - } - - return mAccessor.getProperty(state); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java deleted file mode 100644 index b7547bc9a..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.GLSparseArrayProperty; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * A {@link SparseArrayElementAddTransform} changes given state by adding an - * element to a sparse array, if there is no item with the same key already. - */ -public class SparseArrayElementAddTransform implements IStateTransform { - private IGLPropertyAccessor mAccessor; - private int mKey; - private IGLProperty mOldValue; - - public SparseArrayElementAddTransform(IGLPropertyAccessor accessor, int key) { - mAccessor = accessor; - mKey = key; - } - - @Override - public void apply(IGLProperty currentState) { - GLSparseArrayProperty propertyArray = getArray(currentState); - if (propertyArray != null) { - mOldValue = propertyArray.getProperty(mKey); - if (mOldValue == null) { - // add only if there is no item with this key already present - propertyArray.add(mKey); - } - } - } - - @Override - public void revert(IGLProperty currentState) { - GLSparseArrayProperty propertyArray = getArray(currentState); - if (propertyArray != null) { - if (mOldValue == null) { - // delete only if we actually added this key - propertyArray.delete(mKey); - } - } - } - - @Override - public IGLProperty getChangedProperty(IGLProperty currentState) { - return getArray(currentState); - } - - private GLSparseArrayProperty getArray(IGLProperty state) { - IGLProperty p = state; - - if (mAccessor != null) { - p = mAccessor.getProperty(p); - } - - if (p instanceof GLSparseArrayProperty) { - return (GLSparseArrayProperty) p; - } else { - return null; - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementRemoveTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementRemoveTransform.java deleted file mode 100644 index c1ff211bd..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementRemoveTransform.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * A {@link SparseArrayElementRemoveTransform} changes given state by removing an - * element from a sparse array. - */ -public class SparseArrayElementRemoveTransform implements IStateTransform { - private final SparseArrayElementAddTransform mAddTransform; - - public SparseArrayElementRemoveTransform(IGLPropertyAccessor accessor, int key) { - mAddTransform = new SparseArrayElementAddTransform(accessor, key); - } - - @Override - public void apply(IGLProperty currentState) { - // applying a RemoveTransform is the same as reverting an AddTransform. - mAddTransform.revert(currentState); - } - - @Override - public void revert(IGLProperty currentState) { - // reverting a RemoveTransform is the same as applying an AddTransform. - mAddTransform.apply(currentState); - } - - @Override - public IGLProperty getChangedProperty(IGLProperty currentState) { - return mAddTransform.getChangedProperty(currentState); - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java deleted file mode 100644 index 023f84b6a..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java +++ /dev/null @@ -1,1384 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.FileUtils; -import com.android.ide.eclipse.gltrace.GLEnum; -import com.android.ide.eclipse.gltrace.GLProtoBuf.GLMessage; -import com.android.ide.eclipse.gltrace.state.GLState; -import com.android.ide.eclipse.gltrace.state.GLStateType; -import com.android.ide.eclipse.gltrace.state.IGLProperty; -import com.google.common.io.Files; -import com.google.protobuf.ByteString; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; - -public class StateTransformFactory { - private static final String TEXTURE_DATA_FILE_PREFIX = "tex"; //$NON-NLS-1$ - private static final String TEXTURE_DATA_FILE_SUFFIX = ".dat"; //$NON-NLS-1$ - private static EnumSet<GLEnum> sTexParameterPnameValues; - - /** Construct a list of transformations to be applied for the provided OpenGL call. */ - public static List<IStateTransform> getTransformsFor(GLMessage msg) { - switch (msg.getFunction()) { - case eglCreateContext: - return transformsForEglCreateContext(msg); - case glBindFramebuffer: - return transformsForGlBindFramebuffer(msg); - - // vertex data - case glVertexAttribPointer: - return transformsForGlVertexAttribPointer(msg); - case glVertexAttrib1f: - case glVertexAttrib2f: - case glVertexAttrib3f: - case glVertexAttrib4f: - return transformsForGlVertexAttribxf(msg); - case glVertexAttrib1fv: - case glVertexAttrib2fv: - case glVertexAttrib3fv: - case glVertexAttrib4fv: - return transformsForGlVertexAttribxfv(msg); - case glEnableVertexAttribArray: - return transformsForGlEnableVertexAttribArray(msg); - case glDisableVertexAttribArray: - return transformsForGlDisableVertexAttribArray(msg); - - // VBO's - case glBindBuffer: - return transformsForGlBindBuffer(msg); - case glGenBuffers: - return transformsForGlGenBuffers(msg); - case glDeleteBuffers: - return transformsForGlDeleteBuffers(msg); - case glBufferData: - return transformsForGlBufferData(msg); - case glBufferSubData: - return transformsForGlBufferSubData(msg); - - // transformation state - case glViewport: - return transformsForGlViewport(msg); - case glDepthRangef: - return transformsForGlDepthRangef(msg); - - // rasterization - case glLineWidth: - return transformsForGlLineWidth(msg); - case glCullFace: - return transformsForGlCullFace(msg); - case glFrontFace: - return transformsForGlFrontFace(msg); - case glPolygonOffset: - return transformsForGlPolygonOffset(msg); - - // pixel operations - case glScissor: - return transformsForGlScissor(msg); - case glStencilFunc: - return transformsForGlStencilFunc(msg); - case glStencilFuncSeparate: - return transformsForGlStencilFuncSeparate(msg); - case glStencilOp: - return transformsForGlStencilOp(msg); - case glStencilOpSeparate: - return transformsForGlStencilOpSeparate(msg); - case glDepthFunc: - return transformsForGlDepthFunc(msg); - case glBlendEquation: - return transformsForGlBlendEquation(msg); - case glBlendEquationSeparate: - return transformsForGlBlendEquationSeparate(msg); - case glBlendFunc: - return transformsForGlBlendFunc(msg); - case glBlendFuncSeparate: - return transformsForGlBlendFuncSeparate(msg); - case glPixelStorei: - return transformsForGlPixelStorei(msg); - - // Texture State Transformations - case glGenTextures: - return transformsForGlGenTextures(msg); - case glDeleteTextures: - return transformsForGlDeleteTextures(msg); - case glActiveTexture: - return transformsForGlActiveTexture(msg); - case glBindTexture: - return transformsForGlBindTexture(msg); - case glTexImage2D: - return transformsForGlTexImage2D(msg); - case glTexSubImage2D: - return transformsForGlTexSubImage2D(msg); - case glTexParameteri: - return transformsForGlTexParameter(msg); - - // Program State Transformations - case glCreateProgram: - return transformsForGlCreateProgram(msg); - case glUseProgram: - return transformsForGlUseProgram(msg); - case glAttachShader: - return transformsForGlAttachShader(msg); - case glDetachShader: - return transformsForGlDetachShader(msg); - case glGetActiveAttrib: - return transformsForGlGetActiveAttrib(msg); - case glGetActiveUniform: - return transformsForGlGetActiveUniform(msg); - case glUniform1i: - case glUniform2i: - case glUniform3i: - case glUniform4i: - return transformsForGlUniform(msg, false); - case glUniform1f: - case glUniform2f: - case glUniform3f: - case glUniform4f: - return transformsForGlUniform(msg, true); - case glUniform1iv: - case glUniform2iv: - case glUniform3iv: - case glUniform4iv: - return transformsForGlUniformv(msg, false); - case glUniform1fv: - case glUniform2fv: - case glUniform3fv: - case glUniform4fv: - return transformsForGlUniformv(msg, true); - case glUniformMatrix2fv: - case glUniformMatrix3fv: - case glUniformMatrix4fv: - return transformsForGlUniformMatrix(msg); - - // Shader State Transformations - case glCreateShader: - return transformsForGlCreateShader(msg); - case glDeleteShader: - return transformsForGlDeleteShader(msg); - case glShaderSource: - return transformsForGlShaderSource(msg); - default: - return Collections.emptyList(); - } - } - - private static List<IStateTransform> transformsForGlVertexAttribPointer(GLMessage msg) { - int index = msg.getArgs(0).getIntValue(0); - - int size = msg.getArgs(1).getIntValue(0); - int type = msg.getArgs(2).getIntValue(0); - boolean normalized = msg.getArgs(3).getBoolValue(0); - int stride = msg.getArgs(4).getIntValue(0); - - long pointer; - if (msg.getArgs(5).getIntValueCount() > 0) { - pointer = msg.getArgs(5).getIntValue(0); - } else { - pointer = msg.getArgs(5).getInt64Value(0); - } - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_SIZE), - Integer.valueOf(size))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_TYPE), - GLEnum.valueOf(type))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_NORMALIZED), - Boolean.valueOf(normalized))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_STRIDE), - Integer.valueOf(stride))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_POINTER), - Long.valueOf(pointer))); - return transforms; - } - - private static List<IStateTransform> transformsForGlVertexAttrib(int context, - int index, float v0, float v1, float v2, float v3) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>(4); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(context, - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.GENERIC_VERTEX_ATTRIBUTES, - Integer.valueOf(index), - GLStateType.GENERIC_VERTEX_ATTRIB_V0), - Float.valueOf(v0))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(context, - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.GENERIC_VERTEX_ATTRIBUTES, - Integer.valueOf(index), - GLStateType.GENERIC_VERTEX_ATTRIB_V1), - Float.valueOf(v1))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(context, - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.GENERIC_VERTEX_ATTRIBUTES, - Integer.valueOf(index), - GLStateType.GENERIC_VERTEX_ATTRIB_V2), - Float.valueOf(v2))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(context, - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.GENERIC_VERTEX_ATTRIBUTES, - Integer.valueOf(index), - GLStateType.GENERIC_VERTEX_ATTRIB_V3), - Float.valueOf(v3))); - return transforms; - } - - private static List<IStateTransform> transformsForGlVertexAttribxf(GLMessage msg) { - // void glVertexAttrib1f(GLuint index, GLfloat v0); - // void glVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); - // void glVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); - // void glVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); - - int index = msg.getArgs(0).getIntValue(0); - float v0 = msg.getArgs(1).getFloatValue(0); - float v1 = msg.getArgsCount() > 2 ? msg.getArgs(2).getFloatValue(0) : 0; - float v2 = msg.getArgsCount() > 3 ? msg.getArgs(3).getFloatValue(0) : 0; - float v3 = msg.getArgsCount() > 4 ? msg.getArgs(4).getFloatValue(0) : 0; - - return transformsForGlVertexAttrib(msg.getContextId(), index, v0, v1, v2, v3); - } - - private static List<IStateTransform> transformsForGlVertexAttribxfv(GLMessage msg) { - // void glVertexAttrib1fv(GLuint index, const GLfloat *v); - // void glVertexAttrib2fv(GLuint index, const GLfloat *v); - // void glVertexAttrib3fv(GLuint index, const GLfloat *v); - // void glVertexAttrib4fv(GLuint index, const GLfloat *v); - - int index = msg.getArgs(0).getIntValue(0); - float v[] = new float[4]; - - for (int i = 0; i < msg.getArgs(1).getFloatValueList().size(); i++) { - v[i] = msg.getArgs(1).getFloatValue(i); - } - - return transformsForGlVertexAttrib(msg.getContextId(), index, v[0], v[1], v[2], v[3]); - } - - private static List<IStateTransform> transformsForGlEnableVertexAttribArray(GLMessage msg) { - // void glEnableVertexAttribArray(GLuint index); - // void glDisableVertexAttribArray(GLuint index); - - int index = msg.getArgs(0).getIntValue(0); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_ENABLED), - Boolean.TRUE); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlDisableVertexAttribArray(GLMessage msg) { - // void glEnableVertexAttribArray(GLuint index); - // void glDisableVertexAttribArray(GLuint index); - - int index = msg.getArgs(0).getIntValue(0); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VERTEX_ATTRIB_ARRAY, - Integer.valueOf(index), - GLStateType.VERTEX_ATTRIB_ARRAY_ENABLED), - Boolean.FALSE); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlBindBuffer(GLMessage msg) { - // void glBindBuffer(GLenum target, GLuint buffer); - // target is one of GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER. - - GLEnum target = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - int buffer = msg.getArgs(1).getIntValue(0); - GLStateType bufferType; - - if (target == GLEnum.GL_ARRAY_BUFFER) { - bufferType = GLStateType.ARRAY_BUFFER_BINDING; - } else { - bufferType = GLStateType.ELEMENT_ARRAY_BUFFER_BINDING; - } - - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.BUFFER_BINDINGS, - bufferType), - Integer.valueOf(buffer)); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlGenBuffers(GLMessage msg) { - // void glGenBuffers(GLsizei n, GLuint * buffers); - int n = msg.getArgs(0).getIntValue(0); - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - - for (int i = 0; i < n; i++) { - transforms.add(new SparseArrayElementAddTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VBO), - msg.getArgs(1).getIntValue(i))); - } - - return transforms; - } - - private static List<IStateTransform> transformsForGlDeleteBuffers(GLMessage msg) { - // void glDeleteBuffers(GLsizei n, const GLuint * buffers); - int n = msg.getArgs(0).getIntValue(0); - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - - for (int i = 0; i < n; i++) { - transforms.add(new SparseArrayElementRemoveTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.VERTEX_ARRAY_DATA, - GLStateType.VBO), - msg.getArgs(1).getIntValue(i))); - } - - return transforms; - } - - private static List<IStateTransform> transformsForGlBufferData(GLMessage msg) { - // void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); - GLEnum target = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - int size = msg.getArgs(1).getIntValue(0); - byte[] data = null; - GLEnum usage = GLEnum.valueOf(msg.getArgs(3).getIntValue(0)); - - if (msg.getArgs(2).getRawBytesList().size() > 0) { - data = msg.getArgs(2).getRawBytesList().get(0).toByteArray(); - } else { - data = new byte[size]; - } - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - - transforms.add(new PropertyChangeTransform( - new CurrentVboPropertyAccessor(msg.getContextId(), - target, - GLStateType.BUFFER_SIZE), - Integer.valueOf(size))); - transforms.add(new PropertyChangeTransform( - new CurrentVboPropertyAccessor(msg.getContextId(), - target, - GLStateType.BUFFER_DATA), - data)); - transforms.add(new PropertyChangeTransform( - new CurrentVboPropertyAccessor(msg.getContextId(), - target, - GLStateType.BUFFER_USAGE), - usage)); - transforms.add(new PropertyChangeTransform( - new CurrentVboPropertyAccessor(msg.getContextId(), - target, - GLStateType.BUFFER_TYPE), - target)); - return transforms; - } - - private static List<IStateTransform> transformsForGlBufferSubData(GLMessage msg) { - // void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); - GLEnum target = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - int offset = msg.getArgs(1).getIntValue(0); - byte[] data = msg.getArgs(3).getRawBytesList().get(0).toByteArray(); - - IStateTransform transform = new BufferSubDataTransform( - new CurrentVboPropertyAccessor(msg.getContextId(), - target, - GLStateType.BUFFER_DATA), - offset, data); - - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlBindFramebuffer(GLMessage msg) { - // void glBindFramebuffer(GLenum target, GLuint framebuffer); - int fb = msg.getArgs(1).getIntValue(0); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.FRAMEBUFFER_STATE, - GLStateType.FRAMEBUFFER_BINDING), - fb); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlLineWidth(GLMessage msg) { - // void glLineWidth(GLfloat width); - float width = msg.getArgs(0).getFloatValue(0); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.RASTERIZATION_STATE, - GLStateType.LINE_WIDTH), - width); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlCullFace(GLMessage msg) { - // void glCullFace(GLenum mode); - int mode = msg.getArgs(0).getIntValue(0); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.RASTERIZATION_STATE, - GLStateType.CULL_FACE_MODE), - GLEnum.valueOf(mode)); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlFrontFace(GLMessage msg) { - // void glFrontFace(GLenum mode); - int mode = msg.getArgs(0).getIntValue(0); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.RASTERIZATION_STATE, - GLStateType.FRONT_FACE), - GLEnum.valueOf(mode)); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlPolygonOffset(GLMessage msg) { - // void glPolygonOffset(GLfloat factor, GLfloat units) - float factor = msg.getArgs(0).getFloatValue(0); - float units = msg.getArgs(1).getFloatValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.RASTERIZATION_STATE, - GLStateType.POLYGON_OFFSET_FACTOR), - Float.valueOf(factor))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.RASTERIZATION_STATE, - GLStateType.POLYGON_OFFSET_UNITS), - Float.valueOf(units))); - return transforms; - } - - private static List<IStateTransform> transformsForGlScissor(GLMessage msg) { - // void glScissor(GLint x, GLint y, GLsizei width, GLsizei height); - int x = msg.getArgs(0).getIntValue(0); - int y = msg.getArgs(1).getIntValue(0); - int w = msg.getArgs(2).getIntValue(0); - int h = msg.getArgs(3).getIntValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_OPERATIONS, - GLStateType.SCISSOR_BOX, - GLStateType.SCISSOR_BOX_X), - Integer.valueOf(x))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_OPERATIONS, - GLStateType.SCISSOR_BOX, - GLStateType.SCISSOR_BOX_Y), - Integer.valueOf(y))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_OPERATIONS, - GLStateType.SCISSOR_BOX, - GLStateType.SCISSOR_BOX_WIDTH), - Integer.valueOf(w))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_OPERATIONS, - GLStateType.SCISSOR_BOX, - GLStateType.SCISSOR_BOX_HEIGHT), - Integer.valueOf(h))); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilFuncFront(int contextId, - GLEnum func, int ref, int mask) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_FUNC), - func)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_REF), - Integer.valueOf(ref))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_VALUE_MASK), - Integer.valueOf(mask))); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilFuncBack(int contextId, - GLEnum func, int ref, int mask) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_BACK_FUNC), - func)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_BACK_REF), - Integer.valueOf(ref))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_BACK_VALUE_MASK), - Integer.valueOf(mask))); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilFunc(GLMessage msg) { - // void glStencilFunc(GLenum func, GLint ref, GLuint mask); - GLEnum func = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - int ref = msg.getArgs(1).getIntValue(0); - int mask = msg.getArgs(2).getIntValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.addAll(transformsForGlStencilFuncFront(msg.getContextId(), func, ref, mask)); - transforms.addAll(transformsForGlStencilFuncBack(msg.getContextId(), func, ref, mask)); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilFuncSeparate(GLMessage msg) { - // void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask); - GLEnum face = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum func = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - int ref = msg.getArgs(2).getIntValue(0); - int mask = msg.getArgs(3).getIntValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - if (face == GLEnum.GL_FRONT || face == GLEnum.GL_FRONT_AND_BACK) { - transforms.addAll( - transformsForGlStencilFuncFront(msg.getContextId(), func, ref, mask)); - } - if (face == GLEnum.GL_BACK || face == GLEnum.GL_FRONT_AND_BACK) { - transforms.addAll( - transformsForGlStencilFuncBack(msg.getContextId(), func, ref, mask)); - } - - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilOpFront(int contextId, - GLEnum sfail, GLEnum dpfail, GLEnum dppass) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_FAIL), - sfail)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_PASS_DEPTH_FAIL), - dpfail)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_PASS_DEPTH_PASS), - dppass)); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilOpBack(int contextId, - GLEnum sfail, GLEnum dpfail, GLEnum dppass) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_BACK_FAIL), - sfail)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_BACK_PASS_DEPTH_FAIL), - dpfail)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.STENCIL, - GLStateType.STENCIL_BACK_PASS_DEPTH_PASS), - dppass)); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilOp(GLMessage msg) { - // void glStencilOp(GLenum sfail, GLenum dpfail, GLenum dppass); - GLEnum sfail = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum dpfail = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - GLEnum dppass = GLEnum.valueOf(msg.getArgs(2).getIntValue(0)); - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.addAll( - transformsForGlStencilOpFront(msg.getContextId(), sfail, dpfail, dppass)); - transforms.addAll( - transformsForGlStencilOpBack(msg.getContextId(), sfail, dpfail, dppass)); - return transforms; - } - - private static List<IStateTransform> transformsForGlStencilOpSeparate(GLMessage msg) { - // void glStencilOp(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); - GLEnum face = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum sfail = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - GLEnum dpfail = GLEnum.valueOf(msg.getArgs(2).getIntValue(0)); - GLEnum dppass = GLEnum.valueOf(msg.getArgs(3).getIntValue(0)); - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - - if (face == GLEnum.GL_FRONT || face == GLEnum.GL_FRONT_AND_BACK) { - transforms.addAll( - transformsForGlStencilOpFront(msg.getContextId(), sfail, dpfail, dppass)); - } - - if (face == GLEnum.GL_BACK || face == GLEnum.GL_FRONT_AND_BACK) { - transforms.addAll( - transformsForGlStencilOpBack(msg.getContextId(), sfail, dpfail, dppass)); - } - - return transforms; - } - - private static List<IStateTransform> transformsForGlDepthFunc(GLMessage msg) { - // void glDepthFunc(GLenum func); - GLEnum func = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_OPERATIONS, - GLStateType.DEPTH_FUNC), - func); - return Collections.singletonList(transform); - } - - private static IStateTransform transformForGlEquationRGB(int contextId, GLEnum mode) { - return new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.BLEND, - GLStateType.BLEND_EQUATION_RGB), - mode); - } - - private static IStateTransform transformForGlEquationAlpha(int contextId, GLEnum mode) { - return new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.BLEND, - GLStateType.BLEND_EQUATION_ALPHA), - mode); - } - - private static List<IStateTransform> transformsForGlBlendEquationSeparate(GLMessage msg) { - // void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha); - GLEnum rgb = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum alpha = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(transformForGlEquationRGB(msg.getContextId(), rgb)); - transforms.add(transformForGlEquationAlpha(msg.getContextId(), alpha)); - return transforms; - } - - private static List<IStateTransform> transformsForGlBlendEquation(GLMessage msg) { - // void glBlendEquation(GLenum mode); - GLEnum mode = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(transformForGlEquationRGB(msg.getContextId(), mode)); - transforms.add(transformForGlEquationAlpha(msg.getContextId(), mode)); - return transforms; - } - - private static List<IStateTransform> transformsForGlBlendFuncSrcDst(boolean src, - int contextId, GLEnum rgb, GLEnum alpha) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - - GLStateType rgbAccessor = GLStateType.BLEND_DST_RGB; - GLStateType alphaAccessor = GLStateType.BLEND_DST_ALPHA; - if (src) { - rgbAccessor = GLStateType.BLEND_SRC_RGB; - alphaAccessor = GLStateType.BLEND_SRC_ALPHA; - } - - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.BLEND, - rgbAccessor), - rgb)); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.PIXEL_OPERATIONS, - GLStateType.BLEND, - alphaAccessor), - alpha)); - return transforms; - } - - private static List<IStateTransform> transformsForGlBlendFuncSeparate(GLMessage msg) { - // void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) - GLEnum srcRgb = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum dstRgb = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - GLEnum srcAlpha = GLEnum.valueOf(msg.getArgs(2).getIntValue(0)); - GLEnum dstAlpha = GLEnum.valueOf(msg.getArgs(3).getIntValue(0)); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.addAll(transformsForGlBlendFuncSrcDst(true, - msg.getContextId(), srcRgb, srcAlpha)); - transforms.addAll(transformsForGlBlendFuncSrcDst(false, - msg.getContextId(), dstRgb, dstAlpha)); - return transforms; - } - - private static List<IStateTransform> transformsForGlBlendFunc(GLMessage msg) { - // void glBlendFunc(GLenum sfactor, GLenum dfactor); - GLEnum sfactor = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum dfactor = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.addAll(transformsForGlBlendFuncSrcDst(true, - msg.getContextId(), sfactor, sfactor)); - transforms.addAll(transformsForGlBlendFuncSrcDst(false, - msg.getContextId(), dfactor, dfactor)); - return transforms; - } - - private static List<IStateTransform> transformsForGlPixelStorei(GLMessage msg) { - // void glPixelStorei(GLenum pname, GLint param); - GLEnum pname = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - Integer param = Integer.valueOf(msg.getArgs(1).getIntValue(0)); - - IStateTransform transform; - if (pname == GLEnum.GL_PACK_ALIGNMENT) { - transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_PACKING, - GLStateType.PACK_ALIGNMENT), - param); - } else { - transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PIXEL_PACKING, - GLStateType.UNPACK_ALIGNMENT), - param); - } - - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlViewport(GLMessage msg) { - // void glViewport( GLint x, GLint y, GLsizei width, GLsizei height); - int x = msg.getArgs(0).getIntValue(0); - int y = msg.getArgs(1).getIntValue(0); - int w = msg.getArgs(2).getIntValue(0); - int h = msg.getArgs(3).getIntValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TRANSFORMATION_STATE, - GLStateType.VIEWPORT, - GLStateType.VIEWPORT_X), - Integer.valueOf(x))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TRANSFORMATION_STATE, - GLStateType.VIEWPORT, - GLStateType.VIEWPORT_Y), - Integer.valueOf(y))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TRANSFORMATION_STATE, - GLStateType.VIEWPORT, - GLStateType.VIEWPORT_WIDTH), - Integer.valueOf(w))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TRANSFORMATION_STATE, - GLStateType.VIEWPORT, - GLStateType.VIEWPORT_HEIGHT), - Integer.valueOf(h))); - return transforms; - } - - private static List<IStateTransform> transformsForGlDepthRangef(GLMessage msg) { - // void glDepthRangef(GLclampf nearVal, GLclampf farVal); - float near = msg.getArgs(0).getFloatValue(0); - float far = msg.getArgs(1).getFloatValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TRANSFORMATION_STATE, - GLStateType.DEPTH_RANGE, - GLStateType.DEPTH_RANGE_NEAR), - Float.valueOf(near))); - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TRANSFORMATION_STATE, - GLStateType.DEPTH_RANGE, - GLStateType.DEPTH_RANGE_FAR), - Float.valueOf(far))); - return transforms; - } - - private static List<IStateTransform> transformsForGlGenTextures(GLMessage msg) { - // void glGenTextures(GLsizei n, GLuint *textures); - int n = msg.getArgs(0).getIntValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - for (int i = 0; i < n; i++) { - int texture = msg.getArgs(1).getIntValue(i); - transforms.add(new SparseArrayElementAddTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TEXTURE_STATE, - GLStateType.TEXTURES), - texture)); - } - - return transforms; - } - - /** - * Obtain a list of transforms that will reset any existing texture units - * that are bound to provided texture. - * @param contextId context to operate on - * @param texture texture that should be unbound - */ - private static List<IStateTransform> transformsToResetBoundTextureUnits(int contextId, - int texture) { - List<IStateTransform> transforms = new ArrayList<IStateTransform>( - GLState.TEXTURE_UNIT_COUNT); - - for (int i = 0; i < GLState.TEXTURE_UNIT_COUNT; i++) { - transforms.add(new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(contextId, - GLStateType.TEXTURE_STATE, - GLStateType.TEXTURE_UNITS, - Integer.valueOf(i), - GLStateType.TEXTURE_BINDING_2D), - Integer.valueOf(0), /* reset binding to texture 0 */ - Predicates.matchesInteger(texture) /* only if currently bound to @texture */ )); - } - return transforms; - } - - private static List<IStateTransform> transformsForGlDeleteTextures(GLMessage msg) { - // void glDeleteTextures(GLsizei n, const GLuint * textures); - int n = msg.getArgs(0).getIntValue(0); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(n); - for (int i = 0; i < n; i++) { - int texture = msg.getArgs(1).getIntValue(i); - transforms.add(new SparseArrayElementRemoveTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TEXTURE_STATE, - GLStateType.TEXTURES), - texture)); - transforms.addAll(transformsToResetBoundTextureUnits(msg.getContextId(), texture)); - } - - return transforms; - } - - private static List<IStateTransform> transformsForGlActiveTexture(GLMessage msg) { - // void glActiveTexture(GLenum texture); - GLEnum texture = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - Integer textureIndex = Integer.valueOf((int)(texture.value - GLEnum.GL_TEXTURE0.value)); - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.TEXTURE_STATE, - GLStateType.ACTIVE_TEXTURE_UNIT), - textureIndex); - return Collections.singletonList(transform); - } - - private static GLStateType getTextureUnitTargetName(GLEnum target) { - if (target == GLEnum.GL_TEXTURE_CUBE_MAP) { - return GLStateType.TEXTURE_BINDING_CUBE_MAP; - } else if (target == GLEnum.GL_TEXTURE_EXTERNAL) { - // added by OES_EGL_image_external - return GLStateType.TEXTURE_BINDING_EXTERNAL; - } else { - return GLStateType.TEXTURE_BINDING_2D; - } - } - - private static GLStateType getTextureTargetName(GLEnum pname) { - switch (pname) { - case GL_TEXTURE_MIN_FILTER: - return GLStateType.TEXTURE_MIN_FILTER; - case GL_TEXTURE_MAG_FILTER: - return GLStateType.TEXTURE_MAG_FILTER; - case GL_TEXTURE_WRAP_S: - return GLStateType.TEXTURE_WRAP_S; - case GL_TEXTURE_WRAP_T: - return GLStateType.TEXTURE_WRAP_T; - } - - assert false : "glTexParameter's pname argument does not support provided value."; - return GLStateType.TEXTURE_MIN_FILTER; - } - - private static List<IStateTransform> transformsForGlBindTexture(GLMessage msg) { - // void glBindTexture(GLenum target, GLuint texture); - GLEnum target = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - Integer texture = Integer.valueOf(msg.getArgs(1).getIntValue(0)); - - IStateTransform transform = new PropertyChangeTransform( - new TextureUnitPropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target)), - texture); - return Collections.singletonList(transform); - } - - /** - * Utility function used by both {@link #transformsForGlTexImage2D(GLMessage) and - * {@link #transformsForGlTexSubImage2D(GLMessage)}. - */ - private static List<IStateTransform> transformsForGlTexImage(GLMessage msg, int widthArgIndex, - int heightArgIndex, int xOffsetIndex, int yOffsetIndex) { - GLEnum target = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - int level = msg.getArgs(1).getIntValue(0); - Integer width = Integer.valueOf(msg.getArgs(widthArgIndex).getIntValue(0)); - Integer height = Integer.valueOf(msg.getArgs(heightArgIndex).getIntValue(0)); - GLEnum format = GLEnum.valueOf(msg.getArgs(6).getIntValue(0)); - GLEnum type = GLEnum.valueOf(msg.getArgs(7).getIntValue(0)); - - List<IStateTransform> transforms = new ArrayList<IStateTransform>(); - transforms.add(new PropertyChangeTransform( - new TexturePropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target), - level, - GLStateType.TEXTURE_WIDTH), - width)); - transforms.add(new PropertyChangeTransform( - new TexturePropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target), - level, - GLStateType.TEXTURE_HEIGHT), - height)); - transforms.add(new PropertyChangeTransform( - new TexturePropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target), - level, - GLStateType.TEXTURE_FORMAT), - format)); - transforms.add(new PropertyChangeTransform( - new TexturePropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target), - level, - GLStateType.TEXTURE_IMAGE_TYPE), - type)); - - // if texture data is available, extract and store it in the cache folder - File f = null; - if (msg.getArgs(8).getIsArray()) { - ByteString data = msg.getArgs(8).getRawBytes(0); - f = FileUtils.createTempFile(TEXTURE_DATA_FILE_PREFIX, TEXTURE_DATA_FILE_SUFFIX); - try { - Files.write(data.toByteArray(), f); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - int xOffset = 0; - int yOffset = 0; - - if (xOffsetIndex >= 0) { - xOffset = msg.getArgs(xOffsetIndex).getIntValue(0); - } - - if (yOffsetIndex >= 0) { - yOffset = msg.getArgs(yOffsetIndex).getIntValue(0); - } - - transforms.add(new TexImageTransform( - new TexturePropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target), - level, - GLStateType.TEXTURE_IMAGE), - f, format, type, xOffset, yOffset, width, height)); - - return transforms; - } - - private static List<IStateTransform> transformsForGlTexImage2D(GLMessage msg) { - // void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, - // GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data); - return transformsForGlTexImage(msg, 3, 4, -1, -1); - } - - private static List<IStateTransform> transformsForGlTexSubImage2D(GLMessage msg) { - // void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, - // GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data); - return transformsForGlTexImage(msg, 4, 5, 2, 3); - } - - private static List<IStateTransform> transformsForGlTexParameter(GLMessage msg) { - // void glTexParameteri(GLenum target, GLenum pname, GLint param); - GLEnum target = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - GLEnum pname = GLEnum.valueOf(msg.getArgs(1).getIntValue(0)); - GLEnum pvalue = GLEnum.valueOf(msg.getArgs(2).getIntValue(0)); - - if (sTexParameterPnameValues == null) { - GLEnum[] pnameValues = new GLEnum[] { - GLEnum.GL_TEXTURE_BASE_LEVEL, - GLEnum.GL_TEXTURE_COMPARE_FUNC, - GLEnum.GL_TEXTURE_COMPARE_MODE, - GLEnum.GL_TEXTURE_MIN_FILTER, - GLEnum.GL_TEXTURE_MAG_FILTER, - GLEnum.GL_TEXTURE_MIN_LOD, - GLEnum.GL_TEXTURE_MAX_LOD, - GLEnum.GL_TEXTURE_MAX_LEVEL, - GLEnum.GL_TEXTURE_SWIZZLE_R, - GLEnum.GL_TEXTURE_SWIZZLE_G, - GLEnum.GL_TEXTURE_SWIZZLE_B, - GLEnum.GL_TEXTURE_SWIZZLE_A, - GLEnum.GL_TEXTURE_WRAP_S, - GLEnum.GL_TEXTURE_WRAP_T, - GLEnum.GL_TEXTURE_WRAP_R - }; - sTexParameterPnameValues = EnumSet.copyOf(Arrays.asList(pnameValues)); - } - - if (!sTexParameterPnameValues.contains(pname)) { - throw new IllegalArgumentException( - String.format("Unsupported parameter (%s) for glTexParameter()", pname)); - } - - IStateTransform transform = new PropertyChangeTransform( - new TexturePropertyAccessor(msg.getContextId(), - getTextureUnitTargetName(target), - getTextureTargetName(pname)), - pvalue); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlCreateProgram(GLMessage msg) { - // GLuint glCreateProgram(void); - int program = msg.getReturnValue().getIntValue(0); - - IStateTransform transform = new SparseArrayElementAddTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS), - program); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlUseProgram(GLMessage msg) { - // void glUseProgram(GLuint program); - Integer program = Integer.valueOf(msg.getArgs(0).getIntValue(0)); - - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.CURRENT_PROGRAM), - program); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlAttachShader(GLMessage msg) { - // void glAttachShader(GLuint program, GLuint shader); - int program = msg.getArgs(0).getIntValue(0); - int shader = msg.getArgs(1).getIntValue(0); - - IStateTransform transform = new SparseArrayElementAddTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - Integer.valueOf(program), - GLStateType.ATTACHED_SHADERS), - Integer.valueOf(shader)); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlDetachShader(GLMessage msg) { - // void glDetachShader(GLuint program, GLuint shader); - int program = msg.getArgs(0).getIntValue(0); - int shader = msg.getArgs(1).getIntValue(0); - - IStateTransform transform = new SparseArrayElementRemoveTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - Integer.valueOf(program), - GLStateType.ATTACHED_SHADERS), - Integer.valueOf(shader)); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlGetActiveAttribOrUniform( - GLMessage msg, boolean isAttrib) { - // void glGetActive[Attrib|Uniform](GLuint program, GLuint index, GLsizei bufsize, - // GLsizei* length, GLint* size, GLenum* type, GLchar* name); - int program = msg.getArgs(0).getIntValue(0); - int size = msg.getArgs(4).getIntValue(0); - GLEnum type = GLEnum.valueOf(msg.getArgs(5).getIntValue(0)); - String name = msg.getArgs(6).getCharValue(0).toStringUtf8(); - - // The 2nd argument (index) does not give the correct location of the - // attribute/uniform in device. The actual location is obtained from - // the getAttribLocation or getUniformLocation calls. The trace library - // appends this value as an additional last argument to this call. - int location = msg.getArgs(7).getIntValue(0); - - GLStateType activeInput; - GLStateType inputName; - GLStateType inputType; - GLStateType inputSize; - - if (isAttrib) { - activeInput = GLStateType.ACTIVE_ATTRIBUTES; - inputName = GLStateType.ATTRIBUTE_NAME; - inputType = GLStateType.ATTRIBUTE_TYPE; - inputSize = GLStateType.ATTRIBUTE_SIZE; - } else { - activeInput = GLStateType.ACTIVE_UNIFORMS; - inputName = GLStateType.UNIFORM_NAME; - inputType = GLStateType.UNIFORM_TYPE; - inputSize = GLStateType.UNIFORM_SIZE; - } - - IStateTransform addAttribute = new SparseArrayElementAddTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - Integer.valueOf(program), - activeInput), - Integer.valueOf(location)); - IStateTransform setAttributeName = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - Integer.valueOf(program), - activeInput, - Integer.valueOf(location), - inputName), - name); - IStateTransform setAttributeType = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - Integer.valueOf(program), - activeInput, - Integer.valueOf(location), - inputType), - type); - IStateTransform setAttributeSize = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.PROGRAM_STATE, - GLStateType.PROGRAMS, - Integer.valueOf(program), - activeInput, - Integer.valueOf(location), - inputSize), - Integer.valueOf(size)); - return Arrays.asList(addAttribute, setAttributeName, setAttributeType, setAttributeSize); - } - - private static List<IStateTransform> transformsForGlGetActiveAttrib(GLMessage msg) { - return transformsForGlGetActiveAttribOrUniform(msg, true); - } - - private static List<IStateTransform> transformsForGlGetActiveUniform(GLMessage msg) { - return transformsForGlGetActiveAttribOrUniform(msg, false); - } - - private static List<IStateTransform> transformsForGlUniformMatrix(GLMessage msg) { - // void glUniformMatrix[2|3|4]fv(GLint location, GLsizei count, GLboolean transpose, - // const GLfloat *value); - int location = msg.getArgs(0).getIntValue(0); - List<Float> uniforms = msg.getArgs(3).getFloatValueList(); - - IStateTransform setValues = new PropertyChangeTransform( - new CurrentProgramPropertyAccessor(msg.getContextId(), - GLStateType.ACTIVE_UNIFORMS, - location, - GLStateType.UNIFORM_VALUE), - uniforms); - - return Collections.singletonList(setValues); - } - - private static List<IStateTransform> transformsForGlUniformv(GLMessage msg, boolean isFloats) { - // void glUniform1fv(GLint location, GLsizei count, const GLfloat *value); - int location = msg.getArgs(0).getIntValue(0); - List<?> uniforms; - if (isFloats) { - uniforms = msg.getArgs(2).getFloatValueList(); - } else { - uniforms = msg.getArgs(2).getIntValueList(); - } - - IStateTransform setValues = new PropertyChangeTransform( - new CurrentProgramPropertyAccessor(msg.getContextId(), - GLStateType.ACTIVE_UNIFORMS, - location, - GLStateType.UNIFORM_VALUE), - uniforms); - - return Collections.singletonList(setValues); - } - - private static List<IStateTransform> transformsForGlUniform(GLMessage msg, boolean isFloats) { - // void glUniform1f(GLint location, GLfloat v0); - // void glUniform2f(GLint location, GLfloat v0, GLfloat v1); - // .. 3f - // .. 4f - // void glUniform1i(GLint location, GLfloat v0); - // void glUniform2i(GLint location, GLfloat v0, GLfloat v1); - // .. 3i - // .. 4i - - int location = msg.getArgs(0).getIntValue(0); - if (location < 0) { - throw new IllegalArgumentException("Argument location cannot be less than 0."); - } - List<?> uniforms; - if (isFloats) { - List<Float> args = new ArrayList<Float>(msg.getArgsCount() - 1); - for (int i = 1; i < msg.getArgsCount(); i++) { - args.add(Float.valueOf(msg.getArgs(1).getFloatValue(0))); - } - uniforms = args; - } else { - List<Integer> args = new ArrayList<Integer>(msg.getArgsCount() - 1); - for (int i = 1; i < msg.getArgsCount(); i++) { - args.add(Integer.valueOf(msg.getArgs(1).getIntValue(0))); - } - uniforms = args; - } - - IStateTransform setValues = new PropertyChangeTransform( - new CurrentProgramPropertyAccessor(msg.getContextId(), - GLStateType.ACTIVE_UNIFORMS, - location, - GLStateType.UNIFORM_VALUE), - uniforms); - - return Collections.singletonList(setValues); - } - - private static List<IStateTransform> transformsForGlCreateShader(GLMessage msg) { - // GLuint glCreateShader(GLenum shaderType); - GLEnum shaderType = GLEnum.valueOf(msg.getArgs(0).getIntValue(0)); - int shader = msg.getReturnValue().getIntValue(0); - - IStateTransform addShader = new SparseArrayElementAddTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.SHADERS), - shader); - IStateTransform setShaderType = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.SHADERS, - Integer.valueOf(shader), - GLStateType.SHADER_TYPE), - shaderType); - return Arrays.asList(addShader, setShaderType); - } - - private static List<IStateTransform> transformsForGlDeleteShader(GLMessage msg) { - // void glDeleteShader(GLuint shader); - int shader = msg.getArgs(0).getIntValue(0); - - IStateTransform transform = new SparseArrayElementRemoveTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.SHADERS), - shader); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForGlShaderSource(GLMessage msg) { - // void glShaderSource(GLuint shader, GLsizei count, const GLchar **string, - // const GLint *length); - // This message is patched up on the device to return a single string as opposed to a - // list of strings - int shader = msg.getArgs(0).getIntValue(0); - String src = msg.getArgs(2).getCharValue(0).toStringUtf8(); - - IStateTransform transform = new PropertyChangeTransform( - GLPropertyAccessor.makeAccessor(msg.getContextId(), - GLStateType.SHADERS, - Integer.valueOf(shader), - GLStateType.SHADER_SOURCE), - src); - return Collections.singletonList(transform); - } - - private static List<IStateTransform> transformsForEglCreateContext(GLMessage msg) { - // void eglCreateContext(int version, int context); - int version = msg.getArgs(0).getIntValue(0); - IGLProperty glState = null; - if (version == 0) { - glState = GLState.createDefaultES1State(); - } else { - glState = GLState.createDefaultES2State(); - } - IStateTransform transform = new ListElementAddTransform(null, glState); - return Collections.singletonList(transform); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TexImageTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TexImageTransform.java deleted file mode 100644 index dde89eae6..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TexImageTransform.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.FileUtils; -import com.android.ide.eclipse.gltrace.GLEnum; -import com.android.ide.eclipse.gltrace.state.GLStringProperty; -import com.android.ide.eclipse.gltrace.state.IGLProperty; -import com.google.common.io.Files; -import com.google.common.primitives.UnsignedBytes; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; - -import javax.imageio.ImageIO; - -/** - * {@link TexImageTransform} transforms the state to reflect the effect of a - * glTexImage2D or glTexSubImage2D GL call. - */ -public class TexImageTransform implements IStateTransform { - private static final String PNG_IMAGE_FORMAT = "PNG"; - private static final String TEXTURE_FILE_PREFIX = "tex"; - private static final String TEXTURE_FILE_SUFFIX = ".png"; - - private final IGLPropertyAccessor mAccessor; - private final File mTextureDataFile; - - private final int mxOffset; - private final int myOffset; - private final int mWidth; - private final int mHeight; - - private String mOldValue; - private String mNewValue; - private GLEnum mFormat; - private GLEnum mType; - - /** - * Construct a texture image transformation. - * @param accessor accessor to obtain the GL state variable to modify - * @param textureData texture data passed in by the call. Could be null. - * @param format format of the source texture data - * @param xOffset x offset for the source data (used only in glTexSubImage2D) - * @param yOffset y offset for the source data (used only in glTexSubImage2D) - * @param width width of the texture - * @param height height of the texture - */ - public TexImageTransform(IGLPropertyAccessor accessor, File textureData, GLEnum format, - GLEnum type, int xOffset, int yOffset, int width, int height) { - mAccessor = accessor; - mTextureDataFile = textureData; - mFormat = format; - mType = type; - - mxOffset = xOffset; - myOffset = yOffset; - mWidth = width; - mHeight = height; - } - - @Override - public void apply(IGLProperty currentState) { - assert mOldValue == null : "Transform cannot be applied multiple times"; //$NON-NLS-1$ - - IGLProperty property = mAccessor.getProperty(currentState); - if (!(property instanceof GLStringProperty)) { - return; - } - - GLStringProperty prop = (GLStringProperty) property; - mOldValue = prop.getStringValue(); - - // Applying texture transformations is a heavy weight process. So we perform - // it only once and save the result in a temporary file. The property is actually - // the path to the file. - if (mNewValue == null) { - try { - if (mOldValue == null) { - mNewValue = createTexture(mTextureDataFile, mWidth, mHeight); - } else { - mNewValue = updateTextureData(mOldValue, mTextureDataFile, mxOffset, myOffset, - mWidth, mHeight); - } - } catch (IOException e) { - throw new RuntimeException(e); - } catch (RuntimeException e) { - throw e; - } - } - - prop.setValue(mNewValue); - } - - @Override - public void revert(IGLProperty state) { - if (mOldValue != null) { - IGLProperty property = mAccessor.getProperty(state); - property.setValue(mOldValue); - mOldValue = null; - } - } - - @Override - public IGLProperty getChangedProperty(IGLProperty state) { - return mAccessor.getProperty(state); - } - - /** - * Creates a texture of provided width and height. If the texture data file is provided, - * then the texture is initialized with the contents of that file, otherwise an empty - * image is created. - * @param textureDataFile path to texture data, could be null. - * @param width width of texture - * @param height height of texture - * @return path to cached texture - */ - private String createTexture(File textureDataFile, int width, int height) throws IOException { - File f = FileUtils.createTempFile(TEXTURE_FILE_PREFIX, TEXTURE_FILE_SUFFIX); - - BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); - - if (textureDataFile != null) { - byte[] initialData = Files.toByteArray(textureDataFile); - img.getRaster().setDataElements(0, 0, width, height, - formatSourceData(initialData, width, height)); - } - - ImageIO.write(img, PNG_IMAGE_FORMAT, f); - - return f.getAbsolutePath(); - } - - /** - * Update part of an existing texture. - * @param currentImagePath current texture image. - * @param textureDataFile new data to update the current texture with - * @param xOffset x offset for the update region - * @param yOffset y offset for the update region - * @param width width of the update region - * @param height height of the update region - * @return path to the updated texture - */ - private String updateTextureData(String currentImagePath, File textureDataFile, - int xOffset, int yOffset, int width, int height) throws IOException { - assert currentImagePath != null : "Attempt to update a null texture"; - - if (textureDataFile == null) { - // Do not perform any updates if we don't have the actual data. - return currentImagePath; - } - - File f = FileUtils.createTempFile(TEXTURE_FILE_PREFIX, TEXTURE_FILE_SUFFIX); - BufferedImage image = null; - image = ImageIO.read(new File(currentImagePath)); - - byte[] subImageData = Files.toByteArray(textureDataFile); - image.getRaster().setDataElements(xOffset, yOffset, width, height, - formatSourceData(subImageData, width, height)); - ImageIO.write(image, PNG_IMAGE_FORMAT, f); - - return f.getAbsolutePath(); - } - - private byte[] formatSourceData(byte[] subImageData, int width, int height) { - if (mType != GLEnum.GL_UNSIGNED_BYTE) { - subImageData = unpackData(subImageData, mType); - } - - switch (mFormat) { - case GL_RGBA: - // no conversions necessary - return subImageData; - case GL_RGB: - return addAlphaChannel(subImageData, width, height); - case GL_RED: - case GL_GREEN: - case GL_BLUE: - // GL_RED, GL_GREEN and GL_BLUE are all supposed to fill those respective - // channels, but we assume that the programmers intent was to use GL_ALPHA in order - // to overcome the issue that GL_ALPHA cannot be used with float data. - if (mType != GLEnum.GL_FLOAT) { - throw new RuntimeException(); - } else { - // fall through - assume that it is GL_ALPHA - } - //$FALL-THROUGH$ - case GL_ALPHA: - return addRGBChannels(subImageData, width, height); - case GL_LUMINANCE: - return createRGBAFromLuminance(subImageData, width, height); - case GL_LUMINANCE_ALPHA: - return createRGBAFromLuminanceAlpha(subImageData, width, height); - default: - throw new RuntimeException(); - } - } - - private byte[] unpackData(byte[] data, GLEnum type) { - switch (type) { - case GL_UNSIGNED_BYTE: - return data; - case GL_UNSIGNED_SHORT_4_4_4_4: - return convertShortToUnsigned(data, 0xf000, 12, 0x0f00, 8, 0x00f0, 4, 0x000f, 0, - true); - case GL_UNSIGNED_SHORT_5_6_5: - return convertShortToUnsigned(data, 0xf800, 11, 0x07e0, 5, 0x001f, 0, 0, 0, - false); - case GL_UNSIGNED_SHORT_5_5_5_1: - return convertShortToUnsigned(data, 0xf800, 11, 0x07c0, 6, 0x003e, 1, 0x1, 0, - true); - case GL_FLOAT: - return convertFloatToUnsigned(data); - default: - return data; - } - } - - private byte[] convertFloatToUnsigned(byte[] data) { - byte[] unsignedData = new byte[data.length]; - ByteBuffer floatBuffer = ByteBuffer.wrap(data); - for (int i = 0; i < data.length / 4; i++) { - float v = floatBuffer.getFloat(i); - byte alpha = (byte)(v * 255); - unsignedData[i*4 + 3] = alpha; - } - return unsignedData; - } - - private byte[] convertShortToUnsigned(byte[] shortData, - int rmask, int rshift, - int gmask, int gshift, - int bmask, int bshift, - int amask, int ashift, - boolean includeAlpha) { - int numChannels = includeAlpha ? 4 : 3; - byte[] unsignedData = new byte[(shortData.length/2) * numChannels]; - - for (int i = 0; i < (shortData.length / 2); i++) { - int hi = UnsignedBytes.toInt(shortData[i*2 + 0]); - int lo = UnsignedBytes.toInt(shortData[i*2 + 1]); - - int x = hi << 8 | lo; - - int r = (x & rmask) >>> rshift; - int g = (x & gmask) >>> gshift; - int b = (x & bmask) >>> bshift; - int a = (x & amask) >>> ashift; - - unsignedData[i * numChannels + 0] = UnsignedBytes.checkedCast(r); - unsignedData[i * numChannels + 1] = UnsignedBytes.checkedCast(g); - unsignedData[i * numChannels + 2] = UnsignedBytes.checkedCast(b); - - if (includeAlpha) { - unsignedData[i * numChannels + 3] = UnsignedBytes.checkedCast(a); - } - } - - return unsignedData; - } - - private byte[] addAlphaChannel(byte[] sourceData, int width, int height) { - assert sourceData.length == 3 * width * height; // should have R, G & B channels - - byte[] data = new byte[4 * width * height]; - - for (int src = 0, dst = 0; src < sourceData.length; src += 3, dst += 4) { - data[dst + 0] = sourceData[src + 0]; // copy R byte - data[dst + 1] = sourceData[src + 1]; // copy G byte - data[dst + 2] = sourceData[src + 2]; // copy B byte - data[dst + 3] = 1; // add alpha = 1 - } - - return data; - } - - private byte[] addRGBChannels(byte[] sourceData, int width, int height) { - assert sourceData.length == width * height; // should have a single alpha channel - - byte[] data = new byte[4 * width * height]; - - for (int src = 0, dst = 0; src < sourceData.length; src++, dst += 4) { - data[dst + 0] = data[dst + 1] = data[dst + 2] = 0; // set R = G = B = 0 - data[dst + 3] = sourceData[src]; // copy over alpha - } - - return data; - } - - private byte[] createRGBAFromLuminance(byte[] sourceData, int width, int height) { - assert sourceData.length == width * height; // should have a single luminance channel - - byte[] data = new byte[4 * width * height]; - - for (int src = 0, dst = 0; src < sourceData.length; src++, dst += 4) { - int l = sourceData[src] * 3; - if (l > 255) { // clamp to 255 - l = 255; - } - - data[dst + 0] = data[dst + 1] = data[dst + 2] = (byte) l; // set R = G = B = L * 3 - data[dst + 3] = 1; // set alpha = 1 - } - - return data; - } - - private byte[] createRGBAFromLuminanceAlpha(byte[] sourceData, int width, int height) { - assert sourceData.length == 2 * width * height; // should have luminance & alpha channels - - byte[] data = new byte[4 * width * height]; - - for (int src = 0, dst = 0; src < sourceData.length; src += 2, dst += 4) { - int l = sourceData[src] * 3; - if (l > 255) { // clamp to 255 - l = 255; - } - - data[dst + 0] = data[dst + 1] = data[dst + 2] = (byte) l; // set R = G = B = L * 3 - data[dst + 3] = sourceData[src + 1]; // copy over alpha - } - - return data; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TexturePropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TexturePropertyAccessor.java deleted file mode 100644 index 10758d819..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TexturePropertyAccessor.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.GLIntegerProperty; -import com.android.ide.eclipse.gltrace.state.GLStateType; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * The {@link TexturePropertyAccessor} provides the ability to access a - * texture property. Texture properties are accessed by first identifying the active - * texture unit ({@link GLStateType#ACTIVE_TEXTURE_UNIT}), and then identifying the texture - * that is bound to that unit. - */ -public class TexturePropertyAccessor implements IGLPropertyAccessor { - private final int mContextId; - private final GLStateType mTargetUnitType; - private final int mMipmapLevel; - private final GLStateType mTextureType; - private TextureUnitPropertyAccessor mTextureUnitPropertyAccessor; - - public TexturePropertyAccessor(int contextId, GLStateType textureUnitTarget, int level, - GLStateType textureTargetName) { - mContextId = contextId; - mTargetUnitType = textureUnitTarget; - mMipmapLevel = level; - mTextureType = textureTargetName; - mTextureUnitPropertyAccessor = new TextureUnitPropertyAccessor(mContextId, - mTargetUnitType); - } - - public TexturePropertyAccessor(int contextId, GLStateType textureUnitTarget, - GLStateType textureTargetName) { - this(contextId, textureUnitTarget, -1, textureTargetName); - } - - @Override - public IGLProperty getProperty(IGLProperty state) { - // identify the texture that is bound in the current active texture unit - IGLProperty targetTexture = mTextureUnitPropertyAccessor.getProperty(state); - if (!(targetTexture instanceof GLIntegerProperty)) { - return null; - } - Integer textureId = (Integer) targetTexture.getValue(); - - // now extract the required property from the selected texture - IGLPropertyAccessor textureAccessor; - if (mMipmapLevel >= 0) { - textureAccessor = GLPropertyAccessor.makeAccessor(mContextId, - GLStateType.TEXTURE_STATE, - GLStateType.TEXTURES, - textureId, - GLStateType.TEXTURE_MIPMAPS, - Integer.valueOf(mMipmapLevel), - mTextureType); - } else { - textureAccessor = GLPropertyAccessor.makeAccessor(mContextId, - GLStateType.TEXTURE_STATE, - GLStateType.TEXTURES, - textureId, - mTextureType); - } - - return textureAccessor.getProperty(state); - } - - @Override - public String getPath() { - return String.format("TEXTURE_STATE/TEXTURES/${activeTexture}/%s", mTextureType); - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TextureUnitPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TextureUnitPropertyAccessor.java deleted file mode 100644 index 2489e14db..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/TextureUnitPropertyAccessor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2012 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 com.android.ide.eclipse.gltrace.state.transforms; - -import com.android.ide.eclipse.gltrace.state.GLIntegerProperty; -import com.android.ide.eclipse.gltrace.state.GLStateType; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -/** - * The {@link TextureUnitPropertyAccessor} provides the ability to access a - * texture unit property that is indexed based on the run time value of the - * {@link GLStateType#ACTIVE_TEXTURE_UNIT} property. - */ -public class TextureUnitPropertyAccessor implements IGLPropertyAccessor { - private final int mContextId; - private final IGLPropertyAccessor mActiveTextureAccessor; - private final GLStateType mTargetType; - - public TextureUnitPropertyAccessor(int contextId, GLStateType targetPropertyType) { - mContextId = contextId; - mTargetType = targetPropertyType; - - mActiveTextureAccessor = GLPropertyAccessor.makeAccessor(mContextId, - GLStateType.TEXTURE_STATE, - GLStateType.ACTIVE_TEXTURE_UNIT); - } - - @Override - public IGLProperty getProperty(IGLProperty state) { - // first extract the current active texture unit - IGLProperty activeTextureProperty = mActiveTextureAccessor.getProperty(state); - if (!(activeTextureProperty instanceof GLIntegerProperty)) { - return null; - } - Integer activeTexture = (Integer) activeTextureProperty.getValue(); - - // extract the required property for the current texture unit - IGLPropertyAccessor targetAccessor = GLPropertyAccessor.makeAccessor(mContextId, - GLStateType.TEXTURE_STATE, - GLStateType.TEXTURE_UNITS, - activeTexture, - mTargetType); - return targetAccessor.getProperty(state); - } - - @Override - public String getPath() { - return String.format("TEXTURE_STATE/TEXTURE_UNITS/${activeTextureUnit}/%s", mTargetType); - } -} |