blob: 0eb6a6d6c82f1db1d92d3d0572430d0a9f038e47 [file] [log] [blame]
Jason Samsf70b0fc2012-02-22 15:22:41 -08001/*
2 * Copyright (C) 2008-2012 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 ANDROID_RENDERSCRIPT_H
18#define ANDROID_RENDERSCRIPT_H
19
20
21#include <pthread.h>
22#include <utils/String8.h>
23#include <utils/Vector.h>
24
25#include "rs.h"
26
27class Element;
28class Type;
29class Allocation;
30
31class RenderScript {
32 friend class BaseObj;
33 friend class Allocation;
34 friend class Element;
35 friend class Type;
Jason Sams170dc842012-02-23 17:14:39 -080036 friend class Script;
37 friend class ScriptC;
Jason Samsf70b0fc2012-02-22 15:22:41 -080038
39public:
40 RenderScript();
41 virtual ~RenderScript();
42
43 typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
44 typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
45
46
47 void setErrorHandler(ErrorHandlerFunc_t func);
48 ErrorHandlerFunc_t getErrorHandler() {return mErrorFunc;}
49
50 void setMessageHandler(MessageHandlerFunc_t func);
51 MessageHandlerFunc_t getMessageHandler() {return mMessageFunc;}
52
53 bool init(int targetApi);
54 void contextDump();
55 void finish();
56
57private:
58 static bool gInitialized;
59 static pthread_mutex_t gInitMutex;
60
61 pthread_t mMessageThreadId;
62 pid_t mNativeMessageThreadId;
63 bool mMessageRun;
64
65 RsDevice mDev;
66 RsContext mContext;
67
68 ErrorHandlerFunc_t mErrorFunc;
69 MessageHandlerFunc_t mMessageFunc;
70
71 struct {
72 Element *U8;
73 Element *I8;
74 Element *U16;
75 Element *I16;
76 Element *U32;
77 Element *I32;
78 Element *U64;
79 Element *I64;
80 Element *F32;
81 Element *F64;
82 Element *BOOLEAN;
83
84 Element *ELEMENT;
85 Element *TYPE;
86 Element *ALLOCATION;
87 Element *SAMPLER;
88 Element *SCRIPT;
89 Element *MESH;
90 Element *PROGRAM_FRAGMENT;
91 Element *PROGRAM_VERTEX;
92 Element *PROGRAM_RASTER;
93 Element *PROGRAM_STORE;
94
95 Element *A_8;
96 Element *RGB_565;
97 Element *RGB_888;
98 Element *RGBA_5551;
99 Element *RGBA_4444;
100 Element *RGBA_8888;
101
102 Element *FLOAT_2;
103 Element *FLOAT_3;
104 Element *FLOAT_4;
105
106 Element *DOUBLE_2;
107 Element *DOUBLE_3;
108 Element *DOUBLE_4;
109
110 Element *UCHAR_2;
111 Element *UCHAR_3;
112 Element *UCHAR_4;
113
114 Element *CHAR_2;
115 Element *CHAR_3;
116 Element *CHAR_4;
117
118 Element *USHORT_2;
119 Element *USHORT_3;
120 Element *USHORT_4;
121
122 Element *SHORT_2;
123 Element *SHORT_3;
124 Element *SHORT_4;
125
126 Element *UINT_2;
127 Element *UINT_3;
128 Element *UINT_4;
129
130 Element *INT_2;
131 Element *INT_3;
132 Element *INT_4;
133
134 Element *ULONG_2;
135 Element *ULONG_3;
136 Element *ULONG_4;
137
138 Element *LONG_2;
139 Element *LONG_3;
140 Element *LONG_4;
141
142 Element *MATRIX_4X4;
143 Element *MATRIX_3X3;
144 Element *MATRIX_2X2;
145 } mElements;
146
147
148
Jason Sams170dc842012-02-23 17:14:39 -0800149 void throwError(const char *err) const;
Jason Samsf70b0fc2012-02-22 15:22:41 -0800150
151 static void * threadProc(void *);
152
153};
154
155#endif
156