• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.model;
18 
19 import com.android.ide.eclipse.gltrace.GLProtoBuf;
20 import com.android.ide.eclipse.gltrace.GLProtoBuf.GLMessage.Function;
21 import com.android.ide.eclipse.gltrace.state.transforms.IStateTransform;
22 import com.android.utils.SparseArray;
23 
24 import java.util.Collections;
25 import java.util.List;
26 
27 /**
28  * A GLCall is the in memory representation of a single {@link GLProtoBuf.GLMessage}.
29  *
30  * Some protocol buffer messages have a large amount of image data packed in them. Rather
31  * than storing all of that in memory, the GLCall stores a thumbnail image, and an offset
32  * into the trace file corresponding to original protocol buffer message. If full image data
33  * is required, the protocol buffer message can be recreated by reading the trace at the
34  * specified offset.
35  */
36 public class GLCall {
37     /** Marker name provided by a {@link Function#glPushGroupMarkerEXT} call. */
38     public static final int PROPERTY_MARKERNAME = 0;
39 
40     /** Size argument in a {@link Function#glVertexAttribPointerData} call. */
41     public static final int PROPERTY_VERTEX_ATTRIB_POINTER_SIZE = 1;
42 
43     /** Type argument in a {@link Function#glVertexAttribPointerData} call. */
44     public static final int PROPERTY_VERTEX_ATTRIB_POINTER_TYPE = 2;
45 
46     /** Data argument in a {@link Function#glVertexAttribPointerData} call. */
47     public static final int PROPERTY_VERTEX_ATTRIB_POINTER_DATA = 3;
48 
49     /** Index of this call in the trace. */
50     private int mIndex;
51 
52     /** Time on device when this call was invoked. */
53     private final long mStartTime;
54 
55     /** Offset of the protobuf message corresponding to this call in the trace file. */
56     private final long mTraceFileOffset;
57 
58     /** Flag indicating whether the original protobuf message included FB data. */
59     private final boolean mHasFb;
60 
61     /** Full string representation of this call. */
62     private final String mDisplayString;
63 
64     /** The actual GL Function called. */
65     private final Function mFunction;
66 
67     /** GL Context identifier corresponding to the context of this call. */
68     private final int mContextId;
69 
70     /** Duration of this call (MONOTONIC/wall clock time). */
71     private final int mWallDuration;
72 
73     /** Duration of this call (THREAD time). */
74     private final int mThreadDuration;
75 
76     /** List of state transformations performed by this call. */
77     private List<IStateTransform> mStateTransforms = Collections.emptyList();
78 
79     /** Error conditions while creating state transforms for this call. */
80     private String mStateTransformationCreationErrorMessage;
81 
82     /** List of properties associated to this call. */
83     private SparseArray<Object> mProperties;
84 
GLCall(int index, long startTime, long traceFileOffset, String displayString, Function function, boolean hasFb, int contextId, int wallTime, int threadTime)85     public GLCall(int index, long startTime, long traceFileOffset, String displayString,
86             Function function, boolean hasFb, int contextId,
87             int wallTime, int threadTime) {
88         mIndex = index;
89         mStartTime = startTime;
90         mTraceFileOffset = traceFileOffset;
91         mDisplayString = displayString;
92         mFunction = function;
93         mHasFb = hasFb;
94         mContextId = contextId;
95         mWallDuration = wallTime;
96         mThreadDuration = threadTime;
97     }
98 
getIndex()99     public int getIndex() {
100         return mIndex;
101     }
102 
setIndex(int i)103     public void setIndex(int i) {
104         mIndex = i;
105     }
106 
getOffsetInTraceFile()107     public long getOffsetInTraceFile() {
108         return mTraceFileOffset;
109     }
110 
getFunction()111     public Function getFunction() {
112         return mFunction;
113     }
114 
getContextId()115     public int getContextId() {
116         return mContextId;
117     }
118 
hasFb()119     public boolean hasFb() {
120         return mHasFb;
121     }
122 
getStartTime()123     public long getStartTime() {
124         return mStartTime;
125     }
126 
getWallDuration()127     public int getWallDuration() {
128         return mWallDuration;
129     }
130 
getThreadDuration()131     public int getThreadDuration() {
132         return mThreadDuration;
133     }
134 
setStateTransformations(List<IStateTransform> transforms)135     public void setStateTransformations(List<IStateTransform> transforms) {
136         mStateTransforms = transforms;
137     }
138 
setStateTransformationCreationError(String errorMessage)139     public void setStateTransformationCreationError(String errorMessage) {
140         mStateTransformationCreationErrorMessage = errorMessage;
141     }
142 
hasErrors()143     public boolean hasErrors() {
144         return mStateTransformationCreationErrorMessage != null;
145     }
146 
getError()147     public String getError() {
148         return mStateTransformationCreationErrorMessage;
149     }
150 
getStateTransformations()151     public List<IStateTransform> getStateTransformations() {
152         return mStateTransforms;
153     }
154 
155     @Override
toString()156     public String toString() {
157         return mDisplayString;
158     }
159 
160     /**
161      * Associate a certain value to the property name. Property names are defined
162      * as constants in {@link GLCall}.
163      */
addProperty(int propertyName, Object value)164     public void addProperty(int propertyName, Object value) {
165         if (mProperties == null) {
166             mProperties = new SparseArray<Object>(1);
167         }
168 
169         mProperties.put(propertyName, value);
170     }
171 
172     /**
173      * Obtain the value for the given property. Returns null if no such property
174      * is associated with this {@link GLCall}.
175      */
getProperty(int propertyName)176     public Object getProperty(int propertyName) {
177         if (mProperties == null) {
178             return null;
179         }
180 
181         return mProperties.get(propertyName);
182     }
183 }
184