Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | #ifndef __GLTRACE_CONTEXT_H_ |
| 18 | #define __GLTRACE_CONTEXT_H_ |
| 19 | |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 20 | #include <map> |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 21 | #include <pthread.h> |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 22 | |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 23 | #include "hooks.h" |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 24 | #include "gltrace_transport.h" |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace gltrace { |
| 28 | |
| 29 | using ::android::gl_hooks_t; |
| 30 | |
Siva Velusamy | 1598ef9 | 2011-12-07 16:00:58 -0800 | [diff] [blame] | 31 | enum FBBinding {CURRENTLY_BOUND_FB, FB0}; |
| 32 | |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 33 | class GLTraceState; |
| 34 | |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 35 | /** GL Trace Context info associated with each EGLContext */ |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 36 | class GLTraceContext { |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 37 | int mId; /* unique context id */ |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 38 | GLTraceState *mState; /* parent GL Trace state (for per process GL Trace State Info) */ |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 39 | |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 40 | void *fbcontents; /* memory area to read framebuffer contents */ |
| 41 | void *fbcompressed; /* destination for lzf compressed framebuffer */ |
| 42 | unsigned fbcontentsSize; /* size of fbcontents & fbcompressed buffers */ |
| 43 | |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 44 | BufferedOutputStream *mBufferedOutputStream; /* stream where trace info is sent */ |
| 45 | |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 46 | void resizeFBMemory(unsigned minSize); |
| 47 | public: |
| 48 | gl_hooks_t *hooks; |
| 49 | |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 50 | GLTraceContext(int id, GLTraceState *state, BufferedOutputStream *stream); |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 51 | int getId(); |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 52 | GLTraceState *getGlobalTraceState(); |
Siva Velusamy | 1598ef9 | 2011-12-07 16:00:58 -0800 | [diff] [blame] | 53 | void getCompressedFB(void **fb, unsigned *fbsize, |
| 54 | unsigned *fbwidth, unsigned *fbheight, |
| 55 | FBBinding fbToRead); |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 56 | void traceGLMessage(GLMessage *msg); |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 59 | /** Per process trace state. */ |
| 60 | class GLTraceState { |
| 61 | int mTraceContextIds; |
| 62 | TCPStream *mStream; |
| 63 | std::map<EGLContext, GLTraceContext*> mPerContextState; |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 64 | |
| 65 | /* Options controlling additional data to be collected on |
| 66 | certain trace calls. */ |
| 67 | bool mCollectFbOnEglSwap; |
| 68 | bool mCollectFbOnGlDraw; |
| 69 | bool mCollectTextureDataOnGlTexImage; |
| 70 | pthread_rwlock_t mTraceOptionsRwLock; |
| 71 | |
| 72 | /* helper methods to get/set values using provided lock for mutual exclusion. */ |
| 73 | void safeSetValue(bool *ptr, bool value, pthread_rwlock_t *lock); |
| 74 | bool safeGetValue(bool *ptr, pthread_rwlock_t *lock); |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 75 | public: |
| 76 | GLTraceState(TCPStream *stream); |
| 77 | ~GLTraceState(); |
| 78 | |
| 79 | GLTraceContext *createTraceContext(int version, EGLContext c); |
| 80 | GLTraceContext *getTraceContext(EGLContext c); |
| 81 | |
| 82 | TCPStream *getStream(); |
Siva Velusamy | 157fea64 | 2012-01-03 14:39:31 -0800 | [diff] [blame] | 83 | |
| 84 | /* Methods to set trace options. */ |
| 85 | void setCollectFbOnEglSwap(bool en); |
| 86 | void setCollectFbOnGlDraw(bool en); |
| 87 | void setCollectTextureDataOnGlTexImage(bool en); |
| 88 | |
| 89 | /* Methods to retrieve trace options. */ |
| 90 | bool shouldCollectFbOnEglSwap(); |
| 91 | bool shouldCollectFbOnGlDraw(); |
| 92 | bool shouldCollectTextureDataOnGlTexImage(); |
Siva Velusamy | 1e81e71 | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | void setupTraceContextThreadSpecific(GLTraceContext *context); |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 96 | GLTraceContext *getGLTraceContext(); |
Siva Velusamy | db97468 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 97 | void releaseContext(); |
| 98 | |
| 99 | }; |
| 100 | }; |
| 101 | |
| 102 | #endif |