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