19fba23219876eca6b817829618537a9956be4a42Siva Velusamy/* 29fba23219876eca6b817829618537a9956be4a42Siva Velusamy * Copyright (C) 2012 The Android Open Source Project 39fba23219876eca6b817829618537a9956be4a42Siva Velusamy * 49fba23219876eca6b817829618537a9956be4a42Siva Velusamy * Licensed under the Apache License, Version 2.0 (the "License"); 59fba23219876eca6b817829618537a9956be4a42Siva Velusamy * you may not use this file except in compliance with the License. 69fba23219876eca6b817829618537a9956be4a42Siva Velusamy * You may obtain a copy of the License at 79fba23219876eca6b817829618537a9956be4a42Siva Velusamy * 89fba23219876eca6b817829618537a9956be4a42Siva Velusamy * http://www.apache.org/licenses/LICENSE-2.0 99fba23219876eca6b817829618537a9956be4a42Siva Velusamy * 109fba23219876eca6b817829618537a9956be4a42Siva Velusamy * Unless required by applicable law or agreed to in writing, software 119fba23219876eca6b817829618537a9956be4a42Siva Velusamy * distributed under the License is distributed on an "AS IS" BASIS, 129fba23219876eca6b817829618537a9956be4a42Siva Velusamy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139fba23219876eca6b817829618537a9956be4a42Siva Velusamy * See the License for the specific language governing permissions and 149fba23219876eca6b817829618537a9956be4a42Siva Velusamy * limitations under the License. 159fba23219876eca6b817829618537a9956be4a42Siva Velusamy */ 169fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1744c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamypackage com.android.ide.eclipse.gltrace.views.detail; 189fba23219876eca6b817829618537a9956be4a42Siva Velusamy 199fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport com.android.ide.eclipse.gltrace.editors.GLCallGroups.GLCallNode; 209fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport com.android.ide.eclipse.gltrace.editors.GLFunctionTraceViewer; 219fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport com.android.ide.eclipse.gltrace.model.GLCall; 229fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport com.android.ide.eclipse.gltrace.model.GLTrace; 239fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport com.android.ide.eclipse.gltrace.state.IGLProperty; 2444c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamyimport com.android.ide.eclipse.gltrace.views.StateView; 259fba23219876eca6b817829618537a9956be4a42Siva Velusamy 269fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.jface.action.IContributionItem; 279fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.jface.action.IToolBarManager; 289fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.jface.viewers.ISelection; 299fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.jface.viewers.IStructuredSelection; 309fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.jface.viewers.TreeSelection; 319fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.swt.SWT; 329fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.swt.custom.StackLayout; 339fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.swt.layout.GridData; 349fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.swt.widgets.Composite; 359fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.swt.widgets.Control; 369fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.ui.ISelectionListener; 379fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.ui.IWorkbenchPart; 389fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.ui.part.IPageSite; 399fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport org.eclipse.ui.part.Page; 409fba23219876eca6b817829618537a9956be4a42Siva Velusamy 419fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport java.util.Arrays; 429fba23219876eca6b817829618537a9956be4a42Siva Velusamyimport java.util.List; 439fba23219876eca6b817829618537a9956be4a42Siva Velusamy 449fba23219876eca6b817829618537a9956be4a42Siva Velusamypublic class DetailsPage extends Page implements ISelectionListener { 45fc3fad075b7a8ed83b5e314720868b2db19ee9c8Siva Velusamy private GLTrace mTrace; 469fba23219876eca6b817829618537a9956be4a42Siva Velusamy 479fba23219876eca6b817829618537a9956be4a42Siva Velusamy private IToolBarManager mToolBarManager; 489fba23219876eca6b817829618537a9956be4a42Siva Velusamy private Composite mTopComposite; 499fba23219876eca6b817829618537a9956be4a42Siva Velusamy private StackLayout mStackLayout; 509fba23219876eca6b817829618537a9956be4a42Siva Velusamy private Composite mBlankComposite; 519fba23219876eca6b817829618537a9956be4a42Siva Velusamy 5244c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy private List<IDetailProvider> mDetailProviders = Arrays.asList( 539fba23219876eca6b817829618537a9956be4a42Siva Velusamy new ShaderSourceDetailsProvider(), 54c9a8c4aa0b9c5ae0f0287fd2805fd5cde49fd0cfSiva Velusamy new ShaderUniformDetailsProvider(), 5544c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy new TextureImageDetailsProvider(), 563099b177619345a94ce3c7c8a2dc03e06f1b7bf5Siva Velusamy new VboDetailProvider(), 5752ecd2f08ee936df425e4c53f9bd8310061f3f57Siva Velusamy new GlDrawCallDetailProvider(), 5852ecd2f08ee936df425e4c53f9bd8310061f3f57Siva Velusamy new VertexAttribPointerDataDetailProvider()); 599fba23219876eca6b817829618537a9956be4a42Siva Velusamy 609fba23219876eca6b817829618537a9956be4a42Siva Velusamy public DetailsPage(GLTrace trace) { 619fba23219876eca6b817829618537a9956be4a42Siva Velusamy mTrace = trace; 629fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 639fba23219876eca6b817829618537a9956be4a42Siva Velusamy 64fc3fad075b7a8ed83b5e314720868b2db19ee9c8Siva Velusamy public void setInput(GLTrace trace) { 65fc3fad075b7a8ed83b5e314720868b2db19ee9c8Siva Velusamy mTrace = trace; 66fc3fad075b7a8ed83b5e314720868b2db19ee9c8Siva Velusamy } 67fc3fad075b7a8ed83b5e314720868b2db19ee9c8Siva Velusamy 689fba23219876eca6b817829618537a9956be4a42Siva Velusamy @Override 699fba23219876eca6b817829618537a9956be4a42Siva Velusamy public void createControl(Composite parent) { 709fba23219876eca6b817829618537a9956be4a42Siva Velusamy mTopComposite = new Composite(parent, SWT.NONE); 719fba23219876eca6b817829618537a9956be4a42Siva Velusamy mStackLayout = new StackLayout(); 729fba23219876eca6b817829618537a9956be4a42Siva Velusamy mTopComposite.setLayout(mStackLayout); 739fba23219876eca6b817829618537a9956be4a42Siva Velusamy mTopComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 749fba23219876eca6b817829618537a9956be4a42Siva Velusamy 759fba23219876eca6b817829618537a9956be4a42Siva Velusamy mBlankComposite = new Composite(mTopComposite, SWT.NONE); 769fba23219876eca6b817829618537a9956be4a42Siva Velusamy 779fba23219876eca6b817829618537a9956be4a42Siva Velusamy mToolBarManager = getSite().getActionBars().getToolBarManager(); 789fba23219876eca6b817829618537a9956be4a42Siva Velusamy 7944c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy for (IDetailProvider provider : mDetailProviders) { 809fba23219876eca6b817829618537a9956be4a42Siva Velusamy provider.createControl(mTopComposite); 819fba23219876eca6b817829618537a9956be4a42Siva Velusamy 829fba23219876eca6b817829618537a9956be4a42Siva Velusamy for (IContributionItem item: provider.getToolBarItems()) { 839fba23219876eca6b817829618537a9956be4a42Siva Velusamy mToolBarManager.add(item); 849fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 859fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 869fba23219876eca6b817829618537a9956be4a42Siva Velusamy 879fba23219876eca6b817829618537a9956be4a42Siva Velusamy setDetailsProvider(null); 889fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 899fba23219876eca6b817829618537a9956be4a42Siva Velusamy 9044c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy private void setDetailsProvider(IDetailProvider provider) { 919fba23219876eca6b817829618537a9956be4a42Siva Velusamy for (IContributionItem item: mToolBarManager.getItems()) { 929fba23219876eca6b817829618537a9956be4a42Siva Velusamy item.setVisible(false); 939fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 949fba23219876eca6b817829618537a9956be4a42Siva Velusamy 959fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (provider == null) { 969fba23219876eca6b817829618537a9956be4a42Siva Velusamy setTopControl(mBlankComposite); 979fba23219876eca6b817829618537a9956be4a42Siva Velusamy } else { 989fba23219876eca6b817829618537a9956be4a42Siva Velusamy setTopControl(provider.getControl()); 999fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1009fba23219876eca6b817829618537a9956be4a42Siva Velusamy for (IContributionItem item: provider.getToolBarItems()) { 1019fba23219876eca6b817829618537a9956be4a42Siva Velusamy item.setVisible(true); 1029fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1039fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1049fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1059fba23219876eca6b817829618537a9956be4a42Siva Velusamy mToolBarManager.update(true); 1069fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1079fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1089fba23219876eca6b817829618537a9956be4a42Siva Velusamy private void setTopControl(Control c) { 1099fba23219876eca6b817829618537a9956be4a42Siva Velusamy mStackLayout.topControl = c; 1109fba23219876eca6b817829618537a9956be4a42Siva Velusamy mTopComposite.layout(); 1119fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1129fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1139fba23219876eca6b817829618537a9956be4a42Siva Velusamy @Override 1149fba23219876eca6b817829618537a9956be4a42Siva Velusamy public Control getControl() { 1159fba23219876eca6b817829618537a9956be4a42Siva Velusamy return mTopComposite; 1169fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1179fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1189fba23219876eca6b817829618537a9956be4a42Siva Velusamy @Override 1199fba23219876eca6b817829618537a9956be4a42Siva Velusamy public void init(IPageSite pageSite) { 1209fba23219876eca6b817829618537a9956be4a42Siva Velusamy super.init(pageSite); 1219fba23219876eca6b817829618537a9956be4a42Siva Velusamy pageSite.getPage().addSelectionListener(this); 1229fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1239fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1249fba23219876eca6b817829618537a9956be4a42Siva Velusamy @Override 1259fba23219876eca6b817829618537a9956be4a42Siva Velusamy public void dispose() { 1269fba23219876eca6b817829618537a9956be4a42Siva Velusamy getSite().getPage().removeSelectionListener(this); 1279fba23219876eca6b817829618537a9956be4a42Siva Velusamy 12844c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy for (IDetailProvider provider : mDetailProviders) { 1299fba23219876eca6b817829618537a9956be4a42Siva Velusamy provider.disposeControl(); 1309fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1319fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1329fba23219876eca6b817829618537a9956be4a42Siva Velusamy super.dispose(); 1339fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1349fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1359fba23219876eca6b817829618537a9956be4a42Siva Velusamy @Override 1369fba23219876eca6b817829618537a9956be4a42Siva Velusamy public void setFocus() { 1379fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1389fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1399fba23219876eca6b817829618537a9956be4a42Siva Velusamy @Override 1409fba23219876eca6b817829618537a9956be4a42Siva Velusamy public void selectionChanged(IWorkbenchPart part, ISelection selection) { 1419fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (part instanceof GLFunctionTraceViewer) { 1429fba23219876eca6b817829618537a9956be4a42Siva Velusamy GLCall selectedCall = getSelectedCall((GLFunctionTraceViewer) part, selection); 1439fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (selectedCall == null) { 1449fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1459fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1469fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1479fba23219876eca6b817829618537a9956be4a42Siva Velusamy callSelected(selectedCall); 1489fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1499fba23219876eca6b817829618537a9956be4a42Siva Velusamy } else if (part instanceof StateView) { 1509fba23219876eca6b817829618537a9956be4a42Siva Velusamy IGLProperty selectedProperty = getSelectedProperty((StateView) part, selection); 1519fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (selectedProperty == null) { 1529fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1539fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1549fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1559fba23219876eca6b817829618537a9956be4a42Siva Velusamy stateVariableSelected(selectedProperty); 1569fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1579fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1589fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1599fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1609fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1619fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1629fba23219876eca6b817829618537a9956be4a42Siva Velusamy private void stateVariableSelected(IGLProperty property) { 16344c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy for (IDetailProvider p : mDetailProviders) { 16444c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy if (!(p instanceof IStateDetailProvider)) { 16544c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy continue; 16644c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy } 16744c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy 16844c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy IStateDetailProvider sp = (IStateDetailProvider) p; 16944c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy if (sp.isApplicable(property)) { 17044c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy sp.updateControl(property); 17144c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy setDetailsProvider(sp); 1729fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1739fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1749fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1759fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1769fba23219876eca6b817829618537a9956be4a42Siva Velusamy setDetailsProvider(null); 1779fba23219876eca6b817829618537a9956be4a42Siva Velusamy return; 1789fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1799fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1809fba23219876eca6b817829618537a9956be4a42Siva Velusamy private void callSelected(GLCall selectedCall) { 18144c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy for (IDetailProvider p : mDetailProviders) { 18244c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy if (!(p instanceof ICallDetailProvider)) { 18344c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy continue; 18444c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy } 18544c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy 18644c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy ICallDetailProvider cp = (ICallDetailProvider) p; 18744c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy if (cp.isApplicable(selectedCall)) { 18844c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy cp.updateControl(mTrace, selectedCall); 18944c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy setDetailsProvider(cp); 19044c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy return; 19144c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy } 19244c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy } 19344c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy 19444c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy setDetailsProvider(null); 19544c6542d04e2eb9b6c2c33f7ca4074d5bab9c5dbSiva Velusamy return; 1969fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 1979fba23219876eca6b817829618537a9956be4a42Siva Velusamy 1989fba23219876eca6b817829618537a9956be4a42Siva Velusamy private GLCall getSelectedCall(GLFunctionTraceViewer part, ISelection selection) { 1999fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (part.getTrace() != mTrace) { 2009fba23219876eca6b817829618537a9956be4a42Siva Velusamy return null; 2019fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2029fba23219876eca6b817829618537a9956be4a42Siva Velusamy 2039fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (!(selection instanceof TreeSelection)) { 2049fba23219876eca6b817829618537a9956be4a42Siva Velusamy return null; 2059fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2069fba23219876eca6b817829618537a9956be4a42Siva Velusamy 2079fba23219876eca6b817829618537a9956be4a42Siva Velusamy Object data = ((TreeSelection) selection).getFirstElement(); 2089fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (data instanceof GLCallNode) { 2099fba23219876eca6b817829618537a9956be4a42Siva Velusamy return ((GLCallNode) data).getCall(); 2109fba23219876eca6b817829618537a9956be4a42Siva Velusamy } else { 2119fba23219876eca6b817829618537a9956be4a42Siva Velusamy return null; 2129fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2139fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2149fba23219876eca6b817829618537a9956be4a42Siva Velusamy 2159fba23219876eca6b817829618537a9956be4a42Siva Velusamy private IGLProperty getSelectedProperty(StateView view, ISelection selection) { 2169fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (!(selection instanceof IStructuredSelection)) { 2179fba23219876eca6b817829618537a9956be4a42Siva Velusamy return null; 2189fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2199fba23219876eca6b817829618537a9956be4a42Siva Velusamy 2209fba23219876eca6b817829618537a9956be4a42Siva Velusamy IStructuredSelection ssel = (IStructuredSelection) selection; 2219fba23219876eca6b817829618537a9956be4a42Siva Velusamy @SuppressWarnings("rawtypes") 2229fba23219876eca6b817829618537a9956be4a42Siva Velusamy List objects = ssel.toList(); 2239fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (objects.size() > 0) { 2249fba23219876eca6b817829618537a9956be4a42Siva Velusamy Object data = objects.get(0); 2259fba23219876eca6b817829618537a9956be4a42Siva Velusamy if (data instanceof IGLProperty) { 2269fba23219876eca6b817829618537a9956be4a42Siva Velusamy return (IGLProperty) data; 2279fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2289fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2299fba23219876eca6b817829618537a9956be4a42Siva Velusamy 2309fba23219876eca6b817829618537a9956be4a42Siva Velusamy return null; 2319fba23219876eca6b817829618537a9956be4a42Siva Velusamy } 2329fba23219876eca6b817829618537a9956be4a42Siva Velusamy} 233