blob: 129116a1dd05a7c83566108cedeb2ceb37897914 [file] [log] [blame]
Siva Velusamydb974682011-11-30 15:05:37 -08001/*
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 Velusamy1e81e712011-12-14 12:19:56 -080020#include <map>
Siva Velusamy157fea642012-01-03 14:39:31 -080021#include <pthread.h>
Siva Velusamy1e81e712011-12-14 12:19:56 -080022
Siva Velusamydb974682011-11-30 15:05:37 -080023#include "hooks.h"
Siva Velusamy1e81e712011-12-14 12:19:56 -080024#include "gltrace_transport.h"
Siva Velusamydb974682011-11-30 15:05:37 -080025
26namespace android {
27namespace gltrace {
28
29using ::android::gl_hooks_t;
30
Siva Velusamy1598ef92011-12-07 16:00:58 -080031enum FBBinding {CURRENTLY_BOUND_FB, FB0};
32
Siva Velusamy157fea642012-01-03 14:39:31 -080033class GLTraceState;
34
Siva Velusamy1e81e712011-12-14 12:19:56 -080035/** GL Trace Context info associated with each EGLContext */
Siva Velusamydb974682011-11-30 15:05:37 -080036class GLTraceContext {
Siva Velusamy1e81e712011-12-14 12:19:56 -080037 int mId; /* unique context id */
Siva Velusamy157fea642012-01-03 14:39:31 -080038 GLTraceState *mState; /* parent GL Trace state (for per process GL Trace State Info) */
Siva Velusamy1e81e712011-12-14 12:19:56 -080039
Siva Velusamydb974682011-11-30 15:05:37 -080040 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 Velusamy1e81e712011-12-14 12:19:56 -080044 BufferedOutputStream *mBufferedOutputStream; /* stream where trace info is sent */
45
Siva Velusamydb974682011-11-30 15:05:37 -080046 void resizeFBMemory(unsigned minSize);
47public:
48 gl_hooks_t *hooks;
49
Siva Velusamy157fea642012-01-03 14:39:31 -080050 GLTraceContext(int id, GLTraceState *state, BufferedOutputStream *stream);
Siva Velusamy1e81e712011-12-14 12:19:56 -080051 int getId();
Siva Velusamy157fea642012-01-03 14:39:31 -080052 GLTraceState *getGlobalTraceState();
Siva Velusamy1598ef92011-12-07 16:00:58 -080053 void getCompressedFB(void **fb, unsigned *fbsize,
54 unsigned *fbwidth, unsigned *fbheight,
55 FBBinding fbToRead);
Siva Velusamy1e81e712011-12-14 12:19:56 -080056 void traceGLMessage(GLMessage *msg);
Siva Velusamydb974682011-11-30 15:05:37 -080057};
58
Siva Velusamy1e81e712011-12-14 12:19:56 -080059/** Per process trace state. */
60class GLTraceState {
61 int mTraceContextIds;
62 TCPStream *mStream;
63 std::map<EGLContext, GLTraceContext*> mPerContextState;
Siva Velusamy157fea642012-01-03 14:39:31 -080064
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 Velusamy1e81e712011-12-14 12:19:56 -080075public:
76 GLTraceState(TCPStream *stream);
77 ~GLTraceState();
78
79 GLTraceContext *createTraceContext(int version, EGLContext c);
80 GLTraceContext *getTraceContext(EGLContext c);
81
82 TCPStream *getStream();
Siva Velusamy157fea642012-01-03 14:39:31 -080083
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 Velusamy1e81e712011-12-14 12:19:56 -080093};
94
95void setupTraceContextThreadSpecific(GLTraceContext *context);
Siva Velusamydb974682011-11-30 15:05:37 -080096GLTraceContext *getGLTraceContext();
Siva Velusamydb974682011-11-30 15:05:37 -080097void releaseContext();
98
99};
100};
101
102#endif