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