diff options
author | Siva Velusamy <vsiva@google.com> | 2012-01-12 11:16:01 -0800 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2012-01-12 13:09:57 -0800 |
commit | 6e179c18c2791a64b4023b4574400f8048cc2a12 (patch) | |
tree | 9b4ba5ec95dc5d31c30a3c6545024e6302b36a58 /eclipse | |
parent | ab6d02d04c8bb37506b1844590ab52c5c7d794e7 (diff) | |
download | sdk-6e179c18c2791a64b4023b4574400f8048cc2a12.zip sdk-6e179c18c2791a64b4023b4574400f8048cc2a12.tar.gz sdk-6e179c18c2791a64b4023b4574400f8048cc2a12.tar.bz2 |
gltrace: state view improvements
The GL State View currently utilizes a single tree and switches
the underlying model depending on which editor is active. This causes
loss of context when switching between editors.
This patch makes the state view behave more like the Eclipse Outline
View. State View now inherits from PageBookView, and it allows each
editor to supply whatever controls it wants to display in the view.
Each editor supplies an instance of StateViewPage based on the state
of the trace in the editor.
This patch also moves the state information out of the GLTrace object
and into the StateViewPage.
Change-Id: Ied827ffc53ebba835f1617126068eb3de50f12d4
Diffstat (limited to 'eclipse')
14 files changed, 362 insertions, 279 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.gldebugger/plugin.xml index 6c1e134..798175b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/plugin.xml +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/plugin.xml @@ -25,9 +25,9 @@ </view>
<view
category="com.android.ide.eclipse.gltrace"
- class="com.android.ide.eclipse.gltrace.views.GLStateView"
+ class="com.android.ide.eclipse.gltrace.views.StateView"
icon="icons/opengl.png"
- id="com.android.ide.eclipse.gltrace.views.GLState"
+ id="com.android.ide.eclipse.gltrace.views.State"
name="GL State"
restorable="true">
</view>
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/GLTracePerspective.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/GLTracePerspective.java index fee40a1..6f4ee7e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/GLTracePerspective.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/GLTracePerspective.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.gltrace; import com.android.ide.eclipse.gltrace.views.GLFramebufferView; -import com.android.ide.eclipse.gltrace.views.GLStateView; +import com.android.ide.eclipse.gltrace.views.StateView; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; @@ -32,7 +32,7 @@ public class GLTracePerspective implements IPerspectiveFactory { // Add the OpenGL state view to the right of the editor IFolderLayout right = layout.createFolder(STATE_FOLDER_ID, IPageLayout.RIGHT, 0.7f, layout.getEditorArea()); - right.addView(GLStateView.ID); + right.addView(StateView.ID); // Add the OpenGL Framebuffer view below the state view IFolderLayout rightBottom = layout.createFolder(FB_FOLDER_ID, IPageLayout.BOTTOM, 0.6f, diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/GLFunctionTraceViewer.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/GLFunctionTraceViewer.java index 476e334..96eb3a9 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/GLFunctionTraceViewer.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/GLFunctionTraceViewer.java @@ -534,4 +534,8 @@ public class GLFunctionTraceViewer extends EditorPart implements ISelectionProvi public GLTrace getTrace() { return mTrace; } + + public StateViewPage getStateViewPage() { + return new StateViewPage(mTrace); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateContentProvider.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateContentProvider.java index e0aac50..f24c799 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateContentProvider.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateContentProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.ide.eclipse.gltrace.views; +package com.android.ide.eclipse.gltrace.editors; import com.android.ide.eclipse.gltrace.state.GLCompositeProperty; import com.android.ide.eclipse.gltrace.state.GLListProperty; @@ -23,7 +23,7 @@ import com.android.ide.eclipse.gltrace.state.IGLProperty; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; -public class GLStateContentProvider implements ITreeContentProvider { +public class StateContentProvider implements ITreeContentProvider { @Override public void dispose() { } diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateLabelProvider.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateLabelProvider.java index e13daa7..611ecaf 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateLabelProvider.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateLabelProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.ide.eclipse.gltrace.views; +package com.android.ide.eclipse.gltrace.editors; import com.android.ide.eclipse.gltrace.state.GLListProperty; import com.android.ide.eclipse.gltrace.state.IGLProperty; @@ -23,7 +23,7 @@ import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; -public class GLStateLabelProvider extends LabelProvider implements ITableLabelProvider { +public class StateLabelProvider extends LabelProvider implements ITableLabelProvider { @Override public Image getColumnImage(Object element, int columnIndex) { return null; diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java new file mode 100644 index 0000000..2478288 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java @@ -0,0 +1,221 @@ +/* + * 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.editors; + +import com.android.ide.eclipse.gltrace.model.GLCall; +import com.android.ide.eclipse.gltrace.model.GLTrace; +import com.android.ide.eclipse.gltrace.state.GLState; +import com.android.ide.eclipse.gltrace.state.GLStateTransform; +import com.android.ide.eclipse.gltrace.state.IGLProperty; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.part.Page; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * A tree view of the OpenGL state. It listens to the current GLCall that is selected + * in the Function Trace view, and updates its view to reflect the state as of the selected call. + */ +public class StateViewPage extends Page implements ISelectionListener { + public static final String ID = "com.android.ide.eclipse.gltrace.views.GLState"; //$NON-NLS-1$ + private TreeViewer mTreeViewer; + + private final List<GLCall> mGLCalls; + + /** OpenGL State as of call {@link #mCurrentStateIndex}. */ + private final IGLProperty mState; + private int mCurrentStateIndex; + + private String[] TREE_PROPERTIES = { "Name", "Value" }; + + public StateViewPage(GLTrace trace) { + mGLCalls = trace.getGLCalls(); + + mState = GLState.createDefaultState(trace.getContexts().size()); + mCurrentStateIndex = 0; + } + + @Override + public void createControl(Composite parent) { + final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + tree.setLayoutData(new GridData(GridData.FILL_BOTH)); + + TreeColumn col1 = new TreeColumn(tree, SWT.LEFT); + col1.setText(TREE_PROPERTIES[0]); + col1.setWidth(200); + + TreeColumn col2 = new TreeColumn(tree, SWT.LEFT); + col2.setText(TREE_PROPERTIES[1]); + col2.setWidth(200); + + mTreeViewer = new TreeViewer(tree); + mTreeViewer.setContentProvider(new StateContentProvider()); + mTreeViewer.setLabelProvider(new StateLabelProvider()); + mTreeViewer.setInput(mState); + mTreeViewer.refresh(); + } + + @Override + public void init(IPageSite pageSite) { + super.init(pageSite); + pageSite.getPage().addSelectionListener(this); + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (!(part instanceof GLFunctionTraceViewer)) { + return; + } + + if (!(selection instanceof IStructuredSelection)) { + return; + } + + GLCall selectedCall = null; + + IStructuredSelection ssel = (IStructuredSelection) selection; + if (ssel.toList().size() > 0) { + Object data = ssel.toList().get(0); + if (data instanceof GLCall) { + selectedCall = (GLCall) data; + } + } + + if (selectedCall == null) { + return; + } + + if (selectedCall.getIndex() != mCurrentStateIndex) { + final Set<IGLProperty> changedProperties = updateState(mCurrentStateIndex, + selectedCall.getIndex()); + mCurrentStateIndex = selectedCall.getIndex(); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + mTreeViewer.update(changedProperties.toArray(), TREE_PROPERTIES); + } + }); + } + } + + @Override + public Control getControl() { + if (mTreeViewer == null) { + return null; + } + + return mTreeViewer.getControl(); + } + + @Override + public void setFocus() { + } + + /** + * Update GL state from GL call at fromIndex to the call at toIndex. + * If fromIndex < toIndex, the GL state will be updated by applying all the transformations + * corresponding to calls from (fromIndex + 1) to toIndex (inclusive). + * If fromIndex > toIndex, the GL state will be updated by reverting all the calls from + * fromIndex (inclusive) to (toIndex + 1). + * @return GL state properties that changed as a result of this update. + */ + private Set<IGLProperty> updateState(int fromIndex, int toIndex) { + assert fromIndex >= 0 && fromIndex < mGLCalls.size(); + assert toIndex >= 0 && toIndex < mGLCalls.size(); + + if (fromIndex < toIndex) { + return applyTransformations(fromIndex, toIndex); + } else if (fromIndex > toIndex) { + return revertTransformations(fromIndex, toIndex); + } else { + return Collections.emptySet(); + } + } + + private Set<IGLProperty> applyTransformations(int fromIndex, int toIndex) { + int setSizeHint = 3 * (toIndex - fromIndex) + 10; + Set<IGLProperty> changedProperties = new HashSet<IGLProperty>(setSizeHint); + + for (int i = fromIndex + 1; i <= toIndex; i++) { + for (GLStateTransform f : mGLCalls.get(i).getStateTransformations()) { + f.apply(mState); + + IGLProperty changedProperty = f.getChangedProperty(mState); + if (changedProperty != null) { + changedProperties.addAll(getHierarchy(changedProperty)); + } + } + } + + return changedProperties; + } + + private Set<IGLProperty> revertTransformations(int fromIndex, int toIndex) { + int setSizeHint = 3 * (fromIndex - toIndex) + 10; + Set<IGLProperty> changedProperties = new HashSet<IGLProperty>(setSizeHint); + + for (int i = fromIndex; i > toIndex; i--) { + for (GLStateTransform f : mGLCalls.get(i).getStateTransformations()) { + f.revert(mState); + + IGLProperty changedProperty = f.getChangedProperty(mState); + if (changedProperty != null) { + changedProperties.addAll(getHierarchy(changedProperty)); + } + } + } + + return changedProperties; + } + + /** + * Obtain the list of properties starting from the provided property up to + * the root of GL state. + */ + private List<IGLProperty> getHierarchy(IGLProperty changedProperty) { + List<IGLProperty> changedProperties = new ArrayList<IGLProperty>(5); + changedProperties.add(changedProperty); + + // add the entire parent chain until we reach the root + IGLProperty prop = changedProperty; + while ((prop = prop.getParent()) != null) { + changedProperties.add(prop); + } + + return changedProperties; + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/model/GLTrace.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/model/GLTrace.java index 57256e9..dd675fe 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/model/GLTrace.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/model/GLTrace.java @@ -20,9 +20,6 @@ import com.android.ide.eclipse.gltrace.GLProtoBuf.GLMessage; import com.android.ide.eclipse.gltrace.ProtoBufUtils; import com.android.ide.eclipse.gltrace.TraceFileInfo; import com.android.ide.eclipse.gltrace.TraceFileReader; -import com.android.ide.eclipse.gltrace.state.GLState; -import com.android.ide.eclipse.gltrace.state.GLStateTransform; -import com.android.ide.eclipse.gltrace.state.IGLProperty; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; @@ -32,9 +29,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; /** GLTrace is the in memory model of a OpenGL trace file. */ public class GLTrace { @@ -52,19 +47,12 @@ public class GLTrace { /** List of context ids used by the application. */ private List<Integer> mContextIds; - /** OpenGL State as of call {@link #mCurrentStateIndex}. */ - private IGLProperty mState; - private int mCurrentStateIndex; - public GLTrace(TraceFileInfo traceFileInfo, List<GLFrame> glFrames, List<GLCall> glCalls, List<Integer> contextIds) { mTraceFileInfo = traceFileInfo; mGLFrames = glFrames; mGLCalls = glCalls; mContextIds = contextIds; - - mState = GLState.createDefaultState(); - mCurrentStateIndex = -1; } public List<GLFrame> getFrames() { @@ -90,78 +78,6 @@ public class GLTrace { return mGLCalls.subList(start, end); } - public IGLProperty getStateAt(GLCall call) { - if (call == null) { - return null; - } - - int callIndex = call.getIndex(); - if (callIndex == mCurrentStateIndex) { - return mState; - } - - if (callIndex > mCurrentStateIndex) { - // if the state is needed for a future GLCall, then apply the transformations - // for all the GLCall's upto and including the required GLCall - for (int i = mCurrentStateIndex + 1; i <= callIndex; i++) { - for (GLStateTransform f : mGLCalls.get(i).getStateTransformations()) { - f.apply(mState); - } - } - - mCurrentStateIndex = callIndex; - return mState; - } - - // if the state is needed for a call that is before the current index, - // then revert the transformations until we reach the required call - for (int i = mCurrentStateIndex; i > callIndex; i--) { - for (GLStateTransform f : mGLCalls.get(i).getStateTransformations()) { - f.revert(mState); - } - } - - mCurrentStateIndex = callIndex; - return mState; - } - - /** - * Gets the set of properties in the provided OpenGL state that are affected by - * changing state from one GL call to another. - */ - public Set<IGLProperty> getChangedProperties(GLCall from, GLCall to, IGLProperty state) { - int fromIndex = from == null ? 0 : from.getIndex(); - int toIndex = to == null ? 0 : to.getIndex(); - - if (fromIndex == -1 || toIndex == -1) { - return null; - } - - int setSizeHint = 3 * Math.abs(fromIndex - toIndex) + 10; - Set<IGLProperty> changedProperties = new HashSet<IGLProperty>(setSizeHint); - - for (int i = Math.min(fromIndex, toIndex); i <= Math.max(fromIndex, toIndex); i++) { - for (GLStateTransform f : mGLCalls.get(i).getStateTransformations()) { - IGLProperty changedProperty = f.getChangedProperty(state); - if (changedProperty == null) { - continue; - } - - // add the property that is affected - changedProperties.add(changedProperty); - - // also add its entire parent chain until we reach the root - IGLProperty parent = changedProperty.getParent(); - while (parent != null) { - changedProperties.add(parent); - parent = parent.getParent(); - } - } - } - - return changedProperties; - } - public Image getImage(GLCall c) { if (!c.hasFb()) { return null; 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 index 6c5455a..b4b1898 100644 --- 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 @@ -26,6 +26,7 @@ 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. @@ -34,6 +35,7 @@ public class GLListProperty implements IGLProperty { */ public GLListProperty(GLStateType type, IGLProperty template, int size) { mType = type; + mTemplate = template; mList = new ArrayList<IGLProperty>(size); for (int i = 0; i < size; i++) { @@ -62,10 +64,17 @@ public class GLListProperty implements IGLProperty { } 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>( diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLPropertyAccessor.java index fb0c84c..afc7230 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLPropertyAccessor.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLPropertyAccessor.java @@ -24,13 +24,17 @@ import java.util.List; * OpenGL State hierarchy. */ public class GLPropertyAccessor { - private List<GLPropertyExtractor> mExtractors; + private final int mContextId; + private final List<GLPropertyExtractor> mExtractors; - private GLPropertyAccessor(List<GLPropertyExtractor> extractors) { + private GLPropertyAccessor(int contextId, List<GLPropertyExtractor> extractors) { + mContextId = contextId; mExtractors = extractors; } - public IGLProperty getProperty(IGLProperty root) { + public IGLProperty getProperty(IGLProperty state) { + IGLProperty root = ((GLListProperty) state).get(mContextId); + for (GLPropertyExtractor e : mExtractors) { IGLProperty successor = e.getProperty(root); if (successor == null) { @@ -44,12 +48,13 @@ public class GLPropertyAccessor { /** * 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}, and the * GLStateType enum objects are used to query {@link GLCompositeProperty}'s. */ - public static GLPropertyAccessor makeAccessor(Object...accessors) { + public static GLPropertyAccessor makeAccessor(int contextId, Object...accessors) { List<GLPropertyExtractor> extractors = new ArrayList<GLPropertyExtractor>(); for (Object accessor : accessors) { @@ -63,7 +68,7 @@ public class GLPropertyAccessor { } } - return new GLPropertyAccessor(extractors); + return new GLPropertyAccessor(contextId, extractors); } private interface GLPropertyExtractor { 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 index 0724e69..38ee7c7 100644 --- 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 @@ -83,12 +83,18 @@ public class GLState { return framebufferState; } - /** Construct the default OpenGL State hierarchy. */ - public static IGLProperty createDefaultState() { + public static IGLProperty createDefaultES2State() { // TODO: Currently, this only models a tiny subset of the OpenGL state. - GLCompositeProperty glState = new GLCompositeProperty(GLStateType.GL_STATE, + GLCompositeProperty glState = new GLCompositeProperty(GLStateType.GL_STATE_ES2, sGLState.createVertexArrayData(), sGLState.createFramebufferState()); return glState; } + + /** Construct the default OpenGL State hierarchy. */ + public static IGLProperty createDefaultState(int numContexts) { + return new GLListProperty(GLStateType.GL_STATE, + createDefaultES2State(), + numContexts); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateTransform.java index 5ee8da6..93a44b6 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateTransform.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateTransform.java @@ -95,31 +95,36 @@ public class GLStateTransform { List<GLStateTransform> transforms = new ArrayList<GLStateTransform>(); transforms.add(new GLStateTransform( - GLPropertyAccessor.makeAccessor(GLStateType.VERTEX_ARRAY_DATA, + 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 GLStateTransform( - GLPropertyAccessor.makeAccessor(GLStateType.VERTEX_ARRAY_DATA, + 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 GLStateTransform( - GLPropertyAccessor.makeAccessor(GLStateType.VERTEX_ARRAY_DATA, + 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 GLStateTransform( - GLPropertyAccessor.makeAccessor(GLStateType.VERTEX_ARRAY_DATA, + 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 GLStateTransform( - GLPropertyAccessor.makeAccessor(GLStateType.VERTEX_ARRAY_DATA, + GLPropertyAccessor.makeAccessor(msg.getContextId(), + GLStateType.VERTEX_ARRAY_DATA, GLStateType.VERTEX_ATTRIB_ARRAY, Integer.valueOf(index), GLStateType.VERTEX_ATTRIB_ARRAY_POINTER), @@ -131,7 +136,8 @@ public class GLStateTransform { // void glBindFramebuffer(GLenum target, GLuint framebuffer); int fb = msg.getArgs(1).getIntValue(0); return Collections.singletonList(new GLStateTransform( - GLPropertyAccessor.makeAccessor(GLStateType.FRAMEBUFFER_STATE, + GLPropertyAccessor.makeAccessor(msg.getContextId(), + GLStateType.FRAMEBUFFER_STATE, GLStateType.FRAMEBUFFER_BINDING), fb)); } 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 index a4eb59d..f6d34d8 100644 --- 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 @@ -21,6 +21,8 @@ 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"), VERTEX_ATTRIB_ARRAY("Vertex Attrib Array Properties"), diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateView.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateView.java deleted file mode 100644 index 1275dae..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/GLStateView.java +++ /dev/null @@ -1,173 +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.views; - -import com.android.ide.eclipse.gltrace.editors.GLFunctionTraceViewer; -import com.android.ide.eclipse.gltrace.model.GLCall; -import com.android.ide.eclipse.gltrace.model.GLTrace; -import com.android.ide.eclipse.gltrace.state.IGLProperty; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISelectionService; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.part.ViewPart; - -import java.util.Set; - -/** - * A tree view of the OpenGL state. It listens to the current GLCall that is selected - * in the Function Trace view, and updates its view to reflect the state as of the selected call. - */ -public class GLStateView extends ViewPart implements ISelectionListener { - public static final String ID = "com.android.ide.eclipse.gltrace.views.GLState"; //$NON-NLS-1$ - private TreeViewer mTreeViewer; - - private IGLProperty mState; - private GLCall mCurrentGLCall; - - private Set<IGLProperty> mChangedProperties; - private boolean mStateChanged; - - private String []TREE_PROPERTIES = { "Name", "Value" }; - - public GLStateView() { - mState = null; - mCurrentGLCall = null; - } - - @Override - public void createPartControl(Composite parent) { - Composite c = new Composite(parent, SWT.NONE); - c.setLayout(new GridLayout(1, false)); - GridData gd = new GridData(GridData.FILL_BOTH); - c.setLayoutData(gd); - - createStateTreeViewer(c); - - ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService(); - selectionService.addPostSelectionListener(this); - } - - private void createStateTreeViewer(Composite parent) { - final Tree tree = new Tree(parent, SWT.VIRTUAL); - tree.setHeaderVisible(true); - tree.setLinesVisible(true); - tree.setLayoutData(new GridData(GridData.FILL_BOTH)); - - TreeColumn col1 = new TreeColumn(tree, SWT.LEFT); - col1.setText(TREE_PROPERTIES[0]); - col1.setWidth(200); - - TreeColumn col2 = new TreeColumn(tree, SWT.LEFT); - col2.setText(TREE_PROPERTIES[1]); - col2.setWidth(200); - - mTreeViewer = new TreeViewer(tree); - mTreeViewer.setContentProvider(new GLStateContentProvider()); - mTreeViewer.setLabelProvider(new GLStateLabelProvider()); - } - - @Override - public void dispose() { - ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService(); - selectionService.removePostSelectionListener(this); - super.dispose(); - } - - @Override - public void setFocus() { - } - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if (!(part instanceof GLFunctionTraceViewer)) { - return; - } - - if (!(selection instanceof IStructuredSelection)) { - return; - } - - GLFunctionTraceViewer traceViewer = (GLFunctionTraceViewer) part; - GLCall selectedCall = null; - - IStructuredSelection ssel = (IStructuredSelection) selection; - if (ssel.toList().size() > 0) { - Object data = ssel.toList().get(0); - if (data instanceof GLCall) { - selectedCall = (GLCall) data; - } - } - - GLTrace trace = traceViewer.getTrace(); - if (trace == null) { - return; - } - - if (selectedCall != mCurrentGLCall) { - IGLProperty nextState = trace.getStateAt(selectedCall); - if (nextState != mState) { - mState = nextState; - mStateChanged = true; - } else { - mStateChanged = false; - } - - mChangedProperties = trace.getChangedProperties(mCurrentGLCall, selectedCall, - mState); - - refreshUI(); - mCurrentGLCall = selectedCall; - } - } - - private void refreshUI() { - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - if (mTreeViewer == null) { - return; - } - - if (mStateChanged) { - // if the state has changed, provide the new input and refresh the entire tree - mTreeViewer.setInput(mState); - mTreeViewer.refresh(); - } else { - if (mChangedProperties == null) { - // refresh the entire tree if we cannot figure out exactly which properties - // have changed - mTreeViewer.refresh(); - } else { - // only refresh the nodes that have changed - mTreeViewer.update(mChangedProperties.toArray(), TREE_PROPERTIES); - } - } - } - }); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/StateView.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/StateView.java new file mode 100644 index 0000000..cd7669d --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/views/StateView.java @@ -0,0 +1,87 @@ +/* + * 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.views; + +import com.android.ide.eclipse.gltrace.editors.GLFunctionTraceViewer; +import com.android.ide.eclipse.gltrace.editors.StateViewPage; + +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.MessagePage; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.PageBookView; + +/** + * The StateView shows the GL state for the current active {@link GLFunctionTraceViewer}. + * It behaves like the Eclipse Outline View: Each active editor provides the GL state content + * to show via a {@link StateViewPage}. This class simply acts as a stack view showing the + * state corresponding to whichever editor is active. + */ +public class StateView extends PageBookView { + public static final String ID = "com.android.ide.eclipse.gltrace.views.State"; //$NON-NLS-1$ + + @Override + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage("Open (or select) a GL Trace file to view the GL State."); + return page; + } + + @Override + protected PageRec doCreatePage(IWorkbenchPart part) { + if (!(part instanceof GLFunctionTraceViewer)) { + return null; + } + + GLFunctionTraceViewer viewer = (GLFunctionTraceViewer) part; + StateViewPage page = viewer.getStateViewPage(); + initPage(page); + page.createControl(getPageBook()); + + return new PageRec(part, page); + } + + @Override + protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { + StateViewPage v = (StateViewPage) pageRecord.page; + v.dispose(); + pageRecord.dispose(); + } + + @Override + protected IWorkbenchPart getBootstrapPart() { + IWorkbenchPage page = getSite().getPage(); + if (page != null) { + return page.getActiveEditor(); + } + + return null; + } + + @Override + protected boolean isImportant(IWorkbenchPart part) { + return part instanceof GLFunctionTraceViewer; + } + + @Override + public void partBroughtToTop(IWorkbenchPart part) { + partActivated(part); + } +} |