1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.gltrace.views.detail;
18 
19 import com.android.ide.eclipse.gltrace.GLProtoBuf.GLMessage.Function;
20 import com.android.ide.eclipse.gltrace.model.GLCall;
21 import com.android.ide.eclipse.gltrace.model.GLTrace;
22 import com.android.ide.eclipse.gltrace.views.FitToCanvasAction;
23 import com.android.ide.eclipse.gltrace.views.SaveImageAction;
24 import com.android.ide.eclipse.gltrace.widgets.ImageCanvas;
25 
26 import org.eclipse.jface.action.ActionContributionItem;
27 import org.eclipse.jface.action.IContributionItem;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 
31 import java.util.Arrays;
32 import java.util.List;
33 
34 public class GlDrawCallDetailProvider implements ICallDetailProvider {
35     private ImageCanvas mImageCanvas;
36     private FitToCanvasAction mFitToCanvasAction;
37     private SaveImageAction mSaveImageAction;
38     private List<IContributionItem> mToolBarItems;
39 
40     @Override
isApplicable(GLCall call)41     public boolean isApplicable(GLCall call) {
42         return (call.getFunction() == Function.glDrawArrays
43                 || call.getFunction() == Function.glDrawElements) && call.hasFb();
44     }
45 
46     @Override
createControl(Composite parent)47     public void createControl(Composite parent) {
48         mImageCanvas = new ImageCanvas(parent);
49         mImageCanvas.setFitToCanvas(false);
50 
51         mFitToCanvasAction = new FitToCanvasAction(false, mImageCanvas);
52         mSaveImageAction = new SaveImageAction(mImageCanvas);
53 
54         mToolBarItems = Arrays.asList(
55                 (IContributionItem) new ActionContributionItem(mFitToCanvasAction),
56                 (IContributionItem) new ActionContributionItem(mSaveImageAction));
57     }
58 
59     @Override
disposeControl()60     public void disposeControl() {
61         if (mImageCanvas != null) {
62             mImageCanvas.dispose();
63             mImageCanvas = null;
64         }
65     }
66 
67     @Override
getControl()68     public Control getControl() {
69         return mImageCanvas;
70     }
71 
72     @Override
updateControl(GLTrace trace, GLCall call)73     public void updateControl(GLTrace trace, GLCall call) {
74         mImageCanvas.setImage(trace.getImage(call));
75         mImageCanvas.setFitToCanvas(true);
76     }
77 
78     @Override
getToolBarItems()79     public List<IContributionItem> getToolBarItems() {
80         return mToolBarItems;
81     }
82 }
83