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; 18 19 import java.io.DataOutputStream; 20 import java.io.IOException; 21 22 /** 23 * Write trace control options to the trace backend. 24 * Currently, the number of options is limited, so all the options are packed into a 25 * single integer. Any changes to this protocol have to be updated on the device as well. 26 */ 27 public class TraceCommandWriter { 28 private static final int CMD_SIZE = 4; 29 30 private static final int READ_FB_ON_EGLSWAP_BIT = 0; 31 private static final int READ_FB_ON_GLDRAW_BIT = 1; 32 private static final int READ_TEXTURE_DATA_ON_GLTEXIMAGE_BIT = 2; 33 34 private final DataOutputStream mStream;; 35 TraceCommandWriter(DataOutputStream traceCommandStream)36 public TraceCommandWriter(DataOutputStream traceCommandStream) { 37 mStream = traceCommandStream; 38 } 39 setTraceOptions(boolean readFbOnEglSwap, boolean readFbOnGlDraw, boolean readTextureOnGlTexImage)40 public void setTraceOptions(boolean readFbOnEglSwap, boolean readFbOnGlDraw, 41 boolean readTextureOnGlTexImage) throws IOException { 42 int eglSwap = readFbOnEglSwap ? (1 << READ_FB_ON_EGLSWAP_BIT) : 0; 43 int glDraw = readFbOnGlDraw ? (1 << READ_FB_ON_GLDRAW_BIT) : 0; 44 int tex = readTextureOnGlTexImage ? ( 1 << READ_TEXTURE_DATA_ON_GLTEXIMAGE_BIT) : 0; 45 46 int cmd = eglSwap | glDraw | tex; 47 48 mStream.writeInt(CMD_SIZE); 49 mStream.writeInt(cmd); 50 mStream.flush(); 51 } 52 close()53 public void close() { 54 try { 55 mStream.close(); 56 } catch (IOException e) { 57 // ignore exception while closing stream 58 } 59 } 60 } 61