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